@croct/plug 0.17.1 → 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,14 +24,22 @@ 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 preferredLocale = options?.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
38
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
31
39
  const promise = new import_contentFetcher.ContentFetcher({ ...auth, baseEndpointUrl }).fetch(id, {
32
40
  ...fetchOptions,
33
- preferredLocale,
34
- version: version === "latest" ? void 0 : version
41
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
42
+ ...version !== "latest" ? { version } : {}
35
43
  });
36
44
  return promise.catch(
37
45
  async (error) => {
@@ -41,7 +49,7 @@ function fetchContent(slotId, options) {
41
49
  if (fallback !== void 0) {
42
50
  return { content: fallback };
43
51
  }
44
- const staticContent = await (0, import_content.loadSlotContent)(id, preferredLocale);
52
+ const staticContent = await (0, import_content.loadSlotContent)(id, normalizedLocale);
45
53
  if (staticContent === null) {
46
54
  throw error;
47
55
  }
@@ -4,14 +4,22 @@ 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 preferredLocale = options?.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
18
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
11
19
  const promise = new ContentFetcher({ ...auth, baseEndpointUrl }).fetch(id, {
12
20
  ...fetchOptions,
13
- preferredLocale,
14
- version: version === "latest" ? void 0 : version
21
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
22
+ ...version !== "latest" ? { version } : {}
15
23
  });
16
24
  return promise.catch(
17
25
  async (error) => {
@@ -21,7 +29,7 @@ function fetchContent(slotId, options) {
21
29
  if (fallback !== void 0) {
22
30
  return { content: fallback };
23
31
  }
24
- const staticContent = await loadSlotContent(id, preferredLocale);
32
+ const staticContent = await loadSlotContent(id, normalizedLocale);
25
33
  if (staticContent === null) {
26
34
  throw error;
27
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.1.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.1.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.1.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.1.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.1",
3
+ "version": "0.17.2",
4
4
  "description": "A fully-featured devkit for building natively personalized applications.",
5
5
  "license": "MIT",
6
6
  "author": {
package/plug.cjs CHANGED
@@ -222,17 +222,17 @@ class GlobalPlug {
222
222
  test(expression, options = {}) {
223
223
  return this.evaluate(expression, options).then((result) => result === true);
224
224
  }
225
- fetch(slotId, { fallback, ...options } = {}) {
225
+ fetch(slotId, { fallback, preferredLocale = "", ...options } = {}) {
226
226
  const [id, version = "latest"] = slotId.split("@");
227
227
  const logger = this.sdk.getLogger();
228
- const preferredLocale = options.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
228
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
229
229
  return this.sdk.contentFetcher.fetch(id, {
230
230
  ...options,
231
- preferredLocale,
232
- version: version === "latest" ? void 0 : version
231
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
232
+ ...version !== "latest" ? { version } : {}
233
233
  }).catch(async (error) => {
234
234
  logger.error(`Failed to fetch content for slot "${id}@${version}": ${(0, import_error.formatCause)(error)}`);
235
- const resolvedFallback = fallback === void 0 ? await (0, import_content.loadSlotContent)(slotId, preferredLocale) ?? void 0 : fallback;
235
+ const resolvedFallback = fallback === void 0 ? await (0, import_content.loadSlotContent)(slotId, normalizedLocale) ?? void 0 : fallback;
236
236
  if (resolvedFallback === void 0) {
237
237
  throw error;
238
238
  }
package/plug.js CHANGED
@@ -200,17 +200,17 @@ class GlobalPlug {
200
200
  test(expression, options = {}) {
201
201
  return this.evaluate(expression, options).then((result) => result === true);
202
202
  }
203
- fetch(slotId, { fallback, ...options } = {}) {
203
+ fetch(slotId, { fallback, preferredLocale = "", ...options } = {}) {
204
204
  const [id, version = "latest"] = slotId.split("@");
205
205
  const logger = this.sdk.getLogger();
206
- const preferredLocale = options.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
206
+ const normalizedLocale = preferredLocale === "" ? void 0 : preferredLocale;
207
207
  return this.sdk.contentFetcher.fetch(id, {
208
208
  ...options,
209
- preferredLocale,
210
- version: version === "latest" ? void 0 : version
209
+ ...normalizedLocale !== void 0 ? { preferredLocale: normalizedLocale } : {},
210
+ ...version !== "latest" ? { version } : {}
211
211
  }).catch(async (error) => {
212
212
  logger.error(`Failed to fetch content for slot "${id}@${version}": ${formatCause(error)}`);
213
- const resolvedFallback = fallback === void 0 ? await loadSlotContent(slotId, preferredLocale) ?? void 0 : fallback;
213
+ const resolvedFallback = fallback === void 0 ? await loadSlotContent(slotId, normalizedLocale) ?? void 0 : fallback;
214
214
  if (resolvedFallback === void 0) {
215
215
  throw error;
216
216
  }