@superblocksteam/sdk-api 2.0.157-next.5 → 2.0.157
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
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { RestApiValidationError } from "../../errors.js";
|
|
3
|
-
import { decodeWorkerBinaryResponse } from "./decode-worker-binary-response.js";
|
|
4
|
-
describe("decodeWorkerBinaryResponse", () => {
|
|
5
|
-
it("copies a Uint8Array into a plain Uint8Array with the same bytes", () => {
|
|
6
|
-
const source = new Uint8Array([1, 2, 255]);
|
|
7
|
-
const result = decodeWorkerBinaryResponse(source);
|
|
8
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
9
|
-
expect(result.constructor).toBe(Uint8Array);
|
|
10
|
-
expect(Array.from(result)).toEqual([1, 2, 255]);
|
|
11
|
-
source[0] = 9;
|
|
12
|
-
expect(result[0]).toBe(1);
|
|
13
|
-
});
|
|
14
|
-
it("converts worker Buffer JSON into a plain Uint8Array", () => {
|
|
15
|
-
const result = decodeWorkerBinaryResponse({
|
|
16
|
-
type: "Buffer",
|
|
17
|
-
data: [37, 80, 68, 70],
|
|
18
|
-
});
|
|
19
|
-
expect(result.constructor).toBe(Uint8Array);
|
|
20
|
-
expect(Array.from(result)).toEqual([37, 80, 68, 70]);
|
|
21
|
-
});
|
|
22
|
-
it("converts empty Buffer JSON into a zero-length Uint8Array", () => {
|
|
23
|
-
const result = decodeWorkerBinaryResponse({ type: "Buffer", data: [] });
|
|
24
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
25
|
-
expect(result.byteLength).toBe(0);
|
|
26
|
-
});
|
|
27
|
-
it("rejects a missing discriminant", () => {
|
|
28
|
-
expect(() => decodeWorkerBinaryResponse({ data: [1] })).toThrow(RestApiValidationError);
|
|
29
|
-
});
|
|
30
|
-
it("rejects a non-Buffer discriminant", () => {
|
|
31
|
-
expect(() => decodeWorkerBinaryResponse({ type: "Array", data: [1] })).toThrow(RestApiValidationError);
|
|
32
|
-
});
|
|
33
|
-
it("rejects a non-array data field", () => {
|
|
34
|
-
expect(() => decodeWorkerBinaryResponse({ type: "Buffer", data: "00ff" })).toThrow(RestApiValidationError);
|
|
35
|
-
});
|
|
36
|
-
it("rejects a byte outside 0 through 255", () => {
|
|
37
|
-
expect(() => decodeWorkerBinaryResponse({ type: "Buffer", data: [256] })).toThrow(RestApiValidationError);
|
|
38
|
-
});
|
|
39
|
-
it("rejects a negative byte", () => {
|
|
40
|
-
expect(() => decodeWorkerBinaryResponse({ type: "Buffer", data: [-1] })).toThrow(RestApiValidationError);
|
|
41
|
-
});
|
|
42
|
-
it("reports the index of a non-integer byte", () => {
|
|
43
|
-
try {
|
|
44
|
-
decodeWorkerBinaryResponse({ type: "Buffer", data: [1, 1.5] });
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
expect(error).toBeInstanceOf(RestApiValidationError);
|
|
48
|
-
if (!(error instanceof RestApiValidationError)) {
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
expect(error.details.zodError.issues).toEqual([
|
|
52
|
-
expect.objectContaining({ path: ["data", 1] }),
|
|
53
|
-
]);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
throw new Error("Expected binary response validation to fail");
|
|
57
|
-
});
|
|
58
|
-
it("redacts malformed binary data from validation errors", () => {
|
|
59
|
-
const data = Array.from({ length: 4096 }, () => 0);
|
|
60
|
-
data[4095] = 256;
|
|
61
|
-
try {
|
|
62
|
-
decodeWorkerBinaryResponse({ type: "Buffer", data });
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
expect(error).toBeInstanceOf(RestApiValidationError);
|
|
66
|
-
if (!(error instanceof RestApiValidationError)) {
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
expect(error.details.data).toEqual({
|
|
70
|
-
dataType: "binary",
|
|
71
|
-
redacted: true,
|
|
72
|
-
});
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
throw new Error("Expected malformed binary response to fail");
|
|
76
|
-
});
|
|
77
|
-
it("rejects a string payload", () => {
|
|
78
|
-
expect(() => decodeWorkerBinaryResponse("not-binary")).toThrow(RestApiValidationError);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
//# sourceMappingURL=decode-worker-binary-response.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decode-worker-binary-response.test.js","sourceRoot":"","sources":["../../../src/integrations/base/decode-worker-binary-response.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAEhF,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,EAAE,CAAC,iEAAiE,EA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,KAAK,CAAC;YACd,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;gBACjC,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,GAAG,EAAE,CAAC,0BAA0B,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAC5D,sBAAsB,CACvB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { RestApiValidationError } from "../../errors.js";
|
|
4
|
-
import { decodeWorkerBinaryResponse } from "./decode-worker-binary-response.js";
|
|
5
|
-
|
|
6
|
-
describe("decodeWorkerBinaryResponse", () => {
|
|
7
|
-
it("copies a Uint8Array into a plain Uint8Array with the same bytes", () => {
|
|
8
|
-
const source = new Uint8Array([1, 2, 255]);
|
|
9
|
-
|
|
10
|
-
const result = decodeWorkerBinaryResponse(source);
|
|
11
|
-
|
|
12
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
13
|
-
expect(result.constructor).toBe(Uint8Array);
|
|
14
|
-
expect(Array.from(result)).toEqual([1, 2, 255]);
|
|
15
|
-
source[0] = 9;
|
|
16
|
-
expect(result[0]).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("converts worker Buffer JSON into a plain Uint8Array", () => {
|
|
20
|
-
const result = decodeWorkerBinaryResponse({
|
|
21
|
-
type: "Buffer",
|
|
22
|
-
data: [37, 80, 68, 70],
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
expect(result.constructor).toBe(Uint8Array);
|
|
26
|
-
expect(Array.from(result)).toEqual([37, 80, 68, 70]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("converts empty Buffer JSON into a zero-length Uint8Array", () => {
|
|
30
|
-
const result = decodeWorkerBinaryResponse({ type: "Buffer", data: [] });
|
|
31
|
-
|
|
32
|
-
expect(result).toBeInstanceOf(Uint8Array);
|
|
33
|
-
expect(result.byteLength).toBe(0);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("rejects a missing discriminant", () => {
|
|
37
|
-
expect(() => decodeWorkerBinaryResponse({ data: [1] })).toThrow(
|
|
38
|
-
RestApiValidationError,
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("rejects a non-Buffer discriminant", () => {
|
|
43
|
-
expect(() =>
|
|
44
|
-
decodeWorkerBinaryResponse({ type: "Array", data: [1] }),
|
|
45
|
-
).toThrow(RestApiValidationError);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("rejects a non-array data field", () => {
|
|
49
|
-
expect(() =>
|
|
50
|
-
decodeWorkerBinaryResponse({ type: "Buffer", data: "00ff" }),
|
|
51
|
-
).toThrow(RestApiValidationError);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("rejects a byte outside 0 through 255", () => {
|
|
55
|
-
expect(() =>
|
|
56
|
-
decodeWorkerBinaryResponse({ type: "Buffer", data: [256] }),
|
|
57
|
-
).toThrow(RestApiValidationError);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("rejects a negative byte", () => {
|
|
61
|
-
expect(() =>
|
|
62
|
-
decodeWorkerBinaryResponse({ type: "Buffer", data: [-1] }),
|
|
63
|
-
).toThrow(RestApiValidationError);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("reports the index of a non-integer byte", () => {
|
|
67
|
-
try {
|
|
68
|
-
decodeWorkerBinaryResponse({ type: "Buffer", data: [1, 1.5] });
|
|
69
|
-
} catch (error) {
|
|
70
|
-
expect(error).toBeInstanceOf(RestApiValidationError);
|
|
71
|
-
if (!(error instanceof RestApiValidationError)) {
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
expect(error.details.zodError.issues).toEqual([
|
|
75
|
-
expect.objectContaining({ path: ["data", 1] }),
|
|
76
|
-
]);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
throw new Error("Expected binary response validation to fail");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("redacts malformed binary data from validation errors", () => {
|
|
83
|
-
const data = Array.from({ length: 4096 }, () => 0);
|
|
84
|
-
data[4095] = 256;
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
decodeWorkerBinaryResponse({ type: "Buffer", data });
|
|
88
|
-
} catch (error) {
|
|
89
|
-
expect(error).toBeInstanceOf(RestApiValidationError);
|
|
90
|
-
if (!(error instanceof RestApiValidationError)) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
expect(error.details.data).toEqual({
|
|
94
|
-
dataType: "binary",
|
|
95
|
-
redacted: true,
|
|
96
|
-
});
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
throw new Error("Expected malformed binary response to fail");
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("rejects a string payload", () => {
|
|
103
|
-
expect(() => decodeWorkerBinaryResponse("not-binary")).toThrow(
|
|
104
|
-
RestApiValidationError,
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
REDACTED_BINARY_RESPONSE_DATA,
|
|
5
|
-
RestApiValidationError,
|
|
6
|
-
} from "../../errors.js";
|
|
7
|
-
|
|
8
|
-
export { REDACTED_BINARY_RESPONSE_DATA };
|
|
9
|
-
|
|
10
|
-
const workerBinaryResponseSchema = z.union([
|
|
11
|
-
z.instanceof(Uint8Array).transform((value) => new Uint8Array(value)),
|
|
12
|
-
z
|
|
13
|
-
.object({
|
|
14
|
-
data: z.unknown(),
|
|
15
|
-
type: z.literal("Buffer"),
|
|
16
|
-
})
|
|
17
|
-
.transform((value, context) => {
|
|
18
|
-
if (!Array.isArray(value.data)) {
|
|
19
|
-
context.addIssue({
|
|
20
|
-
code: z.ZodIssueCode.custom,
|
|
21
|
-
message: "data must be an array of bytes",
|
|
22
|
-
path: ["data"],
|
|
23
|
-
});
|
|
24
|
-
return z.NEVER;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const bytes = new Uint8Array(value.data.length);
|
|
28
|
-
for (let index = 0; index < value.data.length; index += 1) {
|
|
29
|
-
const item = value.data[index];
|
|
30
|
-
if (
|
|
31
|
-
typeof item !== "number" ||
|
|
32
|
-
!Number.isInteger(item) ||
|
|
33
|
-
item < 0 ||
|
|
34
|
-
item > 255
|
|
35
|
-
) {
|
|
36
|
-
context.addIssue({
|
|
37
|
-
code: z.ZodIssueCode.custom,
|
|
38
|
-
message: "byte must be an integer from 0 through 255",
|
|
39
|
-
path: ["data", index],
|
|
40
|
-
});
|
|
41
|
-
return z.NEVER;
|
|
42
|
-
}
|
|
43
|
-
bytes[index] = item;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return bytes;
|
|
47
|
-
}),
|
|
48
|
-
]);
|
|
49
|
-
|
|
50
|
-
export function decodeWorkerBinaryResponse(value: unknown): Uint8Array {
|
|
51
|
-
const result = workerBinaryResponseSchema.safeParse(value);
|
|
52
|
-
if (!result.success) {
|
|
53
|
-
throw new RestApiValidationError(
|
|
54
|
-
`Binary response is malformed: ${result.error.message}`,
|
|
55
|
-
{
|
|
56
|
-
data: REDACTED_BINARY_RESPONSE_DATA,
|
|
57
|
-
zodError: result.error,
|
|
58
|
-
},
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
return result.data;
|
|
62
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
## Non-JSON Responses
|
|
2
|
-
|
|
3
|
-
`apiRequest()` decodes responses as JSON by default. For endpoints that return non-JSON payloads, pass `responseType`:
|
|
4
|
-
|
|
5
|
-
- `"binary"` for PDFs and other byte payloads. The result is a `Uint8Array`
|
|
6
|
-
- `"text"` for XML, CSV, HTML, and other decoded strings
|
|
7
|
-
|
|
8
|
-
With `responseType: "text"` or `responseType: "binary"` the response schema may be omitted. Text returns the raw string typed `unknown`. Binary returns a `Uint8Array`:
|
|
9
|
-
|
|
10
|
-
```typescript
|
|
11
|
-
const xml = await ctx.integrations.legacyApi.apiRequest({
|
|
12
|
-
method: "GET",
|
|
13
|
-
path: "/report.xml",
|
|
14
|
-
responseType: "text",
|
|
15
|
-
});
|
|
16
|
-
// xml is the raw XML string (typed unknown)
|
|
17
|
-
|
|
18
|
-
const pdf = await ctx.integrations.legacyApi.apiRequest({
|
|
19
|
-
method: "GET",
|
|
20
|
-
path: "/file.pdf",
|
|
21
|
-
responseType: "binary",
|
|
22
|
-
});
|
|
23
|
-
// pdf is a Uint8Array
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
To validate after decoding, pass a schema that matches the decoded value:
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
const xml = await ctx.integrations.legacyApi.apiRequest(
|
|
30
|
-
{ method: "GET", path: "/report.xml", responseType: "text" },
|
|
31
|
-
{ response: z.string() },
|
|
32
|
-
);
|
|
33
|
-
// xml is typed string
|
|
34
|
-
|
|
35
|
-
const pdf = await ctx.integrations.legacyApi.apiRequest(
|
|
36
|
-
{ method: "GET", path: "/file.pdf", responseType: "binary" },
|
|
37
|
-
{ response: z.instanceof(Uint8Array) },
|
|
38
|
-
);
|
|
39
|
-
// pdf is typed Uint8Array
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Convert binary data to a JSON-safe representation before returning it from an SDK API:
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
return {
|
|
46
|
-
contentBase64: Buffer.from(pdf).toString("base64"),
|
|
47
|
-
filename: "file.pdf",
|
|
48
|
-
};
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
JSON responses (the default) always require a response schema. Omitting the schema is only allowed together with an explicit `responseType: "text"` or `responseType: "binary"`, so unvalidated JSON is not representable.
|