routesync 1.0.7 → 1.0.9

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/dist/cli.js CHANGED
@@ -8722,7 +8722,7 @@ var TypeGenerator = class {
8722
8722
  }
8723
8723
  }
8724
8724
  }
8725
- await import_fs_extra4.default.writeFile(import_path3.default.join(outputDir, "types.ts"), lines.join("\\n"));
8725
+ await import_fs_extra4.default.writeFile(import_path3.default.join(outputDir, "types.ts"), lines.join("\n"));
8726
8726
  }
8727
8727
  };
8728
8728
 
@@ -8755,7 +8755,7 @@ var HookGenerator = class _HookGenerator {
8755
8755
  lines.push(`export function ${hookName}() {`);
8756
8756
  lines.push(` const queryClient = useQueryClient()`);
8757
8757
  lines.push(` return useMutation({`);
8758
- lines.push(` mutationFn: (data: unknown) => api.${group}.${route.actionName}({ body: data }),`);
8758
+ lines.push(` mutationFn: (data: Record<string, unknown>) => api.${group}.${route.actionName}({ body: data }),`);
8759
8759
  lines.push(` onSuccess: () => {`);
8760
8760
  lines.push(` queryClient.invalidateQueries({ queryKey: ['${group}'] })`);
8761
8761
  lines.push(` }`);
@@ -8791,27 +8791,30 @@ var NextActionGenerator = class {
8791
8791
  lines.push(` return token ? { Authorization: \`Bearer \${token}\` } : {}`);
8792
8792
  lines.push(`}`);
8793
8793
  lines.push(``);
8794
- for (const route of manifest.routes) {
8795
- const actionName = toMethodName(route);
8796
- lines.push(`export async function ${actionName}Action(payload?: unknown) {`);
8797
- const args = [];
8798
- if (route.method === "GET") {
8799
- args.push(`query: payload`);
8800
- } else {
8801
- args.push(`body: payload`);
8802
- }
8803
- if (route.auth) {
8804
- args.push(`headers: await getAuthHeaders()`);
8805
- }
8806
- const apiCall = `await api.${route.name.split(".")[0]}.${route.name.split(".")[1] || "action"}({ ${args.join(", ")} })`;
8807
- lines.push(` try {`);
8808
- lines.push(` const response = ${apiCall}`);
8809
- lines.push(` return { success: true, data: response.data }`);
8810
- lines.push(` } catch (error: unknown) {`);
8811
- lines.push(` return { success: false, error: error instanceof Error ? error.message : String(error) }`);
8812
- lines.push(` }`);
8813
- lines.push(`}`);
8814
- lines.push(``);
8794
+ const grouped = buildGeneratedRoutes(manifest.routes);
8795
+ for (const [groupName, routes] of Object.entries(grouped)) {
8796
+ for (const route of routes) {
8797
+ const actionName = `${groupName}${toTypeName(route.actionName)}`;
8798
+ lines.push(`export async function ${actionName}Action(payload?: Record<string, unknown>) {`);
8799
+ const args = [];
8800
+ if (route.method === "GET") {
8801
+ args.push(`query: payload`);
8802
+ } else {
8803
+ args.push(`body: payload`);
8804
+ }
8805
+ if (route.auth) {
8806
+ args.push(`headers: await getAuthHeaders()`);
8807
+ }
8808
+ const apiCall = `await api.${groupName}.${route.actionName}({ ${args.join(", ")} })`;
8809
+ lines.push(` try {`);
8810
+ lines.push(` const response = ${apiCall}`);
8811
+ lines.push(` return { success: true, data: response.data }`);
8812
+ lines.push(` } catch (error: unknown) {`);
8813
+ lines.push(` return { success: false, error: error instanceof Error ? error.message : String(error) }`);
8814
+ lines.push(` }`);
8815
+ lines.push(`}`);
8816
+ lines.push(``);
8817
+ }
8815
8818
  }
8816
8819
  await import_fs_extra6.default.writeFile(import_path5.default.join(outputDir, "actions.ts"), lines.join("\n"));
8817
8820
  }
package/dist/react.d.mts CHANGED
@@ -42,6 +42,7 @@ type CallOptions = {
42
42
  params?: Record<string, any>;
43
43
  query?: Record<string, any>;
44
44
  body?: Record<string, any>;
45
+ headers?: Record<string, string>;
45
46
  };
46
47
  interface EndpointCallable {
47
48
  (options?: CallOptions): Promise<any>;
package/dist/react.d.ts CHANGED
@@ -42,6 +42,7 @@ type CallOptions = {
42
42
  params?: Record<string, any>;
43
43
  query?: Record<string, any>;
44
44
  body?: Record<string, any>;
45
+ headers?: Record<string, string>;
45
46
  };
46
47
  interface EndpointCallable {
47
48
  (options?: CallOptions): Promise<any>;
package/dist/sdk.d.mts CHANGED
@@ -103,6 +103,7 @@ type CallOptions = {
103
103
  params?: Record<string, any>;
104
104
  query?: Record<string, any>;
105
105
  body?: Record<string, any>;
106
+ headers?: Record<string, string>;
106
107
  };
107
108
  interface EndpointCallable {
108
109
  (options?: CallOptions): Promise<any>;
package/dist/sdk.d.ts CHANGED
@@ -103,6 +103,7 @@ type CallOptions = {
103
103
  params?: Record<string, any>;
104
104
  query?: Record<string, any>;
105
105
  body?: Record<string, any>;
106
+ headers?: Record<string, string>;
106
107
  };
107
108
  interface EndpointCallable {
108
109
  (options?: CallOptions): Promise<any>;
package/dist/sdk.js CHANGED
@@ -280,7 +280,7 @@ function defineApi(definition, config) {
280
280
  );
281
281
  const resolvedPath = PathResolver.resolve(route.path, params);
282
282
  const method = route.method.toLowerCase();
283
- const requestConfig = { params: query, headers: route.headers };
283
+ const requestConfig = { params: query, headers: { ...route.headers, ...options?.headers } };
284
284
  let response;
285
285
  if (method === "get" || method === "delete") {
286
286
  response = await client[method](resolvedPath, requestConfig);
package/dist/sdk.mjs CHANGED
@@ -238,7 +238,7 @@ function defineApi(definition, config) {
238
238
  );
239
239
  const resolvedPath = PathResolver.resolve(route.path, params);
240
240
  const method = route.method.toLowerCase();
241
- const requestConfig = { params: query, headers: route.headers };
241
+ const requestConfig = { params: query, headers: { ...route.headers, ...options?.headers } };
242
242
  let response;
243
243
  if (method === "get" || method === "delete") {
244
244
  response = await client[method](resolvedPath, requestConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routesync",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Laravel routes to typed frontend SDKs.",
5
5
  "main": "./dist/sdk.js",
6
6
  "module": "./dist/sdk.mjs",