atmx-cli 0.51.0 → 0.55.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.
@@ -9,13 +9,30 @@ function generateSdk(multiIr, isReact = false) {
9
9
  `import * as models from './models';\n`,
10
10
  ];
11
11
  if (isReact) {
12
- lines.push(`import { useAxiomQuery, useAxiomMutation } from 'atmx-react';`);
12
+ // ✨ FIX: Auto-import the auth helpers to bind them to the module
13
+ lines.push(`import { useAxiomQuery, useAxiomMutation, setAuthToken, clearAuthToken } from 'atmx-react';`);
13
14
  lines.push(`import type { AxiomQueryDef } from 'atmx-react';\n`);
14
15
  }
15
16
  for (const [ns, ir] of Object.entries(multiIr)) {
16
17
  const camelNs = (0, utils_1.camelCase)(ns);
17
- // ✨ FIX: Use an object literal instead of a Class to support React Hooks!
18
18
  lines.push(`export const ${camelNs}Module = {`);
19
+ // ✨ FIX: Safely bind auth tokens using the EXACT namespace string from the TOML file!
20
+ if (isReact) {
21
+ lines.push(` setAuthToken(methodName: string, token: string) {`);
22
+ lines.push(` setAuthToken("${ns}", methodName, token);`);
23
+ lines.push(` },`);
24
+ lines.push(` clearAuthToken(methodName: string) {`);
25
+ lines.push(` clearAuthToken("${ns}", methodName);`);
26
+ lines.push(` },`);
27
+ }
28
+ else {
29
+ lines.push(` setAuthToken(methodName: string, token: string) {`);
30
+ lines.push(` (window as any).atmx?.setAuthToken("${ns}", methodName, token);`);
31
+ lines.push(` },`);
32
+ lines.push(` clearAuthToken(methodName: string) {`);
33
+ lines.push(` (window as any).atmx?.clearAuthToken("${ns}", methodName);`);
34
+ lines.push(` },`);
35
+ }
19
36
  const endpointsMap = ir.endpoints || {};
20
37
  const endpoints = Array.isArray(endpointsMap)
21
38
  ? endpointsMap
@@ -25,13 +42,11 @@ function generateSdk(multiIr, isReact = false) {
25
42
  });
26
43
  lines.push(`};\n`);
27
44
  }
28
- // Generate main SDK object
29
45
  lines.push(`export const sdk = {`);
30
46
  for (const ns of Object.keys(multiIr)) {
31
47
  lines.push(` ${(0, utils_1.camelCase)(ns)}: ${(0, utils_1.camelCase)(ns)}Module,`);
32
48
  }
33
49
  lines.push(`};\n`);
34
- // Generate Config
35
50
  lines.push(`export const AxiomDefaultConfig = {`);
36
51
  lines.push(` contracts: {`);
