@croct/sdk 0.22.2 → 0.22.3
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/channel/httpBeaconChannel.cjs +12 -5
- package/channel/httpBeaconChannel.d.cts +5 -1
- package/channel/httpBeaconChannel.d.ts +5 -1
- package/channel/httpBeaconChannel.js +10 -4
- package/constants.cjs +1 -1
- package/constants.d.cts +2 -2
- package/constants.d.ts +2 -2
- package/constants.js +1 -1
- package/container.d.cts +3 -1
- package/container.d.ts +3 -1
- package/contentFetcher.cjs +22 -9
- package/contentFetcher.d.cts +19 -11
- package/contentFetcher.d.ts +19 -11
- package/contentFetcher.js +20 -8
- package/context.d.cts +2 -1
- package/context.d.ts +2 -1
- package/error.d.cts +8 -1
- package/error.d.ts +8 -1
- package/evaluator.cjs +62 -14
- package/evaluator.d.cts +35 -15
- package/evaluator.d.ts +35 -15
- package/evaluator.js +61 -14
- package/facade/contentFetcherFacade.d.cts +2 -0
- package/facade/contentFetcherFacade.d.ts +2 -0
- package/facade/evaluatorFacade.cjs +10 -18
- package/facade/evaluatorFacade.d.cts +2 -0
- package/facade/evaluatorFacade.d.ts +2 -0
- package/facade/evaluatorFacade.js +10 -18
- package/facade/index.d.cts +2 -0
- package/facade/index.d.ts +2 -0
- package/facade/sdkFacade.d.cts +3 -1
- package/facade/sdkFacade.d.ts +3 -1
- package/facade/sessionFacade.d.cts +1 -0
- package/facade/sessionFacade.d.ts +1 -0
- package/facade/sessionPatch.d.cts +1 -0
- package/facade/sessionPatch.d.ts +1 -0
- package/facade/trackerFacade.d.cts +1 -0
- package/facade/trackerFacade.d.ts +1 -0
- package/facade/userFacade.d.cts +1 -0
- package/facade/userFacade.d.ts +1 -0
- package/facade/userPatch.d.cts +1 -0
- package/facade/userPatch.d.ts +1 -0
- package/help.cjs +16 -4
- package/help.d.cts +4 -1
- package/help.d.ts +4 -1
- package/help.js +16 -4
- package/index.d.cts +2 -0
- package/index.d.ts +2 -0
- package/interactionMonitor.cjs +42 -9
- package/interactionMonitor.d.cts +1 -0
- package/interactionMonitor.d.ts +1 -0
- package/interactionMonitor.js +42 -9
- package/package.json +1 -1
- package/sdk.d.cts +3 -1
- package/sdk.d.ts +3 -1
- package/tab.cjs +2 -5
- package/tab.d.cts +2 -2
- package/tab.d.ts +2 -2
- package/tab.js +2 -5
- package/tracker.d.cts +1 -0
- package/tracker.d.ts +1 -0
- package/url.cjs +30 -0
- package/url.d.cts +12 -0
- package/url.d.ts +12 -0
- package/url.js +7 -0
package/evaluator.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from '@croct/json';
|
|
2
2
|
import { Token } from './token/token.cjs';
|
|
3
|
+
import { ApiProblem } from './error.cjs';
|
|
3
4
|
import { Location } from './sourceLocation.cjs';
|
|
4
5
|
import { Logger } from './logging/logger.cjs';
|
|
5
6
|
import { ApiKey } from './apiKey.cjs';
|
|
7
|
+
import { UrlSanitizer } from './url.cjs';
|
|
6
8
|
|
|
7
9
|
type Campaign = {
|
|
8
10
|
name?: string;
|
|
@@ -16,12 +18,38 @@ type Page = {
|
|
|
16
18
|
title?: string;
|
|
17
19
|
referrer?: string;
|
|
18
20
|
};
|
|
21
|
+
type PageEvaluationContext = Omit<EvaluationContext, 'page'> & Required<Pick<EvaluationContext, 'page'>>;
|
|
22
|
+
type PageContextOptions = {
|
|
23
|
+
urlSanitizer?: UrlSanitizer;
|
|
24
|
+
};
|
|
19
25
|
type EvaluationContext = {
|
|
20
26
|
timeZone?: string;
|
|
21
27
|
campaign?: Campaign;
|
|
22
28
|
page?: Page;
|
|
23
29
|
attributes?: JsonObject;
|
|
24
30
|
};
|
|
31
|
+
declare namespace EvaluationContext {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a context describing the page an evaluation refers to.
|
|
34
|
+
*
|
|
35
|
+
* The context describes the page currently open in the browser, if any,
|
|
36
|
+
* extended with the given context. Values provided by the caller take
|
|
37
|
+
* precedence over the captured ones, so the context can describe a page
|
|
38
|
+
* other than the one running the code, as in server-side evaluations.
|
|
39
|
+
*
|
|
40
|
+
* The URLs of the resulting page are sanitized, whether captured or
|
|
41
|
+
* provided, so the context never carries what the sanitizer strips.
|
|
42
|
+
*
|
|
43
|
+
* @param base The context to extend the captured one with.
|
|
44
|
+
* @param options The options for creating the context.
|
|
45
|
+
*
|
|
46
|
+
* @returns The context describing the page.
|
|
47
|
+
*
|
|
48
|
+
* @throws {TypeError} If the URL of the page is not absolute.
|
|
49
|
+
*/
|
|
50
|
+
function createPageContext(base: PageEvaluationContext, options?: PageContextOptions): PageEvaluationContext;
|
|
51
|
+
function createPageContext(base?: EvaluationContext, options?: PageContextOptions): EvaluationContext;
|
|
52
|
+
}
|
|
25
53
|
type AllowedFetchOptions = Exclude<keyof RequestInit, 'method' | 'body' | 'headers' | 'signal'>;
|
|
26
54
|
type ExtraFetchOptions<T extends keyof RequestInit = AllowedFetchOptions> = Pick<RequestInit, T> & {
|
|
27
55
|
[key in Exclude<keyof RequestInit, T>]?: never;
|
|
@@ -37,21 +65,13 @@ type EvaluationOptions = {
|
|
|
37
65
|
};
|
|
38
66
|
declare enum EvaluationErrorType {
|
|
39
67
|
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
68
|
SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
|
|
46
|
-
|
|
69
|
+
TOO_COMPLEX_QUERY = "https://croct.help/sdk/javascript/too-complex-query",
|
|
70
|
+
INTERNAL_ERROR = "https://croct.help/api/evaluation/internal-error",
|
|
71
|
+
INVALID_QUERY = "https://croct.help/api/evaluation/invalid-query",
|
|
72
|
+
EVALUATION_FAILED = "https://croct.help/api/evaluation/evaluation-failed"
|
|
47
73
|
}
|
|
48
|
-
|
|
49
|
-
type: EvaluationErrorType;
|
|
50
|
-
title: string;
|
|
51
|
-
status: number;
|
|
52
|
-
detail?: string;
|
|
53
|
-
};
|
|
54
|
-
declare class EvaluationError<T extends ErrorResponse = ErrorResponse> extends Error {
|
|
74
|
+
declare class EvaluationError<T extends ApiProblem = ApiProblem> extends Error {
|
|
55
75
|
readonly response: T;
|
|
56
76
|
constructor(response: T);
|
|
57
77
|
}
|
|
@@ -59,7 +79,7 @@ type QueryErrorDetail = {
|
|
|
59
79
|
cause: string;
|
|
60
80
|
location: Location;
|
|
61
81
|
};
|
|
62
|
-
type QueryErrorResponse =
|
|
82
|
+
type QueryErrorResponse = ApiProblem & {
|
|
63
83
|
errors: QueryErrorDetail[];
|
|
64
84
|
};
|
|
65
85
|
declare class QueryError extends EvaluationError<QueryErrorResponse> {
|
|
@@ -84,4 +104,4 @@ declare class Evaluator {
|
|
|
84
104
|
toJSON(): never;
|
|
85
105
|
}
|
|
86
106
|
|
|
87
|
-
export { type Campaign, type Configuration,
|
|
107
|
+
export { type Campaign, type Configuration, EvaluationContext, EvaluationError, EvaluationErrorType, type EvaluationOptions, Evaluator, type Page, type PageContextOptions, type PageEvaluationContext, QueryError, type QueryErrorResponse };
|
package/evaluator.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from '@croct/json';
|
|
2
2
|
import { Token } from './token/token.js';
|
|
3
|
+
import { ApiProblem } from './error.js';
|
|
3
4
|
import { Location } from './sourceLocation.js';
|
|
4
5
|
import { Logger } from './logging/logger.js';
|
|
5
6
|
import { ApiKey } from './apiKey.js';
|
|
7
|
+
import { UrlSanitizer } from './url.js';
|
|
6
8
|
|
|
7
9
|
type Campaign = {
|
|
8
10
|
name?: string;
|
|
@@ -16,12 +18,38 @@ type Page = {
|
|
|
16
18
|
title?: string;
|
|
17
19
|
referrer?: string;
|
|
18
20
|
};
|
|
21
|
+
type PageEvaluationContext = Omit<EvaluationContext, 'page'> & Required<Pick<EvaluationContext, 'page'>>;
|
|
22
|
+
type PageContextOptions = {
|
|
23
|
+
urlSanitizer?: UrlSanitizer;
|
|
24
|
+
};
|
|
19
25
|
type EvaluationContext = {
|
|
20
26
|
timeZone?: string;
|
|
21
27
|
campaign?: Campaign;
|
|
22
28
|
page?: Page;
|
|
23
29
|
attributes?: JsonObject;
|
|
24
30
|
};
|
|
31
|
+
declare namespace EvaluationContext {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a context describing the page an evaluation refers to.
|
|
34
|
+
*
|
|
35
|
+
* The context describes the page currently open in the browser, if any,
|
|
36
|
+
* extended with the given context. Values provided by the caller take
|
|
37
|
+
* precedence over the captured ones, so the context can describe a page
|
|
38
|
+
* other than the one running the code, as in server-side evaluations.
|
|
39
|
+
*
|
|
40
|
+
* The URLs of the resulting page are sanitized, whether captured or
|
|
41
|
+
* provided, so the context never carries what the sanitizer strips.
|
|
42
|
+
*
|
|
43
|
+
* @param base The context to extend the captured one with.
|
|
44
|
+
* @param options The options for creating the context.
|
|
45
|
+
*
|
|
46
|
+
* @returns The context describing the page.
|
|
47
|
+
*
|
|
48
|
+
* @throws {TypeError} If the URL of the page is not absolute.
|
|
49
|
+
*/
|
|
50
|
+
function createPageContext(base: PageEvaluationContext, options?: PageContextOptions): PageEvaluationContext;
|
|
51
|
+
function createPageContext(base?: EvaluationContext, options?: PageContextOptions): EvaluationContext;
|
|
52
|
+
}
|
|
25
53
|
type AllowedFetchOptions = Exclude<keyof RequestInit, 'method' | 'body' | 'headers' | 'signal'>;
|
|
26
54
|
type ExtraFetchOptions<T extends keyof RequestInit = AllowedFetchOptions> = Pick<RequestInit, T> & {
|
|
27
55
|
[key in Exclude<keyof RequestInit, T>]?: never;
|
|
@@ -37,21 +65,13 @@ type EvaluationOptions = {
|
|
|
37
65
|
};
|
|
38
66
|
declare enum EvaluationErrorType {
|
|
39
67
|
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
68
|
SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
|
|
46
|
-
|
|
69
|
+
TOO_COMPLEX_QUERY = "https://croct.help/sdk/javascript/too-complex-query",
|
|
70
|
+
INTERNAL_ERROR = "https://croct.help/api/evaluation/internal-error",
|
|
71
|
+
INVALID_QUERY = "https://croct.help/api/evaluation/invalid-query",
|
|
72
|
+
EVALUATION_FAILED = "https://croct.help/api/evaluation/evaluation-failed"
|
|
47
73
|
}
|
|
48
|
-
|
|
49
|
-
type: EvaluationErrorType;
|
|
50
|
-
title: string;
|
|
51
|
-
status: number;
|
|
52
|
-
detail?: string;
|
|
53
|
-
};
|
|
54
|
-
declare class EvaluationError<T extends ErrorResponse = ErrorResponse> extends Error {
|
|
74
|
+
declare class EvaluationError<T extends ApiProblem = ApiProblem> extends Error {
|
|
55
75
|
readonly response: T;
|
|
56
76
|
constructor(response: T);
|
|
57
77
|
}
|
|
@@ -59,7 +79,7 @@ type QueryErrorDetail = {
|
|
|
59
79
|
cause: string;
|
|
60
80
|
location: Location;
|
|
61
81
|
};
|
|
62
|
-
type QueryErrorResponse =
|
|
82
|
+
type QueryErrorResponse = ApiProblem & {
|
|
63
83
|
errors: QueryErrorDetail[];
|
|
64
84
|
};
|
|
65
85
|
declare class QueryError extends EvaluationError<QueryErrorResponse> {
|
|
@@ -84,4 +104,4 @@ declare class Evaluator {
|
|
|
84
104
|
toJSON(): never;
|
|
85
105
|
}
|
|
86
106
|
|
|
87
|
-
export { type Campaign, type Configuration,
|
|
107
|
+
export { type Campaign, type Configuration, EvaluationContext, EvaluationError, EvaluationErrorType, type EvaluationOptions, Evaluator, type Page, type PageContextOptions, type PageEvaluationContext, QueryError, type QueryErrorResponse };
|
package/evaluator.js
CHANGED
|
@@ -4,15 +4,62 @@ import { getLength, getLocation } from "./sourceLocation.js";
|
|
|
4
4
|
import { NullLogger } from "./logging/index.js";
|
|
5
5
|
import { ApiKey } from "./apiKey.js";
|
|
6
6
|
import { Help } from "./help.js";
|
|
7
|
+
import { sanitizeUrl } from "./url.js";
|
|
8
|
+
const UNKNOWN_TIME_ZONE = "Etc/Unknown";
|
|
9
|
+
var EvaluationContext;
|
|
10
|
+
((EvaluationContext2) => {
|
|
11
|
+
function createPageContext(base = {}, options = {}) {
|
|
12
|
+
const { page, timeZone = detectTimeZone(), attributes, ...context } = base;
|
|
13
|
+
const currentPage = mergePage(capturePage(), page);
|
|
14
|
+
return {
|
|
15
|
+
...context,
|
|
16
|
+
...currentPage !== void 0 ? { page: normalizePage(currentPage, options.urlSanitizer) } : {},
|
|
17
|
+
...timeZone !== void 0 ? { timeZone } : {},
|
|
18
|
+
...attributes !== void 0 && Object.keys(attributes).length > 0 ? { attributes } : {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
EvaluationContext2.createPageContext = createPageContext;
|
|
22
|
+
function capturePage() {
|
|
23
|
+
if (typeof window === "undefined") {
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
url: window.location.href,
|
|
28
|
+
title: document.title,
|
|
29
|
+
referrer: document.referrer
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function mergePage(currentPage, providedPage) {
|
|
33
|
+
if (providedPage === void 0) {
|
|
34
|
+
return currentPage;
|
|
35
|
+
}
|
|
36
|
+
return currentPage === void 0 ? providedPage : { ...currentPage, ...providedPage };
|
|
37
|
+
}
|
|
38
|
+
function normalizePage({ url, title, referrer }, urlSanitizer) {
|
|
39
|
+
return {
|
|
40
|
+
url: new URL(sanitizeUrl(url, urlSanitizer)).toString(),
|
|
41
|
+
...title !== void 0 && title !== "" ? { title } : {},
|
|
42
|
+
...referrer !== void 0 && referrer !== "" ? { referrer: sanitizeUrl(referrer, urlSanitizer) } : {}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function detectTimeZone() {
|
|
46
|
+
if (typeof window === "undefined") {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
const { timeZone } = Intl.DateTimeFormat().resolvedOptions();
|
|
50
|
+
if (timeZone === void 0 || timeZone === UNKNOWN_TIME_ZONE) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
return timeZone;
|
|
54
|
+
}
|
|
55
|
+
})(EvaluationContext || (EvaluationContext = {}));
|
|
7
56
|
var EvaluationErrorType = /* @__PURE__ */ ((EvaluationErrorType2) => {
|
|
8
57
|
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
58
|
EvaluationErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
|
|
15
|
-
EvaluationErrorType2["
|
|
59
|
+
EvaluationErrorType2["TOO_COMPLEX_QUERY"] = "https://croct.help/sdk/javascript/too-complex-query";
|
|
60
|
+
EvaluationErrorType2["INTERNAL_ERROR"] = "https://croct.help/api/evaluation/internal-error";
|
|
61
|
+
EvaluationErrorType2["INVALID_QUERY"] = "https://croct.help/api/evaluation/invalid-query";
|
|
62
|
+
EvaluationErrorType2["EVALUATION_FAILED"] = "https://croct.help/api/evaluation/evaluation-failed";
|
|
16
63
|
return EvaluationErrorType2;
|
|
17
64
|
})(EvaluationErrorType || {});
|
|
18
65
|
class EvaluationError extends Error {
|
|
@@ -80,7 +127,7 @@ const _Evaluator = class _Evaluator {
|
|
|
80
127
|
// Request Timeout
|
|
81
128
|
};
|
|
82
129
|
abortController.abort();
|
|
83
|
-
this.logHelp(response
|
|
130
|
+
this.logHelp(response);
|
|
84
131
|
reject(new EvaluationError(response));
|
|
85
132
|
},
|
|
86
133
|
timeout
|
|
@@ -105,12 +152,11 @@ const _Evaluator = class _Evaluator {
|
|
|
105
152
|
if (response.ok) {
|
|
106
153
|
return resolve(body);
|
|
107
154
|
}
|
|
108
|
-
this.logHelp(response.status);
|
|
109
155
|
const problem = body;
|
|
156
|
+
this.logHelp(problem);
|
|
110
157
|
switch (problem.type) {
|
|
111
|
-
case "https://croct.help/
|
|
112
|
-
case "https://croct.help/
|
|
113
|
-
case "https://croct.help/sdk/javascript/too-complex-query" /* TOO_COMPLEX_QUERY */:
|
|
158
|
+
case "https://croct.help/api/evaluation/invalid-query" /* INVALID_QUERY */:
|
|
159
|
+
case "https://croct.help/api/evaluation/evaluation-failed" /* EVALUATION_FAILED */:
|
|
114
160
|
reject(new QueryError(problem));
|
|
115
161
|
break;
|
|
116
162
|
default:
|
|
@@ -130,7 +176,7 @@ const _Evaluator = class _Evaluator {
|
|
|
130
176
|
reject(
|
|
131
177
|
new EvaluationError({
|
|
132
178
|
title: formatMessage(error),
|
|
133
|
-
type: "https://croct.help/
|
|
179
|
+
type: "https://croct.help/api/evaluation/internal-error" /* INTERNAL_ERROR */,
|
|
134
180
|
detail: "Please try again or contact Croct support if the error persists.",
|
|
135
181
|
status: 500
|
|
136
182
|
// Internal Server Error
|
|
@@ -181,8 +227,8 @@ const _Evaluator = class _Evaluator {
|
|
|
181
227
|
body: JSON.stringify(body)
|
|
182
228
|
});
|
|
183
229
|
}
|
|
184
|
-
logHelp(
|
|
185
|
-
const help = Help.
|
|
230
|
+
logHelp(problem) {
|
|
231
|
+
const help = Help.forApiProblem(problem);
|
|
186
232
|
if (help !== void 0) {
|
|
187
233
|
this.logger.error(help);
|
|
188
234
|
}
|
|
@@ -194,6 +240,7 @@ const _Evaluator = class _Evaluator {
|
|
|
194
240
|
_Evaluator.MAX_QUERY_LENGTH = MAX_QUERY_LENGTH;
|
|
195
241
|
let Evaluator = _Evaluator;
|
|
196
242
|
export {
|
|
243
|
+
EvaluationContext,
|
|
197
244
|
EvaluationError,
|
|
198
245
|
EvaluationErrorType,
|
|
199
246
|
Evaluator,
|
|
@@ -5,9 +5,11 @@ import { TokenProvider } from '../token/token.cjs';
|
|
|
5
5
|
import { CidAssigner } from '../cid/assigner.cjs';
|
|
6
6
|
import '@croct/content-model/definition';
|
|
7
7
|
import '../evaluator.cjs';
|
|
8
|
+
import '../error.cjs';
|
|
8
9
|
import '../sourceLocation.cjs';
|
|
9
10
|
import '../logging/logger.cjs';
|
|
10
11
|
import '../apiKey.cjs';
|
|
12
|
+
import '../url.cjs';
|
|
11
13
|
import '../tab.cjs';
|
|
12
14
|
import '../eventManager.cjs';
|
|
13
15
|
|
|
@@ -5,9 +5,11 @@ import { TokenProvider } from '../token/token.js';
|
|
|
5
5
|
import { CidAssigner } from '../cid/assigner.js';
|
|
6
6
|
import '@croct/content-model/definition';
|
|
7
7
|
import '../evaluator.js';
|
|
8
|
+
import '../error.js';
|
|
8
9
|
import '../sourceLocation.js';
|
|
9
10
|
import '../logging/logger.js';
|
|
10
11
|
import '../apiKey.js';
|
|
12
|
+
import '../url.js';
|
|
11
13
|
import '../tab.js';
|
|
12
14
|
import '../eventManager.js';
|
|
13
15
|
|
|
@@ -22,6 +22,7 @@ __export(evaluatorFacade_exports, {
|
|
|
22
22
|
TabContextFactory: () => TabContextFactory
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(evaluatorFacade_exports);
|
|
25
|
+
var import_evaluator = require('../evaluator.cjs');
|
|
25
26
|
var import_schema = require('../schema/index.cjs');
|
|
26
27
|
var import_error = require('../error.cjs');
|
|
27
28
|
function validate(options) {
|
|
@@ -65,24 +66,15 @@ class TabContextFactory {
|
|
|
65
66
|
this.timeZone = timeZone;
|
|
66
67
|
}
|
|
67
68
|
createContext(attributes) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
context.page = page;
|
|
79
|
-
if (this.timeZone !== void 0) {
|
|
80
|
-
context.timeZone = this.timeZone;
|
|
81
|
-
}
|
|
82
|
-
if (attributes !== void 0 && Object.keys(attributes).length > 0) {
|
|
83
|
-
context.attributes = attributes;
|
|
84
|
-
}
|
|
85
|
-
return context;
|
|
69
|
+
return import_evaluator.EvaluationContext.createPageContext({
|
|
70
|
+
page: {
|
|
71
|
+
url: this.tab.url,
|
|
72
|
+
title: this.tab.title,
|
|
73
|
+
referrer: this.tab.referrer
|
|
74
|
+
},
|
|
75
|
+
...this.timeZone !== void 0 ? { timeZone: this.timeZone } : {},
|
|
76
|
+
...attributes !== void 0 ? { attributes } : {}
|
|
77
|
+
});
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -3,9 +3,11 @@ import { EvaluationContext, Evaluator } from '../evaluator.cjs';
|
|
|
3
3
|
import { Tab } from '../tab.cjs';
|
|
4
4
|
import { TokenProvider } from '../token/token.cjs';
|
|
5
5
|
import { CidAssigner } from '../cid/assigner.cjs';
|
|
6
|
+
import '../error.cjs';
|
|
6
7
|
import '../sourceLocation.cjs';
|
|
7
8
|
import '../logging/logger.cjs';
|
|
8
9
|
import '../apiKey.cjs';
|
|
10
|
+
import '../url.cjs';
|
|
9
11
|
import '../eventManager.cjs';
|
|
10
12
|
|
|
11
13
|
type EvaluationOptions = {
|
|
@@ -3,9 +3,11 @@ import { EvaluationContext, Evaluator } from '../evaluator.js';
|
|
|
3
3
|
import { Tab } from '../tab.js';
|
|
4
4
|
import { TokenProvider } from '../token/token.js';
|
|
5
5
|
import { CidAssigner } from '../cid/assigner.js';
|
|
6
|
+
import '../error.js';
|
|
6
7
|
import '../sourceLocation.js';
|
|
7
8
|
import '../logging/logger.js';
|
|
8
9
|
import '../apiKey.js';
|
|
10
|
+
import '../url.js';
|
|
9
11
|
import '../eventManager.js';
|
|
10
12
|
|
|
11
13
|
type EvaluationOptions = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EvaluationContext } from "../evaluator.js";
|
|
1
2
|
import { evaluationOptionsSchema as optionsSchema } from "../schema/index.js";
|
|
2
3
|
import { formatCause } from "../error.js";
|
|
3
4
|
function validate(options) {
|
|
@@ -41,24 +42,15 @@ class TabContextFactory {
|
|
|
41
42
|
this.timeZone = timeZone;
|
|
42
43
|
}
|
|
43
44
|
createContext(attributes) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
context.page = page;
|
|
55
|
-
if (this.timeZone !== void 0) {
|
|
56
|
-
context.timeZone = this.timeZone;
|
|
57
|
-
}
|
|
58
|
-
if (attributes !== void 0 && Object.keys(attributes).length > 0) {
|
|
59
|
-
context.attributes = attributes;
|
|
60
|
-
}
|
|
61
|
-
return context;
|
|
45
|
+
return EvaluationContext.createPageContext({
|
|
46
|
+
page: {
|
|
47
|
+
url: this.tab.url,
|
|
48
|
+
title: this.tab.title,
|
|
49
|
+
referrer: this.tab.referrer
|
|
50
|
+
},
|
|
51
|
+
...this.timeZone !== void 0 ? { timeZone: this.timeZone } : {},
|
|
52
|
+
...attributes !== void 0 ? { attributes } : {}
|
|
53
|
+
});
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
56
|
export {
|
package/facade/index.d.cts
CHANGED
|
@@ -9,8 +9,10 @@ import '@croct/json';
|
|
|
9
9
|
import '../evaluator.cjs';
|
|
10
10
|
import '../token/token.cjs';
|
|
11
11
|
import '../apiKey.cjs';
|
|
12
|
+
import '../error.cjs';
|
|
12
13
|
import '../sourceLocation.cjs';
|
|
13
14
|
import '../logging/logger.cjs';
|
|
15
|
+
import '../url.cjs';
|
|
14
16
|
import '../tab.cjs';
|
|
15
17
|
import '../eventManager.cjs';
|
|
16
18
|
import '../cid/assigner.cjs';
|
package/facade/index.d.ts
CHANGED
|
@@ -9,8 +9,10 @@ import '@croct/json';
|
|
|
9
9
|
import '../evaluator.js';
|
|
10
10
|
import '../token/token.js';
|
|
11
11
|
import '../apiKey.js';
|
|
12
|
+
import '../error.js';
|
|
12
13
|
import '../sourceLocation.js';
|
|
13
14
|
import '../logging/logger.js';
|
|
15
|
+
import '../url.js';
|
|
14
16
|
import '../tab.js';
|
|
15
17
|
import '../eventManager.js';
|
|
16
18
|
import '../cid/assigner.js';
|
package/facade/sdkFacade.d.cts
CHANGED
|
@@ -8,15 +8,17 @@ import { Logger } from '../logging/logger.cjs';
|
|
|
8
8
|
import { SdkEventMap } from '../sdkEvents.cjs';
|
|
9
9
|
import { EventManager } from '../eventManager.cjs';
|
|
10
10
|
import { CidAssigner } from '../cid/assigner.cjs';
|
|
11
|
-
import { UrlSanitizer } from '../
|
|
11
|
+
import { UrlSanitizer } from '../url.cjs';
|
|
12
12
|
import { ContentFetcherFacade } from './contentFetcherFacade.cjs';
|
|
13
13
|
import { CookieCacheConfiguration } from '../cache/cookieCache.cjs';
|
|
14
14
|
import './sessionPatch.cjs';
|
|
15
15
|
import './userPatch.cjs';
|
|
16
16
|
import '@croct/json';
|
|
17
17
|
import '../evaluator.cjs';
|
|
18
|
+
import '../error.cjs';
|
|
18
19
|
import '../sourceLocation.cjs';
|
|
19
20
|
import '../apiKey.cjs';
|
|
21
|
+
import '../tab.cjs';
|
|
20
22
|
import '../trackingEvents.cjs';
|
|
21
23
|
import '../patch.cjs';
|
|
22
24
|
import '../utilityTypes.cjs';
|
package/facade/sdkFacade.d.ts
CHANGED
|
@@ -8,15 +8,17 @@ import { Logger } from '../logging/logger.js';
|
|
|
8
8
|
import { SdkEventMap } from '../sdkEvents.js';
|
|
9
9
|
import { EventManager } from '../eventManager.js';
|
|
10
10
|
import { CidAssigner } from '../cid/assigner.js';
|
|
11
|
-
import { UrlSanitizer } from '../
|
|
11
|
+
import { UrlSanitizer } from '../url.js';
|
|
12
12
|
import { ContentFetcherFacade } from './contentFetcherFacade.js';
|
|
13
13
|
import { CookieCacheConfiguration } from '../cache/cookieCache.js';
|
|
14
14
|
import './sessionPatch.js';
|
|
15
15
|
import './userPatch.js';
|
|
16
16
|
import '@croct/json';
|
|
17
17
|
import '../evaluator.js';
|
|
18
|
+
import '../error.js';
|
|
18
19
|
import '../sourceLocation.js';
|
|
19
20
|
import '../apiKey.js';
|
|
21
|
+
import '../tab.js';
|
|
20
22
|
import '../trackingEvents.js';
|
|
21
23
|
import '../patch.js';
|
|
22
24
|
import '../utilityTypes.js';
|
package/facade/sessionPatch.d.ts
CHANGED
package/facade/userFacade.d.cts
CHANGED
package/facade/userFacade.d.ts
CHANGED
package/facade/userPatch.d.cts
CHANGED
package/facade/userPatch.d.ts
CHANGED
package/help.cjs
CHANGED
|
@@ -20,20 +20,32 @@ __export(help_exports, {
|
|
|
20
20
|
Help: () => Help
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(help_exports);
|
|
23
|
+
var AuthErrorType = /* @__PURE__ */ ((AuthErrorType2) => {
|
|
24
|
+
AuthErrorType2["FORBIDDEN_ORIGIN"] = "https://croct.help/api/authentication/forbidden-origin";
|
|
25
|
+
AuthErrorType2["QUOTA_EXCEEDED"] = "https://croct.help/api/authentication/quota-exceeded";
|
|
26
|
+
return AuthErrorType2;
|
|
27
|
+
})(AuthErrorType || {});
|
|
23
28
|
var Help;
|
|
24
29
|
((Help2) => {
|
|
30
|
+
function forApiProblem(problem) {
|
|
31
|
+
switch (problem.type) {
|
|
32
|
+
case "https://croct.help/api/authentication/forbidden-origin" /* FORBIDDEN_ORIGIN */:
|
|
33
|
+
return "The origin of the request is not allowed in your application settings. For help, see https://croct.help/sdk/javascript/unauthorized-origin";
|
|
34
|
+
case "https://croct.help/api/authentication/quota-exceeded" /* QUOTA_EXCEEDED */:
|
|
35
|
+
return "The application has exceeded the monthly active users (MAU) quota. For help, see https://croct.help/sdk/javascript/mau-exceeded";
|
|
36
|
+
default:
|
|
37
|
+
return Help2.forStatusCode(problem.status);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
Help2.forApiProblem = forApiProblem;
|
|
25
41
|
function forStatusCode(statusCode) {
|
|
26
42
|
switch (statusCode) {
|
|
27
43
|
case 202:
|
|
28
44
|
return "The service is temporarily suspended. For help, see https://croct.help/sdk/javascript/suspended-service";
|
|
29
45
|
case 401:
|
|
30
46
|
return "The request was not authorized, most likely due to invalid credentials. For help, see https://croct.help/sdk/javascript/invalid-credentials";
|
|
31
|
-
case 403:
|
|
32
|
-
return "The origin of the request is not allowed in your application settings. For help, see https://croct.help/sdk/javascript/unauthorized-origin";
|
|
33
47
|
case 408:
|
|
34
48
|
return "The request timed out. For help, see https://croct.help/sdk/javascript/request-timeout";
|
|
35
|
-
case 423:
|
|
36
|
-
return "The application has exceeded the monthly active users (MAU) quota. For help, see https://croct.help/sdk/javascript/mau-exceeded";
|
|
37
49
|
default:
|
|
38
50
|
return void 0;
|
|
39
51
|
}
|
package/help.d.cts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { ApiProblem } from './error.cjs';
|
|
2
|
+
|
|
1
3
|
declare namespace Help {
|
|
2
|
-
function
|
|
4
|
+
function forApiProblem(problem: ApiProblem): string | undefined;
|
|
5
|
+
function forStatusCode(statusCode: 202 | 401 | 408): string;
|
|
3
6
|
function forStatusCode(statusCode: number): string | undefined;
|
|
4
7
|
}
|
|
5
8
|
|
package/help.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { ApiProblem } from './error.js';
|
|
2
|
+
|
|
1
3
|
declare namespace Help {
|
|
2
|
-
function
|
|
4
|
+
function forApiProblem(problem: ApiProblem): string | undefined;
|
|
5
|
+
function forStatusCode(statusCode: 202 | 401 | 408): string;
|
|
3
6
|
function forStatusCode(statusCode: number): string | undefined;
|
|
4
7
|
}
|
|
5
8
|
|