UNPKG

@aws-amplify/analytics

Version:

Analytics category of aws-amplify

63 lines (61 loc) 2.15 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 = void 0; 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 utils_2 = require("../utils"); const utils_3 = require("../../../utils"); const logger = new core_1.ConsoleLogger('KinesisFirehose'); /** * Record one analytic event and send it to Kinesis Data Firehose. Events will be buffered and periodically sent to * Kinesis Data Firehose. * * @param params The input object used to construct the request. * * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library * configuration is incorrect. * * @example * ```ts * record({ * streamName: 'myFirehoseStream', * data: { } // The data blob to put into the record * }); * ``` */ const record = ({ streamName, data }) => { if (!(0, utils_3.isAnalyticsEnabled)()) { logger.debug('Analytics is disabled, event will not be recorded.'); return; } const timestamp = Date.now(); const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, utils_2.resolveConfig)(); (0, utils_3.resolveCredentials)() .then(({ credentials, identityId }) => { const buffer = (0, utils_2.getEventBuffer)({ region, credentials, identityId, bufferSize, flushSize, flushInterval, resendLimit, userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record), }); buffer.append({ region, streamName, event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)), timestamp, retryCount: 0, }); }) .catch(e => { logger.warn('Failed to record event.', e); }); }; exports.record = record; //# sourceMappingURL=record.js.map