@trayio/cdk-cli 4.104.0 → 5.6.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 (52) hide show
  1. package/OAUTH2_TOKEN.md +290 -0
  2. package/README.md +38 -1
  3. package/dist/commands/connector/oauth2-token.d.ts +45 -0
  4. package/dist/commands/connector/oauth2-token.d.ts.map +1 -0
  5. package/dist/commands/connector/oauth2-token.js +243 -0
  6. package/dist/commands/connector/oauth2-token.unit.test.d.ts +2 -0
  7. package/dist/commands/connector/oauth2-token.unit.test.d.ts.map +1 -0
  8. package/dist/commands/connector/oauth2-token.unit.test.js +1244 -0
  9. package/dist/lib/oauth2-token/flows/authorization-code.d.ts +4 -0
  10. package/dist/lib/oauth2-token/flows/authorization-code.d.ts.map +1 -0
  11. package/dist/lib/oauth2-token/flows/authorization-code.js +218 -0
  12. package/dist/lib/oauth2-token/flows/client-credentials.d.ts +4 -0
  13. package/dist/lib/oauth2-token/flows/client-credentials.d.ts.map +1 -0
  14. package/dist/lib/oauth2-token/flows/client-credentials.js +55 -0
  15. package/dist/lib/oauth2-token/flows/device-code.d.ts +4 -0
  16. package/dist/lib/oauth2-token/flows/device-code.d.ts.map +1 -0
  17. package/dist/lib/oauth2-token/flows/device-code.js +143 -0
  18. package/dist/lib/oauth2-token/flows/index.d.ts +8 -0
  19. package/dist/lib/oauth2-token/flows/index.d.ts.map +1 -0
  20. package/dist/lib/oauth2-token/flows/index.js +14 -0
  21. package/dist/lib/oauth2-token/flows/refresh-token.d.ts +4 -0
  22. package/dist/lib/oauth2-token/flows/refresh-token.d.ts.map +1 -0
  23. package/dist/lib/oauth2-token/flows/refresh-token.js +60 -0
  24. package/dist/lib/oauth2-token/token-writer.d.ts +7 -0
  25. package/dist/lib/oauth2-token/token-writer.d.ts.map +1 -0
  26. package/dist/lib/oauth2-token/token-writer.js +83 -0
  27. package/dist/lib/oauth2-token/types.d.ts +34 -0
  28. package/dist/lib/oauth2-token/types.d.ts.map +1 -0
  29. package/dist/lib/oauth2-token/types.js +5 -0
  30. package/dist/lib/oauth2-token/utils/browser.d.ts +2 -0
  31. package/dist/lib/oauth2-token/utils/browser.d.ts.map +1 -0
  32. package/dist/lib/oauth2-token/utils/browser.js +22 -0
  33. package/dist/lib/oauth2-token/utils/crypto.d.ts +6 -0
  34. package/dist/lib/oauth2-token/utils/crypto.d.ts.map +1 -0
  35. package/dist/lib/oauth2-token/utils/crypto.js +47 -0
  36. package/dist/lib/oauth2-token/utils/env.d.ts +7 -0
  37. package/dist/lib/oauth2-token/utils/env.d.ts.map +1 -0
  38. package/dist/lib/oauth2-token/utils/env.js +85 -0
  39. package/dist/lib/oauth2-token/utils/file.d.ts +4 -0
  40. package/dist/lib/oauth2-token/utils/file.d.ts.map +1 -0
  41. package/dist/lib/oauth2-token/utils/file.js +40 -0
  42. package/dist/lib/oauth2-token/utils/index.d.ts +10 -0
  43. package/dist/lib/oauth2-token/utils/index.d.ts.map +1 -0
  44. package/dist/lib/oauth2-token/utils/index.js +25 -0
  45. package/dist/lib/oauth2-token/utils/json.d.ts +9 -0
  46. package/dist/lib/oauth2-token/utils/json.d.ts.map +1 -0
  47. package/dist/lib/oauth2-token/utils/json.js +52 -0
  48. package/dist/lib/oauth2-token/utils/url.d.ts +6 -0
  49. package/dist/lib/oauth2-token/utils/url.d.ts.map +1 -0
  50. package/dist/lib/oauth2-token/utils/url.js +22 -0
  51. package/oclif.manifest.json +150 -1
  52. package/package.json +11 -9
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shared types for OAuth2 token command
3
+ */
4
+ export type AnyObject = Record<string, any>;
5
+ export type FoundField = {
6
+ path: string[];
7
+ parent: AnyObject;
8
+ key: string;
9
+ value: any;
10
+ };
11
+ export type ClientAuthMethod = 'basic' | 'body' | 'both';
12
+ export type OAuth2Config = {
13
+ tokenUrl: string;
14
+ authorizeUrl?: string;
15
+ deviceCodeUrl?: string;
16
+ clientId: string;
17
+ clientSecret?: string;
18
+ scope?: string;
19
+ audience?: string;
20
+ redirectUri?: string;
21
+ clientAuthMethod?: ClientAuthMethod;
22
+ disablePkce?: boolean;
23
+ };
24
+ export type TokenResponse = {
25
+ access_token: string;
26
+ refresh_token?: string;
27
+ expires_in?: number;
28
+ token_type?: string;
29
+ };
30
+ export type PkceChallenge = {
31
+ verifier: string;
32
+ challenge: string;
33
+ };
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/oauth2-token/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5C,MAAM,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzD,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /**
3
+ * Shared types for OAuth2 token command
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare const openBrowser: (urlToOpen: string) => void;
2
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/lib/oauth2-token/utils/browser.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW,cAAe,MAAM,KAAG,IAW/C,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openBrowser = void 0;
4
+ /**
5
+ * Browser interaction utilities
6
+ */
7
+ const child_process_1 = require("child_process");
8
+ const openBrowser = (urlToOpen) => {
9
+ const { platform } = process;
10
+ let command = '';
11
+ if (platform === 'darwin') {
12
+ command = `open '${urlToOpen}'`;
13
+ }
14
+ else if (platform === 'win32') {
15
+ command = `start "" "${urlToOpen}"`;
16
+ }
17
+ else {
18
+ command = `xdg-open '${urlToOpen}'`;
19
+ }
20
+ (0, child_process_1.exec)(command);
21
+ };
22
+ exports.openBrowser = openBrowser;
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { PkceChallenge } from '../types';
3
+ export declare const base64UrlEncode: (buffer: Buffer) => string;
4
+ export declare const generatePkce: () => PkceChallenge;
5
+ export declare const generateState: () => string;
6
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../../src/lib/oauth2-token/utils/crypto.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,eAAO,MAAM,eAAe,WAAY,MAAM,KAAG,MAK3B,CAAC;AAEvB,eAAO,MAAM,YAAY,QAAO,aAO/B,CAAC;AAEF,eAAO,MAAM,aAAa,QAAO,MACO,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateState = exports.generatePkce = exports.base64UrlEncode = void 0;
27
+ /**
28
+ * Cryptographic utilities for OAuth2 (PKCE, state generation)
29
+ */
30
+ const crypto = __importStar(require("crypto"));
31
+ const base64UrlEncode = (buffer) => buffer
32
+ .toString('base64')
33
+ .replace(/=/g, '')
34
+ .replace(/\+/g, '-')
35
+ .replace(/\//g, '_');
36
+ exports.base64UrlEncode = base64UrlEncode;
37
+ const generatePkce = () => {
38
+ const verifier = (0, exports.base64UrlEncode)(crypto.randomBytes(64));
39
+ const sha = crypto.createHash('sha256');
40
+ sha.update(verifier);
41
+ const digest = sha.digest();
42
+ const challenge = (0, exports.base64UrlEncode)(digest);
43
+ return { verifier, challenge };
44
+ };
45
+ exports.generatePkce = generatePkce;
46
+ const generateState = () => (0, exports.base64UrlEncode)(crypto.randomBytes(16));
47
+ exports.generateState = generateState;
@@ -0,0 +1,7 @@
1
+ export declare const loadEnvConfig: (envPath: string) => Promise<Record<string, string>>;
2
+ /**
3
+ * Get value from environment variables with fallback keys
4
+ * Precedence: OAUTH2_* keys first, then fallback keys
5
+ */
6
+ export declare const getEnvValue: (env: Record<string, string>, primaryKey: string, fallbackKey?: string) => string;
7
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../../src/lib/oauth2-token/utils/env.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,aAAa,YAChB,MAAM,KACb,QAAQ,OAAO,MAAM,EAAE,MAAM,CAAC,CAqBhC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,QAClB,OAAO,MAAM,EAAE,MAAM,CAAC,cACf,MAAM,gBACJ,MAAM,KAClB,MAQF,CAAC"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getEnvValue = exports.loadEnvConfig = void 0;
27
+ /**
28
+ * Environment configuration utilities
29
+ *
30
+ * Load environment variables from a .env file
31
+ * Expected .env file structure for OAuth2 configuration:
32
+ *
33
+ * # OAuth2 Configuration
34
+ * CLIENT_ID=your_client_id_here
35
+ * CLIENT_SECRET=your_client_secret_here
36
+ * TOKEN_URL=https://oauth.provider.com/token
37
+ * AUTHORIZE_URL=https://oauth.provider.com/authorize
38
+ * DEVICE_CODE_URL=https://oauth.provider.com/device_authorization
39
+ * REDIRECT_URI=http://localhost:3400/callback
40
+ * SCOPE="read write admin"
41
+ * AUDIENCE=https://api.provider.com
42
+ * REFRESH_TOKEN=your_refresh_token_here
43
+ * CLIENT_AUTH_METHOD=basic
44
+ *
45
+ * # Client Auth Method options:
46
+ * # - basic: Send credentials via HTTP Basic Auth header (required for Workday)
47
+ * # - body: Send credentials in request body (default, most common)
48
+ * # - both: Send credentials in both header and body
49
+ */
50
+ const fs = __importStar(require("fs/promises"));
51
+ const dotenv = __importStar(require("dotenv"));
52
+ const loadEnvConfig = async (envPath) => {
53
+ try {
54
+ const envExists = await fs
55
+ .access(envPath)
56
+ .then(() => true)
57
+ .catch(() => false);
58
+ if (!envExists) {
59
+ return {};
60
+ }
61
+ const result = dotenv.config({ path: envPath });
62
+ if (result.error) {
63
+ throw result.error;
64
+ }
65
+ return result.parsed || {};
66
+ }
67
+ catch (error) {
68
+ // If .env file doesn't exist or can't be read, return empty config
69
+ // This allows the command to work without .env file
70
+ return {};
71
+ }
72
+ };
73
+ exports.loadEnvConfig = loadEnvConfig;
74
+ /**
75
+ * Get value from environment variables with fallback keys
76
+ * Precedence: OAUTH2_* keys first, then fallback keys
77
+ */
78
+ const getEnvValue = (env, primaryKey, fallbackKey) => {
79
+ const oauth2Key = `OAUTH2_${primaryKey}`;
80
+ return (env[oauth2Key] ||
81
+ (fallbackKey ? env[fallbackKey] : '') ||
82
+ env[primaryKey] ||
83
+ '');
84
+ };
85
+ exports.getEnvValue = getEnvValue;
@@ -0,0 +1,4 @@
1
+ import { AnyObject } from '../types';
2
+ export declare const readJsonFile: (filePath: string) => Promise<AnyObject>;
3
+ export declare const writeJsonFile: (filePath: string, data: AnyObject) => Promise<void>;
4
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../src/lib/oauth2-token/utils/file.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,eAAO,MAAM,YAAY,aAAoB,MAAM,KAAG,QAAQ,SAAS,CAGtE,CAAC;AAEF,eAAO,MAAM,aAAa,aACf,MAAM,QACV,SAAS,KACb,QAAQ,IAAI,CAGd,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.writeJsonFile = exports.readJsonFile = void 0;
27
+ /**
28
+ * File I/O utilities
29
+ */
30
+ const fs = __importStar(require("fs/promises"));
31
+ const readJsonFile = async (filePath) => {
32
+ const raw = await fs.readFile(filePath, 'utf-8');
33
+ return JSON.parse(raw);
34
+ };
35
+ exports.readJsonFile = readJsonFile;
36
+ const writeJsonFile = async (filePath, data) => {
37
+ const content = `${JSON.stringify(data, null, 2)}\n`;
38
+ await fs.writeFile(filePath, content, 'utf-8');
39
+ };
40
+ exports.writeJsonFile = writeJsonFile;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Utility functions
3
+ */
4
+ export * from './json';
5
+ export * from './file';
6
+ export * from './crypto';
7
+ export * from './browser';
8
+ export * from './url';
9
+ export * from './env';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/oauth2-token/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Utility functions
19
+ */
20
+ __exportStar(require("./json"), exports);
21
+ __exportStar(require("./file"), exports);
22
+ __exportStar(require("./crypto"), exports);
23
+ __exportStar(require("./browser"), exports);
24
+ __exportStar(require("./url"), exports);
25
+ __exportStar(require("./env"), exports);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * JSON and object manipulation utilities
3
+ */
4
+ import * as O from 'fp-ts/Option';
5
+ import { AnyObject, FoundField } from '../types';
6
+ export declare const isObject: (val: unknown) => val is AnyObject;
7
+ export declare const normalizeKey: (key: string) => string;
8
+ export declare const findFirstByKeys: (obj: AnyObject, keys: string[]) => O.Option<FoundField>;
9
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../../src/lib/oauth2-token/utils/json.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEjD,eAAO,MAAM,QAAQ,QAAS,OAAO,qBAC0B,CAAC;AAEhE,eAAO,MAAM,YAAY,QAAS,MAAM,KAAG,MACJ,CAAC;AAExC,eAAO,MAAM,eAAe,QACtB,SAAS,QACR,MAAM,EAAE,KACZ,EAAE,MAAM,CAAC,UAAU,CAoBrB,CAAC"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.findFirstByKeys = exports.normalizeKey = exports.isObject = void 0;
27
+ /**
28
+ * JSON and object manipulation utilities
29
+ */
30
+ const O = __importStar(require("fp-ts/Option"));
31
+ const isObject = (val) => val !== null && typeof val === 'object' && !Array.isArray(val);
32
+ exports.isObject = isObject;
33
+ const normalizeKey = (key) => key.replace(/[-_]/g, '').toLowerCase();
34
+ exports.normalizeKey = normalizeKey;
35
+ const findFirstByKeys = (obj, keys) => {
36
+ const targetKeys = new Set(keys.map(exports.normalizeKey));
37
+ const dfs = (current, currentPath) => {
38
+ for (const [k, v] of Object.entries(current)) {
39
+ if (targetKeys.has((0, exports.normalizeKey)(k))) {
40
+ return O.some({ path: currentPath, parent: current, key: k, value: v });
41
+ }
42
+ if ((0, exports.isObject)(v)) {
43
+ const found = dfs(v, [...currentPath, k]);
44
+ if (O.isSome(found))
45
+ return found;
46
+ }
47
+ }
48
+ return O.none;
49
+ };
50
+ return dfs(obj, []);
51
+ };
52
+ exports.findFirstByKeys = findFirstByKeys;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * URL utilities
3
+ */
4
+ export declare const isLocalhostRedirect: (redirectUri: string) => boolean;
5
+ export declare const sleep: (ms: number) => Promise<void>;
6
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../../src/lib/oauth2-token/utils/url.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,mBAAmB,gBAAiB,MAAM,KAAG,OAWzD,CAAC;AAEF,eAAO,MAAM,KAAK,OAAQ,MAAM,KAAG,QAAQ,IAAI,CAG5C,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * URL utilities
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sleep = exports.isLocalhostRedirect = void 0;
7
+ const isLocalhostRedirect = (redirectUri) => {
8
+ try {
9
+ const u = new URL(redirectUri);
10
+ return (u.hostname === 'localhost' ||
11
+ u.hostname === '127.0.0.1' ||
12
+ u.hostname === '[::1]');
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ };
18
+ exports.isLocalhostRedirect = isLocalhostRedirect;
19
+ const sleep = (ms) => new Promise((resolve) => {
20
+ setTimeout(resolve, ms);
21
+ });
22
+ exports.sleep = sleep;
@@ -154,6 +154,155 @@
154
154
  "init.js"
155
155
  ]
156
156
  },
