@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.
@@ -1,29 +1,23 @@
1
- import BlockletNotification from "@blocklet/sdk/service/notification";
2
- class Notification {
3
- constructor({ logger, auth }) {
4
- this.auth = auth;
5
- this.logger = logger || { info: console.info, error: console.error };
1
+ import n from "@blocklet/sdk/service/notification";
2
+ class f {
3
+ constructor({ logger: o, auth: i }) {
4
+ this.auth = i, this.logger = o || { info: console.info, error: console.error };
6
5
  }
7
- async sendNotification({ to, title, message, actions, attachments = [], assetAddress }) {
6
+ async sendNotification({ to: o, title: i, message: e, actions: a, attachments: s = [], assetAddress: r }) {
8
7
  try {
9
- const payload = { title, body: message, actions: actions || [], attachments: [...attachments] };
10
- if (typeof assetAddress !== "undefined") {
11
- payload.attachments.push({
12
- type: "asset",
13
- data: {
14
- chainHost: this.auth.chainHost,
15
- did: assetAddress
16
- }
17
- });
18
- }
19
- await BlockletNotification.sendToUser(to, payload);
20
- this.logger.info("text message was sent", { to, payload: JSON.stringify(payload, null, 2) });
21
- } catch (error) {
22
- this.logger.error("send text message failed", { error, to, message, actions, attachments });
23
- throw error;
8
+ const t = { title: i, body: e, actions: a || [], attachments: [...s] };
9
+ typeof r < "u" && t.attachments.push({
10
+ type: "asset",
11
+ data: {
12
+ chainHost: this.auth.chainHost,
13
+ did: r
14
+ }
15
+ }), await n.sendToUser(o, t), this.logger.info("text message was sent", { to: o, payload: JSON.stringify(t, null, 2) });
16
+ } catch (t) {
17
+ throw this.logger.error("send text message failed", { error: t, to: o, message: e, actions: a, attachments: s }), t;
24
18
  }
25
19
  }
26
20
  }
27
21
  export {
28
- Notification as default
22
+ f as default
29
23
  };
package/es/payment-kit.js CHANGED
@@ -1,4 +1,4 @@
1
- const formatTimestamp = (timestamp) => new Date(timestamp * 1e3).toISOString();
1
+ const e = (t) => new Date(t * 1e3).toISOString();
2
2
  export {
3
- formatTimestamp
3
+ e as formatTimestamp
4
4
  };
package/es/permission.js CHANGED
@@ -1,5 +1,4 @@
1
- const ADMIN_ROLES = ["owner", "admin"];
2
- const canAccessAdmin = (role) => ADMIN_ROLES.includes(role);
1
+ const c = ["owner", "admin"], s = (n) => c.includes(n);
3
2
  export {
4
- canAccessAdmin
3
+ s as canAccessAdmin
5
4
  };
package/es/util.js CHANGED
@@ -1,190 +1,103 @@
1
1
  import "moment-timezone";
2
2
  import "moment/locale/zh-cn";
3
- import moment from "moment";
4
- import joinURL from "url-join";
5
- import get from "lodash/get";
6
- import { TIME_LOCALE, LAUNCH_STATUS } from "./constant";
7
- const formatPeriod = (duration) => {
8
- const value = Number(duration.slice(0, duration.length - 1));
9
- const unit = duration[duration.length - 1];
10
- return { value, unit };
11
- };
12
- const prettyDurationUnit = ({ value, unit }, locale) => {
13
- if (!Object.keys(TIME_LOCALE).includes(locale)) {
14
- locale = "en";
15
- }
16
- const localeKey = value > 1 ? `${unit}s` : unit;
17
- return TIME_LOCALE[locale][localeKey.toLowerCase()];
18
- };
19
- const prettyDuration = (duration, locale) => {
20
- if (!duration) {
3
+ import u from "moment";
4
+ import c from "url-join";
5
+ import l from "lodash/get";
6
+ import { TIME_LOCALE as f, LAUNCH_STATUS as a } from "./constant.js";
7
+ const g = (t) => {
8
+ const r = Number(t.slice(0, t.length - 1)), e = t[t.length - 1];
9
+ return { value: r, unit: e };
10
+ }, p = ({ value: t, unit: r }, e) => {
11
+ Object.keys(f).includes(e) || (e = "en");
12
+ const n = t > 1 ? `${r}s` : r;
13
+ return f[e][n.toLowerCase()];
14
+ }, y = (t, r) => {
15
+ if (!t)
21
16
  return "";
22
- }
23
- const { value, unit } = duration;
24
- return `${value}${prettyDurationUnit({ value, unit }, locale)}`;
25
- };
26
- const formatDatetime = (time, locale = "en-us", timezone = Intl.DateTimeFormat().resolvedOptions().timeZone) => {
27
- if (!time) {
17
+ const { value: e, unit: n } = t;
18
+ return `${e}${p({ value: e, unit: n }, r)}`;
19
+ }, d = (t, r = "en-us", e = Intl.DateTimeFormat().resolvedOptions().timeZone) => {
20
+ if (!t)
28
21
  return "";
29
- }
30
- locale = locale || "en-us";
31
- if (locale === "zh") {
32
- locale = "zh-cn";
33
- }
22
+ r = r || "en-us", r === "zh" && (r = "zh-cn");
34
23
  try {
35
- return moment(time).locale(locale).tz(timezone).format("LLL zz");
36
- } catch (error) {
37
- console.error(`formate date time "${time}" error`, error);
38
- return "";
39
- }
40
- };
41
- const formatUtcDatetime = (time, locale = "en-us") => formatDatetime(time, locale, "UTC");
42
- const sortArrayByDate = (array, asc = true, field = void 0) => (array || []).sort((x, y) => {
43
- let v1 = x;
44
- let v2 = y;
45
- if (typeof field !== "undefined") {
46
- v1 = v1[field];
47
- v2 = v2[field];
24
+ return u(t).locale(r).tz(e).format("LLL zz");
25
+ } catch (n) {
26
+ return console.error(`formate date time "${t}" error`, n), "";
48
27
  }
49
- if (v1 === v2) {
28
+ }, L = (t, r = "en-us") => d(t, r, "UTC"), U = (t, r = !0, e = void 0) => (t || []).sort((n, i) => {
29
+ let o = n, s = i;
30
+ if (typeof e < "u" && (o = o[e], s = s[e]), o === s)
50
31
  return 0;
51
- }
52
- const directionResult = asc ? 1 : -1;
53
- if (moment(v1).diff(moment(v2)) > 0) {
54
- return directionResult;
55
- }
56
- return -1 * directionResult;
57
- });
58
- const getSort = (sortby, sortdir) => {
59
- if (sortby && sortby !== "undefined") {
60
- return { [sortby]: sortdir };
61
- }
62
- return { createdAt: -1 };
63
- };
64
- const getExplorerUrl = ({ address, type = "txs", chainHost }) => {
65
- return `https://explorer.abtnetwork.io/explorer/${type}/${address}?host=${chainHost}`;
66
- };
67
- const getBlockletDisplayName = (blocklet) => get(blocklet, "title") || get(blocklet, "name") || "";
68
- const getBlockletAdminURL = (appUrl) => {
69
- if (!appUrl) {
70
- return "#";
71
- }
72
- return joinURL(appUrl, "/.well-known/service/admin/overview");
73
- };
74
- const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
75
- const getContinueLaunchURL = ({ baseURL, launch }) => {
76
- const urlObject = new URL(baseURL);
77
- if (launch.status < LAUNCH_STATUS.paid) {
78
- urlObject.searchParams.set("sessionId", launch.id);
79
- urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
80
- return urlObject.href;
81
- }
82
- if (launch.status >= LAUNCH_STATUS.paid && launch.status < LAUNCH_STATUS.consuming) {
83
- urlObject.pathname = joinURL(urlObject.pathname, `/launch/${launch.id}`);
84
- urlObject.searchParams.set("sessionId", launch.id);
85
- urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
86
- urlObject.searchParams.set("launchType", launch.type);
87
- if (launch.from) {
88
- urlObject.searchParams.set("from", launch.from);
89
- }
90
- return urlObject.href;
91
- }
92
- return "";
93
- };
94
- const getBlockletMetaUrlFromQuery = (query) => {
95
- const url = (query.get("blocklet_meta_url") || query.get("meta_url") || "").trim();
96
- return decodeURIComponent(url);
97
- };
98
- const getRegistryUrlFromBlockletMetaUrl = (blockletMetaUrl) => {
32
+ const m = r ? 1 : -1;
33
+ return u(o).diff(u(s)) > 0 ? m : -1 * m;
34
+ }), h = (t, r) => t && t !== "undefined" ? { [t]: r } : { createdAt: -1 }, k = ({ address: t, type: r = "txs", chainHost: e }) => `https://explorer.abtnetwork.io/explorer/${r}/${t}?host=${e}`, $ = (t) => l(t, "title") || l(t, "name") || "", w = (t) => t ? c(t, "/.well-known/service/admin/overview") : "#", D = (t) => !!t && new Date(t).getTime() <= Date.now(), R = ({ baseURL: t, launch: r }) => {
35
+ const e = new URL(t);
36
+ return r.status < a.paid ? (e.searchParams.set("sessionId", r.id), e.searchParams.set("blocklet_meta_url", r.blockletMetaUrl), e.href) : r.status >= a.paid && r.status < a.consuming ? (e.pathname = c(e.pathname, `/launch/${r.id}`), e.searchParams.set("sessionId", r.id), e.searchParams.set("blocklet_meta_url", r.blockletMetaUrl), e.searchParams.set("launchType", r.type), r.from && e.searchParams.set("from", r.from), e.href) : "";
37
+ }, T = (t) => {
38
+ const r = (t.get("blocklet_meta_url") || t.get("meta_url") || "").trim();
39
+ return decodeURIComponent(r);
40
+ }, _ = (t) => {
99
41
  try {
100
- return blockletMetaUrl ? new URL(blockletMetaUrl).origin : "";
101
- } catch (error) {
102
- console.error("get registry url from blocklet meta url error:", error);
103
- return "";
104
- }
105
- };
106
- const formatRegistryLogoPath = (did, asset) => {
107
- if (asset.startsWith("/assets")) {
108
- return asset;
109
- }
110
- return `/assets/${did}/${asset}`;
111
- };
112
- const getBlockletLogoUrl = ({ did, baseUrl, logoPath }) => {
113
- if (!logoPath) {
114
- return "";
42
+ return t ? new URL(t).origin : "";
43
+ } catch (r) {
44
+ return console.error("get registry url from blocklet meta url error:", r), "";
115
45
  }
116
- if (logoPath == null ? void 0 : logoPath.startsWith("http")) {
117
- return logoPath;
118
- }
119
- if ((baseUrl == null ? void 0 : baseUrl.startsWith("http")) && logoPath) {
120
- return joinURL(baseUrl, formatRegistryLogoPath(did, logoPath));
121
- }
122
- return "";
123
- };
124
- const getBlockletUrlOnStore = ({ did, baseUrl }) => {
46
+ }, v = (t, r) => r.startsWith("/assets") ? r : `/assets/${t}/${r}`, A = ({ did: t, baseUrl: r, logoPath: e }) => e ? e?.startsWith("http") ? e : r?.startsWith("http") && e ? c(r, v(t, e)) : "" : "", B = ({ did: t, baseUrl: r }) => {
125
47
  try {
126
- if (!baseUrl || !did) {
48
+ if (!r || !t)
127
49
  return "";
128
- }
129
- const url = new URL(baseUrl);
130
- return joinURL(url.origin, `/blocklets/${did}`);
131
- } catch (error) {
132
- console.error("get registry url from blocklet meta url error:", error);
133
- return "";
50
+ const e = new URL(r);
51
+ return c(e.origin, `/blocklets/${t}`);
52
+ } catch (e) {
53
+ return console.error("get registry url from blocklet meta url error:", e), "";
134
54
  }
135
- };
136
- const getDefaultTrialEnd = () => moment().add(1, "years").unix();
137
- const getProductFreeTrial = ({ typeName, freeTrialProducts, currencyId }) => {
138
- if (!Array.isArray(freeTrialProducts)) {
55
+ }, C = () => u().add(1, "years").unix(), b = ({ typeName: t, freeTrialProducts: r, currencyId: e }) => {
56
+ if (!Array.isArray(r))
139
57
  return null;
140
- }
141
- const matched = freeTrialProducts.find((x) => {
142
- const paymentCurrencies = x.paymentCurrencies.split(",").map((y) => y.trim()).filter(Boolean);
143
- return x.productTypeName === typeName && x.isFreeTrial && paymentCurrencies.includes(currencyId);
58
+ const n = r.find((i) => {
59
+ const o = i.paymentCurrencies.split(",").map((s) => s.trim()).filter(Boolean);
60
+ return i.productTypeName === t && i.isFreeTrial && o.includes(e);
144
61
  });
145
- if (!matched) {
146
- return null;
147
- }
148
- return matched;
149
- };
150
- const util = {
151
- formatPeriod,
152
- prettyDurationUnit,
153
- prettyDuration,
154
- formatDatetime,
155
- formatUtcDatetime,
156
- isDateExpired,
157
- sortArrayByDate,
158
- getSort,
159
- getExplorerUrl,
160
- getBlockletDisplayName,
161
- getBlockletAdminURL,
162
- getContinueLaunchURL,
163
- getBlockletMetaUrlFromQuery,
164
- getRegistryUrlFromBlockletMetaUrl,
165
- getBlockletLogoUrl,
166
- getBlockletUrlOnStore,
167
- getDefaultTrialEnd,
168
- getProductFreeTrial
62
+ return n || null;
63
+ }, M = {
64
+ formatPeriod: g,
65
+ prettyDurationUnit: p,
66
+ prettyDuration: y,
67
+ formatDatetime: d,
68
+ formatUtcDatetime: L,
69
+ isDateExpired: D,
70
+ sortArrayByDate: U,
71
+ getSort: h,
72
+ getExplorerUrl: k,
73
+ getBlockletDisplayName: $,
74
+ getBlockletAdminURL: w,
75
+ getContinueLaunchURL: R,
76
+ getBlockletMetaUrlFromQuery: T,
77
+ getRegistryUrlFromBlockletMetaUrl: _,
78
+ getBlockletLogoUrl: A,
79
+ getBlockletUrlOnStore: B,
80
+ getDefaultTrialEnd: C,
81
+ getProductFreeTrial: b
169
82
  };
170
83
  export {
171
- util as default,
172
- formatDatetime,
173
- formatPeriod,
174
- formatUtcDatetime,
175
- getBlockletAdminURL,
176
- getBlockletDisplayName,
177
- getBlockletLogoUrl,
178
- getBlockletMetaUrlFromQuery,
179
- getBlockletUrlOnStore,
180
- getContinueLaunchURL,
181
- getDefaultTrialEnd,
182
- getExplorerUrl,
183
- getProductFreeTrial,
184
- getRegistryUrlFromBlockletMetaUrl,
185
- getSort,
186
- isDateExpired,
187
- prettyDuration,
188
- prettyDurationUnit,
189
- sortArrayByDate
84
+ M as default,
85
+ d as formatDatetime,
86
+ g as formatPeriod,
87
+ L as formatUtcDatetime,
88
+ w as getBlockletAdminURL,
89
+ $ as getBlockletDisplayName,
90
+ A as getBlockletLogoUrl,
91
+ T as getBlockletMetaUrlFromQuery,
92
+ B as getBlockletUrlOnStore,
93
+ R as getContinueLaunchURL,
94
+ C as getDefaultTrialEnd,
95
+ k as getExplorerUrl,
96
+ b as getProductFreeTrial,
97
+ _ as getRegistryUrlFromBlockletMetaUrl,
98
+ h as getSort,
99
+ D as isDateExpired,
100
+ y as prettyDuration,
101
+ p as prettyDurationUnit,
102
+ U as sortArrayByDate
190
103
  };
package/es/validator.js CHANGED
@@ -1,10 +1,9 @@
1
- const create = (schema) => (data, locale) => {
2
- const { error, value } = schema.validate(data, { errors: { language: locale || "en" } });
3
- if (error) {
4
- throw new Error(error.message);
5
- }
6
- return value;
1
+ const n = (e) => (a, o) => {
2
+ const { error: r, value: t } = e.validate(a, { errors: { language: o || "en" } });
3
+ if (r)
4
+ throw new Error(r.message);
5
+ return t;
7
6
  };
8
7
  export {
9
- create
8
+ n as create
10
9
  };
package/lib/api.js CHANGED
@@ -1,9 +1 @@
1
- "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const axios = require("axios");
4
- const jsSdk = require("@blocklet/js-sdk");
5
- axios.defaults.baseURL = "";
6
- axios.defaults.timeout = 2e5;
7
- const create = (...args) => jsSdk.createAxios(...args);
8
- exports.default = axios;
9
- exports.create = create;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("axios"),s=require("@blocklet/js-sdk");e.defaults.baseURL="";e.defaults.timeout=2e5;const r=(...t)=>s.createAxios(...t);exports.default=e;exports.create=r;
package/lib/constant.js CHANGED
@@ -1,205 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const INSTANCE_STATUS = Object.freeze({
4
- error: 0,
5
- waiting: 5,
6
- pending: 10,
7
- starting: 20,
8
- running: 30,
9
- restarting: 40,
10
- underMaintenance: 45,
11
- stopping: 50,
12
- stopped: 60,
13
- terminatedInstance: 70,
14
- expired: 80,
15
- terminated: 90
16
- // 最终状态
17
- });
18
- const PLAN_STATUS = Object.freeze({
19
- draft: 10,
20
- published: 20,
21
- dropped: 30
22
- // 已下架
23
- });
24
- const LAUNCH_STATUS = Object.freeze({
25
- created: 0,
26
- selected: 10,
27
- connected: 20,
28
- timeout: 25,
29
- paid: 30,
30
- nftMinted: 35,
31
- allocated: 40,
32
- consuming: 46,
33
- installed: 50,
34
- pastDue: 60,
35
- canceled: 65,
36
- terminated: 70,
37
- transferred: 90,
38
- blocked: 100
39
- });
40
- const LAUNCH_SESSION_TYPE = Object.freeze({
41
- serverless: "serverless",
42
- dedicated: "dedicated",
43
- onDemand: "on-demand"
44
- // FIXME: on-demand 是兼容字段,未来该字段会被移除
45
- });
46
- const SERVERLESS_INSTANCE_STATUS = {
47
- launching: 10,
48
- running: 20,
49
- expired: 30,
50
- terminated: 40
51
- };
52
- const LAUNCH_ACTIVITY_TYPE = Object.freeze({
53
- created: "created",
54
- selected: "selected",
55
- connected: "connected",
56
- paid: "paid",
57
- allocated: "allocated",
58
- installed: "installed",
59
- timeout: "timeout",
60
- pastDue: "pastDue",
61
- canceled: "canceled",
62
- terminated: "terminated",
63
- transferred: "transferred"
64
- });
65
- const SERVER_ACTIVITY_TYPE = Object.freeze({
66
- purchase: "purchase",
67
- launch: "launch",
68
- createFailed: "createFailed",
69
- created: "created",
70
- modifiedInstanceType: "modifiedInstanceType",
71
- start: "start",
72
- started: "started",
73
- startFailed: "startFailed",
74
- stop: "stop",
75
- stopped: "stopped",
76
- stopFailed: "stopFailed",
77
- restart: "restart",
78
- restarted: "restarted",
79
- restartFailed: "restartFailed",
80
- expired: "expired",
81
- terminate: "terminate",
82
- terminated: "terminated",
83
- terminateFailed: "terminateFailed",
84
- renewaled: "renewaled",
85
- transferred: "transferred",
86
- replacement: "replacement"
87
- });
88
- const toMap = (status) => Object.keys(status).reduce((acc, cur) => {
89
- acc[status[cur]] = cur;
90
- return acc;
91
- }, {});
92
- const fromStatus = (map) => (status) => map[status];
93
- const statusInstanceMap = toMap(INSTANCE_STATUS);
94
- const planStatusMap = toMap(PLAN_STATUS);
95
- const launchStatusMap = toMap(LAUNCH_STATUS);
96
- const fromInstanceStatus = fromStatus(statusInstanceMap);
97
- const fromPlanStatus = fromStatus(planStatusMap);
98
- const fromLaunchStatus = fromStatus(launchStatusMap);
99
- const NFT_TYPE_SERVERLESS = "BlockletServerServerlessNFT";
100
- const NFT_TYPE_DEDICATE = "BlockletServerOwnershipNFT";
101
- const TIME_LOCALE = {
102
- en: {
103
- h: "hour",
104
- hs: "hours",
105
- d: " day",
106
- ds: " days",
107
- m: " month",
108
- ms: " months",
109
- y: " year",
110
- ys: " years"
111
- },
112
- zh: {
113
- h: "小时",
114
- hs: "小时",
115
- d: "天",
116
- ds: "天",
117
- m: "个月",
118
- ms: "个月",
119
- y: "年",
120
- ys: "年"
121
- }
122
- };
123
- const APP_TYPE = Object.freeze({
124
- serverless: "serverless",
125
- dedicated: "dedicated"
126
- });
127
- const SKU_STATUS = Object.freeze({
128
- DISABLED: 0,
129
- ENABLED: 1
130
- });
131
- const PAYMENT_STATUS = Object.freeze({
132
- unpaid: 10,
133
- paid: 20,
134
- done: 30,
135
- expired: 40,
136
- canceled: 60,
137
- failed: 70
138
- });
139
- const PAYMENT_TYPES = {
140
- purchase: "purchase",
141
- renewal: "renewal",
142
- autoRenewal: "auto-renewal"
143
- };
144
- const PAYMENT_METHODS = Object.freeze({
145
- crypto: "crypto",
146
- stripe: "stripe",
147
- fiat: "fiat"
148
- // TODO: 区分支付货币和支付方式
149
- });
150
- const DID_DOMAIN_SUFFIX = "did.abtnet.io";
151
- const REDEEM_NFT_ID = "redeem";
152
- const INSTANCE_MAX_NAME_LENGTH = 30;
153
- const INSTANCE_MAX_DESC_LENGTH = 50;
154
- const LAUNCH_TYPE = {
155
- instant: "instant",
156
- redeem: "redeem"
157
- };
158
- const CURRENCY_TYPE = {
159
- fiat: "fiat",
160
- crypto: "crypto"
161
- };
162
- const SERVERLESS_RETAIN_DAYS = 30;
163
- const APP_RECORD_TYPE = {
164
- install: "install",
165
- uninstall: "uninstall"
166
- };
167
- const APP_CHARGE_TYPE = {
168
- freeTrial: "free-trial",
169
- // 免费试用
170
- instant: "instant"
171
- // 立即付费
172
- };
173
- const CONFIG_DATA_TYPE = {
174
- ami: "ami",
175
- syncNFT: "syncNFT",
176
- nftFactories: "nftFactories"
177
- };
178
- exports.APP_CHARGE_TYPE = APP_CHARGE_TYPE;
179
- exports.APP_RECORD_TYPE = APP_RECORD_TYPE;
180
- exports.APP_TYPE = APP_TYPE;
181
- exports.CONFIG_DATA_TYPE = CONFIG_DATA_TYPE;
182
- exports.CURRENCY_TYPE = CURRENCY_TYPE;
183
- exports.DID_DOMAIN_SUFFIX = DID_DOMAIN_SUFFIX;
184
- exports.INSTANCE_MAX_DESC_LENGTH = INSTANCE_MAX_DESC_LENGTH;
185
- exports.INSTANCE_MAX_NAME_LENGTH = INSTANCE_MAX_NAME_LENGTH;
186
- exports.INSTANCE_STATUS = INSTANCE_STATUS;
187
- exports.LAUNCH_ACTIVITY_TYPE = LAUNCH_ACTIVITY_TYPE;
188
- exports.LAUNCH_SESSION_TYPE = LAUNCH_SESSION_TYPE;
189
- exports.LAUNCH_STATUS = LAUNCH_STATUS;
190
- exports.LAUNCH_TYPE = LAUNCH_TYPE;
191
- exports.NFT_TYPE_DEDICATE = NFT_TYPE_DEDICATE;
192
- exports.NFT_TYPE_SERVERLESS = NFT_TYPE_SERVERLESS;
193
- exports.PAYMENT_METHODS = PAYMENT_METHODS;
194
- exports.PAYMENT_STATUS = PAYMENT_STATUS;
195
- exports.PAYMENT_TYPES = PAYMENT_TYPES;
196
- exports.PLAN_STATUS = PLAN_STATUS;
197
- exports.REDEEM_NFT_ID = REDEEM_NFT_ID;
198
- exports.SERVERLESS_INSTANCE_STATUS = SERVERLESS_INSTANCE_STATUS;
199
- exports.SERVERLESS_RETAIN_DAYS = SERVERLESS_RETAIN_DAYS;
200
- exports.SERVER_ACTIVITY_TYPE = SERVER_ACTIVITY_TYPE;
201
- exports.SKU_STATUS = SKU_STATUS;
202
- exports.TIME_LOCALE = TIME_LOCALE;
203
- exports.fromInstanceStatus = fromInstanceStatus;
204
- exports.fromLaunchStatus = fromLaunchStatus;
205
- exports.fromPlanStatus = fromPlanStatus;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=Object.freeze({error:0,waiting:5,pending:10,starting:20,running:30,restarting:40,underMaintenance:45,stopping:50,stopped:60,terminatedInstance:70,expired:80,terminated:90}),c=Object.freeze({draft:10,published:20,dropped:30}),d=Object.freeze({created:0,selected:10,connected:20,timeout:25,paid:30,nftMinted:35,allocated:40,consuming:46,installed:50,pastDue:60,canceled:65,terminated:70,transferred:90,blocked:100}),T=Object.freeze({serverless:"serverless",dedicated:"dedicated",onDemand:"on-demand"}),E={launching:10,running:20,expired:30,terminated:40},i=Object.freeze({created:"created",selected:"selected",connected:"connected",paid:"paid",allocated:"allocated",installed:"installed",timeout:"timeout",pastDue:"pastDue",canceled:"canceled",terminated:"terminated",transferred:"transferred"}),o=Object.freeze({purchase:"purchase",launch:"launch",createFailed:"createFailed",created:"created",modifiedInstanceType:"modifiedInstanceType",start:"start",started:"started",startFailed:"startFailed",stop:"stop",stopped:"stopped",stopFailed:"stopFailed",restart:"restart",restarted:"restarted",restartFailed:"restartFailed",expired:"expired",terminate:"terminate",terminated:"terminated",terminateFailed:"terminateFailed",renewaled:"renewaled",transferred:"transferred",replacement:"replacement"}),a=e=>Object.keys(e).reduce((t,r)=>(t[e[r]]=r,t),{}),n=e=>t=>e[t],S=a(s),_=a(c),A=a(d),l=n(S),N=n(_),p=n(A),P="BlockletServerServerlessNFT",m="BlockletServerOwnershipNFT",u={en:{h:"hour",hs:"hours",d:" day",ds:" days",m:" month",ms:" months",y:" year",ys:" years"},zh:{h:"小时",hs:"小时",d:"天",ds:"天",m:"个月",ms:"个月",y:"年",ys:"年"}},I=Object.freeze({serverless:"serverless",dedicated:"dedicated"}),Y=Object.freeze({DISABLED:0,ENABLED:1}),f=Object.freeze({unpaid:10,paid:20,done:30,expired:40,canceled:60,failed:70}),C={purchase:"purchase",renewal:"renewal",autoRenewal:"auto-renewal"},D=Object.freeze({crypto:"crypto",stripe:"stripe",fiat:"fiat"}),R="did.abtnet.io",F="redeem",L=30,M=50,U={instant:"instant",redeem:"redeem"},O={fiat:"fiat",crypto:"crypto"},h=30,y={install:"install",uninstall:"uninstall"},b={freeTrial:"free-trial",instant:"instant"},H={ami:"ami",syncNFT:"syncNFT",nftFactories:"nftFactories"};exports.APP_CHARGE_TYPE=b;exports.APP_RECORD_TYPE=y;exports.APP_TYPE=I;exports.CONFIG_DATA_TYPE=H;exports.CURRENCY_TYPE=O;exports.DID_DOMAIN_SUFFIX=R;exports.INSTANCE_MAX_DESC_LENGTH=M;exports.INSTANCE_MAX_NAME_LENGTH=L;exports.INSTANCE_STATUS=s;exports.LAUNCH_ACTIVITY_TYPE=i;exports.LAUNCH_SESSION_TYPE=T;exports.LAUNCH_STATUS=d;exports.LAUNCH_TYPE=U;exports.NFT_TYPE_DEDICATE=m;exports.NFT_TYPE_SERVERLESS=P;exports.PAYMENT_METHODS=D;exports.PAYMENT_STATUS=f;exports.PAYMENT_TYPES=C;exports.PLAN_STATUS=c;exports.REDEEM_NFT_ID=F;exports.SERVERLESS_INSTANCE_STATUS=E;exports.SERVERLESS_RETAIN_DAYS=h;exports.SERVER_ACTIVITY_TYPE=o;exports.SKU_STATUS=Y;exports.TIME_LOCALE=u;exports.fromInstanceStatus=l;exports.fromLaunchStatus=p;exports.fromPlanStatus=N;
@@ -1,24 +1,2 @@
1
- "use strict";
2
- const formatError = (err) => {
3
- var _a;
4
- if (!err) {
5
- return err;
6
- }
7
- const { details, errors, response } = err;
8
- if (Array.isArray(errors)) {
9
- return errors.map((x) => x.message).join("\n");
10
- }
11
- if (Array.isArray(details)) {
12
- const formatted = details.map((e) => {
13
- const errorMessage = e.message.replace(/["]/g, "'");
14
- const errorPath = e.path.join(".");
15
- return `${errorPath}: ${errorMessage}`;
16
- });
17
- return `Validate failed: ${formatted.join(";")}`;
18
- }
19
- if (response) {
20
- return ((_a = response.data) == null ? void 0 : _a.error) || `Request failed: ${response.status} ${response.statusText}: ${JSON.stringify(response.data)}`;
21
- }
22
- return err.message || err;
23
- };
24
- module.exports = formatError;
1
+ "use strict";const i=r=>{if(!r)return r;const{details:e,errors:a,response:t}=r;return Array.isArray(a)?a.map(s=>s.message).join(`
2
+ `):Array.isArray(e)?`Validate failed: ${e.map(o=>{const n=o.message.replace(/["]/g,"'");return`${o.path.join(".")}: ${n}`}).join(";")}`:t?t.data?.error||`Request failed: ${t.status} ${t.statusText}: ${JSON.stringify(t.data)}`:r.message||r};module.exports=i;
package/lib/get-asset.js CHANGED
@@ -1,15 +1,5 @@
1
- "use strict";
2
- const joinUrl = require("url-join");
3
- const get = require("lodash/get");
4
- const api = require("./api");
5
- const getAsset = async (chainHost, address) => {
6
- const url = joinUrl(new URL(chainHost).origin, "/api/gql/");
7
- const request = api.create();
8
- const result = await request.post(
9
- url,
10
- JSON.stringify({
11
- query: `{
12
- getAssetState(address: "${address}") {
1
+ "use strict";const n=require("url-join"),o=require("lodash/get"),i=require("./api.js"),c=async(e,s)=>{const a=n(new URL(e).origin,"/api/gql/"),r=await i.create().post(a,JSON.stringify({query:`{
2
+ getAssetState(address: "${s}") {
13
3
  state {
14
4
  address
15
5
  data {
@@ -26,20 +16,4 @@ const getAsset = async (chainHost, address) => {
26
16
  tags
27
17
  }
28
18
  }
29
- }`
30
- }),
31
- {
32
- headers: {
33
- "Content-Type": "application/json",
34
- Accept: "application/json"
35
- },
36
- timeout: 60 * 1e3
37
- }
38
- );
39
- const state = get(result, "data.data.getAssetState.state");
40
- if (state && state.data.typeUrl === "json") {
41
- state.data.value = JSON.parse(state.data.value);
42
- }
43
- return state;
44
- };
45
- module.exports = getAsset;
19
+ }`}),{headers:{"Content-Type":"application/json",Accept:"application/json"},timeout:60*1e3}),t=o(r,"data.data.getAssetState.state");return t&&t.data.typeUrl==="json"&&(t.data.value=JSON.parse(t.data.value)),t};module.exports=c;