@blocklet/launcher-util 2.2.54 → 2.2.56

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/constant.js CHANGED
@@ -24,6 +24,7 @@ const LAUNCH_STATUS = Object.freeze({
24
24
  selected: 10,
25
25
  connected: 20,
26
26
  paid: 30,
27
+ nftMinted: 35,
27
28
  allocated: 40,
28
29
  consuming: 46,
29
30
  installed: 50,
@@ -32,6 +33,12 @@ const LAUNCH_STATUS = Object.freeze({
32
33
  timeout: 80,
33
34
  transferred: 90
34
35
  });
36
+ const LAUNCH_SESSION_TYPE = Object.freeze({
37
+ serverless: "serverless",
38
+ dedicated: "dedicated",
39
+ onDemand: "on-demand"
40
+ // FIXME: on-demand 是兼容字段,未来该字段会被移除
41
+ });
35
42
  const SERVERLESS_INSTANCE_STATUS = {
36
43
  launching: 10,
37
44
  running: 20,
@@ -55,6 +62,7 @@ const SERVER_ACTIVITY_TYPE = Object.freeze({
55
62
  launch: "launch",
56
63
  createFailed: "createFailed",
57
64
  created: "created",
65
+ modifiedInstanceType: "modifiedInstanceType",
58
66
  start: "start",
59
67
  started: "started",
60
68
  startFailed: "startFailed",
@@ -79,10 +87,12 @@ const toMap = (status) => Object.keys(status).reduce((acc, cur) => {
79
87
  const fromStatus = (map) => (status) => map[status];
80
88
  const statusInstanceMap = toMap(INSTANCE_STATUS);
81
89
  const planStatusMap = toMap(PLAN_STATUS);
90
+ const launchStatusMap = toMap(LAUNCH_STATUS);
82
91
  const fromInstanceStatus = fromStatus(statusInstanceMap);
83
92
  const fromPlanStatus = fromStatus(planStatusMap);
93
+ const fromLaunchStatus = fromStatus(launchStatusMap);
84
94
  const NFT_TYPE_SERVERLESS = "BlockletServerServerlessNFT";
85
- const BLOCKLET_SERVER_OWNERSHIP_NFT = "BlockletServerOwnershipNFT";
95
+ const NFT_TYPE_DEDICATE = "BlockletServerOwnershipNFT";
86
96
  const TIME_LOCALE = {
87
97
  en: {
88
98
  h: "hour",
@@ -145,17 +155,23 @@ const CURRENCY_TYPE = {
145
155
  crypto: "crypto"
146
156
  };
147
157
  const SERVERLESS_RETAIN_DAYS = 30;
158
+ const APP_RECORD_TYPE = {
159
+ install: "install",
160
+ uninstall: "uninstall"
161
+ };
148
162
  export {
163
+ APP_RECORD_TYPE,
149
164
  APP_TYPE,
150
- BLOCKLET_SERVER_OWNERSHIP_NFT,
151
165
  CURRENCY_TYPE,
152
166
  DID_DOMAIN_SUFFIX,
153
167
  INSTANCE_MAX_DESC_LENGTH,
154
168
  INSTANCE_MAX_NAME_LENGTH,
155
169
  INSTANCE_STATUS,
156
170
  LAUNCH_ACTIVITY_TYPE,
171
+ LAUNCH_SESSION_TYPE,
157
172
  LAUNCH_STATUS,
158
173
  LAUNCH_TYPE,
174
+ NFT_TYPE_DEDICATE,
159
175
  NFT_TYPE_SERVERLESS,
160
176
  PAYMENT_METHODS,
161
177
  PAYMENT_STATUS,
@@ -168,5 +184,6 @@ export {
168
184
  SKU_STATUS,
169
185
  TIME_LOCALE,
170
186
  fromInstanceStatus,
187
+ fromLaunchStatus,
171
188
  fromPlanStatus
172
189
  };
package/es/get-asset.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import joinUrl from "url-join";
2
2
  import axios from "axios";
3
- import get from "lodash.get";
3
+ import get from "lodash/get";
4
4
  const getAsset = async (chainHost, address) => {
5
5
  const url = joinUrl(new URL(chainHost).origin, "/api/gql/");
6
6
  const result = await axios.post(
package/es/middleware.js CHANGED
@@ -1,4 +1,4 @@
1
- import pick from "lodash.pick";
1
+ import pick from "lodash/pick";
2
2
  import { getSort } from "./util";
3
3
  const MAX_PAGING_SIZE = 100;
4
4
  const DEFAULT_PAGING_SIZE = MAX_PAGING_SIZE;
@@ -25,6 +25,7 @@ const validate = (schema, option = {}) => (req, res, next) => {
25
25
  ...option
26
26
  });
27
27
  if (error) {
28
+ console.error("validate error", { error: error.message });
28
29
  res.status(400).json({ error: error.message });
29
30
  return;
30
31
  }
package/es/nft.js ADDED
@@ -0,0 +1,13 @@
1
+ import get from "lodash/get";
2
+ import last from "lodash/last";
3
+ const getNftExpirationDate = (asset) => last(get(asset, "data.value.expirationDate", []));
4
+ const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
5
+ const isNFTExpired = (asset) => {
6
+ const expirationDate = getNftExpirationDate(asset);
7
+ return isDateExpired(expirationDate);
8
+ };
9
+ export {
10
+ getNftExpirationDate,
11
+ isDateExpired,
12
+ isNFTExpired
13
+ };
@@ -0,0 +1,4 @@
1
+ const formatTimestamp = (timestamp) => new Date(timestamp * 1e3).toISOString();
2
+ export {
3
+ formatTimestamp
4
+ };
package/es/util.js CHANGED
@@ -2,7 +2,7 @@ import "moment-timezone";
2
2
  import "moment/locale/zh-cn";
3
3
  import moment from "moment";
4
4
  import joinURL from "url-join";
5
- import get from "lodash.get";
5
+ import get from "lodash/get";
6
6
  import { TIME_LOCALE, LAUNCH_STATUS } from "./constant";
7
7
  const formatPeriod = (duration) => {
8
8
  const value = Number(duration.slice(0, duration.length - 1));
@@ -75,7 +75,7 @@ const getContinueLaunchURL = ({ baseURL, launch }) => {
75
75
  return urlObject.href;
76
76
  }
77
77
  if (launch.status >= LAUNCH_STATUS.paid && launch.status < LAUNCH_STATUS.consuming) {
78
- urlObject.pathname = joinURL(urlObject.pathname, `/launch/${launch.nftDid}`);
78
+ urlObject.pathname = joinURL(urlObject.pathname, `/launch/${launch._id}`);
79
79
  urlObject.searchParams.set("sessionId", launch._id);
80
80
  urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
81
81
  urlObject.searchParams.set("launchType", launch.type);
@@ -105,15 +105,51 @@ const formatRegistryLogoPath = (did, asset) => {
105
105
  return `/assets/${did}/${asset}`;
106
106
  };
107
107
  const getBlockletLogoUrl = ({ did, baseUrl, logoPath }) => {
108
- if (logoPath && logoPath.startsWith("http")) {
108
+ if (!logoPath) {
109
+ return "";
110
+ }
111
+ if (logoPath == null ? void 0 : logoPath.startsWith("http")) {
109
112
  return logoPath;
110
113
  }
111
- if (baseUrl.startsWith("http") && logoPath) {
114
+ if ((baseUrl == null ? void 0 : baseUrl.startsWith("http")) && logoPath) {
112
115
  return joinURL(baseUrl, formatRegistryLogoPath(did, logoPath));
113
116
  }
114
117
  return "";
115
118
  };
119
+ const getBlockletUrlOnStore = ({ did, baseUrl }) => {
120
+ try {
121
+ if (!baseUrl || !did) {
122
+ return "";
123
+ }
124
+ const url = new URL(baseUrl);
125
+ return joinURL(url.origin, `/blocklets/${did}`);
126
+ } catch (error) {
127
+ console.error("get registry url from blocklet meta url error:", error);
128
+ return "";
129
+ }
130
+ };
131
+ const getDefaultTrialEnd = () => moment().add(1, "years").unix();
132
+ const util = {
133
+ formatPeriod,
134
+ prettyDurationUnit,
135
+ prettyDuration,
136
+ formatDatetime,
137
+ formatUtcDatetime,
138
+ isDateExpired,
139
+ sortArrayByDate,
140
+ getSort,
141
+ getExplorerUrl,
142
+ getBlockletDisplayName,
143
+ getBlockletAdminURL,
144
+ getContinueLaunchURL,
145
+ getBlockletMetaUrlFromQuery,
146
+ getRegistryUrlFromBlockletMetaUrl,
147
+ getBlockletLogoUrl,
148
+ getBlockletUrlOnStore,
149
+ getDefaultTrialEnd
150
+ };
116
151
  export {
152
+ util as default,
117
153
  formatDatetime,
118
154
  formatPeriod,
119
155
  formatUtcDatetime,
@@ -121,7 +157,9 @@ export {
121
157
  getBlockletDisplayName,
122
158
  getBlockletLogoUrl,
123
159
  getBlockletMetaUrlFromQuery,
160
+ getBlockletUrlOnStore,
124
161
  getContinueLaunchURL,
162
+ getDefaultTrialEnd,
125
163
  getExplorerUrl,
126
164
  getRegistryUrlFromBlockletMetaUrl,
127
165
  getSort,
package/lib/constant.js CHANGED
@@ -26,6 +26,7 @@ const LAUNCH_STATUS = Object.freeze({
26
26
  selected: 10,
27
27
  connected: 20,
28
28
  paid: 30,
29
+ nftMinted: 35,
29
30
  allocated: 40,
30
31
  consuming: 46,
31
32
  installed: 50,
@@ -34,6 +35,12 @@ const LAUNCH_STATUS = Object.freeze({
34
35
  timeout: 80,
35
36
  transferred: 90
36
37
  });
38
+ const LAUNCH_SESSION_TYPE = Object.freeze({
39
+ serverless: "serverless",
40
+ dedicated: "dedicated",
41
+ onDemand: "on-demand"
42
+ // FIXME: on-demand 是兼容字段,未来该字段会被移除
43
+ });
37
44
  const SERVERLESS_INSTANCE_STATUS = {
38
45
  launching: 10,
39
46
  running: 20,
@@ -57,6 +64,7 @@ const SERVER_ACTIVITY_TYPE = Object.freeze({
57
64
  launch: "launch",
58
65
  createFailed: "createFailed",
59
66
  created: "created",
67
+ modifiedInstanceType: "modifiedInstanceType",
60
68
  start: "start",
61
69
  started: "started",
62
70
  startFailed: "startFailed",
@@ -81,10 +89,12 @@ const toMap = (status) => Object.keys(status).reduce((acc, cur) => {
81
89
  const fromStatus = (map) => (status) => map[status];
82
90
  const statusInstanceMap = toMap(INSTANCE_STATUS);
83
91
  const planStatusMap = toMap(PLAN_STATUS);
92
+ const launchStatusMap = toMap(LAUNCH_STATUS);
84
93
  const fromInstanceStatus = fromStatus(statusInstanceMap);
85
94
  const fromPlanStatus = fromStatus(planStatusMap);
95
+ const fromLaunchStatus = fromStatus(launchStatusMap);
86
96
  const NFT_TYPE_SERVERLESS = "BlockletServerServerlessNFT";
87
- const BLOCKLET_SERVER_OWNERSHIP_NFT = "BlockletServerOwnershipNFT";
97
+ const NFT_TYPE_DEDICATE = "BlockletServerOwnershipNFT";
88
98
  const TIME_LOCALE = {
89
99
  en: {
90
100
  h: "hour",
@@ -147,16 +157,22 @@ const CURRENCY_TYPE = {
147
157
  crypto: "crypto"
148
158
  };
149
159
  const SERVERLESS_RETAIN_DAYS = 30;
160
+ const APP_RECORD_TYPE = {
161
+ install: "install",
162
+ uninstall: "uninstall"
163
+ };
164
+ exports.APP_RECORD_TYPE = APP_RECORD_TYPE;
150
165
  exports.APP_TYPE = APP_TYPE;
151
- exports.BLOCKLET_SERVER_OWNERSHIP_NFT = BLOCKLET_SERVER_OWNERSHIP_NFT;
152
166
  exports.CURRENCY_TYPE = CURRENCY_TYPE;
153
167
  exports.DID_DOMAIN_SUFFIX = DID_DOMAIN_SUFFIX;
154
168
  exports.INSTANCE_MAX_DESC_LENGTH = INSTANCE_MAX_DESC_LENGTH;
155
169
  exports.INSTANCE_MAX_NAME_LENGTH = INSTANCE_MAX_NAME_LENGTH;
156
170
  exports.INSTANCE_STATUS = INSTANCE_STATUS;
157
171
  exports.LAUNCH_ACTIVITY_TYPE = LAUNCH_ACTIVITY_TYPE;
172
+ exports.LAUNCH_SESSION_TYPE = LAUNCH_SESSION_TYPE;
158
173
  exports.LAUNCH_STATUS = LAUNCH_STATUS;
159
174
  exports.LAUNCH_TYPE = LAUNCH_TYPE;
175
+ exports.NFT_TYPE_DEDICATE = NFT_TYPE_DEDICATE;
160
176
  exports.NFT_TYPE_SERVERLESS = NFT_TYPE_SERVERLESS;
161
177
  exports.PAYMENT_METHODS = PAYMENT_METHODS;
162
178
  exports.PAYMENT_STATUS = PAYMENT_STATUS;
@@ -169,4 +185,5 @@ exports.SERVER_ACTIVITY_TYPE = SERVER_ACTIVITY_TYPE;
169
185
  exports.SKU_STATUS = SKU_STATUS;
170
186
  exports.TIME_LOCALE = TIME_LOCALE;
171
187
  exports.fromInstanceStatus = fromInstanceStatus;
188
+ exports.fromLaunchStatus = fromLaunchStatus;
172
189
  exports.fromPlanStatus = fromPlanStatus;
package/lib/get-asset.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const joinUrl = require("url-join");
3
3
  const axios = require("axios");
4
- const get = require("lodash.get");
4
+ const get = require("lodash/get");
5
5
  const getAsset = async (chainHost, address) => {
6
6
  const url = joinUrl(new URL(chainHost).origin, "/api/gql/");
7
7
  const result = await axios.post(
package/lib/middleware.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const pick = require("lodash.pick");
3
+ const pick = require("lodash/pick");
4
4
  const util = require("./util");
5
5
  const MAX_PAGING_SIZE = 100;
6
6
  const DEFAULT_PAGING_SIZE = MAX_PAGING_SIZE;
@@ -27,6 +27,7 @@ const validate = (schema, option = {}) => (req, res, next) => {
27
27
  ...option
28
28
  });
29
29
  if (error) {
30
+ console.error("validate error", { error: error.message });
30
31
  res.status(400).json({ error: error.message });
31
32
  return;
32
33
  }
package/lib/nft.js ADDED
@@ -0,0 +1,13 @@
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 getNftExpirationDate = (asset) => last(get(asset, "data.value.expirationDate", []));
6
+ const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
7
+ const isNFTExpired = (asset) => {
8
+ const expirationDate = getNftExpirationDate(asset);
9
+ return isDateExpired(expirationDate);
10
+ };
11
+ exports.getNftExpirationDate = getNftExpirationDate;
12
+ exports.isDateExpired = isDateExpired;
13
+ exports.isNFTExpired = isNFTExpired;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const formatTimestamp = (timestamp) => new Date(timestamp * 1e3).toISOString();
4
+ exports.formatTimestamp = formatTimestamp;
package/lib/util.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
3
  require("moment-timezone");
4
4
  require("moment/locale/zh-cn");
5
5
  const moment = require("moment");
6
6
  const joinURL = require("url-join");
7
- const get = require("lodash.get");
7
+ const get = require("lodash/get");
8
8
  const constant = require("./constant");
9
9
  const formatPeriod = (duration) => {
10
10
  const value = Number(duration.slice(0, duration.length - 1));
@@ -77,7 +77,7 @@ const getContinueLaunchURL = ({ baseURL, launch }) => {
77
77
  return urlObject.href;
78
78
  }
79
79
  if (launch.status >= constant.LAUNCH_STATUS.paid && launch.status < constant.LAUNCH_STATUS.consuming) {
80
- urlObject.pathname = joinURL(urlObject.pathname, `/launch/${launch.nftDid}`);
80
+ urlObject.pathname = joinURL(urlObject.pathname, `/launch/${launch._id}`);
81
81
  urlObject.searchParams.set("sessionId", launch._id);
82
82
  urlObject.searchParams.set("blocklet_meta_url", launch.blockletMetaUrl);
83
83
  urlObject.searchParams.set("launchType", launch.type);
@@ -107,14 +107,50 @@ const formatRegistryLogoPath = (did, asset) => {
107
107
  return `/assets/${did}/${asset}`;
108
108
  };
109
109
  const getBlockletLogoUrl = ({ did, baseUrl, logoPath }) => {
110
- if (logoPath && logoPath.startsWith("http")) {
110
+ if (!logoPath) {
111
+ return "";
112
+ }
113
+ if (logoPath == null ? void 0 : logoPath.startsWith("http")) {
111
114
  return logoPath;
112
115
  }
113
- if (baseUrl.startsWith("http") && logoPath) {
116
+ if ((baseUrl == null ? void 0 : baseUrl.startsWith("http")) && logoPath) {
114
117
  return joinURL(baseUrl, formatRegistryLogoPath(did, logoPath));
115
118
  }
116
119
  return "";
117
120
  };
121
+ const getBlockletUrlOnStore = ({ did, baseUrl }) => {
122
+ try {
123
+ if (!baseUrl || !did) {
124
+ return "";
125
+ }
126
+ const url = new URL(baseUrl);
127
+ return joinURL(url.origin, `/blocklets/${did}`);
128
+ } catch (error) {
129
+ console.error("get registry url from blocklet meta url error:", error);
130
+ return "";
131
+ }
132
+ };
133
+ const getDefaultTrialEnd = () => moment().add(1, "years").unix();
134
+ const util = {
135
+ formatPeriod,
136
+ prettyDurationUnit,
137
+ prettyDuration,
138
+ formatDatetime,
139
+ formatUtcDatetime,
140
+ isDateExpired,
141
+ sortArrayByDate,
142
+ getSort,
143
+ getExplorerUrl,
144
+ getBlockletDisplayName,
145
+ getBlockletAdminURL,
146
+ getContinueLaunchURL,
147
+ getBlockletMetaUrlFromQuery,
148
+ getRegistryUrlFromBlockletMetaUrl,
149
+ getBlockletLogoUrl,
150
+ getBlockletUrlOnStore,
151
+ getDefaultTrialEnd
152
+ };
153
+ exports.default = util;
118
154
  exports.formatDatetime = formatDatetime;
119
155
  exports.formatPeriod = formatPeriod;
120
156
  exports.formatUtcDatetime = formatUtcDatetime;
@@ -122,7 +158,9 @@ exports.getBlockletAdminURL = getBlockletAdminURL;
122
158
  exports.getBlockletDisplayName = getBlockletDisplayName;
123
159
  exports.getBlockletLogoUrl = getBlockletLogoUrl;
124
160
  exports.getBlockletMetaUrlFromQuery = getBlockletMetaUrlFromQuery;
161
+ exports.getBlockletUrlOnStore = getBlockletUrlOnStore;
125
162
  exports.getContinueLaunchURL = getContinueLaunchURL;
163
+ exports.getDefaultTrialEnd = getDefaultTrialEnd;
126
164
  exports.getExplorerUrl = getExplorerUrl;
127
165
  exports.getRegistryUrlFromBlockletMetaUrl = getRegistryUrlFromBlockletMetaUrl;
128
166
  exports.getSort = getSort;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-util",
3
- "version": "2.2.54",
3
+ "version": "2.2.56",
4
4
  "description": "Common constants",
5
5
  "keywords": [
6
6
  "constant"
@@ -35,20 +35,19 @@
35
35
  "url": "https://github.com/blocklet/launcher/issues"
36
36
  },
37
37
  "dependencies": {
38
- "@blocklet/sdk": "^1.16.23",
39
- "@ocap/util": "^1.18.110",
38
+ "@blocklet/sdk": "^1.16.24",
39
+ "@ocap/util": "^1.18.113",
40
40
  "axios": "^0.27.2",
41
41
  "flat": "^5.0.2",
42
- "lodash.get": "^4.4.2",
43
- "lodash.pick": "^4.4.0",
42
+ "lodash": "^4.17.21",
44
43
  "moment": "^2.30.1",
45
44
  "moment-timezone": "^0.5.45",
46
45
  "url-join": "^4.0.1"
47
46
  },
48
47
  "devDependencies": {
49
48
  "jest": "^27.5.1",
50
- "vite": "^5.0.12",
49
+ "vite": "^5.2.2",
51
50
  "vite-plugin-build": "^0.10.0"
52
51
  },
53
- "gitHead": "cd8c9b12e0d4c89557cd76ce1dc89c5d14ed50e1"
52
+ "gitHead": "0386d6a9170c437800e7e892163787277df7a682"
54
53
  }