{"version":3,"file":"configureAutoTrack.mjs","sources":["../../../../../src/providers/kinesis/apis/configureAutoTrack.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';\nimport { peekCtxArgs, updateProviderTrackers, validateTrackerConfiguration, } from '../../../utils';\nimport { record } from './record';\n// Configured Tracker instances for Kinesis\nconst configuredTrackers = {};\nexport function configureAutoTrack(...args) {\n    // Peek the optional leading context WITHOUT falling back to the global\n    // context. The context is only needed when events are emitted; resolving it\n    // eagerly would (a) throw when trackers are configured before\n    // `Amplify.configure()` and (b) pin auto-tracked events to the configuration\n    // snapshot captured at setup time after a later `configure()` call.\n    const { ctx, input } = peekCtxArgs(args);\n    validateTrackerConfiguration(input);\n    if (input.enable) {\n        assertValidationError(!!input.options?.streamName, AnalyticsValidationErrorCode.NoStreamName);\n        assertValidationError(!!input.options?.partitionKey, AnalyticsValidationErrorCode.NoPartitionKey);\n    }\n    // Callback that will emit an appropriate event to Kinesis when required by the Tracker.\n    // When no explicit context was supplied, `record` resolves the global context\n    // lazily at emit time so auto-tracked events follow the live configuration.\n    const emitTrackingEvent = (eventName, attributes) => {\n        const recordInput = {\n            streamName: input.options.streamName,\n            partitionKey: input.options.partitionKey,\n            data: {\n                name: eventName,\n                attributes,\n            },\n        };\n        if (ctx) {\n            record(ctx, recordInput);\n        }\n        else {\n            record(recordInput);\n        }\n    };\n    // Initialize or update this provider's trackers. The 'kinesis' namespace keeps\n    // page-view tracking state isolated from other providers (e.g. Pinpoint).\n    updateProviderTrackers(input, emitTrackingEvent, configuredTrackers, 'kinesis');\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA;AACA,MAAM,kBAAkB,GAAG,EAAE;AACtB,SAAS,kBAAkB,CAAC,GAAG,IAAI,EAAE;AAC5C;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC;AAC5C,IAAI,4BAA4B,CAAC,KAAK,CAAC;AACvC,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE;AACtB,QAAQ,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,4BAA4B,CAAC,YAAY,CAAC;AACrG,QAAQ,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,4BAA4B,CAAC,cAAc,CAAC;AACzG,IAAI;AACJ;AACA;AACA;AACA,IAAI,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,UAAU,KAAK;AACzD,QAAQ,MAAM,WAAW,GAAG;AAC5B,YAAY,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU;AAChD,YAAY,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,YAAY;AACpD,YAAY,IAAI,EAAE;AAClB,gBAAgB,IAAI,EAAE,SAAS;AAC/B,gBAAgB,UAAU;AAC1B,aAAa;AACb,SAAS;AACT,QAAQ,IAAI,GAAG,EAAE;AACjB,YAAY,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC;AACpC,QAAQ;AACR,aAAa;AACb,YAAY,MAAM,CAAC,WAAW,CAAC;AAC/B,QAAQ;AACR,IAAI,CAAC;AACL;AACA;AACA,IAAI,sBAAsB,CAAC,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,SAAS,CAAC;AACnF;;;;"}