@zapier/zapier-sdk 0.4.1 → 0.5.1
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 +13 -0
- package/README.md +343 -0
- package/dist/api/auth.d.ts +9 -0
- package/dist/api/auth.d.ts.map +1 -0
- package/dist/api/auth.js +25 -0
- package/dist/api/client.d.ts +9 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +322 -0
- package/dist/api/debug.d.ts +13 -0
- package/dist/api/debug.d.ts.map +1 -0
- package/dist/api/debug.js +55 -0
- package/dist/api/index.d.ts +29 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +41 -0
- package/dist/api/polling.d.ts +16 -0
- package/dist/api/polling.d.ts.map +1 -0
- package/dist/api/polling.js +45 -0
- package/dist/api/schemas.d.ts +2473 -0
- package/dist/api/schemas.d.ts.map +1 -0
- package/dist/api/schemas.js +355 -0
- package/dist/api/types.d.ts +75 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +11 -0
- package/dist/auth.d.ts +34 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +47 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/index.cjs +2108 -1379
- package/dist/index.d.mts +2440 -620
- package/dist/index.d.ts +17 -892
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.mjs +2093 -1362
- package/dist/plugins/api/index.d.ts +14 -0
- package/dist/plugins/api/index.d.ts.map +1 -0
- package/dist/plugins/api/index.js +21 -0
- package/dist/plugins/apps/index.d.ts +11 -0
- package/dist/plugins/apps/index.d.ts.map +1 -0
- package/dist/plugins/apps/index.js +91 -0
- package/dist/plugins/apps/types.d.ts +30 -0
- package/dist/plugins/apps/types.d.ts.map +1 -0
- package/dist/plugins/apps/types.js +2 -0
- package/dist/plugins/fetch/index.d.ts +21 -0
- package/dist/plugins/fetch/index.d.ts.map +1 -0
- package/dist/plugins/fetch/index.js +20 -0
- package/dist/plugins/findFirstAuthentication/index.d.ts +20 -0
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/index.js +24 -0
- package/dist/plugins/findFirstAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/findFirstAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/index.test.js +171 -0
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +29 -0
- package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/findFirstAuthentication/schemas.js +18 -0
- package/dist/plugins/findUniqueAuthentication/index.d.ts +20 -0
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/index.js +31 -0
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/findUniqueAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/index.test.js +152 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +29 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/findUniqueAuthentication/schemas.js +18 -0
- package/dist/plugins/getAction/index.d.ts +23 -0
- package/dist/plugins/getAction/index.d.ts.map +1 -0
- package/dist/plugins/getAction/index.js +28 -0
- package/dist/plugins/getAction/index.test.d.ts +2 -0
- package/dist/plugins/getAction/index.test.d.ts.map +1 -0
- package/dist/plugins/getAction/index.test.js +186 -0
- package/dist/plugins/getAction/schemas.d.ts +23 -0
- package/dist/plugins/getAction/schemas.d.ts.map +1 -0
- package/dist/plugins/getAction/schemas.js +10 -0
- package/dist/plugins/getApp/index.d.ts +22 -0
- package/dist/plugins/getApp/index.d.ts.map +1 -0
- package/dist/plugins/getApp/index.js +39 -0
- package/dist/plugins/getApp/index.test.d.ts +2 -0
- package/dist/plugins/getApp/index.test.d.ts.map +1 -0
- package/dist/plugins/getApp/index.test.js +100 -0
- package/dist/plugins/getApp/schemas.d.ts +18 -0
- package/dist/plugins/getApp/schemas.d.ts.map +1 -0
- package/dist/plugins/getApp/schemas.js +10 -0
- package/dist/plugins/getAuthentication/index.d.ts +22 -0
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/index.js +41 -0
- package/dist/plugins/getAuthentication/index.test.d.ts +2 -0
- package/dist/plugins/getAuthentication/index.test.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/index.test.js +205 -0
- package/dist/plugins/getAuthentication/schemas.d.ts +17 -0
- package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -0
- package/dist/plugins/getAuthentication/schemas.js +11 -0
- package/dist/plugins/getProfile/index.d.ts +23 -0
- package/dist/plugins/getProfile/index.d.ts.map +1 -0
- package/dist/plugins/getProfile/index.js +29 -0
- package/dist/plugins/getProfile/schemas.d.ts +13 -0
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -0
- package/dist/plugins/getProfile/schemas.js +5 -0
- package/dist/plugins/listActions/index.d.ts +28 -0
- package/dist/plugins/listActions/index.d.ts.map +1 -0
- package/dist/plugins/listActions/index.js +61 -0
- package/dist/plugins/listActions/index.test.d.ts +2 -0
- package/dist/plugins/listActions/index.test.d.ts.map +1 -0
- package/dist/plugins/listActions/index.test.js +467 -0
- package/dist/plugins/listActions/schemas.d.ts +29 -0
- package/dist/plugins/listActions/schemas.d.ts.map +1 -0
- package/dist/plugins/listActions/schemas.js +21 -0
- package/dist/plugins/listApps/index.d.ts +28 -0
- package/dist/plugins/listApps/index.d.ts.map +1 -0
- package/dist/plugins/listApps/index.js +62 -0
- package/dist/plugins/listApps/index.test.d.ts +2 -0
- package/dist/plugins/listApps/index.test.d.ts.map +1 -0
- package/dist/plugins/listApps/index.test.js +313 -0
- package/dist/plugins/listApps/schemas.d.ts +30 -0
- package/dist/plugins/listApps/schemas.d.ts.map +1 -0
- package/dist/plugins/listApps/schemas.js +23 -0
- package/dist/plugins/listAuthentications/index.d.ts +28 -0
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/index.js +77 -0
- package/dist/plugins/listAuthentications/index.test.d.ts +2 -0
- package/dist/plugins/listAuthentications/index.test.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/index.test.js +564 -0
- package/dist/plugins/listAuthentications/schemas.d.ts +38 -0
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -0
- package/dist/plugins/listAuthentications/schemas.js +28 -0
- package/dist/plugins/listInputFields/index.d.ts +28 -0
- package/dist/plugins/listInputFields/index.d.ts.map +1 -0
- package/dist/plugins/listInputFields/index.js +133 -0
- package/dist/plugins/listInputFields/index.test.d.ts +2 -0
- package/dist/plugins/listInputFields/index.test.d.ts.map +1 -0
- package/dist/plugins/listInputFields/index.test.js +325 -0
- package/dist/plugins/listInputFields/schemas.d.ts +38 -0
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -0
- package/dist/plugins/listInputFields/schemas.js +22 -0
- package/dist/plugins/registry/index.d.ts +11 -0
- package/dist/plugins/registry/index.d.ts.map +1 -0
- package/dist/plugins/registry/index.js +14 -0
- package/dist/plugins/request/index.d.ts +19 -0
- package/dist/plugins/request/index.d.ts.map +1 -0
- package/dist/plugins/request/index.js +62 -0
- package/dist/plugins/request/index.test.d.ts +2 -0
- package/dist/plugins/request/index.test.d.ts.map +1 -0
- package/dist/plugins/request/index.test.js +256 -0
- package/dist/plugins/request/schemas.d.ts +69 -0
- package/dist/plugins/request/schemas.d.ts.map +1 -0
- package/dist/plugins/request/schemas.js +42 -0
- package/dist/plugins/runAction/index.d.ts +28 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -0
- package/dist/plugins/runAction/index.js +86 -0
- package/dist/plugins/runAction/index.test.d.ts +2 -0
- package/dist/plugins/runAction/index.test.d.ts.map +1 -0
- package/dist/plugins/runAction/index.test.js +320 -0
- package/dist/plugins/runAction/schemas.d.ts +37 -0
- package/dist/plugins/runAction/schemas.d.ts.map +1 -0
- package/dist/plugins/runAction/schemas.js +22 -0
- package/dist/resolvers/actionKey.d.ts +9 -0
- package/dist/resolvers/actionKey.d.ts.map +1 -0
- package/dist/resolvers/actionKey.js +19 -0
- package/dist/resolvers/actionType.d.ts +9 -0
- package/dist/resolvers/actionType.d.ts.map +1 -0
- package/dist/resolvers/actionType.js +22 -0
- package/dist/resolvers/appKey.d.ts +7 -0
- package/dist/resolvers/appKey.d.ts.map +1 -0
- package/dist/resolvers/appKey.js +5 -0
- package/dist/resolvers/authenticationId.d.ts +9 -0
- package/dist/resolvers/authenticationId.d.ts.map +1 -0
- package/dist/resolvers/authenticationId.js +33 -0
- package/dist/resolvers/index.d.ts +40 -0
- package/dist/resolvers/index.d.ts.map +1 -0
- package/dist/resolvers/index.js +91 -0
- package/dist/resolvers/inputs.d.ts +8 -0
- package/dist/resolvers/inputs.d.ts.map +1 -0
- package/dist/resolvers/inputs.js +14 -0
- package/dist/schemas/Action.d.ts +243 -0
- package/dist/schemas/Action.d.ts.map +1 -0
- package/dist/schemas/Action.js +34 -0
- package/dist/schemas/App.d.ts +26 -0
- package/dist/schemas/App.d.ts.map +1 -0
- package/dist/schemas/App.js +22 -0
- package/dist/schemas/Auth.d.ts +161 -0
- package/dist/schemas/Auth.d.ts.map +1 -0
- package/dist/schemas/Auth.js +41 -0
- package/dist/schemas/Field.d.ts +144 -0
- package/dist/schemas/Field.d.ts.map +1 -0
- package/dist/schemas/Field.js +105 -0
- package/dist/schemas/UserProfile.d.ts +163 -0
- package/dist/schemas/UserProfile.d.ts.map +1 -0
- package/dist/schemas/UserProfile.js +29 -0
- package/dist/sdk.d.ts +10 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +94 -0
- package/dist/sdk.test.d.ts +2 -0
- package/dist/sdk.test.d.ts.map +1 -0
- package/dist/sdk.test.js +135 -0
- package/dist/types/domain.d.ts +36 -0
- package/dist/types/domain.d.ts.map +1 -0
- package/dist/types/domain.js +1 -0
- package/dist/types/domain.test.d.ts +2 -0
- package/dist/types/domain.test.d.ts.map +1 -0
- package/dist/types/domain.test.js +39 -0
- package/dist/types/errors.d.ts +143 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +187 -0
- package/dist/types/events.d.ts +38 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +7 -0
- package/dist/types/functions.d.ts +26 -0
- package/dist/types/functions.d.ts.map +1 -0
- package/dist/types/functions.js +4 -0
- package/dist/types/plugin.d.ts +61 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +9 -0
- package/dist/types/properties.d.ts +22 -0
- package/dist/types/properties.d.ts.map +1 -0
- package/dist/types/properties.js +50 -0
- package/dist/types/sdk.d.ts +43 -0
- package/dist/types/sdk.d.ts.map +1 -0
- package/dist/types/sdk.js +4 -0
- package/dist/utils/array-utils.d.ts +31 -0
- package/dist/utils/array-utils.d.ts.map +1 -0
- package/dist/utils/array-utils.js +36 -0
- package/dist/utils/array-utils.test.d.ts +2 -0
- package/dist/utils/array-utils.test.d.ts.map +1 -0
- package/dist/utils/array-utils.test.js +107 -0
- package/dist/utils/domain-utils.d.ts +78 -0
- package/dist/utils/domain-utils.d.ts.map +1 -0
- package/dist/utils/domain-utils.js +218 -0
- package/dist/utils/domain-utils.test.d.ts +2 -0
- package/dist/utils/domain-utils.test.d.ts.map +1 -0
- package/dist/utils/domain-utils.test.js +192 -0
- package/dist/utils/function-utils.d.ts +45 -0
- package/dist/utils/function-utils.d.ts.map +1 -0
- package/dist/utils/function-utils.js +158 -0
- package/dist/utils/function-utils.test.d.ts +2 -0
- package/dist/utils/function-utils.test.d.ts.map +1 -0
- package/dist/utils/function-utils.test.js +110 -0
- package/dist/utils/pagination-utils.d.ts +37 -0
- package/dist/utils/pagination-utils.d.ts.map +1 -0
- package/dist/utils/pagination-utils.js +165 -0
- package/dist/utils/pagination-utils.test.d.ts +17 -0
- package/dist/utils/pagination-utils.test.d.ts.map +1 -0
- package/dist/utils/pagination-utils.test.js +461 -0
- package/dist/utils/schema-utils.d.ts +45 -0
- package/dist/utils/schema-utils.d.ts.map +1 -0
- package/dist/utils/schema-utils.js +65 -0
- package/dist/utils/validation.d.ts +4 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +30 -0
- package/dist/utils/validation.test.d.ts +2 -0
- package/dist/utils/validation.test.d.ts.map +1 -0
- package/dist/utils/validation.test.js +43 -0
- package/package.json +12 -3
- package/src/api/client.ts +394 -171
- package/src/api/debug.ts +10 -1
- package/src/api/index.ts +0 -2
- package/src/api/polling.ts +28 -7
- package/src/api/schemas.ts +387 -0
- package/src/api/types.ts +72 -136
- package/src/constants.ts +10 -0
- package/src/index.ts +40 -19
- package/src/plugins/api/index.ts +47 -0
- package/src/plugins/apps/index.ts +25 -19
- package/src/plugins/apps/types.ts +7 -11
- package/src/plugins/fetch/index.ts +48 -40
- package/src/plugins/findFirstAuthentication/index.test.ts +206 -0
- package/src/plugins/findFirstAuthentication/index.ts +55 -0
- package/src/plugins/findFirstAuthentication/schemas.ts +41 -0
- package/src/plugins/findUniqueAuthentication/index.test.ts +197 -0
- package/src/plugins/findUniqueAuthentication/index.ts +72 -0
- package/src/plugins/findUniqueAuthentication/schemas.ts +42 -0
- package/src/plugins/getAction/index.test.ts +239 -0
- package/src/plugins/getAction/index.ts +57 -0
- package/src/plugins/getAction/schemas.ts +33 -0
- package/src/plugins/getApp/index.test.ts +127 -0
- package/src/plugins/getApp/index.ts +66 -0
- package/src/plugins/getApp/schemas.ts +38 -0
- package/src/plugins/getAuthentication/index.test.ts +284 -0
- package/src/plugins/getAuthentication/index.ts +86 -0
- package/src/plugins/getAuthentication/schemas.ts +31 -0
- package/src/plugins/getProfile/index.ts +55 -0
- package/src/plugins/getProfile/schemas.ts +26 -0
- package/src/plugins/listActions/index.test.ts +582 -0
- package/src/plugins/listActions/index.ts +115 -0
- package/src/plugins/listActions/schemas.ts +54 -0
- package/src/plugins/listApps/index.test.ts +357 -0
- package/src/plugins/listApps/index.ts +121 -0
- package/src/plugins/listApps/schemas.ts +49 -0
- package/src/plugins/listAuthentications/index.test.ts +709 -0
- package/src/plugins/listAuthentications/index.ts +136 -0
- package/src/plugins/listAuthentications/schemas.ts +60 -0
- package/src/plugins/listInputFields/index.test.ts +408 -0
- package/src/plugins/listInputFields/index.ts +204 -0
- package/src/plugins/listInputFields/schemas.ts +56 -0
- package/src/plugins/registry/index.ts +30 -0
- package/src/plugins/request/index.test.ts +329 -0
- package/src/plugins/request/index.ts +103 -0
- package/src/{functions → plugins}/request/schemas.ts +20 -9
- package/src/plugins/runAction/index.test.ts +387 -0
- package/src/plugins/runAction/index.ts +176 -0
- package/src/plugins/runAction/schemas.ts +53 -0
- package/src/resolvers/actionKey.ts +6 -4
- package/src/resolvers/actionType.ts +7 -2
- package/src/resolvers/appKey.ts +1 -1
- package/src/resolvers/authenticationId.ts +12 -3
- package/src/resolvers/inputs.ts +3 -1
- package/src/schemas/Action.ts +18 -12
- package/src/schemas/App.ts +11 -19
- package/src/schemas/Auth.ts +18 -13
- package/src/schemas/Field.ts +106 -11
- package/src/schemas/UserProfile.ts +43 -0
- package/src/sdk.test.ts +212 -0
- package/src/sdk.ts +132 -102
- package/src/types/domain.test.ts +50 -0
- package/src/types/domain.ts +43 -75
- package/src/types/errors.ts +275 -0
- package/src/types/functions.ts +27 -0
- package/src/types/optional-zapier-sdk-cli-login.d.ts +37 -0
- package/src/types/plugin.ts +105 -0
- package/src/types/properties.ts +4 -3
- package/src/types/sdk.ts +70 -48
- package/src/utils/array-utils.test.ts +131 -0
- package/src/utils/array-utils.ts +41 -0
- package/src/utils/domain-utils.test.ts +239 -0
- package/src/utils/domain-utils.ts +283 -0
- package/src/utils/function-utils.test.ts +141 -0
- package/src/utils/function-utils.ts +245 -0
- package/src/utils/pagination-utils.test.ts +620 -0
- package/src/utils/pagination-utils.ts +242 -0
- package/src/utils/validation.test.ts +50 -0
- package/src/utils/validation.ts +44 -0
- package/tsconfig.build.json +16 -2
- package/tsconfig.json +3 -1
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +2 -0
- package/src/functions/bundleCode/index.ts +0 -78
- package/src/functions/bundleCode/info.ts +0 -9
- package/src/functions/bundleCode/schemas.ts +0 -30
- package/src/functions/findFirstAuthentication/index.ts +0 -24
- package/src/functions/findFirstAuthentication/info.ts +0 -9
- package/src/functions/findFirstAuthentication/schemas.ts +0 -50
- package/src/functions/findUniqueAuthentication/index.ts +0 -35
- package/src/functions/findUniqueAuthentication/info.ts +0 -9
- package/src/functions/findUniqueAuthentication/schemas.ts +0 -50
- package/src/functions/generateTypes/index.ts +0 -363
- package/src/functions/generateTypes/info.ts +0 -9
- package/src/functions/generateTypes/schemas.ts +0 -31
- package/src/functions/getAction/index.ts +0 -33
- package/src/functions/getAction/info.ts +0 -9
- package/src/functions/getAction/schemas.ts +0 -25
- package/src/functions/getApp/index.ts +0 -41
- package/src/functions/getApp/info.ts +0 -9
- package/src/functions/getApp/schemas.ts +0 -20
- package/src/functions/getAuthentication/index.ts +0 -50
- package/src/functions/getAuthentication/info.ts +0 -9
- package/src/functions/getAuthentication/schemas.ts +0 -29
- package/src/functions/listActions/index.ts +0 -149
- package/src/functions/listActions/info.ts +0 -9
- package/src/functions/listActions/schemas.ts +0 -30
- package/src/functions/listApps/index.ts +0 -60
- package/src/functions/listApps/info.ts +0 -9
- package/src/functions/listApps/schemas.ts +0 -32
- package/src/functions/listAuthentications/index.ts +0 -162
- package/src/functions/listAuthentications/info.ts +0 -9
- package/src/functions/listAuthentications/schemas.ts +0 -50
- package/src/functions/listFields/index.ts +0 -86
- package/src/functions/listFields/info.ts +0 -9
- package/src/functions/listFields/schemas.ts +0 -36
- package/src/functions/request/index.ts +0 -150
- package/src/functions/request/info.ts +0 -11
- package/src/functions/runAction/index.ts +0 -127
- package/src/functions/runAction/info.ts +0 -9
- package/src/functions/runAction/schemas.ts +0 -34
- package/src/plugins/apps/info.ts +0 -12
- package/src/plugins/fetch/types.ts +0 -2
- /package/src/{schema-utils.ts → utils/schema-utils.ts} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ApiClient } from "../../api/types";
|
|
2
|
+
import type { BaseSdkOptions } from "../../types/sdk";
|
|
3
|
+
import type { Plugin } from "../../types/plugin";
|
|
4
|
+
export interface ApiPluginOptions extends BaseSdkOptions {
|
|
5
|
+
}
|
|
6
|
+
export interface ApiPluginProvides {
|
|
7
|
+
context: {
|
|
8
|
+
api: ApiClient;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const apiPlugin: Plugin<{}, // no SDK dependencies
|
|
12
|
+
{}, // requires no context
|
|
13
|
+
ApiPluginProvides>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/api/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG;AAG3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE;QACP,GAAG,EAAE,SAAS,CAAC;KAChB,CAAC;CACH;AAGD,eAAO,MAAM,SAAS,EAAE,MAAM,CAC5B,EAAE,EAAE,sBAAsB;AAC1B,EAAE,EAAE,sBAAsB;AAC1B,iBAAiB,CA4BlB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createZapierApi } from "../../api";
|
|
2
|
+
// API plugin requires no context and provides api in context
|
|
3
|
+
export const apiPlugin = (params) => {
|
|
4
|
+
// Extract all options - everything passed to the plugin
|
|
5
|
+
const { fetch: customFetch = globalThis.fetch, baseUrl = "https://zapier.com", token, getToken, onEvent, debug = false, } = params;
|
|
6
|
+
// Create the API client - it will handle token resolution internally
|
|
7
|
+
const api = createZapierApi({
|
|
8
|
+
baseUrl,
|
|
9
|
+
token,
|
|
10
|
+
getToken,
|
|
11
|
+
debug,
|
|
12
|
+
fetch: customFetch,
|
|
13
|
+
onEvent,
|
|
14
|
+
});
|
|
15
|
+
// Return flat structure with context only
|
|
16
|
+
return {
|
|
17
|
+
context: {
|
|
18
|
+
api, // Provide API client in context for other plugins to use
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ActionProxy } from "./types";
|
|
2
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
3
|
+
import type { FetchPluginProvides } from "../fetch/index";
|
|
4
|
+
import type { RunActionPluginProvides } from "../runAction/index";
|
|
5
|
+
export interface AppsPluginProvides {
|
|
6
|
+
apps: ActionProxy;
|
|
7
|
+
}
|
|
8
|
+
export declare const appsPlugin: Plugin<GetSdkType<FetchPluginProvides & RunActionPluginProvides>, // requires fetch + runAction in SDK
|
|
9
|
+
{}, // no context requirements
|
|
10
|
+
AppsPluginProvides>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/apps/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;CACnB;AA4JD,eAAO,MAAM,UAAU,EAAE,MAAM,CAC7B,UAAU,CAAC,mBAAmB,GAAG,uBAAuB,CAAC,EAAE,oCAAoC;AAC/F,EAAE,EAAE,0BAA0B;AAC9B,kBAAkB,CAMnB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ZapierValidationError } from "../../types/errors";
|
|
2
|
+
function createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId) {
|
|
3
|
+
return (actionOptions = {}) => {
|
|
4
|
+
const { sdk } = options;
|
|
5
|
+
const { inputs, authenticationId: providedAuthenticationId } = actionOptions;
|
|
6
|
+
// Use pinned auth ID first, then provided auth ID
|
|
7
|
+
const authenticationId = pinnedAuthId || providedAuthenticationId;
|
|
8
|
+
if (!authenticationId) {
|
|
9
|
+
throw new ZapierValidationError(`Authentication ID is required. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }) or provide authenticationId in the action call.`);
|
|
10
|
+
}
|
|
11
|
+
// Call sdk.runAction with the resolved parameters
|
|
12
|
+
return sdk.runAction({
|
|
13
|
+
appKey,
|
|
14
|
+
actionType: actionType,
|
|
15
|
+
actionKey,
|
|
16
|
+
inputs,
|
|
17
|
+
authenticationId,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createActionTypeProxy(appKey, actionType, options, pinnedAuthId) {
|
|
22
|
+
// Special handling for "fetch" action type
|
|
23
|
+
if (actionType === "fetch") {
|
|
24
|
+
return async (url, init) => {
|
|
25
|
+
const { sdk } = options;
|
|
26
|
+
// Use pinned auth ID first, then provided auth ID
|
|
27
|
+
const authenticationId = pinnedAuthId || init?.authenticationId;
|
|
28
|
+
if (!authenticationId) {
|
|
29
|
+
throw new ZapierValidationError(`Authentication ID is required for fetch. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }).fetch(...) or provide authenticationId in the fetch call.`);
|
|
30
|
+
}
|
|
31
|
+
// Call sdk.fetch with the resolved authenticationId
|
|
32
|
+
return sdk.fetch(url, {
|
|
33
|
+
...init,
|
|
34
|
+
authenticationId,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return new Proxy({}, {
|
|
39
|
+
get(_, actionKey) {
|
|
40
|
+
if (typeof actionKey === "string") {
|
|
41
|
+
return createActionFunction(appKey, actionType, actionKey, options, pinnedAuthId);
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function createPinnedAppProxy(appKey, options, pinnedAuthId) {
|
|
48
|
+
return new Proxy({}, {
|
|
49
|
+
get(_, actionType) {
|
|
50
|
+
if (typeof actionType === "string") {
|
|
51
|
+
return createActionTypeProxy(appKey, actionType, options, pinnedAuthId);
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function createAppProxy(appKey, options) {
|
|
58
|
+
// Create the factory function that returns a pinned version
|
|
59
|
+
const appFactory = (factoryOptions) => {
|
|
60
|
+
return createPinnedAppProxy(appKey, options, factoryOptions.authenticationId);
|
|
61
|
+
};
|
|
62
|
+
// Add properties for direct usage (backward compatibility)
|
|
63
|
+
return new Proxy(appFactory, {
|
|
64
|
+
get(_, actionType) {
|
|
65
|
+
if (typeof actionType === "string") {
|
|
66
|
+
return createActionTypeProxy(appKey, actionType, options);
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function createAppsProxy(options) {
|
|
73
|
+
// Create a proxy object that intercepts property access
|
|
74
|
+
const appsProxy = new Proxy({}, {
|
|
75
|
+
get(_, prop) {
|
|
76
|
+
if (typeof prop === "string") {
|
|
77
|
+
// First level: App names (e.g., 'slack')
|
|
78
|
+
return createAppProxy(prop, options);
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return appsProxy;
|
|
84
|
+
}
|
|
85
|
+
// Direct plugin function - takes options + sdk + context in one object
|
|
86
|
+
export const appsPlugin = ({ sdk }) => {
|
|
87
|
+
// Return flat structure - apps goes directly to SDK
|
|
88
|
+
return {
|
|
89
|
+
apps: createAppsProxy({ sdk }),
|
|
90
|
+
};
|
|
91
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ActionExecutionOptions {
|
|
2
|
+
inputs?: Record<string, any>;
|
|
3
|
+
authenticationId?: number;
|
|
4
|
+
}
|
|
5
|
+
interface AppFactoryOptions {
|
|
6
|
+
authenticationId: number;
|
|
7
|
+
}
|
|
8
|
+
interface BaseActionTypeProxy {
|
|
9
|
+
[action: string]: (options?: ActionExecutionOptions) => any;
|
|
10
|
+
}
|
|
11
|
+
interface FetchActionType {
|
|
12
|
+
fetch: (url: string | URL, init?: RequestInit & {
|
|
13
|
+
authenticationId?: number;
|
|
14
|
+
callbackUrl?: string;
|
|
15
|
+
authenticationTemplate?: string;
|
|
16
|
+
}) => Promise<Response>;
|
|
17
|
+
}
|
|
18
|
+
type ActionTypeProxy = BaseActionTypeProxy & Partial<FetchActionType>;
|
|
19
|
+
interface AppProxy {
|
|
20
|
+
[type: string]: ActionTypeProxy;
|
|
21
|
+
}
|
|
22
|
+
interface AppFactory {
|
|
23
|
+
(options: AppFactoryOptions): AppProxy;
|
|
24
|
+
}
|
|
25
|
+
type AppProxyWithFactory = AppFactory & AppProxy;
|
|
26
|
+
export interface ActionProxy {
|
|
27
|
+
[app: string]: AppProxyWithFactory;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/apps/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,UAAU,iBAAiB;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAGD,UAAU,mBAAmB;IAC3B,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,GAAG,CAAC;CAC7D;AAGD,UAAU,eAAe;IACvB,KAAK,EAAE,CACL,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,WAAW,GAAG;QACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,KACE,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxB;AAGD,KAAK,eAAe,GAAG,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAEtE,UAAU,QAAQ;IAChB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;CACjC;AAED,UAAU,UAAU;IAClB,CAAC,OAAO,EAAE,iBAAiB,GAAG,QAAQ,CAAC;CACxC;AAGD,KAAK,mBAAmB,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEjD,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAC;CACpC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { RequestPluginProvides } from "../request";
|
|
3
|
+
export interface FetchPluginProvides {
|
|
4
|
+
fetch: (url: string | URL, init?: RequestInit & {
|
|
5
|
+
authenticationId?: number;
|
|
6
|
+
callbackUrl?: string;
|
|
7
|
+
authenticationTemplate?: string;
|
|
8
|
+
}) => Promise<Response>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Direct plugin function - takes options + sdk + context in one object
|
|
12
|
+
*/
|
|
13
|
+
export declare const fetchPlugin: Plugin<GetSdkType<RequestPluginProvides>, // requires request in SDK
|
|
14
|
+
{}, // requires no context (uses SDK methods)
|
|
15
|
+
FetchPluginProvides>;
|
|
16
|
+
export type ZapierFetchInitOptions = RequestInit & {
|
|
17
|
+
authenticationId?: number;
|
|
18
|
+
callbackUrl?: string;
|
|
19
|
+
authenticationTemplate?: string;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,CACL,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,WAAW,GAAG;QACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,KACE,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxB;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAC9B,UAAU,CAAC,qBAAqB,CAAC,EAAE,0BAA0B;AAC7D,EAAE,EAAE,yCAAyC;AAC7C,mBAAmB,CA8BpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,WAAW,GAAG;IACjD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct plugin function - takes options + sdk + context in one object
|
|
3
|
+
*/
|
|
4
|
+
export const fetchPlugin = ({ sdk }) => {
|
|
5
|
+
// Return flat structure - fetch goes directly to SDK
|
|
6
|
+
return {
|
|
7
|
+
fetch: async function fetch(url, init) {
|
|
8
|
+
const { authenticationId, callbackUrl, authenticationTemplate, ...fetchInit } = init || {};
|
|
9
|
+
return sdk.request({
|
|
10
|
+
url: url.toString(),
|
|
11
|
+
method: fetchInit.method,
|
|
12
|
+
body: fetchInit.body,
|
|
13
|
+
headers: fetchInit.headers,
|
|
14
|
+
authenticationId,
|
|
15
|
+
callbackUrl,
|
|
16
|
+
authenticationTemplate,
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
3
|
+
import { FindFirstAuthenticationSchema, type FindFirstAuthenticationOptions } from "./schemas";
|
|
4
|
+
import type { ListAuthenticationsPluginProvides } from "../listAuthentications";
|
|
5
|
+
export interface FindFirstAuthenticationPluginProvides {
|
|
6
|
+
findFirstAuthentication: (options?: FindFirstAuthenticationOptions) => Promise<{
|
|
7
|
+
data: AuthenticationItem | null;
|
|
8
|
+
}>;
|
|
9
|
+
context: {
|
|
10
|
+
meta: {
|
|
11
|
+
findFirstAuthentication: {
|
|
12
|
+
inputSchema: typeof FindFirstAuthenticationSchema;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare const findFirstAuthenticationPlugin: Plugin<GetSdkType<ListAuthenticationsPluginProvides>, // requires listAuthentications in SDK
|
|
18
|
+
{}, // no context requirements
|
|
19
|
+
FindFirstAuthenticationPluginProvides>;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/findFirstAuthentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,KAAK,8BAA8B,EACpC,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAEhF,MAAM,WAAW,qCAAqC;IACpD,uBAAuB,EAAE,CACvB,OAAO,CAAC,EAAE,8BAA8B,KACrC,OAAO,CAAC;QAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IAClD,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,uBAAuB,EAAE;gBACvB,WAAW,EAAE,OAAO,6BAA6B,CAAC;aACnD,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAChD,UAAU,CAAC,iCAAiC,CAAC,EAAE,sCAAsC;AACrF,EAAE,EAAE,0BAA0B;AAC9B,qCAAqC,CA6BtC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FindFirstAuthenticationSchema, } from "./schemas";
|
|
2
|
+
import { createFunction } from "../../utils/function-utils";
|
|
3
|
+
export const findFirstAuthenticationPlugin = ({ sdk }) => {
|
|
4
|
+
const findFirstAuthentication = createFunction(async function findFirstAuthentication(options = {}) {
|
|
5
|
+
// Use listAuthentications with maxItems 1 to get the first result
|
|
6
|
+
const authsResponse = await sdk.listAuthentications({
|
|
7
|
+
...options,
|
|
8
|
+
maxItems: 1,
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
data: authsResponse.data.length > 0 ? authsResponse.data[0] : null,
|
|
12
|
+
};
|
|
13
|
+
}, FindFirstAuthenticationSchema);
|
|
14
|
+
return {
|
|
15
|
+
findFirstAuthentication,
|
|
16
|
+
context: {
|
|
17
|
+
meta: {
|
|
18
|
+
findFirstAuthentication: {
|
|
19
|
+
inputSchema: FindFirstAuthenticationSchema,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/findFirstAuthentication/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { ZapierValidationError } from "../../types/errors";
|
|
3
|
+
import { findFirstAuthenticationPlugin } from "./index";
|
|
4
|
+
import { createSdk } from "../../sdk";
|
|
5
|
+
import { ListAuthenticationsSchema } from "../listAuthentications/schemas";
|
|
6
|
+
const mockAuthentications = [
|
|
7
|
+
{
|
|
8
|
+
id: 123,
|
|
9
|
+
title: "My Slack",
|
|
10
|
+
date: "2021-01-01",
|
|
11
|
+
account_id: 123,
|
|
12
|
+
implementation_id: "api_123",
|
|
13
|
+
is_expired: "false",
|
|
14
|
+
expired_at: null,
|
|
15
|
+
is_invite_only: false,
|
|
16
|
+
is_private: false,
|
|
17
|
+
shared_with_all: false,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: 456,
|
|
21
|
+
title: "Slack Workspace 2",
|
|
22
|
+
is_expired: "false",
|
|
23
|
+
expired_at: null,
|
|
24
|
+
date: "2021-01-01",
|
|
25
|
+
account_id: 123,
|
|
26
|
+
implementation_id: "api_123",
|
|
27
|
+
is_invite_only: false,
|
|
28
|
+
is_private: false,
|
|
29
|
+
shared_with_all: false,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
describe("findFirstAuthentication plugin", () => {
|
|
33
|
+
let mockListAuthentications;
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
vi.clearAllMocks();
|
|
36
|
+
mockListAuthentications = vi.fn().mockResolvedValue({
|
|
37
|
+
data: mockAuthentications,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
function createTestSdk() {
|
|
41
|
+
// Create a proper plugin chain: first add a mock listAuthentications plugin, then add findFirstAuthentication
|
|
42
|
+
const mockListAuthenticationsPlugin = () => ({
|
|
43
|
+
listAuthentications: mockListAuthentications,
|
|
44
|
+
context: {
|
|
45
|
+
meta: {
|
|
46
|
+
listAuthentications: {
|
|
47
|
+
inputSchema: ListAuthenticationsSchema,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
// Build SDK with proper plugin composition
|
|
53
|
+
return createSdk()
|
|
54
|
+
.addPlugin(mockListAuthenticationsPlugin)
|
|
55
|
+
.addPlugin(findFirstAuthenticationPlugin);
|
|
56
|
+
}
|
|
57
|
+
describe("schema validation", () => {
|
|
58
|
+
it("should pass validation with empty options", async () => {
|
|
59
|
+
const sdk = createTestSdk();
|
|
60
|
+
const result = await sdk.findFirstAuthentication({});
|
|
61
|
+
expect(result.data).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
it("should pass validation with undefined options", async () => {
|
|
64
|
+
const sdk = createTestSdk();
|
|
65
|
+
const result = await sdk.findFirstAuthentication();
|
|
66
|
+
expect(result.data).toBeDefined();
|
|
67
|
+
});
|
|
68
|
+
it("should throw validation error for invalid appKey type", async () => {
|
|
69
|
+
const sdk = createTestSdk();
|
|
70
|
+
await expect(sdk.findFirstAuthentication({
|
|
71
|
+
appKey: 123, // intentionally wrong type for testing
|
|
72
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
73
|
+
});
|
|
74
|
+
it("should throw validation error for invalid search type", async () => {
|
|
75
|
+
const sdk = createTestSdk();
|
|
76
|
+
await expect(sdk.findFirstAuthentication({
|
|
77
|
+
search: 123,
|
|
78
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
79
|
+
});
|
|
80
|
+
it("should throw validation error for invalid parameter types", async () => {
|
|
81
|
+
const sdk = createTestSdk();
|
|
82
|
+
await expect(sdk.findFirstAuthentication({
|
|
83
|
+
title: 123,
|
|
84
|
+
account_id: 456,
|
|
85
|
+
owner: true,
|
|
86
|
+
})).rejects.toThrow(ZapierValidationError);
|
|
87
|
+
});
|
|
88
|
+
it("should pass validation with all valid fields", async () => {
|
|
89
|
+
const sdk = createTestSdk();
|
|
90
|
+
const result = await sdk.findFirstAuthentication({
|
|
91
|
+
appKey: "slack",
|
|
92
|
+
search: "workspace",
|
|
93
|
+
title: "My Slack Workspace",
|
|
94
|
+
account_id: "acc_123",
|
|
95
|
+
owner: "me",
|
|
96
|
+
});
|
|
97
|
+
expect(result.data).toBeDefined();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe("business logic", () => {
|
|
101
|
+
it("should return first authentication when found", async () => {
|
|
102
|
+
const mockAuth = mockAuthentications[0];
|
|
103
|
+
mockListAuthentications.mockResolvedValue({
|
|
104
|
+
data: [mockAuth],
|
|
105
|
+
});
|
|
106
|
+
const sdk = createTestSdk();
|
|
107
|
+
const result = await sdk.findFirstAuthentication({
|
|
108
|
+
appKey: "slack",
|
|
109
|
+
});
|
|
110
|
+
expect(result.data).toEqual(mockAuth);
|
|
111
|
+
});
|
|
112
|
+
it("should return null when no authentications found", async () => {
|
|
113
|
+
mockListAuthentications.mockResolvedValue({
|
|
114
|
+
data: [],
|
|
115
|
+
});
|
|
116
|
+
const sdk = createTestSdk();
|
|
117
|
+
const result = await sdk.findFirstAuthentication({
|
|
118
|
+
appKey: "nonexistent",
|
|
119
|
+
});
|
|
120
|
+
expect(result.data).toBeNull();
|
|
121
|
+
});
|
|
122
|
+
it("should return first authentication when multiple found", async () => {
|
|
123
|
+
const mockAuth = mockAuthentications[0];
|
|
124
|
+
mockListAuthentications.mockResolvedValue({
|
|
125
|
+
data: [mockAuth, mockAuthentications[1]],
|
|
126
|
+
});
|
|
127
|
+
const sdk = createTestSdk();
|
|
128
|
+
const result = await sdk.findFirstAuthentication({
|
|
129
|
+
search: "Slack",
|
|
130
|
+
});
|
|
131
|
+
expect(result.data).toEqual(mockAuth);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe("options forwarding", () => {
|
|
135
|
+
it("should forward all options to listAuthentications", async () => {
|
|
136
|
+
const sdk = createTestSdk();
|
|
137
|
+
const options = {
|
|
138
|
+
appKey: "slack",
|
|
139
|
+
search: "workspace",
|
|
140
|
+
title: "My Slack Workspace",
|
|
141
|
+
account_id: "acc_123",
|
|
142
|
+
owner: "me",
|
|
143
|
+
};
|
|
144
|
+
await sdk.findFirstAuthentication(options);
|
|
145
|
+
expect(mockListAuthentications).toHaveBeenCalledWith({
|
|
146
|
+
...options,
|
|
147
|
+
maxItems: 1,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe("limit enforcement", () => {
|
|
152
|
+
it("should automatically set maxItems to 1", async () => {
|
|
153
|
+
const sdk = createTestSdk();
|
|
154
|
+
await sdk.findFirstAuthentication({
|
|
155
|
+
appKey: "slack",
|
|
156
|
+
});
|
|
157
|
+
expect(mockListAuthentications).toHaveBeenCalledWith({
|
|
158
|
+
appKey: "slack",
|
|
159
|
+
maxItems: 1,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
describe("context and metadata", () => {
|
|
164
|
+
it("should provide context with meta information", () => {
|
|
165
|
+
const sdk = createTestSdk();
|
|
166
|
+
const context = sdk.getContext();
|
|
167
|
+
expect(context.meta.findFirstAuthentication).toBeDefined();
|
|
168
|
+
expect(context.meta.findFirstAuthentication.inputSchema).toBeDefined();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
3
|
+
export declare const FindFirstAuthenticationSchema: z.ZodObject<{
|
|
4
|
+
appKey: z.ZodOptional<z.ZodString>;
|
|
5
|
+
search: z.ZodOptional<z.ZodString>;
|
|
6
|
+
title: z.ZodOptional<z.ZodString>;
|
|
7
|
+
account_id: z.ZodOptional<z.ZodString>;
|
|
8
|
+
owner: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
title?: string | undefined;
|
|
11
|
+
search?: string | undefined;
|
|
12
|
+
account_id?: string | undefined;
|
|
13
|
+
appKey?: string | undefined;
|
|
14
|
+
owner?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
title?: string | undefined;
|
|
17
|
+
search?: string | undefined;
|
|
18
|
+
account_id?: string | undefined;
|
|
19
|
+
appKey?: string | undefined;
|
|
20
|
+
owner?: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export type FindFirstAuthenticationOptions = z.infer<typeof FindFirstAuthenticationSchema>;
|
|
23
|
+
export type FindFirstAuthenticationError = import("../../types/errors").ZapierAuthenticationError | import("../../types/errors").ZapierApiError | import("../../types/errors").ZapierValidationError | import("../../types/errors").ZapierUnknownError;
|
|
24
|
+
export interface FindFirstAuthenticationSdkFunction {
|
|
25
|
+
findFirstAuthentication: (options?: FindFirstAuthenticationOptions) => Promise<{
|
|
26
|
+
data: AuthenticationItem | null;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/findFirstAuthentication/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;EAgBwB,CAAC;AAGnE,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAClD,OAAO,6BAA6B,CACrC,CAAC;AAGF,MAAM,MAAM,4BAA4B,GACpC,OAAO,oBAAoB,EAAE,yBAAyB,GACtD,OAAO,oBAAoB,EAAE,cAAc,GAC3C,OAAO,oBAAoB,EAAE,qBAAqB,GAClD,OAAO,oBAAoB,EAAE,kBAAkB,CAAC;AAGpD,MAAM,WAAW,kCAAkC;IACjD,uBAAuB,EAAE,CACvB,OAAO,CAAC,EAAE,8BAA8B,KACrC,OAAO,CAAC;QAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AppKeyPropertySchema } from "../../types/properties";
|
|
3
|
+
// Pure Zod schema - no resolver metadata!
|
|
4
|
+
export const FindFirstAuthenticationSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
appKey: AppKeyPropertySchema.optional().describe("App key of authentication to find (e.g., 'SlackCLIAPI')"),
|
|
7
|
+
search: z
|
|
8
|
+
.string()
|
|
9
|
+
.optional()
|
|
10
|
+
.describe("Search term to filter authentications by title"),
|
|
11
|
+
title: z
|
|
12
|
+
.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Filter authentications by exact title match"),
|
|
15
|
+
account_id: z.string().optional().describe("Filter by account ID"),
|
|
16
|
+
owner: z.string().optional().describe("Filter by owner"),
|
|
17
|
+
})
|
|
18
|
+
.describe("Find the first authentication matching the criteria");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
|
+
import type { AuthenticationItem } from "../../types/domain";
|
|
3
|
+
import { FindUniqueAuthenticationSchema, type FindUniqueAuthenticationOptions } from "./schemas";
|
|
4
|
+
import type { ListAuthenticationsPluginProvides } from "../listAuthentications";
|
|
5
|
+
export interface FindUniqueAuthenticationPluginProvides {
|
|
6
|
+
findUniqueAuthentication: (options?: FindUniqueAuthenticationOptions) => Promise<{
|
|
7
|
+
data: AuthenticationItem;
|
|
8
|
+
}>;
|
|
9
|
+
context: {
|
|
10
|
+
meta: {
|
|
11
|
+
findUniqueAuthentication: {
|
|
12
|
+
inputSchema: typeof FindUniqueAuthenticationSchema;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare const findUniqueAuthenticationPlugin: Plugin<GetSdkType<ListAuthenticationsPluginProvides>, // requires listAuthentications in SDK
|
|
18
|
+
{}, // no context requirements
|
|
19
|
+
FindUniqueAuthenticationPluginProvides>;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/findUniqueAuthentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACL,8BAA8B,EAC9B,KAAK,+BAA+B,EACrC,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAEhF,MAAM,WAAW,sCAAsC;IACrD,wBAAwB,EAAE,CACxB,OAAO,CAAC,EAAE,+BAA+B,KACtC,OAAO,CAAC;QAAE,IAAI,EAAE,kBAAkB,CAAA;KAAE,CAAC,CAAC;IAC3C,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,wBAAwB,EAAE;gBACxB,WAAW,EAAE,OAAO,8BAA8B,CAAC;aACpD,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,8BAA8B,EAAE,MAAM,CACjD,UAAU,CAAC,iCAAiC,CAAC,EAAE,sCAAsC;AACrF,EAAE,EAAE,0BAA0B;AAC9B,sCAAsC,CA0CvC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FindUniqueAuthenticationSchema, } from "./schemas";
|
|
2
|
+
import { ZapierResourceNotFoundError, ZapierValidationError, } from "../../types/errors";
|
|
3
|
+
import { createFunction } from "../../utils/function-utils";
|
|
4
|
+
export const findUniqueAuthenticationPlugin = ({ sdk }) => {
|
|
5
|
+
const findUniqueAuthentication = createFunction(async function findUniqueAuthentication(options = {}) {
|
|
6
|
+
// Use listAuthentications with maxItems 2 to check for uniqueness
|
|
7
|
+
const authsResponse = await sdk.listAuthentications({
|
|
8
|
+
...options,
|
|
9
|
+
maxItems: 2, // Get up to 2 to check for uniqueness
|
|
10
|
+
});
|
|
11
|
+
if (authsResponse.data.length === 0) {
|
|
12
|
+
throw new ZapierResourceNotFoundError("No authentication found matching the specified criteria", { resourceType: "Authentication" });
|
|
13
|
+
}
|
|
14
|
+
if (authsResponse.data.length > 1) {
|
|
15
|
+
throw new ZapierValidationError("Multiple authentications found matching the specified criteria. Expected exactly one.");
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
data: authsResponse.data[0],
|
|
19
|
+
};
|
|
20
|
+
}, FindUniqueAuthenticationSchema);
|
|
21
|
+
return {
|
|
22
|
+
findUniqueAuthentication,
|
|
23
|
+
context: {
|
|
24
|
+
meta: {
|
|
25
|
+
findUniqueAuthentication: {
|
|
26
|
+
inputSchema: FindUniqueAuthenticationSchema,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/findUniqueAuthentication/index.test.ts"],"names":[],"mappings":""}
|