@salesforce/external-service-sdk 0.0.0-stage → 13.1.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 ADDED
@@ -0,0 +1,82 @@
1
+ Terms of Use
2
+
3
+ Copyright 2026 Salesforce, Inc. All rights reserved.
4
+
5
+ These Terms of Use govern the download, installation, and/or use of this
6
+ software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
7
+ last updated on April 15, 2025, and constitute a legally binding
8
+ agreement between you and Salesforce. If you do not agree to these Terms of
9
+ Use, do not install or use the Software.
10
+
11
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
12
+ copyright license to reproduce, prepare derivative works of, publicly
13
+ display, publicly perform, sublicense, and distribute the Software and
14
+ derivative works subject to these Terms. These Terms shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ Subject to the limited rights expressly granted hereunder, Salesforce
18
+ reserves all rights, title, and interest in and to all intellectual
19
+ property subsisting in the Software. No rights are granted to you hereunder
20
+ other than as expressly set forth herein. Users residing in countries on
21
+ the United States Office of Foreign Assets Control sanction list, or which
22
+ are otherwise subject to a US export embargo, may not use the Software.
23
+
24
+ Implementation of the Software may require development work, for which you
25
+ are responsible. The Software may contain bugs, errors and
26
+ incompatibilities and is made available on an AS IS basis without support,
27
+ updates, or service level commitments.
28
+
29
+ Salesforce reserves the right at any time to modify, suspend, or
30
+ discontinue, the Software (or any part thereof) with or without notice. You
31
+ agree that Salesforce shall not be liable to you or to any third party for
32
+ any modification, suspension, or discontinuance.
33
+
34
+ You agree to defend Salesforce against any claim, demand, suit or
35
+ proceeding made or brought against Salesforce by a third party arising out
36
+ of or accruing from (a) your use of the Software, and (b) any application
37
+ you develop with the Software that infringes any copyright, trademark,
38
+ trade secret, trade dress, patent, or other intellectual property right of
39
+ any person or defames any person or violates their rights of publicity or
40
+ privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
41
+ from any damages, attorney fees, and costs finally awarded against
42
+ Salesforce as a result of, or for any amounts paid by Salesforce under a
43
+ settlement approved by you in writing of, a Claim Against Salesforce,
44
+ provided Salesforce (x) promptly gives you written notice of the Claim
45
+ Against Salesforce, (y) gives you sole control of the defense and
46
+ settlement of the Claim Against Salesforce (except that you may not settle
47
+ any Claim Against Salesforce unless it unconditionally releases Salesforce
48
+ of all liability), and (z) gives you all reasonable assistance, at your
49
+ expense.
50
+
51
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
52
+ SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
54
+ INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
55
+ PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
56
+ OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
57
+ CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
58
+ HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
59
+
60
+ These Terms of Use shall be governed exclusively by the internal laws of
61
+ the State of California, without regard to its conflicts of laws
62
+ rules. Each party hereby consents to the exclusive jurisdiction of the
63
+ state and federal courts located in San Francisco County, California to
64
+ adjudicate any dispute arising out of or relating to these Terms of Use and
65
+ the download, installation, and/or use of the Software. Except as expressly
66
+ stated herein, these Terms of Use constitute the entire agreement between
67
+ the parties, and supersede all prior and contemporaneous agreements,
68
+ proposals, or representations, written or oral, concerning their subject
69
+ matter. No modification, amendment, or waiver of any provision of these
70
+ Terms of Use shall be effective unless it is by an update to these Terms of
71
+ Use that Salesforce makes available, or is in writing and signed by the
72
+ party against whom the modification, amendment, or waiver is to be
73
+ asserted.
74
+
75
+ Data Privacy: Salesforce may collect, process, and store device,
76
+ system, and other information related to your use of the Software. This
77
+ information includes, but is not limited to, IP address, user metrics, and
78
+ other data ("Usage Data"). Salesforce may use Usage Data for analytics,
79
+ product development, and marketing purposes. You acknowledge that files
80
+ generated in conjunction with the Software may contain sensitive or
81
+ confidential data, and you are solely responsible for anonymizing and
82
+ protecting such data.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # @salesforce/external-service-sdk (Beta)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Beta:** This is a pilot or beta service subject to the
4
+ > [Beta Services Terms](https://www.salesforce.com/company/legal/agreements/) or a written
5
+ > Unified Pilot Agreement, and applicable terms in the
6
+ > [Product Terms Directory](https://ptd.salesforce.com/).
7
+
8
+ A `DataSDK` extension that invokes [Salesforce External Service](https://help.salesforce.com/s/articleView?id=platform.external_services.htm) actions
9
+ (`/services/data/v65.0/actions/custom/externalService/<Service>.<Action>`)
10
+ through the DataSDK's `fetch`, reusing its session and CSRF handling. The
11
+ API version is pinned to `65.0`; a future release will pin a newer version.
12
+
13
+ ## Usage
14
+
15
+ Import the factory from the package root, and each operation from its own
16
+ subpath. Only the operations you import end up in your bundle.
17
+
18
+ ```typescript
19
+ import { createDataSDK } from "@salesforce/platform-sdk/data";
20
+ import { externalService, isExternalServiceError } from "@salesforce/external-service-sdk";
21
+ import { invoke } from "@salesforce/external-service-sdk/invoke";
22
+
23
+ const sdk = await createDataSDK({
24
+ extensions: [externalService({ invoke })],
25
+ });
26
+
27
+ try {
28
+ const accounts = await sdk.ext.externalService.invoke?.<Account[]>({
29
+ actionName: "MyService.ListAccounts",
30
+ });
31
+ const order = await sdk.ext.externalService.invoke?.({
32
+ actionName: "Orders.Create",
33
+ input: { body: { sku: "A1" } },
34
+ });
35
+ } catch (error) {
36
+ if (isExternalServiceError(error) && error.kind === "unauthorized") {
37
+ // Ask the user to sign in again.
38
+ }
39
+ }
40
+ ```
41
+
42
+ `actionName` is always the fully-qualified `"Service.Action"`. Failures throw
43
+ an `ExternalServiceError`; narrow with `isExternalServiceError`.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ /** Splits `"Service.Action"`. Throws when a part is empty or the dot is missing. */
7
+ export declare function qualifyAction(action: string): {
8
+ service: string;
9
+ name: string;
10
+ };
11
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAiB/E"}
@@ -0,0 +1,16 @@
1
+ import { ExternalServiceEnvelope, ExternalServiceOutputValues } from './types.js';
2
+ export declare function tryParseJson(text: string): unknown;
3
+ export declare function isEnvelope(value: unknown): value is ExternalServiceEnvelope;
4
+ /** The service's HTTP status: `responseCode`, else the first status key. */
5
+ export declare function serviceStatusOf(outputValues: ExternalServiceOutputValues): number | undefined;
6
+ /**
7
+ * Looks up the response body under `status`, then its `"NXX"` status class, then `"default"`.
8
+ *
9
+ * @remarks
10
+ * External Services passes OpenAPI response keys through verbatim, so the same
11
+ * body can land under `"200"`, `"2XX"`, or `"default"` depending on the schema.
12
+ */
13
+ export declare function bodyForStatus(outputValues: ExternalServiceOutputValues, status: number | undefined): unknown;
14
+ /** Parses a string body that holds a JSON object or array. Other values pass through. */
15
+ export declare function decodeBody(value: unknown): unknown;
16
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAEvF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMlD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,uBAAuB,CAkB3E;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,YAAY,EAAE,2BAA2B,GAAG,MAAM,GAAG,SAAS,CAI7F;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,YAAY,EAAE,2BAA2B,EACzC,MAAM,EAAE,MAAM,GAAG,SAAS,GACxB,OAAO,CAUT;AAED,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMlD"}
@@ -0,0 +1,27 @@
1
+ function i(t) {
2
+ const e = new Error(
3
+ `External Service action ${t.action} failed (${t.kind}): ${t.message}`
4
+ );
5
+ return e.name = "ExternalServiceError", e.kind = t.kind, e.action = t.action, e.status = t.status, e.body = t.body, t.cause !== void 0 && (e.cause = t.cause), e;
6
+ }
7
+ function n(t) {
8
+ if (t === null || typeof t != "object") return !1;
9
+ const e = t;
10
+ return e.name === "ExternalServiceError" && typeof e.kind == "string" && typeof e.action == "string";
11
+ }
12
+ function o(t) {
13
+ const e = Array.isArray(t) ? t[0] : void 0;
14
+ if (e && typeof e == "object" && "errorCode" in e) {
15
+ const { errorCode: r } = e;
16
+ return typeof r == "string" ? r : void 0;
17
+ }
18
+ }
19
+ function c(t, e) {
20
+ return t === 401 || e === "INVALID_SESSION_ID" ? "unauthorized" : e === "API_DISABLED_FOR_ORG" || e === "API_CURRENTLY_DISABLED" ? "apiDisabled" : e === "REQUEST_LIMIT_EXCEEDED" ? "apiLimit" : "service";
21
+ }
22
+ export {
23
+ i as c,
24
+ o as e,
25
+ c as h,
26
+ n as i
27
+ };
@@ -0,0 +1,24 @@
1
+ import { ExternalServiceError, ExternalServiceErrorKind } from './types.js';
2
+ /** Creates an {@link ExternalServiceError}. */
3
+ export declare function createExternalServiceError(args: {
4
+ kind: ExternalServiceErrorKind;
5
+ action: string;
6
+ message: string;
7
+ status?: number;
8
+ body?: unknown;
9
+ cause?: unknown;
10
+ }): ExternalServiceError;
11
+ /**
12
+ * Narrows `error` to an {@link ExternalServiceError}.
13
+ *
14
+ * @remarks
15
+ * Duck-types on `name === "ExternalServiceError"` plus string `kind` and `action`,
16
+ * so it holds across module-loader and realm boundaries (for example, errors
17
+ * thrown from another realm such as an iframe) where `instanceof Error` would be `false`.
18
+ */
19
+ export declare function isExternalServiceError(error: unknown): error is ExternalServiceError;
20
+ /** Reads `errorCode` from a Salesforce error body: `[{ errorCode, message }]`. */
21
+ export declare function errorCodeOf(body: unknown): string | undefined;
22
+ /** Maps an HTTP status + optional Salesforce `errorCode` to an {@link ExternalServiceErrorKind}. */
23
+ export declare function httpErrorKind(status: number, errorCode: string | undefined): ExternalServiceErrorKind;
24
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEjF,+CAA+C;AAC/C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE;IAChD,IAAI,EAAE,wBAAwB,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,GAAG,oBAAoB,CAoBvB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAQpF;AAED,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAO7D;AAED,oGAAoG;AACpG,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAAG,SAAS,GAC3B,wBAAwB,CAO1B"}
@@ -0,0 +1,49 @@
1
+ import { ExternalServiceApi, ExternalServiceOperations } from './types.js';
2
+ export { isExternalServiceError } from './errors.js';
3
+ export type { ExternalServiceApi, ExternalServiceEnvelope, ExternalServiceError, ExternalServiceErrorKind, ExternalServiceFailureEnvelope, ExternalServiceOperations, ExternalServiceOutputValues, ExternalServiceSuccessEnvelope, InvokeFn, InvokeInput, OperationBuilder, OperationContext, } from './types.js';
4
+ /**
5
+ * Creates a DataSDK extension that calls External Service actions.
6
+ *
7
+ * @remarks
8
+ * The factory mounts whatever operations it is handed. Import each operation
9
+ * from its own subpath and pass it in; only those operations end up in your
10
+ * bundle.
11
+ *
12
+ * Each call POSTs `{"inputs":[input]}` to
13
+ * `/services/data/v65.0/actions/custom/externalService/<Service>.<Action>`
14
+ * through the DataSDK's `fetch`, so it gets the same session and CSRF handling.
15
+ *
16
+ * @param operations - The operations to mount (e.g. `{ invoke }`).
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { createDataSDK } from "@salesforce/platform-sdk/data";
21
+ * import { externalService, isExternalServiceError } from "@salesforce/external-service-sdk";
22
+ * import { invoke } from "@salesforce/external-service-sdk/invoke";
23
+ *
24
+ * type Account = {
25
+ * id: string;
26
+ * name: string;
27
+ * };
28
+ *
29
+ * const sdk = await createDataSDK({
30
+ * extensions: [externalService({ invoke })],
31
+ * });
32
+ *
33
+ * try {
34
+ * const accounts = await sdk.ext.externalService.invoke?.<Account[]>({
35
+ * actionName: "MyService.ListAccounts",
36
+ * });
37
+ * const order = await sdk.ext.externalService.invoke?.({
38
+ * actionName: "Orders.Create",
39
+ * input: { body: { sku: "A1" } },
40
+ * });
41
+ * } catch (error) {
42
+ * if (isExternalServiceError(error) && error.kind === "unauthorized") {
43
+ * // Ask the user to sign in again.
44
+ * }
45
+ * }
46
+ * ```
47
+ */
48
+ export declare function externalService(operations?: ExternalServiceOperations): import('@salesforce/platform-sdk/data').DataSDKExtension<"externalService", ExternalServiceApi>;
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEhF,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EACX,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,EACxB,8BAA8B,EAC9B,yBAAyB,EACzB,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,eAAe,CAAC,UAAU,GAAE,yBAA8B,mGAoBzE"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import { defineDataExtension as o } from "@salesforce/platform-sdk/data";
2
+ import { i as p } from "./errors-jPdvTAz8.js";
3
+ function a(i = {}) {
4
+ const e = { ...i };
5
+ return o({
6
+ name: "externalService",
7
+ setup: (r) => {
8
+ const n = r.fetch?.bind(r);
9
+ if (!n)
10
+ return {};
11
+ const t = {};
12
+ return e.invoke && (t.invoke = e.invoke({ fetch: n })), t;
13
+ }
14
+ });
15
+ }
16
+ export {
17
+ a as externalService,
18
+ p as isExternalServiceError
19
+ };
@@ -0,0 +1,20 @@
1
+ import { InvokeFn, OperationContext } from './types.js';
2
+ /**
3
+ * The `invoke` operation.
4
+ *
5
+ * @remarks
6
+ * Import this and pass it to the factory:
7
+ *
8
+ * ```typescript
9
+ * import { externalService } from "@salesforce/external-service-sdk";
10
+ * import { invoke } from "@salesforce/external-service-sdk/invoke";
11
+ *
12
+ * const sdk = await createDataSDK({ extensions: [externalService({ invoke })] });
13
+ * await sdk.ext.externalService.invoke?.({ actionName: "Orders.Create", input: { body: { sku: "A1" } } });
14
+ * ```
15
+ *
16
+ * @param context - Internal: supplied by the factory at setup.
17
+ */
18
+ export declare function invoke(context: OperationContext): InvokeFn;
19
+ export default invoke;
20
+ //# sourceMappingURL=invoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../src/invoke.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,QAAQ,EAAe,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAc1E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,QAAQ,CAgF1D;AAED,eAAe,MAAM,CAAC"}
package/dist/invoke.js ADDED
@@ -0,0 +1,122 @@
1
+ import { c as f, e as A, h as $ } from "./errors-jPdvTAz8.js";
2
+ function E(t) {
3
+ const e = t.indexOf(".");
4
+ if (e === -1)
5
+ throw new TypeError(
6
+ `External Service action ${JSON.stringify(t)} has no service name. Pass the fully-qualified "Service.Action".`
7
+ );
8
+ const r = t.slice(0, e), i = t.slice(e + 1);
9
+ if (!r)
10
+ throw new TypeError(`External Service action ${JSON.stringify(t)} has no service name.`);
11
+ if (!i)
12
+ throw new TypeError(`External Service action ${JSON.stringify(t)} has no action name.`);
13
+ return { service: r, name: i };
14
+ }
15
+ function b(t) {
16
+ try {
17
+ return JSON.parse(t);
18
+ } catch {
19
+ return;
20
+ }
21
+ }
22
+ function O(t) {
23
+ if (!t || typeof t != "object") return !1;
24
+ const e = t;
25
+ if (typeof e.actionName != "string" || typeof e.isSuccess != "boolean" || !("errors" in e)) return !1;
26
+ if (e.isSuccess) {
27
+ const r = e.outputValues;
28
+ return !!r && typeof r == "object" && !Array.isArray(r);
29
+ }
30
+ if ("outputValues" in e) {
31
+ const r = e.outputValues;
32
+ return r == null ? !0 : typeof r == "object" && !Array.isArray(r);
33
+ }
34
+ return !0;
35
+ }
36
+ function h(t) {
37
+ if (typeof t.responseCode == "number") return t.responseCode;
38
+ const e = Object.keys(t).find((r) => /^\d{3}$/.test(r));
39
+ return e === void 0 ? void 0 : Number(e);
40
+ }
41
+ function m(t, e) {
42
+ if (e !== void 0) {
43
+ const r = t[String(e)];
44
+ if (r !== void 0) return r;
45
+ const i = `${Math.floor(e / 100)}XX`, d = t[i];
46
+ if (d !== void 0) return d;
47
+ }
48
+ if (t.default !== void 0) return t.default;
49
+ }
50
+ function S(t) {
51
+ if (typeof t != "string") return t;
52
+ const e = t.trim();
53
+ if (!e.startsWith("{") && !e.startsWith("[")) return t;
54
+ const r = b(e);
55
+ return r === void 0 ? t : r;
56
+ }
57
+ const k = "65.0", T = `/services/data/v${k}`;
58
+ function N(t) {
59
+ const e = t.fetch;
60
+ return async function(i) {
61
+ const { actionName: d, input: g = {} } = i, { service: v, name: l } = E(d), a = `${v}.${l}`, w = `${T}/actions/custom/externalService/${encodeURIComponent(v)}.${encodeURIComponent(l)}`;
62
+ let o, y;
63
+ try {
64
+ o = await e(w, {
65
+ method: "POST",
66
+ headers: { "Content-Type": "application/json" },
67
+ body: JSON.stringify({ inputs: [g] })
68
+ }), y = await o.text();
69
+ } catch (n) {
70
+ throw f({
71
+ kind: "transport",
72
+ action: a,
73
+ message: n instanceof Error ? n.message : String(n),
74
+ cause: n
75
+ });
76
+ }
77
+ const u = b(y);
78
+ if (!o.ok) {
79
+ const n = A(u);
80
+ throw f({
81
+ kind: $(o.status, n),
82
+ action: a,
83
+ message: n ?? `HTTP ${o.status}`,
84
+ status: o.status,
85
+ body: u ?? y
86
+ });
87
+ }
88
+ const c = Array.isArray(u) ? u[0] : void 0;
89
+ if (!O(c))
90
+ throw f({
91
+ kind: "response",
92
+ action: a,
93
+ message: "the response is not an Invocable Action envelope",
94
+ status: o.status,
95
+ body: u ?? y
96
+ });
97
+ if (!c.isSuccess) {
98
+ const n = c.outputValues ? h(c.outputValues) : void 0;
99
+ throw f({
100
+ kind: "service",
101
+ action: a,
102
+ message: "the action did not complete",
103
+ status: n ?? o.status,
104
+ body: c.errors
105
+ });
106
+ }
107
+ const { outputValues: p } = c, s = h(p);
108
+ if (s !== void 0 && (s < 200 || s > 299))
109
+ throw f({
110
+ kind: "service",
111
+ action: a,
112
+ message: `the service returned HTTP ${s}`,
113
+ status: s,
114
+ body: S(m(p, s))
115
+ });
116
+ return S(m(p, s));
117
+ };
118
+ }
119
+ export {
120
+ N as default,
121
+ N as invoke
122
+ };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ /** The envelope's `outputValues`: the response body keyed by HTTP status (`"200"`), plus `responseCode`. */
7
+ export type ExternalServiceOutputValues = {
8
+ [statusCode: string]: unknown;
9
+ responseCode?: number;
10
+ };
11
+ /** The envelope of a completed Invocable Action. */
12
+ export type ExternalServiceSuccessEnvelope = {
13
+ /** The `"Service.Action"` that ran. */
14
+ actionName: string;
15
+ /** `true` when the action completed. */
16
+ isSuccess: true;
17
+ /** The error details, or `null`. */
18
+ errors: unknown;
19
+ /** The response body, keyed by HTTP status. */
20
+ outputValues: ExternalServiceOutputValues;
21
+ };
22
+ /** The envelope of a failed Invocable Action. `outputValues` may be absent. */
23
+ export type ExternalServiceFailureEnvelope = {
24
+ /** The `"Service.Action"` that ran. */
25
+ actionName: string;
26
+ /** `false` when the action did not complete. */
27
+ isSuccess: false;
28
+ /** The error details, or `null`. */
29
+ errors: unknown;
30
+ /** The response body, keyed by HTTP status. Absent on some failures. */
31
+ outputValues?: ExternalServiceOutputValues | null;
32
+ };
33
+ /** The first envelope of an Invocable Action response. */
34
+ export type ExternalServiceEnvelope = ExternalServiceSuccessEnvelope | ExternalServiceFailureEnvelope;
35
+ /**
36
+ * Why an {@link ExternalServiceError} was thrown.
37
+ *
38
+ * @remarks
39
+ * - `"unauthorized"`: HTTP 401 or `INVALID_SESSION_ID`.
40
+ * - `"apiDisabled"`: `API_DISABLED_FOR_ORG` or `API_CURRENTLY_DISABLED`.
41
+ * - `"apiLimit"`: `REQUEST_LIMIT_EXCEEDED`.
42
+ * - `"service"`: Salesforce or the service rejected the call.
43
+ * - `"transport"`: the request did not complete.
44
+ * - `"response"`: the response is not an Invocable Action envelope.
45
+ */
46
+ export type ExternalServiceErrorKind = "unauthorized" | "apiDisabled" | "apiLimit" | "service" | "transport" | "response";
47
+ /**
48
+ * The error thrown when an External Service call fails.
49
+ *
50
+ * @remarks
51
+ * This is a plain `Error` with extra fields, not a class. Use `isExternalServiceError`
52
+ * to narrow unknown errors; it holds across module-loader and realm boundaries where
53
+ * `instanceof` would not.
54
+ */
55
+ export type ExternalServiceError = Error & {
56
+ readonly name: "ExternalServiceError";
57
+ /** Why the call failed. */
58
+ readonly kind: ExternalServiceErrorKind;
59
+ /** The `"Service.Action"` of the call. */
60
+ readonly action: string;
61
+ /** The service's HTTP status, else the Salesforce one. `undefined` for `"transport"`. */
62
+ readonly status: number | undefined;
63
+ /** The error payload, when the server sent one. */
64
+ readonly body: unknown;
65
+ };
66
+ /** The input to {@link InvokeFn}. `actionName` is always `"Service.Action"`. */
67
+ export type InvokeInput = {
68
+ /** The fully-qualified `"Service.Action"` name. */
69
+ actionName: string;
70
+ /** The action input. Defaults to `{}`. */
71
+ input?: Record<string, unknown>;
72
+ };
73
+ /**
74
+ * Calls an External Service action and returns the service's response body.
75
+ *
76
+ * @remarks
77
+ * Parses a body sent as a JSON string. Returns `undefined` when there is no
78
+ * body. Throws an {@link ExternalServiceError} on failure.
79
+ *
80
+ * Imported from `@salesforce/external-service-sdk/invoke` and passed to
81
+ * `externalService({ invoke })`.
82
+ */
83
+ export type InvokeFn = <TOutput = unknown>(params: InvokeInput) => Promise<TOutput | undefined>;
84
+ /** Internal: the context the factory supplies to each operation builder at setup. */
85
+ export type OperationContext = {
86
+ fetch: (input: string, init?: RequestInit) => Promise<Response>;
87
+ };
88
+ /** An operation builder, as imported from a subpath. */
89
+ export type OperationBuilder<TFn> = (context: OperationContext) => TFn;
90
+ /**
91
+ * The operations accepted by {@link externalService}.
92
+ *
93
+ * @remarks
94
+ * Each value is the operation builder imported from its own subpath, e.g.
95
+ * `invoke` from `@salesforce/external-service-sdk/invoke`.
96
+ */
97
+ export type ExternalServiceOperations = {
98
+ /** The `invoke` operation builder. */
99
+ invoke?: OperationBuilder<InvokeFn>;
100
+ };
101
+ /**
102
+ * The `sdk.ext.externalService` namespace.
103
+ *
104
+ * @remarks
105
+ * `invoke` is present only when it was passed to `externalService({ invoke })`
106
+ * AND the DataSDK has `fetch`. Call it with `?.`.
107
+ */
108
+ export type ExternalServiceApi = {
109
+ /**
110
+ * Calls an action and returns the service's response body.
111
+ *
112
+ * @remarks
113
+ * Parses a body sent as a JSON string. Returns `undefined` when there is no
114
+ * body. Throws an {@link ExternalServiceError} on failure.
115
+ *
116
+ * @param params - `{ actionName, input? }`. `actionName` is always `"Service.Action"`.
117
+ */
118
+ invoke?: InvokeFn;
119
+ };
120
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,4GAA4G;AAC5G,MAAM,MAAM,2BAA2B,GAAG;IACzC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,oDAAoD;AACpD,MAAM,MAAM,8BAA8B,GAAG;IAC5C,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,SAAS,EAAE,IAAI,CAAC;IAChB,oCAAoC;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,+CAA+C;IAC/C,YAAY,EAAE,2BAA2B,CAAC;CAC1C,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,8BAA8B,GAAG;IAC5C,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,SAAS,EAAE,KAAK,CAAC;IACjB,oCAAoC;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,wEAAwE;IACxE,YAAY,CAAC,EAAE,2BAA2B,GAAG,IAAI,CAAC;CAClD,CAAC;AAEF,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAClC,8BAA8B,GAAG,8BAA8B,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,wBAAwB,GACnC,cAAc,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;AAEpF;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG;IAC1C,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,2BAA2B;IAC3B,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yFAAyF;IACzF,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,gFAAgF;AAChF,MAAM,MAAM,WAAW,GAAG;IACzB,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;AAEhG,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChE,CAAC;AAEF,wDAAwD;AACxD,MAAM,MAAM,gBAAgB,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,gBAAgB,KAAK,GAAG,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACvC,sCAAsC;IACtC,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;CAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@salesforce/external-service-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "13.1.0",
4
+ "description": "A DataSDK extension that invokes Salesforce External Service actions (/actions/custom/externalService), reusing the DataSDK's session and CSRF handling.",
5
+ "license": "SEE LICENSE IN LICENSE.txt",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "sideEffects": false,
11
+ "exports": {
12
+ "./package.json": "./package.json",
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./invoke": {
19
+ "types": "./dist/invoke.d.ts",
20
+ "import": "./dist/invoke.js",
21
+ "default": "./dist/invoke.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "vite build",
29
+ "clean": "rm -rf dist",
30
+ "dev": "vite build --watch",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest",
33
+ "test:coverage": "vitest run --coverage"
34
+ },
35
+ "peerDependencies": {
36
+ "@salesforce/platform-sdk": "^13.1.0"
37
+ },
38
+ "devDependencies": {
39
+ "@salesforce/platform-sdk": "^13.1.0",
40
+ "vite": "^7.3.5",
41
+ "vite-plugin-dts": "^4.5.4",
42
+ "vitest": "^4.1.11"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }