@zapier/zapier-sdk 0.13.5 → 0.13.7

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.
Files changed (129) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api/schemas.d.ts +38 -38
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.mts +170 -177
  5. package/dist/index.mjs +1 -1
  6. package/dist/plugins/fetch/schemas.d.ts +4 -4
  7. package/dist/plugins/getAction/schemas.d.ts +2 -2
  8. package/dist/plugins/listActions/schemas.d.ts +6 -6
  9. package/dist/plugins/listApps/schemas.d.ts +6 -6
  10. package/dist/plugins/listAuthentications/schemas.d.ts +4 -4
  11. package/dist/plugins/listInputFieldChoices/schemas.d.ts +8 -8
  12. package/dist/plugins/listInputFields/schemas.d.ts +8 -8
  13. package/dist/plugins/request/schemas.d.ts +8 -8
  14. package/dist/plugins/runAction/schemas.d.ts +8 -8
  15. package/dist/schemas/Action.d.ts +2 -2
  16. package/dist/schemas/App.d.ts +8 -8
  17. package/dist/types/sdk.d.ts +2 -8
  18. package/dist/types/sdk.d.ts.map +1 -1
  19. package/package.json +8 -3
  20. package/src/api/auth.ts +0 -28
  21. package/src/api/client.ts +0 -491
  22. package/src/api/debug.test.ts +0 -76
  23. package/src/api/debug.ts +0 -154
  24. package/src/api/index.ts +0 -90
  25. package/src/api/polling.test.ts +0 -405
  26. package/src/api/polling.ts +0 -253
  27. package/src/api/schemas.ts +0 -465
  28. package/src/api/types.ts +0 -152
  29. package/src/auth.ts +0 -72
  30. package/src/constants.ts +0 -16
  31. package/src/index.ts +0 -111
  32. package/src/plugins/api/index.ts +0 -43
  33. package/src/plugins/apps/index.ts +0 -203
  34. package/src/plugins/apps/schemas.ts +0 -64
  35. package/src/plugins/eventEmission/builders.ts +0 -115
  36. package/src/plugins/eventEmission/index.test.ts +0 -169
  37. package/src/plugins/eventEmission/index.ts +0 -294
  38. package/src/plugins/eventEmission/transport.test.ts +0 -214
  39. package/src/plugins/eventEmission/transport.ts +0 -135
  40. package/src/plugins/eventEmission/types.ts +0 -58
  41. package/src/plugins/eventEmission/utils.ts +0 -121
  42. package/src/plugins/fetch/index.ts +0 -83
  43. package/src/plugins/fetch/schemas.ts +0 -37
  44. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  45. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  46. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  47. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  48. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  49. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  50. package/src/plugins/getAction/index.test.ts +0 -239
  51. package/src/plugins/getAction/index.ts +0 -75
  52. package/src/plugins/getAction/schemas.ts +0 -41
  53. package/src/plugins/getApp/index.test.ts +0 -181
  54. package/src/plugins/getApp/index.ts +0 -60
  55. package/src/plugins/getApp/schemas.ts +0 -33
  56. package/src/plugins/getAuthentication/index.test.ts +0 -294
  57. package/src/plugins/getAuthentication/index.ts +0 -95
  58. package/src/plugins/getAuthentication/schemas.ts +0 -38
  59. package/src/plugins/getProfile/index.ts +0 -60
  60. package/src/plugins/getProfile/schemas.ts +0 -24
  61. package/src/plugins/listActions/index.test.ts +0 -526
  62. package/src/plugins/listActions/index.ts +0 -132
  63. package/src/plugins/listActions/schemas.ts +0 -55
  64. package/src/plugins/listApps/index.test.ts +0 -378
  65. package/src/plugins/listApps/index.ts +0 -159
  66. package/src/plugins/listApps/schemas.ts +0 -41
  67. package/src/plugins/listAuthentications/index.test.ts +0 -739
  68. package/src/plugins/listAuthentications/index.ts +0 -152
  69. package/src/plugins/listAuthentications/schemas.ts +0 -77
  70. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  71. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  72. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  73. package/src/plugins/listInputFields/index.test.ts +0 -439
  74. package/src/plugins/listInputFields/index.ts +0 -294
  75. package/src/plugins/listInputFields/schemas.ts +0 -68
  76. package/src/plugins/manifest/index.test.ts +0 -776
  77. package/src/plugins/manifest/index.ts +0 -461
  78. package/src/plugins/manifest/schemas.ts +0 -60
  79. package/src/plugins/registry/index.ts +0 -160
  80. package/src/plugins/request/index.test.ts +0 -333
  81. package/src/plugins/request/index.ts +0 -105
  82. package/src/plugins/request/schemas.ts +0 -69
  83. package/src/plugins/runAction/index.test.ts +0 -388
  84. package/src/plugins/runAction/index.ts +0 -215
  85. package/src/plugins/runAction/schemas.ts +0 -60
  86. package/src/resolvers/actionKey.ts +0 -37
  87. package/src/resolvers/actionType.ts +0 -34
  88. package/src/resolvers/appKey.ts +0 -7
  89. package/src/resolvers/authenticationId.ts +0 -54
  90. package/src/resolvers/index.ts +0 -11
  91. package/src/resolvers/inputFieldKey.ts +0 -70
  92. package/src/resolvers/inputs.ts +0 -69
  93. package/src/schemas/Action.ts +0 -52
  94. package/src/schemas/App.ts +0 -45
  95. package/src/schemas/Auth.ts +0 -59
  96. package/src/schemas/Field.ts +0 -169
  97. package/src/schemas/Run.ts +0 -40
  98. package/src/schemas/UserProfile.ts +0 -60
  99. package/src/sdk.test.ts +0 -212
  100. package/src/sdk.ts +0 -178
  101. package/src/types/domain.test.ts +0 -50
  102. package/src/types/domain.ts +0 -66
  103. package/src/types/errors.ts +0 -278
  104. package/src/types/events.ts +0 -43
  105. package/src/types/functions.ts +0 -28
  106. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  107. package/src/types/plugin.ts +0 -125
  108. package/src/types/properties.ts +0 -80
  109. package/src/types/sdk.ts +0 -117
  110. package/src/types/telemetry-events.ts +0 -85
  111. package/src/utils/array-utils.test.ts +0 -131
  112. package/src/utils/array-utils.ts +0 -41
  113. package/src/utils/domain-utils.test.ts +0 -433
  114. package/src/utils/domain-utils.ts +0 -267
  115. package/src/utils/file-utils.test.ts +0 -73
  116. package/src/utils/file-utils.ts +0 -94
  117. package/src/utils/function-utils.test.ts +0 -141
  118. package/src/utils/function-utils.ts +0 -245
  119. package/src/utils/pagination-utils.test.ts +0 -620
  120. package/src/utils/pagination-utils.ts +0 -242
  121. package/src/utils/schema-utils.ts +0 -207
  122. package/src/utils/string-utils.test.ts +0 -45
  123. package/src/utils/string-utils.ts +0 -54
  124. package/src/utils/validation.test.ts +0 -51
  125. package/src/utils/validation.ts +0 -44
  126. package/tsconfig.build.json +0 -18
  127. package/tsconfig.json +0 -20
  128. package/tsconfig.tsbuildinfo +0 -1
  129. package/tsup.config.ts +0 -23
