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