@zapier/zapier-sdk 0.18.4 → 0.19.0
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 +35 -0
- package/README.md +43 -31
- package/dist/index.cjs +365 -64
- package/dist/index.d.mts +220 -33
- package/dist/index.d.ts +2541 -40
- package/dist/index.mjs +345 -63
- package/package.json +14 -13
- package/dist/api/auth.d.ts +0 -19
- package/dist/api/auth.d.ts.map +0 -1
- package/dist/api/auth.js +0 -70
- package/dist/api/auth.test.d.ts +0 -2
- package/dist/api/auth.test.d.ts.map +0 -1
- package/dist/api/auth.test.js +0 -220
- package/dist/api/client.d.ts +0 -9
- package/dist/api/client.d.ts.map +0 -1
- package/dist/api/client.js +0 -356
- package/dist/api/client.test.d.ts +0 -2
- package/dist/api/client.test.d.ts.map +0 -1
- package/dist/api/client.test.js +0 -96
- package/dist/api/debug.d.ts +0 -14
- package/dist/api/debug.d.ts.map +0 -1
- package/dist/api/debug.js +0 -131
- package/dist/api/debug.test.d.ts +0 -2
- package/dist/api/debug.test.d.ts.map +0 -1
- package/dist/api/debug.test.js +0 -59
- package/dist/api/index.d.ts +0 -30
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -43
- package/dist/api/polling.d.ts +0 -46
- package/dist/api/polling.d.ts.map +0 -1
- package/dist/api/polling.js +0 -139
- package/dist/api/polling.test.d.ts +0 -2
- package/dist/api/polling.test.d.ts.map +0 -1
- package/dist/api/polling.test.js +0 -318
- package/dist/api/schemas.d.ts +0 -422
- package/dist/api/schemas.d.ts.map +0 -1
- package/dist/api/schemas.js +0 -322
- package/dist/api/types.d.ts +0 -83
- package/dist/api/types.d.ts.map +0 -1
- package/dist/api/types.js +0 -1
- package/dist/auth.d.ts +0 -52
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -72
- package/dist/auth.test.d.ts +0 -2
- package/dist/auth.test.d.ts.map +0 -1
- package/dist/auth.test.js +0 -102
- package/dist/constants.d.ts +0 -14
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -42
- package/dist/plugins/api/index.d.ts +0 -12
- package/dist/plugins/api/index.d.ts.map +0 -1
- package/dist/plugins/api/index.js +0 -24
- package/dist/plugins/apps/index.d.ts +0 -15
- package/dist/plugins/apps/index.d.ts.map +0 -1
- package/dist/plugins/apps/index.js +0 -112
- package/dist/plugins/apps/schemas.d.ts +0 -42
- package/dist/plugins/apps/schemas.d.ts.map +0 -1
- package/dist/plugins/apps/schemas.js +0 -14
- package/dist/plugins/eventEmission/builders.d.ts +0 -14
- package/dist/plugins/eventEmission/builders.d.ts.map +0 -1
- package/dist/plugins/eventEmission/builders.js +0 -109
- package/dist/plugins/eventEmission/index.d.ts +0 -38
- package/dist/plugins/eventEmission/index.d.ts.map +0 -1
- package/dist/plugins/eventEmission/index.js +0 -336
- package/dist/plugins/eventEmission/index.test.d.ts +0 -5
- package/dist/plugins/eventEmission/index.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/index.test.js +0 -581
- package/dist/plugins/eventEmission/transport.d.ts +0 -27
- package/dist/plugins/eventEmission/transport.d.ts.map +0 -1
- package/dist/plugins/eventEmission/transport.js +0 -104
- package/dist/plugins/eventEmission/transport.test.d.ts +0 -5
- package/dist/plugins/eventEmission/transport.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/transport.test.js +0 -164
- package/dist/plugins/eventEmission/types.d.ts +0 -63
- package/dist/plugins/eventEmission/types.d.ts.map +0 -1
- package/dist/plugins/eventEmission/types.js +0 -1
- package/dist/plugins/eventEmission/utils.d.ts +0 -45
- package/dist/plugins/eventEmission/utils.d.ts.map +0 -1
- package/dist/plugins/eventEmission/utils.js +0 -114
- package/dist/plugins/fetch/index.d.ts +0 -36
- package/dist/plugins/fetch/index.d.ts.map +0 -1
- package/dist/plugins/fetch/index.js +0 -62
- package/dist/plugins/fetch/schemas.d.ts +0 -19
- package/dist/plugins/fetch/schemas.d.ts.map +0 -1
- package/dist/plugins/fetch/schemas.js +0 -31
- package/dist/plugins/findFirstAuthentication/index.d.ts +0 -21
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +0 -1
- package/dist/plugins/findFirstAuthentication/index.js +0 -36
- package/dist/plugins/findFirstAuthentication/index.test.d.ts +0 -2
- package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +0 -1
- package/dist/plugins/findFirstAuthentication/index.test.js +0 -177
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +0 -20
- package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +0 -1
- package/dist/plugins/findFirstAuthentication/schemas.js +0 -18
- package/dist/plugins/findUniqueAuthentication/index.d.ts +0 -21
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +0 -1
- package/dist/plugins/findUniqueAuthentication/index.js +0 -39
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts +0 -2
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +0 -1
- package/dist/plugins/findUniqueAuthentication/index.test.js +0 -159
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +0 -20
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +0 -1
- package/dist/plugins/findUniqueAuthentication/schemas.js +0 -18
- package/dist/plugins/getAction/index.d.ts +0 -25
- package/dist/plugins/getAction/index.d.ts.map +0 -1
- package/dist/plugins/getAction/index.js +0 -42
- package/dist/plugins/getAction/index.test.d.ts +0 -2
- package/dist/plugins/getAction/index.test.d.ts.map +0 -1
- package/dist/plugins/getAction/index.test.js +0 -211
- package/dist/plugins/getAction/schemas.d.ts +0 -30
- package/dist/plugins/getAction/schemas.d.ts.map +0 -1
- package/dist/plugins/getAction/schemas.js +0 -12
- package/dist/plugins/getApp/index.d.ts +0 -21
- package/dist/plugins/getApp/index.d.ts.map +0 -1
- package/dist/plugins/getApp/index.js +0 -44
- package/dist/plugins/getApp/index.test.d.ts +0 -2
- package/dist/plugins/getApp/index.test.d.ts.map +0 -1
- package/dist/plugins/getApp/index.test.js +0 -157
- package/dist/plugins/getApp/schemas.d.ts +0 -16
- package/dist/plugins/getApp/schemas.d.ts.map +0 -1
- package/dist/plugins/getApp/schemas.js +0 -8
- package/dist/plugins/getAuthentication/index.d.ts +0 -21
- package/dist/plugins/getAuthentication/index.d.ts.map +0 -1
- package/dist/plugins/getAuthentication/index.js +0 -29
- package/dist/plugins/getAuthentication/index.test.d.ts +0 -2
- package/dist/plugins/getAuthentication/index.test.d.ts.map +0 -1
- package/dist/plugins/getAuthentication/index.test.js +0 -106
- package/dist/plugins/getAuthentication/schemas.d.ts +0 -7
- package/dist/plugins/getAuthentication/schemas.d.ts.map +0 -1
- package/dist/plugins/getAuthentication/schemas.js +0 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts +0 -23
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +0 -1
- package/dist/plugins/getInputFieldsSchema/index.js +0 -53
- package/dist/plugins/getInputFieldsSchema/index.test.d.ts +0 -2
- package/dist/plugins/getInputFieldsSchema/index.test.d.ts.map +0 -1
- package/dist/plugins/getInputFieldsSchema/index.test.js +0 -291
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts +0 -28
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts.map +0 -1
- package/dist/plugins/getInputFieldsSchema/schemas.js +0 -13
- package/dist/plugins/getProfile/index.d.ts +0 -25
- package/dist/plugins/getProfile/index.d.ts.map +0 -1
- package/dist/plugins/getProfile/index.js +0 -39
- package/dist/plugins/getProfile/schemas.d.ts +0 -13
- package/dist/plugins/getProfile/schemas.d.ts.map +0 -1
- package/dist/plugins/getProfile/schemas.js +0 -6
- package/dist/plugins/listActions/index.d.ts +0 -30
- package/dist/plugins/listActions/index.d.ts.map +0 -1
- package/dist/plugins/listActions/index.js +0 -75
- package/dist/plugins/listActions/index.test.d.ts +0 -2
- package/dist/plugins/listActions/index.test.d.ts.map +0 -1
- package/dist/plugins/listActions/index.test.js +0 -453
- package/dist/plugins/listActions/schemas.d.ts +0 -35
- package/dist/plugins/listActions/schemas.d.ts.map +0 -1
- package/dist/plugins/listActions/schemas.js +0 -22
- package/dist/plugins/listApps/index.d.ts +0 -19
- package/dist/plugins/listApps/index.d.ts.map +0 -1
- package/dist/plugins/listApps/index.js +0 -67
- package/dist/plugins/listApps/index.test.d.ts +0 -2
- package/dist/plugins/listApps/index.test.d.ts.map +0 -1
- package/dist/plugins/listApps/index.test.js +0 -121
- package/dist/plugins/listApps/schemas.d.ts +0 -47
- package/dist/plugins/listApps/schemas.d.ts.map +0 -1
- package/dist/plugins/listApps/schemas.js +0 -49
- package/dist/plugins/listAuthentications/index.d.ts +0 -24
- package/dist/plugins/listAuthentications/index.d.ts.map +0 -1
- package/dist/plugins/listAuthentications/index.js +0 -77
- package/dist/plugins/listAuthentications/index.test.d.ts +0 -2
- package/dist/plugins/listAuthentications/index.test.d.ts.map +0 -1
- package/dist/plugins/listAuthentications/index.test.js +0 -848
- package/dist/plugins/listAuthentications/schemas.d.ts +0 -30
- package/dist/plugins/listAuthentications/schemas.d.ts.map +0 -1
- package/dist/plugins/listAuthentications/schemas.js +0 -32
- package/dist/plugins/listInputFieldChoices/index.d.ts +0 -33
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +0 -1
- package/dist/plugins/listInputFieldChoices/index.js +0 -115
- package/dist/plugins/listInputFieldChoices/index.test.d.ts +0 -2
- package/dist/plugins/listInputFieldChoices/index.test.d.ts.map +0 -1
- package/dist/plugins/listInputFieldChoices/index.test.js +0 -717
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +0 -43
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +0 -1
- package/dist/plugins/listInputFieldChoices/schemas.js +0 -65
- package/dist/plugins/listInputFields/index.d.ts +0 -34
- package/dist/plugins/listInputFields/index.d.ts.map +0 -1
- package/dist/plugins/listInputFields/index.js +0 -204
- package/dist/plugins/listInputFields/index.test.d.ts +0 -2
- package/dist/plugins/listInputFields/index.test.d.ts.map +0 -1
- package/dist/plugins/listInputFields/index.test.js +0 -359
- package/dist/plugins/listInputFields/schemas.d.ts +0 -35
- package/dist/plugins/listInputFields/schemas.d.ts.map +0 -1
- package/dist/plugins/listInputFields/schemas.js +0 -23
- package/dist/plugins/manifest/index.d.ts +0 -85
- package/dist/plugins/manifest/index.d.ts.map +0 -1
- package/dist/plugins/manifest/index.js +0 -376
- package/dist/plugins/manifest/index.test.d.ts +0 -2
- package/dist/plugins/manifest/index.test.d.ts.map +0 -1
- package/dist/plugins/manifest/index.test.js +0 -1139
- package/dist/plugins/manifest/schemas.d.ts +0 -57
- package/dist/plugins/manifest/schemas.d.ts.map +0 -1
- package/dist/plugins/manifest/schemas.js +0 -50
- package/dist/plugins/registry/index.d.ts +0 -21
- package/dist/plugins/registry/index.d.ts.map +0 -1
- package/dist/plugins/registry/index.js +0 -117
- package/dist/plugins/request/index.d.ts +0 -21
- package/dist/plugins/request/index.d.ts.map +0 -1
- package/dist/plugins/request/index.js +0 -76
- package/dist/plugins/request/index.test.d.ts +0 -2
- package/dist/plugins/request/index.test.d.ts.map +0 -1
- package/dist/plugins/request/index.test.js +0 -337
- package/dist/plugins/request/schemas.d.ts +0 -54
- package/dist/plugins/request/schemas.d.ts.map +0 -1
- package/dist/plugins/request/schemas.js +0 -41
- package/dist/plugins/runAction/index.d.ts +0 -33
- package/dist/plugins/runAction/index.d.ts.map +0 -1
- package/dist/plugins/runAction/index.js +0 -108
- package/dist/plugins/runAction/index.test.d.ts +0 -2
- package/dist/plugins/runAction/index.test.d.ts.map +0 -1
- package/dist/plugins/runAction/index.test.js +0 -333
- package/dist/plugins/runAction/schemas.d.ts +0 -34
- package/dist/plugins/runAction/schemas.d.ts.map +0 -1
- package/dist/plugins/runAction/schemas.js +0 -23
- package/dist/resolvers/actionKey.d.ts +0 -15
- package/dist/resolvers/actionKey.d.ts.map +0 -1
- package/dist/resolvers/actionKey.js +0 -19
- package/dist/resolvers/actionType.d.ts +0 -10
- package/dist/resolvers/actionType.d.ts.map +0 -1
- package/dist/resolvers/actionType.js +0 -21
- package/dist/resolvers/appKey.d.ts +0 -3
- package/dist/resolvers/appKey.d.ts.map +0 -1
- package/dist/resolvers/appKey.js +0 -5
- package/dist/resolvers/authenticationId.d.ts +0 -9
- package/dist/resolvers/authenticationId.d.ts.map +0 -1
- package/dist/resolvers/authenticationId.js +0 -42
- package/dist/resolvers/index.d.ts +0 -8
- package/dist/resolvers/index.d.ts.map +0 -1
- package/dist/resolvers/index.js +0 -8
- package/dist/resolvers/inputFieldKey.d.ts +0 -11
- package/dist/resolvers/inputFieldKey.d.ts.map +0 -1
- package/dist/resolvers/inputFieldKey.js +0 -47
- package/dist/resolvers/inputs.d.ts +0 -17
- package/dist/resolvers/inputs.d.ts.map +0 -1
- package/dist/resolvers/inputs.js +0 -50
- package/dist/schemas/Action.d.ts +0 -24
- package/dist/schemas/Action.d.ts.map +0 -1
- package/dist/schemas/Action.js +0 -40
- package/dist/schemas/App.d.ts +0 -57
- package/dist/schemas/App.d.ts.map +0 -1
- package/dist/schemas/App.js +0 -26
- package/dist/schemas/Auth.d.ts +0 -55
- package/dist/schemas/Auth.d.ts.map +0 -1
- package/dist/schemas/Auth.js +0 -33
- package/dist/schemas/Field.d.ts +0 -61
- package/dist/schemas/Field.d.ts.map +0 -1
- package/dist/schemas/Field.js +0 -116
- package/dist/schemas/Run.d.ts +0 -3
- package/dist/schemas/Run.d.ts.map +0 -1
- package/dist/schemas/Run.js +0 -31
- package/dist/schemas/UserProfile.d.ts +0 -13
- package/dist/schemas/UserProfile.d.ts.map +0 -1
- package/dist/schemas/UserProfile.js +0 -32
- package/dist/sdk.d.ts +0 -146
- package/dist/sdk.d.ts.map +0 -1
- package/dist/sdk.js +0 -112
- package/dist/sdk.test.d.ts +0 -2
- package/dist/sdk.test.d.ts.map +0 -1
- package/dist/sdk.test.js +0 -258
- package/dist/services/implementations.d.ts +0 -63
- package/dist/services/implementations.d.ts.map +0 -1
- package/dist/services/implementations.js +0 -80
- package/dist/types/domain.d.ts +0 -52
- package/dist/types/domain.d.ts.map +0 -1
- package/dist/types/domain.js +0 -1
- package/dist/types/domain.test.d.ts +0 -2
- package/dist/types/domain.test.d.ts.map +0 -1
- package/dist/types/domain.test.js +0 -39
- package/dist/types/errors.d.ts +0 -143
- package/dist/types/errors.d.ts.map +0 -1
- package/dist/types/errors.js +0 -187
- package/dist/types/events.d.ts +0 -38
- package/dist/types/events.d.ts.map +0 -1
- package/dist/types/events.js +0 -7
- package/dist/types/functions.d.ts +0 -27
- package/dist/types/functions.d.ts.map +0 -1
- package/dist/types/functions.js +0 -1
- package/dist/types/plugin.d.ts +0 -75
- package/dist/types/plugin.d.ts.map +0 -1
- package/dist/types/plugin.js +0 -9
- package/dist/types/properties.d.ts +0 -33
- package/dist/types/properties.d.ts.map +0 -1
- package/dist/types/properties.js +0 -52
- package/dist/types/sdk.d.ts +0 -69
- package/dist/types/sdk.d.ts.map +0 -1
- package/dist/types/sdk.js +0 -4
- package/dist/types/telemetry-events.d.ts +0 -105
- package/dist/types/telemetry-events.d.ts.map +0 -1
- package/dist/types/telemetry-events.js +0 -8
- package/dist/utils/array-utils.d.ts +0 -31
- package/dist/utils/array-utils.d.ts.map +0 -1
- package/dist/utils/array-utils.js +0 -36
- package/dist/utils/array-utils.test.d.ts +0 -2
- package/dist/utils/array-utils.test.d.ts.map +0 -1
- package/dist/utils/array-utils.test.js +0 -107
- package/dist/utils/batch-utils.d.ts +0 -72
- package/dist/utils/batch-utils.d.ts.map +0 -1
- package/dist/utils/batch-utils.js +0 -162
- package/dist/utils/batch-utils.test.d.ts +0 -2
- package/dist/utils/batch-utils.test.d.ts.map +0 -1
- package/dist/utils/batch-utils.test.js +0 -476
- package/dist/utils/domain-utils.d.ts +0 -66
- package/dist/utils/domain-utils.d.ts.map +0 -1
- package/dist/utils/domain-utils.js +0 -164
- package/dist/utils/domain-utils.test.d.ts +0 -2
- package/dist/utils/domain-utils.test.d.ts.map +0 -1
- package/dist/utils/domain-utils.test.js +0 -346
- package/dist/utils/file-utils.d.ts +0 -4
- package/dist/utils/file-utils.d.ts.map +0 -1
- package/dist/utils/file-utils.js +0 -74
- package/dist/utils/file-utils.test.d.ts +0 -2
- package/dist/utils/file-utils.test.d.ts.map +0 -1
- package/dist/utils/file-utils.test.js +0 -51
- package/dist/utils/function-utils.d.ts +0 -73
- package/dist/utils/function-utils.d.ts.map +0 -1
- package/dist/utils/function-utils.js +0 -245
- package/dist/utils/function-utils.test.d.ts +0 -2
- package/dist/utils/function-utils.test.d.ts.map +0 -1
- package/dist/utils/function-utils.test.js +0 -110
- package/dist/utils/id-utils.d.ts +0 -13
- package/dist/utils/id-utils.d.ts.map +0 -1
- package/dist/utils/id-utils.js +0 -22
- package/dist/utils/id-utils.test.d.ts +0 -2
- package/dist/utils/id-utils.test.d.ts.map +0 -1
- package/dist/utils/id-utils.test.js +0 -22
- package/dist/utils/pagination-utils.d.ts +0 -37
- package/dist/utils/pagination-utils.d.ts.map +0 -1
- package/dist/utils/pagination-utils.js +0 -165
- package/dist/utils/pagination-utils.test.d.ts +0 -17
- package/dist/utils/pagination-utils.test.d.ts.map +0 -1
- package/dist/utils/pagination-utils.test.js +0 -461
- package/dist/utils/retry-utils.d.ts +0 -45
- package/dist/utils/retry-utils.d.ts.map +0 -1
- package/dist/utils/retry-utils.js +0 -51
- package/dist/utils/retry-utils.test.d.ts +0 -2
- package/dist/utils/retry-utils.test.d.ts.map +0 -1
- package/dist/utils/retry-utils.test.js +0 -90
- package/dist/utils/schema-utils.d.ts +0 -69
- package/dist/utils/schema-utils.d.ts.map +0 -1
- package/dist/utils/schema-utils.js +0 -72
- package/dist/utils/string-utils.d.ts +0 -40
- package/dist/utils/string-utils.d.ts.map +0 -1
- package/dist/utils/string-utils.js +0 -69
- package/dist/utils/string-utils.test.d.ts +0 -2
- package/dist/utils/string-utils.test.d.ts.map +0 -1
- package/dist/utils/string-utils.test.js +0 -59
- package/dist/utils/telemetry-utils.d.ts +0 -44
- package/dist/utils/telemetry-utils.d.ts.map +0 -1
- package/dist/utils/telemetry-utils.js +0 -55
- package/dist/utils/telemetry-utils.test.d.ts +0 -2
- package/dist/utils/telemetry-utils.test.d.ts.map +0 -1
- package/dist/utils/telemetry-utils.test.js +0 -94
- package/dist/utils/url-utils.d.ts +0 -19
- package/dist/utils/url-utils.d.ts.map +0 -1
- package/dist/utils/url-utils.js +0 -62
- package/dist/utils/url-utils.test.d.ts +0 -2
- package/dist/utils/url-utils.test.d.ts.map +0 -1
- package/dist/utils/url-utils.test.js +0 -103
- package/dist/utils/validation.d.ts +0 -4
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js +0 -30
- package/dist/utils/validation.test.d.ts +0 -2
- package/dist/utils/validation.test.d.ts.map +0 -1
- package/dist/utils/validation.test.js +0 -44
package/dist/api/client.test.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { createZapierApi } from "./client";
|
|
3
|
-
import * as auth from "../auth";
|
|
4
|
-
vi.mock("../auth");
|
|
5
|
-
describe("ApiClient", () => {
|
|
6
|
-
const mockResolveAuthToken = vi.mocked(auth.resolveAuthToken);
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
vi.clearAllMocks();
|
|
9
|
-
// Prevent any actual HTTP calls
|
|
10
|
-
global.fetch = vi.fn().mockResolvedValue({
|
|
11
|
-
ok: true,
|
|
12
|
-
status: 200,
|
|
13
|
-
json: () => Promise.resolve({ data: "test" }),
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
describe("authentication token resolution", () => {
|
|
17
|
-
it("should pass authBaseUrl to resolveAuthToken when provided", async () => {
|
|
18
|
-
mockResolveAuthToken.mockResolvedValue("test-token");
|
|
19
|
-
const client = createZapierApi({
|
|
20
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
21
|
-
authBaseUrl: "https://auth.custom.zapier.dev",
|
|
22
|
-
debug: false,
|
|
23
|
-
});
|
|
24
|
-
// Make a request that would trigger token resolution
|
|
25
|
-
await client.get("/test", { authRequired: true });
|
|
26
|
-
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
27
|
-
token: undefined,
|
|
28
|
-
getToken: undefined,
|
|
29
|
-
onEvent: undefined,
|
|
30
|
-
fetch: expect.any(Function),
|
|
31
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
32
|
-
authBaseUrl: "https://auth.custom.zapier.dev",
|
|
33
|
-
authClientId: undefined,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it("should pass undefined authBaseUrl when not provided", async () => {
|
|
37
|
-
mockResolveAuthToken.mockResolvedValue("test-token");
|
|
38
|
-
const client = createZapierApi({
|
|
39
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
40
|
-
// authBaseUrl intentionally omitted
|
|
41
|
-
debug: false,
|
|
42
|
-
});
|
|
43
|
-
// Make a request that would trigger token resolution
|
|
44
|
-
await client.get("/test", { authRequired: true });
|
|
45
|
-
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
46
|
-
token: undefined,
|
|
47
|
-
getToken: undefined,
|
|
48
|
-
onEvent: undefined,
|
|
49
|
-
fetch: expect.any(Function),
|
|
50
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
51
|
-
authBaseUrl: undefined,
|
|
52
|
-
authClientId: undefined,
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it("should pass authClientId to resolveAuthToken when provided", async () => {
|
|
56
|
-
mockResolveAuthToken.mockResolvedValue("test-token");
|
|
57
|
-
const client = createZapierApi({
|
|
58
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
59
|
-
authClientId: "custom-client-id",
|
|
60
|
-
debug: false,
|
|
61
|
-
});
|
|
62
|
-
// Make a request that would trigger token resolution
|
|
63
|
-
await client.get("/test", { authRequired: true });
|
|
64
|
-
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
65
|
-
token: undefined,
|
|
66
|
-
getToken: undefined,
|
|
67
|
-
onEvent: undefined,
|
|
68
|
-
fetch: expect.any(Function),
|
|
69
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
70
|
-
authBaseUrl: undefined,
|
|
71
|
-
authClientId: "custom-client-id",
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
it("should not call resolveAuthToken when token is provided directly", async () => {
|
|
75
|
-
mockResolveAuthToken.mockResolvedValue("direct-token");
|
|
76
|
-
const client = createZapierApi({
|
|
77
|
-
token: "direct-token",
|
|
78
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
79
|
-
authBaseUrl: "https://auth.custom.zapier.dev",
|
|
80
|
-
debug: false,
|
|
81
|
-
});
|
|
82
|
-
// Make a request that would use the direct token
|
|
83
|
-
await client.get("/test", { authRequired: true });
|
|
84
|
-
// resolveAuthToken is still called, but it returns the direct token immediately
|
|
85
|
-
expect(mockResolveAuthToken).toHaveBeenCalledWith({
|
|
86
|
-
token: "direct-token",
|
|
87
|
-
getToken: undefined,
|
|
88
|
-
onEvent: undefined,
|
|
89
|
-
fetch: expect.any(Function),
|
|
90
|
-
baseUrl: "https://api.custom.zapier.dev",
|
|
91
|
-
authBaseUrl: "https://auth.custom.zapier.dev",
|
|
92
|
-
authClientId: undefined,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
package/dist/api/debug.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debug Logging Utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides debug logging capabilities for API requests and responses,
|
|
5
|
-
* including request timing and detailed logging of HTTP interactions.
|
|
6
|
-
*/
|
|
7
|
-
import type { DebugLogger } from "./types";
|
|
8
|
-
export declare function createDebugLogger(enabled: boolean): DebugLogger;
|
|
9
|
-
export declare function censorHeaders(headers?: HeadersInit): Record<string, string> | undefined;
|
|
10
|
-
export declare function createDebugFetch(options: {
|
|
11
|
-
originalFetch: typeof globalThis.fetch;
|
|
12
|
-
debugLog: DebugLogger;
|
|
13
|
-
}): (input: RequestInfo | URL, options?: RequestInit) => Promise<Response>;
|
|
14
|
-
//# sourceMappingURL=debug.d.ts.map
|
package/dist/api/debug.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/api/debug.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAa3C,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAwC/D;AAED,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,WAAW,GACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAwCpC;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,aAAa,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACvC,QAAQ,EAAE,WAAW,CAAC;CACvB,IAEe,OAAO,WAAW,GAAG,GAAG,EAAE,UAAU,WAAW,uBA0C9D"}
|
package/dist/api/debug.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debug Logging Utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides debug logging capabilities for API requests and responses,
|
|
5
|
-
* including request timing and detailed logging of HTTP interactions.
|
|
6
|
-
*/
|
|
7
|
-
// We don't want to import util since it might not work in a browser. So we'll lazily load it and cache the result so
|
|
8
|
-
// we can use it synchronously after that. The types above are just to make our linter happy.
|
|
9
|
-
let utilModule = null;
|
|
10
|
-
let utilPromise = null;
|
|
11
|
-
export function createDebugLogger(enabled) {
|
|
12
|
-
if (!enabled) {
|
|
13
|
-
return () => { }; // No-op function when debug is disabled
|
|
14
|
-
}
|
|
15
|
-
// Try to load util module on first use.
|
|
16
|
-
if (!utilPromise) {
|
|
17
|
-
utilPromise = import("util")
|
|
18
|
-
.then((util) => {
|
|
19
|
-
utilModule = util;
|
|
20
|
-
return util;
|
|
21
|
-
})
|
|
22
|
-
.catch(() => {
|
|
23
|
-
utilModule = null;
|
|
24
|
-
return null;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return (message, data) => {
|
|
28
|
-
if (data === undefined || data === "") {
|
|
29
|
-
console.log(`[Zapier SDK] ${message}`);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
// Use cached module if available for sync logging. Yes, this means if the util module isn't yet loaded, we'll fall
|
|
33
|
-
// back to a plain old console.log, which might mean we don't see proper formatting/nesting. But that's unlikely
|
|
34
|
-
// since this logging happens during async fetching. Alternatively, we could switch to async logging, but this
|
|
35
|
-
// seems fine since we have to have a fallback anyway.
|
|
36
|
-
if (utilModule) {
|
|
37
|
-
const formatted = utilModule.inspect(data, {
|
|
38
|
-
colors: true,
|
|
39
|
-
depth: null,
|
|
40
|
-
breakLength: 80,
|
|
41
|
-
});
|
|
42
|
-
console.log(`[Zapier SDK] ${message}`, formatted);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
// Fallback - browser will handle formatting automatically
|
|
46
|
-
console.log(`[Zapier SDK] ${message}`, data);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export function censorHeaders(headers) {
|
|
51
|
-
if (!headers)
|
|
52
|
-
return headers;
|
|
53
|
-
const headersObj = new Headers(headers);
|
|
54
|
-
const authKeys = ["authorization", "x-api-key"];
|
|
55
|
-
for (const [key, value] of headersObj.entries()) {
|
|
56
|
-
if (authKeys.some((authKey) => key.toLowerCase() === authKey)) {
|
|
57
|
-
// Find space after prefix (like "Bearer ")
|
|
58
|
-
const spaceIndex = value.indexOf(" ");
|
|
59
|
-
if (spaceIndex > 0 && spaceIndex < value.length - 1) {
|
|
60
|
-
const prefix = value.substring(0, spaceIndex + 1); // Include the space
|
|
61
|
-
const token = value.substring(spaceIndex + 1);
|
|
62
|
-
if (token.length > 12) {
|
|
63
|
-
// Show first 4 and last 4 chars, truncate middle
|
|
64
|
-
const start = token.substring(0, 4);
|
|
65
|
-
const end = token.substring(token.length - 4);
|
|
66
|
-
headersObj.set(key, `${prefix}${start}...${end}`);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// Short token, use first character + three dots
|
|
70
|
-
const firstChar = token.charAt(0);
|
|
71
|
-
headersObj.set(key, `${prefix}${firstChar}...`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
// No prefix found, truncate the whole value
|
|
76
|
-
if (value.length > 12) {
|
|
77
|
-
const start = value.substring(0, 4);
|
|
78
|
-
const end = value.substring(value.length - 4);
|
|
79
|
-
headersObj.set(key, `${start}...${end}`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
// Short token, use first character + three dots
|
|
83
|
-
const firstChar = value.charAt(0);
|
|
84
|
-
headersObj.set(key, `${firstChar}...`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return Object.fromEntries(headersObj);
|
|
90
|
-
}
|
|
91
|
-
export function createDebugFetch(options) {
|
|
92
|
-
const { originalFetch, debugLog } = options;
|
|
93
|
-
return async (input, options) => {
|
|
94
|
-
const startTime = Date.now();
|
|
95
|
-
// Convert input to URL string for logging
|
|
96
|
-
const url = typeof input === "string" ? input : input.toString();
|
|
97
|
-
const method = options?.method || "GET";
|
|
98
|
-
debugLog(`→ ${method} ${url}`, {
|
|
99
|
-
headers: censorHeaders(options?.headers),
|
|
100
|
-
body: options?.body && typeof options.body === "string"
|
|
101
|
-
? (() => {
|
|
102
|
-
try {
|
|
103
|
-
return JSON.parse(options.body);
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
return options.body;
|
|
107
|
-
}
|
|
108
|
-
})()
|
|
109
|
-
: options?.body,
|
|
110
|
-
});
|
|
111
|
-
try {
|
|
112
|
-
const response = await originalFetch(input, options);
|
|
113
|
-
const duration = Date.now() - startTime;
|
|
114
|
-
debugLog(`← ${response.status} ${response.statusText} (${duration}ms)`, {
|
|
115
|
-
url,
|
|
116
|
-
method,
|
|
117
|
-
status: response.status,
|
|
118
|
-
});
|
|
119
|
-
return response;
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
const duration = Date.now() - startTime;
|
|
123
|
-
debugLog(`✖ Request failed (${duration}ms)`, {
|
|
124
|
-
url,
|
|
125
|
-
method,
|
|
126
|
-
error: error instanceof Error ? error.message : error,
|
|
127
|
-
});
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
package/dist/api/debug.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debug.test.d.ts","sourceRoot":"","sources":["../../src/api/debug.test.ts"],"names":[],"mappings":""}
|
package/dist/api/debug.test.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { censorHeaders } from "./debug";
|
|
3
|
-
describe("censorHeaders", () => {
|
|
4
|
-
it("should return undefined for undefined headers", () => {
|
|
5
|
-
expect(censorHeaders(undefined)).toBeUndefined();
|
|
6
|
-
});
|
|
7
|
-
it("should return headers unchanged for non-auth headers", () => {
|
|
8
|
-
const headers = {
|
|
9
|
-
"Content-Type": "application/json",
|
|
10
|
-
"User-Agent": "test",
|
|
11
|
-
};
|
|
12
|
-
const result = censorHeaders(headers);
|
|
13
|
-
// Headers API normalizes header names to lowercase
|
|
14
|
-
expect(result["content-type"]).toBe("application/json");
|
|
15
|
-
expect(result["user-agent"]).toBe("test");
|
|
16
|
-
});
|
|
17
|
-
it("should censor authorization header with Bearer prefix - long token", () => {
|
|
18
|
-
const headers = { authorization: "Bearer abcdef1234567890xyz" };
|
|
19
|
-
const result = censorHeaders(headers);
|
|
20
|
-
expect(result.authorization).toBe("Bearer abcd...0xyz");
|
|
21
|
-
});
|
|
22
|
-
it("should censor authorization header with Bearer prefix - short token", () => {
|
|
23
|
-
const headers = { authorization: "Bearer short123" };
|
|
24
|
-
const result = censorHeaders(headers);
|
|
25
|
-
expect(result.authorization).toBe("Bearer s...");
|
|
26
|
-
});
|
|
27
|
-
it("should censor x-api-key header - long token", () => {
|
|
28
|
-
const headers = { "x-api-key": "sk-1234567890abcdefghij" };
|
|
29
|
-
const result = censorHeaders(headers);
|
|
30
|
-
expect(result["x-api-key"]).toBe("sk-1...ghij");
|
|
31
|
-
});
|
|
32
|
-
it("should censor x-api-key header - short token", () => {
|
|
33
|
-
const headers = { "x-api-key": "short" };
|
|
34
|
-
const result = censorHeaders(headers);
|
|
35
|
-
expect(result["x-api-key"]).toBe("s...");
|
|
36
|
-
});
|
|
37
|
-
it("should handle Headers object input", () => {
|
|
38
|
-
const headers = new Headers();
|
|
39
|
-
headers.set("authorization", "Bearer verylongtoken123456789");
|
|
40
|
-
const result = censorHeaders(headers);
|
|
41
|
-
expect(result.authorization).toBe("Bearer very...6789");
|
|
42
|
-
});
|
|
43
|
-
it("should handle mixed case authorization headers", () => {
|
|
44
|
-
const headers = { Authorization: "Bearer mixedcasetoken123" };
|
|
45
|
-
const result = censorHeaders(headers);
|
|
46
|
-
expect(result.authorization).toBe("Bearer mixe...n123");
|
|
47
|
-
});
|
|
48
|
-
it("should preserve non-auth headers while censoring auth headers", () => {
|
|
49
|
-
const headers = {
|
|
50
|
-
"Content-Type": "application/json",
|
|
51
|
-
authorization: "Bearer shouldbecensored123456789",
|
|
52
|
-
"User-Agent": "test-agent",
|
|
53
|
-
};
|
|
54
|
-
const result = censorHeaders(headers);
|
|
55
|
-
expect(result["content-type"]).toBe("application/json");
|
|
56
|
-
expect(result["user-agent"]).toBe("test-agent");
|
|
57
|
-
expect(result.authorization).toBe("Bearer shou...6789");
|
|
58
|
-
});
|
|
59
|
-
});
|
package/dist/api/index.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zapier API Client Module
|
|
3
|
-
*
|
|
4
|
-
* This module provides a centralized API layer for all HTTP interactions
|
|
5
|
-
* with Zapier's various APIs. It handles authentication, error handling,
|
|
6
|
-
* polling, and provides consistent patterns across all services.
|
|
7
|
-
*/
|
|
8
|
-
export type { ApiClient, ApiClientOptions, RequestOptions, PollOptions, DebugLogger, Action, Field, Choice, ActionExecutionResult, ActionField, ActionFieldChoice, NeedsRequest, NeedsResponse, Authentication, AuthenticationsResponse, Implementation, ImplementationsResponse, } from "./types";
|
|
9
|
-
import type { ApiClient } from "./types";
|
|
10
|
-
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
11
|
-
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
12
|
-
export { pollUntilComplete } from "./polling";
|
|
13
|
-
export { createZapierApi } from "./client";
|
|
14
|
-
export declare function generateRequestId(): string;
|
|
15
|
-
/**
|
|
16
|
-
* Utility function to get or create an API client for standalone functions
|
|
17
|
-
*
|
|
18
|
-
* @param config - Configuration that may include an existing API client
|
|
19
|
-
* @returns ApiClient instance
|
|
20
|
-
*/
|
|
21
|
-
export declare function getOrCreateApiClient(config: {
|
|
22
|
-
baseUrl?: string;
|
|
23
|
-
authBaseUrl?: string;
|
|
24
|
-
token?: string;
|
|
25
|
-
getToken?: () => Promise<string | undefined>;
|
|
26
|
-
api?: ApiClient;
|
|
27
|
-
debug?: boolean;
|
|
28
|
-
fetch?: typeof globalThis.fetch;
|
|
29
|
-
}): ApiClient;
|
|
30
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAEV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,EAEX,MAAM,EACN,KAAK,EACL,MAAM,EACN,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAGvD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAM3C,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC,GAAG,SAAS,CAwBZ"}
|
package/dist/api/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zapier API Client Module
|
|
3
|
-
*
|
|
4
|
-
* This module provides a centralized API layer for all HTTP interactions
|
|
5
|
-
* with Zapier's various APIs. It handles authentication, error handling,
|
|
6
|
-
* polling, and provides consistent patterns across all services.
|
|
7
|
-
*/
|
|
8
|
-
import { ZAPIER_BASE_URL } from "../constants";
|
|
9
|
-
// Re-export authentication utilities
|
|
10
|
-
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
11
|
-
// Re-export debug utilities
|
|
12
|
-
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
13
|
-
// Re-export polling utilities
|
|
14
|
-
export { pollUntilComplete } from "./polling";
|
|
15
|
-
// Re-export the main client factory
|
|
16
|
-
export { createZapierApi } from "./client";
|
|
17
|
-
// Import for local use
|
|
18
|
-
import { createZapierApi } from "./client";
|
|
19
|
-
// Utility Functions
|
|
20
|
-
export function generateRequestId() {
|
|
21
|
-
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Utility function to get or create an API client for standalone functions
|
|
25
|
-
*
|
|
26
|
-
* @param config - Configuration that may include an existing API client
|
|
27
|
-
* @returns ApiClient instance
|
|
28
|
-
*/
|
|
29
|
-
export function getOrCreateApiClient(config) {
|
|
30
|
-
const { baseUrl = ZAPIER_BASE_URL, authBaseUrl, token, getToken, api: providedApi, debug = false, fetch: customFetch, } = config;
|
|
31
|
-
// Use provided API client or create a new one
|
|
32
|
-
if (providedApi) {
|
|
33
|
-
return providedApi;
|
|
34
|
-
}
|
|
35
|
-
return createZapierApi({
|
|
36
|
-
baseUrl,
|
|
37
|
-
authBaseUrl,
|
|
38
|
-
token,
|
|
39
|
-
getToken,
|
|
40
|
-
debug,
|
|
41
|
-
fetch: customFetch,
|
|
42
|
-
});
|
|
43
|
-
}
|
package/dist/api/polling.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Polling Utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides utilities for polling HTTP endpoints until completion,
|
|
5
|
-
* with configurable retry logic and exponential backoff.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Options for the polling function
|
|
9
|
-
*/
|
|
10
|
-
export interface PollOptions<TResult = unknown> {
|
|
11
|
-
/** Function that performs the HTTP request */
|
|
12
|
-
fetchPoll: () => Promise<Response>;
|
|
13
|
-
/** Maximum time to wait for completion (in milliseconds) */
|
|
14
|
-
timeoutMs?: number;
|
|
15
|
-
/** HTTP status code indicating successful completion */
|
|
16
|
-
successStatus?: number;
|
|
17
|
-
/** HTTP status code indicating the operation is still pending */
|
|
18
|
-
pendingStatus?: number;
|
|
19
|
-
/** Function to extract the result from the response */
|
|
20
|
-
resultExtractor?: (response: unknown) => TResult;
|
|
21
|
-
/** Initial delay before the first poll attempt (in milliseconds) */
|
|
22
|
-
initialDelay?: number;
|
|
23
|
-
}
|
|
24
|
-
declare const enum PollStatus {
|
|
25
|
-
Success = "success",
|
|
26
|
-
Continue = "continue"
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Result of a poll operation
|
|
30
|
-
*/
|
|
31
|
-
export type PollResult<TResult = unknown> = {
|
|
32
|
-
result?: TResult;
|
|
33
|
-
status: PollStatus;
|
|
34
|
-
errorCount: number;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Polls an endpoint until completion, timeout, or error
|
|
38
|
-
* @param options Configuration options for polling
|
|
39
|
-
* @returns The extracted result from the successful response
|
|
40
|
-
* @throws {ZapierValidationError} When the input parameters are invalid
|
|
41
|
-
* @throws {ZapierTimeoutError} When the operation times out
|
|
42
|
-
* @throws {ZapierApiError} When the API returns consecutive errors
|
|
43
|
-
*/
|
|
44
|
-
export declare function pollUntilComplete<TResult = unknown>(options: PollOptions<TResult>): Promise<TResult>;
|
|
45
|
-
export {};
|
|
46
|
-
//# sourceMappingURL=polling.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/api/polling.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,GAAG,OAAO;IAC5C,8CAA8C;IAC9C,SAAS,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC;IACjD,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,mBAAW,UAAU;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,GAAG,OAAO,IAAI;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAwDF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,GAAG,OAAO,EACvD,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC,CAyGlB"}
|
package/dist/api/polling.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Polling Utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides utilities for polling HTTP endpoints until completion,
|
|
5
|
-
* with configurable retry logic and exponential backoff.
|
|
6
|
-
*/
|
|
7
|
-
import { ZapierTimeoutError, ZapierApiError, ZapierValidationError, } from "../types/errors";
|
|
8
|
-
import { setTimeout } from "timers/promises";
|
|
9
|
-
import { calculateWaitTime, MAX_CONSECUTIVE_ERRORS, } from "../utils/retry-utils";
|
|
10
|
-
// Constants
|
|
11
|
-
const DEFAULT_TIMEOUT_MS = 180000;
|
|
12
|
-
const DEFAULT_SUCCESS_STATUS = 200;
|
|
13
|
-
const DEFAULT_PENDING_STATUS = 202;
|
|
14
|
-
const DEFAULT_INITIAL_DELAY_MS = 50;
|
|
15
|
-
const DEFAULT_MAX_POLLING_INTERVAL_MS = 10000;
|
|
16
|
-
const MAX_TIMEOUT_BUFFER_MS = 10000;
|
|
17
|
-
// Polling stages: [threshold_ms, interval_ms]
|
|
18
|
-
// Note: These are default stages, actual hard timeout is enforced separately below
|
|
19
|
-
const DEFAULT_POLLING_STAGES = [
|
|
20
|
-
[125, 125], // Up to 125ms: poll every 125ms
|
|
21
|
-
[375, 250], // Up to 375ms: poll every 250ms
|
|
22
|
-
[875, 500], // Up to 875ms: poll every 500ms
|
|
23
|
-
[10000, 1000], // Up to 10s: poll every 1s
|
|
24
|
-
[30000, 2500], // Up to 30s: poll every 2.5s
|
|
25
|
-
[60000, 5000], // Up to 60s: poll every 5s
|
|
26
|
-
];
|
|
27
|
-
const processResponse = async (response, successStatus, pendingStatus, resultExtractor, errorCount) => {
|
|
28
|
-
// Handle other error responses
|
|
29
|
-
if (!response.ok) {
|
|
30
|
-
return {
|
|
31
|
-
status: "continue" /* PollStatus.Continue */,
|
|
32
|
-
// If for some reason the status is pending, we don't want to increment the error count
|
|
33
|
-
errorCount: response.status === pendingStatus ? errorCount : errorCount + 1,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// Check for successful completion
|
|
37
|
-
if (response.status === successStatus) {
|
|
38
|
-
try {
|
|
39
|
-
const resultJson = await response.json();
|
|
40
|
-
return {
|
|
41
|
-
result: resultExtractor(resultJson),
|
|
42
|
-
status: "success" /* PollStatus.Success */,
|
|
43
|
-
errorCount: 0,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
throw new ZapierApiError("Result extractor failed to parse successful response as JSON", {
|
|
48
|
-
statusCode: response.status,
|
|
49
|
-
cause: error,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// If it's not pending, it's unexpected
|
|
54
|
-
if (response.status !== pendingStatus) {
|
|
55
|
-
throw new ZapierApiError(`Unexpected response status during polling: ${response.status}`, {
|
|
56
|
-
statusCode: response.status,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
// It's still pending, so we continue polling
|
|
60
|
-
return {
|
|
61
|
-
status: "continue" /* PollStatus.Continue */,
|
|
62
|
-
errorCount: 0,
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Polls an endpoint until completion, timeout, or error
|
|
67
|
-
* @param options Configuration options for polling
|
|
68
|
-
* @returns The extracted result from the successful response
|
|
69
|
-
* @throws {ZapierValidationError} When the input parameters are invalid
|
|
70
|
-
* @throws {ZapierTimeoutError} When the operation times out
|
|
71
|
-
* @throws {ZapierApiError} When the API returns consecutive errors
|
|
72
|
-
*/
|
|
73
|
-
export async function pollUntilComplete(options) {
|
|
74
|
-
const { fetchPoll, timeoutMs = DEFAULT_TIMEOUT_MS, initialDelay = DEFAULT_INITIAL_DELAY_MS, successStatus = DEFAULT_SUCCESS_STATUS, pendingStatus = DEFAULT_PENDING_STATUS, resultExtractor = (response) => response, } = options;
|
|
75
|
-
// Validate input parameters
|
|
76
|
-
if (timeoutMs <= 0) {
|
|
77
|
-
throw new ZapierValidationError("Timeout must be greater than 0", {
|
|
78
|
-
details: { timeoutMs },
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (initialDelay < 0) {
|
|
82
|
-
throw new ZapierValidationError("Initial delay must be non-negative", {
|
|
83
|
-
details: { initialDelay },
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
const startTime = Date.now();
|
|
87
|
-
let attempts = 0;
|
|
88
|
-
let errorCount = 0;
|
|
89
|
-
// Build polling stages with the actual timeout appended
|
|
90
|
-
const pollingStages = [
|
|
91
|
-
...DEFAULT_POLLING_STAGES,
|
|
92
|
-
[timeoutMs + MAX_TIMEOUT_BUFFER_MS, DEFAULT_MAX_POLLING_INTERVAL_MS], // Up to timeout + 10s: poll every 10s
|
|
93
|
-
];
|
|
94
|
-
// Apply initial delay if specified
|
|
95
|
-
if (initialDelay > 0) {
|
|
96
|
-
await setTimeout(initialDelay);
|
|
97
|
-
}
|
|
98
|
-
while (true) {
|
|
99
|
-
attempts++;
|
|
100
|
-
const elapsedTime = Date.now() - startTime;
|
|
101
|
-
// Find the current polling stage
|
|
102
|
-
const pollingInterval = pollingStages.find(([maxTimeForStage, _interval]) => {
|
|
103
|
-
return elapsedTime < maxTimeForStage;
|
|
104
|
-
});
|
|
105
|
-
// If there isn't a current stage, throw timeout error
|
|
106
|
-
if (!pollingInterval) {
|
|
107
|
-
throw new ZapierTimeoutError(`Operation timed out after ${Math.floor(elapsedTime / 1000)}s (${attempts} attempts)`, {
|
|
108
|
-
attempts,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
// Wait before polling (except on first attempt)
|
|
112
|
-
if (attempts > 1) {
|
|
113
|
-
const waitTime = calculateWaitTime(pollingInterval[1], errorCount);
|
|
114
|
-
await setTimeout(waitTime);
|
|
115
|
-
}
|
|
116
|
-
// Perform the poll request
|
|
117
|
-
try {
|
|
118
|
-
const response = await fetchPoll();
|
|
119
|
-
const { result, errorCount: newErrorCount, status, } = await processResponse(response, successStatus, pendingStatus, resultExtractor, errorCount);
|
|
120
|
-
errorCount = newErrorCount;
|
|
121
|
-
if (status === "success" /* PollStatus.Success */) {
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
if (errorCount >= MAX_CONSECUTIVE_ERRORS) {
|
|
125
|
-
// Too many consecutive errors, fail
|
|
126
|
-
throw new ZapierApiError(`Poll request failed: ${response.status} ${response.statusText}`, { statusCode: response.status });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
errorCount++;
|
|
131
|
-
if (errorCount >= MAX_CONSECUTIVE_ERRORS) {
|
|
132
|
-
throw new ZapierApiError(`Failed to poll after ${errorCount} consecutive errors: ${error instanceof Error ? error.message : String(error)}`, {
|
|
133
|
-
cause: error,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// Continue polling if status is pending
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"polling.test.d.ts","sourceRoot":"","sources":["../../src/api/polling.test.ts"],"names":[],"mappings":""}
|