@croct/plug 0.17.0 → 0.17.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.
@@ -24,13 +24,23 @@ var import_contentFetcher = require("@croct/sdk/contentFetcher");
24
24
  var import_error = require("@croct/sdk/error");
25
25
  var import_content = require("@croct/content");
26
26
  function fetchContent(slotId, options) {
27
- const { apiKey, appId, fallback, baseEndpointUrl, logger, ...fetchOptions } = options ?? {};
27
+ const {
28
+ apiKey,
29
+ appId,
30
+ fallback,
31
+ baseEndpointUrl,
32
+ logger,
33
+ preferredLocale = "",
34
+ ...fetchOptions
35
+ } = options ?? {};
28
36
  const auth = { appId, apiKey };
29
37
  const [id, version = "latest"] = slotId.split("@");
30
- const promise = new import_contentFetcher.ContentFetcher({ ...auth, baseEndpointUrl }).fetch(
31
- id,
32
- version === "latest" ? fetchOptions : { ...fetchOptions, version }
33
- );
38
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
39
+ const promise = new import_contentFetcher.ContentFetcher({ ...auth, baseEndpointUrl }).fetch(id, {
40
+ ...fetchOptions,
41
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
42
+ ...version !== "latest" ? { version } : {}
43
+ });
34
44
  return promise.catch(
35
45
  async (error) => {
36
46
  if (logger !== void 0) {
@@ -39,7 +49,7 @@ function fetchContent(slotId, options) {
39
49
  if (fallback !== void 0) {
40
50
  return { content: fallback };
41
51
  }
42
- const staticContent = await (0, import_content.loadSlotContent)(id, fetchOptions.preferredLocale);
52
+ const staticContent = await (0, import_content.loadSlotContent)(id, normalizedLocale);
43
53
  if (staticContent === null) {
44
54
  throw error;
45
55
  }
@@ -4,13 +4,23 @@ import {
4
4
  import { formatCause } from "@croct/sdk/error";
5
5
  import { loadSlotContent } from "@croct/content";
6
6
  function fetchContent(slotId, options) {
7
- const { apiKey, appId, fallback, baseEndpointUrl, logger, ...fetchOptions } = options ?? {};
7
+ const {
8
+ apiKey,
9
+ appId,
10
+ fallback,
11
+ baseEndpointUrl,
12
+ logger,
13
+ preferredLocale = "",
14
+ ...fetchOptions
15
+ } = options ?? {};
8
16
  const auth = { appId, apiKey };
9
17
  const [id, version = "latest"] = slotId.split("@");
10
- const promise = new ContentFetcher({ ...auth, baseEndpointUrl }).fetch(
11
- id,
12
- version === "latest" ? fetchOptions : { ...fetchOptions, version }
13
- );
18
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
19
+ const promise = new ContentFetcher({ ...auth, baseEndpointUrl }).fetch(id, {
20
+ ...fetchOptions,
21
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
22
+ ...version !== "latest" ? { version } : {}
23
+ });
14
24
  return promise.catch(
15
25
  async (error) => {
16
26
  if (logger !== void 0) {
@@ -19,7 +29,7 @@ function fetchContent(slotId, options) {
19
29
  if (fallback !== void 0) {
20
30
  return { content: fallback };
21
31
  }
22
- const staticContent = await loadSlotContent(id, fetchOptions.preferredLocale);
32
+ const staticContent = await loadSlotContent(id, normalizedLocale);
23
33
  if (staticContent === null) {
24
34
  throw error;
25
35
  }
package/constants.cjs CHANGED
@@ -28,7 +28,7 @@ const CDN_URL = "https://cdn.croct.io/js/v1/lib/plug.js";
28
28
  const PLAYGROUND_ORIGIN = "https://play.croct.com";
29
29
  const PLAYGROUND_CONNECT_URL = "https://play.croct.com/connect.html";
30
30
  const PREVIEW_WIDGET_ORIGIN = "https://cdn.croct.io";
31
- const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.0.html";
31
+ const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.2.html";
32
32
  // Annotate the CommonJS export names for ESM import in node:
33
33
  0 && (module.exports = {
34
34
  CDN_URL,
package/constants.d.cts CHANGED
@@ -2,6 +2,6 @@ declare const CDN_URL = "https://cdn.croct.io/js/v1/lib/plug.js";
2
2
  declare const PLAYGROUND_ORIGIN = "https://play.croct.com";
3
3
  declare const PLAYGROUND_CONNECT_URL = "https://play.croct.com/connect.html";
4
4
  declare const PREVIEW_WIDGET_ORIGIN = "https://cdn.croct.io";
5
- declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.0.html";
5
+ declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.2.html";
6
6
 
7
7
  export { CDN_URL, PLAYGROUND_CONNECT_URL, PLAYGROUND_ORIGIN, PREVIEW_WIDGET_ORIGIN, PREVIEW_WIDGET_URL };
package/constants.d.ts CHANGED
@@ -2,6 +2,6 @@ declare const CDN_URL = "https://cdn.croct.io/js/v1/lib/plug.js";
2
2
  declare const PLAYGROUND_ORIGIN = "https://play.croct.com";
3
3
  declare const PLAYGROUND_CONNECT_URL = "https://play.croct.com/connect.html";
4
4
  declare const PREVIEW_WIDGET_ORIGIN = "https://cdn.croct.io";
5
- declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.0.html";
5
+ declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.2.html";
6
6
 
7
7
  export { CDN_URL, PLAYGROUND_CONNECT_URL, PLAYGROUND_ORIGIN, PREVIEW_WIDGET_ORIGIN, PREVIEW_WIDGET_URL };
package/constants.js CHANGED
@@ -2,7 +2,7 @@ const CDN_URL = "https://cdn.croct.io/js/v1/lib/plug.js";
2
2
  const PLAYGROUND_ORIGIN = "https://play.croct.com";
3
3
  const PLAYGROUND_CONNECT_URL = "https://play.croct.com/connect.html";
4
4
  const PREVIEW_WIDGET_ORIGIN = "https://cdn.croct.io";
5
- const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.0.html";
5
+ const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.17.2.html";
6
6
  export {
7
7
  CDN_URL,
8
8
  PLAYGROUND_CONNECT_URL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/plug",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "A fully-featured devkit for building natively personalized applications.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -61,7 +61,7 @@
61
61
  "devDependencies": {
62
62
  "@croct/eslint-plugin": "^0.7.1",
63
63
  "@rollup/plugin-commonjs": "^28.0.0",
64
- "@rollup/plugin-node-resolve": "^15.2.3",
64
+ "@rollup/plugin-node-resolve": "^16.0.0",
65
65
  "@rollup/plugin-replace": "^6.0.0",
66
66
  "@rollup/plugin-terser": "^0.4.4",
67
67
  "@rollup/plugin-typescript": "^12.0.0",
package/plug.cjs CHANGED
@@ -74,6 +74,9 @@ class GlobalPlug {
74
74
  );
75
75
  }
76
76
  const { plugins, test, ...sdkConfiguration } = configuration;
77
+ if (sdkConfiguration.defaultPreferredLocale === "") {
78
+ delete sdkConfiguration.defaultPreferredLocale;
79
+ }
77
80
  const sdk = import_sdkFacade.SdkFacade.init({
78
81
  ...sdkConfiguration,
79
82
  appId,
@@ -219,12 +222,17 @@ class GlobalPlug {
219
222
  test(expression, options = {}) {
220
223
  return this.evaluate(expression, options).then((result) => result === true);
221
224
  }
222
- fetch(slotId, { fallback, ...options } = {}) {
225
+ fetch(slotId, { fallback, preferredLocale = "", ...options } = {}) {
223
226
  const [id, version = "latest"] = slotId.split("@");
224
227
  const logger = this.sdk.getLogger();
225
- return this.sdk.contentFetcher.fetch(id, version === "latest" ? options : { ...options, version }).catch(async (error) => {
228
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
229
+ return this.sdk.contentFetcher.fetch(id, {
230
+ ...options,
231
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
232
+ ...version !== "latest" ? { version } : {}
233
+ }).catch(async (error) => {
226
234
  logger.error(`Failed to fetch content for slot "${id}@${version}": ${(0, import_error.formatCause)(error)}`);
227
- const resolvedFallback = fallback === void 0 ? await (0, import_content.loadSlotContent)(slotId, options.preferredLocale) ?? void 0 : fallback;
235
+ const resolvedFallback = fallback === void 0 ? await (0, import_content.loadSlotContent)(slotId, normalizedLocale) ?? void 0 : fallback;
228
236
  if (resolvedFallback === void 0) {
229
237
  throw error;
230
238
  }
package/plug.js CHANGED
@@ -52,6 +52,9 @@ class GlobalPlug {
52
52
  );
53
53
  }
54
54
  const { plugins, test, ...sdkConfiguration } = configuration;
55
+ if (sdkConfiguration.defaultPreferredLocale === "") {
56
+ delete sdkConfiguration.defaultPreferredLocale;
57
+ }
55
58
  const sdk = SdkFacade.init({
56
59
  ...sdkConfiguration,
57
60
  appId,
@@ -197,12 +200,17 @@ class GlobalPlug {
197
200
  test(expression, options = {}) {
198
201
  return this.evaluate(expression, options).then((result) => result === true);
199
202
  }
200
- fetch(slotId, { fallback, ...options } = {}) {
203
+ fetch(slotId, { fallback, preferredLocale = "", ...options } = {}) {
201
204
  const [id, version = "latest"] = slotId.split("@");
202
205
  const logger = this.sdk.getLogger();
203
- return this.sdk.contentFetcher.fetch(id, version === "latest" ? options : { ...options, version }).catch(async (error) => {
206
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
207
+ return this.sdk.contentFetcher.fetch(id, {
208
+ ...options,
209
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
210
+ ...version !== "latest" ? { version } : {}
211
+ }).catch(async (error) => {
204
212
  logger.error(`Failed to fetch content for slot "${id}@${version}": ${formatCause(error)}`);
205
- const resolvedFallback = fallback === void 0 ? await loadSlotContent(slotId, options.preferredLocale) ?? void 0 : fallback;
213
+ const resolvedFallback = fallback === void 0 ? await loadSlotContent(slotId, normalizedLocale) ?? void 0 : fallback;
206
214
  if (resolvedFallback === void 0) {
207
215
  throw error;
208
216
  }