@etsoo/appscript 1.6.56 → 1.6.58

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.
@@ -25,7 +25,7 @@ await ExtendUtils.sleep(50);
25
25
  // Then change the culture to the first one (here is 'zh-CN')
26
26
  await app.changeCulture(app.settings.cultures[0]);
27
27
 
28
- await ExtendUtils.sleep(50);
28
+ await ExtendUtils.sleep(100);
29
29
 
30
30
  test("Test for domain substitution", () => {
31
31
  expect(app.settings.endpoint).toBe("http://admin.etsoo.com:9000/api/");
@@ -49,7 +49,7 @@ test("Test for formatApp", () => {
49
49
  ).toBe("https://localhost/api/");
50
50
 
51
51
  // Custom sub domain match
52
- ExternalSettings.subDomainMatch = /app(?=\.)/i;
52
+ ExternalSettings.updateSubDomainMatch(/app(?=\.)/i);
53
53
 
54
54
  expect(
55
55
  ExternalSettings.formatApp(
@@ -62,7 +62,7 @@ test("Test for formatApp", () => {
62
62
 
63
63
  test("Test for formatHost with endpoints", () => {
64
64
  // Reset sub domain match
65
- ExternalSettings.subDomainMatch = /(?<=\/\/)[0-9a-z]+(?=\.)/i;
65
+ ExternalSettings.updateSubDomainMatch(/(?<=\/\/)[0-9a-z]+(?=\.)/i);
66
66
 
67
67
  const endpoints: Record<string, ExternalEndpoint> = {
68
68
  core: {
@@ -567,7 +567,7 @@ class CoreApp {
567
567
  * @returns true means device is invalid
568
568
  */
569
569
  checkDeviceResult(result) {
570
- if (result.type === "DataProcessingFailed" ||
570
+ if ((result.type === "DataProcessingFailed" && result.field !== "Token") ||
571
571
  (result.type === "NoValidData" && result.field === "Device"))
572
572
  return true;
573
573
  return false;
@@ -37,10 +37,6 @@ export interface IExternalSettings extends ExternalEndpoint {
37
37
  * External settings namespace
38
38
  */
39
39
  export declare namespace ExternalSettings {
40
- /**
41
- * Sub domain match regular expression
42
- */
43
- let subDomainMatch: RegExp;
44
40
  /**
45
41
  * Create settings instance
46
42
  * @param settings Settings
@@ -63,4 +59,9 @@ export declare namespace ExternalSettings {
63
59
  */
64
60
  function formatHost(setting: string, hostname: string): string;
65
61
  function formatHost(setting: Record<string, ExternalEndpoint>, hostname?: string | null): Record<string, ExternalEndpoint>;
62
+ /**
63
+ * Update sub domain match regex
64
+ * @param regex New regex
65
+ */
66
+ function updateSubDomainMatch(regex: RegExp): void;
66
67
  }
@@ -9,7 +9,7 @@ var ExternalSettings;
9
9
  /**
10
10
  * Sub domain match regular expression
11
11
  */
12
- ExternalSettings.subDomainMatch = /(?<=\/\/)[0-9a-z]+(?=\.)/i;
12
+ let subDomainMatch = /(?<=\/\/)[0-9a-z]+(?=\.)/i;
13
13
  /**
14
14
  * Create settings instance
15
15
  * @param settings Settings
@@ -43,7 +43,7 @@ var ExternalSettings;
43
43
  * @returns Result
44
44
  */
45
45
  function formatApp(hostname, app, endpoint) {
46
- return formatHost(endpoint, hostname).replace(ExternalSettings.subDomainMatch, app);
46
+ return formatHost(endpoint, hostname).replace(subDomainMatch, app);
47
47
  }
48
48
  ExternalSettings.formatApp = formatApp;
49
49
  function formatHost(setting, hostname) {
@@ -63,4 +63,12 @@ var ExternalSettings;
63
63
  }
64
64
  }
65
65
  ExternalSettings.formatHost = formatHost;
66
+ /**
67
+ * Update sub domain match regex
68
+ * @param regex New regex
69
+ */
70
+ function updateSubDomainMatch(regex) {
71
+ subDomainMatch = regex;
72
+ }
73
+ ExternalSettings.updateSubDomainMatch = updateSubDomainMatch;
66
74
  })(ExternalSettings || (exports.ExternalSettings = ExternalSettings = {}));
@@ -59,7 +59,6 @@ export * from "./business/EntityStatus";
59
59
  export * from "./business/MapApiProvider";
60
60
  export * from "./business/ProductUnit";
61
61
  export * from "./business/RepeatOption";
62
- export * from "./business/ShoppingCart";
63
62
  export * from "./custom/CustomField";
64
63
  export * from "./custom/CustomFieldData";
65
64
  export * from "./def/CustomCulture";
package/lib/cjs/index.js CHANGED
@@ -81,7 +81,6 @@ __exportStar(require("./business/EntityStatus"), exports);
81
81
  __exportStar(require("./business/MapApiProvider"), exports);
82
82
  __exportStar(require("./business/ProductUnit"), exports);
83
83
  __exportStar(require("./business/RepeatOption"), exports);
84
- __exportStar(require("./business/ShoppingCart"), exports);
85
84
  // custom
86
85
  __exportStar(require("./custom/CustomField"), exports);
87
86
  __exportStar(require("./custom/CustomFieldData"), exports);
@@ -564,7 +564,7 @@ export class CoreApp {
564
564
  * @returns true means device is invalid
565
565
  */
566
566
  checkDeviceResult(result) {
567
- if (result.type === "DataProcessingFailed" ||
567
+ if ((result.type === "DataProcessingFailed" && result.field !== "Token") ||
568
568
  (result.type === "NoValidData" && result.field === "Device"))
569
569
  return true;
570
570
  return false;
@@ -37,10 +37,6 @@ export interface IExternalSettings extends ExternalEndpoint {
37
37
  * External settings namespace
38
38
  */
39
39
  export declare namespace ExternalSettings {
40
- /**
41
- * Sub domain match regular expression
42
- */
43
- let subDomainMatch: RegExp;
44
40
  /**
45
41
  * Create settings instance
46
42
  * @param settings Settings
@@ -63,4 +59,9 @@ export declare namespace ExternalSettings {
63
59
  */
64
60
  function formatHost(setting: string, hostname: string): string;
65
61
  function formatHost(setting: Record<string, ExternalEndpoint>, hostname?: string | null): Record<string, ExternalEndpoint>;
62
+ /**
63
+ * Update sub domain match regex
64
+ * @param regex New regex
65
+ */
66
+ function updateSubDomainMatch(regex: RegExp): void;
66
67
  }
@@ -6,7 +6,7 @@ export var ExternalSettings;
6
6
  /**
7
7
  * Sub domain match regular expression
8
8
  */
9
- ExternalSettings.subDomainMatch = /(?<=\/\/)[0-9a-z]+(?=\.)/i;
9
+ let subDomainMatch = /(?<=\/\/)[0-9a-z]+(?=\.)/i;
10
10
  /**
11
11
  * Create settings instance
12
12
  * @param settings Settings
@@ -40,7 +40,7 @@ export var ExternalSettings;
40
40
  * @returns Result
41
41
  */
42
42
  function formatApp(hostname, app, endpoint) {
43
- return formatHost(endpoint, hostname).replace(ExternalSettings.subDomainMatch, app);
43
+ return formatHost(endpoint, hostname).replace(subDomainMatch, app);
44
44
  }
45
45
  ExternalSettings.formatApp = formatApp;
46
46
  function formatHost(setting, hostname) {
@@ -60,4 +60,12 @@ export var ExternalSettings;
60
60
  }
61
61
  }
62
62
  ExternalSettings.formatHost = formatHost;
63
+ /**
64
+ * Update sub domain match regex
65
+ * @param regex New regex
66
+ */
67
+ function updateSubDomainMatch(regex) {
68
+ subDomainMatch = regex;
69
+ }
70
+ ExternalSettings.updateSubDomainMatch = updateSubDomainMatch;
63
71
  })(ExternalSettings || (ExternalSettings = {}));
@@ -59,7 +59,6 @@ export * from "./business/EntityStatus";
59
59
  export * from "./business/MapApiProvider";
60
60
  export * from "./business/ProductUnit";
61
61
  export * from "./business/RepeatOption";
62
- export * from "./business/ShoppingCart";
63
62
  export * from "./custom/CustomField";
64
63
  export * from "./custom/CustomFieldData";
65
64
  export * from "./def/CustomCulture";
package/lib/mjs/index.js CHANGED
@@ -64,7 +64,6 @@ export * from "./business/EntityStatus";
64
64
  export * from "./business/MapApiProvider";
65
65
  export * from "./business/ProductUnit";
66
66
  export * from "./business/RepeatOption";
67
- export * from "./business/ShoppingCart";
68
67
  // custom
69
68
  export * from "./custom/CustomField";
70
69
  export * from "./custom/CustomFieldData";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.6.56",
3
+ "version": "1.6.58",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "homepage": "https://github.com/ETSOO/AppScript#readme",
37
37
  "dependencies": {
38
- "@etsoo/notificationbase": "^1.1.66",
38
+ "@etsoo/notificationbase": "^1.1.67",
39
39
  "@etsoo/restclient": "^1.1.33",
40
40
  "@etsoo/shared": "^1.2.80",
41
41
  "crypto-js": "^4.2.0"
@@ -44,12 +44,12 @@
44
44
  "@babel/cli": "^7.28.6",
45
45
  "@babel/core": "^7.29.0",
46
46
  "@babel/plugin-transform-runtime": "^7.29.0",
47
- "@babel/preset-env": "^7.29.0",
48
- "@babel/runtime-corejs3": "^7.29.0",
47
+ "@babel/preset-env": "^7.29.2",
48
+ "@babel/runtime-corejs3": "^7.29.2",
49
49
  "@types/crypto-js": "^4.2.2",
50
- "@vitejs/plugin-react": "^5.1.4",
51
- "jsdom": "^28.1.0",
50
+ "@vitejs/plugin-react": "^6.0.1",
51
+ "jsdom": "^29.0.1",
52
52
  "typescript": "^5.9.3",
53
- "vitest": "^4.0.18"
53
+ "vitest": "^4.1.0"
54
54
  }
55
55
  }
@@ -100,8 +100,7 @@ export abstract class CoreApp<
100
100
  S extends IAppSettings,
101
101
  N,
102
102
  C extends NotificationCallProps
103
- > implements ICoreApp<U, S, N, C>
104
- {
103
+ > implements ICoreApp<U, S, N, C> {
105
104
  /**
106
105
  * Settings
107
106
  */
@@ -504,8 +503,8 @@ export abstract class CoreApp<
504
503
  (endSlash
505
504
  ? Utils.trimStart(url, "/")
506
505
  : url.startsWith("/")
507
- ? url
508
- : "/" + url)
506
+ ? url
507
+ : "/" + url)
509
508
  );
510
509
  }
511
510
 
@@ -884,7 +883,7 @@ export abstract class CoreApp<
884
883
  */
885
884
  checkDeviceResult(result: IActionResult): boolean {
886
885
  if (
887
- result.type === "DataProcessingFailed" ||
886
+ (result.type === "DataProcessingFailed" && result.field !== "Token") ||
888
887
  (result.type === "NoValidData" && result.field === "Device")
889
888
  )
890
889
  return true;
@@ -49,7 +49,7 @@ export namespace ExternalSettings {
49
49
  /**
50
50
  * Sub domain match regular expression
51
51
  */
52
- export let subDomainMatch: RegExp = /(?<=\/\/)[0-9a-z]+(?=\.)/i;
52
+ let subDomainMatch: RegExp = /(?<=\/\/)[0-9a-z]+(?=\.)/i;
53
53
 
54
54
  /**
55
55
  * Create settings instance
@@ -128,4 +128,12 @@ export namespace ExternalSettings {
128
128
  );
129
129
  }
130
130
  }
131
+
132
+ /**
133
+ * Update sub domain match regex
134
+ * @param regex New regex
135
+ */
136
+ export function updateSubDomainMatch(regex: RegExp) {
137
+ subDomainMatch = regex;
138
+ }
131
139
  }
package/src/index.ts CHANGED
@@ -70,7 +70,6 @@ export * from "./business/EntityStatus";
70
70
  export * from "./business/MapApiProvider";
71
71
  export * from "./business/ProductUnit";
72
72
  export * from "./business/RepeatOption";
73
- export * from "./business/ShoppingCart";
74
73
 
75
74
  // custom
76
75
  export * from "./custom/CustomField";
@@ -1,368 +0,0 @@
1
- import { DataTypes, IStorage, IdType } from "@etsoo/shared";
2
- import { Currency } from "./Currency";
3
- /**
4
- * Shopping cart owner
5
- * 购物篮所有人
6
- */
7
- export type ShoppingCartOwner = DataTypes.IdNameItem & {
8
- culture?: string;
9
- currency?: Currency;
10
- };
11
- /**
12
- * Shopping cart data
13
- * 购物篮数据
14
- */
15
- export type ShoppingCartData<T extends ShoppingCartItem> = {
16
- culture: string;
17
- currency: Currency;
18
- owner: ShoppingCartOwner;
19
- items: T[];
20
- promotions: ShoppingPromotion[];
21
- formData?: any;
22
- cache?: Record<string, unknown>;
23
- };
24
- /**
25
- * Shopping promotion
26
- * 购物促销
27
- */
28
- export type ShoppingPromotion = {
29
- /**
30
- * Promotion id
31
- * 促销编号
32
- */
33
- id: number;
34
- /**
35
- * Promotion title
36
- * 促销标题
37
- */
38
- title: string;
39
- /**
40
- * Discount amount
41
- * 折扣金额
42
- */
43
- amount: number;
44
- };
45
- /**
46
- * Shopping cart base item
47
- * 购物篮基础项目
48
- */
49
- export type ShoppingCartItemBase = {
50
- /**
51
- * Product id
52
- * 产品编号
53
- */
54
- id: IdType;
55
- /**
56
- * Product title, default is name
57
- * 产品标题,默认为name
58
- */
59
- title?: string;
60
- /**
61
- * Sale price
62
- * 销售价格
63
- */
64
- price: number;
65
- /**
66
- * Qty
67
- * 数量
68
- */
69
- qty: number;
70
- /**
71
- * Asset qty
72
- */
73
- assetQty?: number;
74
- /**
75
- * Product level promotions
76
- * 产品层次促销
77
- */
78
- promotions: ShoppingPromotion[];
79
- };
80
- /**
81
- * Shopping cart item
82
- * 购物篮项目
83
- */
84
- export type ShoppingCartItem = ShoppingCartItemBase & {
85
- /**
86
- * Product name
87
- * 产品名称
88
- */
89
- name: string;
90
- /**
91
- * Current price for cache
92
- * 当前缓存价格
93
- */
94
- currentPrice?: number;
95
- /**
96
- * Subtotal
97
- * 小计
98
- */
99
- subtotal: number;
100
- /**
101
- * Total discount amount
102
- * 总折扣金额
103
- */
104
- discount: number;
105
- };
106
- /**
107
- * Shopping cart change reason
108
- * 购物篮改变原因
109
- */
110
- export type ShoppingCartChangeReason = "add" | "clear" | "remove" | "title" | "update";
111
- /**
112
- * Shopping cart
113
- * 购物篮
114
- */
115
- export declare class ShoppingCart<T extends ShoppingCartItem> {
116
- private readonly storage;
117
- /**
118
- * Create identifier key
119
- * 创建识别键
120
- * @param currency Currency
121
- * @param culture Culture
122
- * @param key Additional key
123
- * @returns Result
124
- */
125
- static createKey(currency: Currency, culture: string, key: string): string;
126
- /**
127
- * Clear shopping cart
128
- * 清除购物篮
129
- * @param identifier Identifier
130
- * @param storage Storage
131
- */
132
- static clear(identifier: string, storage: IStorage): void;
133
- /**
134
- * Get cart data
135
- * 获取购物篮数据
136
- * @param storage Storage
137
- * @param id Cart id
138
- * @returns Result
139
- */
140
- static getCartData<D extends ShoppingCartItem>(storage: IStorage, id: string): ShoppingCartData<D> | undefined;
141
- /**
142
- * Owner data
143
- * 所有者信息
144
- */
145
- owner?: ShoppingCartOwner;
146
- _currency: Currency;
147
- /**
148
- * ISO currency id
149
- * 标准货币编号
150
- */
151
- get currency(): Currency;
152
- private set currency(value);
153
- _culture: string;
154
- /**
155
- * ISO culture id, like zh-Hans
156
- * 标准语言文化编号
157
- */
158
- get culture(): string;
159
- private set culture(value);
160
- _items: T[];
161
- /**
162
- * Items
163
- * 项目
164
- */
165
- get items(): T[];
166
- private set items(value);
167
- _promotions: ShoppingPromotion[];
168
- /**
169
- * Order level promotions
170
- * 订单层面促销
171
- */
172
- get promotions(): ShoppingPromotion[];
173
- private set promotions(value);
174
- /**
175
- * Related form data
176
- * 关联的表单数据
177
- */
178
- formData: any;
179
- /**
180
- * Cache
181
- * 缓存对象
182
- */
183
- cache?: Record<string, unknown>;
184
- _symbol: string | undefined;
185
- /**
186
- * Currency symbol
187
- * 币种符号
188
- */
189
- get symbol(): string | undefined;
190
- private set symbol(value);
191
- /**
192
- * Key for identifier
193
- */
194
- readonly key: string;
195
- /**
196
- * Cart identifier
197
- * 购物篮标识
198
- */
199
- get identifier(): string;
200
- /**
201
- * All data keys
202
- * 所有的数据键
203
- */
204
- get keys(): string[];
205
- set keys(items: string[]);
206
- /**
207
- * Lines count
208
- * 项目数量
209
- */
210
- get lines(): number;
211
- /**
212
- * Total qty
213
- * 总数量
214
- */
215
- get totalQty(): number;
216
- /**
217
- * Total amount
218
- * 总金额
219
- */
220
- get totalAmount(): number;
221
- /**
222
- * Total amount string
223
- * 总金额字符串
224
- */
225
- get totalAmountStr(): string;
226
- /**
227
- * Cached prices
228
- * 缓存的价格
229
- */
230
- private prices;
231
- /**
232
- * Onchange callback
233
- * 改变时回调
234
- */
235
- onChange?: (reason: ShoppingCartChangeReason, changedItems: T[]) => void;
236
- /**
237
- * Constructor
238
- * 构造函数
239
- * @param key Key for identifier
240
- * @param init Currency & culture ISO code array
241
- * @param storage Data storage
242
- */
243
- constructor(key: string, init: [Currency, string], storage?: IStorage);
244
- /**
245
- * Constructor
246
- * 构造函数
247
- * @param key Key for identifier
248
- * @param state Initialization state
249
- * @param storage Data storage
250
- */
251
- constructor(key: string, state: ShoppingCartData<T>, storage?: IStorage);
252
- private getCartData;
253
- private setCartData;
254
- private doChange;
255
- /**
256
- * Add item
257
- * 添加项目
258
- * @param item New item
259
- */
260
- addItem(item: T): void;
261
- /**
262
- * Add items
263
- * @param items New items
264
- */
265
- addItems(items: T[]): void;
266
- /**
267
- * Cache price
268
- * @param id Item id
269
- * @param price Price
270
- * @param overrideExisting Override existing price
271
- */
272
- cachePrice(id: T["id"], price: number, overrideExisting?: boolean): void;
273
- /**
274
- * Change currency
275
- * @param currency Currency
276
- */
277
- changeCurrency(currency: Currency): void;
278
- /**
279
- * Change culture
280
- * @param culture Culture
281
- */
282
- changeCulture(culture: string): void;
283
- /**
284
- * Clear storage
285
- * @param keepOwner Keep owner data
286
- */
287
- clear(keepOwner?: boolean): void;
288
- /**
289
- * Format amount
290
- * @param amount Amount
291
- * @returns Result
292
- */
293
- formatAmount(amount: number): string;
294
- /**
295
- * Get item
296
- * @param id Item id
297
- * @returns Result
298
- */
299
- getItem(id: T["id"]): T | undefined;
300
- /**
301
- * Push item
302
- * 推送项目
303
- * @param data Item data
304
- * @returns Added or not
305
- */
306
- pushItem(data: T): boolean;
307
- /**
308
- * Reset currency and culture
309
- * @param currency New currency
310
- * @param culture New culture
311
- */
312
- reset(currency: Currency, culture: string): void;
313
- /**
314
- * Remove item from the index
315
- * @param index Item index
316
- */
317
- removeItem(index: number): void;
318
- /**
319
- * Reset item
320
- * @param item Shopping cart item
321
- */
322
- resetItem(item: ShoppingCartItem): void;
323
- /**
324
- * Save cart data
325
- * @param persisted For persisted storage
326
- */
327
- save(persisted?: boolean): ShoppingCartData<T> | undefined;
328
- /**
329
- * Trigger update
330
- * 触发更新
331
- */
332
- update(): void;
333
- /**
334
- * Update discount
335
- * @param item Shopping cart item
336
- */
337
- updateDiscount(item: ShoppingCartItem): void;
338
- /**
339
- * Update asset item
340
- * 更新资产项目
341
- * @param id Product id
342
- * @param qty Asset qty
343
- * @param itemCreator New item creator
344
- * @returns Updated or not
345
- */
346
- updateAssetItem(id: T["id"], assetQty: number | undefined, itemCreator?: () => Omit<T, "id" | "price" | "assetQty" | "subtotal" | "discount" | "promotions">): boolean;
347
- /**
348
- * Update item
349
- * 更新项目
350
- * @param id Product id
351
- * @param qty Qty
352
- * @param itemCreator New item creator
353
- * @returns Updated or not
354
- */
355
- updateItem(id: T["id"], qty: number | undefined, itemCreator?: () => Omit<T, "id" | "price" | "qty" | "subtotal" | "discount" | "promotions">): boolean;
356
- /**
357
- * Update price
358
- * @param id Item id
359
- * @param price New price
360
- */
361
- updatePrice(id: T["id"], price: number): void;
362
- /**
363
- * Update title
364
- * @param id Item id
365
- * @param title New title
366
- */
367
- updateTitle(id: T["id"], title: string): void;
368
- }