wexts 4.0.0 → 4.1.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.
- package/dist/chunk-342VRT25.mjs +504 -0
- package/dist/chunk-342VRT25.mjs.map +1 -0
- package/dist/chunk-7HNQWJWV.js +504 -0
- package/dist/chunk-7HNQWJWV.js.map +1 -0
- package/dist/chunk-7SSCNCTW.mjs +137 -0
- package/dist/chunk-7SSCNCTW.mjs.map +1 -0
- package/dist/chunk-7TLSPR65.mjs +95 -0
- package/dist/chunk-7TLSPR65.mjs.map +1 -0
- package/dist/chunk-AVMQJWYD.js +95 -0
- package/dist/chunk-AVMQJWYD.js.map +1 -0
- package/dist/chunk-O4II6N34.js +137 -0
- package/dist/chunk-O4II6N34.js.map +1 -0
- package/dist/cli/index.d.mts +13 -1
- package/dist/cli/index.d.ts +13 -1
- package/dist/cli/index.js +438 -54
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +438 -54
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.js +3 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +2 -1
- package/dist/codegen/index.js +3 -2
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/index.mjs +2 -1
- package/dist/index.d.mts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +22 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -4
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.js +68 -5
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +68 -5
- package/dist/next/index.mjs.map +1 -1
- package/dist/runtime/index.js +9 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/index.mjs +9 -1
- package/dist/runtime/index.mjs.map +1 -1
- package/package.json +1 -1
- package/templates/nestjs-api/package-lock.json +0 -5623
- package/templates/nextjs-web/package-lock.json +0 -3254
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WextsRpcError
|
|
3
|
+
} from "./chunk-7TLSPR65.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-7WULUGLH.mjs";
|
|
7
|
+
|
|
8
|
+
// src/client/fetcher.ts
|
|
9
|
+
var FusionFetcher = class {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "FusionFetcher");
|
|
12
|
+
}
|
|
13
|
+
baseUrl;
|
|
14
|
+
constructor(baseUrl = "/api") {
|
|
15
|
+
this.baseUrl = baseUrl;
|
|
16
|
+
}
|
|
17
|
+
async request(method, path, body) {
|
|
18
|
+
const headers = {
|
|
19
|
+
"Content-Type": "application/json"
|
|
20
|
+
};
|
|
21
|
+
if (typeof window !== "undefined") {
|
|
22
|
+
const token = localStorage.getItem("fusion_token");
|
|
23
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
24
|
+
}
|
|
25
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
26
|
+
method,
|
|
27
|
+
headers,
|
|
28
|
+
body: body ? JSON.stringify(body) : void 0
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new WextsRpcError({
|
|
32
|
+
code: "WEXTS_API_REQUEST_FAILED",
|
|
33
|
+
message: `Fusion API Error: ${response.status} ${response.statusText}`,
|
|
34
|
+
suggestedFix: "Check the API route, server logs, and authentication headers.",
|
|
35
|
+
docsSlug: "troubleshooting"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (response.status === 204) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
return response.json();
|
|
42
|
+
}
|
|
43
|
+
get(path) {
|
|
44
|
+
return this.request("GET", path);
|
|
45
|
+
}
|
|
46
|
+
post(path, body) {
|
|
47
|
+
return this.request("POST", path, body);
|
|
48
|
+
}
|
|
49
|
+
put(path, body) {
|
|
50
|
+
return this.request("PUT", path, body);
|
|
51
|
+
}
|
|
52
|
+
delete(path) {
|
|
53
|
+
return this.request("DELETE", path);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var apiFetcher = new FusionFetcher();
|
|
57
|
+
function createWextsRpcClient(manifest, options = {}) {
|
|
58
|
+
const hasManifest = Boolean(manifest);
|
|
59
|
+
const services = new Set((manifest?.services ?? []).map((service) => service.name));
|
|
60
|
+
const methodMap = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const service of manifest?.services ?? []) {
|
|
62
|
+
methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));
|
|
63
|
+
}
|
|
64
|
+
const createServiceProxy = /* @__PURE__ */ __name((serviceName) => new Proxy({}, {
|
|
65
|
+
get(_target, methodName) {
|
|
66
|
+
if (typeof methodName !== "string") return void 0;
|
|
67
|
+
if (methodName === "then") return void 0;
|
|
68
|
+
const knownMethods = methodMap.get(serviceName);
|
|
69
|
+
if (knownMethods && !knownMethods.has(methodName)) {
|
|
70
|
+
throw new WextsRpcError({
|
|
71
|
+
code: "WEXTS_RPC_METHOD_NOT_FOUND",
|
|
72
|
+
message: `Wexts RPC method not found: ${serviceName}.${methodName}`,
|
|
73
|
+
suggestedFix: "Run `wexts generate` and verify the method is decorated with @RpcMethod().",
|
|
74
|
+
docsSlug: "rpc"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return (...args) => invokeRpc(serviceName, methodName, args, options);
|
|
78
|
+
}
|
|
79
|
+
}), "createServiceProxy");
|
|
80
|
+
return new Proxy({}, {
|
|
81
|
+
get(_target, serviceName) {
|
|
82
|
+
if (typeof serviceName !== "string") return void 0;
|
|
83
|
+
if (serviceName === "then") return void 0;
|
|
84
|
+
if (!hasManifest) {
|
|
85
|
+
throw new WextsRpcError({
|
|
86
|
+
code: "WEXTS_RPC_MANIFEST_MISSING",
|
|
87
|
+
message: "Wexts RPC manifest is missing.",
|
|
88
|
+
suggestedFix: "Run `wexts generate` and import the generated client/provider instead of creating an empty client.",
|
|
89
|
+
docsSlug: "codegen"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (!services.has(serviceName)) {
|
|
93
|
+
throw new WextsRpcError({
|
|
94
|
+
code: "WEXTS_RPC_SERVICE_NOT_FOUND",
|
|
95
|
+
message: `Wexts RPC service not found: ${serviceName}`,
|
|
96
|
+
suggestedFix: "Run `wexts generate` and verify the service is decorated with @RpcService().",
|
|
97
|
+
docsSlug: "rpc"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return createServiceProxy(serviceName);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
__name(createWextsRpcClient, "createWextsRpcClient");
|
|
105
|
+
async function invokeRpc(serviceName, methodName, args, options) {
|
|
106
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
107
|
+
const baseUrl = options.baseUrl ?? "/rpc";
|
|
108
|
+
const headers = {
|
|
109
|
+
"Content-Type": "application/json",
|
|
110
|
+
...await options.getHeaders?.() ?? {}
|
|
111
|
+
};
|
|
112
|
+
const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers,
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
args
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
throw new WextsRpcError({
|
|
121
|
+
code: "WEXTS_RPC_REQUEST_FAILED",
|
|
122
|
+
message: `Wexts RPC Error: ${response.status} ${response.statusText}`,
|
|
123
|
+
suggestedFix: "Check the RPC route, service policy, and server logs.",
|
|
124
|
+
docsSlug: "troubleshooting"
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const payload = await response.json();
|
|
128
|
+
return payload.data;
|
|
129
|
+
}
|
|
130
|
+
__name(invokeRpc, "invokeRpc");
|
|
131
|
+
|
|
132
|
+
export {
|
|
133
|
+
FusionFetcher,
|
|
134
|
+
apiFetcher,
|
|
135
|
+
createWextsRpcClient
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=chunk-7SSCNCTW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/fetcher.ts"],"sourcesContent":["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":";;;;;;;;AAGO,IAAMA,gBAAN,MAAMA;EAFb,OAEaA;;;EACDC;EAER,YAAYA,UAAkB,QAAQ;AAClC,SAAKA,UAAUA;EACnB;EAEA,MAAcC,QAAWC,QAAgBC,MAAcC,MAAwB;AAC3E,UAAMC,UAAkC;MACpC,gBAAgB;IACpB;AAGA,QAAI,OAAOC,WAAW,aAAa;AAC/B,YAAMC,QAAQC,aAAaC,QAAQ,cAAA;AACnC,UAAIF,MAAOF,SAAQ,eAAA,IAAmB,UAAUE,KAAAA;IACpD;AAEJ,UAAMG,WAAW,MAAMC,MAAM,GAAG,KAAKX,OAAO,GAAGG,IAAAA,IAAQ;MAC/CD;MACAG;MACAD,MAAMA,OAAOQ,KAAKC,UAAUT,IAAAA,IAAQU;IACxC,CAAA;AAEA,QAAI,CAACJ,SAASK,IAAI;AACd,YAAM,IAAIC,cAAc;QACpBC,MAAM;QACNC,SAAS,qBAAqBR,SAASS,MAAM,IAAIT,SAASU,UAAU;QACpEC,cAAc;QACdC,UAAU;MACd,CAAA;IACJ;AAEA,QAAIZ,SAASS,WAAW,KAAK;AACzB,aAAOL;IACX;AAEA,WAAOJ,SAASa,KAAI;EACxB;EAEAC,IAAOrB,MAAc;AAAE,WAAO,KAAKF,QAAW,OAAOE,IAAAA;EAAO;EAC5DsB,KAAQtB,MAAcC,MAAW;AAAE,WAAO,KAAKH,QAAW,QAAQE,MAAMC,IAAAA;EAAO;EAC/EsB,IAAOvB,MAAcC,MAAW;AAAE,WAAO,KAAKH,QAAW,OAAOE,MAAMC,IAAAA;EAAO;EAC7EuB,OAAUxB,MAAc;AAAE,WAAO,KAAKF,QAAW,UAAUE,IAAAA;EAAO;AACtE;AA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,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":["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"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7WULUGLH.mjs";
|
|
4
|
+
|
|
5
|
+
// src/errors.ts
|
|
6
|
+
var WextsError = class extends Error {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "WextsError");
|
|
9
|
+
}
|
|
10
|
+
code;
|
|
11
|
+
suggestedFix;
|
|
12
|
+
docsSlug;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options.message, options.cause === void 0 ? void 0 : {
|
|
15
|
+
cause: options.cause
|
|
16
|
+
});
|
|
17
|
+
this.name = "WextsError";
|
|
18
|
+
this.code = options.code;
|
|
19
|
+
this.suggestedFix = options.suggestedFix;
|
|
20
|
+
this.docsSlug = options.docsSlug;
|
|
21
|
+
}
|
|
22
|
+
get docsUrl() {
|
|
23
|
+
return this.docsSlug ? `https://github.com/ziadmustafa1/wexts/blob/main/docs/${this.docsSlug}.md` : void 0;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var WextsRpcError = class extends WextsError {
|
|
27
|
+
static {
|
|
28
|
+
__name(this, "WextsRpcError");
|
|
29
|
+
}
|
|
30
|
+
constructor(options) {
|
|
31
|
+
super({
|
|
32
|
+
code: options.code ?? "WEXTS_RPC_ERROR",
|
|
33
|
+
...options
|
|
34
|
+
});
|
|
35
|
+
this.name = "WextsRpcError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var WextsCodegenError = class extends WextsError {
|
|
39
|
+
static {
|
|
40
|
+
__name(this, "WextsCodegenError");
|
|
41
|
+
}
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super({
|
|
44
|
+
code: options.code ?? "WEXTS_CODEGEN_ERROR",
|
|
45
|
+
...options
|
|
46
|
+
});
|
|
47
|
+
this.name = "WextsCodegenError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var WextsRuntimeError = class extends WextsError {
|
|
51
|
+
static {
|
|
52
|
+
__name(this, "WextsRuntimeError");
|
|
53
|
+
}
|
|
54
|
+
constructor(options) {
|
|
55
|
+
super({
|
|
56
|
+
code: options.code ?? "WEXTS_RUNTIME_ERROR",
|
|
57
|
+
...options
|
|
58
|
+
});
|
|
59
|
+
this.name = "WextsRuntimeError";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var WextsSecurityError = class extends WextsError {
|
|
63
|
+
static {
|
|
64
|
+
__name(this, "WextsSecurityError");
|
|
65
|
+
}
|
|
66
|
+
constructor(options) {
|
|
67
|
+
super({
|
|
68
|
+
code: options.code ?? "WEXTS_SECURITY_ERROR",
|
|
69
|
+
...options
|
|
70
|
+
});
|
|
71
|
+
this.name = "WextsSecurityError";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function formatWextsError(error) {
|
|
75
|
+
if (!(error instanceof WextsError)) {
|
|
76
|
+
return error instanceof Error ? error.message : String(error);
|
|
77
|
+
}
|
|
78
|
+
const lines = [
|
|
79
|
+
`${error.code}: ${error.message}`
|
|
80
|
+
];
|
|
81
|
+
if (error.suggestedFix) lines.push(`Suggested fix: ${error.suggestedFix}`);
|
|
82
|
+
if (error.docsUrl) lines.push(`Docs: ${error.docsUrl}`);
|
|
83
|
+
return lines.join("\n");
|
|
84
|
+
}
|
|
85
|
+
__name(formatWextsError, "formatWextsError");
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
WextsError,
|
|
89
|
+
WextsRpcError,
|
|
90
|
+
WextsCodegenError,
|
|
91
|
+
WextsRuntimeError,
|
|
92
|
+
WextsSecurityError,
|
|
93
|
+
formatWextsError
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=chunk-7TLSPR65.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.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"],"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,SAAKC,WAAWC,QAAQD;EAC5B;EAEA,IAAIM,UA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extsCodegenError","WextsRuntimeError","WextsSecurityError","formatWextsError","error","String","lines","push","join"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkXE4OXN2Wjs = require('./chunk-XE4OXN2W.js');
|
|
4
|
+
|
|
5
|
+
// src/errors.ts
|
|
6
|
+
var WextsError = class extends Error {
|
|
7
|
+
static {
|
|
8
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, this, "WextsError");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options.message, options.cause === void 0 ? void 0 : {
|
|
15
|
+
cause: options.cause
|
|
16
|
+
});
|
|
17
|
+
this.name = "WextsError";
|
|
18
|
+
this.code = options.code;
|
|
19
|
+
this.suggestedFix = options.suggestedFix;
|
|
20
|
+
this.docsSlug = options.docsSlug;
|
|
21
|
+
}
|
|
22
|
+
get docsUrl() {
|
|
23
|
+
return this.docsSlug ? `https://github.com/ziadmustafa1/wexts/blob/main/docs/${this.docsSlug}.md` : void 0;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var WextsRpcError = class extends WextsError {
|
|
27
|
+
static {
|
|
28
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, this, "WextsRpcError");
|
|
29
|
+
}
|
|
30
|
+
constructor(options) {
|
|
31
|
+
super({
|
|
32
|
+
code: _nullishCoalesce(options.code, () => ( "WEXTS_RPC_ERROR")),
|
|
33
|
+
...options
|
|
34
|
+
});
|
|
35
|
+
this.name = "WextsRpcError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var WextsCodegenError = class extends WextsError {
|
|
39
|
+
static {
|
|
40
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, this, "WextsCodegenError");
|
|
41
|
+
}
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super({
|
|
44
|
+
code: _nullishCoalesce(options.code, () => ( "WEXTS_CODEGEN_ERROR")),
|
|
45
|
+
...options
|
|
46
|
+
});
|
|
47
|
+
this.name = "WextsCodegenError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var WextsRuntimeError = class extends WextsError {
|
|
51
|
+
static {
|
|
52
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, this, "WextsRuntimeError");
|
|
53
|
+
}
|
|
54
|
+
constructor(options) {
|
|
55
|
+
super({
|
|
56
|
+
code: _nullishCoalesce(options.code, () => ( "WEXTS_RUNTIME_ERROR")),
|
|
57
|
+
...options
|
|
58
|
+
});
|
|
59
|
+
this.name = "WextsRuntimeError";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var WextsSecurityError = class extends WextsError {
|
|
63
|
+
static {
|
|
64
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, this, "WextsSecurityError");
|
|
65
|
+
}
|
|
66
|
+
constructor(options) {
|
|
67
|
+
super({
|
|
68
|
+
code: _nullishCoalesce(options.code, () => ( "WEXTS_SECURITY_ERROR")),
|
|
69
|
+
...options
|
|
70
|
+
});
|
|
71
|
+
this.name = "WextsSecurityError";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function formatWextsError(error) {
|
|
75
|
+
if (!(error instanceof WextsError)) {
|
|
76
|
+
return error instanceof Error ? error.message : String(error);
|
|
77
|
+
}
|
|
78
|
+
const lines = [
|
|
79
|
+
`${error.code}: ${error.message}`
|
|
80
|
+
];
|
|
81
|
+
if (error.suggestedFix) lines.push(`Suggested fix: ${error.suggestedFix}`);
|
|
82
|
+
if (error.docsUrl) lines.push(`Docs: ${error.docsUrl}`);
|
|
83
|
+
return lines.join("\n");
|
|
84
|
+
}
|
|
85
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, formatWextsError, "formatWextsError");
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
exports.WextsError = WextsError; exports.WextsRpcError = WextsRpcError; exports.WextsCodegenError = WextsCodegenError; exports.WextsRuntimeError = WextsRuntimeError; exports.WextsSecurityError = WextsSecurityError; exports.formatWextsError = formatWextsError;
|
|
95
|
+
//# sourceMappingURL=chunk-AVMQJWYD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Volumes/Projects/wexts/packages/dist/chunk-AVMQJWYD.js","../src/errors.ts"],"names":["WextsError","Error","code","suggestedFix","docsSlug","options","message","cause","undefined","name","docsUrl","WextsRpcError","WextsCodegenError","WextsRuntimeError","WextsSecurityError","formatWextsError","error","String","lines"],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACIO,IAAMA,WAAAA,EAAN,MAAA,QAAyBC,MAAAA;ADFhC,ECEA,OAAgCA;ADDhC,IAAI,qCAAM,IAAK,EAAE,YAAY,CAAC;AAC9B,EAAE;AACF,ECAaC;ADCb,ECAaC;ADCb,ECAaC;ADCb,ECCI,WAAA,CAAYC,OAAAA,EAA4B;AACpC,IAAA,KAAA,CAAMA,OAAAA,CAAQC,OAAAA,EAASD,OAAAA,CAAQE,MAAAA,IAAUC,KAAAA,EAAAA,EAAYA,KAAAA,EAAAA,EAAY;ADAzE,MCA2ED,KAAAA,EAAOF,OAAAA,CAAQE;ADC1F,ICDgG,CAAA,CAAA;AACxF,IAAA,IAAA,CAAKE,KAAAA,EAAO,YAAA;AACZ,IAAA,IAAA,CAAKP,KAAAA,EAAOG,OAAAA,CAAQH,IAAAA;AACpB,IAAA,IAAA,CAAKC,aAAAA,EAAeE,OAAAA,CAAQF,YAAAA;AAC5B,IAAA,IAAA,CAAKC,SAAAA,EAAWC,OAAAA,CAAQD,QAAAA;ADEhC,ECDI;ADEJ,ECAI,IAAIM,OAAAA,CAAAA,EAA8B;AAC9B,IAAA,OAAO,IAAA,CAAKN,SAA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fI;AACJ,CAAA;AAEO,IAAMK,mBAAAA,EAAN,MAAA,QAAiCd,WAAAA;ADexC,ECtDA,OAuCwCA;ADgBxC,IAAI,qCAAM,IAAK,EAAE,oBAAoB,CAAC;AACtC,EAAE;AACF,ECjBI,WAAA,CAAYK,OAAAA,EAA8D;AACtE,IAAA,KAAA,CAAM;ADkBd,MClBgBH,IAAAA,mBAAMG,OAAAA,CAAQH,IAAAA,UAAQ,wBAAA;ADmBtC,MCnB8D,GAAGG;ADoBjE,ICpByE,CAAA,CAAA;AACjE,IAAA,IAAA,CAAKI,KAAAA,EAAO,oBAAA;ADqBpB,ECpBI;AACJ,CAAA;AAEO,SAASM,gBAAAA,CAAiBC,KAAAA,EAAc;AAC3C,EAAA,GAAA,CAAI,CAAA,CAAEA,MAAAA,WAAiBhB,UAAAA,CAAAA,EAAa;AAChC,IAAA,OAAOgB,MAAAA,WAAiBf,MAAAA,EAAQe,KAAAA,CAAMV,QAAAA,EAAUW,MAAAA,CAAOD,KAAAA,CAAAA;ADoB/D,ECnBI;AAEA,EAAA,MAAME,MAAAA,EAAQ;ADmBlB,ICnBmB,CAAA,EAAA;ADoBd,EAAA;ACnBD,EAAA;AACA,EAAA;AACA,EAAA;AACJ;AATgBH;AD+BX;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Volumes/Projects/wexts/packages/dist/chunk-AVMQJWYD.js","sourcesContent":[null,"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"]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkAVMQJWYDjs = require('./chunk-AVMQJWYD.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkXE4OXN2Wjs = require('./chunk-XE4OXN2W.js');
|
|
7
|
+
|
|
8
|
+
// src/client/fetcher.ts
|
|
9
|
+
var FusionFetcher = class {
|
|
10
|
+
static {
|
|
11
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, this, "FusionFetcher");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
constructor(baseUrl = "/api") {
|
|
15
|
+
this.baseUrl = baseUrl;
|
|
16
|
+
}
|
|
17
|
+
async request(method, path, body) {
|
|
18
|
+
const headers = {
|
|
19
|
+
"Content-Type": "application/json"
|
|
20
|
+
};
|
|
21
|
+
if (typeof window !== "undefined") {
|
|
22
|
+
const token = localStorage.getItem("fusion_token");
|
|
23
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
24
|
+
}
|
|
25
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
26
|
+
method,
|
|
27
|
+
headers,
|
|
28
|
+
body: body ? JSON.stringify(body) : void 0
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new (0, _chunkAVMQJWYDjs.WextsRpcError)({
|
|
32
|
+
code: "WEXTS_API_REQUEST_FAILED",
|
|
33
|
+
message: `Fusion API Error: ${response.status} ${response.statusText}`,
|
|
34
|
+
suggestedFix: "Check the API route, server logs, and authentication headers.",
|
|
35
|
+
docsSlug: "troubleshooting"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (response.status === 204) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
return response.json();
|
|
42
|
+
}
|
|
43
|
+
get(path) {
|
|
44
|
+
return this.request("GET", path);
|
|
45
|
+
}
|
|
46
|
+
post(path, body) {
|
|
47
|
+
return this.request("POST", path, body);
|
|
48
|
+
}
|
|
49
|
+
put(path, body) {
|
|
50
|
+
return this.request("PUT", path, body);
|
|
51
|
+
}
|
|
52
|
+
delete(path) {
|
|
53
|
+
return this.request("DELETE", path);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var apiFetcher = new FusionFetcher();
|
|
57
|
+
function createWextsRpcClient(manifest, options = {}) {
|
|
58
|
+
const hasManifest = Boolean(manifest);
|
|
59
|
+
const services = new Set((_nullishCoalesce(_optionalChain([manifest, 'optionalAccess', _ => _.services]), () => ( []))).map((service) => service.name));
|
|
60
|
+
const methodMap = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const service of _nullishCoalesce(_optionalChain([manifest, 'optionalAccess', _2 => _2.services]), () => ( []))) {
|
|
62
|
+
methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));
|
|
63
|
+
}
|
|
64
|
+
const createServiceProxy = /* @__PURE__ */ _chunkXE4OXN2Wjs.__name.call(void 0, (serviceName) => new Proxy({}, {
|
|
65
|
+
get(_target, methodName) {
|
|
66
|
+
if (typeof methodName !== "string") return void 0;
|
|
67
|
+
if (methodName === "then") return void 0;
|
|
68
|
+
const knownMethods = methodMap.get(serviceName);
|
|
69
|
+
if (knownMethods && !knownMethods.has(methodName)) {
|
|
70
|
+
throw new (0, _chunkAVMQJWYDjs.WextsRpcError)({
|
|
71
|
+
code: "WEXTS_RPC_METHOD_NOT_FOUND",
|
|
72
|
+
message: `Wexts RPC method not found: ${serviceName}.${methodName}`,
|
|
73
|
+
suggestedFix: "Run `wexts generate` and verify the method is decorated with @RpcMethod().",
|
|
74
|
+
docsSlug: "rpc"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return (...args) => invokeRpc(serviceName, methodName, args, options);
|
|
78
|
+
}
|
|
79
|
+
}), "createServiceProxy");
|
|
80
|
+
return new Proxy({}, {
|
|
81
|
+
get(_target, serviceName) {
|
|
82
|
+
if (typeof serviceName !== "string") return void 0;
|
|
83
|
+
if (serviceName === "then") return void 0;
|
|
84
|
+
if (!hasManifest) {
|
|
85
|
+
throw new (0, _chunkAVMQJWYDjs.WextsRpcError)({
|
|
86
|
+
code: "WEXTS_RPC_MANIFEST_MISSING",
|
|
87
|
+
message: "Wexts RPC manifest is missing.",
|
|
88
|
+
suggestedFix: "Run `wexts generate` and import the generated client/provider instead of creating an empty client.",
|
|
89
|
+
docsSlug: "codegen"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (!services.has(serviceName)) {
|
|
93
|
+
throw new (0, _chunkAVMQJWYDjs.WextsRpcError)({
|
|
94
|
+
code: "WEXTS_RPC_SERVICE_NOT_FOUND",
|
|
95
|
+
message: `Wexts RPC service not found: ${serviceName}`,
|
|
96
|
+
suggestedFix: "Run `wexts generate` and verify the service is decorated with @RpcService().",
|
|
97
|
+
docsSlug: "rpc"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return createServiceProxy(serviceName);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, createWextsRpcClient, "createWextsRpcClient");
|
|
105
|
+
async function invokeRpc(serviceName, methodName, args, options) {
|
|
106
|
+
const fetchImpl = _nullishCoalesce(options.fetch, () => ( fetch));
|
|
107
|
+
const baseUrl = _nullishCoalesce(options.baseUrl, () => ( "/rpc"));
|
|
108
|
+
const headers = {
|
|
109
|
+
"Content-Type": "application/json",
|
|
110
|
+
...await _asyncNullishCoalesce(await _optionalChain([options, 'access', _3 => _3.getHeaders, 'optionalCall', _4 => _4()]), async () => ( {}))
|
|
111
|
+
};
|
|
112
|
+
const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers,
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
args
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
throw new (0, _chunkAVMQJWYDjs.WextsRpcError)({
|
|
121
|
+
code: "WEXTS_RPC_REQUEST_FAILED",
|
|
122
|
+
message: `Wexts RPC Error: ${response.status} ${response.statusText}`,
|
|
123
|
+
suggestedFix: "Check the RPC route, service policy, and server logs.",
|
|
124
|
+
docsSlug: "troubleshooting"
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const payload = await response.json();
|
|
128
|
+
return payload.data;
|
|
129
|
+
}
|
|
130
|
+
_chunkXE4OXN2Wjs.__name.call(void 0, invokeRpc, "invokeRpc");
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
exports.FusionFetcher = FusionFetcher; exports.apiFetcher = apiFetcher; exports.createWextsRpcClient = createWextsRpcClient;
|
|
137
|
+
//# sourceMappingURL=chunk-O4II6N34.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Volumes/Projects/wexts/packages/dist/chunk-O4II6N34.js","../src/client/fetcher.ts"],"names":["FusionFetcher","baseUrl","request","method","path","body","headers","window","token","localStorage","getItem","undefined","response","manifest","service","Map","serviceName","methodName","createWextsRpcClient","options","fetch","encodeURIComponent","args","data","invokeRpc"],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACJO,IAAMA,cAAAA,EAAN,MAAMA;ADMb,ECRA,OAEaA;ADOb,IAAI,qCAAM,IAAK,EAAE,eAAe,CAAC;AACjC,EAAE;AACF,ECRYC;ADSZ,ECPI,WAAA,CAAYA,QAAAA,EAAkB,MAAA,EAAQ;AAClC,IAAA,IAAA,CAAKA,QAAAA,EAAUA,OAAAA;ADQvB,ECPI;ADQJ,ECNI,MAAcC,OAAAA,CAAWC,MAAAA,EAAgBC,IAAAA,EAAcC,IAAAA,EAAwB;AAC3E,IAAA,MAAMC,QAAAA,EAAkC;ADOhD,MCNY,cAAA,EAAgB;ADO5B,ICNQ,CAAA;AAGA,IAAA,GAAA,CAAI,OAAO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6DZC;AAEmCC,EAAAA;AACA,EAAA;AACnB,EAAA;AACI,IAAA;AACqB,IAAA;AACzC,EAAA;AAC+CC,EAAAA;AACnC,IAAA;AACRf,IAAAA;AACqB,IAAA;AAAEgB,MAAAA;AAAK,IAAA;AAChC,EAAA;AAEkB,EAAA;AACU,IAAA;AACd,MAAA;AAC0CV,MAAAA;AAClC,MAAA;AACJ,MAAA;AACd,IAAA;AACJ,EAAA;AAEmC,EAAA;AACpBW,EAAAA;AACnB;AA7BeC;ADc6C;AACA;AACA;AACA;AACA;AACA","file":"/Volumes/Projects/wexts/packages/dist/chunk-O4II6N34.js","sourcesContent":[null,"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"]}
|
package/dist/cli/index.d.mts
CHANGED
|
@@ -7,5 +7,17 @@ interface DoctorResult {
|
|
|
7
7
|
warnings: string[];
|
|
8
8
|
}
|
|
9
9
|
declare function runDoctor(cwd: string, security?: boolean): DoctorResult;
|
|
10
|
+
declare function createProject(projectName: string, template: string, options: {
|
|
11
|
+
skipInstall: boolean;
|
|
12
|
+
wextsDependency?: string;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
type ScaffoldGeneratorType = 'rpc' | 'service' | 'module' | 'entity' | 'guard' | 'config';
|
|
15
|
+
interface ScaffoldGeneratorOptions {
|
|
16
|
+
type: ScaffoldGeneratorType;
|
|
17
|
+
name?: string;
|
|
18
|
+
targetRoot: string;
|
|
19
|
+
force?: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare function scaffoldGenerator(options: ScaffoldGeneratorOptions): Promise<string[]>;
|
|
10
22
|
|
|
11
|
-
export { type DoctorResult, createCliProgram, runDoctor };
|
|
23
|
+
export { type DoctorResult, createCliProgram, createProject, runDoctor, scaffoldGenerator };
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -7,5 +7,17 @@ interface DoctorResult {
|
|
|
7
7
|
warnings: string[];
|
|
8
8
|
}
|
|
9
9
|
declare function runDoctor(cwd: string, security?: boolean): DoctorResult;
|
|
10
|
+
declare function createProject(projectName: string, template: string, options: {
|
|
11
|
+
skipInstall: boolean;
|
|
12
|
+
wextsDependency?: string;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
type ScaffoldGeneratorType = 'rpc' | 'service' | 'module' | 'entity' | 'guard' | 'config';
|
|
15
|
+
interface ScaffoldGeneratorOptions {
|
|
16
|
+
type: ScaffoldGeneratorType;
|
|
17
|
+
name?: string;
|
|
18
|
+
targetRoot: string;
|
|
19
|
+
force?: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare function scaffoldGenerator(options: ScaffoldGeneratorOptions): Promise<string[]>;
|
|
10
22
|
|
|
11
|
-
export { type DoctorResult, createCliProgram, runDoctor };
|
|
23
|
+
export { type DoctorResult, createCliProgram, createProject, runDoctor, scaffoldGenerator };
|