@blocklet/launcher-util 2.3.138 → 2.4.0

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/es/api.js CHANGED
@@ -1,10 +1,10 @@
1
- import axios from "axios";
2
- import { default as default2 } from "axios";
3
- import { createAxios } from "@blocklet/js-sdk";
4
- axios.defaults.baseURL = "";
5
- axios.defaults.timeout = 2e5;
6
- const create = (...args) => createAxios(...args);
1
+ import t from "axios";
2
+ import { default as i } from "axios";
3
+ import { createAxios as o } from "@blocklet/js-sdk";
4
+ t.defaults.baseURL = "";
5
+ t.defaults.timeout = 2e5;
6
+ const f = (...e) => o(...e);
7
7
  export {
8
- create,
9
- default2 as default
8
+ f as create,
9
+ i as default
10
10
  };
package/es/constant.js CHANGED
@@ -1,4 +1,4 @@
1
- const INSTANCE_STATUS = Object.freeze({
1
+ const s = Object.freeze({
2
2
  error: 0,
3
3
  waiting: 5,
4
4
  pending: 10,
@@ -12,14 +12,12 @@ const INSTANCE_STATUS = Object.freeze({
12
12
  expired: 80,
13
13
  terminated: 90
14
14
  // 最终状态
15
- });
16
- const PLAN_STATUS = Object.freeze({
15
+ }), d = Object.freeze({
17
16
  draft: 10,
18
17
  published: 20,
19
18
  dropped: 30
20
19
  // 已下架
21
- });
22
- const LAUNCH_STATUS = Object.freeze({
20
+ }), c = Object.freeze({
23
21
  created: 0,
24
22
  selected: 10,
25
23
  connected: 20,
@@ -34,20 +32,17 @@ const LAUNCH_STATUS = Object.freeze({
34
32
  terminated: 70,
35
33
  transferred: 90,
36
34
  blocked: 100
37
- });
38
- const LAUNCH_SESSION_TYPE = Object.freeze({
35
+ }), T = Object.freeze({
39
36
  serverless: "serverless",
40
37
  dedicated: "dedicated",
41
38
  onDemand: "on-demand"
42
39
  // FIXME: on-demand 是兼容字段,未来该字段会被移除
43
- });
44
- const SERVERLESS_INSTANCE_STATUS = {
40
+ }), p = {
45
41
  launching: 10,
46
42
  running: 20,
47
43
  expired: 30,
48
44
  terminated: 40
49
- };
50
- const LAUNCH_ACTIVITY_TYPE = Object.freeze({
45
+ }, E = Object.freeze({
51
46
  created: "created",
52
47
  selected: "selected",
53
48
  connected: "connected",
@@ -59,8 +54,7 @@ const LAUNCH_ACTIVITY_TYPE = Object.freeze({
59
54
  canceled: "canceled",
60
55
  terminated: "terminated",
61
56
  transferred: "transferred"
62
- });
63
- const SERVER_ACTIVITY_TYPE = Object.freeze({
57
+ }), S = Object.freeze({
64
58
  purchase: "purchase",
65
59
  launch: "launch",
66
60
  createFailed: "createFailed",
@@ -82,21 +76,7 @@ const SERVER_ACTIVITY_TYPE = Object.freeze({
82
76
  renewaled: "renewaled",
83
77
  transferred: "transferred",
84
78
  replacement: "replacement"
85
- });
86
- const toMap = (status) => Object.keys(status).reduce((acc, cur) => {
87
- acc[status[cur]] = cur;
88
- return acc;
89
- }, {});
90
- const fromStatus = (map) => (status) => map[status];
91
- const statusInstanceMap = toMap(INSTANCE_STATUS);
92
- const planStatusMap = toMap(PLAN_STATUS);
93
- const launchStatusMap = toMap(LAUNCH_STATUS);
94
- const fromInstanceStatus = fromStatus(statusInstanceMap);
95
- const fromPlanStatus = fromStatus(planStatusMap);
96
- const fromLaunchStatus = fromStatus(launchStatusMap);
97
- const NFT_TYPE_SERVERLESS = "BlockletServerServerlessNFT";
98
- const NFT_TYPE_DEDICATE = "BlockletServerOwnershipNFT";
99
- const TIME_LOCALE = {
79
+ }), n = (e) => Object.keys(e).reduce((t, r) => (t[e[r]] = r, t), {}), a = (e) => (t) => e[t], i = n(s), o = n(d), l = n(c), _ = a(i), m = a(o), A = a(l), u = "BlockletServerServerlessNFT", f = "BlockletServerOwnershipNFT", N = {
100
80
  en: {
101
81
  h: "hour",
102
82
  hs: "hours",
@@ -117,89 +97,74 @@ const TIME_LOCALE = {
117
97
  y: "年",
118
98
  ys: "年"
119
99
  }
120
- };
121
- const APP_TYPE = Object.freeze({
100
+ }, I = Object.freeze({
122
101
  serverless: "serverless",
123
102
  dedicated: "dedicated"
124
- });
125
- const SKU_STATUS = Object.freeze({
103
+ }), P = Object.freeze({
126
104
  DISABLED: 0,
127
105
  ENABLED: 1
128
- });
129
- const PAYMENT_STATUS = Object.freeze({
106
+ }), F = Object.freeze({
130
107
  unpaid: 10,
131
108
  paid: 20,
132
109
  done: 30,
133
110
  expired: 40,
134
111
  canceled: 60,
135
112
  failed: 70
136
- });
137
- const PAYMENT_TYPES = {
113
+ }), h = {
138
114
  purchase: "purchase",
139
115
  renewal: "renewal",
140
116
  autoRenewal: "auto-renewal"
141
- };
142
- const PAYMENT_METHODS = Object.freeze({
117
+ }, D = Object.freeze({
143
118
  crypto: "crypto",
144
119
  stripe: "stripe",
145
120
  fiat: "fiat"
146
121
  // TODO: 区分支付货币和支付方式
147
- });
148
- const DID_DOMAIN_SUFFIX = "did.abtnet.io";
149
- const REDEEM_NFT_ID = "redeem";
150
- const INSTANCE_MAX_NAME_LENGTH = 30;
151
- const INSTANCE_MAX_DESC_LENGTH = 50;
152
- const LAUNCH_TYPE = {
122
+ }), Y = "did.abtnet.io", C = "redeem", O = 30, y = 50, M = {
153
123
  instant: "instant",
154
124
  redeem: "redeem"
155
- };
156
- const CURRENCY_TYPE = {
125
+ }, R = {
157
126
  fiat: "fiat",
158
127
  crypto: "crypto"
159
- };
160
- const SERVERLESS_RETAIN_DAYS = 30;
161
- const APP_RECORD_TYPE = {
128
+ }, L = 30, b = {
162
129
  install: "install",
163
130
  uninstall: "uninstall"
164
- };
165
- const APP_CHARGE_TYPE = {
131
+ }, U = {
166
132
  freeTrial: "free-trial",
167
133
  // 免费试用
168
134
  instant: "instant"
169
135
  // 立即付费
170
- };
171
- const CONFIG_DATA_TYPE = {
136
+ }, j = {
172
137
  ami: "ami",
173
138
  syncNFT: "syncNFT",
174
139
  nftFactories: "nftFactories"
175
140
  };
176
141
  export {
177
- APP_CHARGE_TYPE,
178
- APP_RECORD_TYPE,
179
- APP_TYPE,
180
- CONFIG_DATA_TYPE,
181
- CURRENCY_TYPE,
182
- DID_DOMAIN_SUFFIX,
183
- INSTANCE_MAX_DESC_LENGTH,
184
- INSTANCE_MAX_NAME_LENGTH,
185
- INSTANCE_STATUS,
186
- LAUNCH_ACTIVITY_TYPE,
187
- LAUNCH_SESSION_TYPE,
188
- LAUNCH_STATUS,
189
- LAUNCH_TYPE,
190
- NFT_TYPE_DEDICATE,
191
- NFT_TYPE_SERVERLESS,
192
- PAYMENT_METHODS,
193
- PAYMENT_STATUS,
194
- PAYMENT_TYPES,
195
- PLAN_STATUS,
196
- REDEEM_NFT_ID,
197
- SERVERLESS_INSTANCE_STATUS,
198
- SERVERLESS_RETAIN_DAYS,
199
- SERVER_ACTIVITY_TYPE,
200
- SKU_STATUS,
201
- TIME_LOCALE,
202
- fromInstanceStatus,
203
- fromLaunchStatus,
204
- fromPlanStatus
142
+ U as APP_CHARGE_TYPE,
143
+ b as APP_RECORD_TYPE,
144
+ I as APP_TYPE,
145
+ j as CONFIG_DATA_TYPE,
146
+ R as CURRENCY_TYPE,
147
+ Y as DID_DOMAIN_SUFFIX,
148
+ y as INSTANCE_MAX_DESC_LENGTH,
149
+ O as INSTANCE_MAX_NAME_LENGTH,
150
+ s as INSTANCE_STATUS,
151
+ E as LAUNCH_ACTIVITY_TYPE,
152
+ T as LAUNCH_SESSION_TYPE,
153
+ c as LAUNCH_STATUS,
154
+ M as LAUNCH_TYPE,
155
+ f as NFT_TYPE_DEDICATE,
156
+ u as NFT_TYPE_SERVERLESS,
157
+ D as PAYMENT_METHODS,
158
+ F as PAYMENT_STATUS,
159
+ h as PAYMENT_TYPES,
160
+ d as PLAN_STATUS,
161
+ C as REDEEM_NFT_ID,
162
+ p as SERVERLESS_INSTANCE_STATUS,
163
+ L as SERVERLESS_RETAIN_DAYS,
164
+ S as SERVER_ACTIVITY_TYPE,
165
+ P as SKU_STATUS,
166
+ N as TIME_LOCALE,
167
+ _ as fromInstanceStatus,
168
+ A as fromLaunchStatus,
169
+ m as fromPlanStatus
205
170
  };
@@ -1,25 +1,13 @@
1
- const formatError = (err) => {
2
- var _a;
3
- if (!err) {
4
- return err;
5
- }
6
- const { details, errors, response } = err;
7
- if (Array.isArray(errors)) {
8
- return errors.map((x) => x.message).join("\n");
9
- }
10
- if (Array.isArray(details)) {
11
- const formatted = details.map((e) => {
12
- const errorMessage = e.message.replace(/["]/g, "'");
13
- const errorPath = e.path.join(".");
14
- return `${errorPath}: ${errorMessage}`;
15
- });
16
- return `Validate failed: ${formatted.join(";")}`;
17
- }
18
- if (response) {
19
- return ((_a = response.data) == null ? void 0 : _a.error) || `Request failed: ${response.status} ${response.statusText}: ${JSON.stringify(response.data)}`;
20
- }
21
- return err.message || err;
1
+ const f = (r) => {
2
+ if (!r)
3
+ return r;
4
+ const { details: a, errors: e, response: t } = r;
5
+ return Array.isArray(e) ? e.map((s) => s.message).join(`
6
+ `) : Array.isArray(a) ? `Validate failed: ${a.map((o) => {
7
+ const n = o.message.replace(/["]/g, "'");
8
+ return `${o.path.join(".")}: ${n}`;
9
+ }).join(";")}` : t ? t.data?.error || `Request failed: ${t.status} ${t.statusText}: ${JSON.stringify(t.data)}` : r.message || r;
22
10
  };
23
11
  export {
24
- formatError as default
12
+ f as default
25
13
  };
package/es/get-asset.js CHANGED
@@ -1,14 +1,12 @@
1
- import joinUrl from "url-join";
2
- import get from "lodash/get";
3
- import { create } from "./api";
4
- const getAsset = async (chainHost, address) => {
5
- const url = joinUrl(new URL(chainHost).origin, "/api/gql/");
6
- const request = create();
7
- const result = await request.post(
8
- url,
1
+ import o from "url-join";
2
+ import n from "lodash/get";
3
+ import { create as i } from "./api.js";
4
+ const u = async (e, a) => {
5
+ const s = o(new URL(e).origin, "/api/gql/"), r = await i().post(
6
+ s,
9
7
  JSON.stringify({
10
8
  query: `{
11
- getAssetState(address: "${address}") {
9
+ getAssetState(address: "${a}") {
12
10
  state {
13
11
  address
14
12
  data {
@@ -34,13 +32,9 @@ const getAsset = async (chainHost, address) => {
34
32
  },
35
33
  timeout: 60 * 1e3
36
34
  }
37
- );
38
- const state = get(result, "data.data.getAssetState.state");
39
- if (state && state.data.typeUrl === "json") {
40
- state.data.value = JSON.parse(state.data.value);
41
- }
42
- return state;
35
+ ), t = n(r, "data.data.getAssetState.state");
36
+ return t && t.data.typeUrl === "json" && (t.data.value = JSON.parse(t.data.value)), t;
43
37
  };
44
38
  export {
45
- getAsset as default
39
+ u as default
46
40
  };
package/es/locale/en.js CHANGED
@@ -1,6 +1,6 @@
1
- import flat from "flat";
2
- import { INSTANCE_STATUS, PAYMENT_METHODS, CURRENCY_TYPE, LAUNCH_STATUS, LAUNCH_ACTIVITY_TYPE } from "../constant";
3
- const en = flat({
1
+ import i from "flat";
2
+ import { LAUNCH_ACTIVITY_TYPE as t, LAUNCH_STATUS as e, CURRENCY_TYPE as a, PAYMENT_METHODS as r, INSTANCE_STATUS as n } from "../constant.js";
3
+ const o = i({
4
4
  common: {
5
5
  app: "App",
6
6
  billing: "Billing",
@@ -32,51 +32,51 @@ const en = flat({
32
32
  },
33
33
  dedicatedInstance: {
34
34
  appStatus: {
35
- [INSTANCE_STATUS.unknown]: "Unknown",
36
- [INSTANCE_STATUS.pending]: "Pending",
37
- [INSTANCE_STATUS.starting]: "Starting",
38
- [INSTANCE_STATUS.running]: "Running",
39
- [INSTANCE_STATUS.restarting]: "Restarting",
40
- [INSTANCE_STATUS.underMaintenance]: "Under-Maintenance",
41
- [INSTANCE_STATUS.stopping]: "Stopping",
42
- [INSTANCE_STATUS.stopped]: "Stopped",
43
- [INSTANCE_STATUS.terminatedInstance]: "Instance Terminated",
44
- [INSTANCE_STATUS.expired]: "Expired",
45
- [INSTANCE_STATUS.error]: "Error",
46
- [INSTANCE_STATUS.waiting]: "Waiting",
47
- [INSTANCE_STATUS.terminated]: "Terminated"
35
+ [n.unknown]: "Unknown",
36
+ [n.pending]: "Pending",
37
+ [n.starting]: "Starting",
38
+ [n.running]: "Running",
39
+ [n.restarting]: "Restarting",
40
+ [n.underMaintenance]: "Under-Maintenance",
41
+ [n.stopping]: "Stopping",
42
+ [n.stopped]: "Stopped",
43
+ [n.terminatedInstance]: "Instance Terminated",
44
+ [n.expired]: "Expired",
45
+ [n.error]: "Error",
46
+ [n.waiting]: "Waiting",
47
+ [n.terminated]: "Terminated"
48
48
  }
49
49
  },
50
50
  paymentMethod: {
51
- [PAYMENT_METHODS.crypto]: "Crypto",
52
- [PAYMENT_METHODS.stripe]: "Credit",
53
- [CURRENCY_TYPE.fiat]: "Credit",
54
- [CURRENCY_TYPE.crypto]: "Crypto"
51
+ [r.crypto]: "Crypto",
52
+ [r.stripe]: "Credit",
53
+ [a.fiat]: "Credit",
54
+ [a.crypto]: "Crypto"
55
55
  },
56
56
  launchSession: {
57
57
  installSource: "Install Source",
58
58
  status: {
59
- [LAUNCH_STATUS.created]: "In Progress",
60
- [LAUNCH_STATUS.selected]: "In Progress",
61
- [LAUNCH_STATUS.connected]: "In Progress",
62
- [LAUNCH_STATUS.paid]: "Paid",
63
- [LAUNCH_STATUS.nftMinted]: "NFT Minted",
64
- [LAUNCH_STATUS.allocated]: "Paid",
65
- [LAUNCH_STATUS.consuming]: "Handling",
66
- [LAUNCH_STATUS.installed]: "Installed",
67
- [LAUNCH_STATUS.timeout]: "Timeout",
68
- [LAUNCH_STATUS.pastDue]: "PastDue",
59
+ [e.created]: "In Progress",
60
+ [e.selected]: "In Progress",
61
+ [e.connected]: "In Progress",
62
+ [e.paid]: "Paid",
63
+ [e.nftMinted]: "NFT Minted",
64
+ [e.allocated]: "Paid",
65
+ [e.consuming]: "Handling",
66
+ [e.installed]: "Installed",
67
+ [e.timeout]: "Timeout",
68
+ [e.pastDue]: "PastDue",
69
69
  canceling: "Canceling",
70
- [LAUNCH_STATUS.canceled]: "Canceled",
71
- [LAUNCH_STATUS.terminated]: "Terminated",
72
- [LAUNCH_STATUS.transferred]: "Transferred",
73
- [LAUNCH_STATUS.blocked]: "Blocked"
70
+ [e.canceled]: "Canceled",
71
+ [e.terminated]: "Terminated",
72
+ [e.transferred]: "Transferred",
73
+ [e.blocked]: "Blocked"
74
74
  },
75
75
  activity: {
76
- [LAUNCH_ACTIVITY_TYPE.canceled]: "Canceled",
77
- [LAUNCH_ACTIVITY_TYPE.pastDue]: "PastDue",
78
- [LAUNCH_ACTIVITY_TYPE.terminated]: "Terminated",
79
- [LAUNCH_ACTIVITY_TYPE.transferred]: "Transferred"
76
+ [t.canceled]: "Canceled",
77
+ [t.pastDue]: "PastDue",
78
+ [t.terminated]: "Terminated",
79
+ [t.transferred]: "Transferred"
80
80
  },
81
81
  steps: {
82
82
  create: "Create",
@@ -86,5 +86,5 @@ const en = flat({
86
86
  }
87
87
  });
88
88
  export {
89
- en as default
89
+ o as default
90
90
  };
@@ -1,17 +1,10 @@
1
- const index = (locales) => {
2
- const replace = (template, data) => (template || "").replace(
1
+ const o = (r) => {
2
+ const s = (e, t) => (e || "").replace(
3
3
  /{(\w*)}/g,
4
- (_, key) => Object.prototype.hasOwnProperty.call(data || {}, key) ? data[key] : ""
5
- );
6
- const translate = (key, locale, params) => {
7
- if (!locales[locale]) {
8
- locale = "en";
9
- }
10
- return replace(locales[locale][key], params) || key;
11
- };
12
- const createTranslateFunc = (locale) => (key, params) => translate(key, locale || "en", params);
13
- return { translate, createTranslateFunc };
4
+ (n, c) => Object.prototype.hasOwnProperty.call(t || {}, c) ? t[c] : ""
5
+ ), a = (e, t, n) => (r[t] || (t = "en"), s(r[t][e], n) || e);
6
+ return { translate: a, createTranslateFunc: (e) => (t, n) => a(t, e || "en", n) };
14
7
  };
15
8
  export {
16
- index as default
9
+ o as default
17
10
  };
package/es/locale/zh.js CHANGED
@@ -1,6 +1,6 @@
1
- import flat from "flat";
2
- import { INSTANCE_STATUS, PAYMENT_METHODS, CURRENCY_TYPE, LAUNCH_STATUS, LAUNCH_ACTIVITY_TYPE } from "../constant";
3
- const zh = flat({
1
+ import r from "flat";
2
+ import { LAUNCH_ACTIVITY_TYPE as n, LAUNCH_STATUS as e, CURRENCY_TYPE as a, PAYMENT_METHODS as i, INSTANCE_STATUS as t } from "../constant.js";
3
+ const p = r({
4
4
  common: {
5
5
  app: "应用",
6
6
  billing: "账单",
@@ -32,53 +32,53 @@ const zh = flat({
32
32
  },
33
33
  dedicatedInstance: {
34
34
  appStatus: {
35
- [INSTANCE_STATUS.unknown]: "未知",
36
- [INSTANCE_STATUS.pending]: "待处理",
37
- [INSTANCE_STATUS.starting]: "启动中",
38
- [INSTANCE_STATUS.running]: "运行中",
39
- [INSTANCE_STATUS.restarting]: "重启中",
40
- [INSTANCE_STATUS.underMaintenance]: "维护中",
41
- [INSTANCE_STATUS.stopping]: "停止中",
42
- [INSTANCE_STATUS.stopped]: "已停止",
43
- [INSTANCE_STATUS.terminatedInstance]: "已终止实例",
44
- [INSTANCE_STATUS.expired]: "已过期",
45
- [INSTANCE_STATUS.error]: "错误",
46
- [INSTANCE_STATUS.waiting]: "等待中",
47
- [INSTANCE_STATUS.terminated]: "已终止"
35
+ [t.unknown]: "未知",
36
+ [t.pending]: "待处理",
37
+ [t.starting]: "启动中",
38
+ [t.running]: "运行中",
39
+ [t.restarting]: "重启中",
40
+ [t.underMaintenance]: "维护中",
41
+ [t.stopping]: "停止中",
42
+ [t.stopped]: "已停止",
43
+ [t.terminatedInstance]: "已终止实例",
44
+ [t.expired]: "已过期",
45
+ [t.error]: "错误",
46
+ [t.waiting]: "等待中",
47
+ [t.terminated]: "已终止"
48
48
  }
49
49
  },
50
50
  paymentMethod: {
51
- [PAYMENT_METHODS.crypto]: "加密货币",
52
- [PAYMENT_METHODS.stripe]: "信用卡",
53
- [CURRENCY_TYPE.fiat]: "信用卡",
51
+ [i.crypto]: "加密货币",
52
+ [i.stripe]: "信用卡",
53
+ [a.fiat]: "信用卡",
54
54
  // TODO: 统一管理支付方式和货币类型
55
- [CURRENCY_TYPE.crypto]: "加密货币"
55
+ [a.crypto]: "加密货币"
56
56
  // TODO: 统一管理支付方式和货币类型
57
57
  },
58
58
  launchSession: {
59
59
  installSource: "安装源",
60
60
  status: {
61
- [LAUNCH_STATUS.created]: "进行中",
62
- [LAUNCH_STATUS.selected]: "进行中",
63
- [LAUNCH_STATUS.connected]: "进行中",
64
- [LAUNCH_STATUS.paid]: "已付款",
65
- [LAUNCH_STATUS.nftMinted]: "已铸造NFT",
66
- [LAUNCH_STATUS.allocated]: "已付款",
67
- [LAUNCH_STATUS.consuming]: "处理中",
68
- [LAUNCH_STATUS.installed]: "已安装",
69
- [LAUNCH_STATUS.timeout]: "已超时",
70
- [LAUNCH_STATUS.pastDue]: "已欠费",
61
+ [e.created]: "进行中",
62
+ [e.selected]: "进行中",
63
+ [e.connected]: "进行中",
64
+ [e.paid]: "已付款",
65
+ [e.nftMinted]: "已铸造NFT",
66
+ [e.allocated]: "已付款",
67
+ [e.consuming]: "处理中",
68
+ [e.installed]: "已安装",
69
+ [e.timeout]: "已超时",
70
+ [e.pastDue]: "已欠费",
71
71
  canceling: "将要取消",
72
- [LAUNCH_STATUS.canceled]: "已取消",
73
- [LAUNCH_STATUS.terminated]: "已终止",
74
- [LAUNCH_STATUS.transferred]: "已转移",
75
- [LAUNCH_STATUS.blocked]: "已禁用"
72
+ [e.canceled]: "已取消",
73
+ [e.terminated]: "已终止",
74
+ [e.transferred]: "已转移",
75
+ [e.blocked]: "已禁用"
76
76
  },
77
77
  activity: {
78
- [LAUNCH_ACTIVITY_TYPE.canceled]: "已取消",
79
- [LAUNCH_ACTIVITY_TYPE.pastDue]: "已欠费",
80
- [LAUNCH_ACTIVITY_TYPE.terminated]: "已终止",
81
- [LAUNCH_ACTIVITY_TYPE.transferred]: "已转移"
78
+ [n.canceled]: "已取消",
79
+ [n.pastDue]: "已欠费",
80
+ [n.terminated]: "已终止",
81
+ [n.transferred]: "已转移"
82
82
  },
83
83
  steps: {
84
84
  create: "创建",
@@ -88,5 +88,5 @@ const zh = flat({
88
88
  }
89
89
  });
90
90
  export {
91
- zh as default
91
+ p as default
92
92
  };
package/es/middleware.js CHANGED
@@ -1,40 +1,29 @@
1
- import { getSort } from "./util";
2
- const MAX_PAGING_SIZE = 100;
3
- const DEFAULT_PAGING_SIZE = MAX_PAGING_SIZE;
4
- const DEFAULT_PAGE = 1;
5
- const pagination = (req, res, next) => {
6
- const paging = {
7
- page: DEFAULT_PAGE,
8
- size: DEFAULT_PAGING_SIZE
1
+ import { getSort as u } from "./util.js";
2
+ const t = 100, g = t, N = 1, m = (e, i, s) => {
3
+ const r = {
4
+ page: N,
5
+ size: g
9
6
  };
10
- req.paging = paging;
11
- if (!Number.isNaN(Number(req.query.page))) {
12
- paging.page = Number(req.query.page);
7
+ if (e.paging = r, Number.isNaN(Number(e.query.page)) || (r.page = Number(e.query.page)), !Number.isNaN(Number(e.query.size))) {
8
+ const o = Number(e.query.size);
9
+ r.size = o <= t ? o : t;
13
10
  }
14
- if (!Number.isNaN(Number(req.query.size))) {
15
- const size = Number(req.query.size);
16
- paging.size = size <= MAX_PAGING_SIZE ? size : MAX_PAGING_SIZE;
17
- }
18
- paging.sort = getSort(req.query.sortby, req.query.sortdir);
19
- next();
20
- };
21
- const validate = (schema, option = {}) => (req, res, next) => {
22
- const { error, value } = schema.validate(req.body, {
23
- errors: { language: req.query.locale || "en" },
24
- ...option
11
+ r.sort = u(e.query.sortby, e.query.sortdir), s();
12
+ }, p = (e, i = {}) => (s, r, o) => {
13
+ const { error: a, value: n } = e.validate(s.body, {
14
+ errors: { language: s.query.locale || "en" },
15
+ ...i
25
16
  });
26
- if (error) {
27
- console.error("validate error", { error: error.message });
28
- res.status(400).json({ error: error.message });
17
+ if (a) {
18
+ console.error("validate error", { error: a.message }), r.status(400).json({ error: a.message });
29
19
  return;
30
20
  }
31
- req.data = value;
32
- next();
21
+ s.data = n, o();
33
22
  };
34
23
  export {
35
- DEFAULT_PAGE,
36
- DEFAULT_PAGING_SIZE,
37
- MAX_PAGING_SIZE,
38
- pagination,
39
- validate
24
+ N as DEFAULT_PAGE,
25
+ g as DEFAULT_PAGING_SIZE,
26
+ t as MAX_PAGING_SIZE,
27
+ m as pagination,
28
+ p as validate
40
29
  };
package/es/nft.js CHANGED
@@ -1,19 +1,13 @@
1
- import get from "lodash/get";
2
- import last from "lodash/last";
3
- import { NFT_TYPE_SERVERLESS } from "../lib/constant";
4
- const getNftExpirationDate = (asset) => last(get(asset, "data.value.expirationDate", []));
5
- const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
6
- const isNFTExpired = (asset) => {
7
- const expirationDate = getNftExpirationDate(asset);
8
- return isDateExpired(expirationDate);
9
- };
10
- const isServerlessNFT = (assetState) => {
11
- var _a;
12
- return assetState.moniker === NFT_TYPE_SERVERLESS || ((_a = assetState.tags) == null ? void 0 : _a.includes(NFT_TYPE_SERVERLESS));
13
- };
1
+ import r from "lodash/get";
2
+ import i from "lodash/last";
3
+ import { NFT_TYPE_SERVERLESS as e } from "./constant.js";
4
+ const n = (t) => i(r(t, "data.value.expirationDate", [])), s = (t) => !!t && new Date(t).getTime() <= Date.now(), E = (t) => {
5
+ const o = n(t);
6
+ return s(o);
7
+ }, c = (t) => t.moniker === e || t.tags?.includes(e);
14
8
  export {
15
- getNftExpirationDate,
16
- isDateExpired,
17
- isNFTExpired,
18
- isServerlessNFT
9
+ n as getNftExpirationDate,
10
+ s as isDateExpired,
11
+ E as isNFTExpired,
12
+ c as isServerlessNFT
19
13
  };