aws-amplify
Version:
AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.
75 lines (74 loc) • 3.33 kB
TypeScript
import { AuthSession, AuthTokens, FetchAuthSessionOptions, LibraryOptions, ResourcesConfig } from '@aws-amplify/core';
import { AmplifyOutputsUnknown, LegacyConfig } from '@aws-amplify/core/internals/utils';
/**
* The `Amplify` singleton facade provides the v6-compatible, global-state
* `configure()` / `getConfig()` API. It builds a branded, frozen
* {@link AmplifyContext}, publishes it as the global context (so category APIs
* can be called without an explicit context argument), and dispatches the
* `configure` Hub event that side effects such as auth's OAuth listener depend
* on.
*
* @example
* ```ts
* import { Amplify } from 'aws-amplify';
* import config from './amplifyconfiguration.json';
*
* Amplify.configure(config);
* ```
*/
export declare const Amplify: {
/**
* Configures Amplify with the {@link resourceConfig} and {@link libraryOptions},
* publishing the resulting branded context as the global {@link AmplifyContext}.
*
* If `libraryOptions` is omitted on a reconfigure, the previously configured
* non-Auth `libraryOptions` are preserved (mirroring the previous singleton
* merge behavior); when provided they replace the previous ones. When
* `resourceConfig.Auth` is present and the caller does not supply
* `libraryOptions.Auth`, the default Cognito token/credentials providers are
* wired using cookie storage (`ssr: true`) or `localStorage` (default), and
* the singleton token provider's auth config is re-synced on every call so a
* reconfigure with a new `userPoolId` retargets token refresh.
*
* @param resourceConfig The {@link ResourcesConfig} object that is typically imported from the
* `amplifyconfiguration.json` / `amplify_outputs.json` file. It can also be an object literal
* created inline when calling `Amplify.configure`.
* @param libraryOptions The {@link LibraryOptions} additional options for the library.
*
* @example
* import config from './amplifyconfiguration.json';
*
* Amplify.configure(config);
*/
configure(resourceConfig: ResourcesConfig | LegacyConfig | AmplifyOutputsUnknown, libraryOptions?: LibraryOptions): void;
/**
* Returns the {@link ResourcesConfig} object passed in as the `resourceConfig` parameter when
* calling `Amplify.configure`.
*
* If `configure()` has not been called yet, this warns and returns an empty
* config object (`{}`) rather than throwing, preserving the historical
* pre-context singleton behavior that callers (and release-gating e2e tests)
* depend on.
*
* @returns An {@link ResourcesConfig} object.
*/
getConfig(): ResourcesConfig;
/**
* Fetches the current auth session from the global context.
*
* @throws If `configure()` has not been called yet.
*/
fetchAuthSession(options?: FetchAuthSessionOptions): Promise<AuthSession>;
/**
* Clears cached credentials in the global context.
*
* @throws If `configure()` has not been called yet.
*/
clearCredentials(): Promise<void>;
/**
* Fetches auth tokens from the global context.
*
* @throws If `configure()` has not been called yet.
*/
getTokens(options: FetchAuthSessionOptions): Promise<AuthTokens | undefined>;
};