UNPKG

@aws-amplify/core

Version:
1 lines 5.7 kB
{"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 { amplifyUuid } from '../../../utils/amplifyUuid';\nimport { getClientInfo } from '../../../utils/getClientInfo';\nimport { updateEndpoint as clientUpdateEndpoint, } from '../../../awsClients/pinpoint';\nimport { cacheEndpointId } from '../utils/cacheEndpointId';\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 ? amplifyUuid() : undefined;\n const { customProperties, demographic, email, location, metrics, name, plan, } = userProfile ?? {};\n const clientInfo = getClientInfo();\n const mergedDemographic = {\n appVersion: clientInfo.appVersion,\n make: clientInfo.make,\n model: clientInfo.model,\n modelVersion: clientInfo.version,\n platform: clientInfo.platform,\n ...demographic,\n };\n const shouldAddAttributes = email || customProperties || name || plan;\n const attributes = {\n ...(email && { email: [email] }),\n ...(name && { name: [name] }),\n ...(plan && { plan: [plan] }),\n ...customProperties,\n };\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 Attributes: shouldAddAttributes ? attributes : undefined,\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 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 Metrics: metrics,\n OptOut: optOut,\n User: {\n UserId: userId ?? identityId,\n UserAttributes: userAttributes,\n },\n },\n };\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 return cacheEndpointId(appId, category, createdEndpointId);\n }\n};\n"],"names":["clientUpdateEndpoint"],"mappings":";;;;;;;;;;;AAAA;AACA;AAMA;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,CAAC;AAC5D;AACA,IAAI,MAAM,iBAAiB,GAAG,CAAC,UAAU,GAAG,WAAW,EAAE,GAAG,SAAS,CAAC;AACtE,IAAI,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,GAAG,WAAW,IAAI,EAAE,CAAC;AACvG,IAAI,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;AACvC,IAAI,MAAM,iBAAiB,GAAG;AAC9B,QAAQ,UAAU,EAAE,UAAU,CAAC,UAAU;AACzC,QAAQ,IAAI,EAAE,UAAU,CAAC,IAAI;AAC7B,QAAQ,KAAK,EAAE,UAAU,CAAC,KAAK;AAC/B,QAAQ,YAAY,EAAE,UAAU,CAAC,OAAO;AACxC,QAAQ,QAAQ,EAAE,UAAU,CAAC,QAAQ;AACrC,QAAQ,GAAG,WAAW;AACtB,KAAK,CAAC;AACN,IAAI,MAAM,mBAAmB,GAAG,KAAK,IAAI,gBAAgB,IAAI,I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