@zapier/zapier-sdk-cli 0.1.0 → 0.2.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.
Files changed (72) hide show
  1. package/dist/cli.js +15 -11
  2. package/dist/commands/configPath.d.ts +2 -0
  3. package/dist/commands/configPath.js +9 -0
  4. package/dist/commands/index.d.ts +4 -0
  5. package/dist/commands/index.js +4 -0
  6. package/dist/commands/login.d.ts +2 -0
  7. package/dist/commands/login.js +25 -0
  8. package/dist/commands/logout.d.ts +2 -0
  9. package/dist/commands/logout.js +16 -0
  10. package/dist/commands/whoami.d.ts +2 -0
  11. package/dist/commands/whoami.js +16 -0
  12. package/dist/utils/api/client.d.ts +15 -0
  13. package/dist/utils/api/client.js +27 -0
  14. package/dist/utils/auth/ensureValidToken.d.ts +7 -0
  15. package/dist/utils/auth/ensureValidToken.js +33 -0
  16. package/dist/utils/auth/getAuthState.d.ts +12 -0
  17. package/dist/utils/auth/getAuthState.js +17 -0
  18. package/dist/utils/auth/getJWT.d.ts +2 -0
  19. package/dist/utils/auth/getJWT.js +13 -0
  20. package/dist/utils/auth/getLoggedInUser.d.ts +6 -0
  21. package/dist/utils/auth/getLoggedInUser.js +47 -0
  22. package/dist/utils/auth/login.d.ts +2 -0
  23. package/dist/utils/auth/login.js +135 -0
  24. package/dist/utils/auth/logout.d.ts +2 -0
  25. package/dist/utils/auth/logout.js +7 -0
  26. package/dist/utils/auth/refreshJWT.d.ts +2 -0
  27. package/dist/utils/auth/refreshJWT.js +33 -0
  28. package/dist/utils/auth/updateLogin.d.ts +7 -0
  29. package/dist/utils/auth/updateLogin.js +7 -0
  30. package/dist/utils/cli-generator.js +49 -49
  31. package/dist/utils/config.d.ts +2 -0
  32. package/dist/utils/config.js +2 -0
  33. package/dist/utils/constants.d.ts +5 -0
  34. package/dist/utils/constants.js +6 -0
  35. package/dist/utils/getCallablePromise.d.ts +6 -0
  36. package/dist/utils/getCallablePromise.js +14 -0
  37. package/dist/utils/getConfigPath.d.ts +1 -0
  38. package/dist/utils/getConfigPath.js +4 -0
  39. package/dist/utils/log.d.ts +7 -0
  40. package/dist/utils/log.js +16 -0
  41. package/dist/utils/pager.js +10 -20
  42. package/dist/utils/parameter-resolver.js +34 -41
  43. package/dist/utils/schema-formatter.js +11 -17
  44. package/dist/utils/serializeAsync.d.ts +2 -0
  45. package/dist/utils/serializeAsync.js +16 -0
  46. package/dist/utils/spinner.d.ts +1 -0
  47. package/dist/utils/spinner.js +13 -0
  48. package/package.json +9 -2
  49. package/src/cli.ts +15 -3
  50. package/src/commands/configPath.ts +10 -0
  51. package/src/commands/index.ts +4 -0
  52. package/src/commands/login.ts +34 -0
  53. package/src/commands/logout.ts +19 -0
  54. package/src/commands/whoami.ts +20 -0
  55. package/src/utils/api/client.ts +44 -0
  56. package/src/utils/auth/ensureValidToken.ts +35 -0
  57. package/src/utils/auth/getAuthState.ts +36 -0
  58. package/src/utils/auth/getJWT.ts +20 -0
  59. package/src/utils/auth/getLoggedInUser.ts +68 -0
  60. package/src/utils/auth/login.ts +191 -0
  61. package/src/utils/auth/logout.ts +9 -0
  62. package/src/utils/auth/refreshJWT.ts +50 -0
  63. package/src/utils/auth/updateLogin.ts +19 -0
  64. package/src/utils/cli-generator.ts +14 -3
  65. package/src/utils/config.ts +3 -0
  66. package/src/utils/constants.ts +9 -0
  67. package/src/utils/getCallablePromise.ts +21 -0
  68. package/src/utils/getConfigPath.ts +5 -0
  69. package/src/utils/log.ts +18 -0
  70. package/src/utils/serializeAsync.ts +26 -0
  71. package/src/utils/spinner.ts +16 -0
  72. package/tsconfig.json +2 -2
