@amplitude/session-replay-browser 1.36.0 → 1.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/events/events-idb-store.d.ts.map +1 -1
- package/lib/cjs/events/events-idb-store.js +64 -46
- package/lib/cjs/events/events-idb-store.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/events/events-idb-store.d.ts.map +1 -1
- package/lib/esm/events/events-idb-store.js +64 -46
- package/lib/esm/events/events-idb-store.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/index-min.js +1 -1
- package/lib/scripts/index-min.js.gz +0 -0
- package/lib/scripts/index-min.js.map +1 -1
- package/lib/scripts/session-replay-browser-min.js +1 -1
- package/lib/scripts/session-replay-browser-min.js.gz +0 -0
- package/lib/scripts/session-replay-browser-min.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events-idb-store.d.ts","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAU,MAAM,KAAK,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGxF,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,kBAAkB,oBAAoB,CAAC;AACpD,eAAO,MAAM,eAAe,iBAAiB,CAAC;AAE9C,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,sBAAsB,EAAE;QACtB,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,IAAI,CAAC,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jE;IAEF,kBAAkB,cAAqB,MAAM,iDAW3C;IAEF,yBAAyB,eAAsB,MAAM,eAAe,MAAM,mBASxE;CACH"}
|
|
@@ -46,18 +46,32 @@ var SessionReplayEventsIDBStore = /** @class */ (function (_super) {
|
|
|
46
46
|
function SessionReplayEventsIDBStore(args) {
|
|
47
47
|
var _this = _super.call(this, args) || this;
|
|
48
48
|
_this.getSequencesToSend = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
49
|
-
var sequences, cursor, _a, sessionId, events, e_1;
|
|
49
|
+
var errorLogged, sequences, tx, cursor, _a, sessionId, events, e_1;
|
|
50
|
+
var _this = this;
|
|
50
51
|
return tslib_1.__generator(this, function (_b) {
|
|
51
52
|
switch (_b.label) {
|
|
52
53
|
case 0:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return [4 /*yield*/, this.db.transaction('sequencesToSend').store.openCursor()];
|
|
54
|
+
errorLogged = false;
|
|
55
|
+
_b.label = 1;
|
|
56
56
|
case 1:
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
_b.trys.push([1, 6, , 7]);
|
|
58
|
+
sequences = [];
|
|
59
|
+
tx = this.db.transaction('sequencesToSend');
|
|
60
|
+
// Attach a catch handler immediately so tx.done rejections (e.g. AbortError after
|
|
61
|
+
// cursor traversal completes) are always handled without blocking the return path.
|
|
62
|
+
// The errorLogged flag prevents double-logging when the outer catch already fired
|
|
63
|
+
// for the same abort (e.g. cursor.continue() threw mid-traversal).
|
|
64
|
+
tx.done.catch(function (e) {
|
|
65
|
+
if (!errorLogged) {
|
|
66
|
+
(0, is_abort_error_1.logIdbError)(_this.loggerProvider, "".concat(messages_1.STORAGE_FAILURE, ": ").concat(e), e);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return [4 /*yield*/, tx.store.openCursor()];
|
|
59
70
|
case 2:
|
|
60
|
-
|
|
71
|
+
cursor = _b.sent();
|
|
72
|
+
_b.label = 3;
|
|
73
|
+
case 3:
|
|
74
|
+
if (!cursor) return [3 /*break*/, 5];
|
|
61
75
|
_a = cursor.value, sessionId = _a.sessionId, events = _a.events;
|
|
62
76
|
sequences.push({
|
|
63
77
|
events: events,
|
|
@@ -65,15 +79,16 @@ var SessionReplayEventsIDBStore = /** @class */ (function (_super) {
|
|
|
65
79
|
sessionId: sessionId,
|
|
66
80
|
});
|
|
67
81
|
return [4 /*yield*/, cursor.continue()];
|
|
68
|
-
case
|
|
82
|
+
case 4:
|
|
69
83
|
cursor = _b.sent();
|
|
70
|
-
return [3 /*break*/,
|
|
71
|
-
case
|
|
72
|
-
case
|
|
84
|
+
return [3 /*break*/, 3];
|
|
85
|
+
case 5: return [2 /*return*/, sequences];
|
|
86
|
+
case 6:
|
|
73
87
|
e_1 = _b.sent();
|
|
88
|
+
errorLogged = true;
|
|
74
89
|
(0, is_abort_error_1.logIdbError)(this.loggerProvider, "".concat(messages_1.STORAGE_FAILURE, ": ").concat(e_1), e_1);
|
|
75
|
-
return [3 /*break*/,
|
|
76
|
-
case
|
|
90
|
+
return [3 /*break*/, 7];
|
|
91
|
+
case 7: return [2 /*return*/, undefined];
|
|
77
92
|
}
|
|
78
93
|
});
|
|
79
94
|
}); };
|
|
@@ -111,58 +126,61 @@ var SessionReplayEventsIDBStore = /** @class */ (function (_super) {
|
|
|
111
126
|
});
|
|
112
127
|
}); };
|
|
113
128
|
_this.addEventToCurrentSequence = function (sessionId, event) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
114
|
-
var tx, sequenceEvents, eventsToSend,
|
|
129
|
+
var errorLogged, tx, sequenceEvents, eventsToSend, sequenceId, e_3;
|
|
130
|
+
var _this = this;
|
|
115
131
|
return tslib_1.__generator(this, function (_a) {
|
|
116
132
|
switch (_a.label) {
|
|
117
133
|
case 0:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return [4 /*yield*/, tx.store.get(sessionId)];
|
|
134
|
+
errorLogged = false;
|
|
135
|
+
_a.label = 1;
|
|
121
136
|
case 1:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
_a.trys.push([1, 9, , 10]);
|
|
138
|
+
tx = this.db.transaction([exports.currentSequenceKey, exports.sequencesToSendKey], 'readwrite');
|
|
139
|
+
// Attach a catch handler immediately so tx.done rejections (e.g. AbortError after
|
|
140
|
+
// put succeeds but before auto-commit) are always handled without blocking.
|
|
141
|
+
// The errorLogged flag prevents double-logging when the outer catch already fired
|
|
142
|
+
// for the same abort (e.g. a put() threw).
|
|
143
|
+
tx.done.catch(function (e) {
|
|
144
|
+
if (!errorLogged) {
|
|
145
|
+
(0, is_abort_error_1.logIdbError)(_this.loggerProvider, "".concat(messages_1.STORAGE_FAILURE, ": ").concat(e), e);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return [4 /*yield*/, tx.objectStore(exports.currentSequenceKey).get(sessionId)];
|
|
125
149
|
case 2:
|
|
126
|
-
_a.sent();
|
|
127
|
-
return [
|
|
150
|
+
sequenceEvents = _a.sent();
|
|
151
|
+
if (!!sequenceEvents) return [3 /*break*/, 4];
|
|
152
|
+
return [4 /*yield*/, tx.objectStore(exports.currentSequenceKey).put({ sessionId: sessionId, events: [event] })];
|
|
128
153
|
case 3:
|
|
129
|
-
eventsToSend = void 0;
|
|
130
|
-
if (!this.shouldSplitEventsList(sequenceEvents.events, event)) return [3 /*break*/, 5];
|
|
131
|
-
eventsToSend = sequenceEvents.events;
|
|
132
|
-
// set store to empty array
|
|
133
|
-
return [4 /*yield*/, tx.store.put({ sessionId: sessionId, events: [event] })];
|
|
134
|
-
case 4:
|
|
135
|
-
// set store to empty array
|
|
136
154
|
_a.sent();
|
|
137
|
-
return [
|
|
155
|
+
return [2 /*return*/, undefined];
|
|
156
|
+
case 4:
|
|
157
|
+
if (!!this.shouldSplitEventsList(sequenceEvents.events, event)) return [3 /*break*/, 6];
|
|
158
|
+
return [4 /*yield*/, tx.objectStore(exports.currentSequenceKey).put({ sessionId: sessionId, events: sequenceEvents.events.concat(event) })];
|
|
138
159
|
case 5:
|
|
139
|
-
|
|
140
|
-
return [
|
|
160
|
+
_a.sent();
|
|
161
|
+
return [2 /*return*/, undefined];
|
|
141
162
|
case 6:
|
|
163
|
+
eventsToSend = sequenceEvents.events;
|
|
164
|
+
return [4 /*yield*/, tx.objectStore(exports.currentSequenceKey).put({ sessionId: sessionId, events: [event] })];
|
|
165
|
+
case 7:
|
|
142
166
|
_a.sent();
|
|
143
|
-
|
|
144
|
-
|
|
167
|
+
return [4 /*yield*/, tx.objectStore(exports.sequencesToSendKey).put({
|
|
168
|
+
sessionId: sessionId,
|
|
169
|
+
events: eventsToSend,
|
|
170
|
+
})];
|
|
145
171
|
case 8:
|
|
146
|
-
_a.sent();
|
|
147
|
-
if (!eventsToSend) {
|
|
148
|
-
return [2 /*return*/, undefined];
|
|
149
|
-
}
|
|
150
|
-
return [4 /*yield*/, this.storeSendingEvents(sessionId, eventsToSend)];
|
|
151
|
-
case 9:
|
|
152
172
|
sequenceId = _a.sent();
|
|
153
|
-
if (!sequenceId) {
|
|
154
|
-
return [2 /*return*/, undefined];
|
|
155
|
-
}
|
|
156
173
|
return [2 /*return*/, {
|
|
157
174
|
events: eventsToSend,
|
|
158
175
|
sessionId: sessionId,
|
|
159
176
|
sequenceId: sequenceId,
|
|
160
177
|
}];
|
|
161
|
-
case
|
|
178
|
+
case 9:
|
|
162
179
|
e_3 = _a.sent();
|
|
180
|
+
errorLogged = true;
|
|
163
181
|
(0, is_abort_error_1.logIdbError)(this.loggerProvider, "".concat(messages_1.STORAGE_FAILURE, ": ").concat(e_3), e_3);
|
|
164
|
-
return [3 /*break*/,
|
|
165
|
-
case
|
|
182
|
+
return [3 /*break*/, 10];
|
|
183
|
+
case 10: return [2 /*return*/, undefined];
|
|
166
184
|
}
|
|
167
185
|
});
|
|
168
186
|
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events-idb-store.js","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":";;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wBAEtD,QAAQ,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAI,IAAI,CAAE,CAAC;wBAC/C,MAAM,GAAG,UAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,uCAA6B,QAAQ,CAAE,CAAC;wBAC3E,qBAAM,IAAA,mBAAW,EAAC,MAAM,CAAC,EAAA;;wBAA9B,EAAE,GAAG,SAAyB;wBACpC,sBAAO,IAAI,2BAA2B,uCACjC,IAAI,KACP,EAAE,IAAA,IACF,EAAC;;;wBAEH,IAAA,4BAAW,EAAC,IAAI,CAAC,cAAc,EAAE,UAAG,0BAAe,eAAK,GAAW,CAAE,EAAE,GAAC,CAAC,CAAC;;4BAE5E,sBAAO;;;;KACR;IAEK,8DAAwB,GAA9B,UAA+B,SAAkB;;;;;;;6BAC3C,SAAS,EAAT,wBAAS;wBACI,qBAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,wBAAwB,EAAE,SAAS,CAAC,EAAA;;wBAA/D,MAAM,GAAG,SAAsD;wBACrE,IAAI,CAAC,MAAM,EAAE;4BACX,sBAAO,SAAS,EAAC;yBAClB;wBACD,sBAAO,CAAC,MAAM,CAAC,EAAC;;wBAGZ,SAAS,GAAG,EAAE,CAAC;;;;wBACA,qBAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,wBAAwB,CAAC,EAAA;;wBAA9C,KAAA,gCAAA,SAA8C,EAAA;;;;wBAAxD,MAAM;wBACf,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;;;;6BAGzB,sBAAO,SAAS,EAAC;;;;KAClB;IAmHH,kCAAC;AAAD,CAAC,AAzJD,CAAiD,mCAAe,GAyJ/D;AAzJY,kEAA2B","sourcesContent":["import { DBSchema, IDBPDatabase, openDB } from 'idb';\nimport { STORAGE_FAILURE } from '../messages';\nimport { EventType, Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore, InstanceArgs as BaseInstanceArgs } from './base-events-store';\nimport { logIdbError } from '../utils/is-abort-error';\n\nexport const currentSequenceKey = 'sessionCurrentSequence';\nexport const sequencesToSendKey = 'sequencesToSend';\nexport const remoteConfigKey = 'remoteConfig';\n\nexport interface SessionReplayDB extends DBSchema {\n sessionCurrentSequence: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n };\n sequencesToSend: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n indexes: { sessionId: string | number };\n };\n}\n\nexport const defineObjectStores = (db: IDBPDatabase<SessionReplayDB>) => {\n let sequencesStore;\n let currentSequenceStore;\n if (!db.objectStoreNames.contains(currentSequenceKey)) {\n currentSequenceStore = db.createObjectStore(currentSequenceKey, {\n keyPath: 'sessionId',\n });\n }\n if (!db.objectStoreNames.contains(sequencesToSendKey)) {\n sequencesStore = db.createObjectStore(sequencesToSendKey, {\n keyPath: 'sequenceId',\n autoIncrement: true,\n });\n sequencesStore.createIndex('sessionId', 'sessionId');\n }\n return {\n sequencesStore,\n currentSequenceStore,\n };\n};\n\nexport const createStore = async (dbName: string) => {\n return await openDB<SessionReplayDB>(dbName, 1, {\n upgrade: defineObjectStores,\n });\n};\n\ntype InstanceArgs = {\n apiKey: string;\n db: IDBPDatabase<SessionReplayDB>;\n} & BaseInstanceArgs;\n\nexport class SessionReplayEventsIDBStore extends BaseEventsStore<number> {\n private readonly db: IDBPDatabase<SessionReplayDB>;\n\n constructor(args: InstanceArgs) {\n super(args);\n this.db = args.db;\n }\n\n static async new(type: EventType, args: Omit<InstanceArgs, 'db'>): Promise<SessionReplayEventsIDBStore | undefined> {\n try {\n const dbSuffix = type === 'replay' ? '' : `_${type}`;\n const dbName = `${args.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`;\n const db = await createStore(dbName);\n return new SessionReplayEventsIDBStore({\n ...args,\n db,\n });\n } catch (e) {\n logIdbError(args.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return;\n }\n\n async getCurrentSequenceEvents(sessionId?: number) {\n if (sessionId) {\n const events = await this.db.get('sessionCurrentSequence', sessionId);\n if (!events) {\n return undefined;\n }\n return [events];\n }\n\n const allEvents = [];\n for (const events of await this.db.getAll('sessionCurrentSequence')) {\n allEvents.push(events);\n }\n\n return allEvents;\n }\n\n getSequencesToSend = async (): Promise<SendingSequencesReturn<number>[] | undefined> => {\n try {\n const sequences: SendingSequencesReturn<number>[] = [];\n let cursor = await this.db.transaction('sequencesToSend').store.openCursor();\n while (cursor) {\n const { sessionId, events } = cursor.value;\n sequences.push({\n events,\n sequenceId: cursor.key,\n sessionId,\n });\n cursor = await cursor.continue();\n }\n\n return sequences;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeCurrentSequence = async (sessionId: number) => {\n try {\n const currentSequenceData = await this.db.get<'sessionCurrentSequence'>(currentSequenceKey, sessionId);\n if (!currentSequenceData) {\n return undefined;\n }\n\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: currentSequenceData.events,\n });\n\n await this.db.put<'sessionCurrentSequence'>(currentSequenceKey, {\n sessionId,\n events: [],\n });\n\n return {\n ...currentSequenceData,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n addEventToCurrentSequence = async (sessionId: number, event: string) => {\n try {\n const tx = this.db.transaction<'sessionCurrentSequence', 'readwrite'>(currentSequenceKey, 'readwrite');\n const sequenceEvents = await tx.store.get(sessionId);\n if (!sequenceEvents) {\n await tx.store.put({ sessionId, events: [event] });\n return;\n }\n let eventsToSend;\n if (this.shouldSplitEventsList(sequenceEvents.events, event)) {\n eventsToSend = sequenceEvents.events;\n // set store to empty array\n await tx.store.put({ sessionId, events: [event] });\n } else {\n // add event to array\n const updatedEvents = sequenceEvents.events.concat(event);\n await tx.store.put({ sessionId, events: updatedEvents });\n }\n\n await tx.done;\n if (!eventsToSend) {\n return undefined;\n }\n\n const sequenceId = await this.storeSendingEvents(sessionId, eventsToSend);\n\n if (!sequenceId) {\n return undefined;\n }\n\n return {\n events: eventsToSend,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeSendingEvents = async (sessionId: number, events: Events) => {\n try {\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: events,\n });\n return sequenceId;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n cleanUpSessionEventsStore = async (_sessionId: number, sequenceId?: number) => {\n if (!sequenceId) {\n return;\n }\n try {\n await this.db.delete<'sequencesToSend'>(sequencesToSendKey, sequenceId);\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"events-idb-store.js","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":";;;;AAAA,2BAAqD;AACrD,wCAA8C;AAE9C,yDAAwF;AACxF,0DAAsD;AAEzC,QAAA,kBAAkB,GAAG,wBAAwB,CAAC;AAC9C,QAAA,kBAAkB,GAAG,iBAAiB,CAAC;AACvC,QAAA,eAAe,GAAG,cAAc,CAAC;AAcvC,IAAM,kBAAkB,GAAG,UAAC,EAAiC;IAClE,IAAI,cAAc,CAAC;IACnB,IAAI,oBAAoB,CAAC;IACzB,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,0BAAkB,CAAC,EAAE;QACrD,oBAAoB,GAAG,EAAE,CAAC,iBAAiB,CAAC,0BAAkB,EAAE;YAC9D,OAAO,EAAE,WAAW;SACrB,CAAC,CAAC;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;;;;6BAGzB,sBAAO,SAAS,EAAC;;;;KAClB;IA0IH,kCAAC;AAAD,CAAC,AAhLD,CAAiD,mCAAe,GAgL/D;AAhLY,kEAA2B","sourcesContent":["import { DBSchema, IDBPDatabase, openDB } from 'idb';\nimport { STORAGE_FAILURE } from '../messages';\nimport { EventType, Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore, InstanceArgs as BaseInstanceArgs } from './base-events-store';\nimport { logIdbError } from '../utils/is-abort-error';\n\nexport const currentSequenceKey = 'sessionCurrentSequence';\nexport const sequencesToSendKey = 'sequencesToSend';\nexport const remoteConfigKey = 'remoteConfig';\n\nexport interface SessionReplayDB extends DBSchema {\n sessionCurrentSequence: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n };\n sequencesToSend: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n indexes: { sessionId: string | number };\n };\n}\n\nexport const defineObjectStores = (db: IDBPDatabase<SessionReplayDB>) => {\n let sequencesStore;\n let currentSequenceStore;\n if (!db.objectStoreNames.contains(currentSequenceKey)) {\n currentSequenceStore = db.createObjectStore(currentSequenceKey, {\n keyPath: 'sessionId',\n });\n }\n if (!db.objectStoreNames.contains(sequencesToSendKey)) {\n sequencesStore = db.createObjectStore(sequencesToSendKey, {\n keyPath: 'sequenceId',\n autoIncrement: true,\n });\n sequencesStore.createIndex('sessionId', 'sessionId');\n }\n return {\n sequencesStore,\n currentSequenceStore,\n };\n};\n\nexport const createStore = async (dbName: string) => {\n return await openDB<SessionReplayDB>(dbName, 1, {\n upgrade: defineObjectStores,\n });\n};\n\ntype InstanceArgs = {\n apiKey: string;\n db: IDBPDatabase<SessionReplayDB>;\n} & BaseInstanceArgs;\n\nexport class SessionReplayEventsIDBStore extends BaseEventsStore<number> {\n private readonly db: IDBPDatabase<SessionReplayDB>;\n\n constructor(args: InstanceArgs) {\n super(args);\n this.db = args.db;\n }\n\n static async new(type: EventType, args: Omit<InstanceArgs, 'db'>): Promise<SessionReplayEventsIDBStore | undefined> {\n try {\n const dbSuffix = type === 'replay' ? '' : `_${type}`;\n const dbName = `${args.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`;\n const db = await createStore(dbName);\n return new SessionReplayEventsIDBStore({\n ...args,\n db,\n });\n } catch (e) {\n logIdbError(args.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return;\n }\n\n async getCurrentSequenceEvents(sessionId?: number) {\n if (sessionId) {\n const events = await this.db.get('sessionCurrentSequence', sessionId);\n if (!events) {\n return undefined;\n }\n return [events];\n }\n\n const allEvents = [];\n for (const events of await this.db.getAll('sessionCurrentSequence')) {\n allEvents.push(events);\n }\n\n return allEvents;\n }\n\n getSequencesToSend = async (): Promise<SendingSequencesReturn<number>[] | undefined> => {\n let errorLogged = false;\n try {\n const sequences: SendingSequencesReturn<number>[] = [];\n const tx = this.db.transaction('sequencesToSend');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // cursor traversal completes) are always handled without blocking the return path.\n // The errorLogged flag prevents double-logging when the outer catch already fired\n // for the same abort (e.g. cursor.continue() threw mid-traversal).\n tx.done.catch((e: unknown) => {\n if (!errorLogged) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n });\n let cursor = await tx.store.openCursor();\n while (cursor) {\n const { sessionId, events } = cursor.value;\n sequences.push({\n events,\n sequenceId: cursor.key,\n sessionId,\n });\n cursor = await cursor.continue();\n }\n\n return sequences;\n } catch (e) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeCurrentSequence = async (sessionId: number) => {\n try {\n const currentSequenceData = await this.db.get<'sessionCurrentSequence'>(currentSequenceKey, sessionId);\n if (!currentSequenceData) {\n return undefined;\n }\n\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: currentSequenceData.events,\n });\n\n await this.db.put<'sessionCurrentSequence'>(currentSequenceKey, {\n sessionId,\n events: [],\n });\n\n return {\n ...currentSequenceData,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n addEventToCurrentSequence = async (sessionId: number, event: string) => {\n let errorLogged = false;\n try {\n // Always open a readwrite transaction over both stores so that the read and\n // any subsequent write are atomic. IDB serializes readwrite transactions on\n // overlapping stores, so concurrent fire-and-forget callers (events-manager\n // does not await this method) are queued by the engine rather than interleaving\n // — eliminating the TOCTOU race that a narrow-read + separate-write approach\n // would introduce on the split path.\n const tx = this.db.transaction([currentSequenceKey, sequencesToSendKey], 'readwrite');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // put succeeds but before auto-commit) are always handled without blocking.\n // The errorLogged flag prevents double-logging when the outer catch already fired\n // for the same abort (e.g. a put() threw).\n tx.done.catch((e: unknown) => {\n if (!errorLogged) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n });\n const sequenceEvents = await tx.objectStore(currentSequenceKey).get(sessionId);\n\n if (!sequenceEvents) {\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event] });\n return undefined;\n }\n\n if (!this.shouldSplitEventsList(sequenceEvents.events, event)) {\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: sequenceEvents.events.concat(event) });\n return undefined;\n }\n\n // Split path: reset sessionCurrentSequence and write the old events to\n // sequencesToSend atomically within the same transaction.\n const eventsToSend = sequenceEvents.events;\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event] });\n const sequenceId = await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: eventsToSend,\n });\n\n return {\n events: eventsToSend,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeSendingEvents = async (sessionId: number, events: Events) => {\n try {\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: events,\n });\n return sequenceId;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n cleanUpSessionEventsStore = async (_sessionId: number, sequenceId?: number) => {\n if (!sequenceId) {\n return;\n }\n try {\n await this.db.delete<'sequencesToSend'>(sequencesToSendKey, sequenceId);\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n };\n}\n"]}
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.36.
|
|
1
|
+
export declare const VERSION = "1.36.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.36.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.36.2';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events-idb-store.d.ts","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAU,MAAM,KAAK,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAA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,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAe7G,wBAAwB,CAAC,SAAS,CAAC,EAAE,MAAM;IAiBjD,kBAAkB,QAAa,QAAQ,uBAAuB,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,CA+BlF;IAEF,oBAAoB,cAAqB,MAAM;;;;mBA0B7C;IAEF,yBAAyB,cAAqB,MAAM,SAAS,MAAM;;;;mBAkDjE;IAEF,kBAAkB,cAAqB,MAAM,iDAW3C;IAEF,yBAAyB,eAAsB,MAAM,eAAe,MAAM,mBASxE;CACH"}
|
|
@@ -41,18 +41,32 @@ var SessionReplayEventsIDBStore = /** @class */ (function (_super) {
|
|
|
41
41
|
function SessionReplayEventsIDBStore(args) {
|
|
42
42
|
var _this = _super.call(this, args) || this;
|
|
43
43
|
_this.getSequencesToSend = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
44
|
-
var sequences, cursor, _a, sessionId, events, e_1;
|
|
44
|
+
var errorLogged, sequences, tx, cursor, _a, sessionId, events, e_1;
|
|
45
|
+
var _this = this;
|
|
45
46
|
return __generator(this, function (_b) {
|
|
46
47
|
switch (_b.label) {
|
|
47
48
|
case 0:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return [4 /*yield*/, this.db.transaction('sequencesToSend').store.openCursor()];
|
|
49
|
+
errorLogged = false;
|
|
50
|
+
_b.label = 1;
|
|
51
51
|
case 1:
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
_b.trys.push([1, 6, , 7]);
|
|
53
|
+
sequences = [];
|
|
54
|
+
tx = this.db.transaction('sequencesToSend');
|
|
55
|
+
// Attach a catch handler immediately so tx.done rejections (e.g. AbortError after
|
|
56
|
+
// cursor traversal completes) are always handled without blocking the return path.
|
|
57
|
+
// The errorLogged flag prevents double-logging when the outer catch already fired
|
|
58
|
+
// for the same abort (e.g. cursor.continue() threw mid-traversal).
|
|
59
|
+
tx.done.catch(function (e) {
|
|
60
|
+
if (!errorLogged) {
|
|
61
|
+
logIdbError(_this.loggerProvider, "".concat(STORAGE_FAILURE, ": ").concat(e), e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return [4 /*yield*/, tx.store.openCursor()];
|
|
54
65
|
case 2:
|
|
55
|
-
|
|
66
|
+
cursor = _b.sent();
|
|
67
|
+
_b.label = 3;
|
|
68
|
+
case 3:
|
|
69
|
+
if (!cursor) return [3 /*break*/, 5];
|
|
56
70
|
_a = cursor.value, sessionId = _a.sessionId, events = _a.events;
|
|
57
71
|
sequences.push({
|
|
58
72
|
events: events,
|
|
@@ -60,15 +74,16 @@ var SessionReplayEventsIDBStore = /** @class */ (function (_super) {
|
|
|
60
74
|
sessionId: sessionId,
|
|
61
75
|
});
|
|
62
76
|
return [4 /*yield*/, cursor.continue()];
|
|
63
|
-
case
|
|
77
|
+
case 4:
|
|
64
78
|
cursor = _b.sent();
|
|
65
|
-
return [3 /*break*/,
|
|
66
|
-
case
|
|
67
|
-
case
|
|
79
|
+
return [3 /*break*/, 3];
|
|
80
|
+
case 5: return [2 /*return*/, sequences];
|
|
81
|
+
case 6:
|
|
68
82
|
e_1 = _b.sent();
|
|
83
|
+
errorLogged = true;
|
|
69
84
|
logIdbError(this.loggerProvider, "".concat(STORAGE_FAILURE, ": ").concat(e_1), e_1);
|
|
70
|
-
return [3 /*break*/,
|
|
71
|
-
case
|
|
85
|
+
return [3 /*break*/, 7];
|
|
86
|
+
case 7: return [2 /*return*/, undefined];
|
|
72
87
|
}
|
|
73
88
|
});
|
|
74
89
|
}); };
|
|
@@ -106,58 +121,61 @@ var SessionReplayEventsIDBStore = /** @class */ (function (_super) {
|
|
|
106
121
|
});
|
|
107
122
|
}); };
|
|
108
123
|
_this.addEventToCurrentSequence = function (sessionId, event) { return __awaiter(_this, void 0, void 0, function () {
|
|
109
|
-
var tx, sequenceEvents, eventsToSend,
|
|
124
|
+
var errorLogged, tx, sequenceEvents, eventsToSend, sequenceId, e_3;
|
|
125
|
+
var _this = this;
|
|
110
126
|
return __generator(this, function (_a) {
|
|
111
127
|
switch (_a.label) {
|
|
112
128
|
case 0:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return [4 /*yield*/, tx.store.get(sessionId)];
|
|
129
|
+
errorLogged = false;
|
|
130
|
+
_a.label = 1;
|
|
116
131
|
case 1:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
_a.trys.push([1, 9, , 10]);
|
|
133
|
+
tx = this.db.transaction([currentSequenceKey, sequencesToSendKey], 'readwrite');
|
|
134
|
+
// Attach a catch handler immediately so tx.done rejections (e.g. AbortError after
|
|
135
|
+
// put succeeds but before auto-commit) are always handled without blocking.
|
|
136
|
+
// The errorLogged flag prevents double-logging when the outer catch already fired
|
|
137
|
+
// for the same abort (e.g. a put() threw).
|
|
138
|
+
tx.done.catch(function (e) {
|
|
139
|
+
if (!errorLogged) {
|
|
140
|
+
logIdbError(_this.loggerProvider, "".concat(STORAGE_FAILURE, ": ").concat(e), e);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return [4 /*yield*/, tx.objectStore(currentSequenceKey).get(sessionId)];
|
|
120
144
|
case 2:
|
|
121
|
-
_a.sent();
|
|
122
|
-
return [
|
|
145
|
+
sequenceEvents = _a.sent();
|
|
146
|
+
if (!!sequenceEvents) return [3 /*break*/, 4];
|
|
147
|
+
return [4 /*yield*/, tx.objectStore(currentSequenceKey).put({ sessionId: sessionId, events: [event] })];
|
|
123
148
|
case 3:
|
|
124
|
-
eventsToSend = void 0;
|
|
125
|
-
if (!this.shouldSplitEventsList(sequenceEvents.events, event)) return [3 /*break*/, 5];
|
|
126
|
-
eventsToSend = sequenceEvents.events;
|
|
127
|
-
// set store to empty array
|
|
128
|
-
return [4 /*yield*/, tx.store.put({ sessionId: sessionId, events: [event] })];
|
|
129
|
-
case 4:
|
|
130
|
-
// set store to empty array
|
|
131
149
|
_a.sent();
|
|
132
|
-
return [
|
|
150
|
+
return [2 /*return*/, undefined];
|
|
151
|
+
case 4:
|
|
152
|
+
if (!!this.shouldSplitEventsList(sequenceEvents.events, event)) return [3 /*break*/, 6];
|
|
153
|
+
return [4 /*yield*/, tx.objectStore(currentSequenceKey).put({ sessionId: sessionId, events: sequenceEvents.events.concat(event) })];
|
|
133
154
|
case 5:
|
|
134
|
-
|
|
135
|
-
return [
|
|
155
|
+
_a.sent();
|
|
156
|
+
return [2 /*return*/, undefined];
|
|
136
157
|
case 6:
|
|
158
|
+
eventsToSend = sequenceEvents.events;
|
|
159
|
+
return [4 /*yield*/, tx.objectStore(currentSequenceKey).put({ sessionId: sessionId, events: [event] })];
|
|
160
|
+
case 7:
|
|
137
161
|
_a.sent();
|
|
138
|
-
|
|
139
|
-
|
|
162
|
+
return [4 /*yield*/, tx.objectStore(sequencesToSendKey).put({
|
|
163
|
+
sessionId: sessionId,
|
|
164
|
+
events: eventsToSend,
|
|
165
|
+
})];
|
|
140
166
|
case 8:
|
|
141
|
-
_a.sent();
|
|
142
|
-
if (!eventsToSend) {
|
|
143
|
-
return [2 /*return*/, undefined];
|
|
144
|
-
}
|
|
145
|
-
return [4 /*yield*/, this.storeSendingEvents(sessionId, eventsToSend)];
|
|
146
|
-
case 9:
|
|
147
167
|
sequenceId = _a.sent();
|
|
148
|
-
if (!sequenceId) {
|
|
149
|
-
return [2 /*return*/, undefined];
|
|
150
|
-
}
|
|
151
168
|
return [2 /*return*/, {
|
|
152
169
|
events: eventsToSend,
|
|
153
170
|
sessionId: sessionId,
|
|
154
171
|
sequenceId: sequenceId,
|
|
155
172
|
}];
|
|
156
|
-
case
|
|
173
|
+
case 9:
|
|
157
174
|
e_3 = _a.sent();
|
|
175
|
+
errorLogged = true;
|
|
158
176
|
logIdbError(this.loggerProvider, "".concat(STORAGE_FAILURE, ": ").concat(e_3), e_3);
|
|
159
|
-
return [3 /*break*/,
|
|
160
|
-
case
|
|
177
|
+
return [3 /*break*/, 10];
|
|
178
|
+
case 10: return [2 /*return*/, undefined];
|
|
161
179
|
}
|
|
162
180
|
});
|
|
163
181
|
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events-idb-store.js","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":";AAAA,OAAO,EAA0B,MAAM,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAoC,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,CAAC,IAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAC3D,MAAM,CAAC,IAAM,kBAAkB,GAAG,iBAAiB,CAAC;AACpD,MAAM,CAAC,IAAM,eAAe,GAAG,cAAc,CAAC;AAc9C,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,EAAiC;IAClE,IAAI,cAAc,CAAC;IACnB,IAAI,oBAAoB,CAAC;IACzB,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE;QACrD,oBAAoB,GAAG,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,EAAE;YAC9D,OAAO,EAAE,WAAW;SACrB,CAAC,CAAC;KACJ;IACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE;QACrD,cAAc,GAAG,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,EAAE;YACxD,OAAO,EAAE,YAAY;YACrB,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,cAAc,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;KACtD;IACD,OAAO;QACL,cAAc,gBAAA;QACd,oBAAoB,sBAAA;KACrB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,WAAW,GAAG,UAAO,MAAc;;;oBACvC,qBAAM,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MAAM,CAAC,CAAC;;;;;;;;;;;;;;;;6BAGzB,sBAAO,SAAS,EAAC;;;;KAClB;IAmHH,kCAAC;AAAD,CAAC,AAzJD,CAAiD,eAAe,GAyJ/D","sourcesContent":["import { DBSchema, IDBPDatabase, openDB } from 'idb';\nimport { STORAGE_FAILURE } from '../messages';\nimport { EventType, Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore, InstanceArgs as BaseInstanceArgs } from './base-events-store';\nimport { logIdbError } from '../utils/is-abort-error';\n\nexport const currentSequenceKey = 'sessionCurrentSequence';\nexport const sequencesToSendKey = 'sequencesToSend';\nexport const remoteConfigKey = 'remoteConfig';\n\nexport interface SessionReplayDB extends DBSchema {\n sessionCurrentSequence: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n };\n sequencesToSend: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n indexes: { sessionId: string | number };\n };\n}\n\nexport const defineObjectStores = (db: IDBPDatabase<SessionReplayDB>) => {\n let sequencesStore;\n let currentSequenceStore;\n if (!db.objectStoreNames.contains(currentSequenceKey)) {\n currentSequenceStore = db.createObjectStore(currentSequenceKey, {\n keyPath: 'sessionId',\n });\n }\n if (!db.objectStoreNames.contains(sequencesToSendKey)) {\n sequencesStore = db.createObjectStore(sequencesToSendKey, {\n keyPath: 'sequenceId',\n autoIncrement: true,\n });\n sequencesStore.createIndex('sessionId', 'sessionId');\n }\n return {\n sequencesStore,\n currentSequenceStore,\n };\n};\n\nexport const createStore = async (dbName: string) => {\n return await openDB<SessionReplayDB>(dbName, 1, {\n upgrade: defineObjectStores,\n });\n};\n\ntype InstanceArgs = {\n apiKey: string;\n db: IDBPDatabase<SessionReplayDB>;\n} & BaseInstanceArgs;\n\nexport class SessionReplayEventsIDBStore extends BaseEventsStore<number> {\n private readonly db: IDBPDatabase<SessionReplayDB>;\n\n constructor(args: InstanceArgs) {\n super(args);\n this.db = args.db;\n }\n\n static async new(type: EventType, args: Omit<InstanceArgs, 'db'>): Promise<SessionReplayEventsIDBStore | undefined> {\n try {\n const dbSuffix = type === 'replay' ? '' : `_${type}`;\n const dbName = `${args.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`;\n const db = await createStore(dbName);\n return new SessionReplayEventsIDBStore({\n ...args,\n db,\n });\n } catch (e) {\n logIdbError(args.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return;\n }\n\n async getCurrentSequenceEvents(sessionId?: number) {\n if (sessionId) {\n const events = await this.db.get('sessionCurrentSequence', sessionId);\n if (!events) {\n return undefined;\n }\n return [events];\n }\n\n const allEvents = [];\n for (const events of await this.db.getAll('sessionCurrentSequence')) {\n allEvents.push(events);\n }\n\n return allEvents;\n }\n\n getSequencesToSend = async (): Promise<SendingSequencesReturn<number>[] | undefined> => {\n try {\n const sequences: SendingSequencesReturn<number>[] = [];\n let cursor = await this.db.transaction('sequencesToSend').store.openCursor();\n while (cursor) {\n const { sessionId, events } = cursor.value;\n sequences.push({\n events,\n sequenceId: cursor.key,\n sessionId,\n });\n cursor = await cursor.continue();\n }\n\n return sequences;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeCurrentSequence = async (sessionId: number) => {\n try {\n const currentSequenceData = await this.db.get<'sessionCurrentSequence'>(currentSequenceKey, sessionId);\n if (!currentSequenceData) {\n return undefined;\n }\n\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: currentSequenceData.events,\n });\n\n await this.db.put<'sessionCurrentSequence'>(currentSequenceKey, {\n sessionId,\n events: [],\n });\n\n return {\n ...currentSequenceData,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n addEventToCurrentSequence = async (sessionId: number, event: string) => {\n try {\n const tx = this.db.transaction<'sessionCurrentSequence', 'readwrite'>(currentSequenceKey, 'readwrite');\n const sequenceEvents = await tx.store.get(sessionId);\n if (!sequenceEvents) {\n await tx.store.put({ sessionId, events: [event] });\n return;\n }\n let eventsToSend;\n if (this.shouldSplitEventsList(sequenceEvents.events, event)) {\n eventsToSend = sequenceEvents.events;\n // set store to empty array\n await tx.store.put({ sessionId, events: [event] });\n } else {\n // add event to array\n const updatedEvents = sequenceEvents.events.concat(event);\n await tx.store.put({ sessionId, events: updatedEvents });\n }\n\n await tx.done;\n if (!eventsToSend) {\n return undefined;\n }\n\n const sequenceId = await this.storeSendingEvents(sessionId, eventsToSend);\n\n if (!sequenceId) {\n return undefined;\n }\n\n return {\n events: eventsToSend,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeSendingEvents = async (sessionId: number, events: Events) => {\n try {\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: events,\n });\n return sequenceId;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n cleanUpSessionEventsStore = async (_sessionId: number, sequenceId?: number) => {\n if (!sequenceId) {\n return;\n }\n try {\n await this.db.delete<'sequencesToSend'>(sequencesToSendKey, sequenceId);\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"events-idb-store.js","sourceRoot":"","sources":["../../../src/events/events-idb-store.ts"],"names":[],"mappings":";AAAA,OAAO,EAA0B,MAAM,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAoC,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,CAAC,IA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AAE;4BACX,sBAAO,SAAS,EAAC;yBAClB;wBACD,sBAAO,CAAC,MAAM,CAAC,EAAC;;wBAGZ,SAAS,GAAG,EAAE,CAAC;;;;wBACA,qBAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,wBAAwB,CAAC,EAAA;;wBAA9C,KAAA,wBAAA,SAA8C,EAAA;;;;wBAAxD,MAAM;wBACf,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;;;;6BAGzB,sBAAO,SAAS,EAAC;;;;KAClB;IA0IH,kCAAC;AAAD,CAAC,AAhLD,CAAiD,eAAe,GAgL/D","sourcesContent":["import { DBSchema, IDBPDatabase, openDB } from 'idb';\nimport { STORAGE_FAILURE } from '../messages';\nimport { EventType, Events, SendingSequencesReturn } from '../typings/session-replay';\nimport { BaseEventsStore, InstanceArgs as BaseInstanceArgs } from './base-events-store';\nimport { logIdbError } from '../utils/is-abort-error';\n\nexport const currentSequenceKey = 'sessionCurrentSequence';\nexport const sequencesToSendKey = 'sequencesToSend';\nexport const remoteConfigKey = 'remoteConfig';\n\nexport interface SessionReplayDB extends DBSchema {\n sessionCurrentSequence: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n };\n sequencesToSend: {\n key: number;\n value: Omit<SendingSequencesReturn<number>, 'sequenceId'>;\n indexes: { sessionId: string | number };\n };\n}\n\nexport const defineObjectStores = (db: IDBPDatabase<SessionReplayDB>) => {\n let sequencesStore;\n let currentSequenceStore;\n if (!db.objectStoreNames.contains(currentSequenceKey)) {\n currentSequenceStore = db.createObjectStore(currentSequenceKey, {\n keyPath: 'sessionId',\n });\n }\n if (!db.objectStoreNames.contains(sequencesToSendKey)) {\n sequencesStore = db.createObjectStore(sequencesToSendKey, {\n keyPath: 'sequenceId',\n autoIncrement: true,\n });\n sequencesStore.createIndex('sessionId', 'sessionId');\n }\n return {\n sequencesStore,\n currentSequenceStore,\n };\n};\n\nexport const createStore = async (dbName: string) => {\n return await openDB<SessionReplayDB>(dbName, 1, {\n upgrade: defineObjectStores,\n });\n};\n\ntype InstanceArgs = {\n apiKey: string;\n db: IDBPDatabase<SessionReplayDB>;\n} & BaseInstanceArgs;\n\nexport class SessionReplayEventsIDBStore extends BaseEventsStore<number> {\n private readonly db: IDBPDatabase<SessionReplayDB>;\n\n constructor(args: InstanceArgs) {\n super(args);\n this.db = args.db;\n }\n\n static async new(type: EventType, args: Omit<InstanceArgs, 'db'>): Promise<SessionReplayEventsIDBStore | undefined> {\n try {\n const dbSuffix = type === 'replay' ? '' : `_${type}`;\n const dbName = `${args.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`;\n const db = await createStore(dbName);\n return new SessionReplayEventsIDBStore({\n ...args,\n db,\n });\n } catch (e) {\n logIdbError(args.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return;\n }\n\n async getCurrentSequenceEvents(sessionId?: number) {\n if (sessionId) {\n const events = await this.db.get('sessionCurrentSequence', sessionId);\n if (!events) {\n return undefined;\n }\n return [events];\n }\n\n const allEvents = [];\n for (const events of await this.db.getAll('sessionCurrentSequence')) {\n allEvents.push(events);\n }\n\n return allEvents;\n }\n\n getSequencesToSend = async (): Promise<SendingSequencesReturn<number>[] | undefined> => {\n let errorLogged = false;\n try {\n const sequences: SendingSequencesReturn<number>[] = [];\n const tx = this.db.transaction('sequencesToSend');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // cursor traversal completes) are always handled without blocking the return path.\n // The errorLogged flag prevents double-logging when the outer catch already fired\n // for the same abort (e.g. cursor.continue() threw mid-traversal).\n tx.done.catch((e: unknown) => {\n if (!errorLogged) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n });\n let cursor = await tx.store.openCursor();\n while (cursor) {\n const { sessionId, events } = cursor.value;\n sequences.push({\n events,\n sequenceId: cursor.key,\n sessionId,\n });\n cursor = await cursor.continue();\n }\n\n return sequences;\n } catch (e) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeCurrentSequence = async (sessionId: number) => {\n try {\n const currentSequenceData = await this.db.get<'sessionCurrentSequence'>(currentSequenceKey, sessionId);\n if (!currentSequenceData) {\n return undefined;\n }\n\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: currentSequenceData.events,\n });\n\n await this.db.put<'sessionCurrentSequence'>(currentSequenceKey, {\n sessionId,\n events: [],\n });\n\n return {\n ...currentSequenceData,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n addEventToCurrentSequence = async (sessionId: number, event: string) => {\n let errorLogged = false;\n try {\n // Always open a readwrite transaction over both stores so that the read and\n // any subsequent write are atomic. IDB serializes readwrite transactions on\n // overlapping stores, so concurrent fire-and-forget callers (events-manager\n // does not await this method) are queued by the engine rather than interleaving\n // — eliminating the TOCTOU race that a narrow-read + separate-write approach\n // would introduce on the split path.\n const tx = this.db.transaction([currentSequenceKey, sequencesToSendKey], 'readwrite');\n // Attach a catch handler immediately so tx.done rejections (e.g. AbortError after\n // put succeeds but before auto-commit) are always handled without blocking.\n // The errorLogged flag prevents double-logging when the outer catch already fired\n // for the same abort (e.g. a put() threw).\n tx.done.catch((e: unknown) => {\n if (!errorLogged) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n });\n const sequenceEvents = await tx.objectStore(currentSequenceKey).get(sessionId);\n\n if (!sequenceEvents) {\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event] });\n return undefined;\n }\n\n if (!this.shouldSplitEventsList(sequenceEvents.events, event)) {\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: sequenceEvents.events.concat(event) });\n return undefined;\n }\n\n // Split path: reset sessionCurrentSequence and write the old events to\n // sequencesToSend atomically within the same transaction.\n const eventsToSend = sequenceEvents.events;\n await tx.objectStore(currentSequenceKey).put({ sessionId, events: [event] });\n const sequenceId = await tx.objectStore(sequencesToSendKey).put({\n sessionId,\n events: eventsToSend,\n });\n\n return {\n events: eventsToSend,\n sessionId,\n sequenceId,\n };\n } catch (e) {\n errorLogged = true;\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n storeSendingEvents = async (sessionId: number, events: Events) => {\n try {\n const sequenceId = await this.db.put<'sequencesToSend'>(sequencesToSendKey, {\n sessionId: sessionId,\n events: events,\n });\n return sequenceId;\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n return undefined;\n };\n\n cleanUpSessionEventsStore = async (_sessionId: number, sequenceId?: number) => {\n if (!sequenceId) {\n return;\n }\n try {\n await this.db.delete<'sequencesToSend'>(sequencesToSendKey, sequenceId);\n } catch (e) {\n logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e);\n }\n };\n}\n"]}
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.36.
|
|
1
|
+
export declare const VERSION = "1.36.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.js
CHANGED
package/lib/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.36.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// Autogenerated by `pnpm version-file`. DO NOT EDIT\nexport const VERSION = '1.36.2';\n"]}
|