@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/auth.test.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { isJwt, getAuthorizationHeader, extractUserIdsFromJwt } from "./auth";
|
|
3
|
-
describe("api/auth", () => {
|
|
4
|
-
describe("isJwt", () => {
|
|
5
|
-
it("should return true for valid JWT tokens", () => {
|
|
6
|
-
const validJwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
|
|
7
|
-
expect(isJwt(validJwt)).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
it("should return true for JWT with minimal valid parts", () => {
|
|
10
|
-
const minimalJwt = "a.b.c";
|
|
11
|
-
expect(isJwt(minimalJwt)).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
it("should return false for tokens with fewer than 3 parts", () => {
|
|
14
|
-
expect(isJwt("header.payload")).toBe(false);
|
|
15
|
-
expect(isJwt("onlyonepart")).toBe(false);
|
|
16
|
-
expect(isJwt("")).toBe(false);
|
|
17
|
-
});
|
|
18
|
-
it("should return false for tokens with more than 3 parts", () => {
|
|
19
|
-
expect(isJwt("part1.part2.part3.part4")).toBe(false);
|
|
20
|
-
});
|
|
21
|
-
it("should return false for tokens with empty parts", () => {
|
|
22
|
-
expect(isJwt("..")).toBe(false);
|
|
23
|
-
expect(isJwt(".payload.signature")).toBe(false);
|
|
24
|
-
expect(isJwt("header..signature")).toBe(false);
|
|
25
|
-
expect(isJwt("header.payload.")).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
it("should return false for tokens with invalid base64url characters", () => {
|
|
28
|
-
expect(isJwt("header+plus.payload.signature")).toBe(false);
|
|
29
|
-
expect(isJwt("header.payload/slash.signature")).toBe(false);
|
|
30
|
-
expect(isJwt("header.payload=padding.signature")).toBe(false);
|
|
31
|
-
expect(isJwt("header.payload with space.signature")).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
it("should accept valid base64url characters including dashes and underscores", () => {
|
|
34
|
-
const validBase64Url = "abc-123_XYZ.def-456_UVW.ghi-789_RST";
|
|
35
|
-
expect(isJwt(validBase64Url)).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe("getAuthorizationHeader", () => {
|
|
39
|
-
it("should return JWT prefix for valid JWT tokens", () => {
|
|
40
|
-
const jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U";
|
|
41
|
-
expect(getAuthorizationHeader(jwt)).toBe(`JWT ${jwt}`);
|
|
42
|
-
});
|
|
43
|
-
it("should return Bearer prefix for non-JWT tokens", () => {
|
|
44
|
-
const apiKey = "sk_test_1234567890abcdef";
|
|
45
|
-
expect(getAuthorizationHeader(apiKey)).toBe(`Bearer ${apiKey}`);
|
|
46
|
-
});
|
|
47
|
-
it("should return Bearer prefix for tokens with wrong number of parts", () => {
|
|
48
|
-
expect(getAuthorizationHeader("header.payload")).toBe("Bearer header.payload");
|
|
49
|
-
});
|
|
50
|
-
it("should return Bearer prefix for empty string", () => {
|
|
51
|
-
expect(getAuthorizationHeader("")).toBe("Bearer ");
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe("extractUserIdsFromJwt", () => {
|
|
55
|
-
function createJwt(payload) {
|
|
56
|
-
const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" })).toString("base64url");
|
|
57
|
-
const payloadEncoded = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
58
|
-
const signature = "fake_signature_for_testing";
|
|
59
|
-
return `${header}.${payloadEncoded}.${signature}`;
|
|
60
|
-
}
|
|
61
|
-
it("should return null values for invalid JWT tokens", () => {
|
|
62
|
-
expect(extractUserIdsFromJwt("not-a-jwt")).toEqual({
|
|
63
|
-
customuser_id: null,
|
|
64
|
-
account_id: null,
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
it("should return null values for JWT with invalid payload", () => {
|
|
68
|
-
const invalidJwt = "header.not-valid-base64!.signature";
|
|
69
|
-
expect(extractUserIdsFromJwt(invalidJwt)).toEqual({
|
|
70
|
-
customuser_id: null,
|
|
71
|
-
account_id: null,
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
it("should extract customuser_id and account_id from regular JWT", () => {
|
|
75
|
-
const payload = {
|
|
76
|
-
sub: "12345",
|
|
77
|
-
sub_type: "customuser",
|
|
78
|
-
"zap:acc": "67890",
|
|
79
|
-
};
|
|
80
|
-
const jwt = createJwt(payload);
|
|
81
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
82
|
-
customuser_id: 12345,
|
|
83
|
-
account_id: 67890,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
it("should handle numeric sub and zap:acc values", () => {
|
|
87
|
-
const payload = {
|
|
88
|
-
sub: 99999,
|
|
89
|
-
sub_type: "customuser",
|
|
90
|
-
"zap:acc": 11111,
|
|
91
|
-
};
|
|
92
|
-
const jwt = createJwt(payload);
|
|
93
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
94
|
-
customuser_id: 99999,
|
|
95
|
-
account_id: 11111,
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
it("should return null customuser_id when sub_type is not customuser", () => {
|
|
99
|
-
const payload = {
|
|
100
|
-
sub: "12345",
|
|
101
|
-
sub_type: "other",
|
|
102
|
-
"zap:acc": "67890",
|
|
103
|
-
};
|
|
104
|
-
const jwt = createJwt(payload);
|
|
105
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
106
|
-
customuser_id: null,
|
|
107
|
-
account_id: 67890,
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
it("should return null customuser_id when sub is missing", () => {
|
|
111
|
-
const payload = {
|
|
112
|
-
sub_type: "customuser",
|
|
113
|
-
"zap:acc": "67890",
|
|
114
|
-
};
|
|
115
|
-
const jwt = createJwt(payload);
|
|
116
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
117
|
-
customuser_id: null,
|
|
118
|
-
account_id: 67890,
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
it("should return null account_id when zap:acc is missing", () => {
|
|
122
|
-
const payload = {
|
|
123
|
-
sub: "12345",
|
|
124
|
-
sub_type: "customuser",
|
|
125
|
-
};
|
|
126
|
-
const jwt = createJwt(payload);
|
|
127
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
128
|
-
customuser_id: 12345,
|
|
129
|
-
account_id: null,
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
it("should return null values when both fields are missing", () => {
|
|
133
|
-
const payload = {
|
|
134
|
-
other_field: "value",
|
|
135
|
-
};
|
|
136
|
-
const jwt = createJwt(payload);
|
|
137
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
138
|
-
customuser_id: null,
|
|
139
|
-
account_id: null,
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
it("should handle nested JWT for service tokens", () => {
|
|
143
|
-
const nestedPayload = {
|
|
144
|
-
sub: "12345",
|
|
145
|
-
sub_type: "customuser",
|
|
146
|
-
"zap:acc": "67890",
|
|
147
|
-
};
|
|
148
|
-
const nestedJwt = createJwt(nestedPayload);
|
|
149
|
-
const servicePayload = {
|
|
150
|
-
sub_type: "service",
|
|
151
|
-
njwt: nestedJwt,
|
|
152
|
-
};
|
|
153
|
-
const serviceJwt = createJwt(servicePayload);
|
|
154
|
-
expect(extractUserIdsFromJwt(serviceJwt)).toEqual({
|
|
155
|
-
customuser_id: 12345,
|
|
156
|
-
account_id: 67890,
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
it("should fall back to outer payload when nested JWT is invalid", () => {
|
|
160
|
-
const servicePayload = {
|
|
161
|
-
sub_type: "service",
|
|
162
|
-
njwt: "invalid.jwt",
|
|
163
|
-
"zap:acc": "99999",
|
|
164
|
-
};
|
|
165
|
-
const serviceJwt = createJwt(servicePayload);
|
|
166
|
-
expect(extractUserIdsFromJwt(serviceJwt)).toEqual({
|
|
167
|
-
customuser_id: null,
|
|
168
|
-
account_id: 99999,
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
it("should use outer payload when sub_type is service but njwt is missing", () => {
|
|
172
|
-
const servicePayload = {
|
|
173
|
-
sub: "12345",
|
|
174
|
-
sub_type: "service",
|
|
175
|
-
"zap:acc": "67890",
|
|
176
|
-
};
|
|
177
|
-
const serviceJwt = createJwt(servicePayload);
|
|
178
|
-
expect(extractUserIdsFromJwt(serviceJwt)).toEqual({
|
|
179
|
-
customuser_id: null,
|
|
180
|
-
account_id: 67890,
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
it("should return null for non-numeric sub values", () => {
|
|
184
|
-
const payload = {
|
|
185
|
-
sub: "not-a-number",
|
|
186
|
-
sub_type: "customuser",
|
|
187
|
-
"zap:acc": "67890",
|
|
188
|
-
};
|
|
189
|
-
const jwt = createJwt(payload);
|
|
190
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
191
|
-
customuser_id: null,
|
|
192
|
-
account_id: 67890,
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
it("should return null for non-numeric zap:acc values", () => {
|
|
196
|
-
const payload = {
|
|
197
|
-
sub: "12345",
|
|
198
|
-
sub_type: "customuser",
|
|
199
|
-
"zap:acc": "not-a-number",
|
|
200
|
-
};
|
|
201
|
-
const jwt = createJwt(payload);
|
|
202
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
203
|
-
customuser_id: 12345,
|
|
204
|
-
account_id: null,
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
it("should return null for values that parse to NaN", () => {
|
|
208
|
-
const payload = {
|
|
209
|
-
sub: "abc",
|
|
210
|
-
sub_type: "customuser",
|
|
211
|
-
"zap:acc": "xyz",
|
|
212
|
-
};
|
|
213
|
-
const jwt = createJwt(payload);
|
|
214
|
-
expect(extractUserIdsFromJwt(jwt)).toEqual({
|
|
215
|
-
customuser_id: null,
|
|
216
|
-
account_id: null,
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
package/dist/api/client.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Client Implementation
|
|
3
|
-
*
|
|
4
|
-
* This module contains the core API client implementation, including
|
|
5
|
-
* HTTP method handlers, response processing, and client factory functions.
|
|
6
|
-
*/
|
|
7
|
-
import type { ApiClient, ApiClientOptions } from "./types";
|
|
8
|
-
export declare const createZapierApi: (options: ApiClientOptions) => ApiClient;
|
|
9
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/api/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AA4ejB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
|
package/dist/api/client.js
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Client Implementation
|
|
3
|
-
*
|
|
4
|
-
* This module contains the core API client implementation, including
|
|
5
|
-
* HTTP method handlers, response processing, and client factory functions.
|
|
6
|
-
*/
|
|
7
|
-
import { getAuthorizationHeader } from "./auth";
|
|
8
|
-
import { createDebugLogger, createDebugFetch } from "./debug";
|
|
9
|
-
import { pollUntilComplete } from "./polling";
|
|
10
|
-
import { resolveAuthToken } from "../auth";
|
|
11
|
-
import { getZapierBaseUrl } from "../utils/url-utils";
|
|
12
|
-
import { ZapierApiError, ZapierAuthenticationError, ZapierValidationError, ZapierNotFoundError, } from "../types/errors";
|
|
13
|
-
// Configuration for paths
|
|
14
|
-
const pathConfig = {
|
|
15
|
-
// e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
|
|
16
|
-
"/relay": {
|
|
17
|
-
authHeader: "X-Relay-Authorization",
|
|
18
|
-
pathPrefix: "/api/v0/sdk/relay",
|
|
19
|
-
},
|
|
20
|
-
// e.g. /zapier -> https://sdkapi.zapier.com/api/v0/sdk/zapier/...
|
|
21
|
-
"/zapier": {
|
|
22
|
-
authHeader: "Authorization",
|
|
23
|
-
pathPrefix: "/api/v0/sdk/zapier",
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
class ZapierApiClient {
|
|
27
|
-
constructor(options) {
|
|
28
|
-
this.options = options;
|
|
29
|
-
this.fetch = async (path, init) => {
|
|
30
|
-
return this.plainFetch(path, init);
|
|
31
|
-
};
|
|
32
|
-
this.get = async (path, options = {}) => {
|
|
33
|
-
return this.fetchJson("GET", path, undefined, options);
|
|
34
|
-
};
|
|
35
|
-
this.post = async (path, data, options = {}) => {
|
|
36
|
-
return this.fetchJson("POST", path, data, options);
|
|
37
|
-
};
|
|
38
|
-
this.put = async (path, data, options = {}) => {
|
|
39
|
-
return this.fetchJson("PUT", path, data, options);
|
|
40
|
-
};
|
|
41
|
-
this.delete = async (path, options = {}) => {
|
|
42
|
-
return this.fetchJson("DELETE", path, undefined, options);
|
|
43
|
-
};
|
|
44
|
-
this.poll = async (path, options = {}) => {
|
|
45
|
-
return pollUntilComplete({
|
|
46
|
-
fetchPoll: () => this.plainFetch(path, {
|
|
47
|
-
method: "GET",
|
|
48
|
-
searchParams: options.searchParams,
|
|
49
|
-
authRequired: options.authRequired,
|
|
50
|
-
}),
|
|
51
|
-
initialDelay: options.initialDelay,
|
|
52
|
-
timeoutMs: options.timeoutMs,
|
|
53
|
-
successStatus: options.successStatus,
|
|
54
|
-
pendingStatus: options.pendingStatus,
|
|
55
|
-
resultExtractor: options.resultExtractor,
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
// Helper to parse response data
|
|
60
|
-
async parseResult(response) {
|
|
61
|
-
try {
|
|
62
|
-
return { type: "json", data: await response.json() };
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return { type: "text", data: await response.text() };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// Helper to get a token from the different places it could be gotten
|
|
69
|
-
async getAuthToken() {
|
|
70
|
-
return resolveAuthToken({
|
|
71
|
-
token: this.options.token,
|
|
72
|
-
getToken: this.options.getToken,
|
|
73
|
-
onEvent: this.options.onEvent,
|
|
74
|
-
fetch: this.options.fetch,
|
|
75
|
-
baseUrl: this.options.baseUrl,
|
|
76
|
-
authBaseUrl: this.options.authBaseUrl,
|
|
77
|
-
authClientId: this.options.authClientId,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
// Helper to handle responses
|
|
81
|
-
async handleResponse(params) {
|
|
82
|
-
const { response, customErrorHandler, wasMissingAuthToken } = params;
|
|
83
|
-
const { data: responseData } = await this.parseResult(response);
|
|
84
|
-
if (response.ok) {
|
|
85
|
-
return responseData;
|
|
86
|
-
}
|
|
87
|
-
const errorInfo = {
|
|
88
|
-
status: response.status,
|
|
89
|
-
statusText: response.statusText,
|
|
90
|
-
data: responseData,
|
|
91
|
-
};
|
|
92
|
-
// Check for custom error handling first
|
|
93
|
-
if (customErrorHandler) {
|
|
94
|
-
const customError = customErrorHandler(errorInfo);
|
|
95
|
-
if (customError) {
|
|
96
|
-
// javascript may not respect customErrorHandler return type, so we need to throw a proper error if it's not an Error
|
|
97
|
-
if (customError instanceof Error) {
|
|
98
|
-
throw customError;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw new Error(`customErrorHandler returned a non-Error: ${JSON.stringify(customError)}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// Parse the error response
|
|
106
|
-
const { message, errors } = this.parseErrorResponse(errorInfo);
|
|
107
|
-
const errorOptions = {
|
|
108
|
-
statusCode: response.status,
|
|
109
|
-
errors,
|
|
110
|
-
};
|
|
111
|
-
// Use appropriate error type based on status code
|
|
112
|
-
if (response.status === 404) {
|
|
113
|
-
throw new ZapierNotFoundError(message, errorOptions);
|
|
114
|
-
}
|
|
115
|
-
if (response.status === 401 || response.status === 403) {
|
|
116
|
-
// If we get a 401/403 error and no auth token was provided, give helpful message
|
|
117
|
-
if (wasMissingAuthToken) {
|
|
118
|
-
throw new ZapierAuthenticationError(`Authentication required (HTTP ${response.status}). Please provide a token in options or set ZAPIER_TOKEN environment variable.`, errorOptions);
|
|
119
|
-
}
|
|
120
|
-
throw new ZapierAuthenticationError(message, errorOptions);
|
|
121
|
-
}
|
|
122
|
-
if (response.status === 400) {
|
|
123
|
-
throw new ZapierValidationError(message, errorOptions);
|
|
124
|
-
}
|
|
125
|
-
// Generic API error for other status codes
|
|
126
|
-
throw new ZapierApiError(message, errorOptions);
|
|
127
|
-
}
|
|
128
|
-
hasErrorArray(data) {
|
|
129
|
-
return (typeof data === "object" &&
|
|
130
|
-
data !== null &&
|
|
131
|
-
"errors" in data &&
|
|
132
|
-
Array.isArray(data.errors));
|
|
133
|
-
}
|
|
134
|
-
// Helper to check if data has API errors
|
|
135
|
-
isApiErrorArray(dataArray) {
|
|
136
|
-
const data = dataArray[0];
|
|
137
|
-
return (typeof data === "object" &&
|
|
138
|
-
data !== null &&
|
|
139
|
-
"message" in data &&
|
|
140
|
-
"code" in data &&
|
|
141
|
-
"title" in data &&
|
|
142
|
-
"detail" in data);
|
|
143
|
-
}
|
|
144
|
-
// Do our best to extract an error message from the response data
|
|
145
|
-
extractErrorMessage(data) {
|
|
146
|
-
if (typeof data === "string") {
|
|
147
|
-
return data;
|
|
148
|
-
}
|
|
149
|
-
if (typeof data === "object" && data !== null) {
|
|
150
|
-
if ("message" in data && typeof data.message === "string") {
|
|
151
|
-
return data.message;
|
|
152
|
-
}
|
|
153
|
-
if ("error" in data) {
|
|
154
|
-
if (typeof data.error === "string") {
|
|
155
|
-
return data.error;
|
|
156
|
-
}
|
|
157
|
-
if (typeof data.error === "object" && data.error !== null) {
|
|
158
|
-
if ("message" in data.error &&
|
|
159
|
-
typeof data.error.message === "string") {
|
|
160
|
-
return data.error.message;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
return JSON.stringify(data.error);
|
|
165
|
-
}
|
|
166
|
-
catch {
|
|
167
|
-
/* defend against circular objects, even though they shouldn't be coming back from the wire */
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if ("errors" in data && Array.isArray(data.errors)) {
|
|
171
|
-
if (this.isApiErrorArray(data.errors)) {
|
|
172
|
-
return data.errors[0].detail || data.errors[0].title;
|
|
173
|
-
}
|
|
174
|
-
else if (data.errors.length > 0) {
|
|
175
|
-
// Handle simple string errors array
|
|
176
|
-
const firstError = data.errors[0];
|
|
177
|
-
if (typeof firstError === "string") {
|
|
178
|
-
return firstError;
|
|
179
|
-
}
|
|
180
|
-
// For non-string errors, stringify them
|
|
181
|
-
try {
|
|
182
|
-
return JSON.stringify(firstError);
|
|
183
|
-
}
|
|
184
|
-
catch {
|
|
185
|
-
return String(firstError);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
// Helper to parse API error response
|
|
193
|
-
parseErrorResponse(errorInfo) {
|
|
194
|
-
// If we can't parse data, use status text
|
|
195
|
-
const fallbackMessage = `HTTP ${errorInfo.status}: ${errorInfo.statusText}`;
|
|
196
|
-
try {
|
|
197
|
-
// Check if the response has the standard error format
|
|
198
|
-
if (typeof errorInfo.data === "string") {
|
|
199
|
-
return { message: `${fallbackMessage}: ${errorInfo.data}` };
|
|
200
|
-
}
|
|
201
|
-
const errorMessage = this.extractErrorMessage(errorInfo.data) || fallbackMessage;
|
|
202
|
-
if (this.hasErrorArray(errorInfo.data)) {
|
|
203
|
-
if (this.isApiErrorArray(errorInfo.data.errors)) {
|
|
204
|
-
return {
|
|
205
|
-
message: errorMessage,
|
|
206
|
-
errors: errorInfo.data.errors,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
return {
|
|
211
|
-
message: errorMessage,
|
|
212
|
-
errors: errorInfo.data.errors.map((e) => ({
|
|
213
|
-
status: errorInfo.status,
|
|
214
|
-
code: String(errorInfo.status),
|
|
215
|
-
title: errorInfo.statusText,
|
|
216
|
-
detail: JSON.stringify(e),
|
|
217
|
-
})),
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return { message: errorMessage };
|
|
222
|
-
}
|
|
223
|
-
catch {
|
|
224
|
-
return { message: fallbackMessage };
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
// Apply any special routing logic for configured paths.
|
|
228
|
-
applyPathConfiguration(path) {
|
|
229
|
-
// Find matching path configuration.
|
|
230
|
-
const matchingPathKey = Object.keys(pathConfig).find((configPath) => path === configPath || path.startsWith(configPath + "/"));
|
|
231
|
-
const config = matchingPathKey ? pathConfig[matchingPathKey] : undefined;
|
|
232
|
-
// Check if baseUrl is a Zapier-inferred base URL.
|
|
233
|
-
const zapierBaseUrl = getZapierBaseUrl(this.options.baseUrl);
|
|
234
|
-
// Let's remain compatible with a base URL that is set to a Zapier-inferred
|
|
235
|
-
// domain, rather than requiring the base URL to go to our proxy. Later, the
|
|
236
|
-
// proxy will be removed, so this should make that transition easier.
|
|
237
|
-
if (zapierBaseUrl === this.options.baseUrl) {
|
|
238
|
-
// If baseUrl is already the Zapier base URL, use sdkapi subdomain.
|
|
239
|
-
const originalBaseUrl = new URL(this.options.baseUrl);
|
|
240
|
-
const finalBaseUrl = `https://sdkapi.${originalBaseUrl.hostname}`;
|
|
241
|
-
// Only prepend pathPrefix if there's a matching config with pathPrefix.
|
|
242
|
-
let finalPath = path;
|
|
243
|
-
if (config &&
|
|
244
|
-
"pathPrefix" in config &&
|
|
245
|
-
config.pathPrefix &&
|
|
246
|
-
matchingPathKey) {
|
|
247
|
-
// Strip the matching path key, and use the pathPrefix instead.
|
|
248
|
-
const pathWithoutPrefix = path.slice(matchingPathKey.length) || "/";
|
|
249
|
-
finalPath = `${config.pathPrefix}${pathWithoutPrefix}`;
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
url: new URL(finalPath, finalBaseUrl),
|
|
253
|
-
pathConfig: config,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
// For a base URL that isn't a Zapier-inferred domain, use the whole base URL.
|
|
257
|
-
const baseUrl = new URL(this.options.baseUrl);
|
|
258
|
-
const fullPath = baseUrl.pathname.replace(/\/$/, "") + path;
|
|
259
|
-
return {
|
|
260
|
-
url: new URL(fullPath, baseUrl.origin),
|
|
261
|
-
pathConfig: config,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
// Helper to build full URLs and return routing info
|
|
265
|
-
buildUrl(path, searchParams) {
|
|
266
|
-
const { url, pathConfig: config } = this.applyPathConfiguration(path);
|
|
267
|
-
if (searchParams) {
|
|
268
|
-
Object.entries(searchParams).forEach(([key, value]) => {
|
|
269
|
-
url.searchParams.set(key, value);
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
return { url: url.toString(), pathConfig: config };
|
|
273
|
-
}
|
|
274
|
-
// Helper to build headers
|
|
275
|
-
async buildHeaders(options = {}, pathConfig) {
|
|
276
|
-
const headers = new Headers(options.headers ?? {});
|
|
277
|
-
// Even if auth is not required, we still want to add it in case it adds
|
|
278
|
-
// useful context to the API. The session is a good example of this. Auth
|
|
279
|
-
// is not required, but if we don't add auth, then we won't get the user's
|
|
280
|
-
// session!
|
|
281
|
-
const authToken = await this.getAuthToken();
|
|
282
|
-
if (authToken) {
|
|
283
|
-
const authHeaderName = pathConfig && pathConfig.authHeader
|
|
284
|
-
? pathConfig.authHeader
|
|
285
|
-
: "Authorization";
|
|
286
|
-
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
287
|
-
}
|
|
288
|
-
// If we know auth is required, and we don't have a token, throw an error
|
|
289
|
-
// before we even make a request.
|
|
290
|
-
if (options.authRequired) {
|
|
291
|
-
if (headers.get("Authorization") == null && authToken == null) {
|
|
292
|
-
throw new ZapierAuthenticationError(`Authentication required but no token available. Please set ZAPIER_TOKEN, or run the 'login' command with the CLI.`);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return headers;
|
|
296
|
-
}
|
|
297
|
-
// Helper to perform HTTP requests with JSON handling
|
|
298
|
-
async fetchJson(method, path, data, options = {}) {
|
|
299
|
-
const headers = { ...options.headers };
|
|
300
|
-
// Add Content-Type for JSON requests with body data
|
|
301
|
-
if (data && typeof data === "object") {
|
|
302
|
-
headers["Content-Type"] = "application/json";
|
|
303
|
-
}
|
|
304
|
-
// Check if we have an auth token available
|
|
305
|
-
const wasMissingAuthToken = options.authRequired && (await this.getAuthToken()) == null;
|
|
306
|
-
const response = await this.plainFetch(path, {
|
|
307
|
-
...options,
|
|
308
|
-
method,
|
|
309
|
-
body: data != null ? JSON.stringify(data) : undefined,
|
|
310
|
-
headers,
|
|
311
|
-
});
|
|
312
|
-
// plainFetch already handled all auth and headers
|
|
313
|
-
const result = await this.handleResponse({
|
|
314
|
-
response,
|
|
315
|
-
customErrorHandler: options.customErrorHandler,
|
|
316
|
-
wasMissingAuthToken,
|
|
317
|
-
});
|
|
318
|
-
if (typeof result === "string") {
|
|
319
|
-
throw new ZapierValidationError(`Response could not be parsed as JSON: ${result}`);
|
|
320
|
-
}
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
// Plain fetch method for API paths (must start with /)
|
|
324
|
-
async plainFetch(path, fetchOptions) {
|
|
325
|
-
if (!path.startsWith("/")) {
|
|
326
|
-
throw new ZapierValidationError(`plainFetch expects a path starting with '/', got: ${path}`);
|
|
327
|
-
}
|
|
328
|
-
if (fetchOptions?.body && typeof fetchOptions.body === "object") {
|
|
329
|
-
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
|
330
|
-
}
|
|
331
|
-
const { url, pathConfig } = this.buildUrl(path, fetchOptions?.searchParams);
|
|
332
|
-
const builtHeaders = await this.buildHeaders(fetchOptions, pathConfig);
|
|
333
|
-
const inputHeaders = new Headers(fetchOptions?.headers ?? {});
|
|
334
|
-
const mergedHeaders = new Headers();
|
|
335
|
-
builtHeaders.forEach((value, key) => {
|
|
336
|
-
mergedHeaders.set(key, value);
|
|
337
|
-
});
|
|
338
|
-
inputHeaders.forEach((value, key) => {
|
|
339
|
-
mergedHeaders.set(key, value);
|
|
340
|
-
});
|
|
341
|
-
return await this.options.fetch(url, {
|
|
342
|
-
...fetchOptions,
|
|
343
|
-
headers: mergedHeaders,
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
export const createZapierApi = (options) => {
|
|
348
|
-
const { debug = false, fetch: originalFetch = globalThis.fetch } = options;
|
|
349
|
-
const debugLog = createDebugLogger(debug);
|
|
350
|
-
const debugFetch = createDebugFetch({ originalFetch, debugLog });
|
|
351
|
-
return new ZapierApiClient({
|
|
352
|
-
...options,
|
|
353
|
-
debug,
|
|
354
|
-
fetch: debugFetch,
|
|
355
|
-
});
|
|
356
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../src/api/client.test.ts"],"names":[],"mappings":""}
|