@croct/sdk 0.18.2 → 0.19.1
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/README.md +0 -1
- package/channel/httpBeaconChannel.cjs +5 -0
- package/channel/httpBeaconChannel.js +5 -0
- package/constants.cjs +1 -1
- package/constants.d.cts +2 -2
- package/constants.d.ts +2 -2
- package/constants.js +1 -1
- package/container.cjs +2 -1
- package/container.js +2 -1
- package/contentFetcher.cjs +13 -4
- package/contentFetcher.d.cts +3 -2
- package/contentFetcher.d.ts +3 -2
- package/contentFetcher.js +13 -4
- package/evaluator.cjs +22 -13
- package/evaluator.d.cts +8 -7
- package/evaluator.d.ts +8 -7
- package/evaluator.js +22 -13
- package/facade/trackerFacade.cjs +2 -1
- package/facade/trackerFacade.js +4 -2
- package/help.cjs +2 -0
- package/help.d.cts +1 -0
- package/help.d.ts +1 -0
- package/help.js +2 -0
- package/logging/deduplicatedLogger.cjs +70 -0
- package/logging/deduplicatedLogger.d.cts +15 -0
- package/logging/deduplicatedLogger.d.ts +15 -0
- package/logging/deduplicatedLogger.js +47 -0
- package/package.json +1 -1
- package/schema/eventSchemas.cjs +18 -0
- package/schema/eventSchemas.d.cts +2 -1
- package/schema/eventSchemas.d.ts +2 -1
- package/schema/eventSchemas.js +17 -0
- package/schema/index.d.cts +1 -1
- package/schema/index.d.ts +1 -1
- package/tracker.cjs +15 -0
- package/tracker.js +15 -0
- package/trackingEvents.cjs +2 -1
- package/trackingEvents.d.cts +16 -5
- package/trackingEvents.d.ts +16 -5
- package/trackingEvents.js +2 -1
package/README.md
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
<p align="center">
|
|
17
17
|
<a href="https://www.npmjs.com/package/@croct/sdk"><img alt="Version" src="https://img.shields.io/npm/v/@croct/sdk"/></a>
|
|
18
18
|
<a href="https://github.com/croct-tech/sdk-js/actions?query=workflow%3AValidations"><img alt="Build" src="https://github.com/croct-tech/sdk-js/workflows/Validations/badge.svg"/></a>
|
|
19
|
-
<a href="https://codeclimate.com/repos/5e7251b3172af05fe9000e27/test_coverage"><img alt="Coverage" src="https://api.codeclimate.com/v1/badges/c44df78a3ed891af11bb/test_coverage"/></a>
|
|
20
19
|
</p>
|
|
21
20
|
|
|
22
21
|
## Installation
|
|
@@ -56,6 +56,11 @@ class HttpBeaconChannel {
|
|
|
56
56
|
keepalive: true
|
|
57
57
|
}).then(async (response) => {
|
|
58
58
|
if (response.ok) {
|
|
59
|
+
if (response.status === 202) {
|
|
60
|
+
this.logger.warn(
|
|
61
|
+
"Event tracking is currently suspended for this application, check the workspace settings. For help, see https://croct.help/sdk/javascript/suspended-service"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
59
64
|
this.notify(receiptId);
|
|
60
65
|
return;
|
|
61
66
|
}
|
|
@@ -34,6 +34,11 @@ class HttpBeaconChannel {
|
|
|
34
34
|
keepalive: true
|
|
35
35
|
}).then(async (response) => {
|
|
36
36
|
if (response.ok) {
|
|
37
|
+
if (response.status === 202) {
|
|
38
|
+
this.logger.warn(
|
|
39
|
+
"Event tracking is currently suspended for this application, check the workspace settings. For help, see https://croct.help/sdk/javascript/suspended-service"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
37
42
|
this.notify(receiptId);
|
|
38
43
|
return;
|
|
39
44
|
}
|
package/constants.cjs
CHANGED
|
@@ -25,7 +25,7 @@ __export(constants_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(constants_exports);
|
|
26
26
|
const BASE_ENDPOINT_URL = "https://api.croct.io";
|
|
27
27
|
const MAX_QUERY_LENGTH = parseInt("<@maxQueryLength@>", 10);
|
|
28
|
-
const VERSION = "0.
|
|
28
|
+
const VERSION = "0.19.1";
|
|
29
29
|
const CLIENT_LIBRARY = `Croct SDK JS v${VERSION}`;
|
|
30
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
31
|
0 && (module.exports = {
|
package/constants.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const BASE_ENDPOINT_URL = "https://api.croct.io";
|
|
2
2
|
declare const MAX_QUERY_LENGTH: number;
|
|
3
|
-
declare const VERSION = "0.
|
|
4
|
-
declare const CLIENT_LIBRARY = "Croct SDK JS v0.
|
|
3
|
+
declare const VERSION = "0.19.1";
|
|
4
|
+
declare const CLIENT_LIBRARY = "Croct SDK JS v0.19.1";
|
|
5
5
|
|
|
6
6
|
export { BASE_ENDPOINT_URL, CLIENT_LIBRARY, MAX_QUERY_LENGTH, VERSION };
|
package/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const BASE_ENDPOINT_URL = "https://api.croct.io";
|
|
2
2
|
declare const MAX_QUERY_LENGTH: number;
|
|
3
|
-
declare const VERSION = "0.
|
|
4
|
-
declare const CLIENT_LIBRARY = "Croct SDK JS v0.
|
|
3
|
+
declare const VERSION = "0.19.1";
|
|
4
|
+
declare const CLIENT_LIBRARY = "Croct SDK JS v0.19.1";
|
|
5
5
|
|
|
6
6
|
export { BASE_ENDPOINT_URL, CLIENT_LIBRARY, MAX_QUERY_LENGTH, VERSION };
|
package/constants.js
CHANGED
package/container.cjs
CHANGED
|
@@ -38,6 +38,7 @@ var import_contentFetcher = require('./contentFetcher.cjs');
|
|
|
38
38
|
var import_cookieCache = require('./cache/cookieCache.cjs');
|
|
39
39
|
var import_filteredLogger = require('./logging/filteredLogger.cjs');
|
|
40
40
|
var import_httpBeaconChannel = require('./channel/httpBeaconChannel.cjs');
|
|
41
|
+
var import_deduplicatedLogger = require('./logging/deduplicatedLogger.cjs');
|
|
41
42
|
const _Container = class _Container {
|
|
42
43
|
constructor(configuration) {
|
|
43
44
|
this.eventManager = new import_eventManager.SynchronousEventManager();
|
|
@@ -230,7 +231,7 @@ const _Container = class _Container {
|
|
|
230
231
|
if (this.configuration.debug) {
|
|
231
232
|
return new import_logging.ConsoleLogger(prefix);
|
|
232
233
|
}
|
|
233
|
-
return import_filteredLogger.FilteredLogger.include(new import_logging.ConsoleLogger(), ["error", "warn"]);
|
|
234
|
+
return new import_deduplicatedLogger.DeduplicatedLogger(import_filteredLogger.FilteredLogger.include(new import_logging.ConsoleLogger(prefix), ["error", "warn"]));
|
|
234
235
|
}
|
|
235
236
|
getTabStorage(namespace, ...subnamespace) {
|
|
236
237
|
return this.getGlobalTabStorage("external", namespace, ...subnamespace);
|
package/container.js
CHANGED
|
@@ -22,6 +22,7 @@ import { ContentFetcher } from "./contentFetcher.js";
|
|
|
22
22
|
import { CookieCache } from "./cache/cookieCache.js";
|
|
23
23
|
import { FilteredLogger } from "./logging/filteredLogger.js";
|
|
24
24
|
import { HttpBeaconChannel } from "./channel/httpBeaconChannel.js";
|
|
25
|
+
import { DeduplicatedLogger } from "./logging/deduplicatedLogger.js";
|
|
25
26
|
const _Container = class _Container {
|
|
26
27
|
constructor(configuration) {
|
|
27
28
|
this.eventManager = new SynchronousEventManager();
|
|
@@ -214,7 +215,7 @@ const _Container = class _Container {
|
|
|
214
215
|
if (this.configuration.debug) {
|
|
215
216
|
return new ConsoleLogger(prefix);
|
|
216
217
|
}
|
|
217
|
-
return FilteredLogger.include(new ConsoleLogger(), ["error", "warn"]);
|
|
218
|
+
return new DeduplicatedLogger(FilteredLogger.include(new ConsoleLogger(prefix), ["error", "warn"]));
|
|
218
219
|
}
|
|
219
220
|
getTabStorage(namespace, ...subnamespace) {
|
|
220
221
|
return this.getGlobalTabStorage("external", namespace, ...subnamespace);
|
package/contentFetcher.cjs
CHANGED
|
@@ -28,8 +28,9 @@ var import_logging = require('./logging/index.cjs');
|
|
|
28
28
|
var import_apiKey = require('./apiKey.cjs');
|
|
29
29
|
var import_help = require('./help.cjs');
|
|
30
30
|
var ContentErrorType = /* @__PURE__ */ ((ContentErrorType2) => {
|
|
31
|
-
ContentErrorType2["TIMEOUT"] = "https://croct.help/
|
|
32
|
-
ContentErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/
|
|
31
|
+
ContentErrorType2["TIMEOUT"] = "https://croct.help/sdk/javascript/request-timeout";
|
|
32
|
+
ContentErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/sdk/javascript/unexpected-error";
|
|
33
|
+
ContentErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
|
|
33
34
|
return ContentErrorType2;
|
|
34
35
|
})(ContentErrorType || {});
|
|
35
36
|
class ContentError extends Error {
|
|
@@ -69,7 +70,7 @@ class ContentFetcher {
|
|
|
69
70
|
() => {
|
|
70
71
|
const response = {
|
|
71
72
|
title: `Content could not be loaded in time for slot '${slotId}'.`,
|
|
72
|
-
type: "https://croct.help/
|
|
73
|
+
type: "https://croct.help/sdk/javascript/request-timeout" /* TIMEOUT */,
|
|
73
74
|
detail: `The content took more than ${timeout}ms to load.`,
|
|
74
75
|
status: 408
|
|
75
76
|
// Request Timeout
|
|
@@ -85,6 +86,14 @@ class ContentFetcher {
|
|
|
85
86
|
const region = response.headers.get("X-Croct-Region");
|
|
86
87
|
const timing = response.headers.get("X-Croct-Timing");
|
|
87
88
|
this.logger.debug(`Content for slot '${slotId}' processed by region ${region} in ${timing}.`);
|
|
89
|
+
if (response.status === 202) {
|
|
90
|
+
return reject(new ContentError({
|
|
91
|
+
status: 202,
|
|
92
|
+
title: "Service is suspended.",
|
|
93
|
+
type: "https://croct.help/sdk/javascript/suspended-service" /* SUSPENDED_SERVICE */,
|
|
94
|
+
detail: import_help.Help.forStatusCode(202)
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
88
97
|
return response.json().then((body) => {
|
|
89
98
|
if (response.ok) {
|
|
90
99
|
return resolve(body);
|
|
@@ -102,7 +111,7 @@ class ContentFetcher {
|
|
|
102
111
|
reject(
|
|
103
112
|
new ContentError({
|
|
104
113
|
title: (0, import_error.formatMessage)(error),
|
|
105
|
-
type: "https://croct.help/
|
|
114
|
+
type: "https://croct.help/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
|
|
106
115
|
detail: "Please try again or contact Croct support if the error persists.",
|
|
107
116
|
status: 500
|
|
108
117
|
// Internal Server Error
|
package/contentFetcher.d.cts
CHANGED
|
@@ -12,8 +12,9 @@ type ErrorResponse = {
|
|
|
12
12
|
detail?: string;
|
|
13
13
|
};
|
|
14
14
|
declare enum ContentErrorType {
|
|
15
|
-
TIMEOUT = "https://croct.help/
|
|
16
|
-
UNEXPECTED_ERROR = "https://croct.help/
|
|
15
|
+
TIMEOUT = "https://croct.help/sdk/javascript/request-timeout",
|
|
16
|
+
UNEXPECTED_ERROR = "https://croct.help/sdk/javascript/unexpected-error",
|
|
17
|
+
SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service"
|
|
17
18
|
}
|
|
18
19
|
declare class ContentError<T extends ErrorResponse = ErrorResponse> extends Error {
|
|
19
20
|
readonly response: T;
|
package/contentFetcher.d.ts
CHANGED
|
@@ -12,8 +12,9 @@ type ErrorResponse = {
|
|
|
12
12
|
detail?: string;
|
|
13
13
|
};
|
|
14
14
|
declare enum ContentErrorType {
|
|
15
|
-
TIMEOUT = "https://croct.help/
|
|
16
|
-
UNEXPECTED_ERROR = "https://croct.help/
|
|
15
|
+
TIMEOUT = "https://croct.help/sdk/javascript/request-timeout",
|
|
16
|
+
UNEXPECTED_ERROR = "https://croct.help/sdk/javascript/unexpected-error",
|
|
17
|
+
SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service"
|
|
17
18
|
}
|
|
18
19
|
declare class ContentError<T extends ErrorResponse = ErrorResponse> extends Error {
|
|
19
20
|
readonly response: T;
|
package/contentFetcher.js
CHANGED
|
@@ -4,8 +4,9 @@ import { NullLogger } from "./logging/index.js";
|
|
|
4
4
|
import { ApiKey } from "./apiKey.js";
|
|
5
5
|
import { Help } from "./help.js";
|
|
6
6
|
var ContentErrorType = /* @__PURE__ */ ((ContentErrorType2) => {
|
|
7
|
-
ContentErrorType2["TIMEOUT"] = "https://croct.help/
|
|
8
|
-
ContentErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/
|
|
7
|
+
ContentErrorType2["TIMEOUT"] = "https://croct.help/sdk/javascript/request-timeout";
|
|
8
|
+
ContentErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/sdk/javascript/unexpected-error";
|
|
9
|
+
ContentErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
|
|
9
10
|
return ContentErrorType2;
|
|
10
11
|
})(ContentErrorType || {});
|
|
11
12
|
class ContentError extends Error {
|
|
@@ -45,7 +46,7 @@ class ContentFetcher {
|
|
|
45
46
|
() => {
|
|
46
47
|
const response = {
|
|
47
48
|
title: `Content could not be loaded in time for slot '${slotId}'.`,
|
|
48
|
-
type: "https://croct.help/
|
|
49
|
+
type: "https://croct.help/sdk/javascript/request-timeout" /* TIMEOUT */,
|
|
49
50
|
detail: `The content took more than ${timeout}ms to load.`,
|
|
50
51
|
status: 408
|
|
51
52
|
// Request Timeout
|
|
@@ -61,6 +62,14 @@ class ContentFetcher {
|
|
|
61
62
|
const region = response.headers.get("X-Croct-Region");
|
|
62
63
|
const timing = response.headers.get("X-Croct-Timing");
|
|
63
64
|
this.logger.debug(`Content for slot '${slotId}' processed by region ${region} in ${timing}.`);
|
|
65
|
+
if (response.status === 202) {
|
|
66
|
+
return reject(new ContentError({
|
|
67
|
+
status: 202,
|
|
68
|
+
title: "Service is suspended.",
|
|
69
|
+
type: "https://croct.help/sdk/javascript/suspended-service" /* SUSPENDED_SERVICE */,
|
|
70
|
+
detail: Help.forStatusCode(202)
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
64
73
|
return response.json().then((body) => {
|
|
65
74
|
if (response.ok) {
|
|
66
75
|
return resolve(body);
|
|
@@ -78,7 +87,7 @@ class ContentFetcher {
|
|
|
78
87
|
reject(
|
|
79
88
|
new ContentError({
|
|
80
89
|
title: formatMessage(error),
|
|
81
|
-
type: "https://croct.help/
|
|
90
|
+
type: "https://croct.help/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
|
|
82
91
|
detail: "Please try again or contact Croct support if the error persists.",
|
|
83
92
|
status: 500
|
|
84
93
|
// Internal Server Error
|
package/evaluator.cjs
CHANGED
|
@@ -30,13 +30,14 @@ var import_logging = require('./logging/index.cjs');
|
|
|
30
30
|
var import_apiKey = require('./apiKey.cjs');
|
|
31
31
|
var import_help = require('./help.cjs');
|
|
32
32
|
var EvaluationErrorType = /* @__PURE__ */ ((EvaluationErrorType2) => {
|
|
33
|
-
EvaluationErrorType2["TIMEOUT"] = "https://croct.help/
|
|
34
|
-
EvaluationErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/
|
|
35
|
-
EvaluationErrorType2["INVALID_QUERY"] = "https://croct.help/
|
|
36
|
-
EvaluationErrorType2["TOO_COMPLEX_QUERY"] = "https://croct.help/
|
|
37
|
-
EvaluationErrorType2["EVALUATION_FAILED"] = "https://croct.help/
|
|
38
|
-
EvaluationErrorType2["UNALLOWED_RESULT"] = "https://croct.help/
|
|
39
|
-
EvaluationErrorType2["
|
|
33
|
+
EvaluationErrorType2["TIMEOUT"] = "https://croct.help/sdk/javascript/request-timeout";
|
|
34
|
+
EvaluationErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/sdk/javascript/unexpected-error";
|
|
35
|
+
EvaluationErrorType2["INVALID_QUERY"] = "https://croct.help/sdk/javascript/invalid-query";
|
|
36
|
+
EvaluationErrorType2["TOO_COMPLEX_QUERY"] = "https://croct.help/sdk/javascript/too-complex-query";
|
|
37
|
+
EvaluationErrorType2["EVALUATION_FAILED"] = "https://croct.help/sdk/javascript/evaluation-failed";
|
|
38
|
+
EvaluationErrorType2["UNALLOWED_RESULT"] = "https://croct.help/sdk/javascript/unallowed-result";
|
|
39
|
+
EvaluationErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
|
|
40
|
+
EvaluationErrorType2["UNSERIALIZABLE_RESULT"] = "https://croct.help/sdk/javascript/unserializable-result";
|
|
40
41
|
return EvaluationErrorType2;
|
|
41
42
|
})(EvaluationErrorType || {});
|
|
42
43
|
class EvaluationError extends Error {
|
|
@@ -74,7 +75,7 @@ const _Evaluator = class _Evaluator {
|
|
|
74
75
|
title: "The query is too complex.",
|
|
75
76
|
status: 422,
|
|
76
77
|
// Unprocessable Entity
|
|
77
|
-
type: "https://croct.help/
|
|
78
|
+
type: "https://croct.help/sdk/javascript/too-complex-query" /* TOO_COMPLEX_QUERY */,
|
|
78
79
|
detail: `The query "${reference}" must be at most ${_Evaluator.MAX_QUERY_LENGTH} characters long, but it is ${length} characters long.`,
|
|
79
80
|
errors: [{
|
|
80
81
|
cause: "The query is longer than expected.",
|
|
@@ -98,7 +99,7 @@ const _Evaluator = class _Evaluator {
|
|
|
98
99
|
() => {
|
|
99
100
|
const response = {
|
|
100
101
|
title: `Evaluation could not be completed in time for query "${reference}".`,
|
|
101
|
-
type: "https://croct.help/
|
|
102
|
+
type: "https://croct.help/sdk/javascript/request-timeout" /* TIMEOUT */,
|
|
102
103
|
detail: `The evaluation took more than ${timeout}ms to complete.`,
|
|
103
104
|
status: 408
|
|
104
105
|
// Request Timeout
|
|
@@ -117,6 +118,14 @@ const _Evaluator = class _Evaluator {
|
|
|
117
118
|
this.logger.debug(
|
|
118
119
|
`Evaluation of the query "${reference}" processed by region ${region} in ${timing}.`
|
|
119
120
|
);
|
|
121
|
+
if (response.status === 202) {
|
|
122
|
+
return reject(new EvaluationError({
|
|
123
|
+
status: 202,
|
|
124
|
+
type: "https://croct.help/sdk/javascript/suspended-service" /* SUSPENDED_SERVICE */,
|
|
125
|
+
title: "Service is suspended.",
|
|
126
|
+
detail: import_help.Help.forStatusCode(202)
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
120
129
|
return response.json().then((body) => {
|
|
121
130
|
if (response.ok) {
|
|
122
131
|
return resolve(body);
|
|
@@ -124,9 +133,9 @@ const _Evaluator = class _Evaluator {
|
|
|
124
133
|
this.logHelp(response.status);
|
|
125
134
|
const problem = body;
|
|
126
135
|
switch (problem.type) {
|
|
127
|
-
case "https://croct.help/
|
|
128
|
-
case "https://croct.help/
|
|
129
|
-
case "https://croct.help/
|
|
136
|
+
case "https://croct.help/sdk/javascript/invalid-query" /* INVALID_QUERY */:
|
|
137
|
+
case "https://croct.help/sdk/javascript/evaluation-failed" /* EVALUATION_FAILED */:
|
|
138
|
+
case "https://croct.help/sdk/javascript/too-complex-query" /* TOO_COMPLEX_QUERY */:
|
|
130
139
|
reject(new QueryError(problem));
|
|
131
140
|
break;
|
|
132
141
|
default:
|
|
@@ -146,7 +155,7 @@ const _Evaluator = class _Evaluator {
|
|
|
146
155
|
reject(
|
|
147
156
|
new EvaluationError({
|
|
148
157
|
title: (0, import_error.formatMessage)(error),
|
|
149
|
-
type: "https://croct.help/
|
|
158
|
+
type: "https://croct.help/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
|
|
150
159
|
detail: "Please try again or contact Croct support if the error persists.",
|
|
151
160
|
status: 500
|
|
152
161
|
// Internal Server Error
|
package/evaluator.d.cts
CHANGED
|
@@ -36,13 +36,14 @@ type EvaluationOptions = {
|
|
|
36
36
|
extra?: ExtraFetchOptions;
|
|
37
37
|
};
|
|
38
38
|
declare enum EvaluationErrorType {
|
|
39
|
-
TIMEOUT = "https://croct.help/
|
|
40
|
-
UNEXPECTED_ERROR = "https://croct.help/
|
|
41
|
-
INVALID_QUERY = "https://croct.help/
|
|
42
|
-
TOO_COMPLEX_QUERY = "https://croct.help/
|
|
43
|
-
EVALUATION_FAILED = "https://croct.help/
|
|
44
|
-
UNALLOWED_RESULT = "https://croct.help/
|
|
45
|
-
|
|
39
|
+
TIMEOUT = "https://croct.help/sdk/javascript/request-timeout",
|
|
40
|
+
UNEXPECTED_ERROR = "https://croct.help/sdk/javascript/unexpected-error",
|
|
41
|
+
INVALID_QUERY = "https://croct.help/sdk/javascript/invalid-query",
|
|
42
|
+
TOO_COMPLEX_QUERY = "https://croct.help/sdk/javascript/too-complex-query",
|
|
43
|
+
EVALUATION_FAILED = "https://croct.help/sdk/javascript/evaluation-failed",
|
|
44
|
+
UNALLOWED_RESULT = "https://croct.help/sdk/javascript/unallowed-result",
|
|
45
|
+
SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
|
|
46
|
+
UNSERIALIZABLE_RESULT = "https://croct.help/sdk/javascript/unserializable-result"
|
|
46
47
|
}
|
|
47
48
|
type ErrorResponse = {
|
|
48
49
|
type: EvaluationErrorType;
|
package/evaluator.d.ts
CHANGED
|
@@ -36,13 +36,14 @@ type EvaluationOptions = {
|
|
|
36
36
|
extra?: ExtraFetchOptions;
|
|
37
37
|
};
|
|
38
38
|
declare enum EvaluationErrorType {
|
|
39
|
-
TIMEOUT = "https://croct.help/
|
|
40
|
-
UNEXPECTED_ERROR = "https://croct.help/
|
|
41
|
-
INVALID_QUERY = "https://croct.help/
|
|
42
|
-
TOO_COMPLEX_QUERY = "https://croct.help/
|
|
43
|
-
EVALUATION_FAILED = "https://croct.help/
|
|
44
|
-
UNALLOWED_RESULT = "https://croct.help/
|
|
45
|
-
|
|
39
|
+
TIMEOUT = "https://croct.help/sdk/javascript/request-timeout",
|
|
40
|
+
UNEXPECTED_ERROR = "https://croct.help/sdk/javascript/unexpected-error",
|
|
41
|
+
INVALID_QUERY = "https://croct.help/sdk/javascript/invalid-query",
|
|
42
|
+
TOO_COMPLEX_QUERY = "https://croct.help/sdk/javascript/too-complex-query",
|
|
43
|
+
EVALUATION_FAILED = "https://croct.help/sdk/javascript/evaluation-failed",
|
|
44
|
+
UNALLOWED_RESULT = "https://croct.help/sdk/javascript/unallowed-result",
|
|
45
|
+
SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
|
|
46
|
+
UNSERIALIZABLE_RESULT = "https://croct.help/sdk/javascript/unserializable-result"
|
|
46
47
|
}
|
|
47
48
|
type ErrorResponse = {
|
|
48
49
|
type: EvaluationErrorType;
|
package/evaluator.js
CHANGED
|
@@ -5,13 +5,14 @@ import { NullLogger } from "./logging/index.js";
|
|
|
5
5
|
import { ApiKey } from "./apiKey.js";
|
|
6
6
|
import { Help } from "./help.js";
|
|
7
7
|
var EvaluationErrorType = /* @__PURE__ */ ((EvaluationErrorType2) => {
|
|
8
|
-
EvaluationErrorType2["TIMEOUT"] = "https://croct.help/
|
|
9
|
-
EvaluationErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/
|
|
10
|
-
EvaluationErrorType2["INVALID_QUERY"] = "https://croct.help/
|
|
11
|
-
EvaluationErrorType2["TOO_COMPLEX_QUERY"] = "https://croct.help/
|
|
12
|
-
EvaluationErrorType2["EVALUATION_FAILED"] = "https://croct.help/
|
|
13
|
-
EvaluationErrorType2["UNALLOWED_RESULT"] = "https://croct.help/
|
|
14
|
-
EvaluationErrorType2["
|
|
8
|
+
EvaluationErrorType2["TIMEOUT"] = "https://croct.help/sdk/javascript/request-timeout";
|
|
9
|
+
EvaluationErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/sdk/javascript/unexpected-error";
|
|
10
|
+
EvaluationErrorType2["INVALID_QUERY"] = "https://croct.help/sdk/javascript/invalid-query";
|
|
11
|
+
EvaluationErrorType2["TOO_COMPLEX_QUERY"] = "https://croct.help/sdk/javascript/too-complex-query";
|
|
12
|
+
EvaluationErrorType2["EVALUATION_FAILED"] = "https://croct.help/sdk/javascript/evaluation-failed";
|
|
13
|
+
EvaluationErrorType2["UNALLOWED_RESULT"] = "https://croct.help/sdk/javascript/unallowed-result";
|
|
14
|
+
EvaluationErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
|
|
15
|
+
EvaluationErrorType2["UNSERIALIZABLE_RESULT"] = "https://croct.help/sdk/javascript/unserializable-result";
|
|
15
16
|
return EvaluationErrorType2;
|
|
16
17
|
})(EvaluationErrorType || {});
|
|
17
18
|
class EvaluationError extends Error {
|
|
@@ -49,7 +50,7 @@ const _Evaluator = class _Evaluator {
|
|
|
49
50
|
title: "The query is too complex.",
|
|
50
51
|
status: 422,
|
|
51
52
|
// Unprocessable Entity
|
|
52
|
-
type: "https://croct.help/
|
|
53
|
+
type: "https://croct.help/sdk/javascript/too-complex-query" /* TOO_COMPLEX_QUERY */,
|
|
53
54
|
detail: `The query "${reference}" must be at most ${_Evaluator.MAX_QUERY_LENGTH} characters long, but it is ${length} characters long.`,
|
|
54
55
|
errors: [{
|
|
55
56
|
cause: "The query is longer than expected.",
|
|
@@ -73,7 +74,7 @@ const _Evaluator = class _Evaluator {
|
|
|
73
74
|
() => {
|
|
74
75
|
const response = {
|
|
75
76
|
title: `Evaluation could not be completed in time for query "${reference}".`,
|
|
76
|
-
type: "https://croct.help/
|
|
77
|
+
type: "https://croct.help/sdk/javascript/request-timeout" /* TIMEOUT */,
|
|
77
78
|
detail: `The evaluation took more than ${timeout}ms to complete.`,
|
|
78
79
|
status: 408
|
|
79
80
|
// Request Timeout
|
|
@@ -92,6 +93,14 @@ const _Evaluator = class _Evaluator {
|
|
|
92
93
|
this.logger.debug(
|
|
93
94
|
`Evaluation of the query "${reference}" processed by region ${region} in ${timing}.`
|
|
94
95
|
);
|
|
96
|
+
if (response.status === 202) {
|
|
97
|
+
return reject(new EvaluationError({
|
|
98
|
+
status: 202,
|
|
99
|
+
type: "https://croct.help/sdk/javascript/suspended-service" /* SUSPENDED_SERVICE */,
|
|
100
|
+
title: "Service is suspended.",
|
|
101
|
+
detail: Help.forStatusCode(202)
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
95
104
|
return response.json().then((body) => {
|
|
96
105
|
if (response.ok) {
|
|
97
106
|
return resolve(body);
|
|
@@ -99,9 +108,9 @@ const _Evaluator = class _Evaluator {
|
|
|
99
108
|
this.logHelp(response.status);
|
|
100
109
|
const problem = body;
|
|
101
110
|
switch (problem.type) {
|
|
102
|
-
case "https://croct.help/
|
|
103
|
-
case "https://croct.help/
|
|
104
|
-
case "https://croct.help/
|
|
111
|
+
case "https://croct.help/sdk/javascript/invalid-query" /* INVALID_QUERY */:
|
|
112
|
+
case "https://croct.help/sdk/javascript/evaluation-failed" /* EVALUATION_FAILED */:
|
|
113
|
+
case "https://croct.help/sdk/javascript/too-complex-query" /* TOO_COMPLEX_QUERY */:
|
|
105
114
|
reject(new QueryError(problem));
|
|
106
115
|
break;
|
|
107
116
|
default:
|
|
@@ -121,7 +130,7 @@ const _Evaluator = class _Evaluator {
|
|
|
121
130
|
reject(
|
|
122
131
|
new EvaluationError({
|
|
123
132
|
title: formatMessage(error),
|
|
124
|
-
type: "https://croct.help/
|
|
133
|
+
type: "https://croct.help/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
|
|
125
134
|
detail: "Please try again or contact Croct support if the error persists.",
|
|
126
135
|
status: 500
|
|
127
136
|
// Internal Server Error
|
package/facade/trackerFacade.cjs
CHANGED
|
@@ -33,7 +33,8 @@ const eventSchemas = {
|
|
|
33
33
|
interestShown: import_schema.interestShown,
|
|
34
34
|
postViewed: import_schema.postViewed,
|
|
35
35
|
goalCompleted: import_schema.goalCompleted,
|
|
36
|
-
linkOpened: import_schema.linkOpened
|
|
36
|
+
linkOpened: import_schema.linkOpened,
|
|
37
|
+
leadGenerated: import_schema.leadGenerated
|
|
37
38
|
};
|
|
38
39
|
function validateEvent(event) {
|
|
39
40
|
const { type, ...payload } = event;
|
package/facade/trackerFacade.js
CHANGED
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
orderPlaced,
|
|
11
11
|
productViewed,
|
|
12
12
|
userSignedUp,
|
|
13
|
-
linkOpened
|
|
13
|
+
linkOpened,
|
|
14
|
+
leadGenerated
|
|
14
15
|
} from "../schema/index.js";
|
|
15
16
|
const eventSchemas = {
|
|
16
17
|
cartViewed,
|
|
@@ -23,7 +24,8 @@ const eventSchemas = {
|
|
|
23
24
|
interestShown,
|
|
24
25
|
postViewed,
|
|
25
26
|
goalCompleted,
|
|
26
|
-
linkOpened
|
|
27
|
+
linkOpened,
|
|
28
|
+
leadGenerated
|
|
27
29
|
};
|
|
28
30
|
function validateEvent(event) {
|
|
29
31
|
const { type, ...payload } = event;
|
package/help.cjs
CHANGED
|
@@ -24,6 +24,8 @@ var Help;
|
|
|
24
24
|
((Help2) => {
|
|
25
25
|
function forStatusCode(statusCode) {
|
|
26
26
|
switch (statusCode) {
|
|
27
|
+
case 202:
|
|
28
|
+
return "The service is temporarily suspended. For help, see https://croct.help/sdk/javascript/suspended-service";
|
|
27
29
|
case 401:
|
|
28
30
|
return "The request was not authorized, most likely due to invalid credentials. For help, see https://croct.help/sdk/javascript/invalid-credentials";
|
|
29
31
|
case 403:
|
package/help.d.cts
CHANGED
package/help.d.ts
CHANGED
package/help.js
CHANGED
|
@@ -2,6 +2,8 @@ var Help;
|
|
|
2
2
|
((Help2) => {
|
|
3
3
|
function forStatusCode(statusCode) {
|
|
4
4
|
switch (statusCode) {
|
|
5
|
+
case 202:
|
|
6
|
+
return "The service is temporarily suspended. For help, see https://croct.help/sdk/javascript/suspended-service";
|
|
5
7
|
case 401:
|
|
6
8
|
return "The request was not authorized, most likely due to invalid credentials. For help, see https://croct.help/sdk/javascript/invalid-credentials";
|
|
7
9
|
case 403:
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var deduplicatedLogger_exports = {};
|
|
19
|
+
__export(deduplicatedLogger_exports, {
|
|
20
|
+
DeduplicatedLogger: () => DeduplicatedLogger
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(deduplicatedLogger_exports);
|
|
23
|
+
class DeduplicatedLogger {
|
|
24
|
+
constructor(logger, maxSize = 100) {
|
|
25
|
+
this.recentMessages = /* @__PURE__ */ new Set();
|
|
26
|
+
this.logger = logger;
|
|
27
|
+
this.maxSize = maxSize;
|
|
28
|
+
if (maxSize <= 0 || !Number.isInteger(maxSize)) {
|
|
29
|
+
throw new Error("maxSize must be greater than 0");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
debug(message) {
|
|
33
|
+
if (this.isDuplicated("debug", message)) {
|
|
34
|
+
this.logger.debug(message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
info(message) {
|
|
38
|
+
if (this.isDuplicated("info", message)) {
|
|
39
|
+
this.logger.info(message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
warn(message) {
|
|
43
|
+
if (this.isDuplicated("warn", message)) {
|
|
44
|
+
this.logger.warn(message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
error(message) {
|
|
48
|
+
if (this.isDuplicated("error", message)) {
|
|
49
|
+
this.logger.error(message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
isDuplicated(level, message) {
|
|
53
|
+
const key = `${level}:${message}`;
|
|
54
|
+
if (this.recentMessages.has(key)) {
|
|
55
|
+
this.recentMessages.delete(key);
|
|
56
|
+
this.recentMessages.add(key);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (this.recentMessages.size >= this.maxSize) {
|
|
60
|
+
const oldest = this.recentMessages.values().next().value;
|
|
61
|
+
this.recentMessages.delete(oldest);
|
|
62
|
+
}
|
|
63
|
+
this.recentMessages.add(key);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
DeduplicatedLogger
|
|
70
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from './logger.cjs';
|
|
2
|
+
|
|
3
|
+
declare class DeduplicatedLogger implements Logger {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly recentMessages;
|
|
6
|
+
private readonly maxSize;
|
|
7
|
+
constructor(logger: Logger, maxSize?: number);
|
|
8
|
+
debug(message: string): void;
|
|
9
|
+
info(message: string): void;
|
|
10
|
+
warn(message: string): void;
|
|
11
|
+
error(message: string): void;
|
|
12
|
+
private isDuplicated;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { DeduplicatedLogger };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from './logger.js';
|
|
2
|
+
|
|
3
|
+
declare class DeduplicatedLogger implements Logger {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly recentMessages;
|
|
6
|
+
private readonly maxSize;
|
|
7
|
+
constructor(logger: Logger, maxSize?: number);
|
|
8
|
+
debug(message: string): void;
|
|
9
|
+
info(message: string): void;
|
|
10
|
+
warn(message: string): void;
|
|
11
|
+
error(message: string): void;
|
|
12
|
+
private isDuplicated;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { DeduplicatedLogger };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class DeduplicatedLogger {
|
|
2
|
+
constructor(logger, maxSize = 100) {
|
|
3
|
+
this.recentMessages = /* @__PURE__ */ new Set();
|
|
4
|
+
this.logger = logger;
|
|
5
|
+
this.maxSize = maxSize;
|
|
6
|
+
if (maxSize <= 0 || !Number.isInteger(maxSize)) {
|
|
7
|
+
throw new Error("maxSize must be greater than 0");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
debug(message) {
|
|
11
|
+
if (this.isDuplicated("debug", message)) {
|
|
12
|
+
this.logger.debug(message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
info(message) {
|
|
16
|
+
if (this.isDuplicated("info", message)) {
|
|
17
|
+
this.logger.info(message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
warn(message) {
|
|
21
|
+
if (this.isDuplicated("warn", message)) {
|
|
22
|
+
this.logger.warn(message);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
error(message) {
|
|
26
|
+
if (this.isDuplicated("error", message)) {
|
|
27
|
+
this.logger.error(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
isDuplicated(level, message) {
|
|
31
|
+
const key = `${level}:${message}`;
|
|
32
|
+
if (this.recentMessages.has(key)) {
|
|
33
|
+
this.recentMessages.delete(key);
|
|
34
|
+
this.recentMessages.add(key);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (this.recentMessages.size >= this.maxSize) {
|
|
38
|
+
const oldest = this.recentMessages.values().next().value;
|
|
39
|
+
this.recentMessages.delete(oldest);
|
|
40
|
+
}
|
|
41
|
+
this.recentMessages.add(key);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
DeduplicatedLogger
|
|
47
|
+
};
|
package/package.json
CHANGED
package/schema/eventSchemas.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(eventSchemas_exports, {
|
|
|
23
23
|
eventOccurred: () => eventOccurred,
|
|
24
24
|
goalCompleted: () => goalCompleted,
|
|
25
25
|
interestShown: () => interestShown,
|
|
26
|
+
leadGenerated: () => leadGenerated,
|
|
26
27
|
linkOpened: () => linkOpened,
|
|
27
28
|
orderPlaced: () => orderPlaced,
|
|
28
29
|
postViewed: () => postViewed,
|
|
@@ -145,6 +146,22 @@ const eventOccurred = new import_validation.ObjectType({
|
|
|
145
146
|
})
|
|
146
147
|
}
|
|
147
148
|
});
|
|
149
|
+
const leadGenerated = new import_validation.ObjectType({
|
|
150
|
+
properties: {
|
|
151
|
+
leadId: new import_validation.StringType({
|
|
152
|
+
minLength: 1,
|
|
153
|
+
maxLength: 100
|
|
154
|
+
}),
|
|
155
|
+
currency: new import_validation.StringType({
|
|
156
|
+
maxLength: 10,
|
|
157
|
+
minLength: 1
|
|
158
|
+
}),
|
|
159
|
+
value: new import_validation.NumberType({
|
|
160
|
+
minimum: 0
|
|
161
|
+
}),
|
|
162
|
+
lead: import_userSchema.userProfileSchema
|
|
163
|
+
}
|
|
164
|
+
});
|
|
148
165
|
// Annotate the CommonJS export names for ESM import in node:
|
|
149
166
|
0 && (module.exports = {
|
|
150
167
|
cartModified,
|
|
@@ -153,6 +170,7 @@ const eventOccurred = new import_validation.ObjectType({
|
|
|
153
170
|
eventOccurred,
|
|
154
171
|
goalCompleted,
|
|
155
172
|
interestShown,
|
|
173
|
+
leadGenerated,
|
|
156
174
|
linkOpened,
|
|
157
175
|
orderPlaced,
|
|
158
176
|
postViewed,
|
|
@@ -12,5 +12,6 @@ declare const interestShown: ObjectType;
|
|
|
12
12
|
declare const postViewed: ObjectType;
|
|
13
13
|
declare const linkOpened: ObjectType;
|
|
14
14
|
declare const eventOccurred: ObjectType;
|
|
15
|
+
declare const leadGenerated: ObjectType;
|
|
15
16
|
|
|
16
|
-
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp };
|
|
17
|
+
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, leadGenerated, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp };
|
package/schema/eventSchemas.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ declare const interestShown: ObjectType;
|
|
|
12
12
|
declare const postViewed: ObjectType;
|
|
13
13
|
declare const linkOpened: ObjectType;
|
|
14
14
|
declare const eventOccurred: ObjectType;
|
|
15
|
+
declare const leadGenerated: ObjectType;
|
|
15
16
|
|
|
16
|
-
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp };
|
|
17
|
+
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, leadGenerated, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp };
|
package/schema/eventSchemas.js
CHANGED
|
@@ -121,6 +121,22 @@ const eventOccurred = new ObjectType({
|
|
|
121
121
|
})
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
|
+
const leadGenerated = new ObjectType({
|
|
125
|
+
properties: {
|
|
126
|
+
leadId: new StringType({
|
|
127
|
+
minLength: 1,
|
|
128
|
+
maxLength: 100
|
|
129
|
+
}),
|
|
130
|
+
currency: new StringType({
|
|
131
|
+
maxLength: 10,
|
|
132
|
+
minLength: 1
|
|
133
|
+
}),
|
|
134
|
+
value: new NumberType({
|
|
135
|
+
minimum: 0
|
|
136
|
+
}),
|
|
137
|
+
lead: userProfileSchema
|
|
138
|
+
}
|
|
139
|
+
});
|
|
124
140
|
export {
|
|
125
141
|
cartModified,
|
|
126
142
|
cartViewed,
|
|
@@ -128,6 +144,7 @@ export {
|
|
|
128
144
|
eventOccurred,
|
|
129
145
|
goalCompleted,
|
|
130
146
|
interestShown,
|
|
147
|
+
leadGenerated,
|
|
131
148
|
linkOpened,
|
|
132
149
|
orderPlaced,
|
|
133
150
|
postViewed,
|
package/schema/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ export { tokenScopeSchema } from './contextSchemas.cjs';
|
|
|
2
2
|
export { cart, cartItem, order, orderItem, productDetails } from './ecommerceSchemas.cjs';
|
|
3
3
|
export { evaluationOptionsSchema } from './evaluatorSchemas.cjs';
|
|
4
4
|
export { fetchOptionsSchema } from './contentFetcherSchemas.cjs';
|
|
5
|
-
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp } from './eventSchemas.cjs';
|
|
5
|
+
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, leadGenerated, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp } from './eventSchemas.cjs';
|
|
6
6
|
export { loggerSchema } from './loggerSchema.cjs';
|
|
7
7
|
export { addOperation, clearOperation, combineOperation, decrementOperation, incrementOperation, mergeOperation, removeOperation, setOperation, unsetOperation } from './operationSchemas.cjs';
|
|
8
8
|
export { sdkFacadeConfigurationSchema } from './sdkFacadeSchemas.cjs';
|
package/schema/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { tokenScopeSchema } from './contextSchemas.js';
|
|
|
2
2
|
export { cart, cartItem, order, orderItem, productDetails } from './ecommerceSchemas.js';
|
|
3
3
|
export { evaluationOptionsSchema } from './evaluatorSchemas.js';
|
|
4
4
|
export { fetchOptionsSchema } from './contentFetcherSchemas.js';
|
|
5
|
-
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp } from './eventSchemas.js';
|
|
5
|
+
export { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, interestShown, leadGenerated, linkOpened, orderPlaced, postViewed, productViewed, userSignedUp } from './eventSchemas.js';
|
|
6
6
|
export { loggerSchema } from './loggerSchema.js';
|
|
7
7
|
export { addOperation, clearOperation, combineOperation, decrementOperation, incrementOperation, mergeOperation, removeOperation, setOperation, unsetOperation } from './operationSchemas.js';
|
|
8
8
|
export { sdkFacadeConfigurationSchema } from './sdkFacadeSchemas.js';
|
package/tracker.cjs
CHANGED
|
@@ -314,6 +314,21 @@ class Tracker {
|
|
|
314
314
|
};
|
|
315
315
|
}
|
|
316
316
|
createBeaconPayload(event) {
|
|
317
|
+
if (event.type === "leadGenerated" && event.lead !== void 0) {
|
|
318
|
+
const { lead, ...payload2 } = event;
|
|
319
|
+
return {
|
|
320
|
+
...payload2,
|
|
321
|
+
patch: {
|
|
322
|
+
operations: [
|
|
323
|
+
{
|
|
324
|
+
type: "merge",
|
|
325
|
+
path: ".",
|
|
326
|
+
value: lead
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
317
332
|
if (!(0, import_trackingEvents.isIdentifiedUserEvent)(event)) {
|
|
318
333
|
return event;
|
|
319
334
|
}
|
package/tracker.js
CHANGED
|
@@ -295,6 +295,21 @@ class Tracker {
|
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
297
|
createBeaconPayload(event) {
|
|
298
|
+
if (event.type === "leadGenerated" && event.lead !== void 0) {
|
|
299
|
+
const { lead, ...payload2 } = event;
|
|
300
|
+
return {
|
|
301
|
+
...payload2,
|
|
302
|
+
patch: {
|
|
303
|
+
operations: [
|
|
304
|
+
{
|
|
305
|
+
type: "merge",
|
|
306
|
+
path: ".",
|
|
307
|
+
value: lead
|
|
308
|
+
}
|
|
309
|
+
]
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
298
313
|
if (!isIdentifiedUserEvent(event)) {
|
|
299
314
|
return event;
|
|
300
315
|
}
|
package/trackingEvents.cjs
CHANGED
package/trackingEvents.d.cts
CHANGED
|
@@ -73,8 +73,8 @@ declare const cartEventTypes: readonly ["cartModified", "cartViewed", "checkoutS
|
|
|
73
73
|
declare const ecommerceEventTypes: readonly ["cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed"];
|
|
74
74
|
declare const identifiedUserEventTypes: string[];
|
|
75
75
|
declare const userEventTypes: readonly [...string[], "userProfileChanged"];
|
|
76
|
-
declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
|
|
77
|
-
declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
|
|
76
|
+
declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened", "leadGenerated"];
|
|
77
|
+
declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened", "leadGenerated"];
|
|
78
78
|
interface BaseEvent {
|
|
79
79
|
type: string;
|
|
80
80
|
}
|
|
@@ -237,7 +237,14 @@ interface LinkOpened extends BaseEvent {
|
|
|
237
237
|
type: 'linkOpened';
|
|
238
238
|
link: string;
|
|
239
239
|
}
|
|
240
|
-
|
|
240
|
+
interface LeadGenerated extends BaseEvent {
|
|
241
|
+
type: 'leadGenerated';
|
|
242
|
+
leadId?: string;
|
|
243
|
+
currency?: string;
|
|
244
|
+
value?: number;
|
|
245
|
+
lead?: UserProfile;
|
|
246
|
+
}
|
|
247
|
+
type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed | LinkOpened | LeadGenerated;
|
|
241
248
|
type EventMap = {
|
|
242
249
|
tabVisibilityChanged: TabVisibilityChanged;
|
|
243
250
|
tabUrlChanged: TabUrlChanged;
|
|
@@ -260,6 +267,7 @@ type EventMap = {
|
|
|
260
267
|
postViewed: PostViewed;
|
|
261
268
|
eventOccurred: EventOccurred;
|
|
262
269
|
linkOpened: LinkOpened;
|
|
270
|
+
leadGenerated: LeadGenerated;
|
|
263
271
|
};
|
|
264
272
|
type TrackingEventType = keyof EventMap;
|
|
265
273
|
type TrackingEvent<T extends TrackingEventType = TrackingEventType> = T extends TrackingEventType ? EventMap[T] : EventMap[TrackingEventType];
|
|
@@ -283,6 +291,7 @@ type ExternalEventMap = {
|
|
|
283
291
|
postViewed: PostViewed;
|
|
284
292
|
linkOpened: LinkOpened;
|
|
285
293
|
eventOccurred: EventOccurred;
|
|
294
|
+
leadGenerated: LeadGenerated;
|
|
286
295
|
};
|
|
287
296
|
type ExternalTrackingEventType = keyof ExternalEventMap;
|
|
288
297
|
type ExternalTrackingEvent<T extends ExternalTrackingEventType = ExternalTrackingEventType> = T extends ExternalTrackingEventType ? ExternalEventMap[T] : ExternalEventMap[ExternalTrackingEventType];
|
|
@@ -296,7 +305,9 @@ type TrackingEventContext = {
|
|
|
296
305
|
[key: string]: string;
|
|
297
306
|
};
|
|
298
307
|
};
|
|
299
|
-
type BeaconPayload = Exclude<TrackingEvent, IdentifiedUserEvent> | DistributiveOmit<Exclude<IdentifiedUserEvent, UserSignedUp>, 'userId'> & Record<'externalUserId', IdentifiedUserEvent['userId']> | Omit<UserSignedUp, 'userId' | 'profile'> & Record<'externalUserId', IdentifiedUserEvent['userId']> & {
|
|
308
|
+
type BeaconPayload = Exclude<TrackingEvent, IdentifiedUserEvent | LeadGenerated> | DistributiveOmit<Exclude<IdentifiedUserEvent, UserSignedUp>, 'userId'> & Record<'externalUserId', IdentifiedUserEvent['userId']> | Omit<UserSignedUp, 'userId' | 'profile'> & Record<'externalUserId', IdentifiedUserEvent['userId']> & {
|
|
309
|
+
patch?: Patch;
|
|
310
|
+
} | Omit<LeadGenerated, 'lead'> & {
|
|
300
311
|
patch?: Patch;
|
|
301
312
|
};
|
|
302
313
|
type Beacon = {
|
|
@@ -306,4 +317,4 @@ type Beacon = {
|
|
|
306
317
|
payload: BeaconPayload;
|
|
307
318
|
};
|
|
308
319
|
|
|
309
|
-
export { type Beacon, type BeaconPayload, type Cart, type CartEvent, type CartEventType, type CartItem, type CartModified, type CartViewed, type CheckoutStarted, type EcommerceEvent, type EventOccurred, type ExternalTrackingEvent, type ExternalTrackingEventPayload, type ExternalTrackingEventType, type Gender, type GoalCompleted, type IdentifiedUserEvent, type InterestShown, type LinkOpened, type MiscEvent, type NothingChanged, type Order, type OrderItem, type OrderPlaced, type OrderStatus, type PageEvent, type PageEventType, type PageLoaded, type PageOpened, type PartialTrackingEvent, type PostDetails, type PostViewed, type ProductDetails, type ProductViewed, type SessionAttributesChanged, type TabEvent, type TabEventType, type TabOpened, type TabUrlChanged, type TabVisibilityChanged, type TrackingEvent, type TrackingEventContext, type TrackingEventType, type UserEvent, type UserProfile, type UserProfileChanged, type UserSignedIn, type UserSignedOut, type UserSignedUp, cartEventTypes, ecommerceEventTypes, eventTypes, identifiedUserEventTypes, isCartPartialEvent, isIdentifiedUserEvent, miscEventTypes, pageEventTypes, tabEventTypes, userEventTypes };
|
|
320
|
+
export { type Beacon, type BeaconPayload, type Cart, type CartEvent, type CartEventType, type CartItem, type CartModified, type CartViewed, type CheckoutStarted, type EcommerceEvent, type EventOccurred, type ExternalTrackingEvent, type ExternalTrackingEventPayload, type ExternalTrackingEventType, type Gender, type GoalCompleted, type IdentifiedUserEvent, type InterestShown, type LeadGenerated, type LinkOpened, type MiscEvent, type NothingChanged, type Order, type OrderItem, type OrderPlaced, type OrderStatus, type PageEvent, type PageEventType, type PageLoaded, type PageOpened, type PartialTrackingEvent, type PostDetails, type PostViewed, type ProductDetails, type ProductViewed, type SessionAttributesChanged, type TabEvent, type TabEventType, type TabOpened, type TabUrlChanged, type TabVisibilityChanged, type TrackingEvent, type TrackingEventContext, type TrackingEventType, type UserEvent, type UserProfile, type UserProfileChanged, type UserSignedIn, type UserSignedOut, type UserSignedUp, cartEventTypes, ecommerceEventTypes, eventTypes, identifiedUserEventTypes, isCartPartialEvent, isIdentifiedUserEvent, miscEventTypes, pageEventTypes, tabEventTypes, userEventTypes };
|
package/trackingEvents.d.ts
CHANGED
|
@@ -73,8 +73,8 @@ declare const cartEventTypes: readonly ["cartModified", "cartViewed", "checkoutS
|
|
|
73
73
|
declare const ecommerceEventTypes: readonly ["cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed"];
|
|
74
74
|
declare const identifiedUserEventTypes: string[];
|
|
75
75
|
declare const userEventTypes: readonly [...string[], "userProfileChanged"];
|
|
76
|
-
declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
|
|
77
|
-
declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
|
|
76
|
+
declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened", "leadGenerated"];
|
|
77
|
+
declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened", "leadGenerated"];
|
|
78
78
|
interface BaseEvent {
|
|
79
79
|
type: string;
|
|
80
80
|
}
|
|
@@ -237,7 +237,14 @@ interface LinkOpened extends BaseEvent {
|
|
|
237
237
|
type: 'linkOpened';
|
|
238
238
|
link: string;
|
|
239
239
|
}
|
|
240
|
-
|
|
240
|
+
interface LeadGenerated extends BaseEvent {
|
|
241
|
+
type: 'leadGenerated';
|
|
242
|
+
leadId?: string;
|
|
243
|
+
currency?: string;
|
|
244
|
+
value?: number;
|
|
245
|
+
lead?: UserProfile;
|
|
246
|
+
}
|
|
247
|
+
type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed | LinkOpened | LeadGenerated;
|
|
241
248
|
type EventMap = {
|
|
242
249
|
tabVisibilityChanged: TabVisibilityChanged;
|
|
243
250
|
tabUrlChanged: TabUrlChanged;
|
|
@@ -260,6 +267,7 @@ type EventMap = {
|
|
|
260
267
|
postViewed: PostViewed;
|
|
261
268
|
eventOccurred: EventOccurred;
|
|
262
269
|
linkOpened: LinkOpened;
|
|
270
|
+
leadGenerated: LeadGenerated;
|
|
263
271
|
};
|
|
264
272
|
type TrackingEventType = keyof EventMap;
|
|
265
273
|
type TrackingEvent<T extends TrackingEventType = TrackingEventType> = T extends TrackingEventType ? EventMap[T] : EventMap[TrackingEventType];
|
|
@@ -283,6 +291,7 @@ type ExternalEventMap = {
|
|
|
283
291
|
postViewed: PostViewed;
|
|
284
292
|
linkOpened: LinkOpened;
|
|
285
293
|
eventOccurred: EventOccurred;
|
|
294
|
+
leadGenerated: LeadGenerated;
|
|
286
295
|
};
|
|
287
296
|
type ExternalTrackingEventType = keyof ExternalEventMap;
|
|
288
297
|
type ExternalTrackingEvent<T extends ExternalTrackingEventType = ExternalTrackingEventType> = T extends ExternalTrackingEventType ? ExternalEventMap[T] : ExternalEventMap[ExternalTrackingEventType];
|
|
@@ -296,7 +305,9 @@ type TrackingEventContext = {
|
|
|
296
305
|
[key: string]: string;
|
|
297
306
|
};
|
|
298
307
|
};
|
|
299
|
-
type BeaconPayload = Exclude<TrackingEvent, IdentifiedUserEvent> | DistributiveOmit<Exclude<IdentifiedUserEvent, UserSignedUp>, 'userId'> & Record<'externalUserId', IdentifiedUserEvent['userId']> | Omit<UserSignedUp, 'userId' | 'profile'> & Record<'externalUserId', IdentifiedUserEvent['userId']> & {
|
|
308
|
+
type BeaconPayload = Exclude<TrackingEvent, IdentifiedUserEvent | LeadGenerated> | DistributiveOmit<Exclude<IdentifiedUserEvent, UserSignedUp>, 'userId'> & Record<'externalUserId', IdentifiedUserEvent['userId']> | Omit<UserSignedUp, 'userId' | 'profile'> & Record<'externalUserId', IdentifiedUserEvent['userId']> & {
|
|
309
|
+
patch?: Patch;
|
|
310
|
+
} | Omit<LeadGenerated, 'lead'> & {
|
|
300
311
|
patch?: Patch;
|
|
301
312
|
};
|
|
302
313
|
type Beacon = {
|
|
@@ -306,4 +317,4 @@ type Beacon = {
|
|
|
306
317
|
payload: BeaconPayload;
|
|
307
318
|
};
|
|
308
319
|
|
|
309
|
-
export { type Beacon, type BeaconPayload, type Cart, type CartEvent, type CartEventType, type CartItem, type CartModified, type CartViewed, type CheckoutStarted, type EcommerceEvent, type EventOccurred, type ExternalTrackingEvent, type ExternalTrackingEventPayload, type ExternalTrackingEventType, type Gender, type GoalCompleted, type IdentifiedUserEvent, type InterestShown, type LinkOpened, type MiscEvent, type NothingChanged, type Order, type OrderItem, type OrderPlaced, type OrderStatus, type PageEvent, type PageEventType, type PageLoaded, type PageOpened, type PartialTrackingEvent, type PostDetails, type PostViewed, type ProductDetails, type ProductViewed, type SessionAttributesChanged, type TabEvent, type TabEventType, type TabOpened, type TabUrlChanged, type TabVisibilityChanged, type TrackingEvent, type TrackingEventContext, type TrackingEventType, type UserEvent, type UserProfile, type UserProfileChanged, type UserSignedIn, type UserSignedOut, type UserSignedUp, cartEventTypes, ecommerceEventTypes, eventTypes, identifiedUserEventTypes, isCartPartialEvent, isIdentifiedUserEvent, miscEventTypes, pageEventTypes, tabEventTypes, userEventTypes };
|
|
320
|
+
export { type Beacon, type BeaconPayload, type Cart, type CartEvent, type CartEventType, type CartItem, type CartModified, type CartViewed, type CheckoutStarted, type EcommerceEvent, type EventOccurred, type ExternalTrackingEvent, type ExternalTrackingEventPayload, type ExternalTrackingEventType, type Gender, type GoalCompleted, type IdentifiedUserEvent, type InterestShown, type LeadGenerated, type LinkOpened, type MiscEvent, type NothingChanged, type Order, type OrderItem, type OrderPlaced, type OrderStatus, type PageEvent, type PageEventType, type PageLoaded, type PageOpened, type PartialTrackingEvent, type PostDetails, type PostViewed, type ProductDetails, type ProductViewed, type SessionAttributesChanged, type TabEvent, type TabEventType, type TabOpened, type TabUrlChanged, type TabVisibilityChanged, type TrackingEvent, type TrackingEventContext, type TrackingEventType, type UserEvent, type UserProfile, type UserProfileChanged, type UserSignedIn, type UserSignedOut, type UserSignedUp, cartEventTypes, ecommerceEventTypes, eventTypes, identifiedUserEventTypes, isCartPartialEvent, isIdentifiedUserEvent, miscEventTypes, pageEventTypes, tabEventTypes, userEventTypes };
|