@aws-amplify/core
Version:
Core category of aws-amplify
1 lines • 6.76 kB
Source Map (JSON)
{"version":3,"file":"Amplify.mjs","sources":["../../../src/singleton/Amplify.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AMPLIFY_SYMBOL, Hub } from '../Hub';\nimport { deepFreeze } from '../utils';\nimport { parseAmplifyConfig } from '../libraryUtils';\nimport { AMPLIFY_CONTEXT_BRAND } from '../context/contextBrand';\nimport { createAmplifyContextToken } from '../context/contextToken';\nimport { setGlobalContext } from '../context/globalContext';\nimport { AuthClass } from './Auth';\nexport class AmplifyClass {\n constructor() {\n this.isConfigured = false;\n this.resourcesConfig = {};\n this.libraryOptions = {};\n this.Auth = new AuthClass();\n }\n /**\n * Configures Amplify for use with your back-end resources.\n *\n * @remarks\n * This API does not perform any merging of either `resourcesConfig` or `libraryOptions`. The most recently\n * provided values will be used after configuration.\n *\n * @remarks\n * `configure` can be used to specify additional library options where available for supported categories.\n *\n * @param resourceConfig - Back-end resource configuration. Typically provided via the `aws-exports.js` file.\n * @param libraryOptions - Additional options for customizing the behavior of the library.\n */\n configure(resourcesConfig, libraryOptions) {\n const resolvedResourceConfig = parseAmplifyConfig(resourcesConfig);\n this.resourcesConfig = resolvedResourceConfig;\n if (libraryOptions) {\n this.libraryOptions = libraryOptions;\n }\n // Make resource config immutable\n this.resourcesConfig = deepFreeze(this.resourcesConfig);\n this.Auth.configure(this.resourcesConfig.Auth, this.libraryOptions.Auth);\n // Warn if Pinpoint is configured\n if (this.resourcesConfig.Analytics?.Pinpoint ||\n this.resourcesConfig.Notifications?.InAppMessaging?.Pinpoint ||\n this.resourcesConfig.Notifications?.PushNotification?.Pinpoint) {\n // eslint-disable-next-line no-console\n console.warn('AWS will end support for Amazon Pinpoint on October 30, 2026. ' +\n 'The guidance is to use AWS End User Messaging for push notifications and SMS, ' +\n 'Amazon Simple Email Service for sending emails, Amazon Connect for campaigns, journeys, endpoints, and engagement analytics. ' +\n 'Pinpoint recommends Amazon Kinesis for event collection and mobile analytics.');\n }\n // Publish a branded AmplifyContext so that context-based APIs\n // (fetchAuthSession, clearCredentials) can resolve the global context.\n // Must be set BEFORE Hub.dispatch so listeners can call getGlobalContext().\n const ctx = {\n resourcesConfig: this.resourcesConfig,\n libraryOptions: this.libraryOptions,\n // Unique, frozen per-context identity handle (see AmplifyContextToken):\n // each configure() publishes a NEW global context with a fresh token.\n // Attached before the brand/freeze below so the frozen context carries it.\n token: createAmplifyContextToken(),\n fetchAuthSession: (options) => this.Auth.fetchAuthSession(options ?? {}),\n clearCredentials: () => this.Auth.clearCredentials(),\n getTokens: options => this.Auth.getTokens(options),\n };\n Object.defineProperty(ctx, AMPLIFY_CONTEXT_BRAND, {\n value: true,\n enumerable: false,\n configurable: false,\n writable: false,\n });\n Object.freeze(ctx);\n setGlobalContext(ctx);\n Hub.dispatch('core', {\n event: 'configure',\n data: this.resourcesConfig,\n }, 'Configure', AMPLIFY_SYMBOL);\n this.isConfigured = true;\n }\n /**\n * Provides access to the current back-end resource configuration for the Library.\n *\n * @returns Returns the immutable back-end resource configuration.\n */\n getConfig() {\n if (!this.isConfigured) {\n // eslint-disable-next-line no-console\n console.warn(`Amplify has not been configured. Please call Amplify.configure() before using this service.`);\n }\n return this.resourcesConfig;\n }\n}\n/**\n * The `Amplify` utility is used to configure the library.\n *\n * @remarks\n * `Amplify` orchestrates cross-category communication within the library.\n */\nexport const Amplify = new AmplifyClass();\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAQO,MAAM,YAAY,CAAC;AAC1B,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,YAAY,GAAG,KAAK;AACjC,QAAQ,IAAI,CAAC,eAAe,GAAG,EAAE;AACjC,QAAQ,IAAI,CAAC,cAAc,GAAG,EAAE;AAChC,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,SAAS,EAAE;AACnC,IAAI;AACJ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