@pisell/pisellos 0.0.5

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.
Files changed (138) hide show
  1. package/README.md +180 -0
  2. package/dist/core/index.d.ts +30 -0
  3. package/dist/core/index.js +360 -0
  4. package/dist/effects/index.d.ts +17 -0
  5. package/dist/effects/index.js +162 -0
  6. package/dist/index.d.ts +11 -0
  7. package/dist/index.js +17 -0
  8. package/dist/modules/Account/index.d.ts +21 -0
  9. package/dist/modules/Account/index.js +212 -0
  10. package/dist/modules/Account/types.d.ts +41 -0
  11. package/dist/modules/Account/types.js +19 -0
  12. package/dist/modules/BaseModule.d.ts +11 -0
  13. package/dist/modules/BaseModule.js +27 -0
  14. package/dist/modules/Cart/index.d.ts +33 -0
  15. package/dist/modules/Cart/index.js +242 -0
  16. package/dist/modules/Cart/types.d.ts +35 -0
  17. package/dist/modules/Cart/types.js +19 -0
  18. package/dist/modules/Date/index.d.ts +17 -0
  19. package/dist/modules/Date/index.js +133 -0
  20. package/dist/modules/Date/types.d.ts +32 -0
  21. package/dist/modules/Date/types.js +17 -0
  22. package/dist/modules/Guests/index.d.ts +17 -0
  23. package/dist/modules/Guests/index.js +259 -0
  24. package/dist/modules/Guests/types.d.ts +43 -0
  25. package/dist/modules/Guests/types.js +23 -0
  26. package/dist/modules/Order/index.d.ts +17 -0
  27. package/dist/modules/Order/index.js +228 -0
  28. package/dist/modules/Order/types.d.ts +57 -0
  29. package/dist/modules/Order/types.js +29 -0
  30. package/dist/modules/Payment/index.d.ts +18 -0
  31. package/dist/modules/Payment/index.js +243 -0
  32. package/dist/modules/Payment/types.d.ts +49 -0
  33. package/dist/modules/Payment/types.js +31 -0
  34. package/dist/modules/Product/index.d.ts +39 -0
  35. package/dist/modules/Product/index.js +118 -0
  36. package/dist/modules/Product/types.d.ts +387 -0
  37. package/dist/modules/Product/types.js +1 -0
  38. package/dist/modules/ProductList/index.d.ts +16 -0
  39. package/dist/modules/ProductList/index.js +158 -0
  40. package/dist/modules/ProductList/types.d.ts +9 -0
  41. package/dist/modules/ProductList/types.js +5 -0
  42. package/dist/modules/Resource/index.d.ts +15 -0
  43. package/dist/modules/Resource/index.js +219 -0
  44. package/dist/modules/Resource/types.d.ts +44 -0
  45. package/dist/modules/Resource/types.js +22 -0
  46. package/dist/modules/index.d.ts +3 -0
  47. package/dist/modules/index.js +3 -0
  48. package/dist/plugins/index.d.ts +2 -0
  49. package/dist/plugins/index.js +2 -0
  50. package/dist/plugins/request.d.ts +127 -0
  51. package/dist/plugins/request.js +592 -0
  52. package/dist/plugins/window.d.ts +115 -0
  53. package/dist/plugins/window.js +328 -0
  54. package/dist/solution/BookingByStep/index.d.ts +12 -0
  55. package/dist/solution/BookingByStep/index.js +77 -0
  56. package/dist/solution/BookingByStep/types.d.ts +27 -0
  57. package/dist/solution/BookingByStep/types.js +10 -0
  58. package/dist/solution/BuyTickets/index.d.ts +26 -0
  59. package/dist/solution/BuyTickets/index.js +339 -0
  60. package/dist/solution/BuyTickets/types.d.ts +24 -0
  61. package/dist/solution/BuyTickets/types.js +19 -0
  62. package/dist/solution/PlaceOrder/index.d.ts +0 -0
  63. package/dist/solution/PlaceOrder/index.js +54 -0
  64. package/dist/solution/index.d.ts +1 -0
  65. package/dist/solution/index.js +1 -0
  66. package/dist/store/createStore.d.ts +3 -0
  67. package/dist/store/createStore.js +43 -0
  68. package/dist/types/index.d.ts +85 -0
  69. package/dist/types/index.js +1 -0
  70. package/lib/core/index.d.ts +30 -0
  71. package/lib/core/index.js +212 -0
  72. package/lib/effects/index.d.ts +17 -0
  73. package/lib/effects/index.js +78 -0
  74. package/lib/index.d.ts +11 -0
  75. package/lib/index.js +51 -0
  76. package/lib/modules/Account/index.d.ts +21 -0
  77. package/lib/modules/Account/index.js +93 -0
  78. package/lib/modules/Account/types.d.ts +41 -0
  79. package/lib/modules/Account/types.js +35 -0
  80. package/lib/modules/BaseModule.d.ts +11 -0
  81. package/lib/modules/BaseModule.js +40 -0
  82. package/lib/modules/Cart/index.d.ts +33 -0
  83. package/lib/modules/Cart/index.js +104 -0
  84. package/lib/modules/Cart/types.d.ts +35 -0
  85. package/lib/modules/Cart/types.js +35 -0
  86. package/lib/modules/Date/index.d.ts +17 -0
  87. package/lib/modules/Date/index.js +75 -0
  88. package/lib/modules/Date/types.d.ts +32 -0
  89. package/lib/modules/Date/types.js +33 -0
  90. package/lib/modules/Guests/index.d.ts +17 -0
  91. package/lib/modules/Guests/index.js +95 -0
  92. package/lib/modules/Guests/types.d.ts +43 -0
  93. package/lib/modules/Guests/types.js +35 -0
  94. package/lib/modules/Order/index.d.ts +17 -0
  95. package/lib/modules/Order/index.js +95 -0
  96. package/lib/modules/Order/types.d.ts +57 -0
  97. package/lib/modules/Order/types.js +35 -0
  98. package/lib/modules/Payment/index.d.ts +18 -0
  99. package/lib/modules/Payment/index.js +103 -0
  100. package/lib/modules/Payment/types.d.ts +49 -0
  101. package/lib/modules/Payment/types.js +35 -0
  102. package/lib/modules/Product/index.d.ts +39 -0
  103. package/lib/modules/Product/index.js +87 -0
  104. package/lib/modules/Product/types.d.ts +387 -0
  105. package/lib/modules/Product/types.js +17 -0
  106. package/lib/modules/ProductList/index.d.ts +16 -0
  107. package/lib/modules/ProductList/index.js +71 -0
  108. package/lib/modules/ProductList/types.d.ts +9 -0
  109. package/lib/modules/ProductList/types.js +33 -0
  110. package/lib/modules/Resource/index.d.ts +15 -0
  111. package/lib/modules/Resource/index.js +91 -0
  112. package/lib/modules/Resource/types.d.ts +44 -0
  113. package/lib/modules/Resource/types.js +34 -0
  114. package/lib/modules/index.d.ts +3 -0
  115. package/lib/modules/index.js +27 -0
  116. package/lib/plugins/index.d.ts +2 -0
  117. package/lib/plugins/index.js +25 -0
  118. package/lib/plugins/request.d.ts +127 -0
  119. package/lib/plugins/request.js +297 -0
  120. package/lib/plugins/window.d.ts +115 -0
  121. package/lib/plugins/window.js +252 -0
  122. package/lib/solution/BookingByStep/index.d.ts +12 -0
  123. package/lib/solution/BookingByStep/index.js +53 -0
  124. package/lib/solution/BookingByStep/types.d.ts +27 -0
  125. package/lib/solution/BookingByStep/types.js +38 -0
  126. package/lib/solution/BuyTickets/index.d.ts +26 -0
  127. package/lib/solution/BuyTickets/index.js +122 -0
  128. package/lib/solution/BuyTickets/types.d.ts +24 -0
  129. package/lib/solution/BuyTickets/types.js +40 -0
  130. package/lib/solution/PlaceOrder/index.d.ts +0 -0
  131. package/lib/solution/PlaceOrder/index.js +0 -0
  132. package/lib/solution/index.d.ts +1 -0
  133. package/lib/solution/index.js +23 -0
  134. package/lib/store/createStore.d.ts +3 -0
  135. package/lib/store/createStore.js +46 -0
  136. package/lib/types/index.d.ts +85 -0
  137. package/lib/types/index.js +17 -0
  138. package/package.json +65 -0
