@croct/sdk 0.6.1 → 0.7.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/constants.js CHANGED
@@ -5,4 +5,4 @@ exports.TRACKER_ENDPOINT_URL = 'wss://api.croct.io/client/web/connect';
5
5
  exports.EVALUATION_ENDPOINT_URL = 'https://api.croct.io/client/web/evaluate';
6
6
  exports.BOOTSTRAP_ENDPOINT_URL = 'https://api.croct.io/client/web/bootstrap';
7
7
  exports.MAX_EXPRESSION_LENGTH = 300;
8
- exports.VERSION = '0.6.1';
8
+ exports.VERSION = '0.7.0';
@@ -11,8 +11,9 @@ var eventSchemas = {
11
11
  orderPlaced: schema_1.orderPlaced,
12
12
  productViewed: schema_1.productViewed,
13
13
  userSignedUp: schema_1.userSignedUp,
14
- testGroupAssigned: schema_1.testGroupAssigned,
15
14
  eventOccurred: schema_1.eventOccurred,
15
+ interestShown: schema_1.interestShown,
16
+ postViewed: schema_1.postViewed,
16
17
  goalCompleted: schema_1.goalCompleted,
17
18
  };
18
19
  function createEvent(type, payload) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/sdk",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Croct SDK for JavaScript.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -0,0 +1,2 @@
1
+ import { StringType } from '../validation';
2
+ export declare const attributeNameSchema: StringType;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attributeNameSchema = void 0;
4
+ var validation_1 = require("../validation");
5
+ exports.attributeNameSchema = new validation_1.StringType({
6
+ maxLength: 50,
7
+ format: 'identifier',
8
+ });
@@ -0,0 +1,2 @@
1
+ import { ObjectType } from '../validation';
2
+ export declare const postDetails: ObjectType;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postDetails = void 0;
4
+ var validation_1 = require("../validation");
5
+ exports.postDetails = new validation_1.ObjectType({
6
+ required: ['postId', 'title', 'publishTime'],
7
+ properties: {
8
+ postId: new validation_1.StringType({
9
+ minLength: 1,
10
+ maxLength: 100,
11
+ }),
12
+ url: new validation_1.StringType({
13
+ format: 'url',
14
+ }),
15
+ title: new validation_1.StringType({
16
+ minLength: 1,
17
+ maxLength: 100,
18
+ }),
19
+ tags: new validation_1.ArrayType({
20
+ items: new validation_1.StringType({
21
+ minLength: 1,
22
+ maxLength: 50,
23
+ }),
24
+ minItems: 1,
25
+ maxItems: 10,
26
+ }),
27
+ categories: new validation_1.ArrayType({
28
+ items: new validation_1.StringType({
29
+ minLength: 1,
30
+ maxLength: 50,
31
+ }),
32
+ minItems: 1,
33
+ maxItems: 10,
34
+ }),
35
+ authors: new validation_1.ArrayType({
36
+ items: new validation_1.StringType({
37
+ minLength: 1,
38
+ maxLength: 50,
39
+ }),
40
+ minItems: 1,
41
+ maxItems: 10,
42
+ }),
43
+ publishTime: new validation_1.NumberType(),
44
+ updateTime: new validation_1.NumberType(),
45
+ },
46
+ });
@@ -5,6 +5,7 @@ export declare const checkoutStarted: ObjectType;
5
5
  export declare const orderPlaced: ObjectType;
6
6
  export declare const productViewed: ObjectType;
7
7
  export declare const userSignedUp: ObjectType;
8
- export declare const testGroupAssigned: ObjectType;
9
8
  export declare const goalCompleted: ObjectType;
9
+ export declare const interestShown: ObjectType;
10
+ export declare const postViewed: ObjectType;
10
11
  export declare const eventOccurred: ObjectType;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eventOccurred = exports.goalCompleted = exports.testGroupAssigned = exports.userSignedUp = exports.productViewed = exports.orderPlaced = exports.checkoutStarted = exports.cartViewed = exports.cartModified = void 0;
3
+ exports.eventOccurred = exports.postViewed = exports.interestShown = exports.goalCompleted = exports.userSignedUp = exports.productViewed = exports.orderPlaced = exports.checkoutStarted = exports.cartViewed = exports.cartModified = void 0;
4
4
  var validation_1 = require("../validation");
5
5
  var ecommerceSchemas_1 = require("./ecommerceSchemas");
6
6
  var userSchema_1 = require("./userSchema");
