@zapier/zapier-sdk 0.13.6 → 0.13.7

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +7 -2
  5. package/src/api/auth.ts +0 -28
  6. package/src/api/client.ts +0 -491
  7. package/src/api/debug.test.ts +0 -76
  8. package/src/api/debug.ts +0 -154
  9. package/src/api/index.ts +0 -90
  10. package/src/api/polling.test.ts +0 -405
  11. package/src/api/polling.ts +0 -253
  12. package/src/api/schemas.ts +0 -465
  13. package/src/api/types.ts +0 -152
  14. package/src/auth.ts +0 -72
  15. package/src/constants.ts +0 -16
  16. package/src/index.ts +0 -111
  17. package/src/plugins/api/index.ts +0 -43
  18. package/src/plugins/apps/index.ts +0 -203
  19. package/src/plugins/apps/schemas.ts +0 -64
  20. package/src/plugins/eventEmission/builders.ts +0 -115
  21. package/src/plugins/eventEmission/index.test.ts +0 -169
  22. package/src/plugins/eventEmission/index.ts +0 -294
  23. package/src/plugins/eventEmission/transport.test.ts +0 -214
  24. package/src/plugins/eventEmission/transport.ts +0 -135
  25. package/src/plugins/eventEmission/types.ts +0 -58
  26. package/src/plugins/eventEmission/utils.ts +0 -121
  27. package/src/plugins/fetch/index.ts +0 -83
  28. package/src/plugins/fetch/schemas.ts +0 -37
  29. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  30. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  31. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  32. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  33. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  34. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  35. package/src/plugins/getAction/index.test.ts +0 -239
  36. package/src/plugins/getAction/index.ts +0 -75
  37. package/src/plugins/getAction/schemas.ts +0 -41
  38. package/src/plugins/getApp/index.test.ts +0 -181
  39. package/src/plugins/getApp/index.ts +0 -60
  40. package/src/plugins/getApp/schemas.ts +0 -33
  41. package/src/plugins/getAuthentication/index.test.ts +0 -294
  42. package/src/plugins/getAuthentication/index.ts +0 -95
  43. package/src/plugins/getAuthentication/schemas.ts +0 -38
  44. package/src/plugins/getProfile/index.ts +0 -60
  45. package/src/plugins/getProfile/schemas.ts +0 -24
  46. package/src/plugins/listActions/index.test.ts +0 -526
  47. package/src/plugins/listActions/index.ts +0 -132
  48. package/src/plugins/listActions/schemas.ts +0 -55
  49. package/src/plugins/listApps/index.test.ts +0 -378
  50. package/src/plugins/listApps/index.ts +0 -159
  51. package/src/plugins/listApps/schemas.ts +0 -41
  52. package/src/plugins/listAuthentications/index.test.ts +0 -739
  53. package/src/plugins/listAuthentications/index.ts +0 -152
  54. package/src/plugins/listAuthentications/schemas.ts +0 -77
  55. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  56. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  57. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  58. package/src/plugins/listInputFields/index.test.ts +0 -439
  59. package/src/plugins/listInputFields/index.ts +0 -294
  60. package/src/plugins/listInputFields/schemas.ts +0 -68
  61. package/src/plugins/manifest/index.test.ts +0 -776
  62. package/src/plugins/manifest/index.ts +0 -461
  63. package/src/plugins/manifest/schemas.ts +0 -60
  64. package/src/plugins/registry/index.ts +0 -160
  65. package/src/plugins/request/index.test.ts +0 -333
  66. package/src/plugins/request/index.ts +0 -105
  67. package/src/plugins/request/schemas.ts +0 -69
  68. package/src/plugins/runAction/index.test.ts +0 -388
  69. package/src/plugins/runAction/index.ts +0 -215
  70. package/src/plugins/runAction/schemas.ts +0 -60
  71. package/src/resolvers/actionKey.ts +0 -37
  72. package/src/resolvers/actionType.ts +0 -34
  73. package/src/resolvers/appKey.ts +0 -7
  74. package/src/resolvers/authenticationId.ts +0 -54
  75. package/src/resolvers/index.ts +0 -11
  76. package/src/resolvers/inputFieldKey.ts +0 -70
  77. package/src/resolvers/inputs.ts +0 -69
  78. package/src/schemas/Action.ts +0 -52
  79. package/src/schemas/App.ts +0 -45
  80. package/src/schemas/Auth.ts +0 -59
  81. package/src/schemas/Field.ts +0 -169
  82. package/src/schemas/Run.ts +0 -40
  83. package/src/schemas/UserProfile.ts +0 -60
  84. package/src/sdk.test.ts +0 -212
  85. package/src/sdk.ts +0 -178
  86. package/src/types/domain.test.ts +0 -50
  87. package/src/types/domain.ts +0 -66
  88. package/src/types/errors.ts +0 -278
  89. package/src/types/events.ts +0 -43
  90. package/src/types/functions.ts +0 -28
  91. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  92. package/src/types/plugin.ts +0 -125
  93. package/src/types/properties.ts +0 -80
  94. package/src/types/sdk.ts +0 -111
  95. package/src/types/telemetry-events.ts +0 -85
  96. package/src/utils/array-utils.test.ts +0 -131
  97. package/src/utils/array-utils.ts +0 -41
  98. package/src/utils/domain-utils.test.ts +0 -433
  99. package/src/utils/domain-utils.ts +0 -267
  100. package/src/utils/file-utils.test.ts +0 -73
  101. package/src/utils/file-utils.ts +0 -94
  102. package/src/utils/function-utils.test.ts +0 -141
  103. package/src/utils/function-utils.ts +0 -245
  104. package/src/utils/pagination-utils.test.ts +0 -620
  105. package/src/utils/pagination-utils.ts +0 -242
  106. package/src/utils/schema-utils.ts +0 -207
  107. package/src/utils/string-utils.test.ts +0 -45
  108. package/src/utils/string-utils.ts +0 -54
  109. package/src/utils/validation.test.ts +0 -51
  110. package/src/utils/validation.ts +0 -44
  111. package/tsconfig.build.json +0 -18
  112. package/tsconfig.json +0 -20
  113. package/tsconfig.tsbuildinfo +0 -1
  114. package/tsup.config.ts +0 -23
