@salesforce/platform-sdk 11.8.4 → 11.10.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.
@@ -1,61 +1,94 @@
1
- import { g as L, S as m } from "../surface-Dd2tqrPi.js";
2
- import { w as V } from "../sdk-promise-D0sy7OW1.js";
3
- import { buildServiceDescriptor as _, setHeader as y } from "@conduit-client/service-fetch-network/v1";
4
- import { resolvedPromiseLike as u, ok as w, err as C, stableJSONStringify as x, DataNotFoundError as Q, UserVisibleError as H, deepFreeze as b, isUserVisibleError as G } from "@conduit-client/utils";
5
- import { print as D, parse as K } from "@conduit-client/onestore-graphql-parser/v1";
6
- import { RetryPolicy as z, buildServiceDescriptor as W } from "@conduit-client/service-retry/v1";
7
- import { buildServiceDescriptor as j } from "@conduit-client/service-cache/v1";
8
- import { buildServiceDescriptor as B } from "@conduit-client/service-cache-control/v1";
9
- import { buildInMemoryCacheInclusionPolicyService as J } from "@conduit-client/service-cache-inclusion-policy/v1";
10
- import { buildServiceDescriptor as X } from "@conduit-client/service-pubsub/v1";
11
- import { HttpCacheControlCommand as Y } from "@conduit-client/command-http-cache-control/v1";
12
- function Z(t) {
1
+ import { g as x, S as y } from "../surface-Dd2tqrPi.js";
2
+ import { w as K } from "../sdk-promise-D0sy7OW1.js";
3
+ import { buildServiceDescriptor as R, setHeader as b } from "@conduit-client/service-fetch-network/v1";
4
+ import { resolvedPromiseLike as u, ok as C, err as E, stableJSONStringify as V, DataNotFoundError as Q, UserVisibleError as G, deepFreeze as v, isUserVisibleError as z } from "@conduit-client/utils";
5
+ import { print as A, parse as j } from "@conduit-client/onestore-graphql-parser/v1";
6
+ import { RetryPolicy as W, buildServiceDescriptor as B } from "@conduit-client/service-retry/v1";
7
+ import { buildServiceDescriptor as J } from "@conduit-client/service-cache/v1";
8
+ import { buildServiceDescriptor as X } from "@conduit-client/service-cache-control/v1";
9
+ import { buildInMemoryCacheInclusionPolicyService as Y } from "@conduit-client/service-cache-inclusion-policy/v1";
10
+ import { buildServiceDescriptor as Z } from "@conduit-client/service-pubsub/v1";
11
+ import { HttpCacheControlCommand as ee } from "@conduit-client/command-http-cache-control/v1";
12
+ function re(r) {
13
13
  return (e) => {
14
- const [r, n] = e;
15
- if (typeof r == "string" && !r.startsWith("http")) {
16
- const s = r.startsWith("/") ? r : `/${r}`;
17
- return u([`${t}${s}`, n]);
14
+ const [t, n] = e;
15
+ if (typeof t == "string" && !t.startsWith("http")) {
16
+ const s = t.startsWith("/") ? t : `/${t}`;
17
+ return u([`${r}${s}`, n]);
18
18
  }
19
19
  return u(e);
20
20
  };
21
21
  }
22
- function ee(t) {
23
- return (e) => u(y("Authorization", `Bearer ${t}`, e));
22
+ function te(r) {
23
+ return (e) => u(b("Authorization", `Bearer ${r}`, e));
24
24
  }
25
- function re(t, e) {
26
- const r = [];
27
- return t && r.push(Z(t)), e && r.push(ee(e)), _({
28
- request: r
25
+ function ne(r, e) {
26
+ const t = [];
27
+ return r && t.push(re(r)), e && t.push(te(e)), R({
28
+ request: t
29
29
  }).service;
30
30
  }
31
- const v = () => {
32
- }, E = async () => {
31
+ const se = {
32
+ "Content-Type": "application/json",
33
+ Accept: "application/json",
34
+ "X-Chatter-Entity-Encoding": "false"
33
35
  };
34
- function q(t) {
36
+ function ae(r) {
37
+ if (r instanceof Headers) {
38
+ const e = [];
39
+ return r.forEach((t, n) => e.push([n, t])), e;
40
+ }
41
+ return Array.isArray(r) ? r.map(([e, t]) => [e, t]) : Object.entries(r);
42
+ }
43
+ function M(r, e) {
44
+ if (e === void 0) return { ...r };
45
+ const t = { ...r }, n = /* @__PURE__ */ new Map();
46
+ for (const a of Object.keys(t)) n.set(a.toLowerCase(), a);
47
+ const s = /* @__PURE__ */ new Set();
48
+ for (const [a, i] of ae(e)) {
49
+ const o = a.toLowerCase(), c = n.get(o);
50
+ c === void 0 ? (t[a] = i, n.set(o, a), s.add(o)) : s.has(o) ? t[c] = `${t[c]}, ${i}` : (t[c] = i, s.add(o));
51
+ }
52
+ return t;
53
+ }
54
+ function I(r) {
55
+ return M(se, r);
56
+ }
57
+ function oe(r) {
58
+ if (r === void 0) return;
59
+ const e = {};
60
+ return new Headers(r).forEach((t, n) => {
61
+ e[n] = t;
62
+ }), Object.keys(e).length > 0 ? e : void 0;
63
+ }
64
+ const S = () => {
65
+ }, D = async () => {
66
+ };
67
+ function k(r) {
35
68
  try {
36
- return w(K(t));
69
+ return C(j(r));
37
70
  } catch (e) {
38
- return C(l(e));
71
+ return E(d(e));
39
72
  }
40
73
  }
41
- function k(t, e) {
42
- const r = t.definitions.filter(
74
+ function q(r, e) {
75
+ const t = r.definitions.filter(
43
76
  (n) => n.kind === "OperationDefinition"
44
77
  );
45
- return r.length === 0 ? "unknown" : r.length === 1 ? e === void 0 || r[0].name?.value === e ? r[0].operation : "unknown" : e === void 0 ? "unknown" : r.find((n) => n.name?.value === e)?.operation ?? "unknown";
78
+ return t.length === 0 ? "unknown" : t.length === 1 ? e === void 0 || t[0].name?.value === e ? t[0].operation : "unknown" : e === void 0 ? "unknown" : t.find((n) => n.name?.value === e)?.operation ?? "unknown";
46
79
  }
47
- function l(t) {
48
- if (t && typeof t == "object" && "data" in t) {
49
- const e = t.data;
80
+ function d(r) {
81
+ if (r && typeof r == "object" && "data" in r) {
82
+ const e = r.data;
50
83
  if (e && typeof e == "object" && "errors" in e && Array.isArray(e.errors))
51
84
  return e.errors;
52
85
  }
53
- return t instanceof Error ? [{ message: t.message }] : typeof t == "string" ? [{ message: t }] : [{ message: "Unknown error" }];
86
+ return r instanceof Error ? [{ message: r.message }] : typeof r == "string" ? [{ message: r }] : [{ message: "Unknown error" }];
54
87
  }
55
- async function R(t, { mutation: e, variables: r, operationName: n }) {
56
- const s = q(e);
57
- if (s.isErr()) return { data: void 0, errors: s.error };
58
- const a = s.value, o = k(a, n);
88
+ async function L(r, { mutation: e, variables: t, operationName: n, headers: s }) {
89
+ const a = k(e);
90
+ if (a.isErr()) return { data: void 0, errors: a.error };
91
+ const i = a.value, o = q(i, n);
59
92
  if (o !== "mutation")
60
93
  return {
61
94
  data: void 0,
@@ -66,182 +99,192 @@ async function R(t, { mutation: e, variables: r, operationName: n }) {
66
99
  ]
67
100
  };
68
101
  try {
69
- const i = await t({
70
- query: D(a),
71
- variables: r,
72
- operationName: n
102
+ const c = await r({
103
+ query: A(i),
104
+ variables: t,
105
+ operationName: n,
106
+ headers: s
73
107
  });
74
108
  return {
75
- data: i.data ?? void 0,
76
- errors: i.errors
109
+ data: c.data ?? void 0,
110
+ errors: c.errors
77
111
  };
78
- } catch (i) {
79
- return { data: void 0, errors: l(i) };
112
+ } catch (c) {
113
+ return { data: void 0, errors: d(c) };
80
114
  }
81
115
  }
82
- function M(t) {
83
- function e(n, s, a) {
84
- return t({
85
- query: D(n),
116
+ function $(r) {
117
+ function e(n, s, a, i) {
118
+ return r({
119
+ query: A(n),
86
120
  variables: s,
87
- operationName: a
121
+ operationName: a,
122
+ headers: i
88
123
  }).then(
89
124
  (o) => ({
90
125
  data: o.data ?? void 0,
91
126
  errors: o.errors
92
127
  }),
93
- (o) => ({ data: void 0, errors: l(o) })
128
+ (o) => ({ data: void 0, errors: d(o) })
94
129
  );
95
130
  }
96
- async function r({
131
+ async function t({
97
132
  query: n,
98
133
  variables: s,
99
- operationName: a
134
+ operationName: a,
135
+ headers: i
100
136
  }) {
101
- const o = q(n);
137
+ const o = k(n);
102
138
  if (o.isErr())
103
139
  return {
104
140
  data: void 0,
105
141
  errors: o.error,
106
- subscribe: () => v,
107
- refresh: E
142
+ subscribe: () => S,
143
+ refresh: D
108
144
  };
109
- const i = o.value, d = k(i, a);
110
- if (d !== "query")
145
+ const c = o.value, f = q(c, a);
146
+ if (f !== "query")
111
147
  return {
112
148
  data: void 0,
113
149
  errors: [
114
150
  {
115
- message: `DataSDK.graphql.query() requires a GraphQL query, received ${d}.`
151
+ message: `DataSDK.graphql.query() requires a GraphQL query, received ${f}.`
116
152
  }
117
153
  ],
118
- subscribe: () => v,
119
- refresh: E
154
+ subscribe: () => S,
155
+ refresh: D
120
156
  };
121
- const c = /* @__PURE__ */ new Set(), p = s, f = await e(i, p, a);
157
+ const h = /* @__PURE__ */ new Set(), p = s, m = await e(c, p, a, i);
122
158
  return {
123
- data: f.data,
124
- errors: f.errors,
125
- subscribe(h) {
126
- return c.add(h), () => {
127
- c.delete(h);
159
+ data: m.data,
160
+ errors: m.errors,
161
+ subscribe(l) {
162
+ return h.add(l), () => {
163
+ h.delete(l);
128
164
  };
129
165
  },
130
166
  async refresh() {
131
- const h = await e(i, p, a);
132
- for (const S of c) S(h);
167
+ const l = await e(c, p, a, i);
168
+ for (const w of h) w(l);
133
169
  }
134
170
  };
135
171
  }
136
172
  return {
137
- query: r,
138
- mutate: (n) => R(t, n)
173
+ query: t,
174
+ mutate: (n) => L(r, n)
139
175
  };
140
176
  }
141
- const te = typeof __SF_API_VERSION__ < "u" ? __SF_API_VERSION__ : "65.0";
142
- function $(t = te) {
143
- return `/services/data/v${t}`;
177
+ const ie = typeof __SF_API_VERSION__ < "u" ? __SF_API_VERSION__ : "65.0";
178
+ function H(r = ie) {
179
+ return `/services/data/v${r}`;
144
180
  }
145
- class ne {
181
+ const ce = {
182
+ "Content-Type": "application/json",
183
+ Accept: "application/json"
184
+ };
185
+ class ue {
146
186
  clientFetch;
147
187
  pathData;
148
188
  graphql;
149
189
  constructor(e) {
150
- const r = se(), n = ae(e?.instanceUrl ?? r.instanceUrl), s = e?.accessToken ?? r.accessToken;
151
- this.pathData = $(e?.apiVersion ?? r.apiVersion), this.clientFetch = re(n || void 0, s), this.graphql = M(this.executeRawGraphQL.bind(this));
190
+ const t = he(), n = le(e?.instanceUrl ?? t.instanceUrl), s = e?.accessToken ?? t.accessToken;
191
+ this.pathData = H(e?.apiVersion ?? t.apiVersion), this.clientFetch = ne(n || void 0, s), this.graphql = $(this.executeRawGraphQL.bind(this));
152
192
  }
153
193
  async executeRawGraphQL({
154
194
  query: e,
155
- variables: r,
156
- operationName: n
195
+ variables: t,
196
+ operationName: n,
197
+ headers: s
157
198
  }) {
158
199
  return (await this.clientFetch(`${this.pathData}/graphql`, {
159
200
  method: "POST",
160
- body: JSON.stringify({ query: e, variables: r, operationName: n }),
161
- headers: {
162
- "Content-Type": "application/json",
163
- Accept: "application/json"
164
- }
201
+ body: JSON.stringify({ query: e, variables: t, operationName: n }),
202
+ headers: M(ce, s)
165
203
  })).json();
166
204
  }
167
205
  }
168
- function se() {
169
- const t = globalThis.MOSAIC_ENV;
206
+ function he() {
207
+ const r = globalThis.MOSAIC_ENV;
170
208
  return {
171
- instanceUrl: t?.instanceUrl,
172
- accessToken: t?.accessToken,
173
- apiVersion: t?.apiVersion
209
+ instanceUrl: r?.instanceUrl,
210
+ accessToken: r?.accessToken,
211
+ apiVersion: r?.apiVersion
174
212
  };
175
213
  }
176
- function ae(t) {
177
- if (!t || t === "/") return "";
178
- let e = t;
214
+ function le(r) {
215
+ if (!r || r === "/") return "";
216
+ let e = r;
179
217
  return !e.startsWith("/") && !e.startsWith("http") && (e = `/${e}`), e.endsWith("/") && (e = e.slice(0, -1)), e;
180
218
  }
181
- const oe = "graphqlQuery";
182
- class ie {
219
+ const de = "graphqlQuery";
220
+ class fe {
183
221
  graphql;
184
222
  constructor() {
185
- this.graphql = M(this.executeRawGraphQL.bind(this));
223
+ this.graphql = $(this.executeRawGraphQL.bind(this));
186
224
  }
225
+ /**
226
+ * The `headers` request option is intentionally not forwarded: this surface
227
+ * delegates to the `graphqlQuery` MCP tool over the ChatGPT bridge, which
228
+ * issues the HTTP request host-side and exposes no header channel.
229
+ */
187
230
  async executeRawGraphQL({
188
231
  query: e,
189
- variables: r,
232
+ variables: t,
190
233
  operationName: n
191
234
  }) {
192
- return (await window.openai.callTool(oe, {
235
+ return (await window.openai.callTool(de, {
193
236
  query: e,
194
- ...r != null ? { variables: r } : {},
237
+ ...t != null ? { variables: t } : {},
195
238
  ...n != null ? { operationName: n } : {}
196
239
  })).structuredContent;
197
240
  }
198
241
  }
199
- const ce = "X-SFDC-Client-Name", ue = "X-SFDC-Client-Version", he = "@salesforce/platform-sdk", le = "11.8.4", de = (t) => {
200
- let e = y(ce, he, t);
201
- return e = y(ue, le, e), u(e);
202
- }, pe = "X-CSRF-Token";
203
- function fe(t, e = {}) {
204
- const { protectedUrls: r = [], alwaysProtectedUrls: n = [] } = e;
242
+ const pe = "X-SFDC-Client-Name", me = "X-SFDC-Client-Version", ye = "@salesforce/platform-sdk", be = "11.10.0", ve = (r) => {
243
+ let e = b(pe, ye, r);
244
+ return e = b(me, be, e), u(e);
245
+ }, Se = "X-CSRF-Token";
246
+ function we(r, e = {}) {
247
+ const { protectedUrls: t = [], alwaysProtectedUrls: n = [] } = e;
205
248
  return async (s) => {
206
- const [a, o] = s, i = new Request(a, o);
207
- if (P(n, i.url) || me(i.method) && P(r, i.url)) {
208
- const c = await t.getToken();
209
- s = y(pe, c, s);
249
+ const [a, i] = s, o = new Request(a, i);
250
+ if (O(n, o.url) || ge(o.method) && O(t, o.url)) {
251
+ const f = await r.getToken();
252
+ s = b(Se, f, s);
210
253
  }
211
254
  return u(s);
212
255
  };
213
256
  }
214
- function me(t) {
215
- const e = t.toLowerCase();
257
+ function ge(r) {
258
+ const e = r.toLowerCase();
216
259
  return e === "post" || e === "put" || e === "patch" || e === "delete";
217
260
  }
218
- function P(t, e) {
219
- const r = new URL(e);
220
- return t.some((n) => r.pathname.includes(n));
261
+ function O(r, e) {
262
+ const t = new URL(e);
263
+ return r.some((n) => t.pathname.includes(n));
221
264
  }
222
- function ye(t, e = {}) {
223
- const r = fe(t, e);
265
+ function Ce(r, e = {}) {
266
+ const t = we(r, e);
224
267
  async function n(s) {
225
- const a = await r(s);
268
+ const a = await t(s);
226
269
  return fetch(a[0], a[1]);
227
270
  }
228
271
  return (s, a) => a ? a.applyRetry(async () => n(s)) : n(s);
229
272
  }
230
- const be = [400, 401, 403];
231
- class ve extends z {
273
+ const Ee = [400, 401, 403];
274
+ class De extends W {
232
275
  constructor(e) {
233
276
  super(e), this.csrfTokenManager = e;
234
277
  }
235
278
  /**
236
279
  * Determines if a failed request should be retried due to CSRF token issues.
237
280
  */
238
- async shouldRetry(e, r) {
239
- return r.attempt >= 1 ? !1 : be.includes(e.status);
281
+ async shouldRetry(e, t) {
282
+ return t.attempt >= 1 ? !1 : Ee.includes(e.status);
240
283
  }
241
284
  /**
242
285
  * CSRF token refresh should happen immediately with no delay.
243
286
  */
244
- async calculateDelay(e, r) {
287
+ async calculateDelay(e, t) {
245
288
  return 0;
246
289
  }
247
290
  /**
@@ -250,13 +293,13 @@ class ve extends z {
250
293
  * @param _result - The failed response that triggered the retry (unused, already validated)
251
294
  * @param _context - Current retry context (unused but part of interface)
252
295
  */
253
- async prepareRetry(e, r) {
296
+ async prepareRetry(e, t) {
254
297
  await this.csrfTokenManager.refreshToken();
255
298
  }
256
299
  }
257
- class Se {
258
- constructor(e, r) {
259
- this.endpoint = e, this.cacheName = r, this.tokenPromise = this.obtainToken();
300
+ class Ae {
301
+ constructor(e, t) {
302
+ this.endpoint = e, this.cacheName = t, this.tokenPromise = this.obtainToken();
260
303
  }
261
304
  tokenPromise;
262
305
  refreshPromise;
@@ -283,10 +326,10 @@ class Se {
283
326
  * @returns Promise that resolves to the CSRF token string
284
327
  */
285
328
  async obtainToken() {
286
- let e = await this.withCache((s) => s.match(this.endpoint)), r = !1;
287
- e || (e = await fetch(this.endpoint, { method: "get" }), r = !0);
329
+ let e = await this.withCache((s) => s.match(this.endpoint)), t = !1;
330
+ e || (e = await fetch(this.endpoint, { method: "get" }), t = !0);
288
331
  const n = (await e.clone().json()).csrfToken;
289
- return r && await this.withCache((s) => s.put(this.endpoint, e)), n;
332
+ return t && await this.withCache((s) => s.put(this.endpoint, e)), n;
290
333
  }
291
334
  /**
292
335
  * Provides a safe way to interact with the Cache API with fallback for unsupported environments.
@@ -296,87 +339,82 @@ class Se {
296
339
  */
297
340
  async withCache(e) {
298
341
  if (this.cacheName && caches) {
299
- const r = await caches.open(this.cacheName);
300
- return e(r);
342
+ const t = await caches.open(this.cacheName);
343
+ return e(t);
301
344
  } else
302
345
  return;
303
346
  }
304
347
  }
305
- const T = /* @__PURE__ */ new Map();
306
- function ge(t) {
307
- const { endpoint: e, cacheName: r, ...n } = t.csrf;
308
- let s = T.get(e);
309
- return s || (s = new Se(e, r), T.set(e, s)), _(
348
+ const P = /* @__PURE__ */ new Map();
349
+ function ke(r) {
350
+ const { endpoint: e, cacheName: t, ...n } = r.csrf;
351
+ let s = P.get(e);
352
+ return s || (s = new Ae(e, t), P.set(e, s)), R(
310
353
  {
311
- retry: ye(s, n),
312
- request: [de]
354
+ retry: Ce(s, n),
355
+ request: [ve]
313
356
  },
314
- W(new ve(s)).service
357
+ B(new De(s)).service
315
358
  ).service;
316
359
  }
317
- const A = /* @__PURE__ */ new Map();
318
- function we(t) {
319
- let e = A.get(t);
360
+ const _ = /* @__PURE__ */ new Map();
361
+ function qe(r) {
362
+ let e = _.get(r);
320
363
  if (!e) {
321
- const r = j().service, n = J(r).service, s = B(r, n).service, a = X().service;
322
- e = { cache: r, cacheController: s, pubSub: a }, A.set(t, e);
364
+ const t = J().service, n = Y(t).service, s = X(t, n).service, a = Z().service;
365
+ e = { cache: t, cacheController: s, pubSub: a }, _.set(r, e);
323
366
  }
324
367
  return e;
325
368
  }
326
- function Ce(t, e) {
327
- const r = we(t);
369
+ function Oe(r, e) {
370
+ const t = qe(r);
328
371
  return {
329
- shared: r,
372
+ shared: t,
330
373
  services: {
331
- cacheController: r.cacheController,
332
- pubSub: r.pubSub,
374
+ cacheController: t.cacheController,
375
+ pubSub: t.pubSub,
333
376
  fetch: e
334
377
  }
335
378
  };
336
379
  }
337
- function I() {
338
- return {
339
- "Content-Type": "application/json",
340
- Accept: "application/json",
341
- "X-Chatter-Entity-Encoding": "false"
342
- };
343
- }
344
380
  const N = 300;
345
- function Ee(t, e) {
381
+ function Pe(r, e) {
346
382
  try {
347
- return JSON.parse(JSON.stringify(t));
348
- } catch (r) {
383
+ return JSON.parse(JSON.stringify(r));
384
+ } catch (t) {
349
385
  const n = e || "(anonymous)", s = new TypeError(
350
- `HttpGraphQLResourceCacheControlCommand: variables for operation "${n}" must be JSON-serializable. ${r.message}`
386
+ `HttpGraphQLResourceCacheControlCommand: variables for operation "${n}" must be JSON-serializable. ${t.message}`
351
387
  );
352
- throw s.cause = r, s;
388
+ throw s.cause = t, s;
353
389
  }
354
390
  }
355
- function De(t) {
356
- if (typeof t == "object" && t.type === "max-age") {
357
- const e = t.maxAge;
391
+ function _e(r) {
392
+ if (typeof r == "object" && r.type === "max-age") {
393
+ const e = r.maxAge;
358
394
  return Number.isFinite(e) && e >= 0 ? e : N;
359
395
  }
360
396
  return N;
361
397
  }
362
- class qe extends Y {
363
- constructor(e, r, n) {
364
- super(r), this.url = n, this.query = e.query, this.normalizedOperationName = e.operationName ?? "", this.normalizedVariables = Ee(
398
+ class Ne extends ee {
399
+ constructor(e, t, n) {
400
+ super(t), this.url = n, this.query = e.query, this.normalizedOperationName = e.operationName ?? "", this.normalizedVariables = Pe(
365
401
  e.variables ?? {},
366
402
  this.normalizedOperationName
367
- ), this.cacheControl = e.cacheControl, this.resolvedMaxAge = De(e.cacheControl);
403
+ ), this.cacheControl = e.cacheControl, this.resolvedMaxAge = _e(e.cacheControl), this.headers = e.headers, this.headersKey = oe(e.headers);
368
404
  }
369
405
  query;
370
406
  normalizedVariables;
371
407
  normalizedOperationName;
372
408
  cacheControl;
373
409
  resolvedMaxAge;
410
+ headers;
411
+ headersKey;
374
412
  get fetchParams() {
375
413
  return [
376
414
  this.url,
377
415
  {
378
416
  method: "POST",
379
- headers: I(),
417
+ headers: I(this.headers),
380
418
  body: JSON.stringify({
381
419
  query: this.query,
382
420
  variables: this.normalizedVariables,
@@ -386,11 +424,12 @@ class qe extends Y {
386
424
  ];
387
425
  }
388
426
  buildKey() {
389
- return x({
427
+ const e = {
390
428
  query: this.query,
391
429
  variables: this.normalizedVariables,
392
430
  operationName: this.normalizedOperationName
393
- });
431
+ };
432
+ return this.headersKey !== void 0 && (e.headers = this.headersKey), V(e);
394
433
  }
395
434
  /**
396
435
  * Reads from the cache and returns the cache result or error
@@ -406,14 +445,14 @@ class qe extends Y {
406
445
  * @returns result or error from the cache
407
446
  */
408
447
  readFromCache(e) {
409
- const r = this.buildKey(), n = e.get(r)?.value;
410
- return n === void 0 ? u(C(new Q())) : u(w(n));
448
+ const t = this.buildKey(), n = e.get(t)?.value;
449
+ return n === void 0 ? u(E(new Q())) : u(C(n));
411
450
  }
412
- writeToCache(e, r) {
413
- if (r.isOk() && r.value.data != null && Object.keys(r.value.data).length > 0) {
451
+ writeToCache(e, t) {
452
+ if (t.isOk() && t.value.data != null && Object.keys(t.value.data).length > 0) {
414
453
  const n = Math.floor(Date.now() / 1e3);
415
454
  e.set(this.buildKey(), {
416
- value: r.value.data,
455
+ value: t.value.data,
417
456
  metadata: {
418
457
  cacheControl: {
419
458
  type: "max-age",
@@ -437,122 +476,124 @@ class qe extends Y {
437
476
  return e.errors && e.errors.length > 0;
438
477
  }
439
478
  processFetchReturnValue(e) {
440
- return this.responseHasErrors(e) ? C(new H(e)) : w(e);
479
+ return this.responseHasErrors(e) ? E(new G(e)) : C(e);
441
480
  }
442
481
  }
443
- function U(t) {
444
- if (G(t) && t.data && typeof t.data == "object") {
445
- const e = t.data;
482
+ function F(r) {
483
+ if (z(r) && r.data && typeof r.data == "object") {
484
+ const e = r.data;
446
485
  if (e.data != null)
447
486
  return e.data;
448
487
  }
449
488
  }
450
- function ke(t) {
489
+ function Te(r) {
451
490
  return (e) => {
452
491
  if (e.isOk()) {
453
- const r = e.value;
454
- b(r), t({ data: r, errors: void 0 });
492
+ const t = e.value;
493
+ v(t), r({ data: t, errors: void 0 });
455
494
  } else {
456
- const r = U(e.error);
457
- r && b(r), t({ data: r, errors: l(e.error) });
495
+ const t = F(e.error);
496
+ t && v(t), r({ data: t, errors: d(e.error) });
458
497
  }
459
498
  };
460
499
  }
461
- async function Pe(t) {
462
- let e, r, n;
500
+ async function Re(r) {
501
+ let e, t, n;
463
502
  try {
464
- const s = await t.execute();
465
- s.isOk() ? (e = s.value.data, b(e), n = (a) => s.value.subscribe(a)) : (e = U(s.error.failure), e && b(e), r = l(s.error.failure), n = (a) => s.error.subscribe(a));
503
+ const s = await r.execute();
504
+ s.isOk() ? (e = s.value.data, v(e), n = (a) => s.value.subscribe(a)) : (e = F(s.error.failure), e && v(e), t = d(s.error.failure), n = (a) => s.error.subscribe(a));
466
505
  } catch (s) {
467
- r = l(s);
506
+ t = d(s);
468
507
  }
469
508
  return {
470
509
  data: e,
471
- errors: r,
510
+ errors: t,
472
511
  subscribe(s) {
473
- return n ? n(ke(s)) : v;
512
+ return n ? n(Te(s)) : S;
474
513
  },
475
514
  async refresh() {
476
- await t.refresh();
515
+ await r.refresh();
477
516
  }
478
517
  };
479
518
  }
480
- function g(t) {
519
+ function g(r) {
481
520
  return {
482
521
  data: void 0,
483
- errors: t,
484
- subscribe: () => v,
485
- refresh: E
522
+ errors: r,
523
+ subscribe: () => S,
524
+ refresh: D
486
525
  };
487
526
  }
488
- function Te({
489
- bundle: t,
527
+ function Me({
528
+ bundle: r,
490
529
  url: e,
491
- executeRaw: r
530
+ executeRaw: t
492
531
  }) {
493
- const { services: n } = t;
532
+ const { services: n } = r;
494
533
  async function s({
495
534
  query: a,
496
- variables: o,
497
- operationName: i,
498
- cacheControl: d
535
+ variables: i,
536
+ operationName: o,
537
+ cacheControl: c,
538
+ headers: f
499
539
  }) {
500
- const c = q(a);
501
- if (c.isErr()) return g(c.error);
502
- const p = c.value, f = k(p, i);
503
- if (f !== "query")
540
+ const h = k(a);
541
+ if (h.isErr()) return g(h.error);
542
+ const p = h.value, m = q(p, o);
543
+ if (m !== "query")
504
544
  return g([
505
545
  {
506
- message: `DataSDK.graphql.query() requires a GraphQL query, received ${f}.`
546
+ message: `DataSDK.graphql.query() requires a GraphQL query, received ${m}.`
507
547
  }
508
548
  ]);
509
- let h;
549
+ let l;
510
550
  try {
511
- h = new qe(
551
+ l = new Ne(
512
552
  {
513
- query: D(p),
514
- variables: o,
515
- operationName: i,
516
- cacheControl: d
553
+ query: A(p),
554
+ variables: i,
555
+ operationName: o,
556
+ cacheControl: c,
557
+ headers: f
517
558
  },
518
559
  n,
519
560
  e
520
561
  );
521
- } catch (S) {
522
- return g(l(S));
562
+ } catch (w) {
563
+ return g(d(w));
523
564
  }
524
- return Pe(h);
565
+ return Re(l);
525
566
  }
526
567
  return {
527
568
  query: s,
528
- mutate: (a) => R(r, a)
569
+ mutate: (a) => L(t, a)
529
570
  };
530
571
  }
531
- const Ae = 1, Ne = `@salesforce/platform-sdk-data_v${Ae}`, F = $(), Oe = `${F}/ui-api`, O = `${F}/graphql`;
532
- class _e {
572
+ const Ie = 1, Le = `@salesforce/platform-sdk-data_v${Ie}`, U = H(), $e = `${U}/ui-api`, T = `${U}/graphql`;
573
+ class He {
533
574
  baseUrl;
534
575
  clientFetch;
535
576
  onStatus;
536
577
  graphql;
537
578
  constructor(e) {
538
- const r = Re();
539
- this.baseUrl = Me(e?.basePath ?? r.apiPath), this.onStatus = e?.onStatus ?? {}, this.clientFetch = ge({
579
+ const t = Fe();
580
+ this.baseUrl = Ue(e?.basePath ?? t.apiPath), this.onStatus = e?.onStatus ?? {}, this.clientFetch = ke({
540
581
  csrf: {
541
- endpoint: `${this.baseUrl}${Oe}/session/csrf`,
542
- cacheName: Ne,
582
+ endpoint: `${this.baseUrl}${$e}/session/csrf`,
583
+ cacheName: Le,
543
584
  protectedUrls: ["services/data/v", "services/apexrest"],
544
585
  alwaysProtectedUrls: ["services/apexrest"]
545
586
  }
546
587
  });
547
- const n = (a, o) => this.fetch(a, o), s = Ce(this.baseUrl, n);
548
- this.graphql = Te({
588
+ const n = (a, i) => this.fetch(a, i), s = Oe(this.baseUrl, n);
589
+ this.graphql = Me({
549
590
  bundle: s,
550
- url: O,
591
+ url: T,
551
592
  executeRaw: this.executeRawGraphQL.bind(this)
552
593
  });
553
594
  }
554
- async fetch(e, r) {
555
- const n = this.applySalesforceBase(e), s = await this.clientFetch(n, r);
595
+ async fetch(e, t) {
596
+ const n = this.applySalesforceBase(e), s = await this.clientFetch(n, t);
556
597
  return await this.onStatus[s.status]?.(), s;
557
598
  }
558
599
  /**
@@ -563,13 +604,14 @@ class _e {
563
604
  */
564
605
  async executeRawGraphQL({
565
606
  query: e,
566
- variables: r,
567
- operationName: n
607
+ variables: t,
608
+ operationName: n,
609
+ headers: s
568
610
  }) {
569
- return (await this.fetch(O, {
611
+ return (await this.fetch(T, {
570
612
  method: "POST",
571
- body: JSON.stringify({ query: e, variables: r, operationName: n }),
572
- headers: I()
613
+ body: JSON.stringify({ query: e, variables: t, operationName: n }),
614
+ headers: I(s)
573
615
  })).json();
574
616
  }
575
617
  /**
@@ -580,41 +622,41 @@ class _e {
580
622
  if (typeof e == "string") {
581
623
  if (e.startsWith("http"))
582
624
  return e;
583
- const r = e.startsWith("/") ? e : `/${e}`;
584
- return `${this.baseUrl}${r}`;
625
+ const t = e.startsWith("/") ? e : `/${e}`;
626
+ return `${this.baseUrl}${t}`;
585
627
  }
586
628
  return e;
587
629
  }
588
630
  }
589
- function Re() {
631
+ function Fe() {
590
632
  return {
591
633
  apiPath: globalThis.SFDC_ENV?.apiPath
592
634
  };
593
635
  }
594
- function Me(t) {
595
- if (!t || t === "/") return "";
596
- let e = t;
636
+ function Ue(r) {
637
+ if (!r || r === "/") return "";
638
+ let e = r;
597
639
  return e.startsWith("/") || (e = `/${e}`), e.endsWith("/") && (e = e.slice(0, -1)), e;
598
640
  }
599
- function ze(t, ...e) {
600
- let r = t[0] ?? "";
641
+ function Ye(r, ...e) {
642
+ let t = r[0] ?? "";
601
643
  for (let n = 0; n < e.length; n += 1)
602
- r += String(e[n]) + (t[n + 1] ?? "");
603
- return r;
644
+ t += String(e[n]) + (r[n + 1] ?? "");
645
+ return t;
604
646
  }
605
- function We(t) {
606
- return V(
647
+ function Ze(r) {
648
+ return K(
607
649
  (async () => {
608
650
  try {
609
- switch (await L(t?.surface)) {
610
- case m.OpenAI:
611
- return new ie();
612
- case m.WebApp:
613
- case m.MicroFrontend:
614
- return new _e(t?.webapp);
615
- case m.Mosaic:
616
- return new ne(t?.mosaic);
617
- case m.MCPApps:
651
+ switch (await x(r?.surface)) {
652
+ case y.OpenAI:
653
+ return new fe();
654
+ case y.WebApp:
655
+ case y.MicroFrontend:
656
+ return new He(r?.webapp);
657
+ case y.Mosaic:
658
+ return new ue(r?.mosaic);
659
+ case y.MCPApps:
618
660
  return {};
619
661
  default:
620
662
  return {};
@@ -627,6 +669,6 @@ function We(t) {
627
669
  );
628
670
  }
629
671
  export {
630
- We as createDataSDK,
631
- ze as gql
672
+ Ze as createDataSDK,
673
+ Ye as gql
632
674
  };