@etsoo/appscript 1.3.2 → 1.3.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.
Files changed (94) hide show
  1. package/README.md +0 -1
  2. package/__tests__/app/CoreApp.ts +54 -16
  3. package/lib/cjs/address/AddressContinent.d.ts +5 -1
  4. package/lib/cjs/address/AddressContinent.js +1 -1
  5. package/lib/cjs/address/AddressRegion.d.ts +31 -15
  6. package/lib/cjs/address/AddressRegion.js +3 -2
  7. package/lib/cjs/address/AddressState.d.ts +17 -0
  8. package/lib/cjs/address/AddressState.js +2 -0
  9. package/lib/cjs/address/AddressUtils.d.ts +1 -17
  10. package/lib/cjs/address/AddressUtils.js +4 -35
  11. package/lib/cjs/app/CoreApp.d.ts +8 -22
  12. package/lib/cjs/app/CoreApp.js +16 -46
  13. package/lib/cjs/app/ExternalSettings.d.ts +1 -0
  14. package/lib/cjs/app/ExternalSettings.js +16 -10
  15. package/lib/cjs/app/IApp.d.ts +11 -21
  16. package/lib/cjs/business/BusinessUtils.d.ts +1 -43
  17. package/lib/cjs/business/BusinessUtils.js +0 -72
  18. package/lib/cjs/business/Currency.d.ts +8 -0
  19. package/lib/cjs/business/Currency.js +18 -0
  20. package/lib/cjs/erp/AddressApi.d.ts +38 -0
  21. package/lib/cjs/erp/AddressApi.js +102 -0
  22. package/lib/cjs/erp/BaseApi.d.ts +12 -0
  23. package/lib/cjs/erp/BaseApi.js +16 -0
  24. package/lib/cjs/erp/OrgApi.d.ts +20 -0
  25. package/lib/cjs/erp/OrgApi.js +37 -0
  26. package/lib/cjs/erp/PublicApi.d.ts +75 -0
  27. package/lib/cjs/erp/PublicApi.js +118 -0
  28. package/lib/cjs/erp/dto/CurrencyDto.d.ts +6 -0
  29. package/lib/cjs/erp/dto/CurrencyDto.js +2 -0
  30. package/lib/cjs/erp/dto/ExchangeRateDto.d.ts +13 -0
  31. package/lib/cjs/erp/dto/ExchangeRateDto.js +2 -0
  32. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
  33. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.js +2 -0
  34. package/lib/cjs/erp/dto/PublicProductDto.d.ts +35 -0
  35. package/lib/cjs/erp/dto/PublicProductDto.js +2 -0
  36. package/lib/cjs/index.d.ts +6 -0
  37. package/lib/cjs/index.js +7 -0
  38. package/lib/mjs/address/AddressContinent.d.ts +5 -1
  39. package/lib/mjs/address/AddressContinent.js +1 -1
  40. package/lib/mjs/address/AddressRegion.d.ts +31 -15
  41. package/lib/mjs/address/AddressRegion.js +3 -2
  42. package/lib/mjs/address/AddressState.d.ts +17 -0
  43. package/lib/mjs/address/AddressState.js +1 -0
  44. package/lib/mjs/address/AddressUtils.d.ts +1 -17
  45. package/lib/mjs/address/AddressUtils.js +1 -32
  46. package/lib/mjs/app/CoreApp.d.ts +8 -22
  47. package/lib/mjs/app/CoreApp.js +16 -46
  48. package/lib/mjs/app/ExternalSettings.d.ts +1 -0
  49. package/lib/mjs/app/ExternalSettings.js +16 -10
  50. package/lib/mjs/app/IApp.d.ts +11 -21
  51. package/lib/mjs/business/BusinessUtils.d.ts +1 -43
  52. package/lib/mjs/business/BusinessUtils.js +0 -72
  53. package/lib/mjs/business/Currency.d.ts +8 -0
  54. package/lib/mjs/business/Currency.js +15 -0
  55. package/lib/mjs/erp/AddressApi.d.ts +38 -0
  56. package/lib/mjs/erp/AddressApi.js +75 -0
  57. package/lib/mjs/erp/BaseApi.d.ts +12 -0
  58. package/lib/mjs/erp/BaseApi.js +12 -0
  59. package/lib/mjs/erp/OrgApi.d.ts +20 -0
  60. package/lib/mjs/erp/OrgApi.js +33 -0
  61. package/lib/mjs/erp/PublicApi.d.ts +75 -0
  62. package/lib/mjs/erp/PublicApi.js +114 -0
  63. package/lib/mjs/erp/dto/CurrencyDto.d.ts +6 -0
  64. package/lib/mjs/erp/dto/CurrencyDto.js +1 -0
  65. package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +13 -0
  66. package/lib/mjs/erp/dto/ExchangeRateDto.js +1 -0
  67. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +8 -0
  68. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.js +1 -0
  69. package/lib/mjs/erp/dto/PublicProductDto.d.ts +35 -0
  70. package/lib/mjs/erp/dto/PublicProductDto.js +1 -0
  71. package/lib/mjs/index.d.ts +6 -0
  72. package/lib/mjs/index.js +7 -0
  73. package/package.json +2 -2
  74. package/src/address/AddressContinent.ts +6 -1
  75. package/src/address/AddressRegion.ts +36 -16
  76. package/src/address/AddressState.ts +19 -0
  77. package/src/address/AddressUtils.ts +1 -35
  78. package/src/app/CoreApp.ts +22 -57
  79. package/src/app/ExternalSettings.ts +17 -13
  80. package/src/app/IApp.ts +12 -25
  81. package/src/business/BusinessUtils.ts +1 -105
  82. package/src/business/Currency.ts +20 -0
  83. package/src/erp/AddressApi.ts +97 -0
  84. package/src/erp/BaseApi.ts +12 -0
  85. package/src/erp/OrgApi.ts +39 -0
  86. package/src/erp/PublicApi.ts +156 -0
  87. package/src/erp/dto/CurrencyDto.ts +7 -0
  88. package/src/erp/dto/ExchangeRateDto.ts +14 -0
  89. package/src/erp/dto/ExchangeRateHistoryDto.ts +9 -0
  90. package/src/erp/dto/PublicProductDto.ts +41 -0
  91. package/src/i18n/address.en-US.json +21 -0
  92. package/src/i18n/address.zh-CN.json +21 -0
  93. package/src/i18n/address.zh-HK.json +21 -0
  94. package/src/index.ts +8 -0