package/src/api/types.ts DELETED
@@ -1,152 +0,0 @@
1
- /**
2
- * API Client Type Definitions
3
- *
4
- * This module contains all type definitions related to the Zapier API client,
5
- * including configuration options, client interfaces, request/response types,
6
- * and API response models.
7
- *
8
- * API response model types are inferred from Zod schemas defined in api/schemas.ts
9
- * to ensure a single source of truth and eliminate duplication.
10
- */
11
-
12
- import type { SdkEvent } from "../types/events";
13
- import type { z } from "zod";
14
- import type {
15
- NeedChoicesSchema,
16
- NeedSchema,
17
- ActionLinksSchema,
18
- ActionPermissionsSchema,
19
- ActionSchema,
20
- ChoiceSchema,
21
- FieldSchema,
22
- ActionExecutionResultSchema,
23
- ActionFieldChoiceSchema,
24
- ActionFieldSchema,
25
- AuthenticationSchema,
26
- AuthenticationsResponseSchema,
27
- UserProfileSchema,
28
- AppSchema,
29
- NeedsRequestSchema,
30
- NeedsResponseSchema,
31
- ImplementationSchema,
32
- ImplementationsResponseSchema,
33
- ImplementationMetaSchema,
34
- ImplementationsMetaResponseSchema,
35
- ServiceSchema,
36
- ServicesResponseSchema,
37
- NeedChoicesRequestSchema,
38
- NeedChoicesResponseSchema,
39
- NeedChoicesResponseMetaSchema,
40
- NeedChoicesResponseLinksSchema,
41
- } from "./schemas";
42
-
43
- // ============================================================================
44
- // API Client Infrastructure Types
45
- // ============================================================================
46
-
47
- export interface ApiClientOptions {
48
- baseUrl: string;
49
- token?: string;
50
- getToken?: () => Promise<string | undefined>;
51
- debug?: boolean;
52
- fetch?: typeof globalThis.fetch;
53
- onEvent?: (event: SdkEvent) => void;
54
- }
55
-
56
- export interface ApiClient {
57
- get: <T = unknown>(path: string, options?: RequestOptions) => Promise<T>;
58
- post: <T = unknown>(
59
- path: string,
60
- data?: unknown,
61
- options?: RequestOptions,
62
- ) => Promise<T>;
63
- put: <T = unknown>(
64
- path: string,
65
- data?: unknown,
66
- options?: RequestOptions,
67
- ) => Promise<T>;
68
- delete: <T = unknown>(path: string, options?: RequestOptions) => Promise<T>;
69
- poll: <T = unknown>(path: string, options?: PollOptions) => Promise<T>;
70
- fetch: (
71
- path: string,
72
- init?: RequestInit & {
73
- searchParams?: Record<string, string>;
74
- authRequired?: boolean;
75
- },
76
- ) => Promise<Response>;
77
- }
78
-
79
- export interface RequestOptions {
80
- headers?: Record<string, string>;
81
- searchParams?: Record<string, string>;
82
- authRequired?: boolean;
83
- customErrorHandler?: (errorInfo: {
84
- status: number;
85
- statusText: string;
86
- data: unknown;
87
- }) => Error | undefined;
88
- }
89
-
90
- export interface PollOptions extends RequestOptions {
91
- initialDelay?: number;
92
- timeoutMs?: number;
93
- successStatus?: number;
94
- pendingStatus?: number;
95
- resultExtractor?: (response: unknown) => unknown;
96
- }
97
-
98
- export interface DebugLogger {
99
- (message: string, data?: unknown): void;
100
- }
101
-
102
- // ============================================================================
103
- // API Response Models (inferred from Zod schemas)
104
- // ============================================================================
105
-
106
- // Basic building blocks
107
- export type NeedChoices = z.infer<typeof NeedChoicesSchema>;
108
- export type Need = z.infer<typeof NeedSchema>;
109
- export type ActionLinks = z.infer<typeof ActionLinksSchema>;
110
- export type ActionPermissions = z.infer<typeof ActionPermissionsSchema>;
111
- export type Action = z.infer<typeof ActionSchema>;
112
- export type Choice = z.infer<typeof ChoiceSchema>;
113
- export type Field = z.infer<typeof FieldSchema>;
114
- export type ActionExecutionResult = z.infer<typeof ActionExecutionResultSchema>;
115
- export type ActionFieldChoice = z.infer<typeof ActionFieldChoiceSchema>;
116
- export type ActionField = z.infer<typeof ActionFieldSchema>;
117
-
118
- // Main API entities
119
- export type Authentication = z.infer<typeof AuthenticationSchema>;
120
- export type AuthenticationsResponse = z.infer<
121
- typeof AuthenticationsResponseSchema
122
- >;
123
- export type UserProfile = z.infer<typeof UserProfileSchema>;
124
- export type App = z.infer<typeof AppSchema>;
125
- export type Service = z.infer<typeof ServiceSchema>;
126
- export type ServicesResponse = z.infer<typeof ServicesResponseSchema>;
127
-
128
- // Request/Response types
129
- export type NeedsRequest = z.infer<typeof NeedsRequestSchema>;
130
- export type NeedsResponse = z.infer<typeof NeedsResponseSchema>;
131
-
132
- // Implementation types
133
- export type Implementation = z.infer<typeof ImplementationSchema>;
134
- export type ImplementationsResponse = z.infer<
135
- typeof ImplementationsResponseSchema
136
- >;
137
-
138
- // Implementation Meta types (lightweight)
139
- export type ImplementationMeta = z.infer<typeof ImplementationMetaSchema>;
140
- export type ImplementationsMetaResponse = z.infer<
141
- typeof ImplementationsMetaResponseSchema
142
- >;
143
-
144
- // Need Choices types (for listInputFieldChoices functionality)
145
- export type NeedChoicesRequest = z.infer<typeof NeedChoicesRequestSchema>;
146
- export type NeedChoicesResponse = z.infer<typeof NeedChoicesResponseSchema>;
147
- export type NeedChoicesResponseMeta = z.infer<
148
- typeof NeedChoicesResponseMetaSchema
149
- >;
150
- export type NeedChoicesResponseLinks = z.infer<
151
- typeof NeedChoicesResponseLinksSchema
152
- >;
package/src/auth.ts DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * SDK Authentication Utilities
3
- *
4
- * This module provides SDK-level authentication utilities focused
5
- * solely on token acquisition. CLI-specific functionality like login/logout
6
- * is handled by the @zapier/zapier-sdk-cli-login package.
7
- */
8
-
9
- // Import event types from common location
10
- import type { EventCallback } from "./types/events";
11
-
12
- // Re-export for backward compatibility
13
- export type {
14
- SdkEvent,
15
- AuthEvent,
16
- ApiEvent,
17
- LoadingEvent,
18
- EventCallback,
19
- } from "./types/events";
20
-
21
- // Options interfaces for auth functions
22
- export interface AuthOptions {
23
- onEvent?: EventCallback;
24
- fetch?: typeof globalThis.fetch;
25
- }
26
-
27
- /**
28
- * Gets the ZAPIER_TOKEN from environment variables.
29
- * Returns undefined if not set.
30
- */
31
- export function getTokenFromEnv(): string | undefined {
32
- return process.env.ZAPIER_TOKEN;
33
- }
34
-
35
- /**
36
- * Attempts to get a token by optionally importing from CLI login package.
37
- * This provides a graceful fallback when the CLI login package is not available.
38
- *
39
- * Returns undefined if no valid token is found or CLI package is not available.
40
- */
41
- export async function getTokenFromCliLogin(
42
- options: AuthOptions = {},
43
- ): Promise<string | undefined> {
44
- try {
45
- // Dynamically import the CLI login package if available
46
- const { getToken } = await import("@zapier/zapier-sdk-cli-login");
47
- return await getToken(options);
48
- } catch {
49
- // CLI login package is not available, return undefined
50
- return undefined;
51
- }
52
- }
53
-
54
- /**
55
- * Attempts to get a token with the following precedence:
56
- * 1. ZAPIER_TOKEN environment variable
57
- * 2. CLI login package (if available) with auto-refresh
58
- *
59
- * Returns undefined if no valid token is found.
60
- */
61
- export async function getTokenFromEnvOrConfig(
62
- options: AuthOptions = {},
63
- ): Promise<string | undefined> {
64
- // First priority: environment variable
65
- const envToken = getTokenFromEnv();
66
- if (envToken) {
67
- return envToken;
68
- }
69
-
70
- // Second priority: CLI login package (if available)
71
- return getTokenFromCliLogin(options);
72
- }
package/src/constants.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * SDK Constants
3
- *
4
- * This module contains shared constants used throughout the SDK.
5
- */
6
-
7
- /**
8
- * Maximum number of items that can be requested per page across all paginated functions
9
- */
10
- export const MAX_PAGE_LIMIT = 10000;
11
-
12
- /**
13
- * Default telemetry endpoint for the Tracking API
14
- */
15
- export const TRACKING_API_ENDPOINT =
16
- "https://zapier.com/api/v4/tracking/event/";
package/src/index.ts DELETED
@@ -1,111 +0,0 @@
1
- // Export everything from types and plugins
2
- export * from "./types/domain";
3
- export * from "./types/functions";
4
- export * from "./types/properties";
5
- export * from "./types/errors";
6
- export * from "./plugins/apps";
7
- export * from "./plugins/fetch";
8
- export * from "./plugins/listApps";
9
- export * from "./plugins/listActions";
10
- export * from "./plugins/listInputFields";
11
- export * from "./plugins/listAuthentications";
12
- export * from "./plugins/getApp";
13
- export * from "./plugins/getAction";
14
- export * from "./plugins/getAuthentication";
15
- export * from "./plugins/findFirstAuthentication";
16
- export * from "./plugins/findUniqueAuthentication";
17
- export * from "./plugins/runAction";
18
- export * from "./plugins/request";
19
- export * from "./plugins/manifest";
20
- export * from "./plugins/getProfile";
21
- export * from "./plugins/api";
22
-
23
- // Export API types directly (no longer re-exported from domain)
24
- export type {
25
- Action,
26
- App,
27
- Need,
28
- Field,
29
- Choice,
30
- ActionExecutionResult,
31
- ActionField,
32
- ActionFieldChoice,
33
- NeedsRequest,
34
- NeedsResponse,
35
- Authentication,
36
- AuthenticationsResponse,
37
- UserProfile,
38
- } from "./api/types";
39
-
40
- // Export schema utilities for CLI
41
- export { isPositional, PositionalMetadata } from "./utils/schema-utils";
42
- export { createFunction } from "./utils/function-utils";
43
- export type { FormattedItem, FormatMetadata } from "./utils/schema-utils";
44
-
45
- // Export string utilities
46
- export { toSnakeCase, toTitleCase } from "./utils/string-utils";
47
-
48
- // Export resolver utilities for CLI
49
- export * from "./resolvers";
50
-
51
- // Export auth utilities for CLI use
52
- export * from "./auth";
53
-
54
- // All functions now available through the plugin system via createZapierSdk()
55
- // Export plugin schemas for external use
56
- export {
57
- RelayRequestSchema,
58
- RelayFetchSchema,
59
- } from "./plugins/request/schemas";
60
-
61
- // Export the main combined SDK and new flexible SDK creator
62
- export {
63
- createZapierSdk,
64
- createZapierSdkWithoutRegistry,
65
- createSdk,
66
- ZapierSdkOptions,
67
- } from "./sdk";
68
-
69
- // Export SDK types from types (not sdk.ts to avoid circular imports)
70
- export type { FunctionRegistryEntry } from "./types/sdk";
71
-
72
- // Export plugin utilities and SDK types
73
- export type {
74
- Plugin,
75
- PluginProvides,
76
- PluginDependencies,
77
- PluginOptions,
78
- GetSdkType,
79
- GetContextType,
80
- Sdk,
81
- } from "./types/plugin";
82
-
83
- // Export registry plugin for manual use
84
- export { registryPlugin } from "./plugins/registry";
85
-
86
- // Export ZapierSdk from sdk.ts (it's now ReturnType<typeof createZapierSdk>)
87
- export type { ZapierSdk } from "./types/sdk";
88
-
89
- // Export event types and utilities for external packages
90
- export type { BaseEvent } from "./types/telemetry-events";
91
- export type {
92
- EventEmissionContext,
93
- EventContext,
94
- ApplicationLifecycleEventData,
95
- EnhancedErrorEventData,
96
- } from "./plugins/eventEmission";
97
- export {
98
- generateEventId,
99
- getCurrentTimestamp,
100
- getReleaseId,
101
- getOsInfo,
102
- getPlatformVersions,
103
- isCi,
104
- getCiPlatform,
105
- getMemoryUsage,
106
- getCpuTime,
107
- buildApplicationLifecycleEvent,
108
- buildErrorEventWithContext,
109
- buildErrorEvent,
110
- createBaseEvent,
111
- } from "./plugins/eventEmission";
@@ -1,43 +0,0 @@
1
- import { createZapierApi } from "../../api";
2
- import type { ApiClient } from "../../api/types";
3
- import type { BaseSdkOptions } from "../../types/sdk";
4
- import type { Plugin } from "../../types/plugin";
5
-
6
- export interface ApiPluginOptions extends BaseSdkOptions {}
7
-
8
- // API plugin only provides context, no SDK methods
9
- export interface ApiPluginProvides {
10
- context: {
11
- api: ApiClient;
12
- };
13
- }
14
-
15
- // API plugin requires no context and provides api in context
16
- export const apiPlugin: Plugin<{}, {}, ApiPluginProvides> = (params) => {
17
- // Extract all options - everything passed to the plugin
18
- const {
19
- fetch: customFetch = globalThis.fetch,
20
- baseUrl = "https://zapier.com",
21
- token,
22
- getToken,
23
- onEvent,
24
- debug = false,
25
- } = params.context.options;
26
-
27
- // Create the API client - it will handle token resolution internally
28
- const api = createZapierApi({
29
- baseUrl,
30
- token,
31
- getToken,
32
- debug,
33
- fetch: customFetch,
34
- onEvent,
35
- });
36
-
37
- // Return flat structure with context only
38
- return {
39
- context: {
40
- api, // Provide API client in context for other plugins to use
41
- },
42
- };
43
- };
@@ -1,203 +0,0 @@
1
- import type {
2
- ActionExecutionOptions,
3
- ActionProxy,
4
- AppFactoryInput,
5
- } from "./schemas";
6
- import { ActionExecutionInputSchema, AppFactoryInputSchema } from "./schemas";
7
- import { ZapierValidationError } from "../../types/errors";
8
- import type { Plugin, GetSdkType } from "../../types/plugin";
9
- import type { FetchPluginProvides } from "../fetch/index";
10
- import type { RunActionPluginProvides } from "../runAction/index";
11
- import { ActionResultItemSchema } from "../../schemas/Run";
12
-
13
- export interface AppsPluginProvides {
14
- apps: ActionProxy;
15
- }
16
-
17
- interface AppsPluginOptions {
18
- sdk: GetSdkType<FetchPluginProvides & RunActionPluginProvides>;
19
- }
20
-
21
- function createActionFunction(
22
- appKey: string,
23
- actionType: string,
24
- actionKey: string,
25
- options: AppsPluginOptions,
26
- pinnedAuthId?: number,
27
- ) {
28
- return (actionOptions: ActionExecutionOptions = {}): any => {
29
- const { sdk } = options;
30
- const { inputs, authenticationId: providedAuthenticationId } =
31
- actionOptions;
32
-
33
- // Use pinned auth ID first, then provided auth ID
34
- const authenticationId = pinnedAuthId || providedAuthenticationId;
35
-
36
- if (!authenticationId) {
37
- throw new ZapierValidationError(
38
- `Authentication ID is required. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }) or provide authenticationId in the action call.`,
39
- );
40
- }
41
-
42
- // Call sdk.runAction with the resolved parameters
43
- return sdk.runAction({
44
- appKey,
45
- actionType: actionType as any,
46
- actionKey,
47
- inputs,
48
- authenticationId,
49
- });
50
- };
51
- }
52
-
53
- function createActionTypeProxy(
54
- appKey: string,
55
- actionType: string,
56
- options: AppsPluginOptions,
57
- pinnedAuthId?: number,
58
- ) {
59
- // Special handling for "fetch" action type
60
- if (actionType === "fetch") {
61
- return async (
62
- url: string | URL,
63
- init?: RequestInit & {
64
- authenticationId?: number;
65
- callbackUrl?: string;
66
- authenticationTemplate?: string;
67
- },
68
- ) => {
69
- const { sdk } = options;
70
-
71
- // Use pinned auth ID first, then provided auth ID
72
- const authenticationId = pinnedAuthId || init?.authenticationId;
73
-
74
- if (!authenticationId) {
75
- throw new ZapierValidationError(
76
- `Authentication ID is required for fetch. Either use the factory pattern: sdk.apps.${appKey}({ authenticationId }).fetch(...) or provide authenticationId in the fetch call.`,
77
- );
78
- }
79
-
80
- // Call sdk.fetch with the resolved authenticationId
81
- return sdk.fetch(url, {
82
- ...init,
83
- authenticationId,
84
- });
85
- };
86
- }
87
-
88
- return new Proxy(
89
- {},
90
- {
91
- get(_, actionKey) {
92
- if (typeof actionKey === "string") {
93
- return createActionFunction(
94
- appKey,
95
- actionType,
96
- actionKey,
97
- options,
98
- pinnedAuthId,
99
- );
100
- }
101
- return undefined;
102
- },
103
- },
104
- );
105
- }
106
-
107
- function createPinnedAppProxy(
108
- appKey: string,
109
- options: AppsPluginOptions,
110
- pinnedAuthId: number,
111
- ) {
112
- return new Proxy(
113
- {},
114
- {
115
- get(_, actionType) {
116
- if (typeof actionType === "string") {
117
- return createActionTypeProxy(
118
- appKey,
119
- actionType,
120
- options,
121
- pinnedAuthId,
122
- );
123
- }
124
- return undefined;
125
- },
126
- },
127
- );
128
- }
129
-
130
- function createAppProxy(appKey: string, options: AppsPluginOptions) {
131
- // Create the factory function that returns a pinned version
132
- const appFactory = (factoryOptions: AppFactoryInput) => {
133
- return createPinnedAppProxy(
134
- appKey,
135
- options,
136
- factoryOptions.authenticationId,
137
- );
138
- };
139
-
140
- // Add properties for direct usage (backward compatibility)
141
- return new Proxy(appFactory, {
142
- get(_, actionType) {
143
- if (typeof actionType === "string") {
144
- return createActionTypeProxy(appKey, actionType, options);
145
- }
146
- return undefined;
147
- },
148
- });
149
- }
150
-
151
- function createAppsProxy(options: AppsPluginOptions): ActionProxy {
152
- // Create a proxy object that intercepts property access
153
- const appsProxy = new Proxy({} as ActionProxy, {
154
- get(_, prop) {
155
- if (typeof prop === "string") {
156
- // First level: App names (e.g., 'slack')
157
- return createAppProxy(prop, options);
158
- }
159
- return undefined;
160
- },
161
- });
162
-
163
- return appsProxy;
164
- }
165
-
166
- // Direct plugin function - takes options + sdk + context in one object
167
- export const appsPlugin: Plugin<
168
- GetSdkType<FetchPluginProvides & RunActionPluginProvides>, // requires fetch + runAction in SDK
169
- {}, // no context requirements
170
- AppsPluginProvides
171
- > = ({ sdk }) => {
172
- // Return flat structure - apps goes directly to SDK
173
- return {
174
- apps: createAppsProxy({ sdk }),
175
- context: {
176
- meta: {
177
- "apps.{appKey}": {
178
- categories: ["app"],
179
- packages: ["sdk"],
180
- type: "function",
181
- inputSchema: AppFactoryInputSchema,
182
- returnType: "AppProxy",
183
- },
184
- "apps.{appKey}.{actionType}.{actionKey}": {
185
- categories: ["app"],
186
- packages: ["sdk"],
187
- type: "list",
188
- inputSchema: ActionExecutionInputSchema,
189
- itemType: "ActionResult",
190
- outputSchema: ActionResultItemSchema,
191
- },
192
- },
193
- },
194
- };
195
- };
196
-
197
- // Export types for use in generated code
198
- export type { ActionExecutionOptions } from "./schemas";
199
- export type { ActionExecutionResult } from "../../api/types";
200
-
201
- // Interface for generated apps - will be augmented by generated .d.ts files
202
- // This interface will contain only the specifically typed apps
203
- export interface ZapierSdkApps {}
@@ -1,64 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export const ActionExecutionInputSchema = z
4
- .object({
5
- inputs: z.record(z.unknown()).optional(),
6
- authenticationId: z.number().optional(),
7
- })
8
- .describe(
9
- "Execute an action with the given inputs for the bound app, as an alternative to runAction",
10
- );
11
-
12
- // Apps plugin-specific execution options
13
- export type ActionExecutionOptions = z.infer<typeof ActionExecutionInputSchema>;
14
-
15
- export const AppFactoryInputSchema = z
16
- .object({
17
- authenticationId: z.number(),
18
- })
19
- .describe("Bind an authentication ID to an app");
20
-
21
- export type AppFactoryInput = z.infer<typeof AppFactoryInputSchema>;
22
-
23
- // Base action type proxy for regular actions
24
- interface BaseActionTypeProxy {
25
- [action: string]: (options?: ActionExecutionOptions) => Promise<{
26
- data: any[];
27
- nextCursor?: string;
28
- }> &
29
- AsyncIterable<{ data: any[]; nextCursor?: string }> & {
30
- items(): AsyncIterable<any>;
31
- };
32
- }
33
-
34
- // Special fetch function type
35
- interface FetchActionType {
36
- fetch: (
37
- url: string | URL,
38
- init?: RequestInit & {
39
- authenticationId?: number;
40
- callbackUrl?: string;
41
- authenticationTemplate?: string;
42
- },
43
- ) => Promise<Response>;
44
- }
45
-
46
- // Combined action type proxy
47
- type ActionTypeProxy = BaseActionTypeProxy & Partial<FetchActionType>;
48
-
49
- interface AppProxy {
50
- [type: string]: ActionTypeProxy;
51
- }
52
-
53
- interface AppFactory {
54
- (options: AppFactoryInput): AppProxy;
55
- }
56
-
57
- // An app can be both a factory function and have properties for direct access
58
- type AppProxyWithFactory = AppFactory & AppProxy;
59
-
60
- export interface ActionProxy {
61
- [app: string]: AppProxyWithFactory;
62
- }
63
-
64
- // Note: AppsPluginSdkExtension removed - now using AppsPluginProvides in index.ts