37
52
  for (const ns of Object.keys(multiIr)) {
@@ -49,9 +64,34 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
49
64
  const params = Array.isArray(rawParams)
50
65
  ? rawParams
51
66
  : Object.values(rawParams);
52
- const argType = params.length > 0
53
- ? `{ ${params.map((p) => `${(0, utils_1.camelCase)(p.name)}${p.isOptional ? "?" : ""}: ${prefixModels((0, utils_1.mapTypeToTs)(p.typeRef, camelNs))}`).join(", ")} }`
54
- : "void";
67
+ if (params.length === 0) {
68
+ if (isReact) {
69
+ const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
70
+ const rawReturnType = (0, utils_1.mapTypeToTs)(ep.returnType, camelNs);
71
+ const returnType = rawReturnType === "void" || rawReturnType === "any"
72
+ ? rawReturnType
73
+ : prefixModels(rawReturnType);
74
+ const decLogic = generateLambda(ep.returnType, "fromJson", camelNs);
75
+ return `
76
+ get${(0, utils_1.pascalCase)(ep.name)}Def(): AxiomQueryDef<${returnType}> {
77
+ return {
78
+ namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
79
+ method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
80
+ args: {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
81
+ };
82
+ },
83
+ use${(0, utils_1.pascalCase)(ep.name)}${!isQuery ? "Mutation" : ""}(options?: { enabled?: boolean }) {
84
+ ${isQuery ? `return useAxiomQuery<${returnType}>(this.get${(0, utils_1.pascalCase)(ep.name)}Def(), options);` : `return useAxiomMutation<${returnType}, void | Record<string,any>>(() => this.get${(0, utils_1.pascalCase)(ep.name)}Def());`}
85
+ },`;
86
+ }
87
+ else {
88
+ return `
89
+ ${(0, utils_1.camelCase)(ep.name)}(): string {
90
+ return \`${ns}.${ep.name}()\`;
91
+ },`;
92
+ }
93
+ }
94
+ const argType = `{ ${params.map((p) => `${(0, utils_1.camelCase)(p.name)}?: ${prefixModels((0, utils_1.mapTypeToTs)(p.typeRef, camelNs))}`).join(", ")} }`;
55
95
  const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
56
96
  const rawReturnType = (0, utils_1.mapTypeToTs)(ep.returnType, camelNs);
57
97
  const returnType = rawReturnType === "void" || rawReturnType === "any"
@@ -67,31 +107,21 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
67
107
  ? generateLambda(bodyParam.typeRef, "toJson", camelNs)
68
108
  : `(p: any) => p`;
69
109
  return `
70
- get${(0, utils_1.pascalCase)(ep.name)}Def(args${params.length > 0 ? "?" : ""}: ${argType === "void" ? "any" : argType}): AxiomQueryDef<${returnType}> {
110
+ get${(0, utils_1.pascalCase)(ep.name)}Def(args?: ${argType}): AxiomQueryDef<${returnType}> {
71
111
  ${payloadLogic}
72
112
  return {
73
- namespace: "${ns}",
74
- name: "${ep.name}",
75
- endpointId: ${ep.id},
76
- method: "${ep.method ? ep.method.toUpperCase() : "GET"}",
77
- path: "${ep.path}",
78
- payload: payload,
79
- args: args || {},
80
- decoder: ${decLogic},
81
- serializer: ${serLogic},
82
- isStream: ${ep.isStream === true}
113
+ namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
114
+ method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
115
+ payload: payload, args: args || {}, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
83
116
  };
84
117
  },
85
-
86
- use${(0, utils_1.pascalCase)(ep.name)}${!isQuery ? "Mutation" : ""}(${isQuery ? `args${params.length > 0 ? "?" : ""}: ${argType === "void" ? "any" : argType}, options?: { enabled?: boolean }` : ""}) {
87
- ${isQuery
88
- ? `return useAxiomQuery<${returnType}>(this.get${(0, utils_1.pascalCase)(ep.name)}Def(args), options);`
89
- : `return useAxiomMutation<${returnType}, ${argType === "void" ? "void | Record<string,any>" : argType}>((args) => this.get${(0, utils_1.pascalCase)(ep.name)}Def(args));`}
118
+ use${(0, utils_1.pascalCase)(ep.name)}${!isQuery ? "Mutation" : ""}(args?: ${argType}, options?: { enabled?: boolean }) {
119
+ ${isQuery ? `return useAxiomQuery<${returnType}>(this.get${(0, utils_1.pascalCase)(ep.name)}Def(args), options);` : `return useAxiomMutation<${returnType}, ${argType}>((a) => this.get${(0, utils_1.pascalCase)(ep.name)}Def(a || args));`}
90
120
  },`;
91
121
  }
