@zapier/zapier-sdk-cli 0.42.1 → 0.43.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/dist/login.d.mts CHANGED
@@ -1 +1,144 @@
1
- export * from '@zapier/zapier-sdk-cli-login';
1
+ import Conf from 'conf';
2
+
3
+ /**
4
+ * Default filesystem + OS keychain cache adapter for the SDK.
5
+ *
6
+ * Conforms to the generic ZapierCache interface that the SDK defines.
7
+ * Secrets go to the OS keychain via cross-keychain; non-secret values
8
+ * and the identity metadata (expires_at, secret flag) go to the
9
+ * existing zapier-sdk-cli Conf file. A proper-lockfile lock wraps the
10
+ * exchange/persist critical section so N concurrent CLI invocations
11
+ * collapse to a single network exchange.
12
+ *
13
+ * The SDK treats this (like any ZapierCache) as a cache — values may
14
+ * disappear, and the caller must always be able to recreate them.
15
+ */
16
+ declare function createCache(): {
17
+ get(key: string): Promise<{
18
+ value: string;
19
+ expiresAt?: number;
20
+ } | undefined>;
21
+ set(key: string, value: string, options?: {
22
+ secret?: boolean;
23
+ ttl?: number;
24
+ }): Promise<void>;
25
+ delete(key: string): Promise<void>;
26
+ withLock<T>(key: string, fn: () => Promise<T>): Promise<T>;
27
+ };
28
+
29
+ /**
30
+ * Zapier SDK CLI Login Package
31
+ *
32
+ * Handles login, logout, token cache and refresh for Zapier SDK CLI.
33
+ * Provides getToken function that can be optionally imported by zapier-sdk.
34
+ */
35
+
36
+ /**
37
+ * Authentication error for token refresh failures.
38
+ * This is a standalone clone of ZapierAuthenticationError from the SDK.
39
+ * We can't import from SDK because cli-login must remain a standalone package
40
+ * with no SDK dependencies. The SDK recognizes this error by name.
41
+ */
42
+ declare class ZapierAuthenticationError extends Error {
43
+ constructor(message: string);
44
+ }
45
+ interface PkceCredentials {
46
+ type: "pkce";
47
+ clientId: string;
48
+ baseUrl?: string;
49
+ scope?: string;
50
+ }
51
+ interface AuthOptions {
52
+ onEvent?: (event: {
53
+ type: string;
54
+ payload: Record<string, unknown>;
55
+ timestamp: number;
56
+ }) => void;
57
+ fetch?: typeof globalThis.fetch;
58
+ /** Credentials object from SDK. Contains clientId and resolved auth baseUrl. */
59
+ credentials?: PkceCredentials;
60
+ /** Enable debug logging for fetch requests and config operations. */
61
+ debug?: boolean;
62
+ }
63
+ interface LoginData {
64
+ access_token: string;
65
+ refresh_token: string;
66
+ expires_in: number;
67
+ }
68
+ declare const AUTH_MODE_HEADER = "X-Auth";
69
+ /**
70
+ * Gets the OAuth token endpoint URL.
71
+ * baseUrl should be the auth base URL (e.g., https://zapier.com), already resolved by SDK.
72
+ */
73
+ declare function getAuthTokenUrl(options?: {
74
+ baseUrl?: string;
75
+ }): string;
76
+ /**
77
+ * Gets the OAuth authorization endpoint URL.
78
+ * baseUrl should be the auth base URL (e.g., https://zapier.com), already resolved by SDK.
79
+ */
80
+ declare function getAuthAuthorizeUrl(options?: {
81
+ baseUrl?: string;
82
+ }): string;
83
+ /**
84
+ * Configuration needed for PKCE login flow.
85
+ */
86
+ interface PkceLoginConfig {
87
+ clientId: string;
88
+ tokenUrl: string;
89
+ authorizeUrl: string;
90
+ }
91
+ /**
92
+ * Gets all configuration needed for the PKCE login flow.
93
+ * Credentials should have baseUrl already resolved by SDK.
94
+ */
95
+ declare function getPkceLoginConfig(options?: {
96
+ credentials?: PkceCredentials;
97
+ }): PkceLoginConfig;
98
+ type LoginStorageMode = "keychain" | "config";
99
+ declare function getConfig(): Conf;
100
+ /**
101
+ * Drops the cached Conf instance so the next getConfig() call re-initializes
102
+ * from disk (including re-running the pre-existing file detection).
103
+ */
104
+ declare function unloadConfig(): void;
105
+ declare function updateLogin(loginData: LoginData, options?: {
106
+ storage?: LoginStorageMode;
107
+ debug?: boolean;
108
+ }): Promise<void>;
109
+ /**
110
+ * Main function exported for zapier-sdk to optionally use.
111
+ * Returns the stored token from CLI configuration (with auto-refresh).
112
+ *
113
+ * Note: Environment variable handling (ZAPIER_CREDENTIALS, ZAPIER_TOKEN)
114
+ * is done by the SDK before calling this function.
115
+ *
116
+ * Returns undefined if no valid token is found.
117
+ */
118
+ declare function getToken(options?: AuthOptions): Promise<string | undefined>;
119
+ /**
120
+ * Gets the logged-in user information from JWT token.
121
+ * Automatically refreshes token if expired.
122
+ */
123
+ declare function getLoggedInUser(options?: AuthOptions): Promise<{
124
+ accountId: number;
125
+ customUserId: number;
126
+ email: string;
127
+ }>;
128
+ /**
129
+ * Checks config to determine current cache mode without reading keychain.
130
+ * Credential keys in config are ground truth — if login_jwt exists, we're in
131
+ * config mode regardless of the marker. The marker only matters when no
132
+ * credential keys are present (e.g. after logout or when using keychain).
133
+ */
134
+ declare function getLoginStorageMode(): LoginStorageMode;
135
+ /**
136
+ * Clears stored login information.
137
+ */
138
+ declare function logout(options?: Pick<AuthOptions, "onEvent">): Promise<void>;
139
+ /**
140
+ * Gets the path to the configuration file.
141
+ */
142
+ declare function getConfigPath(): string;
143
+
144
+ export { AUTH_MODE_HEADER, type AuthOptions, type LoginData, type LoginStorageMode, type PkceCredentials, type PkceLoginConfig, ZapierAuthenticationError, createCache, getAuthAuthorizeUrl, getAuthTokenUrl, getConfig, getConfigPath, getLoggedInUser, getLoginStorageMode, getPkceLoginConfig, getToken, logout, unloadConfig, updateLogin };
package/dist/login.d.ts CHANGED
@@ -1 +1,144 @@
1
- export * from '@zapier/zapier-sdk-cli-login';
1
+ import Conf from 'conf';
2
+
3
+ /**
4
+ * Default filesystem + OS keychain cache adapter for the SDK.
5
+ *
6
+ * Conforms to the generic ZapierCache interface that the SDK defines.
7
+ * Secrets go to the OS keychain via cross-keychain; non-secret values
8
+ * and the identity metadata (expires_at, secret flag) go to the
9
+ * existing zapier-sdk-cli Conf file. A proper-lockfile lock wraps the
10
+ * exchange/persist critical section so N concurrent CLI invocations
11
+ * collapse to a single network exchange.
12
+ *
13
+ * The SDK treats this (like any ZapierCache) as a cache — values may
14
+ * disappear, and the caller must always be able to recreate them.
15
+ */
16
+ declare function createCache(): {
17
+ get(key: string): Promise<{
18
+ value: string;
19
+ expiresAt?: number;
20
+ } | undefined>;
21
+ set(key: string, value: string, options?: {
22
+ secret?: boolean;
23
+ ttl?: number;
24
+ }): Promise<void>;
25
+ delete(key: string): Promise<void>;
26
+ withLock<T>(key: string, fn: () => Promise<T>): Promise<T>;
27
+ };
28
+
29
+ /**
30
+ * Zapier SDK CLI Login Package
31
+ *
32
+ * Handles login, logout, token cache and refresh for Zapier SDK CLI.
33
+ * Provides getToken function that can be optionally imported by zapier-sdk.
34
+ */
35
+
36
+ /**
37
+ * Authentication error for token refresh failures.
38
+ * This is a standalone clone of ZapierAuthenticationError from the SDK.
39
+ * We can't import from SDK because cli-login must remain a standalone package
40
+ * with no SDK dependencies. The SDK recognizes this error by name.
41
+ */
42
+ declare class ZapierAuthenticationError extends Error {
43
+ constructor(message: string);
44
+ }
45
+ interface PkceCredentials {
46
+ type: "pkce";
47
+ clientId: string;
48
+ baseUrl?: string;
49
+ scope?: string;
50
+ }
51
+ interface AuthOptions {
52
+ onEvent?: (event: {
53
+ type: string;
54
+ payload: Record<string, unknown>;
55
+ timestamp: number;
56
+ }) => void;
57
+ fetch?: typeof globalThis.fetch;
58
+ /** Credentials object from SDK. Contains clientId and resolved auth baseUrl. */
59
+ credentials?: PkceCredentials;
60
+ /** Enable debug logging for fetch requests and config operations. */
61
+ debug?: boolean;
62
+ }
63
+ interface LoginData {
64
+ access_token: string;
65
+ refresh_token: string;
66
+ expires_in: number;
67
+ }
68
+ declare const AUTH_MODE_HEADER = "X-Auth";
69
+ /**
70
+ * Gets the OAuth token endpoint URL.
71
+ * baseUrl should be the auth base URL (e.g., https://zapier.com), already resolved by SDK.
72
+ */
73
+ declare function getAuthTokenUrl(options?: {
74
+ baseUrl?: string;
75
+ }): string;
76
+ /**
77
+ * Gets the OAuth authorization endpoint URL.
78
+ * baseUrl should be the auth base URL (e.g., https://zapier.com), already resolved by SDK.
79
+ */
80
+ declare function getAuthAuthorizeUrl(options?: {
81
+ baseUrl?: string;
82
+ }): string;
83
+ /**
84
+ * Configuration needed for PKCE login flow.
85
+ */
86
+ interface PkceLoginConfig {
87
+ clientId: string;
88
+ tokenUrl: string;
89
+ authorizeUrl: string;
90
+ }
91
+ /**
92
+ * Gets all configuration needed for the PKCE login flow.
93
+ * Credentials should have baseUrl already resolved by SDK.
94
+ */
95
+ declare function getPkceLoginConfig(options?: {
96
+ credentials?: PkceCredentials;
97
+ }): PkceLoginConfig;
98
+ type LoginStorageMode = "keychain" | "config";
99
+ declare function getConfig(): Conf;
100
+ /**
101
+ * Drops the cached Conf instance so the next getConfig() call re-initializes
102
+ * from disk (including re-running the pre-existing file detection).
103
+ */
104
+ declare function unloadConfig(): void;
105
+ declare function updateLogin(loginData: LoginData, options?: {
106
+ storage?: LoginStorageMode;
107
+ debug?: boolean;
108
+ }): Promise<void>;
109
+ /**
110
+ * Main function exported for zapier-sdk to optionally use.
111
+ * Returns the stored token from CLI configuration (with auto-refresh).
112
+ *
113
+ * Note: Environment variable handling (ZAPIER_CREDENTIALS, ZAPIER_TOKEN)
114
+ * is done by the SDK before calling this function.
115
+ *
116
+ * Returns undefined if no valid token is found.
117
+ */
118
+ declare function getToken(options?: AuthOptions): Promise<string | undefined>;
119
+ /**
120
+ * Gets the logged-in user information from JWT token.
121
+ * Automatically refreshes token if expired.
122
+ */
123
+ declare function getLoggedInUser(options?: AuthOptions): Promise<{
124
+ accountId: number;
125
+ customUserId: number;
126
+ email: string;
127
+ }>;
128
+ /**
129
+ * Checks config to determine current cache mode without reading keychain.
130
+ * Credential keys in config are ground truth — if login_jwt exists, we're in
131
+ * config mode regardless of the marker. The marker only matters when no
132
+ * credential keys are present (e.g. after logout or when using keychain).
133
+ */
134
+ declare function getLoginStorageMode(): LoginStorageMode;
135
+ /**
136
+ * Clears stored login information.
137
+ */
138
+ declare function logout(options?: Pick<AuthOptions, "onEvent">): Promise<void>;
139
+ /**
140
+ * Gets the path to the configuration file.
141
+ */
142
+ declare function getConfigPath(): string;
143
+
144
+ export { AUTH_MODE_HEADER, type AuthOptions, type LoginData, type LoginStorageMode, type PkceCredentials, type PkceLoginConfig, ZapierAuthenticationError, createCache, getAuthAuthorizeUrl, getAuthTokenUrl, getConfig, getConfigPath, getLoggedInUser, getLoginStorageMode, getPkceLoginConfig, getToken, logout, unloadConfig, updateLogin };