@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
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { resolve, writeFile, readFile } from "./file-utils";
|
|
3
|
-
// Mock the dynamic imports to simulate missing modules
|
|
4
|
-
vi.mock("fs/promises", () => {
|
|
5
|
-
throw new Error("Module not found");
|
|
6
|
-
});
|
|
7
|
-
vi.mock("path", () => {
|
|
8
|
-
throw new Error("Module not found");
|
|
9
|
-
});
|
|
10
|
-
describe("file-utils", () => {
|
|
11
|
-
describe("resolve", () => {
|
|
12
|
-
it("should handle absolute paths", async () => {
|
|
13
|
-
expect(await resolve("/absolute/path")).toBe("/absolute/path");
|
|
14
|
-
});
|
|
15
|
-
it("should handle relative paths with ./", async () => {
|
|
16
|
-
expect(await resolve("./relative/path")).toBe("/relative/path");
|
|
17
|
-
expect(await resolve("./relative/path", "/base")).toBe("/base/relative/path");
|
|
18
|
-
expect(await resolve("./relative/path", "/base/")).toBe("/base/relative/path");
|
|
19
|
-
});
|
|
20
|
-
it("should handle parent directory paths with ../", async () => {
|
|
21
|
-
expect(await resolve("../parent/path")).toBe("/parent/path");
|
|
22
|
-
expect(await resolve("../../nested/parent/path")).toBe("/nested/parent/path");
|
|
23
|
-
expect(await resolve("../parent/path", "/base")).toBe("/base/parent/path");
|
|
24
|
-
});
|
|
25
|
-
it("should handle paths without prefix", async () => {
|
|
26
|
-
expect(await resolve("simple/path")).toBe("/simple/path");
|
|
27
|
-
expect(await resolve("simple/path", "/base")).toBe("/base/simple/path");
|
|
28
|
-
expect(await resolve("simple/path", "/base/")).toBe("/base/simple/path");
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe("writeFile and readFile with in-memory filesystem", () => {
|
|
32
|
-
it("should write and read files using in-memory filesystem when fs is not available", async () => {
|
|
33
|
-
const filePath = "/test/file.txt";
|
|
34
|
-
const content = "Hello, world!";
|
|
35
|
-
await writeFile(filePath, content);
|
|
36
|
-
const readContent = await readFile(filePath);
|
|
37
|
-
expect(readContent).toBe(content);
|
|
38
|
-
});
|
|
39
|
-
it("should throw error when reading non-existent file", async () => {
|
|
40
|
-
await expect(readFile("/non/existent/file.txt")).rejects.toThrow("File not found: /non/existent/file.txt");
|
|
41
|
-
});
|
|
42
|
-
it("should handle multiple files in in-memory filesystem", async () => {
|
|
43
|
-
await writeFile("/file1.txt", "content1");
|
|
44
|
-
await writeFile("/file2.txt", "content2");
|
|
45
|
-
await writeFile("/dir/file3.txt", "content3");
|
|
46
|
-
expect(await readFile("/file1.txt")).toBe("content1");
|
|
47
|
-
expect(await readFile("/file2.txt")).toBe("content2");
|
|
48
|
-
expect(await readFile("/dir/file3.txt")).toBe("content3");
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic utility functions for creating paginated SDK functions
|
|
3
|
-
*/
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
/**
|
|
6
|
-
* Zod schema for telemetry marker to prevent nested telemetry emissions.
|
|
7
|
-
* Used to extend options schemas with proper typing.
|
|
8
|
-
*/
|
|
9
|
-
export declare const TelemetryMarkerSchema: z.ZodObject<{
|
|
10
|
-
_telemetry: z.ZodOptional<z.ZodObject<{
|
|
11
|
-
isNested: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
-
}, z.core.$strip>>;
|
|
13
|
-
}, z.core.$strip>;
|
|
14
|
-
/**
|
|
15
|
-
* Marker for SDK method calls to control telemetry behavior
|
|
16
|
-
*/
|
|
17
|
-
export type TelemetryMarker = z.infer<typeof TelemetryMarkerSchema>;
|
|
18
|
-
/**
|
|
19
|
-
* Callbacks for telemetry events during function execution
|
|
20
|
-
*/
|
|
21
|
-
export interface TelemetryCallbacks {
|
|
22
|
-
onMethodCalled?: (data: {
|
|
23
|
-
methodName: string;
|
|
24
|
-
durationMs: number;
|
|
25
|
-
success: boolean;
|
|
26
|
-
error?: Error;
|
|
27
|
-
argumentCount: number;
|
|
28
|
-
isPaginated: boolean;
|
|
29
|
-
}) => void;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Helper function to extract cursor from pagination data
|
|
33
|
-
* Supports JSON:API style `links.next` URLs by extracting the `offset` parameter.
|
|
34
|
-
*/
|
|
35
|
-
export declare function extractCursor(data: {
|
|
36
|
-
next?: string | null;
|
|
37
|
-
} | null | undefined): string | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Higher-order function that creates a function from a core function
|
|
40
|
-
*
|
|
41
|
-
* @param coreFn - Function that returns T directly or throws errors
|
|
42
|
-
* @param schema - Optional Zod schema for validation
|
|
43
|
-
* @param telemetry - Optional telemetry callbacks
|
|
44
|
-
* @returns A function that normalizes and rethrows errors
|
|
45
|
-
*/
|
|
46
|
-
export declare function createFunction<TOptions, TResult, TSchemaOptions extends TOptions = TOptions>(coreFn: (options: TOptions) => Promise<TResult>, schema?: z.ZodSchema<TSchemaOptions>, telemetry?: TelemetryCallbacks): (options?: TOptions) => Promise<TResult>;
|
|
47
|
-
/**
|
|
48
|
-
* Higher-order function that creates a paginated function that wraps results in {data}
|
|
49
|
-
*
|
|
50
|
-
* @param coreFn - Function that returns T directly or throws errors
|
|
51
|
-
* @returns A function that normalizes errors and wraps results in {data}
|
|
52
|
-
*/
|
|
53
|
-
type PaginatedResult<TResult> = TResult extends {
|
|
54
|
-
data: any;
|
|
55
|
-
nextCursor?: string;
|
|
56
|
-
} ? TResult : {
|
|
57
|
-
data: TResult;
|
|
58
|
-
nextCursor?: string;
|
|
59
|
-
};
|
|
60
|
-
type ItemType<TResult> = TResult extends {
|
|
61
|
-
data: infer TData;
|
|
62
|
-
} ? TData extends readonly (infer TItem)[] ? TItem : TData : TResult extends readonly (infer TItem)[] ? TItem : TResult;
|
|
63
|
-
export declare function createPaginatedFunction<TOptions, TResult, TSchemaOptions extends TOptions = TOptions>(coreFn: (options: TOptions & {
|
|
64
|
-
pageSize: number;
|
|
65
|
-
}) => Promise<TResult>, schema?: z.ZodSchema<TSchemaOptions>, telemetry?: TelemetryCallbacks, explicitFunctionName?: string): (options?: TOptions & {
|
|
66
|
-
cursor?: string;
|
|
67
|
-
pageSize?: number;
|
|
68
|
-
maxItems?: number;
|
|
69
|
-
}) => Promise<PaginatedResult<TResult>> & AsyncIterable<PaginatedResult<TResult>> & {
|
|
70
|
-
items(): AsyncIterable<ItemType<TResult>>;
|
|
71
|
-
};
|
|
72
|
-
export {};
|
|
73
|
-
//# sourceMappingURL=function-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"function-utils.d.ts","sourceRoot":"","sources":["../../src/utils/function-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;iBAMhC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,OAAO,CAAC;KACtB,KAAK,IAAI,CAAC;CACZ;AAUD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAChD,MAAM,GAAG,SAAS,CAYpB;AAcD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EACR,OAAO,EACP,cAAc,SAAS,QAAQ,GAAG,QAAQ,EAE1C,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,EAC/C,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,EACpC,SAAS,CAAC,EAAE,kBAAkB,cAMc,QAAQ,KAAG,OAAO,CAAC,OAAO,CAAC,CAsExE;AA6DD;;;;;GAKG;AACH,KAAK,eAAe,CAAC,OAAO,IAAI,OAAO,SAAS;IAC9C,IAAI,EAAE,GAAG,CAAC;IACV,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACG,OAAO,GACP;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C,KAAK,QAAQ,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,IAAI,EAAE,MAAM,KAAK,CAAA;CAAE,GAC1D,KAAK,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GACpC,KAAK,GACL,KAAK,GACP,OAAO,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,GACtC,KAAK,GACL,OAAO,CAAC;AAEd,wBAAgB,uBAAuB,CACrC,QAAQ,EACR,OAAO,EACP,cAAc,SAAS,QAAQ,GAAG,QAAQ,EAE1C,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,OAAO,CAAC,EACtE,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,EACpC,SAAS,CAAC,EAAE,kBAAkB,EAC9B,oBAAoB,CAAC,EAAE,MAAM,GAC5B,CACD,OAAO,CAAC,EAAE,QAAQ,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,KACE,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,GACpC,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,GAAG;IACxC,KAAK,IAAI,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3C,CAgHF"}
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic utility functions for creating paginated SDK functions
|
|
3
|
-
*/
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import { ZapierError, ZapierUnknownError } from "../types/errors";
|
|
6
|
-
import { paginate } from "./pagination-utils";
|
|
7
|
-
import { createValidator, validateOptions } from "./validation";
|
|
8
|
-
/**
|
|
9
|
-
* Zod schema for telemetry marker to prevent nested telemetry emissions.
|
|
10
|
-
* Used to extend options schemas with proper typing.
|
|
11
|
-
*/
|
|
12
|
-
export const TelemetryMarkerSchema = z.object({
|
|
13
|
-
_telemetry: z
|
|
14
|
-
.object({
|
|
15
|
-
isNested: z.boolean().optional(),
|
|
16
|
-
})
|
|
17
|
-
.optional(),
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* Helper function to extract cursor from pagination data
|
|
21
|
-
* Supports JSON:API style `links.next` URLs by extracting the `offset` parameter.
|
|
22
|
-
*/
|
|
23
|
-
export function extractCursor(data) {
|
|
24
|
-
if (!data?.next) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
const urlObj = new URL(data.next);
|
|
29
|
-
const offset = urlObj.searchParams.get("offset");
|
|
30
|
-
return offset || undefined;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Helper function to convert unknown errors to SDK errors
|
|
38
|
-
*/
|
|
39
|
-
function normalizeError(error) {
|
|
40
|
-
if (error instanceof ZapierError) {
|
|
41
|
-
return error;
|
|
42
|
-
}
|
|
43
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
44
|
-
return new ZapierUnknownError(`Unknown error: ${message}`, { cause: error });
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Higher-order function that creates a function from a core function
|
|
48
|
-
*
|
|
49
|
-
* @param coreFn - Function that returns T directly or throws errors
|
|
50
|
-
* @param schema - Optional Zod schema for validation
|
|
51
|
-
* @param telemetry - Optional telemetry callbacks
|
|
52
|
-
* @returns A function that normalizes and rethrows errors
|
|
53
|
-
*/
|
|
54
|
-
export function createFunction(coreFn, schema, telemetry) {
|
|
55
|
-
const functionName = coreFn.name;
|
|
56
|
-
// Create a named function using dynamic property access
|
|
57
|
-
const namedFunctions = {
|
|
58
|
-
[functionName]: async function (options) {
|
|
59
|
-
const startTime = Date.now();
|
|
60
|
-
const normalizedOptions = (options ?? {});
|
|
61
|
-
const isNested = normalizedOptions?._telemetry?.isNested === true;
|
|
62
|
-
try {
|
|
63
|
-
if (schema) {
|
|
64
|
-
const validatedOptions = validateOptions(schema, normalizedOptions);
|
|
65
|
-
const result = await coreFn({
|
|
66
|
-
...normalizedOptions,
|
|
67
|
-
...validatedOptions,
|
|
68
|
-
});
|
|
69
|
-
// Emit telemetry only for top-level calls
|
|
70
|
-
if (!isNested && telemetry?.onMethodCalled) {
|
|
71
|
-
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
72
|
-
telemetry.onMethodCalled({
|
|
73
|
-
methodName: functionName,
|
|
74
|
-
durationMs: Date.now() - startTime,
|
|
75
|
-
success: true,
|
|
76
|
-
argumentCount,
|
|
77
|
-
isPaginated: false,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
const result = await coreFn(normalizedOptions);
|
|
83
|
-
if (!isNested && telemetry?.onMethodCalled) {
|
|
84
|
-
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
85
|
-
telemetry.onMethodCalled({
|
|
86
|
-
methodName: functionName,
|
|
87
|
-
durationMs: Date.now() - startTime,
|
|
88
|
-
success: true,
|
|
89
|
-
argumentCount,
|
|
90
|
-
isPaginated: false,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
const normalizedError = normalizeError(error);
|
|
97
|
-
if (!isNested && telemetry?.onMethodCalled) {
|
|
98
|
-
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
99
|
-
telemetry.onMethodCalled({
|
|
100
|
-
methodName: functionName,
|
|
101
|
-
durationMs: Date.now() - startTime,
|
|
102
|
-
success: false,
|
|
103
|
-
error: normalizedError,
|
|
104
|
-
argumentCount,
|
|
105
|
-
isPaginated: false,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
throw normalizedError;
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
return namedFunctions[functionName];
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Higher-order function that creates a page function that wraps results in {data}
|
|
116
|
-
* Internal utility used by createPaginatedFunction
|
|
117
|
-
*/
|
|
118
|
-
function createPageFunction(coreFn) {
|
|
119
|
-
const functionName = coreFn.name + "Page";
|
|
120
|
-
// Create a named function using dynamic property access
|
|
121
|
-
const namedFunctions = {
|
|
122
|
-
[functionName]: async function (options) {
|
|
123
|
-
try {
|
|
124
|
-
const result = await coreFn(options);
|
|
125
|
-
// If result already has a data property, ensure it's an array
|
|
126
|
-
if (result && typeof result === "object" && "data" in result) {
|
|
127
|
-
const paginatedResult = result;
|
|
128
|
-
// Support both nextCursor and JSON:API links.next format
|
|
129
|
-
let nextCursor;
|
|
130
|
-
if (paginatedResult.nextCursor) {
|
|
131
|
-
nextCursor = paginatedResult.nextCursor;
|
|
132
|
-
}
|
|
133
|
-
else if (paginatedResult.links?.next) {
|
|
134
|
-
// Extract cursor from fully qualified URL (JSON:API spec format)
|
|
135
|
-
nextCursor = extractCursor({ next: paginatedResult.links.next });
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
data: Array.isArray(paginatedResult.data)
|
|
139
|
-
? paginatedResult.data
|
|
140
|
-
: [paginatedResult.data],
|
|
141
|
-
nextCursor,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
// If result is an array, wrap in {data: result}
|
|
145
|
-
if (Array.isArray(result)) {
|
|
146
|
-
return { data: result };
|
|
147
|
-
}
|
|
148
|
-
// If result is non-array, wrap in {data: [result]}
|
|
149
|
-
return { data: [result] };
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
// Catch and normalize any errors, then rethrow
|
|
153
|
-
throw normalizeError(error);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
return namedFunctions[functionName];
|
|
158
|
-
}
|
|
159
|
-
export function createPaginatedFunction(coreFn, schema, telemetry, explicitFunctionName) {
|
|
160
|
-
const pageFunction = createPageFunction(coreFn);
|
|
161
|
-
const functionName = explicitFunctionName || coreFn.name;
|
|
162
|
-
const validator = schema ? createValidator(schema) : null;
|
|
163
|
-
// Create the main paginated function
|
|
164
|
-
const namedFunctions = {
|
|
165
|
-
[functionName]: function (options) {
|
|
166
|
-
const startTime = Date.now();
|
|
167
|
-
// Convert undefined options to empty object
|
|
168
|
-
const normalizedOptions = (options ?? {});
|
|
169
|
-
const isNested = normalizedOptions?._telemetry?.isNested === true;
|
|
170
|
-
// Validate options if schema provided (validated fields take precedence)
|
|
171
|
-
const validatedOptions = {
|
|
172
|
-
...normalizedOptions,
|
|
173
|
-
...(validator ? validator(normalizedOptions) : normalizedOptions),
|
|
174
|
-
};
|
|
175
|
-
// Set default pageSize if not provided
|
|
176
|
-
const pageSize = validatedOptions.pageSize || 100;
|
|
177
|
-
const optimizedOptions = {
|
|
178
|
-
...validatedOptions,
|
|
179
|
-
pageSize,
|
|
180
|
-
};
|
|
181
|
-
const iterator = paginate(pageFunction, optimizedOptions);
|
|
182
|
-
// Get a promise for the first iteration
|
|
183
|
-
const firstPagePromise = iterator.next().then((result) => {
|
|
184
|
-
if (result.done) {
|
|
185
|
-
throw new Error("Paginate should always iterate at least once");
|
|
186
|
-
}
|
|
187
|
-
return result.value;
|
|
188
|
-
});
|
|
189
|
-
// Emit telemetry after first page completes
|
|
190
|
-
if (!isNested && telemetry?.onMethodCalled) {
|
|
191
|
-
firstPagePromise
|
|
192
|
-
.then(() => {
|
|
193
|
-
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
194
|
-
telemetry.onMethodCalled({
|
|
195
|
-
methodName: functionName,
|
|
196
|
-
durationMs: Date.now() - startTime,
|
|
197
|
-
success: true,
|
|
198
|
-
argumentCount,
|
|
199
|
-
isPaginated: true,
|
|
200
|
-
});
|
|
201
|
-
})
|
|
202
|
-
.catch((error) => {
|
|
203
|
-
const argumentCount = Object.keys(normalizedOptions).filter((k) => k !== "_telemetry").length;
|
|
204
|
-
telemetry.onMethodCalled({
|
|
205
|
-
methodName: functionName,
|
|
206
|
-
durationMs: Date.now() - startTime,
|
|
207
|
-
success: false,
|
|
208
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
209
|
-
argumentCount,
|
|
210
|
-
isPaginated: true,
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
// Add Symbol.asyncIterator to make the promise iterable
|
|
215
|
-
return Object.assign(firstPagePromise, {
|
|
216
|
-
[Symbol.asyncIterator]: async function* () {
|
|
217
|
-
// Yield the first page (await the promise)
|
|
218
|
-
yield await firstPagePromise;
|
|
219
|
-
// Yield the rest of the pages
|
|
220
|
-
for await (const page of iterator) {
|
|
221
|
-
yield page;
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
items: function () {
|
|
225
|
-
return {
|
|
226
|
-
[Symbol.asyncIterator]: async function* () {
|
|
227
|
-
// Yield the first page items
|
|
228
|
-
const firstPage = await firstPagePromise;
|
|
229
|
-
for (const item of firstPage.data) {
|
|
230
|
-
yield item;
|
|
231
|
-
}
|
|
232
|
-
// Yield items from the rest of the pages
|
|
233
|
-
for await (const page of iterator) {
|
|
234
|
-
for (const item of page.data) {
|
|
235
|
-
yield item;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
return namedFunctions[functionName];
|
|
245
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"function-utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/function-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createFunction, createPaginatedFunction } from "./function-utils";
|
|
3
|
-
import { ZapierValidationError, ZapierUnknownError } from "../types/errors";
|
|
4
|
-
import { ALL_ITEMS, listTestItems } from "./pagination-utils.test";
|
|
5
|
-
describe("createFunction", () => {
|
|
6
|
-
it("should return result from core function", async () => {
|
|
7
|
-
const mockCoreFn = async (options) => {
|
|
8
|
-
return `Hello, ${options.name}!`;
|
|
9
|
-
};
|
|
10
|
-
const wrappedFn = createFunction(mockCoreFn);
|
|
11
|
-
const result = await wrappedFn({ name: "World" });
|
|
12
|
-
expect(result).toBe("Hello, World!");
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
describe.each([
|
|
16
|
-
{ name: "createFunction", createFn: createFunction },
|
|
17
|
-
{ name: "createPaginatedFunction", createFn: createPaginatedFunction },
|
|
18
|
-
])("$name", ({ createFn }) => {
|
|
19
|
-
it("should preserve function name", async () => {
|
|
20
|
-
async function testCoreFn(options) {
|
|
21
|
-
return options.value * 2;
|
|
22
|
-
}
|
|
23
|
-
const wrappedFn = createFn(testCoreFn);
|
|
24
|
-
expect(wrappedFn.name).toBe("testCoreFn");
|
|
25
|
-
});
|
|
26
|
-
it("should normalize and rethrow ZapierError instances", async () => {
|
|
27
|
-
const mockError = new ZapierValidationError("Validation failed", {
|
|
28
|
-
details: { field: "name" },
|
|
29
|
-
});
|
|
30
|
-
const mockCoreFn = async () => {
|
|
31
|
-
throw mockError;
|
|
32
|
-
};
|
|
33
|
-
const wrappedFn = createFn(mockCoreFn);
|
|
34
|
-
await expect(wrappedFn({})).rejects.toBe(mockError);
|
|
35
|
-
});
|
|
36
|
-
it("should normalize generic Error to ZapierUnknownError", async () => {
|
|
37
|
-
const mockCoreFn = async () => {
|
|
38
|
-
throw new Error("Something went wrong");
|
|
39
|
-
};
|
|
40
|
-
const wrappedFn = createFn(mockCoreFn);
|
|
41
|
-
await expect(wrappedFn({})).rejects.toThrow(ZapierUnknownError);
|
|
42
|
-
});
|
|
43
|
-
it("should normalize non-Error values to ZapierUnknownError", async () => {
|
|
44
|
-
const mockCoreFn = async () => {
|
|
45
|
-
throw "String error";
|
|
46
|
-
};
|
|
47
|
-
const wrappedFn = createFn(mockCoreFn);
|
|
48
|
-
await expect(wrappedFn({})).rejects.toThrow(ZapierUnknownError);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe("createPaginatedFunction", () => {
|
|
52
|
-
it("should wrap non-array result in {data: [result]}", async () => {
|
|
53
|
-
const mockCoreFn = async (options) => {
|
|
54
|
-
return `Hello, ${options.name}!`;
|
|
55
|
-
};
|
|
56
|
-
const wrappedFn = createPaginatedFunction(mockCoreFn);
|
|
57
|
-
const result = await wrappedFn({ name: "World" });
|
|
58
|
-
expect(result).toEqual({ data: ["Hello, World!"] });
|
|
59
|
-
});
|
|
60
|
-
it("should wrap array result in {data: result}", async () => {
|
|
61
|
-
const mockCoreFn = async (options) => {
|
|
62
|
-
return Array.from({ length: options.count }, (_, i) => `Item ${i + 1}`);
|
|
63
|
-
};
|
|
64
|
-
const wrappedFn = createPaginatedFunction(mockCoreFn);
|
|
65
|
-
const result = await wrappedFn({ count: 3 });
|
|
66
|
-
expect(result).toEqual({ data: ["Item 1", "Item 2", "Item 3"] });
|
|
67
|
-
});
|
|
68
|
-
it("should return {data} object unchanged", async () => {
|
|
69
|
-
const mockCoreFn = async (options) => {
|
|
70
|
-
return { data: options.items };
|
|
71
|
-
};
|
|
72
|
-
const wrappedFn = createPaginatedFunction(mockCoreFn);
|
|
73
|
-
const result = await wrappedFn({ items: ["A", "B", "C"] });
|
|
74
|
-
expect(result).toEqual({ data: ["A", "B", "C"] });
|
|
75
|
-
});
|
|
76
|
-
it("should allow for await iteration over pages", async () => {
|
|
77
|
-
const listItems = createPaginatedFunction(listTestItems);
|
|
78
|
-
const pages = [];
|
|
79
|
-
for await (const page of listItems({ pageSize: 3 })) {
|
|
80
|
-
pages.push(page);
|
|
81
|
-
if (pages.length >= 3)
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
// Should have collected 3 pages
|
|
85
|
-
expect(pages).toHaveLength(3);
|
|
86
|
-
// Check first page structure
|
|
87
|
-
expect(pages[0]).toEqual({
|
|
88
|
-
data: ALL_ITEMS.slice(0, 3),
|
|
89
|
-
nextCursor: "cursor-3",
|
|
90
|
-
});
|
|
91
|
-
// Check second page
|
|
92
|
-
expect(pages[1]).toEqual({
|
|
93
|
-
data: ALL_ITEMS.slice(3, 6),
|
|
94
|
-
nextCursor: "cursor-6",
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
it("should allow for await iteration over individual items", async () => {
|
|
98
|
-
const listItems = createPaginatedFunction(listTestItems);
|
|
99
|
-
const items = [];
|
|
100
|
-
for await (const item of listItems({ pageSize: 3 }).items()) {
|
|
101
|
-
items.push(item);
|
|
102
|
-
if (items.length >= 7)
|
|
103
|
-
break; // Get first 7 items across pages
|
|
104
|
-
}
|
|
105
|
-
// Should have collected 7 individual items
|
|
106
|
-
expect(items).toHaveLength(7);
|
|
107
|
-
// Should be the first 7 items from ALL_ITEMS (flattened from pages)
|
|
108
|
-
expect(items).toEqual(ALL_ITEMS.slice(0, 7));
|
|
109
|
-
});
|
|
110
|
-
});
|
package/dist/utils/id-utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for working with IDs
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Coerces a string or number ID to a number for API calls that require numeric IDs.
|
|
6
|
-
*
|
|
7
|
-
* @param fieldName - The name of the field (for error messages)
|
|
8
|
-
* @param value - The ID value to coerce
|
|
9
|
-
* @returns The numeric ID
|
|
10
|
-
* @throws {ZapierValidationError} If the value cannot be converted to a valid number
|
|
11
|
-
*/
|
|
12
|
-
export declare function coerceToNumericId(fieldName: string, value: string | number): number;
|
|
13
|
-
//# sourceMappingURL=id-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id-utils.d.ts","sourceRoot":"","sources":["../../src/utils/id-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GAAG,MAAM,GACrB,MAAM,CAcR"}
|
package/dist/utils/id-utils.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for working with IDs
|
|
3
|
-
*/
|
|
4
|
-
import { ZapierValidationError } from "../types/errors";
|
|
5
|
-
/**
|
|
6
|
-
* Coerces a string or number ID to a number for API calls that require numeric IDs.
|
|
7
|
-
*
|
|
8
|
-
* @param fieldName - The name of the field (for error messages)
|
|
9
|
-
* @param value - The ID value to coerce
|
|
10
|
-
* @returns The numeric ID
|
|
11
|
-
* @throws {ZapierValidationError} If the value cannot be converted to a valid number
|
|
12
|
-
*/
|
|
13
|
-
export function coerceToNumericId(fieldName, value) {
|
|
14
|
-
if (value === "") {
|
|
15
|
-
throw new ZapierValidationError(`The ${fieldName} cannot be empty`);
|
|
16
|
-
}
|
|
17
|
-
const numericValue = typeof value === "number" ? value : Number(value);
|
|
18
|
-
if (!Number.isFinite(numericValue)) {
|
|
19
|
-
throw new ZapierValidationError(`The ${fieldName} "${value}" could not be converted to a number`);
|
|
20
|
-
}
|
|
21
|
-
return numericValue;
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id-utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/id-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { coerceToNumericId } from "./id-utils";
|
|
3
|
-
import { ZapierValidationError } from "../types/errors";
|
|
4
|
-
describe("coerceToNumericId", () => {
|
|
5
|
-
it("should return number unchanged", () => {
|
|
6
|
-
expect(coerceToNumericId("test_id", 123)).toBe(123);
|
|
7
|
-
});
|
|
8
|
-
it("should convert string number to number", () => {
|
|
9
|
-
expect(coerceToNumericId("test_id", "456")).toBe(456);
|
|
10
|
-
});
|
|
11
|
-
it("should throw for non-numeric string", () => {
|
|
12
|
-
expect(() => coerceToNumericId("auth_id", "abc")).toThrow(ZapierValidationError);
|
|
13
|
-
expect(() => coerceToNumericId("auth_id", "abc")).toThrow('The auth_id "abc" could not be converted to a number');
|
|
14
|
-
});
|
|
15
|
-
it("should throw for empty string", () => {
|
|
16
|
-
expect(() => coerceToNumericId("test_id", "")).toThrow(ZapierValidationError);
|
|
17
|
-
expect(() => coerceToNumericId("test_id", "")).toThrow("The test_id cannot be empty");
|
|
18
|
-
});
|
|
19
|
-
it("should throw for Infinity", () => {
|
|
20
|
-
expect(() => coerceToNumericId("test_id", Infinity)).toThrow(ZapierValidationError);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
type TPageOptions<TOptions> = TOptions extends undefined ? {
|
|
2
|
-
cursor?: string;
|
|
3
|
-
maxItems?: number;
|
|
4
|
-
pageSize?: number;
|
|
5
|
-
} : TOptions & {
|
|
6
|
-
cursor?: string;
|
|
7
|
-
maxItems?: number;
|
|
8
|
-
pageSize?: number;
|
|
9
|
-
};
|
|
10
|
-
export declare function createPrefixedCursor(prefix: string, cursor: string | undefined): string;
|
|
11
|
-
export declare function splitPrefixedCursor(cursor: string | undefined, prefixes?: string[]): [string | undefined, string | undefined];
|
|
12
|
-
/**
|
|
13
|
-
* Utility for paginating through API endpoints that return cursor-based pages
|
|
14
|
-
*
|
|
15
|
-
* @param pageFunction - Function that fetches a single page with {data, nextCursor} structure
|
|
16
|
-
* @param pageOptions - Options to pass to the page function (cursor will be managed automatically)
|
|
17
|
-
* @returns Async iterator that yields pages
|
|
18
|
-
*/
|
|
19
|
-
export declare function paginateMaxItems<TOptions, TPage extends {
|
|
20
|
-
data: any[];
|
|
21
|
-
nextCursor?: string;
|
|
22
|
-
}>(pageFunction: (options: TOptions & {
|
|
23
|
-
cursor?: string;
|
|
24
|
-
maxItems?: number;
|
|
25
|
-
pageSize?: number;
|
|
26
|
-
}) => Promise<TPage>, pageOptions?: TPageOptions<TOptions>): AsyncIterableIterator<TPage>;
|
|
27
|
-
export declare function paginateBuffered<TOptions, TPage extends {
|
|
28
|
-
data: any[];
|
|
29
|
-
nextCursor?: string;
|
|
30
|
-
}>(pageFunction: (options: TOptions & {
|
|
31
|
-
cursor?: string;
|
|
32
|
-
maxItems?: number;
|
|
33
|
-
pageSize?: number;
|
|
34
|
-
}) => Promise<TPage>, pageOptions?: TPageOptions<TOptions>): AsyncIterableIterator<TPage>;
|
|
35
|
-
export declare const paginate: typeof paginateBuffered;
|
|
36
|
-
export {};
|
|
37
|
-
//# sourceMappingURL=pagination-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pagination-utils.d.ts","sourceRoot":"","sources":["../../src/utils/pagination-utils.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,CAAC,QAAQ,IAAI,QAAQ,SAAS,SAAS,GACpD;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACzD,QAAQ,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAoCzE,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,MAAM,CAKR;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,CAAC,EAAE,MAAM,EAAE,GAClB,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAkB1C;AAED;;;;;;GAMG;AACH,wBAAuB,gBAAgB,CACrC,QAAQ,EACR,KAAK,SAAS;IAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,EAElD,YAAY,EAAE,CACZ,OAAO,EAAE,QAAQ,GAAG;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,KACE,OAAO,CAAC,KAAK,CAAC,EACnB,WAAW,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,GACnC,qBAAqB,CAAC,KAAK,CAAC,CAoC9B;AAED,wBAAuB,gBAAgB,CACrC,QAAQ,EACR,KAAK,SAAS;IAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,EAElD,YAAY,EAAE,CACZ,OAAO,EAAE,QAAQ,GAAG;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,KACE,OAAO,CAAC,KAAK,CAAC,EACnB,WAAW,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,GACnC,qBAAqB,CAAC,KAAK,CAAC,CAiG9B;AAED,eAAO,MAAM,QAAQ,yBAAmB,CAAC"}
|