157
+ "connector:oauth2-token": {
158
+ "aliases": [],
159
+ "args": {},
160
+ "description": "Generate or refresh an OAuth2 token from .env and write it to src/test.ctx.json.",
161
+ "flags": {
162
+ "ctxPath": {
163
+ "char": "c",
164
+ "description": "Path to context JSON file",
165
+ "name": "ctxPath",
166
+ "default": "src/test.ctx.json",
167
+ "hasDynamicHelp": false,
168
+ "multiple": false,
169
+ "type": "option"
170
+ },
171
+ "envPath": {
172
+ "char": "e",
173
+ "description": "Path to .env file for sensitive credentials",
174
+ "name": "envPath",
175
+ "default": ".env",
176
+ "hasDynamicHelp": false,
177
+ "multiple": false,
178
+ "type": "option"
179
+ },
180
+ "grantType": {
181
+ "char": "g",
182
+ "description": "OAuth2 grant type to use (auto infers from context)",
183
+ "name": "grantType",
184
+ "default": "auto",
185
+ "hasDynamicHelp": false,
186
+ "multiple": false,
187
+ "options": [
188
+ "auto",
189
+ "client_credentials",
190
+ "authorization_code",
191
+ "device_code"
192
+ ],
193
+ "type": "option"
194
+ },
195
+ "refresh": {
196
+ "char": "r",
197
+ "description": "Use refresh token to get new access token",
198
+ "name": "refresh",
199
+ "allowNo": false,
200
+ "type": "boolean"
201
+ },
202
+ "authorizeUrl": {
203
+ "description": "Override authorization URL",
204
+ "name": "authorizeUrl",
205
+ "hasDynamicHelp": false,
206
+ "multiple": false,
207
+ "type": "option"
208
+ },
209
+ "redirectUri": {
210
+ "description": "Override redirect URI for auth code",
211
+ "name": "redirectUri",
212
+ "hasDynamicHelp": false,
213
+ "multiple": false,
214
+ "type": "option"
215
+ },
216
+ "deviceCodeUrl": {
217
+ "description": "Override device authorization URL",
218
+ "name": "deviceCodeUrl",
219
+ "hasDynamicHelp": false,
220
+ "multiple": false,
221
+ "type": "option"
222
+ },
223
+ "openBrowser": {
224
+ "description": "Open browser for interactive flows",
225
+ "name": "openBrowser",
226
+ "allowNo": false,
227
+ "type": "boolean"
228
+ },
229
+ "tokenUrl": {
230
+ "description": "Override token URL",
231
+ "name": "tokenUrl",
232
+ "hasDynamicHelp": false,
233
+ "multiple": false,
234
+ "type": "option"
235
+ },
236
+ "clientId": {
237
+ "description": "Override client ID",
238
+ "name": "clientId",
239
+ "hasDynamicHelp": false,
240
+ "multiple": false,
241
+ "type": "option"
242
+ },
243
+ "clientSecret": {
244
+ "description": "Override client secret",
245
+ "name": "clientSecret",
246
+ "hasDynamicHelp": false,
247
+ "multiple": false,
248
+ "type": "option"
249
+ },
250
+ "scope": {
251
+ "description": "Override scope (space-separated)",
252
+ "name": "scope",
253
+ "hasDynamicHelp": false,
254
+ "multiple": false,
255
+ "type": "option"
256
+ },
257
+ "audience": {
258
+ "description": "Override audience",
259
+ "name": "audience",
260
+ "hasDynamicHelp": false,
261
+ "multiple": false,
262
+ "type": "option"
263
+ },
264
+ "clientAuthMethod": {
265
+ "description": "Client authentication method: basic (header), body (form), or both (default: body for backwards compatibility)",
266
+ "name": "clientAuthMethod",
267
+ "hasDynamicHelp": false,
268
+ "multiple": false,
269
+ "options": [
270
+ "basic",
271
+ "body",
272
+ "both"
273
+ ],
274
+ "type": "option"
275
+ },
276
+ "disablePkce": {
277
+ "description": "Disable PKCE (Proof Key for Code Exchange) for providers that do not support it",
278
+ "name": "disablePkce",
279
+ "allowNo": false,
280
+ "type": "boolean"
281
+ },
282
+ "dryRun": {
283
+ "char": "n",
284
+ "description": "Do not write to file, just print the token JSON",
285
+ "name": "dryRun",
286
+ "allowNo": false,
287
+ "type": "boolean"
288
+ }
289
+ },
290
+ "hasDynamicHelp": false,
291
+ "hiddenAliases": [],
292
+ "id": "connector:oauth2-token",
293
+ "pluginAlias": "@trayio/cdk-cli",
294
+ "pluginName": "@trayio/cdk-cli",
295
+ "pluginType": "core",
296
+ "strict": true,
297
+ "enableJsonFlag": false,
298
+ "isESM": false,
299
+ "relativePath": [
300
+ "dist",
301
+ "commands",
302
+ "connector",
303
+ "oauth2-token.js"
304
+ ]
305
+ },
157
306
  "connector:test": {
158
307
  "aliases": [],
159
308
  "args": {
@@ -535,5 +684,5 @@
535
684
  ]
536
685
  }
