@zapier/zapier-sdk 0.31.1 → 0.31.2
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 +6 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +15 -2
- package/dist/auth.d.ts +7 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +43 -12
- package/dist/auth.test.js +10 -1
- package/dist/index.cjs +26 -7
- package/dist/index.d.mts +8 -4
- package/dist/index.mjs +26 -8
- package/dist/plugins/eventEmission/index.test.js +3 -0
- package/dist/plugins/listApps/index.test.js +4 -1
- package/dist/plugins/listConnections/index.test.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AA2oBjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
|
package/dist/api/client.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { getAuthorizationHeader } from "./auth";
|
|
8
8
|
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
9
9
|
import { pollUntilComplete } from "./polling";
|
|
10
|
-
import { resolveAuthToken, invalidateCredentialsToken } from "../auth";
|
|
10
|
+
import { resolveAuthToken, invalidateCredentialsToken, isCliLoginAvailable, } from "../auth";
|
|
11
11
|
import { getZapierBaseUrl } from "../utils/url-utils";
|
|
12
12
|
import { sleep, calculateExponentialBackoffMs } from "../utils/retry-utils";
|
|
13
13
|
import { isPlainObject } from "../utils/type-guard-utils";
|
|
@@ -421,7 +421,20 @@ class ZapierApiClient {
|
|
|
421
421
|
// before we even make a request.
|
|
422
422
|
if (options.authRequired) {
|
|
423
423
|
if (headers.get("Authorization") == null && authToken == null) {
|
|
424
|
-
|
|
424
|
+
const message = isCliLoginAvailable() === false
|
|
425
|
+
? "Authentication required but no credentials available. " +
|
|
426
|
+
"To use CLI login, install the CLI as a dev dependency " +
|
|
427
|
+
"(e.g. `npm install -D @zapier/zapier-sdk-cli`) and " +
|
|
428
|
+
"log in (e.g. `npx zapier-sdk login`). " +
|
|
429
|
+
"Alternatively, set the ZAPIER_CREDENTIALS environment variable " +
|
|
430
|
+
"or ZAPIER_CREDENTIALS_CLIENT_ID and " +
|
|
431
|
+
"ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables."
|
|
432
|
+
: "Authentication required but no credentials available. " +
|
|
433
|
+
"Please log in (e.g. `npx zapier-sdk login`) or set the " +
|
|
434
|
+
"ZAPIER_CREDENTIALS environment variable or " +
|
|
435
|
+
"ZAPIER_CREDENTIALS_CLIENT_ID and " +
|
|
436
|
+
"ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables.";
|
|
437
|
+
throw new ZapierAuthenticationError(message);
|
|
425
438
|
}
|
|
426
439
|
}
|
|
427
440
|
return headers;
|
package/dist/auth.d.ts
CHANGED
|
@@ -56,10 +56,14 @@ interface CliLoginOptions {
|
|
|
56
56
|
debug?: boolean;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* Returns whether a CLI login package is available.
|
|
60
|
+
* `undefined` if no import has been attempted yet, `true` if found, `false` if not.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isCliLoginAvailable(): boolean | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Attempts to get a token from the CLI login package.
|
|
61
65
|
*
|
|
62
|
-
* Returns undefined if no valid token is found or
|
|
66
|
+
* Returns undefined if no valid token is found or no login package is available.
|
|
63
67
|
* Throws if there's an actual error (like token refresh failure).
|
|
64
68
|
*/
|
|
65
69
|
export declare function getTokenFromCliLogin(options: CliLoginOptions): Promise<string | undefined>;
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,qBAAqB,CAAC;AAM5E,YAAY,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,gDAAgD;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA+BD;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,qBAAqB,CAAC;AAM5E,YAAY,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,gDAAgD;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA+BD;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAItC;AA0CD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EAAE,GACf,IAAI,CAIN;AA6HD;;GAEG;AACH,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,WAAW,CAAC,EAAE;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAsCD;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,GAAG,SAAS,CAGzD;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK7B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAkB7B;AA6ED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE;IACxD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAQhB"}
|
package/dist/auth.js
CHANGED
|
@@ -36,6 +36,7 @@ function buildCacheKey(clientId, scopes) {
|
|
|
36
36
|
export function clearTokenCache() {
|
|
37
37
|
tokenCache.clear();
|
|
38
38
|
pendingExchanges.clear();
|
|
39
|
+
cachedCliLogin = undefined;
|
|
39
40
|
}
|
|
40
41
|
const TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1000; // 5 minutes
|
|
41
42
|
/**
|
|
@@ -169,26 +170,56 @@ async function exchangeClientCredentials(options) {
|
|
|
169
170
|
});
|
|
170
171
|
return data.access_token;
|
|
171
172
|
}
|
|
173
|
+
let cachedCliLogin;
|
|
172
174
|
/**
|
|
173
|
-
*
|
|
174
|
-
* This provides a graceful fallback when the CLI login package is not available.
|
|
175
|
+
* Dynamically imports a CLI login package with caching.
|
|
175
176
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
177
|
+
* Tries `@zapier/zapier-sdk-cli/login` first (available when the CLI is a
|
|
178
|
+
* direct dependency), then falls back to `@zapier/zapier-sdk-cli-login` (for
|
|
179
|
+
* users who install the lightweight login package directly).
|
|
180
|
+
*
|
|
181
|
+
* Returns the module if found, or `undefined` if neither package is available.
|
|
182
|
+
* The result is cached after the first attempt.
|
|
178
183
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
async function getCliLogin() {
|
|
185
|
+
if (cachedCliLogin !== undefined) {
|
|
186
|
+
return cachedCliLogin || undefined;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
cachedCliLogin = await import("@zapier/zapier-sdk-cli/login");
|
|
190
|
+
return cachedCliLogin;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// First path not available, try fallback
|
|
194
|
+
}
|
|
184
195
|
try {
|
|
185
|
-
|
|
196
|
+
cachedCliLogin = await import("@zapier/zapier-sdk-cli-login");
|
|
197
|
+
return cachedCliLogin;
|
|
186
198
|
}
|
|
187
199
|
catch {
|
|
188
|
-
|
|
200
|
+
cachedCliLogin = false;
|
|
189
201
|
return undefined;
|
|
190
202
|
}
|
|
191
|
-
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns whether a CLI login package is available.
|
|
206
|
+
* `undefined` if no import has been attempted yet, `true` if found, `false` if not.
|
|
207
|
+
*/
|
|
208
|
+
export function isCliLoginAvailable() {
|
|
209
|
+
if (cachedCliLogin === undefined)
|
|
210
|
+
return undefined;
|
|
211
|
+
return cachedCliLogin !== false;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Attempts to get a token from the CLI login package.
|
|
215
|
+
*
|
|
216
|
+
* Returns undefined if no valid token is found or no login package is available.
|
|
217
|
+
* Throws if there's an actual error (like token refresh failure).
|
|
218
|
+
*/
|
|
219
|
+
export async function getTokenFromCliLogin(options) {
|
|
220
|
+
const cliLogin = await getCliLogin();
|
|
221
|
+
if (!cliLogin)
|
|
222
|
+
return undefined;
|
|
192
223
|
return await cliLogin.getToken(options);
|
|
193
224
|
}
|
|
194
225
|
/**
|
package/dist/auth.test.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
2
|
import * as auth from "./auth";
|
|
3
3
|
import { resetDeprecationWarnings } from "./utils/logging";
|
|
4
|
-
// Mock
|
|
4
|
+
// Mock both CLI login import paths (SDK tries @zapier/zapier-sdk-cli/login
|
|
5
|
+
// first, then falls back to @zapier/zapier-sdk-cli-login)
|
|
5
6
|
const mockGetToken = vi.fn();
|
|
7
|
+
vi.mock("@zapier/zapier-sdk-cli/login", () => ({
|
|
8
|
+
getToken: mockGetToken,
|
|
9
|
+
}));
|
|
6
10
|
vi.mock("@zapier/zapier-sdk-cli-login", () => ({
|
|
7
11
|
getToken: mockGetToken,
|
|
8
12
|
}));
|
|
@@ -41,6 +45,11 @@ describe("auth", () => {
|
|
|
41
45
|
mockGetToken.mockRejectedValue(new Error("Token refresh failed"));
|
|
42
46
|
await expect(auth.getTokenFromCliLogin({})).rejects.toThrow("Token refresh failed");
|
|
43
47
|
});
|
|
48
|
+
it("should set isCliLoginAvailable to true when import succeeds", async () => {
|
|
49
|
+
mockGetToken.mockResolvedValue("cli-token");
|
|
50
|
+
await auth.getTokenFromCliLogin({});
|
|
51
|
+
expect(auth.isCliLoginAvailable()).toBe(true);
|
|
52
|
+
});
|
|
44
53
|
});
|
|
45
54
|
describe("resolveAuthToken", () => {
|
|
46
55
|
it("should return string credentials directly", async () => {
|
package/dist/index.cjs
CHANGED
|
@@ -4168,6 +4168,7 @@ function buildCacheKey(clientId, scopes) {
|
|
|
4168
4168
|
function clearTokenCache() {
|
|
4169
4169
|
tokenCache.clear();
|
|
4170
4170
|
pendingExchanges.clear();
|
|
4171
|
+
cachedCliLogin = void 0;
|
|
4171
4172
|
}
|
|
4172
4173
|
var TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1e3;
|
|
4173
4174
|
function getCachedToken(clientId, scopes) {
|
|
@@ -4272,13 +4273,31 @@ async function exchangeClientCredentials(options) {
|
|
|
4272
4273
|
});
|
|
4273
4274
|
return data.access_token;
|
|
4274
4275
|
}
|
|
4275
|
-
|
|
4276
|
-
|
|
4276
|
+
var cachedCliLogin;
|
|
4277
|
+
async function getCliLogin() {
|
|
4278
|
+
if (cachedCliLogin !== void 0) {
|
|
4279
|
+
return cachedCliLogin || void 0;
|
|
4280
|
+
}
|
|
4281
|
+
try {
|
|
4282
|
+
cachedCliLogin = await import('@zapier/zapier-sdk-cli/login');
|
|
4283
|
+
return cachedCliLogin;
|
|
4284
|
+
} catch {
|
|
4285
|
+
}
|
|
4277
4286
|
try {
|
|
4278
|
-
|
|
4287
|
+
cachedCliLogin = await import('@zapier/zapier-sdk-cli-login');
|
|
4288
|
+
return cachedCliLogin;
|
|
4279
4289
|
} catch {
|
|
4290
|
+
cachedCliLogin = false;
|
|
4280
4291
|
return void 0;
|
|
4281
4292
|
}
|
|
4293
|
+
}
|
|
4294
|
+
function isCliLoginAvailable() {
|
|
4295
|
+
if (cachedCliLogin === void 0) return void 0;
|
|
4296
|
+
return cachedCliLogin !== false;
|
|
4297
|
+
}
|
|
4298
|
+
async function getTokenFromCliLogin(options) {
|
|
4299
|
+
const cliLogin = await getCliLogin();
|
|
4300
|
+
if (!cliLogin) return void 0;
|
|
4282
4301
|
return await cliLogin.getToken(options);
|
|
4283
4302
|
}
|
|
4284
4303
|
async function resolveAuthToken(options = {}) {
|
|
@@ -4704,9 +4723,8 @@ var ZapierApiClient = class {
|
|
|
4704
4723
|
}
|
|
4705
4724
|
if (options.authRequired) {
|
|
4706
4725
|
if (headers.get("Authorization") == null && authToken == null) {
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
);
|
|
4726
|
+
const message = isCliLoginAvailable() === false ? "Authentication required but no credentials available. To use CLI login, install the CLI as a dev dependency (e.g. `npm install -D @zapier/zapier-sdk-cli`) and log in (e.g. `npx zapier-sdk login`). Alternatively, set the ZAPIER_CREDENTIALS environment variable or ZAPIER_CREDENTIALS_CLIENT_ID and ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables." : "Authentication required but no credentials available. Please log in (e.g. `npx zapier-sdk login`) or set the ZAPIER_CREDENTIALS environment variable or ZAPIER_CREDENTIALS_CLIENT_ID and ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables.";
|
|
4727
|
+
throw new ZapierAuthenticationError(message);
|
|
4710
4728
|
}
|
|
4711
4729
|
}
|
|
4712
4730
|
return headers;
|
|
@@ -5469,7 +5487,7 @@ function getCpuTime() {
|
|
|
5469
5487
|
|
|
5470
5488
|
// package.json
|
|
5471
5489
|
var package_default = {
|
|
5472
|
-
version: "0.31.
|
|
5490
|
+
version: "0.31.2"};
|
|
5473
5491
|
|
|
5474
5492
|
// src/plugins/eventEmission/builders.ts
|
|
5475
5493
|
function createBaseEvent(context = {}) {
|
|
@@ -6056,6 +6074,7 @@ exports.inputsResolver = inputsResolver;
|
|
|
6056
6074
|
exports.invalidateCachedToken = invalidateCachedToken;
|
|
6057
6075
|
exports.invalidateCredentialsToken = invalidateCredentialsToken;
|
|
6058
6076
|
exports.isCi = isCi;
|
|
6077
|
+
exports.isCliLoginAvailable = isCliLoginAvailable;
|
|
6059
6078
|
exports.isClientCredentials = isClientCredentials;
|
|
6060
6079
|
exports.isCredentialsFunction = isCredentialsFunction;
|
|
6061
6080
|
exports.isCredentialsObject = isCredentialsObject;
|
package/dist/index.d.mts
CHANGED
|
@@ -2623,10 +2623,14 @@ interface CliLoginOptions {
|
|
|
2623
2623
|
debug?: boolean;
|
|
2624
2624
|
}
|
|
2625
2625
|
/**
|
|
2626
|
-
*
|
|
2627
|
-
*
|
|
2626
|
+
* Returns whether a CLI login package is available.
|
|
2627
|
+
* `undefined` if no import has been attempted yet, `true` if found, `false` if not.
|
|
2628
|
+
*/
|
|
2629
|
+
declare function isCliLoginAvailable(): boolean | undefined;
|
|
2630
|
+
/**
|
|
2631
|
+
* Attempts to get a token from the CLI login package.
|
|
2628
2632
|
*
|
|
2629
|
-
* Returns undefined if no valid token is found or
|
|
2633
|
+
* Returns undefined if no valid token is found or no login package is available.
|
|
2630
2634
|
* Throws if there's an actual error (like token refresh failure).
|
|
2631
2635
|
*/
|
|
2632
2636
|
declare function getTokenFromCliLogin(options: CliLoginOptions): Promise<string | undefined>;
|
|
@@ -2949,4 +2953,4 @@ declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk
|
|
|
2949
2953
|
}>;
|
|
2950
2954
|
declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
|
2951
2955
|
|
|
2952
|
-
export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTimeoutMsProperty, ActionTimeoutMsPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type BaseEvent, BaseSdkOptionsSchema, type BatchOptions, type Choice, type ClientCredentialsObject, ClientCredentialsObjectSchema, type Connection, type ConnectionIdProperty, ConnectionIdPropertySchema, type ConnectionItem, type ConnectionsResponse, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsFunction, CredentialsFunctionSchema, type CredentialsObject, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindFirstConnectionPluginProvides, type FindUniqueAuthenticationPluginProvides, type FindUniqueConnectionPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetConnectionPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListConnectionsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, PkceCredentialsObjectSchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, type RateLimitInfo, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, ResolvedCredentialsSchema, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type StaticResolver, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
2956
|
+
export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTimeoutMsProperty, ActionTimeoutMsPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type BaseEvent, BaseSdkOptionsSchema, type BatchOptions, type Choice, type ClientCredentialsObject, ClientCredentialsObjectSchema, type Connection, type ConnectionIdProperty, ConnectionIdPropertySchema, type ConnectionItem, type ConnectionsResponse, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsFunction, CredentialsFunctionSchema, type CredentialsObject, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindFirstConnectionPluginProvides, type FindUniqueAuthenticationPluginProvides, type FindUniqueConnectionPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetConnectionPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListConnectionsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, PkceCredentialsObjectSchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, type RateLimitInfo, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, ResolvedCredentialsSchema, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type StaticResolver, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
package/dist/index.mjs
CHANGED
|
@@ -4146,6 +4146,7 @@ function buildCacheKey(clientId, scopes) {
|
|
|
4146
4146
|
function clearTokenCache() {
|
|
4147
4147
|
tokenCache.clear();
|
|
4148
4148
|
pendingExchanges.clear();
|
|
4149
|
+
cachedCliLogin = void 0;
|
|
4149
4150
|
}
|
|
4150
4151
|
var TOKEN_EXPIRATION_BUFFER = 5 * 60 * 1e3;
|
|
4151
4152
|
function getCachedToken(clientId, scopes) {
|
|
@@ -4250,13 +4251,31 @@ async function exchangeClientCredentials(options) {
|
|
|
4250
4251
|
});
|
|
4251
4252
|
return data.access_token;
|
|
4252
4253
|
}
|
|
4253
|
-
|
|
4254
|
-
|
|
4254
|
+
var cachedCliLogin;
|
|
4255
|
+
async function getCliLogin() {
|
|
4256
|
+
if (cachedCliLogin !== void 0) {
|
|
4257
|
+
return cachedCliLogin || void 0;
|
|
4258
|
+
}
|
|
4259
|
+
try {
|
|
4260
|
+
cachedCliLogin = await import('@zapier/zapier-sdk-cli/login');
|
|
4261
|
+
return cachedCliLogin;
|
|
4262
|
+
} catch {
|
|
4263
|
+
}
|
|
4255
4264
|
try {
|
|
4256
|
-
|
|
4265
|
+
cachedCliLogin = await import('@zapier/zapier-sdk-cli-login');
|
|
4266
|
+
return cachedCliLogin;
|
|
4257
4267
|
} catch {
|
|
4268
|
+
cachedCliLogin = false;
|
|
4258
4269
|
return void 0;
|
|
4259
4270
|
}
|
|
4271
|
+
}
|
|
4272
|
+
function isCliLoginAvailable() {
|
|
4273
|
+
if (cachedCliLogin === void 0) return void 0;
|
|
4274
|
+
return cachedCliLogin !== false;
|
|
4275
|
+
}
|
|
4276
|
+
async function getTokenFromCliLogin(options) {
|
|
4277
|
+
const cliLogin = await getCliLogin();
|
|
4278
|
+
if (!cliLogin) return void 0;
|
|
4260
4279
|
return await cliLogin.getToken(options);
|
|
4261
4280
|
}
|
|
4262
4281
|
async function resolveAuthToken(options = {}) {
|
|
@@ -4682,9 +4701,8 @@ var ZapierApiClient = class {
|
|
|
4682
4701
|
}
|
|
4683
4702
|
if (options.authRequired) {
|
|
4684
4703
|
if (headers.get("Authorization") == null && authToken == null) {
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
);
|
|
4704
|
+
const message = isCliLoginAvailable() === false ? "Authentication required but no credentials available. To use CLI login, install the CLI as a dev dependency (e.g. `npm install -D @zapier/zapier-sdk-cli`) and log in (e.g. `npx zapier-sdk login`). Alternatively, set the ZAPIER_CREDENTIALS environment variable or ZAPIER_CREDENTIALS_CLIENT_ID and ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables." : "Authentication required but no credentials available. Please log in (e.g. `npx zapier-sdk login`) or set the ZAPIER_CREDENTIALS environment variable or ZAPIER_CREDENTIALS_CLIENT_ID and ZAPIER_CREDENTIALS_CLIENT_SECRET environment variables.";
|
|
4705
|
+
throw new ZapierAuthenticationError(message);
|
|
4688
4706
|
}
|
|
4689
4707
|
}
|
|
4690
4708
|
return headers;
|
|
@@ -5447,7 +5465,7 @@ function getCpuTime() {
|
|
|
5447
5465
|
|
|
5448
5466
|
// package.json
|
|
5449
5467
|
var package_default = {
|
|
5450
|
-
version: "0.31.
|
|
5468
|
+
version: "0.31.2"};
|
|
5451
5469
|
|
|
5452
5470
|
// src/plugins/eventEmission/builders.ts
|
|
5453
5471
|
function createBaseEvent(context = {}) {
|
|
@@ -5935,4 +5953,4 @@ var BaseSdkOptionsSchema = z.object({
|
|
|
5935
5953
|
// Use credentials instead
|
|
5936
5954
|
});
|
|
5937
5955
|
|
|
5938
|
-
export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
5956
|
+
export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
@@ -14,6 +14,9 @@ vi.mock("./transport", () => ({
|
|
|
14
14
|
}));
|
|
15
15
|
// Mock CLI login package - default to returning null context
|
|
16
16
|
const mockGetToken = vi.fn().mockResolvedValue(undefined);
|
|
17
|
+
vi.mock("@zapier/zapier-sdk-cli/login", () => ({
|
|
18
|
+
getToken: mockGetToken,
|
|
19
|
+
}));
|
|
17
20
|
vi.mock("@zapier/zapier-sdk-cli-login", () => ({
|
|
18
21
|
getToken: mockGetToken,
|
|
19
22
|
}));
|
|
@@ -11,7 +11,10 @@ const mockTransport = {
|
|
|
11
11
|
vi.mock("../eventEmission/transport", () => ({
|
|
12
12
|
createTransport: vi.fn(() => mockTransport),
|
|
13
13
|
}));
|
|
14
|
-
// Mock CLI login
|
|
14
|
+
// Mock CLI login packages - prevents real token resolution requests
|
|
15
|
+
vi.mock("@zapier/zapier-sdk-cli/login", () => ({
|
|
16
|
+
getToken: vi.fn().mockResolvedValue(undefined),
|
|
17
|
+
}));
|
|
15
18
|
vi.mock("@zapier/zapier-sdk-cli-login", () => ({
|
|
16
19
|
getToken: vi.fn().mockResolvedValue(undefined),
|
|
17
20
|
}));
|
|
@@ -11,7 +11,10 @@ const mockTransport = {
|
|
|
11
11
|
vi.mock("../eventEmission/transport", () => ({
|
|
12
12
|
createTransport: vi.fn(() => mockTransport),
|
|
13
13
|
}));
|
|
14
|
-
// Mock CLI login
|
|
14
|
+
// Mock CLI login packages - prevents real token resolution requests
|
|
15
|
+
vi.mock("@zapier/zapier-sdk-cli/login", () => ({
|
|
16
|
+
getToken: vi.fn().mockResolvedValue(undefined),
|
|
17
|
+
}));
|
|
15
18
|
vi.mock("@zapier/zapier-sdk-cli-login", () => ({
|
|
16
19
|
getToken: vi.fn().mockResolvedValue(undefined),
|
|
17
20
|
}));
|