@major-tech/resource-client 0.2.38 → 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.
@@ -98,6 +98,7 @@ export const ${data.clientName} = ${data.clientName}Singleton.getInstance();
98
98
  * Client template for tool mode
99
99
  */
100
100
  function clientTemplateTool(data) {
101
+ const factoryName = 'create' + data.clientName.charAt(0).toUpperCase() + data.clientName.slice(1);
101
102
  return `import { ${data.clientClass} } from '@major-tech/resource-client';
102
103
 
103
104
  /**
@@ -110,28 +111,20 @@ function clientTemplateTool(data) {
110
111
  * DO NOT EDIT - Auto-generated by @major-tech/resource-client (tool mode)
111
112
  */
112
113
 
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
- }
114
+ interface ToolContext {
115
+ resourceApiUrl: string;
116
+ majorJwtToken: string;
132
117
  }
133
118
 
134
- export const ${data.clientName} = ${data.clientName}Singleton.getInstance();
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
+ }
135
128
  `;
136
129
  }
137
130
 
@@ -260,6 +253,10 @@ function generateIndexFile(resources) {
260
253
  const exports = resources.map(resource => {
261
254
  const clientName = toCamelCase(resource.name) + 'Client';
262
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
+ }
263
260
  return `export { ${clientName} } from './${fileName}';`;
264
261
  });
265
262
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@major-tech/resource-client",
3
- "version": "0.2.38",
3
+ "version": "0.2.40",
4
4
  "description": "TypeScript client library for invoking Major resources (PostgreSQL, Custom APIs, HubSpot, S3)",
5
5
  "type": "module",
6
6
  "sideEffects": false,