@salesforce/platform-sdk 11.35.6 → 11.37.0

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.
@@ -239,7 +239,7 @@ class fe {
239
239
  })).structuredContent;
240
240
  }
241
241
  }
242
- const pe = "X-SFDC-Client-Name", me = "X-SFDC-Client-Version", ye = "@salesforce/platform-sdk", be = "11.35.6", ve = (r) => {
242
+ const pe = "X-SFDC-Client-Name", me = "X-SFDC-Client-Version", ye = "@salesforce/platform-sdk", be = "11.37.0", ve = (r) => {
243
243
  let e = b(pe, ye, r);
244
244
  return e = b(me, be, e), u(e);
245
245
  }, Se = "X-CSRF-Token";
@@ -7,4 +7,6 @@ export { fetchI18nContext, createSalesforceDetector, reloadI18nContext, } from '
7
7
  export type { I18nContext } from './salesforce-detector';
8
8
  export { SalesforceBackend } from './salesforce-backend';
9
9
  export type { SalesforceBackendOptions } from './salesforce-backend';
10
+ export { createI18nFormatters } from './locale-format';
11
+ export type { I18nFormatters } from './locale-format';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,9 +1,9 @@
1
1
  let o = null;
2
- async function i(r) {
2
+ async function c(a) {
3
3
  if (o) return o;
4
- if (!r.graphql)
4
+ if (!a.graphql)
5
5
  throw new Error("Data SDK GraphQL surface unavailable");
6
- const a = await r.graphql.query({
6
+ const t = await a.graphql.query({
7
7
  operationName: "I18nDetect",
8
8
  query: `
9
9
  query I18nDetect {
@@ -21,17 +21,17 @@ async function i(r) {
21
21
  }
22
22
  `
23
23
  });
24
- if (!a.data)
24
+ if (!t.data)
25
25
  throw new Error(
26
- `I18nDetect query failed: ${JSON.stringify(a.errors ?? "no data, no errors")}`
26
+ `I18nDetect query failed: ${JSON.stringify(t.errors ?? "no data, no errors")}`
27
27
  );
28
- const e = a.data.uiapi.platform.i18n;
28
+ const e = t.data.uiapi.platform.i18n;
29
29
  return o = e, e;
30
30
  }
31
- async function f(r) {
32
- return o = null, i(r);
31
+ async function f(a) {
32
+ return o = null, c(a);
33
33
  }
34
- function p(r) {
34
+ function d(a) {
35
35
  return {
36
36
  type: "languageDetector",
37
37
  detect() {
@@ -39,7 +39,7 @@ function p(r) {
39
39
  }
40
40
  };
41
41
  }
42
- const c = `
42
+ const i = `
43
43
  query Labels($ns: String!, $names: [String!]!, $locale: String) {
44
44
  uiapi {
45
45
  platform {
@@ -53,36 +53,36 @@ const c = `
53
53
  }
54
54
  }
55
55
  `;
56
- function u(r) {
57
- const a = {};
58
- for (const e of r) {
59
- const t = e.indexOf(":");
60
- if (t === -1) continue;
61
- const n = e.slice(0, t), l = e.slice(t + 1);
62
- (a[n] ??= []).push(l);
56
+ function u(a) {
57
+ const t = {};
58
+ for (const e of a) {
59
+ const r = e.indexOf(":");
60
+ if (r === -1) continue;
61
+ const n = e.slice(0, r), l = e.slice(r + 1);
62
+ (t[n] ??= []).push(l);
63
63
  }
64
- return a;
64
+ return t;
65
65
  }
66
- class d {
66
+ class p {
67
67
  type = "backend";
68
68
  static type = "backend";
69
69
  options = { dataSDK: {} };
70
70
  grouped = {};
71
- init(a, e) {
71
+ init(t, e) {
72
72
  this.options = e, this.grouped = u(e.labelManifest ?? []);
73
73
  }
74
- read(a, e, t) {
75
- this.loadLabels(a, e).then((n) => t(null, n)).catch((n) => t(n, !1));
74
+ read(t, e, r) {
75
+ this.loadLabels(t, e).then((n) => r(null, n)).catch((n) => r(n, !1));
76
76
  }
77
- async loadLabels(a, e) {
78
- const t = this.grouped[e];
79
- if (!t?.length) return {};
77
+ async loadLabels(t, e) {
78
+ const r = this.grouped[e];
79
+ if (!r?.length) return {};
80
80
  if (!this.options.dataSDK.graphql)
81
81
  throw new Error("Data SDK GraphQL surface unavailable");
82
82
  const n = await this.options.dataSDK.graphql.query({
83
83
  operationName: "Labels",
84
- query: c,
85
- variables: { ns: e, names: t, locale: a }
84
+ query: i,
85
+ variables: { ns: e, names: r, locale: t }
86
86
  });
87
87
  if (!n.data)
88
88
  throw new Error(
@@ -94,9 +94,36 @@ class d {
94
94
  return l;
95
95
  }
96
96
  }
97
+ function m(a) {
98
+ const t = a.locale.replace(/_/g, "-") || void 0;
99
+ return {
100
+ formatDate(e, r) {
101
+ return new Intl.DateTimeFormat(t, {
102
+ timeZone: a.timeZone || void 0,
103
+ ...r
104
+ }).format(e);
105
+ },
106
+ formatNumber(e, r) {
107
+ return new Intl.NumberFormat(t, r).format(e);
108
+ },
109
+ formatCurrency(e, r) {
110
+ const n = r?.currency ?? a.currency;
111
+ if (!n)
112
+ throw new Error(
113
+ "createI18nFormatters: formatCurrency requires a currency code, but the i18n context did not provide one and none was passed in options."
114
+ );
115
+ return new Intl.NumberFormat(t, {
116
+ style: "currency",
117
+ ...r,
118
+ currency: n
119
+ }).format(e);
120
+ }
121
+ };
122
+ }
97
123
  export {
98
- d as SalesforceBackend,
99
- p as createSalesforceDetector,
100
- i as fetchI18nContext,
124
+ p as SalesforceBackend,
125
+ m as createI18nFormatters,
126
+ d as createSalesforceDetector,
127
+ c as fetchI18nContext,
101
128
  f as reloadI18nContext
102
129
  };
@@ -0,0 +1,37 @@
1
+ import { I18nContext } from './salesforce-detector';
2
+ /**
3
+ * Locale-aware formatting functions bound to a single {@link I18nContext}.
4
+ *
5
+ * Each function wraps a built-in `Intl` formatter constructed from the
6
+ * context's locale (plus, where relevant, its currency and time zone).
7
+ * Callers can override any default by passing their own options: the
8
+ * context-derived defaults are merged first, so caller options always win.
9
+ */
10
+ export interface I18nFormatters {
11
+ formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
12
+ formatNumber(value: number, options?: Intl.NumberFormatOptions): string;
13
+ formatCurrency(value: number, options?: Intl.NumberFormatOptions): string;
14
+ }
15
+ /**
16
+ * Build a set of locale-aware formatters bound to the given {@link I18nContext}.
17
+ *
18
+ * This factory is pure and synchronous: it takes an already-fetched context
19
+ * rather than fetching one itself, so it never imports `DataSDK` or calls
20
+ * `fetchI18nContext`. This mirrors the factory shape of
21
+ * `createSalesforceDetector` and keeps the returned formatters trivially
22
+ * unit-testable with a plain `I18nContext` fixture.
23
+ *
24
+ * The formatters are built from `ctx.locale`, the formatting axis, not
25
+ * `ctx.lang`, the translation axis. The platform i18n context returns
26
+ * `locale` as a BCP 47 tag (for example `"en-US"` or `"en-GB"`), which `Intl`
27
+ * accepts directly. Using `locale` rather than `lang` is deliberate: a user
28
+ * can share a language but differ in locale (for example `lang: "en"` with
29
+ * `locale: "en-GB"`), and only `locale` carries the region that decides date
30
+ * order and digit grouping.
31
+ *
32
+ * @param ctx the resolved i18n context to format against (locale, currency,
33
+ * and time zone are read from it as defaults)
34
+ * @returns an {@link I18nFormatters} bound to `ctx`
35
+ */
36
+ export declare function createI18nFormatters(ctx: I18nContext): I18nFormatters;
37
+ //# sourceMappingURL=locale-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-format.d.ts","sourceRoot":"","sources":["../../src/i18n/locale-format.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC9B,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;IAC/E,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IACxE,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;CAC1E;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,cAAc,CAkDrE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/platform-sdk",
3
- "version": "11.35.6",
3
+ "version": "11.37.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -115,7 +115,7 @@
115
115
  "@conduit-client/service-pubsub": "3.19.6",
116
116
  "@conduit-client/service-retry": "3.19.6",
117
117
  "@conduit-client/utils": "3.19.6",
118
- "@salesforce/jsonrpc": "^11.35.6",
118
+ "@salesforce/jsonrpc": "^11.37.0",
119
119
  "@salesforce/sf-embedding-bridge": "2.2.5-rc.2"
120
120
  },
121
121
  "peerDependencies": {