@@ -1,294 +0,0 @@
1
- import type { Plugin, GetSdkType } from "../../types/plugin";
2
- import type { ApiClient } from "../../api";
3
- import type { NeedsRequest, NeedsResponse, Need } from "../../api/types";
4
- import type {
5
- InputFieldItem,
6
- InfoFieldItem,
7
- FieldsetItem,
8
- RootFieldItem,
9
- } from "../../types/domain";
10
- import {
11
- ListInputFieldsSchema,
12
- type ListInputFieldsOptions,
13
- type ListInputFieldsPage,
14
- } from "./schemas";
15
- import { ZapierConfigurationError, ZapierApiError } from "../../types/errors";
16
- import { createPaginatedFunction } from "../../utils/function-utils";
17
- import type { GetAppPluginProvides } from "../getApp";
18
- import type { GetActionPluginProvides } from "../getAction";
19
- import type { GetVersionedImplementationId } from "../manifest/schemas";
20
- import {
21
- appKeyResolver,
22
- actionTypeResolver,
23
- actionKeyResolver,
24
- authenticationIdResolver,
25
- inputsAllOptionalResolver,
26
- } from "../../resolvers";
27
- import { RootFieldItemSchema } from "../../schemas/Field";
28
- import { toTitleCase } from "../../utils/string-utils";
29
-
30
- // Enums for input field transformation
31
- enum InputFieldType {
32
- STRING = "STRING",
33
- NUMBER = "NUMBER",
34
- INTEGER = "INTEGER",
35
- BOOLEAN = "BOOLEAN",
36
- OBJECT = "OBJECT",
37
- ARRAY = "ARRAY",
38
- }
39
-
40
- enum InputFieldFormat {
41
- DATETIME = "DATETIME",
42
- SELECT = "SELECT",
43
- MULTILINE = "MULTILINE",
44
- FILE = "FILE",
45
- PASSWORD = "PASSWORD",
46
- CODE = "CODE",
47
- }
48
-
49
- enum ItemsType {
50
- STRING = "STRING",
51
- NUMBER = "NUMBER",
52
- INTEGER = "INTEGER",
53
- BOOLEAN = "BOOLEAN",
54
- OBJECT = "OBJECT",
55
- }
56
-
57
- // Transformation helper functions
58
- function getInputFieldTypeFromNeed(need: Need): InputFieldType {
59
- if (need.list) {
60
- return InputFieldType.ARRAY;
61
- }
62
-
63
- const typeMap: Record<string, InputFieldType> = {
64
- string: InputFieldType.STRING,
65
- decimal: InputFieldType.NUMBER,
66
- integer: InputFieldType.INTEGER,
67
- boolean: InputFieldType.BOOLEAN,
68
- dict: InputFieldType.OBJECT,
69
- };
70
-
71
- return typeMap[need.type || ""] || InputFieldType.STRING;
72
- }
73
-
74
- function getInputFieldFormatFromNeed(need: Need): InputFieldFormat | undefined {
75
- if (need.prefill || need.choices) {
76
- return InputFieldFormat.SELECT;
77
- }
78
-
79
- const formatMap: Record<string, InputFieldFormat> = {
80
- text: InputFieldFormat.MULTILINE,
81
- datetime: InputFieldFormat.DATETIME,
82
- file: InputFieldFormat.FILE,
83
- password: InputFieldFormat.PASSWORD,
84
- code: InputFieldFormat.CODE,
85
- };
86
-
87
- return formatMap[need.type || ""];
88
- }
89
-
90
- function getItemsTypeFromNeed(need: Need): ItemsType | undefined {
91
- if (!need.list) {
92
- return undefined;
93
- }
94
-
95
- const typeMap: Record<string, ItemsType> = {
96
- string: ItemsType.STRING,
97
- decimal: ItemsType.NUMBER,
98
- integer: ItemsType.INTEGER,
99
- boolean: ItemsType.BOOLEAN,
100
- dict: ItemsType.OBJECT,
101
- };
102
-
103
- return typeMap[need.type || ""] || ItemsType.STRING;
104
- }
105
-
106
- // Transform Need to InputFieldItem
107
- function transformNeedToInputFieldItem(need: Need): InputFieldItem {
108
- const itemsType = getItemsTypeFromNeed(need);
109
-
110
- return {
111
- type: "input_field",
112
- key: need.key,
113
- default_value: need.default || "",
114
- depends_on: need.depends_on || [],
115
- description: need.help_text || "",
116
- invalidates_input_fields: need.alters_custom_fields || false,
117
- is_required: need.required || false,
118
- placeholder: need.placeholder || "",
119
- title: need.label || "",
120
- value_type: getInputFieldTypeFromNeed(need),
121
- format: getInputFieldFormatFromNeed(need),
122
- items: itemsType ? { type: itemsType } : undefined,
123
- };
124
- }
125
-
126
- // Transform Need to InfoFieldItem (for copy fields)
127
- function transformNeedToInfoFieldItem(need: Need): InfoFieldItem {
128
- return {
129
- type: "info_field",
130
- key: need.key,
131
- description: need.help_text || "",
132
- title: need.label,
133
- };
134
- }
135
-
136
- // Transform needs to fields (similar to partnerapi compute_root_fieldset_from_needs)
137
- function transformNeedsToFields(needs: Need[]): RootFieldItem[] {
138
- const rootFields: (InputFieldItem | InfoFieldItem | FieldsetItem)[] = [];
139
- const fieldsetMap = new Map<string, FieldsetItem>();
140
-
141
- for (const need of needs) {
142
- if (need.computed) {
143
- // Computed needs (i.e zap_id for CodeAPI steps) are not shown by the
144
- // editor, hide them here too.
145
- continue;
146
- }
147
-
148
- // If parent_key is set, we need to ensure that a corresponding
149
- // fieldset exists, since we'll be adding this need to that fieldset
150
- if (need.parent_key) {
151
- let fieldset = fieldsetMap.get(need.parent_key);
152
- if (!fieldset) {
153
- fieldset = {
154
- type: "fieldset",
155
- key: need.parent_key,
156
- title: toTitleCase(need.parent_key),
157
- fields: [],
158
- };
159
- fieldsetMap.set(need.parent_key, fieldset);
160
- rootFields.push(fieldset);
161
- }
162
-
163
- // Add field to fieldset
164
- if (need.type === "copy" && need.help_text) {
165
- fieldset.fields.push(transformNeedToInfoFieldItem(need));
166
- } else {
167
- fieldset.fields.push(transformNeedToInputFieldItem(need));
168
- }
169
- } else {
170
- // Add field to root
171
- if (need.type === "copy" && need.help_text) {
172
- rootFields.push(transformNeedToInfoFieldItem(need));
173
- } else {
174
- rootFields.push(transformNeedToInputFieldItem(need));
175
- }
176
- }
177
- }
178
-
179
- return rootFields;
180
- }
181
-
182
- export interface ListInputFieldsPluginProvides {
183
- listInputFields: (options?: ListInputFieldsOptions) => Promise<{
184
- data: RootFieldItem[];
185
- nextCursor?: string;
186
- }> &
187
- AsyncIterable<{ data: RootFieldItem[]; nextCursor?: string }> & {
188
- items(): AsyncIterable<InputFieldItem | InfoFieldItem | FieldsetItem>;
189
- };
190
- context: {
191
- meta: {
192
- listInputFields: {
193
- inputSchema: typeof ListInputFieldsSchema;
194
- };
195
- };
196
- };
197
- }
198
-
199
- export const listInputFieldsPlugin: Plugin<
200
- GetSdkType<GetAppPluginProvides & GetActionPluginProvides>, // requires getApp and getAction in SDK
201
- {
202
- api: ApiClient;
203
- getVersionedImplementationId: GetVersionedImplementationId;
204
- }, // requires api and getVersionedImplementationId in context
205
- ListInputFieldsPluginProvides
206
- > = ({ sdk, context }) => {
207
- const listInputFields = createPaginatedFunction(
208
- async function listInputFieldsPage(
209
- options: ListInputFieldsOptions & { cursor?: string } & {
210
- pageSize: number;
211
- },
212
- ): Promise<ListInputFieldsPage> {
213
- // Note: This function ignores pageSize and cursor since it's not actually paginated internally
214
- const { api, getVersionedImplementationId } = context;
215
-
216
- // Extract parameters
217
- const { appKey, actionKey, actionType, authenticationId, inputs } =
218
- options;
219
-
220
- // Use the manifest plugin
221
- const selectedApi = await getVersionedImplementationId(appKey);
222
-
223
- if (!selectedApi) {
224
- throw new ZapierConfigurationError(
225
- "No current_implementation_id found for app",
226
- { configType: "current_implementation_id" },
227
- );
228
- }
229
-
230
- const { data: action } = await sdk.getAction({
231
- appKey,
232
- actionType,
233
- actionKey,
234
- });
235
-
236
- // Build needs request
237
- const needsRequest: NeedsRequest = {
238
- selected_api: selectedApi,
239
- action: action.key,
240
- type_of: actionType,
241
- params: inputs || {},
242
- };
243
-
244
- // Only include authentication_id if it's not null (skip authentication when null)
245
- if (authenticationId !== null) {
246
- needsRequest.authentication_id = authenticationId;
247
- }
248
-
249
- const needsData: NeedsResponse = await api.post(
250
- "/api/v4/implementations/needs/",
251
- needsRequest,
252
- );
253
-
254
- if (!needsData.success) {
255
- throw new ZapierApiError(
256
- `Failed to get action fields: ${
257
- needsData.errors?.join(", ") || "Unknown error"
258
- }`,
259
- );
260
- }
261
-
262
- // Transform Need objects to Root Fieldset with proper nesting
263
- const rootFieldset = transformNeedsToFields(needsData.needs || []);
264
-
265
- return {
266
- data: rootFieldset,
267
- nextCursor: undefined, // No pagination needed since we return all input fields
268
- };
269
- },
270
- ListInputFieldsSchema,
271
- );
272
-
273
- return {
274
- listInputFields,
275
- context: {
276
- meta: {
277
- listInputFields: {
278
- categories: ["action"],
279
- type: "list",
280
- itemType: "RootFieldItem",
281
- inputSchema: ListInputFieldsSchema,
282
- outputSchema: RootFieldItemSchema,
283
- resolvers: {
284
- appKey: appKeyResolver,
285
- actionType: actionTypeResolver,
286
- actionKey: actionKeyResolver,
287
- authenticationId: authenticationIdResolver,
288
- inputs: inputsAllOptionalResolver,
289
- },
290
- },
291
- },
292
- },
293
- };
294
- };
@@ -1,68 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- AppKeyPropertySchema,
4
- ActionTypePropertySchema,
5
- ActionKeyPropertySchema,
6
- AuthenticationIdPropertySchema,
7
- InputsPropertySchema,
8
- } from "../../types/properties";
9
- import type { RootFieldItem } from "../../types/domain";
10
- import type { PaginatedSdkFunction } from "../../types/functions";
11
- import type {
12
- ZapierConfigurationError,
13
- ZapierApiError,
14
- ZapierAuthenticationError,
15
- ZapierAppNotFoundError,
16
- ZapierValidationError,
17
- ZapierUnknownError,
18
- } from "../../types/errors";
19
-
20
- // Pure Zod schema - no resolver metadata!
21
- export const ListInputFieldsSchema = z
22
- .object({
23
- appKey: AppKeyPropertySchema,
24
- actionType: ActionTypePropertySchema,
25
- actionKey: ActionKeyPropertySchema,
26
- authenticationId: AuthenticationIdPropertySchema.nullable().optional(),
27
- inputs: InputsPropertySchema.optional().describe(
28
- "Current input values that may affect available fields",
29
- ),
30
- pageSize: z
31
- .number()
32
- .min(1)
33
- .optional()
34
- .describe("Number of input fields per page"),
35
- maxItems: z
36
- .number()
37
- .min(1)
38
- .optional()
39
- .describe("Maximum total items to return across all pages"),
40
- cursor: z.string().optional().describe("Cursor to start from"),
41
- })
42
- .describe("Get the input fields required for a specific action");
43
-
44
- // Type inferred from schema
45
- export type ListInputFieldsOptions = z.infer<typeof ListInputFieldsSchema>;
46
-
47
- // Error union for this function
48
- export type ListInputFieldsError =
49
- | ZapierConfigurationError
50
- | ZapierApiError
51
- | ZapierAuthenticationError
52
- | ZapierAppNotFoundError
53
- | ZapierValidationError
54
- | ZapierUnknownError;
55
-
56
- // Page result structure
57
- export interface ListInputFieldsPage {
58
- data: RootFieldItem[];
59
- nextCursor?: string;
60
- }
61
-
62
- // SDK function interface
63
- export interface ListInputFieldsSdkFunction {
64
- listInputFields: PaginatedSdkFunction<
65
- ListInputFieldsOptions,
66
- RootFieldItem[]
67
- >;
68
- }