package/dist/cli.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const commander_1 = require("commander");
5
- const zapier_sdk_1 = require("@zapier/zapier-sdk");
6
- const cli_generator_1 = require("./utils/cli-generator");
7
- const program = new commander_1.Command();
2
+ import { Command } from "commander";
3
+ import { createZapierSdk } from "@zapier/zapier-sdk";
4
+ import { generateCliCommands } from "./utils/cli-generator";
5
+ import { ensureValidToken } from "./utils/auth/ensureValidToken";
6
+ import { createLoginCommand, createLogoutCommand, createWhoamiCommand, createConfigPathCommand, } from "./commands";
7
+ const program = new Command();
8
8
  program
9
9
  .name("zapier-sdk")
10
10
  .description("CLI for Zapier SDK - Commands auto-generated from SDK schemas")
@@ -12,12 +12,16 @@ program
12
12
  .option("--debug", "Enable debug logging");
13
13
  // Check for debug flag early
14
14
  const isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
15
- // Create SDK instance for CLI operations
16
- // Auth will be resolved from environment variables or command options
17
- const sdk = (0, zapier_sdk_1.createZapierSdk)({
18
- // Token will be picked up from ZAPIER_TOKEN env var or provided via options
15
+ // Create SDK instance with dynamic token resolution
16
+ const sdk = createZapierSdk({
17
+ getToken: ensureValidToken,
19
18
  debug: isDebugMode,
20
19
  });
20
+ // Add auth commands before generating SDK commands
21
+ program.addCommand(createLoginCommand());
22
+ program.addCommand(createLogoutCommand());
23
+ program.addCommand(createWhoamiCommand());
24
+ program.addCommand(createConfigPathCommand());
21
25
  // Generate CLI commands from SDK schemas
22
- (0, cli_generator_1.generateCliCommands)(program, sdk);
26
+ generateCliCommands(program, sdk);
23
27
  program.parse();
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function createConfigPathCommand(): Command;
@@ -0,0 +1,9 @@
1
+ import { Command } from "commander";
2
+ import { getConfigPath } from "../utils/getConfigPath";
3
+ export function createConfigPathCommand() {
4
+ return new Command("get-config-path")
5
+ .description("Show the path to the configuration file")
6
+ .action(async () => {
7
+ console.log(`Configuration file: ${getConfigPath()}`);
8
+ });
9
+ }
@@ -0,0 +1,4 @@
1
+ export { createLoginCommand } from "./login";
2
+ export { createLogoutCommand } from "./logout";
3
+ export { createWhoamiCommand } from "./whoami";
4
+ export { createConfigPathCommand } from "./configPath";
@@ -0,0 +1,4 @@
1
+ export { createLoginCommand } from "./login";
2
+ export { createLogoutCommand } from "./logout";
3
+ export { createWhoamiCommand } from "./whoami";
4
+ export { createConfigPathCommand } from "./configPath";
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function createLoginCommand(): Command;
@@ -0,0 +1,25 @@
1
+ import { Command } from "commander";
2
+ import login from "../utils/auth/login";
3
+ import getLoggedInUser from "../utils/auth/getLoggedInUser";
4
+ export function createLoginCommand() {
5
+ return new Command("login")
6
+ .description("Log in to Zapier to access your account")
7
+ .option("--timeout <seconds>", "Login timeout in seconds (default: 300)", "300")
8
+ .action(async (options) => {
9
+ try {
10
+ const timeoutSeconds = parseInt(options.timeout, 10);
11
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
12
+ throw new Error("Timeout must be a positive number");
13
+ }
14
+ await login(timeoutSeconds * 1000); // Convert to milliseconds
15
+ const user = await getLoggedInUser();
16
+ console.log(`✅ Successfully logged in as ${user.email}`);
17
+ // Force immediate exit to prevent hanging (especially in development with tsx)
18
+ setTimeout(() => process.exit(0), 100);
19
+ }
20
+ catch (error) {
21
+ console.error("❌ Login failed:", error instanceof Error ? error.message : "Unknown error");
22
+ process.exit(1);
23
+ }
24
+ });
25
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function createLogoutCommand(): Command;
@@ -0,0 +1,16 @@
1
+ import { Command } from "commander";
2
+ import logout from "../utils/auth/logout";
3
+ export function createLogoutCommand() {
4
+ return new Command("logout")
5
+ .description("Log out of your Zapier account")
6
+ .action(async () => {
7
+ try {
8
+ logout();
9
+ console.log("✅ Successfully logged out");
10
+ }
11
+ catch (error) {
12
+ console.error("❌ Logout failed:", error instanceof Error ? error.message : "Unknown error");
13
+ process.exit(1);
14
+ }
15
+ });
16
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function createWhoamiCommand(): Command;
@@ -0,0 +1,16 @@
1
+ import { Command } from "commander";
2
+ import getLoggedInUser from "../utils/auth/getLoggedInUser";
3
+ export function createWhoamiCommand() {
4
+ return new Command("whoami")
5
+ .description("Show current login status and user information")
6
+ .action(async () => {
7
+ try {
8
+ const user = await getLoggedInUser();
9
+ console.log(`✅ Logged in as ${user.email} (Account ID: ${user.accountId})`);
10
+ }
11
+ catch {
12
+ console.log("❌ Not logged in. Use 'zapier-sdk login' to authenticate.");
13
+ process.exit(1);
14
+ }
15
+ });
16
+ }
@@ -0,0 +1,15 @@
1
+ export interface ApiResponse<T = any> {
2
+ data: T;
3
+ status: number;
4
+ }
5
+ export declare const createApiClient: () => {
6
+ post: <T = any>(url: string, data: any, options?: {
7
+ headers?: Record<string, string>;
8
+ }) => Promise<ApiResponse<T>>;
9
+ };
10
+ declare const api: {
11
+ post: <T = any>(url: string, data: any, options?: {
12
+ headers?: Record<string, string>;
13
+ }) => Promise<ApiResponse<T>>;
14
+ };
15
+ export default api;
@@ -0,0 +1,27 @@
1
+ export const createApiClient = () => {
2
+ const post = async (url, data, options = {}) => {
3
+ const { headers = {} } = options;
4
+ const response = await fetch(url, {
5
+ method: "POST",
6
+ headers: {
7
+ "Content-Type": "application/x-www-form-urlencoded",
8
+ Connection: "close",
9
+ ...headers,
10
+ },
11
+ body: new URLSearchParams(data),
12
+ });
13
+ if (!response.ok) {
14
+ throw new Error(`${response.status} ${response.statusText}`);
15
+ }
16
+ const responseData = await response.json();
17
+ return {
18
+ data: responseData,
19
+ status: response.status,
20
+ };
21
+ };
22
+ return {
23
+ post,
24
+ };
25
+ };
26
+ const api = createApiClient();
27
+ export default api;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Ensures we have a valid, non-expired JWT token.
3
+ * Will attempt to refresh expired tokens automatically.
4
+ * Falls back to ZAPIER_TOKEN environment variable if no stored login.
5
+ * Returns undefined if no token is available or refresh fails.
6
+ */
7
+ export declare const ensureValidToken: () => Promise<string | undefined>;
@@ -0,0 +1,33 @@
1
+ import getAuthState from "./getAuthState";
2
+ import refreshJWT from "./refreshJWT";
3
+ /**
4
+ * Ensures we have a valid, non-expired JWT token.
5
+ * Will attempt to refresh expired tokens automatically.
6
+ * Falls back to ZAPIER_TOKEN environment variable if no stored login.
7
+ * Returns undefined if no token is available or refresh fails.
8
+ */
9
+ export const ensureValidToken = async () => {
10
+ try {
11
+ const state = getAuthState();
12
+ if (state.status === "logged-out") {
13
+ // Fall back to environment variable if not logged in
14
+ return process.env.ZAPIER_TOKEN;
15
+ }
16
+ if (state.status === "expired") {
17
+ // Attempt to refresh the token
18
+ try {
19
+ return await refreshJWT();
20
+ }
21
+ catch {
22
+ // If refresh fails, fall back to environment variable
23
+ return process.env.ZAPIER_TOKEN;
24
+ }
25
+ }
26
+ // Status is "logged-in", return the valid token
27
+ return state.jwt;
28
+ }
29
+ catch {
30
+ // If any error occurs, fall back to environment variable
31
+ return process.env.ZAPIER_TOKEN;
32
+ }
33
+ };
@@ -0,0 +1,12 @@
1
+ type Status = {
2
+ status: "logged-in";
3
+ jwt: string;
4
+ refresh_token: string;
5
+ } | {
6
+ status: "expired";
7
+ refresh_token: string;
8
+ } | {
9
+ status: "logged-out";
10
+ };
11
+ declare const getAuthState: () => Status;
12
+ export default getAuthState;
@@ -0,0 +1,17 @@
1
+ import { config } from "../config";
2
+ const getAuthState = () => {
3
+ const jwt = config.get("login_jwt");
4
+ const refreshToken = config.get("login_refresh_token");
5
+ const expiresAt = config.get("login_expires_at");
6
+ if (!jwt || !refreshToken || !expiresAt) {
7
+ return { status: "logged-out" };
8
+ }
9
+ if (expiresAt > Date.now() + 30 * 1000) {
10
+ return { status: "logged-in", jwt, refresh_token: refreshToken };
11
+ }
12
+ return {
13
+ status: "expired",
14
+ refresh_token: refreshToken,
15
+ };
16
+ };
17
+ export default getAuthState;
@@ -0,0 +1,2 @@
1
+ declare const getJWT: () => Promise<string>;
2
+ export default getJWT;
@@ -0,0 +1,13 @@
1
+ import getAuthState from "./getAuthState";
2
+ import refreshJWT from "./refreshJWT";
3
+ const getJWT = async () => {
4
+ const state = getAuthState();
5
+ if (state.status === "logged-out") {
6
+ throw new Error("Expected getJWT to only be called when user has logged in.");
7
+ }
8
+ if (state.status === "expired") {
9
+ return await refreshJWT();
10
+ }
11
+ return state.jwt;
12
+ };
13
+ export default getJWT;
@@ -0,0 +1,6 @@
1
+ declare const getLoggedInUser: () => Promise<{
2
+ accountId: number;
3
+ customUserId: number;
4
+ email: string;
5
+ }>;
6
+ export default getLoggedInUser;
@@ -0,0 +1,47 @@
1
+ import jsonwebtoken from "jsonwebtoken";
2
+ import getJWT from "./getJWT";
3
+ const decodeJWTOrThrow = (jwt) => {
4
+ if (typeof jwt !== "string") {
5
+ throw new Error("Expected JWT to be a string");
6
+ }
7
+ const decodedJWT = jsonwebtoken.decode(jwt, { complete: true });
8
+ if (!decodedJWT) {
9
+ throw new Error("Could not decode JWT");
10
+ }
11
+ if (typeof decodedJWT.payload === "string") {
12
+ throw new Error("Did not expect JWT payload to be a string");
13
+ }
14
+ return decodedJWT;
15
+ };
16
+ const getLoggedInUser = async () => {
17
+ const jwt = await getJWT();
18
+ let decodedJwt = decodeJWTOrThrow(jwt);
19
+ if (decodedJwt.payload["sub_type"] == "service") {
20
+ decodedJwt = decodeJWTOrThrow(decodedJwt.payload["njwt"]);
21
+ }
22
+ if (typeof decodedJwt.payload["zap:acc"] !== "string") {
23
+ throw new Error("JWT payload does not contain accountId");
24
+ }
25
+ const accountId = parseInt(decodedJwt.payload["zap:acc"], 10);
26
+ if (isNaN(accountId)) {
27
+ throw new Error("JWT accountId is not a number");
28
+ }
29
+ if (decodedJwt.payload["sub_type"] !== "customuser" ||
30
+ typeof decodedJwt.payload["sub"] !== "string") {
31
+ throw new Error("JWT payload does not contain customUserId");
32
+ }
33
+ const customUserId = parseInt(decodedJwt.payload["sub"], 10);
34
+ if (isNaN(customUserId)) {
35
+ throw new Error("JWT customUserId is not a number");
36
+ }
37
+ const email = decodedJwt.payload["zap:uname"];
38
+ if (typeof email !== "string") {
39
+ throw new Error("JWT payload does not contain email");
40
+ }
41
+ return {
42
+ accountId,
43
+ customUserId,
44
+ email,
45
+ };
46
+ };
47
+ export default getLoggedInUser;
@@ -0,0 +1,2 @@
1
+ declare const login: (timeoutMs?: number) => Promise<string>;
2
+ export default login;
@@ -0,0 +1,135 @@
1
+ import open from "open";
2
+ import crypto from "node:crypto";
3
+ import express from "express";
4
+ import pkceChallenge from "pkce-challenge";
5
+ import { AUTH_MODE_HEADER, LOGIN_CLIENT_ID, LOGIN_PORTS, LOGIN_TIMEOUT_MS, ZAPIER_BASE, } from "../constants";
6
+ import { spinPromise } from "../spinner";
7
+ import log from "../log";
8
+ import api from "../api/client";
9
+ import getCallablePromise from "../getCallablePromise";
10
+ import updateLogin from "./updateLogin";
11
+ import logout from "./logout";
12
+ const findAvailablePort = () => {
13
+ return new Promise((resolve, reject) => {
14
+ let portIndex = 0;
15
+ const tryPort = (port) => {
16
+ const server = express().listen(port, () => {
17
+ server.close();
18
+ resolve(port);
19
+ });
20
+ server.on("error", (err) => {
21
+ if (err.code === "EADDRINUSE") {
22
+ if (portIndex < LOGIN_PORTS.length) {
23
+ // Try next predefined port
24
+ tryPort(LOGIN_PORTS[portIndex++]);
25
+ }
26
+ else {
27
+ // All configured ports are busy
28
+ reject(new Error(`All configured OAuth callback ports are busy: ${LOGIN_PORTS.join(", ")}. Please try again later or close applications using these ports.`));
29
+ }
30
+ }
31
+ else {
32
+ reject(err);
33
+ }
34
+ });
35
+ };
36
+ if (LOGIN_PORTS.length > 0) {
37
+ tryPort(LOGIN_PORTS[portIndex++]);
38
+ }
39
+ else {
40
+ reject(new Error("No OAuth callback ports configured"));
41
+ }
42
+ });
43
+ };
44
+ const generateRandomString = () => {
45
+ const array = new Uint32Array(28);
46
+ crypto.getRandomValues(array);
47
+ return Array.from(array, (dec) => ("0" + dec.toString(16)).substring(-2)).join("");
48
+ };
49
+ const login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
50
+ // Force logout
51
+ logout();
52
+ // Find an available port
53
+ const availablePort = await findAvailablePort();
54
+ const redirectUri = `http://localhost:${availablePort}/oauth`;
55
+ log.info(`Using port ${availablePort} for OAuth callback`);
56
+ const { promise: promisedCode, resolve: setCode } = getCallablePromise();
57
+ const app = express();
58
+ app.get("/oauth", (req, res) => {
59
+ setCode(String(req.query.code));
60
+ // Set headers to prevent keep-alive
61
+ res.setHeader("Connection", "close");
62
+ res.end("You can now close this tab and return to the CLI.");
63
+ });
64
+ const server = app.listen(availablePort);
65
+ // Track connections to force close them if needed
66
+ const connections = new Set();
67
+ server.on("connection", (conn) => {
68
+ connections.add(conn);
69
+ conn.on("close", () => connections.delete(conn));
70
+ });
71
+ // Set up signal handlers for graceful shutdown
72
+ const cleanup = () => {
73
+ server.close();
74
+ log.info("\n❌ Login cancelled by user");
75
+ process.exit(0);
76
+ };
77
+ process.on("SIGINT", cleanup);
78
+ process.on("SIGTERM", cleanup);
79
+ const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge();
80
+ const authUrl = `${ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
81
+ response_type: "code",
82
+ client_id: LOGIN_CLIENT_ID,
83
+ redirect_uri: redirectUri,
84
+ scope: "internal offline_access",
85
+ state: generateRandomString(),
86
+ code_challenge: codeChallenge,
87
+ code_challenge_method: "S256",
88
+ }).toString()}`;
89
+ log.info("Opening your browser to log in.");
90
+ log.info("If it doesn't open, visit:", authUrl);
91
+ open(authUrl);
92
+ try {
93
+ await spinPromise(Promise.race([
94
+ promisedCode,
95
+ new Promise((_resolve, reject) => setTimeout(() => {
96
+ reject(new Error(`Login timed out after ${Math.round(timeoutMs / 1000)} seconds.`));
97
+ }, timeoutMs)),
98
+ ]), "Waiting for you to login and authorize");
99
+ }
100
+ finally {
101
+ // Remove signal handlers
102
+ process.off("SIGINT", cleanup);
103
+ process.off("SIGTERM", cleanup);
104
+ // Close server with timeout and force-close connections if needed
105
+ await new Promise((resolve) => {
106
+ const timeout = setTimeout(() => {
107
+ log.info("Server close timed out, forcing connection shutdown...");
108
+ // Force close all connections
109
+ connections.forEach((conn) => conn.destroy());
110
+ resolve();
111
+ }, 1000); // 1 second timeout
112
+ server.close(() => {
113
+ clearTimeout(timeout);
114
+ resolve();
115
+ });
116
+ });
117
+ }
118
+ log.info("Exchanging authorization code for tokens...");
119
+ const { data } = await api.post(`${ZAPIER_BASE}/oauth/token/`, {
120
+ grant_type: "authorization_code",
121
+ code: await promisedCode,
122
+ redirect_uri: redirectUri,
123
+ client_id: LOGIN_CLIENT_ID,
124
+ code_verifier: codeVerifier,
125
+ }, {
126
+ headers: {
127
+ [AUTH_MODE_HEADER]: "no",
128
+ "Content-Type": "application/x-www-form-urlencoded",
129
+ },
130
+ });
131
+ updateLogin(data);
132
+ log.info("Token exchange completed successfully");
133
+ return data.access_token;
134
+ };
135
+ export default login;
@@ -0,0 +1,2 @@
1
+ declare const logout: () => void;
2
+ export default logout;
@@ -0,0 +1,7 @@
1
+ import { config } from "../config";
2
+ const logout = () => {
3
+ config.delete("login_jwt");
4
+ config.delete("login_refresh_token");
5
+ config.delete("login_expires_at");
6
+ };
7
+ export default logout;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<string>;
2
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import { AUTH_MODE_HEADER, LOGIN_CLIENT_ID, ZAPIER_BASE } from "../constants";
2
+ import api from "../api/client";
3
+ import serializeAsync from "../serializeAsync";
4
+ import { spinPromise } from "../spinner";
5
+ import getAuthState from "./getAuthState";
6
+ import updateLogin from "./updateLogin";
7
+ import logout from "./logout";
8
+ const refreshJWT = async () => {
9
+ const state = getAuthState();
10
+ if (state.status === "logged-out") {
11
+ throw new Error("Unexpected call to refreshJWT while logged out.");
12
+ }
13
+ try {
14
+ const { data } = await spinPromise(api.post(`${ZAPIER_BASE}/oauth/token/`, {
15
+ client_id: LOGIN_CLIENT_ID,
16
+ refresh_token: state.refresh_token,
17
+ grant_type: "refresh_token",
18
+ }, {
19
+ headers: {
20
+ "Content-Type": "application/x-www-form-urlencoded",
21
+ [AUTH_MODE_HEADER]: "no",
22
+ },
23
+ }), "Refreshing your token...");
24
+ updateLogin(data);
25
+ return data.access_token;
26
+ }
27
+ catch (e) {
28
+ // Force logout
29
+ logout();
30
+ throw e;
31
+ }
32
+ };
33
+ export default serializeAsync(refreshJWT);
@@ -0,0 +1,7 @@
1
+ interface LoginData {
2
+ access_token: string;
3
+ refresh_token: string;
4
+ expires_in: number;
5
+ }
6
+ declare const updateLogin: ({ access_token: accessToken, refresh_token: refreshToken, expires_in: expiresIn, }: LoginData) => void;
7
+ export default updateLogin;
@@ -0,0 +1,7 @@
1
+ import { config } from "../config";
2
+ const updateLogin = ({ access_token: accessToken, refresh_token: refreshToken, expires_in: expiresIn, }) => {
3
+ config.set("login_jwt", accessToken);
4
+ config.set("login_refresh_token", refreshToken);
5
+ config.set("login_expires_at", Date.now() + expiresIn * 1000);
6
+ };
7
+ export default updateLogin;