@croct/sdk 0.22.1 → 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.
Files changed (67) 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 +1 -1
  6. package/constants.d.cts +2 -2
  7. package/constants.d.ts +2 -2
  8. package/constants.js +1 -1
  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 +4 -4
  54. package/schema/ecommerceSchemas.cjs +1 -1
  55. package/schema/ecommerceSchemas.js +1 -1
  56. package/sdk.d.cts +3 -1
  57. package/sdk.d.ts +3 -1
  58. package/tab.cjs +2 -5
  59. package/tab.d.cts +2 -2
  60. package/tab.d.ts +2 -2
  61. package/tab.js +2 -5
  62. package/tracker.d.cts +1 -0
  63. package/tracker.d.ts +1 -0
  64. package/url.cjs +30 -0
  65. package/url.d.cts +12 -0
  66. package/url.d.ts +12 -0
  67. 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
- 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';
@@ -7,6 +7,7 @@ import '../utilityTypes.js';
7
7
  import '../logging/logger.js';
8
8
  import '../tab.js';
9
9
  import '../eventManager.js';
10
+ import '../url.js';
10
11
  import '../channel/channel.js';
11
12
  import '../retry/policy.js';
12
13
  import '../token/token.js';
@@ -6,6 +6,7 @@ import '../utilityTypes.cjs';
6
6
  import '../logging/logger.cjs';
7
7
  import '../tab.cjs';
8
8
  import '../eventManager.cjs';
9
+ import '../url.cjs';
9
10
  import '../channel/channel.cjs';
10
11
  import '../retry/policy.cjs';
11
12
  import '../token/token.cjs';
@@ -6,6 +6,7 @@ import '../utilityTypes.js';
6
6
  import '../logging/logger.js';
7
7
  import '../tab.js';
8
8
  import '../eventManager.js';
9
+ import '../url.js';
9
10
  import '../channel/channel.js';
10
11
  import '../retry/policy.js';
11
12
  import '../token/token.js';
@@ -4,6 +4,7 @@ import { Context } from '../context.cjs';
4
4
  import '../logging/logger.cjs';
5
5
  import '../tab.cjs';
6
6
  import '../eventManager.cjs';
7
+ import '../url.cjs';
7
8
  import '../channel/channel.cjs';
8
9
  import '../retry/policy.cjs';
9
10
  import '../token/token.cjs';
@@ -4,6 +4,7 @@ import { Context } from '../context.js';
4
4
  import '../logging/logger.js';
5
5
  import '../tab.js';
6
6
  import '../eventManager.js';
7
+ import '../url.js';
7
8
  import '../channel/channel.js';
8
9
  import '../retry/policy.js';
9
10
  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';
@@ -7,6 +7,7 @@ import '../utilityTypes.js';
7
7
  import '../logging/logger.js';
8
8
  import '../tab.js';
9
9
  import '../eventManager.js';
10
+ import '../url.js';
10
11
  import '../channel/channel.js';
11
12
  import '../retry/policy.js';
12
13
  import '../token/token.js';
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 forStatusCode(statusCode: 204 | 401 | 403 | 408 | 423): string;
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 forStatusCode(statusCode: 204 | 401 | 403 | 408 | 423): string;
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