@blocklet/launcher-util 2.1.108 → 2.2.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/lib/constant.js +120 -121
- package/lib/format-error.js +6 -17
- package/lib/get-asset.js +11 -15
- package/lib/locale/en.js +32 -31
- package/lib/locale/index.js +9 -19
- package/lib/locale/zh.js +34 -31
- package/lib/middleware.js +47 -67
- package/lib/notification/index.js +8 -14
- package/lib/permission.js +4 -6
- package/lib/util.js +72 -112
- package/lib/validator.js +4 -4
- package/package.json +8 -4
package/lib/constant.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
3
|
const INSTANCE_STATUS = Object.freeze({
|
|
2
4
|
error: 0,
|
|
3
5
|
waiting: 5,
|
|
@@ -9,15 +11,14 @@ const INSTANCE_STATUS = Object.freeze({
|
|
|
9
11
|
stopped: 60,
|
|
10
12
|
terminated: 70,
|
|
11
13
|
expired: 80,
|
|
12
|
-
underMaintenance: 90
|
|
14
|
+
underMaintenance: 90
|
|
13
15
|
});
|
|
14
|
-
|
|
15
16
|
const PLAN_STATUS = Object.freeze({
|
|
16
17
|
draft: 10,
|
|
17
18
|
published: 20,
|
|
18
|
-
dropped: 30
|
|
19
|
+
dropped: 30
|
|
20
|
+
// 已下架
|
|
19
21
|
});
|
|
20
|
-
|
|
21
22
|
const LAUNCH_STATUS = Object.freeze({
|
|
22
23
|
created: 0,
|
|
23
24
|
selected: 10,
|
|
@@ -28,143 +29,141 @@ const LAUNCH_STATUS = Object.freeze({
|
|
|
28
29
|
expired: 60,
|
|
29
30
|
terminated: 70,
|
|
30
31
|
timeout: 80,
|
|
31
|
-
transferred: 90
|
|
32
|
+
transferred: 90
|
|
32
33
|
});
|
|
33
|
-
|
|
34
34
|
const LAUNCH_ACTIVITY_TYPE = Object.freeze({
|
|
35
|
-
created:
|
|
36
|
-
selected:
|
|
37
|
-
connected:
|
|
38
|
-
paid:
|
|
39
|
-
allocated:
|
|
40
|
-
installed:
|
|
41
|
-
timeout:
|
|
42
|
-
expired:
|
|
43
|
-
terminated:
|
|
44
|
-
transferred:
|
|
35
|
+
created: "created",
|
|
36
|
+
selected: "selected",
|
|
37
|
+
connected: "connected",
|
|
38
|
+
paid: "paid",
|
|
39
|
+
allocated: "allocated",
|
|
40
|
+
installed: "installed",
|
|
41
|
+
timeout: "timeout",
|
|
42
|
+
expired: "expired",
|
|
43
|
+
terminated: "terminated",
|
|
44
|
+
transferred: "transferred"
|
|
45
45
|
});
|
|
46
|
-
|
|
47
46
|
const SERVER_ACTIVITY_TYPE = Object.freeze({
|
|
48
|
-
purchase:
|
|
49
|
-
launch:
|
|
50
|
-
createFailed:
|
|
51
|
-
created:
|
|
52
|
-
start:
|
|
53
|
-
started:
|
|
54
|
-
startFailed:
|
|
55
|
-
stop:
|
|
56
|
-
stopped:
|
|
57
|
-
stopFailed:
|
|
58
|
-
restart:
|
|
59
|
-
restarted:
|
|
60
|
-
restartFailed:
|
|
61
|
-
expired:
|
|
62
|
-
terminate:
|
|
63
|
-
terminated:
|
|
64
|
-
terminateFailed:
|
|
65
|
-
renewaled:
|
|
66
|
-
transferred:
|
|
67
|
-
replacement:
|
|
47
|
+
purchase: "purchase",
|
|
48
|
+
launch: "launch",
|
|
49
|
+
createFailed: "createFailed",
|
|
50
|
+
created: "created",
|
|
51
|
+
start: "start",
|
|
52
|
+
started: "started",
|
|
53
|
+
startFailed: "startFailed",
|
|
54
|
+
stop: "stop",
|
|
55
|
+
stopped: "stopped",
|
|
56
|
+
stopFailed: "stopFailed",
|
|
57
|
+
restart: "restart",
|
|
58
|
+
restarted: "restarted",
|
|
59
|
+
restartFailed: "restartFailed",
|
|
60
|
+
expired: "expired",
|
|
61
|
+
terminate: "terminate",
|
|
62
|
+
terminated: "terminated",
|
|
63
|
+
terminateFailed: "terminateFailed",
|
|
64
|
+
renewaled: "renewaled",
|
|
65
|
+
transferred: "transferred",
|
|
66
|
+
replacement: "replacement"
|
|
68
67
|
});
|
|
69
|
-
|
|
70
68
|
const SERVERLESS_INSTANCE_STATUS = {
|
|
71
69
|
launching: 10,
|
|
72
70
|
running: 20,
|
|
73
71
|
expired: 30,
|
|
74
|
-
terminated: 40
|
|
72
|
+
terminated: 40
|
|
75
73
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return acc;
|
|
81
|
-
}, {});
|
|
82
|
-
|
|
74
|
+
const toMap = (staus) => Object.keys(staus).reduce((acc, cur) => {
|
|
75
|
+
acc[staus[cur]] = cur;
|
|
76
|
+
return acc;
|
|
77
|
+
}, {});
|
|
83
78
|
const fromStatus = (map) => (status) => map[status];
|
|
84
|
-
|
|
85
79
|
const statusInstanceMap = toMap(INSTANCE_STATUS);
|
|
86
80
|
const planStatusMap = toMap(PLAN_STATUS);
|
|
87
|
-
|
|
88
81
|
const fromInstanceStatus = fromStatus(statusInstanceMap);
|
|
89
82
|
const fromPlanStatus = fromStatus(planStatusMap);
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
const BLOCKLET_SERVER_OWNERSHIP_NFT = 'BlockletServerOwnershipNFT';
|
|
93
|
-
|
|
83
|
+
const NFT_TYPE_SERVERLESS = "BlockletServerServerlessNFT";
|
|
84
|
+
const BLOCKLET_SERVER_OWNERSHIP_NFT = "BlockletServerOwnershipNFT";
|
|
94
85
|
const TIME_LOCALE = {
|
|
95
86
|
en: {
|
|
96
|
-
h:
|
|
97
|
-
hs:
|
|
98
|
-
d:
|
|
99
|
-
ds:
|
|
100
|
-
m:
|
|
101
|
-
ms:
|
|
102
|
-
y:
|
|
103
|
-
ys:
|
|
87
|
+
h: "hour",
|
|
88
|
+
hs: "hours",
|
|
89
|
+
d: " day",
|
|
90
|
+
ds: " days",
|
|
91
|
+
m: " month",
|
|
92
|
+
ms: " months",
|
|
93
|
+
y: " year",
|
|
94
|
+
ys: " years"
|
|
104
95
|
},
|
|
105
96
|
zh: {
|
|
106
|
-
h:
|
|
107
|
-
hs:
|
|
108
|
-
d:
|
|
109
|
-
ds:
|
|
110
|
-
m:
|
|
111
|
-
ms:
|
|
112
|
-
y:
|
|
113
|
-
ys:
|
|
114
|
-
}
|
|
97
|
+
h: "小时",
|
|
98
|
+
hs: "小时",
|
|
99
|
+
d: "天",
|
|
100
|
+
ds: "天",
|
|
101
|
+
m: "个月",
|
|
102
|
+
ms: "个月",
|
|
103
|
+
y: "年",
|
|
104
|
+
ys: "年"
|
|
105
|
+
}
|
|
115
106
|
};
|
|
116
|
-
|
|
117
107
|
const APP_TYPE = Object.freeze({
|
|
118
|
-
serverless:
|
|
119
|
-
dedicated:
|
|
108
|
+
serverless: "serverless",
|
|
109
|
+
dedicated: "dedicated"
|
|
120
110
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
expired: 40,
|
|
133
|
-
canceled: 60,
|
|
134
|
-
failed: 70,
|
|
135
|
-
}),
|
|
136
|
-
PAYMENT_TYPES: {
|
|
137
|
-
purchase: 'purchase',
|
|
138
|
-
renewal: 'renewal',
|
|
139
|
-
autoRenewal: 'auto-renewal',
|
|
140
|
-
},
|
|
141
|
-
PAYMENT_METHODS: Object.freeze({
|
|
142
|
-
crypto: 'crypto',
|
|
143
|
-
stripe: 'stripe',
|
|
144
|
-
fiat: 'fiat', // TODO: 区分支付货币和支付方式
|
|
145
|
-
}),
|
|
146
|
-
DID_DOMAIN_SUFFIX: 'did.abtnet.io',
|
|
147
|
-
INSTANCE_STATUS,
|
|
148
|
-
fromInstanceStatus,
|
|
149
|
-
fromPlanStatus,
|
|
150
|
-
REDEEM_NFT_ID: 'redeem',
|
|
151
|
-
INSTANCE_MAX_NAME_LENGTH: 30,
|
|
152
|
-
INSTANCE_MAX_DESC_LENGTH: 50,
|
|
153
|
-
LAUNCH_TYPE: {
|
|
154
|
-
instant: 'instant',
|
|
155
|
-
redeem: 'redeem',
|
|
156
|
-
},
|
|
157
|
-
PLAN_STATUS,
|
|
158
|
-
SERVER_ACTIVITY_TYPE,
|
|
159
|
-
CURRENCY_TYPE: {
|
|
160
|
-
fiat: 'fiat',
|
|
161
|
-
crypto: 'crypto',
|
|
162
|
-
},
|
|
163
|
-
NFT_TYPE_SERVERLESS,
|
|
164
|
-
BLOCKLET_SERVER_OWNERSHIP_NFT,
|
|
165
|
-
SERVERLESS_INSTANCE_STATUS,
|
|
166
|
-
LAUNCH_STATUS,
|
|
167
|
-
LAUNCH_ACTIVITY_TYPE,
|
|
168
|
-
SERVERLESS_RETAIN_DAYS: 30,
|
|
169
|
-
TIME_LOCALE,
|
|
111
|
+
const SKU_STATUS = Object.freeze({
|
|
112
|
+
DISABLED: 0,
|
|
113
|
+
ENABLED: 1
|
|
114
|
+
});
|
|
115
|
+
const PAYMENT_STATUS = Object.freeze({
|
|
116
|
+
unpaid: 10,
|
|
117
|
+
paid: 20,
|
|
118
|
+
done: 30,
|
|
119
|
+
expired: 40,
|
|
120
|
+
canceled: 60,
|
|
121
|
+
failed: 70
|
|
170
122
|
});
|
|
123
|
+
const PAYMENT_TYPES = {
|
|
124
|
+
purchase: "purchase",
|
|
125
|
+
renewal: "renewal",
|
|
126
|
+
autoRenewal: "auto-renewal"
|
|
127
|
+
};
|
|
128
|
+
const PAYMENT_METHODS = Object.freeze({
|
|
129
|
+
crypto: "crypto",
|
|
130
|
+
stripe: "stripe",
|
|
131
|
+
fiat: "fiat"
|
|
132
|
+
// TODO: 区分支付货币和支付方式
|
|
133
|
+
});
|
|
134
|
+
const DID_DOMAIN_SUFFIX = "did.abtnet.io";
|
|
135
|
+
const REDEEM_NFT_ID = "redeem";
|
|
136
|
+
const INSTANCE_MAX_NAME_LENGTH = 30;
|
|
137
|
+
const INSTANCE_MAX_DESC_LENGTH = 50;
|
|
138
|
+
const LAUNCH_TYPE = {
|
|
139
|
+
instant: "instant",
|
|
140
|
+
redeem: "redeem"
|
|
141
|
+
};
|
|
142
|
+
const CURRENCY_TYPE = {
|
|
143
|
+
fiat: "fiat",
|
|
144
|
+
crypto: "crypto"
|
|
145
|
+
};
|
|
146
|
+
const SERVERLESS_RETAIN_DAYS = 30;
|
|
147
|
+
exports.APP_TYPE = APP_TYPE;
|
|
148
|
+
exports.BLOCKLET_SERVER_OWNERSHIP_NFT = BLOCKLET_SERVER_OWNERSHIP_NFT;
|
|
149
|
+
exports.CURRENCY_TYPE = CURRENCY_TYPE;
|
|
150
|
+
exports.DID_DOMAIN_SUFFIX = DID_DOMAIN_SUFFIX;
|
|
151
|
+
exports.INSTANCE_MAX_DESC_LENGTH = INSTANCE_MAX_DESC_LENGTH;
|
|
152
|
+
exports.INSTANCE_MAX_NAME_LENGTH = INSTANCE_MAX_NAME_LENGTH;
|
|
153
|
+
exports.INSTANCE_STATUS = INSTANCE_STATUS;
|
|
154
|
+
exports.LAUNCH_ACTIVITY_TYPE = LAUNCH_ACTIVITY_TYPE;
|
|
155
|
+
exports.LAUNCH_STATUS = LAUNCH_STATUS;
|
|
156
|
+
exports.LAUNCH_TYPE = LAUNCH_TYPE;
|
|
157
|
+
exports.NFT_TYPE_SERVERLESS = NFT_TYPE_SERVERLESS;
|
|
158
|
+
exports.PAYMENT_METHODS = PAYMENT_METHODS;
|
|
159
|
+
exports.PAYMENT_STATUS = PAYMENT_STATUS;
|
|
160
|
+
exports.PAYMENT_TYPES = PAYMENT_TYPES;
|
|
161
|
+
exports.PLAN_STATUS = PLAN_STATUS;
|
|
162
|
+
exports.REDEEM_NFT_ID = REDEEM_NFT_ID;
|
|
163
|
+
exports.SERVERLESS_INSTANCE_STATUS = SERVERLESS_INSTANCE_STATUS;
|
|
164
|
+
exports.SERVERLESS_RETAIN_DAYS = SERVERLESS_RETAIN_DAYS;
|
|
165
|
+
exports.SERVER_ACTIVITY_TYPE = SERVER_ACTIVITY_TYPE;
|
|
166
|
+
exports.SKU_STATUS = SKU_STATUS;
|
|
167
|
+
exports.TIME_LOCALE = TIME_LOCALE;
|
|
168
|
+
exports.fromInstanceStatus = fromInstanceStatus;
|
|
169
|
+
exports.fromPlanStatus = fromPlanStatus;
|
package/lib/format-error.js
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const formatError = (err) => {
|
|
3
|
+
var _a;
|
|
2
4
|
if (!err) {
|
|
3
5
|
return err;
|
|
4
6
|
}
|
|
5
|
-
|
|
6
7
|
const { details, errors, response } = err;
|
|
7
|
-
|
|
8
|
-
// graphql error
|
|
9
8
|
if (Array.isArray(errors)) {
|
|
10
|
-
return errors.map((x) => x.message).join(
|
|
9
|
+
return errors.map((x) => x.message).join("\n");
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
// joi validate error
|
|
14
11
|
if (Array.isArray(details)) {
|
|
15
12
|
const formatted = details.map((e) => {
|
|
16
13
|
const errorMessage = e.message.replace(/["]/g, "'");
|
|
17
|
-
const errorPath = e.path.join(
|
|
14
|
+
const errorPath = e.path.join(".");
|
|
18
15
|
return `${errorPath}: ${errorMessage}`;
|
|
19
16
|
});
|
|
20
|
-
|
|
21
|
-
return `Validate failed: ${formatted.join(';')}`;
|
|
17
|
+
return `Validate failed: ${formatted.join(";")}`;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
// axios error
|
|
25
19
|
if (response) {
|
|
26
|
-
return (
|
|
27
|
-
response.data.error ||
|
|
28
|
-
`Request failed: ${response.status} ${response.statusText}: ${JSON.stringify(response.data)}`
|
|
29
|
-
);
|
|
20
|
+
return ((_a = response.data) == null ? void 0 : _a.error) || `Request failed: ${response.status} ${response.statusText}: ${JSON.stringify(response.data)}`;
|
|
30
21
|
}
|
|
31
|
-
|
|
32
22
|
return err.message || err;
|
|
33
23
|
};
|
|
34
|
-
|
|
35
24
|
module.exports = formatError;
|
package/lib/get-asset.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const joinUrl = require("url-join");
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const get = require("lodash.get");
|
|
5
5
|
const getAsset = async (chainHost, address) => {
|
|
6
|
-
const url = joinUrl(new URL(chainHost).origin,
|
|
7
|
-
|
|
6
|
+
const url = joinUrl(new URL(chainHost).origin, "/api/gql/");
|
|
8
7
|
const result = await axios.post(
|
|
9
8
|
url,
|
|
10
9
|
JSON.stringify({
|
|
@@ -26,23 +25,20 @@ const getAsset = async (chainHost, address) => {
|
|
|
26
25
|
tags
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
|
-
}
|
|
28
|
+
}`
|
|
30
29
|
}),
|
|
31
30
|
{
|
|
32
31
|
headers: {
|
|
33
|
-
|
|
34
|
-
Accept:
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
Accept: "application/json"
|
|
35
34
|
},
|
|
36
|
-
timeout: 60 *
|
|
35
|
+
timeout: 60 * 1e3
|
|
37
36
|
}
|
|
38
37
|
);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (state && state.data.typeUrl === 'json') {
|
|
38
|
+
const state = get(result, "data.data.getAssetState.state");
|
|
39
|
+
if (state && state.data.typeUrl === "json") {
|
|
42
40
|
state.data.value = JSON.parse(state.data.value);
|
|
43
41
|
}
|
|
44
|
-
|
|
45
42
|
return state;
|
|
46
43
|
};
|
|
47
|
-
|
|
48
44
|
module.exports = getAsset;
|
package/lib/locale/en.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const flat = require("flat");
|
|
3
|
+
const constant = require("../constant");
|
|
4
|
+
const en = flat({
|
|
5
5
|
common: {
|
|
6
|
-
app:
|
|
7
|
-
billing:
|
|
8
|
-
duration:
|
|
9
|
-
spaceName:
|
|
6
|
+
app: "App",
|
|
7
|
+
billing: "Billing",
|
|
8
|
+
duration: "Duration",
|
|
9
|
+
spaceName: "Space Name"
|
|
10
10
|
},
|
|
11
11
|
serverlessInstance: {
|
|
12
12
|
appStatus: {
|
|
13
|
-
[SERVERLESS_INSTANCE_STATUS.launching]:
|
|
14
|
-
[SERVERLESS_INSTANCE_STATUS.running]:
|
|
15
|
-
[SERVERLESS_INSTANCE_STATUS.expired]:
|
|
16
|
-
[SERVERLESS_INSTANCE_STATUS.terminated]:
|
|
17
|
-
}
|
|
13
|
+
[constant.SERVERLESS_INSTANCE_STATUS.launching]: "Launching",
|
|
14
|
+
[constant.SERVERLESS_INSTANCE_STATUS.running]: "Running",
|
|
15
|
+
[constant.SERVERLESS_INSTANCE_STATUS.expired]: "Expired",
|
|
16
|
+
[constant.SERVERLESS_INSTANCE_STATUS.terminated]: "Terminated"
|
|
17
|
+
}
|
|
18
18
|
},
|
|
19
19
|
dedicatedInstance: {
|
|
20
20
|
appStatus: {
|
|
21
|
-
[INSTANCE_STATUS.unknown]:
|
|
22
|
-
[INSTANCE_STATUS.pending]:
|
|
23
|
-
[INSTANCE_STATUS.starting]:
|
|
24
|
-
[INSTANCE_STATUS.running]:
|
|
25
|
-
[INSTANCE_STATUS.restarting]:
|
|
26
|
-
[INSTANCE_STATUS.stopping]:
|
|
27
|
-
[INSTANCE_STATUS.stopped]:
|
|
28
|
-
[INSTANCE_STATUS.terminated]:
|
|
29
|
-
[INSTANCE_STATUS.expired]:
|
|
30
|
-
[INSTANCE_STATUS.error]:
|
|
31
|
-
[INSTANCE_STATUS.waiting]:
|
|
32
|
-
[INSTANCE_STATUS.underMaintenance]:
|
|
33
|
-
}
|
|
21
|
+
[constant.INSTANCE_STATUS.unknown]: "Unknown",
|
|
22
|
+
[constant.INSTANCE_STATUS.pending]: "Pending",
|
|
23
|
+
[constant.INSTANCE_STATUS.starting]: "Starting",
|
|
24
|
+
[constant.INSTANCE_STATUS.running]: "Running",
|
|
25
|
+
[constant.INSTANCE_STATUS.restarting]: "Restarting",
|
|
26
|
+
[constant.INSTANCE_STATUS.stopping]: "Stopping",
|
|
27
|
+
[constant.INSTANCE_STATUS.stopped]: "Stopped",
|
|
28
|
+
[constant.INSTANCE_STATUS.terminated]: "Terminated",
|
|
29
|
+
[constant.INSTANCE_STATUS.expired]: "Expired",
|
|
30
|
+
[constant.INSTANCE_STATUS.error]: "Error",
|
|
31
|
+
[constant.INSTANCE_STATUS.waiting]: "Waiting",
|
|
32
|
+
[constant.INSTANCE_STATUS.underMaintenance]: "Under-Maintenance"
|
|
33
|
+
}
|
|
34
34
|
},
|
|
35
35
|
paymentMethod: {
|
|
36
|
-
[PAYMENT_METHODS.crypto]:
|
|
37
|
-
[PAYMENT_METHODS.stripe]:
|
|
38
|
-
[CURRENCY_TYPE.fiat]:
|
|
39
|
-
[CURRENCY_TYPE.crypto]:
|
|
40
|
-
}
|
|
36
|
+
[constant.PAYMENT_METHODS.crypto]: "Crypto",
|
|
37
|
+
[constant.PAYMENT_METHODS.stripe]: "Credit",
|
|
38
|
+
[constant.CURRENCY_TYPE.fiat]: "Credit",
|
|
39
|
+
[constant.CURRENCY_TYPE.crypto]: "Crypto"
|
|
40
|
+
}
|
|
41
41
|
});
|
|
42
|
+
module.exports = en;
|
package/lib/locale/index.js
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 翻译函数
|
|
9
|
-
* @param {string} key
|
|
10
|
-
* @param {string} locale
|
|
11
|
-
* @param {object} [params]
|
|
12
|
-
* @returns {string}
|
|
13
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
const index = (locales) => {
|
|
3
|
+
const replace = (template, data) => (template || "").replace(
|
|
4
|
+
/{(\w*)}/g,
|
|
5
|
+
(_, key) => Object.prototype.hasOwnProperty.call(data || {}, key) ? data[key] : ""
|
|
6
|
+
);
|
|
14
7
|
const translate = (key, locale, params) => {
|
|
15
8
|
if (!locales[locale]) {
|
|
16
|
-
|
|
17
|
-
locale = 'en';
|
|
9
|
+
locale = "en";
|
|
18
10
|
}
|
|
19
|
-
|
|
20
11
|
return replace(locales[locale][key], params) || key;
|
|
21
12
|
};
|
|
22
|
-
|
|
23
|
-
const createTranslateFunc = (locale) => (key, params) => translate(key, locale || 'en', params);
|
|
24
|
-
|
|
13
|
+
const createTranslateFunc = (locale) => (key, params) => translate(key, locale || "en", params);
|
|
25
14
|
return { translate, createTranslateFunc };
|
|
26
15
|
};
|
|
16
|
+
module.exports = index;
|
package/lib/locale/zh.js
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const flat = require("flat");
|
|
3
|
+
const constant = require("../constant");
|
|
4
|
+
const zh = flat({
|
|
5
5
|
common: {
|
|
6
|
-
app:
|
|
7
|
-
billing:
|
|
8
|
-
duration:
|
|
9
|
-
spaceName:
|
|
6
|
+
app: "应用",
|
|
7
|
+
billing: "账单",
|
|
8
|
+
duration: "时长",
|
|
9
|
+
spaceName: "应用空间"
|
|
10
10
|
},
|
|
11
11
|
serverlessInstance: {
|
|
12
12
|
appStatus: {
|
|
13
|
-
[SERVERLESS_INSTANCE_STATUS.launching]:
|
|
14
|
-
[SERVERLESS_INSTANCE_STATUS.running]:
|
|
15
|
-
[SERVERLESS_INSTANCE_STATUS.expired]:
|
|
16
|
-
[SERVERLESS_INSTANCE_STATUS.terminated]:
|
|
17
|
-
}
|
|
13
|
+
[constant.SERVERLESS_INSTANCE_STATUS.launching]: "启动中",
|
|
14
|
+
[constant.SERVERLESS_INSTANCE_STATUS.running]: "运行中",
|
|
15
|
+
[constant.SERVERLESS_INSTANCE_STATUS.expired]: "已过期",
|
|
16
|
+
[constant.SERVERLESS_INSTANCE_STATUS.terminated]: "已终止"
|
|
17
|
+
}
|
|
18
18
|
},
|
|
19
19
|
dedicatedInstance: {
|
|
20
20
|
appStatus: {
|
|
21
|
-
[INSTANCE_STATUS.unknown]:
|
|
22
|
-
[INSTANCE_STATUS.pending]:
|
|
23
|
-
[INSTANCE_STATUS.starting]:
|
|
24
|
-
[INSTANCE_STATUS.running]:
|
|
25
|
-
[INSTANCE_STATUS.restarting]:
|
|
26
|
-
[INSTANCE_STATUS.stopping]:
|
|
27
|
-
[INSTANCE_STATUS.stopped]:
|
|
28
|
-
[INSTANCE_STATUS.terminated]:
|
|
29
|
-
[INSTANCE_STATUS.expired]:
|
|
30
|
-
[INSTANCE_STATUS.error]:
|
|
31
|
-
[INSTANCE_STATUS.waiting]:
|
|
32
|
-
[INSTANCE_STATUS.underMaintenance]:
|
|
33
|
-
}
|
|
21
|
+
[constant.INSTANCE_STATUS.unknown]: "未知",
|
|
22
|
+
[constant.INSTANCE_STATUS.pending]: "待处理",
|
|
23
|
+
[constant.INSTANCE_STATUS.starting]: "启动中",
|
|
24
|
+
[constant.INSTANCE_STATUS.running]: "运行中",
|
|
25
|
+
[constant.INSTANCE_STATUS.restarting]: "重启中",
|
|
26
|
+
[constant.INSTANCE_STATUS.stopping]: "停止中",
|
|
27
|
+
[constant.INSTANCE_STATUS.stopped]: "已停止",
|
|
28
|
+
[constant.INSTANCE_STATUS.terminated]: "已终止",
|
|
29
|
+
[constant.INSTANCE_STATUS.expired]: "已过期",
|
|
30
|
+
[constant.INSTANCE_STATUS.error]: "错误",
|
|
31
|
+
[constant.INSTANCE_STATUS.waiting]: "等待中",
|
|
32
|
+
[constant.INSTANCE_STATUS.underMaintenance]: "维护中"
|
|
33
|
+
}
|
|
34
34
|
},
|
|
35
35
|
paymentMethod: {
|
|
36
|
-
[PAYMENT_METHODS.crypto]:
|
|
37
|
-
[PAYMENT_METHODS.stripe]:
|
|
38
|
-
[CURRENCY_TYPE.fiat]:
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
[constant.PAYMENT_METHODS.crypto]: "加密货币",
|
|
37
|
+
[constant.PAYMENT_METHODS.stripe]: "信用卡",
|
|
38
|
+
[constant.CURRENCY_TYPE.fiat]: "信用卡",
|
|
39
|
+
// TODO: 统一管理支付方式和货币类型
|
|
40
|
+
[constant.CURRENCY_TYPE.crypto]: "加密货币"
|
|
41
|
+
// TODO: 统一管理支付方式和货币类型
|
|
42
|
+
}
|
|
41
43
|
});
|
|
44
|
+
module.exports = zh;
|
package/lib/middleware.js
CHANGED
|
@@ -1,86 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const pick = require("lodash.pick");
|
|
4
|
+
const util = require("./util");
|
|
5
5
|
const MAX_PAGING_SIZE = 100;
|
|
6
6
|
const DEFAULT_PAGING_SIZE = MAX_PAGING_SIZE;
|
|
7
7
|
const DEFAULT_PAGE = 1;
|
|
8
|
-
|
|
9
8
|
const pagination = (req, res, next) => {
|
|
10
9
|
const paging = {
|
|
11
10
|
page: DEFAULT_PAGE,
|
|
12
|
-
size: DEFAULT_PAGING_SIZE
|
|
11
|
+
size: DEFAULT_PAGING_SIZE
|
|
13
12
|
};
|
|
14
13
|
req.paging = paging;
|
|
15
|
-
|
|
16
14
|
if (!Number.isNaN(Number(req.query.page))) {
|
|
17
15
|
paging.page = Number(req.query.page);
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
if (!Number.isNaN(Number(req.query.size))) {
|
|
21
18
|
const size = Number(req.query.size);
|
|
22
19
|
paging.size = size <= MAX_PAGING_SIZE ? size : MAX_PAGING_SIZE;
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
paging.sort = getSort(req.query.sortby, req.query.sortdir);
|
|
26
|
-
|
|
21
|
+
paging.sort = util.getSort(req.query.sortby, req.query.sortdir);
|
|
27
22
|
next();
|
|
28
23
|
};
|
|
29
|
-
|
|
30
|
-
const validate
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
user: { ...pick(req.user, ['did', 'role', 'fullName']) },
|
|
59
|
-
id: formater.id,
|
|
60
|
-
resource: formater.resource,
|
|
61
|
-
payload: formater.format({ req, res }),
|
|
62
|
-
ip: req.get('x-Real-ip', ''),
|
|
63
|
-
ua: req.get('user-agent', ''),
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
writer(data);
|
|
67
|
-
}
|
|
24
|
+
const validate = (schema, option = {}) => (req, res, next) => {
|
|
25
|
+
const { error, value } = schema.validate(req.body, {
|
|
26
|
+
errors: { language: req.query.locale || "en" },
|
|
27
|
+
...option
|
|
28
|
+
});
|
|
29
|
+
if (error) {
|
|
30
|
+
res.status(400).json({ error: error.message });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
req.data = value;
|
|
34
|
+
next();
|
|
35
|
+
};
|
|
36
|
+
const createAuditMiddleware = ({ baseURL, writer, formatterMap }) => (req, res, next) => {
|
|
37
|
+
if (["PUT", "POST", "PATCH", "DELETE"].includes(req.method)) {
|
|
38
|
+
const originalResponse = res.end.bind(res);
|
|
39
|
+
const wrappedResponse = (...args) => {
|
|
40
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
41
|
+
const key = `${req.baseUrl}${req.route.path}`.replace(baseURL, req.method.toLowerCase());
|
|
42
|
+
const formater = formatterMap[key];
|
|
43
|
+
if (formater) {
|
|
44
|
+
const data = {
|
|
45
|
+
user: { ...pick(req.user, ["did", "role", "fullName"]) },
|
|
46
|
+
id: formater.id,
|
|
47
|
+
resource: formater.resource,
|
|
48
|
+
payload: formater.format({ req, res }),
|
|
49
|
+
ip: req.get("x-Real-ip", ""),
|
|
50
|
+
ua: req.get("user-agent", "")
|
|
51
|
+
};
|
|
52
|
+
writer(data);
|
|
68
53
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
next();
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
module.exports = {
|
|
80
|
-
createAuditMiddleware,
|
|
81
|
-
pagination,
|
|
82
|
-
validate,
|
|
83
|
-
DEFAULT_PAGE,
|
|
84
|
-
MAX_PAGING_SIZE,
|
|
85
|
-
DEFAULT_PAGING_SIZE,
|
|
54
|
+
}
|
|
55
|
+
return originalResponse(...args);
|
|
56
|
+
};
|
|
57
|
+
res.end = wrappedResponse;
|
|
58
|
+
}
|
|
59
|
+
next();
|
|
86
60
|
};
|
|
61
|
+
exports.DEFAULT_PAGE = DEFAULT_PAGE;
|
|
62
|
+
exports.DEFAULT_PAGING_SIZE = DEFAULT_PAGING_SIZE;
|
|
63
|
+
exports.MAX_PAGING_SIZE = MAX_PAGING_SIZE;
|
|
64
|
+
exports.createAuditMiddleware = createAuditMiddleware;
|
|
65
|
+
exports.pagination = pagination;
|
|
66
|
+
exports.validate = validate;
|
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const BlockletNotification = require("@blocklet/sdk/service/notification");
|
|
3
3
|
class Notification {
|
|
4
4
|
constructor({ logger, auth }) {
|
|
5
5
|
this.auth = auth;
|
|
6
|
-
// eslint-disable-next-line no-console
|
|
7
6
|
this.logger = logger || { info: console.info, error: console.error };
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
async sendNotification({ to, title, message, actions, attachments = [], assetAddress }) {
|
|
11
9
|
try {
|
|
12
10
|
const payload = { title, body: message, actions: actions || [], attachments: [...attachments] };
|
|
13
|
-
|
|
14
|
-
if (typeof assetAddress !== 'undefined') {
|
|
11
|
+
if (typeof assetAddress !== "undefined") {
|
|
15
12
|
payload.attachments.push({
|
|
16
|
-
type:
|
|
13
|
+
type: "asset",
|
|
17
14
|
data: {
|
|
18
15
|
chainHost: this.auth.chainHost,
|
|
19
|
-
did: assetAddress
|
|
20
|
-
}
|
|
16
|
+
did: assetAddress
|
|
17
|
+
}
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
await BlockletNotification.sendToUser(to, payload);
|
|
25
|
-
|
|
26
|
-
this.logger.info('text message was sent', { to, payload: JSON.stringify(payload, null, 2) });
|
|
21
|
+
this.logger.info("text message was sent", { to, payload: JSON.stringify(payload, null, 2) });
|
|
27
22
|
} catch (error) {
|
|
28
|
-
this.logger.error(
|
|
23
|
+
this.logger.error("send text message failed", { error, to, message, actions, attachments });
|
|
29
24
|
throw error;
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
module.exports = Notification;
|
package/lib/permission.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ADMIN_ROLES = ["owner", "admin"];
|
|
3
4
|
const canAccessAdmin = (role) => ADMIN_ROLES.includes(role);
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
canAccessAdmin,
|
|
7
|
-
};
|
|
5
|
+
exports.canAccessAdmin = canAccessAdmin;
|
package/lib/util.js
CHANGED
|
@@ -1,172 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
require("moment-timezone");
|
|
4
|
+
require("moment/locale/zh-cn");
|
|
5
|
+
const moment = require("moment");
|
|
6
|
+
const joinURL = require("url-join");
|
|
7
|
+
const get = require("lodash.get");
|
|
8
|
+
const constant = require("./constant");
|
|
8
9
|
const formatPeriod = (duration) => {
|
|
9
10
|
const value = Number(duration.slice(0, duration.length - 1));
|
|
10
11
|
const unit = duration[duration.length - 1];
|
|
11
|
-
|
|
12
12
|
return { value, unit };
|
|
13
13
|
};
|
|
14
|
-
|
|
15
14
|
const prettyDurationUnit = ({ value, unit }, locale) => {
|
|
16
|
-
if (!Object.keys(TIME_LOCALE).includes(locale)) {
|
|
17
|
-
|
|
18
|
-
locale = 'en';
|
|
15
|
+
if (!Object.keys(constant.TIME_LOCALE).includes(locale)) {
|
|
16
|
+
locale = "en";
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
const localeKey = value > 1 ? `${unit}s` : unit;
|
|
22
|
-
return TIME_LOCALE[locale][localeKey.toLowerCase()];
|
|
19
|
+
return constant.TIME_LOCALE[locale][localeKey.toLowerCase()];
|
|
23
20
|
};
|
|
24
|
-
|
|
25
21
|
const prettyDuration = (duration, locale) => {
|
|
26
22
|
if (!duration) {
|
|
27
|
-
return
|
|
23
|
+
return "";
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
const { value, unit } = duration;
|
|
31
26
|
return `${value}${prettyDurationUnit({ value, unit }, locale)}`;
|
|
32
27
|
};
|
|
33
|
-
|
|
34
|
-
const formatDatetime = (time, locale = 'en-us', timezone = Intl.DateTimeFormat().resolvedOptions().timeZone) => {
|
|
35
|
-
/* eslint-disable no-param-reassign */
|
|
28
|
+
const formatDatetime = (time, locale = "en-us", timezone = Intl.DateTimeFormat().resolvedOptions().timeZone) => {
|
|
36
29
|
if (!time) {
|
|
37
|
-
return
|
|
30
|
+
return "";
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
locale
|
|
41
|
-
|
|
42
|
-
locale = 'zh-cn';
|
|
32
|
+
locale = locale || "en-us";
|
|
33
|
+
if (locale === "zh") {
|
|
34
|
+
locale = "zh-cn";
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
try {
|
|
46
|
-
return moment(time).locale(locale).tz(timezone).format(
|
|
37
|
+
return moment(time).locale(locale).tz(timezone).format("LLL zz");
|
|
47
38
|
} catch (error) {
|
|
48
39
|
console.error(`formate date time "${time}" error`, error);
|
|
49
|
-
return
|
|
40
|
+
return "";
|
|
50
41
|
}
|
|
51
42
|
};
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (moment(v1).diff(moment(v2)) > 0) {
|
|
70
|
-
return directionResult;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return -1 * directionResult;
|
|
74
|
-
});
|
|
75
|
-
|
|
43
|
+
const formatUtcDatetime = (time, locale = "en-us") => formatDatetime(time, locale, "UTC");
|
|
44
|
+
const sortArrayByDate = (array, asc = true, field = void 0) => (array || []).sort((x, y) => {
|
|
45
|
+
let v1 = x;
|
|
46
|
+
let v2 = y;
|
|
47
|
+
if (typeof field !== "undefined") {
|
|
48
|
+
v1 = v1[field];
|
|
49
|
+
v2 = v2[field];
|
|
50
|
+
}
|
|
51
|
+
if (v1 === v2) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
const directionResult = asc ? 1 : -1;
|
|
55
|
+
if (moment(v1).diff(moment(v2)) > 0) {
|
|
56
|
+
return directionResult;
|
|
57
|
+
}
|
|
58
|
+
return -1 * directionResult;
|
|
59
|
+
});
|
|
76
60
|
const getSort = (sortby, sortdir) => {
|
|
77
|
-
if (sortby && sortby !==
|
|
61
|
+
if (sortby && sortby !== "undefined") {
|
|
78
62
|
return { [sortby]: sortdir };
|
|
79
63
|
}
|
|
80
|
-
|
|
81
64
|
return { createdAt: -1 };
|
|
82
65
|
};
|
|
83
|
-
|
|
84
|
-
const getExplorerUrl = ({ address, type = 'txs', chainHost }) => {
|
|
66
|
+
const getExplorerUrl = ({ address, type = "txs", chainHost }) => {
|
|
85
67
|
return `https://explorer.abtnetwork.io/explorer/${type}/${address}?host=${chainHost}`;
|
|
86
68
|
};
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
const getBlockletAdminURL = (appURL) => joinURL(appURL, '/.well-known/service/admin/overview');
|
|
91
|
-
|
|
69
|
+
const getBlockletDisplayName = (blocklet) => get(blocklet, "title") || get(blocklet, "name") || "";
|
|
70
|
+
const getBlockletAdminURL = (appURL) => joinURL(appURL, "/.well-known/service/admin/overview");
|
|
92
71
|
const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
|
|
93
|
-
|
|
94
72
|
const getContinueLaunchURL = ({ baseURL, launch }) => {
|
|
95
73
|
const urlObject = new URL(baseURL);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
urlObject.searchParams.set(
|
|
99
|
-
urlObject.searchParams.set('blocklet_meta_url', launch.blockletMetaUrl);
|
|
100
|
-
|
|
74
|
+
if (launch.status < constant.LAUNCH_STATUS.paid) {
|
|
75
|
+
urlObject.searchParams.set("sessionId", launch._id);
|
|
76
|
+
urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
|
|
101
77
|
return urlObject.href;
|
|
102
78
|
}
|
|
103
|
-
|
|
104
|
-
if (launch.status >= LAUNCH_STATUS.paid && launch.status < LAUNCH_STATUS.installed) {
|
|
79
|
+
if (launch.status >= constant.LAUNCH_STATUS.paid && launch.status < constant.LAUNCH_STATUS.installed) {
|
|
105
80
|
urlObject.pathname = joinURL(urlObject.pathname, `/launch/${launch.nftDid}`);
|
|
106
|
-
|
|
107
|
-
urlObject.searchParams.set(
|
|
108
|
-
urlObject.searchParams.set(
|
|
109
|
-
urlObject.searchParams.set('launchType', launch.type);
|
|
110
|
-
|
|
81
|
+
urlObject.searchParams.set("sessionId", launch._id);
|
|
82
|
+
urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
|
|
83
|
+
urlObject.searchParams.set("launchType", launch.type);
|
|
111
84
|
if (launch.from) {
|
|
112
|
-
urlObject.searchParams.set(
|
|
85
|
+
urlObject.searchParams.set("from", launch.from);
|
|
113
86
|
}
|
|
114
|
-
|
|
115
87
|
return urlObject.href;
|
|
116
88
|
}
|
|
117
|
-
|
|
118
|
-
return '';
|
|
89
|
+
return "";
|
|
119
90
|
};
|
|
120
|
-
|
|
121
91
|
const getBlockletMetaUrlFromQuery = (query) => {
|
|
122
|
-
|
|
123
|
-
const url = (query.get('blocklet_meta_url') || query.get('meta_url') || '').trim();
|
|
92
|
+
const url = (query.get("blocklet_meta_url") || query.get("meta_url") || "").trim();
|
|
124
93
|
return decodeURIComponent(url);
|
|
125
94
|
};
|
|
126
|
-
|
|
127
95
|
const getRegistryUrlFromBlockletMetaUrl = (blockletMetaUrl) => {
|
|
128
96
|
try {
|
|
129
|
-
return blockletMetaUrl ? new URL(blockletMetaUrl).origin :
|
|
97
|
+
return blockletMetaUrl ? new URL(blockletMetaUrl).origin : "";
|
|
130
98
|
} catch (error) {
|
|
131
|
-
console.error(
|
|
132
|
-
return
|
|
99
|
+
console.error("get registry url from blocklet meta url error:", error);
|
|
100
|
+
return "";
|
|
133
101
|
}
|
|
134
102
|
};
|
|
135
|
-
|
|
136
103
|
const formatRegistryLogoPath = (did, asset) => {
|
|
137
|
-
if (asset.startsWith(
|
|
104
|
+
if (asset.startsWith("/assets")) {
|
|
138
105
|
return asset;
|
|
139
106
|
}
|
|
140
|
-
|
|
141
107
|
return `/assets/${did}/${asset}`;
|
|
142
108
|
};
|
|
143
|
-
|
|
144
109
|
const getBlockletLogoUrl = ({ did, baseUrl, logoPath }) => {
|
|
145
|
-
if (logoPath && logoPath.startsWith(
|
|
110
|
+
if (logoPath && logoPath.startsWith("http")) {
|
|
146
111
|
return logoPath;
|
|
147
112
|
}
|
|
148
|
-
|
|
149
|
-
if (baseUrl.startsWith('http') && logoPath) {
|
|
113
|
+
if (baseUrl.startsWith("http") && logoPath) {
|
|
150
114
|
return joinURL(baseUrl, formatRegistryLogoPath(did, logoPath));
|
|
151
115
|
}
|
|
152
|
-
|
|
153
|
-
return '';
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
module.exports = {
|
|
157
|
-
formatPeriod,
|
|
158
|
-
prettyDurationUnit,
|
|
159
|
-
prettyDuration,
|
|
160
|
-
formatDatetime,
|
|
161
|
-
formatUtcDatetime,
|
|
162
|
-
isDateExpired,
|
|
163
|
-
sortArrayByDate,
|
|
164
|
-
getSort,
|
|
165
|
-
getExplorerUrl,
|
|
166
|
-
getBlockletDisplayName,
|
|
167
|
-
getBlockletAdminURL,
|
|
168
|
-
getContinueLaunchURL,
|
|
169
|
-
getBlockletMetaUrlFromQuery,
|
|
170
|
-
getRegistryUrlFromBlockletMetaUrl,
|
|
171
|
-
getBlockletLogoUrl,
|
|
116
|
+
return "";
|
|
172
117
|
};
|
|
118
|
+
exports.formatDatetime = formatDatetime;
|
|
119
|
+
exports.formatPeriod = formatPeriod;
|
|
120
|
+
exports.formatUtcDatetime = formatUtcDatetime;
|
|
121
|
+
exports.getBlockletAdminURL = getBlockletAdminURL;
|
|
122
|
+
exports.getBlockletDisplayName = getBlockletDisplayName;
|
|
123
|
+
exports.getBlockletLogoUrl = getBlockletLogoUrl;
|
|
124
|
+
exports.getBlockletMetaUrlFromQuery = getBlockletMetaUrlFromQuery;
|
|
125
|
+
exports.getContinueLaunchURL = getContinueLaunchURL;
|
|
126
|
+
exports.getExplorerUrl = getExplorerUrl;
|
|
127
|
+
exports.getRegistryUrlFromBlockletMetaUrl = getRegistryUrlFromBlockletMetaUrl;
|
|
128
|
+
exports.getSort = getSort;
|
|
129
|
+
exports.isDateExpired = isDateExpired;
|
|
130
|
+
exports.prettyDuration = prettyDuration;
|
|
131
|
+
exports.prettyDurationUnit = prettyDurationUnit;
|
|
132
|
+
exports.sortArrayByDate = sortArrayByDate;
|
package/lib/validator.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
3
|
const create = (schema) => (data, locale) => {
|
|
2
|
-
const { error, value } = schema.validate(data, { errors: { language: locale ||
|
|
4
|
+
const { error, value } = schema.validate(data, { errors: { language: locale || "en" } });
|
|
3
5
|
if (error) {
|
|
4
6
|
throw new Error(error.message);
|
|
5
7
|
}
|
|
6
|
-
|
|
7
8
|
return value;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
module.exports = { create };
|
|
10
|
+
exports.create = create;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/launcher-util",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Common constants",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"constant"
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"url": "git+https://github.com/blocklet/launcher.git"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"
|
|
26
|
+
"build": "vite build",
|
|
27
|
+
"watch": "vite build --watch",
|
|
28
|
+
"lint": "eslint src",
|
|
27
29
|
"lint:fix": "npm run lint -- --fix",
|
|
28
30
|
"test": "node jest.js --runInBand",
|
|
29
31
|
"coverage": "npm run test -- --coverage"
|
|
@@ -44,7 +46,9 @@
|
|
|
44
46
|
"url-join": "^4.0.1"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"jest": "^27.5.1"
|
|
49
|
+
"jest": "^27.5.1",
|
|
50
|
+
"vite": "^4.4.9",
|
|
51
|
+
"vite-plugin-build": "^0.10.0"
|
|
48
52
|
},
|
|
49
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "53a48bfa25be13fd526aea6c361b6c862506721c"
|
|
50
54
|
}
|