7
+ var contentSchemas_1 = require("./contentSchemas");
7
8
  exports.cartModified = new validation_1.ObjectType({
8
9
  required: ['cart'],
9
10
  properties: {
@@ -48,19 +49,6 @@ exports.userSignedUp = new validation_1.ObjectType({
48
49
  profile: userSchema_1.userProfileSchema,
49
50
  },
50
51
  });
51
- exports.testGroupAssigned = new validation_1.ObjectType({
52
- required: ['testId', 'groupId'],
53
- properties: {
54
- testId: new validation_1.StringType({
55
- minLength: 1,
56
- maxLength: 50,
57
- }),
58
- groupId: new validation_1.StringType({
59
- minLength: 1,
60
- maxLength: 50,
61
- }),
62
- },
63
- });
64
52
  exports.goalCompleted = new validation_1.ObjectType({
65
53
  required: ['goalId'],
66
54
  properties: {
@@ -77,6 +65,25 @@ exports.goalCompleted = new validation_1.ObjectType({
77
65
  }),
78
66
  },
79
67
  });
68
+ exports.interestShown = new validation_1.ObjectType({
69
+ required: ['interests'],
70
+ properties: {
71
+ interests: new validation_1.ArrayType({
72
+ items: new validation_1.StringType({
73
+ minLength: 1,
74
+ maxLength: 50,
75
+ }),
76
+ minItems: 1,
77
+ maxItems: 10,
78
+ }),
79
+ },
80
+ });
81
+ exports.postViewed = new validation_1.ObjectType({
82
+ required: ['post'],
83
+ properties: {
84
+ post: contentSchemas_1.postDetails,
85
+ },
86
+ });
80
87
  exports.eventOccurred = new validation_1.ObjectType({
81
88
  required: ['name'],
82
89
  properties: {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unsetOperation = exports.clearOperation = exports.incrementOperation = exports.decrementOperation = exports.mergeOperation = exports.combineOperation = exports.setOperation = exports.addOperation = void 0;
4
4
  var validation_1 = require("../validation");
5
+ var attributeSchema_1 = require("./attributeSchema");
5
6
  var pointer = new validation_1.StringType({
6
7
  format: 'pointer',
7
8
  });
@@ -10,9 +11,11 @@ var simpleArray = new validation_1.JsonArrayType({
10
11
  });
11
12
  var simpleMap = new validation_1.JsonObjectType({
12
13
  properties: new validation_1.JsonPrimitiveType(),
14
+ propertyNames: attributeSchema_1.attributeNameSchema,
13
15
  });
14
16
  var complexMap = new validation_1.JsonObjectType({
15
17
  properties: new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, simpleMap),
18
+ propertyNames: attributeSchema_1.attributeNameSchema,
16
19
  });
17
20
  var collectionValue = new validation_1.UnionType(simpleArray, complexMap);
18
21
  var mixedValue = new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, complexMap);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userProfileSchema = void 0;
4
4
  var validation_1 = require("../validation");
5
+ var attributeSchema_1 = require("./attributeSchema");
5
6
  exports.userProfileSchema = new validation_1.ObjectType({
6
7
  properties: {
7
8
  firstName: new validation_1.StringType({
@@ -93,10 +94,7 @@ exports.userProfileSchema = new validation_1.ObjectType({
93
94
  }),
94
95
  }),
95
96
  custom: new validation_1.ObjectType({
96
- propertyNames: new validation_1.StringType({
97
- maxLength: 50,
98
- format: 'identifier',
99
- }),
97
+ propertyNames: attributeSchema_1.attributeNameSchema,
100
98
  maxProperties: 10,
101
99
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
102
100
  maxLength: 100,
@@ -110,20 +108,14 @@ exports.userProfileSchema = new validation_1.ObjectType({
110
108
  maxLength: 100,
111
109
  })),
112
110
  }), new validation_1.ObjectType({
113
- propertyNames: new validation_1.StringType({
114
- maxLength: 50,
115
- format: 'identifier',
116
- }),
111
+ propertyNames: attributeSchema_1.attributeNameSchema,
117
112
  maxProperties: 10,
118
113
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
119
114
  maxLength: 100,
120
115
  })),
121
116
  })),
122
117
  }), new validation_1.ObjectType({
123
- propertyNames: new validation_1.StringType({
124
- maxLength: 50,
125
- format: 'identifier',
126
- }),
118
+ propertyNames: attributeSchema_1.attributeNameSchema,
127
119
  maxProperties: 10,
128
120
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
129
121
  maxLength: 100,
@@ -133,10 +125,7 @@ exports.userProfileSchema = new validation_1.ObjectType({
133
125
  maxLength: 100,
134
126
  })),
135
127
  }), new validation_1.ObjectType({
136
- propertyNames: new validation_1.StringType({
137
- maxLength: 50,
138
- format: 'identifier',
139
- }),
128
+ propertyNames: attributeSchema_1.attributeNameSchema,
140
129
  maxProperties: 10,
141
130
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
142
131
  maxLength: 100,
@@ -71,8 +71,8 @@ export declare const cartEventTypes: readonly ["cartModified", "cartViewed", "ch
71
71
  export declare const ecommerceEventTypes: readonly ["cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed"];
72
72
  export declare const identifiedUserEventTypes: string[];
73
73
  export declare const userEventTypes: readonly [...string[], "userProfileChanged"];
74
- export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "testGroupAssigned", "goalCompleted", "eventOccurred"];
75
- export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "testGroupAssigned", "goalCompleted", "eventOccurred"];
74
+ export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred"];
75
+ export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred"];
76
76
  interface BaseEvent {
77
77
  type: string;
78
78
  }
@@ -200,17 +200,30 @@ export interface SessionAttributesChanged extends BaseEvent {
200
200
  type: 'sessionAttributesChanged';
201
201
  patch: Patch;
202
202
  }
203
- export interface TestGroupAssigned extends BaseEvent {
204
- type: 'testGroupAssigned';
205
- testId: string;
206
- groupId: string;
207
- }
208
203
  export interface GoalCompleted extends BaseEvent {
209
204
  type: 'goalCompleted';
210
205
  goalId: string;
211
206
  value?: number;
212
207
  currency?: string;
213
208
  }
209
+ export interface InterestShown extends BaseEvent {
210
+ type: 'interestShown';
211
+ interests: string[];
212
+ }
213
+ export interface PostDetails {
214
+ postId: string;
215
+ url?: string;
216
+ title: string;
217
+ tags?: string[];
218
+ categories?: string[];
219
+ authors?: string[];
220
+ publishTime: number;
221
+ updateTime?: number;
222
+ }
223
+ export interface PostViewed extends BaseEvent {
224
+ type: 'postViewed';
225
+ post: PostDetails;
226
+ }
214
227
  export interface EventOccurred extends BaseEvent {
215
228
  type: 'eventOccurred';
216
229
  name: string;
@@ -222,7 +235,7 @@ export interface EventOccurred extends BaseEvent {
222
235
  [key: string]: string | number | boolean | null;
223
236
  };
224
237
  }
225
- export declare type MiscEvent = NothingChanged | SessionAttributesChanged | TestGroupAssigned | EventOccurred | GoalCompleted;
238
+ export declare type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed;
226
239
  declare type EventMap = {
227
240
  tabVisibilityChanged: TabVisibilityChanged;
228
241
  tabUrlChanged: TabUrlChanged;
@@ -240,8 +253,9 @@ declare type EventMap = {
240
253
  orderPlaced: OrderPlaced;
241
254
  nothingChanged: NothingChanged;
242
255
  sessionAttributesChanged: SessionAttributesChanged;
243
- testGroupAssigned: TestGroupAssigned;
244
256
  goalCompleted: GoalCompleted;
257
+ interestShown: InterestShown;
258
+ postViewed: PostViewed;
245
259
  eventOccurred: EventOccurred;
246
260
  };
247
261
  export declare type TrackingEventType = keyof EventMap;
@@ -261,8 +275,9 @@ declare type ExternalEventMap = {
261
275
  orderPlaced: OrderPlaced;
262
276
  productViewed: ProductViewed;
263
277
  userSignedUp: UserSignedUp;
264
- testGroupAssigned: TestGroupAssigned;
265
278
  goalCompleted: GoalCompleted;
279
+ interestShown: InterestShown;
280
+ postViewed: PostViewed;
266
281
  eventOccurred: EventOccurred;
267
282
  };
268
283
  export declare type ExternalTrackingEventType = keyof ExternalEventMap;
package/trackingEvents.js CHANGED
@@ -34,8 +34,9 @@ exports.userEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1
34
34
  exports.miscEventTypes = [
35
35
  'nothingChanged',
36
36
  'sessionAttributesChanged',
37
- 'testGroupAssigned',
38
37
  'goalCompleted',
38
+ 'interestShown',
39
+ 'postViewed',
39
40
  'eventOccurred',
40
41
  ];
41
42
  exports.eventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.pageEventTypes)), tslib_1.__read(exports.ecommerceEventTypes)), tslib_1.__read(exports.userEventTypes)), tslib_1.__read(exports.miscEventTypes));
