wexts 4.1.5 → 4.1.7
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/README.md +49 -49
- package/bin/wexts.cjs +2 -2
- package/dist/chunk-27NEYQD2.mjs +222 -0
- package/dist/chunk-27NEYQD2.mjs.map +1 -0
- package/dist/chunk-2LJVUMXW.js +228 -0
- package/dist/chunk-2LJVUMXW.js.map +1 -0
- package/dist/chunk-5DBFN65W.mjs +183 -0
- package/dist/chunk-5DBFN65W.mjs.map +1 -0
- package/dist/chunk-75HBI2XG.js +504 -0
- package/dist/chunk-75HBI2XG.js.map +1 -0
- package/dist/chunk-AVMQJWYD.js +95 -0
- package/dist/chunk-AVMQJWYD.js.map +1 -0
- package/dist/chunk-C2AG7Q3C.mjs +65 -0
- package/dist/chunk-C2AG7Q3C.mjs.map +1 -0
- package/dist/chunk-DS5KVVWJ.mjs +95 -0
- package/dist/chunk-DS5KVVWJ.mjs.map +1 -0
- package/dist/chunk-FUPLZMSR.mjs +228 -0
- package/dist/chunk-FUPLZMSR.mjs.map +1 -0
- package/dist/chunk-HLT3IHJY.js +183 -0
- package/dist/chunk-HLT3IHJY.js.map +1 -0
- package/dist/chunk-IRRJJ7KL.js +273 -0
- package/dist/chunk-IRRJJ7KL.js.map +1 -0
- package/dist/chunk-L77ANWWT.mjs +22 -0
- package/dist/chunk-L77ANWWT.mjs.map +1 -0
- package/dist/chunk-P3Q4I5FD.js +222 -0
- package/dist/chunk-P3Q4I5FD.js.map +1 -0
- package/dist/chunk-VBIQGUDI.mjs +504 -0
- package/dist/chunk-VBIQGUDI.mjs.map +1 -0
- package/dist/chunk-VJY6PHYF.mjs +273 -0
- package/dist/chunk-VJY6PHYF.mjs.map +1 -0
- package/dist/chunk-WCKSKU3C.js +65 -0
- package/dist/chunk-WCKSKU3C.js.map +1 -0
- package/dist/chunk-XE4OXN2W.js +12 -0
- package/dist/chunk-XE4OXN2W.js.map +1 -0
- package/dist/cli/index.d.mts +23 -0
- package/dist/cli/index.d.ts +23 -0
- package/dist/cli/index.js +634 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +636 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/client/index.d.mts +43 -0
- package/dist/client/index.d.ts +43 -0
- package/dist/client/index.js +187 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +166 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/codegen/index.d.mts +2 -0
- package/dist/codegen/index.d.ts +2 -0
- package/dist/codegen/index.js +16 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/index.mjs +16 -0
- package/dist/codegen/index.mjs.map +1 -0
- package/dist/decorators-BiQtOHuF.d.ts +60 -0
- package/dist/decorators-vBopODtr.d.mts +60 -0
- package/dist/dev-server/index.d.mts +1 -0
- package/dist/dev-server/index.d.ts +1 -0
- package/dist/dev-server/index.js +13 -0
- package/dist/dev-server/index.js.map +1 -0
- package/dist/dev-server/index.mjs +13 -0
- package/dist/dev-server/index.mjs.map +1 -0
- package/dist/errors-D545UvXf.d.mts +37 -0
- package/dist/errors-D545UvXf.d.ts +37 -0
- package/dist/index-7RvU-jGE.d.mts +66 -0
- package/dist/index-7RvU-jGE.d.ts +66 -0
- package/dist/index-BsafLP-a.d.mts +70 -0
- package/dist/index-BsafLP-a.d.ts +70 -0
- package/dist/index-CJKs4wtN.d.ts +92 -0
- package/dist/index-CUR6CnLk.d.ts +27 -0
- package/dist/index-h66Vq9dK.d.mts +92 -0
- package/dist/index-tqmYsTUn.d.mts +27 -0
- package/dist/index.d.mts +289 -0
- package/dist/index.d.ts +289 -0
- package/dist/index.js +544 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +544 -0
- package/dist/index.mjs.map +1 -0
- package/dist/nest/index.d.mts +2 -0
- package/dist/nest/index.d.ts +2 -0
- package/dist/nest/index.js +36 -0
- package/dist/nest/index.js.map +1 -0
- package/dist/nest/index.mjs +36 -0
- package/dist/nest/index.mjs.map +1 -0
- package/dist/next/index.d.mts +66 -0
- package/dist/next/index.d.ts +66 -0
- package/dist/next/index.js +282 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/index.mjs +251 -0
- package/dist/next/index.mjs.map +1 -0
- package/dist/rpc/index.d.mts +32 -0
- package/dist/rpc/index.d.ts +32 -0
- package/dist/rpc/index.js +19 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/rpc/index.mjs +1 -0
- package/dist/rpc/index.mjs.map +1 -0
- package/dist/runtime/index.d.mts +55 -0
- package/dist/runtime/index.d.ts +55 -0
- package/dist/runtime/index.js +15 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/index.mjs +15 -0
- package/dist/runtime/index.mjs.map +1 -0
- 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/server/index.mjs.map +1 -0
- package/dist/types/index.d.mts +12 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types-CQ_aexOX.d.mts +32 -0
- package/dist/types-CQ_aexOX.d.ts +32 -0
- package/dist/vercel-builder/index.d.mts +58 -0
- package/dist/vercel-builder/index.d.ts +58 -0
- package/dist/vercel-builder/index.js +330 -0
- package/dist/vercel-builder/index.js.map +1 -0
- package/dist/vercel-builder/index.mjs +330 -0
- package/dist/vercel-builder/index.mjs.map +1 -0
- package/package.json +153 -153
- package/templates/.dockerignore +43 -43
- package/templates/.env.example +17 -17
- package/templates/Dockerfile +60 -60
- package/templates/Procfile +1 -1
- package/templates/README.md +67 -67
- package/templates/api-sdk.ts +115 -115
- package/templates/docker-compose.yml +34 -34
- package/templates/nestjs-api/.env.example +3 -3
- package/templates/nestjs-api/README.md +87 -87
- package/templates/nestjs-api/nest-cli.json +6 -6
- package/templates/nestjs-api/package.json +40 -40
- package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +24 -24
- package/templates/nestjs-api/prisma/migrations/migration_lock.toml +3 -3
- package/templates/nestjs-api/prisma/schema.prisma +29 -29
- package/templates/nestjs-api/src/app.module.ts +19 -17
- package/templates/nestjs-api/src/auth/auth.controller.ts +27 -27
- package/templates/nestjs-api/src/auth/auth.module.ts +37 -37
- package/templates/nestjs-api/src/auth/auth.service.ts +86 -86
- package/templates/nestjs-api/src/auth/dto/auth.dto.ts +22 -22
- package/templates/nestjs-api/src/auth/guards/jwt-auth.guard.ts +5 -5
- package/templates/nestjs-api/src/auth/strategies/jwt.strategy.ts +27 -27
- package/templates/nestjs-api/src/hello.service.ts +11 -0
- package/templates/nestjs-api/src/main.ts +32 -32
- package/templates/nestjs-api/src/prisma/prisma.module.ts +9 -9
- package/templates/nestjs-api/src/prisma/prisma.service.ts +14 -14
- package/templates/nestjs-api/src/todos/dto/todo.dto.ts +24 -24
- package/templates/nestjs-api/src/todos/todos.controller.ts +39 -39
- package/templates/nestjs-api/src/todos/todos.module.ts +11 -11
- package/templates/nestjs-api/src/todos/todos.service.ts +53 -53
- package/templates/nestjs-api/src/users/users.controller.ts +14 -14
- package/templates/nestjs-api/src/users/users.module.ts +12 -12
- package/templates/nestjs-api/src/users/users.service.ts +19 -19
- package/templates/nestjs-api/tsconfig.json +39 -39
- package/templates/nextjs-web/README.md +76 -76
- package/templates/nextjs-web/app/actions/auth.ts +108 -108
- package/templates/nextjs-web/app/dashboard/error.tsx +39 -39
- package/templates/nextjs-web/app/dashboard/loading.tsx +14 -14
- package/templates/nextjs-web/app/dashboard/page.tsx +5 -5
- package/templates/nextjs-web/app/globals.css +93 -93
- package/templates/nextjs-web/app/layout.tsx +29 -29
- package/templates/nextjs-web/app/login/page.tsx +5 -5
- package/templates/nextjs-web/app/page.tsx +138 -28
- package/templates/nextjs-web/app/register/page.tsx +5 -5
- package/templates/nextjs-web/components/ui/button.tsx +56 -56
- package/templates/nextjs-web/components/ui/card.tsx +79 -79
- package/templates/nextjs-web/components/ui/input.tsx +25 -25
- package/templates/nextjs-web/components/ui/label.tsx +24 -24
- package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -140
- package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -159
- package/templates/nextjs-web/features/auth/api.ts +35 -35
- package/templates/nextjs-web/features/auth/index.ts +3 -3
- package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -204
- package/templates/nextjs-web/features/dashboard/api.ts +9 -9
- package/templates/nextjs-web/features/dashboard/components.tsx +74 -74
- package/templates/nextjs-web/features/dashboard/index.ts +3 -3
- package/templates/nextjs-web/hooks/index.ts +4 -4
- package/templates/nextjs-web/lib/api-client.ts +89 -89
- package/templates/nextjs-web/lib/api.ts +115 -115
- package/templates/nextjs-web/lib/axios-global-config.ts +17 -17
- package/templates/nextjs-web/lib/utils.ts +6 -6
- package/templates/nextjs-web/lib/wexts-client.ts +4 -4
- package/templates/nextjs-web/next-env.d.ts +6 -6
- package/templates/nextjs-web/next.config.ts +20 -20
- package/templates/nextjs-web/package.json +37 -37
- package/templates/nextjs-web/postcss.config.js +6 -6
- package/templates/nextjs-web/tailwind.config.ts +69 -69
- package/templates/nextjs-web/tsconfig.json +41 -41
- package/templates/nixpacks.toml +11 -11
- package/templates/root-package.json +31 -31
- package/templates/server.ts +66 -66
- package/templates/tsconfig.json +30 -30
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
|
|
5
|
+
// src/next/provider.tsx
|
|
6
|
+
import React, { createContext, useContext } from "react";
|
|
7
|
+
|
|
8
|
+
// src/errors.ts
|
|
9
|
+
var WextsError = class extends Error {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "WextsError");
|
|
12
|
+
}
|
|
13
|
+
code;
|
|
14
|
+
suggestedFix;
|
|
15
|
+
docsSlug;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(options.message, options.cause === void 0 ? void 0 : {
|
|
18
|
+
cause: options.cause
|
|
19
|
+
});
|
|
20
|
+
this.name = "WextsError";
|
|
21
|
+
this.code = options.code;
|
|
22
|
+
this.suggestedFix = options.suggestedFix;
|
|
23
|
+
this.docsSlug = options.docsSlug;
|
|
24
|
+
}
|
|
25
|
+
get docsUrl() {
|
|
26
|
+
return this.docsSlug ? `https://github.com/ziadmustafa1/wexts/blob/main/docs/${this.docsSlug}.md` : void 0;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var WextsRpcError = class extends WextsError {
|
|
30
|
+
static {
|
|
31
|
+
__name(this, "WextsRpcError");
|
|
32
|
+
}
|
|
33
|
+
constructor(options) {
|
|
34
|
+
super({
|
|
35
|
+
code: options.code ?? "WEXTS_RPC_ERROR",
|
|
36
|
+
...options
|
|
37
|
+
});
|
|
38
|
+
this.name = "WextsRpcError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/client/fetcher.ts
|
|
43
|
+
var FusionFetcher = class {
|
|
44
|
+
static {
|
|
45
|
+
__name(this, "FusionFetcher");
|
|
46
|
+
}
|
|
47
|
+
baseUrl;
|
|
48
|
+
constructor(baseUrl = "/api") {
|
|
49
|
+
this.baseUrl = baseUrl;
|
|
50
|
+
}
|
|
51
|
+
async request(method, path, body) {
|
|
52
|
+
const headers = {
|
|
53
|
+
"Content-Type": "application/json"
|
|
54
|
+
};
|
|
55
|
+
if (typeof window !== "undefined") {
|
|
56
|
+
const token = localStorage.getItem("fusion_token");
|
|
57
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
58
|
+
}
|
|
59
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
60
|
+
method,
|
|
61
|
+
headers,
|
|
62
|
+
body: body ? JSON.stringify(body) : void 0
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new WextsRpcError({
|
|
66
|
+
code: "WEXTS_API_REQUEST_FAILED",
|
|
67
|
+
message: `Fusion API Error: ${response.status} ${response.statusText}`,
|
|
68
|
+
suggestedFix: "Check the API route, server logs, and authentication headers.",
|
|
69
|
+
docsSlug: "troubleshooting"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (response.status === 204) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
return response.json();
|
|
76
|
+
}
|
|
77
|
+
get(path) {
|
|
78
|
+
return this.request("GET", path);
|
|
79
|
+
}
|
|
80
|
+
post(path, body) {
|
|
81
|
+
return this.request("POST", path, body);
|
|
82
|
+
}
|
|
83
|
+
put(path, body) {
|
|
84
|
+
return this.request("PUT", path, body);
|
|
85
|
+
}
|
|
86
|
+
delete(path) {
|
|
87
|
+
return this.request("DELETE", path);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var apiFetcher = new FusionFetcher();
|
|
91
|
+
function createWextsRpcClient(manifest, options = {}) {
|
|
92
|
+
const hasManifest = Boolean(manifest);
|
|
93
|
+
const services = new Set((manifest?.services ?? []).map((service) => service.name));
|
|
94
|
+
const methodMap = /* @__PURE__ */ new Map();
|
|
95
|
+
for (const service of manifest?.services ?? []) {
|
|
96
|
+
methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));
|
|
97
|
+
}
|
|
98
|
+
const createServiceProxy = /* @__PURE__ */ __name((serviceName) => new Proxy({}, {
|
|
99
|
+
get(_target, methodName) {
|
|
100
|
+
if (typeof methodName !== "string") return void 0;
|
|
101
|
+
if (methodName === "then") return void 0;
|
|
102
|
+
const knownMethods = methodMap.get(serviceName);
|
|
103
|
+
if (knownMethods && !knownMethods.has(methodName)) {
|
|
104
|
+
throw new WextsRpcError({
|
|
105
|
+
code: "WEXTS_RPC_METHOD_NOT_FOUND",
|
|
106
|
+
message: `Wexts RPC method not found: ${serviceName}.${methodName}`,
|
|
107
|
+
suggestedFix: "Run `wexts generate` and verify the method is decorated with @RpcMethod().",
|
|
108
|
+
docsSlug: "rpc"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return (...args) => invokeRpc(serviceName, methodName, args, options);
|
|
112
|
+
}
|
|
113
|
+
}), "createServiceProxy");
|
|
114
|
+
return new Proxy({}, {
|
|
115
|
+
get(_target, serviceName) {
|
|
116
|
+
if (typeof serviceName !== "string") return void 0;
|
|
117
|
+
if (serviceName === "then") return void 0;
|
|
118
|
+
if (!hasManifest) {
|
|
119
|
+
throw new WextsRpcError({
|
|
120
|
+
code: "WEXTS_RPC_MANIFEST_MISSING",
|
|
121
|
+
message: "Wexts RPC manifest is missing.",
|
|
122
|
+
suggestedFix: "Run `wexts generate` and import the generated client/provider instead of creating an empty client.",
|
|
123
|
+
docsSlug: "codegen"
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (!services.has(serviceName)) {
|
|
127
|
+
throw new WextsRpcError({
|
|
128
|
+
code: "WEXTS_RPC_SERVICE_NOT_FOUND",
|
|
129
|
+
message: `Wexts RPC service not found: ${serviceName}`,
|
|
130
|
+
suggestedFix: "Run `wexts generate` and verify the service is decorated with @RpcService().",
|
|
131
|
+
docsSlug: "rpc"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return createServiceProxy(serviceName);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
__name(createWextsRpcClient, "createWextsRpcClient");
|
|
139
|
+
async function invokeRpc(serviceName, methodName, args, options) {
|
|
140
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
141
|
+
const baseUrl = options.baseUrl ?? "/rpc";
|
|
142
|
+
const headers = {
|
|
143
|
+
"Content-Type": "application/json",
|
|
144
|
+
...await options.getHeaders?.() ?? {}
|
|
145
|
+
};
|
|
146
|
+
const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {
|
|
147
|
+
method: "POST",
|
|
148
|
+
headers,
|
|
149
|
+
body: JSON.stringify({
|
|
150
|
+
args
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new WextsRpcError({
|
|
155
|
+
code: "WEXTS_RPC_REQUEST_FAILED",
|
|
156
|
+
message: `Wexts RPC Error: ${response.status} ${response.statusText}`,
|
|
157
|
+
suggestedFix: "Check the RPC route, service policy, and server logs.",
|
|
158
|
+
docsSlug: "troubleshooting"
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const payload = await response.json();
|
|
162
|
+
return payload.data;
|
|
163
|
+
}
|
|
164
|
+
__name(invokeRpc, "invokeRpc");
|
|
165
|
+
|
|
166
|
+
// src/next/provider.tsx
|
|
167
|
+
var FusionContext = /* @__PURE__ */ createContext(null);
|
|
168
|
+
function FusionProvider({ children, baseUrl = "/api", rpcBaseUrl = "/rpc", rpcClient }) {
|
|
169
|
+
const client = React.useMemo(() => new FusionFetcher(baseUrl), [
|
|
170
|
+
baseUrl
|
|
171
|
+
]);
|
|
172
|
+
const wexts = React.useMemo(() => rpcClient ?? createWextsRpcClient(void 0, {
|
|
173
|
+
baseUrl: rpcBaseUrl
|
|
174
|
+
}), [
|
|
175
|
+
rpcBaseUrl,
|
|
176
|
+
rpcClient
|
|
177
|
+
]);
|
|
178
|
+
return /* @__PURE__ */ React.createElement(FusionContext.Provider, {
|
|
179
|
+
value: {
|
|
180
|
+
client,
|
|
181
|
+
wexts
|
|
182
|
+
}
|
|
183
|
+
}, children);
|
|
184
|
+
}
|
|
185
|
+
__name(FusionProvider, "FusionProvider");
|
|
186
|
+
function useFusion() {
|
|
187
|
+
const context = useContext(FusionContext);
|
|
188
|
+
if (!context) {
|
|
189
|
+
throw new Error("useFusion must be used within FusionProvider");
|
|
190
|
+
}
|
|
191
|
+
return context;
|
|
192
|
+
}
|
|
193
|
+
__name(useFusion, "useFusion");
|
|
194
|
+
function useWexts() {
|
|
195
|
+
const context = useFusion();
|
|
196
|
+
return context.wexts;
|
|
197
|
+
}
|
|
198
|
+
__name(useWexts, "useWexts");
|
|
199
|
+
|
|
200
|
+
// src/next/useAuth.ts
|
|
201
|
+
import { useState, useEffect } from "react";
|
|
202
|
+
function useAuth() {
|
|
203
|
+
const { client } = useFusion();
|
|
204
|
+
const [user, setUser] = useState(null);
|
|
205
|
+
const [loading, setLoading] = useState(true);
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
const token = localStorage.getItem("fusion_token");
|
|
208
|
+
if (token) {
|
|
209
|
+
loadUser();
|
|
210
|
+
} else {
|
|
211
|
+
setLoading(false);
|
|
212
|
+
}
|
|
213
|
+
}, []);
|
|
214
|
+
const loadUser = /* @__PURE__ */ __name(async () => {
|
|
215
|
+
try {
|
|
216
|
+
const userData = await client.get("/auth/me");
|
|
217
|
+
setUser(userData);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
localStorage.removeItem("fusion_token");
|
|
220
|
+
} finally {
|
|
221
|
+
setLoading(false);
|
|
222
|
+
}
|
|
223
|
+
}, "loadUser");
|
|
224
|
+
const login = /* @__PURE__ */ __name(async (email, password) => {
|
|
225
|
+
const response = await client.post("/auth/login", {
|
|
226
|
+
email,
|
|
227
|
+
password
|
|
228
|
+
});
|
|
229
|
+
localStorage.setItem("fusion_token", response.token);
|
|
230
|
+
setUser(response.user);
|
|
231
|
+
}, "login");
|
|
232
|
+
const logout = /* @__PURE__ */ __name(async () => {
|
|
233
|
+
localStorage.removeItem("fusion_token");
|
|
234
|
+
setUser(null);
|
|
235
|
+
}, "logout");
|
|
236
|
+
return {
|
|
237
|
+
user,
|
|
238
|
+
loading,
|
|
239
|
+
login,
|
|
240
|
+
logout,
|
|
241
|
+
isAuthenticated: !!user
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
__name(useAuth, "useAuth");
|
|
245
|
+
export {
|
|
246
|
+
FusionProvider,
|
|
247
|
+
useAuth,
|
|
248
|
+
useFusion,
|
|
249
|
+
useWexts
|
|
250
|
+
};
|
|
251
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/next/provider.tsx","../../src/errors.ts","../../src/client/fetcher.ts","../../src/next/useAuth.ts"],"sourcesContent":["'use client';\n\nimport React, { createContext, useContext, ReactNode } from 'react';\nimport { createWextsRpcClient, FusionFetcher, WextsRpcClient } from '../client/fetcher';\n\ninterface FusionContextType {\n client: FusionFetcher;\n wexts: WextsRpcClient;\n}\n\nconst FusionContext = createContext<FusionContextType | null>(null);\n\nexport interface FusionProviderProps {\n children: ReactNode;\n baseUrl?: string;\n rpcBaseUrl?: string;\n rpcClient?: object;\n}\n\n/**\n * FusionProvider - Provides API client to React components\n * Usage:\n * ```tsx\n * <FusionProvider baseUrl=\"/api\">\n * <App />\n * </FusionProvider>\n * ```\n */\nexport function FusionProvider({ children, baseUrl = '/api', rpcBaseUrl = '/rpc', rpcClient }: FusionProviderProps) {\n const client = React.useMemo(() => new FusionFetcher(baseUrl), [baseUrl]);\n const wexts = React.useMemo(\n () => (rpcClient as WextsRpcClient | undefined) ?? createWextsRpcClient(undefined, { baseUrl: rpcBaseUrl }),\n [rpcBaseUrl, rpcClient]\n );\n\n return (\n <FusionContext.Provider value={{ client, wexts }}>\n {children}\n </FusionContext.Provider>\n );\n}\n\n/**\n * useFusion hook - Access API client in components\n * Usage:\n * ```tsx\n * const { client } = useFusion();\n * const data = await client.get('/users');\n * ```\n */\nexport function useFusion(): FusionContextType {\n const context = useContext(FusionContext);\n if (!context) {\n throw new Error('useFusion must be used within FusionProvider');\n }\n return context;\n}\n\nexport function useWexts<TClient = WextsRpcClient>(): TClient {\n const context = useFusion();\n return context.wexts as TClient;\n}\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","'use client';\n\nimport { useState, useEffect } from 'react';\nimport { useFusion } from './provider';\n\nexport interface AuthUser {\n id: string;\n email: string;\n name?: string;\n}\n\nexport interface UseAuthReturn {\n user: AuthUser | null;\n loading: boolean;\n login: (email: string, password: string) => Promise<void>;\n logout: () => Promise<void>;\n isAuthenticated: boolean;\n}\n\n/**\n * useAuth hook - Authentication state management\n * Usage:\n * ```tsx\n * const { user, login, logout, isAuthenticated } = useAuth();\n * ```\n */\nexport function useAuth(): UseAuthReturn {\n const { client } = useFusion();\n const [user, setUser] = useState<AuthUser | null>(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n // Check for existing session\n const token = localStorage.getItem('fusion_token');\n if (token) {\n // Validate token and load user\n loadUser();\n } else {\n setLoading(false);\n }\n }, []);\n\n const loadUser = async () => {\n try {\n const userData = await client.get<AuthUser>('/auth/me');\n setUser(userData);\n } catch (error) {\n localStorage.removeItem('fusion_token');\n } finally {\n setLoading(false);\n }\n };\n\n const login = async (email: string, password: string) => {\n const response = await client.post<{ token: string; user: AuthUser }>('/auth/login', {\n email,\n password,\n });\n localStorage.setItem('fusion_token', response.token);\n setUser(response.user);\n };\n\n const logout = async () => {\n localStorage.removeItem('fusion_token');\n setUser(null);\n };\n\n return {\n user,\n loading,\n login,\n logout,\n isAuthenticated: !!user,\n };\n}\n"],"mappings":";;;;;AAEA,OAAOA,SAASC,eAAeC,kBAA6B;;;ACMrD,IAAMC,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,UAA8B;AAC9B,WAAO,KAAKN,WAAW,wDAAwD,KAAKA,QAAQ,QAAQI;EACxG;AACJ;AAEO,IAAMG,gBAAN,cAA4BX,WAAAA;EAlBnC,OAkBmCA;;;EAC/B,YAAYK,SAA8D;AACtE,UAAM;MAAEH,MAAMG,QAAQH,QAAQ;MAAmB,GAAGG;IAAQ,CAAA;AAC5D,SAAKI,OAAO;EAChB;A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AAA;AAChB,SAAOC,QAAQN;AACnB;AAHgBS;;;AGxDhB,SAASC,UAAUC,iBAAiB;AAwB7B,SAASC,UAAAA;AACZ,QAAM,EAAEC,OAAM,IAAKC,UAAAA;AACnB,QAAM,CAACC,MAAMC,OAAAA,IAAWC,SAA0B,IAAA;AAClD,QAAM,CAACC,SAASC,UAAAA,IAAcF,SAAS,IAAA;AAEvCG,YAAU,MAAA;AAEN,UAAMC,QAAQC,aAAaC,QAAQ,cAAA;AACnC,QAAIF,OAAO;AAEPG,eAAAA;IACJ,OAAO;AACHL,iBAAW,KAAA;IACf;EACJ,GAAG,CAAA,CAAE;AAEL,QAAMK,WAAW,mCAAA;AACb,QAAI;AACA,YAAMC,WAAW,MAAMZ,OAAOa,IAAc,UAAA;AAC5CV,cAAQS,QAAAA;IACZ,SAASE,OAAO;AACZL,mBAAaM,WAAW,cAAA;IAC5B,UAAA;AACIT,iBAAW,KAAA;IACf;EACJ,GATiB;AAWjB,QAAMU,QAAQ,8BAAOC,OAAeC,aAAAA;AAChC,UAAMC,WAAW,MAAMnB,OAAOoB,KAAwC,eAAe;MACjFH;MACAC;IACJ,CAAA;AACAT,iBAAaY,QAAQ,gBAAgBF,SAASX,KAAK;AACnDL,YAAQgB,SAASjB,IAAI;EACzB,GAPc;AASd,QAAMoB,SAAS,mCAAA;AACXb,iBAAaM,WAAW,cAAA;AACxBZ,YAAQ,IAAA;EACZ,GAHe;AAKf,SAAO;IACHD;IACAG;IACAW;IACAM;IACAC,iBAAiB,CAAC,CAACrB;EACvB;AACJ;AAhDgBH;","names":["React","createContext","useContext","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","FusionContext","createContext","FusionProvider","children","baseUrl","rpcBaseUrl","rpcClient","client","React","useMemo","FusionFetcher","wexts","createWextsRpcClient","undefined","Provider","value","useFusion","context","useContext","Error","useWexts","useState","useEffect","useAuth","client","useFusion","user","setUser","useState","loading","setLoading","useEffect","token","localStorage","getItem","loadUser","userData","get","error","removeItem","login","email","password","response","post","setItem","logout","isAuthenticated"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type RpcAuthPolicy = 'public' | 'required';
|
|
2
|
+
interface RpcParameterManifest {
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
optional: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface RpcMethodManifest {
|
|
8
|
+
name: string;
|
|
9
|
+
handlerName: string;
|
|
10
|
+
requireAuth: boolean;
|
|
11
|
+
parameters: RpcParameterManifest[];
|
|
12
|
+
returnType: string;
|
|
13
|
+
}
|
|
14
|
+
interface RpcServiceManifest {
|
|
15
|
+
name: string;
|
|
16
|
+
className: string;
|
|
17
|
+
importPath: string;
|
|
18
|
+
requireAuth: boolean;
|
|
19
|
+
methods: RpcMethodManifest[];
|
|
20
|
+
}
|
|
21
|
+
interface RpcManifest {
|
|
22
|
+
schemaVersion: 1;
|
|
23
|
+
services: RpcServiceManifest[];
|
|
24
|
+
}
|
|
25
|
+
interface RpcInvocationRequest {
|
|
26
|
+
args: unknown[];
|
|
27
|
+
}
|
|
28
|
+
interface RpcInvocationResponse<T = unknown> {
|
|
29
|
+
data: T;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type { RpcAuthPolicy, RpcInvocationRequest, RpcInvocationResponse, RpcManifest, RpcMethodManifest, RpcParameterManifest, RpcServiceManifest };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type RpcAuthPolicy = 'public' | 'required';
|
|
2
|
+
interface RpcParameterManifest {
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
optional: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface RpcMethodManifest {
|
|
8
|
+
name: string;
|
|
9
|
+
handlerName: string;
|
|
10
|
+
requireAuth: boolean;
|
|
11
|
+
parameters: RpcParameterManifest[];
|
|
12
|
+
returnType: string;
|
|
13
|
+
}
|
|
14
|
+
interface RpcServiceManifest {
|
|
15
|
+
name: string;
|
|
16
|
+
className: string;
|
|
17
|
+
importPath: string;
|
|
18
|
+
requireAuth: boolean;
|
|
19
|
+
methods: RpcMethodManifest[];
|
|
20
|
+
}
|
|
21
|
+
interface RpcManifest {
|
|
22
|
+
schemaVersion: 1;
|
|
23
|
+
services: RpcServiceManifest[];
|
|
24
|
+
}
|
|
25
|
+
interface RpcInvocationRequest {
|
|
26
|
+
args: unknown[];
|
|
27
|
+
}
|
|
28
|
+
interface RpcInvocationResponse<T = unknown> {
|
|
29
|
+
data: T;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type { RpcAuthPolicy, RpcInvocationRequest, RpcInvocationResponse, RpcManifest, RpcMethodManifest, RpcParameterManifest, RpcServiceManifest };
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/rpc/index.ts
|
|
17
|
+
var rpc_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(rpc_exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rpc/index.ts"],"sourcesContent":["export * from './types';\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { FastifyRequest, FastifyInstance, FastifyServerOptions } from 'fastify';
|
|
2
|
+
import { a as RpcManifest, f as RpcServiceManifest } from '../types-CQ_aexOX.mjs';
|
|
3
|
+
import { WextsShieldConfig } from '@wexts/security';
|
|
4
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
5
|
+
|
|
6
|
+
type RpcServiceInstances = Record<string, Record<string, (...args: unknown[]) => unknown | Promise<unknown>>>;
|
|
7
|
+
interface RegisterRpcRoutesOptions {
|
|
8
|
+
manifest: RpcManifest;
|
|
9
|
+
services: RpcServiceInstances;
|
|
10
|
+
authorize?: (request: FastifyRequest, service: RpcServiceManifest, methodName: string) => boolean | Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
declare function registerRpcRoutes(fastify: FastifyInstance, options: RegisterRpcRoutesOptions): Promise<void>;
|
|
13
|
+
|
|
14
|
+
interface WextsRuntimeConfig {
|
|
15
|
+
rootDir?: string;
|
|
16
|
+
port?: number;
|
|
17
|
+
host?: string;
|
|
18
|
+
dev?: boolean;
|
|
19
|
+
nextDir?: string;
|
|
20
|
+
nestAppModule?: unknown;
|
|
21
|
+
nestAppModulePath?: string;
|
|
22
|
+
rpcManifest?: RpcManifest;
|
|
23
|
+
rpcManifestPath?: string;
|
|
24
|
+
rpcServices?: RpcServiceInstances;
|
|
25
|
+
security?: WextsShieldConfig;
|
|
26
|
+
logger?: FastifyServerOptions['logger'];
|
|
27
|
+
}
|
|
28
|
+
interface WextsRuntimeServer {
|
|
29
|
+
fastify: FastifyInstance;
|
|
30
|
+
start: () => Promise<void>;
|
|
31
|
+
close: () => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
declare function createWextsRuntimeServer(config?: WextsRuntimeConfig): Promise<WextsRuntimeServer>;
|
|
34
|
+
declare function startWextsRuntime(config?: WextsRuntimeConfig): Promise<WextsRuntimeServer>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Vercel / serverless handler adapter for the Wexts runtime.
|
|
38
|
+
*
|
|
39
|
+
* Creates a standard Node.js (req, res) handler that delegates to the
|
|
40
|
+
* Fastify-backed Wexts runtime **without** calling fastify.listen().
|
|
41
|
+
*
|
|
42
|
+
* Usage:
|
|
43
|
+
* const handler = await createWextsHandler({ ... });
|
|
44
|
+
* export default handler; // Vercel function entry
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
type WextsHandler = (req: IncomingMessage, res: ServerResponse) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Build a serverless-compatible handler from the Wexts runtime.
|
|
50
|
+
* The returned function accepts Node http (req, res) and passes them
|
|
51
|
+
* into the Fastify instance without ever calling listen().
|
|
52
|
+
*/
|
|
53
|
+
declare function createWextsHandler(config?: WextsRuntimeConfig): Promise<WextsHandler>;
|
|
54
|
+
|
|
55
|
+
export { type RegisterRpcRoutesOptions, type RpcServiceInstances, type WextsHandler, type WextsRuntimeConfig, type WextsRuntimeServer, createWextsHandler, createWextsRuntimeServer, registerRpcRoutes, startWextsRuntime };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { FastifyRequest, FastifyInstance, FastifyServerOptions } from 'fastify';
|
|
2
|
+
import { a as RpcManifest, f as RpcServiceManifest } from '../types-CQ_aexOX.js';
|
|
3
|
+
import { WextsShieldConfig } from '@wexts/security';
|
|
4
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
5
|
+
|
|
6
|
+
type RpcServiceInstances = Record<string, Record<string, (...args: unknown[]) => unknown | Promise<unknown>>>;
|
|
7
|
+
interface RegisterRpcRoutesOptions {
|
|
8
|
+
manifest: RpcManifest;
|
|
9
|
+
services: RpcServiceInstances;
|
|
10
|
+
authorize?: (request: FastifyRequest, service: RpcServiceManifest, methodName: string) => boolean | Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
declare function registerRpcRoutes(fastify: FastifyInstance, options: RegisterRpcRoutesOptions): Promise<void>;
|
|
13
|
+
|
|
14
|
+
interface WextsRuntimeConfig {
|
|
15
|
+
rootDir?: string;
|
|
16
|
+
port?: number;
|
|
17
|
+
host?: string;
|
|
18
|
+
dev?: boolean;
|
|
19
|
+
nextDir?: string;
|
|
20
|
+
nestAppModule?: unknown;
|
|
21
|
+
nestAppModulePath?: string;
|
|
22
|
+
rpcManifest?: RpcManifest;
|
|
23
|
+
rpcManifestPath?: string;
|
|
24
|
+
rpcServices?: RpcServiceInstances;
|
|
25
|
+
security?: WextsShieldConfig;
|
|
26
|
+
logger?: FastifyServerOptions['logger'];
|
|
27
|
+
}
|
|
28
|
+
interface WextsRuntimeServer {
|
|
29
|
+
fastify: FastifyInstance;
|
|
30
|
+
start: () => Promise<void>;
|
|
31
|
+
close: () => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
declare function createWextsRuntimeServer(config?: WextsRuntimeConfig): Promise<WextsRuntimeServer>;
|
|
34
|
+
declare function startWextsRuntime(config?: WextsRuntimeConfig): Promise<WextsRuntimeServer>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Vercel / serverless handler adapter for the Wexts runtime.
|
|
38
|
+
*
|
|
39
|
+
* Creates a standard Node.js (req, res) handler that delegates to the
|
|
40
|
+
* Fastify-backed Wexts runtime **without** calling fastify.listen().
|
|
41
|
+
*
|
|
42
|
+
* Usage:
|
|
43
|
+
* const handler = await createWextsHandler({ ... });
|
|
44
|
+
* export default handler; // Vercel function entry
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
type WextsHandler = (req: IncomingMessage, res: ServerResponse) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Build a serverless-compatible handler from the Wexts runtime.
|
|
50
|
+
* The returned function accepts Node http (req, res) and passes them
|
|
51
|
+
* into the Fastify instance without ever calling listen().
|
|
52
|
+
*/
|
|
53
|
+
declare function createWextsHandler(config?: WextsRuntimeConfig): Promise<WextsHandler>;
|
|
54
|
+
|
|
55
|
+
export { type RegisterRpcRoutesOptions, type RpcServiceInstances, type WextsHandler, type WextsRuntimeConfig, type WextsRuntimeServer, createWextsHandler, createWextsRuntimeServer, registerRpcRoutes, startWextsRuntime };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkP3Q4I5FDjs = require('../chunk-P3Q4I5FD.js');
|
|
7
|
+
require('../chunk-AVMQJWYD.js');
|
|
8
|
+
require('../chunk-XE4OXN2W.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.createWextsHandler = _chunkP3Q4I5FDjs.createWextsHandler; exports.createWextsRuntimeServer = _chunkP3Q4I5FDjs.createWextsRuntimeServer; exports.registerRpcRoutes = _chunkP3Q4I5FDjs.registerRpcRoutes; exports.startWextsRuntime = _chunkP3Q4I5FDjs.startWextsRuntime;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Volumes/Projects/wexts/packages/dist/runtime/index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,+QAAC","file":"/Volumes/Projects/wexts/packages/dist/runtime/index.js"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWextsHandler,
|
|
3
|
+
createWextsRuntimeServer,
|
|
4
|
+
registerRpcRoutes,
|
|
5
|
+
startWextsRuntime
|
|
6
|
+
} from "../chunk-27NEYQD2.mjs";
|
|
7
|
+
import "../chunk-DS5KVVWJ.mjs";
|
|
8
|
+
import "../chunk-L77ANWWT.mjs";
|
|
9
|
+
export {
|
|
10
|
+
createWextsHandler,
|
|
11
|
+
createWextsRuntimeServer,
|
|
12
|
+
registerRpcRoutes,
|
|
13
|
+
startWextsRuntime
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { RegisterRpcRoutesOptions, RpcServiceInstances, WextsHandler, WextsRuntimeConfig, WextsRuntimeServer, createWextsHandler, createWextsRuntimeServer, registerRpcRoutes, startWextsRuntime } from '../runtime/index.mjs';
|
|
2
|
+
export { F as FusionController, a as FusionDelete, b as FusionGet, c as FusionPost, d as FusionPut, e as FusionRoute, f as FusionRouteMetadata, R as RequireAuth, g as RpcMethod, h as RpcMethodOptions, i as RpcService, j as RpcServiceOptions, k as RuntimeRpcMethodMetadata, l as RuntimeRpcServiceMetadata, W as WextsRpc, m as WextsRpcService, n as getFusionMetadata, o as getRpcAuthPolicy, p as getRuntimeRpcMethodsMetadata, q as getRuntimeRpcServiceMetadata } from '../decorators-vBopODtr.mjs';
|
|
3
|
+
export { W as WextsError, a as WextsRpcError, b as WextsRuntimeError, c as WextsSecurityError, f as formatWextsError } from '../errors-D545UvXf.mjs';
|
|
4
|
+
import 'fastify';
|
|
5
|
+
import '../types-CQ_aexOX.mjs';
|
|
6
|
+
import '@wexts/security';
|
|
7
|
+
import 'http';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { RegisterRpcRoutesOptions, RpcServiceInstances, WextsHandler, WextsRuntimeConfig, WextsRuntimeServer, createWextsHandler, createWextsRuntimeServer, registerRpcRoutes, startWextsRuntime } from '../runtime/index.js';
|
|
2
|
+
export { F as FusionController, a as FusionDelete, b as FusionGet, c as FusionPost, d as FusionPut, e as FusionRoute, f as FusionRouteMetadata, R as RequireAuth, g as RpcMethod, h as RpcMethodOptions, i as RpcService, j as RpcServiceOptions, k as RuntimeRpcMethodMetadata, l as RuntimeRpcServiceMetadata, W as WextsRpc, m as WextsRpcService, n as getFusionMetadata, o as getRpcAuthPolicy, p as getRuntimeRpcMethodsMetadata, q as getRuntimeRpcServiceMetadata } from '../decorators-BiQtOHuF.js';
|
|
3
|
+
export { W as WextsError, a as WextsRpcError, b as WextsRuntimeError, c as WextsSecurityError, f as formatWextsError } from '../errors-D545UvXf.js';
|
|
4
|
+
import 'fastify';
|
|
5
|
+
import '../types-CQ_aexOX.js';
|
|
6
|
+
import '@wexts/security';
|
|
7
|
+
import 'http';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkHLT3IHJYjs = require('../chunk-HLT3IHJY.js');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _chunkP3Q4I5FDjs = require('../chunk-P3Q4I5FD.js');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var _chunkAVMQJWYDjs = require('../chunk-AVMQJWYD.js');
|
|
31
|
+
require('../chunk-XE4OXN2W.js');
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
exports.FusionController = _chunkHLT3IHJYjs.FusionController; exports.FusionDelete = _chunkHLT3IHJYjs.FusionDelete; exports.FusionGet = _chunkHLT3IHJYjs.FusionGet; exports.FusionPost = _chunkHLT3IHJYjs.FusionPost; exports.FusionPut = _chunkHLT3IHJYjs.FusionPut; exports.FusionRoute = _chunkHLT3IHJYjs.FusionRoute; exports.RequireAuth = _chunkHLT3IHJYjs.RequireAuth; exports.RpcMethod = _chunkHLT3IHJYjs.RpcMethod; exports.RpcService = _chunkHLT3IHJYjs.RpcService; exports.WextsError = _chunkAVMQJWYDjs.WextsError; exports.WextsRpc = _chunkHLT3IHJYjs.WextsRpc; exports.WextsRpcError = _chunkAVMQJWYDjs.WextsRpcError; exports.WextsRpcService = _chunkHLT3IHJYjs.WextsRpcService; exports.WextsRuntimeError = _chunkAVMQJWYDjs.WextsRuntimeError; exports.WextsSecurityError = _chunkAVMQJWYDjs.WextsSecurityError; exports.createWextsHandler = _chunkP3Q4I5FDjs.createWextsHandler; exports.createWextsRuntimeServer = _chunkP3Q4I5FDjs.createWextsRuntimeServer; exports.formatWextsError = _chunkAVMQJWYDjs.formatWextsError; exports.getFusionMetadata = _chunkHLT3IHJYjs.getFusionMetadata; exports.getRpcAuthPolicy = _chunkHLT3IHJYjs.getRpcAuthPolicy; exports.getRuntimeRpcMethodsMetadata = _chunkHLT3IHJYjs.getRuntimeRpcMethodsMetadata; exports.getRuntimeRpcServiceMetadata = _chunkHLT3IHJYjs.getRuntimeRpcServiceMetadata; exports.registerRpcRoutes = _chunkP3Q4I5FDjs.registerRpcRoutes; exports.startWextsRuntime = _chunkP3Q4I5FDjs.startWextsRuntime;
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Volumes/Projects/wexts/packages/dist/server/index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,uDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,65CAAC","file":"/Volumes/Projects/wexts/packages/dist/server/index.js"}
|