@assembly-js/node-sdk 3.19.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 (42) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +152 -0
  3. package/dist/api/init.d.ts +25 -0
  4. package/dist/api/init.js +116 -0
  5. package/dist/api/init.js.map +1 -0
  6. package/dist/bin/decode-token.d.ts +2 -0
  7. package/dist/bin/decode-token.js +238 -0
  8. package/dist/bin/decode-token.js.map +1 -0
  9. package/dist/bin/run-with-http-monitor.d.ts +2 -0
  10. package/dist/bin/run-with-http-monitor.js +7 -0
  11. package/dist/bin/run-with-http-monitor.js.map +1 -0
  12. package/dist/codegen/api/core/ApiError.d.ts +10 -0
  13. package/dist/codegen/api/core/ApiError.js +12 -0
  14. package/dist/codegen/api/core/ApiError.js.map +1 -0
  15. package/dist/codegen/api/core/ApiRequestOptions.d.ts +20 -0
  16. package/dist/codegen/api/core/ApiRequestOptions.js +2 -0
  17. package/dist/codegen/api/core/ApiRequestOptions.js.map +1 -0
  18. package/dist/codegen/api/core/ApiResult.d.ts +7 -0
  19. package/dist/codegen/api/core/ApiResult.js +2 -0
  20. package/dist/codegen/api/core/ApiResult.js.map +1 -0
  21. package/dist/codegen/api/core/CancelablePromise.d.ts +31 -0
  22. package/dist/codegen/api/core/CancelablePromise.js +230 -0
  23. package/dist/codegen/api/core/CancelablePromise.js.map +1 -0
  24. package/dist/codegen/api/core/OpenAPI.d.ts +16 -0
  25. package/dist/codegen/api/core/OpenAPI.js +15 -0
  26. package/dist/codegen/api/core/OpenAPI.js.map +1 -0
  27. package/dist/codegen/api/core/request.d.ts +57 -0
  28. package/dist/codegen/api/core/request.js +351 -0
  29. package/dist/codegen/api/core/request.js.map +1 -0
  30. package/dist/codegen/api/index.d.ts +5 -0
  31. package/dist/codegen/api/index.js +9 -0
  32. package/dist/codegen/api/index.js.map +1 -0
  33. package/dist/codegen/api/services/DefaultService.d.ts +3267 -0
  34. package/dist/codegen/api/services/DefaultService.js +1459 -0
  35. package/dist/codegen/api/services/DefaultService.js.map +1 -0
  36. package/dist/package.json +46 -0
  37. package/dist/tsconfig.build.tsbuildinfo +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -0
  39. package/dist/utils/crypto.d.ts +19 -0
  40. package/dist/utils/crypto.js +42 -0
  41. package/dist/utils/crypto.js.map +1 -0
  42. package/package.json +49 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Copilot Platforms Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # Assembly.js Node SDK
