@blocklet/launcher-util 2.3.139 → 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/lib/locale/en.js CHANGED
@@ -1,89 +1 @@
1
- "use strict";
2
- const flat = require("flat");
3
- const constant = require("../constant");
4
- const en = flat({
5
- common: {
6
- app: "App",
7
- billing: "Billing",
8
- duration: "Duration",
9
- spaceName: "Space Name"
10
- },
11
- serverlessInstance: {
12
- appStatus: {
13
- added: "Added",
14
- waiting: "Waiting",
15
- downloading: "Downloading",
16
- extracting: "Extracting",
17
- installing: "Installing",
18
- upgrading: "Upgrading",
19
- installed: "Installed",
20
- created: "Created",
21
- starting: "Starting",
22
- running: "Running",
23
- stopping: "Stopping",
24
- stopped: "Stopped",
25
- error: "Error",
26
- deleting: "Deleting",
27
- corrupted: "Corrupted",
28
- purchasing: "Waiting for purchase",
29
- purchased: "Purchased",
30
- verifying: "Verifying purchase",
31
- unknown: "Unknown"
32
- }
33
- },
34
- dedicatedInstance: {
35
- appStatus: {
36
- [constant.INSTANCE_STATUS.unknown]: "Unknown",
37
- [constant.INSTANCE_STATUS.pending]: "Pending",
38
- [constant.INSTANCE_STATUS.starting]: "Starting",
39
- [constant.INSTANCE_STATUS.running]: "Running",
40
- [constant.INSTANCE_STATUS.restarting]: "Restarting",
41
- [constant.INSTANCE_STATUS.underMaintenance]: "Under-Maintenance",
42
- [constant.INSTANCE_STATUS.stopping]: "Stopping",
43
- [constant.INSTANCE_STATUS.stopped]: "Stopped",
44
- [constant.INSTANCE_STATUS.terminatedInstance]: "Instance Terminated",
45
- [constant.INSTANCE_STATUS.expired]: "Expired",
46
- [constant.INSTANCE_STATUS.error]: "Error",
47
- [constant.INSTANCE_STATUS.waiting]: "Waiting",
48
- [constant.INSTANCE_STATUS.terminated]: "Terminated"
49
- }
50
- },
51
- paymentMethod: {
52
- [constant.PAYMENT_METHODS.crypto]: "Crypto",
53
- [constant.PAYMENT_METHODS.stripe]: "Credit",
54
- [constant.CURRENCY_TYPE.fiat]: "Credit",
55
- [constant.CURRENCY_TYPE.crypto]: "Crypto"
56
- },
57
- launchSession: {
58
- installSource: "Install Source",
59
- status: {
60
- [constant.LAUNCH_STATUS.created]: "In Progress",
61
- [constant.LAUNCH_STATUS.selected]: "In Progress",
62
- [constant.LAUNCH_STATUS.connected]: "In Progress",
63
- [constant.LAUNCH_STATUS.paid]: "Paid",
64
- [constant.LAUNCH_STATUS.nftMinted]: "NFT Minted",
65
- [constant.LAUNCH_STATUS.allocated]: "Paid",
66
- [constant.LAUNCH_STATUS.consuming]: "Handling",
67
- [constant.LAUNCH_STATUS.installed]: "Installed",
68
- [constant.LAUNCH_STATUS.timeout]: "Timeout",
69
- [constant.LAUNCH_STATUS.pastDue]: "PastDue",
70
- canceling: "Canceling",
71
- [constant.LAUNCH_STATUS.canceled]: "Canceled",
72
- [constant.LAUNCH_STATUS.terminated]: "Terminated",
73
- [constant.LAUNCH_STATUS.transferred]: "Transferred",
74
- [constant.LAUNCH_STATUS.blocked]: "Blocked"
75
- },
76
- activity: {
77
- [constant.LAUNCH_ACTIVITY_TYPE.canceled]: "Canceled",
78
- [constant.LAUNCH_ACTIVITY_TYPE.pastDue]: "PastDue",
79
- [constant.LAUNCH_ACTIVITY_TYPE.terminated]: "Terminated",
80
- [constant.LAUNCH_ACTIVITY_TYPE.transferred]: "Transferred"
81
- },
82
- steps: {
83
- create: "Create",
84
- paid: "Paid",
85
- installed: "Installed"
86
- }
87
- }
88
- });
89
- module.exports = en;
1
+ "use strict";const n=require("flat"),e=require("../constant.js"),t=n({common:{app:"App",billing:"Billing",duration:"Duration",spaceName:"Space Name"},serverlessInstance:{appStatus:{added:"Added",waiting:"Waiting",downloading:"Downloading",extracting:"Extracting",installing:"Installing",upgrading:"Upgrading",installed:"Installed",created:"Created",starting:"Starting",running:"Running",stopping:"Stopping",stopped:"Stopped",error:"Error",deleting:"Deleting",corrupted:"Corrupted",purchasing:"Waiting for purchase",purchased:"Purchased",verifying:"Verifying purchase",unknown:"Unknown"}},dedicatedInstance:{appStatus:{[e.INSTANCE_STATUS.unknown]:"Unknown",[e.INSTANCE_STATUS.pending]:"Pending",[e.INSTANCE_STATUS.starting]:"Starting",[e.INSTANCE_STATUS.running]:"Running",[e.INSTANCE_STATUS.restarting]:"Restarting",[e.INSTANCE_STATUS.underMaintenance]:"Under-Maintenance",[e.INSTANCE_STATUS.stopping]:"Stopping",[e.INSTANCE_STATUS.stopped]:"Stopped",[e.INSTANCE_STATUS.terminatedInstance]:"Instance Terminated",[e.INSTANCE_STATUS.expired]:"Expired",[e.INSTANCE_STATUS.error]:"Error",[e.INSTANCE_STATUS.waiting]:"Waiting",[e.INSTANCE_STATUS.terminated]:"Terminated"}},paymentMethod:{[e.PAYMENT_METHODS.crypto]:"Crypto",[e.PAYMENT_METHODS.stripe]:"Credit",[e.CURRENCY_TYPE.fiat]:"Credit",[e.CURRENCY_TYPE.crypto]:"Crypto"},launchSession:{installSource:"Install Source",status:{[e.LAUNCH_STATUS.created]:"In Progress",[e.LAUNCH_STATUS.selected]:"In Progress",[e.LAUNCH_STATUS.connected]:"In Progress",[e.LAUNCH_STATUS.paid]:"Paid",[e.LAUNCH_STATUS.nftMinted]:"NFT Minted",[e.LAUNCH_STATUS.allocated]:"Paid",[e.LAUNCH_STATUS.consuming]:"Handling",[e.LAUNCH_STATUS.installed]:"Installed",[e.LAUNCH_STATUS.timeout]:"Timeout",[e.LAUNCH_STATUS.pastDue]:"PastDue",canceling:"Canceling",[e.LAUNCH_STATUS.canceled]:"Canceled",[e.LAUNCH_STATUS.terminated]:"Terminated",[e.LAUNCH_STATUS.transferred]:"Transferred",[e.LAUNCH_STATUS.blocked]:"Blocked"},activity:{[e.LAUNCH_ACTIVITY_TYPE.canceled]:"Canceled",[e.LAUNCH_ACTIVITY_TYPE.pastDue]:"PastDue",[e.LAUNCH_ACTIVITY_TYPE.terminated]:"Terminated",[e.LAUNCH_ACTIVITY_TYPE.transferred]:"Transferred"},steps:{create:"Create",paid:"Paid",installed:"Installed"}}});module.exports=t;
@@ -1,16 +1 @@
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
- );
7
- const translate = (key, locale, params) => {
8
- if (!locales[locale]) {
9
- locale = "en";
10
- }
11
- return replace(locales[locale][key], params) || key;
12
- };
13
- const createTranslateFunc = (locale) => (key, params) => translate(key, locale || "en", params);
14
- return { translate, createTranslateFunc };
15
- };
16
- module.exports = index;
1
+ "use strict";const p=n=>{const a=(e,t)=>(e||"").replace(/{(\w*)}/g,(r,s)=>Object.prototype.hasOwnProperty.call(t||{},s)?t[s]:""),c=(e,t,r)=>(n[t]||(t="en"),a(n[t][e],r)||e);return{translate:c,createTranslateFunc:e=>(t,r)=>c(t,e||"en",r)}};module.exports=p;
package/lib/locale/zh.js CHANGED
@@ -1,91 +1 @@
1
- "use strict";
2
- const flat = require("flat");
3
- const constant = require("../constant");
4
- const zh = flat({
5
- common: {
6
- app: "应用",
7
- billing: "账单",
8
- duration: "时长",
9
- spaceName: "应用空间"
10
- },
11
- serverlessInstance: {
12
- appStatus: {
13
- added: "已添加",
14
- waiting: "等待中",
15
- downloading: "下载中",
16
- extracting: "提取中",
17
- installing: "安装中",
18
- upgrading: "升级中",
19
- installed: "已安装",
20
- created: "已创建",
21
- starting: "启动中",
22
- running: "运行中",
23
- stopping: "停止中",
24
- stopped: "已停止",
25
- error: "错误",
26
- deleting: "删除中",
27
- corrupted: "已损坏",
28
- purchased: "已购买",
29
- purchasing: "购买中...",
30
- verifying: "验证中...",
31
- unknown: "未知状态"
32
- }
33
- },
34
- dedicatedInstance: {
35
- appStatus: {
36
- [constant.INSTANCE_STATUS.unknown]: "未知",
37
- [constant.INSTANCE_STATUS.pending]: "待处理",
38
- [constant.INSTANCE_STATUS.starting]: "启动中",
39
- [constant.INSTANCE_STATUS.running]: "运行中",
40
- [constant.INSTANCE_STATUS.restarting]: "重启中",
41
- [constant.INSTANCE_STATUS.underMaintenance]: "维护中",
42
- [constant.INSTANCE_STATUS.stopping]: "停止中",
43
- [constant.INSTANCE_STATUS.stopped]: "已停止",
44
- [constant.INSTANCE_STATUS.terminatedInstance]: "已终止实例",
45
- [constant.INSTANCE_STATUS.expired]: "已过期",
46
- [constant.INSTANCE_STATUS.error]: "错误",
47
- [constant.INSTANCE_STATUS.waiting]: "等待中",
48
- [constant.INSTANCE_STATUS.terminated]: "已终止"
49
- }
50
- },
51
- paymentMethod: {
52
- [constant.PAYMENT_METHODS.crypto]: "加密货币",
53
- [constant.PAYMENT_METHODS.stripe]: "信用卡",
54
- [constant.CURRENCY_TYPE.fiat]: "信用卡",
55
- // TODO: 统一管理支付方式和货币类型
56
- [constant.CURRENCY_TYPE.crypto]: "加密货币"
57
- // TODO: 统一管理支付方式和货币类型
58
- },
59
- launchSession: {
60
- installSource: "安装源",
61
- status: {
62
- [constant.LAUNCH_STATUS.created]: "进行中",
63
- [constant.LAUNCH_STATUS.selected]: "进行中",
64
- [constant.LAUNCH_STATUS.connected]: "进行中",
65
- [constant.LAUNCH_STATUS.paid]: "已付款",
66
- [constant.LAUNCH_STATUS.nftMinted]: "已铸造NFT",
67
- [constant.LAUNCH_STATUS.allocated]: "已付款",
68
- [constant.LAUNCH_STATUS.consuming]: "处理中",
69
- [constant.LAUNCH_STATUS.installed]: "已安装",
70
- [constant.LAUNCH_STATUS.timeout]: "已超时",
71
- [constant.LAUNCH_STATUS.pastDue]: "已欠费",
72
- canceling: "将要取消",
73
- [constant.LAUNCH_STATUS.canceled]: "已取消",
74
- [constant.LAUNCH_STATUS.terminated]: "已终止",
75
- [constant.LAUNCH_STATUS.transferred]: "已转移",
76
- [constant.LAUNCH_STATUS.blocked]: "已禁用"
77
- },
78
- activity: {
79
- [constant.LAUNCH_ACTIVITY_TYPE.canceled]: "已取消",
80
- [constant.LAUNCH_ACTIVITY_TYPE.pastDue]: "已欠费",
81
- [constant.LAUNCH_ACTIVITY_TYPE.terminated]: "已终止",
82
- [constant.LAUNCH_ACTIVITY_TYPE.transferred]: "已转移"
83
- },
84
- steps: {
85
- create: "创建",
86
- paid: "已付款",
87
- installed: "已安装"
88
- }
89
- }
90
- });
91
- module.exports = zh;
1
+ "use strict";const e=require("flat"),T=require("../constant.js"),t=e({common:{app:"应用",billing:"账单",duration:"时长",spaceName:"应用空间"},serverlessInstance:{appStatus:{added:"已添加",waiting:"等待中",downloading:"下载中",extracting:"提取中",installing:"安装中",upgrading:"升级中",installed:"已安装",created:"已创建",starting:"启动中",running:"运行中",stopping:"停止中",stopped:"已停止",error:"错误",deleting:"删除中",corrupted:"已损坏",purchased:"已购买",purchasing:"购买中...",verifying:"验证中...",unknown:"未知状态"}},dedicatedInstance:{appStatus:{[T.INSTANCE_STATUS.unknown]:"未知",[T.INSTANCE_STATUS.pending]:"待处理",[T.INSTANCE_STATUS.starting]:"启动中",[T.INSTANCE_STATUS.running]:"运行中",[T.INSTANCE_STATUS.restarting]:"重启中",[T.INSTANCE_STATUS.underMaintenance]:"维护中",[T.INSTANCE_STATUS.stopping]:"停止中",[T.INSTANCE_STATUS.stopped]:"已停止",[T.INSTANCE_STATUS.terminatedInstance]:"已终止实例",[T.INSTANCE_STATUS.expired]:"已过期",[T.INSTANCE_STATUS.error]:"错误",[T.INSTANCE_STATUS.waiting]:"等待中",[T.INSTANCE_STATUS.terminated]:"已终止"}},paymentMethod:{[T.PAYMENT_METHODS.crypto]:"加密货币",[T.PAYMENT_METHODS.stripe]:"信用卡",[T.CURRENCY_TYPE.fiat]:"信用卡",[T.CURRENCY_TYPE.crypto]:"加密货币"},launchSession:{installSource:"安装源",status:{[T.LAUNCH_STATUS.created]:"进行中",[T.LAUNCH_STATUS.selected]:"进行中",[T.LAUNCH_STATUS.connected]:"进行中",[T.LAUNCH_STATUS.paid]:"已付款",[T.LAUNCH_STATUS.nftMinted]:"已铸造NFT",[T.LAUNCH_STATUS.allocated]:"已付款",[T.LAUNCH_STATUS.consuming]:"处理中",[T.LAUNCH_STATUS.installed]:"已安装",[T.LAUNCH_STATUS.timeout]:"已超时",[T.LAUNCH_STATUS.pastDue]:"已欠费",canceling:"将要取消",[T.LAUNCH_STATUS.canceled]:"已取消",[T.LAUNCH_STATUS.terminated]:"已终止",[T.LAUNCH_STATUS.transferred]:"已转移",[T.LAUNCH_STATUS.blocked]:"已禁用"},activity:{[T.LAUNCH_ACTIVITY_TYPE.canceled]:"已取消",[T.LAUNCH_ACTIVITY_TYPE.pastDue]:"已欠费",[T.LAUNCH_ACTIVITY_TYPE.terminated]:"已终止",[T.LAUNCH_ACTIVITY_TYPE.transferred]:"已转移"},steps:{create:"创建",paid:"已付款",installed:"已安装"}}});module.exports=t;
package/lib/middleware.js CHANGED
@@ -1,40 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const util = require("./util");
4
- const MAX_PAGING_SIZE = 100;
5
- const DEFAULT_PAGING_SIZE = MAX_PAGING_SIZE;
6
- const DEFAULT_PAGE = 1;
7
- const pagination = (req, res, next) => {
8
- const paging = {
9
- page: DEFAULT_PAGE,
10
- size: DEFAULT_PAGING_SIZE
11
- };
12
- req.paging = paging;
13
- if (!Number.isNaN(Number(req.query.page))) {
14
- paging.page = Number(req.query.page);
15
- }
16
- if (!Number.isNaN(Number(req.query.size))) {
17
- const size = Number(req.query.size);
18
- paging.size = size <= MAX_PAGING_SIZE ? size : MAX_PAGING_SIZE;
19
- }
20
- paging.sort = util.getSort(req.query.sortby, req.query.sortdir);
21
- next();
22
- };
23
- const validate = (schema, option = {}) => (req, res, next) => {
24
- const { error, value } = schema.validate(req.body, {
25
- errors: { language: req.query.locale || "en" },
26
- ...option
27
- });
28
- if (error) {
29
- console.error("validate error", { error: error.message });
30
- res.status(400).json({ error: error.message });
31
- return;
32
- }
33
- req.data = value;
34
- next();
35
- };
36
- exports.DEFAULT_PAGE = DEFAULT_PAGE;
37
- exports.DEFAULT_PAGING_SIZE = DEFAULT_PAGING_SIZE;
38
- exports.MAX_PAGING_SIZE = MAX_PAGING_SIZE;
39
- exports.pagination = pagination;
40
- exports.validate = validate;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./util.js"),t=100,n=t,u=1,c=(e,i,a)=>{const r={page:u,size:n};if(e.paging=r,Number.isNaN(Number(e.query.page))||(r.page=Number(e.query.page)),!Number.isNaN(Number(e.query.size))){const s=Number(e.query.size);r.size=s<=t?s:t}r.sort=N.getSort(e.query.sortby,e.query.sortdir),a()},l=(e,i={})=>(a,r,s)=>{const{error:o,value:g}=e.validate(a.body,{errors:{language:a.query.locale||"en"},...i});if(o){console.error("validate error",{error:o.message}),r.status(400).json({error:o.message});return}a.data=g,s()};exports.DEFAULT_PAGE=u;exports.DEFAULT_PAGING_SIZE=n;exports.MAX_PAGING_SIZE=t;exports.pagination=c;exports.validate=l;
package/lib/nft.js CHANGED
@@ -1,19 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const get = require("lodash/get");
4
- const last = require("lodash/last");
5
- const constant = require("../lib/constant");
6
- const getNftExpirationDate = (asset) => last(get(asset, "data.value.expirationDate", []));
7
- const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
8
- const isNFTExpired = (asset) => {
9
- const expirationDate = getNftExpirationDate(asset);
10
- return isDateExpired(expirationDate);
11
- };
12
- const isServerlessNFT = (assetState) => {
13
- var _a;
14
- return assetState.moniker === constant.NFT_TYPE_SERVERLESS || ((_a = assetState.tags) == null ? void 0 : _a.includes(constant.NFT_TYPE_SERVERLESS));
15
- };
16
- exports.getNftExpirationDate = getNftExpirationDate;
17
- exports.isDateExpired = isDateExpired;
18
- exports.isNFTExpired = isNFTExpired;
19
- exports.isServerlessNFT = isServerlessNFT;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("lodash/get"),o=require("lodash/last"),t=require("./constant.js"),i=e=>o(n(e,"data.value.expirationDate",[])),r=e=>!!e&&new Date(e).getTime()<=Date.now(),a=e=>{const s=i(e);return r(s)},E=e=>e.moniker===t.NFT_TYPE_SERVERLESS||e.tags?.includes(t.NFT_TYPE_SERVERLESS);exports.getNftExpirationDate=i;exports.isDateExpired=r;exports.isNFTExpired=a;exports.isServerlessNFT=E;
@@ -1,28 +1 @@
1
- "use strict";
2
- const BlockletNotification = require("@blocklet/sdk/service/notification");
3
- class Notification {
4
- constructor({ logger, auth }) {
5
- this.auth = auth;
6
- this.logger = logger || { info: console.info, error: console.error };
7
- }
8
- async sendNotification({ to, title, message, actions, attachments = [], assetAddress }) {
9
- try {
10
- const payload = { title, body: message, actions: actions || [], attachments: [...attachments] };
11
- if (typeof assetAddress !== "undefined") {
12
- payload.attachments.push({
13
- type: "asset",
14
- data: {
15
- chainHost: this.auth.chainHost,
16
- did: assetAddress
17
- }
18
- });
19
- }
20
- await BlockletNotification.sendToUser(to, payload);
21
- this.logger.info("text message was sent", { to, payload: JSON.stringify(payload, null, 2) });
22
- } catch (error) {
23
- this.logger.error("send text message failed", { error, to, message, actions, attachments });
24
- throw error;
25
- }
26
- }
27
- }
28
- module.exports = Notification;
1
+ "use strict";const n=require("@blocklet/sdk/service/notification");class c{constructor({logger:o,auth:e}){this.auth=e,this.logger=o||{info:console.info,error:console.error}}async sendNotification({to:o,title:e,message:i,actions:s,attachments:r=[],assetAddress:a}){try{const t={title:e,body:i,actions:s||[],attachments:[...r]};typeof a<"u"&&t.attachments.push({type:"asset",data:{chainHost:this.auth.chainHost,did:a}}),await n.sendToUser(o,t),this.logger.info("text message was sent",{to:o,payload:JSON.stringify(t,null,2)})}catch(t){throw this.logger.error("send text message failed",{error:t,to:o,message:i,actions:s,attachments:r}),t}}}module.exports=c;
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const formatTimestamp = (timestamp) => new Date(timestamp * 1e3).toISOString();
4
- exports.formatTimestamp = formatTimestamp;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=t=>new Date(t*1e3).toISOString();exports.formatTimestamp=e;
package/lib/permission.js CHANGED
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const ADMIN_ROLES = ["owner", "admin"];
4
- const canAccessAdmin = (role) => ADMIN_ROLES.includes(role);
5
- exports.canAccessAdmin = canAccessAdmin;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=["owner","admin"],n=c=>e.includes(c);exports.canAccessAdmin=n;
package/lib/util.js CHANGED
@@ -1,190 +1 @@
1
- "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [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");
9
- const formatPeriod = (duration) => {
10
- const value = Number(duration.slice(0, duration.length - 1));
11
- const unit = duration[duration.length - 1];
12
- return { value, unit };
13
- };
14
- const prettyDurationUnit = ({ value, unit }, locale) => {
15
- if (!Object.keys(constant.TIME_LOCALE).includes(locale)) {
16
- locale = "en";
17
- }
18
- const localeKey = value > 1 ? `${unit}s` : unit;
19
- return constant.TIME_LOCALE[locale][localeKey.toLowerCase()];
20
- };
21
- const prettyDuration = (duration, locale) => {
22
- if (!duration) {
23
- return "";
24
- }
25
- const { value, unit } = duration;
26
- return `${value}${prettyDurationUnit({ value, unit }, locale)}`;
27
- };
28
- const formatDatetime = (time, locale = "en-us", timezone = Intl.DateTimeFormat().resolvedOptions().timeZone) => {
29
- if (!time) {
30
- return "";
31
- }
32
- locale = locale || "en-us";
33
- if (locale === "zh") {
34
- locale = "zh-cn";
35
- }
36
- try {
37
- return moment(time).locale(locale).tz(timezone).format("LLL zz");
38
- } catch (error) {
39
- console.error(`formate date time "${time}" error`, error);
40
- return "";
41
- }
42
- };
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
- });
60
- const getSort = (sortby, sortdir) => {
61
- if (sortby && sortby !== "undefined") {
62
- return { [sortby]: sortdir };
63
- }
64
- return { createdAt: -1 };
65
- };
66
- const getExplorerUrl = ({ address, type = "txs", chainHost }) => {
67
- return `https://explorer.abtnetwork.io/explorer/${type}/${address}?host=${chainHost}`;
68
- };
69
- const getBlockletDisplayName = (blocklet) => get(blocklet, "title") || get(blocklet, "name") || "";
70
- const getBlockletAdminURL = (appUrl) => {
71
- if (!appUrl) {
72
- return "#";
73
- }
74
- return joinURL(appUrl, "/.well-known/service/admin/overview");
75
- };
76
- const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
77
- const getContinueLaunchURL = ({ baseURL, launch }) => {
78
- const urlObject = new URL(baseURL);
79
- if (launch.status < constant.LAUNCH_STATUS.paid) {
80
- urlObject.searchParams.set("sessionId", launch.id);
81
- urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
82
- return urlObject.href;
83
- }
84
- if (launch.status >= constant.LAUNCH_STATUS.paid && launch.status < constant.LAUNCH_STATUS.consuming) {
85
- urlObject.pathname = joinURL(urlObject.pathname, `/launch/${launch.id}`);
86
- urlObject.searchParams.set("sessionId", launch.id);
87
- urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
88
- urlObject.searchParams.set("launchType", launch.type);
89
- if (launch.from) {
90
- urlObject.searchParams.set("from", launch.from);
91
- }
92
- return urlObject.href;
93
- }
94
- return "";
95
- };
96
- const getBlockletMetaUrlFromQuery = (query) => {
97
- const url = (query.get("blocklet_meta_url") || query.get("meta_url") || "").trim();
98
- return decodeURIComponent(url);
99
- };
100
- const getRegistryUrlFromBlockletMetaUrl = (blockletMetaUrl) => {
101
- try {
102
- return blockletMetaUrl ? new URL(blockletMetaUrl).origin : "";
103
- } catch (error) {
104
- console.error("get registry url from blocklet meta url error:", error);
105
- return "";
106
- }
107
- };
108
- const formatRegistryLogoPath = (did, asset) => {
109
- if (asset.startsWith("/assets")) {
110
- return asset;
111
- }
112
- return `/assets/${did}/${asset}`;
113
- };
114
- const getBlockletLogoUrl = ({ did, baseUrl, logoPath }) => {
115
- if (!logoPath) {
116
- return "";
117
- }
118
- if (logoPath == null ? void 0 : logoPath.startsWith("http")) {
119
- return logoPath;
120
- }
121
- if ((baseUrl == null ? void 0 : baseUrl.startsWith("http")) && logoPath) {
122
- return joinURL(baseUrl, formatRegistryLogoPath(did, logoPath));
123
- }
124
- return "";
125
- };
126
- const getBlockletUrlOnStore = ({ did, baseUrl }) => {
127
- try {
128
- if (!baseUrl || !did) {
129
- return "";
130
- }
131
- const url = new URL(baseUrl);
132
- return joinURL(url.origin, `/blocklets/${did}`);
133
- } catch (error) {
134
- console.error("get registry url from blocklet meta url error:", error);
135
- return "";
136
- }
137
- };
138
- const getDefaultTrialEnd = () => moment().add(1, "years").unix();
139
- const getProductFreeTrial = ({ typeName, freeTrialProducts, currencyId }) => {
140
- if (!Array.isArray(freeTrialProducts)) {
141
- return null;
142
- }
143
- const matched = freeTrialProducts.find((x) => {
144
- const paymentCurrencies = x.paymentCurrencies.split(",").map((y) => y.trim()).filter(Boolean);
145
- return x.productTypeName === typeName && x.isFreeTrial && paymentCurrencies.includes(currencyId);
146
- });
147
- if (!matched) {
148
- return null;
149
- }
150
- return matched;
151
- };
152
- const util = {
153
- formatPeriod,
154
- prettyDurationUnit,
155
- prettyDuration,
156
- formatDatetime,
157
- formatUtcDatetime,
158
- isDateExpired,
159
- sortArrayByDate,
160
- getSort,
161
- getExplorerUrl,
162
- getBlockletDisplayName,
163
- getBlockletAdminURL,
164
- getContinueLaunchURL,
165
- getBlockletMetaUrlFromQuery,
166
- getRegistryUrlFromBlockletMetaUrl,
167
- getBlockletLogoUrl,
168
- getBlockletUrlOnStore,
169
- getDefaultTrialEnd,
170
- getProductFreeTrial
171
- };
172
- exports.default = util;
173
- exports.formatDatetime = formatDatetime;
174
- exports.formatPeriod = formatPeriod;
175
- exports.formatUtcDatetime = formatUtcDatetime;
176
- exports.getBlockletAdminURL = getBlockletAdminURL;
177
- exports.getBlockletDisplayName = getBlockletDisplayName;
178
- exports.getBlockletLogoUrl = getBlockletLogoUrl;
179
- exports.getBlockletMetaUrlFromQuery = getBlockletMetaUrlFromQuery;
180
- exports.getBlockletUrlOnStore = getBlockletUrlOnStore;
181
- exports.getContinueLaunchURL = getContinueLaunchURL;
182
- exports.getDefaultTrialEnd = getDefaultTrialEnd;
183
- exports.getExplorerUrl = getExplorerUrl;
184
- exports.getProductFreeTrial = getProductFreeTrial;
185
- exports.getRegistryUrlFromBlockletMetaUrl = getRegistryUrlFromBlockletMetaUrl;
186
- exports.getSort = getSort;
187
- exports.isDateExpired = isDateExpired;
188
- exports.prettyDuration = prettyDuration;
189
- exports.prettyDurationUnit = prettyDurationUnit;
190
- exports.sortArrayByDate = sortArrayByDate;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("moment-timezone");require("moment/locale/zh-cn");const a=require("moment"),l=require("url-join"),g=require("lodash/get"),u=require("./constant.js"),d=t=>{const e=Number(t.slice(0,t.length-1)),r=t[t.length-1];return{value:e,unit:r}},c=({value:t,unit:e},r)=>{Object.keys(u.TIME_LOCALE).includes(r)||(r="en");const n=t>1?`${e}s`:e;return u.TIME_LOCALE[r][n.toLowerCase()]},U=(t,e)=>{if(!t)return"";const{value:r,unit:n}=t;return`${r}${c({value:r,unit:n},e)}`},m=(t,e="en-us",r=Intl.DateTimeFormat().resolvedOptions().timeZone)=>{if(!t)return"";e=e||"en-us",e==="zh"&&(e="zh-cn");try{return a(t).locale(e).tz(r).format("LLL zz")}catch(n){return console.error(`formate date time "${t}" error`,n),""}},y=(t,e="en-us")=>m(t,e,"UTC"),p=(t,e=!0,r=void 0)=>(t||[]).sort((n,i)=>{let o=n,s=i;if(typeof r<"u"&&(o=o[r],s=s[r]),o===s)return 0;const f=e?1:-1;return a(o).diff(a(s))>0?f:-1*f}),L=(t,e)=>t&&t!=="undefined"?{[t]:e}:{createdAt:-1},k=({address:t,type:e="txs",chainHost:r})=>`https://explorer.abtnetwork.io/explorer/${e}/${t}?host=${r}`,D=t=>g(t,"title")||g(t,"name")||"",T=t=>t?l(t,"/.well-known/service/admin/overview"):"#",h=t=>!!t&&new Date(t).getTime()<=Date.now(),A=({baseURL:t,launch:e})=>{const r=new URL(t);return e.status<u.LAUNCH_STATUS.paid?(r.searchParams.set("sessionId",e.id),r.searchParams.set("blocklet_meta_url",e.blockletMetaUrl),r.href):e.status>=u.LAUNCH_STATUS.paid&&e.status<u.LAUNCH_STATUS.consuming?(r.pathname=l(r.pathname,`/launch/${e.id}`),r.searchParams.set("sessionId",e.id),r.searchParams.set("blocklet_meta_url",e.blockletMetaUrl),r.searchParams.set("launchType",e.type),e.from&&r.searchParams.set("from",e.from),r.href):""},B=t=>{const e=(t.get("blocklet_meta_url")||t.get("meta_url")||"").trim();return decodeURIComponent(e)},_=t=>{try{return t?new URL(t).origin:""}catch(e){return console.error("get registry url from blocklet meta url error:",e),""}},v=(t,e)=>e.startsWith("/assets")?e:`/assets/${t}/${e}`,R=({did:t,baseUrl:e,logoPath:r})=>r?r?.startsWith("http")?r:e?.startsWith("http")&&r?l(e,v(t,r)):"":"",C=({did:t,baseUrl:e})=>{try{if(!e||!t)return"";const r=new URL(e);return l(r.origin,`/blocklets/${t}`)}catch(r){return console.error("get registry url from blocklet meta url error:",r),""}},S=()=>a().add(1,"years").unix(),$=({typeName:t,freeTrialProducts:e,currencyId:r})=>{if(!Array.isArray(e))return null;const n=e.find(i=>{const o=i.paymentCurrencies.split(",").map(s=>s.trim()).filter(Boolean);return i.productTypeName===t&&i.isFreeTrial&&o.includes(r)});return n||null},w={formatPeriod:d,prettyDurationUnit:c,prettyDuration:U,formatDatetime:m,formatUtcDatetime:y,isDateExpired:h,sortArrayByDate:p,getSort:L,getExplorerUrl:k,getBlockletDisplayName:D,getBlockletAdminURL:T,getContinueLaunchURL:A,getBlockletMetaUrlFromQuery:B,getRegistryUrlFromBlockletMetaUrl:_,getBlockletLogoUrl:R,getBlockletUrlOnStore:C,getDefaultTrialEnd:S,getProductFreeTrial:$};exports.default=w;exports.formatDatetime=m;exports.formatPeriod=d;exports.formatUtcDatetime=y;exports.getBlockletAdminURL=T;exports.getBlockletDisplayName=D;exports.getBlockletLogoUrl=R;exports.getBlockletMetaUrlFromQuery=B;exports.getBlockletUrlOnStore=C;exports.getContinueLaunchURL=A;exports.getDefaultTrialEnd=S;exports.getExplorerUrl=k;exports.getProductFreeTrial=$;exports.getRegistryUrlFromBlockletMetaUrl=_;exports.getSort=L;exports.isDateExpired=h;exports.prettyDuration=U;exports.prettyDurationUnit=c;exports.sortArrayByDate=p;
package/lib/validator.js CHANGED
@@ -1,10 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const create = (schema) => (data, locale) => {
4
- const { error, value } = schema.validate(data, { errors: { language: locale || "en" } });
5
- if (error) {
6
- throw new Error(error.message);
7
- }
8
- return value;
9
- };
10
- exports.create = create;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=r=>(t,a)=>{const{error:e,value:o}=r.validate(t,{errors:{language:a||"en"}});if(e)throw new Error(e.message);return o};exports.create=n;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-util",
3
- "version": "2.3.139",
3
+ "version": "2.4.0",
4
4
  "description": "Common constants",
5
5
  "keywords": [
6
6
  "constant"
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@blocklet/js-sdk": "1.16.44",
39
39
  "@blocklet/sdk": "1.16.44",
40
- "@ocap/util": "^1.20.14",
41
- "axios": "^1.9.0",
40
+ "@ocap/util": "^1.20.15",
41
+ "axios": "^1.10.0",
42
42
  "flat": "^5.0.2",
43
43
  "lodash": "^4.17.21",
44
44
  "moment": "^2.30.1",
@@ -46,8 +46,10 @@
46
46
  "url-join": "^4.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "vite": "^5.4.19",
50
- "vite-plugin-build": "^0.10.0"
49
+ "fast-glob": "^3.3.3",
50
+ "vite": "^7.0.0",
51
+ "vite-plugin-build": "^0.10.0",
52
+ "vite-plugin-no-bundle": "^4.0.0"
51
53
  },
52
- "gitHead": "edc4cafa66a1d76b6f570fad3f82831909b52d06"
54
+ "gitHead": "e66df918847edbe28af223d6f6bfb42b1d2a4699"
53
55
  }