@zapier/zapier-sdk 0.6.4 → 0.8.1
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 +55 -23
- 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 +8 -3
- package/dist/api/types.d.ts.map +1 -1
- package/dist/index.cjs +173 -9
- package/dist/index.d.mts +516 -442
- package/dist/index.mjs +173 -9
- 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/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/listInputFields/schemas.d.ts +3 -3
- package/dist/plugins/runAction/schemas.d.ts +5 -5
- package/dist/plugins/runAction/schemas.d.ts.map +1 -1
- package/dist/sdk.d.ts +7 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +2 -0
- package/dist/types/functions.d.ts +1 -1
- package/dist/types/functions.d.ts.map +1 -1
- package/dist/types/properties.d.ts +2 -2
- package/dist/types/properties.d.ts.map +1 -1
- package/dist/types/properties.js +2 -2
- package/package.json +1 -1
- package/src/api/schemas.ts +62 -0
- package/src/api/types.ts +17 -2
- 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/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/runAction/schemas.ts +2 -2
- package/src/sdk.ts +2 -0
- package/src/types/functions.ts +1 -1
- package/src/types/properties.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.mjs
CHANGED
|
@@ -47,12 +47,12 @@ var ActionTypePropertySchema = z.enum([
|
|
|
47
47
|
]).describe("Action type that matches the action's defined type");
|
|
48
48
|
var ActionKeyPropertySchema = z.string().min(1).describe("Action key to execute");
|
|
49
49
|
var AuthenticationIdPropertySchema = z.number().int().describe("Authentication ID to use for this action");
|
|
50
|
-
var InputsPropertySchema = z.record(z.
|
|
50
|
+
var InputsPropertySchema = z.record(z.unknown()).describe("Input parameters for the action");
|
|
51
51
|
var LimitPropertySchema = z.number().int().min(1).max(MAX_PAGE_LIMIT).default(50).describe("Maximum number of items to return");
|
|
52
52
|
var OffsetPropertySchema = z.number().int().min(0).default(0).describe("Number of items to skip for pagination");
|
|
53
53
|
var OutputPropertySchema = z.string().describe("Output file path");
|
|
54
54
|
var DebugPropertySchema = z.boolean().default(false).describe("Enable debug logging");
|
|
55
|
-
var ParamsPropertySchema = z.record(z.
|
|
55
|
+
var ParamsPropertySchema = z.record(z.unknown()).describe("Additional parameters");
|
|
56
56
|
|
|
57
57
|
// src/types/errors.ts
|
|
58
58
|
var ZapierError = class extends Error {
|
|
@@ -1187,6 +1187,42 @@ z.object({
|
|
|
1187
1187
|
previous: z.string().nullable().optional(),
|
|
1188
1188
|
results: z.array(ImplementationMetaSchema)
|
|
1189
1189
|
});
|
|
1190
|
+
var NeedChoicesResponseMetaSchema = z.object({
|
|
1191
|
+
page: z.string().nullable().optional()
|
|
1192
|
+
});
|
|
1193
|
+
var NeedChoicesResponseLinksSchema = z.object({
|
|
1194
|
+
next: z.string().nullable().optional(),
|
|
1195
|
+
prev: z.string().nullable().optional()
|
|
1196
|
+
});
|
|
1197
|
+
z.object({
|
|
1198
|
+
selected_api: z.string().optional().describe(
|
|
1199
|
+
"Something like `SlackAPI` (for Python apps) or `SplitwiseCLIAPI@1.0.0` (for CLI apps). Non-public apps are fine as long as the authed user can access them."
|
|
1200
|
+
),
|
|
1201
|
+
authentication_id: z.number().optional().describe(
|
|
1202
|
+
"If the app needs auth, provide an `authentication_id` that has the `selected_api` of the app you want to run. Can be any auth visible to the user (including shared)."
|
|
1203
|
+
),
|
|
1204
|
+
params: z.record(z.any()).optional().describe(
|
|
1205
|
+
"Object that matches the input the node would normally get. Has all the same keys/types as the `needs` of the action."
|
|
1206
|
+
),
|
|
1207
|
+
page: z.number().optional().default(0),
|
|
1208
|
+
prefill: z.string().optional().describe(
|
|
1209
|
+
"The prefill string to indicate what we're fetching choices for. Likely something like `spreadsheet.id.title`. Must be provided alongside `selected_api` if both `action_id` and `input_field_id` are not."
|
|
1210
|
+
),
|
|
1211
|
+
action_id: z.string().optional().describe(
|
|
1212
|
+
"The id that will be used to lookup the Action for prefill lookup. If provided, `input_field_id` is required, else `prefill` must be provided."
|
|
1213
|
+
),
|
|
1214
|
+
input_field_id: z.string().optional().describe(
|
|
1215
|
+
"The id (key) of the input field (Need) that dynamic choices are being retrieved for. If provided, `action_id` is required, else `prefill` must be provided."
|
|
1216
|
+
)
|
|
1217
|
+
});
|
|
1218
|
+
z.object({
|
|
1219
|
+
success: z.boolean(),
|
|
1220
|
+
choices: z.array(NeedChoicesSchema).optional(),
|
|
1221
|
+
next_page: z.number().optional(),
|
|
1222
|
+
errors: z.array(z.string()).optional(),
|
|
1223
|
+
meta: NeedChoicesResponseMetaSchema.optional(),
|
|
1224
|
+
links: NeedChoicesResponseLinksSchema.optional()
|
|
1225
|
+
});
|
|
1190
1226
|
|
|
1191
1227
|
// src/schemas/Action.ts
|
|
1192
1228
|
var ActionItemSchema = withFormatter(
|
|
@@ -1440,7 +1476,7 @@ var ListAuthenticationsSchema = z.object({
|
|
|
1440
1476
|
),
|
|
1441
1477
|
search: z.string().optional().describe("Search term to filter authentications by title"),
|
|
1442
1478
|
title: z.string().optional().describe("Filter authentications by exact title match"),
|
|
1443
|
-
|
|
1479
|
+
accountId: z.string().optional().describe("Filter by account ID"),
|
|
1444
1480
|
owner: z.string().optional().describe("Filter by owner"),
|
|
1445
1481
|
pageSize: z.number().min(1).optional().describe("Number of authentications per page"),
|
|
1446
1482
|
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
@@ -1466,8 +1502,8 @@ var listAuthenticationsPlugin = ({ context }) => {
|
|
|
1466
1502
|
} else if (options.title) {
|
|
1467
1503
|
searchParams.search = options.title;
|
|
1468
1504
|
}
|
|
1469
|
-
if (options.
|
|
1470
|
-
searchParams.account_id = options.
|
|
1505
|
+
if (options.accountId) {
|
|
1506
|
+
searchParams.account_id = options.accountId;
|
|
1471
1507
|
}
|
|
1472
1508
|
if (options.owner) {
|
|
1473
1509
|
searchParams.owner = options.owner;
|
|
@@ -1476,7 +1512,6 @@ var listAuthenticationsPlugin = ({ context }) => {
|
|
|
1476
1512
|
if (options.cursor) {
|
|
1477
1513
|
searchParams.offset = options.cursor;
|
|
1478
1514
|
}
|
|
1479
|
-
console.log({ searchParams });
|
|
1480
1515
|
const data = await api.get(
|
|
1481
1516
|
"/api/v4/authentications/",
|
|
1482
1517
|
{
|
|
@@ -1652,7 +1687,7 @@ var FindFirstAuthenticationSchema = z.object({
|
|
|
1652
1687
|
),
|
|
1653
1688
|
search: z.string().optional().describe("Search term to filter authentications by title"),
|
|
1654
1689
|
title: z.string().optional().describe("Filter authentications by exact title match"),
|
|
1655
|
-
|
|
1690
|
+
accountId: z.string().optional().describe("Filter by account ID"),
|
|
1656
1691
|
owner: z.string().optional().describe("Filter by owner")
|
|
1657
1692
|
}).describe("Find the first authentication matching the criteria");
|
|
1658
1693
|
|
|
@@ -1688,7 +1723,7 @@ var FindUniqueAuthenticationSchema = z.object({
|
|
|
1688
1723
|
),
|
|
1689
1724
|
search: z.string().optional().describe("Search term to filter authentications by title"),
|
|
1690
1725
|
title: z.string().optional().describe("Filter authentications by exact title match"),
|
|
1691
|
-
|
|
1726
|
+
accountId: z.string().optional().describe("Filter by account ID"),
|
|
1692
1727
|
owner: z.string().optional().describe("Filter by owner")
|
|
1693
1728
|
}).describe("Find a unique authentication matching the criteria");
|
|
1694
1729
|
|
|
@@ -2871,6 +2906,135 @@ var registryPlugin = ({ sdk, context }) => {
|
|
|
2871
2906
|
getRegistry
|
|
2872
2907
|
};
|
|
2873
2908
|
};
|
|
2909
|
+
var InputFieldChoiceItemSchema = withFormatter(
|
|
2910
|
+
z.object({
|
|
2911
|
+
key: z.string().optional().describe("Unique key/value for the choice"),
|
|
2912
|
+
label: z.string().optional().describe("Human readable label for the choice"),
|
|
2913
|
+
sample: z.string().optional().describe("Sample value for the choice"),
|
|
2914
|
+
value: z.string().optional().describe("Value to be submitted when selected")
|
|
2915
|
+
}),
|
|
2916
|
+
{
|
|
2917
|
+
format: (item) => {
|
|
2918
|
+
const title = item.label || item.key || "Choice";
|
|
2919
|
+
const subtitle = item.label && item.key && item.label !== item.key ? `(${item.key})` : void 0;
|
|
2920
|
+
const details = [];
|
|
2921
|
+
if (item.sample && item.sample !== item.key) {
|
|
2922
|
+
details.push({ text: `Sample: ${item.sample}`, style: "dim" });
|
|
2923
|
+
}
|
|
2924
|
+
if (item.value && item.value !== item.key) {
|
|
2925
|
+
details.push({ text: `Value: ${item.value}`, style: "normal" });
|
|
2926
|
+
}
|
|
2927
|
+
return {
|
|
2928
|
+
title,
|
|
2929
|
+
subtitle,
|
|
2930
|
+
details
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
);
|
|
2935
|
+
var ListInputFieldChoicesSchema = withOutputSchema(
|
|
2936
|
+
z.object({
|
|
2937
|
+
// Required action identification
|
|
2938
|
+
appKey: AppKeyPropertySchema,
|
|
2939
|
+
actionType: ActionTypePropertySchema,
|
|
2940
|
+
actionKey: ActionKeyPropertySchema,
|
|
2941
|
+
// Input field specification
|
|
2942
|
+
inputFieldKey: z.string().min(1).describe("Input field key to get choices for."),
|
|
2943
|
+
// Common parameters
|
|
2944
|
+
authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
|
|
2945
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
2946
|
+
"Current input values that may affect available choices"
|
|
2947
|
+
),
|
|
2948
|
+
page: z.number().int().min(0).optional().describe("Page number for paginated results"),
|
|
2949
|
+
// Pagination options (SDK-level)
|
|
2950
|
+
pageSize: z.number().min(1).optional().describe("Number of choices per page"),
|
|
2951
|
+
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
2952
|
+
}).describe("Get the available choices for a dynamic dropdown input field"),
|
|
2953
|
+
InputFieldChoiceItemSchema
|
|
2954
|
+
);
|
|
2955
|
+
|
|
2956
|
+
// src/plugins/listInputFieldChoices/index.ts
|
|
2957
|
+
function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
2958
|
+
return {
|
|
2959
|
+
key: choice.key,
|
|
2960
|
+
label: choice.label,
|
|
2961
|
+
sample: choice.sample,
|
|
2962
|
+
value: choice.value
|
|
2963
|
+
};
|
|
2964
|
+
}
|
|
2965
|
+
var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
2966
|
+
const listInputFieldChoices = createPaginatedFunction(async function listInputFieldChoicesPage(options) {
|
|
2967
|
+
const { api } = context;
|
|
2968
|
+
const {
|
|
2969
|
+
appKey,
|
|
2970
|
+
actionType,
|
|
2971
|
+
actionKey,
|
|
2972
|
+
inputFieldKey,
|
|
2973
|
+
authenticationId,
|
|
2974
|
+
inputs,
|
|
2975
|
+
page,
|
|
2976
|
+
cursor
|
|
2977
|
+
} = options;
|
|
2978
|
+
const actionResult = await sdk.getAction({ appKey, actionType, actionKey });
|
|
2979
|
+
const actionId = actionResult.data.id;
|
|
2980
|
+
if (!actionId) {
|
|
2981
|
+
throw new ZapierApiError(
|
|
2982
|
+
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`
|
|
2983
|
+
);
|
|
2984
|
+
}
|
|
2985
|
+
const requestPage = cursor ? parseInt(cursor, 10) : page ?? 0;
|
|
2986
|
+
const choicesRequest = {
|
|
2987
|
+
action_id: actionId,
|
|
2988
|
+
input_field_id: inputFieldKey,
|
|
2989
|
+
page: requestPage,
|
|
2990
|
+
params: inputs || {}
|
|
2991
|
+
};
|
|
2992
|
+
if (authenticationId !== null) {
|
|
2993
|
+
choicesRequest.authentication_id = authenticationId;
|
|
2994
|
+
}
|
|
2995
|
+
const choicesData = await api.post(
|
|
2996
|
+
"/api/v4/implementations/choices/",
|
|
2997
|
+
choicesRequest
|
|
2998
|
+
);
|
|
2999
|
+
if (!choicesData.success) {
|
|
3000
|
+
throw new ZapierApiError(
|
|
3001
|
+
`Failed to get input field choices: ${choicesData.errors?.join(", ") || "Unknown error"}`
|
|
3002
|
+
);
|
|
3003
|
+
}
|
|
3004
|
+
const choices = (choicesData.choices || []).map(
|
|
3005
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
3006
|
+
);
|
|
3007
|
+
let nextCursor;
|
|
3008
|
+
if (choicesData.next_page !== void 0) {
|
|
3009
|
+
nextCursor = choicesData.next_page.toString();
|
|
3010
|
+
} else if (choicesData.links?.next) {
|
|
3011
|
+
try {
|
|
3012
|
+
const nextUrl = new URL(choicesData.links.next);
|
|
3013
|
+
const nextPage = nextUrl.searchParams.get("page");
|
|
3014
|
+
if (nextPage) {
|
|
3015
|
+
nextCursor = nextPage;
|
|
3016
|
+
}
|
|
3017
|
+
} catch {
|
|
3018
|
+
nextCursor = void 0;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
return {
|
|
3022
|
+
data: choices,
|
|
3023
|
+
nextCursor
|
|
3024
|
+
};
|
|
3025
|
+
}, ListInputFieldChoicesSchema);
|
|
3026
|
+
return {
|
|
3027
|
+
listInputFieldChoices,
|
|
3028
|
+
context: {
|
|
3029
|
+
meta: {
|
|
3030
|
+
listInputFieldChoices: {
|
|
3031
|
+
categories: ["action"],
|
|
3032
|
+
inputSchema: ListInputFieldChoicesSchema
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
};
|
|
3037
|
+
};
|
|
2874
3038
|
|
|
2875
3039
|
// src/sdk.ts
|
|
2876
3040
|
function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} }) {
|
|
@@ -2921,7 +3085,7 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
|
|
|
2921
3085
|
};
|
|
2922
3086
|
}
|
|
2923
3087
|
function createZapierSdkWithoutRegistry(options = {}) {
|
|
2924
|
-
return createSdk(options).addPlugin(apiPlugin).addPlugin(listAppsPlugin).addPlugin(manifestPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(runActionPlugin).addPlugin(lockVersionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
|
|
3088
|
+
return createSdk(options).addPlugin(apiPlugin).addPlugin(listAppsPlugin).addPlugin(manifestPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(lockVersionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
|
|
2925
3089
|
}
|
|
2926
3090
|
function createZapierSdk(options = {}) {
|
|
2927
3091
|
return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
|
|
@@ -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":""}
|