2
+
3
+ The Assembly.js Node SDK provides easy to call functions written in TypeScript for interacting with the Assembly REST API. Right now this is a TypeScript only package. In the future we will have a Vanilla JS package with a corresponding @types package to go along with it.
4
+
5
+ This SDK is intended to be used on the server-side only. We do not currently offer a package for client-side development.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @assembly-js/node-sdk
11
+ # or
12
+ yarn add @assembly-js/node-sdk
13
+ ```
14
+
15
+ ## Setup
16
+
17
+ ### For Custom Apps
18
+
19
+ ```typescript
20
+ import { assemblyApi } from '@assembly-js/node-sdk';
21
+
22
+ const assembly = assemblyApi({ apiKey: YOUR_API_KEY_HERE });
23
+ ```
24
+
25
+ ### For Marketplace Apps
26
+
27
+ If you're building a Marketplace app you should go through one additional step of fetching a query parameter that gets passed into the App URL when rendered in the dashboard: `?token=TOKEN_IS_HERE`
28
+
29
+ Grab that token from the URL and pass it in to the assemblyApi configuration object.
30
+
31
+ ```typescript
32
+ import { assemblyApi } from '@assembly-js/node-sdk';
33
+
34
+ const assembly = assemblyApi({
35
+ apiKey: YOUR_API_KEY_HERE,
36
+ token: searchParams.token,
37
+ });
38
+ ```
39
+
40
+ ## Migration from copilot-node-sdk
41
+
42
+ If you're migrating from `copilot-node-sdk`, the following changes are needed:
43
+
44
+ ### Package Installation
45
+
46
+ ```bash
47
+ # Remove old package
48
+ npm uninstall copilot-node-sdk
49
+
50
+ # Install new package
51
+ npm install @assembly-js/node-sdk
52
+ ```
53
+
54
+ ### Code Changes
55
+
56
+ ```typescript
57
+ // Before
58
+ import { copilotApi } from 'copilot-node-sdk';
59
+ const copilot = copilotApi({ apiKey: YOUR_API_KEY });
60
+
61
+ // After
62
+ import { assemblyApi } from '@assembly-js/node-sdk';
63
+ const assembly = assemblyApi({ apiKey: YOUR_API_KEY });
64
+ ```
65
+
66
+ ### Environment Variables
67
+
68
+ | Old Variable | New Variable | Notes |
69
+ | --------------- | ---------------- | ------------------------------- |
70
+ | `COPILOT_ENV` | `ASSEMBLY_ENV` | Both work, new takes precedence |
71
+ | `COPILOT_DEBUG` | `ASSEMBLY_DEBUG` | Both work, new takes precedence |
72
+
73
+ ### Backwards Compatibility
74
+
75
+ For a gradual migration, the old names are still available but deprecated:
76
+
77
+ ```typescript
78
+ // These still work but are deprecated
79
+ import { copilotApi, type CopilotAPI } from '@assembly-js/node-sdk';
80
+ ```
81
+
82
+ ## How to develop this package internally:
83
+
84
+ 1. `yarn`
85
+ 2. `yarn generate-api`
86
+ 3. `yarn test` to produce a successful response
87
+ 4. `yarn test:fail` to product a response that fails because of a missing env variable.
88
+
89
+ For additional logging you can set the environment variable `ASSEMBLY_DEBUG` to any truthy value. This is useful if you'd like to see SDK logs while developing in an application's codebase.
90
+
91
+ ## Field Deprecations
92
+
93
+ ### Deprecated Fields
94
+
95
+ The following fields are deprecated and will be removed in a future version of the SDK:
96
+
97
+ #### `companyId` (deprecated in v3.15.0)
98
+
99
+ - **Replacement**: Use `companyIds` array instead
100
+ - **Reason**: To support multi-company functionality
101
+ - **Removal**: Will be removed in v4.0.0
102
+ - **Affected endpoints**: Client operations, App connections, Tasks
103
+
104
+ #### `recipientId` (deprecated in v3.15.0)
105
+
106
+ - **Replacement**: Use `clientId` and `companyId` instead
107
+ - **Reason**: More explicit recipient targeting
108
+ - **Removal**: Will be removed in v4.0.0
109
+ - **Affected endpoints**: Contracts, Invoices, Notifications, Subscriptions
110
+
111
+ ### Migration Guide
112
+
113
+ **Before (deprecated):**
114
+
115
+ ```typescript
116
+ // Creating a client with single company
117
+ await assembly.createClient({
118
+ companyId: 'company-uuid-here',
119
+ // ... other fields
120
+ });
121
+
122
+ // Creating an invoice with recipient ID
123
+ await assembly.createInvoice({
124
+ recipientId: 'recipient-uuid-here',
125
+ // ... other fields
126
+ });
127
+ ```
128
+
129
+ **After (recommended):**
130
+
131
+ ```typescript
132
+ // Creating a client with multiple companies support
133
+ await assembly.createClient({
134
+ companyIds: ['company-uuid-here'], // Now an array
135
+ // ... other fields
136
+ });
137
+
138
+ // Creating an invoice with explicit client and company targeting
139
+ await assembly.createInvoice({
140
+ clientId: 'client-uuid-here',
141
+ companyId: 'company-uuid-here',
142
+ // ... other fields
143
+ });
144
+ ```
145
+
146
+ ### Developer Experience
147
+
148
+ When using deprecated fields, you'll see:
149
+
150
+ - **IDE warnings**: TypeScript will show deprecation warnings in your editor
151
+ - **JSDoc annotations**: Hover over deprecated fields to see migration guidance
152
+ - **Continued functionality**: Deprecated fields continue to work until removal
@@ -0,0 +1,25 @@
1
+ import { DefaultService as Assembly, OpenAPI } from '../codegen/api';
2
+ export { OpenAPI };
3
+ import type { CancelablePromise } from '../codegen/api/core/CancelablePromise';
4
+ interface Token {
5
+ clientId?: string;
6
+ companyId?: string;
7
+ internalUserId?: string;
8
+ workspaceId: string;
9
+ notificationId?: string;
10
+ baseUrl?: string;
11
+ tokenId?: string;
12
+ }
13
+ export type AssemblyAPI = typeof Assembly & {
14
+ getTokenPayload?: () => Promise<Token>;
15
+ sendWebhook: <T = unknown>(event: string, payload: T) => CancelablePromise<void>;
16
+ };
17
+ /** @deprecated Use `AssemblyAPI` instead. Will be removed in v5.0.0. */
18
+ export type CopilotAPI = AssemblyAPI;
19
+ export declare function processToken(token: string): Token | null;
20
+ export declare function assemblyApi({ apiKey, token: tokenString, }: {
21
+ apiKey: string;
22
+ token?: string;
23
+ }): AssemblyAPI;
24
+ /** @deprecated Use `assemblyApi` instead. Will be removed in v5.0.0. */
25
+ export declare const copilotApi: typeof assemblyApi;
@@ -0,0 +1,116 @@
1
+ import { DefaultService as Assembly, OpenAPI } from '../codegen/api';
2
+ export { OpenAPI };
3
+ import { request as __request } from '../codegen/api/core/request';
4
+ import { decryptAES128BitToken, generate128BitKey } from '../utils/crypto';
5
+ // SDK version for tracking compatibility
6
+ // TODO: Restore dynamic version reading after fixing build
7
+ const SDK_VERSION = '3.19.0';
8
+ const sdk = Assembly;
9
+ // Helper functions to check env vars at runtime (supports both new and old names)
10
+ function getIsDebug() {
11
+ var _a;
12
+ return !!((_a = process.env.ASSEMBLY_DEBUG) !== null && _a !== void 0 ? _a : process.env.COPILOT_DEBUG);
13
+ }
14
+ function getEnvMode() {
15
+ var _a;
16
+ return (_a = process.env.ASSEMBLY_ENV) !== null && _a !== void 0 ? _a : process.env.COPILOT_ENV;
17
+ }
18
+ // Exported for testing purposes only
19
+ export function processToken(token) {
20
+ try {
21
+ const json = JSON.parse(token);
22
+ // workspaceId is the only required field
23
+ if (!('workspaceId' in json)) {
24
+ throw new Error('Missing required field in token payload: workspaceId');
25
+ }
26
+ // Note: We intentionally do NOT validate that all keys are from a known list.
27
+ // This allows the backend to add new fields (like tokenId, expiresAt) without
28
+ // breaking older SDK versions. Unknown fields are simply ignored.
29
+ const areAllValuesValid = Object.values(json).every((val) => typeof val === 'string');
30
+ if (!areAllValuesValid) {
31
+ throw new Error('Invalid values in token payload.');
32
+ }
33
+ const result = {
34
+ companyId: json.companyId,
35
+ clientId: json.clientId,
36
+ internalUserId: json.internalUserId,
37
+ workspaceId: json.workspaceId,
38
+ notificationId: json.notificationId,
39
+ baseUrl: json.baseUrl,
40
+ tokenId: json.tokenId,
41
+ };
42
+ return result;
43
+ }
44
+ catch (e) {
45
+ if (getIsDebug()) {
46
+ console.error(e);
47
+ }
48
+ return null;
49
+ }
50
+ }
51
+ // Primary function (new name)
52
+ export function assemblyApi({ apiKey, token: tokenString, }) {
53
+ const isDebug = getIsDebug();
54
+ const envMode = getEnvMode();
55
+ let key = ['local', '__SECRET_STAGING__'].includes(envMode !== null && envMode !== void 0 ? envMode : '')
56
+ ? apiKey
57
+ : undefined;
58
+ if (isDebug) {
59
+ console.log('Debugging the assemblyApi init script.');
60
+ console.log({ env: envMode });
61
+ }
62
+ if (tokenString) {
63
+ if (isDebug) {
64
+ console.log({ tokenString, apiKey });
65
+ }
66
+ try {
67
+ const decipherKey = generate128BitKey(apiKey);
68
+ const decryptedPayload = decryptAES128BitToken(decipherKey, tokenString);
69
+ if (isDebug) {
70
+ console.log('Decrypted Payload:', decryptedPayload);
71
+ }
72
+ const payload = processToken(decryptedPayload);
73
+ if (!payload) {
74
+ throw new Error('Invalid token payload.');
75
+ }
76
+ if (isDebug) {
77
+ console.log('Payload:', payload);
78
+ }
79
+ if (payload.baseUrl) {
80
+ OpenAPI.BASE = payload.baseUrl;
81
+ }
82
+ sdk.getTokenPayload = () => new Promise((resolve) => resolve(payload));
83
+ // Build the key: workspaceId/apiKey or workspaceId/apiKey/tokenId if tokenId is present
84
+ key = payload.tokenId
85
+ ? `${payload.workspaceId}/${apiKey}/${payload.tokenId}`
86
+ : `${payload.workspaceId}/${apiKey}`;
87
+ }
88
+ catch (error) {
89
+ console.error(error);
90
+ }
91
+ }
92
+ if (!key) {
93
+ console.warn('We were unable to authorize the SDK. If you are working in a local development environment, set the ASSEMBLY_ENV environment variable to "local" (COPILOT_ENV also works).');
94
+ throw new Error('Unable to authorize Assembly SDK.');
95
+ }
96
+ if (isDebug) {
97
+ console.log(`Authorizing with key: ${key}`);
98
+ }
99
+ OpenAPI.HEADERS = {
100
+ 'X-API-Key': key,
101
+ 'X-Assembly-SDK-Version': SDK_VERSION,
102
+ };
103
+ sdk.sendWebhook = (event, payload) => {
104
+ return __request(OpenAPI, {
105
+ method: 'POST',
106
+ url: '/v1/webhooks/{event}',
107
+ path: { event },
108
+ body: payload,
109
+ mediaType: 'application/json',
110
+ });
111
+ };
112
+ return sdk;
113
+ }
114
+ /** @deprecated Use `assemblyApi` instead. Will be removed in v5.0.0. */
115
+ export const copilotApi = assemblyApi;
116
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../api/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,IAAI,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,yCAAyC;AACzC,2DAA2D;AAC3D,MAAM,WAAW,GAAG,QAAQ,CAAC;AAwB7B,MAAM,GAAG,GAAgB,QAAuB,CAAC;AAEj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ter) ||
4
+ function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) {
6
+ return value instanceof P
7
+ ? value
8
+ : new P(function (resolve) {
9
+ resolve(value);
10
+ });
11
+ }
12
+ return new (P || (P = Promise))(function (resolve, reject) {
13
+ function fulfilled(value) {
14
+ try {
15
+ step(generator.next(value));
16
+ } catch (e) {
17
+ reject(e);
18
+ }
19
+ }
20
+ function rejected(value) {
21
+ try {
22
+ step(generator['throw'](value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ }
27
+ function step(result) {
28
+ result.done
29
+ ? resolve(result.value)
30
+ : adopt(result.value).then(fulfilled, rejected);
31
+ }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ import process from 'process';
36
+ import { decodeToken } from '../utils/tokenDecoder.js';
37
+ function parseArguments() {
38
+ const args = process.argv.slice(2);
39
+ const options = {};
40
+ for (let i = 0; i < args.length; i++) {
41
+ const arg = args[i];
42
+ switch (arg) {
43
+ case '--json':
44
+ case '-j':
45
+ options.json = true;
46
+ break;
47
+ case '--verbose':
48
+ case '-v':
49
+ options.verbose = true;
50
+ break;
51
+ case '--help':
52
+ case '-h':
53
+ options.help = true;
54
+ break;
55
+ case '--api-key':
56
+ case '-k':
57
+ if (i + 1 < args.length) {
58
+ options.apiKey = args[++i];
59
+ } else {
60
+ console.error('Error: --api-key requires a value');
61
+ process.exit(1);
62
+ }
63
+ break;
64
+ default:
65
+ if (!arg.startsWith('-')) {
66
+ if (!options.token) {
67
+ options.token = arg;
68
+ } else if (!options.apiKey) {
69
+ options.apiKey = arg;
70
+ }
71
+ } else {
72
+ console.error(`Error: Unknown option ${arg}`);
73
+ process.exit(1);
74
+ }
75
+ }
76
+ }
77
+ return options;
78
+ }
79
+ function showHelp() {
80
+ const help = `
81
+ Copilot Token Decoder
82
+
83
+ Decodes and validates Copilot tokens for debugging and testing purposes.
84
+
85
+ USAGE:
86
+ copilot-decode-token <token> <api-key> [options]
87
+ copilot-decode-token --api-key <api-key> [options] < token_file
88
+ echo "<token>" | copilot-decode-token --api-key <api-key> [options]
89
+
90
+ ARGUMENTS:
91
+ token The encrypted token string to decode
92
+ api-key The API key used for token decryption
93
+
94
+ OPTIONS:
95
+ -k, --api-key <key> API key for decryption (alternative to positional arg)
96
+ -j, --json Output result as JSON
97
+ -v, --verbose Enable verbose debug output
98
+ -h, --help Show this help message
99
+
100
+ EXAMPLES:
101
+ # Basic usage
102
+ copilot-decode-token "abc123..." "api_key_123"
103
+
104
+ # JSON output for scripting
105
+ copilot-decode-token --json "abc123..." "api_key_123"
106
+
107
+ # Verbose mode for debugging
108
+ copilot-decode-token --verbose "abc123..." "api_key_123"
109
+
110
+ # Read from stdin
111
+ echo "abc123..." | copilot-decode-token --api-key "api_key_123"
112
+
113
+ # From file
114
+ cat token.txt | copilot-decode-token --api-key "api_key_123" --json
115
+
116
+ OUTPUT:
117
+ The decoded token will show:
118
+ - workspaceId: The workspace identifier (required)
119
+ - companyId: The company context (optional)
120
+ - clientId: The client context (optional)
121
+ - internalUserId: The internal user context (optional)
122
+ - notificationId: The notification context (optional)
123
+ `;
124
+ console.log(help);
125
+ }
126
+ function readStdin() {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ return new Promise((resolve, reject) => {
129
+ let data = '';
130
+ process.stdin.setEncoding('utf8');
131
+ process.stdin.on('data', (chunk) => {
132
+ data += chunk;
133
+ });
134
+ process.stdin.on('end', () => {
135
+ resolve(data.trim());
136
+ });
137
+ process.stdin.on('error', reject);
138
+ });
139
+ });
140
+ }
141
+ function formatOutput(result, options) {
142
+ if (options.json) {
143
+ console.log(JSON.stringify(result, null, 2));
144
+ } else {
145
+ if (result.success) {
146
+ console.log('✅ Token decoded successfully');
147
+ console.log();
148
+ console.log('Token Details:');
149
+ console.log(' Workspace ID:', result.token.workspaceId);
150
+ if (result.token.companyId) {
151
+ console.log(' Company ID: ', result.token.companyId);
152
+ }
153
+ if (result.token.clientId) {
154
+ console.log(' Client ID: ', result.token.clientId);
155
+ }
156
+ if (result.token.internalUserId) {
157
+ console.log(' Internal User ID:', result.token.internalUserId);
158
+ }
159
+ if (result.token.notificationId) {
160
+ console.log(' Notification ID: ', result.token.notificationId);
161
+ }
162
+ if (options.verbose && result.rawPayload) {
163
+ console.log();
164
+ console.log('Raw Payload:');
165
+ console.log(' ', result.rawPayload);
166
+ }
167
+ } else {
168
+ console.log('❌ Token decoding failed');
169
+ console.log();
170
+ console.log('Error:', result.error);
171
+ if (options.verbose && result.rawPayload) {
172
+ console.log();
173
+ console.log('Raw Payload:');
174
+ console.log(' ', result.rawPayload);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ function main() {
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ const options = parseArguments();
182
+ if (options.help) {
183
+ showHelp();
184
+ return;
185
+ }
186
+ // Set debug mode based on verbose flag
187
+ if (options.verbose) {
188
+ process.env.COPILOT_DEBUG = '1';
189
+ }
190
+ let token = options.token;
191
+ const apiKey = options.apiKey;
192
+ // Read from stdin if no token provided as argument
193
+ if (!token) {
194
+ if (process.stdin.isTTY) {
195
+ console.error(
196
+ 'Error: No token provided. Use --help for usage information.',
197
+ );
198
+ process.exit(1);
199
+ }
200
+ try {
201
+ token = yield readStdin();
202
+ } catch (error) {
203
+ console.error('Error reading from stdin:', error);
204
+ process.exit(1);
205
+ }
206
+ }
207
+ if (!token) {
208
+ console.error('Error: Token is required');
209
+ process.exit(1);
210
+ }
211
+ if (!apiKey) {
212
+ console.error('Error: API key is required');
213
+ process.exit(1);
214
+ }
215
+ // Decode the token
216
+ const result = decodeToken(token, apiKey, options.verbose);
217
+ // Format and output the result
218
+ formatOutput(result, options);
219
+ // Exit with appropriate code
220
+ process.exit(result.success ? 0 : 1);
221
+ });
222
+ }
223
+ // Handle unhandled promise rejections
224
+ process.on('unhandledRejection', (reason, promise) => {
225
+ console.error('Unhandled Rejection at:', promise, 'reason:', reason);
226
+ process.exit(1);
227
+ });
228
+ // Handle uncaught exceptions
229
+ process.on('uncaughtException', (error) => {
230
+ console.error('Uncaught Exception:', error);
231
+ process.exit(1);
232
+ });
233
+ // Run the main function
234
+ main().catch((error) => {
235
+ console.error('Fatal error:', error);
236
+ process.exit(1);
237
+ });
238
+ //# sourceMappingURL=decode-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-token.js","sourceRoot":"","sources":["../../bin/decode-token.ts"],"names":[],"mappings":";;;;;;;;;;AAEA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAUvD,SAAS,cAAc;IACrB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAe,EAAE,CAAC;IAE/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEpB,QAAQ,GAAG,EAAE;YACX,KAAK,QAAQ,CAAC;YACd,KAAK,IAAI;gBACP,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;gBACpB,MAAM;YAER,KAAK,WAAW,CAAC;YACjB,KAAK,IAAI;gBACP,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;gBACvB,MAAM;YAER,KAAK,QAAQ,CAAC;YACd,KAAK,IAAI;gBACP,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;gBACpB,MAAM;YAER,KAAK,WAAW,CAAC;YACjB,KAAK,IAAI;gBACP,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE;oBACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;iBAC5B;qBAAM;oBACL,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;oBACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,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0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ // Load the HTTP monitor
4
+ require('../test/setupHttpMonitor');
5
+ // Run the original script
6
+ require(process.argv[2]);
7
+ //# sourceMappingURL=run-with-http-monitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-with-http-monitor.js","sourceRoot":"","sources":["../../bin/run-with-http-monitor.js"],"names":[],"mappings":";;AAEA,wBAAwB;AACxB,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAEpC,0BAA0B;AAC1B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ import type { ApiResult } from './ApiResult';
3
+ export declare class ApiError extends Error {
4
+ readonly url: string;
5
+ readonly status: number;
6
+ readonly statusText: string;
7
+ readonly body: any;
8
+ readonly request: ApiRequestOptions;
9
+ constructor(request: ApiRequestOptions, response: ApiResult, message: string);
10
+ }
@@ -0,0 +1,12 @@
1
+ export class ApiError extends Error {
2
+ constructor(request, response, message) {
3
+ super(message);
4
+ this.name = 'ApiError';
5
+ this.url = response.url;
6
+ this.status = response.status;
7
+ this.statusText = response.statusText;
8
+ this.body = response.body;
9
+ this.request = request;
10
+ }
11
+ }
12
+ //# sourceMappingURL=ApiError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiError.js","sourceRoot":"","sources":["../../../../codegen/api/core/ApiError.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAO/B,YAAY,OAA0B,EAAE,QAAmB,EAAE,OAAe;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;CACJ"}
@@ -0,0 +1,20 @@
1
+ export type ApiRequestOptions = {
2
+ readonly method:
3
+ | 'GET'
4
+ | 'PUT'
5
+ | 'POST'
6
+ | 'DELETE'
7
+ | 'OPTIONS'
8
+ | 'HEAD'
9
+ | 'PATCH';
10
+ readonly url: string;
11
+ readonly path?: Record<string, any>;
12
+ readonly cookies?: Record<string, any>;
13
+ readonly headers?: Record<string, any>;
14
+ readonly query?: Record<string, any>;
15
+ readonly formData?: Record<string, any>;
16
+ readonly body?: any;
17
+ readonly mediaType?: string;
18
+ readonly responseHeader?: string;
19
+ readonly errors?: Record<number, string>;
20
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ApiRequestOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiRequestOptions.js","sourceRoot":"","sources":["../../../../codegen/api/core/ApiRequestOptions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export type ApiResult = {
2
+ readonly url: string;
3
+ readonly ok: boolean;
4
+ readonly status: number;
5
+ readonly statusText: string;
6
+ readonly body: any;
7
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ApiResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiResult.js","sourceRoot":"","sources":["../../../../codegen/api/core/ApiResult.ts"],"names":[],"mappings":""}