@salesforce/sdk-data 1.80.1 → 1.82.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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { DataSDK, SDKOptions } from "@salesforce/sdk-core";
1
+ import { DataSDK, SDKOptions } from '@salesforce/sdk-core';
2
2
  /**
3
3
  * Options for creating a WebAppDataSDK
4
4
  */
@@ -20,8 +20,8 @@ export interface DataSDKOptions extends SDKOptions {
20
20
  * @returns Promise resolving to an initialized DataSDK instance
21
21
  */
22
22
  export declare function createDataSDK(options?: DataSDKOptions): Promise<DataSDK>;
23
- export { gql } from "./gql.js";
24
- export type { DataSDK, SDKOptions } from "@salesforce/sdk-core";
23
+ export { gql } from './gql';
24
+ export type { DataSDK, SDKOptions } from '@salesforce/sdk-core';
25
25
  /**
26
26
  * Get a lazily-initialized DataSDK singleton.
27
27
  * Concurrent first calls await the same initialization promise so createDataSDK runs only once.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIhE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IACjD,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAe9E;AAED,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,C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gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS;IAC3C,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;CAC3B,GAAG,IAAI,GACL,CAAC,SAAS;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,IAAI,GAClC,CAAC,GACD,KAAK,GACN,KAAK,CAAC"}
package/dist/index.js CHANGED
@@ -1,57 +1,93 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import { getSurface, Surface } from "@salesforce/sdk-core";
7
- import { OpenAIDataSDK } from "./openai/index.js";
8
- import { WebAppDataSDK } from "./webapp/index.js";
9
- /**
10
- * Create and initialize a DataSDK instance based on the detected surface
11
- *
12
- * @param options - Optional configuration including surface override
13
- * @returns Promise resolving to an initialized DataSDK instance
14
- */
15
- export async function createDataSDK(options) {
16
- const surface = getSurface(options?.surface);
17
- switch (surface) {
18
- case Surface.OpenAI:
19
- return new OpenAIDataSDK();
20
- case Surface.WebApp:
21
- case Surface.MicroFrontend:
22
- return new WebAppDataSDK(options?.webapp);
23
- case Surface.SalesforceACC:
24
- return {};
25
- case Surface.MCPApps:
26
- return {};
27
- default:
28
- return {};
29
- }
1
+ import { getSurface as u, Surface as a } from "@salesforce/sdk-core";
2
+ import { ConduitClient as i } from "@conduit-client/salesforce-lightning-service-worker";
3
+ const _ = "salesforce_graphql";
4
+ class f {
5
+ async graphql(t, n) {
6
+ return (await window.openai.callTool(_, {
7
+ query: t,
8
+ ...n != null ? { variables: n } : {}
9
+ })).structuredContent;
10
+ }
30
11
  }
31
- export { gql } from "./gql.js";
32
- let sdkInstance = null;
33
- /** Shared promise so concurrent callers await the same initialization (no double createDataSDK). */
34
- let initPromise = null;
35
- /**
36
- * Get a lazily-initialized DataSDK singleton.
37
- * Concurrent first calls await the same initialization promise so createDataSDK runs only once.
38
- *
39
- * @param options - Optional configuration passed to createDataSDK on first call
40
- * @returns The shared DataSDK instance
41
- */
42
- export async function getDataSDK(options) {
43
- if (sdkInstance) {
44
- return sdkInstance;
45
- }
46
- if (!initPromise) {
47
- initPromise = createDataSDK(options);
48
- }
49
- try {
50
- sdkInstance = await initPromise;
51
- return sdkInstance;
52
- }
53
- catch (e) {
54
- initPromise = null;
55
- throw e;
12
+ const p = 1, h = `@salesforce/sdk-data_v${p}`, S = typeof __SF_API_VERSION__ < "u" ? __SF_API_VERSION__ : "65.0", d = typeof __SF_SERVER_BASE_PATH__ < "u" ? __SF_SERVER_BASE_PATH__ : "", l = `/services/data/v${S}`, A = `${l}/ui-api`;
13
+ class E {
14
+ base;
15
+ conduitClient;
16
+ on401;
17
+ on403;
18
+ constructor(t) {
19
+ this.base = t?.basePath ?? d, this.on401 = t?.on401, this.on403 = t?.on403, i.initialize({
20
+ csrf: {
21
+ endpoint: `${this.base}${A}/session/csrf`,
22
+ cacheName: h,
23
+ protectedUrls: ["/services/data/v"]
24
+ }
25
+ }), this.conduitClient = i.instance();
26
+ }
27
+ async graphql(t, n) {
28
+ return (await this.fetch(`${l}/graphql`, {
29
+ method: "POST",
30
+ body: JSON.stringify({ query: t, variables: n }),
31
+ headers: {
32
+ "Content-Type": "application/json",
33
+ Accept: "application/json"
34
+ }
35
+ })).json();
36
+ }
37
+ async fetch(t, n) {
38
+ const s = this.applySalesforceBase(t), o = await this.conduitClient.fetch(s, n);
39
+ switch (o.status) {
40
+ case 401:
41
+ await this.on401?.();
42
+ break;
43
+ case 403:
44
+ await this.on403?.();
45
+ break;
56
46
  }
47
+ return o;
48
+ }
49
+ /**
50
+ * If the url is relative, convert to it to an absolute Salesforce URL. This is due to the way Code
51
+ * Builder deployments structure the url for Salesforce
52
+ */
53
+ applySalesforceBase(t) {
54
+ return typeof t == "string" ? t.startsWith("http") ? t : this.base + t : t;
55
+ }
56
+ }
57
+ function I(e, ...t) {
58
+ let n = e[0] ?? "";
59
+ for (let s = 0; s < t.length; s += 1)
60
+ n += String(t[s]) + (e[s + 1] ?? "");
61
+ return n;
62
+ }
63
+ async function w(e) {
64
+ switch (u(e?.surface)) {
65
+ case a.OpenAI:
66
+ return new f();
67
+ case a.WebApp:
68
+ case a.MicroFrontend:
69
+ return new E(e?.webapp);
70
+ case a.SalesforceACC:
71
+ return {};
72
+ case a.MCPApps:
73
+ return {};
74
+ default:
75
+ return {};
76
+ }
77
+ }
78
+ let r = null, c = null;
79
+ async function P(e) {
80
+ if (r)
81
+ return r;
82
+ c || (c = w(e));
83
+ try {
84
+ return r = await c, r;
85
+ } catch (t) {
86
+ throw c = null, t;
87
+ }
57
88
  }
89
+ export {
90
+ w as createDataSDK,
91
+ P as getDataSDK,
92
+ I as gql
93
+ };
@@ -1,9 +1,4 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import type { DataSDK, GraphQLResponse } from "@salesforce/sdk-core";
1
+ import { DataSDK, GraphQLResponse } from '@salesforce/sdk-core';
7
2
  /**
8
3
  * Data SDK implementation for the OpenAI surface, which delegates GraphQL
9
4
  * queries to the Salesforce MCP server via the ChatGPT bridge.
@@ -1,5 +1,5 @@
1
- import type { DataSDK, GraphQLResponse } from "@salesforce/sdk-core";
2
- import type { WebAppDataSDKOptions } from "../index.js";
1
+ import { DataSDK, GraphQLResponse } from '@salesforce/sdk-core';
2
+ import { WebAppDataSDKOptions } from '../index';
3
3
  export declare const API_VERSION: string;
4
4
  /**
5
5
  * Data SDK implementation for web apps, which is based on making `fetch` calls to REST endpoints
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webapp/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAQxD,eAAO,MAAM,WAAW,QAA0E,C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,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.80.1",
3
+ "version": "1.82.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,18 +18,20 @@
18
18
  "dist"
19
19
  ],
20
20
  "scripts": {
21
- "build": "tsc --build",
22
- "clean": "rm -rf dist tsconfig.tsbuildinfo",
23
- "dev": "tsc --build --watch",
21
+ "build": "vite build",
22
+ "clean": "rm -rf dist",
23
+ "dev": "vite build --watch",
24
24
  "test": "vitest run",
25
25
  "test:watch": "vitest",
26
26
  "test:coverage": "vitest run --coverage"
27
27
  },
28
28
  "dependencies": {
29
29
  "@conduit-client/salesforce-lightning-service-worker": "^3.7.0",
30
- "@salesforce/sdk-core": "^1.80.1"
30
+ "@salesforce/sdk-core": "^1.82.0"
31
31
  },
32
32
  "devDependencies": {
33
+ "vite": "^7.3.1",
34
+ "vite-plugin-dts": "^4.5.4",
33
35
  "vitest": "^4.0.6"
34
36
  },
35
37
  "publishConfig": {
package/dist/gql.js DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- export function gql(strings, ...values) {
7
- /**
8
- * Pass-through tag for IDE GraphQL integrations only.
9
- */
10
- let result = strings[0] ?? "";
11
- for (let i = 0; i < values.length; i += 1) {
12
- result += String(values[i]) + (strings[i + 1] ?? "");
13
- }
14
- return result;
15
- }
@@ -1,14 +0,0 @@
1
- const TOOL_NAME = "salesforce_graphql";
2
- /**
3
- * Data SDK implementation for the OpenAI surface, which delegates GraphQL
4
- * queries to the Salesforce MCP server via the ChatGPT bridge.
5
- */
6
- export class OpenAIDataSDK {
7
- async graphql(query, variables) {
8
- const result = (await window.openai.callTool(TOOL_NAME, {
9
- query,
10
- ...(variables != null ? { variables } : {}),
11
- }));
12
- return result.structuredContent;
13
- }
14
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import { ConduitClient } from "@conduit-client/salesforce-lightning-service-worker";
7
- const CACHE_VERSION = 1;
8
- const CACHE_NAME = `@salesforce/sdk-data_v${CACHE_VERSION}`;
9
- export const API_VERSION = typeof __SF_API_VERSION__ !== "undefined" ? __SF_API_VERSION__ : "65.0";
10
- const BASE = typeof __SF_SERVER_BASE_PATH__ !== "undefined" ? __SF_SERVER_BASE_PATH__ : "";
11
- const PATH_DATA = `/services/data/v${API_VERSION}`;
12
- const PATH_UIAPI = `${PATH_DATA}/ui-api`;
13
- /**
14
- * Data SDK implementation for web apps, which is based on making `fetch` calls to REST endpoints
15
- */
16
- export class WebAppDataSDK {
17
- base;
18
- conduitClient;
19
- on401;
20
- on403;
21
- constructor(options) {
22
- this.base = options?.basePath ?? BASE;
23
- this.on401 = options?.on401;
24
- this.on403 = options?.on403;
25
- ConduitClient.initialize({
26
- csrf: {
27
- endpoint: `${this.base}${PATH_UIAPI}/session/csrf`,
28
- cacheName: CACHE_NAME,
29
- protectedUrls: ["/services/data/v"],
30
- },
31
- });
32
- this.conduitClient = ConduitClient.instance();
33
- }
34
- async graphql(query, variables) {
35
- const res = await this.fetch(`${PATH_DATA}/graphql`, {
36
- method: "POST",
37
- body: JSON.stringify({ query, variables }),
38
- headers: {
39
- "Content-Type": "application/json",
40
- Accept: "application/json",
41
- },
42
- });
43
- return res.json();
44
- }
45
- async fetch(input, init) {
46
- const updatedInput = this.applySalesforceBase(input);
47
- const response = await this.conduitClient.fetch(updatedInput, init);
48
- switch (response.status) {
49
- case 401:
50
- await this.on401?.();
51
- break;
52
- case 403:
53
- await this.on403?.();
54
- break;
55
- }
56
- return response;
57
- }
58
- /**
59
- * If the url is relative, convert to it to an absolute Salesforce URL. This is due to the way Code
60
- * Builder deployments structure the url for Salesforce
61
- */
62
- applySalesforceBase(input) {
63
- // Handle string input
64
- if (typeof input === "string") {
65
- if (input.startsWith("http")) {
66
- return input;
67
- }
68
- return this.base + input;
69
- }
70
- // URLs require a protocol and domain, thus are already absolute
71
- return input;
72
- }
73
- }