537
686
  },
538
- "version": "4.104.0"
687
+ "version": "5.6.0"
539
688
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-cli",
3
- "version": "4.104.0",
3
+ "version": "5.6.0",
4
4
  "description": "A CLI for connector development",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -22,14 +22,15 @@
22
22
  "@oclif/plugin-version": "2.0.11",
23
23
  "@oclif/plugin-warn-if-update-available": "^3.1.4",
24
24
  "@oclif/test": "3.1.12",
25
- "@trayio/axios": "4.104.0",
26
- "@trayio/cdk-build": "4.104.0",
27
- "@trayio/cdk-cli-commons": "4.104.0",
28
- "@trayio/commons": "4.104.0",
29
- "@trayio/generator": "4.104.0",
30
- "@trayio/tray-client": "4.104.0",
31
- "@trayio/tray-openapi": "4.104.0",
25
+ "@trayio/axios": "5.6.0",
26
+ "@trayio/cdk-build": "5.6.0",
27
+ "@trayio/cdk-cli-commons": "5.6.0",
28
+ "@trayio/commons": "5.6.0",
29
+ "@trayio/generator": "5.6.0",
30
+ "@trayio/tray-client": "5.6.0",
31
+ "@trayio/tray-openapi": "5.6.0",
32
32
  "chalk": "4.1.2",
33
+ "dotenv": "^16.0.0",
33
34
  "inquirer": "8.2.6"
34
35
  },
35
36
  "typesVersions": {
@@ -44,7 +45,8 @@
44
45
  "/bin",
45
46
  "/dist",
46
47
  "/oclif.manifest.json",
47
- "/INTRODUCTION.md"
48
+ "/INTRODUCTION.md",
49
+ "/OAUTH2_TOKEN.md"
48
50
  ],
49
51
  "bin": {
50
52
  "tray-cdk": "./bin/run"