@croct/plug 0.17.0 → 0.17.1

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.
@@ -27,10 +27,12 @@ function fetchContent(slotId, options) {
27
27
  const { apiKey, appId, fallback, baseEndpointUrl, logger, ...fetchOptions } = options ?? {};
28
28
  const auth = { appId, apiKey };
29
29
  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
- );
30
+ const preferredLocale = options?.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
31
+ const promise = new import_contentFetcher.ContentFetcher({ ...auth, baseEndpointUrl }).fetch(id, {
32
+ ...fetchOptions,
33
+ preferredLocale,
34
+ version: version === "latest" ? void 0 : version
35
+ });
34
36
  return promise.catch(
35
37
  async (error) => {
36
38
  if (logger !== void 0) {
@@ -39,7 +41,7 @@ function fetchContent(slotId, options) {
39
41
  if (fallback !== void 0) {
40
42
  return { content: fallback };
41
43
  }
42
- const staticContent = await (0, import_content.loadSlotContent)(id, fetchOptions.preferredLocale);
44
+ const staticContent = await (0, import_content.loadSlotContent)(id, preferredLocale);
43
45
  if (staticContent === null) {
44
46
  throw error;
45
47
  }
@@ -7,10 +7,12 @@ function fetchContent(slotId, options) {
7
7
  const { apiKey, appId, fallback, baseEndpointUrl, logger, ...fetchOptions } = options ?? {};
8
8
  const auth = { appId, apiKey };
9
9
  const [id, version = "latest"] = slotId.split("@");
10
- const promise = new ContentFetcher({ ...auth, baseEndpointUrl }).fetch(
11
- id,
12
- version === "latest" ? fetchOptions : { ...fetchOptions, version }
13
- );
10
+ const preferredLocale = options?.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
11
+ const promise = new ContentFetcher({ ...auth, baseEndpointUrl }).fetch(id, {
12
+ ...fetchOptions,
13
+ preferredLocale,
14
+ version: version === "latest" ? void 0 : version
15
+ });
14
16
  return promise.catch(
15
17
  async (error) => {
16
18
  if (logger !== void 0) {
@@ -19,7 +21,7 @@ function fetchContent(slotId, options) {
19
21
  if (fallback !== void 0) {
20
22
  return { content: fallback };
21
23
  }
22
- const staticContent = await loadSlotContent(id, fetchOptions.preferredLocale);
24
+ const staticContent = await loadSlotContent(id, preferredLocale);
23
25
  if (staticContent === null) {
24
26
  throw error;
25
27
  }
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.1.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.1.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.1.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.1.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.1",
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,
@@ -222,9 +225,14 @@ class GlobalPlug {
222
225
  fetch(slotId, { fallback, ...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 preferredLocale = options.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
229
+ return this.sdk.contentFetcher.fetch(id, {
230
+ ...options,
231
+ preferredLocale,
232
+ version: version === "latest" ? void 0 : 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, preferredLocale) ?? 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,
@@ -200,9 +203,14 @@ class GlobalPlug {
200
203
  fetch(slotId, { fallback, ...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 preferredLocale = options.preferredLocale !== void 0 && options.preferredLocale !== "" ? options.preferredLocale : void 0;
207
+ return this.sdk.contentFetcher.fetch(id, {
208
+ ...options,
209
+ preferredLocale,
210
+ version: version === "latest" ? void 0 : 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, preferredLocale) ?? void 0 : fallback;
206
214
  if (resolvedFallback === void 0) {
207
215
  throw error;
208
216
  }