@zapier/zapier-sdk 0.13.6 → 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 (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +7 -2
  5. package/src/api/auth.ts +0 -28
  6. package/src/api/client.ts +0 -491
  7. package/src/api/debug.test.ts +0 -76
  8. package/src/api/debug.ts +0 -154
  9. package/src/api/index.ts +0 -90
  10. package/src/api/polling.test.ts +0 -405
  11. package/src/api/polling.ts +0 -253
  12. package/src/api/schemas.ts +0 -465
  13. package/src/api/types.ts +0 -152
  14. package/src/auth.ts +0 -72
  15. package/src/constants.ts +0 -16
  16. package/src/index.ts +0 -111
  17. package/src/plugins/api/index.ts +0 -43
  18. package/src/plugins/apps/index.ts +0 -203
  19. package/src/plugins/apps/schemas.ts +0 -64
  20. package/src/plugins/eventEmission/builders.ts +0 -115
  21. package/src/plugins/eventEmission/index.test.ts +0 -169
  22. package/src/plugins/eventEmission/index.ts +0 -294
  23. package/src/plugins/eventEmission/transport.test.ts +0 -214
  24. package/src/plugins/eventEmission/transport.ts +0 -135
  25. package/src/plugins/eventEmission/types.ts +0 -58
  26. package/src/plugins/eventEmission/utils.ts +0 -121
  27. package/src/plugins/fetch/index.ts +0 -83
  28. package/src/plugins/fetch/schemas.ts +0 -37
  29. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  30. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  31. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  32. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  33. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  34. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  35. package/src/plugins/getAction/index.test.ts +0 -239
  36. package/src/plugins/getAction/index.ts +0 -75
  37. package/src/plugins/getAction/schemas.ts +0 -41
  38. package/src/plugins/getApp/index.test.ts +0 -181
  39. package/src/plugins/getApp/index.ts +0 -60
  40. package/src/plugins/getApp/schemas.ts +0 -33
  41. package/src/plugins/getAuthentication/index.test.ts +0 -294
  42. package/src/plugins/getAuthentication/index.ts +0 -95
  43. package/src/plugins/getAuthentication/schemas.ts +0 -38
  44. package/src/plugins/getProfile/index.ts +0 -60
  45. package/src/plugins/getProfile/schemas.ts +0 -24
  46. package/src/plugins/listActions/index.test.ts +0 -526
  47. package/src/plugins/listActions/index.ts +0 -132
  48. package/src/plugins/listActions/schemas.ts +0 -55
  49. package/src/plugins/listApps/index.test.ts +0 -378
  50. package/src/plugins/listApps/index.ts +0 -159
  51. package/src/plugins/listApps/schemas.ts +0 -41
  52. package/src/plugins/listAuthentications/index.test.ts +0 -739
  53. package/src/plugins/listAuthentications/index.ts +0 -152
  54. package/src/plugins/listAuthentications/schemas.ts +0 -77
  55. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  56. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  57. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  58. package/src/plugins/listInputFields/index.test.ts +0 -439
  59. package/src/plugins/listInputFields/index.ts +0 -294
  60. package/src/plugins/listInputFields/schemas.ts +0 -68
  61. package/src/plugins/manifest/index.test.ts +0 -776
  62. package/src/plugins/manifest/index.ts +0 -461
  63. package/src/plugins/manifest/schemas.ts +0 -60
  64. package/src/plugins/registry/index.ts +0 -160
  65. package/src/plugins/request/index.test.ts +0 -333
  66. package/src/plugins/request/index.ts +0 -105
  67. package/src/plugins/request/schemas.ts +0 -69
  68. package/src/plugins/runAction/index.test.ts +0 -388
  69. package/src/plugins/runAction/index.ts +0 -215
  70. package/src/plugins/runAction/schemas.ts +0 -60
  71. package/src/resolvers/actionKey.ts +0 -37
  72. package/src/resolvers/actionType.ts +0 -34
  73. package/src/resolvers/appKey.ts +0 -7
  74. package/src/resolvers/authenticationId.ts +0 -54
  75. package/src/resolvers/index.ts +0 -11
  76. package/src/resolvers/inputFieldKey.ts +0 -70
  77. package/src/resolvers/inputs.ts +0 -69
  78. package/src/schemas/Action.ts +0 -52
  79. package/src/schemas/App.ts +0 -45
  80. package/src/schemas/Auth.ts +0 -59
  81. package/src/schemas/Field.ts +0 -169
  82. package/src/schemas/Run.ts +0 -40
  83. package/src/schemas/UserProfile.ts +0 -60
  84. package/src/sdk.test.ts +0 -212
  85. package/src/sdk.ts +0 -178
  86. package/src/types/domain.test.ts +0 -50
  87. package/src/types/domain.ts +0 -66
  88. package/src/types/errors.ts +0 -278
  89. package/src/types/events.ts +0 -43
  90. package/src/types/functions.ts +0 -28
  91. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  92. package/src/types/plugin.ts +0 -125
  93. package/src/types/properties.ts +0 -80
  94. package/src/types/sdk.ts +0 -111
  95. package/src/types/telemetry-events.ts +0 -85
  96. package/src/utils/array-utils.test.ts +0 -131
  97. package/src/utils/array-utils.ts +0 -41
  98. package/src/utils/domain-utils.test.ts +0 -433
  99. package/src/utils/domain-utils.ts +0 -267
  100. package/src/utils/file-utils.test.ts +0 -73
  101. package/src/utils/file-utils.ts +0 -94
  102. package/src/utils/function-utils.test.ts +0 -141
  103. package/src/utils/function-utils.ts +0 -245
  104. package/src/utils/pagination-utils.test.ts +0 -620
  105. package/src/utils/pagination-utils.ts +0 -242
  106. package/src/utils/schema-utils.ts +0 -207
  107. package/src/utils/string-utils.test.ts +0 -45
  108. package/src/utils/string-utils.ts +0 -54
  109. package/src/utils/validation.test.ts +0 -51
  110. package/src/utils/validation.ts +0 -44
  111. package/tsconfig.build.json +0 -18
  112. package/tsconfig.json +0 -20
  113. package/tsconfig.tsbuildinfo +0 -1
  114. 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
- }