@major-tech/resource-client 0.2.36 → 0.2.40
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/bin/generate-clients.mjs +128 -28
- package/dist/base.cjs +7 -1
- package/dist/base.cjs.map +2 -2
- package/dist/base.d.ts +4 -2
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +7 -1
- package/dist/base.js.map +1 -1
- package/package.json +1 -1
package/bin/generate-clients.mjs
CHANGED
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
* Part of @major-tech/resource-client
|
|
5
5
|
*
|
|
6
6
|
* Usage:
|
|
7
|
-
* npx @major-tech/resource-client add <resource_id> <name> <type> <description> <application_id>
|
|
8
|
-
* npx @major-tech/resource-client
|
|
7
|
+
* npx @major-tech/resource-client add <resource_id> <name> <type> <description> <application_id> [--mode app]
|
|
8
|
+
* npx @major-tech/resource-client add <resource_id> <name> <type> <description> --mode tool
|
|
9
|
+
* npx @major-tech/resource-client remove <name> [--mode <app|tool>]
|
|
9
10
|
* npx @major-tech/resource-client list
|
|
10
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Modes: app (default) | tool
|
|
11
13
|
* Types: postgresql | mssql | dynamodb | cosmosdb | snowflake | bigquery | neo4j | hubspot | googlesheets | outreach | custom | graphql | lambda | salesforce | s3 | slack | majorauth | googleanalytics | quickbooks
|
|
12
|
-
*
|
|
14
|
+
*
|
|
13
15
|
* Examples:
|
|
14
16
|
* npx @major-tech/resource-client add "abc-123" "orders-db" "postgresql" "Orders database" "app-123"
|
|
17
|
+
* npx @major-tech/resource-client add "abc-123" "orders-db" "postgresql" "Orders database" --mode tool
|
|
15
18
|
* npx @major-tech/resource-client add "xyz-789" "payment-api" "custom" "Payment API" "app-456"
|
|
16
19
|
* npx @major-tech/resource-client remove "orders-db"
|
|
17
20
|
* npx @major-tech/resource-client list
|
|
@@ -37,9 +40,9 @@ function getClientsDir() {
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
|
-
* Client template
|
|
43
|
+
* Client template for app mode
|
|
41
44
|
*/
|
|
42
|
-
function
|
|
45
|
+
function clientTemplateApp(data, framework) {
|
|
43
46
|
const isNextJs = framework === 'nextjs';
|
|
44
47
|
|
|
45
48
|
const imports = [
|
|
@@ -59,11 +62,11 @@ function clientTemplate(data, framework) {
|
|
|
59
62
|
|
|
60
63
|
/**
|
|
61
64
|
* ${data.description}
|
|
62
|
-
*
|
|
65
|
+
*
|
|
63
66
|
* Type: ${data.type}
|
|
64
67
|
* Resource ID: ${data.resourceId}
|
|
65
68
|
* Application ID: ${data.applicationId}
|
|
66
|
-
*
|
|
69
|
+
*
|
|
67
70
|
* DO NOT EDIT - Auto-generated by @major-tech/resource-client
|
|
68
71
|
*/
|
|
69
72
|
|
|
@@ -91,6 +94,50 @@ export const ${data.clientName} = ${data.clientName}Singleton.getInstance();
|
|
|
91
94
|
`;
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Client template for tool mode
|
|
99
|
+
*/
|
|
100
|
+
function clientTemplateTool(data) {
|
|
101
|
+
const factoryName = 'create' + data.clientName.charAt(0).toUpperCase() + data.clientName.slice(1);
|
|
102
|
+
return `import { ${data.clientClass} } from '@major-tech/resource-client';
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* ${data.description}
|
|
106
|
+
*
|
|
107
|
+
* Type: ${data.type}
|
|
108
|
+
* Resource ID: ${data.resourceId}
|
|
109
|
+
* Tool ID: ${data.toolId}
|
|
110
|
+
*
|
|
111
|
+
* DO NOT EDIT - Auto-generated by @major-tech/resource-client (tool mode)
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
interface ToolContext {
|
|
115
|
+
resourceApiUrl: string;
|
|
116
|
+
majorJwtToken: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function ${factoryName}(context: ToolContext): ${data.clientClass} {
|
|
120
|
+
return new ${data.clientClass}({
|
|
121
|
+
baseUrl: context.resourceApiUrl,
|
|
122
|
+
majorJwtToken: context.majorJwtToken,
|
|
123
|
+
toolId: '${data.toolId}',
|
|
124
|
+
resourceId: '${data.resourceId}',
|
|
125
|
+
fetch: (...args: Parameters<typeof fetch>) => fetch(...args),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Client template dispatcher
|
|
133
|
+
*/
|
|
134
|
+
function clientTemplate(data, framework, mode) {
|
|
135
|
+
if (mode === 'tool') {
|
|
136
|
+
return clientTemplateTool(data);
|
|
137
|
+
}
|
|
138
|
+
return clientTemplateApp(data, framework);
|
|
139
|
+
}
|
|
140
|
+
|
|
94
141
|
/**
|
|
95
142
|
* Index template
|
|
96
143
|
*/
|
|
@@ -163,18 +210,39 @@ function getClientClass(type) {
|
|
|
163
210
|
return typeMap[type] || 'PostgresResourceClient';
|
|
164
211
|
}
|
|
165
212
|
|
|
166
|
-
function
|
|
213
|
+
function readToolId() {
|
|
214
|
+
const toolJsonPath = path.join(projectRoot, 'tool.json');
|
|
215
|
+
if (!fs.existsSync(toolJsonPath)) {
|
|
216
|
+
console.error('❌ tool.json not found in project root. Run this from your tool directory.');
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
const toolJson = JSON.parse(fs.readFileSync(toolJsonPath, 'utf-8'));
|
|
220
|
+
if (!toolJson.id) {
|
|
221
|
+
console.error('❌ tool.json is missing an "id" field.');
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
return toolJson.id;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function generateClientFile(resource, framework, mode) {
|
|
167
228
|
const clientName = toCamelCase(resource.name) + 'Client';
|
|
168
229
|
const clientClass = getClientClass(resource.type);
|
|
230
|
+
const effectiveMode = resource.mode === 'tool' ? 'tool' : mode;
|
|
169
231
|
|
|
170
|
-
|
|
232
|
+
const data = {
|
|
171
233
|
clientClass,
|
|
172
234
|
description: resource.description,
|
|
173
235
|
type: resource.type,
|
|
174
236
|
resourceId: resource.id,
|
|
175
237
|
applicationId: resource.applicationId,
|
|
176
238
|
clientName,
|
|
177
|
-
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
if (effectiveMode === 'tool') {
|
|
242
|
+
data.toolId = readToolId();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return clientTemplate(data, framework, effectiveMode);
|
|
178
246
|
}
|
|
179
247
|
|
|
180
248
|
function generateIndexFile(resources) {
|
|
@@ -185,13 +253,17 @@ function generateIndexFile(resources) {
|
|
|
185
253
|
const exports = resources.map(resource => {
|
|
186
254
|
const clientName = toCamelCase(resource.name) + 'Client';
|
|
187
255
|
const fileName = toCamelCase(resource.name);
|
|
256
|
+
if (resource.mode === 'tool') {
|
|
257
|
+
const factoryName = 'create' + clientName.charAt(0).toUpperCase() + clientName.slice(1);
|
|
258
|
+
return `export { ${factoryName} } from './${fileName}';`;
|
|
259
|
+
}
|
|
188
260
|
return `export { ${clientName} } from './${fileName}';`;
|
|
189
261
|
});
|
|
190
262
|
|
|
191
263
|
return indexTemplate({ exports });
|
|
192
264
|
}
|
|
193
265
|
|
|
194
|
-
function addResource(resourceId, name, type, description, applicationId, framework) {
|
|
266
|
+
function addResource(resourceId, name, type, description, applicationId, framework, mode) {
|
|
195
267
|
const validTypes = ['postgresql', 'mssql', 'dynamodb', 'cosmosdb', 'snowflake', 'bigquery', 'neo4j', 'hubspot', 'googlesheets', 'outreach', 'custom', 'graphql', 'lambda', 'salesforce', 's3', 'slack', 'majorauth', 'googleanalytics', 'quickbooks'];
|
|
196
268
|
if (!validTypes.includes(type)) {
|
|
197
269
|
console.error(`❌ Invalid type: ${type}`);
|
|
@@ -200,7 +272,7 @@ function addResource(resourceId, name, type, description, applicationId, framewo
|
|
|
200
272
|
process.exit(1);
|
|
201
273
|
}
|
|
202
274
|
|
|
203
|
-
if (!applicationId) {
|
|
275
|
+
if (mode !== 'tool' && !applicationId) {
|
|
204
276
|
console.error('❌ Application ID is required');
|
|
205
277
|
process.exit(1);
|
|
206
278
|
}
|
|
@@ -218,7 +290,7 @@ function addResource(resourceId, name, type, description, applicationId, framewo
|
|
|
218
290
|
name,
|
|
219
291
|
type,
|
|
220
292
|
description,
|
|
221
|
-
applicationId
|
|
293
|
+
...(mode === 'tool' ? { mode: 'tool' } : { applicationId }),
|
|
222
294
|
};
|
|
223
295
|
|
|
224
296
|
resources.push(newResource);
|
|
@@ -228,13 +300,13 @@ function addResource(resourceId, name, type, description, applicationId, framewo
|
|
|
228
300
|
console.log(` Type: ${type}`);
|
|
229
301
|
console.log(` ID: ${resourceId}`);
|
|
230
302
|
|
|
231
|
-
regenerateClients(resources, framework);
|
|
303
|
+
regenerateClients(resources, framework, mode);
|
|
232
304
|
}
|
|
233
305
|
|
|
234
306
|
/**
|
|
235
307
|
* Remove a resource by name
|
|
236
308
|
*/
|
|
237
|
-
function removeResource(name, framework) {
|
|
309
|
+
function removeResource(name, framework, mode) {
|
|
238
310
|
const resources = loadResources();
|
|
239
311
|
const index = resources.findIndex(r => r.name === name);
|
|
240
312
|
|
|
@@ -249,7 +321,7 @@ function removeResource(name, framework) {
|
|
|
249
321
|
console.log(`✅ Removed resource: ${removed.name}`);
|
|
250
322
|
console.log(` ID: ${removed.id}`);
|
|
251
323
|
|
|
252
|
-
regenerateClients(resources, framework);
|
|
324
|
+
regenerateClients(resources, framework, mode);
|
|
253
325
|
}
|
|
254
326
|
|
|
255
327
|
/**
|
|
@@ -275,7 +347,7 @@ function listResources() {
|
|
|
275
347
|
/**
|
|
276
348
|
* Regenerate all client files
|
|
277
349
|
*/
|
|
278
|
-
function regenerateClients(resources, framework) {
|
|
350
|
+
function regenerateClients(resources, framework, mode) {
|
|
279
351
|
const clientsDir = getClientsDir();
|
|
280
352
|
|
|
281
353
|
// Ensure clients directory exists
|
|
@@ -293,7 +365,7 @@ function regenerateClients(resources, framework) {
|
|
|
293
365
|
resources.forEach(resource => {
|
|
294
366
|
const fileName = toCamelCase(resource.name) + '.ts';
|
|
295
367
|
const filePath = path.join(clientsDir, fileName);
|
|
296
|
-
const code = generateClientFile(resource, framework);
|
|
368
|
+
const code = generateClientFile(resource, framework, mode);
|
|
297
369
|
fs.writeFileSync(filePath, code, 'utf-8');
|
|
298
370
|
});
|
|
299
371
|
|
|
@@ -324,24 +396,52 @@ function main() {
|
|
|
324
396
|
args.splice(frameworkIndex, 2);
|
|
325
397
|
}
|
|
326
398
|
|
|
399
|
+
// Extract --mode flag (app | tool, default: app)
|
|
400
|
+
const modeIndex = args.indexOf('--mode');
|
|
401
|
+
let mode = 'app';
|
|
402
|
+
if (modeIndex !== -1 && args[modeIndex + 1]) {
|
|
403
|
+
mode = args[modeIndex + 1];
|
|
404
|
+
// Remove --mode and its value from args
|
|
405
|
+
args.splice(modeIndex, 2);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (mode !== 'app' && mode !== 'tool') {
|
|
409
|
+
console.error(`❌ Invalid mode: ${mode}. Must be "app" or "tool".`);
|
|
410
|
+
process.exit(1);
|
|
411
|
+
}
|
|
412
|
+
|
|
327
413
|
if (!command) {
|
|
328
414
|
console.log('Usage:');
|
|
329
|
-
console.log(' npx @major-tech/resource-client add <resource_id> <name> <type> <description> <application_id> [--framework <nextjs|vite>]');
|
|
330
|
-
console.log(' npx @major-tech/resource-client
|
|
415
|
+
console.log(' npx @major-tech/resource-client add <resource_id> <name> <type> <description> <application_id> [--framework <nextjs|vite>] [--mode <app|tool>]');
|
|
416
|
+
console.log(' npx @major-tech/resource-client add <resource_id> <name> <type> <description> --mode tool');
|
|
417
|
+
console.log(' npx @major-tech/resource-client remove <name> [--framework <nextjs|vite>] [--mode <app|tool>]');
|
|
331
418
|
console.log(' npx @major-tech/resource-client list');
|
|
419
|
+
console.log('\nModes: app (default) | tool');
|
|
420
|
+
console.log(' app — requires <application_id>, reads MAJOR_API_BASE_URL');
|
|
421
|
+
console.log(' tool — embeds toolId from tool.json at generation time, reads RESOURCE_API_URL');
|
|
332
422
|
console.log('\nTypes: postgresql | mssql | dynamodb | cosmosdb | snowflake | bigquery | neo4j | hubspot | googlesheets | outreach | custom | graphql | lambda | salesforce | s3 | slack | majorauth | googleanalytics | quickbooks');
|
|
333
423
|
return;
|
|
334
424
|
}
|
|
335
425
|
|
|
336
426
|
switch (command) {
|
|
337
427
|
case 'add': {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
428
|
+
if (mode === 'tool') {
|
|
429
|
+
const [, resourceId, name, type, description] = args;
|
|
430
|
+
if (!resourceId || !name || !type || !description) {
|
|
431
|
+
console.error('❌ Missing arguments');
|
|
432
|
+
console.log('Usage: add <resource_id> <name> <type> <description> --mode tool');
|
|
433
|
+
process.exit(1);
|
|
434
|
+
}
|
|
435
|
+
addResource(resourceId, name, type, description, null, framework, mode);
|
|
436
|
+
} else {
|
|
437
|
+
const [, resourceId, name, type, description, applicationId] = args;
|
|
438
|
+
if (!resourceId || !name || !type || !description || !applicationId) {
|
|
439
|
+
console.error('❌ Missing arguments');
|
|
440
|
+
console.log('Usage: add <resource_id> <name> <type> <description> <application_id> [--framework <nextjs|vite>]');
|
|
441
|
+
process.exit(1);
|
|
442
|
+
}
|
|
443
|
+
addResource(resourceId, name, type, description, applicationId, framework, mode);
|
|
343
444
|
}
|
|
344
|
-
addResource(resourceId, name, type, description, applicationId, framework);
|
|
345
445
|
break;
|
|
346
446
|
}
|
|
347
447
|
|
|
@@ -351,7 +451,7 @@ function main() {
|
|
|
351
451
|
console.error('❌ Missing name');
|
|
352
452
|
process.exit(1);
|
|
353
453
|
}
|
|
354
|
-
removeResource(name, framework);
|
|
454
|
+
removeResource(name, framework, mode);
|
|
355
455
|
break;
|
|
356
456
|
}
|
|
357
457
|
|
package/dist/base.cjs
CHANGED
|
@@ -29,17 +29,23 @@ class BaseResourceClient {
|
|
|
29
29
|
}
|
|
30
30
|
config;
|
|
31
31
|
constructor(config) {
|
|
32
|
+
if (!config.applicationId && !config.toolId) {
|
|
33
|
+
throw new Error("BaseResourceClient requires either applicationId or toolId");
|
|
34
|
+
}
|
|
32
35
|
this.config = {
|
|
33
36
|
baseUrl: config.baseUrl.replace(/\/$/, ""),
|
|
34
37
|
majorJwtToken: config.majorJwtToken,
|
|
35
38
|
applicationId: config.applicationId,
|
|
39
|
+
toolId: config.toolId,
|
|
36
40
|
resourceId: config.resourceId,
|
|
37
41
|
fetch: config.fetch || globalThis.fetch,
|
|
38
42
|
getHeaders: config.getHeaders
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
45
|
async invokeRaw(payload, invocationKey) {
|
|
42
|
-
const
|
|
46
|
+
const entityType = this.config.toolId ? "tools" : "apps";
|
|
47
|
+
const entityId = this.config.toolId || this.config.applicationId;
|
|
48
|
+
const url = `${this.config.baseUrl}/internal/${entityType}/v1/${entityId}/resource/${this.config.resourceId}/invoke`;
|
|
43
49
|
const body = {
|
|
44
50
|
payload,
|
|
45
51
|
invocationKey
|
package/dist/base.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/base.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n ResourceInvokePayload,\n InvokeResponse,\n InvokeRequest,\n} from \"./schemas\";\nimport { ResourceInvokeError } from \"./errors\";\n\nexport interface BaseClientConfig {\n baseUrl: string;\n majorJwtToken?: string;\n applicationId
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAKA;;;;;AAAA,oBAAoC;
|
|
4
|
+
"sourcesContent": ["import type {\n ResourceInvokePayload,\n InvokeResponse,\n InvokeRequest,\n} from \"./schemas\";\nimport { ResourceInvokeError } from \"./errors\";\n\nexport interface BaseClientConfig {\n baseUrl: string;\n majorJwtToken?: string;\n applicationId?: string; // For app mode\n toolId?: string; // For tool mode \u2014 mutually exclusive with applicationId\n resourceId: string;\n fetch?: typeof fetch;\n /**\n * Optional function to get additional headers (e.g. for auth)\n * Useful for Next.js Server Components where headers() must be called dynamically\n */\n getHeaders?: () => Promise<Record<string, string>> | Record<string, string>;\n}\n\nexport abstract class BaseResourceClient {\n protected readonly config: {\n baseUrl: string;\n majorJwtToken?: string;\n applicationId?: string;\n toolId?: string;\n resourceId: string;\n fetch: typeof fetch;\n getHeaders?: () => Promise<Record<string, string>> | Record<string, string>;\n };\n\n constructor(config: BaseClientConfig) {\n if (!config.applicationId && !config.toolId) {\n throw new Error(\"BaseResourceClient requires either applicationId or toolId\");\n }\n\n this.config = {\n baseUrl: config.baseUrl.replace(/\\/$/, \"\"),\n majorJwtToken: config.majorJwtToken,\n applicationId: config.applicationId,\n toolId: config.toolId,\n resourceId: config.resourceId,\n fetch: config.fetch || globalThis.fetch,\n getHeaders: config.getHeaders,\n };\n }\n\n protected async invokeRaw(\n payload: ResourceInvokePayload,\n invocationKey: string,\n ): Promise<InvokeResponse> {\n const entityType = this.config.toolId ? \"tools\" : \"apps\";\n const entityId = this.config.toolId || this.config.applicationId;\n const url = `${this.config.baseUrl}/internal/${entityType}/v1/${entityId}/resource/${this.config.resourceId}/invoke`;\n \n const body: InvokeRequest = {\n payload,\n invocationKey,\n };\n\n let headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (this.config.majorJwtToken) {\n headers[\"x-major-jwt\"] = this.config.majorJwtToken;\n }\n\n if (this.config.getHeaders) {\n const extraHeaders = await this.config.getHeaders();\n headers = { ...headers, ...extraHeaders };\n }\n\n try {\n const response = await this.config.fetch(url, {\n method: \"POST\",\n headers,\n credentials: \"include\",\n body: JSON.stringify(body),\n });\n\n const data = await response.json();\n return data as InvokeResponse;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new ResourceInvokeError(`Failed to invoke resource: ${message}`);\n }\n }\n}\n\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAKA;;;;;AAAA,oBAAoC;AAgB9B,MAAgB,mBAAk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
|
|
2
2
|
export interface BaseClientConfig {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
majorJwtToken?: string;
|
|
5
|
-
applicationId
|
|
5
|
+
applicationId?: string;
|
|
6
|
+
toolId?: string;
|
|
6
7
|
resourceId: string;
|
|
7
8
|
fetch?: typeof fetch;
|
|
8
9
|
/**
|
|
@@ -15,7 +16,8 @@ export declare abstract class BaseResourceClient {
|
|
|
15
16
|
protected readonly config: {
|
|
16
17
|
baseUrl: string;
|
|
17
18
|
majorJwtToken?: string;
|
|
18
|
-
applicationId
|
|
19
|
+
applicationId?: string;
|
|
20
|
+
toolId?: string;
|
|
19
21
|
resourceId: string;
|
|
20
22
|
fetch: typeof fetch;
|
|
21
23
|
getHeaders?: () => Promise<Record<string, string>> | Record<string, string>;
|
package/dist/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EAEf,MAAM,WAAW,CAAC;AAGnB,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EAEf,MAAM,WAAW,CAAC;AAGnB,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7E;AAED,8BAAsB,kBAAkB;IACtC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC7E,CAAC;gBAEU,MAAM,EAAE,gBAAgB;cAgBpB,SAAS,CACvB,OAAO,EAAE,qBAAqB,EAC9B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,CAAC;CAsC3B"}
|
package/dist/base.js
CHANGED
|
@@ -2,17 +2,23 @@ import { ResourceInvokeError } from "./errors";
|
|
|
2
2
|
export class BaseResourceClient {
|
|
3
3
|
config;
|
|
4
4
|
constructor(config) {
|
|
5
|
+
if (!config.applicationId && !config.toolId) {
|
|
6
|
+
throw new Error("BaseResourceClient requires either applicationId or toolId");
|
|
7
|
+
}
|
|
5
8
|
this.config = {
|
|
6
9
|
baseUrl: config.baseUrl.replace(/\/$/, ""),
|
|
7
10
|
majorJwtToken: config.majorJwtToken,
|
|
8
11
|
applicationId: config.applicationId,
|
|
12
|
+
toolId: config.toolId,
|
|
9
13
|
resourceId: config.resourceId,
|
|
10
14
|
fetch: config.fetch || globalThis.fetch,
|
|
11
15
|
getHeaders: config.getHeaders,
|
|
12
16
|
};
|
|
13
17
|
}
|
|
14
18
|
async invokeRaw(payload, invocationKey) {
|
|
15
|
-
const
|
|
19
|
+
const entityType = this.config.toolId ? "tools" : "apps";
|
|
20
|
+
const entityId = this.config.toolId || this.config.applicationId;
|
|
21
|
+
const url = `${this.config.baseUrl}/internal/${entityType}/v1/${entityId}/resource/${this.config.resourceId}/invoke`;
|
|
16
22
|
const body = {
|
|
17
23
|
payload,
|
|
18
24
|
invocationKey,
|
package/dist/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAgB/C,MAAM,OAAgB,kBAAkB;IACnB,MAAM,CAQvB;IAEF,YAAY,MAAwB;QAClC,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,CAAC;QAED,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;YAC1C,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK;YACvC,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,SAAS,CACvB,OAA8B,EAC9B,aAAqB;QAErB,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;QACzD,MAAM,QAAQ,GAAG,IAAI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