@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
package/src/types/errors.ts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard error format returned by the Zapier API
|
|
3
|
-
*/
|
|
4
|
-
export interface ApiError {
|
|
5
|
-
status: number;
|
|
6
|
-
code: string;
|
|
7
|
-
title: string;
|
|
8
|
-
detail: string;
|
|
9
|
-
source?: unknown;
|
|
10
|
-
meta?: unknown;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Base options for all error constructors
|
|
15
|
-
*/
|
|
16
|
-
export interface ErrorOptions {
|
|
17
|
-
statusCode?: number;
|
|
18
|
-
errors?: ApiError[];
|
|
19
|
-
cause?: unknown;
|
|
20
|
-
response?: unknown;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Base class for all Zapier SDK errors
|
|
25
|
-
* Use instanceof ZapierError to check if an error is from the SDK
|
|
26
|
-
*/
|
|
27
|
-
export abstract class ZapierError extends Error {
|
|
28
|
-
abstract readonly name: string;
|
|
29
|
-
public statusCode?: number;
|
|
30
|
-
public errors?: ApiError[];
|
|
31
|
-
public cause?: unknown;
|
|
32
|
-
public response?: unknown;
|
|
33
|
-
|
|
34
|
-
constructor(message: string, options: ErrorOptions = {}) {
|
|
35
|
-
super(message);
|
|
36
|
-
this.statusCode = options.statusCode;
|
|
37
|
-
this.errors = options.errors;
|
|
38
|
-
this.cause = options.cause;
|
|
39
|
-
this.response = options.response;
|
|
40
|
-
// Maintain proper prototype chain for instanceof checks
|
|
41
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Error thrown when API requests fail
|
|
47
|
-
*/
|
|
48
|
-
export class ZapierApiError extends ZapierError {
|
|
49
|
-
readonly name = "ZapierApiError";
|
|
50
|
-
|
|
51
|
-
constructor(message: string, options: ErrorOptions = {}) {
|
|
52
|
-
super(message, options);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Error thrown when an app is not found
|
|
58
|
-
*/
|
|
59
|
-
export class ZapierAppNotFoundError extends ZapierError {
|
|
60
|
-
readonly name = "ZapierAppNotFoundError";
|
|
61
|
-
public appKey?: string;
|
|
62
|
-
|
|
63
|
-
constructor(
|
|
64
|
-
message: string,
|
|
65
|
-
options: ErrorOptions & { appKey?: string } = {},
|
|
66
|
-
) {
|
|
67
|
-
super(message, options);
|
|
68
|
-
this.appKey = options.appKey;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Error thrown when validation fails (e.g., invalid parameters)
|
|
74
|
-
*/
|
|
75
|
-
export class ZapierValidationError extends ZapierError {
|
|
76
|
-
readonly name = "ZapierValidationError";
|
|
77
|
-
public details?: unknown;
|
|
78
|
-
|
|
79
|
-
constructor(
|
|
80
|
-
message: string,
|
|
81
|
-
options: ErrorOptions & { details?: unknown } = {},
|
|
82
|
-
) {
|
|
83
|
-
super(message, options);
|
|
84
|
-
this.details = options.details;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Error for unrecognized/unknown errors that get wrapped by safe functions
|
|
90
|
-
*/
|
|
91
|
-
export class ZapierUnknownError extends ZapierError {
|
|
92
|
-
readonly name = "ZapierUnknownError";
|
|
93
|
-
|
|
94
|
-
constructor(message: string, options: ErrorOptions = {}) {
|
|
95
|
-
super(message, options);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Error thrown for authentication and authorization failures (401/403)
|
|
101
|
-
*/
|
|
102
|
-
export class ZapierAuthenticationError extends ZapierError {
|
|
103
|
-
readonly name = "ZapierAuthenticationError";
|
|
104
|
-
|
|
105
|
-
constructor(message: string, options: ErrorOptions = {}) {
|
|
106
|
-
super(message, options);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Error thrown when a requested resource is not found
|
|
112
|
-
*/
|
|
113
|
-
export class ZapierResourceNotFoundError extends ZapierError {
|
|
114
|
-
readonly name = "ZapierResourceNotFoundError";
|
|
115
|
-
public resourceType?: string;
|
|
116
|
-
public resourceId?: string;
|
|
117
|
-
|
|
118
|
-
constructor(
|
|
119
|
-
message: string,
|
|
120
|
-
options: ErrorOptions & { resourceType?: string; resourceId?: string } = {},
|
|
121
|
-
) {
|
|
122
|
-
super(message, options);
|
|
123
|
-
this.resourceType = options.resourceType;
|
|
124
|
-
this.resourceId = options.resourceId;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Error thrown when required app or implementation configuration is missing
|
|
130
|
-
*/
|
|
131
|
-
export class ZapierConfigurationError extends ZapierError {
|
|
132
|
-
readonly name = "ZapierConfigurationError";
|
|
133
|
-
public configType?: string;
|
|
134
|
-
|
|
135
|
-
constructor(
|
|
136
|
-
message: string,
|
|
137
|
-
options: ErrorOptions & { configType?: string } = {},
|
|
138
|
-
) {
|
|
139
|
-
super(message, options);
|
|
140
|
-
this.configType = options.configType;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Error thrown when code bundling or compilation fails
|
|
146
|
-
*/
|
|
147
|
-
export class ZapierBundleError extends ZapierError {
|
|
148
|
-
readonly name = "ZapierBundleError";
|
|
149
|
-
public buildErrors?: string[];
|
|
150
|
-
|
|
151
|
-
constructor(
|
|
152
|
-
message: string,
|
|
153
|
-
options: ErrorOptions & { buildErrors?: string[] } = {},
|
|
154
|
-
) {
|
|
155
|
-
super(message, options);
|
|
156
|
-
this.buildErrors = options.buildErrors;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Error thrown when operations timeout or exceed retry limits
|
|
162
|
-
*/
|
|
163
|
-
export class ZapierTimeoutError extends ZapierError {
|
|
164
|
-
readonly name = "ZapierTimeoutError";
|
|
165
|
-
public attempts?: number;
|
|
166
|
-
public maxAttempts?: number;
|
|
167
|
-
|
|
168
|
-
constructor(
|
|
169
|
-
message: string,
|
|
170
|
-
options: ErrorOptions & { attempts?: number; maxAttempts?: number } = {},
|
|
171
|
-
) {
|
|
172
|
-
super(message, options);
|
|
173
|
-
this.attempts = options.attempts;
|
|
174
|
-
this.maxAttempts = options.maxAttempts;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Error thrown when action execution fails due to errors returned from the third-party service
|
|
180
|
-
* This happens when the Actions API returns a 200 status but includes errors in the response
|
|
181
|
-
*/
|
|
182
|
-
export class ZapierActionError extends ZapierError {
|
|
183
|
-
readonly name = "ZapierActionError";
|
|
184
|
-
public appKey?: string;
|
|
185
|
-
public actionKey?: string;
|
|
186
|
-
|
|
187
|
-
constructor(
|
|
188
|
-
message: string,
|
|
189
|
-
options: ErrorOptions & { appKey?: string; actionKey?: string } = {},
|
|
190
|
-
) {
|
|
191
|
-
super(message, options);
|
|
192
|
-
this.appKey = options.appKey;
|
|
193
|
-
this.actionKey = options.actionKey;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Legacy accessor for backward compatibility
|
|
197
|
-
get actionErrors() {
|
|
198
|
-
return this.errors;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Error thrown when a resource is not found (404)
|
|
204
|
-
*/
|
|
205
|
-
export class ZapierNotFoundError extends ZapierError {
|
|
206
|
-
readonly name = "ZapierNotFoundError";
|
|
207
|
-
|
|
208
|
-
constructor(message: string, options: ErrorOptions = {}) {
|
|
209
|
-
super(message, options);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Utility function to format error messages for display
|
|
215
|
-
*/
|
|
216
|
-
export function formatErrorMessage(error: ZapierError): string {
|
|
217
|
-
let message = error.message;
|
|
218
|
-
|
|
219
|
-
// Add additional context from errors array if available
|
|
220
|
-
if (error.errors && error.errors.length > 0) {
|
|
221
|
-
const additionalErrors = error.errors.slice(1); // Skip first error (already in message)
|
|
222
|
-
if (additionalErrors.length > 0) {
|
|
223
|
-
const errorDetails = additionalErrors
|
|
224
|
-
.map((err) => ` • ${err.detail || err.title || err.code}`)
|
|
225
|
-
.join("\n");
|
|
226
|
-
message += "\n\nAdditional errors:\n" + errorDetails;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Add error-specific context
|
|
231
|
-
if (error instanceof ZapierAppNotFoundError && error.appKey) {
|
|
232
|
-
message += `\nApp key: ${error.appKey}`;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (error instanceof ZapierActionError && (error.appKey || error.actionKey)) {
|
|
236
|
-
const context = [];
|
|
237
|
-
if (error.appKey) context.push(`App: ${error.appKey}`);
|
|
238
|
-
if (error.actionKey) context.push(`Action: ${error.actionKey}`);
|
|
239
|
-
message += `\n${context.join(", ")}`;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (
|
|
243
|
-
error instanceof ZapierResourceNotFoundError &&
|
|
244
|
-
(error.resourceType || error.resourceId)
|
|
245
|
-
) {
|
|
246
|
-
const context = [];
|
|
247
|
-
if (error.resourceType) context.push(`Type: ${error.resourceType}`);
|
|
248
|
-
if (error.resourceId) context.push(`ID: ${error.resourceId}`);
|
|
249
|
-
message += `\n${context.join(", ")}`;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (
|
|
253
|
-
error instanceof ZapierTimeoutError &&
|
|
254
|
-
(error.attempts || error.maxAttempts)
|
|
255
|
-
) {
|
|
256
|
-
const context = [];
|
|
257
|
-
if (error.attempts) context.push(`Attempts: ${error.attempts}`);
|
|
258
|
-
if (error.maxAttempts) context.push(`Max attempts: ${error.maxAttempts}`);
|
|
259
|
-
message += `\n${context.join(", ")}`;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (
|
|
263
|
-
error instanceof ZapierBundleError &&
|
|
264
|
-
error.buildErrors &&
|
|
265
|
-
error.buildErrors.length > 0
|
|
266
|
-
) {
|
|
267
|
-
message +=
|
|
268
|
-
"\n\nBuild errors:\n" +
|
|
269
|
-
error.buildErrors.map((err) => ` • ${err}`).join("\n");
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Add status code if available and not already obvious from the message
|
|
273
|
-
if (error.statusCode && !message.includes(`${error.statusCode}`)) {
|
|
274
|
-
message += `\nHTTP Status: ${error.statusCode}`;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return message;
|
|
278
|
-
}
|
package/src/types/events.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK Event System
|
|
3
|
-
*
|
|
4
|
-
* This module provides common event type definitions for the SDK's
|
|
5
|
-
* event system, including authentication, API, and loading events.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// Generic event system
|
|
9
|
-
export interface SdkEvent {
|
|
10
|
-
type: string;
|
|
11
|
-
payload?: Record<string, unknown>;
|
|
12
|
-
timestamp?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface AuthEvent extends SdkEvent {
|
|
16
|
-
type: "auth_refreshing" | "auth_success" | "auth_error" | "auth_logout";
|
|
17
|
-
payload?: {
|
|
18
|
-
message?: string;
|
|
19
|
-
error?: string;
|
|
20
|
-
operation?: string;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ApiEvent extends SdkEvent {
|
|
25
|
-
type: "api_request" | "api_response" | "api_error";
|
|
26
|
-
payload?: {
|
|
27
|
-
url?: string;
|
|
28
|
-
method?: string;
|
|
29
|
-
status?: number;
|
|
30
|
-
duration?: number;
|
|
31
|
-
error?: string;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface LoadingEvent extends SdkEvent {
|
|
36
|
-
type: "loading_start" | "loading_end";
|
|
37
|
-
payload?: {
|
|
38
|
-
operation?: string;
|
|
39
|
-
resource?: string;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type EventCallback = (event: SdkEvent) => void;
|
package/src/types/functions.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ApiClient } from "../api/types";
|
|
2
|
-
/**
|
|
3
|
-
* Function-related types and interfaces
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Common options shared across all function types
|
|
7
|
-
export interface FunctionOptions {
|
|
8
|
-
/** Base URL for Zapier API */
|
|
9
|
-
baseUrl?: string;
|
|
10
|
-
/** Authentication token */
|
|
11
|
-
token?: string;
|
|
12
|
-
/** Function to dynamically resolve authentication token */
|
|
13
|
-
getToken?: () => Promise<string | undefined>;
|
|
14
|
-
/** Optional pre-instantiated API client */
|
|
15
|
-
api?: ApiClient;
|
|
16
|
-
/** Enable debug logging */
|
|
17
|
-
debug?: boolean;
|
|
18
|
-
/** Custom fetch implementation */
|
|
19
|
-
fetch?: typeof globalThis.fetch;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Generic type helper for paginated SDK functions
|
|
23
|
-
export type PaginatedSdkFunction<TOptions, TItem> = (
|
|
24
|
-
options: TOptions,
|
|
25
|
-
) => Promise<{ data: TItem[] }> &
|
|
26
|
-
AsyncIterable<{ data: TItem[]; nextCursor?: string }> & {
|
|
27
|
-
items(): AsyncIterable<TItem>;
|
|
28
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// packages/zapier-sdk/types/cli-login-shim.d.ts
|
|
2
|
-
declare module '@zapier/zapier-sdk-cli-login' {
|
|
3
|
-
export interface AuthOptions {
|
|
4
|
-
onEvent?: (event: {
|
|
5
|
-
type: string;
|
|
6
|
-
payload: Record<string, any>;
|
|
7
|
-
timestamp: number;
|
|
8
|
-
}) => void;
|
|
9
|
-
fetch?: typeof globalThis.fetch;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface LoginData {
|
|
13
|
-
access_token: string;
|
|
14
|
-
refresh_token: string;
|
|
15
|
-
expires_in: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Minimal API — include only what your SDK actually uses.
|
|
19
|
-
// (Keeping a few extra exports here is harmless and future-proofs a bit.)
|
|
20
|
-
export function getToken(
|
|
21
|
-
options?: AuthOptions
|
|
22
|
-
): Promise<string | undefined>;
|
|
23
|
-
|
|
24
|
-
export function getValidJwt(
|
|
25
|
-
options?: AuthOptions
|
|
26
|
-
): Promise<string | undefined>;
|
|
27
|
-
|
|
28
|
-
export function getLoggedInUser(
|
|
29
|
-
options?: AuthOptions
|
|
30
|
-
): Promise<{ accountId: number; customUserId: number; email: string }>;
|
|
31
|
-
|
|
32
|
-
export function logout(options?: Pick<AuthOptions, 'onEvent'>): void;
|
|
33
|
-
|
|
34
|
-
export function updateLogin(loginData: LoginData): void;
|
|
35
|
-
|
|
36
|
-
export function getConfigPath(): string;
|
|
37
|
-
}
|
package/src/types/plugin.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ------------------------------
|
|
3
|
-
* Plugin Type System with Explicit Context Dependencies
|
|
4
|
-
* ------------------------------
|
|
5
|
-
*
|
|
6
|
-
* This system makes context dependencies explicit to restore TypeScript's
|
|
7
|
-
* ability to catch missing context at compile time.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { z } from "zod";
|
|
11
|
-
import type { BaseSdkOptions } from "./sdk";
|
|
12
|
-
|
|
13
|
-
export interface PluginDependencies<TSdk = {}, TContext = {}> {
|
|
14
|
-
sdk: TSdk;
|
|
15
|
-
context: TContext;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Plugin provides = sdk properties + optional context
|
|
19
|
-
export interface PluginProvides extends Record<string, any> {
|
|
20
|
-
context?: Record<string, any>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface PluginMeta {
|
|
24
|
-
categories: string[];
|
|
25
|
-
type?: "list" | "item";
|
|
26
|
-
itemType?: string;
|
|
27
|
-
returnType?: string;
|
|
28
|
-
inputSchema: z.ZodSchema;
|
|
29
|
-
outputSchema?: z.ZodSchema;
|
|
30
|
-
resolvers?: Record<string, any>;
|
|
31
|
-
[key: string]: any;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Utility type to extract SDK properties (everything except 'context')
|
|
35
|
-
export type ExtractSdkProperties<T extends Record<string, any>> = Omit<
|
|
36
|
-
T,
|
|
37
|
-
"context"
|
|
38
|
-
>;
|
|
39
|
-
|
|
40
|
-
// Utility type to extract context properties from plugin
|
|
41
|
-
export type ExtractContextProperties<T extends PluginProvides> = T["context"];
|
|
42
|
-
|
|
43
|
-
// Helper type to create SDK type with properly typed getContext method
|
|
44
|
-
export type GetSdkType<TPluginProvides extends PluginProvides> =
|
|
45
|
-
ExtractSdkProperties<TPluginProvides> & {
|
|
46
|
-
getContext(): NonNullable<ExtractContextProperties<TPluginProvides>>;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export type GetContextType<TPluginProvides extends PluginProvides> =
|
|
50
|
-
NonNullable<ExtractContextProperties<TPluginProvides>>;
|
|
51
|
-
|
|
52
|
-
// Helper type for standard plugin options with SDK dependency and meta context
|
|
53
|
-
export type PluginOptions<TSdk = {}, TContext = {}> = {
|
|
54
|
-
sdk: TSdk;
|
|
55
|
-
context: TContext & { meta: Record<string, any> };
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Plugin interface — now has 3 type params:
|
|
60
|
-
*
|
|
61
|
-
* TRequiresContext = what this plugin *needs* in context
|
|
62
|
-
* TProvides = what this plugin *returns* (sdk + context)
|
|
63
|
-
* TSdk = current sdk shape when plugin runs
|
|
64
|
-
*/
|
|
65
|
-
export interface Plugin<
|
|
66
|
-
TSdk = {},
|
|
67
|
-
TRequiresContext = {},
|
|
68
|
-
TProvides extends PluginProvides = PluginProvides,
|
|
69
|
-
> {
|
|
70
|
-
(params: {
|
|
71
|
-
sdk: TSdk;
|
|
72
|
-
context: TRequiresContext & {
|
|
73
|
-
meta: Record<string, PluginMeta>;
|
|
74
|
-
options: BaseSdkOptions;
|
|
75
|
-
};
|
|
76
|
-
}): TProvides;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Helper type to get missing keys from required context
|
|
80
|
-
type MissingContextKeys<TRequired, TCurrent> =
|
|
81
|
-
TRequired extends Record<string, any>
|
|
82
|
-
? TCurrent extends Record<string, any>
|
|
83
|
-
? {
|
|
84
|
-
[K in keyof TRequired]: K extends keyof TCurrent ? never : K;
|
|
85
|
-
}[keyof TRequired]
|
|
86
|
-
: keyof TRequired
|
|
87
|
-
: never;
|
|
88
|
-
|
|
89
|
-
// Helper type to create detailed error message
|
|
90
|
-
type ContextError<TRequired, TCurrent> =
|
|
91
|
-
MissingContextKeys<TRequired, TCurrent> extends never
|
|
92
|
-
? never
|
|
93
|
-
: MissingContextKeys<TRequired, TCurrent> extends infer Missing
|
|
94
|
-
? Missing extends string
|
|
95
|
-
? `❌ Missing required context: { ${Missing}: any }`
|
|
96
|
-
: Missing extends number
|
|
97
|
-
? `❌ Missing required context: { ${Missing}: any }`
|
|
98
|
-
: `❌ Missing required context properties. Required: ${keyof TRequired extends string ? keyof TRequired : "unknown"}, Available: ${keyof TCurrent extends string ? keyof TCurrent : "unknown"}`
|
|
99
|
-
: "❌ Context requirement not satisfied";
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* SDK interface — result of createSdk()
|
|
103
|
-
*
|
|
104
|
-
* addPlugin now enforces that TRequiresContext is assignable to TCurrentContext.
|
|
105
|
-
* If not, TypeScript will emit a detailed error showing missing properties.
|
|
106
|
-
*/
|
|
107
|
-
export type Sdk<
|
|
108
|
-
TCurrentSdk = {},
|
|
109
|
-
TCurrentContext = { meta: Record<string, PluginMeta> },
|
|
110
|
-
> = TCurrentSdk & {
|
|
111
|
-
addPlugin<TRequiresContext, TProvides extends PluginProvides>(
|
|
112
|
-
plugin: Plugin<
|
|
113
|
-
TCurrentSdk & { getContext(): TCurrentContext },
|
|
114
|
-
TRequiresContext,
|
|
115
|
-
TProvides
|
|
116
|
-
>,
|
|
117
|
-
options?: any,
|
|
118
|
-
): TCurrentContext extends TRequiresContext
|
|
119
|
-
? Sdk<
|
|
120
|
-
TCurrentSdk & ExtractSdkProperties<TProvides>,
|
|
121
|
-
TCurrentContext & NonNullable<ExtractContextProperties<TProvides>>
|
|
122
|
-
>
|
|
123
|
-
: ContextError<TRequiresContext, TCurrentContext>;
|
|
124
|
-
getContext(): TCurrentContext;
|
|
125
|
-
};
|
package/src/types/properties.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { withPositional } from "../utils/schema-utils";
|
|
3
|
-
import { MAX_PAGE_LIMIT } from "../constants";
|
|
4
|
-
|
|
5
|
-
// Shared property definitions for common parameters across functions
|
|
6
|
-
// These can be reused in function schemas without duplication
|
|
7
|
-
|
|
8
|
-
export const AppKeyPropertySchema = withPositional(
|
|
9
|
-
z
|
|
10
|
-
.string()
|
|
11
|
-
.min(1)
|
|
12
|
-
.describe("App key (e.g., 'SlackCLIAPI' or slug like 'github')"),
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
export const ActionTypePropertySchema = z
|
|
16
|
-
.enum([
|
|
17
|
-
"read",
|
|
18
|
-
"read_bulk",
|
|
19
|
-
"write",
|
|
20
|
-
"run",
|
|
21
|
-
"search",
|
|
22
|
-
"search_or_write",
|
|
23
|
-
"search_and_write",
|
|
24
|
-
"filter",
|
|
25
|
-
])
|
|
26
|
-
.describe("Action type that matches the action's defined type");
|
|
27
|
-
|
|
28
|
-
export const ActionKeyPropertySchema = z
|
|
29
|
-
.string()
|
|
30
|
-
.min(1)
|
|
31
|
-
.describe("Action key to execute");
|
|
32
|
-
|
|
33
|
-
export const AuthenticationIdPropertySchema = z
|
|
34
|
-
.number()
|
|
35
|
-
.int()
|
|
36
|
-
.describe("Authentication ID to use for this action");
|
|
37
|
-
|
|
38
|
-
export const InputsPropertySchema = z
|
|
39
|
-
.record(z.unknown())
|
|
40
|
-
.describe("Input parameters for the action");
|
|
41
|
-
|
|
42
|
-
export const LimitPropertySchema = z
|
|
43
|
-
.number()
|
|
44
|
-
.int()
|
|
45
|
-
.min(1)
|
|
46
|
-
.max(MAX_PAGE_LIMIT)
|
|
47
|
-
.default(50)
|
|
48
|
-
.describe("Maximum number of items to return");
|
|
49
|
-
|
|
50
|
-
export const OffsetPropertySchema = z
|
|
51
|
-
.number()
|
|
52
|
-
.int()
|
|
53
|
-
.min(0)
|
|
54
|
-
.default(0)
|
|
55
|
-
.describe("Number of items to skip for pagination");
|
|
56
|
-
|
|
57
|
-
export const OutputPropertySchema = z.string().describe("Output file path");
|
|
58
|
-
|
|
59
|
-
export const DebugPropertySchema = z
|
|
60
|
-
.boolean()
|
|
61
|
-
.default(false)
|
|
62
|
-
.describe("Enable debug logging");
|
|
63
|
-
|
|
64
|
-
export const ParamsPropertySchema = z
|
|
65
|
-
.record(z.unknown())
|
|
66
|
-
.describe("Additional parameters");
|
|
67
|
-
|
|
68
|
-
// Inferred TypeScript types for the properties
|
|
69
|
-
export type AppKeyProperty = z.infer<typeof AppKeyPropertySchema>;
|
|
70
|
-
export type ActionTypeProperty = z.infer<typeof ActionTypePropertySchema>;
|
|
71
|
-
export type ActionKeyProperty = z.infer<typeof ActionKeyPropertySchema>;
|
|
72
|
-
export type AuthenticationIdProperty = z.infer<
|
|
73
|
-
typeof AuthenticationIdPropertySchema
|
|
74
|
-
>;
|
|
75
|
-
export type InputsProperty = z.infer<typeof InputsPropertySchema>;
|
|
76
|
-
export type LimitProperty = z.infer<typeof LimitPropertySchema>;
|
|
77
|
-
export type OffsetProperty = z.infer<typeof OffsetPropertySchema>;
|
|
78
|
-
export type OutputProperty = z.infer<typeof OutputPropertySchema>;
|
|
79
|
-
export type DebugProperty = z.infer<typeof DebugPropertySchema>;
|
|
80
|
-
export type ParamsProperty = z.infer<typeof ParamsPropertySchema>;
|
package/src/types/sdk.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK-related types and interfaces
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { EventCallback } from "./events";
|
|
6
|
-
import type { EventEmissionConfig } from "../plugins/eventEmission";
|
|
7
|
-
import type { Manifest } from "../plugins/manifest";
|
|
8
|
-
|
|
9
|
-
// SDK Configuration Types
|
|
10
|
-
export interface BaseSdkOptions {
|
|
11
|
-
token?: string;
|
|
12
|
-
getToken?: () => Promise<string | undefined>;
|
|
13
|
-
onEvent?: EventCallback;
|
|
14
|
-
fetch?: typeof fetch;
|
|
15
|
-
baseUrl?: string;
|
|
16
|
-
debug?: boolean;
|
|
17
|
-
manifestPath?: string;
|
|
18
|
-
manifest?: Manifest;
|
|
19
|
-
eventEmission?: EventEmissionConfig;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// SDK interface composed from individual function interfaces
|
|
23
|
-
import type { ListInputFieldsSdkFunction } from "../plugins/listInputFields/schemas";
|
|
24
|
-
import type { GetAuthenticationSdkFunction } from "../plugins/getAuthentication/schemas";
|
|
25
|
-
import type { FindFirstAuthenticationSdkFunction } from "../plugins/findFirstAuthentication/schemas";
|
|
26
|
-
import type { FindUniqueAuthenticationSdkFunction } from "../plugins/findUniqueAuthentication/schemas";
|
|
27
|
-
import type { RelayRequestSdkFunction } from "../plugins/request/schemas";
|
|
28
|
-
|
|
29
|
-
import type { z } from "zod";
|
|
30
|
-
import type { RegistryPluginProvides } from "../plugins/registry";
|
|
31
|
-
import type { GetProfilePluginProvides } from "../plugins/getProfile";
|
|
32
|
-
import type { EventEmissionProvides } from "../plugins/eventEmission";
|
|
33
|
-
import type { ApiPluginProvides } from "../plugins/api";
|
|
34
|
-
import type { AppsPluginProvides, ZapierSdkApps } from "../plugins/apps";
|
|
35
|
-
import type { ActionProxy } from "../plugins/apps/schemas";
|
|
36
|
-
import type { FetchPluginProvides } from "../plugins/fetch";
|
|
37
|
-
import type { ListAppsPluginProvides } from "../plugins/listApps";
|
|
38
|
-
import type { GetAppPluginProvides } from "../plugins/getApp";
|
|
39
|
-
import type { ListActionsPluginProvides } from "../plugins/listActions";
|
|
40
|
-
import type { GetActionPluginProvides } from "../plugins/getAction";
|
|
41
|
-
import type { RunActionPluginProvides } from "../plugins/runAction";
|
|
42
|
-
import type { ListAuthenticationsPluginProvides } from "../plugins/listAuthentications";
|
|
43
|
-
import type { GetAuthenticationPluginProvides } from "../plugins/getAuthentication";
|
|
44
|
-
import type { FindFirstAuthenticationPluginProvides } from "../plugins/findFirstAuthentication";
|
|
45
|
-
import type { FindUniqueAuthenticationPluginProvides } from "../plugins/findUniqueAuthentication";
|
|
46
|
-
import type { ListInputFieldsPluginProvides } from "../plugins/listInputFields";
|
|
47
|
-
import type { ListInputFieldChoicesPluginProvides } from "../plugins/listInputFieldChoices";
|
|
48
|
-
import type { RequestPluginProvides } from "../plugins/request";
|
|
49
|
-
import type { GetSdkType } from "./plugin";
|
|
50
|
-
import type { ManifestPluginProvides } from "../plugins/manifest";
|
|
51
|
-
|
|
52
|
-
// Plugin interfaces
|
|
53
|
-
// Note: Plugin extension types removed - now using new plugin system
|
|
54
|
-
|
|
55
|
-
// Registry entry interface with proper types
|
|
56
|
-
export interface FunctionRegistryEntry {
|
|
57
|
-
name: string;
|
|
58
|
-
type?: "list" | "item";
|
|
59
|
-
itemType?: string;
|
|
60
|
-
returnType?: string;
|
|
61
|
-
inputSchema?: z.ZodSchema;
|
|
62
|
-
inputParameters?: Array<{ name: string; schema: z.ZodSchema }>;
|
|
63
|
-
outputSchema?: z.ZodSchema;
|
|
64
|
-
categories: string[];
|
|
65
|
-
resolvers?: Record<string, any>;
|
|
66
|
-
packages?: string[];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Compose SDK functions from individual function interfaces
|
|
70
|
-
export interface ZapierSdkFunctions
|
|
71
|
-
extends ListInputFieldsSdkFunction,
|
|
72
|
-
GetAuthenticationSdkFunction,
|
|
73
|
-
FindFirstAuthenticationSdkFunction,
|
|
74
|
-
FindUniqueAuthenticationSdkFunction,
|
|
75
|
-
RelayRequestSdkFunction {
|
|
76
|
-
// All functions now properly typed!
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Note: ZapierSdkPlugins removed - plugins are now handled by the plugin builder system
|
|
80
|
-
|
|
81
|
-
// Note: BaseZapierSdk removed - all functions now provided by individual plugins
|
|
82
|
-
// The registry is provided by RegistryPlugin
|
|
83
|
-
|
|
84
|
-
// Note: ZapierSdk type removed - use ReturnType<typeof createZapierSdk> instead
|
|
85
|
-
// This ensures the type matches exactly what the builder produces
|
|
86
|
-
|
|
87
|
-
export interface ZapierSdk
|
|
88
|
-
extends GetSdkType<
|
|
89
|
-
RegistryPluginProvides &
|
|
90
|
-
FetchPluginProvides &
|
|
91
|
-
AppsPluginProvides &
|
|
92
|
-
ListAppsPluginProvides &
|
|
93
|
-
ManifestPluginProvides &
|
|
94
|
-
GetAppPluginProvides &
|
|
95
|
-
ListActionsPluginProvides &
|
|
96
|
-
GetActionPluginProvides &
|
|
97
|
-
RunActionPluginProvides &
|
|
98
|
-
ListAuthenticationsPluginProvides &
|
|
99
|
-
GetAuthenticationPluginProvides &
|
|
100
|
-
FindFirstAuthenticationPluginProvides &
|
|
101
|
-
FindUniqueAuthenticationPluginProvides &
|
|
102
|
-
ListInputFieldsPluginProvides &
|
|
103
|
-
ListInputFieldChoicesPluginProvides &
|
|
104
|
-
RequestPluginProvides &
|
|
105
|
-
GetProfilePluginProvides &
|
|
106
|
-
EventEmissionProvides &
|
|
107
|
-
ApiPluginProvides
|
|
108
|
-
> {
|
|
109
|
-
// Override apps property to intersect ActionProxy with our typed apps
|
|
110
|
-
apps: ActionProxy & ZapierSdkApps;
|
|
111
|
-
}
|