@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,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
- }