UNPKG

@aws-amplify/analytics

Version:

Analytics category of aws-amplify

50 lines (48 loc) • 1.93 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.record = record; const util_utf8_1 = require("@smithy/util-utf8"); const utils_1 = require("@aws-amplify/core/internals/utils"); const core_1 = require("@aws-amplify/core"); const getEventBuffer_1 = require("../utils/getEventBuffer"); const resolveConfig_1 = require("../utils/resolveConfig"); const utils_2 = require("../../../utils"); const logger = new core_1.ConsoleLogger('Kinesis'); function record(...args) { const [ctx, input] = (0, utils_1.resolveCtxArgs)(args); const { streamName, partitionKey, data } = input; if (!(0, utils_2.isAnalyticsEnabled)()) { logger.debug('Analytics is disabled, event will not be recorded.'); return; } const timestamp = Date.now(); const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, resolveConfig_1.resolveConfig)(ctx); (0, utils_2.resolveCredentials)(ctx) .then(({ credentials, identityId }) => { const buffer = (0, getEventBuffer_1.getEventBuffer)({ region, bufferSize, flushSize, flushInterval, credentials, identityId, resendLimit, userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record), }); buffer.append({ region, streamName, partitionKey, event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)), timestamp, retryCount: 0, }); }) .catch(e => { // An error occurred while fetching credentials or persisting the event to the buffer logger.warn('Failed to record event.', e); }); } //# sourceMappingURL=record.js.map