@major-tech/resource-client 0.2.36 → 0.2.38
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 +131 -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,57 @@ 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
|
+
return `import { ${data.clientClass} } from '@major-tech/resource-client';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* ${data.description}
|
|
105
|
+
*
|
|
106
|
+
* Type: ${data.type}
|
|
107
|
+
* Resource ID: ${data.resourceId}
|
|
108
|
+
* Tool ID: ${data.toolId}
|
|
109
|
+
*
|
|
110
|
+
* DO NOT EDIT - Auto-generated by @major-tech/resource-client (tool mode)
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
const TOOL_ID = '${data.toolId}';
|
|
114
|
+
const BASE_URL = process.env.RESOURCE_API_URL || 'https://go-api.prod.major.build';
|
|
115
|
+
const MAJOR_JWT_TOKEN = process.env.MAJOR_JWT_TOKEN;
|
|
116
|
+
|
|
117
|
+
class ${data.clientName}Singleton {
|
|
118
|
+
private static instance: ${data.clientClass} | null = null;
|
|
119
|
+
|
|
120
|
+
static getInstance(): ${data.clientClass} {
|
|
121
|
+
if (!${data.clientName}Singleton.instance) {
|
|
122
|
+
${data.clientName}Singleton.instance = new ${data.clientClass}({
|
|
123
|
+
baseUrl: BASE_URL,
|
|
124
|
+
majorJwtToken: MAJOR_JWT_TOKEN,
|
|
125
|
+
toolId: TOOL_ID,
|
|
126
|
+
resourceId: '${data.resourceId}',
|
|
127
|
+
fetch: (...args) => fetch(...args),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return ${data.clientName}Singleton.instance;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const ${data.clientName} = ${data.clientName}Singleton.getInstance();
|
|
135
|
+
`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Client template dispatcher
|
|
140
|
+
*/
|
|
141
|
+
function clientTemplate(data, framework, mode) {
|
|
142
|
+
if (mode === 'tool') {
|
|
143
|
+
return clientTemplateTool(data);
|
|
144
|
+
}
|
|
145
|
+
return clientTemplateApp(data, framework);
|
|
146
|
+
}
|
|
147
|
+
|
|
94
148
|
/**
|
|
95
149
|
* Index template
|
|
96
150
|
*/
|
|
@@ -163,18 +217,39 @@ function getClientClass(type) {
|
|
|
163
217
|
return typeMap[type] || 'PostgresResourceClient';
|
|
164
218
|
}
|
|
165
219
|
|
|
166
|
-
function
|
|
220
|
+
function readToolId() {
|
|
221
|
+
const toolJsonPath = path.join(projectRoot, 'tool.json');
|
|
222
|
+
if (!fs.existsSync(toolJsonPath)) {
|
|
223
|
+
console.error('❌ tool.json not found in project root. Run this from your tool directory.');
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
const toolJson = JSON.parse(fs.readFileSync(toolJsonPath, 'utf-8'));
|
|
227
|
+
if (!toolJson.id) {
|
|
228
|
+
console.error('❌ tool.json is missing an "id" field.');
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
return toolJson.id;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function generateClientFile(resource, framework, mode) {
|
|
167
235
|
const clientName = toCamelCase(resource.name) + 'Client';
|
|
168
236
|
const clientClass = getClientClass(resource.type);
|
|
237
|
+
const effectiveMode = resource.mode === 'tool' ? 'tool' : mode;
|
|
169
238
|
|
|
170
|
-
|
|
239
|
+
const data = {
|
|
171
240
|
clientClass,
|
|
172
241
|
description: resource.description,
|
|
173
242
|
type: resource.type,
|
|
174
243
|
resourceId: resource.id,
|
|
175
244
|
applicationId: resource.applicationId,
|
|
176
245
|
clientName,
|
|
177
|
-
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
if (effectiveMode === 'tool') {
|
|
249
|
+
data.toolId = readToolId();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return clientTemplate(data, framework, effectiveMode);
|
|
178
253
|
}
|
|
179
254
|
|
|
180
255
|
function generateIndexFile(resources) {
|
|
@@ -191,7 +266,7 @@ function generateIndexFile(resources) {
|
|
|
191
266
|
return indexTemplate({ exports });
|
|
192
267
|
}
|
|
193
268
|
|
|
194
|
-
function addResource(resourceId, name, type, description, applicationId, framework) {
|
|
269
|
+
function addResource(resourceId, name, type, description, applicationId, framework, mode) {
|
|
195
270
|
const validTypes = ['postgresql', 'mssql', 'dynamodb', 'cosmosdb', 'snowflake', 'bigquery', 'neo4j', 'hubspot', 'googlesheets', 'outreach', 'custom', 'graphql', 'lambda', 'salesforce', 's3', 'slack', 'majorauth', 'googleanalytics', 'quickbooks'];
|
|
196
271
|
if (!validTypes.includes(type)) {
|
|
197
272
|
console.error(`❌ Invalid type: ${type}`);
|
|
@@ -200,7 +275,7 @@ function addResource(resourceId, name, type, description, applicationId, framewo
|
|
|
200
275
|
process.exit(1);
|
|
201
276
|
}
|
|
202
277
|
|
|
203
|
-
if (!applicationId) {
|
|
278
|
+
if (mode !== 'tool' && !applicationId) {
|
|
204
279
|
console.error('❌ Application ID is required');
|
|
205
280
|
process.exit(1);
|
|
206
281
|
}
|
|
@@ -218,7 +293,7 @@ function addResource(resourceId, name, type, description, applicationId, framewo
|
|
|
218
293
|
name,
|
|
219
294
|
type,
|
|
220
295
|
description,
|
|
221
|
-
applicationId
|
|
296
|
+
...(mode === 'tool' ? { mode: 'tool' } : { applicationId }),
|
|
222
297
|
};
|
|
223
298
|
|
|
224
299
|
resources.push(newResource);
|
|
@@ -228,13 +303,13 @@ function addResource(resourceId, name, type, description, applicationId, framewo
|
|
|
228
303
|
console.log(` Type: ${type}`);
|
|
229
304
|
console.log(` ID: ${resourceId}`);
|
|
230
305
|
|
|
231
|
-
regenerateClients(resources, framework);
|
|
306
|
+
regenerateClients(resources, framework, mode);
|
|
232
307
|
}
|
|
233
308
|
|
|
234
309
|
/**
|
|
235
310
|
* Remove a resource by name
|
|
236
311
|
*/
|
|
237
|
-
function removeResource(name, framework) {
|
|
312
|
+
function removeResource(name, framework, mode) {
|
|
238
313
|
const resources = loadResources();
|
|
239
314
|
const index = resources.findIndex(r => r.name === name);
|
|
240
315
|
|
|
@@ -249,7 +324,7 @@ function removeResource(name, framework) {
|
|
|
249
324
|
console.log(`✅ Removed resource: ${removed.name}`);
|
|
250
325
|
console.log(` ID: ${removed.id}`);
|
|
251
326
|
|
|
252
|
-
regenerateClients(resources, framework);
|
|
327
|
+
regenerateClients(resources, framework, mode);
|
|
253
328
|
}
|
|
254
329
|
|
|
255
330
|
/**
|
|
@@ -275,7 +350,7 @@ function listResources() {
|
|
|
275
350
|
/**
|
|
276
351
|
* Regenerate all client files
|
|
277
352
|
*/
|
|
278
|
-
function regenerateClients(resources, framework) {
|
|
353
|
+
function regenerateClients(resources, framework, mode) {
|
|
279
354
|
const clientsDir = getClientsDir();
|
|
280
355
|
|
|
281
356
|
// Ensure clients directory exists
|
|
@@ -293,7 +368,7 @@ function regenerateClients(resources, framework) {
|
|
|
293
368
|
resources.forEach(resource => {
|
|
294
369
|
const fileName = toCamelCase(resource.name) + '.ts';
|
|
295
370
|
const filePath = path.join(clientsDir, fileName);
|
|
296
|
-
const code = generateClientFile(resource, framework);
|
|
371
|
+
const code = generateClientFile(resource, framework, mode);
|
|
297
372
|
fs.writeFileSync(filePath, code, 'utf-8');
|
|
298
373
|
});
|
|
299
374
|
|
|
@@ -324,24 +399,52 @@ function main() {
|
|
|
324
399
|
args.splice(frameworkIndex, 2);
|
|
325
400
|
}
|
|
326
401
|
|
|
402
|
+
// Extract --mode flag (app | tool, default: app)
|
|
403
|
+
const modeIndex = args.indexOf('--mode');
|
|
404
|
+
let mode = 'app';
|
|
405
|
+
if (modeIndex !== -1 && args[modeIndex + 1]) {
|
|
406
|
+
mode = args[modeIndex + 1];
|
|
407
|
+
// Remove --mode and its value from args
|
|
408
|
+
args.splice(modeIndex, 2);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (mode !== 'app' && mode !== 'tool') {
|
|
412
|
+
console.error(`❌ Invalid mode: ${mode}. Must be "app" or "tool".`);
|
|
413
|
+
process.exit(1);
|
|
414
|
+
}
|
|
415
|
+
|
|
327
416
|
if (!command) {
|
|
328
417
|
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
|
|
418
|
+
console.log(' npx @major-tech/resource-client add <resource_id> <name> <type> <description> <application_id> [--framework <nextjs|vite>] [--mode <app|tool>]');
|
|
419
|
+
console.log(' npx @major-tech/resource-client add <resource_id> <name> <type> <description> --mode tool');
|
|
420
|
+
console.log(' npx @major-tech/resource-client remove <name> [--framework <nextjs|vite>] [--mode <app|tool>]');
|
|
331
421
|
console.log(' npx @major-tech/resource-client list');
|
|
422
|
+
console.log('\nModes: app (default) | tool');
|
|
423
|
+
console.log(' app — requires <application_id>, reads MAJOR_API_BASE_URL');
|
|
424
|
+
console.log(' tool — embeds toolId from tool.json at generation time, reads RESOURCE_API_URL');
|
|
332
425
|
console.log('\nTypes: postgresql | mssql | dynamodb | cosmosdb | snowflake | bigquery | neo4j | hubspot | googlesheets | outreach | custom | graphql | lambda | salesforce | s3 | slack | majorauth | googleanalytics | quickbooks');
|
|
333
426
|
return;
|
|
334
427
|
}
|
|
335
428
|
|
|
336
429
|
switch (command) {
|
|
337
430
|
case 'add': {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
431
|
+
if (mode === 'tool') {
|
|
432
|
+
const [, resourceId, name, type, description] = args;
|
|
433
|
+
if (!resourceId || !name || !type || !description) {
|
|
434
|
+
console.error('❌ Missing arguments');
|
|
435
|
+
console.log('Usage: add <resource_id> <name> <type> <description> --mode tool');
|
|
436
|
+
process.exit(1);
|
|
437
|
+
}
|
|
438
|
+
addResource(resourceId, name, type, description, null, framework, mode);
|
|
439
|
+
} else {
|
|
440
|
+
const [, resourceId, name, type, description, applicationId] = args;
|
|
441
|
+
if (!resourceId || !name || !type || !description || !applicationId) {
|
|
442
|
+
console.error('❌ Missing arguments');
|
|
443
|
+
console.log('Usage: add <resource_id> <name> <type> <description> <application_id> [--framework <nextjs|vite>]');
|
|
444
|
+
process.exit(1);
|
|
445
|
+
}
|
|
446
|
+
addResource(resourceId, name, type, description, applicationId, framework, mode);
|
|
343
447
|
}
|
|
344
|
-
addResource(resourceId, name, type, description, applicationId, framework);
|
|
345
448
|
break;
|
|
346
449
|
}
|
|
347
450
|
|
|
@@ -351,7 +454,7 @@ function main() {
|
|
|
351
454
|
console.error('❌ Missing name');
|
|
352
455
|
process.exit(1);
|
|
353
456
|
}
|
|
354
|
-
removeResource(name, framework);
|
|
457
|
+
removeResource(name, framework, mode);
|
|
355
458
|
break;
|
|
356
459
|
}
|
|
357
460
|
|
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,mBAAkB;EAhBxC,OAgBwC;;;EACnB;EAUnB,YAAY,QAAwB;AAClC,QAAI,CAAC,OAAO,iBAAiB,CAAC,OAAO,QAAQ;AAC3C,YAAM,IAAI,MAAM,4DAA4D;IAC9E;AAEA,SAAK,SAAS;MACZ,SAAS,OAAO,QAAQ,QAAQ,OAAO,EAAE;MACzC,eAAe,OAAO;MACtB,eAAe,OAAO;MACtB,QAAQ,OAAO;MACf,YAAY,OAAO;MACnB,OAAO,OAAO,SAAS,WAAW;MAClC,YAAY,OAAO;;EAEvB;EAEU,MAAM,UACd,SACA,eAAqB;AAErB,UAAM,aAAa,KAAK,OAAO,SAAS,UAAU;AAClD,UAAM,WAAW,KAAK,OAAO,UAAU,KAAK,OAAO;AACnD,UAAM,MAAM,GAAG,KAAK,OAAO,OAAO,aAAa,UAAU,OAAO,QAAQ,aAAa,KAAK,OAAO,UAAU;AAE3G,UAAM,OAAsB;MAC1B;MACA;;AAGF,QAAI,UAAkC;MACpC,gBAAgB;;AAGlB,QAAI,KAAK,OAAO,eAAe;AAC7B,cAAQ,aAAa,IAAI,KAAK,OAAO;IACvC;AAEA,QAAI,KAAK,OAAO,YAAY;AAC1B,YAAM,eAAe,MAAM,KAAK,OAAO,WAAU;AACjD,gBAAU,EAAE,GAAG,SAAS,GAAG,aAAY;IACzC;AAEA,QAAI;AACF,YAAM,WAAW,MAAM,KAAK,OAAO,MAAM,KAAK;QAC5C,QAAQ;QACR;QACA,aAAa;QACb,MAAM,KAAK,UAAU,IAAI;OAC1B;AAED,YAAM,OAAO,MAAM,SAAS,KAAI;AAChC,aAAO;IACT,SAAS,OAAO;AACd,YAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,YAAM,IAAI,kCAAoB,8BAA8B,OAAO,EAAE;IACvE;EACF;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/base.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { ResourceInvokePayload, InvokeResponse } from "./schemas";
|
|
|
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,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;QACjE,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,aAAa,UAAU,OAAO,QAAQ,aAAa,IAAI,CAAC,MAAM,CAAC,UAAU,SAAS,CAAC;QAErH,MAAM,IAAI,GAAkB;YAC1B,OAAO;YACP,aAAa;SACd,CAAC;QAEF,IAAI,OAAO,GAA2B;YACpC,cAAc,EAAE,kBAAkB;SACnC,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YAC9B,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;QACrD,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAC3B,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACpD,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;QAC5C,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;gBAC5C,MAAM,EAAE,MAAM;gBACd,OAAO;gBACP,WAAW,EAAE,SAAS;gBACtB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;aAC3B,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO,IAAsB,CAAC;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,MAAM,IAAI,mBAAmB,CAAC,8BAA8B,OAAO,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED