@croct/sdk 0.22.2 → 0.22.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/channel/httpBeaconChannel.cjs +12 -5
  2. package/channel/httpBeaconChannel.d.cts +5 -1
  3. package/channel/httpBeaconChannel.d.ts +5 -1
  4. package/channel/httpBeaconChannel.js +10 -4
  5. package/constants.cjs +2 -2
  6. package/constants.d.cts +2 -2
  7. package/constants.d.ts +2 -2
  8. package/constants.js +2 -2
  9. package/container.d.cts +3 -1
  10. package/container.d.ts +3 -1
  11. package/contentFetcher.cjs +22 -9
  12. package/contentFetcher.d.cts +19 -11
  13. package/contentFetcher.d.ts +19 -11
  14. package/contentFetcher.js +20 -8
  15. package/context.d.cts +2 -1
  16. package/context.d.ts +2 -1
  17. package/error.d.cts +8 -1
  18. package/error.d.ts +8 -1
  19. package/evaluator.cjs +62 -14
  20. package/evaluator.d.cts +35 -15
  21. package/evaluator.d.ts +35 -15
  22. package/evaluator.js +61 -14
  23. package/facade/contentFetcherFacade.d.cts +2 -0
  24. package/facade/contentFetcherFacade.d.ts +2 -0
  25. package/facade/evaluatorFacade.cjs +10 -18
  26. package/facade/evaluatorFacade.d.cts +2 -0
  27. package/facade/evaluatorFacade.d.ts +2 -0
  28. package/facade/evaluatorFacade.js +10 -18
  29. package/facade/index.d.cts +2 -0
  30. package/facade/index.d.ts +2 -0
  31. package/facade/sdkFacade.d.cts +3 -1
  32. package/facade/sdkFacade.d.ts +3 -1
  33. package/facade/sessionFacade.d.cts +1 -0
  34. package/facade/sessionFacade.d.ts +1 -0
  35. package/facade/sessionPatch.d.cts +1 -0
  36. package/facade/sessionPatch.d.ts +1 -0
  37. package/facade/trackerFacade.d.cts +1 -0
  38. package/facade/trackerFacade.d.ts +1 -0
  39. package/facade/userFacade.d.cts +1 -0
  40. package/facade/userFacade.d.ts +1 -0
  41. package/facade/userPatch.d.cts +1 -0
  42. package/facade/userPatch.d.ts +1 -0
  43. package/help.cjs +16 -4
  44. package/help.d.cts +4 -1
  45. package/help.d.ts +4 -1
  46. package/help.js +16 -4
  47. package/index.d.cts +2 -0
  48. package/index.d.ts +2 -0
  49. package/interactionMonitor.cjs +42 -9
  50. package/interactionMonitor.d.cts +1 -0
  51. package/interactionMonitor.d.ts +1 -0
  52. package/interactionMonitor.js +42 -9
  53. package/package.json +1 -1
  54. package/sdk.d.cts +3 -1
  55. package/sdk.d.ts +3 -1
  56. package/tab.cjs +2 -5
  57. package/tab.d.cts +2 -2
  58. package/tab.d.ts +2 -2
  59. package/tab.js +2 -5
  60. package/tracker.d.cts +1 -0
  61. package/tracker.d.ts +1 -0
  62. package/url.cjs +30 -0
  63. package/url.d.cts +12 -0
  64. package/url.d.ts +12 -0
  65. package/url.js +7 -0
