@croct/sdk 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,24 +1,22 @@
1
1
  <p align="center">
2
- <a href="https://croct.com">
3
- <img src="https://cdn.croct.io/brand/logo/repo-icon-green.svg" alt="Croct" height="80" />
4
- </a>
5
- <br />
6
- <strong>SDK JS</strong>
7
- <br />
8
- The official Croct SDK for JavaScript.
2
+ <a href="https://croct.com" target="_blank">
3
+ <picture>
4
+ <source media="(min-width: 769px) and (prefers-color-scheme: light)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-light.svg">
5
+ <source media="(min-width: 769px) and (prefers-color-scheme: dark)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-dark.svg">
6
+ <source media="(max-width: 768px) and (prefers-color-scheme: dark)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-dark-mobile.svg">
7
+ <source media="(max-width: 768px) and (prefers-color-scheme: light)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-light-mobile.svg">
8
+ <img src="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-light-mobile.svg" alt="Croct JavaScript SDK" title="Croct JavaScript SDK" width="100%">
9
+ </picture>
10
+ </a>
11
+ <br/>
12
+ <strong>SDK JS</strong><br/>
13
+ The official Croct SDK for JavaScript.
9
14
  </p>
15
+
10
16
  <p align="center">
11
17
  <a href="https://www.npmjs.com/package/@croct/sdk"><img alt="Version" src="https://img.shields.io/npm/v/@croct/sdk"/></a>
12
18
  <a href="https://github.com/croct-tech/sdk-js/actions?query=workflow%3AValidations"><img alt="Build" src="https://github.com/croct-tech/sdk-js/workflows/Validations/badge.svg"/></a>
13
- <a href="https://codeclimate.com/repos/5e7251b3172af05fe9000e27/maintainability"><img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/c44df78a3ed891af11bb/maintainability"/></a>
14
19
  <a href="https://codeclimate.com/repos/5e7251b3172af05fe9000e27/test_coverage"><img alt="Coverage" src="https://api.codeclimate.com/v1/badges/c44df78a3ed891af11bb/test_coverage"/></a>
15
- <br />
16
- <br />
17
- <a href="https://github.com/croct-tech/sdk-js/releases">📦Releases</a>
18
- ·
19
- <a href="https://github.com/croct-tech/sdk-js/issues/new?labels=bug&template=bug-report.md">🐞Report Bug</a>
20
- ·
21
- <a href="https://github.com/croct-tech/sdk-js/issues/new?labels=enhancement&template=feature-request.md">✨Request Feature</a>
22
20
  </p>
23
21
 
24
22
  ## Installation
