wexts 4.1.0 → 4.1.6
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/chunk-27NEYQD2.mjs +222 -0
- package/dist/chunk-27NEYQD2.mjs.map +1 -0
- package/dist/{chunk-YBM3IJEA.mjs → chunk-5DBFN65W.mjs} +92 -3
- package/dist/chunk-5DBFN65W.mjs.map +1 -0
- package/dist/{chunk-7HNQWJWV.js → chunk-75HBI2XG.js} +3 -3
- package/dist/{chunk-7HNQWJWV.js.map → chunk-75HBI2XG.js.map} +1 -1
- package/dist/{chunk-JHOVXH3X.mjs → chunk-C2AG7Q3C.mjs} +2 -2
- package/dist/{chunk-7TLSPR65.mjs → chunk-DS5KVVWJ.mjs} +2 -2
- package/dist/{chunk-YN6WIWNQ.mjs → chunk-FUPLZMSR.mjs} +3 -3
- package/dist/{chunk-7QKLIVRF.js → chunk-HLT3IHJY.js} +92 -3
- package/dist/chunk-HLT3IHJY.js.map +1 -0
- package/dist/{chunk-7WULUGLH.mjs → chunk-L77ANWWT.mjs} +2 -2
- package/dist/{chunk-7WULUGLH.mjs.map → chunk-L77ANWWT.mjs.map} +1 -1
- package/dist/chunk-P3Q4I5FD.js +222 -0
- package/dist/chunk-P3Q4I5FD.js.map +1 -0
- package/dist/{chunk-342VRT25.mjs → chunk-VBIQGUDI.mjs} +6 -6
- package/dist/cli/index.js +32 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +35 -6
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.d.mts +23 -1
- package/dist/client/index.d.ts +23 -1
- package/dist/client/index.js +183 -9
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +160 -7
- package/dist/client/index.mjs.map +1 -1
- package/dist/codegen/index.d.mts +2 -2
- package/dist/codegen/index.d.ts +2 -2
- package/dist/codegen/index.js +3 -3
- package/dist/codegen/index.mjs +4 -4
- package/dist/decorators-BiQtOHuF.d.ts +60 -0
- package/dist/decorators-vBopODtr.d.mts +60 -0
- package/dist/dev-server/index.mjs +3 -3
- package/dist/errors-D545UvXf.d.mts +37 -0
- package/dist/errors-D545UvXf.d.ts +37 -0
- package/dist/{index-7QeQEf37.d.ts → index-CJKs4wtN.d.ts} +1 -1
- package/dist/index-CUR6CnLk.d.ts +27 -0
- package/dist/{index-8nzxy0NN.d.mts → index-h66Vq9dK.d.mts} +1 -1
- package/dist/index-tqmYsTUn.d.mts +27 -0
- package/dist/index.d.mts +82 -87
- package/dist/index.d.ts +82 -87
- package/dist/index.js +140 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +142 -22
- package/dist/index.mjs.map +1 -1
- package/dist/nest/index.d.mts +2 -3
- package/dist/nest/index.d.ts +2 -3
- package/dist/nest/index.js +2 -4
- package/dist/nest/index.js.map +1 -1
- package/dist/nest/index.mjs +3 -5
- package/dist/next/index.js +0 -7
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs.map +1 -1
- package/dist/rpc/index.d.mts +32 -2
- package/dist/rpc/index.d.ts +32 -2
- package/dist/rpc/index.js +18 -22
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/index.mjs +0 -22
- package/dist/runtime/index.d.mts +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +5 -211
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/index.mjs +7 -213
- package/dist/runtime/index.mjs.map +1 -1
- package/dist/server/index.d.mts +7 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +58 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +58 -0
- package/dist/types/index.js +18 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +0 -2
- package/dist/{types-7d_fC-C3.d.ts → types-CQ_aexOX.d.mts} +1 -1
- package/dist/{types-7d_fC-C3.d.mts → types-CQ_aexOX.d.ts} +1 -1
- package/dist/vercel-builder/index.mjs +1 -1
- package/package.json +6 -1
- package/templates/nestjs-api/README.md +1 -1
- package/dist/chunk-2KAQYLVN.js +0 -1
- package/dist/chunk-2KAQYLVN.js.map +0 -1
- package/dist/chunk-7QKLIVRF.js.map +0 -1
- package/dist/chunk-7SSCNCTW.mjs +0 -137
- package/dist/chunk-7SSCNCTW.mjs.map +0 -1
- package/dist/chunk-BG56B4DE.js +0 -106
- package/dist/chunk-BG56B4DE.js.map +0 -1
- package/dist/chunk-CLM5PNSG.mjs +0 -496
- package/dist/chunk-CLM5PNSG.mjs.map +0 -1
- package/dist/chunk-DNLGCKTT.js +0 -31
- package/dist/chunk-DNLGCKTT.js.map +0 -1
- package/dist/chunk-MXINIFPC.js +0 -105
- package/dist/chunk-MXINIFPC.js.map +0 -1
- package/dist/chunk-O4II6N34.js +0 -137
- package/dist/chunk-O4II6N34.js.map +0 -1
- package/dist/chunk-SE32ZPOZ.js +0 -496
- package/dist/chunk-SE32ZPOZ.js.map +0 -1
- package/dist/chunk-UAL54DVV.mjs +0 -106
- package/dist/chunk-UAL54DVV.mjs.map +0 -1
- package/dist/chunk-WU6FW77M.mjs +0 -105
- package/dist/chunk-WU6FW77M.mjs.map +0 -1
- package/dist/chunk-YBM3IJEA.mjs.map +0 -1
- package/dist/chunk-YSLEF5C5.mjs +0 -1
- package/dist/chunk-ZX7QIN24.mjs +0 -31
- package/dist/chunk-ZX7QIN24.mjs.map +0 -1
- package/dist/decorators-BT1FFqN0.d.mts +0 -29
- package/dist/decorators-DvS58PqC.d.ts +0 -29
- package/dist/index-Co5ZsLqq.d.ts +0 -58
- package/dist/index-D94W1__r.d.mts +0 -58
- package/dist/index-DQmyVp6F.d.mts +0 -27
- package/dist/index-KL_1BrQb.d.ts +0 -27
- /package/dist/{chunk-JHOVXH3X.mjs.map → chunk-C2AG7Q3C.mjs.map} +0 -0
- /package/dist/{chunk-7TLSPR65.mjs.map → chunk-DS5KVVWJ.mjs.map} +0 -0
- /package/dist/{chunk-YN6WIWNQ.mjs.map → chunk-FUPLZMSR.mjs.map} +0 -0
- /package/dist/{chunk-342VRT25.mjs.map → chunk-VBIQGUDI.mjs.map} +0 -0
- /package/dist/{chunk-YSLEF5C5.mjs.map → server/index.mjs.map} +0 -0
package/dist/client/index.js
CHANGED
|
@@ -1,13 +1,187 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
20
|
|
|
21
|
+
// src/client/index.ts
|
|
22
|
+
var client_exports = {};
|
|
23
|
+
__export(client_exports, {
|
|
24
|
+
FusionFetcher: () => FusionFetcher,
|
|
25
|
+
apiFetcher: () => apiFetcher,
|
|
26
|
+
createWextsRpcClient: () => createWextsRpcClient
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(client_exports);
|
|
3
29
|
|
|
30
|
+
// src/errors.ts
|
|
31
|
+
var WextsError = class extends Error {
|
|
32
|
+
static {
|
|
33
|
+
__name(this, "WextsError");
|
|
34
|
+
}
|
|
35
|
+
code;
|
|
36
|
+
suggestedFix;
|
|
37
|
+
docsSlug;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
super(options.message, options.cause === void 0 ? void 0 : {
|
|
40
|
+
cause: options.cause
|
|
41
|
+
});
|
|
42
|
+
this.name = "WextsError";
|
|
43
|
+
this.code = options.code;
|
|
44
|
+
this.suggestedFix = options.suggestedFix;
|
|
45
|
+
this.docsSlug = options.docsSlug;
|
|
46
|
+
}
|
|
47
|
+
get docsUrl() {
|
|
48
|
+
return this.docsSlug ? `https://github.com/ziadmustafa1/wexts/blob/main/docs/${this.docsSlug}.md` : void 0;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var WextsRpcError = class extends WextsError {
|
|
52
|
+
static {
|
|
53
|
+
__name(this, "WextsRpcError");
|
|
54
|
+
}
|
|
55
|
+
constructor(options) {
|
|
56
|
+
super({
|
|
57
|
+
code: options.code ?? "WEXTS_RPC_ERROR",
|
|
58
|
+
...options
|
|
59
|
+
});
|
|
60
|
+
this.name = "WextsRpcError";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
4
63
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
64
|
+
// src/client/fetcher.ts
|
|
65
|
+
var FusionFetcher = class {
|
|
66
|
+
static {
|
|
67
|
+
__name(this, "FusionFetcher");
|
|
68
|
+
}
|
|
69
|
+
baseUrl;
|
|
70
|
+
constructor(baseUrl = "/api") {
|
|
71
|
+
this.baseUrl = baseUrl;
|
|
72
|
+
}
|
|
73
|
+
async request(method, path, body) {
|
|
74
|
+
const headers = {
|
|
75
|
+
"Content-Type": "application/json"
|
|
76
|
+
};
|
|
77
|
+
if (typeof window !== "undefined") {
|
|
78
|
+
const token = localStorage.getItem("fusion_token");
|
|
79
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
80
|
+
}
|
|
81
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
82
|
+
method,
|
|
83
|
+
headers,
|
|
84
|
+
body: body ? JSON.stringify(body) : void 0
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new WextsRpcError({
|
|
88
|
+
code: "WEXTS_API_REQUEST_FAILED",
|
|
89
|
+
message: `Fusion API Error: ${response.status} ${response.statusText}`,
|
|
90
|
+
suggestedFix: "Check the API route, server logs, and authentication headers.",
|
|
91
|
+
docsSlug: "troubleshooting"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (response.status === 204) {
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
return response.json();
|
|
98
|
+
}
|
|
99
|
+
get(path) {
|
|
100
|
+
return this.request("GET", path);
|
|
101
|
+
}
|
|
102
|
+
post(path, body) {
|
|
103
|
+
return this.request("POST", path, body);
|
|
104
|
+
}
|
|
105
|
+
put(path, body) {
|
|
106
|
+
return this.request("PUT", path, body);
|
|
107
|
+
}
|
|
108
|
+
delete(path) {
|
|
109
|
+
return this.request("DELETE", path);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var apiFetcher = new FusionFetcher();
|
|
113
|
+
function createWextsRpcClient(manifest, options = {}) {
|
|
114
|
+
const hasManifest = Boolean(manifest);
|
|
115
|
+
const services = new Set((manifest?.services ?? []).map((service) => service.name));
|
|
116
|
+
const methodMap = /* @__PURE__ */ new Map();
|
|
117
|
+
for (const service of manifest?.services ?? []) {
|
|
118
|
+
methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));
|
|
119
|
+
}
|
|
120
|
+
const createServiceProxy = /* @__PURE__ */ __name((serviceName) => new Proxy({}, {
|
|
121
|
+
get(_target, methodName) {
|
|
122
|
+
if (typeof methodName !== "string") return void 0;
|
|
123
|
+
if (methodName === "then") return void 0;
|
|
124
|
+
const knownMethods = methodMap.get(serviceName);
|
|
125
|
+
if (knownMethods && !knownMethods.has(methodName)) {
|
|
126
|
+
throw new WextsRpcError({
|
|
127
|
+
code: "WEXTS_RPC_METHOD_NOT_FOUND",
|
|
128
|
+
message: `Wexts RPC method not found: ${serviceName}.${methodName}`,
|
|
129
|
+
suggestedFix: "Run `wexts generate` and verify the method is decorated with @RpcMethod().",
|
|
130
|
+
docsSlug: "rpc"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return (...args) => invokeRpc(serviceName, methodName, args, options);
|
|
134
|
+
}
|
|
135
|
+
}), "createServiceProxy");
|
|
136
|
+
return new Proxy({}, {
|
|
137
|
+
get(_target, serviceName) {
|
|
138
|
+
if (typeof serviceName !== "string") return void 0;
|
|
139
|
+
if (serviceName === "then") return void 0;
|
|
140
|
+
if (!hasManifest) {
|
|
141
|
+
throw new WextsRpcError({
|
|
142
|
+
code: "WEXTS_RPC_MANIFEST_MISSING",
|
|
143
|
+
message: "Wexts RPC manifest is missing.",
|
|
144
|
+
suggestedFix: "Run `wexts generate` and import the generated client/provider instead of creating an empty client.",
|
|
145
|
+
docsSlug: "codegen"
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (!services.has(serviceName)) {
|
|
149
|
+
throw new WextsRpcError({
|
|
150
|
+
code: "WEXTS_RPC_SERVICE_NOT_FOUND",
|
|
151
|
+
message: `Wexts RPC service not found: ${serviceName}`,
|
|
152
|
+
suggestedFix: "Run `wexts generate` and verify the service is decorated with @RpcService().",
|
|
153
|
+
docsSlug: "rpc"
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return createServiceProxy(serviceName);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
__name(createWextsRpcClient, "createWextsRpcClient");
|
|
161
|
+
async function invokeRpc(serviceName, methodName, args, options) {
|
|
162
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
163
|
+
const baseUrl = options.baseUrl ?? "/rpc";
|
|
164
|
+
const headers = {
|
|
165
|
+
"Content-Type": "application/json",
|
|
166
|
+
...await options.getHeaders?.() ?? {}
|
|
167
|
+
};
|
|
168
|
+
const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers,
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
args
|
|
173
|
+
})
|
|
174
|
+
});
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
throw new WextsRpcError({
|
|
177
|
+
code: "WEXTS_RPC_REQUEST_FAILED",
|
|
178
|
+
message: `Wexts RPC Error: ${response.status} ${response.statusText}`,
|
|
179
|
+
suggestedFix: "Check the RPC route, service policy, and server logs.",
|
|
180
|
+
docsSlug: "troubleshooting"
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const payload = await response.json();
|
|
184
|
+
return payload.data;
|
|
185
|
+
}
|
|
186
|
+
__name(invokeRpc, "invokeRpc");
|
|
13
187
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Volumes/Projects/wexts/packages/dist/client/index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACF,+KAAC","file":"/Volumes/Projects/wexts/packages/dist/client/index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/client/index.ts","../../src/errors.ts","../../src/client/fetcher.ts"],"sourcesContent":["export * from './fetcher';\n","export interface WextsErrorOptions {\n code: string;\n message: string;\n cause?: unknown;\n suggestedFix?: string;\n docsSlug?: string;\n}\n\nexport class WextsError extends Error {\n readonly code: string;\n readonly suggestedFix?: string;\n readonly docsSlug?: string;\n\n constructor(options: WextsErrorOptions) {\n super(options.message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = 'WextsError';\n this.code = options.code;\n this.suggestedFix = options.suggestedFix;\n this.docsSlug = options.docsSlug;\n }\n\n get docsUrl(): string | undefined {\n return this.docsSlug ? `https://github.com/ziadmustafa1/wexts/blob/main/docs/${this.docsSlug}.md` : undefined;\n }\n}\n\nexport class WextsRpcError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_RPC_ERROR', ...options });\n this.name = 'WextsRpcError';\n }\n}\n\nexport class WextsCodegenError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_CODEGEN_ERROR', ...options });\n this.name = 'WextsCodegenError';\n }\n}\n\nexport class WextsRuntimeError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_RUNTIME_ERROR', ...options });\n this.name = 'WextsRuntimeError';\n }\n}\n\nexport class WextsSecurityError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_SECURITY_ERROR', ...options });\n this.name = 'WextsSecurityError';\n }\n}\n\nexport function formatWextsError(error: unknown): string {\n if (!(error instanceof WextsError)) {\n return error instanceof Error ? error.message : String(error);\n }\n\n const lines = [`${error.code}: ${error.message}`];\n if (error.suggestedFix) lines.push(`Suggested fix: ${error.suggestedFix}`);\n if (error.docsUrl) lines.push(`Docs: ${error.docsUrl}`);\n return lines.join('\\n');\n}\n","import type { RpcManifest, RpcInvocationResponse } from '../rpc/types';\nimport { WextsRpcError } from '../errors';\n\nexport class FusionFetcher {\n private baseUrl: string;\n\n constructor(baseUrl: string = '/api') {\n this.baseUrl = baseUrl;\n }\n\n private async request<T>(method: string, path: string, body?: any): Promise<T> {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Automatically attach Fusion Token if present\n if (typeof window !== 'undefined') {\n const token = localStorage.getItem('fusion_token');\n if (token) headers['Authorization'] = `Bearer ${token}`;\n }\n\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new WextsRpcError({\n code: 'WEXTS_API_REQUEST_FAILED',\n message: `Fusion API Error: ${response.status} ${response.statusText}`,\n suggestedFix: 'Check the API route, server logs, and authentication headers.',\n docsSlug: 'troubleshooting',\n });\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return response.json();\n }\n\n get<T>(path: string) { return this.request<T>('GET', path); }\n post<T>(path: string, body: any) { return this.request<T>('POST', path, body); }\n put<T>(path: string, body: any) { return this.request<T>('PUT', path, body); }\n delete<T>(path: string) { return this.request<T>('DELETE', path); }\n}\n\nexport const apiFetcher = new FusionFetcher();\n\nexport interface WextsRpcClientOptions {\n baseUrl?: string;\n fetch?: typeof fetch;\n getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;\n}\n\nexport type WextsRpcClient = Record<string, Record<string, (...args: unknown[]) => Promise<unknown>>>;\n\nexport function createWextsRpcClient(\n manifest: Pick<RpcManifest, 'services'> | undefined,\n options: WextsRpcClientOptions = {}\n): WextsRpcClient {\n const hasManifest = Boolean(manifest);\n const services = new Set((manifest?.services ?? []).map((service) => service.name));\n const methodMap = new Map<string, Set<string>>();\n\n for (const service of manifest?.services ?? []) {\n methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));\n }\n\n const createServiceProxy = (serviceName: string) => new Proxy({}, {\n get(_target, methodName) {\n if (typeof methodName !== 'string') return undefined;\n if (methodName === 'then') return undefined;\n\n const knownMethods = methodMap.get(serviceName);\n if (knownMethods && !knownMethods.has(methodName)) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_METHOD_NOT_FOUND',\n message: `Wexts RPC method not found: ${serviceName}.${methodName}`,\n suggestedFix: 'Run `wexts generate` and verify the method is decorated with @RpcMethod().',\n docsSlug: 'rpc',\n });\n }\n\n return (...args: unknown[]) => invokeRpc(serviceName, methodName, args, options);\n },\n }) as Record<string, (...args: unknown[]) => Promise<unknown>>;\n\n return new Proxy({}, {\n get(_target, serviceName) {\n if (typeof serviceName !== 'string') return undefined;\n if (serviceName === 'then') return undefined;\n if (!hasManifest) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_MANIFEST_MISSING',\n message: 'Wexts RPC manifest is missing.',\n suggestedFix: 'Run `wexts generate` and import the generated client/provider instead of creating an empty client.',\n docsSlug: 'codegen',\n });\n }\n if (!services.has(serviceName)) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_SERVICE_NOT_FOUND',\n message: `Wexts RPC service not found: ${serviceName}`,\n suggestedFix: 'Run `wexts generate` and verify the service is decorated with @RpcService().',\n docsSlug: 'rpc',\n });\n }\n\n return createServiceProxy(serviceName);\n },\n }) as WextsRpcClient;\n}\n\nasync function invokeRpc(\n serviceName: string,\n methodName: string,\n args: unknown[],\n options: WextsRpcClientOptions\n): Promise<unknown> {\n const fetchImpl = options.fetch ?? fetch;\n const baseUrl = options.baseUrl ?? '/rpc';\n const headers = {\n 'Content-Type': 'application/json',\n ...(await options.getHeaders?.() ?? {}),\n };\n const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {\n method: 'POST',\n headers,\n body: JSON.stringify({ args }),\n });\n\n if (!response.ok) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_REQUEST_FAILED',\n message: `Wexts RPC Error: ${response.status} ${response.statusText}`,\n suggestedFix: 'Check the RPC route, service policy, and server logs.',\n docsSlug: 'troubleshooting',\n });\n }\n\n const payload = await response.json() as RpcInvocationResponse;\n return payload.data;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACQO,IAAMA,aAAN,cAAyBC,MAAAA;EAAhC,OAAgCA;;;EACnBC;EACAC;EACAC;EAET,YAAYC,SAA4B;AACpC,UAAMA,QAAQC,SAASD,QAAQE,UAAUC,SAAYA,SAAY;MAAED,OAAOF,QAAQE;IAAM,CAAA;AACxF,SAAKE,OAAO;AACZ,SAAKP,OAAOG,QAAQH;AACpB,SAAKC,eAAeE,QAAQF;AAC5B,SAAKC,WAAWC,QAAQD;EAC5B;EAEA,IAAIM,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J;AACA,UAAI,CAACY,SAASe,IAAIL,WAAAA,GAAc;AAC5B,cAAM,IAAI5B,cAAc;UACpBC,MAAM;UACNC,SAAS,gCAAgC0B,WAAAA;UACzCvB,cAAc;UACdC,UAAU;QACd,CAAA;MACJ;AAEA,aAAOqB,mBAAmBC,WAAAA;IAC9B;EACJ,CAAA;AACJ;AAvDgBf;AAyDhB,eAAesB,UACXP,aACAG,YACAG,MACAnB,SAA8B;AAE9B,QAAMqB,YAAYrB,QAAQpB,SAASA;AACnC,QAAMX,UAAU+B,QAAQ/B,WAAW;AACnC,QAAMK,UAAU;IACZ,gBAAgB;IAChB,GAAI,MAAM0B,QAAQsB,aAAU,KAAQ,CAAC;EACzC;AACA,QAAM3C,WAAW,MAAM0C,UAAU,GAAGpD,OAAAA,IAAWsD,mBAAmBV,WAAAA,CAAAA,IAAgBU,mBAAmBP,UAAAA,CAAAA,IAAe;IAChH7C,QAAQ;IACRG;IACAD,MAAMQ,KAAKC,UAAU;MAAEqC;IAAK,CAAA;EAChC,CAAA;AAEA,MAAI,CAACxC,SAASK,IAAI;AACd,UAAM,IAAIC,cAAc;MACpBC,MAAM;MACNC,SAAS,oBAAoBR,SAASS,MAAM,IAAIT,SAASU,UAAU;MACnEC,cAAc;MACdC,UAAU;IACd,CAAA;EACJ;AAEA,QAAMiC,UAAU,MAAM7C,SAASa,KAAI;AACnC,SAAOgC,QAAQC;AACnB;AA7BeL;","names":["WextsError","Error","code","suggestedFix","docsSlug","options","message","cause","undefined","name","docsUrl","WextsRpcError","FusionFetcher","baseUrl","request","method","path","body","headers","window","token","localStorage","getItem","response","fetch","JSON","stringify","undefined","ok","WextsRpcError","code","message","status","statusText","suggestedFix","docsSlug","json","get","post","put","delete","apiFetcher","createWextsRpcClient","manifest","options","hasManifest","Boolean","services","Set","map","service","name","methodMap","Map","set","methods","createServiceProxy","serviceName","Proxy","_target","methodName","knownMethods","has","args","invokeRpc","fetchImpl","getHeaders","encodeURIComponent","payload","data"]}
|
package/dist/client/index.mjs
CHANGED
|
@@ -1,10 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/errors.ts
|
|
5
|
+
var WextsError = class extends Error {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "WextsError");
|
|
8
|
+
}
|
|
9
|
+
code;
|
|
10
|
+
suggestedFix;
|
|
11
|
+
docsSlug;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options.message, options.cause === void 0 ? void 0 : {
|
|
14
|
+
cause: options.cause
|
|
15
|
+
});
|
|
16
|
+
this.name = "WextsError";
|
|
17
|
+
this.code = options.code;
|
|
18
|
+
this.suggestedFix = options.suggestedFix;
|
|
19
|
+
this.docsSlug = options.docsSlug;
|
|
20
|
+
}
|
|
21
|
+
get docsUrl() {
|
|
22
|
+
return this.docsSlug ? `https://github.com/ziadmustafa1/wexts/blob/main/docs/${this.docsSlug}.md` : void 0;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var WextsRpcError = class extends WextsError {
|
|
26
|
+
static {
|
|
27
|
+
__name(this, "WextsRpcError");
|
|
28
|
+
}
|
|
29
|
+
constructor(options) {
|
|
30
|
+
super({
|
|
31
|
+
code: options.code ?? "WEXTS_RPC_ERROR",
|
|
32
|
+
...options
|
|
33
|
+
});
|
|
34
|
+
this.name = "WextsRpcError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/client/fetcher.ts
|
|
39
|
+
var FusionFetcher = class {
|
|
40
|
+
static {
|
|
41
|
+
__name(this, "FusionFetcher");
|
|
42
|
+
}
|
|
43
|
+
baseUrl;
|
|
44
|
+
constructor(baseUrl = "/api") {
|
|
45
|
+
this.baseUrl = baseUrl;
|
|
46
|
+
}
|
|
47
|
+
async request(method, path, body) {
|
|
48
|
+
const headers = {
|
|
49
|
+
"Content-Type": "application/json"
|
|
50
|
+
};
|
|
51
|
+
if (typeof window !== "undefined") {
|
|
52
|
+
const token = localStorage.getItem("fusion_token");
|
|
53
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
54
|
+
}
|
|
55
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
56
|
+
method,
|
|
57
|
+
headers,
|
|
58
|
+
body: body ? JSON.stringify(body) : void 0
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
throw new WextsRpcError({
|
|
62
|
+
code: "WEXTS_API_REQUEST_FAILED",
|
|
63
|
+
message: `Fusion API Error: ${response.status} ${response.statusText}`,
|
|
64
|
+
suggestedFix: "Check the API route, server logs, and authentication headers.",
|
|
65
|
+
docsSlug: "troubleshooting"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (response.status === 204) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
return response.json();
|
|
72
|
+
}
|
|
73
|
+
get(path) {
|
|
74
|
+
return this.request("GET", path);
|
|
75
|
+
}
|
|
76
|
+
post(path, body) {
|
|
77
|
+
return this.request("POST", path, body);
|
|
78
|
+
}
|
|
79
|
+
put(path, body) {
|
|
80
|
+
return this.request("PUT", path, body);
|
|
81
|
+
}
|
|
82
|
+
delete(path) {
|
|
83
|
+
return this.request("DELETE", path);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var apiFetcher = new FusionFetcher();
|
|
87
|
+
function createWextsRpcClient(manifest, options = {}) {
|
|
88
|
+
const hasManifest = Boolean(manifest);
|
|
89
|
+
const services = new Set((manifest?.services ?? []).map((service) => service.name));
|
|
90
|
+
const methodMap = /* @__PURE__ */ new Map();
|
|
91
|
+
for (const service of manifest?.services ?? []) {
|
|
92
|
+
methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));
|
|
93
|
+
}
|
|
94
|
+
const createServiceProxy = /* @__PURE__ */ __name((serviceName) => new Proxy({}, {
|
|
95
|
+
get(_target, methodName) {
|
|
96
|
+
if (typeof methodName !== "string") return void 0;
|
|
97
|
+
if (methodName === "then") return void 0;
|
|
98
|
+
const knownMethods = methodMap.get(serviceName);
|
|
99
|
+
if (knownMethods && !knownMethods.has(methodName)) {
|
|
100
|
+
throw new WextsRpcError({
|
|
101
|
+
code: "WEXTS_RPC_METHOD_NOT_FOUND",
|
|
102
|
+
message: `Wexts RPC method not found: ${serviceName}.${methodName}`,
|
|
103
|
+
suggestedFix: "Run `wexts generate` and verify the method is decorated with @RpcMethod().",
|
|
104
|
+
docsSlug: "rpc"
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return (...args) => invokeRpc(serviceName, methodName, args, options);
|
|
108
|
+
}
|
|
109
|
+
}), "createServiceProxy");
|
|
110
|
+
return new Proxy({}, {
|
|
111
|
+
get(_target, serviceName) {
|
|
112
|
+
if (typeof serviceName !== "string") return void 0;
|
|
113
|
+
if (serviceName === "then") return void 0;
|
|
114
|
+
if (!hasManifest) {
|
|
115
|
+
throw new WextsRpcError({
|
|
116
|
+
code: "WEXTS_RPC_MANIFEST_MISSING",
|
|
117
|
+
message: "Wexts RPC manifest is missing.",
|
|
118
|
+
suggestedFix: "Run `wexts generate` and import the generated client/provider instead of creating an empty client.",
|
|
119
|
+
docsSlug: "codegen"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (!services.has(serviceName)) {
|
|
123
|
+
throw new WextsRpcError({
|
|
124
|
+
code: "WEXTS_RPC_SERVICE_NOT_FOUND",
|
|
125
|
+
message: `Wexts RPC service not found: ${serviceName}`,
|
|
126
|
+
suggestedFix: "Run `wexts generate` and verify the service is decorated with @RpcService().",
|
|
127
|
+
docsSlug: "rpc"
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return createServiceProxy(serviceName);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
__name(createWextsRpcClient, "createWextsRpcClient");
|
|
135
|
+
async function invokeRpc(serviceName, methodName, args, options) {
|
|
136
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
137
|
+
const baseUrl = options.baseUrl ?? "/rpc";
|
|
138
|
+
const headers = {
|
|
139
|
+
"Content-Type": "application/json",
|
|
140
|
+
...await options.getHeaders?.() ?? {}
|
|
141
|
+
};
|
|
142
|
+
const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers,
|
|
145
|
+
body: JSON.stringify({
|
|
146
|
+
args
|
|
147
|
+
})
|
|
148
|
+
});
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
throw new WextsRpcError({
|
|
151
|
+
code: "WEXTS_RPC_REQUEST_FAILED",
|
|
152
|
+
message: `Wexts RPC Error: ${response.status} ${response.statusText}`,
|
|
153
|
+
suggestedFix: "Check the RPC route, service policy, and server logs.",
|
|
154
|
+
docsSlug: "troubleshooting"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const payload = await response.json();
|
|
158
|
+
return payload.data;
|
|
159
|
+
}
|
|
160
|
+
__name(invokeRpc, "invokeRpc");
|
|
8
161
|
export {
|
|
9
162
|
FusionFetcher,
|
|
10
163
|
apiFetcher,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/errors.ts","../../src/client/fetcher.ts"],"sourcesContent":["export interface WextsErrorOptions {\n code: string;\n message: string;\n cause?: unknown;\n suggestedFix?: string;\n docsSlug?: string;\n}\n\nexport class WextsError extends Error {\n readonly code: string;\n readonly suggestedFix?: string;\n readonly docsSlug?: string;\n\n constructor(options: WextsErrorOptions) {\n super(options.message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = 'WextsError';\n this.code = options.code;\n this.suggestedFix = options.suggestedFix;\n this.docsSlug = options.docsSlug;\n }\n\n get docsUrl(): string | undefined {\n return this.docsSlug ? `https://github.com/ziadmustafa1/wexts/blob/main/docs/${this.docsSlug}.md` : undefined;\n }\n}\n\nexport class WextsRpcError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_RPC_ERROR', ...options });\n this.name = 'WextsRpcError';\n }\n}\n\nexport class WextsCodegenError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_CODEGEN_ERROR', ...options });\n this.name = 'WextsCodegenError';\n }\n}\n\nexport class WextsRuntimeError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_RUNTIME_ERROR', ...options });\n this.name = 'WextsRuntimeError';\n }\n}\n\nexport class WextsSecurityError extends WextsError {\n constructor(options: Omit<WextsErrorOptions, 'code'> & { code?: string }) {\n super({ code: options.code ?? 'WEXTS_SECURITY_ERROR', ...options });\n this.name = 'WextsSecurityError';\n }\n}\n\nexport function formatWextsError(error: unknown): string {\n if (!(error instanceof WextsError)) {\n return error instanceof Error ? error.message : String(error);\n }\n\n const lines = [`${error.code}: ${error.message}`];\n if (error.suggestedFix) lines.push(`Suggested fix: ${error.suggestedFix}`);\n if (error.docsUrl) lines.push(`Docs: ${error.docsUrl}`);\n return lines.join('\\n');\n}\n","import type { RpcManifest, RpcInvocationResponse } from '../rpc/types';\nimport { WextsRpcError } from '../errors';\n\nexport class FusionFetcher {\n private baseUrl: string;\n\n constructor(baseUrl: string = '/api') {\n this.baseUrl = baseUrl;\n }\n\n private async request<T>(method: string, path: string, body?: any): Promise<T> {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Automatically attach Fusion Token if present\n if (typeof window !== 'undefined') {\n const token = localStorage.getItem('fusion_token');\n if (token) headers['Authorization'] = `Bearer ${token}`;\n }\n\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new WextsRpcError({\n code: 'WEXTS_API_REQUEST_FAILED',\n message: `Fusion API Error: ${response.status} ${response.statusText}`,\n suggestedFix: 'Check the API route, server logs, and authentication headers.',\n docsSlug: 'troubleshooting',\n });\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return response.json();\n }\n\n get<T>(path: string) { return this.request<T>('GET', path); }\n post<T>(path: string, body: any) { return this.request<T>('POST', path, body); }\n put<T>(path: string, body: any) { return this.request<T>('PUT', path, body); }\n delete<T>(path: string) { return this.request<T>('DELETE', path); }\n}\n\nexport const apiFetcher = new FusionFetcher();\n\nexport interface WextsRpcClientOptions {\n baseUrl?: string;\n fetch?: typeof fetch;\n getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;\n}\n\nexport type WextsRpcClient = Record<string, Record<string, (...args: unknown[]) => Promise<unknown>>>;\n\nexport function createWextsRpcClient(\n manifest: Pick<RpcManifest, 'services'> | undefined,\n options: WextsRpcClientOptions = {}\n): WextsRpcClient {\n const hasManifest = Boolean(manifest);\n const services = new Set((manifest?.services ?? []).map((service) => service.name));\n const methodMap = new Map<string, Set<string>>();\n\n for (const service of manifest?.services ?? []) {\n methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));\n }\n\n const createServiceProxy = (serviceName: string) => new Proxy({}, {\n get(_target, methodName) {\n if (typeof methodName !== 'string') return undefined;\n if (methodName === 'then') return undefined;\n\n const knownMethods = methodMap.get(serviceName);\n if (knownMethods && !knownMethods.has(methodName)) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_METHOD_NOT_FOUND',\n message: `Wexts RPC method not found: ${serviceName}.${methodName}`,\n suggestedFix: 'Run `wexts generate` and verify the method is decorated with @RpcMethod().',\n docsSlug: 'rpc',\n });\n }\n\n return (...args: unknown[]) => invokeRpc(serviceName, methodName, args, options);\n },\n }) as Record<string, (...args: unknown[]) => Promise<unknown>>;\n\n return new Proxy({}, {\n get(_target, serviceName) {\n if (typeof serviceName !== 'string') return undefined;\n if (serviceName === 'then') return undefined;\n if (!hasManifest) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_MANIFEST_MISSING',\n message: 'Wexts RPC manifest is missing.',\n suggestedFix: 'Run `wexts generate` and import the generated client/provider instead of creating an empty client.',\n docsSlug: 'codegen',\n });\n }\n if (!services.has(serviceName)) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_SERVICE_NOT_FOUND',\n message: `Wexts RPC service not found: ${serviceName}`,\n suggestedFix: 'Run `wexts generate` and verify the service is decorated with @RpcService().',\n docsSlug: 'rpc',\n });\n }\n\n return createServiceProxy(serviceName);\n },\n }) as WextsRpcClient;\n}\n\nasync function invokeRpc(\n serviceName: string,\n methodName: string,\n args: unknown[],\n options: WextsRpcClientOptions\n): Promise<unknown> {\n const fetchImpl = options.fetch ?? fetch;\n const baseUrl = options.baseUrl ?? '/rpc';\n const headers = {\n 'Content-Type': 'application/json',\n ...(await options.getHeaders?.() ?? {}),\n };\n const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {\n method: 'POST',\n headers,\n body: JSON.stringify({ args }),\n });\n\n if (!response.ok) {\n throw new WextsRpcError({\n code: 'WEXTS_RPC_REQUEST_FAILED',\n message: `Wexts RPC Error: ${response.status} ${response.statusText}`,\n suggestedFix: 'Check the RPC route, service policy, and server logs.',\n docsSlug: 'troubleshooting',\n });\n }\n\n const payload = await response.json() as RpcInvocationResponse;\n return payload.data;\n}\n"],"mappings":";;;;AAQO,IAAMA,aAAN,cAAyBC,MAAAA;EAAhC,OAAgCA;;;EACnBC;EACAC;EACAC;EAET,YAAYC,SAA4B;AACpC,UAAMA,QAAQC,SAASD,QAAQE,UAAUC,SAAYA,SAAY;MAAED,OAAOF,QAAQE;IAAM,CAAA;AACxF,SAAKE,OAAO;AACZ,SAAKP,OAAOG,QAAQH;AACpB,SAAKC,eAAeE,QAAQF;AAC5B,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AAS;UACTG,cAAc;UACdC,UAAU;QACd,CAAA;MACJ;AACA,UAAI,CAACY,SAASe,IAAIL,WAAAA,GAAc;AAC5B,cAAM,IAAI5B,cAAc;UACpBC,MAAM;UACNC,SAAS,gCAAgC0B,WAAAA;UACzCvB,cAAc;UACdC,UAAU;QACd,CAAA;MACJ;AAEA,aAAOqB,mBAAmBC,WAAAA;IAC9B;EACJ,CAAA;AACJ;AAvDgBf;AAyDhB,eAAesB,UACXP,aACAG,YACAG,MACAnB,SAA8B;AAE9B,QAAMqB,YAAYrB,QAAQpB,SAASA;AACnC,QAAMX,UAAU+B,QAAQ/B,WAAW;AACnC,QAAMK,UAAU;IACZ,gBAAgB;IAChB,GAAI,MAAM0B,QAAQsB,aAAU,KAAQ,CAAC;EACzC;AACA,QAAM3C,WAAW,MAAM0C,UAAU,GAAGpD,OAAAA,IAAWsD,mBAAmBV,WAAAA,CAAAA,IAAgBU,mBAAmBP,UAAAA,CAAAA,IAAe;IAChH7C,QAAQ;IACRG;IACAD,MAAMQ,KAAKC,UAAU;MAAEqC;IAAK,CAAA;EAChC,CAAA;AAEA,MAAI,CAACxC,SAASK,IAAI;AACd,UAAM,IAAIC,cAAc;MACpBC,MAAM;MACNC,SAAS,oBAAoBR,SAASS,MAAM,IAAIT,SAASU,UAAU;MACnEC,cAAc;MACdC,UAAU;IACd,CAAA;EACJ;AAEA,QAAMiC,UAAU,MAAM7C,SAASa,KAAI;AACnC,SAAOgC,QAAQC;AACnB;AA7BeL;","names":["WextsError","Error","code","suggestedFix","docsSlug","options","message","cause","undefined","name","docsUrl","WextsRpcError","FusionFetcher","baseUrl","request","method","path","body","headers","window","token","localStorage","getItem","response","fetch","JSON","stringify","undefined","ok","WextsRpcError","code","message","status","statusText","suggestedFix","docsSlug","json","get","post","put","delete","apiFetcher","createWextsRpcClient","manifest","options","hasManifest","Boolean","services","Set","map","service","name","methodMap","Map","set","methods","createServiceProxy","serviceName","Proxy","_target","methodName","knownMethods","has","args","invokeRpc","fetchImpl","getHeaders","encodeURIComponent","payload","data"]}
|
package/dist/codegen/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as ClientGenerator, a as CodegenWatcher, b as ControllerInfo, G as GenerateOptions, c as GenerateRpcOptions, N as NestJSParser, R as RouteInfo, W as WatchOptions, g as generateRpcClient } from '../index-
|
|
2
|
-
import '../types-
|
|
1
|
+
export { C as ClientGenerator, a as CodegenWatcher, b as ControllerInfo, G as GenerateOptions, c as GenerateRpcOptions, N as NestJSParser, R as RouteInfo, W as WatchOptions, g as generateRpcClient } from '../index-h66Vq9dK.mjs';
|
|
2
|
+
import '../types-CQ_aexOX.mjs';
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as ClientGenerator, a as CodegenWatcher, b as ControllerInfo, G as GenerateOptions, c as GenerateRpcOptions, N as NestJSParser, R as RouteInfo, W as WatchOptions, g as generateRpcClient } from '../index-
|
|
2
|
-
import '../types-
|
|
1
|
+
export { C as ClientGenerator, a as CodegenWatcher, b as ControllerInfo, G as GenerateOptions, c as GenerateRpcOptions, N as NestJSParser, R as RouteInfo, W as WatchOptions, g as generateRpcClient } from '../index-CJKs4wtN.js';
|
|
2
|
+
import '../types-CQ_aexOX.js';
|
package/dist/codegen/index.js
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
require('../chunk-WCKSKU3C.js');
|
|
6
|
+
var _chunk75HBI2XGjs = require('../chunk-75HBI2XG.js');
|
|
8
7
|
require('../chunk-AVMQJWYD.js');
|
|
8
|
+
require('../chunk-WCKSKU3C.js');
|
|
9
9
|
require('../chunk-XE4OXN2W.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
exports.ClientGenerator =
|
|
15
|
+
exports.ClientGenerator = _chunk75HBI2XGjs.ClientGenerator; exports.CodegenWatcher = _chunk75HBI2XGjs.CodegenWatcher; exports.NestJSParser = _chunk75HBI2XGjs.NestJSParser; exports.generateRpcClient = _chunk75HBI2XGjs.generateRpcClient;
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
package/dist/codegen/index.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
CodegenWatcher,
|
|
4
4
|
NestJSParser,
|
|
5
5
|
generateRpcClient
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-VBIQGUDI.mjs";
|
|
7
|
+
import "../chunk-DS5KVVWJ.mjs";
|
|
8
|
+
import "../chunk-C2AG7Q3C.mjs";
|
|
9
|
+
import "../chunk-L77ANWWT.mjs";
|
|
10
10
|
export {
|
|
11
11
|
ClientGenerator,
|
|
12
12
|
CodegenWatcher,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { R as RpcAuthPolicy } from './types-CQ_aexOX.js';
|
|
2
|
+
|
|
3
|
+
interface FusionRouteMetadata {
|
|
4
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
path: string;
|
|
6
|
+
responseType?: string;
|
|
7
|
+
requestType?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Mark a NestJS controller for Fusion codegen
|
|
11
|
+
* Usage: @FusionController('users')
|
|
12
|
+
*/
|
|
13
|
+
declare function FusionController(prefix?: string): ClassDecorator;
|
|
14
|
+
/**
|
|
15
|
+
* Mark a route for API client generation
|
|
16
|
+
* Usage: @FusionRoute({ method: 'GET', path: '/:id' })
|
|
17
|
+
*/
|
|
18
|
+
declare function FusionRoute(metadata: FusionRouteMetadata): MethodDecorator;
|
|
19
|
+
/**
|
|
20
|
+
* Helper decorators for common HTTP methods
|
|
21
|
+
*/
|
|
22
|
+
declare function FusionGet(path?: string): MethodDecorator;
|
|
23
|
+
declare function FusionPost(path?: string): MethodDecorator;
|
|
24
|
+
declare function FusionPut(path?: string): MethodDecorator;
|
|
25
|
+
declare function FusionDelete(path?: string): MethodDecorator;
|
|
26
|
+
/**
|
|
27
|
+
* Get Fusion metadata from a controller
|
|
28
|
+
*/
|
|
29
|
+
declare function getFusionMetadata(controller: any): {
|
|
30
|
+
controller: any;
|
|
31
|
+
routes: any[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface RpcServiceOptions {
|
|
35
|
+
name?: string;
|
|
36
|
+
requireAuth?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface RpcMethodOptions {
|
|
39
|
+
name?: string;
|
|
40
|
+
requireAuth?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface RuntimeRpcServiceMetadata {
|
|
43
|
+
name?: string;
|
|
44
|
+
requireAuth: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface RuntimeRpcMethodMetadata {
|
|
47
|
+
propertyKey: string | symbol;
|
|
48
|
+
name?: string;
|
|
49
|
+
requireAuth?: boolean;
|
|
50
|
+
}
|
|
51
|
+
declare function RpcService(nameOrOptions?: string | RpcServiceOptions): ClassDecorator;
|
|
52
|
+
declare function RpcMethod(nameOrOptions?: string | RpcMethodOptions): MethodDecorator;
|
|
53
|
+
declare function RequireAuth(): MethodDecorator & ClassDecorator;
|
|
54
|
+
declare function getRuntimeRpcServiceMetadata(target: Function): RuntimeRpcServiceMetadata | undefined;
|
|
55
|
+
declare function getRuntimeRpcMethodsMetadata(target: Function): RuntimeRpcMethodMetadata[];
|
|
56
|
+
declare function getRpcAuthPolicy(requireAuth?: boolean): RpcAuthPolicy;
|
|
57
|
+
declare const WextsRpcService: typeof RpcService;
|
|
58
|
+
declare const WextsRpc: typeof RpcMethod;
|
|
59
|
+
|
|
60
|
+
export { FusionController as F, RequireAuth as R, WextsRpc as W, FusionDelete as a, FusionGet as b, FusionPost as c, FusionPut as d, FusionRoute as e, type FusionRouteMetadata as f, RpcMethod as g, type RpcMethodOptions as h, RpcService as i, type RpcServiceOptions as j, type RuntimeRpcMethodMetadata as k, type RuntimeRpcServiceMetadata as l, WextsRpcService as m, getFusionMetadata as n, getRpcAuthPolicy as o, getRuntimeRpcMethodsMetadata as p, getRuntimeRpcServiceMetadata as q };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { R as RpcAuthPolicy } from './types-CQ_aexOX.mjs';
|
|
2
|
+
|
|
3
|
+
interface FusionRouteMetadata {
|
|
4
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
path: string;
|
|
6
|
+
responseType?: string;
|
|
7
|
+
requestType?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Mark a NestJS controller for Fusion codegen
|
|
11
|
+
* Usage: @FusionController('users')
|
|
12
|
+
*/
|
|
13
|
+
declare function FusionController(prefix?: string): ClassDecorator;
|
|
14
|
+
/**
|
|
15
|
+
* Mark a route for API client generation
|
|
16
|
+
* Usage: @FusionRoute({ method: 'GET', path: '/:id' })
|
|
17
|
+
*/
|
|
18
|
+
declare function FusionRoute(metadata: FusionRouteMetadata): MethodDecorator;
|
|
19
|
+
/**
|
|
20
|
+
* Helper decorators for common HTTP methods
|
|
21
|
+
*/
|
|
22
|
+
declare function FusionGet(path?: string): MethodDecorator;
|
|
23
|
+
declare function FusionPost(path?: string): MethodDecorator;
|
|
24
|
+
declare function FusionPut(path?: string): MethodDecorator;
|
|
25
|
+
declare function FusionDelete(path?: string): MethodDecorator;
|
|
26
|
+
/**
|
|
27
|
+
* Get Fusion metadata from a controller
|
|
28
|
+
*/
|
|
29
|
+
declare function getFusionMetadata(controller: any): {
|
|
30
|
+
controller: any;
|
|
31
|
+
routes: any[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface RpcServiceOptions {
|
|
35
|
+
name?: string;
|
|
36
|
+
requireAuth?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface RpcMethodOptions {
|
|
39
|
+
name?: string;
|
|
40
|
+
requireAuth?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface RuntimeRpcServiceMetadata {
|
|
43
|
+
name?: string;
|
|
44
|
+
requireAuth: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface RuntimeRpcMethodMetadata {
|
|
47
|
+
propertyKey: string | symbol;
|
|
48
|
+
name?: string;
|
|
49
|
+
requireAuth?: boolean;
|
|
50
|
+
}
|
|
51
|
+
declare function RpcService(nameOrOptions?: string | RpcServiceOptions): ClassDecorator;
|
|
52
|
+
declare function RpcMethod(nameOrOptions?: string | RpcMethodOptions): MethodDecorator;
|
|
53
|
+
declare function RequireAuth(): MethodDecorator & ClassDecorator;
|
|
54
|
+
declare function getRuntimeRpcServiceMetadata(target: Function): RuntimeRpcServiceMetadata | undefined;
|
|
55
|
+
declare function getRuntimeRpcMethodsMetadata(target: Function): RuntimeRpcMethodMetadata[];
|
|
56
|
+
declare function getRpcAuthPolicy(requireAuth?: boolean): RpcAuthPolicy;
|
|
57
|
+
declare const WextsRpcService: typeof RpcService;
|
|
58
|
+
declare const WextsRpc: typeof RpcMethod;
|
|
59
|
+
|
|
60
|
+
export { FusionController as F, RequireAuth as R, WextsRpc as W, FusionDelete as a, FusionGet as b, FusionPost as c, FusionPut as d, FusionRoute as e, type FusionRouteMetadata as f, RpcMethod as g, type RpcMethodOptions as h, RpcService as i, type RpcServiceOptions as j, type RuntimeRpcMethodMetadata as k, type RuntimeRpcServiceMetadata as l, WextsRpcService as m, getFusionMetadata as n, getRpcAuthPolicy as o, getRuntimeRpcMethodsMetadata as p, getRuntimeRpcServiceMetadata as q };
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
FusionDevServer,
|
|
3
3
|
ProcessRunner,
|
|
4
4
|
ProxyServer
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-FUPLZMSR.mjs";
|
|
6
|
+
import "../chunk-C2AG7Q3C.mjs";
|
|
7
|
+
import "../chunk-L77ANWWT.mjs";
|
|
8
8
|
export {
|
|
9
9
|
FusionDevServer,
|
|
10
10
|
ProcessRunner,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface WextsErrorOptions {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
cause?: unknown;
|
|
5
|
+
suggestedFix?: string;
|
|
6
|
+
docsSlug?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class WextsError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly suggestedFix?: string;
|
|
11
|
+
readonly docsSlug?: string;
|
|
12
|
+
constructor(options: WextsErrorOptions);
|
|
13
|
+
get docsUrl(): string | undefined;
|
|
14
|
+
}
|
|
15
|
+
declare class WextsRpcError extends WextsError {
|
|
16
|
+
constructor(options: Omit<WextsErrorOptions, 'code'> & {
|
|
17
|
+
code?: string;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
declare class WextsCodegenError extends WextsError {
|
|
21
|
+
constructor(options: Omit<WextsErrorOptions, 'code'> & {
|
|
22
|
+
code?: string;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
declare class WextsRuntimeError extends WextsError {
|
|
26
|
+
constructor(options: Omit<WextsErrorOptions, 'code'> & {
|
|
27
|
+
code?: string;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
declare class WextsSecurityError extends WextsError {
|
|
31
|
+
constructor(options: Omit<WextsErrorOptions, 'code'> & {
|
|
32
|
+
code?: string;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
declare function formatWextsError(error: unknown): string;
|
|
36
|
+
|
|
37
|
+
export { WextsError as W, WextsRpcError as a, WextsRuntimeError as b, WextsSecurityError as c, WextsCodegenError as d, type WextsErrorOptions as e, formatWextsError as f };
|