package/evaluator.cjs CHANGED
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var evaluator_exports = {};
19
19
  __export(evaluator_exports, {
20
+ EvaluationContext: () => EvaluationContext,
20
21
  EvaluationError: () => EvaluationError,
21
22
  EvaluationErrorType: () => EvaluationErrorType,
22
23
  Evaluator: () => Evaluator,
@@ -29,15 +30,62 @@ var import_sourceLocation = require('./sourceLocation.cjs');
29
30
  var import_logging = require('./logging/index.cjs');
30
31
  var import_apiKey = require('./apiKey.cjs');
31
32
  var import_help = require('./help.cjs');
33
+ var import_url = require('./url.cjs');
34
+ const UNKNOWN_TIME_ZONE = "Etc/Unknown";
35
+ var EvaluationContext;
36
+ ((EvaluationContext2) => {
37
+ function createPageContext(base = {}, options = {}) {
38
+ const { page, timeZone = detectTimeZone(), attributes, ...context } = base;
39
+ const currentPage = mergePage(capturePage(), page);
40
+ return {
41
+ ...context,
42
+ ...currentPage !== void 0 ? { page: normalizePage(currentPage, options.urlSanitizer) } : {},
43
+ ...timeZone !== void 0 ? { timeZone } : {},
44
+ ...attributes !== void 0 && Object.keys(attributes).length > 0 ? { attributes } : {}
45
+ };
46
+ }
47
+ EvaluationContext2.createPageContext = createPageContext;
48
+ function capturePage() {
49
+ if (typeof window === "undefined") {
50
+ return void 0;
51
+ }
52
+ return {
53
+ url: window.location.href,
54
+ title: document.title,
55
+ referrer: document.referrer
56
+ };
57
+ }
58
+ function mergePage(currentPage, providedPage) {
59
+ if (providedPage === void 0) {
60
+ return currentPage;
61
+ }
62
+ return currentPage === void 0 ? providedPage : { ...currentPage, ...providedPage };
63
+ }
64
+ function normalizePage({ url, title, referrer }, urlSanitizer) {
65
+ return {
66
+ url: new URL((0, import_url.sanitizeUrl)(url, urlSanitizer)).toString(),
67
+ ...title !== void 0 && title !== "" ? { title } : {},
68
+ ...referrer !== void 0 && referrer !== "" ? { referrer: (0, import_url.sanitizeUrl)(referrer, urlSanitizer) } : {}
69
+ };
70
+ }
71
+ function detectTimeZone() {
72
+ if (typeof window === "undefined") {
73
+ return void 0;
74
+ }
75
+ const { timeZone } = Intl.DateTimeFormat().resolvedOptions();
76
+ if (timeZone === void 0 || timeZone === UNKNOWN_TIME_ZONE) {
77
+ return void 0;
78
+ }
79
+ return timeZone;
80
+ }
81
+ })(EvaluationContext || (EvaluationContext = {}));
32
82
  var EvaluationErrorType = /* @__PURE__ */ ((EvaluationErrorType2) => {
33
83
  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
84
  EvaluationErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
40
- EvaluationErrorType2["UNSERIALIZABLE_RESULT"] = "https://croct.help/sdk/javascript/unserializable-result";
85
+ EvaluationErrorType2["TOO_COMPLEX_QUERY"] = "https://croct.help/sdk/javascript/too-complex-query";
86
+ EvaluationErrorType2["INTERNAL_ERROR"] = "https://croct.help/api/evaluation/internal-error";
87
+ EvaluationErrorType2["INVALID_QUERY"] = "https://croct.help/api/evaluation/invalid-query";
88
+ EvaluationErrorType2["EVALUATION_FAILED"] = "https://croct.help/api/evaluation/evaluation-failed";
41
89
  return EvaluationErrorType2;
42
90
  })(EvaluationErrorType || {});
43
91
  class EvaluationError extends Error {
@@ -105,7 +153,7 @@ const _Evaluator = class _Evaluator {
105
153
  // Request Timeout
106
154
  };
107
155
  abortController.abort();
108
- this.logHelp(response.status);
156
+ this.logHelp(response);
109
157
  reject(new EvaluationError(response));
110
158
  },
111
159
  timeout
@@ -130,12 +178,11 @@ const _Evaluator = class _Evaluator {
130
178
  if (response.ok) {
131
179
  return resolve(body);
132
180
  }
133
- this.logHelp(response.status);
134
181
  const problem = body;
182
+ this.logHelp(problem);
135
183
  switch (problem.type) {
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 */:
184
+ case "https://croct.help/api/evaluation/invalid-query" /* INVALID_QUERY */:
185
+ case "https://croct.help/api/evaluation/evaluation-failed" /* EVALUATION_FAILED */:
139
186
  reject(new QueryError(problem));
140
187
  break;
141
188
  default:
@@ -155,7 +202,7 @@ const _Evaluator = class _Evaluator {
155
202
  reject(
156
203
  new EvaluationError({
157
204
  title: (0, import_error.formatMessage)(error),
158
- type: "https://croct.help/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
205
+ type: "https://croct.help/api/evaluation/internal-error" /* INTERNAL_ERROR */,
159
206
  detail: "Please try again or contact Croct support if the error persists.",
160
207
  status: 500
161
208
  // Internal Server Error
@@ -206,8 +253,8 @@ const _Evaluator = class _Evaluator {
206
253
  body: JSON.stringify(body)
207
254
  });
208
255
  }
209
- logHelp(statusCode) {
210
- const help = import_help.Help.forStatusCode(statusCode);
256
+ logHelp(problem) {
257
+ const help = import_help.Help.forApiProblem(problem);
211
258
  if (help !== void 0) {
212
259
  this.logger.error(help);
213
260
  }
@@ -220,6 +267,7 @@ _Evaluator.MAX_QUERY_LENGTH = import_constants.MAX_QUERY_LENGTH;
220
267
  let Evaluator = _Evaluator;
221
268
  // Annotate the CommonJS export names for ESM import in node:
222
269
  0 && (module.exports = {
270
+ EvaluationContext,
223
271
  EvaluationError,
224
272
  EvaluationErrorType,
225
273
  Evaluator,
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
- UNSERIALIZABLE_RESULT = "https://croct.help/sdk/javascript/unserializable-result"
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
- type ErrorResponse = {
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 = ErrorResponse & {
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, type ErrorResponse, type EvaluationContext, EvaluationError, EvaluationErrorType, type EvaluationOptions, Evaluator, type Page, QueryError, type QueryErrorResponse };
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
- UNSERIALIZABLE_RESULT = "https://croct.help/sdk/javascript/unserializable-result"
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
- type ErrorResponse = {
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 = ErrorResponse & {
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, type ErrorResponse, type EvaluationContext, EvaluationError, EvaluationErrorType, type EvaluationOptions, Evaluator, type Page, QueryError, type QueryErrorResponse };
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["UNSERIALIZABLE_RESULT"] = "https://croct.help/sdk/javascript/unserializable-result";
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.status);
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/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 */:
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/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
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(statusCode) {
185
- const help = Help.forStatusCode(statusCode);
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
- const url = new URL(this.tab.url);
69
- const context = {};
70
- const page = {
71
- title: this.tab.title,
72
- url: url.toString()
73
- };
74
- const { referrer } = this.tab;
75
- if (referrer.length > 0) {
76
- page.referrer = referrer;
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
- const url = new URL(this.tab.url);
45
- const context = {};
46
- const page = {
47
- title: this.tab.title,
48
- url: url.toString()
49
- };
50
- const { referrer } = this.tab;
51
- if (referrer.length > 0) {
52
- page.referrer = referrer;
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 {
@@ -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';
@@ -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 '../tab.cjs';
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';
@@ -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 '../tab.js';
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';
@@ -3,6 +3,7 @@ import { SessionPatch } from './sessionPatch.cjs';
3
3
  import '../logging/logger.cjs';
4
4
  import '../tab.cjs';
5
5
  import '../eventManager.cjs';
6
+ import '../url.cjs';
6
7
  import '../channel/channel.cjs';
7
8
  import '../retry/policy.cjs';
8
9
  import '../token/token.cjs';
@@ -3,6 +3,7 @@ import { SessionPatch } from './sessionPatch.js';
3
3
  import '../logging/logger.js';
4
4
  import '../tab.js';
5
5
  import '../eventManager.js';
6
+ import '../url.js';
6
7
  import '../channel/channel.js';
7
8
  import '../retry/policy.js';
8
9
  import '../token/token.js';
@@ -7,6 +7,7 @@ import '../utilityTypes.cjs';
7
7
  import '../logging/logger.cjs';
8
8
  import '../tab.cjs';
9
9
  import '../eventManager.cjs';
10
+ import '../url.cjs';
10
11
  import '../channel/channel.cjs';
11
12
  import '../retry/policy.cjs';
12
13
  import '../token/token.cjs';