@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
@@ -17,7 +17,8 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var httpBeaconChannel_exports = {};
19
19
  __export(httpBeaconChannel_exports, {
20
- HttpBeaconChannel: () => HttpBeaconChannel
20
+ HttpBeaconChannel: () => HttpBeaconChannel,
21
+ TrackingErrorType: () => TrackingErrorType
21
22
  });
22
23
  module.exports = __toCommonJS(httpBeaconChannel_exports);
23
24
  var import_channel = require('./channel.cjs');
@@ -25,6 +26,11 @@ var import_logging = require('../logging/index.cjs');
25
26
  var import_error = require('../error.cjs');
26
27
  var import_constants = require('../constants.cjs');
27
28
  var import_help = require('../help.cjs');
29
+ var TrackingErrorType = /* @__PURE__ */ ((TrackingErrorType2) => {
30
+ TrackingErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
31
+ TrackingErrorType2["INTERNAL_ERROR"] = "https://croct.help/api/event-tracking/internal-error";
32
+ return TrackingErrorType2;
33
+ })(TrackingErrorType || {});
28
34
  class HttpBeaconChannel {
29
35
  constructor({ logger = new import_logging.NullLogger(), ...configuration }) {
30
36
  this.listeners = [];
@@ -58,7 +64,7 @@ class HttpBeaconChannel {
58
64
  if (response.ok) {
59
65
  if (response.status === 202) {
60
66
  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"
67
+ `Event tracking is currently suspended for this application, check the workspace settings. For help, see ${"https://croct.help/sdk/javascript/suspended-service" /* SUSPENDED_SERVICE */}`
62
68
  );
63
69
  }
64
70
  this.notify(receiptId);
@@ -66,13 +72,13 @@ class HttpBeaconChannel {
66
72
  }
67
73
  const problem = await response.json().catch(
68
74
  () => ({
69
- type: "https://croct.help/api/event-tracker#unexpected-error",
75
+ type: "https://croct.help/api/event-tracking/internal-error" /* INTERNAL_ERROR */,
70
76
  title: response.statusText,
71
77
  status: response.status
72
78
  })
73
79
  );
74
80
  const isRetryable = HttpBeaconChannel.isRetryable(problem.status);
75
- const help = import_help.Help.forStatusCode(problem.status);
81
+ const help = import_help.Help.forApiProblem(problem);
76
82
  if (help !== void 0) {
77
83
  this.logger.error(help);
78
84
  } else if (!isRetryable) {
@@ -112,5 +118,6 @@ class HttpBeaconChannel {
112
118
  }
113
119
  // Annotate the CommonJS export names for ESM import in node:
114
120
  0 && (module.exports = {
115
- HttpBeaconChannel
121
+ HttpBeaconChannel,
122
+ TrackingErrorType
116
123
  });
@@ -9,6 +9,10 @@ type Configuration = {
9
9
  cidAssigner: CidAssigner;
10
10
  logger?: Logger;
11
11
  };
12
+ declare enum TrackingErrorType {
13
+ SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
14
+ INTERNAL_ERROR = "https://croct.help/api/event-tracking/internal-error"
15
+ }
12
16
  declare class HttpBeaconChannel implements DuplexChannel<string, Envelope<string, string>> {
13
17
  private readonly configuration;
14
18
  private readonly logger;
@@ -23,4 +27,4 @@ declare class HttpBeaconChannel implements DuplexChannel<string, Envelope<string
23
27
  private static isRetryable;
24
28
  }
25
29
 
26
- export { type Configuration, HttpBeaconChannel };
30
+ export { type Configuration, HttpBeaconChannel, TrackingErrorType };
@@ -9,6 +9,10 @@ type Configuration = {
9
9
  cidAssigner: CidAssigner;
10
10
  logger?: Logger;
11
11
  };
12
+ declare enum TrackingErrorType {
13
+ SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
14
+ INTERNAL_ERROR = "https://croct.help/api/event-tracking/internal-error"
15
+ }
12
16
  declare class HttpBeaconChannel implements DuplexChannel<string, Envelope<string, string>> {
13
17
  private readonly configuration;
14
18
  private readonly logger;
@@ -23,4 +27,4 @@ declare class HttpBeaconChannel implements DuplexChannel<string, Envelope<string
23
27
  private static isRetryable;
24
28
  }
25
29
 
26
- export { type Configuration, HttpBeaconChannel };
30
+ export { type Configuration, HttpBeaconChannel, TrackingErrorType };
@@ -3,6 +3,11 @@ import { NullLogger } from "../logging/index.js";
3
3
  import { formatMessage } from "../error.js";
4
4
  import { CLIENT_LIBRARY } from "../constants.js";
5
5
  import { Help } from "../help.js";
6
+ var TrackingErrorType = /* @__PURE__ */ ((TrackingErrorType2) => {
7
+ TrackingErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
8
+ TrackingErrorType2["INTERNAL_ERROR"] = "https://croct.help/api/event-tracking/internal-error";
9
+ return TrackingErrorType2;
10
+ })(TrackingErrorType || {});
6
11
  class HttpBeaconChannel {
7
12
  constructor({ logger = new NullLogger(), ...configuration }) {
8
13
  this.listeners = [];
@@ -36,7 +41,7 @@ class HttpBeaconChannel {
36
41
  if (response.ok) {
37
42
  if (response.status === 202) {
38
43
  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"
44
+ `Event tracking is currently suspended for this application, check the workspace settings. For help, see ${"https://croct.help/sdk/javascript/suspended-service" /* SUSPENDED_SERVICE */}`
40
45
  );
41
46
  }
42
47
  this.notify(receiptId);
@@ -44,13 +49,13 @@ class HttpBeaconChannel {
44
49
  }
45
50
  const problem = await response.json().catch(
46
51
  () => ({
47
- type: "https://croct.help/api/event-tracker#unexpected-error",
52
+ type: "https://croct.help/api/event-tracking/internal-error" /* INTERNAL_ERROR */,
48
53
  title: response.statusText,
49
54
  status: response.status
50
55
  })
51
56
  );
52
57
  const isRetryable = HttpBeaconChannel.isRetryable(problem.status);
53
- const help = Help.forStatusCode(problem.status);
58
+ const help = Help.forApiProblem(problem);
54
59
  if (help !== void 0) {
55
60
  this.logger.error(help);
56
61
  } else if (!isRetryable) {
@@ -89,5 +94,6 @@ class HttpBeaconChannel {
89
94
  }
90
95
  }
91
96
  export {
92
- HttpBeaconChannel
97
+ HttpBeaconChannel,
98
+ TrackingErrorType
93
99
  };
package/constants.cjs CHANGED
@@ -24,8 +24,8 @@ __export(constants_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(constants_exports);
26
26
  const BASE_ENDPOINT_URL = "https://api.croct.io";
27
- const MAX_QUERY_LENGTH = parseInt("<@maxQueryLength@>", 10);
28
- const VERSION = "0.22.2";
27
+ const MAX_QUERY_LENGTH = parseInt("500", 10);
28
+ const VERSION = "0.22.4";
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.22.2";
4
- declare const CLIENT_LIBRARY = "Croct SDK JS v0.22.2";
3
+ declare const VERSION = "0.22.4";
4
+ declare const CLIENT_LIBRARY = "Croct SDK JS v0.22.4";
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.22.2";
4
- declare const CLIENT_LIBRARY = "Croct SDK JS v0.22.2";
3
+ declare const VERSION = "0.22.4";
4
+ declare const CLIENT_LIBRARY = "Croct SDK JS v0.22.4";
5
5
 
6
6
  export { BASE_ENDPOINT_URL, CLIENT_LIBRARY, MAX_QUERY_LENGTH, VERSION };
package/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const BASE_ENDPOINT_URL = "https://api.croct.io";
2
- const MAX_QUERY_LENGTH = parseInt("<@maxQueryLength@>", 10);
3
- const VERSION = "0.22.2";
2
+ const MAX_QUERY_LENGTH = parseInt("500", 10);
3
+ const VERSION = "0.22.4";
4
4
  const CLIENT_LIBRARY = `Croct SDK JS v${VERSION}`;
5
5
  export {
6
6
  BASE_ENDPOINT_URL,
package/container.d.cts CHANGED
@@ -7,10 +7,11 @@ import { Evaluator } from './evaluator.cjs';
7
7
  import { CidAssigner } from './cid/assigner.cjs';
8
8
  import { EventManager } from './eventManager.cjs';
9
9
  import { SdkEventMap } from './sdkEvents.cjs';
10
- import { UrlSanitizer } from './tab.cjs';
10
+ import { UrlSanitizer } from './url.cjs';
11
11
  import { ContentFetcher } from './contentFetcher.cjs';
12
12
  import { CookieCacheConfiguration } from './cache/cookieCache.cjs';
13
13
  import './cache/cache.cjs';
14
+ import './tab.cjs';
14
15
  import './queue/queue.cjs';
15
16
  import '@croct/json';
16
17
  import './apiKey.cjs';
@@ -19,6 +20,7 @@ import './retry/policy.cjs';
19
20
  import './trackingEvents.cjs';
20
21
  import './patch.cjs';
21
22
  import './utilityTypes.cjs';
23
+ import './error.cjs';
22
24
  import './sourceLocation.cjs';
23
25
  import '@croct/content-model/definition';
24
26
 
package/container.d.ts CHANGED
@@ -7,10 +7,11 @@ import { Evaluator } from './evaluator.js';
7
7
  import { CidAssigner } from './cid/assigner.js';
8
8
  import { EventManager } from './eventManager.js';
9
9
  import { SdkEventMap } from './sdkEvents.js';
10
- import { UrlSanitizer } from './tab.js';
10
+ import { UrlSanitizer } from './url.js';
11
11
  import { ContentFetcher } from './contentFetcher.js';
12
12
  import { CookieCacheConfiguration } from './cache/cookieCache.js';
13
13
  import './cache/cache.js';
14
+ import './tab.js';
14
15
  import './queue/queue.js';
15
16
  import '@croct/json';
16
17
  import './apiKey.js';
@@ -19,6 +20,7 @@ import './retry/policy.js';
19
20
  import './trackingEvents.js';
20
21
  import './patch.js';
21
22
  import './utilityTypes.js';
23
+ import './error.js';
22
24
  import './sourceLocation.js';
23
25
  import '@croct/content-model/definition';
24
26
 
@@ -19,7 +19,8 @@ var contentFetcher_exports = {};
19
19
  __export(contentFetcher_exports, {
20
20
  ContentError: () => ContentError,
21
21
  ContentErrorType: () => ContentErrorType,
22
- ContentFetcher: () => ContentFetcher
22
+ ContentFetcher: () => ContentFetcher,
23
+ InputError: () => InputError
23
24
  });
24
25
  module.exports = __toCommonJS(contentFetcher_exports);
25
26
  var import_constants = require('./constants.cjs');
@@ -29,8 +30,9 @@ var import_apiKey = require('./apiKey.cjs');
29
30
  var import_help = require('./help.cjs');
30
31
  var ContentErrorType = /* @__PURE__ */ ((ContentErrorType2) => {
31
32
  ContentErrorType2["TIMEOUT"] = "https://croct.help/sdk/javascript/request-timeout";
32
- ContentErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/sdk/javascript/unexpected-error";
33
33
  ContentErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
34
+ ContentErrorType2["INTERNAL_ERROR"] = "https://croct.help/api/content/internal-error";
35
+ ContentErrorType2["INVALID_PAYLOAD"] = "https://croct.help/api/content/invalid-payload";
34
36
  return ContentErrorType2;
35
37
  })(ContentErrorType || {});
36
38
  class ContentError extends Error {
@@ -40,6 +42,12 @@ class ContentError extends Error {
40
42
  Object.setPrototypeOf(this, ContentError.prototype);
41
43
  }
42
44
  }
45
+ class InputError extends ContentError {
46
+ constructor(response) {
47
+ super(response);
48
+ Object.setPrototypeOf(this, InputError.prototype);
49
+ }
50
+ }
43
51
  class ContentFetcher {
44
52
  constructor(configuration) {
45
53
  if (configuration.appId === void 0 === (configuration.apiKey === void 0)) {
@@ -76,7 +84,7 @@ class ContentFetcher {
76
84
  // Request Timeout
77
85
  };
78
86
  abortController.abort();
79
- this.logHelp(response.status);
87
+ this.logHelp(response);
80
88
  reject(new ContentError(response));
81
89
  },
82
90
  timeout
@@ -98,8 +106,12 @@ class ContentFetcher {
98
106
  if (response.ok) {
99
107
  return resolve(body);
100
108
  }
101
- this.logHelp(response.status);
102
- reject(new ContentError(body));
109
+ const problem = body;
110
+ this.logHelp(problem);
111
+ if (problem.type === "https://croct.help/api/content/invalid-payload" /* INVALID_PAYLOAD */) {
112
+ return reject(new InputError(problem));
113
+ }
114
+ reject(new ContentError(problem));
103
115
  }).catch((error) => {
104
116
  if (!response.ok) {
105
117
  throw new Error(`Error ${response.status} - ${response.statusText}`);
@@ -111,7 +123,7 @@ class ContentFetcher {
111
123
  reject(
112
124
  new ContentError({
113
125
  title: (0, import_error.formatMessage)(error),
114
- type: "https://croct.help/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
126
+ type: "https://croct.help/api/content/internal-error" /* INTERNAL_ERROR */,
115
127
  detail: "Please try again or contact Croct support if the error persists.",
116
128
  status: 500
117
129
  // Internal Server Error
@@ -183,8 +195,8 @@ class ContentFetcher {
183
195
  body: JSON.stringify(payload)
184
196
  });
185
197
  }
186
- logHelp(statusCode) {
187
- const help = import_help.Help.forStatusCode(statusCode);
198
+ logHelp(problem) {
199
+ const help = import_help.Help.forApiProblem(problem);
188
200
  if (help !== void 0) {
189
201
  this.logger.error(help);
190
202
  }
@@ -200,5 +212,6 @@ class ContentFetcher {
200
212
  0 && (module.exports = {
201
213
  ContentError,
202
214
  ContentErrorType,
203
- ContentFetcher
215
+ ContentFetcher,
216
+ InputError
204
217
  });
@@ -1,26 +1,34 @@
1
- import { JsonObject } from '@croct/json';
1
+ import { JsonObject, JsonPrimitive } from '@croct/json';
2
2
  import { ContentDefinitionBundle } from '@croct/content-model/definition';
3
3
  import { EvaluationContext } from './evaluator.cjs';
4
4
  import { Token } from './token/token.cjs';
5
+ import { ApiProblem } from './error.cjs';
5
6
  import { Logger } from './logging/logger.cjs';
6
7
  import { ApiKey } from './apiKey.cjs';
7
8
  import './sourceLocation.cjs';
9
+ import './url.cjs';
8
10
 
9
- type ErrorResponse = {
10
- type: string;
11
- title: string;
12
- status: number;
13
- detail?: string;
14
- };
15
11
  declare enum ContentErrorType {
16
12
  TIMEOUT = "https://croct.help/sdk/javascript/request-timeout",
17
- UNEXPECTED_ERROR = "https://croct.help/sdk/javascript/unexpected-error",
18
- SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service"
13
+ SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
14
+ INTERNAL_ERROR = "https://croct.help/api/content/internal-error",
15
+ INVALID_PAYLOAD = "https://croct.help/api/content/invalid-payload"
19
16
  }
20
- declare class ContentError<T extends ErrorResponse = ErrorResponse> extends Error {
17
+ declare class ContentError<T extends ApiProblem = ApiProblem> extends Error {
21
18
  readonly response: T;
22
19
  constructor(response: T);
23
20
  }
21
+ type InputViolation = {
22
+ path: string;
23
+ reason?: string;
24
+ details?: Record<string, JsonPrimitive>;
25
+ };
26
+ type InputErrorResponse = ApiProblem & {
27
+ violations?: InputViolation[];
28
+ };
29
+ declare class InputError extends ContentError<InputErrorResponse> {
30
+ constructor(response: InputErrorResponse);
31
+ }
24
32
  type FetchResponseOptions = {
25
33
  includeSchema?: boolean;
26
34
  };
@@ -90,4 +98,4 @@ declare class ContentFetcher {
90
98
  toJSON(): never;
91
99
  }
92
100
 
93
- export { type Configuration, ContentError, ContentErrorType, ContentFetcher, type DynamicContentOptions, type ErrorResponse, type FetchOptions, type FetchResponse, type FetchResponseOptions, type SlotMetadata, type StaticContentOptions };
101
+ export { type Configuration, ContentError, ContentErrorType, ContentFetcher, type DynamicContentOptions, type FetchOptions, type FetchResponse, type FetchResponseOptions, InputError, type InputErrorResponse, type InputViolation, type SlotMetadata, type StaticContentOptions };
@@ -1,26 +1,34 @@
1
- import { JsonObject } from '@croct/json';
1
+ import { JsonObject, JsonPrimitive } from '@croct/json';
2
2
  import { ContentDefinitionBundle } from '@croct/content-model/definition';
3
3
  import { EvaluationContext } from './evaluator.js';
4
4
  import { Token } from './token/token.js';
5
+ import { ApiProblem } from './error.js';
5
6
  import { Logger } from './logging/logger.js';
6
7
  import { ApiKey } from './apiKey.js';
7
8
  import './sourceLocation.js';
9
+ import './url.js';
8
10
 
9
- type ErrorResponse = {
10
- type: string;
11
- title: string;
12
- status: number;
13
- detail?: string;
14
- };
15
11
  declare enum ContentErrorType {
16
12
  TIMEOUT = "https://croct.help/sdk/javascript/request-timeout",
17
- UNEXPECTED_ERROR = "https://croct.help/sdk/javascript/unexpected-error",
18
- SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service"
13
+ SUSPENDED_SERVICE = "https://croct.help/sdk/javascript/suspended-service",
14
+ INTERNAL_ERROR = "https://croct.help/api/content/internal-error",
15
+ INVALID_PAYLOAD = "https://croct.help/api/content/invalid-payload"
19
16
  }
20
- declare class ContentError<T extends ErrorResponse = ErrorResponse> extends Error {
17
+ declare class ContentError<T extends ApiProblem = ApiProblem> extends Error {
21
18
  readonly response: T;
22
19
  constructor(response: T);
23
20
  }
21
+ type InputViolation = {
22
+ path: string;
23
+ reason?: string;
24
+ details?: Record<string, JsonPrimitive>;
25
+ };
26
+ type InputErrorResponse = ApiProblem & {
27
+ violations?: InputViolation[];
28
+ };
29
+ declare class InputError extends ContentError<InputErrorResponse> {
30
+ constructor(response: InputErrorResponse);
31
+ }
24
32
  type FetchResponseOptions = {
25
33
  includeSchema?: boolean;
26
34
  };
@@ -90,4 +98,4 @@ declare class ContentFetcher {
90
98
  toJSON(): never;
91
99
  }
92
100
 
93
- export { type Configuration, ContentError, ContentErrorType, ContentFetcher, type DynamicContentOptions, type ErrorResponse, type FetchOptions, type FetchResponse, type FetchResponseOptions, type SlotMetadata, type StaticContentOptions };
101
+ export { type Configuration, ContentError, ContentErrorType, ContentFetcher, type DynamicContentOptions, type FetchOptions, type FetchResponse, type FetchResponseOptions, InputError, type InputErrorResponse, type InputViolation, type SlotMetadata, type StaticContentOptions };
package/contentFetcher.js CHANGED
@@ -5,8 +5,9 @@ import { ApiKey } from "./apiKey.js";
5
5
  import { Help } from "./help.js";
6
6
  var ContentErrorType = /* @__PURE__ */ ((ContentErrorType2) => {
7
7
  ContentErrorType2["TIMEOUT"] = "https://croct.help/sdk/javascript/request-timeout";
8
- ContentErrorType2["UNEXPECTED_ERROR"] = "https://croct.help/sdk/javascript/unexpected-error";
9
8
  ContentErrorType2["SUSPENDED_SERVICE"] = "https://croct.help/sdk/javascript/suspended-service";
9
+ ContentErrorType2["INTERNAL_ERROR"] = "https://croct.help/api/content/internal-error";
10
+ ContentErrorType2["INVALID_PAYLOAD"] = "https://croct.help/api/content/invalid-payload";
10
11
  return ContentErrorType2;
11
12
  })(ContentErrorType || {});
12
13
  class ContentError extends Error {
@@ -16,6 +17,12 @@ class ContentError extends Error {
16
17
  Object.setPrototypeOf(this, ContentError.prototype);
17
18
  }
18
19
  }
20
+ class InputError extends ContentError {
21
+ constructor(response) {
22
+ super(response);
23
+ Object.setPrototypeOf(this, InputError.prototype);
24
+ }
25
+ }
19
26
  class ContentFetcher {
20
27
  constructor(configuration) {
21
28
  if (configuration.appId === void 0 === (configuration.apiKey === void 0)) {
@@ -52,7 +59,7 @@ class ContentFetcher {
52
59
  // Request Timeout
53
60
  };
54
61
  abortController.abort();
55
- this.logHelp(response.status);
62
+ this.logHelp(response);
56
63
  reject(new ContentError(response));
57
64
  },
58
65
  timeout
@@ -74,8 +81,12 @@ class ContentFetcher {
74
81
  if (response.ok) {
75
82
  return resolve(body);
76
83
  }
77
- this.logHelp(response.status);
78
- reject(new ContentError(body));
84
+ const problem = body;
85
+ this.logHelp(problem);
86
+ if (problem.type === "https://croct.help/api/content/invalid-payload" /* INVALID_PAYLOAD */) {
87
+ return reject(new InputError(problem));
88
+ }
89
+ reject(new ContentError(problem));
79
90
  }).catch((error) => {
80
91
  if (!response.ok) {
81
92
  throw new Error(`Error ${response.status} - ${response.statusText}`);
@@ -87,7 +98,7 @@ class ContentFetcher {
87
98
  reject(
88
99
  new ContentError({
89
100
  title: formatMessage(error),
90
- type: "https://croct.help/sdk/javascript/unexpected-error" /* UNEXPECTED_ERROR */,
101
+ type: "https://croct.help/api/content/internal-error" /* INTERNAL_ERROR */,
91
102
  detail: "Please try again or contact Croct support if the error persists.",
92
103
  status: 500
93
104
  // Internal Server Error
@@ -159,8 +170,8 @@ class ContentFetcher {
159
170
  body: JSON.stringify(payload)
160
171
  });
161
172
  }
162
- logHelp(statusCode) {
163
- const help = Help.forStatusCode(statusCode);
173
+ logHelp(problem) {
174
+ const help = Help.forApiProblem(problem);
164
175
  if (help !== void 0) {
165
176
  this.logger.error(help);
166
177
  }
@@ -175,5 +186,6 @@ class ContentFetcher {
175
186
  export {
176
187
  ContentError,
177
188
  ContentErrorType,
178
- ContentFetcher
189
+ ContentFetcher,
190
+ InputError
179
191
  };
package/context.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Token } from './token/token.cjs';
2
2
  import { Cache } from './cache/cache.cjs';
3
- import { UrlSanitizer, Tab } from './tab.cjs';
3
+ import { Tab } from './tab.cjs';
4
4
  import { EventDispatcher } from './eventManager.cjs';
5
5
  import { SdkEventMap } from './sdkEvents.cjs';
6
+ import { UrlSanitizer } from './url.cjs';
6
7
  import '@croct/json';
7
8
  import './apiKey.cjs';
8
9
 
package/context.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Token } from './token/token.js';
2
2
  import { Cache } from './cache/cache.js';
3
- import { UrlSanitizer, Tab } from './tab.js';
3
+ import { Tab } from './tab.js';
4
4
  import { EventDispatcher } from './eventManager.js';
5
5
  import { SdkEventMap } from './sdkEvents.js';
6
+ import { UrlSanitizer } from './url.js';
6
7
  import '@croct/json';
7
8
  import './apiKey.js';
8
9
 
package/error.d.cts CHANGED
@@ -1,4 +1,11 @@
1
+ type ApiProblem = {
2
+ title: string;
3
+ type: string;
4
+ status: number;
5
+ detail?: string;
6
+ instance?: string;
7
+ };
1
8
  declare function formatMessage(error: unknown): string;
2
9
  declare function formatCause(error: unknown): string;
3
10
 
4
- export { formatCause, formatMessage };
11
+ export { type ApiProblem, formatCause, formatMessage };
package/error.d.ts CHANGED
@@ -1,4 +1,11 @@
1
+ type ApiProblem = {
2
+ title: string;
3
+ type: string;
4
+ status: number;
5
+ detail?: string;
6
+ instance?: string;
7
+ };
1
8
  declare function formatMessage(error: unknown): string;
2
9
  declare function formatCause(error: unknown): string;
3
10
 
4
- export { formatCause, formatMessage };
11
+ export { type ApiProblem, formatCause, formatMessage };