@@ -1,6 +1,4 @@
1
- import { DataTypes, ListType, ListType1 } from '@etsoo/shared';
2
- import { ICultureGet } from '../state/Culture';
3
- import { ProductUnit } from './ProductUnit';
1
+ import { DataTypes, ListType } from '@etsoo/shared';
4
2
  /**
5
3
  * Business utils
6
4
  */
@@ -13,13 +11,6 @@ export declare namespace BusinessUtils {
13
11
  * @returns Result
14
12
  */
15
13
  function formatAvatarTitle(title?: string, maxChars?: number, defaultTitle?: string): string;
16
- /**
17
- * Get currency collection
18
- * @param currencyNames Names like CNY, USD
19
- * @param func Label delegate
20
- * @returns Collection
21
- */
22
- function getCurrencies(currencyNames: string[], func: ICultureGet): ListType1[];
23
14
  /**
24
15
  * Get 12-month items
25
16
  * @param monthLabels Month labels
@@ -27,39 +18,6 @@ export declare namespace BusinessUtils {
27
18
  * @returns 12 months
28
19
  */
29
20
  function getMonths(monthLabels: string[], startMonth?: number): ListType[];
30
- /**
31
- * Get product unit's label
32
- * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
33
- * @param unit Unit
34
- * @param func Label delegate
35
- * @param isJoined Add the join label like 'per Kg' for Kg
36
- * @returns Label
37
- */
38
- function getUnitLabel(unit: ProductUnit, func: ICultureGet, isJoined?: boolean): string;
39
- /**
40
- * Get all product units
41
- * @param func Label delegate
42
- * @returns Units
43
- */
44
- function getUnits(func: ICultureGet): ListType[];
45
- /**
46
- *
47
- * Get all product units
48
- * @param func Label delegate
49
- * @param options Define the order and limit the items
50
- * @param isJoined Add the join label like 'per Kg' for Kg
51
- * @returns Units
52
- */
53
- function getUnits(func: ICultureGet, options?: string[], isJoined?: boolean): ListType[];
54
- /**
55
- *
56
- * Get all repeat options
57
- * @param func Label delegate
58
- * @param options Define the order and limit the items
59
- * @param isJoined Add the join label like 'per Kg' for Kg
60
- * @returns Units
61
- */
62
- function getRepeatOptions(func: ICultureGet, options?: string[], isJoined?: boolean): ListType[];
63
21
  /**
64
22
  * Set id value
65
23
  * @param item QueryRQ or TiplistRQ or similiar item
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BusinessUtils = void 0;
4
- const shared_1 = require("@etsoo/shared");
5
- const ProductUnit_1 = require("./ProductUnit");
6
- const RepeatOption_1 = require("./RepeatOption");
7
4
  /**
8
5
  * Business utils
9
6
  */
@@ -41,22 +38,6 @@ var BusinessUtils;
41
38
  return defaultTitle;
42
39
  }
