@aws-amplify/core
Version:
Core category of aws-amplify
1 lines • 7.6 kB
Source Map (JSON)
{"version":3,"file":"updateEndpoint.mjs","sources":["../../../../../src/providers/pinpoint/apis/updateEndpoint.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { updateEndpoint as clientUpdateEndpoint, } from '../../../awsClients/pinpoint';\nimport { amplifyUuid } from '../../../utils/amplifyUuid';\nimport { getClientInfo } from '../../../utils/getClientInfo';\nimport { cacheEndpointId } from '../utils/cacheEndpointId';\nimport { clearCreatedEndpointId, createEndpointId, } from '../utils/createEndpointId';\nimport { getEndpointId } from '../utils/getEndpointId';\n/**\n * @internal\n */\nexport const updateEndpoint = async ({ address, appId, category, channelType, credentials, identityId, optOut, region, userAttributes, userId, userProfile, userAgentValue, }) => {\n const endpointId = await getEndpointId(appId, category);\n // only generate a new endpoint id if one was not found in cache\n const createdEndpointId = !endpointId\n ? createEndpointId(appId, category)\n : undefined;\n const { customProperties, demographic, email, location, metrics, name, plan, } = userProfile ?? {};\n // only automatically populate the endpoint with client info and identity id upon endpoint creation to\n // avoid overwriting the endpoint with these values every time the endpoint is updated\n const demographicsFromClientInfo = {};\n const resolvedUserId = createdEndpointId ? (userId ?? identityId) : userId;\n if (createdEndpointId) {\n const clientInfo = getClientInfo();\n demographicsFromClientInfo.appVersion = clientInfo.appVersion;\n demographicsFromClientInfo.make = clientInfo.make;\n demographicsFromClientInfo.model = clientInfo.model;\n demographicsFromClientInfo.modelVersion = clientInfo.version;\n demographicsFromClientInfo.platform = clientInfo.platform;\n }\n const mergedDemographic = {\n ...demographicsFromClientInfo,\n ...demographic,\n };\n const attributes = {\n ...(email && { email: [email] }),\n ...(name && { name: [name] }),\n ...(plan && { plan: [plan] }),\n ...customProperties,\n };\n const shouldAddDemographics = createdEndpointId || demographic;\n const shouldAddAttributes = email || customProperties || name || plan;\n const shouldAddUser = resolvedUserId || userAttributes;\n const input = {\n ApplicationId: appId,\n EndpointId: endpointId ?? createdEndpointId,\n EndpointRequest: {\n RequestId: amplifyUuid(),\n EffectiveDate: new Date().toISOString(),\n ChannelType: channelType,\n Address: address,\n ...(shouldAddAttributes && { Attributes: attributes }),\n ...(shouldAddDemographics && {\n Demographic: {\n AppVersion: mergedDemographic.appVersion,\n Locale: mergedDemographic.locale,\n Make: mergedDemographic.make,\n Model: mergedDemographic.model,\n ModelVersion: mergedDemographic.modelVersion,\n Platform: mergedDemographic.platform,\n PlatformVersion: mergedDemographic.platformVersion,\n Timezone: mergedDemographic.timezone,\n },\n }),\n ...(location && {\n Location: {\n City: location.city,\n Country: location.country,\n Latitude: location.latitude,\n Longitude: location.longitude,\n PostalCode: location.postalCode,\n Region: location.region,\n },\n }),\n Metrics: metrics,\n OptOut: optOut,\n ...(shouldAddUser && {\n User: {\n UserId: resolvedUserId,\n UserAttributes: userAttributes,\n },\n }),\n },\n };\n try {\n await clientUpdateEndpoint({ credentials, region, userAgentValue }, input);\n // if we had to create an endpoint id, we need to now cache it\n if (createdEndpointId) {\n await cacheEndpointId(appId, category, createdEndpointId);\n }\n }\n finally {\n // at this point, we completely reset the behavior so even if the update was unsuccessful\n // we can just start over with a newly created endpoint id\n if (createdEndpointId) {\n clearCreatedEndpointId(appId, category);\n }\n }\n};\n"],"names":["clientUpdateEndpoint"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAOA;AACA;AACA;AACY,MAAC,cAAc,GAAG,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,GAAG,KAAK;AAClL,IAAI,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC;AAC3D;AACA,IAAI,MAAM,iBAAiB,GAAG,CAAC;AAC/B,UAAU,gBAAgB,CAAC,KAAK,EAAE,QA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