@salesforce/sdk-data 1.94.1 → 1.96.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/index.js +108 -103
- package/dist/webapp/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { getSurface as
|
|
2
|
-
const
|
|
3
|
-
class
|
|
4
|
-
async graphql(e,
|
|
5
|
-
return (await window.openai.callTool(
|
|
1
|
+
import { getSurface as R, Surface as h } from "@salesforce/sdk-core";
|
|
2
|
+
const S = "salesforce_graphql";
|
|
3
|
+
class T {
|
|
4
|
+
async graphql(e, t) {
|
|
5
|
+
return (await window.openai.callTool(S, {
|
|
6
6
|
query: e,
|
|
7
|
-
...
|
|
7
|
+
...t != null ? { variables: t } : {}
|
|
8
8
|
})).structuredContent;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
function u(
|
|
12
|
-
return
|
|
13
|
-
then: (e,
|
|
11
|
+
function u(r) {
|
|
12
|
+
return v(r) ? r.then((e) => e) : {
|
|
13
|
+
then: (e, t) => {
|
|
14
14
|
try {
|
|
15
|
-
return u(e(
|
|
15
|
+
return u(e(r));
|
|
16
16
|
} catch (n) {
|
|
17
|
-
return e === void 0 ? u(
|
|
17
|
+
return e === void 0 ? u(r) : P(n);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return
|
|
24
|
-
then: (e,
|
|
25
|
-
if (typeof
|
|
22
|
+
function P(r) {
|
|
23
|
+
return v(r) ? r.then((e) => e) : {
|
|
24
|
+
then: (e, t) => {
|
|
25
|
+
if (typeof t == "function")
|
|
26
26
|
try {
|
|
27
|
-
return u(r
|
|
27
|
+
return u(t(r));
|
|
28
28
|
} catch (n) {
|
|
29
|
-
return
|
|
29
|
+
return P(n);
|
|
30
30
|
}
|
|
31
|
-
return
|
|
31
|
+
return P(r);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
return typeof
|
|
35
|
+
function v(r) {
|
|
36
|
+
return typeof r?.then == "function";
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function I(r = {
|
|
39
39
|
request: [],
|
|
40
40
|
retry: void 0,
|
|
41
41
|
response: [],
|
|
@@ -44,19 +44,19 @@ function A(t = {
|
|
|
44
44
|
return {
|
|
45
45
|
type: "fetch",
|
|
46
46
|
version: "1.0",
|
|
47
|
-
service: function(...
|
|
47
|
+
service: function(...t) {
|
|
48
48
|
var n;
|
|
49
|
-
const s = (n =
|
|
49
|
+
const s = (n = r.createContext) == null ? void 0 : n.call(r), {
|
|
50
50
|
request: a = [],
|
|
51
51
|
retry: c = void 0,
|
|
52
52
|
response: o = [],
|
|
53
53
|
finally: y = []
|
|
54
|
-
} =
|
|
54
|
+
} = r, p = a.reduce(
|
|
55
55
|
(i, l) => i.then((w) => l(w, s)),
|
|
56
|
-
u(
|
|
56
|
+
u(t)
|
|
57
57
|
);
|
|
58
58
|
return Promise.resolve(p).then((i) => c ? c(i, e, s) : e ? e.applyRetry(() => fetch(...i)) : fetch(...i)).then((i) => o.reduce(
|
|
59
|
-
(l, w) => l.then((
|
|
59
|
+
(l, w) => l.then((C) => w(C, s)),
|
|
60
60
|
u(i)
|
|
61
61
|
)).finally(() => {
|
|
62
62
|
if (y.length > 0)
|
|
@@ -68,47 +68,47 @@ function A(t = {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function b(r, e, [t, n = {}], {
|
|
72
72
|
throwOnExisting: s = !1,
|
|
73
|
-
errorMessage: a = `Unexpected ${
|
|
73
|
+
errorMessage: a = `Unexpected ${r} header encountered`
|
|
74
74
|
} = {}) {
|
|
75
75
|
let c = !1;
|
|
76
|
-
if (
|
|
77
|
-
if (s &&
|
|
76
|
+
if (t instanceof Request && !n?.headers) {
|
|
77
|
+
if (s && t.headers.has(r))
|
|
78
78
|
throw new Error(a);
|
|
79
|
-
|
|
79
|
+
t.headers.set(r, e), c = !0;
|
|
80
80
|
}
|
|
81
81
|
if (n?.headers instanceof Headers) {
|
|
82
|
-
if (s && n.headers.has(
|
|
82
|
+
if (s && n.headers.has(r))
|
|
83
83
|
throw new Error(a);
|
|
84
|
-
n.headers.set(
|
|
84
|
+
n.headers.set(r, e);
|
|
85
85
|
} else {
|
|
86
|
-
if (s && n?.headers && Reflect.has(n.headers,
|
|
86
|
+
if (s && n?.headers && Reflect.has(n.headers, r))
|
|
87
87
|
throw new Error(a);
|
|
88
88
|
c || (n.headers = {
|
|
89
89
|
...n?.headers,
|
|
90
|
-
[
|
|
90
|
+
[r]: e
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
return [
|
|
93
|
+
return [t, n];
|
|
94
94
|
}
|
|
95
|
-
class
|
|
95
|
+
class A {
|
|
96
96
|
constructor(e) {
|
|
97
97
|
this.defaultRetryPolicy = e;
|
|
98
98
|
}
|
|
99
|
-
applyRetry(e,
|
|
100
|
-
return this.retry(e,
|
|
99
|
+
applyRetry(e, t) {
|
|
100
|
+
return this.retry(e, t || this.defaultRetryPolicy);
|
|
101
101
|
}
|
|
102
|
-
async retry(e,
|
|
102
|
+
async retry(e, t) {
|
|
103
103
|
const n = Date.now();
|
|
104
104
|
let s = 0, a = await e(), c = {
|
|
105
105
|
attempt: s,
|
|
106
106
|
totalElapsedMs: Date.now() - n,
|
|
107
107
|
lastResult: a
|
|
108
108
|
};
|
|
109
|
-
for (; await
|
|
110
|
-
const o = await
|
|
111
|
-
await this.delay(o),
|
|
109
|
+
for (; await t.shouldRetry(a, c); ) {
|
|
110
|
+
const o = await t.calculateDelay(a, c);
|
|
111
|
+
await this.delay(o), t.prepareRetry && await t.prepareRetry(a, c), s++, a = await e(), c = {
|
|
112
112
|
attempt: s,
|
|
113
113
|
totalElapsedMs: Date.now() - n,
|
|
114
114
|
lastResult: a
|
|
@@ -117,62 +117,62 @@ class I {
|
|
|
117
117
|
return a;
|
|
118
118
|
}
|
|
119
119
|
delay(e) {
|
|
120
|
-
return new Promise((
|
|
121
|
-
setTimeout(
|
|
120
|
+
return new Promise((t) => {
|
|
121
|
+
setTimeout(t, e);
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
class
|
|
125
|
+
class D {
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function E(r) {
|
|
128
128
|
return {
|
|
129
129
|
version: "1.0",
|
|
130
|
-
service: new
|
|
130
|
+
service: new A(r),
|
|
131
131
|
type: "retry"
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
-
const
|
|
135
|
-
function q(
|
|
136
|
-
const { protectedUrls:
|
|
134
|
+
const _ = "X-CSRF-Token";
|
|
135
|
+
function q(r, e = {}) {
|
|
136
|
+
const { protectedUrls: t = [], alwaysProtectedUrls: n = [] } = e;
|
|
137
137
|
return async (s) => {
|
|
138
138
|
const [a, c] = s, o = new Request(a, c);
|
|
139
|
-
if (!o.headers.has(
|
|
140
|
-
const p = await
|
|
141
|
-
s =
|
|
139
|
+
if (!o.headers.has(_) && (k(n, o.url) || g(o.method) && k(t, o.url))) {
|
|
140
|
+
const p = await r.getToken();
|
|
141
|
+
s = b(_, p, s);
|
|
142
142
|
}
|
|
143
143
|
return u(s);
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
-
function g(
|
|
147
|
-
const e =
|
|
146
|
+
function g(r) {
|
|
147
|
+
const e = r.toLowerCase();
|
|
148
148
|
return e === "post" || e === "put" || e === "patch" || e === "delete";
|
|
149
149
|
}
|
|
150
|
-
function
|
|
151
|
-
const
|
|
152
|
-
return
|
|
150
|
+
function k(r, e) {
|
|
151
|
+
const t = new URL(e);
|
|
152
|
+
return r.some((n) => t.pathname.includes(n));
|
|
153
153
|
}
|
|
154
|
-
function
|
|
155
|
-
const
|
|
154
|
+
function M(r, e = {}) {
|
|
155
|
+
const t = q(r, e);
|
|
156
156
|
async function n(s) {
|
|
157
|
-
const a = await
|
|
157
|
+
const a = await t(s);
|
|
158
158
|
return fetch(a[0], a[1]);
|
|
159
159
|
}
|
|
160
160
|
return (s, a) => a ? a.applyRetry(async () => n(s)) : n(s);
|
|
161
161
|
}
|
|
162
|
-
class
|
|
162
|
+
class $ extends D {
|
|
163
163
|
constructor(e) {
|
|
164
164
|
super(e), this.csrfTokenManager = e;
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
167
|
* Determines if a failed request should be retried due to CSRF token issues.
|
|
168
168
|
*/
|
|
169
|
-
async shouldRetry(e,
|
|
170
|
-
return
|
|
169
|
+
async shouldRetry(e, t) {
|
|
170
|
+
return t.attempt >= 1 || e.status !== 400 ? !1 : await F(e);
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
173
|
* CSRF token refresh should happen immediately with no delay.
|
|
174
174
|
*/
|
|
175
|
-
async calculateDelay(e,
|
|
175
|
+
async calculateDelay(e, t) {
|
|
176
176
|
return 0;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
@@ -181,20 +181,20 @@ class H extends b {
|
|
|
181
181
|
* @param _result - The failed response that triggered the retry (unused, already validated)
|
|
182
182
|
* @param _context - Current retry context (unused but part of interface)
|
|
183
183
|
*/
|
|
184
|
-
async prepareRetry(e,
|
|
184
|
+
async prepareRetry(e, t) {
|
|
185
185
|
await this.csrfTokenManager.refreshToken();
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
async function
|
|
188
|
+
async function F(r) {
|
|
189
189
|
try {
|
|
190
|
-
return (await
|
|
190
|
+
return (await r.clone().json())[0]?.errorCode === "INVALID_ACCESS_TOKEN";
|
|
191
191
|
} catch {
|
|
192
192
|
return !1;
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
class
|
|
196
|
-
constructor(e,
|
|
197
|
-
this.endpoint = e, this.cacheName =
|
|
195
|
+
class N {
|
|
196
|
+
constructor(e, t) {
|
|
197
|
+
this.endpoint = e, this.cacheName = t, this.tokenPromise = this.obtainToken();
|
|
198
198
|
}
|
|
199
199
|
tokenPromise;
|
|
200
200
|
/**
|
|
@@ -217,10 +217,10 @@ class O {
|
|
|
217
217
|
* @returns Promise that resolves to the CSRF token string
|
|
218
218
|
*/
|
|
219
219
|
async obtainToken() {
|
|
220
|
-
let e = await this.withCache((s) => s.match(this.endpoint)),
|
|
221
|
-
e || (e = await fetch(this.endpoint, { method: "get" }),
|
|
220
|
+
let e = await this.withCache((s) => s.match(this.endpoint)), t = !1;
|
|
221
|
+
e || (e = await fetch(this.endpoint, { method: "get" }), t = !0);
|
|
222
222
|
const n = (await e.clone().json()).csrfToken;
|
|
223
|
-
return
|
|
223
|
+
return t && await this.withCache((s) => s.put(this.endpoint, e)), n;
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
226
|
* Provides a safe way to interact with the Cache API with fallback for unsupported environments.
|
|
@@ -230,47 +230,52 @@ class O {
|
|
|
230
230
|
*/
|
|
231
231
|
async withCache(e) {
|
|
232
232
|
if (this.cacheName && caches) {
|
|
233
|
-
const
|
|
234
|
-
return e(
|
|
233
|
+
const t = await caches.open(this.cacheName);
|
|
234
|
+
return e(t);
|
|
235
235
|
} else
|
|
236
236
|
return;
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
function
|
|
240
|
-
const e =
|
|
241
|
-
return
|
|
242
|
-
{ retry:
|
|
243
|
-
|
|
239
|
+
function O(r) {
|
|
240
|
+
const e = r.csrf, t = new N(e.endpoint, e.cacheName);
|
|
241
|
+
return I(
|
|
242
|
+
{ retry: M(t, e) },
|
|
243
|
+
E(new $(t)).service
|
|
244
244
|
).service;
|
|
245
245
|
}
|
|
246
|
-
const
|
|
247
|
-
|
|
246
|
+
const H = 1, U = `@salesforce/sdk-data_v${H}`, x = typeof __SF_API_VERSION__ < "u" ? __SF_API_VERSION__ : "65.0", m = `/services/data/v${x}`, L = `${m}/ui-api`, j = (() => {
|
|
247
|
+
const r = globalThis.SFDC_ENV;
|
|
248
|
+
if (!r) return "";
|
|
249
|
+
const e = (t) => (t.startsWith("/") || (t = `/${t}`), t.endsWith("/") && (t = t.slice(0, -1)), t);
|
|
250
|
+
return e(r.basePath) + e(r.apiPath);
|
|
251
|
+
})();
|
|
252
|
+
class K {
|
|
248
253
|
base;
|
|
249
254
|
clientFetch;
|
|
250
255
|
on401;
|
|
251
256
|
on403;
|
|
252
257
|
constructor(e) {
|
|
253
|
-
this.base = e?.basePath ??
|
|
258
|
+
this.base = e?.basePath ?? j, this.on401 = e?.on401, this.on403 = e?.on403, this.clientFetch = O({
|
|
254
259
|
csrf: {
|
|
255
|
-
endpoint: `${this.base}${
|
|
260
|
+
endpoint: `${this.base}${L}/session/csrf`,
|
|
256
261
|
cacheName: U,
|
|
257
262
|
protectedUrls: ["/services/data/v", "/services/apexrest"],
|
|
258
263
|
alwaysProtectedUrls: ["/services/apexrest"]
|
|
259
264
|
}
|
|
260
265
|
});
|
|
261
266
|
}
|
|
262
|
-
async graphql(e,
|
|
263
|
-
return (await this.fetch(`${
|
|
267
|
+
async graphql(e, t) {
|
|
268
|
+
return (await this.fetch(`${m}/graphql`, {
|
|
264
269
|
method: "POST",
|
|
265
|
-
body: JSON.stringify({ query: e, variables:
|
|
270
|
+
body: JSON.stringify({ query: e, variables: t }),
|
|
266
271
|
headers: {
|
|
267
272
|
"Content-Type": "application/json",
|
|
268
273
|
Accept: "application/json"
|
|
269
274
|
}
|
|
270
275
|
})).json();
|
|
271
276
|
}
|
|
272
|
-
async fetch(e,
|
|
273
|
-
const n = this.applySalesforceBase(e), s = await this.clientFetch(n,
|
|
277
|
+
async fetch(e, t) {
|
|
278
|
+
const n = this.applySalesforceBase(e), s = await this.clientFetch(n, t);
|
|
274
279
|
switch (s.status) {
|
|
275
280
|
case 401:
|
|
276
281
|
await this.on401?.();
|
|
@@ -289,19 +294,19 @@ class B {
|
|
|
289
294
|
return typeof e == "string" ? e.startsWith("http") ? e : this.base + e : e;
|
|
290
295
|
}
|
|
291
296
|
}
|
|
292
|
-
function
|
|
293
|
-
let
|
|
297
|
+
function V(r, ...e) {
|
|
298
|
+
let t = r[0] ?? "";
|
|
294
299
|
for (let n = 0; n < e.length; n += 1)
|
|
295
|
-
|
|
296
|
-
return
|
|
300
|
+
t += String(e[n]) + (r[n + 1] ?? "");
|
|
301
|
+
return t;
|
|
297
302
|
}
|
|
298
|
-
async function
|
|
299
|
-
switch (
|
|
303
|
+
async function W(r) {
|
|
304
|
+
switch (R(r?.surface)) {
|
|
300
305
|
case h.OpenAI:
|
|
301
|
-
return new
|
|
306
|
+
return new T();
|
|
302
307
|
case h.WebApp:
|
|
303
308
|
case h.MicroFrontend:
|
|
304
|
-
return new
|
|
309
|
+
return new K(r?.webapp);
|
|
305
310
|
case h.SalesforceACC:
|
|
306
311
|
return {};
|
|
307
312
|
case h.MCPApps:
|
|
@@ -311,10 +316,10 @@ async function K(t) {
|
|
|
311
316
|
}
|
|
312
317
|
}
|
|
313
318
|
let f = null, d = null;
|
|
314
|
-
async function z(
|
|
319
|
+
async function z(r) {
|
|
315
320
|
if (f)
|
|
316
321
|
return f;
|
|
317
|
-
d || (d =
|
|
322
|
+
d || (d = W(r));
|
|
318
323
|
try {
|
|
319
324
|
return f = await d, f;
|
|
320
325
|
} catch (e) {
|
|
@@ -322,7 +327,7 @@ async function z(t) {
|
|
|
322
327
|
}
|
|
323
328
|
}
|
|
324
329
|
export {
|
|
325
|
-
|
|
330
|
+
W as createDataSDK,
|
|
326
331
|
z as getDataSDK,
|
|
327
|
-
|
|
332
|
+
V as gql
|
|
328
333
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webapp/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webapp/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAMrD,eAAO,MAAM,WAAW,QAA0E,CAAC;AAenG;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC5C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAgC;gBAE3C,OAAO,CAAC,EAAE,oBAAoB;IAepC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAaxE,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiBjF;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAY3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/sdk-data",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.96.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@conduit-client/service-fetch-network": "3.17.0",
|
|
30
30
|
"@conduit-client/utils": "3.17.0",
|
|
31
|
-
"@salesforce/sdk-core": "^1.
|
|
31
|
+
"@salesforce/sdk-core": "^1.96.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"vite": "^7.3.1",
|