@salesforce/vite-plugin-lwc-ui-bundle 1.130.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/LICENSE.txt +82 -0
- package/README.md +222 -0
- package/dist/discovery.d.ts +3 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +509 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/lightning-npm.d.ts +4 -0
- package/dist/plugins/lightning-npm.d.ts.map +1 -0
- package/dist/plugins/lwc-bridge.d.ts +3 -0
- package/dist/plugins/lwc-bridge.d.ts.map +1 -0
- package/dist/plugins/lwc-wrapper.d.ts +6 -0
- package/dist/plugins/lwc-wrapper.d.ts.map +1 -0
- package/dist/plugins/missing-css.d.ts +3 -0
- package/dist/plugins/missing-css.d.ts.map +1 -0
- package/dist/plugins/proxy.d.ts +26 -0
- package/dist/plugins/proxy.d.ts.map +1 -0
- package/dist/plugins/scoped-providers.d.ts +4 -0
- package/dist/plugins/scoped-providers.d.ts.map +1 -0
- package/dist/providers/access-check.d.ts +3 -0
- package/dist/providers/access-check.d.ts.map +1 -0
- package/dist/providers/client.d.ts +3 -0
- package/dist/providers/client.d.ts.map +1 -0
- package/dist/providers/gate.d.ts +3 -0
- package/dist/providers/gate.d.ts.map +1 -0
- package/dist/providers/i18n.d.ts +7 -0
- package/dist/providers/i18n.d.ts.map +1 -0
- package/dist/providers/index.d.ts +13 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +462 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/label.d.ts +3 -0
- package/dist/providers/label.d.ts.map +1 -0
- package/dist/providers/lightning-graphql.d.ts +17 -0
- package/dist/providers/lightning-graphql.d.ts.map +1 -0
- package/dist/providers/primitive-utils.d.ts +3 -0
- package/dist/providers/primitive-utils.d.ts.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.d.ts.map +1 -0
- package/docs/chat-wrapper-guide.md +134 -0
- package/docs/user-guide.md +377 -0
- package/package.json +74 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-providers.d.ts","sourceRoot":"","sources":["../../src/plugins/scoped-providers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAIjE,wBAAgB,eAAe,CAC9B,SAAS,GAAE,QAAQ,EAAO,EAC1B,OAAO,GAAE,sBAA2B,GAClC,MAAM,CAqER"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-check.d.ts","sourceRoot":"","sources":["../../src/providers/access-check.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,WAAW,CAAC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,QAAQ,CAU7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/providers/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAazC,wBAAgB,MAAM,IAAI,QAAQ,CAUjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/providers/gate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,IAAI,CAAC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,QAAQ,CAUtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/providers/i18n.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAqKzC,MAAM,WAAW,WAAW;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,QAAQ,CAwBxD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
export { label } from './label';
|
|
7
|
+
export { i18n } from './i18n';
|
|
8
|
+
export { gate } from './gate';
|
|
9
|
+
export { accessCheck } from './access-check';
|
|
10
|
+
export { client } from './client';
|
|
11
|
+
export { primitiveUtils } from './primitive-utils';
|
|
12
|
+
export { lightningGraphql } from './lightning-graphql';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
const LABEL_DEFAULTS = {
|
|
2
|
+
"LightningForm.edit": "Edit",
|
|
3
|
+
"LightningForm.save": "Save",
|
|
4
|
+
"LightningForm.cancel": "Cancel",
|
|
5
|
+
"LightningForm.error": "Error",
|
|
6
|
+
"RecordDetailUC.Expand": "Expand",
|
|
7
|
+
"RecordDetailUC.Collapse": "Collapse",
|
|
8
|
+
"Global_Entity.created_by": "Created By",
|
|
9
|
+
"Global_Entity.last_modified_by": "Last Modified By",
|
|
10
|
+
"DetailError.GenericSaveError": "An error occurred while saving.",
|
|
11
|
+
"MobileWebError.NoPreEditAccess": "You don't have access to edit this record.",
|
|
12
|
+
"DuplicateList.ToastMessageBlock": "Duplicate records were found.",
|
|
13
|
+
"DuplicateList.NonBlockingHeaderText": "Duplicate records found",
|
|
14
|
+
"DuplicateList.ToastMessageAlertEdit": "Duplicate records were found. You can continue editing.",
|
|
15
|
+
"Errors.ErrorPopoverHeading": "Error"
|
|
16
|
+
};
|
|
17
|
+
function label(overrides = {}) {
|
|
18
|
+
const defaults = { ...LABEL_DEFAULTS, ...overrides };
|
|
19
|
+
return {
|
|
20
|
+
prefix: "@salesforce/label/",
|
|
21
|
+
resolve(specifier) {
|
|
22
|
+
if (!specifier.startsWith("@salesforce/label/")) return null;
|
|
23
|
+
const key = specifier.slice("@salesforce/label/".length);
|
|
24
|
+
const fallbackLabel = key.split(".").at(-1).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/_/g, " ").trim();
|
|
25
|
+
const value = defaults[key] ?? fallbackLabel;
|
|
26
|
+
return `export default ${JSON.stringify(value)};`;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const BROWSER_DERIVED = /* @__PURE__ */ new Set([
|
|
31
|
+
"lang",
|
|
32
|
+
"dir",
|
|
33
|
+
"locale",
|
|
34
|
+
"currency",
|
|
35
|
+
"timeZone",
|
|
36
|
+
"firstDayOfWeek"
|
|
37
|
+
]);
|
|
38
|
+
const STATIC_DEFAULTS = {
|
|
39
|
+
"dateTime.shortDateFormat": "M/d/yyyy",
|
|
40
|
+
"dateTime.mediumDateFormat": "MMM d, yyyy",
|
|
41
|
+
"dateTime.longDateFormat": "MMMM d, yyyy",
|
|
42
|
+
"dateTime.shortTimeFormat": "h:mm a",
|
|
43
|
+
"dateTime.mediumTimeFormat": "h:mm:ss a",
|
|
44
|
+
"dateTime.longTimeFormat": "h:mm:ss a z",
|
|
45
|
+
"dateTime.shortDateTimeFormat": "M/d/yyyy, h:mm a",
|
|
46
|
+
"number.numberFormat": "#,##0.##",
|
|
47
|
+
"number.currencyFormat": "¤#,##0.00",
|
|
48
|
+
"number.decimalSeparator": ".",
|
|
49
|
+
"number.groupingSeparator": ",",
|
|
50
|
+
"number.percentFormat": "#,##0%",
|
|
51
|
+
"number.percentSign": "%",
|
|
52
|
+
"number.plusSign": "+",
|
|
53
|
+
"number.minusSign": "-",
|
|
54
|
+
"number.exponentialSign": "E",
|
|
55
|
+
"number.superscriptingExponentSign": "×",
|
|
56
|
+
"number.perMilleSign": "‰",
|
|
57
|
+
"number.infinity": "∞",
|
|
58
|
+
"number.nan": "NaN",
|
|
59
|
+
"number.currencySymbol": "$",
|
|
60
|
+
defaultCalendar: "gregory",
|
|
61
|
+
defaultNumberingSystem: "latn"
|
|
62
|
+
};
|
|
63
|
+
const MONTHS_WIDE = [
|
|
64
|
+
"January",
|
|
65
|
+
"February",
|
|
66
|
+
"March",
|
|
67
|
+
"April",
|
|
68
|
+
"May",
|
|
69
|
+
"June",
|
|
70
|
+
"July",
|
|
71
|
+
"August",
|
|
72
|
+
"September",
|
|
73
|
+
"October",
|
|
74
|
+
"November",
|
|
75
|
+
"December"
|
|
76
|
+
];
|
|
77
|
+
const MONTHS_ABBR = [
|
|
78
|
+
"Jan",
|
|
79
|
+
"Feb",
|
|
80
|
+
"Mar",
|
|
81
|
+
"Apr",
|
|
82
|
+
"May",
|
|
83
|
+
"Jun",
|
|
84
|
+
"Jul",
|
|
85
|
+
"Aug",
|
|
86
|
+
"Sep",
|
|
87
|
+
"Oct",
|
|
88
|
+
"Nov",
|
|
89
|
+
"Dec"
|
|
90
|
+
];
|
|
91
|
+
const DAYS_WIDE = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
92
|
+
const DAYS_ABBR = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
93
|
+
const OBJECT_DEFAULTS = {
|
|
94
|
+
"common.digits": { latn: "0123456789" },
|
|
95
|
+
"common.calendarData": {
|
|
96
|
+
gregory: { calendarSystem: "solar", eras: {} }
|
|
97
|
+
},
|
|
98
|
+
calendarData: {
|
|
99
|
+
gregory: {
|
|
100
|
+
months: {
|
|
101
|
+
format: {
|
|
102
|
+
wide: MONTHS_WIDE,
|
|
103
|
+
abbreviated: MONTHS_ABBR,
|
|
104
|
+
narrow: MONTHS_ABBR
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
days: {
|
|
108
|
+
format: {
|
|
109
|
+
wide: DAYS_WIDE,
|
|
110
|
+
abbreviated: DAYS_ABBR,
|
|
111
|
+
narrow: DAYS_ABBR
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
dayPeriods: {
|
|
115
|
+
format: {
|
|
116
|
+
wide: ["AM", "PM"],
|
|
117
|
+
abbreviated: ["am", "pm"],
|
|
118
|
+
narrow: ["a", "p"]
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
eras: {
|
|
122
|
+
eraAbbr: ["AD"],
|
|
123
|
+
eraNames: ["Anno Domini"],
|
|
124
|
+
eraNarrow: ["A"]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const RUNTIME_SOURCE = `
|
|
130
|
+
const RTL_LANGS = new Set([
|
|
131
|
+
'ar', 'arc', 'dv', 'fa', 'ha', 'he', 'khw', 'ks', 'ku', 'ps', 'ur', 'yi',
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
function getLocale() {
|
|
135
|
+
if (typeof navigator === 'undefined') return 'en-US';
|
|
136
|
+
return navigator.language || 'en-US';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getLang() {
|
|
140
|
+
return getLocale().split('-')[0];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getDir() {
|
|
144
|
+
return RTL_LANGS.has(getLang()) ? 'rtl' : 'ltr';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function getCurrency() {
|
|
148
|
+
try {
|
|
149
|
+
const parts = new Intl.NumberFormat(getLocale(), {
|
|
150
|
+
style: 'currency',
|
|
151
|
+
currency: 'USD',
|
|
152
|
+
currencyDisplay: 'code',
|
|
153
|
+
}).resolvedOptions();
|
|
154
|
+
return parts.currency || 'USD';
|
|
155
|
+
} catch {
|
|
156
|
+
return 'USD';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function getTimeZone() {
|
|
161
|
+
try {
|
|
162
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
163
|
+
} catch {
|
|
164
|
+
return 'UTC';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function getFirstDayOfWeek() {
|
|
169
|
+
try {
|
|
170
|
+
const loc = new Intl.Locale(getLocale());
|
|
171
|
+
if (loc.weekInfo) return String(loc.weekInfo.firstDay);
|
|
172
|
+
if (typeof loc.getWeekInfo === 'function') return String(loc.getWeekInfo().firstDay);
|
|
173
|
+
} catch { /* unsupported in this browser */ }
|
|
174
|
+
return '7';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const values = {
|
|
178
|
+
lang: getLang(),
|
|
179
|
+
dir: getDir(),
|
|
180
|
+
locale: getLocale(),
|
|
181
|
+
currency: getCurrency(),
|
|
182
|
+
timeZone: getTimeZone(),
|
|
183
|
+
firstDayOfWeek: getFirstDayOfWeek(),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export default values['__KEY__'];
|
|
187
|
+
`;
|
|
188
|
+
function i18n(options = {}) {
|
|
189
|
+
const { staticOverrides = {}, objectOverrides = {} } = options;
|
|
190
|
+
const statics = { ...STATIC_DEFAULTS, ...staticOverrides };
|
|
191
|
+
const objects = { ...OBJECT_DEFAULTS, ...objectOverrides };
|
|
192
|
+
return {
|
|
193
|
+
prefix: "@salesforce/i18n/",
|
|
194
|
+
resolve(specifier) {
|
|
195
|
+
if (!specifier.startsWith("@salesforce/i18n/")) return null;
|
|
196
|
+
const key = specifier.slice("@salesforce/i18n/".length);
|
|
197
|
+
if (BROWSER_DERIVED.has(key)) {
|
|
198
|
+
return RUNTIME_SOURCE.replace("__KEY__", key);
|
|
199
|
+
}
|
|
200
|
+
if (key in objects) {
|
|
201
|
+
return `export default ${JSON.stringify(objects[key])};`;
|
|
202
|
+
}
|
|
203
|
+
const value = statics[key] ?? key;
|
|
204
|
+
return `export default ${JSON.stringify(value)};`;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function gate(overrides = {}) {
|
|
209
|
+
return {
|
|
210
|
+
prefix: "@salesforce/gate/",
|
|
211
|
+
resolve(specifier) {
|
|
212
|
+
if (!specifier.startsWith("@salesforce/gate/")) return null;
|
|
213
|
+
const name = specifier.slice("@salesforce/gate/".length);
|
|
214
|
+
const isOpen = overrides[name] ?? true;
|
|
215
|
+
return `export default { isOpen: () => ${isOpen} };`;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function accessCheck(overrides = {}) {
|
|
220
|
+
return {
|
|
221
|
+
prefix: "@salesforce/accessCheck/",
|
|
222
|
+
resolve(specifier) {
|
|
223
|
+
if (!specifier.startsWith("@salesforce/accessCheck/")) return null;
|
|
224
|
+
const name = specifier.slice("@salesforce/accessCheck/".length);
|
|
225
|
+
const value = overrides[name] ?? false;
|
|
226
|
+
return `export default ${value};`;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const FORM_FACTOR_SOURCE = `
|
|
231
|
+
function getFormFactor() {
|
|
232
|
+
if (typeof window === 'undefined') return 'Large';
|
|
233
|
+
if (window.matchMedia('(max-width: 767px)').matches) return 'Small';
|
|
234
|
+
if (window.matchMedia('(max-width: 1023px)').matches) return 'Medium';
|
|
235
|
+
return 'Large';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default getFormFactor();
|
|
239
|
+
`;
|
|
240
|
+
function client() {
|
|
241
|
+
return {
|
|
242
|
+
prefix: "@salesforce/client/",
|
|
243
|
+
resolve(specifier) {
|
|
244
|
+
if (specifier === "@salesforce/client/formFactor") {
|
|
245
|
+
return FORM_FACTOR_SOURCE;
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function primitiveUtils() {
|
|
252
|
+
return {
|
|
253
|
+
prefix: "lightning/primitiveUtils",
|
|
254
|
+
match(id) {
|
|
255
|
+
return id === "lightning/primitiveUtils";
|
|
256
|
+
},
|
|
257
|
+
resolve(specifier) {
|
|
258
|
+
if (specifier !== "lightning/primitiveUtils") return null;
|
|
259
|
+
return `export function normalizeBoolean(value) {
|
|
260
|
+
return typeof value === 'string' || !!value;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function reflectAttribute(element, attrName, value) {
|
|
264
|
+
if (!element) return;
|
|
265
|
+
if (typeof value === 'string') {
|
|
266
|
+
element.setAttribute(attrName, value);
|
|
267
|
+
} else if (value === true) {
|
|
268
|
+
element.setAttribute(attrName, '');
|
|
269
|
+
} else if (!value) {
|
|
270
|
+
element.removeAttribute(attrName);
|
|
271
|
+
} else {
|
|
272
|
+
console.warn(\`Invalid attribute value for "\${attrName}": \${value}\`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function buildGraphqlSource(toolName) {
|
|
280
|
+
return `
|
|
281
|
+
import { getChatSDK } from '@salesforce/sdk-chat';
|
|
282
|
+
|
|
283
|
+
export function gql(strings, ...values) {
|
|
284
|
+
let result = '';
|
|
285
|
+
strings.forEach((string, i) => {
|
|
286
|
+
result += string;
|
|
287
|
+
if (i < values.length) result += String(values[i]);
|
|
288
|
+
});
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export class graphql {
|
|
293
|
+
_dataCallback;
|
|
294
|
+
_config;
|
|
295
|
+
|
|
296
|
+
constructor(dataCallback) {
|
|
297
|
+
this._dataCallback = dataCallback;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
connect() { this._fetch(); }
|
|
301
|
+
disconnect() {}
|
|
302
|
+
|
|
303
|
+
update(config) {
|
|
304
|
+
this._config = config;
|
|
305
|
+
this._fetch();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
refresh() {
|
|
309
|
+
return this._fetch();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async _fetch() {
|
|
313
|
+
const query = this._config?.query;
|
|
314
|
+
const variables = this._config?.variables ?? {};
|
|
315
|
+
|
|
316
|
+
if (!query) {
|
|
317
|
+
this._emit({ data: undefined, errors: undefined });
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
// 1. UIBundle / local dev: use globalThis.__sfdc_sdk__.graphql if available
|
|
323
|
+
if (typeof globalThis.__sfdc_sdk__?.graphql === 'function') {
|
|
324
|
+
const result = await globalThis.__sfdc_sdk__.graphql(query, variables);
|
|
325
|
+
this._emit({ data: result?.data, errors: result?.errors });
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 2. MCP surface: use getChatSDK().callTool
|
|
330
|
+
const sdk = await getChatSDK();
|
|
331
|
+
|
|
332
|
+
if (typeof sdk.callTool !== 'function') {
|
|
333
|
+
throw new Error(
|
|
334
|
+
'[lightning/graphql] No data surface available. ' +
|
|
335
|
+
'Either initialise globalThis.__sfdc_sdk__ with createDataSDK, ' +
|
|
336
|
+
'or run inside a ChatGPT / MCP Apps context.'
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const raw = await sdk.callTool({
|
|
341
|
+
toolName: ${JSON.stringify(toolName)},
|
|
342
|
+
params: { query, variables },
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// Normalise result across surfaces:
|
|
346
|
+
// - OpenAI surface: { result: "<JSON string of { data, errors }>" }
|
|
347
|
+
// - MCP Apps surface: { structuredContent: { data, errors }, content: [...] }
|
|
348
|
+
let result;
|
|
349
|
+
if (raw?.structuredContent !== undefined) {
|
|
350
|
+
result = raw.structuredContent;
|
|
351
|
+
} else if (typeof raw?.result === 'string') {
|
|
352
|
+
const parsed = JSON.parse(raw.result);
|
|
353
|
+
if (Array.isArray(parsed)) {
|
|
354
|
+
// MCP content array - extract text from first text block
|
|
355
|
+
const textBlock = parsed.find(
|
|
356
|
+
(b) => b && b.type === 'text' && typeof b.text === 'string',
|
|
357
|
+
);
|
|
358
|
+
const text = textBlock ? textBlock.text : null;
|
|
359
|
+
if (text) {
|
|
360
|
+
try { result = JSON.parse(text); } catch { result = { errors: [{ message: text }] }; }
|
|
361
|
+
} else {
|
|
362
|
+
result = {};
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
result = parsed;
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
result = raw ?? {};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
this._emit({ data: result?.data, errors: result?.errors });
|
|
372
|
+
} catch (error) {
|
|
373
|
+
this._emit({ data: undefined, errors: [{ message: error.message }] });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
_emit({ data, errors }) {
|
|
378
|
+
this._dataCallback({
|
|
379
|
+
data,
|
|
380
|
+
error: errors?.length ? errors : undefined,
|
|
381
|
+
refresh: () => this.refresh(),
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export async function executeMutation(config) {
|
|
387
|
+
const { query, variables } = config;
|
|
388
|
+
if (!query) return { data: undefined, errors: [{ message: 'No query provided' }] };
|
|
389
|
+
try {
|
|
390
|
+
// 1. UIBundle / local dev
|
|
391
|
+
if (typeof globalThis.__sfdc_sdk__?.graphql === 'function') {
|
|
392
|
+
const result = await globalThis.__sfdc_sdk__.graphql(query, variables ?? {});
|
|
393
|
+
return { data: result?.data, errors: result?.errors };
|
|
394
|
+
}
|
|
395
|
+
// 2. MCP surface
|
|
396
|
+
const sdk = await getChatSDK();
|
|
397
|
+
if (typeof sdk.callTool !== 'function') {
|
|
398
|
+
throw new Error('[lightning/graphql] No data surface available.');
|
|
399
|
+
}
|
|
400
|
+
const raw = await sdk.callTool({
|
|
401
|
+
toolName: ${JSON.stringify(toolName)},
|
|
402
|
+
params: { query, variables: variables ?? {} },
|
|
403
|
+
});
|
|
404
|
+
let result;
|
|
405
|
+
if (raw?.structuredContent !== undefined) {
|
|
406
|
+
result = raw.structuredContent;
|
|
407
|
+
} else if (typeof raw?.result === 'string') {
|
|
408
|
+
const parsed = JSON.parse(raw.result);
|
|
409
|
+
if (Array.isArray(parsed)) {
|
|
410
|
+
const textBlock = parsed.find(
|
|
411
|
+
(b) => b && b.type === 'text' && typeof b.text === 'string',
|
|
412
|
+
);
|
|
413
|
+
const text = textBlock ? textBlock.text : null;
|
|
414
|
+
if (text) {
|
|
415
|
+
try { result = JSON.parse(text); } catch { result = { errors: [{ message: text }] }; }
|
|
416
|
+
} else {
|
|
417
|
+
result = {};
|
|
418
|
+
}
|
|
419
|
+
} else {
|
|
420
|
+
result = parsed;
|
|
421
|
+
}
|
|
422
|
+
} else {
|
|
423
|
+
result = raw ?? {};
|
|
424
|
+
}
|
|
425
|
+
return { data: result?.data, errors: result?.errors };
|
|
426
|
+
} catch (error) {
|
|
427
|
+
return { data: undefined, errors: [{ message: error.message }] };
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
`;
|
|
431
|
+
}
|
|
432
|
+
function lightningGraphql(options = {}) {
|
|
433
|
+
const toolName = options.toolName ?? "graphqlQuery";
|
|
434
|
+
return {
|
|
435
|
+
prefix: "lightning/graphql",
|
|
436
|
+
resolve(specifier) {
|
|
437
|
+
if (specifier !== "lightning/graphql") return null;
|
|
438
|
+
return buildGraphqlSource(toolName);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
443
|
+
__proto__: null,
|
|
444
|
+
accessCheck,
|
|
445
|
+
client,
|
|
446
|
+
gate,
|
|
447
|
+
i18n,
|
|
448
|
+
label,
|
|
449
|
+
lightningGraphql,
|
|
450
|
+
primitiveUtils
|
|
451
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
452
|
+
export {
|
|
453
|
+
accessCheck,
|
|
454
|
+
client,
|
|
455
|
+
gate,
|
|
456
|
+
index as i,
|
|
457
|
+
i18n,
|
|
458
|
+
label,
|
|
459
|
+
lightningGraphql,
|
|
460
|
+
primitiveUtils
|
|
461
|
+
};
|
|
462
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/providers/label.ts","../../src/providers/i18n.ts","../../src/providers/gate.ts","../../src/providers/access-check.ts","../../src/providers/client.ts","../../src/providers/primitive-utils.ts","../../src/providers/lightning-graphql.ts"],"sourcesContent":["/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport type { Provider } from \"../types\";\n\nconst LABEL_DEFAULTS: Record<string, string> = {\n\t\"LightningForm.edit\": \"Edit\",\n\t\"LightningForm.save\": \"Save\",\n\t\"LightningForm.cancel\": \"Cancel\",\n\t\"LightningForm.error\": \"Error\",\n\t\"RecordDetailUC.Expand\": \"Expand\",\n\t\"RecordDetailUC.Collapse\": \"Collapse\",\n\t\"Global_Entity.created_by\": \"Created By\",\n\t\"Global_Entity.last_modified_by\": \"Last Modified By\",\n\t\"DetailError.GenericSaveError\": \"An error occurred while saving.\",\n\t\"MobileWebError.NoPreEditAccess\": \"You don't have access to edit this record.\",\n\t\"DuplicateList.ToastMessageBlock\": \"Duplicate records were found.\",\n\t\"DuplicateList.NonBlockingHeaderText\": \"Duplicate records found\",\n\t\"DuplicateList.ToastMessageAlertEdit\": \"Duplicate records were found. You can continue editing.\",\n\t\"Errors.ErrorPopoverHeading\": \"Error\",\n};\n\nexport function label(overrides: Record<string, string> = {}): Provider {\n\tconst defaults = { ...LABEL_DEFAULTS, ...overrides };\n\treturn {\n\t\tprefix: \"@salesforce/label/\",\n\t\tresolve(specifier) {\n\t\t\tif (!specifier.startsWith(\"@salesforce/label/\")) return null;\n\n\t\t\tconst key = specifier.slice(\"@salesforce/label/\".length);\n\t\t\tconst fallbackLabel = key\n\t\t\t\t.split(\".\")\n\t\t\t\t.at(-1)!\n\t\t\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t\t\t.replace(/_/g, \" \")\n\t\t\t\t.trim();\n\t\t\tconst value = defaults[key] ?? fallbackLabel;\n\t\t\treturn `export default ${JSON.stringify(value)};`;\n\t\t},\n\t};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport type { Provider } from \"../types\";\n\nconst BROWSER_DERIVED = new Set([\n\t\"lang\",\n\t\"dir\",\n\t\"locale\",\n\t\"currency\",\n\t\"timeZone\",\n\t\"firstDayOfWeek\",\n]);\n\nconst STATIC_DEFAULTS: Record<string, string> = {\n\t\"dateTime.shortDateFormat\": \"M/d/yyyy\",\n\t\"dateTime.mediumDateFormat\": \"MMM d, yyyy\",\n\t\"dateTime.longDateFormat\": \"MMMM d, yyyy\",\n\t\"dateTime.shortTimeFormat\": \"h:mm a\",\n\t\"dateTime.mediumTimeFormat\": \"h:mm:ss a\",\n\t\"dateTime.longTimeFormat\": \"h:mm:ss a z\",\n\t\"dateTime.shortDateTimeFormat\": \"M/d/yyyy, h:mm a\",\n\t\"number.numberFormat\": \"#,##0.##\",\n\t\"number.currencyFormat\": \"¤#,##0.00\",\n\t\"number.decimalSeparator\": \".\",\n\t\"number.groupingSeparator\": \",\",\n\t\"number.percentFormat\": \"#,##0%\",\n\t\"number.percentSign\": \"%\",\n\t\"number.plusSign\": \"+\",\n\t\"number.minusSign\": \"-\",\n\t\"number.exponentialSign\": \"E\",\n\t\"number.superscriptingExponentSign\": \"×\",\n\t\"number.perMilleSign\": \"‰\",\n\t\"number.infinity\": \"∞\",\n\t\"number.nan\": \"NaN\",\n\t\"number.currencySymbol\": \"$\",\n\tdefaultCalendar: \"gregory\",\n\tdefaultNumberingSystem: \"latn\",\n};\n\nconst MONTHS_WIDE = [\n\t\"January\",\n\t\"February\",\n\t\"March\",\n\t\"April\",\n\t\"May\",\n\t\"June\",\n\t\"July\",\n\t\"August\",\n\t\"September\",\n\t\"October\",\n\t\"November\",\n\t\"December\",\n];\nconst MONTHS_ABBR = [\n\t\"Jan\",\n\t\"Feb\",\n\t\"Mar\",\n\t\"Apr\",\n\t\"May\",\n\t\"Jun\",\n\t\"Jul\",\n\t\"Aug\",\n\t\"Sep\",\n\t\"Oct\",\n\t\"Nov\",\n\t\"Dec\",\n];\nconst DAYS_WIDE = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\nconst DAYS_ABBR = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n\nconst OBJECT_DEFAULTS: Record<string, unknown> = {\n\t\"common.digits\": { latn: \"0123456789\" },\n\t\"common.calendarData\": {\n\t\tgregory: { calendarSystem: \"solar\", eras: {} },\n\t},\n\tcalendarData: {\n\t\tgregory: {\n\t\t\tmonths: {\n\t\t\t\tformat: {\n\t\t\t\t\twide: MONTHS_WIDE,\n\t\t\t\t\tabbreviated: MONTHS_ABBR,\n\t\t\t\t\tnarrow: MONTHS_ABBR,\n\t\t\t\t},\n\t\t\t},\n\t\t\tdays: {\n\t\t\t\tformat: {\n\t\t\t\t\twide: DAYS_WIDE,\n\t\t\t\t\tabbreviated: DAYS_ABBR,\n\t\t\t\t\tnarrow: DAYS_ABBR,\n\t\t\t\t},\n\t\t\t},\n\t\t\tdayPeriods: {\n\t\t\t\tformat: {\n\t\t\t\t\twide: [\"AM\", \"PM\"],\n\t\t\t\t\tabbreviated: [\"am\", \"pm\"],\n\t\t\t\t\tnarrow: [\"a\", \"p\"],\n\t\t\t\t},\n\t\t\t},\n\t\t\teras: {\n\t\t\t\teraAbbr: [\"AD\"],\n\t\t\t\teraNames: [\"Anno Domini\"],\n\t\t\t\teraNarrow: [\"A\"],\n\t\t\t},\n\t\t},\n\t},\n};\n\nconst RUNTIME_SOURCE = `\nconst RTL_LANGS = new Set([\n 'ar', 'arc', 'dv', 'fa', 'ha', 'he', 'khw', 'ks', 'ku', 'ps', 'ur', 'yi',\n]);\n\nfunction getLocale() {\n if (typeof navigator === 'undefined') return 'en-US';\n return navigator.language || 'en-US';\n}\n\nfunction getLang() {\n return getLocale().split('-')[0];\n}\n\nfunction getDir() {\n return RTL_LANGS.has(getLang()) ? 'rtl' : 'ltr';\n}\n\nfunction getCurrency() {\n try {\n const parts = new Intl.NumberFormat(getLocale(), {\n style: 'currency',\n currency: 'USD',\n currencyDisplay: 'code',\n }).resolvedOptions();\n return parts.currency || 'USD';\n } catch {\n return 'USD';\n }\n}\n\nfunction getTimeZone() {\n try {\n return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';\n } catch {\n return 'UTC';\n }\n}\n\nfunction getFirstDayOfWeek() {\n try {\n const loc = new Intl.Locale(getLocale());\n if (loc.weekInfo) return String(loc.weekInfo.firstDay);\n if (typeof loc.getWeekInfo === 'function') return String(loc.getWeekInfo().firstDay);\n } catch { /* unsupported in this browser */ }\n return '7';\n}\n\nconst values = {\n lang: getLang(),\n dir: getDir(),\n locale: getLocale(),\n currency: getCurrency(),\n timeZone: getTimeZone(),\n firstDayOfWeek: getFirstDayOfWeek(),\n};\n\nexport default values['__KEY__'];\n`;\n\nexport interface I18nOptions {\n\tstaticOverrides?: Record<string, string>;\n\tobjectOverrides?: Record<string, unknown>;\n}\n\nexport function i18n(options: I18nOptions = {}): Provider {\n\tconst { staticOverrides = {}, objectOverrides = {} } = options;\n\tconst statics = { ...STATIC_DEFAULTS, ...staticOverrides };\n\tconst objects = { ...OBJECT_DEFAULTS, ...objectOverrides };\n\n\treturn {\n\t\tprefix: \"@salesforce/i18n/\",\n\t\tresolve(specifier) {\n\t\t\tif (!specifier.startsWith(\"@salesforce/i18n/\")) return null;\n\n\t\t\tconst key = specifier.slice(\"@salesforce/i18n/\".length);\n\n\t\t\tif (BROWSER_DERIVED.has(key)) {\n\t\t\t\treturn RUNTIME_SOURCE.replace(\"__KEY__\", key);\n\t\t\t}\n\n\t\t\tif (key in objects) {\n\t\t\t\treturn `export default ${JSON.stringify(objects[key])};`;\n\t\t\t}\n\n\t\t\tconst value = statics[key] ?? key;\n\t\t\treturn `export default ${JSON.stringify(value)};`;\n\t\t},\n\t};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport type { Provider } from \"../types\";\n\nexport function gate(overrides: Record<string, boolean> = {}): Provider {\n\treturn {\n\t\tprefix: \"@salesforce/gate/\",\n\t\tresolve(specifier) {\n\t\t\tif (!specifier.startsWith(\"@salesforce/gate/\")) return null;\n\t\t\tconst name = specifier.slice(\"@salesforce/gate/\".length);\n\t\t\tconst isOpen = overrides[name] ?? true;\n\t\t\treturn `export default { isOpen: () => ${isOpen} };`;\n\t\t},\n\t};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport type { Provider } from \"../types\";\n\nexport function accessCheck(overrides: Record<string, boolean> = {}): Provider {\n\treturn {\n\t\tprefix: \"@salesforce/accessCheck/\",\n\t\tresolve(specifier) {\n\t\t\tif (!specifier.startsWith(\"@salesforce/accessCheck/\")) return null;\n\t\t\tconst name = specifier.slice(\"@salesforce/accessCheck/\".length);\n\t\t\tconst value = overrides[name] ?? false;\n\t\t\treturn `export default ${value};`;\n\t\t},\n\t};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport type { Provider } from \"../types\";\n\nconst FORM_FACTOR_SOURCE = `\nfunction getFormFactor() {\n if (typeof window === 'undefined') return 'Large';\n if (window.matchMedia('(max-width: 767px)').matches) return 'Small';\n if (window.matchMedia('(max-width: 1023px)').matches) return 'Medium';\n return 'Large';\n}\n\nexport default getFormFactor();\n`;\n\nexport function client(): Provider {\n\treturn {\n\t\tprefix: \"@salesforce/client/\",\n\t\tresolve(specifier) {\n\t\t\tif (specifier === \"@salesforce/client/formFactor\") {\n\t\t\t\treturn FORM_FACTOR_SOURCE;\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport type { Provider } from \"../types\";\n\nexport function primitiveUtils(): Provider {\n\treturn {\n\t\tprefix: \"lightning/primitiveUtils\",\n\t\tmatch(id) {\n\t\t\treturn id === \"lightning/primitiveUtils\";\n\t\t},\n\t\tresolve(specifier) {\n\t\t\tif (specifier !== \"lightning/primitiveUtils\") return null;\n\n\t\t\treturn `export function normalizeBoolean(value) {\n return typeof value === 'string' || !!value;\n}\n\nexport function reflectAttribute(element, attrName, value) {\n if (!element) return;\n if (typeof value === 'string') {\n element.setAttribute(attrName, value);\n } else if (value === true) {\n element.setAttribute(attrName, '');\n } else if (!value) {\n element.removeAttribute(attrName);\n } else {\n console.warn(\\`Invalid attribute value for \"\\${attrName}\": \\${value}\\`);\n }\n}\n`;\n\t\t},\n\t};\n}\n","/**\n * Copyright (c) 2026, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nimport type { Provider } from \"../types\";\n\nexport interface LightningGraphqlOptions {\n\t/**\n\t * Name of the MCP tool to call for GraphQL query execution.\n\t * Defaults to `'graphqlQuery'`.\n\t *\n\t * The tool must accept `{ query: string; variables?: Record<string, unknown> }`\n\t * and return a GraphQL-shaped response: `{ data: unknown; errors?: unknown[] }`.\n\t *\n\t * The result is normalised across surfaces:\n\t * - OpenAI surface: `sdk.callTool()` resolves with `{ result: \"<JSON string>\" }`\n\t * - MCP Apps surface: `sdk.callTool()` resolves with `{ structuredContent, content }`\n\t */\n\ttoolName?: string;\n}\n\n/**\n * Off-platform implementation of `lightning/graphql`.\n *\n * Provides the `gql` tagged-template helper and a `graphql` wire adapter that\n * executes GraphQL queries by calling an MCP tool via `@salesforce/sdk-chat`.\n *\n * `getChatSDK()` auto-detects the host surface:\n * - `window.openai` present → OpenAI/ChatGPT bridge (`window.openai.callTool`)\n * - Inside an iframe → MCP Apps JSON-RPC session (with OpenAI fallback)\n * - Neither → UIBundle stub (no callTool; adapter emits an error)\n *\n * The tool name is configurable via `options.toolName` (default `'graphqlQuery'`).\n * Requires `@salesforce/sdk-chat` as a peer dependency.\n */\nfunction buildGraphqlSource(toolName: string): string {\n\treturn `\nimport { getChatSDK } from '@salesforce/sdk-chat';\n\nexport function gql(strings, ...values) {\n let result = '';\n strings.forEach((string, i) => {\n result += string;\n if (i < values.length) result += String(values[i]);\n });\n return result;\n}\n\nexport class graphql {\n _dataCallback;\n _config;\n\n constructor(dataCallback) {\n this._dataCallback = dataCallback;\n }\n\n connect() { this._fetch(); }\n disconnect() {}\n\n update(config) {\n this._config = config;\n this._fetch();\n }\n\n refresh() {\n return this._fetch();\n }\n\n async _fetch() {\n const query = this._config?.query;\n const variables = this._config?.variables ?? {};\n\n if (!query) {\n this._emit({ data: undefined, errors: undefined });\n return;\n }\n\n try {\n // 1. UIBundle / local dev: use globalThis.__sfdc_sdk__.graphql if available\n if (typeof globalThis.__sfdc_sdk__?.graphql === 'function') {\n const result = await globalThis.__sfdc_sdk__.graphql(query, variables);\n this._emit({ data: result?.data, errors: result?.errors });\n return;\n }\n\n // 2. MCP surface: use getChatSDK().callTool\n const sdk = await getChatSDK();\n\n if (typeof sdk.callTool !== 'function') {\n throw new Error(\n '[lightning/graphql] No data surface available. ' +\n 'Either initialise globalThis.__sfdc_sdk__ with createDataSDK, ' +\n 'or run inside a ChatGPT / MCP Apps context.'\n );\n }\n\n const raw = await sdk.callTool({\n toolName: ${JSON.stringify(toolName)},\n params: { query, variables },\n });\n\n // Normalise result across surfaces:\n // - OpenAI surface: { result: \"<JSON string of { data, errors }>\" }\n // - MCP Apps surface: { structuredContent: { data, errors }, content: [...] }\n let result;\n if (raw?.structuredContent !== undefined) {\n result = raw.structuredContent;\n } else if (typeof raw?.result === 'string') {\n const parsed = JSON.parse(raw.result);\n if (Array.isArray(parsed)) {\n // MCP content array - extract text from first text block\n const textBlock = parsed.find(\n (b) => b && b.type === 'text' && typeof b.text === 'string',\n );\n const text = textBlock ? textBlock.text : null;\n if (text) {\n try { result = JSON.parse(text); } catch { result = { errors: [{ message: text }] }; }\n } else {\n result = {};\n }\n } else {\n result = parsed;\n }\n } else {\n result = raw ?? {};\n }\n\n this._emit({ data: result?.data, errors: result?.errors });\n } catch (error) {\n this._emit({ data: undefined, errors: [{ message: error.message }] });\n }\n }\n\n _emit({ data, errors }) {\n this._dataCallback({\n data,\n error: errors?.length ? errors : undefined,\n refresh: () => this.refresh(),\n });\n }\n}\n\nexport async function executeMutation(config) {\n const { query, variables } = config;\n if (!query) return { data: undefined, errors: [{ message: 'No query provided' }] };\n try {\n // 1. UIBundle / local dev\n if (typeof globalThis.__sfdc_sdk__?.graphql === 'function') {\n const result = await globalThis.__sfdc_sdk__.graphql(query, variables ?? {});\n return { data: result?.data, errors: result?.errors };\n }\n // 2. MCP surface\n const sdk = await getChatSDK();\n if (typeof sdk.callTool !== 'function') {\n throw new Error('[lightning/graphql] No data surface available.');\n }\n const raw = await sdk.callTool({\n toolName: ${JSON.stringify(toolName)},\n params: { query, variables: variables ?? {} },\n });\n let result;\n if (raw?.structuredContent !== undefined) {\n result = raw.structuredContent;\n } else if (typeof raw?.result === 'string') {\n const parsed = JSON.parse(raw.result);\n if (Array.isArray(parsed)) {\n const textBlock = parsed.find(\n (b) => b && b.type === 'text' && typeof b.text === 'string',\n );\n const text = textBlock ? textBlock.text : null;\n if (text) {\n try { result = JSON.parse(text); } catch { result = { errors: [{ message: text }] }; }\n } else {\n result = {};\n }\n } else {\n result = parsed;\n }\n } else {\n result = raw ?? {};\n }\n return { data: result?.data, errors: result?.errors };\n } catch (error) {\n return { data: undefined, errors: [{ message: error.message }] };\n }\n}\n`;\n}\n\nexport function lightningGraphql(options: LightningGraphqlOptions = {}): Provider {\n\tconst toolName = options.toolName ?? \"graphqlQuery\";\n\treturn {\n\t\tprefix: \"lightning/graphql\",\n\t\tresolve(specifier) {\n\t\t\tif (specifier !== \"lightning/graphql\") return null;\n\t\t\treturn buildGraphqlSource(toolName);\n\t\t},\n\t};\n}\n"],"names":[],"mappings":"AAOA,MAAM,iBAAyC;AAAA,EAC9C,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,wBAAwB;AAAA,EACxB,uBAAuB;AAAA,EACvB,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,4BAA4B;AAAA,EAC5B,kCAAkC;AAAA,EAClC,gCAAgC;AAAA,EAChC,kCAAkC;AAAA,EAClC,mCAAmC;AAAA,EACnC,uCAAuC;AAAA,EACvC,uCAAuC;AAAA,EACvC,8BAA8B;AAC/B;AAEO,SAAS,MAAM,YAAoC,IAAc;AACvE,QAAM,WAAW,EAAE,GAAG,gBAAgB,GAAG,UAAA;AACzC,SAAO;AAAA,IACN,QAAQ;AAAA,IAC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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA4D5B,KAAK,UAAU,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BhD;AAEO,SAAS,iBAAiB,UAAmC,IAAc;AACjF,QAAM,WAAW,QAAQ,YAAY;AACrC,SAAO;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ,WAAW;AAClB,UAAI,cAAc,oBAAqB,QAAO;AAC9C,aAAO,mBAAmB,QAAQ;AAAA,IACnC;AAAA,EAAA;AAEF;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.d.ts","sourceRoot":"","sources":["../../src/providers/label.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAmBzC,wBAAgB,KAAK,CAAC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,QAAQ,CAkBtE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Provider } from '../types';
|
|
2
|
+
export interface LightningGraphqlOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Name of the MCP tool to call for GraphQL query execution.
|
|
5
|
+
* Defaults to `'graphqlQuery'`.
|
|
6
|
+
*
|
|
7
|
+
* The tool must accept `{ query: string; variables?: Record<string, unknown> }`
|
|
8
|
+
* and return a GraphQL-shaped response: `{ data: unknown; errors?: unknown[] }`.
|
|
9
|
+
*
|
|
10
|
+
* The result is normalised across surfaces:
|
|
11
|
+
* - OpenAI surface: `sdk.callTool()` resolves with `{ result: "<JSON string>" }`
|
|
12
|
+
* - MCP Apps surface: `sdk.callTool()` resolves with `{ structuredContent, content }`
|
|
13
|
+
*/
|
|
14
|
+
toolName?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function lightningGraphql(options?: LightningGraphqlOptions): Provider;
|
|
17
|
+
//# sourceMappingURL=lightning-graphql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightning-graphql.d.ts","sourceRoot":"","sources":["../../src/providers/lightning-graphql.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,WAAW,uBAAuB;IACvC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AA0KD,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,QAAQ,CAShF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive-utils.d.ts","sourceRoot":"","sources":["../../src/providers/primitive-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,cAAc,IAAI,QAAQ,CA4BzC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
export interface Provider {
|
|
3
|
+
prefix?: string;
|
|
4
|
+
match?: (id: string) => boolean;
|
|
5
|
+
resolve: (specifier: string) => string | null;
|
|
6
|
+
}
|
|
7
|
+
export interface DirConfig {
|
|
8
|
+
path: string;
|
|
9
|
+
namespace?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ModuleConfig {
|
|
12
|
+
dirs?: (string | DirConfig)[];
|
|
13
|
+
npm?: (string | NpmModuleConfig)[];
|
|
14
|
+
}
|
|
15
|
+
export interface NpmModuleConfig {
|
|
16
|
+
npm: string;
|
|
17
|
+
}
|
|
18
|
+
export interface PassthroughRule {
|
|
19
|
+
specifierPrefix: string;
|
|
20
|
+
importerPattern: string;
|
|
21
|
+
}
|
|
22
|
+
export interface LwcVitePluginOptions {
|
|
23
|
+
modules?: ModuleConfig;
|
|
24
|
+
providers?: Provider[];
|
|
25
|
+
stubs?: Record<string, string>;
|
|
26
|
+
lwcOptions?: Record<string, unknown>;
|
|
27
|
+
ignorePatterns?: string[];
|
|
28
|
+
passthroughRules?: PassthroughRule[];
|
|
29
|
+
}
|
|
30
|
+
export interface DiscoveredModule {
|
|
31
|
+
name: string;
|
|
32
|
+
path: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ScopedProvidersOptions {
|
|
35
|
+
ignorePatterns?: string[];
|
|
36
|
+
interceptPrefixes?: string[];
|
|
37
|
+
passthroughRules?: PassthroughRule[];
|
|
38
|
+
}
|
|
39
|
+
export interface LightningNpmOptions {
|
|
40
|
+
npmRoot: string;
|
|
41
|
+
overrideDirs?: string[];
|
|
42
|
+
}
|
|
43
|
+
export type LwcPlugin = Plugin;
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,WAAW,QAAQ;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IAChC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAC9B,GAAG,CAAC,EA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