@superblocksteam/sdk-api 2.0.156-next.0 → 2.0.156-next.2
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/errors.d.ts +6 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -23
- package/dist/errors.js.map +1 -1
- package/dist/integrations/base/rest-api-client-base.d.ts +27 -0
- package/dist/integrations/base/rest-api-client-base.d.ts.map +1 -1
- package/dist/integrations/base/rest-api-client-base.js +46 -23
- package/dist/integrations/base/rest-api-client-base.js.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.d.ts +19 -7
- package/dist/integrations/base/rest-api-integration-client.d.ts.map +1 -1
- package/dist/integrations/base/rest-api-integration-client.js +29 -2
- package/dist/integrations/base/rest-api-integration-client.js.map +1 -1
- package/dist/integrations/base/types.d.ts +43 -36
- package/dist/integrations/base/types.d.ts.map +1 -1
- package/dist/integrations/base/types.js +26 -1
- package/dist/integrations/base/types.js.map +1 -1
- package/dist/integrations/documentation-resolver.test.js +5 -11
- package/dist/integrations/documentation-resolver.test.js.map +1 -1
- package/dist/integrations/restapiintegration/client.test.d.ts +10 -0
- package/dist/integrations/restapiintegration/client.test.d.ts.map +1 -1
- package/dist/integrations/restapiintegration/client.test.js +69 -146
- package/dist/integrations/restapiintegration/client.test.js.map +1 -1
- package/dist/integrations/slack/client.test.js +1 -26
- package/dist/integrations/slack/client.test.js.map +1 -1
- package/package.json +2 -2
- package/src/errors.ts +5 -33
- package/src/integrations/anthropic/README.md +0 -7
- package/src/integrations/base/rest-api-client-base.ts +56 -28
- package/src/integrations/base/rest-api-integration-client.ts +33 -14
- package/src/integrations/base/types.ts +45 -41
- package/src/integrations/bigquery/README.md +0 -1
- package/src/integrations/box/README.md +0 -3
- package/src/integrations/cohere/README.md +0 -7
- package/src/integrations/documentation-resolver.test.ts +6 -13
- package/src/integrations/fireworks/README.md +0 -7
- package/src/integrations/gemini/README.md +0 -8
- package/src/integrations/groq/README.md +0 -7
- package/src/integrations/mistral/README.md +0 -7
- package/src/integrations/openai_v2/README.md +0 -7
- package/src/integrations/perplexity/README.md +0 -7
- package/src/integrations/restapiintegration/client.test.ts +86 -207
- package/src/integrations/restapiintegration/docs.manifest.json +1 -5
- package/src/integrations/s3/README.md +0 -1
- package/src/integrations/slack/client.test.ts +1 -36
- package/src/integrations/snowflakecortex/README.md +0 -8
- package/src/integrations/stabilityai/README.md +0 -7
- package/dist/integrations/base/decode-worker-binary-response.d.ts +0 -4
- package/dist/integrations/base/decode-worker-binary-response.d.ts.map +0 -1
- package/dist/integrations/base/decode-worker-binary-response.js +0 -49
- package/dist/integrations/base/decode-worker-binary-response.js.map +0 -1
- package/dist/integrations/base/decode-worker-binary-response.test.d.ts +0 -2
- package/dist/integrations/base/decode-worker-binary-response.test.d.ts.map +0 -1
- package/dist/integrations/base/decode-worker-binary-response.test.js +0 -81
- package/dist/integrations/base/decode-worker-binary-response.test.js.map +0 -1
- package/src/integrations/base/decode-worker-binary-response.test.ts +0 -107
- package/src/integrations/base/decode-worker-binary-response.ts +0 -62
- package/src/integrations/restapiintegration/overlays/response-types-binary.md +0 -51
package/dist/errors.d.ts
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
* Error classes for SDK runtime errors.
|
|
3
3
|
*/
|
|
4
4
|
import type { z } from "zod";
|
|
5
|
-
export declare const REDACTED_BINARY_RESPONSE_DATA: Readonly<{
|
|
6
|
-
dataType: "binary";
|
|
7
|
-
redacted: true;
|
|
8
|
-
}>;
|
|
9
5
|
/**
|
|
10
6
|
* Error thrown when REST API response or request body validation fails.
|
|
11
7
|
*
|
|
@@ -14,12 +10,16 @@ export declare const REDACTED_BINARY_RESPONSE_DATA: Readonly<{
|
|
|
14
10
|
*/
|
|
15
11
|
export declare class RestApiValidationError extends Error {
|
|
16
12
|
readonly details: {
|
|
17
|
-
|
|
13
|
+
/** The complete Zod error object with all validation information */
|
|
18
14
|
zodError: z.ZodError;
|
|
15
|
+
/** The actual data that failed validation (request body or response) */
|
|
16
|
+
data: unknown;
|
|
19
17
|
};
|
|
20
18
|
constructor(message: string, details: {
|
|
21
|
-
|
|
19
|
+
/** The complete Zod error object with all validation information */
|
|
22
20
|
zodError: z.ZodError;
|
|
21
|
+
/** The actual data that failed validation (request body or response) */
|
|
22
|
+
data: unknown;
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
/**
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;aAG7B,OAAO,EAAE;QACvB,oEAAoE;QACpE,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC;QACrB,wEAAwE;QACxE,IAAI,EAAE,OAAO,CAAC;KACf;gBAND,OAAO,EAAE,MAAM,EACC,OAAO,EAAE;QACvB,oEAAoE;QACpE,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC;QACrB,wEAAwE;QACxE,IAAI,EAAE,OAAO,CAAC;KACf;CAOJ;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;aAG3B,OAAO,EAAE;QACvB,wDAAwD;QACxD,QAAQ,EAAE,MAAM,CAAC;QACjB,sDAAsD;QACtD,MAAM,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAC9D,8CAA8C;QAC9C,GAAG,EAA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
|
-
dataType: "binary",
|
|
6
|
-
redacted: true,
|
|
7
|
-
});
|
|
8
|
-
function isWorkerBufferJson(data) {
|
|
9
|
-
if (typeof data !== "object" || data === null) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
if (!("data" in data) || !("type" in data)) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return data.type === "Buffer" && Array.isArray(data.data);
|
|
16
|
-
}
|
|
17
|
-
function redactBinaryValidationData(data) {
|
|
18
|
-
if (data instanceof Uint8Array || isWorkerBufferJson(data)) {
|
|
19
|
-
return REDACTED_BINARY_RESPONSE_DATA;
|
|
20
|
-
}
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
4
|
/**
|
|
24
5
|
* Error thrown when REST API response or request body validation fails.
|
|
25
6
|
*
|
|
@@ -30,11 +11,9 @@ export class RestApiValidationError extends Error {
|
|
|
30
11
|
details;
|
|
31
12
|
constructor(message, details) {
|
|
32
13
|
super(message);
|
|
14
|
+
this.details = details;
|
|
33
15
|
this.name = "RestApiValidationError";
|
|
34
|
-
|
|
35
|
-
data: redactBinaryValidationData(details.data),
|
|
36
|
-
zodError: details.zodError,
|
|
37
|
-
};
|
|
16
|
+
// Ensure proper prototype chain for instanceof checks
|
|
38
17
|
Object.setPrototypeOf(this, RestApiValidationError.prototype);
|
|
39
18
|
}
|
|
40
19
|
}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;GAKG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAG7B;IAFlB,YACE,OAAe,EACC,OAKf;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QAPC,YAAO,GAAP,OAAO,CAKtB;QAGD,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,sDAAsD;QACtD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAG3B;IAFlB,YACE,OAAe,EACC,OAOf;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QATC,YAAO,GAAP,OAAO,CAOtB;QAGD,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,sDAAsD;QACtD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGzB;IAFlB,YACE,OAAe,EACC,OAWf;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QAbC,YAAO,GAAP,OAAO,CAWtB;QAGD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,sDAAsD;QACtD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;CACF"}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base for REST API Integration clients.
|
|
3
|
+
*
|
|
4
|
+
* Owns the shared infrastructure that every REST-API-backed integration
|
|
5
|
+
* needs: config storage, parameter helpers, body validation, request
|
|
6
|
+
* construction, and query execution. Subclasses add their own
|
|
7
|
+
* `apiRequest` with whatever response-handling strategy they need
|
|
8
|
+
* (e.g. direct Zod validation, discriminated-union wrapping).
|
|
9
|
+
*/
|
|
1
10
|
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
2
11
|
import { z } from "zod";
|
|
3
12
|
import type { Property } from "@superblocksteam/types/dist/src/common/v1/plugin_pb";
|
|
@@ -6,6 +15,13 @@ import type { QueryExecutor, TraceMetadata } from "../registry.js";
|
|
|
6
15
|
import type { IntegrationConfig, IntegrationClientImpl } from "../types.js";
|
|
7
16
|
import type { ApiRequestOptions } from "./types.js";
|
|
8
17
|
export type RestApiRequest = PartialMessage<RestApiIntegrationPlugin>;
|
|
18
|
+
/**
|
|
19
|
+
* Shared base for all REST API Integration clients.
|
|
20
|
+
*
|
|
21
|
+
* Provides config fields, parameter helpers, body validation, request
|
|
22
|
+
* building, and query execution. Does NOT define `apiRequest` — each
|
|
23
|
+
* concrete subclass supplies its own return-type contract.
|
|
24
|
+
*/
|
|
9
25
|
export declare abstract class RestApiClientBase implements IntegrationClientImpl {
|
|
10
26
|
readonly name: string;
|
|
11
27
|
readonly pluginId: string;
|
|
@@ -16,6 +32,17 @@ export declare abstract class RestApiClientBase implements IntegrationClientImpl
|
|
|
16
32
|
* Create a Property object for query params / headers.
|
|
17
33
|
*/
|
|
18
34
|
protected createParam(key: string, value: unknown): PartialMessage<Property>;
|
|
35
|
+
/**
|
|
36
|
+
* Validate the request body, build the proto request, and execute it.
|
|
37
|
+
*
|
|
38
|
+
* Returns the raw (unvalidated) response from the orchestrator.
|
|
39
|
+
* Subclasses call this, then apply their own response handling.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Request configuration (see {@link ApiRequestOptions})
|
|
42
|
+
* @param bodySchema - Optional Zod schema for body validation
|
|
43
|
+
* @param metadata - Optional trace metadata for observability
|
|
44
|
+
* @returns Raw response from the orchestrator
|
|
45
|
+
*/
|
|
19
46
|
protected executeApiRequest<TBody>(options: ApiRequestOptions<TBody>, bodySchema?: z.ZodSchema<TBody>, metadata?: TraceMetadata): Promise<unknown>;
|
|
20
47
|
}
|
|
21
48
|
//# sourceMappingURL=rest-api-client-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api-client-base.d.ts","sourceRoot":"","sources":["../../../src/integrations/base/rest-api-client-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,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AY,EAAE,aAAa;IAOlE;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC;IAO5E;;;;;;;;;;OAUG;cACa,iBAAiB,CAAC,KAAK,EACrC,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,EACjC,UAAU,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,EAC/B,QAAQ,CAAC,EAAE,aAAa,GACvB,OAAO,CAAC,OAAO,CAAC;CAuFpB"}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base for REST API Integration clients.
|
|
3
|
+
*
|
|
4
|
+
* Owns the shared infrastructure that every REST-API-backed integration
|
|
5
|
+
* needs: config storage, parameter helpers, body validation, request
|
|
6
|
+
* construction, and query execution. Subclasses add their own
|
|
7
|
+
* `apiRequest` with whatever response-handling strategy they need
|
|
8
|
+
* (e.g. direct Zod validation, discriminated-union wrapping).
|
|
9
|
+
*/
|
|
1
10
|
import { z } from "zod";
|
|
2
11
|
import { RestApiValidationError } from "../../errors.js";
|
|
3
|
-
import { decodeWorkerBinaryResponse } from "./decode-worker-binary-response.js";
|
|
4
12
|
import { REST_API_RESPONSE_TYPES } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Shared base for all REST API Integration clients.
|
|
15
|
+
*
|
|
16
|
+
* Provides config fields, parameter helpers, body validation, request
|
|
17
|
+
* building, and query execution. Does NOT define `apiRequest` — each
|
|
18
|
+
* concrete subclass supplies its own return-type contract.
|
|
19
|
+
*/
|
|
5
20
|
export class RestApiClientBase {
|
|
6
21
|
name;
|
|
7
22
|
pluginId;
|
|
@@ -22,7 +37,19 @@ export class RestApiClientBase {
|
|
|
22
37
|
value: typeof value === "string" ? value : JSON.stringify(value),
|
|
23
38
|
};
|
|
24
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate the request body, build the proto request, and execute it.
|
|
42
|
+
*
|
|
43
|
+
* Returns the raw (unvalidated) response from the orchestrator.
|
|
44
|
+
* Subclasses call this, then apply their own response handling.
|
|
45
|
+
*
|
|
46
|
+
* @param options - Request configuration (see {@link ApiRequestOptions})
|
|
47
|
+
* @param bodySchema - Optional Zod schema for body validation
|
|
48
|
+
* @param metadata - Optional trace metadata for observability
|
|
49
|
+
* @returns Raw response from the orchestrator
|
|
50
|
+
*/
|
|
25
51
|
async executeApiRequest(options, bodySchema, metadata) {
|
|
52
|
+
// Validate request body if both body and schema are present.
|
|
26
53
|
if (options.body !== undefined && bodySchema) {
|
|
27
54
|
const bodyParseResult = bodySchema.safeParse(options.body);
|
|
28
55
|
if (!bodyParseResult.success) {
|
|
@@ -44,11 +71,15 @@ export class RestApiClientBase {
|
|
|
44
71
|
params.push(this.createParam(key, value));
|
|
45
72
|
}
|
|
46
73
|
}
|
|
74
|
+
// The RestApiResponseType union is erased in the bundled JS user APIs
|
|
75
|
+
// run as, so values outside it (including wire values the orchestrator
|
|
76
|
+
// implements but the SDK deliberately does not expose, like "auto")
|
|
77
|
+
// must also be rejected at runtime, before the request is issued.
|
|
47
78
|
const responseTypeResult = z
|
|
48
79
|
.enum(REST_API_RESPONSE_TYPES)
|
|
49
80
|
.safeParse(options.responseType ?? "json");
|
|
50
81
|
if (!responseTypeResult.success) {
|
|
51
|
-
throw new RestApiValidationError(`Unsupported responseType ${JSON.stringify(options.responseType)}
|
|
82
|
+
throw new RestApiValidationError(`Unsupported responseType ${JSON.stringify(options.responseType)} — expected one of: ${REST_API_RESPONSE_TYPES.join(", ")}`, {
|
|
52
83
|
zodError: responseTypeResult.error,
|
|
53
84
|
data: options.responseType,
|
|
54
85
|
});
|
|
@@ -66,30 +97,22 @@ export class RestApiClientBase {
|
|
|
66
97
|
request.body = JSON.stringify(options.body);
|
|
67
98
|
request.bodyType = "jsonBody";
|
|
68
99
|
}
|
|
69
|
-
const result = await this.executeQuery(
|
|
100
|
+
const result = await this.executeQuery(request, undefined, metadata);
|
|
101
|
+
// Neither `null` nor `undefined` is a legitimate decode result for the
|
|
102
|
+
// exposed response types: JSON parses to a value the schema sees, and
|
|
103
|
+
// an empty text body decodes to "". Either value only arises from a
|
|
104
|
+
// broken execution contract, so both throw. (If "auto" is ever exposed,
|
|
105
|
+
// `null` becomes legitimate — it parses a literal `null` JSON body.)
|
|
70
106
|
if (result === null || result === undefined) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
]),
|
|
79
|
-
data: result,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
switch (responseType) {
|
|
83
|
-
case "binary":
|
|
84
|
-
return decodeWorkerBinaryResponse(result);
|
|
85
|
-
case "json":
|
|
86
|
-
case "text":
|
|
87
|
-
return result;
|
|
88
|
-
default: {
|
|
89
|
-
const _exhaustive = responseType;
|
|
90
|
-
return _exhaustive;
|
|
107
|
+
const nonNullResult = z.object({}).safeParse(result);
|
|
108
|
+
if (!nonNullResult.success) {
|
|
109
|
+
throw new RestApiValidationError(`Integration query returned ${String(result)} for responseType "${responseType}" — expected a response value`, {
|
|
110
|
+
zodError: nonNullResult.error,
|
|
111
|
+
data: result,
|
|
112
|
+
});
|
|
91
113
|
}
|
|
92
114
|
}
|
|
115
|
+
return result;
|
|
93
116
|
}
|
|
94
117
|
}
|
|
95
118
|
//# sourceMappingURL=rest-api-client-base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api-client-base.js","sourceRoot":"","sources":["../../../src/integrations/base/rest-api-client-base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rest-api-client-base.js","sourceRoot":"","sources":["../../../src/integrations/base/rest-api-client-base.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,i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;YACP,MAAM;YACN,YAAY;SACb,CAAC;QAEF,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO,CAAC,QAAQ,GAAG,UAAU,CAAC;QAChC,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CACpC,OAAkC,EAClC,SAAS,EACT,QAAQ,CACT,CAAC;QAEF,uEAAuE;QACvE,sEAAsE;QACtE,oEAAoE;QACpE,wEAAwE;QACxE,qEAAqE;QACrE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC5C,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACrD,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;gBAC3B,MAAM,IAAI,sBAAsB,CAC9B,8BAA8B,MAAM,CAAC,MAAM,CAAC,sBAAsB,YAAY,+BAA+B,EAC7G;oBACE,QAAQ,EAAE,aAAa,CAAC,KAAK;oBAC7B,IAAI,EAAE,MAAM;iBACb,CACF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic REST API Integration client with Zod response validation.
|
|
3
|
+
*
|
|
4
|
+
* Extends RestApiClientBase with an apiRequest() that validates the
|
|
5
|
+
* full response against a caller-supplied Zod schema and throws
|
|
6
|
+
* RestApiValidationError on mismatch. When no response schema is
|
|
7
|
+
* provided, the raw result is returned without validation — useful for
|
|
8
|
+
* non-JSON responses (e.g. XML), which can alternatively be validated
|
|
9
|
+
* with a schema matching the decoded value (e.g. z.string()).
|
|
10
|
+
*/
|
|
1
11
|
import { z } from "zod";
|
|
2
12
|
import type { TraceMetadata } from "../registry.js";
|
|
3
13
|
import { RestApiClientBase } from "./rest-api-client-base.js";
|
|
4
14
|
import type { ApiRequestOptions, ApiRequestSchema, RestApiResponseType, SupportsApiRequest } from "./types.js";
|
|
15
|
+
/**
|
|
16
|
+
* Base implementation for REST API Integration clients.
|
|
17
|
+
*
|
|
18
|
+
* All OpenAPI-based integration clients (except those with
|
|
19
|
+
* integration-specific response handling) extend this class to
|
|
20
|
+
* inherit the generic apiRequest() method with runtime Zod validation.
|
|
21
|
+
*/
|
|
5
22
|
export declare abstract class RestApiIntegrationClient extends RestApiClientBase implements SupportsApiRequest {
|
|
6
|
-
apiRequest<TBody, TResponse>(options: ApiRequestOptions<TBody> & {
|
|
7
|
-
responseType?: Exclude<RestApiResponseType, "binary">;
|
|
8
|
-
}, schema: ApiRequestSchema<TBody, TResponse> & {
|
|
23
|
+
apiRequest<TBody, TResponse>(options: ApiRequestOptions<TBody>, schema: ApiRequestSchema<TBody, TResponse> & {
|
|
9
24
|
response: z.ZodSchema<TResponse>;
|
|
10
25
|
}, metadata?: TraceMetadata): Promise<TResponse>;
|
|
11
26
|
apiRequest<TBody>(options: ApiRequestOptions<TBody> & {
|
|
12
|
-
responseType: "
|
|
13
|
-
}, schema?: ApiRequestSchema<TBody, Uint8Array>, metadata?: TraceMetadata): Promise<Uint8Array>;
|
|
14
|
-
apiRequest<TBody>(options: ApiRequestOptions<TBody> & {
|
|
15
|
-
responseType: "text";
|
|
27
|
+
responseType: Exclude<RestApiResponseType, "json">;
|
|
16
28
|
}, schema?: ApiRequestSchema<TBody, unknown>, metadata?: TraceMetadata): Promise<unknown>;
|
|
17
29
|
}
|
|
18
30
|
//# sourceMappingURL=rest-api-integration-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api-integration-client.d.ts","sourceRoot":"","sources":["../../../src/integrations/base/rest-api-integration-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,8BAAsB,wBACpB,SAAQ,iBACR,YAAW,kBAAkB;IAEvB,UAAU,CAAC,KAAK,EAAE,SAAS,EAC/B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"rest-api-integration-client.d.ts","sourceRoot":"","sources":["../../../src/integrations/base/rest-api-integration-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,8BAAsB,wBACpB,SAAQ,iBACR,YAAW,kBAAkB;IAEvB,UAAU,CAAC,KAAK,EAAE,SAAS,EAC/B,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,EACjC,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG;QAC3C,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;KAClC,EACD,QAAQ,CAAC,EAAE,aAAa,GACvB,OAAO,CAAC,SAAS,CAAC;IACf,UAAU,CAAC,KAAK,EACpB,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG;QAClC,YAAY,EAAE,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;KACpD,EACD,MAAM,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,EACzC,QAAQ,CAAC,EAAE,aAAa,GACvB,OAAO,CAAC,OAAO,CAAC;CAwDpB"}
|
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic REST API Integration client with Zod response validation.
|
|
3
|
+
*
|
|
4
|
+
* Extends RestApiClientBase with an apiRequest() that validates the
|
|
5
|
+
* full response against a caller-supplied Zod schema and throws
|
|
6
|
+
* RestApiValidationError on mismatch. When no response schema is
|
|
7
|
+
* provided, the raw result is returned without validation — useful for
|
|
8
|
+
* non-JSON responses (e.g. XML), which can alternatively be validated
|
|
9
|
+
* with a schema matching the decoded value (e.g. z.string()).
|
|
10
|
+
*/
|
|
1
11
|
import { z } from "zod";
|
|
2
12
|
import { RestApiValidationError } from "../../errors.js";
|
|
3
13
|
import { RestApiClientBase } from "./rest-api-client-base.js";
|
|
14
|
+
/**
|
|
15
|
+
* Base implementation for REST API Integration clients.
|
|
16
|
+
*
|
|
17
|
+
* All OpenAPI-based integration clients (except those with
|
|
18
|
+
* integration-specific response handling) extend this class to
|
|
19
|
+
* inherit the generic apiRequest() method with runtime Zod validation.
|
|
20
|
+
*/
|
|
4
21
|
export class RestApiIntegrationClient extends RestApiClientBase {
|
|
5
22
|
async apiRequest(options, schema, metadata) {
|
|
23
|
+
// The overloads make schema-less JSON unrepresentable in TypeScript,
|
|
24
|
+
// but user API code executes as bundled JS with no type enforcement —
|
|
25
|
+
// enforce the same contract at runtime, before issuing the request.
|
|
6
26
|
if ((options.responseType ?? "json") === "json" && !schema?.response) {
|
|
7
|
-
throw new RestApiValidationError('apiRequest() with responseType "json" requires a response schema
|
|
27
|
+
throw new RestApiValidationError('apiRequest() with responseType "json" requires a response schema — provide one, or set responseType: "text" to receive a non-JSON payload unvalidated', {
|
|
8
28
|
zodError: new z.ZodError([
|
|
9
29
|
{
|
|
10
30
|
code: z.ZodIssueCode.custom,
|
|
@@ -16,14 +36,21 @@ export class RestApiIntegrationClient extends RestApiClientBase {
|
|
|
16
36
|
});
|
|
17
37
|
}
|
|
18
38
|
const result = await this.executeApiRequest(options, schema?.body, metadata);
|
|
39
|
+
// Without a response schema the raw result is returned as-is (typed
|
|
40
|
+
// unknown). Non-JSON responses (e.g. responseType "text" returning
|
|
41
|
+
// XML) can either omit the schema or pass one matching the decoded
|
|
42
|
+
// value, such as z.string(). Request-body validation is opt-in:
|
|
43
|
+
// executeApiRequest only validates options.body when schema.body is
|
|
44
|
+
// provided (unchanged from the previous contract, where schema.body
|
|
45
|
+
// was already optional).
|
|
19
46
|
if (!schema?.response) {
|
|
20
47
|
return result;
|
|
21
48
|
}
|
|
22
49
|
const responseParseResult = schema.response.safeParse(result);
|
|
23
50
|
if (!responseParseResult.success) {
|
|
24
51
|
throw new RestApiValidationError(`Response validation failed: ${responseParseResult.error.message}`, {
|
|
25
|
-
data: result,
|
|
26
52
|
zodError: responseParseResult.error,
|
|
53
|
+
data: result,
|
|
27
54
|
});
|
|
28
55
|
}
|
|
29
56
|
return responseParseResult.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api-integration-client.js","sourceRoot":"","sources":["../../../src/integrations/base/rest-api-integration-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAQ9D,MAAM,OAAgB,wBACpB,SAAQ,iBAAiB;
|
|
1
|
+
{"version":3,"file":"rest-api-integration-client.js","sourceRoot":"","sources":["../../../src/integrations/base/rest-api-integration-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAA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AI,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for REST API Integration (OpenAPI) based clients.
|
|
3
|
+
*/
|
|
1
4
|
import type { z } from "zod";
|
|
2
5
|
import type { TraceMetadata } from "../registry.js";
|
|
3
6
|
export type { TraceMetadata };
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* How the orchestrator should decode the HTTP response body.
|
|
9
|
+
*
|
|
10
|
+
* - `"json"` (default): parse the response as JSON; fails on non-JSON bodies
|
|
11
|
+
* - `"text"`: return the decoded response body as a string (XML, CSV, HTML, ...)
|
|
12
|
+
*
|
|
13
|
+
* The orchestrator also implements `"auto"`, `"binary"`, and `"raw"` wire
|
|
14
|
+
* values; they are deliberately not exposed here (widening this union later
|
|
15
|
+
* is backward-compatible, narrowing it is not):
|
|
16
|
+
*
|
|
17
|
+
* - `"auto"` returns parsed JSON whenever the body happens to parse, which
|
|
18
|
+
* would let JSON responses bypass schema validation via the schema-less
|
|
19
|
+
* overload
|
|
20
|
+
* - `"binary"` would freeze the worker's internal Buffer JSON encoding
|
|
21
|
+
* (`{ type: "Buffer", data: number[] }`, ~4x payload inflation) into the
|
|
22
|
+
* public SDK contract
|
|
23
|
+
* - `"raw"` is rejected by the orchestrator for non-streaming requests
|
|
24
|
+
*
|
|
25
|
+
* The runtime tuple backs the request-time guard in `executeApiRequest`:
|
|
26
|
+
* the type-level union is erased in the bundled JS user APIs run as, so
|
|
27
|
+
* values outside it must also be rejected at runtime.
|
|
28
|
+
*/
|
|
29
|
+
export declare const REST_API_RESPONSE_TYPES: readonly ["json", "text"];
|
|
5
30
|
export type RestApiResponseType = (typeof REST_API_RESPONSE_TYPES)[number];
|
|
31
|
+
/**
|
|
32
|
+
* Options for making a generic REST API request.
|
|
33
|
+
*/
|
|
6
34
|
export interface ApiRequestOptions<TBody = unknown> {
|
|
7
35
|
/**
|
|
8
36
|
* HTTP method for the request.
|
|
@@ -29,13 +57,14 @@ export interface ApiRequestOptions<TBody = unknown> {
|
|
|
29
57
|
* How the response body should be decoded. Defaults to `"json"`.
|
|
30
58
|
*
|
|
31
59
|
* Use `"text"` for endpoints that return non-JSON payloads such as
|
|
32
|
-
* XML.
|
|
33
|
-
*
|
|
34
|
-
* use one matching the decoded value, e.g. `z.string()` or
|
|
35
|
-
* `z.instanceof(Uint8Array)`).
|
|
60
|
+
* XML. When requesting a text response, omit the response schema (or
|
|
61
|
+
* use one matching the decoded string, e.g. `z.string()`).
|
|
36
62
|
*/
|
|
37
63
|
responseType?: RestApiResponseType;
|
|
38
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Schema configuration for API request validation.
|
|
67
|
+
*/
|
|
39
68
|
export interface ApiRequestSchema<TBody = unknown, TResponse = unknown> {
|
|
40
69
|
/**
|
|
41
70
|
* Optional Zod schema for request body validation.
|
|
@@ -52,9 +81,10 @@ export interface ApiRequestSchema<TBody = unknown, TResponse = unknown> {
|
|
|
52
81
|
* Interface for integration clients that support generic API requests.
|
|
53
82
|
*
|
|
54
83
|
* Providing a response schema gives type-safe, validated results. Omitting
|
|
55
|
-
* it returns the
|
|
56
|
-
*
|
|
57
|
-
*
|
|
84
|
+
* it returns the raw response as `unknown`. For non-JSON payloads (e.g.
|
|
85
|
+
* `responseType: "text"` for XML), either omit the schema or supply one
|
|
86
|
+
* matching the decoded value (e.g. `z.string()` for text) — object schemas
|
|
87
|
+
* only make sense for JSON-shaped results.
|
|
58
88
|
*/
|
|
59
89
|
export interface SupportsApiRequest {
|
|
60
90
|
/**
|
|
@@ -90,41 +120,18 @@ export interface SupportsApiRequest {
|
|
|
90
120
|
* // result is typed as { ts: string; channel: string }
|
|
91
121
|
* ```
|
|
92
122
|
*/
|
|
93
|
-
apiRequest<TBody, TResponse>(options: ApiRequestOptions<TBody> & {
|
|
94
|
-
responseType?: Exclude<RestApiResponseType, "binary">;
|
|
95
|
-
}, schema: ApiRequestSchema<TBody, TResponse> & {
|
|
123
|
+
apiRequest<TBody, TResponse>(options: ApiRequestOptions<TBody>, schema: ApiRequestSchema<TBody, TResponse> & {
|
|
96
124
|
response: z.ZodSchema<TResponse>;
|
|
97
125
|
}, metadata?: TraceMetadata): Promise<TResponse>;
|
|
98
|
-
/**
|
|
99
|
-
* Execute a generic API request that returns binary data.
|
|
100
|
-
*
|
|
101
|
-
* @param options - Request configuration; `responseType` must be "binary"
|
|
102
|
-
* @param schema - Optional Zod schemas for request body and decoded response validation
|
|
103
|
-
* @param metadata - Optional trace metadata for observability (label, description)
|
|
104
|
-
* @returns The decoded body as a `Uint8Array`
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const pdf = await ctx.integrations.legacyApi.apiRequest({
|
|
109
|
-
* method: 'GET',
|
|
110
|
-
* path: '/file.pdf',
|
|
111
|
-
* responseType: 'binary',
|
|
112
|
-
* });
|
|
113
|
-
* // pdf is a Uint8Array
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
apiRequest<TBody>(options: ApiRequestOptions<TBody> & {
|
|
117
|
-
responseType: "binary";
|
|
118
|
-
}, schema?: ApiRequestSchema<TBody, Uint8Array>, metadata?: TraceMetadata): Promise<Uint8Array>;
|
|
119
126
|
/**
|
|
120
127
|
* Execute a generic API request without response validation.
|
|
121
128
|
*
|
|
122
|
-
* This overload requires an explicit `responseType
|
|
129
|
+
* This overload requires an explicit non-JSON `responseType` — JSON
|
|
123
130
|
* responses must always be consumed through the schema overload above,
|
|
124
|
-
* so "unvalidated JSON" is unrepresentable. The decoded
|
|
131
|
+
* so "unvalidated JSON" is unrepresentable. The decoded non-JSON
|
|
125
132
|
* response is returned as-is, typed `unknown`.
|
|
126
133
|
*
|
|
127
|
-
* Note: request-body validation is opt-in
|
|
134
|
+
* Note: request-body validation is opt-in — it runs only when
|
|
128
135
|
* `schema.body` is provided. Omitting `schema` sends `options.body`
|
|
129
136
|
* without validation.
|
|
130
137
|
*
|
|
@@ -144,7 +151,7 @@ export interface SupportsApiRequest {
|
|
|
144
151
|
* ```
|
|
145
152
|
*/
|
|
146
153
|
apiRequest<TBody>(options: ApiRequestOptions<TBody> & {
|
|
147
|
-
responseType: "
|
|
154
|
+
responseType: Exclude<RestApiResponseType, "json">;
|
|
148
155
|
}, schema?: ApiRequestSchema<TBody, unknown>, metadata?: TraceMetadata): Promise<unknown>;
|
|
149
156
|
}
|
|
150
157
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/integrations/base/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/integrations/base/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,uBAAuB,2BAA4B,CAAC;AAEjE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,GAAG,OAAO;IAChD;;OAEG;IACH,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;IAEzE;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,M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|
4
|
+
/**
|
|
5
|
+
* How the orchestrator should decode the HTTP response body.
|
|
6
|
+
*
|
|
7
|
+
* - `"json"` (default): parse the response as JSON; fails on non-JSON bodies
|
|
8
|
+
* - `"text"`: return the decoded response body as a string (XML, CSV, HTML, ...)
|
|
9
|
+
*
|
|
10
|
+
* The orchestrator also implements `"auto"`, `"binary"`, and `"raw"` wire
|
|
11
|
+
* values; they are deliberately not exposed here (widening this union later
|
|
12
|
+
* is backward-compatible, narrowing it is not):
|
|
13
|
+
*
|
|
14
|
+
* - `"auto"` returns parsed JSON whenever the body happens to parse, which
|
|
15
|
+
* would let JSON responses bypass schema validation via the schema-less
|
|
16
|
+
* overload
|
|
17
|
+
* - `"binary"` would freeze the worker's internal Buffer JSON encoding
|
|
18
|
+
* (`{ type: "Buffer", data: number[] }`, ~4x payload inflation) into the
|
|
19
|
+
* public SDK contract
|
|
20
|
+
* - `"raw"` is rejected by the orchestrator for non-streaming requests
|
|
21
|
+
*
|
|
22
|
+
* The runtime tuple backs the request-time guard in `executeApiRequest`:
|
|
23
|
+
* the type-level union is erased in the bundled JS user APIs run as, so
|
|
24
|
+
* values outside it must also be rejected at runtime.
|
|
25
|
+
*/
|
|
26
|
+
export const REST_API_RESPONSE_TYPES = ["json", "text"];
|
|
2
27
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/integrations/base/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/integrations/base/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAU,CAAC"}
|
|
@@ -728,20 +728,15 @@ describe("resolveIntegrationDocumentation", () => {
|
|
|
728
728
|
});
|
|
729
729
|
});
|
|
730
730
|
describe("restapiintegration responseType gating (real docs)", () => {
|
|
731
|
-
|
|
731
|
+
// These resolve the actual shipped docs, not a fixture: the overlay
|
|
732
|
+
// gating is the discoverability guard for the responseType feature
|
|
733
|
+
// (agents whose worker sdk-api predates it must never be told the
|
|
734
|
+
// option exists), so the real manifest content is the contract.
|
|
735
|
+
it("documents responseType for agents whose sdk-api supports it", async () => {
|
|
732
736
|
const docs = await resolveIntegrationDocumentation("restapiintegration", {
|
|
733
737
|
sdkVersion: "0.0.3",
|
|
734
738
|
});
|
|
735
739
|
expect(docs).toContain('responseType: "text"');
|
|
736
|
-
expect(docs).not.toContain('responseType: "binary"');
|
|
737
|
-
expect(docs).not.toContain("does not support the `responseType`");
|
|
738
|
-
});
|
|
739
|
-
it("documents binary responseType only for agents whose sdk-api supports it", async () => {
|
|
740
|
-
const docs = await resolveIntegrationDocumentation("restapiintegration", {
|
|
741
|
-
sdkVersion: "0.0.4",
|
|
742
|
-
});
|
|
743
|
-
expect(docs).toContain('responseType: "text"');
|
|
744
|
-
expect(docs).toContain('responseType: "binary"');
|
|
745
740
|
expect(docs).not.toContain("does not support the `responseType`");
|
|
746
741
|
});
|
|
747
742
|
it("notes non-support instead of documenting responseType on older agents", async () => {
|
|
@@ -750,7 +745,6 @@ describe("resolveIntegrationDocumentation", () => {
|
|
|
750
745
|
});
|
|
751
746
|
expect(docs).toContain("does not support the `responseType`");
|
|
752
747
|
expect(docs).not.toContain('responseType: "text"');
|
|
753
|
-
expect(docs).not.toContain('responseType: "binary"');
|
|
754
748
|
});
|
|
755
749
|
it("stays silent about responseType when the agent reports no sdk-api version", async () => {
|
|
756
750
|
const docs = await resolveIntegrationDocumentation("restapiintegration");
|