{"version":3,"file":"syncMessages.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/syncMessages.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { InAppMessagingAction } from '@aws-amplify/core/internals/utils';\nimport { resolveEndpointId } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { defaultStorage } from '@aws-amplify/core';\nimport { getInAppMessages, } from '@aws-amplify/core/internals/aws-clients/pinpoint';\nimport { CATEGORY, CHANNEL_TYPE, PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX, getInAppMessagingUserAgentString, resolveConfig, resolveCredentials, } from '../utils';\nimport { assertServiceError, } from '../../../errors';\nimport { assertIsInitialized } from '../../../utils';\n/**\n * Fetch and persist messages from Pinpoint campaigns.\n * Calling this API is necessary to trigger InApp messages on the device.\n *\n * @deprecated AWS will end support for Amazon Pinpoint on October 30, 2026.\n *\n * @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @returns A promise that will resolve when the operation is complete.\n * @example\n * ```ts\n * // Sync InApp messages with Pinpoint and device.\n * await syncMessages();\n *\n * ```\n */\nexport async function syncMessages() {\n    assertIsInitialized();\n    const messages = await fetchInAppMessages();\n    if (!messages || messages.length === 0) {\n        return;\n    }\n    try {\n        const key = `${PINPOINT_KEY_PREFIX}${STORAGE_KEY_SUFFIX}`;\n        await defaultStorage.setItem(key, JSON.stringify(messages));\n    }\n    catch (error) {\n        assertServiceError(error);\n        throw error;\n    }\n}\nasync function fetchInAppMessages() {\n    try {\n        const { credentials, identityId } = await resolveCredentials();\n        const { appId, region } = resolveConfig();\n        const endpointId = await resolveEndpointId({\n            appId,\n            category: CATEGORY,\n            channelType: CHANNEL_TYPE,\n            credentials,\n            identityId,\n            region,\n            userAgentValue: getInAppMessagingUserAgentString(InAppMessagingAction.SyncMessages),\n        });\n        const input = {\n            ApplicationId: appId,\n            EndpointId: endpointId,\n        };\n        const response = await getInAppMessages({ credentials, region }, input);\n        const { InAppMessageCampaigns: messages } = response.InAppMessagesResponse ?? {};\n        return messages;\n    }\n    catch (error) {\n        assertServiceError(error);\n        throw error;\n    }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,YAAY,GAAG;AACrC,IAAI,mBAAmB,EAAE;AACzB,IAAI,MAAM,QAAQ,GAAG,MAAM,kBAAkB,EAAE;AAC/C,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AAC5C,QAAQ;AACR,IAAI;AACJ,IAAI,IAAI;AACR,QAAQ,MAAM,GAAG,GAAG,CAAC,EAAE,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,CAAC;AACjE,QAAQ,MAAM,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACnE,IAAI;AACJ,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,kBAAkB,CAAC,KAAK,CAAC;AACjC,QAAQ,MAAM,KAAK;AACnB,IAAI;AACJ;AACA,eAAe,kBAAkB,GAAG;AACpC,IAAI,IAAI;AACR,QAAQ,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,kBAAkB,EAAE;AACtE,QAAQ,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE;AACjD,QAAQ,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC;AACnD,YAAY,KAAK;AACjB,YAAY,QAAQ,EAAE,QAAQ;AAC9B,YAAY,WAAW,EAAE,YAAY;AACrC,YAAY,WAAW;AACvB,YAAY,UAAU;AACtB,YAAY,MAAM;AAClB,Y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