@zapier/zapier-sdk 0.6.3 → 0.8.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 +18 -0
- package/README.md +73 -41
- package/dist/api/schemas.d.ts +114 -0
- package/dist/api/schemas.d.ts.map +1 -1
- package/dist/api/schemas.js +45 -0
- package/dist/api/types.d.ts +5 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/index.cjs +2208 -2022
- package/dist/index.d.mts +327 -10
- package/dist/index.d.ts +18 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/index.mjs +2191 -2024
- package/dist/plugins/findFirstAuthentication/index.test.js +3 -3
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +3 -3
- package/dist/plugins/findFirstAuthentication/schemas.js +1 -1
- package/dist/plugins/findUniqueAuthentication/index.test.js +3 -3
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +3 -3
- package/dist/plugins/findUniqueAuthentication/schemas.js +1 -1
- package/dist/plugins/getProfile/index.js +1 -1
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +2 -3
- package/dist/plugins/listAuthentications/index.test.js +5 -5
- package/dist/plugins/listAuthentications/schemas.d.ts +3 -3
- package/dist/plugins/listAuthentications/schemas.js +1 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts +28 -0
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -0
- package/dist/plugins/listInputFieldChoices/index.js +78 -0
- package/dist/plugins/listInputFieldChoices/index.test.d.ts +2 -0
- package/dist/plugins/listInputFieldChoices/index.test.d.ts.map +1 -0
- package/dist/plugins/listInputFieldChoices/index.test.js +537 -0
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +61 -0
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -0
- package/dist/plugins/listInputFieldChoices/schemas.js +73 -0
- package/dist/plugins/registry/index.js +3 -3
- package/dist/sdk.d.ts +93 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +7 -2
- package/package.json +1 -1
- package/src/api/schemas.ts +62 -0
- package/src/api/types.ts +14 -0
- package/src/index.ts +25 -1
- package/src/plugins/findFirstAuthentication/index.test.ts +3 -3
- package/src/plugins/findFirstAuthentication/schemas.ts +1 -1
- package/src/plugins/findUniqueAuthentication/index.test.ts +3 -3
- package/src/plugins/findUniqueAuthentication/schemas.ts +1 -1
- package/src/plugins/getProfile/index.ts +1 -1
- package/src/plugins/listAuthentications/index.test.ts +5 -5
- package/src/plugins/listAuthentications/index.ts +2 -3
- package/src/plugins/listAuthentications/schemas.ts +1 -1
- package/src/plugins/listInputFieldChoices/index.test.ts +653 -0
- package/src/plugins/listInputFieldChoices/index.ts +152 -0
- package/src/plugins/listInputFieldChoices/schemas.ts +139 -0
- package/src/plugins/registry/index.ts +3 -3
- package/src/sdk.ts +8 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -81,7 +81,7 @@ describe("findFirstAuthentication plugin", () => {
|
|
|
81
81
|
const sdk = createTestSdk();
|
|
82
82
|
await expect(sdk.findFirstAuthentication({
|
|
83
83
|
title: 123,
|
|
84
|
-
|
|
84
|
+
accountId: 456,
|
|
85
85
|
owner: true,
|
|
86
86
|
})).rejects.toThrow(ZapierValidationError);
|
|
87
87
|
});
|
|
@@ -91,7 +91,7 @@ describe("findFirstAuthentication plugin", () => {
|
|
|
91
91
|
appKey: "slack",
|
|
92
92
|
search: "workspace",
|
|
93
93
|
title: "My Slack Workspace",
|
|
94
|
-
|
|
94
|
+
accountId: "acc_123",
|
|
95
95
|
owner: "me",
|
|
96
96
|
});
|
|
97
97
|
expect(result.data).toBeDefined();
|
|
@@ -138,7 +138,7 @@ describe("findFirstAuthentication plugin", () => {
|
|
|
138
138
|
appKey: "slack",
|
|
139
139
|
search: "workspace",
|
|
140
140
|
title: "My Slack Workspace",
|
|
141
|
-
|
|
141
|
+
accountId: "acc_123",
|
|
142
142
|
owner: "me",
|
|
143
143
|
};
|
|
144
144
|
await sdk.findFirstAuthentication(options);
|
|
@@ -4,19 +4,19 @@ export declare const FindFirstAuthenticationSchema: z.ZodObject<{
|
|
|
4
4
|
appKey: z.ZodOptional<z.ZodString>;
|
|
5
5
|
search: z.ZodOptional<z.ZodString>;
|
|
6
6
|
title: z.ZodOptional<z.ZodString>;
|
|
7
|
-
|
|
7
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
8
8
|
owner: z.ZodOptional<z.ZodString>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
title?: string | undefined;
|
|
11
11
|
search?: string | undefined;
|
|
12
|
-
account_id?: string | undefined;
|
|
13
12
|
appKey?: string | undefined;
|
|
13
|
+
accountId?: string | undefined;
|
|
14
14
|
owner?: string | undefined;
|
|
15
15
|
}, {
|
|
16
16
|
title?: string | undefined;
|
|
17
17
|
search?: string | undefined;
|
|
18
|
-
account_id?: string | undefined;
|
|
19
18
|
appKey?: string | undefined;
|
|
19
|
+
accountId?: string | undefined;
|
|
20
20
|
owner?: string | undefined;
|
|
21
21
|
}>;
|
|
22
22
|
export type FindFirstAuthenticationOptions = z.infer<typeof FindFirstAuthenticationSchema>;
|
|
@@ -12,7 +12,7 @@ export const FindFirstAuthenticationSchema = z
|
|
|
12
12
|
.string()
|
|
13
13
|
.optional()
|
|
14
14
|
.describe("Filter authentications by exact title match"),
|
|
15
|
-
|
|
15
|
+
accountId: z.string().optional().describe("Filter by account ID"),
|
|
16
16
|
owner: z.string().optional().describe("Filter by owner"),
|
|
17
17
|
})
|
|
18
18
|
.describe("Find the first authentication matching the criteria");
|
|
@@ -72,7 +72,7 @@ describe("findUniqueAuthentication plugin", () => {
|
|
|
72
72
|
await expect(sdk.findUniqueAuthentication({
|
|
73
73
|
search: 123,
|
|
74
74
|
title: 456,
|
|
75
|
-
|
|
75
|
+
accountId: 789,
|
|
76
76
|
owner: false,
|
|
77
77
|
})).rejects.toThrow(ZapierValidationError);
|
|
78
78
|
});
|
|
@@ -82,7 +82,7 @@ describe("findUniqueAuthentication plugin", () => {
|
|
|
82
82
|
appKey: "slack",
|
|
83
83
|
search: "Workspace",
|
|
84
84
|
title: "My Slack",
|
|
85
|
-
|
|
85
|
+
accountId: "acc_123",
|
|
86
86
|
owner: "me",
|
|
87
87
|
});
|
|
88
88
|
expect(result.data).toBeDefined();
|
|
@@ -131,7 +131,7 @@ describe("findUniqueAuthentication plugin", () => {
|
|
|
131
131
|
appKey: "slack",
|
|
132
132
|
search: "workspace",
|
|
133
133
|
title: "My Slack Workspace",
|
|
134
|
-
|
|
134
|
+
accountId: "acc_123",
|
|
135
135
|
owner: "me",
|
|
136
136
|
};
|
|
137
137
|
await sdk.findUniqueAuthentication(options);
|
|
@@ -4,19 +4,19 @@ export declare const FindUniqueAuthenticationSchema: z.ZodObject<{
|
|
|
4
4
|
appKey: z.ZodOptional<z.ZodString>;
|
|
5
5
|
search: z.ZodOptional<z.ZodString>;
|
|
6
6
|
title: z.ZodOptional<z.ZodString>;
|
|
7
|
-
|
|
7
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
8
8
|
owner: z.ZodOptional<z.ZodString>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
title?: string | undefined;
|
|
11
11
|
search?: string | undefined;
|
|
12
|
-
account_id?: string | undefined;
|
|
13
12
|
appKey?: string | undefined;
|
|
13
|
+
accountId?: string | undefined;
|
|
14
14
|
owner?: string | undefined;
|
|
15
15
|
}, {
|
|
16
16
|
title?: string | undefined;
|
|
17
17
|
search?: string | undefined;
|
|
18
|
-
account_id?: string | undefined;
|
|
19
18
|
appKey?: string | undefined;
|
|
19
|
+
accountId?: string | undefined;
|
|
20
20
|
owner?: string | undefined;
|
|
21
21
|
}>;
|
|
22
22
|
export type FindUniqueAuthenticationOptions = z.infer<typeof FindUniqueAuthenticationSchema>;
|
|
@@ -12,7 +12,7 @@ export const FindUniqueAuthenticationSchema = z
|
|
|
12
12
|
.string()
|
|
13
13
|
.optional()
|
|
14
14
|
.describe("Filter authentications by exact title match"),
|
|
15
|
-
|
|
15
|
+
accountId: z.string().optional().describe("Filter by account ID"),
|
|
16
16
|
owner: z.string().optional().describe("Filter by owner"),
|
|
17
17
|
})
|
|
18
18
|
.describe("Find a unique authentication matching the criteria");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listAuthentications/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,yBAAyB,EACzB,KAAK,0BAA0B,EAEhC,MAAM,WAAW,CAAC;AAUnB,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,iCAAiC;IAChD,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,0BAA0B,KAAK,OAAO,CAAC;QACrE,IAAI,EAAE,kBAAkB,EAAE,CAAC;KAC5B,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QACnE,KAAK,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAAC;KAC5C,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,mBAAmB,EAAE;gBACnB,WAAW,EAAE,OAAO,yBAAyB,CAAC;aAC/C,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAC5C,UAAU,CAAC,sBAAsB,CAAC,EAAE,yBAAyB;AAC7D;IACE,GAAG,EAAE,SAAS,CAAC;IACf,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,EAAE,0BAA0B;AAC7B,iCAAiC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listAuthentications/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,yBAAyB,EACzB,KAAK,0BAA0B,EAEhC,MAAM,WAAW,CAAC;AAUnB,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,iCAAiC;IAChD,mBAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,0BAA0B,KAAK,OAAO,CAAC;QACrE,IAAI,EAAE,kBAAkB,EAAE,CAAC;KAC5B,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QACnE,KAAK,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAAC;KAC5C,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,mBAAmB,EAAE;gBACnB,WAAW,EAAE,OAAO,yBAAyB,CAAC;aAC/C,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAC5C,UAAU,CAAC,sBAAsB,CAAC,EAAE,yBAAyB;AAC7D;IACE,GAAG,EAAE,SAAS,CAAC;IACf,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,EAAE,0BAA0B;AAC7B,iCAAiC,CA8FlC,CAAC"}
|
|
@@ -23,8 +23,8 @@ export const listAuthenticationsPlugin = ({ context }) => {
|
|
|
23
23
|
else if (options.title) {
|
|
24
24
|
searchParams.search = options.title;
|
|
25
25
|
}
|
|
26
|
-
if (options.
|
|
27
|
-
searchParams.account_id = options.
|
|
26
|
+
if (options.accountId) {
|
|
27
|
+
searchParams.account_id = options.accountId;
|
|
28
28
|
}
|
|
29
29
|
if (options.owner) {
|
|
30
30
|
searchParams.owner = options.owner;
|
|
@@ -35,7 +35,6 @@ export const listAuthenticationsPlugin = ({ context }) => {
|
|
|
35
35
|
// Convert cursor back to offset for the API
|
|
36
36
|
searchParams.offset = options.cursor;
|
|
37
37
|
}
|
|
38
|
-
console.log({ searchParams });
|
|
39
38
|
const data = await api.get("/api/v4/authentications/", {
|
|
40
39
|
searchParams,
|
|
41
40
|
customErrorHandler: ({ status }) => {
|
|
@@ -115,11 +115,11 @@ describe("listAuthentications plugin", () => {
|
|
|
115
115
|
});
|
|
116
116
|
}).toThrow(ZapierValidationError);
|
|
117
117
|
});
|
|
118
|
-
it("should throw validation error for invalid
|
|
118
|
+
it("should throw validation error for invalid accountId type", () => {
|
|
119
119
|
const sdk = createTestSdk();
|
|
120
120
|
expect(() => {
|
|
121
121
|
sdk.listAuthentications({
|
|
122
|
-
|
|
122
|
+
accountId: 123,
|
|
123
123
|
});
|
|
124
124
|
}).toThrow(ZapierValidationError);
|
|
125
125
|
});
|
|
@@ -163,7 +163,7 @@ describe("listAuthentications plugin", () => {
|
|
|
163
163
|
appKey: "slack",
|
|
164
164
|
search: "workspace",
|
|
165
165
|
title: "My Slack Workspace",
|
|
166
|
-
|
|
166
|
+
accountId: "acc_123",
|
|
167
167
|
owner: "me",
|
|
168
168
|
pageSize: 10,
|
|
169
169
|
maxItems: 50,
|
|
@@ -255,9 +255,9 @@ describe("listAuthentications plugin", () => {
|
|
|
255
255
|
}),
|
|
256
256
|
}));
|
|
257
257
|
});
|
|
258
|
-
it("should pass
|
|
258
|
+
it("should pass accountId filter to API", async () => {
|
|
259
259
|
const sdk = createTestSdk();
|
|
260
|
-
await sdk.listAuthentications({
|
|
260
|
+
await sdk.listAuthentications({ accountId: "acc_123" });
|
|
261
261
|
expect(mockApiClient.get).toHaveBeenCalledWith("/api/v4/authentications/", expect.objectContaining({
|
|
262
262
|
searchParams: expect.objectContaining({
|
|
263
263
|
account_id: "acc_123",
|
|
@@ -5,25 +5,25 @@ export declare const ListAuthenticationsSchema: z.ZodObject<{
|
|
|
5
5
|
appKey: z.ZodOptional<z.ZodString>;
|
|
6
6
|
search: z.ZodOptional<z.ZodString>;
|
|
7
7
|
title: z.ZodOptional<z.ZodString>;
|
|
8
|
-
|
|
8
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
9
9
|
owner: z.ZodOptional<z.ZodString>;
|
|
10
10
|
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
11
11
|
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
12
12
|
}, "strip", z.ZodTypeAny, {
|
|
13
13
|
title?: string | undefined;
|
|
14
14
|
search?: string | undefined;
|
|
15
|
-
account_id?: string | undefined;
|
|
16
15
|
appKey?: string | undefined;
|
|
17
16
|
pageSize?: number | undefined;
|
|
18
17
|
maxItems?: number | undefined;
|
|
18
|
+
accountId?: string | undefined;
|
|
19
19
|
owner?: string | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
title?: string | undefined;
|
|
22
22
|
search?: string | undefined;
|
|
23
|
-
account_id?: string | undefined;
|
|
24
23
|
appKey?: string | undefined;
|
|
25
24
|
pageSize?: number | undefined;
|
|
26
25
|
maxItems?: number | undefined;
|
|
26
|
+
accountId?: string | undefined;
|
|
27
27
|
owner?: string | undefined;
|
|
28
28
|
}>;
|
|
29
29
|
export type ListAuthenticationsOptions = z.infer<typeof ListAuthenticationsSchema>;
|
|
@@ -12,7 +12,7 @@ export const ListAuthenticationsSchema = z
|
|
|
12
12
|
.string()
|
|
13
13
|
.optional()
|
|
14
14
|
.describe("Filter authentications by exact title match"),
|
|
15
|
-
|
|
15
|
+
accountId: z.string().optional().describe("Filter by account ID"),
|
|
16
16
|
owner: z.string().optional().describe("Filter by owner"),
|
|
17
17
|
pageSize: z
|
|
18
18
|
.number()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { InputFieldChoiceItem } from "./schemas";
|
|
4
|
+
import { ListInputFieldChoicesSchema, type ListInputFieldChoicesOptions } from "./schemas";
|
|
5
|
+
import type { GetActionPluginProvides } from "../getAction";
|
|
6
|
+
export interface ListInputFieldChoicesPluginProvides {
|
|
7
|
+
listInputFieldChoices: (options: ListInputFieldChoicesOptions) => Promise<{
|
|
8
|
+
data: InputFieldChoiceItem[];
|
|
9
|
+
}> & AsyncIterable<{
|
|
10
|
+
data: InputFieldChoiceItem[];
|
|
11
|
+
nextCursor?: string;
|
|
12
|
+
}> & {
|
|
13
|
+
items(): AsyncIterable<InputFieldChoiceItem>;
|
|
14
|
+
};
|
|
15
|
+
context: {
|
|
16
|
+
meta: {
|
|
17
|
+
listInputFieldChoices: {
|
|
18
|
+
inputSchema: typeof ListInputFieldChoicesSchema;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare const listInputFieldChoicesPlugin: Plugin<GetSdkType<GetActionPluginProvides>, // requires getAction in SDK
|
|
24
|
+
{
|
|
25
|
+
api: ApiClient;
|
|
26
|
+
}, // requires api in context
|
|
27
|
+
ListInputFieldChoicesPluginProvides>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFieldChoices/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAM3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EACL,2BAA2B,EAC3B,KAAK,4BAA4B,EAElC,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAc5D,MAAM,WAAW,mCAAmC;IAClD,qBAAqB,EAAE,CAAC,OAAO,EAAE,4BAA4B,KAAK,OAAO,CAAC;QACxE,IAAI,EAAE,oBAAoB,EAAE,CAAC;KAC9B,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QACrE,KAAK,IAAI,aAAa,CAAC,oBAAoB,CAAC,CAAC;KAC9C,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,qBAAqB,EAAE;gBACrB,WAAW,EAAE,OAAO,2BAA2B,CAAC;aACjD,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAC9C,UAAU,CAAC,uBAAuB,CAAC,EAAE,4BAA4B;AACjE;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAAE,0BAA0B;AAC9C,mCAAmC,CAuGpC,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ListInputFieldChoicesSchema, } from "./schemas";
|
|
2
|
+
import { ZapierApiError } from "../../types/errors";
|
|
3
|
+
import { createPaginatedFunction } from "../../utils/function-utils";
|
|
4
|
+
// Transform NeedChoices to InputFieldChoiceItem
|
|
5
|
+
function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
6
|
+
return {
|
|
7
|
+
key: choice.key,
|
|
8
|
+
label: choice.label,
|
|
9
|
+
sample: choice.sample,
|
|
10
|
+
value: choice.value,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export const listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
14
|
+
const listInputFieldChoices = createPaginatedFunction(async function listInputFieldChoicesPage(options) {
|
|
15
|
+
const { api } = context;
|
|
16
|
+
// Extract parameters
|
|
17
|
+
const { appKey, actionType, actionKey, inputFieldKey, authenticationId, inputs, page, cursor, } = options;
|
|
18
|
+
// Use sdk.getAction to get the action ID
|
|
19
|
+
const actionResult = await sdk.getAction({ appKey, actionType, actionKey });
|
|
20
|
+
const actionId = actionResult.data.id;
|
|
21
|
+
if (!actionId) {
|
|
22
|
+
throw new ZapierApiError(`Action ${actionKey} does not have an ID - cannot retrieve input field choices`);
|
|
23
|
+
}
|
|
24
|
+
// Build choices request using action ID from getAction
|
|
25
|
+
// Use cursor (from pagination) as page number if available, otherwise use explicit page or default to 0
|
|
26
|
+
const requestPage = cursor ? parseInt(cursor, 10) : (page ?? 0);
|
|
27
|
+
const choicesRequest = {
|
|
28
|
+
action_id: actionId,
|
|
29
|
+
input_field_id: inputFieldKey,
|
|
30
|
+
page: requestPage,
|
|
31
|
+
params: inputs || {},
|
|
32
|
+
};
|
|
33
|
+
// Only include authentication_id if it's not null (skip authentication when null)
|
|
34
|
+
if (authenticationId !== null) {
|
|
35
|
+
choicesRequest.authentication_id = authenticationId;
|
|
36
|
+
}
|
|
37
|
+
const choicesData = await api.post("/api/v4/implementations/choices/", choicesRequest);
|
|
38
|
+
if (!choicesData.success) {
|
|
39
|
+
throw new ZapierApiError(`Failed to get input field choices: ${choicesData.errors?.join(", ") || "Unknown error"}`);
|
|
40
|
+
}
|
|
41
|
+
// Transform NeedChoices objects to InputFieldChoiceItem objects
|
|
42
|
+
const choices = (choicesData.choices || []).map(transformNeedChoicesToInputFieldChoiceItem);
|
|
43
|
+
// Handle pagination
|
|
44
|
+
let nextCursor;
|
|
45
|
+
if (choicesData.next_page !== undefined) {
|
|
46
|
+
nextCursor = choicesData.next_page.toString();
|
|
47
|
+
}
|
|
48
|
+
else if (choicesData.links?.next) {
|
|
49
|
+
// Extract page from next URL for external actions
|
|
50
|
+
try {
|
|
51
|
+
const nextUrl = new URL(choicesData.links.next);
|
|
52
|
+
const nextPage = nextUrl.searchParams.get("page");
|
|
53
|
+
if (nextPage) {
|
|
54
|
+
nextCursor = nextPage;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Handle malformed URLs gracefully by not setting nextCursor
|
|
59
|
+
nextCursor = undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
data: choices,
|
|
64
|
+
nextCursor,
|
|
65
|
+
};
|
|
66
|
+
}, ListInputFieldChoicesSchema);
|
|
67
|
+
return {
|
|
68
|
+
listInputFieldChoices,
|
|
69
|
+
context: {
|
|
70
|
+
meta: {
|
|
71
|
+
listInputFieldChoices: {
|
|
72
|
+
categories: ["action"],
|
|
73
|
+
inputSchema: ListInputFieldChoicesSchema,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFieldChoices/index.test.ts"],"names":[],"mappings":""}
|