@ninetailed/experience.js 3.0.0-beta.32 → 3.0.0-beta.33

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.
Files changed (3) hide show
  1. package/index.cjs +41 -22
  2. package/index.js +41 -22
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -3203,23 +3203,39 @@ class Ninetailed {
3203
3203
  } = {}) {
3204
3204
  this.isInitialized = false;
3205
3205
  this.page = (data, options) => __awaiter(this, void 0, void 0, function* () {
3206
- const result = experience_jsShared.PageviewProperties.partial().default({}).safeParse(data);
3207
- if (!result.success) {
3208
- throw new Error(`[Validation Error] "page" was called with invalid params. Page data is not valid: ${result.error.format()}`);
3206
+ try {
3207
+ const result = experience_jsShared.PageviewProperties.partial().default({}).safeParse(data);
3208
+ if (!result.success) {
3209
+ throw new Error(`[Validation Error] "page" was called with invalid params. Page data is not valid: ${result.error.format()}`);
3210
+ }
3211
+ yield this.waitUntilInitialized();
3212
+ return this.instance.page(data, this.buildOptions(options));
3213
+ } catch (error) {
3214
+ experience_jsShared.logger.error(error);
3215
+ if (error instanceof RangeError) {
3216
+ throw new Error(`[Validation Error] "page" was called with invalid params. Could not validate due to "RangeError: Maximum call stack size exceeded". This can be caused by passing a cyclic data structure as a parameter. Refrain from passing a cyclic data structure or sanitize it beforehand.`);
3217
+ }
3218
+ throw error;
3209
3219
  }
3210
- yield this.waitUntilInitialized();
3211
- return this.instance.page(data, this.buildOptions(options));
3212
3220
  });
3213
3221
  this.track = (event, properties, options) => __awaiter(this, void 0, void 0, function* () {
3214
- const result = experience_jsShared.Properties.default({}).safeParse(properties);
3215
- if (!result.success) {
3216
- throw new Error(`[Validation Error] "track" was called with invalid params. Properties are no valid json object: ${result.error.format()}`);
3222
+ try {
3223
+ const result = experience_jsShared.Properties.default({}).safeParse(properties);
3224
+ if (!result.success) {
3225
+ throw new Error(`[Validation Error] "track" was called with invalid params. Properties are no valid json object: ${result.error.format()}`);
3226
+ }
3227
+ yield this.waitUntilInitialized();
3228
+ return this.instance.track(event.toString(), result.data, this.buildOptions(options));
3229
+ } catch (error) {
3230
+ experience_jsShared.logger.error(error);
3231
+ if (error instanceof RangeError) {
3232
+ throw new Error(`[Validation Error] "track" was called with invalid params. Could not validate due to "RangeError: Maximum call stack size exceeded". This can be caused by passing a cyclic data structure as a parameter. Refrain from passing a cyclic data structure or sanitize it beforehand.`);
3233
+ }
3234
+ throw error;
3217
3235
  }
3218
- yield this.waitUntilInitialized();
3219
- return this.instance.track(event.toString(), properties, this.buildOptions(options));
3220
3236
  });
3221
3237
  this.trackHasSeenComponent = payload => __awaiter(this, void 0, void 0, function* () {
3222
- return this.track('hasSeenComponent', payload, {
3238
+ return this.instance.track('hasSeenComponent', payload, {
3223
3239
  plugins: {
3224
3240
  all: true,
3225
3241
  ninetailed: false
@@ -3227,10 +3243,7 @@ class Ninetailed {
3227
3243
  });
3228
3244
  });
3229
3245
  this.trackExperience = properties => {
3230
- // we stringify and parse the properties to remove non serializable values
3231
- const stringifiedProperties = JSON.stringify(properties);
3232
- const sanitizedProperties = JSON.parse(stringifiedProperties);
3233
- return this.track('nt_experience', sanitizedProperties, {
3246
+ return this.instance.track('nt_experience', properties, {
3234
3247
  plugins: {
3235
3248
  all: true,
3236
3249
  ninetailed: false
@@ -3238,12 +3251,20 @@ class Ninetailed {
3238
3251
  });
3239
3252
  };
3240
3253
  this.identify = (uid, traits, options) => __awaiter(this, void 0, void 0, function* () {
3241
- const result = experience_jsShared.Traits.default({}).safeParse(traits);
3242
- if (!result.success) {
3243
- throw new Error(`[Validation Error] "identify" was called with invalid params. Traits are no valid json: ${result.error.format()}`);
3254
+ try {
3255
+ const result = experience_jsShared.Traits.default({}).safeParse(traits);
3256
+ if (!result.success) {
3257
+ throw new Error(`[Validation Error] "identify" was called with invalid params. Traits are no valid json: ${result.error.format()}`);
3258
+ }
3259
+ yield this.waitUntilInitialized();
3260
+ return this.instance.identify(uid.toString(), result.data, this.buildOptions(options));
3261
+ } catch (error) {
3262
+ experience_jsShared.logger.error(error);
3263
+ if (error instanceof RangeError) {
3264
+ throw new Error(`[Validation Error] "identify" was called with invalid params. Could not validate due to "RangeError: Maximum call stack size exceeded". This can be caused by passing a cyclic data structure as a parameter. Refrain from passing a cyclic data structure or sanitize it beforehand.`);
3265
+ }
3266
+ throw error;
3244
3267
  }
3245
- yield this.waitUntilInitialized();
3246
- return this.instance.identify(uid.toString(), result.data, this.buildOptions(options));
3247
3268
  });
3248
3269
  this.reset = () => {
3249
3270
  this.onIsInitialized(() => {
@@ -3412,8 +3433,6 @@ const selectVariant$1 = (baseline, variants, {
3412
3433
  return includes__default["default"](profile === null || profile === void 0 ? void 0 : profile.audiences, (_a = variant.audience) === null || _a === void 0 ? void 0 : _a.id);
3413
3434
  });
3414
3435
  if (variant) {
3415
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3416
- // @ts-ignore
3417
3436
  if ((options === null || options === void 0 ? void 0 : options.holdout) || -1 > (profile === null || profile === void 0 ? void 0 : profile.random)) {
3418
3437
  return {
3419
3438
  loading: false,
package/index.js CHANGED
@@ -3190,23 +3190,39 @@ class Ninetailed {
3190
3190
  } = {}) {
3191
3191
  this.isInitialized = false;
3192
3192
  this.page = (data, options) => __awaiter(this, void 0, void 0, function* () {
3193
- const result = PageviewProperties.partial().default({}).safeParse(data);
3194
- if (!result.success) {
3195
- throw new Error(`[Validation Error] "page" was called with invalid params. Page data is not valid: ${result.error.format()}`);
3193
+ try {
3194
+ const result = PageviewProperties.partial().default({}).safeParse(data);
3195
+ if (!result.success) {
3196
+ throw new Error(`[Validation Error] "page" was called with invalid params. Page data is not valid: ${result.error.format()}`);
3197
+ }
3198
+ yield this.waitUntilInitialized();
3199
+ return this.instance.page(data, this.buildOptions(options));
3200
+ } catch (error) {
3201
+ logger.error(error);
3202
+ if (error instanceof RangeError) {
3203
+ throw new Error(`[Validation Error] "page" was called with invalid params. Could not validate due to "RangeError: Maximum call stack size exceeded". This can be caused by passing a cyclic data structure as a parameter. Refrain from passing a cyclic data structure or sanitize it beforehand.`);
3204
+ }
3205
+ throw error;
3196
3206
  }
3197
- yield this.waitUntilInitialized();
3198
- return this.instance.page(data, this.buildOptions(options));
3199
3207
  });
3200
3208
  this.track = (event, properties, options) => __awaiter(this, void 0, void 0, function* () {
3201
- const result = Properties.default({}).safeParse(properties);
3202
- if (!result.success) {
3203
- throw new Error(`[Validation Error] "track" was called with invalid params. Properties are no valid json object: ${result.error.format()}`);
3209
+ try {
3210
+ const result = Properties.default({}).safeParse(properties);
3211
+ if (!result.success) {
3212
+ throw new Error(`[Validation Error] "track" was called with invalid params. Properties are no valid json object: ${result.error.format()}`);
3213
+ }
3214
+ yield this.waitUntilInitialized();
3215
+ return this.instance.track(event.toString(), result.data, this.buildOptions(options));
3216
+ } catch (error) {
3217
+ logger.error(error);
3218
+ if (error instanceof RangeError) {
3219
+ throw new Error(`[Validation Error] "track" was called with invalid params. Could not validate due to "RangeError: Maximum call stack size exceeded". This can be caused by passing a cyclic data structure as a parameter. Refrain from passing a cyclic data structure or sanitize it beforehand.`);
3220
+ }
3221
+ throw error;
3204
3222
  }
3205
- yield this.waitUntilInitialized();
3206
- return this.instance.track(event.toString(), properties, this.buildOptions(options));
3207
3223
  });
3208
3224
  this.trackHasSeenComponent = payload => __awaiter(this, void 0, void 0, function* () {
3209
- return this.track('hasSeenComponent', payload, {
3225
+ return this.instance.track('hasSeenComponent', payload, {
3210
3226
  plugins: {
3211
3227
  all: true,
3212
3228
  ninetailed: false
@@ -3214,10 +3230,7 @@ class Ninetailed {
3214
3230
  });
3215
3231
  });
3216
3232
  this.trackExperience = properties => {
3217
- // we stringify and parse the properties to remove non serializable values
3218
- const stringifiedProperties = JSON.stringify(properties);
3219
- const sanitizedProperties = JSON.parse(stringifiedProperties);
3220
- return this.track('nt_experience', sanitizedProperties, {
3233
+ return this.instance.track('nt_experience', properties, {
3221
3234
  plugins: {
3222
3235
  all: true,
3223
3236
  ninetailed: false
@@ -3225,12 +3238,20 @@ class Ninetailed {
3225
3238
  });
3226
3239
  };
3227
3240
  this.identify = (uid, traits, options) => __awaiter(this, void 0, void 0, function* () {
3228
- const result = Traits.default({}).safeParse(traits);
3229
- if (!result.success) {
3230
- throw new Error(`[Validation Error] "identify" was called with invalid params. Traits are no valid json: ${result.error.format()}`);
3241
+ try {
3242
+ const result = Traits.default({}).safeParse(traits);
3243
+ if (!result.success) {
3244
+ throw new Error(`[Validation Error] "identify" was called with invalid params. Traits are no valid json: ${result.error.format()}`);
3245
+ }
3246
+ yield this.waitUntilInitialized();
3247
+ return this.instance.identify(uid.toString(), result.data, this.buildOptions(options));
3248
+ } catch (error) {
3249
+ logger.error(error);
3250
+ if (error instanceof RangeError) {
3251
+ throw new Error(`[Validation Error] "identify" was called with invalid params. Could not validate due to "RangeError: Maximum call stack size exceeded". This can be caused by passing a cyclic data structure as a parameter. Refrain from passing a cyclic data structure or sanitize it beforehand.`);
3252
+ }
3253
+ throw error;
3231
3254
  }
3232
- yield this.waitUntilInitialized();
3233
- return this.instance.identify(uid.toString(), result.data, this.buildOptions(options));
3234
3255
  });
3235
3256
  this.reset = () => {
3236
3257
  this.onIsInitialized(() => {
@@ -3399,8 +3420,6 @@ const selectVariant$1 = (baseline, variants, {
3399
3420
  return includes(profile === null || profile === void 0 ? void 0 : profile.audiences, (_a = variant.audience) === null || _a === void 0 ? void 0 : _a.id);
3400
3421
  });
3401
3422
  if (variant) {
3402
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3403
- // @ts-ignore
3404
3423
  if ((options === null || options === void 0 ? void 0 : options.holdout) || -1 > (profile === null || profile === void 0 ? void 0 : profile.random)) {
3405
3424
  return {
3406
3425
  loading: false,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "3.0.0-beta.32",
3
+ "version": "3.0.0-beta.33",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "@ninetailed/experience.js-shared": "3.0.0-beta.32",
9
+ "@ninetailed/experience.js-shared": "3.0.0-beta.33",
10
10
  "analytics": "0.8.1",
11
11
  "lodash": "4.17.21",
12
12
  "murmurhash-js": "1.0.0"