43
40
  BusinessUtils.formatAvatarTitle = formatAvatarTitle;
44
- /**
45
- * Get currency collection
46
- * @param currencyNames Names like CNY, USD
47
- * @param func Label delegate
48
- * @returns Collection
49
- */
50
- function getCurrencies(currencyNames, func) {
51
- return currencyNames.map((name) => {
52
- var _a;
53
- return ({
54
- id: name,
55
- label: (_a = func(`currency${name}`)) !== null && _a !== void 0 ? _a : name
56
- });
57
- });
58
- }
59
- BusinessUtils.getCurrencies = getCurrencies;
60
41
  /**
61
42
  * Get 12-month items
62
43
  * @param monthLabels Month labels
@@ -74,59 +55,6 @@ var BusinessUtils;
74
55
  return months;
75
56
  }
76
57
  BusinessUtils.getMonths = getMonths;
77
- /**
78
- * Get product unit's label
79
- * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
80
- * @param unit Unit
81
- * @param func Label delegate
82
- * @param isJoined Add the join label like 'per Kg' for Kg
83
- * @returns Label
84
- */
85
- function getUnitLabel(unit, func, isJoined) {
86
- var _a;
87
- const key = ProductUnit_1.ProductUnit[unit];
88
- const label = (_a = func('unit' + key)) !== null && _a !== void 0 ? _a : key;
89
- if (isJoined) {
90
- const jLabel = func('unitJoin');
91
- if (jLabel)
92
- return jLabel.format(label);
93
- }
94
- return label;
95
- }
96
- BusinessUtils.getUnitLabel = getUnitLabel;
97
- /**
98
- *
99
- * Get all product units
100
- * @param func Label delegate
101
- * @param options Define the order and limit the items
102
- * @param isJoined Add the join label like 'per Kg' for Kg
103
- * @returns Units
104
- */
105
- function getUnits(func, options, isJoined) {
106
- options !== null && options !== void 0 ? options : (options = shared_1.DataTypes.getEnumKeys(ProductUnit_1.ProductUnit));
107
- return options.map((key) => {
108
- const id = shared_1.DataTypes.getEnumByKey(ProductUnit_1.ProductUnit, key);
109
- return {
110
- id,
111
- label: getUnitLabel(id, func, isJoined).formatInitial(true)
112
- };
113
- });
114
- }
115
- BusinessUtils.getUnits = getUnits;
116
- /**
117
- *
118
- * Get all repeat options
119
- * @param func Label delegate
120
- * @param options Define the order and limit the items
121
- * @param isJoined Add the join label like 'per Kg' for Kg
122
- * @returns Units
123
- */
124
- function getRepeatOptions(func, options, isJoined = true) {
125
- options !== null && options !== void 0 ? options : (options = shared_1.DataTypes.getEnumKeys(RepeatOption_1.RepeatOption));
126
- isJoined !== null && isJoined !== void 0 ? isJoined : (isJoined = true);
127
- return getUnits(func, options, isJoined);
128
- }
129
- BusinessUtils.getRepeatOptions = getRepeatOptions;
130
58
  /**
131
59
  * Set id value
132
60
  * @param item QueryRQ or TiplistRQ or similiar item
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Currency array
3
+ */
4
+ export declare const Currencies: readonly ["AUD", "CAD", "CNY", "EUR", "GBP", "HKD", "JPY", "NZD", "SGD", "USD"];
5
+ /**
6
+ * Currency type
7
+ */
8
+ export declare type Currency = typeof Currencies[number];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Currencies = void 0;
4
+ /**
5
+ * Currency array
6
+ */
7
+ exports.Currencies = [
8
+ 'AUD',
9
+ 'CAD',
10
+ 'CNY',
11
+ 'EUR',
12
+ 'GBP',
13
+ 'HKD',
14
+ 'JPY',
15
+ 'NZD',
16
+ 'SGD',
17
+ 'USD'
18
+ ];
@@ -0,0 +1,38 @@
1
+ import { DataTypes } from '@etsoo/shared';
2
+ import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
3
+ import { AddressState } from '../address/AddressState';
4
+ import { IdLabelConditional } from '../dto/IdLabelDto';
5
+ import { BaseApi } from './BaseApi';
6
+ /**
7
+ * Address Api
8
+ */
9
+ export declare class AddressApi extends BaseApi {
10
+ private languageLabels;
11
+ /**
12
+ * Get address labels
13
+ * @param language Language
14
+ * @returns Result
15
+ */
16
+ getLabels(language?: string): Promise<DataTypes.StringRecord>;
17
+ /**
18
+ * Get all continents
19
+ * @param language Language
20
+ * @param isNumberKey Is number key or key as id
21
+ * @returns Continents
22
+ */
23
+ continents<T extends boolean>(language?: string, isNumberKey?: T): Promise<IdLabelConditional<T>>;
24
+ /**
25
+ * Get region list from database
26
+ * @param language Language
27
+ * @param isLocal Is local version
28
+ * @returns Result
29
+ */
30
+ regions<T extends boolean = true>(language?: string, isLocal?: T): Promise<T extends true | undefined ? AddressRegion[] : AddressRegionDb[] | undefined>;
31
+ /**
32
+ * Get state list from database
33
+ * @param regionId Region id
34
+ * @param language Language
35
+ * @returns Result
36
+ */
37
+ states(regionId: string, language?: string): Promise<AddressState[] | undefined>;
38
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AddressApi = void 0;
27
+ const shared_1 = require("@etsoo/shared");
28
+ const AddressContinent_1 = require("../address/AddressContinent");
29
+ const AddressRegion_1 = require("../address/AddressRegion");
30
+ const BaseApi_1 = require("./BaseApi");
31
+ /**
32
+ * Address Api
33
+ */
34
+ class AddressApi extends BaseApi_1.BaseApi {
35
+ constructor() {
36
+ super(...arguments);
37
+ this.languageLabels = {};
38
+ }
39
+ /**
40
+ * Get address labels
41
+ * @param language Language
42
+ * @returns Result
43
+ */
44
+ async getLabels(language) {
45
+ const l = this.app.checkLanguage(language);
46
+ let labels = this.languageLabels[l];
47
+ if (labels == null) {
48
+ labels = await Promise.resolve().then(() => __importStar(require(`./../i18n/address.${l}.json`)));
49
+ // Cache
50
+ this.languageLabels[l] = labels;
51
+ }
52
+ return labels;
53
+ }
54
+ /**
55
+ * Get all continents
56
+ * @param language Language
57
+ * @param isNumberKey Is number key or key as id
58
+ * @returns Continents
59
+ */
60
+ async continents(language, isNumberKey = false) {
61
+ const labels = await this.getLabels(language);
62
+ return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => {
63
+ var _a;
64
+ return ({
65
+ id: isNumberKey
66
+ ? shared_1.DataTypes.getEnumByKey(AddressContinent_1.AddressContinent, key)
67
+ : key.toString(),
68
+ label: (_a = labels['continent' + key]) !== null && _a !== void 0 ? _a : key
69
+ });
70
+ });
71
+ }
72
+ /**
73
+ * Get region list from database
74
+ * @param language Language
75
+ * @param isLocal Is local version
76
+ * @returns Result
77
+ */
78
+ async regions(language, isLocal) {
79
+ language = this.app.checkLanguage(language);
80
+ if (isLocal == null || isLocal) {
81
+ const labels = await this.getLabels(language);
82
+ return AddressRegion_1.AddressRegion.all.map((region) => {
83
+ region.label = labels['region' + region.id];
84
+ return { ...region };
85
+ });
86
+ }
87
+ else {
88
+ return (await this.app.api.get(`Address/RegionList?language=${language}`, undefined, { defaultValue: [] }));
89
+ }
90
+ }
91
+ /**
92
+ * Get state list from database
93
+ * @param regionId Region id
94
+ * @param language Language
95
+ * @returns Result
96
+ */
97
+ states(regionId, language) {
98
+ language = this.app.checkLanguage(language);
99
+ return this.app.api.get(`Address/StateList?regionId=${regionId}&language=${language}`, undefined, { defaultValue: [] });
100
+ }
101
+ }
102
+ exports.AddressApi = AddressApi;
@@ -0,0 +1,12 @@
1
+ import { IApp } from '../app/IApp';
2
+ /**
3
+ * SmartERP base API
4
+ */
5
+ export declare class BaseApi {
6
+ protected app: IApp;
7
+ /**
8
+ * Constructor
9
+ * @param app Application
10
+ */
11
+ constructor(app: IApp);
12
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseApi = void 0;
4
+ /**
5
+ * SmartERP base API
6
+ */
7
+ class BaseApi {
8
+ /**
9
+ * Constructor
10
+ * @param app Application
11
+ */
12
+ constructor(app) {
13
+ this.app = app;
14
+ }
15
+ }
16
+ exports.BaseApi = BaseApi;
@@ -0,0 +1,20 @@
1
+ import { ListType } from '@etsoo/shared';
2
+ import { BaseApi } from './BaseApi';
3
+ /**
4
+ * Organization API
5
+ */
6
+ export declare class OrgApi extends BaseApi {
7
+ /**
8
+ * Get organization list
9
+ * @param items Max items
10
+ * @param serviceId Service id
11
+ * @returns Result
12
+ */
13
+ list(items?: number, serviceId?: number): Promise<ListType[] | undefined>;
14
+ /**
15
+ * Switch organization
16
+ * @param id Organization id
17
+ * @param serviceId Service id
18
+ */
19
+ switch(id: number, serviceId?: number): Promise<boolean | undefined>;
20
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrgApi = void 0;
4
+ const BaseApi_1 = require("./BaseApi");
5
+ /**
6
+ * Organization API
7
+ */
8
+ class OrgApi extends BaseApi_1.BaseApi {
9
+ /**
10
+ * Get organization list
11
+ * @param items Max items
12
+ * @param serviceId Service id
13
+ * @returns Result
14
+ */
15
+ list(items, serviceId) {
16
+ return this.app.api.post('Organization/List', {
17
+ items,
18
+ serviceId
19
+ }, { defaultValue: [], showLoading: false });
20
+ }
21
+ /**
22
+ * Switch organization
23
+ * @param id Organization id
24
+ * @param serviceId Service id
25
+ */
26
+ async switch(id, serviceId) {
27
+ const result = await this.app.api.put('Organization/Switch', {
28
+ id,
29
+ serviceId,
30
+ deviceId: this.app.deviceId
31
+ });
32
+ if (result)
33
+ return await this.app.refreshToken();
34
+ return result;
35
+ }
36
+ }
37
+ exports.OrgApi = OrgApi;
@@ -0,0 +1,75 @@
1
+ import { ListType, ListType1 } from '@etsoo/shared';
2
+ import { Currency } from '../business/Currency';
3
+ import { ProductUnit } from '../business/ProductUnit';
4
+ import { BaseApi } from './BaseApi';
5
+ import { CurrencyDto } from './dto/CurrencyDto';
6
+ import { ExchangeRateDto } from './dto/ExchangeRateDto';
7
+ import { ExchangeRateHistoryDto } from './dto/ExchangeRateHistoryDto';
8
+ import { PublicOrgProductDto, PublicProductDto } from './dto/PublicProductDto';
9
+ /**
10
+ * Public API
11
+ */
12
+ export declare class PublicApi extends BaseApi {
13
+ /**
14
+ * Get currencies
15
+ * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
16
+ * @returns Result
17
+ */
18
+ currencies<T extends string[] | Currency[] | undefined>(currencyNames?: T): Promise<T extends undefined ? CurrencyDto[] | undefined : ListType1[]>;
19
+ /**
20
+ * Get exchange rate
21
+ * @param currency Currency
22
+ * @returns Result
23
+ */
24
+ exchangeRate(currency: Currency): Promise<ExchangeRateDto | undefined>;
25
+ /**
26
+ * Get exchange rate history
27
+ * @param currencies Currencies
28
+ * @param months Max months
29
+ * @returns Result
30
+ */
31
+ exchangeRateHistory(currencies: Currency[], months?: number): Promise<ExchangeRateHistoryDto[] | undefined>;
32
+ /**
33
+ * Get product unit's label
34
+ * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
35
+ * @param unit Unit
36
+ * @param isJoined Add the join label like 'per Kg' for Kg
37
+ * @returns Label
38
+ */
39
+ getUnitLabel(unit: ProductUnit, isJoined?: boolean | string): string;
40
+ private getUnitJoin;
41
+ /**
42
+ * Get mobile base64 QRCode
43
+ * @param id User id
44
+ * @param host Host URL
45
+ */
46
+ mobileQRCode(id?: string, host?: string): Promise<string | undefined>;
47
+ /**
48
+ * Get public and valid product data
49
+ * @param id Product/Service Id or Uid
50
+ * @param culture Language
51
+ * @returns Result
52
+ */
53
+ product<T extends number | string>(id: T, culture?: string): T extends number ? PublicProductDto : PublicOrgProductDto;
54
+ /**
55
+ *
56
+ * Get all repeat options
57
+ * @param options Define the order and limit the items
58
+ * @param isJoined Add the join label like 'per Kg' for Kg
59
+ * @returns Units
60
+ */
61
+ repeatOptions(options?: string[], isJoined?: boolean): ListType[];
62
+ /**
63
+ * Get all product units
64
+ * @returns Units
65
+ */
66
+ units(): ListType[];
67
+ /**
68
+ *
69
+ * Get all product units
70
+ * @param options Define the order and limit the items
71
+ * @param isJoined Add the join label like 'per Kg' for Kg
72
+ * @returns Units
73
+ */
74
+ units(options?: string[], isJoined?: boolean): ListType[];
75
+ }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PublicApi = void 0;
4
+ const shared_1 = require("@etsoo/shared");
5
+ const ProductUnit_1 = require("../business/ProductUnit");
6
+ const RepeatOption_1 = require("../business/RepeatOption");
7
+ const BaseApi_1 = require("./BaseApi");
8
+ /**
9
+ * Public API
10
+ */
11
+ class PublicApi extends BaseApi_1.BaseApi {
12
+ /**
13
+ * Get currencies
14
+ * @param currencyNames Limited currency names for local data, undefined will try to retrive remoately
15
+ * @returns Result
16
+ */
17
+ async currencies(currencyNames) {
18
+ if (currencyNames == null)
19
+ return (await this.app.api.get('Public/GetCurrencies'));
20
+ else
21
+ return currencyNames.map((name) => {
22
+ var _a;
23
+ return ({
24
+ id: name,
25
+ label: (_a = this.app.get(`currency${name}`)) !== null && _a !== void 0 ? _a : name
26
+ });
27
+ });
28
+ }
29
+ /**
30
+ * Get exchange rate
31
+ * @param currency Currency
32
+ * @returns Result
33
+ */
34
+ exchangeRate(currency) {
35
+ return this.app.api.get(`Public/ExchangeRate/${currency}`);
36
+ }
37
+ /**
38
+ * Get exchange rate history
39
+ * @param currencies Currencies
40
+ * @param months Max months
41
+ * @returns Result
42
+ */
43
+ exchangeRateHistory(currencies, months) {
44
+ return this.app.api.post('Public/ExchangeRateHistory', { currencies, months }, { defaultValue: [] });
45
+ }
46
+ /**
47
+ * Get product unit's label
48
+ * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
49
+ * @param unit Unit
50
+ * @param isJoined Add the join label like 'per Kg' for Kg
51
+ * @returns Label
52
+ */
53
+ getUnitLabel(unit, isJoined) {
54
+ var _a;
55
+ const key = ProductUnit_1.ProductUnit[unit];
56
+ const label = (_a = this.app.get('unit' + key)) !== null && _a !== void 0 ? _a : key;
57
+ const join = this.getUnitJoin(isJoined);
58
+ if (join) {
59
+ return join.format(label);
60
+ }
61
+ return label;
62
+ }
63
+ getUnitJoin(isJoined) {
64
+ var _a;
65
+ return typeof isJoined === 'string'
66
+ ? (_a = this.app.get(isJoined)) !== null && _a !== void 0 ? _a : isJoined
67
+ : isJoined
68
+ ? this.app.get('unitJoin')
69
+ : undefined;
70
+ }
71
+ /**
72
+ * Get mobile base64 QRCode
73
+ * @param id User id
74
+ * @param host Host URL
75
+ */
76
+ mobileQRCode(id, host) {
77
+ return this.app.api.post('Public/MobileQRCode', { id, host });
78
+ }
79
+ /**
80
+ * Get public and valid product data
81
+ * @param id Product/Service Id or Uid
82
+ * @param culture Language
83
+ * @returns Result
84
+ */
85
+ product(id, culture) {
86
+ culture = this.app.checkLanguage(culture);
87
+ return this.app.api.post(`Public/Product/${id}/${culture}`);
88
+ }
89
+ /**
90
+ *
91
+ * Get all repeat options
92
+ * @param options Define the order and limit the items
93
+ * @param isJoined Add the join label like 'per Kg' for Kg
94
+ * @returns Units
95
+ */
96
+ repeatOptions(options, isJoined = true) {
97
+ options !== null && options !== void 0 ? options : (options = shared_1.DataTypes.getEnumKeys(RepeatOption_1.RepeatOption));
98
+ return this.units(options, isJoined);
99
+ }
100
+ /**
101
+ *
102
+ * Get all product units
103
+ * @param options Define the order and limit the items
104
+ * @param isJoined Add the join label like 'per Kg' for Kg
105
+ * @returns Units
106
+ */
107
+ units(options, isJoined) {
108
+ options !== null && options !== void 0 ? options : (options = shared_1.DataTypes.getEnumKeys(ProductUnit_1.ProductUnit));
109
+ return options.map((key) => {
110
+ const id = shared_1.DataTypes.getEnumByKey(ProductUnit_1.ProductUnit, key);
111
+ return {
112
+ id,
113
+ label: this.getUnitLabel(id, this.getUnitJoin(isJoined)).formatInitial(true)
114
+ };
115
+ });
116
+ }
117
+ }
118
+ exports.PublicApi = PublicApi;
@@ -0,0 +1,6 @@
1
+ import { ListType1 } from '@etsoo/shared';
2
+ import { ExchangeRateDto } from './ExchangeRateDto';
3
+ /**
4
+ * Currency data
5
+ */
6
+ export declare type CurrencyDto = ListType1 & ExchangeRateDto;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Exchange rate data
3
+ */
4
+ export declare type ExchangeRateDto = {
5
+ /**
6
+ * Exchange rate
7
+ */
8
+ exchangeRate: number;
9
+ /**
10
+ * Update time
11
+ */
12
+ updateTime: string | Date;
13
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { Currency } from '../../business/Currency';
2
+ import { ExchangeRateDto } from './ExchangeRateDto';
3
+ /**
4
+ * Exchange rate history data
5
+ */
6
+ export declare type ExchangeRateHistoryDto = ExchangeRateDto & {
7
+ id: Currency;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,35 @@
1
+ import { EntityStatus } from '../../business/EntityStatus';
2
+ /**
3
+ * Public product data
4
+ */
5
+ export declare type PublicProductDto = {
6
+ /**
7
+ * Id
8
+ */
9
+ id: number;
10
+ /**
11
+ * Name
12
+ */
13
+ name: string;
14
+ /**
15
+ * Logo
16
+ */
17
+ logo?: string;
18
+ /**
19
+ * Web URL for access
20
+ */
21
+ webUrl: string;
22
+ };
23
+ /**
24
+ * Public product with organization data
25
+ */
26
+ export declare type PublicOrgProductDto = PublicProductDto & {
27
+ /**
28
+ * Purchased service status
29
+ */
30
+ serviceEntityStatus?: EntityStatus;
31
+ /**
32
+ * Purchased service expiry
33
+ */
34
+ serviceExpiry?: string | Date;
35
+ };