@@ -1,6 +1,7 @@
1
1
  import { Schema, TypeSchema } from './schema';
2
2
  declare type JsonObjectDefinition = {
3
3
  properties?: Schema;
4
+ propertyNames?: Schema;
4
5
  };
5
6
  export declare class JsonObjectType implements TypeSchema {
6
7
  private readonly definition;
@@ -37,13 +37,19 @@ var JsonObjectType = /** @class */ (function () {
37
37
  if (!isJsonObject(value)) {
38
38
  throw new schema_1.Violation("Expected a JSON object at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'object' });
39
39
  }
40
- if (this.definition.properties === undefined) {
40
+ if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
41
41
  return;
42
42
  }
43
43
  try {
44
44
  for (var _b = tslib_1.__values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
45
45
  var _d = tslib_1.__read(_c.value, 2), entryName = _d[0], entryValue = _d[1];
46
- this.definition.properties.validate(entryValue, path.concat([entryName]));
46
+ var propertyPath = path.concat([entryName]);
47
+ if (this.definition.propertyNames !== undefined) {
48
+ this.definition.propertyNames.validate(entryName, propertyPath);
49
+ }
50
+ if (this.definition.properties !== undefined) {
51
+ this.definition.properties.validate(entryValue, path.concat([entryName]));
52
+ }
47
53
  }
48
54
  }
49
55
  catch (e_1_1) { e_1 = { error: e_1_1 }; }