@zapier/zapier-sdk 0.33.0 → 0.33.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/CHANGELOG.md +12 -0
- package/dist/index.cjs +2 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +1 -0
- package/dist/types/sdk.d.ts +8 -0
- package/dist/types/sdk.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/api/auth.test.d.ts +0 -2
- package/dist/api/auth.test.d.ts.map +0 -1
- package/dist/api/auth.test.js +0 -220
- package/dist/api/client.test.d.ts +0 -2
- package/dist/api/client.test.d.ts.map +0 -1
- package/dist/api/client.test.js +0 -611
- package/dist/api/debug.test.d.ts +0 -2
- package/dist/api/debug.test.d.ts.map +0 -1
- package/dist/api/debug.test.js +0 -59
- package/dist/api/polling.test.d.ts +0 -2
- package/dist/api/polling.test.d.ts.map +0 -1
- package/dist/api/polling.test.js +0 -360
- package/dist/auth.test.d.ts +0 -2
- package/dist/auth.test.d.ts.map +0 -1
- package/dist/auth.test.js +0 -480
- package/dist/plugins/eventEmission/builders.test.d.ts +0 -2
- package/dist/plugins/eventEmission/builders.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/builders.test.js +0 -138
- package/dist/plugins/eventEmission/index.test.d.ts +0 -5
- package/dist/plugins/eventEmission/index.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/index.test.js +0 -712
- package/dist/plugins/eventEmission/transport.test.d.ts +0 -5
- package/dist/plugins/eventEmission/transport.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/transport.test.js +0 -164
- package/dist/plugins/fetch/index.test.d.ts +0 -2
- package/dist/plugins/fetch/index.test.d.ts.map +0 -1
- package/dist/plugins/fetch/index.test.js +0 -428
- package/dist/plugins/findFirstConnection/index.test.d.ts +0 -2
- package/dist/plugins/findFirstConnection/index.test.d.ts.map +0 -1
- package/dist/plugins/findFirstConnection/index.test.js +0 -177
- package/dist/plugins/findUniqueConnection/index.test.d.ts +0 -2
- package/dist/plugins/findUniqueConnection/index.test.d.ts.map +0 -1
- package/dist/plugins/findUniqueConnection/index.test.js +0 -159
- package/dist/plugins/getAction/index.test.d.ts +0 -2
- package/dist/plugins/getAction/index.test.d.ts.map +0 -1
- package/dist/plugins/getAction/index.test.js +0 -211
- package/dist/plugins/getApp/index.test.d.ts +0 -2
- package/dist/plugins/getApp/index.test.d.ts.map +0 -1
- package/dist/plugins/getApp/index.test.js +0 -157
- package/dist/plugins/getConnection/index.test.d.ts +0 -2
- package/dist/plugins/getConnection/index.test.d.ts.map +0 -1
- package/dist/plugins/getConnection/index.test.js +0 -124
- package/dist/plugins/getInputFieldsSchema/index.test.d.ts +0 -2
- package/dist/plugins/getInputFieldsSchema/index.test.d.ts.map +0 -1
- package/dist/plugins/getInputFieldsSchema/index.test.js +0 -291
- package/dist/plugins/listActions/index.test.d.ts +0 -2
- package/dist/plugins/listActions/index.test.d.ts.map +0 -1
- package/dist/plugins/listActions/index.test.js +0 -454
- package/dist/plugins/listApps/index.test.d.ts +0 -2
- package/dist/plugins/listApps/index.test.d.ts.map +0 -1
- package/dist/plugins/listApps/index.test.js +0 -124
- package/dist/plugins/listConnections/index.test.d.ts +0 -2
- package/dist/plugins/listConnections/index.test.d.ts.map +0 -1
- package/dist/plugins/listConnections/index.test.js +0 -920
- package/dist/plugins/listInputFieldChoices/index.test.d.ts +0 -2
- package/dist/plugins/listInputFieldChoices/index.test.d.ts.map +0 -1
- package/dist/plugins/listInputFieldChoices/index.test.js +0 -717
- package/dist/plugins/listInputFields/index.test.d.ts +0 -2
- package/dist/plugins/listInputFields/index.test.d.ts.map +0 -1
- package/dist/plugins/listInputFields/index.test.js +0 -359
- package/dist/plugins/manifest/index.test.d.ts +0 -2
- package/dist/plugins/manifest/index.test.d.ts.map +0 -1
- package/dist/plugins/manifest/index.test.js +0 -1179
- package/dist/plugins/request/index.test.d.ts +0 -2
- package/dist/plugins/request/index.test.d.ts.map +0 -1
- package/dist/plugins/request/index.test.js +0 -458
- package/dist/plugins/runAction/index.test.d.ts +0 -2
- package/dist/plugins/runAction/index.test.d.ts.map +0 -1
- package/dist/plugins/runAction/index.test.js +0 -350
- package/dist/resolvers/connectionId.test.d.ts +0 -2
- package/dist/resolvers/connectionId.test.d.ts.map +0 -1
- package/dist/resolvers/connectionId.test.js +0 -61
- package/dist/sdk.test.d.ts +0 -2
- package/dist/sdk.test.d.ts.map +0 -1
- package/dist/sdk.test.js +0 -260
- package/dist/types/domain.test.d.ts +0 -2
- package/dist/types/domain.test.d.ts.map +0 -1
- package/dist/types/domain.test.js +0 -39
- package/dist/utils/array-utils.test.d.ts +0 -2
- package/dist/utils/array-utils.test.d.ts.map +0 -1
- package/dist/utils/array-utils.test.js +0 -107
- package/dist/utils/batch-utils.test.d.ts +0 -2
- package/dist/utils/batch-utils.test.d.ts.map +0 -1
- package/dist/utils/batch-utils.test.js +0 -476
- package/dist/utils/domain-utils.test.d.ts +0 -2
- package/dist/utils/domain-utils.test.d.ts.map +0 -1
- package/dist/utils/domain-utils.test.js +0 -346
- package/dist/utils/file-utils.test.d.ts +0 -2
- package/dist/utils/file-utils.test.d.ts.map +0 -1
- package/dist/utils/file-utils.test.js +0 -51
- package/dist/utils/function-utils.test.d.ts +0 -2
- package/dist/utils/function-utils.test.d.ts.map +0 -1
- package/dist/utils/function-utils.test.js +0 -188
- package/dist/utils/id-utils.test.d.ts +0 -2
- package/dist/utils/id-utils.test.d.ts.map +0 -1
- package/dist/utils/id-utils.test.js +0 -22
- package/dist/utils/pagination-utils.test.d.ts +0 -17
- package/dist/utils/pagination-utils.test.d.ts.map +0 -1
- package/dist/utils/pagination-utils.test.js +0 -461
- package/dist/utils/retry-utils.test.d.ts +0 -2
- package/dist/utils/retry-utils.test.d.ts.map +0 -1
- package/dist/utils/retry-utils.test.js +0 -90
- package/dist/utils/string-utils.test.d.ts +0 -2
- package/dist/utils/string-utils.test.d.ts.map +0 -1
- package/dist/utils/string-utils.test.js +0 -59
- package/dist/utils/telemetry-context.test.d.ts +0 -2
- package/dist/utils/telemetry-context.test.d.ts.map +0 -1
- package/dist/utils/telemetry-context.test.js +0 -154
- package/dist/utils/telemetry-utils.test.d.ts +0 -2
- package/dist/utils/telemetry-utils.test.d.ts.map +0 -1
- package/dist/utils/telemetry-utils.test.js +0 -155
- package/dist/utils/url-utils.test.d.ts +0 -2
- package/dist/utils/url-utils.test.d.ts.map +0 -1
- package/dist/utils/url-utils.test.js +0 -103
- package/dist/utils/validation.test.d.ts +0 -2
- package/dist/utils/validation.test.d.ts.map +0 -1
- package/dist/utils/validation.test.js +0 -44
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ZapierValidationError, ZapierAppNotFoundError, } from "../../types/errors";
|
|
3
|
-
import { getAppPlugin } from "./index";
|
|
4
|
-
import { createSdk } from "../../sdk";
|
|
5
|
-
import { apiPlugin } from "../api/index";
|
|
6
|
-
import { listAppsPlugin } from "../listApps";
|
|
7
|
-
import { manifestPlugin } from "../manifest";
|
|
8
|
-
import { eventEmissionPlugin } from "../eventEmission";
|
|
9
|
-
function createTestSdk() {
|
|
10
|
-
return createSdk()
|
|
11
|
-
.addPlugin(() => ({
|
|
12
|
-
context: {
|
|
13
|
-
options: {},
|
|
14
|
-
},
|
|
15
|
-
}))
|
|
16
|
-
.addPlugin(apiPlugin, { fetch: global.fetch })
|
|
17
|
-
.addPlugin(eventEmissionPlugin)
|
|
18
|
-
.addPlugin(manifestPlugin)
|
|
19
|
-
.addPlugin(listAppsPlugin)
|
|
20
|
-
.addPlugin(getAppPlugin);
|
|
21
|
-
}
|
|
22
|
-
describe("getApp plugin", () => {
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
vi.clearAllMocks();
|
|
25
|
-
});
|
|
26
|
-
describe("schema validation", () => {
|
|
27
|
-
it("should throw validation error for missing appKey", async () => {
|
|
28
|
-
const sdk = createTestSdk();
|
|
29
|
-
await expect(sdk.getApp({})).rejects.toThrow(ZapierValidationError);
|
|
30
|
-
});
|
|
31
|
-
it("should throw validation error for invalid appKey type", async () => {
|
|
32
|
-
const sdk = createTestSdk();
|
|
33
|
-
await expect(sdk.getApp({
|
|
34
|
-
appKey: 123,
|
|
35
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
36
|
-
});
|
|
37
|
-
it("should throw validation error for empty string appKey", async () => {
|
|
38
|
-
const sdk = createTestSdk();
|
|
39
|
-
await expect(sdk.getApp({
|
|
40
|
-
appKey: "",
|
|
41
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
42
|
-
});
|
|
43
|
-
it("should pass validation with valid appKey", async () => {
|
|
44
|
-
const sdk = createTestSdk();
|
|
45
|
-
const context = sdk.getContext();
|
|
46
|
-
// Mock the API client to handle both resolveAppKeys and listApps calls
|
|
47
|
-
context.api.get = vi
|
|
48
|
-
.fn()
|
|
49
|
-
// First call: resolveAppKeys calls listAppsForSlugsPage which expects raw API format
|
|
50
|
-
.mockResolvedValueOnce({
|
|
51
|
-
results: [
|
|
52
|
-
{
|
|
53
|
-
id: "SlackCLIAPI@1.0.0",
|
|
54
|
-
name: "Slack",
|
|
55
|
-
description: "Team communication",
|
|
56
|
-
primary_color: "#4A154B",
|
|
57
|
-
categories: ["communication"],
|
|
58
|
-
slug: "slack",
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
next: null,
|
|
62
|
-
})
|
|
63
|
-
// Second call: listApps goes through handler which returns transformed format
|
|
64
|
-
.mockResolvedValueOnce({
|
|
65
|
-
data: [
|
|
66
|
-
{
|
|
67
|
-
title: "Slack",
|
|
68
|
-
key: "SlackCLIAPI",
|
|
69
|
-
implementation_id: "SlackCLIAPI@1.0.0",
|
|
70
|
-
description: "Team communication",
|
|
71
|
-
primary_color: "#4A154B",
|
|
72
|
-
categories: ["communication"],
|
|
73
|
-
slug: "slack",
|
|
74
|
-
version: "1.0.0",
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
nextCursor: undefined,
|
|
78
|
-
});
|
|
79
|
-
const result = await sdk.getApp({
|
|
80
|
-
appKey: "slack",
|
|
81
|
-
});
|
|
82
|
-
expect(result.data.title).toBe("Slack");
|
|
83
|
-
expect(result.data.key).toBe("SlackCLIAPI");
|
|
84
|
-
expect(result.data.implementation_id).toBe("SlackCLIAPI@1.0.0");
|
|
85
|
-
expect(result.data.version).toBe("1.0.0");
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe("error handling", () => {
|
|
89
|
-
it("should throw ZapierAppNotFoundError when app does not exist", async () => {
|
|
90
|
-
const sdk = createTestSdk();
|
|
91
|
-
const context = sdk.getContext();
|
|
92
|
-
// Mock API to return empty results for both potential calls
|
|
93
|
-
context.api.get = vi
|
|
94
|
-
.fn()
|
|
95
|
-
// First call: resolveAppKeys may call to resolve slug
|
|
96
|
-
.mockResolvedValueOnce({
|
|
97
|
-
results: [],
|
|
98
|
-
next: null,
|
|
99
|
-
})
|
|
100
|
-
// Second call: listApps main API call (returns transformed format)
|
|
101
|
-
.mockResolvedValueOnce({
|
|
102
|
-
data: [],
|
|
103
|
-
nextCursor: undefined,
|
|
104
|
-
});
|
|
105
|
-
await expect(sdk.getApp({
|
|
106
|
-
appKey: "nonexistent-app",
|
|
107
|
-
})).rejects.toThrow(ZapierAppNotFoundError);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe("data mapping", () => {
|
|
111
|
-
it("should return essential app properties", async () => {
|
|
112
|
-
const sdk = createTestSdk();
|
|
113
|
-
const context = sdk.getContext();
|
|
114
|
-
// Mock the API client to handle both resolveAppKeys and listApps calls
|
|
115
|
-
context.api.get = vi
|
|
116
|
-
.fn()
|
|
117
|
-
// First call: resolveAppKeys calls listAppsForSlugsPage which expects raw API format
|
|
118
|
-
.mockResolvedValueOnce({
|
|
119
|
-
results: [
|
|
120
|
-
{
|
|
121
|
-
id: "TestCLIAPI@1.0.0",
|
|
122
|
-
name: "Test App",
|
|
123
|
-
description: "Test description",
|
|
124
|
-
primary_color: "#FF0000",
|
|
125
|
-
categories: ["testing"],
|
|
126
|
-
slug: "test",
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
next: null,
|
|
130
|
-
})
|
|
131
|
-
// Second call: listApps goes through handler which returns transformed format
|
|
132
|
-
.mockResolvedValueOnce({
|
|
133
|
-
data: [
|
|
134
|
-
{
|
|
135
|
-
title: "Test App",
|
|
136
|
-
key: "TestCLIAPI",
|
|
137
|
-
implementation_id: "TestCLIAPI@1.0.0",
|
|
138
|
-
description: "Test description",
|
|
139
|
-
primary_color: "#FF0000",
|
|
140
|
-
categories: ["testing"],
|
|
141
|
-
slug: "test",
|
|
142
|
-
version: "1.0.0",
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
nextCursor: undefined,
|
|
146
|
-
});
|
|
147
|
-
const result = await sdk.getApp({
|
|
148
|
-
appKey: "test",
|
|
149
|
-
});
|
|
150
|
-
expect(result.data.title).toBeDefined();
|
|
151
|
-
expect(result.data.key).toBeDefined();
|
|
152
|
-
expect(result.data.implementation_id).toBeDefined();
|
|
153
|
-
expect(result.data.title).toBe("Test App");
|
|
154
|
-
expect(result.data.key).toBe("TestCLIAPI");
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/getConnection/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ZapierValidationError } from "../../types/errors";
|
|
3
|
-
import { getConnectionPlugin } from "./index";
|
|
4
|
-
import { createSdk } from "../../sdk";
|
|
5
|
-
import { eventEmissionPlugin } from "../eventEmission";
|
|
6
|
-
const mockConnectionItem = {
|
|
7
|
-
id: "123",
|
|
8
|
-
date: "2021-01-01",
|
|
9
|
-
account_id: "456",
|
|
10
|
-
implementation_id: "SlackCLIAPI@1.21.1",
|
|
11
|
-
is_invite_only: false,
|
|
12
|
-
is_private: false,
|
|
13
|
-
shared_with_all: false,
|
|
14
|
-
is_expired: "false",
|
|
15
|
-
expired_at: null,
|
|
16
|
-
label: "My Slack Workspace",
|
|
17
|
-
title: "My Slack Workspace",
|
|
18
|
-
app_key: "SlackCLIAPI",
|
|
19
|
-
app_version: "1.21.1",
|
|
20
|
-
};
|
|
21
|
-
describe("getConnection plugin", () => {
|
|
22
|
-
let mockApiClient;
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
vi.clearAllMocks();
|
|
25
|
-
mockApiClient = {
|
|
26
|
-
get: vi.fn().mockResolvedValue({ data: mockConnectionItem }),
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
const apiPlugin = () => ({
|
|
30
|
-
context: {
|
|
31
|
-
api: mockApiClient,
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
function createTestSdk() {
|
|
35
|
-
return createSdk()
|
|
36
|
-
.addPlugin(() => ({
|
|
37
|
-
context: {
|
|
38
|
-
options: {},
|
|
39
|
-
},
|
|
40
|
-
}))
|
|
41
|
-
.addPlugin(apiPlugin)
|
|
42
|
-
.addPlugin(eventEmissionPlugin)
|
|
43
|
-
.addPlugin(getConnectionPlugin);
|
|
44
|
-
}
|
|
45
|
-
describe("input validation", () => {
|
|
46
|
-
it("should throw validation error for missing connectionId", async () => {
|
|
47
|
-
const sdk = createTestSdk();
|
|
48
|
-
await expect(sdk.getConnection({})).rejects.toThrow("connectionId is required");
|
|
49
|
-
});
|
|
50
|
-
it("should throw validation error for invalid connectionId type", async () => {
|
|
51
|
-
const sdk = createTestSdk();
|
|
52
|
-
await expect(sdk.getConnection({
|
|
53
|
-
connectionId: true,
|
|
54
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
55
|
-
});
|
|
56
|
-
it("should accept valid connectionId", async () => {
|
|
57
|
-
const sdk = createTestSdk();
|
|
58
|
-
const result = await sdk.getConnection({
|
|
59
|
-
connectionId: "123",
|
|
60
|
-
});
|
|
61
|
-
expect(result.data).toBeDefined();
|
|
62
|
-
expect(result.data.id).toBe("123");
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe("SDK API endpoint routing", () => {
|
|
66
|
-
it("should call the correct SDK API endpoint with path params", async () => {
|
|
67
|
-
const sdk = createTestSdk();
|
|
68
|
-
await sdk.getConnection({ connectionId: "123" });
|
|
69
|
-
expect(mockApiClient.get).toHaveBeenCalledWith("/api/v0/connections/123");
|
|
70
|
-
});
|
|
71
|
-
it("should URI encode string connectionId in path", async () => {
|
|
72
|
-
const sdk = createTestSdk();
|
|
73
|
-
await sdk.getConnection({ connectionId: "test/with spaces" });
|
|
74
|
-
expect(mockApiClient.get).toHaveBeenCalledWith("/api/v0/connections/test%2Fwith%20spaces");
|
|
75
|
-
});
|
|
76
|
-
it("should return data from API response", async () => {
|
|
77
|
-
const sdk = createTestSdk();
|
|
78
|
-
const result = await sdk.getConnection({ connectionId: "123" });
|
|
79
|
-
expect(result.data).toEqual(mockConnectionItem);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe("deprecated authenticationId support", () => {
|
|
83
|
-
it("should accept deprecated authenticationId parameter", async () => {
|
|
84
|
-
const sdk = createTestSdk();
|
|
85
|
-
const result = await sdk.getConnection({
|
|
86
|
-
authenticationId: "123",
|
|
87
|
-
});
|
|
88
|
-
expect(result.data).toBeDefined();
|
|
89
|
-
expect(mockApiClient.get).toHaveBeenCalledWith("/api/v0/connections/123");
|
|
90
|
-
});
|
|
91
|
-
it("should prefer connectionId over authenticationId when both provided", async () => {
|
|
92
|
-
const sdk = createTestSdk();
|
|
93
|
-
await sdk.getConnection({
|
|
94
|
-
connectionId: "new-id",
|
|
95
|
-
authenticationId: "old-id",
|
|
96
|
-
});
|
|
97
|
-
expect(mockApiClient.get).toHaveBeenCalledWith("/api/v0/connections/new-id");
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe("error propagation", () => {
|
|
101
|
-
it("should propagate errors from API client", async () => {
|
|
102
|
-
mockApiClient.get = vi.fn().mockRejectedValue(new Error("API error"));
|
|
103
|
-
const sdk = createTestSdk();
|
|
104
|
-
await expect(sdk.getConnection({ connectionId: "123" })).rejects.toThrow("API error");
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe("plugin metadata", () => {
|
|
108
|
-
it("should provide metadata in SDK context", () => {
|
|
109
|
-
const sdk = createTestSdk();
|
|
110
|
-
const context = sdk.getContext();
|
|
111
|
-
expect(context.meta.getConnection).toBeDefined();
|
|
112
|
-
expect(context.meta.getConnection.inputSchema).toBeDefined();
|
|
113
|
-
expect(context.meta.getConnection.outputSchema).toBeDefined();
|
|
114
|
-
expect(context.meta.getConnection.type).toBe("item");
|
|
115
|
-
expect(context.meta.getConnection.itemType).toBe("Connection");
|
|
116
|
-
});
|
|
117
|
-
it("should include resolvers in metadata", () => {
|
|
118
|
-
const sdk = createTestSdk();
|
|
119
|
-
const context = sdk.getContext();
|
|
120
|
-
expect(context.meta.getConnection.resolvers).toBeDefined();
|
|
121
|
-
expect(context.meta.getConnection.resolvers.connectionId).toBeDefined();
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/getInputFieldsSchema/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ZapierValidationError, ZapierConfigurationError, ZapierApiError, } from "../../types/errors";
|
|
3
|
-
import { getInputFieldsSchemaPlugin } from "./index";
|
|
4
|
-
import { getActionPlugin } from "../getAction";
|
|
5
|
-
import { getAppPlugin } from "../getApp";
|
|
6
|
-
import { listActionsPlugin } from "../listActions";
|
|
7
|
-
import { listAppsPlugin } from "../listApps";
|
|
8
|
-
import { createSdk } from "../../sdk";
|
|
9
|
-
import { eventEmissionPlugin } from "../eventEmission";
|
|
10
|
-
const mockSchema = {
|
|
11
|
-
type: "object",
|
|
12
|
-
properties: {
|
|
13
|
-
message: {
|
|
14
|
-
type: "string",
|
|
15
|
-
title: "Message",
|
|
16
|
-
description: "The message to send",
|
|
17
|
-
},
|
|
18
|
-
channel: {
|
|
19
|
-
type: "string",
|
|
20
|
-
title: "Channel",
|
|
21
|
-
description: "The channel to send to",
|
|
22
|
-
},
|
|
23
|
-
tags: {
|
|
24
|
-
type: "array",
|
|
25
|
-
items: {
|
|
26
|
-
type: "string",
|
|
27
|
-
},
|
|
28
|
-
title: "Tags",
|
|
29
|
-
description: "List of tags",
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
required: ["message", "channel"],
|
|
33
|
-
};
|
|
34
|
-
const mockNeedsResponse = {
|
|
35
|
-
success: true,
|
|
36
|
-
needs: [],
|
|
37
|
-
schema: mockSchema,
|
|
38
|
-
};
|
|
39
|
-
const mockActionsResponse = {
|
|
40
|
-
results: [
|
|
41
|
-
{
|
|
42
|
-
slug: "slack",
|
|
43
|
-
selected_api: "slack",
|
|
44
|
-
actions: [
|
|
45
|
-
{
|
|
46
|
-
key: "send_message",
|
|
47
|
-
name: "Send Message",
|
|
48
|
-
description: "Send a message to a channel",
|
|
49
|
-
type_of: "write",
|
|
50
|
-
type: "write",
|
|
51
|
-
id: "core:12345",
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
meta: {
|
|
57
|
-
next_cursor: null,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
describe("getInputFieldsSchema plugin", () => {
|
|
61
|
-
let mockApiClient;
|
|
62
|
-
let mockGetVersionedImplementationId;
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
vi.clearAllMocks();
|
|
65
|
-
mockApiClient = {
|
|
66
|
-
get: vi.fn().mockResolvedValue(mockActionsResponse),
|
|
67
|
-
post: vi.fn().mockResolvedValue(mockNeedsResponse),
|
|
68
|
-
};
|
|
69
|
-
mockGetVersionedImplementationId = vi
|
|
70
|
-
.fn()
|
|
71
|
-
.mockResolvedValue("SlackCLIAPI@1.21.1");
|
|
72
|
-
});
|
|
73
|
-
function createTestSdk() {
|
|
74
|
-
return createSdk({}, {}, {
|
|
75
|
-
api: mockApiClient,
|
|
76
|
-
meta: {},
|
|
77
|
-
options: {},
|
|
78
|
-
getVersionedImplementationId: mockGetVersionedImplementationId,
|
|
79
|
-
})
|
|
80
|
-
.addPlugin(eventEmissionPlugin)
|
|
81
|
-
.addPlugin(listAppsPlugin)
|
|
82
|
-
.addPlugin(listActionsPlugin)
|
|
83
|
-
.addPlugin(getAppPlugin)
|
|
84
|
-
.addPlugin(getActionPlugin)
|
|
85
|
-
.addPlugin(getInputFieldsSchemaPlugin);
|
|
86
|
-
}
|
|
87
|
-
describe("schema validation", () => {
|
|
88
|
-
it("should throw validation error for missing required fields", async () => {
|
|
89
|
-
const sdk = createTestSdk();
|
|
90
|
-
await expect(sdk.getInputFieldsSchema({
|
|
91
|
-
// Missing required fields
|
|
92
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
93
|
-
});
|
|
94
|
-
it("should throw validation error for invalid field types", async () => {
|
|
95
|
-
const sdk = createTestSdk();
|
|
96
|
-
await expect(sdk.getInputFieldsSchema({
|
|
97
|
-
appKey: 123,
|
|
98
|
-
actionType: "write",
|
|
99
|
-
actionKey: "send_message",
|
|
100
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
101
|
-
});
|
|
102
|
-
it("should pass validation with all required fields", async () => {
|
|
103
|
-
const sdk = createTestSdk();
|
|
104
|
-
const result = await sdk.getInputFieldsSchema({
|
|
105
|
-
appKey: "slack",
|
|
106
|
-
actionType: "write",
|
|
107
|
-
actionKey: "send_message",
|
|
108
|
-
});
|
|
109
|
-
expect(result.data).toBeDefined();
|
|
110
|
-
});
|
|
111
|
-
it("should pass validation with optional fields", async () => {
|
|
112
|
-
const sdk = createTestSdk();
|
|
113
|
-
const result = await sdk.getInputFieldsSchema({
|
|
114
|
-
appKey: "slack",
|
|
115
|
-
actionType: "write",
|
|
116
|
-
actionKey: "send_message",
|
|
117
|
-
authenticationId: 123,
|
|
118
|
-
inputs: { channel: "#general" },
|
|
119
|
-
});
|
|
120
|
-
expect(result.data).toBeDefined();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe("API integration", () => {
|
|
124
|
-
it("should call the correct API endpoint", async () => {
|
|
125
|
-
const sdk = createTestSdk();
|
|
126
|
-
await sdk.getInputFieldsSchema({
|
|
127
|
-
appKey: "slack",
|
|
128
|
-
actionType: "write",
|
|
129
|
-
actionKey: "send_message",
|
|
130
|
-
});
|
|
131
|
-
expect(mockApiClient.post).toHaveBeenCalledWith("/zapier/api/v4/implementations/needs/", {
|
|
132
|
-
selected_api: "SlackCLIAPI@1.21.1",
|
|
133
|
-
action: "send_message",
|
|
134
|
-
type_of: "write",
|
|
135
|
-
params: {},
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
it("should include authentication_id when provided", async () => {
|
|
139
|
-
const sdk = createTestSdk();
|
|
140
|
-
await sdk.getInputFieldsSchema({
|
|
141
|
-
appKey: "slack",
|
|
142
|
-
actionType: "write",
|
|
143
|
-
actionKey: "send_message",
|
|
144
|
-
authenticationId: 123,
|
|
145
|
-
});
|
|
146
|
-
expect(mockApiClient.post).toHaveBeenCalledWith("/zapier/api/v4/implementations/needs/", {
|
|
147
|
-
selected_api: "SlackCLIAPI@1.21.1",
|
|
148
|
-
action: "send_message",
|
|
149
|
-
type_of: "write",
|
|
150
|
-
params: {},
|
|
151
|
-
authentication_id: 123,
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
it("should exclude authentication_id when null", async () => {
|
|
155
|
-
const sdk = createTestSdk();
|
|
156
|
-
await sdk.getInputFieldsSchema({
|
|
157
|
-
appKey: "slack",
|
|
158
|
-
actionType: "write",
|
|
159
|
-
actionKey: "send_message",
|
|
160
|
-
authenticationId: null,
|
|
161
|
-
});
|
|
162
|
-
expect(mockApiClient.post).toHaveBeenCalledWith("/zapier/api/v4/implementations/needs/", {
|
|
163
|
-
selected_api: "SlackCLIAPI@1.21.1",
|
|
164
|
-
action: "send_message",
|
|
165
|
-
type_of: "write",
|
|
166
|
-
params: {},
|
|
167
|
-
// No authentication_id
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
it("should include inputs when provided", async () => {
|
|
171
|
-
const sdk = createTestSdk();
|
|
172
|
-
const inputs = { channel: "#general", message: "test" };
|
|
173
|
-
await sdk.getInputFieldsSchema({
|
|
174
|
-
appKey: "slack",
|
|
175
|
-
actionType: "write",
|
|
176
|
-
actionKey: "send_message",
|
|
177
|
-
inputs,
|
|
178
|
-
});
|
|
179
|
-
expect(mockApiClient.post).toHaveBeenCalledWith("/zapier/api/v4/implementations/needs/", {
|
|
180
|
-
selected_api: "SlackCLIAPI@1.21.1",
|
|
181
|
-
action: "send_message",
|
|
182
|
-
type_of: "write",
|
|
183
|
-
params: inputs,
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
describe("data return", () => {
|
|
188
|
-
it("should return the schema object from the API response", async () => {
|
|
189
|
-
const sdk = createTestSdk();
|
|
190
|
-
const result = await sdk.getInputFieldsSchema({
|
|
191
|
-
appKey: "slack",
|
|
192
|
-
actionType: "write",
|
|
193
|
-
actionKey: "send_message",
|
|
194
|
-
});
|
|
195
|
-
expect(result.data).toEqual(mockSchema);
|
|
196
|
-
});
|
|
197
|
-
it("should return empty object when schema is not present", async () => {
|
|
198
|
-
mockApiClient.post = vi.fn().mockResolvedValue({
|
|
199
|
-
success: true,
|
|
200
|
-
needs: [],
|
|
201
|
-
// No schema field
|
|
202
|
-
});
|
|
203
|
-
const sdk = createTestSdk();
|
|
204
|
-
const result = await sdk.getInputFieldsSchema({
|
|
205
|
-
appKey: "slack",
|
|
206
|
-
actionType: "write",
|
|
207
|
-
actionKey: "send_message",
|
|
208
|
-
});
|
|
209
|
-
expect(result.data).toEqual({});
|
|
210
|
-
});
|
|
211
|
-
it("should handle complex schema structures", async () => {
|
|
212
|
-
const complexSchema = {
|
|
213
|
-
type: "object",
|
|
214
|
-
properties: {
|
|
215
|
-
user: {
|
|
216
|
-
type: "object",
|
|
217
|
-
properties: {
|
|
218
|
-
name: { type: "string" },
|
|
219
|
-
age: { type: "number" },
|
|
220
|
-
},
|
|
221
|
-
required: ["name"],
|
|
222
|
-
},
|
|
223
|
-
tags: {
|
|
224
|
-
type: "array",
|
|
225
|
-
items: { type: "string" },
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
required: ["user"],
|
|
229
|
-
};
|
|
230
|
-
mockApiClient.post = vi.fn().mockResolvedValue({
|
|
231
|
-
success: true,
|
|
232
|
-
needs: [],
|
|
233
|
-
schema: complexSchema,
|
|
234
|
-
});
|
|
235
|
-
const sdk = createTestSdk();
|
|
236
|
-
const result = await sdk.getInputFieldsSchema({
|
|
237
|
-
appKey: "slack",
|
|
238
|
-
actionType: "write",
|
|
239
|
-
actionKey: "send_message",
|
|
240
|
-
});
|
|
241
|
-
expect(result.data).toEqual(complexSchema);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
describe("error handling", () => {
|
|
245
|
-
it("should throw ZapierConfigurationError when app has no current_implementation_id", async () => {
|
|
246
|
-
mockGetVersionedImplementationId.mockResolvedValue(null);
|
|
247
|
-
const sdk = createTestSdk();
|
|
248
|
-
await expect(sdk.getInputFieldsSchema({
|
|
249
|
-
appKey: "invalid",
|
|
250
|
-
actionType: "write",
|
|
251
|
-
actionKey: "send_message",
|
|
252
|
-
})).rejects.toThrow(ZapierConfigurationError);
|
|
253
|
-
});
|
|
254
|
-
it("should throw ZapierApiError when API response indicates failure", async () => {
|
|
255
|
-
mockApiClient.post = vi.fn().mockResolvedValue({
|
|
256
|
-
success: false,
|
|
257
|
-
errors: ["Authentication failed", "Invalid credentials"],
|
|
258
|
-
});
|
|
259
|
-
const sdk = createTestSdk();
|
|
260
|
-
await expect(sdk.getInputFieldsSchema({
|
|
261
|
-
appKey: "slack",
|
|
262
|
-
actionType: "write",
|
|
263
|
-
actionKey: "send_message",
|
|
264
|
-
})).rejects.toThrow(ZapierApiError);
|
|
265
|
-
await expect(sdk.getInputFieldsSchema({
|
|
266
|
-
appKey: "slack",
|
|
267
|
-
actionType: "write",
|
|
268
|
-
actionKey: "send_message",
|
|
269
|
-
})).rejects.toThrow("Failed to get input fields: Authentication failed, Invalid credentials");
|
|
270
|
-
});
|
|
271
|
-
it("should handle API errors gracefully", async () => {
|
|
272
|
-
mockApiClient.post = vi
|
|
273
|
-
.fn()
|
|
274
|
-
.mockRejectedValue(new Error("Network error"));
|
|
275
|
-
const sdk = createTestSdk();
|
|
276
|
-
await expect(sdk.getInputFieldsSchema({
|
|
277
|
-
appKey: "slack",
|
|
278
|
-
actionType: "write",
|
|
279
|
-
actionKey: "send_message",
|
|
280
|
-
})).rejects.toThrow("Network error");
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
describe("context and metadata", () => {
|
|
284
|
-
it("should provide context with meta information", () => {
|
|
285
|
-
const sdk = createTestSdk();
|
|
286
|
-
const context = sdk.getContext();
|
|
287
|
-
expect(context.meta.getInputFieldsSchema).toBeDefined();
|
|
288
|
-
expect(context.meta.getInputFieldsSchema.inputSchema).toBeDefined();
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/listActions/index.test.ts"],"names":[],"mappings":""}
|