@zapier/zapier-sdk 0.13.6 → 0.13.8
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 +15 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +5 -5
- package/dist/api/client.test.d.ts +2 -0
- package/dist/api/client.test.d.ts.map +1 -0
- package/dist/api/client.test.js +80 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +3 -1
- package/dist/api/schemas.d.ts +20 -20
- package/dist/api/types.d.ts +2 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/auth.d.ts +3 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.test.d.ts +2 -0
- package/dist/auth.test.d.ts.map +1 -0
- package/dist/auth.test.js +102 -0
- package/dist/constants.d.ts +4 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -4
- package/dist/index.cjs +89 -21
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +88 -22
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +4 -1
- package/dist/plugins/eventEmission/index.d.ts +2 -0
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +35 -9
- package/dist/plugins/eventEmission/index.test.js +100 -0
- package/dist/schemas/Action.d.ts +2 -2
- package/dist/schemas/Auth.d.ts +4 -4
- package/dist/schemas/Field.d.ts +10 -10
- package/dist/sdk.test.js +121 -1
- package/dist/types/sdk.d.ts +3 -0
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/url-utils.d.ts +19 -0
- package/dist/utils/url-utils.d.ts.map +1 -0
- package/dist/utils/url-utils.js +62 -0
- package/dist/utils/url-utils.test.d.ts +2 -0
- package/dist/utils/url-utils.test.d.ts.map +1 -0
- package/dist/utils/url-utils.test.js +103 -0
- package/package.json +8 -3
- package/src/api/auth.ts +0 -28
- package/src/api/client.ts +0 -491
- package/src/api/debug.test.ts +0 -76
- package/src/api/debug.ts +0 -154
- package/src/api/index.ts +0 -90
- package/src/api/polling.test.ts +0 -405
- package/src/api/polling.ts +0 -253
- package/src/api/schemas.ts +0 -465
- package/src/api/types.ts +0 -152
- package/src/auth.ts +0 -72
- package/src/constants.ts +0 -16
- package/src/index.ts +0 -111
- package/src/plugins/api/index.ts +0 -43
- package/src/plugins/apps/index.ts +0 -203
- package/src/plugins/apps/schemas.ts +0 -64
- package/src/plugins/eventEmission/builders.ts +0 -115
- package/src/plugins/eventEmission/index.test.ts +0 -169
- package/src/plugins/eventEmission/index.ts +0 -294
- package/src/plugins/eventEmission/transport.test.ts +0 -214
- package/src/plugins/eventEmission/transport.ts +0 -135
- package/src/plugins/eventEmission/types.ts +0 -58
- package/src/plugins/eventEmission/utils.ts +0 -121
- package/src/plugins/fetch/index.ts +0 -83
- package/src/plugins/fetch/schemas.ts +0 -37
- package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
- package/src/plugins/findFirstAuthentication/index.ts +0 -68
- package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
- package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
- package/src/plugins/findUniqueAuthentication/index.ts +0 -77
- package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
- package/src/plugins/getAction/index.test.ts +0 -239
- package/src/plugins/getAction/index.ts +0 -75
- package/src/plugins/getAction/schemas.ts +0 -41
- package/src/plugins/getApp/index.test.ts +0 -181
- package/src/plugins/getApp/index.ts +0 -60
- package/src/plugins/getApp/schemas.ts +0 -33
- package/src/plugins/getAuthentication/index.test.ts +0 -294
- package/src/plugins/getAuthentication/index.ts +0 -95
- package/src/plugins/getAuthentication/schemas.ts +0 -38
- package/src/plugins/getProfile/index.ts +0 -60
- package/src/plugins/getProfile/schemas.ts +0 -24
- package/src/plugins/listActions/index.test.ts +0 -526
- package/src/plugins/listActions/index.ts +0 -132
- package/src/plugins/listActions/schemas.ts +0 -55
- package/src/plugins/listApps/index.test.ts +0 -378
- package/src/plugins/listApps/index.ts +0 -159
- package/src/plugins/listApps/schemas.ts +0 -41
- package/src/plugins/listAuthentications/index.test.ts +0 -739
- package/src/plugins/listAuthentications/index.ts +0 -152
- package/src/plugins/listAuthentications/schemas.ts +0 -77
- package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
- package/src/plugins/listInputFieldChoices/index.ts +0 -173
- package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
- package/src/plugins/listInputFields/index.test.ts +0 -439
- package/src/plugins/listInputFields/index.ts +0 -294
- package/src/plugins/listInputFields/schemas.ts +0 -68
- package/src/plugins/manifest/index.test.ts +0 -776
- package/src/plugins/manifest/index.ts +0 -461
- package/src/plugins/manifest/schemas.ts +0 -60
- package/src/plugins/registry/index.ts +0 -160
- package/src/plugins/request/index.test.ts +0 -333
- package/src/plugins/request/index.ts +0 -105
- package/src/plugins/request/schemas.ts +0 -69
- package/src/plugins/runAction/index.test.ts +0 -388
- package/src/plugins/runAction/index.ts +0 -215
- package/src/plugins/runAction/schemas.ts +0 -60
- package/src/resolvers/actionKey.ts +0 -37
- package/src/resolvers/actionType.ts +0 -34
- package/src/resolvers/appKey.ts +0 -7
- package/src/resolvers/authenticationId.ts +0 -54
- package/src/resolvers/index.ts +0 -11
- package/src/resolvers/inputFieldKey.ts +0 -70
- package/src/resolvers/inputs.ts +0 -69
- package/src/schemas/Action.ts +0 -52
- package/src/schemas/App.ts +0 -45
- package/src/schemas/Auth.ts +0 -59
- package/src/schemas/Field.ts +0 -169
- package/src/schemas/Run.ts +0 -40
- package/src/schemas/UserProfile.ts +0 -60
- package/src/sdk.test.ts +0 -212
- package/src/sdk.ts +0 -178
- package/src/types/domain.test.ts +0 -50
- package/src/types/domain.ts +0 -66
- package/src/types/errors.ts +0 -278
- package/src/types/events.ts +0 -43
- package/src/types/functions.ts +0 -28
- package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
- package/src/types/plugin.ts +0 -125
- package/src/types/properties.ts +0 -80
- package/src/types/sdk.ts +0 -111
- package/src/types/telemetry-events.ts +0 -85
- package/src/utils/array-utils.test.ts +0 -131
- package/src/utils/array-utils.ts +0 -41
- package/src/utils/domain-utils.test.ts +0 -433
- package/src/utils/domain-utils.ts +0 -267
- package/src/utils/file-utils.test.ts +0 -73
- package/src/utils/file-utils.ts +0 -94
- package/src/utils/function-utils.test.ts +0 -141
- package/src/utils/function-utils.ts +0 -245
- package/src/utils/pagination-utils.test.ts +0 -620
- package/src/utils/pagination-utils.ts +0 -242
- package/src/utils/schema-utils.ts +0 -207
- package/src/utils/string-utils.test.ts +0 -45
- package/src/utils/string-utils.ts +0 -54
- package/src/utils/validation.test.ts +0 -51
- package/src/utils/validation.ts +0 -44
- package/tsconfig.build.json +0 -18
- package/tsconfig.json +0 -20
- package/tsconfig.tsbuildinfo +0 -1
- package/tsup.config.ts +0 -23
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
-
import type { ApiClient } from "../../api";
|
|
3
|
-
import type {
|
|
4
|
-
NeedChoicesRequest,
|
|
5
|
-
NeedChoicesResponse,
|
|
6
|
-
NeedChoices,
|
|
7
|
-
} from "../../api/types";
|
|
8
|
-
import type { InputFieldChoiceItem } from "./schemas";
|
|
9
|
-
import {
|
|
10
|
-
ListInputFieldChoicesSchema,
|
|
11
|
-
type ListInputFieldChoicesOptions,
|
|
12
|
-
type ListInputFieldChoicesPage,
|
|
13
|
-
InputFieldChoiceItemSchema,
|
|
14
|
-
} from "./schemas";
|
|
15
|
-
import { ZapierApiError } from "../../types/errors";
|
|
16
|
-
import { createPaginatedFunction } from "../../utils/function-utils";
|
|
17
|
-
import type { GetActionPluginProvides } from "../getAction";
|
|
18
|
-
import {
|
|
19
|
-
appKeyResolver,
|
|
20
|
-
actionTypeResolver,
|
|
21
|
-
actionKeyResolver,
|
|
22
|
-
authenticationIdResolver,
|
|
23
|
-
inputFieldKeyResolver,
|
|
24
|
-
inputsAllOptionalResolver,
|
|
25
|
-
} from "../../resolvers";
|
|
26
|
-
|
|
27
|
-
// Transform NeedChoices to InputFieldChoiceItem
|
|
28
|
-
function transformNeedChoicesToInputFieldChoiceItem(
|
|
29
|
-
choice: NeedChoices,
|
|
30
|
-
): InputFieldChoiceItem {
|
|
31
|
-
return {
|
|
32
|
-
key: choice.key,
|
|
33
|
-
label: choice.label,
|
|
34
|
-
sample: choice.sample,
|
|
35
|
-
value: choice.value,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface ListInputFieldChoicesPluginProvides {
|
|
40
|
-
listInputFieldChoices: (options: ListInputFieldChoicesOptions) => Promise<{
|
|
41
|
-
data: InputFieldChoiceItem[];
|
|
42
|
-
nextCursor?: string;
|
|
43
|
-
}> &
|
|
44
|
-
AsyncIterable<{ data: InputFieldChoiceItem[]; nextCursor?: string }> & {
|
|
45
|
-
items(): AsyncIterable<InputFieldChoiceItem>;
|
|
46
|
-
};
|
|
47
|
-
context: {
|
|
48
|
-
meta: {
|
|
49
|
-
listInputFieldChoices: {
|
|
50
|
-
inputSchema: typeof ListInputFieldChoicesSchema;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const listInputFieldChoicesPlugin: Plugin<
|
|
57
|
-
GetSdkType<GetActionPluginProvides>, // requires getAction in SDK
|
|
58
|
-
{ api: ApiClient }, // requires api in context
|
|
59
|
-
ListInputFieldChoicesPluginProvides
|
|
60
|
-
> = ({ context, sdk }) => {
|
|
61
|
-
const listInputFieldChoices = createPaginatedFunction<
|
|
62
|
-
ListInputFieldChoicesOptions & { cursor?: string },
|
|
63
|
-
ListInputFieldChoicesPage,
|
|
64
|
-
ListInputFieldChoicesOptions
|
|
65
|
-
>(async function listInputFieldChoicesPage(
|
|
66
|
-
options: ListInputFieldChoicesOptions & { cursor?: string } & {
|
|
67
|
-
pageSize: number;
|
|
68
|
-
},
|
|
69
|
-
): Promise<ListInputFieldChoicesPage> {
|
|
70
|
-
const { api } = context;
|
|
71
|
-
|
|
72
|
-
// Extract parameters
|
|
73
|
-
const {
|
|
74
|
-
appKey,
|
|
75
|
-
actionType,
|
|
76
|
-
actionKey,
|
|
77
|
-
inputFieldKey,
|
|
78
|
-
authenticationId,
|
|
79
|
-
inputs,
|
|
80
|
-
page,
|
|
81
|
-
cursor,
|
|
82
|
-
} = options;
|
|
83
|
-
|
|
84
|
-
// Use sdk.getAction to get the action ID
|
|
85
|
-
const actionResult = await sdk.getAction({ appKey, actionType, actionKey });
|
|
86
|
-
const actionId = actionResult.data.id;
|
|
87
|
-
|
|
88
|
-
if (!actionId) {
|
|
89
|
-
throw new ZapierApiError(
|
|
90
|
-
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Build choices request using action ID from getAction
|
|
95
|
-
// Use cursor (from pagination) as page number if available, otherwise use explicit page or default to 0
|
|
96
|
-
const requestPage = cursor ? parseInt(cursor, 10) : (page ?? 0);
|
|
97
|
-
const choicesRequest: NeedChoicesRequest = {
|
|
98
|
-
action_id: actionId,
|
|
99
|
-
input_field_id: inputFieldKey,
|
|
100
|
-
page: requestPage,
|
|
101
|
-
params: inputs || {},
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// Only include authentication_id if it's not null (skip authentication when null)
|
|
105
|
-
if (authenticationId !== null) {
|
|
106
|
-
choicesRequest.authentication_id = authenticationId;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const choicesData: NeedChoicesResponse = await api.post(
|
|
110
|
-
"/api/v4/implementations/choices/",
|
|
111
|
-
choicesRequest,
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
if (!choicesData.success) {
|
|
115
|
-
throw new ZapierApiError(
|
|
116
|
-
`Failed to get input field choices: ${
|
|
117
|
-
choicesData.errors?.join(", ") || "Unknown error"
|
|
118
|
-
}`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Transform NeedChoices objects to InputFieldChoiceItem objects
|
|
123
|
-
const choices: InputFieldChoiceItem[] = (choicesData.choices || []).map(
|
|
124
|
-
transformNeedChoicesToInputFieldChoiceItem,
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
// Handle pagination
|
|
128
|
-
let nextCursor: string | undefined;
|
|
129
|
-
if (choicesData.next_page != null) {
|
|
130
|
-
nextCursor = choicesData.next_page.toString();
|
|
131
|
-
} else if (choicesData.links?.next) {
|
|
132
|
-
// Extract page from next URL for external actions
|
|
133
|
-
try {
|
|
134
|
-
const nextUrl = new URL(choicesData.links.next);
|
|
135
|
-
const nextPage = nextUrl.searchParams.get("page");
|
|
136
|
-
if (nextPage) {
|
|
137
|
-
nextCursor = nextPage;
|
|
138
|
-
}
|
|
139
|
-
} catch {
|
|
140
|
-
// Handle malformed URLs gracefully by not setting nextCursor
|
|
141
|
-
nextCursor = undefined;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
data: choices,
|
|
147
|
-
nextCursor,
|
|
148
|
-
};
|
|
149
|
-
}, ListInputFieldChoicesSchema);
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
listInputFieldChoices,
|
|
153
|
-
context: {
|
|
154
|
-
meta: {
|
|
155
|
-
listInputFieldChoices: {
|
|
156
|
-
categories: ["action"],
|
|
157
|
-
type: "list",
|
|
158
|
-
itemType: "InputFieldChoice",
|
|
159
|
-
inputSchema: ListInputFieldChoicesSchema,
|
|
160
|
-
outputSchema: InputFieldChoiceItemSchema,
|
|
161
|
-
resolvers: {
|
|
162
|
-
appKey: appKeyResolver,
|
|
163
|
-
actionType: actionTypeResolver,
|
|
164
|
-
actionKey: actionKeyResolver,
|
|
165
|
-
authenticationId: authenticationIdResolver,
|
|
166
|
-
inputFieldKey: inputFieldKeyResolver,
|
|
167
|
-
inputs: inputsAllOptionalResolver,
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
AuthenticationIdPropertySchema,
|
|
4
|
-
AppKeyPropertySchema,
|
|
5
|
-
ActionTypePropertySchema,
|
|
6
|
-
ActionKeyPropertySchema,
|
|
7
|
-
InputsPropertySchema,
|
|
8
|
-
} from "../../types/properties";
|
|
9
|
-
import { withFormatter } from "../../utils/schema-utils";
|
|
10
|
-
import { NeedChoicesSchema } from "../../api/schemas";
|
|
11
|
-
import type { PaginatedSdkFunction } from "../../types/functions";
|
|
12
|
-
import type {
|
|
13
|
-
ZapierConfigurationError,
|
|
14
|
-
ZapierApiError,
|
|
15
|
-
ZapierAuthenticationError,
|
|
16
|
-
ZapierAppNotFoundError,
|
|
17
|
-
ZapierValidationError,
|
|
18
|
-
ZapierUnknownError,
|
|
19
|
-
} from "../../types/errors";
|
|
20
|
-
|
|
21
|
-
// ============================================================================
|
|
22
|
-
// Input Field Choice Item Schema
|
|
23
|
-
// ============================================================================
|
|
24
|
-
|
|
25
|
-
export const InputFieldChoiceItemSchema = withFormatter(NeedChoicesSchema, {
|
|
26
|
-
format: (item) => {
|
|
27
|
-
const title = item.label || item.key || "Choice";
|
|
28
|
-
const details: Array<{
|
|
29
|
-
text: string;
|
|
30
|
-
style: "success" | "dim" | "normal" | "accent" | "warning";
|
|
31
|
-
}> = [];
|
|
32
|
-
|
|
33
|
-
// Show key as detail if different from label
|
|
34
|
-
if (item.label && item.key && item.label !== item.key) {
|
|
35
|
-
details.push({ text: `Key: ${item.key}`, style: "dim" });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (item.sample && item.sample !== item.key) {
|
|
39
|
-
details.push({ text: `Sample: ${item.sample}`, style: "dim" });
|
|
40
|
-
}
|
|
41
|
-
if (item.value && item.value !== item.key) {
|
|
42
|
-
details.push({ text: `Value: ${item.value}`, style: "normal" });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
title,
|
|
47
|
-
key: item.key,
|
|
48
|
-
details,
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export type InputFieldChoiceItem = z.infer<typeof InputFieldChoiceItemSchema>;
|
|
54
|
-
|
|
55
|
-
// ============================================================================
|
|
56
|
-
// Plugin Schema Definition
|
|
57
|
-
// ============================================================================
|
|
58
|
-
|
|
59
|
-
export const ListInputFieldChoicesSchema = z
|
|
60
|
-
.object({
|
|
61
|
-
// Required action identification
|
|
62
|
-
appKey: AppKeyPropertySchema,
|
|
63
|
-
actionType: ActionTypePropertySchema,
|
|
64
|
-
actionKey: ActionKeyPropertySchema,
|
|
65
|
-
|
|
66
|
-
// Input field specification
|
|
67
|
-
inputFieldKey: z
|
|
68
|
-
.string()
|
|
69
|
-
.min(1)
|
|
70
|
-
.describe("Input field key to get choices for."),
|
|
71
|
-
|
|
72
|
-
// Common parameters
|
|
73
|
-
authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
|
|
74
|
-
inputs: InputsPropertySchema.optional().describe(
|
|
75
|
-
"Current input values that may affect available choices",
|
|
76
|
-
),
|
|
77
|
-
page: z
|
|
78
|
-
.number()
|
|
79
|
-
.int()
|
|
80
|
-
.min(0)
|
|
81
|
-
.optional()
|
|
82
|
-
.describe("Page number for paginated results"),
|
|
83
|
-
|
|
84
|
-
// Pagination options (SDK-level)
|
|
85
|
-
pageSize: z
|
|
86
|
-
.number()
|
|
87
|
-
.min(1)
|
|
88
|
-
.optional()
|
|
89
|
-
.describe("Number of choices per page"),
|
|
90
|
-
maxItems: z
|
|
91
|
-
.number()
|
|
92
|
-
.min(1)
|
|
93
|
-
.optional()
|
|
94
|
-
.describe("Maximum total items to return across all pages"),
|
|
95
|
-
cursor: z.string().optional().describe("Cursor to start from"),
|
|
96
|
-
})
|
|
97
|
-
.describe("Get the available choices for a dynamic dropdown input field");
|
|
98
|
-
|
|
99
|
-
// Type inferred from schema
|
|
100
|
-
export type ListInputFieldChoicesOptions = z.infer<
|
|
101
|
-
typeof ListInputFieldChoicesSchema
|
|
102
|
-
>;
|
|
103
|
-
|
|
104
|
-
// Error union for this function
|
|
105
|
-
export type ListInputFieldChoicesError =
|
|
106
|
-
| ZapierConfigurationError
|
|
107
|
-
| ZapierApiError
|
|
108
|
-
| ZapierAuthenticationError
|
|
109
|
-
| ZapierAppNotFoundError
|
|
110
|
-
| ZapierValidationError
|
|
111
|
-
| ZapierUnknownError;
|
|
112
|
-
|
|
113
|
-
// Page result structure
|
|
114
|
-
export interface ListInputFieldChoicesPage {
|
|
115
|
-
data: InputFieldChoiceItem[];
|
|
116
|
-
nextCursor?: string;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// SDK function interface
|
|
120
|
-
export interface ListInputFieldChoicesSdkFunction {
|
|
121
|
-
listInputFieldChoices: PaginatedSdkFunction<
|
|
122
|
-
ListInputFieldChoicesOptions,
|
|
123
|
-
InputFieldChoiceItem
|
|
124
|
-
>;
|
|
125
|
-
}
|