@amplitude/analytics-core 2.9.0 → 2.10.0
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/core-client.d.ts +36 -4
- package/lib/cjs/core-client.d.ts.map +1 -1
- package/lib/cjs/core-client.js +89 -2
- package/lib/cjs/core-client.js.map +1 -1
- package/lib/cjs/identify.d.ts +4 -0
- package/lib/cjs/identify.d.ts.map +1 -1
- package/lib/cjs/identify.js +16 -1
- package/lib/cjs/identify.js.map +1 -1
- package/lib/cjs/timeline.d.ts +4 -1
- package/lib/cjs/timeline.d.ts.map +1 -1
- package/lib/cjs/timeline.js +30 -0
- package/lib/cjs/timeline.js.map +1 -1
- package/lib/cjs/types/event/event.d.ts +33 -0
- package/lib/cjs/types/event/event.d.ts.map +1 -1
- package/lib/cjs/types/event/event.js.map +1 -1
- package/lib/cjs/types/plugin.d.ts +22 -0
- package/lib/cjs/types/plugin.d.ts.map +1 -1
- package/lib/cjs/types/plugin.js.map +1 -1
- package/lib/esm/core-client.d.ts +36 -4
- package/lib/esm/core-client.d.ts.map +1 -1
- package/lib/esm/core-client.js +89 -2
- package/lib/esm/core-client.js.map +1 -1
- package/lib/esm/identify.d.ts +4 -0
- package/lib/esm/identify.d.ts.map +1 -1
- package/lib/esm/identify.js +15 -0
- package/lib/esm/identify.js.map +1 -1
- package/lib/esm/timeline.d.ts +4 -1
- package/lib/esm/timeline.d.ts.map +1 -1
- package/lib/esm/timeline.js +30 -0
- package/lib/esm/timeline.js.map +1 -1
- package/lib/esm/types/event/event.d.ts +33 -0
- package/lib/esm/types/event/event.d.ts.map +1 -1
- package/lib/esm/types/event/event.js.map +1 -1
- package/lib/esm/types/plugin.d.ts +22 -0
- package/lib/esm/types/plugin.d.ts.map +1 -1
- package/lib/esm/types/plugin.js.map +1 -1
- package/package.json +2 -2
package/lib/cjs/core-client.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import { Plugin } from './types/plugin';
|
|
|
2
2
|
import { IConfig } from './config';
|
|
3
3
|
import { BaseEvent, EventOptions } from './types/event/base-event';
|
|
4
4
|
import { Result } from './types/result';
|
|
5
|
-
import { Event } from './types/event/event';
|
|
5
|
+
import { Event, UserProperties } from './types/event/event';
|
|
6
6
|
import { IIdentify } from './identify';
|
|
7
7
|
import { IRevenue } from './revenue';
|
|
8
8
|
import { Timeline } from './timeline';
|
|
9
|
-
import { returnWrapper } from './utils/return-wrapper';
|
|
10
|
-
|
|
9
|
+
import { AmplitudeReturn, returnWrapper } from './utils/return-wrapper';
|
|
10
|
+
interface PluginHost {
|
|
11
|
+
plugin(name: string): Plugin | undefined;
|
|
12
|
+
}
|
|
11
13
|
export interface CoreClient {
|
|
12
14
|
/**
|
|
13
15
|
* Adds a new plugin.
|
|
@@ -141,7 +143,7 @@ export interface CoreClient {
|
|
|
141
143
|
*/
|
|
142
144
|
flush(): AmplitudeReturn<void>;
|
|
143
145
|
}
|
|
144
|
-
export declare class AmplitudeCore implements CoreClient {
|
|
146
|
+
export declare class AmplitudeCore implements CoreClient, PluginHost {
|
|
145
147
|
protected initializing: boolean;
|
|
146
148
|
protected name: string;
|
|
147
149
|
config: IConfig;
|
|
@@ -164,9 +166,39 @@ export declare class AmplitudeCore implements CoreClient {
|
|
|
164
166
|
_removePlugin(pluginName: string): AmplitudeReturn<void>;
|
|
165
167
|
dispatchWithCallback(event: Event, callback: (result: Result) => void): void;
|
|
166
168
|
dispatch(event: Event): Promise<Result>;
|
|
169
|
+
/**
|
|
170
|
+
*
|
|
171
|
+
* This method applies identify operations to user properties and
|
|
172
|
+
* returns a single object representing the final user property state.
|
|
173
|
+
*
|
|
174
|
+
* This is a best-effort api that only supports $set, $clearAll, and $unset.
|
|
175
|
+
* Other operations are not supported and are ignored.
|
|
176
|
+
*
|
|
177
|
+
*
|
|
178
|
+
* @param userProperties The `event.userProperties` object from an Identify event.
|
|
179
|
+
* @returns A key-value object user properties without operations.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* Input:
|
|
183
|
+
* {
|
|
184
|
+
* $set: { plan: 'premium' },
|
|
185
|
+
* custom_flag: true
|
|
186
|
+
* }
|
|
187
|
+
*
|
|
188
|
+
* Output:
|
|
189
|
+
* {
|
|
190
|
+
* plan: 'premium',
|
|
191
|
+
* custom_flag: true
|
|
192
|
+
* }
|
|
193
|
+
*/
|
|
194
|
+
getOperationAppliedUserProperties(userProperties: UserProperties | undefined): {
|
|
195
|
+
[key: string]: any;
|
|
196
|
+
};
|
|
167
197
|
process(event: Event): Promise<Result>;
|
|
168
198
|
setOptOut(optOut: boolean): void;
|
|
169
199
|
_setOptOut(optOut: boolean): void;
|
|
170
200
|
flush(): AmplitudeReturn<void>;
|
|
201
|
+
plugin(name: string): Plugin | undefined;
|
|
171
202
|
}
|
|
203
|
+
export {};
|
|
172
204
|
//# sourceMappingURL=core-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"core-client.d.ts","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,KAAK,EAIL,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,O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CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,YAAY;IAK/G,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,YAAY;IAKrF,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;IAKtD,GAAG,CAAC,MAAM,EAAE,MAAM;IAQlB,UAAU,CAAC,MAAM,EAAE,MAAM;IAIzB,MAAM,CAAC,UAAU,EAAE,MAAM;IAQzB,aAAa,CAAC,UAAU,EAAE,MAAM;IAIhC,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAOtE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAU7C;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,iCAAiC,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAsD/F,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IA8B5C,SAAS,CAAC,MAAM,EAAE,OAAO;IAQzB,UAAU,CAAC,MAAM,EAAE,OAAO;IAO1B,KAAK;IAIL,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CASzC"}
|
package/lib/cjs/core-client.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AmplitudeCore = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var event_1 = require("./types/event/event");
|
|
6
|
+
var identify_1 = require("./identify");
|
|
5
7
|
var messages_1 = require("./types/messages");
|
|
6
8
|
var timeline_1 = require("./timeline");
|
|
7
9
|
var event_builder_1 = require("./utils/event-builder");
|
|
@@ -145,9 +147,79 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
145
147
|
});
|
|
146
148
|
});
|
|
147
149
|
};
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
* This method applies identify operations to user properties and
|
|
153
|
+
* returns a single object representing the final user property state.
|
|
154
|
+
*
|
|
155
|
+
* This is a best-effort api that only supports $set, $clearAll, and $unset.
|
|
156
|
+
* Other operations are not supported and are ignored.
|
|
157
|
+
*
|
|
158
|
+
*
|
|
159
|
+
* @param userProperties The `event.userProperties` object from an Identify event.
|
|
160
|
+
* @returns A key-value object user properties without operations.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* Input:
|
|
164
|
+
* {
|
|
165
|
+
* $set: { plan: 'premium' },
|
|
166
|
+
* custom_flag: true
|
|
167
|
+
* }
|
|
168
|
+
*
|
|
169
|
+
* Output:
|
|
170
|
+
* {
|
|
171
|
+
* plan: 'premium',
|
|
172
|
+
* custom_flag: true
|
|
173
|
+
* }
|
|
174
|
+
*/
|
|
175
|
+
AmplitudeCore.prototype.getOperationAppliedUserProperties = function (userProperties) {
|
|
176
|
+
var updatedProperties = {};
|
|
177
|
+
if (userProperties === undefined) {
|
|
178
|
+
return updatedProperties;
|
|
179
|
+
}
|
|
180
|
+
// Keep non-operation keys for later merge
|
|
181
|
+
var nonOpProperties = {};
|
|
182
|
+
Object.keys(userProperties).forEach(function (key) {
|
|
183
|
+
if (!Object.values(event_1.IdentifyOperation).includes(key)) {
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
185
|
+
// @ts-ignore
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
187
|
+
nonOpProperties[key] = userProperties[key];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
identify_1.OrderedIdentifyOperations.forEach(function (operation) {
|
|
191
|
+
// Skip when key is an operation.
|
|
192
|
+
if (!Object.keys(userProperties).includes(operation))
|
|
193
|
+
return;
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
195
|
+
var opProperties = userProperties[operation];
|
|
196
|
+
switch (operation) {
|
|
197
|
+
case event_1.IdentifyOperation.CLEAR_ALL:
|
|
198
|
+
// Due to operation order, the following line will never execute.
|
|
199
|
+
/* istanbul ignore next */
|
|
200
|
+
Object.keys(updatedProperties).forEach(function (prop) {
|
|
201
|
+
delete updatedProperties[prop];
|
|
202
|
+
});
|
|
203
|
+
break;
|
|
204
|
+
case event_1.IdentifyOperation.UNSET:
|
|
205
|
+
Object.keys(opProperties).forEach(function (prop) {
|
|
206
|
+
delete updatedProperties[prop];
|
|
207
|
+
});
|
|
208
|
+
break;
|
|
209
|
+
case event_1.IdentifyOperation.SET:
|
|
210
|
+
Object.assign(updatedProperties, opProperties);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
// Merge non-operation properties.
|
|
215
|
+
// Custom properties should not be affected by operations.
|
|
216
|
+
// https://github.com/amplitude/nova/blob/343f678ded83c032e83b189796b3c2be161b48f5/src/main/java/com/amplitude/userproperty/model/ModifyUserPropertiesIdent.java#L79-L83
|
|
217
|
+
Object.assign(updatedProperties, nonOpProperties);
|
|
218
|
+
return updatedProperties;
|
|
219
|
+
};
|
|
148
220
|
AmplitudeCore.prototype.process = function (event) {
|
|
149
221
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var result, e_2, message, result;
|
|
222
|
+
var userProperties, result, e_2, message, result;
|
|
151
223
|
return tslib_1.__generator(this, function (_a) {
|
|
152
224
|
switch (_a.label) {
|
|
153
225
|
case 0:
|
|
@@ -156,6 +228,10 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
156
228
|
if (this.config.optOut) {
|
|
157
229
|
return [2 /*return*/, (0, result_builder_1.buildResult)(event, 0, messages_1.OPT_OUT_MESSAGE)];
|
|
158
230
|
}
|
|
231
|
+
if (event.event_type === event_1.SpecialEventType.IDENTIFY) {
|
|
232
|
+
userProperties = this.getOperationAppliedUserProperties(event.user_properties);
|
|
233
|
+
this.timeline.onIdentityChanged({ userProperties: userProperties });
|
|
234
|
+
}
|
|
159
235
|
return [4 /*yield*/, this.timeline.push(event)];
|
|
160
236
|
case 1:
|
|
161
237
|
result = _a.sent();
|
|
@@ -184,11 +260,22 @@ var AmplitudeCore = /** @class */ (function () {
|
|
|
184
260
|
this._setOptOut(optOut);
|
|
185
261
|
};
|
|
186
262
|
AmplitudeCore.prototype._setOptOut = function (optOut) {
|
|
187
|
-
this.config.optOut
|
|
263
|
+
if (this.config.optOut !== optOut) {
|
|
264
|
+
this.timeline.onOptOutChanged(optOut);
|
|
265
|
+
this.config.optOut = Boolean(optOut);
|
|
266
|
+
}
|
|
188
267
|
};
|
|
189
268
|
AmplitudeCore.prototype.flush = function () {
|
|
190
269
|
return (0, return_wrapper_1.returnWrapper)(this.timeline.flush());
|
|
191
270
|
};
|
|
271
|
+
AmplitudeCore.prototype.plugin = function (name) {
|
|
272
|
+
var plugin = this.timeline.plugins.find(function (plugin) { return plugin.name === name; });
|
|
273
|
+
if (plugin === undefined) {
|
|
274
|
+
this.config.loggerProvider.debug("Cannot find plugin with name ".concat(name));
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
return plugin;
|
|
278
|
+
};
|
|
192
279
|
return AmplitudeCore;
|
|
193
280
|
}());
|
|
194
281
|
exports.AmplitudeCore = AmplitudeCore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;;AAOA,6CAA2E;AAC3E,uCAAsC;AACtC,uDAM+B;AAC/B,yDAAqD;AACrD,yDAAuD;AA+JvD;IAaE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAZnB,iBAAY,GA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,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACzD,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,kCAAU,GAAV,UAAW,MAAe;QACxB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAA,8BAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;IACH,oBAAC;AAAD,CAAC,AAzJD,IAyJC;AAzJY,sCAAa","sourcesContent":["import { Plugin } from './types/plugin';\nimport { IConfig } from './config';\nimport { BaseEvent, EventOptions } from './types/event/base-event';\nimport { Result } from './types/result';\nimport { Event } from './types/event/event';\nimport { IIdentify } from './identify';\nimport { IRevenue } from './revenue';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './types/messages';\nimport { Timeline } from './timeline';\nimport {\n createGroupEvent,\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createRevenueEvent,\n createTrackEvent,\n} from './utils/event-builder';\nimport { buildResult } from './utils/result-builder';\nimport { returnWrapper } from './utils/return-wrapper';\nimport { AmplitudeReturn } from './utils/return-wrapper';\n\nexport interface CoreClient {\n /**\n * Adds a new plugin.\n *\n * ```typescript\n * const plugin = {\n * name: 'myPlugin',\n * type: 'enrichment',\n * setup(config: Config) {\n * return;\n * },\n * execute(context: Event) {\n * return context;\n * },\n * };\n * amplitude.add(plugin);\n * ```\n */\n add(plugin: Plugin): AmplitudeReturn<void>;\n\n /**\n * Removes a plugin.\n *\n * ```typescript\n * amplitude.remove('myPlugin');\n * ```\n */\n remove(pluginName: string): AmplitudeReturn<void>;\n\n /**\n * Tracks user-defined event, with specified type, optional event properties and optional overwrites.\n *\n * ```typescript\n * // event tracking with event type only\n * track('Page Load');\n *\n * // event tracking with event type and additional event properties\n * track('Page Load', { loadTime: 1000 });\n *\n * // event tracking with event type, additional event properties, and overwritten event options\n * track('Page Load', { loadTime: 1000 }, { sessionId: -1 });\n *\n * // alternatively, this tracking method is awaitable\n * const result = await track('Page Load').promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n track(\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n ): AmplitudeReturn<Result>;\n\n /**\n * Alias for track()\n */\n logEvent(\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n ): AmplitudeReturn<Result>;\n\n /**\n * Sends an identify event containing user property operations\n *\n * ```typescript\n * const id = new Identify();\n * id.set('colors', ['rose', 'gold']);\n * identify(id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await identify(id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n identify(identify: IIdentify, eventOptions?: EventOptions): AmplitudeReturn<Result>;\n\n /**\n * Sends a group identify event containing group property operations.\n *\n * ```typescript\n * const id = new Identify();\n * id.set('skills', ['js', 'ts']);\n * const groupType = 'org';\n * const groupName = 'engineering';\n * groupIdentify(groupType, groupName, id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await groupIdentify(groupType, groupName, id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n groupIdentify(\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n ): AmplitudeReturn<Result>;\n\n /**\n * Assigns a user to group\n *\n * ```typescript\n * const groupType = 'orgId';\n * const groupName = '15';\n * setGroup(groupType, groupName, { user_id: '12345' })\n * ```\n */\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): AmplitudeReturn<Result>;\n\n /**\n * Sends a revenue event containing revenue property operations.\n *\n * ```typescript\n * const rev = new Revenue();\n * rev.setRevenue(100);\n * revenue(rev);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await revenue(rev).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n revenue(revenue: IRevenue, eventOptions?: EventOptions): AmplitudeReturn<Result>;\n\n /**\n * Sets a new optOut config value. This toggles event tracking on/off.\n *\n *```typescript\n * // Stops tracking\n * setOptOut(true);\n *\n * // Starts/resumes tracking\n * setOptOut(false);\n * ```\n */\n setOptOut(optOut: boolean): void;\n\n /**\n * Flush all unsent events.\n *\n *```typescript\n * flush();\n * ```\n */\n flush(): AmplitudeReturn<void>;\n}\n\nexport class AmplitudeCore implements CoreClient {\n protected initializing = false;\n protected name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: IConfig;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n isReady = false;\n protected q: Array<CallableFunction | typeof returnWrapper> = [];\n protected dispatchQ: Array<CallableFunction> = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline(this);\n this.name = name;\n }\n\n protected async _init(config: IConfig) {\n this.config = config;\n this.timeline.reset(this);\n await this.runQueuedFunctions('q');\n this.isReady = true;\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const val: ReturnType<typeof returnWrapper> | Promise<any> = queuedFunction();\n if (val && 'promise' in val) {\n await val.promise;\n } else {\n await val;\n }\n }\n // Rerun queued functions if the queue has accrued more while awaiting promises\n if (this[queueName].length) {\n await this.runQueuedFunctions(queueName);\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n add(plugin: Plugin) {\n if (!this.isReady) {\n this.q.push(this._addPlugin.bind(this, plugin));\n return returnWrapper();\n }\n return this._addPlugin(plugin);\n }\n\n _addPlugin(plugin: Plugin) {\n return returnWrapper(this.timeline.register(plugin, this.config));\n }\n\n remove(pluginName: string) {\n if (!this.isReady) {\n this.q.push(this._removePlugin.bind(this, pluginName));\n return returnWrapper();\n }\n return this._removePlugin(pluginName);\n }\n\n _removePlugin(pluginName: string) {\n return returnWrapper(this.timeline.deregister(pluginName, this.config));\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.isReady) {\n return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));\n }\n void this.process(event).then(callback);\n }\n\n async dispatch(event: Event): Promise<Result> {\n if (!this.isReady) {\n return new Promise<Result>((resolve) => {\n this.dispatchQ.push(this.dispatchWithCallback.bind(this, event, resolve));\n });\n }\n\n return this.process(event);\n }\n\n async process(event: Event): Promise<Result> {\n try {\n // skip event processing if opt out\n if (this.config.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n\n const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(result.message)\n : result.code === 100\n ? this.config.loggerProvider.warn(result.message)\n : this.config.loggerProvider.error(result.message);\n\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n const result = buildResult(event, 0, message);\n\n return result;\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.isReady) {\n this.q.push(this._setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this._setOptOut(optOut);\n }\n\n _setOptOut(optOut: boolean) {\n this.config.optOut = Boolean(optOut);\n }\n\n flush() {\n return returnWrapper(this.timeline.flush());\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"core-client.js","sourceRoot":"","sources":["../../src/core-client.ts"],"names":[],"mappings":";;;;AAIA,6CAM6B;AAC7B,uCAAkE;AAElE,6CAA2E;AAC3E,uCAAsC;AACtC,uDAM+B;AAC/B,yDAAqD;AACrD,yDAAwE;AAkKxE;IAaE,uBAAY,IAAiB;QAAjB,qBAAA,EAAA,iBAAiB;QAZnB,iBAAY,GAAG,KAAK,CAAC;QAQ/B,YAAO,GAAG,KAAK,CAAC;QACN,MAAC,GAAmD,EAAE,CAAC;QACvD,cAAS,GAA4B,EAAE,CAAC;QAuClD,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QApC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEe,6BAAK,GAArB,UAAsB,MAAe;;;;;wBACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;wBACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;wBAC1B,qBAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAA;;wBAAlC,SAAkC,CAAC;wBACnC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;;;;;KACrB;IAE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,CAAC,CAAC,CAAC,CAAC;YACzD,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,kCAAU,GAAV,UAAW,MAAe;QACxB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE;YACjC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SACtC;IACH,CAAC;IAED,6BAAK,GAAL;QACE,OAAO,IAAA,8BAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,8BAAM,GAAN,UAAO,IAAY;QACjB,IAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,KAAK,IAAI,EAApB,CAAoB,CAAC,CAAC;QAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,uCAAgC,IAAI,CAAE,CAAC,CAAC;YACzE,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,oBAAC;AAAD,CAAC,AA1PD,IA0PC;AA1PY,sCAAa","sourcesContent":["import { Plugin } from './types/plugin';\nimport { IConfig } from './config';\nimport { BaseEvent, EventOptions } from './types/event/base-event';\nimport { Result } from './types/result';\nimport {\n Event,\n IdentifyOperation,\n IdentifyUserProperties,\n SpecialEventType,\n UserProperties,\n} from './types/event/event';\nimport { IIdentify, OrderedIdentifyOperations } from './identify';\nimport { IRevenue } from './revenue';\nimport { CLIENT_NOT_INITIALIZED, OPT_OUT_MESSAGE } from './types/messages';\nimport { Timeline } from './timeline';\nimport {\n createGroupEvent,\n createGroupIdentifyEvent,\n createIdentifyEvent,\n createRevenueEvent,\n createTrackEvent,\n} from './utils/event-builder';\nimport { buildResult } from './utils/result-builder';\nimport { AmplitudeReturn, returnWrapper } from './utils/return-wrapper';\n\ninterface PluginHost {\n plugin(name: string): Plugin | undefined;\n}\n\nexport interface CoreClient {\n /**\n * Adds a new plugin.\n *\n * ```typescript\n * const plugin = {\n * name: 'myPlugin',\n * type: 'enrichment',\n * setup(config: Config) {\n * return;\n * },\n * execute(context: Event) {\n * return context;\n * },\n * };\n * amplitude.add(plugin);\n * ```\n */\n add(plugin: Plugin): AmplitudeReturn<void>;\n\n /**\n * Removes a plugin.\n *\n * ```typescript\n * amplitude.remove('myPlugin');\n * ```\n */\n remove(pluginName: string): AmplitudeReturn<void>;\n\n /**\n * Tracks user-defined event, with specified type, optional event properties and optional overwrites.\n *\n * ```typescript\n * // event tracking with event type only\n * track('Page Load');\n *\n * // event tracking with event type and additional event properties\n * track('Page Load', { loadTime: 1000 });\n *\n * // event tracking with event type, additional event properties, and overwritten event options\n * track('Page Load', { loadTime: 1000 }, { sessionId: -1 });\n *\n * // alternatively, this tracking method is awaitable\n * const result = await track('Page Load').promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n track(\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n ): AmplitudeReturn<Result>;\n\n /**\n * Alias for track()\n */\n logEvent(\n eventInput: BaseEvent | string,\n eventProperties?: Record<string, any>,\n eventOptions?: EventOptions,\n ): AmplitudeReturn<Result>;\n\n /**\n * Sends an identify event containing user property operations\n *\n * ```typescript\n * const id = new Identify();\n * id.set('colors', ['rose', 'gold']);\n * identify(id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await identify(id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n identify(identify: IIdentify, eventOptions?: EventOptions): AmplitudeReturn<Result>;\n\n /**\n * Sends a group identify event containing group property operations.\n *\n * ```typescript\n * const id = new Identify();\n * id.set('skills', ['js', 'ts']);\n * const groupType = 'org';\n * const groupName = 'engineering';\n * groupIdentify(groupType, groupName, id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await groupIdentify(groupType, groupName, id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n groupIdentify(\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n ): AmplitudeReturn<Result>;\n\n /**\n * Assigns a user to group\n *\n * ```typescript\n * const groupType = 'orgId';\n * const groupName = '15';\n * setGroup(groupType, groupName, { user_id: '12345' })\n * ```\n */\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions): AmplitudeReturn<Result>;\n\n /**\n * Sends a revenue event containing revenue property operations.\n *\n * ```typescript\n * const rev = new Revenue();\n * rev.setRevenue(100);\n * revenue(rev);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await revenue(rev).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\n revenue(revenue: IRevenue, eventOptions?: EventOptions): AmplitudeReturn<Result>;\n\n /**\n * Sets a new optOut config value. This toggles event tracking on/off.\n *\n *```typescript\n * // Stops tracking\n * setOptOut(true);\n *\n * // Starts/resumes tracking\n * setOptOut(false);\n * ```\n */\n setOptOut(optOut: boolean): void;\n\n /**\n * Flush all unsent events.\n *\n *```typescript\n * flush();\n * ```\n */\n flush(): AmplitudeReturn<void>;\n}\n\nexport class AmplitudeCore implements CoreClient, PluginHost {\n protected initializing = false;\n protected name: string;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: IConfig;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n timeline: Timeline;\n isReady = false;\n protected q: Array<CallableFunction | typeof returnWrapper> = [];\n protected dispatchQ: Array<CallableFunction> = [];\n\n constructor(name = '$default') {\n this.timeline = new Timeline(this);\n this.name = name;\n }\n\n protected async _init(config: IConfig) {\n this.config = config;\n this.timeline.reset(this);\n await this.runQueuedFunctions('q');\n this.isReady = true;\n }\n\n async runQueuedFunctions(queueName: 'q' | 'dispatchQ') {\n const queuedFunctions = this[queueName];\n this[queueName] = [];\n for (const queuedFunction of queuedFunctions) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const val: ReturnType<typeof returnWrapper> | Promise<any> = queuedFunction();\n if (val && 'promise' in val) {\n await val.promise;\n } else {\n await val;\n }\n }\n // Rerun queued functions if the queue has accrued more while awaiting promises\n if (this[queueName].length) {\n await this.runQueuedFunctions(queueName);\n }\n }\n\n track(eventInput: BaseEvent | string, eventProperties?: Record<string, any>, eventOptions?: EventOptions) {\n const event = createTrackEvent(eventInput, eventProperties, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n logEvent = this.track.bind(this);\n\n identify(identify: IIdentify, eventOptions?: EventOptions) {\n const event = createIdentifyEvent(identify, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions) {\n const event = createGroupIdentifyEvent(groupType, groupName, identify, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n setGroup(groupType: string, groupName: string | string[], eventOptions?: EventOptions) {\n const event = createGroupEvent(groupType, groupName, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n const event = createRevenueEvent(revenue, eventOptions);\n return returnWrapper(this.dispatch(event));\n }\n\n add(plugin: Plugin) {\n if (!this.isReady) {\n this.q.push(this._addPlugin.bind(this, plugin));\n return returnWrapper();\n }\n return this._addPlugin(plugin);\n }\n\n _addPlugin(plugin: Plugin) {\n return returnWrapper(this.timeline.register(plugin, this.config));\n }\n\n remove(pluginName: string) {\n if (!this.isReady) {\n this.q.push(this._removePlugin.bind(this, pluginName));\n return returnWrapper();\n }\n return this._removePlugin(pluginName);\n }\n\n _removePlugin(pluginName: string) {\n return returnWrapper(this.timeline.deregister(pluginName, this.config));\n }\n\n dispatchWithCallback(event: Event, callback: (result: Result) => void): void {\n if (!this.isReady) {\n return callback(buildResult(event, 0, CLIENT_NOT_INITIALIZED));\n }\n void this.process(event).then(callback);\n }\n\n async dispatch(event: Event): Promise<Result> {\n if (!this.isReady) {\n return new Promise<Result>((resolve) => {\n this.dispatchQ.push(this.dispatchWithCallback.bind(this, event, resolve));\n });\n }\n\n return this.process(event);\n }\n\n /**\n *\n * This method applies identify operations to user properties and\n * returns a single object representing the final user property state.\n *\n * This is a best-effort api that only supports $set, $clearAll, and $unset.\n * Other operations are not supported and are ignored.\n *\n *\n * @param userProperties The `event.userProperties` object from an Identify event.\n * @returns A key-value object user properties without operations.\n *\n * @example\n * Input:\n * {\n * $set: { plan: 'premium' },\n * custom_flag: true\n * }\n *\n * Output:\n * {\n * plan: 'premium',\n * custom_flag: true\n * }\n */\n getOperationAppliedUserProperties(userProperties: UserProperties | undefined): { [key: string]: any } {\n const updatedProperties: { [key: string]: any } = {};\n\n if (userProperties === undefined) {\n return updatedProperties;\n }\n\n // Keep non-operation keys for later merge\n const nonOpProperties: {\n [key in Exclude<string, IdentifyOperation>]: any;\n } = {};\n Object.keys(userProperties).forEach((key) => {\n if (!Object.values(IdentifyOperation).includes(key as IdentifyOperation)) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n nonOpProperties[key] = userProperties[key];\n }\n });\n\n OrderedIdentifyOperations.forEach((operation) => {\n // Skip when key is an operation.\n if (!Object.keys(userProperties).includes(operation)) return;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const opProperties: IdentifyUserProperties = userProperties[operation];\n\n switch (operation) {\n case IdentifyOperation.CLEAR_ALL:\n // Due to operation order, the following line will never execute.\n /* istanbul ignore next */\n Object.keys(updatedProperties).forEach((prop) => {\n delete updatedProperties[prop];\n });\n break;\n case IdentifyOperation.UNSET:\n Object.keys(opProperties).forEach((prop) => {\n delete updatedProperties[prop];\n });\n break;\n case IdentifyOperation.SET:\n Object.assign(updatedProperties, opProperties);\n break;\n }\n });\n\n // Merge non-operation properties.\n // Custom properties should not be affected by operations.\n // https://github.com/amplitude/nova/blob/343f678ded83c032e83b189796b3c2be161b48f5/src/main/java/com/amplitude/userproperty/model/ModifyUserPropertiesIdent.java#L79-L83\n Object.assign(updatedProperties, nonOpProperties);\n\n return updatedProperties;\n }\n\n async process(event: Event): Promise<Result> {\n try {\n // skip event processing if opt out\n if (this.config.optOut) {\n return buildResult(event, 0, OPT_OUT_MESSAGE);\n }\n\n if (event.event_type === SpecialEventType.IDENTIFY) {\n const userProperties = this.getOperationAppliedUserProperties(event.user_properties);\n this.timeline.onIdentityChanged({ userProperties: userProperties });\n }\n\n const result = await this.timeline.push(event);\n\n result.code === 200\n ? this.config.loggerProvider.log(result.message)\n : result.code === 100\n ? this.config.loggerProvider.warn(result.message)\n : this.config.loggerProvider.error(result.message);\n\n return result;\n } catch (e) {\n const message = String(e);\n this.config.loggerProvider.error(message);\n const result = buildResult(event, 0, message);\n\n return result;\n }\n }\n\n setOptOut(optOut: boolean) {\n if (!this.isReady) {\n this.q.push(this._setOptOut.bind(this, Boolean(optOut)));\n return;\n }\n this._setOptOut(optOut);\n }\n\n _setOptOut(optOut: boolean) {\n if (this.config.optOut !== optOut) {\n this.timeline.onOptOutChanged(optOut);\n this.config.optOut = Boolean(optOut);\n }\n }\n\n flush() {\n return returnWrapper(this.timeline.flush());\n }\n\n plugin(name: string): Plugin | undefined {\n const plugin = this.timeline.plugins.find((plugin) => plugin.name === name);\n if (plugin === undefined) {\n this.config.loggerProvider.debug(`Cannot find plugin with name ${name}`);\n return undefined;\n }\n\n return plugin;\n }\n}\n"]}
|
package/lib/cjs/identify.d.ts
CHANGED
|
@@ -62,5 +62,9 @@ export declare enum IdentifyOperation {
|
|
|
62
62
|
UNSET = "$unset",
|
|
63
63
|
CLEAR_ALL = "$clearAll"
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Note that the order of operations should align with https://github.com/amplitude/nova/blob/7701b5986b565d4b2fb53b99a9f2175df055dea8/src/main/java/com/amplitude/ingestion/core/UserPropertyUtils.java#L210
|
|
67
|
+
*/
|
|
68
|
+
export declare const OrderedIdentifyOperations: IdentifyOperation[];
|
|
65
69
|
export {};
|
|
66
70
|
//# sourceMappingURL=identify.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify.d.ts","sourceRoot":"","sources":["../../src/identify.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,iBAAiB,IAAI,sBAAsB,CAAC;IAC5C,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC3D,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC/D,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC9D,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC/D,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAClE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACjE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC9D,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,KAAK,CAAC,QAAQ,EAAE,MAAM,GA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CAAC,CAAC,EAAE,mBAAmB,CAAC;IAClD,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,EAAE,mBAAmB,CAAC;IACrD,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,EAAE,mBAAmB,CAAC;IACpD,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB,CAAC;CAClD;AAED,oBAAY,iBAAiB;IAE3B,GAAG,SAAS;IACZ,QAAQ,aAAa;IAGrB,GAAG,SAAS;IACZ,MAAM,YAAY;IAClB,OAAO,aAAa;IACpB,MAAM,YAAY;IAGlB,SAAS,eAAe;IACxB,UAAU,gBAAgB;IAG1B,KAAK,WAAW;IAChB,SAAS,cAAc;CACxB;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,qBAWrC,CAAC"}
|
package/lib/cjs/identify.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IdentifyOperation = exports.Identify = void 0;
|
|
3
|
+
exports.OrderedIdentifyOperations = exports.IdentifyOperation = exports.Identify = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var constants_1 = require("./types/constants");
|
|
6
6
|
var valid_properties_1 = require("./utils/valid-properties");
|
|
@@ -108,4 +108,19 @@ var IdentifyOperation;
|
|
|
108
108
|
IdentifyOperation["UNSET"] = "$unset";
|
|
109
109
|
IdentifyOperation["CLEAR_ALL"] = "$clearAll";
|
|
110
110
|
})(IdentifyOperation = exports.IdentifyOperation || (exports.IdentifyOperation = {}));
|
|
111
|
+
/**
|
|
112
|
+
* Note that the order of operations should align with https://github.com/amplitude/nova/blob/7701b5986b565d4b2fb53b99a9f2175df055dea8/src/main/java/com/amplitude/ingestion/core/UserPropertyUtils.java#L210
|
|
113
|
+
*/
|
|
114
|
+
exports.OrderedIdentifyOperations = [
|
|
115
|
+
IdentifyOperation.CLEAR_ALL,
|
|
116
|
+
IdentifyOperation.UNSET,
|
|
117
|
+
IdentifyOperation.SET,
|
|
118
|
+
IdentifyOperation.SET_ONCE,
|
|
119
|
+
IdentifyOperation.ADD,
|
|
120
|
+
IdentifyOperation.APPEND,
|
|
121
|
+
IdentifyOperation.PREPEND,
|
|
122
|
+
IdentifyOperation.PREINSERT,
|
|
123
|
+
IdentifyOperation.POSTINSERT,
|
|
124
|
+
IdentifyOperation.REMOVE,
|
|
125
|
+
];
|
|
111
126
|
//# sourceMappingURL=identify.js.map
|
package/lib/cjs/identify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../src/identify.ts"],"names":[],"mappings":";;;;AAAA,+CAAgD;AAChD,6DAA6D;AAgB7D;IAAA;QACqB,iBAAY,GAAgB,IAAI,GAAG,EAAU,CAAC;QACvD,gBAAW,GAA2B,EAAE,CAAC;IAmGrD,CAAC;IAjGQ,oCAAiB,GAAxB;QACE,4BAAY,IAAI,CAAC,WAAW,EAAG;IACjC,CAAC;IAEM,sBAAG,GAAV,UAAW,QAAgB,EAAE,KAAwB;QACnD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,0BAAO,GAAd,UAAe,QAAgB,EAAE,KAAwB;QACvD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,yBAAM,GAAb,UAAc,QAAgB,EAAE,KAAwB;QACtD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,0BAAO,GAAd,UAAe,QAAgB,EAAE,KAAwB;QACvD,IAAI,CAAC,QAAQ,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8C;IAC9C,iCAAY,CAAA;IACZ,uCAAkB,CAAA;IAClB,yCAAoB,CAAA;IACpB,uCAAkB,CAAA;IAElB,8DAA8D;IAC9D,6CAAwB,CAAA;IACxB,+CAA0B,CAAA;IAE1B,+CAA+C;IAC/C,qCAAgB,CAAA;IAChB,4CAAuB,CAAA;AACzB,CAAC,EAlBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAkB5B","sourcesContent":["import { UNSET_VALUE } from './types/constants';\nimport { isValidProperties } from './utils/valid-properties';\n\nexport interface IIdentify {\n getUserProperties(): IdentifyUserProperties;\n set(property: string, value: ValidPropertyType): IIdentify;\n setOnce(property: string, value: ValidPropertyType): IIdentify;\n append(property: string, value: ValidPropertyType): IIdentify;\n prepend(property: string, value: ValidPropertyType): IIdentify;\n postInsert(property: string, value: ValidPropertyType): IIdentify;\n preInsert(property: string, value: ValidPropertyType): IIdentify;\n remove(property: string, value: ValidPropertyType): IIdentify;\n add(property: string, value: number): IIdentify;\n unset(property: string): IIdentify;\n clearAll(): IIdentify;\n}\n\nexport class Identify implements IIdentify {\n protected readonly _propertySet: Set<string> = new Set<string>();\n protected _properties: IdentifyUserProperties = {};\n\n public getUserProperties(): IdentifyUserProperties {\n return { ...this._properties };\n }\n\n public set(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.SET, property, value);\n return this;\n }\n\n public setOnce(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.SET_ONCE, property, value);\n return this;\n }\n\n public append(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.APPEND, property, value);\n return this;\n }\n\n public prepend(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.PREPEND, property, value);\n return this;\n }\n\n public postInsert(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.POSTINSERT, property, value);\n return this;\n }\n\n public preInsert(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.PREINSERT, property, value);\n return this;\n }\n\n public remove(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.REMOVE, property, value);\n return this;\n }\n\n public add(property: string, value: number): Identify {\n this._safeSet(IdentifyOperation.ADD, property, value);\n return this;\n }\n\n public unset(property: string): Identify {\n this._safeSet(IdentifyOperation.UNSET, property, UNSET_VALUE);\n return this;\n }\n\n public clearAll(): Identify {\n // When clear all happens, all properties are unset. Reset the entire object.\n this._properties = {};\n this._properties[IdentifyOperation.CLEAR_ALL] = UNSET_VALUE;\n\n return this;\n }\n\n // Returns whether or not this set actually worked.\n private _safeSet(operation: IdentifyOperation, property: string, value: ValidPropertyType): boolean {\n if (this._validate(operation, property, value)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n let userPropertyMap: any = this._properties[operation];\n if (userPropertyMap === undefined) {\n userPropertyMap = {};\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this._properties[operation] = userPropertyMap;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n userPropertyMap[property] = value;\n this._propertySet.add(property);\n return true;\n }\n\n return false;\n }\n\n private _validate(operation: IdentifyOperation, property: string, value: ValidPropertyType): boolean {\n if (this._properties[IdentifyOperation.CLEAR_ALL] !== undefined) {\n // clear all already set. Skipping operation;\n return false;\n }\n\n if (this._propertySet.has(property)) {\n // Property already used. Skipping operation\n return false;\n }\n\n if (operation === IdentifyOperation.ADD) {\n return typeof value === 'number';\n }\n\n if (operation !== IdentifyOperation.UNSET && operation !== IdentifyOperation.REMOVE) {\n return isValidProperties(property, value);\n }\n return true;\n }\n}\n\nexport type ValidPropertyType =\n | number\n | string\n | boolean\n | Array<string | number>\n | { [key: string]: ValidPropertyType }\n | Array<{ [key: string]: ValidPropertyType }>;\n\ninterface BaseOperationConfig {\n [key: string]: ValidPropertyType;\n}\n\nexport interface IdentifyUserProperties {\n // Add operations can only take numbers\n [IdentifyOperation.ADD]?: { [key: string]: number };\n\n // This reads the keys of the passed object, but the values are not used\n [IdentifyOperation.UNSET]?: BaseOperationConfig;\n // This option does not read the key as it unsets all user properties\n [IdentifyOperation.CLEAR_ALL]?: any;\n\n // These operations can take numbers, strings, or arrays of both.\n [IdentifyOperation.SET]?: BaseOperationConfig;\n [IdentifyOperation.SET_ONCE]?: BaseOperationConfig;\n [IdentifyOperation.APPEND]?: BaseOperationConfig;\n [IdentifyOperation.PREPEND]?: BaseOperationConfig;\n [IdentifyOperation.POSTINSERT]?: BaseOperationConfig;\n [IdentifyOperation.PREINSERT]?: BaseOperationConfig;\n [IdentifyOperation.REMOVE]?: BaseOperationConfig;\n}\n\nexport enum IdentifyOperation {\n // Base Operations to set values\n SET = '$set',\n SET_ONCE = '$setOnce',\n\n // Operations around modifying existing values\n ADD = '$add',\n APPEND = '$append',\n PREPEND = '$prepend',\n REMOVE = '$remove',\n\n // Operations around appending values *if* they aren't present\n PREINSERT = '$preInsert',\n POSTINSERT = '$postInsert',\n\n // Operations around removing properties/values\n UNSET = '$unset',\n CLEAR_ALL = '$clearAll',\n}\n"]}
|
|
1
|
+
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../src/identify.ts"],"names":[],"mappings":";;;;AAAA,+CAAgD;AAChD,6DAA6D;AAgB7D;IAAA;QACqB,iBAAY,GAAgB,IAAI,GAAG,EAAU,CAAC;QACvD,gBAAW,GAA2B,EAAE,CAAC;IAmGrD,CAAC;IAjGQ,oCAAiB,GAAxB;QACE,4BAAY,IAAI,CAAC,WAAW,EAAG;IACjC,CAAC;IAEM,sBAAG,GAAV,UAAW,QAAgB,EAAE,KAAwB;QACnD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,0BAAO,GAAd,UAAe,QAAgB,EAAE,KAAwB;QACvD,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,CAA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,MAAM,EAAE;YACnF,OAAO,IAAA,oCAAiB,EAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;SAC3C;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACH,eAAC;AAAD,CAAC,AArGD,IAqGC;AArGY,4BAAQ;AAsIrB,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B,gCAAgC;IAChC,iCAAY,CAAA;IACZ,0CAAqB,CAAA;IAErB,8CAA8C;IAC9C,iCAAY,CAAA;IACZ,uCAAkB,CAAA;IAClB,yCAAoB,CAAA;IACpB,uCAAkB,CAAA;IAElB,8DAA8D;IAC9D,6CAAwB,CAAA;IACxB,+CAA0B,CAAA;IAE1B,+CAA+C;IAC/C,qCAAgB,CAAA;IAChB,4CAAuB,CAAA;AACzB,CAAC,EAlBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAkB5B;AAED;;GAEG;AACU,QAAA,yBAAyB,GAAG;IACvC,iBAAiB,CAAC,SAAS;IAC3B,iBAAiB,CAAC,KAAK;IACvB,iBAAiB,CAAC,GAAG;IACrB,iBAAiB,CAAC,QAAQ;IAC1B,iBAAiB,CAAC,GAAG;IACrB,iBAAiB,CAAC,MAAM;IACxB,iBAAiB,CAAC,OAAO;IACzB,iBAAiB,CAAC,SAAS;IAC3B,iBAAiB,CAAC,UAAU;IAC5B,iBAAiB,CAAC,MAAM;CACzB,CAAC","sourcesContent":["import { UNSET_VALUE } from './types/constants';\nimport { isValidProperties } from './utils/valid-properties';\n\nexport interface IIdentify {\n getUserProperties(): IdentifyUserProperties;\n set(property: string, value: ValidPropertyType): IIdentify;\n setOnce(property: string, value: ValidPropertyType): IIdentify;\n append(property: string, value: ValidPropertyType): IIdentify;\n prepend(property: string, value: ValidPropertyType): IIdentify;\n postInsert(property: string, value: ValidPropertyType): IIdentify;\n preInsert(property: string, value: ValidPropertyType): IIdentify;\n remove(property: string, value: ValidPropertyType): IIdentify;\n add(property: string, value: number): IIdentify;\n unset(property: string): IIdentify;\n clearAll(): IIdentify;\n}\n\nexport class Identify implements IIdentify {\n protected readonly _propertySet: Set<string> = new Set<string>();\n protected _properties: IdentifyUserProperties = {};\n\n public getUserProperties(): IdentifyUserProperties {\n return { ...this._properties };\n }\n\n public set(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.SET, property, value);\n return this;\n }\n\n public setOnce(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.SET_ONCE, property, value);\n return this;\n }\n\n public append(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.APPEND, property, value);\n return this;\n }\n\n public prepend(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.PREPEND, property, value);\n return this;\n }\n\n public postInsert(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.POSTINSERT, property, value);\n return this;\n }\n\n public preInsert(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.PREINSERT, property, value);\n return this;\n }\n\n public remove(property: string, value: ValidPropertyType): Identify {\n this._safeSet(IdentifyOperation.REMOVE, property, value);\n return this;\n }\n\n public add(property: string, value: number): Identify {\n this._safeSet(IdentifyOperation.ADD, property, value);\n return this;\n }\n\n public unset(property: string): Identify {\n this._safeSet(IdentifyOperation.UNSET, property, UNSET_VALUE);\n return this;\n }\n\n public clearAll(): Identify {\n // When clear all happens, all properties are unset. Reset the entire object.\n this._properties = {};\n this._properties[IdentifyOperation.CLEAR_ALL] = UNSET_VALUE;\n\n return this;\n }\n\n // Returns whether or not this set actually worked.\n private _safeSet(operation: IdentifyOperation, property: string, value: ValidPropertyType): boolean {\n if (this._validate(operation, property, value)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n let userPropertyMap: any = this._properties[operation];\n if (userPropertyMap === undefined) {\n userPropertyMap = {};\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this._properties[operation] = userPropertyMap;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n userPropertyMap[property] = value;\n this._propertySet.add(property);\n return true;\n }\n\n return false;\n }\n\n private _validate(operation: IdentifyOperation, property: string, value: ValidPropertyType): boolean {\n if (this._properties[IdentifyOperation.CLEAR_ALL] !== undefined) {\n // clear all already set. Skipping operation;\n return false;\n }\n\n if (this._propertySet.has(property)) {\n // Property already used. Skipping operation\n return false;\n }\n\n if (operation === IdentifyOperation.ADD) {\n return typeof value === 'number';\n }\n\n if (operation !== IdentifyOperation.UNSET && operation !== IdentifyOperation.REMOVE) {\n return isValidProperties(property, value);\n }\n return true;\n }\n}\n\nexport type ValidPropertyType =\n | number\n | string\n | boolean\n | Array<string | number>\n | { [key: string]: ValidPropertyType }\n | Array<{ [key: string]: ValidPropertyType }>;\n\ninterface BaseOperationConfig {\n [key: string]: ValidPropertyType;\n}\n\nexport interface IdentifyUserProperties {\n // Add operations can only take numbers\n [IdentifyOperation.ADD]?: { [key: string]: number };\n\n // This reads the keys of the passed object, but the values are not used\n [IdentifyOperation.UNSET]?: BaseOperationConfig;\n // This option does not read the key as it unsets all user properties\n [IdentifyOperation.CLEAR_ALL]?: any;\n\n // These operations can take numbers, strings, or arrays of both.\n [IdentifyOperation.SET]?: BaseOperationConfig;\n [IdentifyOperation.SET_ONCE]?: BaseOperationConfig;\n [IdentifyOperation.APPEND]?: BaseOperationConfig;\n [IdentifyOperation.PREPEND]?: BaseOperationConfig;\n [IdentifyOperation.POSTINSERT]?: BaseOperationConfig;\n [IdentifyOperation.PREINSERT]?: BaseOperationConfig;\n [IdentifyOperation.REMOVE]?: BaseOperationConfig;\n}\n\nexport enum IdentifyOperation {\n // Base Operations to set values\n SET = '$set',\n SET_ONCE = '$setOnce',\n\n // Operations around modifying existing values\n ADD = '$add',\n APPEND = '$append',\n PREPEND = '$prepend',\n REMOVE = '$remove',\n\n // Operations around appending values *if* they aren't present\n PREINSERT = '$preInsert',\n POSTINSERT = '$postInsert',\n\n // Operations around removing properties/values\n UNSET = '$unset',\n CLEAR_ALL = '$clearAll',\n}\n\n/**\n * Note that the order of operations should align with https://github.com/amplitude/nova/blob/7701b5986b565d4b2fb53b99a9f2175df055dea8/src/main/java/com/amplitude/ingestion/core/UserPropertyUtils.java#L210\n */\nexport const OrderedIdentifyOperations = [\n IdentifyOperation.CLEAR_ALL,\n IdentifyOperation.UNSET,\n IdentifyOperation.SET,\n IdentifyOperation.SET_ONCE,\n IdentifyOperation.ADD,\n IdentifyOperation.APPEND,\n IdentifyOperation.PREPEND,\n IdentifyOperation.PREINSERT,\n IdentifyOperation.POSTINSERT,\n IdentifyOperation.REMOVE,\n];\n"]}
|
package/lib/cjs/timeline.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin } from './types/plugin';
|
|
1
|
+
import { AnalyticsIdentity, Plugin } from './types/plugin';
|
|
2
2
|
import { CoreClient } from './core-client';
|
|
3
3
|
import { IConfig } from './config';
|
|
4
4
|
import { EventCallback } from './types/event-callback';
|
|
@@ -17,5 +17,8 @@ export declare class Timeline {
|
|
|
17
17
|
scheduleApply(timeout: number): void;
|
|
18
18
|
apply(item: [Event, EventCallback] | undefined): Promise<void>;
|
|
19
19
|
flush(): Promise<void>;
|
|
20
|
+
onIdentityChanged(identity: AnalyticsIdentity): void;
|
|
21
|
+
onSessionIdChanged(sessionId: number): void;
|
|
22
|
+
onOptOutChanged(optOut: boolean): void;
|
|
20
23
|
}
|
|
21
24
|
//# sourceMappingURL=timeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,MAAM,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAqD,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,qBAAa,QAAQ;IAQP,OAAO,CAAC,MAAM;IAP1B,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAM;IAErC,QAAQ,UAAS;IAGjB,OAAO,EAAE,MAAM,EAAE,CAAM;gBAEH,MAAM,EAAE,UAAU;IAEhC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAmBxC,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAWpD,KAAK,CAAC,MAAM,EAAE,UAAU;IAQxB,IAAI,CAAC,KAAK,EAAE,KAAK;IAOjB,aAAa,CAAC,OAAO,EAAE,MAAM;IAavB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS;IAgE9C,KAAK;IAiBX,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB;IAU7C,kBAAkB,CAAC,SAAS,EAAE,MAAM;IAUpC,eAAe,CAAC,MAAM,EAAE,OAAO;CAShC"}
|
package/lib/cjs/timeline.js
CHANGED
|
@@ -220,6 +220,36 @@ var Timeline = /** @class */ (function () {
|
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
222
|
};
|
|
223
|
+
Timeline.prototype.onIdentityChanged = function (identity) {
|
|
224
|
+
this.plugins.forEach(function (plugin) {
|
|
225
|
+
var _a;
|
|
226
|
+
// Intentionally to not await plugin.onIdentityChanged() for non-blocking.
|
|
227
|
+
// Ignore optional channing next line for test coverage.
|
|
228
|
+
// If the plugin doesn't implement it, it won't be called.
|
|
229
|
+
/* istanbul ignore next */
|
|
230
|
+
void ((_a = plugin.onIdentityChanged) === null || _a === void 0 ? void 0 : _a.call(plugin, identity));
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
Timeline.prototype.onSessionIdChanged = function (sessionId) {
|
|
234
|
+
this.plugins.forEach(function (plugin) {
|
|
235
|
+
var _a;
|
|
236
|
+
// Intentionally to not await plugin.onSessionIdChanged() for non-blocking.
|
|
237
|
+
// Ignore optional channing next line for test coverage.
|
|
238
|
+
// If the plugin doesn't implement it, it won't be called.
|
|
239
|
+
/* istanbul ignore next */
|
|
240
|
+
void ((_a = plugin.onSessionIdChanged) === null || _a === void 0 ? void 0 : _a.call(plugin, sessionId));
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
Timeline.prototype.onOptOutChanged = function (optOut) {
|
|
244
|
+
this.plugins.forEach(function (plugin) {
|
|
245
|
+
var _a;
|
|
246
|
+
// Intentionally to not await plugin.onOptOutChanged() for non-blocking.
|
|
247
|
+
// Ignore optional channing next line for test coverage.
|
|
248
|
+
// If the plugin doesn't implement it, it won't be called.
|
|
249
|
+
/* istanbul ignore next */
|
|
250
|
+
void ((_a = plugin.onOptOutChanged) === null || _a === void 0 ? void 0 : _a.call(plugin, optOut));
|
|
251
|
+
});
|
|
252
|
+
};
|
|
223
253
|
return Timeline;
|
|
224
254
|
}());
|
|
225
255
|
exports.Timeline = Timeline;
|
package/lib/cjs/timeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";;;;AAMA,yDAAqD;AACrD,qCAAoC;AAEpC;IAQE,kBAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAPtC,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,GAAa,EAAE,CAAC;IAEkB,CAAC;IAEpC,2BAAQ,GAAd,UAAe,M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AM,CACrC,UAAC,MAAc,IAAkC,OAAA,MAAM,CAAC,IAAI,KAAK,aAAa,EAA7B,CAA6B,CAC/E,CAAC;wBAEI,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM;4BACjD,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AApJD,IAoJC;AApJY,4BAAQ","sourcesContent":["import { BeforePlugin, DestinationPlugin, EnrichmentPlugin, Plugin } from './types/plugin';\nimport { CoreClient } from './core-client';\nimport { IConfig } from './config';\nimport { EventCallback } from './types/event-callback';\nimport { Event } from './types/event/event';\nimport { Result } from './types/result';\nimport { buildResult } from './utils/result-builder';\nimport { UUID } from './utils/uuid';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n constructor(private client: CoreClient) {}\n\n async register(plugin: Plugin, config: IConfig) {\n if (this.plugins.some((existingPlugin) => existingPlugin.name === plugin.name)) {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n config.loggerProvider.warn(`Plugin with name ${plugin.name} already exists, skipping registration`);\n return;\n }\n\n if (plugin.name === undefined) {\n plugin.name = UUID();\n config.loggerProvider.warn(`Plugin name is undefined. \n Generating a random UUID for plugin name: ${plugin.name}. \n Set a name for the plugin to prevent it from being added multiple times.`);\n }\n\n plugin.type = plugin.type ?? 'enrichment';\n await plugin.setup?.(config, this.client);\n this.plugins.push(plugin);\n }\n\n async deregister(pluginName: string, config: IConfig) {\n const index = this.plugins.findIndex((plugin) => plugin.name === pluginName);\n if (index === -1) {\n config.loggerProvider.warn(`Plugin with name ${pluginName} does not exist, skipping deregistration`);\n return;\n }\n const plugin = this.plugins[index];\n this.plugins.splice(index, 1);\n await plugin.teardown?.();\n }\n\n reset(client: CoreClient) {\n this.applying = false;\n const plugins = this.plugins;\n plugins.map((plugin) => plugin.teardown?.());\n this.plugins = [];\n this.client = client;\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === 'before',\n );\n\n for (const plugin of before) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === 'enrichment' || plugin.type === undefined,\n );\n\n for (const plugin of enrichment) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n const resolveResult =\n result || buildResult(event, 100, 'Event not tracked, no destination plugins on the instance');\n resolve(resolveResult);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";;;;AAMA,yDAAqD;AACrD,qCAAoC;AAEpC;IAQE,kBAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAPtC,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,GAAa,EAAE,CAAC;IAEkB,CAAC;IAEpC,2BAAQ,GAAd,UAAe,MAAc,EAAE,MAAe;;;;;;wBAC5C,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAC,cAAc,IAAK,OAAA,cAAc,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAnC,CAAmC,CAAC,EAAE;4BAC9E,4EAA4E;4BAC5E,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,2BAAoB,MAAM,CAAC,IAAI,2CAAwC,CAAC,CAAC;4BACpG,sBAAO;yBACR;wBAED,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;4BAC7B,MAAM,CAAC,IAAI,GAAG,IAAA,WAAI,GAAE,CAAC;4BACrB,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,sFACiB,MAAM,CAAC,IAAI,uFACkB,CAAC,CAAC;yBAC5E;wBAED,MAAM,CAAC,IAAI,GAAG,MAAA,MAAM,CAAC,IAAI,mCAAI,YAAY,CAAC;wBAC1C,qBAAM,CAAA,MAAA,MAAM,CAAC,KAAK,uDAAG,MAAM,EA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SAAiB;QAClC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;;YAC1B,2EAA2E;YAC3E,wDAAwD;YACxD,0DAA0D;YAC1D,0BAA0B;YAC1B,KAAK,CAAA,MAAA,MAAM,CAAC,kBAAkB,uDAAG,SAAS,CAAC,CAAA,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,kCAAe,GAAf,UAAgB,MAAe;QAC7B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;;YAC1B,wEAAwE;YACxE,wDAAwD;YACxD,0DAA0D;YAC1D,0BAA0B;YAC1B,KAAK,CAAA,MAAA,MAAM,CAAC,eAAe,uDAAG,MAAM,CAAC,CAAA,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;IACH,eAAC;AAAD,CAAC,AAlLD,IAkLC;AAlLY,4BAAQ","sourcesContent":["import { AnalyticsIdentity, BeforePlugin, DestinationPlugin, EnrichmentPlugin, Plugin } from './types/plugin';\nimport { CoreClient } from './core-client';\nimport { IConfig } from './config';\nimport { EventCallback } from './types/event-callback';\nimport { Event } from './types/event/event';\nimport { Result } from './types/result';\nimport { buildResult } from './utils/result-builder';\nimport { UUID } from './utils/uuid';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n constructor(private client: CoreClient) {}\n\n async register(plugin: Plugin, config: IConfig) {\n if (this.plugins.some((existingPlugin) => existingPlugin.name === plugin.name)) {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n config.loggerProvider.warn(`Plugin with name ${plugin.name} already exists, skipping registration`);\n return;\n }\n\n if (plugin.name === undefined) {\n plugin.name = UUID();\n config.loggerProvider.warn(`Plugin name is undefined. \n Generating a random UUID for plugin name: ${plugin.name}. \n Set a name for the plugin to prevent it from being added multiple times.`);\n }\n\n plugin.type = plugin.type ?? 'enrichment';\n await plugin.setup?.(config, this.client);\n this.plugins.push(plugin);\n }\n\n async deregister(pluginName: string, config: IConfig) {\n const index = this.plugins.findIndex((plugin) => plugin.name === pluginName);\n if (index === -1) {\n config.loggerProvider.warn(`Plugin with name ${pluginName} does not exist, skipping deregistration`);\n return;\n }\n const plugin = this.plugins[index];\n this.plugins.splice(index, 1);\n await plugin.teardown?.();\n }\n\n reset(client: CoreClient) {\n this.applying = false;\n const plugins = this.plugins;\n plugins.map((plugin) => plugin.teardown?.());\n this.plugins = [];\n this.client = client;\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === 'before',\n );\n\n for (const plugin of before) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === 'enrichment' || plugin.type === undefined,\n );\n\n for (const plugin of enrichment) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n const resolveResult =\n result || buildResult(event, 100, 'Event not tracked, no destination plugins on the instance');\n resolve(resolveResult);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n\n onIdentityChanged(identity: AnalyticsIdentity) {\n this.plugins.forEach((plugin) => {\n // Intentionally to not await plugin.onIdentityChanged() for non-blocking.\n // Ignore optional channing next line for test coverage.\n // If the plugin doesn't implement it, it won't be called.\n /* istanbul ignore next */\n void plugin.onIdentityChanged?.(identity);\n });\n }\n\n onSessionIdChanged(sessionId: number) {\n this.plugins.forEach((plugin) => {\n // Intentionally to not await plugin.onSessionIdChanged() for non-blocking.\n // Ignore optional channing next line for test coverage.\n // If the plugin doesn't implement it, it won't be called.\n /* istanbul ignore next */\n void plugin.onSessionIdChanged?.(sessionId);\n });\n }\n\n onOptOutChanged(optOut: boolean) {\n this.plugins.forEach((plugin) => {\n // Intentionally to not await plugin.onOptOutChanged() for non-blocking.\n // Ignore optional channing next line for test coverage.\n // If the plugin doesn't implement it, it won't be called.\n /* istanbul ignore next */\n void plugin.onOptOutChanged?.(optOut);\n });\n }\n}\n"]}
|
|
@@ -34,6 +34,39 @@ export interface IdentifyUserProperties {
|
|
|
34
34
|
[IdentifyOperation.PREINSERT]?: BaseOperationConfig;
|
|
35
35
|
[IdentifyOperation.REMOVE]?: BaseOperationConfig;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Represents the structure of user properties that can be sent with an Identify or GroupIdentify event.
|
|
39
|
+
*
|
|
40
|
+
* This type supports both:
|
|
41
|
+
*
|
|
42
|
+
* 1. Reserved Amplitude identify operations via `IdentifyUserProperties`:
|
|
43
|
+
* These operations enable structured updates to user properties.
|
|
44
|
+
*
|
|
45
|
+
* Example:
|
|
46
|
+
* ```ts
|
|
47
|
+
* {
|
|
48
|
+
* $set: { plan: 'premium', login_count: 1 },
|
|
49
|
+
* $add: { login_count: 1 },
|
|
50
|
+
* $unset: { plan: '-' },
|
|
51
|
+
* $clearAll: '-'
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* 2. Custom user-defined properties (excluding reserved operation keys):
|
|
56
|
+
* Useful for assigning static properties without using Identify operations.
|
|
57
|
+
*
|
|
58
|
+
* Example:
|
|
59
|
+
* ```ts
|
|
60
|
+
* {
|
|
61
|
+
* custom_flag: true,
|
|
62
|
+
* experiment_group: 'B',
|
|
63
|
+
* favorite_color: 'blue'
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* This union ensures compatibility with Amplitude's identify semantics
|
|
68
|
+
* while allowing flexibility to define arbitrary non-reserved properties.
|
|
69
|
+
*/
|
|
37
70
|
export type UserProperties = IdentifyUserProperties | {
|
|
38
71
|
[key in Exclude<string, IdentifyOperation>]: any;
|
|
39
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../../src/types/event/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,oBAAY,iBAAiB;IAE3B,GAAG,SAAS;IACZ,QAAQ,aAAa;IAGrB,GAAG,SAAS;IACZ,MAAM,YAAY;IAClB,OAAO,aAAa;IACpB,MAAM,YAAY;IAGlB,SAAS,eAAe;IACxB,UAAU,gBAAgB;IAG1B,KAAK,WAAW;IAChB,SAAS,cAAc;CACxB;AAED,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EAAE,gBAAgB,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,UAAU,EAAE,gBAAgB,CAAC,QAAQ,CAAC;IACtC,eAAe,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,UAAU,EAAE,gBAAgB,CAAC,cAAc,CAAC;IAC5C,gBAAgB,EAAE,cAAc,CAAC;CAClC;AAED,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC;IACrC,gBAAgB,EACZ,sBAAsB,GACtB;QACE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACP;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,GAAG,aAAa,GAAG,kBAAkB,GAAG,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../../src/types/event/event.ts"],"names":[],"mappings":";;;AAGA,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B,gCAAgC;IAChC,iCAAY,CAAA;IACZ,0CAAqB,CAAA;IAErB,8CAA8C;IAC9C,iCAAY,CAAA;IACZ,uCAAkB,CAAA;IAClB,yCAAoB,CAAA;IACpB,uCAAkB,CAAA;IAElB,8DAA8D;IAC9D,6CAAwB,CAAA;IACxB,+CAA0B,CAAA;IAE1B,+CAA+C;IAC/C,qCAAgB,CAAA;IAChB,4CAAuB,CAAA;AACzB,CAAC,EAlBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAkB5B;
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../../src/types/event/event.ts"],"names":[],"mappings":";;;AAGA,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B,gCAAgC;IAChC,iCAAY,CAAA;IACZ,0CAAqB,CAAA;IAErB,8CAA8C;IAC9C,iCAAY,CAAA;IACZ,uCAAkB,CAAA;IAClB,yCAAoB,CAAA;IACpB,uCAAkB,CAAA;IAElB,8DAA8D;IAC9D,6CAAwB,CAAA;IACxB,+CAA0B,CAAA;IAE1B,+CAA+C;IAC/C,qCAAgB,CAAA;IAChB,4CAAuB,CAAA;AACzB,CAAC,EAlBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAkB5B;AAwED;;;GAGG;AACH,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,0CAAsB,CAAA;IACtB,qDAAiC,CAAA;IACjC,8CAA0B,CAAA;AAC5B,CAAC,EAJW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAI3B","sourcesContent":["import { BaseEvent } from './base-event';\nimport { RevenueEventProperties } from '../../revenue';\n\nexport enum IdentifyOperation {\n // Base Operations to set values\n SET = '$set',\n SET_ONCE = '$setOnce',\n\n // Operations around modifying existing values\n ADD = '$add',\n APPEND = '$append',\n PREPEND = '$prepend',\n REMOVE = '$remove',\n\n // Operations around appending values *if* they aren't present\n PREINSERT = '$preInsert',\n POSTINSERT = '$postInsert',\n\n // Operations around removing properties/values\n UNSET = '$unset',\n CLEAR_ALL = '$clearAll',\n}\n\nexport type ValidPropertyType =\n | number\n | string\n | boolean\n | Array<string | number>\n | { [key: string]: ValidPropertyType }\n | Array<{ [key: string]: ValidPropertyType }>;\n\ninterface BaseOperationConfig {\n [key: string]: ValidPropertyType;\n}\n\nexport interface IdentifyUserProperties {\n // Add operations can only take numbers\n [IdentifyOperation.ADD]?: { [key: string]: number };\n\n // This reads the keys of the passed object, but the values are not used\n [IdentifyOperation.UNSET]?: BaseOperationConfig;\n // This option does not read the key as it unsets all user properties\n [IdentifyOperation.CLEAR_ALL]?: any;\n\n // These operations can take numbers, strings, or arrays of both.\n [IdentifyOperation.SET]?: BaseOperationConfig;\n [IdentifyOperation.SET_ONCE]?: BaseOperationConfig;\n [IdentifyOperation.APPEND]?: BaseOperationConfig;\n [IdentifyOperation.PREPEND]?: BaseOperationConfig;\n [IdentifyOperation.POSTINSERT]?: BaseOperationConfig;\n [IdentifyOperation.PREINSERT]?: BaseOperationConfig;\n [IdentifyOperation.REMOVE]?: BaseOperationConfig;\n}\n\n/**\n * Represents the structure of user properties that can be sent with an Identify or GroupIdentify event.\n *\n * This type supports both:\n *\n * 1. Reserved Amplitude identify operations via `IdentifyUserProperties`:\n * These operations enable structured updates to user properties.\n *\n * Example:\n * ```ts\n * {\n * $set: { plan: 'premium', login_count: 1 },\n * $add: { login_count: 1 },\n * $unset: { plan: '-' },\n * $clearAll: '-'\n * }\n * ```\n *\n * 2. Custom user-defined properties (excluding reserved operation keys):\n * Useful for assigning static properties without using Identify operations.\n *\n * Example:\n * ```ts\n * {\n * custom_flag: true,\n * experiment_group: 'B',\n * favorite_color: 'blue'\n * }\n * ```\n *\n * This union ensures compatibility with Amplitude's identify semantics\n * while allowing flexibility to define arbitrary non-reserved properties.\n */\nexport type UserProperties =\n | IdentifyUserProperties\n | {\n [key in Exclude<string, IdentifyOperation>]: any;\n };\n\n/**\n * Strings that have special meaning when used as an event's type\n * and have different specifications.\n */\nexport enum SpecialEventType {\n IDENTIFY = '$identify',\n GROUP_IDENTIFY = '$groupidentify',\n REVENUE = 'revenue_amount',\n}\n\nexport interface TrackEvent extends BaseEvent {\n event_type: Exclude<string, SpecialEventType>;\n}\n\nexport interface IdentifyEvent extends BaseEvent {\n event_type: SpecialEventType.IDENTIFY;\n user_properties: UserProperties;\n}\n\nexport interface GroupIdentifyEvent extends BaseEvent {\n event_type: SpecialEventType.GROUP_IDENTIFY;\n group_properties: UserProperties;\n}\n\nexport interface RevenueEvent extends BaseEvent {\n event_type: SpecialEventType.REVENUE;\n event_properties:\n | RevenueEventProperties\n | {\n [key: string]: any;\n };\n}\n\nexport type Event = TrackEvent | IdentifyEvent | GroupIdentifyEvent | RevenueEvent;\n"]}
|
|
@@ -6,11 +6,33 @@ type PluginTypeBefore = 'before';
|
|
|
6
6
|
type PluginTypeEnrichment = 'enrichment';
|
|
7
7
|
type PluginTypeDestination = 'destination';
|
|
8
8
|
export type PluginType = PluginTypeBefore | PluginTypeEnrichment | PluginTypeDestination;
|
|
9
|
+
export interface AnalyticsIdentity {
|
|
10
|
+
deviceId?: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
userProperties?: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
9
16
|
interface PluginBase<T = CoreClient, U = IConfig> {
|
|
10
17
|
name?: string;
|
|
11
18
|
type?: PluginType;
|
|
12
19
|
setup?(config: U, client: T): Promise<void>;
|
|
13
20
|
teardown?(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Called when the identity is changed. This is a **best-effort** API and may not be triggered in all scenarios.
|
|
23
|
+
*
|
|
24
|
+
* Currently supported only in the Browser SDK. Not supported in React Native or Node SDKs.
|
|
25
|
+
*
|
|
26
|
+
* @param identity The changed identity. If a field is missing, it means it has not changed.
|
|
27
|
+
* For example, `{ userId: undefined }` means the userId was explicitly changed to `undefined`,
|
|
28
|
+
* while deviceId and userProperties remain unchanged.
|
|
29
|
+
*
|
|
30
|
+
* Note: `onIdentityChanged()` will be triggered when a user logs in via `setUserId()`.
|
|
31
|
+
* It will not be triggered on subsequent page loads (e.g., when a user reopens the site in a new tab).
|
|
32
|
+
*/
|
|
33
|
+
onIdentityChanged?(identity: AnalyticsIdentity): Promise<void>;
|
|
34
|
+
onSessionIdChanged?(sessionId: number): Promise<void>;
|
|
35
|
+
onOptOutChanged?(optOut: boolean): Promise<void>;
|
|
14
36
|
}
|
|
15
37
|
export interface BeforePlugin<T = CoreClient, U = IConfig> extends PluginBase<T, U> {
|
|
16
38
|
type: PluginTypeBefore;
|