fragment-ts 2.0.3 → 2.0.4
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/platform/cli/commands/install/command.d.ts +14 -0
- package/dist/platform/cli/commands/install/command.d.ts.map +1 -0
- package/dist/platform/cli/commands/install/command.js +145 -0
- package/dist/platform/cli/commands/install/command.js.map +1 -0
- package/dist/platform/cli/commands/register.d.ts.map +1 -1
- package/dist/platform/cli/commands/register.js +37 -28
- package/dist/platform/cli/commands/register.js.map +1 -1
- package/dist/platform/cli/index.js +61 -1
- package/dist/platform/cli/index.js.map +1 -1
- package/dist/platform/cli/web/commands/create/feature.d.ts +11 -0
- package/dist/platform/cli/web/commands/create/feature.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/create/feature.js +43 -0
- package/dist/platform/cli/web/commands/create/feature.js.map +1 -0
- package/dist/platform/cli/web/commands/create/module.d.ts +11 -0
- package/dist/platform/cli/web/commands/create/module.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/create/module.js +44 -0
- package/dist/platform/cli/web/commands/create/module.js.map +1 -0
- package/dist/platform/cli/web/commands/create/mvvm.d.ts +11 -0
- package/dist/platform/cli/web/commands/create/mvvm.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/create/mvvm.js +43 -0
- package/dist/platform/cli/web/commands/create/mvvm.js.map +1 -0
- package/dist/platform/cli/web/commands/init-fullstack.d.ts +12 -0
- package/dist/platform/cli/web/commands/init-fullstack.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/init-fullstack.js +42 -0
- package/dist/platform/cli/web/commands/init-fullstack.js.map +1 -0
- package/dist/platform/cli/web/commands/init-web.d.ts +12 -0
- package/dist/platform/cli/web/commands/init-web.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/init-web.js +70 -0
- package/dist/platform/cli/web/commands/init-web.js.map +1 -0
- package/dist/platform/cli/web/commands/install-api.d.ts +11 -0
- package/dist/platform/cli/web/commands/install-api.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/install-api.js +92 -0
- package/dist/platform/cli/web/commands/install-api.js.map +1 -0
- package/dist/platform/cli/web/commands/install-web.d.ts +13 -0
- package/dist/platform/cli/web/commands/install-web.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/install-web.js +102 -0
- package/dist/platform/cli/web/commands/install-web.js.map +1 -0
- package/dist/platform/cli/web/commands/install.d.ts +3 -0
- package/dist/platform/cli/web/commands/install.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/install.js +23 -0
- package/dist/platform/cli/web/commands/install.js.map +1 -0
- package/dist/platform/cli/web/commands/make/component.d.ts +16 -0
- package/dist/platform/cli/web/commands/make/component.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/make/component.js +73 -0
- package/dist/platform/cli/web/commands/make/component.js.map +1 -0
- package/dist/platform/cli/web/commands/make/guard.d.ts +13 -0
- package/dist/platform/cli/web/commands/make/guard.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/make/guard.js +46 -0
- package/dist/platform/cli/web/commands/make/guard.js.map +1 -0
- package/dist/platform/cli/web/commands/make/layout.d.ts +12 -0
- package/dist/platform/cli/web/commands/make/layout.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/make/layout.js +44 -0
- package/dist/platform/cli/web/commands/make/layout.js.map +1 -0
- package/dist/platform/cli/web/commands/make/page.d.ts +17 -0
- package/dist/platform/cli/web/commands/make/page.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/make/page.js +66 -0
- package/dist/platform/cli/web/commands/make/page.js.map +1 -0
- package/dist/platform/cli/web/commands/make/resource.d.ts +17 -0
- package/dist/platform/cli/web/commands/make/resource.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/make/resource.js +37 -0
- package/dist/platform/cli/web/commands/make/resource.js.map +1 -0
- package/dist/platform/cli/web/commands/make/service.d.ts +16 -0
- package/dist/platform/cli/web/commands/make/service.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/make/service.js +137 -0
- package/dist/platform/cli/web/commands/make/service.js.map +1 -0
- package/dist/platform/cli/web/commands/make/store.d.ts +16 -0
- package/dist/platform/cli/web/commands/make/store.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/make/store.js +72 -0
- package/dist/platform/cli/web/commands/make/store.js.map +1 -0
- package/dist/platform/cli/web/commands/web-sync.d.ts +10 -0
- package/dist/platform/cli/web/commands/web-sync.d.ts.map +1 -0
- package/dist/platform/cli/web/commands/web-sync.js +307 -0
- package/dist/platform/cli/web/commands/web-sync.js.map +1 -0
- package/dist/platform/cli/web/index.d.ts +3 -0
- package/dist/platform/cli/web/index.d.ts.map +1 -0
- package/dist/platform/cli/web/index.js +40 -0
- package/dist/platform/cli/web/index.js.map +1 -0
- package/dist/platform/cli/web/utils/config.d.ts +52 -0
- package/dist/platform/cli/web/utils/config.d.ts.map +1 -0
- package/dist/platform/cli/web/utils/config.js +89 -0
- package/dist/platform/cli/web/utils/config.js.map +1 -0
- package/dist/platform/cli/web/utils/format.d.ts +2 -0
- package/dist/platform/cli/web/utils/format.d.ts.map +1 -0
- package/dist/platform/cli/web/utils/format.js +28 -0
- package/dist/platform/cli/web/utils/format.js.map +1 -0
- package/dist/platform/cli/web/utils/header.d.ts +3 -0
- package/dist/platform/cli/web/utils/header.d.ts.map +1 -0
- package/dist/platform/cli/web/utils/header.js +11 -0
- package/dist/platform/cli/web/utils/header.js.map +1 -0
- package/dist/platform/cli/web/utils/logger.d.ts +10 -0
- package/dist/platform/cli/web/utils/logger.d.ts.map +1 -0
- package/dist/platform/cli/web/utils/logger.js +47 -0
- package/dist/platform/cli/web/utils/logger.js.map +1 -0
- package/dist/platform/cli/web/utils/names.d.ts +7 -0
- package/dist/platform/cli/web/utils/names.d.ts.map +1 -0
- package/dist/platform/cli/web/utils/names.js +43 -0
- package/dist/platform/cli/web/utils/names.js.map +1 -0
- package/dist/platform/cli/web/utils/resolve-paths.d.ts +10 -0
- package/dist/platform/cli/web/utils/resolve-paths.d.ts.map +1 -0
- package/dist/platform/cli/web/utils/resolve-paths.js +87 -0
- package/dist/platform/cli/web/utils/resolve-paths.js.map +1 -0
- package/dist/platform/cli/web/utils/write-file.d.ts +7 -0
- package/dist/platform/cli/web/utils/write-file.d.ts.map +1 -0
- package/dist/platform/cli/web/utils/write-file.js +31 -0
- package/dist/platform/cli/web/utils/write-file.js.map +1 -0
- package/dist/web/cli/commands/create/feature.d.ts +11 -0
- package/dist/web/cli/commands/create/feature.d.ts.map +1 -0
- package/dist/web/cli/commands/create/feature.js +43 -0
- package/dist/web/cli/commands/create/feature.js.map +1 -0
- package/dist/web/cli/commands/create/module.d.ts +11 -0
- package/dist/web/cli/commands/create/module.d.ts.map +1 -0
- package/dist/web/cli/commands/create/module.js +44 -0
- package/dist/web/cli/commands/create/module.js.map +1 -0
- package/dist/web/cli/commands/create/mvvm.d.ts +11 -0
- package/dist/web/cli/commands/create/mvvm.d.ts.map +1 -0
- package/dist/web/cli/commands/create/mvvm.js +43 -0
- package/dist/web/cli/commands/create/mvvm.js.map +1 -0
- package/dist/web/cli/commands/init-fullstack.d.ts +12 -0
- package/dist/web/cli/commands/init-fullstack.d.ts.map +1 -0
- package/dist/web/cli/commands/init-fullstack.js +42 -0
- package/dist/web/cli/commands/init-fullstack.js.map +1 -0
- package/dist/web/cli/commands/init-web.d.ts +12 -0
- package/dist/web/cli/commands/init-web.d.ts.map +1 -0
- package/dist/web/cli/commands/init-web.js +70 -0
- package/dist/web/cli/commands/init-web.js.map +1 -0
- package/dist/web/cli/commands/install-api.d.ts +10 -0
- package/dist/web/cli/commands/install-api.d.ts.map +1 -0
- package/dist/web/cli/commands/install-api.js +91 -0
- package/dist/web/cli/commands/install-api.js.map +1 -0
- package/dist/web/cli/commands/install-web.d.ts +12 -0
- package/dist/web/cli/commands/install-web.d.ts.map +1 -0
- package/dist/web/cli/commands/install-web.js +101 -0
- package/dist/web/cli/commands/install-web.js.map +1 -0
- package/dist/web/cli/commands/make/component.d.ts +13 -0
- package/dist/web/cli/commands/make/component.d.ts.map +1 -0
- package/dist/web/cli/commands/make/component.js +40 -0
- package/dist/web/cli/commands/make/component.js.map +1 -0
- package/dist/web/cli/commands/make/guard.d.ts +11 -0
- package/dist/web/cli/commands/make/guard.d.ts.map +1 -0
- package/dist/web/cli/commands/make/guard.js +37 -0
- package/dist/web/cli/commands/make/guard.js.map +1 -0
- package/dist/web/cli/commands/make/layout.d.ts +11 -0
- package/dist/web/cli/commands/make/layout.d.ts.map +1 -0
- package/dist/web/cli/commands/make/layout.js +37 -0
- package/dist/web/cli/commands/make/layout.js.map +1 -0
- package/dist/web/cli/commands/make/page.d.ts +14 -0
- package/dist/web/cli/commands/make/page.d.ts.map +1 -0
- package/dist/web/cli/commands/make/page.js +42 -0
- package/dist/web/cli/commands/make/page.js.map +1 -0
- package/dist/web/cli/commands/make/resource.d.ts +13 -0
- package/dist/web/cli/commands/make/resource.d.ts.map +1 -0
- package/dist/web/cli/commands/make/resource.js +33 -0
- package/dist/web/cli/commands/make/resource.js.map +1 -0
- package/dist/web/cli/commands/make/service.d.ts +14 -0
- package/dist/web/cli/commands/make/service.d.ts.map +1 -0
- package/dist/web/cli/commands/make/service.js +56 -0
- package/dist/web/cli/commands/make/service.js.map +1 -0
- package/dist/web/cli/commands/make/store.d.ts +14 -0
- package/dist/web/cli/commands/make/store.d.ts.map +1 -0
- package/dist/web/cli/commands/make/store.js +47 -0
- package/dist/web/cli/commands/make/store.js.map +1 -0
- package/dist/web/cli/commands/web-sync.d.ts +10 -0
- package/dist/web/cli/commands/web-sync.d.ts.map +1 -0
- package/dist/web/cli/commands/web-sync.js +48 -0
- package/dist/web/cli/commands/web-sync.js.map +1 -0
- package/dist/web/cli/index.d.mts +5 -0
- package/dist/web/cli/index.d.ts +5 -0
- package/dist/web/cli/index.d.ts.map +1 -0
- package/dist/web/cli/index.js +36 -0
- package/dist/web/cli/index.js.map +1 -0
- package/dist/web/cli/index.mjs +984 -0
- package/dist/web/cli/utils/config.d.ts +52 -0
- package/dist/web/cli/utils/config.d.ts.map +1 -0
- package/dist/web/cli/utils/config.js +89 -0
- package/dist/web/cli/utils/config.js.map +1 -0
- package/dist/web/cli/utils/format.d.ts +2 -0
- package/dist/web/cli/utils/format.d.ts.map +1 -0
- package/dist/web/cli/utils/format.js +28 -0
- package/dist/web/cli/utils/format.js.map +1 -0
- package/dist/web/cli/utils/logger.d.ts +10 -0
- package/dist/web/cli/utils/logger.d.ts.map +1 -0
- package/dist/web/cli/utils/logger.js +34 -0
- package/dist/web/cli/utils/logger.js.map +1 -0
- package/dist/web/cli/utils/names.d.ts +7 -0
- package/dist/web/cli/utils/names.d.ts.map +1 -0
- package/dist/web/cli/utils/names.js +43 -0
- package/dist/web/cli/utils/names.js.map +1 -0
- package/dist/web/cli/utils/resolve-paths.d.ts +10 -0
- package/dist/web/cli/utils/resolve-paths.d.ts.map +1 -0
- package/dist/web/cli/utils/resolve-paths.js +87 -0
- package/dist/web/cli/utils/resolve-paths.js.map +1 -0
- package/dist/web/cli/utils/write-file.d.ts +7 -0
- package/dist/web/cli/utils/write-file.d.ts.map +1 -0
- package/dist/web/cli/utils/write-file.js +31 -0
- package/dist/web/cli/utils/write-file.js.map +1 -0
- package/dist/web/platform/cli/web/index.d.mts +5 -0
- package/dist/web/platform/cli/web/index.d.ts +5 -0
- package/dist/web/platform/cli/web/index.js +2035 -0
- package/dist/web/platform/cli/web/index.mjs +1998 -0
- package/dist/web/src/adapters/jotai.d.ts +2 -0
- package/dist/web/src/adapters/jotai.d.ts.map +1 -0
- package/dist/web/src/adapters/jotai.js +7 -0
- package/dist/web/src/adapters/jotai.js.map +1 -0
- package/dist/web/src/adapters/mobx.d.ts +2 -0
- package/dist/web/src/adapters/mobx.d.ts.map +1 -0
- package/dist/web/src/adapters/mobx.js +7 -0
- package/dist/web/src/adapters/mobx.js.map +1 -0
- package/dist/web/src/adapters/redux.d.ts +2 -0
- package/dist/web/src/adapters/redux.d.ts.map +1 -0
- package/dist/web/src/adapters/redux.js +7 -0
- package/dist/web/src/adapters/redux.js.map +1 -0
- package/dist/web/src/adapters/zustand.d.ts +2 -0
- package/dist/web/src/adapters/zustand.d.ts.map +1 -0
- package/dist/web/src/adapters/zustand.js +7 -0
- package/dist/web/src/adapters/zustand.js.map +1 -0
- package/dist/web/src/config/web-config.d.ts +34 -0
- package/dist/web/src/config/web-config.d.ts.map +1 -0
- package/dist/web/src/config/web-config.js +73 -0
- package/dist/web/src/config/web-config.js.map +1 -0
- package/dist/web/src/core/application.d.ts +8 -0
- package/dist/web/src/core/application.d.ts.map +1 -0
- package/dist/web/src/core/application.js +45 -0
- package/dist/web/src/core/application.js.map +1 -0
- package/dist/web/src/core/decorators/component.d.ts +20 -0
- package/dist/web/src/core/decorators/component.d.ts.map +1 -0
- package/dist/web/src/core/decorators/component.js +83 -0
- package/dist/web/src/core/decorators/component.js.map +1 -0
- package/dist/web/src/core/decorators/page.d.ts +27 -0
- package/dist/web/src/core/decorators/page.d.ts.map +1 -0
- package/dist/web/src/core/decorators/page.js +58 -0
- package/dist/web/src/core/decorators/page.js.map +1 -0
- package/dist/web/src/core/di/container.d.ts +8 -0
- package/dist/web/src/core/di/container.d.ts.map +1 -0
- package/dist/web/src/core/di/container.js +26 -0
- package/dist/web/src/core/di/container.js.map +1 -0
- package/dist/web/src/core/runtime.d.ts +3 -0
- package/dist/web/src/core/runtime.d.ts.map +1 -0
- package/dist/web/src/core/runtime.js +15 -0
- package/dist/web/src/core/runtime.js.map +1 -0
- package/dist/web/src/http/fragment-fetch.d.ts +55 -0
- package/dist/web/src/http/fragment-fetch.d.ts.map +1 -0
- package/dist/web/src/http/fragment-fetch.js +290 -0
- package/dist/web/src/http/fragment-fetch.js.map +1 -0
- package/dist/web/src/index.d.mts +137 -0
- package/dist/web/src/index.d.ts +7 -0
- package/dist/web/src/index.d.ts.map +1 -0
- package/dist/web/src/index.js +31 -0
- package/dist/web/src/index.js.map +1 -0
- package/dist/web/src/index.mjs +643 -0
- package/dist/web/src/router/fragment-router.d.ts +14 -0
- package/dist/web/src/router/fragment-router.d.ts.map +1 -0
- package/dist/web/src/router/fragment-router.js +94 -0
- package/dist/web/src/router/fragment-router.js.map +1 -0
- package/dist/web/web/src/index.d.mts +137 -0
- package/dist/web/web/src/index.d.ts +137 -0
- package/dist/web/web/src/index.js +702 -0
- package/dist/web/web/src/index.mjs +644 -0
- package/package.json +15 -3
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FragmentFetch = exports.FragmentHttpError = void 0;
|
|
4
|
+
class FragmentHttpError extends Error {
|
|
5
|
+
constructor(message, init) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "FragmentHttpError";
|
|
8
|
+
this.status = init.status;
|
|
9
|
+
this.statusText = init.statusText;
|
|
10
|
+
this.body = init.body;
|
|
11
|
+
this.request = init.request;
|
|
12
|
+
this.response = init.response;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.FragmentHttpError = FragmentHttpError;
|
|
16
|
+
const memoryTokenState = { token: null };
|
|
17
|
+
class FragmentFetchClient {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.config = {
|
|
20
|
+
baseUrl: "",
|
|
21
|
+
timeout: 10000,
|
|
22
|
+
retries: 0,
|
|
23
|
+
retryDelay: 300,
|
|
24
|
+
headers: {},
|
|
25
|
+
tokenTransport: "cookie",
|
|
26
|
+
tokenKey: "fragment_token",
|
|
27
|
+
onUnauthorized: "throw",
|
|
28
|
+
onForbidden: "throw",
|
|
29
|
+
onError: undefined,
|
|
30
|
+
};
|
|
31
|
+
this.requestInterceptors = [];
|
|
32
|
+
this.responseInterceptors = [];
|
|
33
|
+
}
|
|
34
|
+
configure(config) {
|
|
35
|
+
this.config = {
|
|
36
|
+
...this.config,
|
|
37
|
+
...config,
|
|
38
|
+
headers: {
|
|
39
|
+
...this.config.headers,
|
|
40
|
+
...(config.headers || {}),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
setToken(token) {
|
|
45
|
+
memoryTokenState.token = token;
|
|
46
|
+
if (this.config.tokenTransport === "localStorage" && typeof window !== "undefined") {
|
|
47
|
+
window.localStorage.setItem(this.config.tokenKey, token);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
clearToken() {
|
|
51
|
+
memoryTokenState.token = null;
|
|
52
|
+
if (this.config.tokenTransport === "localStorage" && typeof window !== "undefined") {
|
|
53
|
+
window.localStorage.removeItem(this.config.tokenKey);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
getToken() {
|
|
57
|
+
if (this.config.tokenTransport === "memory") {
|
|
58
|
+
return memoryTokenState.token;
|
|
59
|
+
}
|
|
60
|
+
if (this.config.tokenTransport === "localStorage" && typeof window !== "undefined") {
|
|
61
|
+
return window.localStorage.getItem(this.config.tokenKey);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
addRequestInterceptor(fn) {
|
|
66
|
+
this.requestInterceptors.push(fn);
|
|
67
|
+
return () => {
|
|
68
|
+
this.requestInterceptors = this.requestInterceptors.filter((it) => it !== fn);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
addResponseInterceptor(fn) {
|
|
72
|
+
this.responseInterceptors.push(fn);
|
|
73
|
+
return () => {
|
|
74
|
+
this.responseInterceptors = this.responseInterceptors.filter((it) => it !== fn);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
get(path, options) {
|
|
78
|
+
return this.request(path, { method: "GET" }, options);
|
|
79
|
+
}
|
|
80
|
+
post(path, body, options) {
|
|
81
|
+
return this.request(path, { method: "POST", body: body ? JSON.stringify(body) : undefined }, options);
|
|
82
|
+
}
|
|
83
|
+
put(path, body, options) {
|
|
84
|
+
return this.request(path, { method: "PUT", body: body ? JSON.stringify(body) : undefined }, options);
|
|
85
|
+
}
|
|
86
|
+
patch(path, body, options) {
|
|
87
|
+
return this.request(path, { method: "PATCH", body: body ? JSON.stringify(body) : undefined }, options);
|
|
88
|
+
}
|
|
89
|
+
delete(path, options) {
|
|
90
|
+
return this.request(path, { method: "DELETE" }, options);
|
|
91
|
+
}
|
|
92
|
+
async request(path, init = {}, options = {}) {
|
|
93
|
+
const url = this.buildUrl(path, options.params);
|
|
94
|
+
const headers = {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
...this.config.headers,
|
|
97
|
+
...options.headers,
|
|
98
|
+
};
|
|
99
|
+
if (!options.skipAuth && this.config.tokenTransport !== "cookie") {
|
|
100
|
+
const token = this.getToken();
|
|
101
|
+
if (token) {
|
|
102
|
+
headers.Authorization = `Bearer ${token}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
const timeoutMs = options.timeout ?? this.config.timeout;
|
|
107
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
108
|
+
let request = new Request(url, {
|
|
109
|
+
...init,
|
|
110
|
+
headers,
|
|
111
|
+
credentials: this.config.tokenTransport === "cookie" ? "include" : init.credentials,
|
|
112
|
+
signal: options.signal || controller.signal,
|
|
113
|
+
});
|
|
114
|
+
for (const interceptor of this.requestInterceptors) {
|
|
115
|
+
request = await interceptor(request);
|
|
116
|
+
}
|
|
117
|
+
const retries = options.retries ?? this.config.retries;
|
|
118
|
+
try {
|
|
119
|
+
return await this.executeWithRetry(request, retries, this.config.retryDelay);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error instanceof FragmentHttpError) {
|
|
123
|
+
this.config.onError?.(error);
|
|
124
|
+
}
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
clearTimeout(timeout);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async executeWithRetry(request, retries, retryDelay) {
|
|
132
|
+
let attempt = 0;
|
|
133
|
+
let lastError = null;
|
|
134
|
+
while (attempt <= retries) {
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetch(request.clone());
|
|
137
|
+
for (const interceptor of this.responseInterceptors) {
|
|
138
|
+
await interceptor(response, { request });
|
|
139
|
+
}
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
const body = await this.parseBody(response);
|
|
142
|
+
const error = new FragmentHttpError(`HTTP ${response.status}`, {
|
|
143
|
+
status: response.status,
|
|
144
|
+
statusText: response.statusText,
|
|
145
|
+
body,
|
|
146
|
+
request,
|
|
147
|
+
response,
|
|
148
|
+
});
|
|
149
|
+
if (response.status === 401) {
|
|
150
|
+
const result = this.handleAuthMode(this.config.onUnauthorized);
|
|
151
|
+
if (result === "silent")
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (response.status === 403) {
|
|
155
|
+
const result = this.handleAuthMode(this.config.onForbidden);
|
|
156
|
+
if (result === "silent")
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
for (const interceptor of this.responseInterceptors) {
|
|
160
|
+
await interceptor(response, { request, error });
|
|
161
|
+
}
|
|
162
|
+
if (response.status >= 500 && attempt < retries) {
|
|
163
|
+
await this.delay(retryDelay);
|
|
164
|
+
attempt += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
return (await this.parseBody(response));
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (error instanceof FragmentHttpError) {
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
if (error?.name === "AbortError") {
|
|
176
|
+
const syntheticResponse = new Response(null, { status: 408, statusText: "Request Timeout" });
|
|
177
|
+
throw new FragmentHttpError("Request timeout", {
|
|
178
|
+
status: 408,
|
|
179
|
+
statusText: "Request Timeout",
|
|
180
|
+
body: null,
|
|
181
|
+
request,
|
|
182
|
+
response: syntheticResponse,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
lastError = error;
|
|
186
|
+
if (attempt >= retries) {
|
|
187
|
+
const syntheticResponse = new Response(null, { status: 503, statusText: "Service Unavailable" });
|
|
188
|
+
throw new FragmentHttpError(error?.message || "Network error", {
|
|
189
|
+
status: 503,
|
|
190
|
+
statusText: "Service Unavailable",
|
|
191
|
+
body: null,
|
|
192
|
+
request,
|
|
193
|
+
response: syntheticResponse,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
await this.delay(retryDelay);
|
|
197
|
+
}
|
|
198
|
+
attempt += 1;
|
|
199
|
+
}
|
|
200
|
+
const syntheticResponse = new Response(null, { status: 503, statusText: "Service Unavailable" });
|
|
201
|
+
throw new FragmentHttpError("Request failed", {
|
|
202
|
+
status: 503,
|
|
203
|
+
statusText: "Service Unavailable",
|
|
204
|
+
body: lastError,
|
|
205
|
+
request,
|
|
206
|
+
response: syntheticResponse,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
async parseBody(response) {
|
|
210
|
+
const contentType = response.headers.get("content-type") || "";
|
|
211
|
+
if (contentType.includes("application/json")) {
|
|
212
|
+
return response.json();
|
|
213
|
+
}
|
|
214
|
+
const text = await response.text();
|
|
215
|
+
return text.length ? text : null;
|
|
216
|
+
}
|
|
217
|
+
buildUrl(path, params) {
|
|
218
|
+
const normalizedBase = this.config.baseUrl.replace(/\/$/, "");
|
|
219
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
220
|
+
const url = new URL(`${normalizedBase}${normalizedPath}`);
|
|
221
|
+
if (params) {
|
|
222
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
223
|
+
if (Array.isArray(value)) {
|
|
224
|
+
value.forEach((v) => url.searchParams.append(key, String(v)));
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
url.searchParams.append(key, String(value));
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return url.toString();
|
|
231
|
+
}
|
|
232
|
+
handleAuthMode(mode) {
|
|
233
|
+
if (!mode || mode === "throw") {
|
|
234
|
+
return "throw";
|
|
235
|
+
}
|
|
236
|
+
if (mode === "silent") {
|
|
237
|
+
return "silent";
|
|
238
|
+
}
|
|
239
|
+
if (mode.startsWith("redirect:")) {
|
|
240
|
+
const to = mode.slice("redirect:".length);
|
|
241
|
+
if (typeof window !== "undefined") {
|
|
242
|
+
window.location.href = to;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return "throw";
|
|
246
|
+
}
|
|
247
|
+
async delay(ms) {
|
|
248
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const client = new FragmentFetchClient();
|
|
252
|
+
exports.FragmentFetch = {
|
|
253
|
+
configure(config) {
|
|
254
|
+
client.configure(config);
|
|
255
|
+
},
|
|
256
|
+
get(path, options) {
|
|
257
|
+
return client.get(path, options);
|
|
258
|
+
},
|
|
259
|
+
post(path, body, options) {
|
|
260
|
+
return client.post(path, body, options);
|
|
261
|
+
},
|
|
262
|
+
put(path, body, options) {
|
|
263
|
+
return client.put(path, body, options);
|
|
264
|
+
},
|
|
265
|
+
patch(path, body, options) {
|
|
266
|
+
return client.patch(path, body, options);
|
|
267
|
+
},
|
|
268
|
+
delete(path, options) {
|
|
269
|
+
return client.delete(path, options);
|
|
270
|
+
},
|
|
271
|
+
request(path, init, options) {
|
|
272
|
+
return client.request(path, init, options);
|
|
273
|
+
},
|
|
274
|
+
setToken(token) {
|
|
275
|
+
client.setToken(token);
|
|
276
|
+
},
|
|
277
|
+
clearToken() {
|
|
278
|
+
client.clearToken();
|
|
279
|
+
},
|
|
280
|
+
getToken() {
|
|
281
|
+
return client.getToken();
|
|
282
|
+
},
|
|
283
|
+
addRequestInterceptor(fn) {
|
|
284
|
+
return client.addRequestInterceptor(fn);
|
|
285
|
+
},
|
|
286
|
+
addResponseInterceptor(fn) {
|
|
287
|
+
return client.addResponseInterceptor(fn);
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
//# sourceMappingURL=fragment-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frag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AAwB;QAC7D,OAAO,MAAM,CAAC,KAAK,CAAI,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IACD,MAAM,CAAI,IAAY,EAAE,OAAwB;QAC9C,OAAO,MAAM,CAAC,MAAM,CAAI,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,CAAI,IAAY,EAAE,IAAkB,EAAE,OAAwB;QACnE,OAAO,MAAM,CAAC,OAAO,CAAI,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IACD,QAAQ,CAAC,KAAa;QACpB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,UAAU;QACR,MAAM,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IACD,QAAQ;QACN,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;IACD,qBAAqB,CAAC,EAAsB;QAC1C,OAAO,MAAM,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IACD,sBAAsB,CAAC,EAAuB;QAC5C,OAAO,MAAM,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
interface FragmentFetchConfig {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
timeout?: number;
|
|
4
|
+
retries?: number;
|
|
5
|
+
retryDelay?: number;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
tokenTransport?: "cookie" | "localStorage" | "memory";
|
|
8
|
+
tokenKey?: string;
|
|
9
|
+
onUnauthorized?: "throw" | `redirect:${string}` | "silent";
|
|
10
|
+
onForbidden?: "throw" | `redirect:${string}` | "silent";
|
|
11
|
+
onError?: (err: FragmentHttpError) => void;
|
|
12
|
+
}
|
|
13
|
+
interface RequestOptions {
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
params?: Record<string, string | number | boolean | Array<string | number | boolean>>;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
retries?: number;
|
|
18
|
+
skipAuth?: boolean;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
declare class FragmentHttpError extends Error {
|
|
22
|
+
status: number;
|
|
23
|
+
statusText: string;
|
|
24
|
+
body: unknown;
|
|
25
|
+
request: Request;
|
|
26
|
+
response: Response;
|
|
27
|
+
constructor(message: string, init: {
|
|
28
|
+
status: number;
|
|
29
|
+
statusText: string;
|
|
30
|
+
body: unknown;
|
|
31
|
+
request: Request;
|
|
32
|
+
response: Response;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
type RequestInterceptor = (request: Request) => Promise<Request> | Request;
|
|
36
|
+
type ResponseInterceptor = (response: Response, context: {
|
|
37
|
+
request: Request;
|
|
38
|
+
error?: FragmentHttpError;
|
|
39
|
+
}) => Promise<Response> | Response;
|
|
40
|
+
declare const FragmentFetch: {
|
|
41
|
+
configure(config: FragmentFetchConfig): void;
|
|
42
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
43
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
44
|
+
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
45
|
+
patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
46
|
+
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
47
|
+
request<T>(path: string, init?: RequestInit, options?: RequestOptions): Promise<T>;
|
|
48
|
+
setToken(token: string): void;
|
|
49
|
+
clearToken(): void;
|
|
50
|
+
getToken(): string | null;
|
|
51
|
+
addRequestInterceptor(fn: RequestInterceptor): () => void;
|
|
52
|
+
addResponseInterceptor(fn: ResponseInterceptor): () => void;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
declare function FragmentWebApplication(options: {
|
|
56
|
+
rootElement: string;
|
|
57
|
+
strict?: boolean;
|
|
58
|
+
}): ClassDecorator;
|
|
59
|
+
declare class FragmentWebUIApplication {
|
|
60
|
+
bootstrap(applicationClass: new () => unknown): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare function Component(options?: {
|
|
64
|
+
tag?: string;
|
|
65
|
+
memo?: boolean;
|
|
66
|
+
displayName?: string;
|
|
67
|
+
}): ClassDecorator;
|
|
68
|
+
declare function State(initial: unknown): PropertyDecorator;
|
|
69
|
+
declare function Computed(deps?: string[]): MethodDecorator;
|
|
70
|
+
declare function Effect(options: {
|
|
71
|
+
on: "mount" | "update" | "unmount";
|
|
72
|
+
deps?: string[];
|
|
73
|
+
}): MethodDecorator;
|
|
74
|
+
declare function Watch(key: string): MethodDecorator;
|
|
75
|
+
declare function Store(store: unknown, selector?: (state: any) => unknown): PropertyDecorator;
|
|
76
|
+
declare function Prop(defaultValue?: unknown): PropertyDecorator;
|
|
77
|
+
declare function Ref(): PropertyDecorator;
|
|
78
|
+
declare function Inject(token: unknown): PropertyDecorator;
|
|
79
|
+
declare function FragmentService(): ClassDecorator;
|
|
80
|
+
declare function Injectable(_scope?: "singleton" | "transient"): ClassDecorator;
|
|
81
|
+
|
|
82
|
+
declare function Page(options: {
|
|
83
|
+
path: string;
|
|
84
|
+
title?: string;
|
|
85
|
+
layout?: string;
|
|
86
|
+
}): ClassDecorator;
|
|
87
|
+
declare function Layout(options: {
|
|
88
|
+
name: string;
|
|
89
|
+
}): ClassDecorator;
|
|
90
|
+
declare function Guard(guardClass: new (...args: any[]) => {
|
|
91
|
+
canActivate?: () => boolean | Promise<boolean>;
|
|
92
|
+
}): ClassDecorator;
|
|
93
|
+
declare function Param(_name: string): PropertyDecorator;
|
|
94
|
+
declare function Query(_name: string, _defaultValue?: string): PropertyDecorator;
|
|
95
|
+
declare function RedirectIfAuthenticated(to?: string): ClassDecorator;
|
|
96
|
+
|
|
97
|
+
type Token<T = unknown> = string | symbol | (new (...args: any[]) => T);
|
|
98
|
+
declare class DIContainer {
|
|
99
|
+
private static providers;
|
|
100
|
+
static register<T>(token: Token<T>, value: T): void;
|
|
101
|
+
static resolve<T>(token: Token<T>): T;
|
|
102
|
+
static clear(): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type StructureMode = "layered" | "module" | "feature" | "mvvm";
|
|
106
|
+
type StoreAdapter = "zustand" | "jotai" | "redux" | "mobx";
|
|
107
|
+
interface FragmentWebConfig {
|
|
108
|
+
webRoot: string;
|
|
109
|
+
serverRoot: string;
|
|
110
|
+
publicRoutes: string[];
|
|
111
|
+
authenticatedRoutes: string[];
|
|
112
|
+
app: {
|
|
113
|
+
name: string;
|
|
114
|
+
rootElement: string;
|
|
115
|
+
strict: boolean;
|
|
116
|
+
router: "react-router";
|
|
117
|
+
stateAdapter: StoreAdapter;
|
|
118
|
+
};
|
|
119
|
+
fetch: {
|
|
120
|
+
baseUrl: string;
|
|
121
|
+
timeout?: number;
|
|
122
|
+
retries?: number;
|
|
123
|
+
retryDelay?: number;
|
|
124
|
+
headers?: Record<string, string>;
|
|
125
|
+
tokenTransport?: "cookie" | "localStorage" | "memory";
|
|
126
|
+
tokenKey?: string;
|
|
127
|
+
onUnauthorized?: "throw" | `redirect:${string}` | "silent";
|
|
128
|
+
onForbidden?: "throw" | `redirect:${string}` | "silent";
|
|
129
|
+
};
|
|
130
|
+
structure: StructureMode;
|
|
131
|
+
di: {
|
|
132
|
+
autoScan: boolean;
|
|
133
|
+
scanPaths: string[];
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { Component, Computed, DIContainer, Effect, FragmentFetch, FragmentHttpError, FragmentService, FragmentWebApplication, type FragmentWebConfig, FragmentWebUIApplication, Guard, Inject, Injectable, Layout, Page, Param, Prop, Query, RedirectIfAuthenticated, Ref, State, Store, Watch };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { FragmentFetch, FragmentHttpError } from "./http/fragment-fetch";
|
|
2
|
+
export { FragmentWebApplication, FragmentWebUIApplication } from "./core/application";
|
|
3
|
+
export { Component, State, Computed, Effect, Watch, Store, Prop, Ref, Inject, FragmentService, Injectable, } from "./core/decorators/component";
|
|
4
|
+
export { Page, Layout, Guard, Param, Query, RedirectIfAuthenticated, } from "./core/decorators/page";
|
|
5
|
+
export { DIContainer } from "./core/di/container";
|
|
6
|
+
export type { FragmentWebConfig } from "./config/web-config";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EACL,SAAS,EACT,KAAK,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,GAAG,EACH,MAAM,EACN,eAAe,EACf,UAAU,GACX,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIContainer = exports.RedirectIfAuthenticated = exports.Query = exports.Param = exports.Guard = exports.Layout = exports.Page = exports.Injectable = exports.FragmentService = exports.Inject = exports.Ref = exports.Prop = exports.Store = exports.Watch = exports.Effect = exports.Computed = exports.State = exports.Component = exports.FragmentWebUIApplication = exports.FragmentWebApplication = exports.FragmentHttpError = exports.FragmentFetch = void 0;
|
|
4
|
+
var fragment_fetch_1 = require("./http/fragment-fetch");
|
|
5
|
+
Object.defineProperty(exports, "FragmentFetch", { enumerable: true, get: function () { return fragment_fetch_1.FragmentFetch; } });
|
|
6
|
+
Object.defineProperty(exports, "FragmentHttpError", { enumerable: true, get: function () { return fragment_fetch_1.FragmentHttpError; } });
|
|
7
|
+
var application_1 = require("./core/application");
|
|
8
|
+
Object.defineProperty(exports, "FragmentWebApplication", { enumerable: true, get: function () { return application_1.FragmentWebApplication; } });
|
|
9
|
+
Object.defineProperty(exports, "FragmentWebUIApplication", { enumerable: true, get: function () { return application_1.FragmentWebUIApplication; } });
|
|
10
|
+
var component_1 = require("./core/decorators/component");
|
|
11
|
+
Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return component_1.Component; } });
|
|
12
|
+
Object.defineProperty(exports, "State", { enumerable: true, get: function () { return component_1.State; } });
|
|
13
|
+
Object.defineProperty(exports, "Computed", { enumerable: true, get: function () { return component_1.Computed; } });
|
|
14
|
+
Object.defineProperty(exports, "Effect", { enumerable: true, get: function () { return component_1.Effect; } });
|
|
15
|
+
Object.defineProperty(exports, "Watch", { enumerable: true, get: function () { return component_1.Watch; } });
|
|
16
|
+
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return component_1.Store; } });
|
|
17
|
+
Object.defineProperty(exports, "Prop", { enumerable: true, get: function () { return component_1.Prop; } });
|
|
18
|
+
Object.defineProperty(exports, "Ref", { enumerable: true, get: function () { return component_1.Ref; } });
|
|
19
|
+
Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return component_1.Inject; } });
|
|
20
|
+
Object.defineProperty(exports, "FragmentService", { enumerable: true, get: function () { return component_1.FragmentService; } });
|
|
21
|
+
Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return component_1.Injectable; } });
|
|
22
|
+
var page_1 = require("./core/decorators/page");
|
|
23
|
+
Object.defineProperty(exports, "Page", { enumerable: true, get: function () { return page_1.Page; } });
|
|
24
|
+
Object.defineProperty(exports, "Layout", { enumerable: true, get: function () { return page_1.Layout; } });
|
|
25
|
+
Object.defineProperty(exports, "Guard", { enumerable: true, get: function () { return page_1.Guard; } });
|
|
26
|
+
Object.defineProperty(exports, "Param", { enumerable: true, get: function () { return page_1.Param; } });
|
|
27
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return page_1.Query; } });
|
|
28
|
+
Object.defineProperty(exports, "RedirectIfAuthenticated", { enumerable: true, get: function () { return page_1.RedirectIfAuthenticated; } });
|
|
29
|
+
var container_1 = require("./core/di/container");
|
|
30
|
+
Object.defineProperty(exports, "DIContainer", { enumerable: true, get: function () { return container_1.DIContainer; } });
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAAyE;AAAhE,+GAAA,aAAa,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AACzC,kDAAsF;AAA7E,qHAAA,sBAAsB,OAAA;AAAE,uHAAA,wBAAwB,OAAA;AACzD,yDAYqC;AAXnC,sGAAA,SAAS,OAAA;AACT,kGAAA,KAAK,OAAA;AACL,qGAAA,QAAQ,OAAA;AACR,mGAAA,MAAM,OAAA;AACN,kGAAA,KAAK,OAAA;AACL,kGAAA,KAAK,OAAA;AACL,iGAAA,IAAI,OAAA;AACJ,gGAAA,GAAG,OAAA;AACH,mGAAA,MAAM,OAAA;AACN,4GAAA,eAAe,OAAA;AACf,uGAAA,UAAU,OAAA;AAEZ,+CAOgC;AAN9B,4FAAA,IAAI,OAAA;AACJ,8FAAA,MAAM,OAAA;AACN,6FAAA,KAAK,OAAA;AACL,6FAAA,KAAK,OAAA;AACL,6FAAA,KAAK,OAAA;AACL,+GAAA,uBAAuB,OAAA;AAEzB,iDAAkD;AAAzC,wGAAA,WAAW,OAAA"}
|