92
122
  else {
93
123
  return `
94
- ${(0, utils_1.camelCase)(ep.name)}(args${params.length > 0 ? "?" : ""}: ${argType === "void" ? "any" : argType}): string {
124
+ ${(0, utils_1.camelCase)(ep.name)}(args?: ${argType}): string {
95
125
  const argsStr = args && Object.keys(args).length > 0 ? JSON.stringify(args) : '';
96
126
  return \`${ns}.${ep.name}(\${argsStr})\`;
97
127
  },`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmx-cli",
3
- "version": "0.51.0",
3
+ "version": "0.55.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,15 +13,38 @@ export function generateSdk(
13
13
  ];
14
14
 
15
15
  if (isReact) {
16
- lines.push(`import { useAxiomQuery, useAxiomMutation } from 'atmx-react';`);
16
+ // ✨ FIX: Auto-import the auth helpers to bind them to the module
17
+ lines.push(
18
+ `import { useAxiomQuery, useAxiomMutation, setAuthToken, clearAuthToken } from 'atmx-react';`,
19
+ );
17
20
  lines.push(`import type { AxiomQueryDef } from 'atmx-react';\n`);
18
21
  }
19
22
 
20
23
  for (const [ns, ir] of Object.entries(multiIr)) {
21
24
  const camelNs = camelCase(ns);
22
- // ✨ FIX: Use an object literal instead of a Class to support React Hooks!
23
25
  lines.push(`export const ${camelNs}Module = {`);
24
26
 
27
+ // ✨ FIX: Safely bind auth tokens using the EXACT namespace string from the TOML file!
28
+ if (isReact) {
29
+ lines.push(` setAuthToken(methodName: string, token: string) {`);
30
+ lines.push(` setAuthToken("${ns}", methodName, token);`);
31
+ lines.push(` },`);
32
+ lines.push(` clearAuthToken(methodName: string) {`);
33
+ lines.push(` clearAuthToken("${ns}", methodName);`);
34
+ lines.push(` },`);
35
+ } else {
36
+ lines.push(` setAuthToken(methodName: string, token: string) {`);
37
+ lines.push(
38
+ ` (window as any).atmx?.setAuthToken("${ns}", methodName, token);`,
39
+ );
40
+ lines.push(` },`);
41
+ lines.push(` clearAuthToken(methodName: string) {`);
42
+ lines.push(
43
+ ` (window as any).atmx?.clearAuthToken("${ns}", methodName);`,
44
+ );
45
+ lines.push(` },`);
46
+ }
47
+
25
48
  const endpointsMap = ir.endpoints || {};
26
49
  const endpoints = Array.isArray(endpointsMap)
27
50
  ? endpointsMap
@@ -33,14 +56,12 @@ export function generateSdk(
33
56
  lines.push(`};\n`);
34
57
  }
35
58
 
36
- // Generate main SDK object
37
59
  lines.push(`export const sdk = {`);
38
60
  for (const ns of Object.keys(multiIr)) {
39
61
  lines.push(` ${camelCase(ns)}: ${camelCase(ns)}Module,`);
40
62
  }
41
63
  lines.push(`};\n`);
42
64
 
43
- // Generate Config
44
65
  lines.push(`export const AxiomDefaultConfig = {`);
45
66
  lines.push(` contracts: {`);
46
67
  for (const ns of Object.keys(multiIr)) {
@@ -66,11 +87,35 @@ function generateEndpointMethod(
66
87
  ? rawParams
67
88
  : Object.values(rawParams);
68
89
 
69
- const argType =
70
- params.length > 0
71
- ? `{ ${params.map((p: any) => `${camelCase(p.name)}${p.isOptional ? "?" : ""}: ${prefixModels(mapTypeToTs(p.typeRef, camelNs))}`).join(", ")} }`
72
- : "void";
90
+ if (params.length === 0) {
91
+ if (isReact) {
92
+ const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
93
+ const rawReturnType = mapTypeToTs(ep.returnType, camelNs);
94
+ const returnType =
95
+ rawReturnType === "void" || rawReturnType === "any"
96
+ ? rawReturnType
97
+ : prefixModels(rawReturnType);
98
+ const decLogic = generateLambda(ep.returnType, "fromJson", camelNs);
99
+ return `
100
+ get${pascalCase(ep.name)}Def(): AxiomQueryDef<${returnType}> {
101
+ return {
102
+ namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
103
+ method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
104
+ args: {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
105
+ };
106
+ },
107
+ use${pascalCase(ep.name)}${!isQuery ? "Mutation" : ""}(options?: { enabled?: boolean }) {
108
+ ${isQuery ? `return useAxiomQuery<${returnType}>(this.get${pascalCase(ep.name)}Def(), options);` : `return useAxiomMutation<${returnType}, void | Record<string,any>>(() => this.get${pascalCase(ep.name)}Def());`}
109
+ },`;
110
+ } else {
111
+ return `
112
+ ${camelCase(ep.name)}(): string {
113
+ return \`${ns}.${ep.name}()\`;
114
+ },`;
115
+ }
116
+ }
73
117
 
118
+ const argType = `{ ${params.map((p: any) => `${camelCase(p.name)}?: ${prefixModels(mapTypeToTs(p.typeRef, camelNs))}`).join(", ")} }`;
74
119
  const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
75
120
  const rawReturnType = mapTypeToTs(ep.returnType, camelNs);
76
121
  const returnType =
@@ -91,32 +136,20 @@ function generateEndpointMethod(
91
136
  : `(p: any) => p`;
92
137
 
93
138
  return `
94
- get${pascalCase(ep.name)}Def(args${params.length > 0 ? "?" : ""}: ${argType === "void" ? "any" : argType}): AxiomQueryDef<${returnType}> {
139
+ get${pascalCase(ep.name)}Def(args?: ${argType}): AxiomQueryDef<${returnType}> {
95
140
  ${payloadLogic}
96
141
  return {
97
- namespace: "${ns}",
98
- name: "${ep.name}",
99
- endpointId: ${ep.id},
100
- method: "${ep.method ? ep.method.toUpperCase() : "GET"}",
101
- path: "${ep.path}",
102
- payload: payload,
103
- args: args || {},
104
- decoder: ${decLogic},
105
- serializer: ${serLogic},
106
- isStream: ${ep.isStream === true}
142
+ namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
143
+ method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
144
+ payload: payload, args: args || {}, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
107
145
  };
108
146
  },
109
-
110
- use${pascalCase(ep.name)}${!isQuery ? "Mutation" : ""}(${isQuery ? `args${params.length > 0 ? "?" : ""}: ${argType === "void" ? "any" : argType}, options?: { enabled?: boolean }` : ""}) {
111
- ${
112
- isQuery
113
- ? `return useAxiomQuery<${returnType}>(this.get${pascalCase(ep.name)}Def(args), options);`
114
- : `return useAxiomMutation<${returnType}, ${argType === "void" ? "void | Record<string,any>" : argType}>((args) => this.get${pascalCase(ep.name)}Def(args));`
115
- }
147
+ use${pascalCase(ep.name)}${!isQuery ? "Mutation" : ""}(args?: ${argType}, options?: { enabled?: boolean }) {
148
+ ${isQuery ? `return useAxiomQuery<${returnType}>(this.get${pascalCase(ep.name)}Def(args), options);` : `return useAxiomMutation<${returnType}, ${argType}>((a) => this.get${pascalCase(ep.name)}Def(a || args));`}
116
149
  },`;
117
150
  } else {
118
151
  return `
119
- ${camelCase(ep.name)}(args${params.length > 0 ? "?" : ""}: ${argType === "void" ? "any" : argType}): string {
152
+ ${camelCase(ep.name)}(args?: ${argType}): string {
120
153
  const argsStr = args && Object.keys(args).length > 0 ? JSON.stringify(args) : '';
121
154
  return \`${ns}.${ep.name}(\${argsStr})\`;
122
155
  },`;