@zapier/zapier-sdk 0.13.9 → 0.15.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/CHANGELOG.md +13 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +45 -22
- package/dist/index.cjs +210 -123
- package/dist/index.mjs +210 -123
- package/dist/plugins/getAuthentication/index.js +1 -1
- package/dist/plugins/getAuthentication/index.test.js +1 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +1 -1
- package/dist/plugins/listActions/index.js +1 -1
- package/dist/plugins/listActions/index.test.js +1 -1
- package/dist/plugins/listApps/index.js +2 -2
- package/dist/plugins/listApps/index.test.js +1 -1
- package/dist/plugins/listAuthentications/index.js +1 -1
- package/dist/plugins/listAuthentications/index.test.js +13 -13
- package/dist/plugins/listInputFieldChoices/index.d.ts +3 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +42 -21
- package/dist/plugins/listInputFieldChoices/index.test.js +188 -11
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +11 -16
- package/dist/plugins/listInputFields/index.test.js +8 -6
- package/dist/plugins/manifest/index.js +2 -2
- package/dist/plugins/manifest/index.test.js +3 -3
- package/dist/plugins/runAction/index.js +2 -2
- package/dist/plugins/runAction/index.test.js +4 -4
- package/dist/sdk.test.js +1 -1
- package/dist/services/implementations.d.ts +63 -0
- package/dist/services/implementations.d.ts.map +1 -0
- package/dist/services/implementations.js +79 -0
- package/package.json +1 -1
|
@@ -62,7 +62,7 @@ export async function getPreferredManifestEntryKey({ appKey, api, }) {
|
|
|
62
62
|
if (locator.implementationName) {
|
|
63
63
|
try {
|
|
64
64
|
// API call to get app metadata by implementation name using selected_apis parameter
|
|
65
|
-
const implementationsEnvelope = await api.get(`/api/v4/implementations-meta/lookup/`, {
|
|
65
|
+
const implementationsEnvelope = await api.get(`/zapier/api/v4/implementations-meta/lookup/`, {
|
|
66
66
|
searchParams: {
|
|
67
67
|
selected_apis: locator.implementationName,
|
|
68
68
|
},
|
|
@@ -88,7 +88,7 @@ async function listAppsForSlugsPage({ slugs, cursor, api, }) {
|
|
|
88
88
|
if (cursor) {
|
|
89
89
|
searchParams.offset = cursor;
|
|
90
90
|
}
|
|
91
|
-
const implementationsEnvelope = await api.get("/api/v4/implementations-meta/lookup/", {
|
|
91
|
+
const implementationsEnvelope = await api.get("/zapier/api/v4/implementations-meta/lookup/", {
|
|
92
92
|
searchParams,
|
|
93
93
|
});
|
|
94
94
|
return {
|
|
@@ -32,7 +32,7 @@ describe("manifestPlugin", () => {
|
|
|
32
32
|
vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
33
33
|
mockApiClient = {
|
|
34
34
|
get: vi.fn().mockImplementation((url, options) => {
|
|
35
|
-
if (url === "/api/v4/implementations/") {
|
|
35
|
+
if (url === "/zapier/api/v4/implementations/") {
|
|
36
36
|
// Mock for manifest entries (versioned)
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
count: 1,
|
|
@@ -87,7 +87,7 @@ describe("manifestPlugin", () => {
|
|
|
87
87
|
],
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
else if (url === "/api/v4/implementations-meta/lookup/") {
|
|
90
|
+
else if (url === "/zapier/api/v4/implementations-meta/lookup/") {
|
|
91
91
|
// Mock for implementations-meta/lookup fallback
|
|
92
92
|
const searchParams = options?.searchParams || {};
|
|
93
93
|
// Check if we're looking for a nonexistent app
|
|
@@ -591,7 +591,7 @@ describe("readManifestFromFile", () => {
|
|
|
591
591
|
api: mockApi,
|
|
592
592
|
});
|
|
593
593
|
expect(result).toBe("slack");
|
|
594
|
-
expect(mockApi.get).toHaveBeenCalledWith("/api/v4/implementations-meta/lookup/", {
|
|
594
|
+
expect(mockApi.get).toHaveBeenCalledWith("/zapier/api/v4/implementations-meta/lookup/", {
|
|
595
595
|
searchParams: { selected_apis: "SlackCLIAPI" },
|
|
596
596
|
});
|
|
597
597
|
});
|
|
@@ -25,10 +25,10 @@ async function executeAction(actionOptions) {
|
|
|
25
25
|
const runRequest = {
|
|
26
26
|
data: runRequestData,
|
|
27
27
|
};
|
|
28
|
-
const runData = await api.post("/api/actions/v1/runs", runRequest);
|
|
28
|
+
const runData = await api.post("/zapier/api/actions/v1/runs", runRequest);
|
|
29
29
|
const runId = runData.data.id;
|
|
30
30
|
// Step 2: Poll GET /actions/v1/runs/{run_id} for results
|
|
31
|
-
return await api.poll(`/api/actions/v1/runs/${runId}`, {
|
|
31
|
+
return await api.poll(`/zapier/api/actions/v1/runs/${runId}`, {
|
|
32
32
|
successStatus: 200,
|
|
33
33
|
pendingStatus: 202,
|
|
34
34
|
resultExtractor: (result) => result.data,
|
|
@@ -125,7 +125,7 @@ describe("runAction plugin", () => {
|
|
|
125
125
|
inputs: { message: "Hello", channel: "#general" },
|
|
126
126
|
authenticationId: 12345,
|
|
127
127
|
});
|
|
128
|
-
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", {
|
|
128
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/zapier/api/actions/v1/runs", {
|
|
129
129
|
data: {
|
|
130
130
|
selected_api: "SlackCLIAPI@1.21.1",
|
|
131
131
|
action_key: "send_message",
|
|
@@ -134,7 +134,7 @@ describe("runAction plugin", () => {
|
|
|
134
134
|
authentication_id: 12345,
|
|
135
135
|
},
|
|
136
136
|
});
|
|
137
|
-
expect(mockApiClient.poll).toHaveBeenCalledWith("/api/actions/v1/runs/run_123", {
|
|
137
|
+
expect(mockApiClient.poll).toHaveBeenCalledWith("/zapier/api/actions/v1/runs/run_123", {
|
|
138
138
|
successStatus: 200,
|
|
139
139
|
pendingStatus: 202,
|
|
140
140
|
resultExtractor: expect.any(Function),
|
|
@@ -148,7 +148,7 @@ describe("runAction plugin", () => {
|
|
|
148
148
|
actionKey: "send_message",
|
|
149
149
|
inputs: { message: "Hello" },
|
|
150
150
|
});
|
|
151
|
-
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", {
|
|
151
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/zapier/api/actions/v1/runs", {
|
|
152
152
|
data: {
|
|
153
153
|
selected_api: "SlackCLIAPI@1.21.1",
|
|
154
154
|
action_key: "send_message",
|
|
@@ -168,7 +168,7 @@ describe("runAction plugin", () => {
|
|
|
168
168
|
// Simulate pagination by getting an iterator
|
|
169
169
|
const iterator = runActionResult[Symbol.asyncIterator]();
|
|
170
170
|
await iterator.next();
|
|
171
|
-
expect(mockApiClient.post).toHaveBeenCalledWith("/api/actions/v1/runs", expect.objectContaining({
|
|
171
|
+
expect(mockApiClient.post).toHaveBeenCalledWith("/zapier/api/actions/v1/runs", expect.objectContaining({
|
|
172
172
|
data: expect.objectContaining({
|
|
173
173
|
inputs: { message: "Hello" },
|
|
174
174
|
selected_api: "SlackCLIAPI@1.21.1",
|
package/dist/sdk.test.js
CHANGED
|
@@ -206,7 +206,7 @@ describe("Environment Variable Support", () => {
|
|
|
206
206
|
// Verify that the request was made to the default base URL
|
|
207
207
|
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
208
208
|
const [actualUrl] = mockFetch.mock.calls[0];
|
|
209
|
-
expect(actualUrl).toMatch(/^https:\/\/zapier\.com/);
|
|
209
|
+
expect(actualUrl).toMatch(/^https:\/\/sdkapi\.zapier\.com/);
|
|
210
210
|
expect(actualUrl).toContain("/api/v4/");
|
|
211
211
|
});
|
|
212
212
|
it("should use explicit baseUrl option for SDK API requests", async () => {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implementation Services
|
|
3
|
+
*
|
|
4
|
+
* This module provides domain-specific service functions for interacting with
|
|
5
|
+
* the /api/v4/implementations/* endpoints. These services handle request building,
|
|
6
|
+
* validation, error handling, and authentication for implementation-related API calls.
|
|
7
|
+
*
|
|
8
|
+
* Services are consumed by plugins to avoid code duplication while maintaining
|
|
9
|
+
* separation between the generic HTTP client layer and business logic.
|
|
10
|
+
*/
|
|
11
|
+
import type { ApiClient } from "../api";
|
|
12
|
+
import type { NeedsResponse, NeedChoicesResponse } from "../api/types";
|
|
13
|
+
/**
|
|
14
|
+
* Fetches implementation needs (input fields) for a specific action.
|
|
15
|
+
*
|
|
16
|
+
* This service calls the /api/v4/implementations/needs/ endpoint and returns
|
|
17
|
+
* the raw response after validating success. The response includes all field
|
|
18
|
+
* metadata including static choices, field types, and validation rules.
|
|
19
|
+
*
|
|
20
|
+
* @param params - Request parameters
|
|
21
|
+
* @param params.api - API client instance
|
|
22
|
+
* @param params.selectedApi - Versioned implementation ID (e.g., "SlackCLIAPI@1.21.1")
|
|
23
|
+
* @param params.action - Action key
|
|
24
|
+
* @param params.actionType - Action type (read, write, etc.)
|
|
25
|
+
* @param params.authenticationId - Authentication ID (null to skip authentication)
|
|
26
|
+
* @param params.inputs - Input values that may affect available fields
|
|
27
|
+
* @returns Promise resolving to NeedsResponse
|
|
28
|
+
* @throws {ZapierApiError} When the API request fails or returns success: false
|
|
29
|
+
*/
|
|
30
|
+
export declare function fetchImplementationNeeds({ api, selectedApi, action, actionType, authenticationId, inputs, }: {
|
|
31
|
+
api: ApiClient;
|
|
32
|
+
selectedApi: string;
|
|
33
|
+
action: string;
|
|
34
|
+
actionType: string;
|
|
35
|
+
authenticationId: number | null;
|
|
36
|
+
inputs?: Record<string, unknown>;
|
|
37
|
+
}): Promise<NeedsResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Fetches dynamic choices for a specific input field.
|
|
40
|
+
*
|
|
41
|
+
* This service calls the /api/v4/implementations/choices/ endpoint and returns
|
|
42
|
+
* the raw response after validating success. The response includes available
|
|
43
|
+
* choices for dropdown fields with pagination support.
|
|
44
|
+
*
|
|
45
|
+
* @param params - Request parameters
|
|
46
|
+
* @param params.api - API client instance
|
|
47
|
+
* @param params.actionId - Action ID (e.g., "core:123")
|
|
48
|
+
* @param params.inputFieldId - Input field key
|
|
49
|
+
* @param params.authenticationId - Authentication ID (null to skip authentication)
|
|
50
|
+
* @param params.inputs - Input values that may affect available choices
|
|
51
|
+
* @param params.page - Page number for pagination (0-indexed)
|
|
52
|
+
* @returns Promise resolving to NeedChoicesResponse
|
|
53
|
+
* @throws {ZapierApiError} When the API request fails or returns success: false
|
|
54
|
+
*/
|
|
55
|
+
export declare function fetchImplementationChoices({ api, actionId, inputFieldId, authenticationId, inputs, page, }: {
|
|
56
|
+
api: ApiClient;
|
|
57
|
+
actionId: string;
|
|
58
|
+
inputFieldId: string;
|
|
59
|
+
authenticationId: number | null;
|
|
60
|
+
inputs?: Record<string, unknown>;
|
|
61
|
+
page: number;
|
|
62
|
+
}): Promise<NeedChoicesResponse>;
|
|
63
|
+
//# sourceMappingURL=implementations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"implementations.d.ts","sourceRoot":"","sources":["../../src/services/implementations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAEV,aAAa,EAEb,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,GAAG,EACH,WAAW,EACX,MAAM,EACN,UAAU,EACV,gBAAgB,EAChB,MAAM,GACP,EAAE;IACD,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,GAAG,OAAO,CAAC,aAAa,CAAC,CAyBzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,GAAG,EACH,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,IAAI,GACL,EAAE;IACD,GAAG,EAAE,SAAS,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAyB/B"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implementation Services
|
|
3
|
+
*
|
|
4
|
+
* This module provides domain-specific service functions for interacting with
|
|
5
|
+
* the /api/v4/implementations/* endpoints. These services handle request building,
|
|
6
|
+
* validation, error handling, and authentication for implementation-related API calls.
|
|
7
|
+
*
|
|
8
|
+
* Services are consumed by plugins to avoid code duplication while maintaining
|
|
9
|
+
* separation between the generic HTTP client layer and business logic.
|
|
10
|
+
*/
|
|
11
|
+
import { ZapierApiError } from "../types/errors";
|
|
12
|
+
/**
|
|
13
|
+
* Fetches implementation needs (input fields) for a specific action.
|
|
14
|
+
*
|
|
15
|
+
* This service calls the /api/v4/implementations/needs/ endpoint and returns
|
|
16
|
+
* the raw response after validating success. The response includes all field
|
|
17
|
+
* metadata including static choices, field types, and validation rules.
|
|
18
|
+
*
|
|
19
|
+
* @param params - Request parameters
|
|
20
|
+
* @param params.api - API client instance
|
|
21
|
+
* @param params.selectedApi - Versioned implementation ID (e.g., "SlackCLIAPI@1.21.1")
|
|
22
|
+
* @param params.action - Action key
|
|
23
|
+
* @param params.actionType - Action type (read, write, etc.)
|
|
24
|
+
* @param params.authenticationId - Authentication ID (null to skip authentication)
|
|
25
|
+
* @param params.inputs - Input values that may affect available fields
|
|
26
|
+
* @returns Promise resolving to NeedsResponse
|
|
27
|
+
* @throws {ZapierApiError} When the API request fails or returns success: false
|
|
28
|
+
*/
|
|
29
|
+
export async function fetchImplementationNeeds({ api, selectedApi, action, actionType, authenticationId, inputs, }) {
|
|
30
|
+
const request = {
|
|
31
|
+
selected_api: selectedApi,
|
|
32
|
+
action,
|
|
33
|
+
type_of: actionType,
|
|
34
|
+
params: inputs || {},
|
|
35
|
+
};
|
|
36
|
+
// Only include authentication_id if it's not null (skip authentication when null)
|
|
37
|
+
if (authenticationId !== null) {
|
|
38
|
+
request.authentication_id = authenticationId;
|
|
39
|
+
}
|
|
40
|
+
const response = await api.post("/zapier/api/v4/implementations/needs/", request);
|
|
41
|
+
if (!response.success) {
|
|
42
|
+
throw new ZapierApiError(`Failed to get input fields: ${response.errors?.join(", ") || "Unknown error"}`);
|
|
43
|
+
}
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fetches dynamic choices for a specific input field.
|
|
48
|
+
*
|
|
49
|
+
* This service calls the /api/v4/implementations/choices/ endpoint and returns
|
|
50
|
+
* the raw response after validating success. The response includes available
|
|
51
|
+
* choices for dropdown fields with pagination support.
|
|
52
|
+
*
|
|
53
|
+
* @param params - Request parameters
|
|
54
|
+
* @param params.api - API client instance
|
|
55
|
+
* @param params.actionId - Action ID (e.g., "core:123")
|
|
56
|
+
* @param params.inputFieldId - Input field key
|
|
57
|
+
* @param params.authenticationId - Authentication ID (null to skip authentication)
|
|
58
|
+
* @param params.inputs - Input values that may affect available choices
|
|
59
|
+
* @param params.page - Page number for pagination (0-indexed)
|
|
60
|
+
* @returns Promise resolving to NeedChoicesResponse
|
|
61
|
+
* @throws {ZapierApiError} When the API request fails or returns success: false
|
|
62
|
+
*/
|
|
63
|
+
export async function fetchImplementationChoices({ api, actionId, inputFieldId, authenticationId, inputs, page, }) {
|
|
64
|
+
const request = {
|
|
65
|
+
action_id: actionId,
|
|
66
|
+
input_field_id: inputFieldId,
|
|
67
|
+
page,
|
|
68
|
+
params: inputs || {},
|
|
69
|
+
};
|
|
70
|
+
// Only include authentication_id if it's not null (skip authentication when null)
|
|
71
|
+
if (authenticationId !== null) {
|
|
72
|
+
request.authentication_id = authenticationId;
|
|
73
|
+
}
|
|
74
|
+
const response = await api.post("/zapier/api/v4/implementations/choices/", request);
|
|
75
|
+
if (!response.success) {
|
|
76
|
+
throw new ZapierApiError(`Failed to get input field choices: ${response.errors?.join(", ") || "Unknown error"}`);
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
79
|
+
}
|