@@ -52,7 +52,8 @@ class HttpBeaconChannel {
52
52
  payload,
53
53
  originalTime: timestamp,
54
54
  departureTime: Date.now()
55
- })
55
+ }),
56
+ keepalive: true
56
57
  }).then(async (response) => {
57
58
  if (response.ok) {
58
59
  this.notify(receiptId);
@@ -30,7 +30,8 @@ class HttpBeaconChannel {
30
30
  payload,
31
31
  originalTime: timestamp,
32
32
  departureTime: Date.now()
33
- })
33
+ }),
34
+ keepalive: true
34
35
  }).then(async (response) => {
35
36
  if (response.ok) {
36
37
  this.notify(receiptId);
@@ -57,7 +57,11 @@ class QueuedChannel {
57
57
  dequeue() {
58
58
  this.logger.debug("Dequeuing message...");
59
59
  this.logger.debug(`Queue length: ${Math.max(0, this.queue.length() - 1)}`);
60
- this.queue.shift();
60
+ if (this.queue.length() === 0) {
61
+ this.logger.debug("Queue unexpectedly empty, possibly due to concurrent modification.");
62
+ } else {
63
+ this.queue.shift();
64
+ }
61
65
  }
62
66
  requeue() {
63
67
  if (this.closed) {
@@ -35,7 +35,11 @@ class QueuedChannel {
35
35
  dequeue() {
36
36
  this.logger.debug("Dequeuing message...");
37
37
  this.logger.debug(`Queue length: ${Math.max(0, this.queue.length() - 1)}`);
38
- this.queue.shift();
38
+ if (this.queue.length() === 0) {
39
+ this.logger.debug("Queue unexpectedly empty, possibly due to concurrent modification.");
40
+ } else {
41
+ this.queue.shift();
42
+ }
39
43
  }
40
44
  requeue() {
41
45
  if (this.closed) {
package/constants.cjs CHANGED
@@ -25,7 +25,7 @@ __export(constants_exports, {
25
25
  module.exports = __toCommonJS(constants_exports);
26
26
  const BASE_ENDPOINT_URL = "https://api.croct.io";
27
27
  const MAX_QUERY_LENGTH = parseInt("<@maxQueryLength@>", 10);
28
- const VERSION = "0.18.0";
28
+ const VERSION = "0.18.2";
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.18.0";
4
- declare const CLIENT_LIBRARY = "Croct SDK JS v0.18.0";
3
+ declare const VERSION = "0.18.2";
4
+ declare const CLIENT_LIBRARY = "Croct SDK JS v0.18.2";
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.18.0";
4
- declare const CLIENT_LIBRARY = "Croct SDK JS v0.18.0";
3
+ declare const VERSION = "0.18.2";
4
+ declare const CLIENT_LIBRARY = "Croct SDK JS v0.18.2";
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
2
  const MAX_QUERY_LENGTH = parseInt("<@maxQueryLength@>", 10);
3
- const VERSION = "0.18.0";
3
+ const VERSION = "0.18.2";
4
4
  const CLIENT_LIBRARY = `Croct SDK JS v${VERSION}`;
5
5
  export {
6
6
  BASE_ENDPOINT_URL,
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(contentFetcher_exports);
25
25
  var import_constants = require('./constants.cjs');
26
26
  var import_error = require('./error.cjs');
27
27
  var import_logging = require('./logging/index.cjs');
28
+ var import_apiKey = require('./apiKey.cjs');
28
29
  var import_help = require('./help.cjs');
29
30
  var ContentErrorType = /* @__PURE__ */ ((ContentErrorType2) => {
30
31
  ContentErrorType2["TIMEOUT"] = "https://croct.help/api/content#timeout";
@@ -44,14 +45,13 @@ class ContentFetcher {
44
45
  throw new Error("Either the application ID or the API key must be provided.");
45
46
  }
46
47
  const { baseEndpointUrl } = configuration;
47
- const apiKey = typeof configuration.apiKey === "object" ? configuration.apiKey.getIdentifier() : configuration.apiKey;
48
- const baseEndpoint = (baseEndpointUrl ?? import_constants.BASE_ENDPOINT_URL).replace(/\/+$/, "") + (apiKey === void 0 ? "/client" : "/external") + "/web";
48
+ const baseEndpoint = (baseEndpointUrl ?? import_constants.BASE_ENDPOINT_URL).replace(/\/+$/, "") + (configuration.apiKey === void 0 ? "/client" : "/external") + "/web";
49
49
  this.dynamicEndpoint = `${baseEndpoint}/content`;
50
50
  this.staticEndpoint = `${baseEndpoint}/static-content`;
51
51
  this.logger = configuration.logger ?? new import_logging.NullLogger();
52
52
  this.configuration = {
53
53
  appId: configuration.appId,
54
- apiKey,
54
+ apiKey: configuration.apiKey !== void 0 ? import_apiKey.ApiKey.from(configuration.apiKey).getIdentifier() : configuration.apiKey,
55
55
  defaultTimeout: configuration.defaultTimeout,
56
56
  defaultPreferredLocale: configuration.defaultPreferredLocale
57
57
  };
package/contentFetcher.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { BASE_ENDPOINT_URL, CLIENT_LIBRARY } from "./constants.js";
2
2
  import { formatMessage } from "./error.js";
3
3
  import { NullLogger } from "./logging/index.js";
4
+ import { ApiKey } from "./apiKey.js";
4
5
  import { Help } from "./help.js";
5
6
  var ContentErrorType = /* @__PURE__ */ ((ContentErrorType2) => {
6
7
  ContentErrorType2["TIMEOUT"] = "https://croct.help/api/content#timeout";
@@ -20,14 +21,13 @@ class ContentFetcher {
20
21
  throw new Error("Either the application ID or the API key must be provided.");
21
22
  }
22
23
  const { baseEndpointUrl } = configuration;
23
- const apiKey = typeof configuration.apiKey === "object" ? configuration.apiKey.getIdentifier() : configuration.apiKey;
24
- const baseEndpoint = (baseEndpointUrl ?? BASE_ENDPOINT_URL).replace(/\/+$/, "") + (apiKey === void 0 ? "/client" : "/external") + "/web";
24
+ const baseEndpoint = (baseEndpointUrl ?? BASE_ENDPOINT_URL).replace(/\/+$/, "") + (configuration.apiKey === void 0 ? "/client" : "/external") + "/web";
25
25
  this.dynamicEndpoint = `${baseEndpoint}/content`;
26
26
  this.staticEndpoint = `${baseEndpoint}/static-content`;
27
27
  this.logger = configuration.logger ?? new NullLogger();
28
28
  this.configuration = {
29
29
  appId: configuration.appId,
30
- apiKey,
30
+ apiKey: configuration.apiKey !== void 0 ? ApiKey.from(configuration.apiKey).getIdentifier() : configuration.apiKey,
31
31
  defaultTimeout: configuration.defaultTimeout,
32
32
  defaultPreferredLocale: configuration.defaultPreferredLocale
33
33
  };
package/evaluator.cjs CHANGED
@@ -27,6 +27,7 @@ var import_constants = require('./constants.cjs');
27
27
  var import_error = require('./error.cjs');
28
28
  var import_sourceLocation = require('./sourceLocation.cjs');
29
29
  var import_logging = require('./logging/index.cjs');
30
+ var import_apiKey = require('./apiKey.cjs');
30
31
  var import_help = require('./help.cjs');
31
32
  var EvaluationErrorType = /* @__PURE__ */ ((EvaluationErrorType2) => {
32
33
  EvaluationErrorType2["TIMEOUT"] = "https://croct.help/api/evaluation#timeout";
@@ -57,12 +58,11 @@ const _Evaluator = class _Evaluator {
57
58
  throw new Error("Either the application ID or the API key must be provided.");
58
59
  }
59
60
  const { baseEndpointUrl } = configuration;
60
- const apiKey = typeof configuration.apiKey === "object" ? configuration.apiKey.getIdentifier() : configuration.apiKey;
61
- this.endpoint = (baseEndpointUrl ?? import_constants.BASE_ENDPOINT_URL).replace(/\/+$/, "") + (apiKey === void 0 ? "/client" : "/external") + "/web/evaluate";
61
+ this.endpoint = (baseEndpointUrl ?? import_constants.BASE_ENDPOINT_URL).replace(/\/+$/, "") + (configuration.apiKey === void 0 ? "/client" : "/external") + "/web/evaluate";
62
62
  this.logger = configuration.logger ?? new import_logging.NullLogger();
63
63
  this.configuration = {
64
64
  appId: configuration.appId,
65
- apiKey,
65
+ apiKey: configuration.apiKey !== void 0 ? import_apiKey.ApiKey.from(configuration.apiKey).getIdentifier() : configuration.apiKey,
66
66
  defaultTimeout: configuration.defaultTimeout
67
67
  };
68
68
  }
package/evaluator.js CHANGED
@@ -2,6 +2,7 @@ import { BASE_ENDPOINT_URL, CLIENT_LIBRARY, MAX_QUERY_LENGTH } from "./constants
2
2
  import { formatMessage } from "./error.js";
3
3
  import { getLength, getLocation } from "./sourceLocation.js";
4
4
  import { NullLogger } from "./logging/index.js";
5
+ import { ApiKey } from "./apiKey.js";
5
6
  import { Help } from "./help.js";
6
7
  var EvaluationErrorType = /* @__PURE__ */ ((EvaluationErrorType2) => {
7
8
  EvaluationErrorType2["TIMEOUT"] = "https://croct.help/api/evaluation#timeout";
@@ -32,12 +33,11 @@ const _Evaluator = class _Evaluator {
32
33
  throw new Error("Either the application ID or the API key must be provided.");
33
34
  }
34
35
  const { baseEndpointUrl } = configuration;
35
- const apiKey = typeof configuration.apiKey === "object" ? configuration.apiKey.getIdentifier() : configuration.apiKey;
36
- this.endpoint = (baseEndpointUrl ?? BASE_ENDPOINT_URL).replace(/\/+$/, "") + (apiKey === void 0 ? "/client" : "/external") + "/web/evaluate";
36
+ this.endpoint = (baseEndpointUrl ?? BASE_ENDPOINT_URL).replace(/\/+$/, "") + (configuration.apiKey === void 0 ? "/client" : "/external") + "/web/evaluate";
37
37
  this.logger = configuration.logger ?? new NullLogger();
38
38
  this.configuration = {
39
39
  appId: configuration.appId,
40
- apiKey,
40
+ apiKey: configuration.apiKey !== void 0 ? ApiKey.from(configuration.apiKey).getIdentifier() : configuration.apiKey,
41
41
  defaultTimeout: configuration.defaultTimeout
42
42
  };
43
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/sdk",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Croct SDK for JavaScript.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -86,12 +86,12 @@
86
86
  "devDependencies": {
87
87
  "esbuild-fix-imports-plugin": "^1.0.19",
88
88
  "@croct/eslint-plugin": "^0.7.0",
89
- "@types/jest": "^29.2.3",
89
+ "@types/jest": "^30.0.0",
90
90
  "eslint": "^8.57.0",
91
91
  "fetch-mock": "^9.11.0",
92
- "jest": "^29.3.1",
93
- "jest-environment-jsdom": "^29.3.1",
94
- "jest-extended": "^4.0.0",
92
+ "jest": "^30.0.0",
93
+ "jest-environment-jsdom": "^30.0.0",
94
+ "jest-extended": "^6.0.0",
95
95
  "node-fetch": "^2.6.7",
96
96
  "ts-jest": "^29.0.3",
97
97
  "tsup": "^8.4.0",