@@ -0,0 +1,34 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Resource/types.ts
20
+ var types_exports = {};
21
+ __export(types_exports, {
22
+ ResourceHooks: () => ResourceHooks
23
+ });
24
+ module.exports = __toCommonJS(types_exports);
25
+ var ResourceHooks = /* @__PURE__ */ ((ResourceHooks2) => {
26
+ ResourceHooks2["OnResourceSelect"] = "resource:onResourceSelect";
27
+ ResourceHooks2["OnResourceChange"] = "resource:onResourceChange";
28
+ ResourceHooks2["OnAvailabilityCheck"] = "resource:onAvailabilityCheck";
29
+ return ResourceHooks2;
30
+ })(ResourceHooks || {});
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ ResourceHooks
34
+ });
@@ -0,0 +1,3 @@
1
+ export * from './Product';
2
+ export * from './ProductList';
3
+ export * from './Cart';
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/modules/index.ts
17
+ var modules_exports = {};
18
+ module.exports = __toCommonJS(modules_exports);
19
+ __reExport(modules_exports, require("./Product"), module.exports);
20
+ __reExport(modules_exports, require("./ProductList"), module.exports);
21
+ __reExport(modules_exports, require("./Cart"), module.exports);
22
+ // Annotate the CommonJS export names for ESM import in node:
23
+ 0 && (module.exports = {
24
+ ...require("./Product"),
25
+ ...require("./ProductList"),
26
+ ...require("./Cart")
27
+ });
@@ -0,0 +1,2 @@
1
+ export * from './request';
2
+ export * from './window';
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/plugins/index.ts
17
+ var plugins_exports = {};
18
+ module.exports = __toCommonJS(plugins_exports);
19
+ __reExport(plugins_exports, require("./request"), module.exports);
20
+ __reExport(plugins_exports, require("./window"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("./request"),
24
+ ...require("./window")
25
+ });
@@ -0,0 +1,127 @@
1
+ import { Plugin } from '../types';
2
+ /**
3
+ * RequestPlugin 接口定义
4
+ */
5
+ export interface RequestPlugin extends Plugin {
6
+ /**
7
+ * 发起 GET 请求
8
+ * @param url 请求地址
9
+ * @param options 请求选项
10
+ */
11
+ get: <T = any>(url: string, options?: RequestOptions) => Promise<T>;
12
+ /**
13
+ * 发起 POST 请求
14
+ * @param url 请求地址
15
+ * @param data 请求数据
16
+ * @param options 请求选项
17
+ */
18
+ post: <T = any>(url: string, data?: any, options?: RequestOptions) => Promise<T>;
19
+ /**
20
+ * 发起 PUT 请求
21
+ * @param url 请求地址
22
+ * @param data 请求数据
23
+ * @param options 请求选项
24
+ */
25
+ put: <T = any>(url: string, data?: any, options?: RequestOptions) => Promise<T>;
26
+ /**
27
+ * 发起 DELETE 请求
28
+ * @param url 请求地址
29
+ * @param options 请求选项
30
+ */
31
+ delete: <T = any>(url: string, options?: RequestOptions) => Promise<T>;
32
+ /**
33
+ * 通用请求方法
34
+ * @param options 完整的请求选项
35
+ */
36
+ request: <T = any>(options: RequestOptions) => Promise<T>;
37
+ }
38
+ /**
39
+ * 请求配置
40
+ */
41
+ export interface RequestOptions {
42
+ url?: string;
43
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
44
+ headers?: Record<string, string>;
45
+ data?: any;
46
+ body?: any;
47
+ params?: Record<string, string | number | boolean>;
48
+ timeout?: number;
49
+ responseType?: 'json' | 'text' | 'arraybuffer' | 'blob';
50
+ withCredentials?: boolean;
51
+ }
52
+ /**
53
+ * 响应接口
54
+ */
55
+ export interface Response<T = any> {
56
+ data: T;
57
+ status: number;
58
+ statusText: string;
59
+ headers: Record<string, string>;
60
+ config: RequestOptions;
61
+ }
62
+ /**
63
+ * 请求错误
64
+ */
65
+ export declare class RequestError extends Error {
66
+ response?: Response;
67
+ request?: any;
68
+ config?: RequestOptions;
69
+ constructor(message: string, config?: RequestOptions, request?: any, response?: Response);
70
+ }
71
+ /**
72
+ * RequestPlugin 实现
73
+ */
74
+ declare class RequestPluginImpl implements RequestPlugin {
75
+ name: string;
76
+ version: string;
77
+ private core;
78
+ /**
79
+ * 默认请求选项
80
+ */
81
+ private defaultOptions;
82
+ /**
83
+ * 全局拦截器
84
+ */
85
+ private interceptors;
86
+ initialize(): void;
87
+ destroy(): void;
88
+ /**
89
+ * 添加请求拦截器
90
+ */
91
+ addRequestInterceptor(interceptor: (config: RequestOptions) => RequestOptions | Promise<RequestOptions>): void;
92
+ /**
93
+ * 添加响应拦截器
94
+ */
95
+ addResponseInterceptor(interceptor: (response: Response) => Response | Promise<Response>): void;
96
+ /**
97
+ * 添加错误拦截器
98
+ */
99
+ addErrorInterceptor(interceptor: (error: RequestError) => RequestError | Promise<RequestError>): void;
100
+ /**
101
+ * GET 请求
102
+ */
103
+ get<T = any>(url: string, options?: RequestOptions): Promise<T>;
104
+ /**
105
+ * POST 请求
106
+ */
107
+ post<T = any>(url: string, data?: any, options?: RequestOptions): Promise<T>;
108
+ /**
109
+ * PUT 请求
110
+ */
111
+ put<T = any>(url: string, data?: any, options?: RequestOptions): Promise<T>;
112
+ /**
113
+ * DELETE 请求
114
+ */
115
+ delete<T = any>(url: string, options?: RequestOptions): Promise<T>;
116
+ /**
117
+ * 通用请求方法
118
+ */
119
+ request<T = any>(options: RequestOptions): Promise<T>;
120
+ /**
121
+ * 执行实际的请求
122
+ * 这里实现了一个基于 fetch API 的请求
123
+ */
124
+ private performRequest;
125
+ }
126
+ declare const _default: RequestPluginImpl;
127
+ export default _default;
@@ -0,0 +1,297 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/plugins/request.ts
20
+ var request_exports = {};
21
+ __export(request_exports, {
22
+ RequestError: () => RequestError,
23
+ default: () => request_default
24
+ });
25
+ module.exports = __toCommonJS(request_exports);
26
+ var RequestError = class extends Error {
27
+ constructor(message, config, request, response) {
28
+ super(message);
29
+ this.name = "RequestError";
30
+ this.config = config;
31
+ this.request = request;
32
+ this.response = response;
33
+ }
34
+ };
35
+ var RequestPluginImpl = class {
36
+ constructor() {
37
+ this.name = "request";
38
+ this.version = "1.0.0";
39
+ this.core = null;
40
+ /**
41
+ * 默认请求选项
42
+ */
43
+ this.defaultOptions = {
44
+ method: "GET",
45
+ headers: {
46
+ "Content-Type": "application/json"
47
+ },
48
+ timeout: 3e4,
49
+ responseType: "json"
50
+ };
51
+ /**
52
+ * 全局拦截器
53
+ */
54
+ this.interceptors = {
55
+ request: [],
56
+ response: [],
57
+ error: []
58
+ };
59
+ }
60
+ // 初始化方法
61
+ initialize() {
62
+ this.core = globalThis.pisellOS;
63
+ console.log("[RequestPlugin] 初始化完成");
64
+ }
65
+ // 销毁方法
66
+ destroy() {
67
+ console.log("[RequestPlugin] 已销毁");
68
+ }
69
+ /**
70
+ * 添加请求拦截器
71
+ */
72
+ addRequestInterceptor(interceptor) {
73
+ this.interceptors.request.push(interceptor);
74
+ }
75
+ /**
76
+ * 添加响应拦截器
77
+ */
78
+ addResponseInterceptor(interceptor) {
79
+ this.interceptors.response.push(interceptor);
80
+ }
81
+ /**
82
+ * 添加错误拦截器
83
+ */
84
+ addErrorInterceptor(interceptor) {
85
+ this.interceptors.error.push(interceptor);
86
+ }
87
+ /**
88
+ * GET 请求
89
+ */
90
+ get(url, options = {}) {
91
+ return this.request({
92
+ ...options,
93
+ url,
94
+ method: "GET"
95
+ });
96
+ }
97
+ /**
98
+ * POST 请求
99
+ */
100
+ post(url, data, options = {}) {
101
+ return this.request({
102
+ ...options,
103
+ url,
104
+ method: "POST",
105
+ data
106
+ });
107
+ }
108
+ /**
109
+ * PUT 请求
110
+ */
111
+ put(url, data, options = {}) {
112
+ return this.request({
113
+ ...options,
114
+ url,
115
+ method: "PUT",
116
+ data
117
+ });
118
+ }
119
+ /**
120
+ * DELETE 请求
121
+ */
122
+ delete(url, options = {}) {
123
+ return this.request({
124
+ ...options,
125
+ url,
126
+ method: "DELETE"
127
+ });
128
+ }
129
+ /**
130
+ * 通用请求方法
131
+ */
132
+ async request(options) {
133
+ let config = {
134
+ ...this.defaultOptions,
135
+ ...options,
136
+ headers: {
137
+ ...this.defaultOptions.headers,
138
+ ...options.headers
139
+ }
140
+ };
141
+ if (!config.headers["authorization"] && this.core) {
142
+ const windowPlugin = this.core.getPlugin("window");
143
+ if (windowPlugin) {
144
+ config.headers["authorization"] = windowPlugin.localStorage.getItem("token") || "";
145
+ }
146
+ }
147
+ for (const interceptor of this.interceptors.request) {
148
+ try {
149
+ config = await Promise.resolve(interceptor(config));
150
+ } catch (error) {
151
+ const requestError = error instanceof RequestError ? error : new RequestError(
152
+ error instanceof Error ? error.message : "请求拦截器错误",
153
+ config
154
+ );
155
+ let processedError = requestError;
156
+ for (const errorInterceptor of this.interceptors.error) {
157
+ try {
158
+ processedError = await Promise.resolve(errorInterceptor(processedError));
159
+ } catch (e) {
160
+ }
161
+ }
162
+ throw processedError;
163
+ }
164
+ }
165
+ try {
166
+ const response = await this.performRequest(config);
167
+ let processedResponse = response;
168
+ for (const interceptor of this.interceptors.response) {
169
+ try {
170
+ processedResponse = await Promise.resolve(interceptor(processedResponse));
171
+ } catch (error) {
172
+ const requestError = error instanceof RequestError ? error : new RequestError(
173
+ error instanceof Error ? error.message : "响应拦截器错误",
174
+ config,
175
+ null,
176
+ response
177
+ );
178
+ let processedError = requestError;
179
+ for (const errorInterceptor of this.interceptors.error) {
180
+ try {
181
+ processedError = await Promise.resolve(errorInterceptor(processedError));
182
+ } catch (e) {
183
+ }
184
+ }
185
+ throw processedError;
186
+ }
187
+ }
188
+ return processedResponse.data;
189
+ } catch (error) {
190
+ const requestError = error instanceof RequestError ? error : new RequestError(
191
+ error instanceof Error ? error.message : "请求错误",
192
+ config
193
+ );
194
+ let processedError = requestError;
195
+ for (const errorInterceptor of this.interceptors.error) {
196
+ try {
197
+ processedError = await Promise.resolve(errorInterceptor(processedError));
198
+ } catch (e) {
199
+ }
200
+ }
201
+ throw processedError;
202
+ }
203
+ }
204
+ /**
205
+ * 执行实际的请求
206
+ * 这里实现了一个基于 fetch API 的请求
207
+ */
208
+ async performRequest(config) {
209
+ const { url, method, headers, data, params, timeout, responseType, withCredentials } = config;
210
+ if (!url) {
211
+ throw new RequestError("URL不能为空", config);
212
+ }
213
+ let fullUrl = url;
214
+ if (params && Object.keys(params).length > 0) {
215
+ const queryString = Object.entries(params).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`).join("&");
216
+ fullUrl += (url.includes("?") ? "&" : "?") + queryString;
217
+ }
218
+ const fetchOptions = {
219
+ method,
220
+ headers: {
221
+ ...headers
222
+ },
223
+ credentials: withCredentials ? "include" : "same-origin"
224
+ };
225
+ if (data !== void 0 && method !== "GET" && method !== "HEAD") {
226
+ if (data instanceof FormData) {
227
+ fetchOptions.body = data;
228
+ delete fetchOptions.headers["Content-Type"];
229
+ } else if (typeof data === "object") {
230
+ fetchOptions.body = JSON.stringify(data);
231
+ } else {
232
+ fetchOptions.body = data;
233
+ }
234
+ }
235
+ let timeoutId;
236
+ const timeoutPromise = new Promise((_, reject) => {
237
+ if (timeout) {
238
+ timeoutId = setTimeout(() => {
239
+ reject(new RequestError(`请求超时: ${timeout}ms`, config));
240
+ }, timeout);
241
+ }
242
+ });
243
+ try {
244
+ const fetchPromise = typeof fetch !== "undefined" ? fetch(fullUrl, fetchOptions) : Promise.reject(new RequestError("当前环境不支持 fetch API", config));
245
+ const response = await Promise.race([fetchPromise, timeoutPromise]);
246
+ const responseHeaders = {};
247
+ response.headers.forEach((value, key) => {
248
+ responseHeaders[key] = value;
249
+ });
250
+ let responseData;
251
+ if (responseType === "json") {
252
+ try {
253
+ responseData = await response.json();
254
+ } catch (e) {
255
+ responseData = await response.text();
256
+ }
257
+ } else if (responseType === "text") {
258
+ responseData = await response.text();
259
+ } else if (responseType === "arraybuffer") {
260
+ responseData = await response.arrayBuffer();
261
+ } else if (responseType === "blob") {
262
+ responseData = await response.blob();
263
+ } else {
264
+ try {
265
+ responseData = await response.json();
266
+ } catch (e) {
267
+ responseData = await response.text();
268
+ }
269
+ }
270
+ const result = {
271
+ data: responseData,
272
+ status: response.status,
273
+ statusText: response.statusText,
274
+ headers: responseHeaders,
275
+ config
276
+ };
277
+ if (!response.ok) {
278
+ throw new RequestError(
279
+ `请求失败,状态码: ${response.status}`,
280
+ config,
281
+ fetchOptions,
282
+ result
283
+ );
284
+ }
285
+ return result;
286
+ } finally {
287
+ if (timeoutId) {
288
+ clearTimeout(timeoutId);
289
+ }
290
+ }
291
+ }
292
+ };
293
+ var request_default = new RequestPluginImpl();
294
+ // Annotate the CommonJS export names for ESM import in node:
295
+ 0 && (module.exports = {
296
+ RequestError
297
+ });
@@ -0,0 +1,115 @@
1
+ import { Plugin } from '../types';
2
+ /**
3
+ * WindowPlugin 接口定义
4
+ */
5
+ export interface WindowPlugin extends Plugin {
6
+ setTimeout: typeof setTimeout;
7
+ clearTimeout: typeof clearTimeout;
8
+ setInterval: typeof setInterval;
9
+ clearInterval: typeof clearInterval;
10
+ localStorage: Storage;
11
+ sessionStorage: Storage;
12
+ location: Partial<Location>;
13
+ navigator: Partial<Navigator>;
14
+ document: Partial<Document>;
15
+ history: History;
16
+ }
17
+ /**
18
+ * 简单的 Storage 接口实现
19
+ */
20
+ declare class SimpleStorage implements Storage {
21
+ private items;
22
+ get length(): number;
23
+ key(index: number): string | null;
24
+ getItem(key: string): string | null;
25
+ setItem(key: string, value: string): void;
26
+ removeItem(key: string): void;
27
+ clear(): void;
28
+ }
29
+ /**
30
+ * 简单的 Location 类实现
31
+ */
32
+ declare class SimpleLocation implements Partial<Location> {
33
+ hash: string;
34
+ host: string;
35
+ hostname: string;
36
+ href: string;
37
+ origin: string;
38
+ pathname: string;
39
+ port: string;
40
+ protocol: string;
41
+ search: string;
42
+ ancestorOrigins: DOMStringList;
43
+ assign(url: string | URL): void;
44
+ reload(): void;
45
+ replace(url: string | URL): void;
46
+ toString(): string;
47
+ }
48
+ /**
49
+ * 简单的 Navigator 类实现
50
+ */
51
+ declare class SimpleNavigator implements Partial<Navigator> {
52
+ userAgent: string;
53
+ language: string;
54
+ languages: string[];
55
+ onLine: boolean;
56
+ cookieEnabled: boolean;
57
+ readonly appCodeName: string;
58
+ readonly appName: string;
59
+ readonly appVersion: string;
60
+ readonly platform: string;
61
+ readonly product: string;
62
+ javaEnabled(): boolean;
63
+ }
64
+ /**
65
+ * 简单的 History 接口实现
66
+ */
67
+ declare class SimpleHistory implements History {
68
+ length: number;
69
+ scrollRestoration: ScrollRestoration;
70
+ state: any;
71
+ back(): void;
72
+ forward(): void;
73
+ go(): void;
74
+ pushState(): void;
75
+ replaceState(): void;
76
+ }
77
+ /**
78
+ * 简单的 Document 类实现
79
+ */
80
+ declare class SimpleDocument implements Partial<Document> {
81
+ private elements;
82
+ createElement(tagName: string): HTMLElement;
83
+ getElementById(id: string): HTMLElement | null;
84
+ readonly URL: string;
85
+ readonly documentURI: string;
86
+ readonly origin: string;
87
+ readonly characterSet: string;
88
+ readonly contentType: string;
89
+ readonly compatMode: string;
90
+ querySelector(): Element | null;
91
+ querySelectorAll(): NodeListOf<Element>;
92
+ getElementsByTagName(): HTMLCollectionOf<Element>;
93
+ getElementsByClassName(): HTMLCollectionOf<Element>;
94
+ }
95
+ /**
96
+ * Window 插件实现
97
+ */
98
+ declare class WindowPluginImpl implements WindowPlugin {
99
+ name: string;
100
+ version: string;
101
+ setTimeout: typeof setTimeout;
102
+ clearTimeout: typeof clearTimeout;
103
+ setInterval: typeof setInterval;
104
+ clearInterval: typeof clearInterval;
105
+ localStorage: SimpleStorage;
106
+ sessionStorage: SimpleStorage;
107
+ location: SimpleLocation;
108
+ navigator: SimpleNavigator;
109
+ document: SimpleDocument;
110
+ history: SimpleHistory;
111
+ initialize(): void;
112
+ destroy(): void;
113
+ }
114
+ declare const _default: WindowPluginImpl;
115
+ export default _default;