@blocklet/launcher-workflow 2.3.32 → 2.3.34

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/locales/en.js CHANGED
@@ -113,6 +113,7 @@ export default {
113
113
  componentCount: '{count} Component Included',
114
114
  componentsCount: '{count} Components Included',
115
115
  onDemandNotSupport: 'This app does not support installation in on-demand space, please purchase dedicated space or install in your own dedicated space',
116
+ freeTrial: 'Free Trial',
116
117
  dialog: {
117
118
  title: 'Purchase Blocklet Space NFT',
118
119
  scan: 'Scan the QR code below with your DID wallet to complete purchase',
@@ -131,7 +132,7 @@ export default {
131
132
  notRemind: 'No more reminders'
132
133
  },
133
134
  productType: {
134
- 'on-demand': 'On Demand Space',
135
+ serverless: 'On Demand Space',
135
136
  dedicated: 'Dedicated Space'
136
137
  },
137
138
  paid: {
@@ -156,6 +157,9 @@ export default {
156
157
  },
157
158
  agreement: '{name} User Agreement',
158
159
  estimatedCost: 'Estimated Cost',
159
- estimatedCostHint: 'The total cost will vary depending on the actual number and duration of components used in the application. The calculation method is: Unit price of component * Number of components * Duration.'
160
+ estimatedCostHint: 'The total cost will vary depending on the actual number and duration of components used in the application. The calculation method is: Unit price of component * Number of components * Duration.',
161
+ freeTrialHint: 'Free trial for {duration}',
162
+ stakeAmount: 'Stake Amount',
163
+ stakeHint: 'On-demand spaces operate on a postpaid strategy. You need to stake {amount} for each space. If there are no due invoices when your subscription ends, the staking will be returned to you; otherwise, the staking will be slashed to pay for the due invoices.'
160
164
  }
161
165
  };
package/es/locales/zh.js CHANGED
@@ -112,6 +112,7 @@ export default {
112
112
  componentCount: '共 {count} 个组件',
113
113
  componentsCount: '共 {count} 个组件',
114
114
  onDemandNotSupport: '该应用不支持安装在按需空间中,请购买专用空间,或者安装在自己已有的专用空间中',
115
+ freeTrial: '免费试用',
115
116
  dialog: {
116
117
  title: '购买 Blocklet Server NFT',
117
118
  scan: '用您的 DID 钱包扫描下面的二维码完成购买',
@@ -130,7 +131,7 @@ export default {
130
131
  notRemind: '不再提醒'
131
132
  },
132
133
  productType: {
133
- 'on-demand': '按需空间',
134
+ serverless: '按需空间',
134
135
  dedicated: '专用空间'
135
136
  },
136
137
  paid: {
@@ -155,6 +156,9 @@ export default {
155
156
  },
156
157
  agreement: '{name} 用户协议',
157
158
  estimatedCost: '估算成本',
158
- estimatedCostHint: '总成本会根据应用实际使用的组件数量和时长而变化,计算方式为: 组件单价*组件数量*时长'
159
+ estimatedCostHint: '总成本会根据应用实际使用的组件数量和时长而变化,计算方式为: 组件单价*组件数量*时长',
160
+ freeTrialHint: '免费试用{duration}',
161
+ stakeAmount: '质押金额',
162
+ stakeHint: '按需空间采用后付费策略,每个按需空间需要您质押 {amount} 作为服务使用保证金,如果服务结束后没有出现欠费,抵押金将会返还给您;否则会从抵押金中扣除欠费金额。'
159
163
  }
160
164
  };
package/es/prepare.js CHANGED
@@ -34,26 +34,13 @@ const Root = styled('div')`
34
34
  width: 100%;
35
35
  }
36
36
  `;
37
- const isBlockletSupportOnDemand = (blockletMetaUrl, serverlessTrustedSources) => {
38
- try {
39
- if (!serverlessTrustedSources || serverlessTrustedSources?.length === 0 || !blockletMetaUrl) {
40
- return true;
41
- }
42
- return (serverlessTrustedSources || []).some(item => {
43
- const url = new URL(item.url);
44
- return url.origin === new URL(blockletMetaUrl).origin;
45
- });
46
- } catch (error) {
47
- // 如果出错,不要阻塞流程
48
- console.warn('exception in isBlockletSupportOnDemand', error, blockletMetaUrl, serverlessTrustedSources);
49
- return true;
50
- }
51
- };
52
37
  function Content({
53
38
  blocklet
54
39
  }) {
55
40
  const [state, setState] = useSetState({
56
- productType: 'on-demand'
41
+ productType: {
42
+ name: 'serverless'
43
+ }
57
44
  });
58
45
  const [params, setParams] = useSearchParams();
59
46
  const {
@@ -73,59 +60,76 @@ function Content({
73
60
  const navigate = useNavigate();
74
61
  const sessionId = params.get('sessionId');
75
62
  const blockletMetaUrl = getBlockletMetaUrlFromQuery(params);
76
- const defaultProductType = params.get('product_type');
63
+ const defaultProductTypeName = params.get('product_type');
77
64
  const from = params.get('from');
65
+ const launchState = useAsync(async () => {
66
+ const createPromiseFn = (fn, ...args) => new Promise((resolve, reject) => {
67
+ fn(...args, (err, value) => {
68
+ if (err) {
69
+ reject(err);
70
+ } else {
71
+ resolve(value);
72
+ }
73
+ });
74
+ });
75
+ let launchFn = null;
76
+ if (sessionId) {
77
+ launchFn = createPromiseFn(launchSession.load, launchSessionAPI, routerPrefix, sessionId, blockletMetaUrl);
78
+ } else {
79
+ launchFn = createPromiseFn(launchSession.create, launchSessionAPI, routerPrefix, blockletMetaUrl);
80
+ }
81
+ const metadataFn = launchSessionAPI.get(`/metadata?blockletMetaUrl=${blockletMetaUrl}`).then(res => res.data);
82
+ const [launch, metadata] = await Promise.all([launchFn, metadataFn]);
83
+ return {
84
+ launch,
85
+ metadata
86
+ };
87
+ }, [session.user, blockletMetaUrl]);
78
88
  const productTypes = useMemo(() => {
79
89
  const result = [];
80
- if (isBlockletSupportOnDemand(blockletMetaUrl, window.blocklet?.preferences?.serverlessTrustedSources) === true) {
81
- result.push('on-demand');
82
- } else {
90
+ if (launchState.loading) {
91
+ return result;
92
+ }
93
+ if (launchState.value?.metadata?.isBlockletSupportOnDemand === false) {
83
94
  Toast.info(t('purchase.onDemandNotSupport'), {
84
95
  persist: true
85
96
  });
97
+ } else {
98
+ const name = 'serverless';
99
+ result.push({
100
+ name
101
+ });
86
102
  }
87
103
  if (window.blocklet?.preferences?.dedicatedPricingTableId) {
88
- result.push('dedicated');
104
+ const name = 'dedicated';
105
+ result.push({
106
+ name
107
+ });
89
108
  }
90
109
  return result;
91
- }, [blockletMetaUrl, t]);
110
+ }, [launchState, t]);
92
111
  useEffect(() => {
93
- const defaultType = productTypes.includes(defaultProductType) ? defaultProductType : productTypes?.[0];
112
+ const defaultType = productTypes.find(x => x.name === defaultProductTypeName) ? {
113
+ name: defaultProductTypeName
114
+ } : productTypes?.[0];
94
115
  if (defaultType) {
95
116
  setState({
96
117
  productType: defaultType
97
118
  });
98
- params.set('product_type', defaultType);
119
+ params.set('product_type', defaultType.name);
99
120
  setParams(params, {
100
121
  replace: true
101
122
  });
102
123
  }
103
- }, [productTypes, defaultProductType, params, setParams, setState]);
104
- const launchState = useAsync(async () => {
105
- const createPromiseFn = (fn, ...args) => new Promise((resolve, reject) => {
106
- fn(...args, (err, value) => {
107
- if (err) {
108
- reject(err);
109
- } else {
110
- resolve(value);
111
- }
112
- });
113
- });
114
- if (sessionId) {
115
- const launch = await createPromiseFn(launchSession.load, launchSessionAPI, routerPrefix, sessionId, blockletMetaUrl);
116
- return launch;
117
- }
118
- const launch = await createPromiseFn(launchSession.create, launchSessionAPI, routerPrefix, blockletMetaUrl);
119
- return launch;
120
- });
124
+ }, [productTypes, defaultProductTypeName, params, setParams, setState]);
121
125
  const getPurchaseNewLink = useCallback(() => {
122
- window.location = launchState?.value?.app?.appURL;
126
+ window.location = launchState?.value?.launch?.app?.appURL;
123
127
  const urlObj = new URL(window.location.href);
124
128
  urlObj.searchParams.delete('sessionId');
125
129
  return urlObj.href;
126
- }, [launchState?.value?.app?.appURL]);
130
+ }, [launchState?.value?.launch?.app?.appURL]);
127
131
  useEffect(() => {
128
- const tmpLaunch = launchState.value;
132
+ const tmpLaunch = launchState.value?.launch;
129
133
  if (!tmpLaunch) {
130
134
  return;
131
135
  }
@@ -135,7 +139,7 @@ function Content({
135
139
  replace: true
136
140
  });
137
141
  }
138
- }, [launchState.value, params, setParams]);
142
+ }, [launchState.value?.launch, params, setParams]);
139
143
  if (launchState.loading || blocklet.loading) {
140
144
  return /*#__PURE__*/_jsx(Center, {
141
145
  relative: "parent",
@@ -148,14 +152,15 @@ function Content({
148
152
  const handlePaid = () => {
149
153
  navigate(`/paid?&sessionId=${launch._id}&blocklet_meta_url=${launch.blockletMetaUrl}&from=${from}`);
150
154
  };
151
- const handleChangeProductType = (a, newProductType) => {
152
- if (!newProductType) {
155
+ const handleChangeProductType = (_, typeName) => {
156
+ if (!typeName) {
153
157
  return;
154
158
  }
159
+ const newProductType = productTypes.find(x => x.name === typeName);
155
160
  setState({
156
161
  productType: newProductType
157
162
  });
158
- params.set('product_type', newProductType);
163
+ params.set('product_type', newProductType.name);
159
164
  setParams(params, {
160
165
  replace: true
161
166
  });
@@ -163,7 +168,7 @@ function Content({
163
168
 
164
169
  // TODO: PaymentKitV2 处理支付失败的情况
165
170
 
166
- const launch = launchState.value;
171
+ const launch = launchState.value?.launch;
167
172
  if ([LAUNCH_STATUS.paid, LAUNCH_STATUS.nftMinted, LAUNCH_STATUS.allocated].includes(launch.status)) {
168
173
  return /*#__PURE__*/_jsx(ConfirmDialog, {
169
174
  title: t('purchase.unexpectedLaunchSession.paid'),
@@ -215,18 +220,23 @@ function Content({
215
220
  children: [productTypes.length > 1 && /*#__PURE__*/_jsx(ToggleButtonGroup, {
216
221
  orientation: "horizontal",
217
222
  color: "primary",
218
- value: state.productType,
223
+ value: state.productType?.name,
219
224
  size: "small",
220
225
  onChange: handleChangeProductType,
221
226
  exclusive: true,
222
- children: productTypes.map(type => {
227
+ sx: {
228
+ marginTop: '8px'
229
+ },
230
+ children: productTypes.map(({
231
+ name
232
+ }) => {
223
233
  return /*#__PURE__*/_jsx(ToggleButton, {
224
- value: type,
234
+ value: name,
225
235
  sx: {
226
236
  textTransform: 'capitalize'
227
237
  },
228
- children: t(`purchase.productType.${type}`)
229
- }, type);
238
+ children: t(`purchase.productType.${name}`)
239
+ }, name);
230
240
  })
231
241
  }), /*#__PURE__*/_jsxs(Box, {
232
242
  sx: {
@@ -240,7 +250,7 @@ function Content({
240
250
  maxWidth: '100%'
241
251
  }
242
252
  },
243
- children: [state.productType === 'on-demand' && /*#__PURE__*/_jsx(CheckoutOnDemand, {
253
+ children: [state.productType?.name === 'serverless' && /*#__PURE__*/_jsx(CheckoutOnDemand, {
244
254
  launchSessionId: sessionId,
245
255
  handlePaid: handlePaid,
246
256
  components: (blocklet.components || []).map(x => ({
@@ -259,8 +269,10 @@ function Content({
259
269
  t: t,
260
270
  locale: locale,
261
271
  api: launchSessionAPI,
262
- checkoutPath: "/payment/checkout"
263
- }), state.productType === 'dedicated' && window.blocklet?.preferences?.dedicatedPricingTableId && /*#__PURE__*/_jsx(Box, {
272
+ freeTrialProducts: launchState.value?.metadata?.freeTrialProducts || [],
273
+ checkoutPath: "/payment/checkout",
274
+ minStakeAmount: launchState.value?.metadata?.minStakeAmount
275
+ }), state.productType?.name === 'dedicated' && window.blocklet?.preferences?.dedicatedPricingTableId && /*#__PURE__*/_jsx(Box, {
264
276
  sx: {
265
277
  display: 'flex',
266
278
  width: '100%',
@@ -19,8 +19,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
19
19
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
20
20
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
21
21
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
22
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
23
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
22
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
23
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
24
24
  var CheckedIcon = function CheckedIcon(props) {
25
25
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", _objectSpread(_objectSpread({}, props), {}, {
26
26
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
@@ -17,8 +17,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
17
17
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
19
19
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
21
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
20
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
21
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
22
22
  const Body = /*#__PURE__*/(0, _react.forwardRef)(function Body(_ref, ref) {
23
23
  let {
24
24
  children
@@ -16,8 +16,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
16
16
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
17
17
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
18
18
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
20
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
19
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
20
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
21
21
  function Footer(_ref) {
22
22
  let {
23
23
  children
@@ -16,8 +16,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
16
16
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
17
17
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
18
18
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
20
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
19
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
20
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
21
21
  function Layout(_ref) {
22
22
  let {
23
23
  children
@@ -26,8 +26,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
26
26
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
27
27
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
28
28
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
29
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
30
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
29
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
30
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
31
31
  function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
32
32
  var CheckIcon = function CheckIcon(props) {
33
33
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", _objectSpread(_objectSpread({}, props), {}, {
package/lib/locales/en.js CHANGED
@@ -119,6 +119,7 @@ var _default = exports.default = {
119
119
  componentCount: '{count} Component Included',
120
120
  componentsCount: '{count} Components Included',
121
121
  onDemandNotSupport: 'This app does not support installation in on-demand space, please purchase dedicated space or install in your own dedicated space',
122
+ freeTrial: 'Free Trial',
122
123
  dialog: {
123
124
  title: 'Purchase Blocklet Space NFT',
124
125
  scan: 'Scan the QR code below with your DID wallet to complete purchase',
@@ -137,7 +138,7 @@ var _default = exports.default = {
137
138
  notRemind: 'No more reminders'
138
139
  },
139
140
  productType: {
140
- 'on-demand': 'On Demand Space',
141
+ serverless: 'On Demand Space',
141
142
  dedicated: 'Dedicated Space'
142
143
  },
143
144
  paid: {
@@ -162,6 +163,9 @@ var _default = exports.default = {
162
163
  },
163
164
  agreement: '{name} User Agreement',
164
165
  estimatedCost: 'Estimated Cost',
165
- estimatedCostHint: 'The total cost will vary depending on the actual number and duration of components used in the application. The calculation method is: Unit price of component * Number of components * Duration.'
166
+ estimatedCostHint: 'The total cost will vary depending on the actual number and duration of components used in the application. The calculation method is: Unit price of component * Number of components * Duration.',
167
+ freeTrialHint: 'Free trial for {duration}',
168
+ stakeAmount: 'Stake Amount',
169
+ stakeHint: 'On-demand spaces operate on a postpaid strategy. You need to stake {amount} for each space. If there are no due invoices when your subscription ends, the staking will be returned to you; otherwise, the staking will be slashed to pay for the due invoices.'
166
170
  }
167
171
  };
package/lib/locales/zh.js CHANGED
@@ -118,6 +118,7 @@ var _default = exports.default = {
118
118
  componentCount: '共 {count} 个组件',
119
119
  componentsCount: '共 {count} 个组件',
120
120
  onDemandNotSupport: '该应用不支持安装在按需空间中,请购买专用空间,或者安装在自己已有的专用空间中',
121
+ freeTrial: '免费试用',
121
122
  dialog: {
122
123
  title: '购买 Blocklet Server NFT',
123
124
  scan: '用您的 DID 钱包扫描下面的二维码完成购买',
@@ -136,7 +137,7 @@ var _default = exports.default = {
136
137
  notRemind: '不再提醒'
137
138
  },
138
139
  productType: {
139
- 'on-demand': '按需空间',
140
+ serverless: '按需空间',
140
141
  dedicated: '专用空间'
141
142
  },
142
143
  paid: {
@@ -161,6 +162,9 @@ var _default = exports.default = {
161
162
  },
162
163
  agreement: '{name} 用户协议',
163
164
  estimatedCost: '估算成本',
164
- estimatedCostHint: '总成本会根据应用实际使用的组件数量和时长而变化,计算方式为: 组件单价*组件数量*时长'
165
+ estimatedCostHint: '总成本会根据应用实际使用的组件数量和时长而变化,计算方式为: 组件单价*组件数量*时长',
166
+ freeTrialHint: '免费试用{duration}',
167
+ stakeAmount: '质押金额',
168
+ stakeHint: '按需空间采用后付费策略,每个按需空间需要您质押 {amount} 作为服务使用保证金,如果服务结束后没有出现欠费,抵押金将会返还给您;否则会从抵押金中扣除欠费金额。'
165
169
  }
166
170
  };
package/lib/prepare.js CHANGED
@@ -35,28 +35,15 @@ var _templateObject;
35
35
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
36
36
  function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
37
37
  const Root = (0, _styled.default)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 100%;\n height: 100%;\n padding-top: 0;\n\n @media (max-width: 960px) {\n width: 100%;\n }\n"])));
38
- const isBlockletSupportOnDemand = (blockletMetaUrl, serverlessTrustedSources) => {
39
- try {
40
- if (!serverlessTrustedSources || (serverlessTrustedSources === null || serverlessTrustedSources === void 0 ? void 0 : serverlessTrustedSources.length) === 0 || !blockletMetaUrl) {
41
- return true;
42
- }
43
- return (serverlessTrustedSources || []).some(item => {
44
- const url = new URL(item.url);
45
- return url.origin === new URL(blockletMetaUrl).origin;
46
- });
47
- } catch (error) {
48
- // 如果出错,不要阻塞流程
49
- console.warn('exception in isBlockletSupportOnDemand', error, blockletMetaUrl, serverlessTrustedSources);
50
- return true;
51
- }
52
- };
53
38
  function Content(_ref) {
54
- var _launchState$value2, _ref2, _window$blocklet3, _window$blocklet4, _window$blocklet5;
39
+ var _launchState$value3, _launchState$value5, _launchState$value6, _state$productType, _state$productType2, _ref3, _launchState$value7, _launchState$value8, _state$productType3, _window$blocklet2, _window$blocklet3, _window$blocklet4;
55
40
  let {
56
41
  blocklet
57
42
  } = _ref;
58
43
  const [state, setState] = (0, _useSetState.default)({
59
- productType: 'on-demand'
44
+ productType: {
45
+ name: 'serverless'
46
+ }
60
47
  });
61
48
  const [params, setParams] = (0, _reactRouterDom.useSearchParams)();
62
49
  const {
@@ -76,35 +63,8 @@ function Content(_ref) {
76
63
  const navigate = (0, _reactRouterDom.useNavigate)();
77
64
  const sessionId = params.get('sessionId');
78
65
  const blockletMetaUrl = (0, _util.getBlockletMetaUrlFromQuery)(params);
79
- const defaultProductType = params.get('product_type');
66
+ const defaultProductTypeName = params.get('product_type');
80
67
  const from = params.get('from');
81
- const productTypes = (0, _react.useMemo)(() => {
82
- var _window$blocklet, _window$blocklet2;
83
- const result = [];
84
- if (isBlockletSupportOnDemand(blockletMetaUrl, (_window$blocklet = window.blocklet) === null || _window$blocklet === void 0 || (_window$blocklet = _window$blocklet.preferences) === null || _window$blocklet === void 0 ? void 0 : _window$blocklet.serverlessTrustedSources) === true) {
85
- result.push('on-demand');
86
- } else {
87
- _Toast.default.info(t('purchase.onDemandNotSupport'), {
88
- persist: true
89
- });
90
- }
91
- if ((_window$blocklet2 = window.blocklet) !== null && _window$blocklet2 !== void 0 && (_window$blocklet2 = _window$blocklet2.preferences) !== null && _window$blocklet2 !== void 0 && _window$blocklet2.dedicatedPricingTableId) {
92
- result.push('dedicated');
93
- }
94
- return result;
95
- }, [blockletMetaUrl, t]);
96
- (0, _react.useEffect)(() => {
97
- const defaultType = productTypes.includes(defaultProductType) ? defaultProductType : productTypes === null || productTypes === void 0 ? void 0 : productTypes[0];
98
- if (defaultType) {
99
- setState({
100
- productType: defaultType
101
- });
102
- params.set('product_type', defaultType);
103
- setParams(params, {
104
- replace: true
105
- });
106
- }
107
- }, [productTypes, defaultProductType, params, setParams, setState]);
108
68
  const launchState = (0, _useAsync.default)(async () => {
109
69
  const createPromiseFn = function createPromiseFn(fn) {
110
70
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -120,22 +80,67 @@ function Content(_ref) {
120
80
  });
121
81
  });
122
82
  };
83
+ let launchFn = null;
123
84
  if (sessionId) {
124
- const launch = await createPromiseFn(_util2.launchSession.load, launchSessionAPI, routerPrefix, sessionId, blockletMetaUrl);
125
- return launch;
85
+ launchFn = createPromiseFn(_util2.launchSession.load, launchSessionAPI, routerPrefix, sessionId, blockletMetaUrl);
86
+ } else {
87
+ launchFn = createPromiseFn(_util2.launchSession.create, launchSessionAPI, routerPrefix, blockletMetaUrl);
126
88
  }
127
- const launch = await createPromiseFn(_util2.launchSession.create, launchSessionAPI, routerPrefix, blockletMetaUrl);
128
- return launch;
129
- });
89
+ const metadataFn = launchSessionAPI.get("/metadata?blockletMetaUrl=".concat(blockletMetaUrl)).then(res => res.data);
90
+ const [launch, metadata] = await Promise.all([launchFn, metadataFn]);
91
+ return {
92
+ launch,
93
+ metadata
94
+ };
95
+ }, [session.user, blockletMetaUrl]);
96
+ const productTypes = (0, _react.useMemo)(() => {
97
+ var _launchState$value, _window$blocklet;
98
+ const result = [];
99
+ if (launchState.loading) {
100
+ return result;
101
+ }
102
+ if (((_launchState$value = launchState.value) === null || _launchState$value === void 0 || (_launchState$value = _launchState$value.metadata) === null || _launchState$value === void 0 ? void 0 : _launchState$value.isBlockletSupportOnDemand) === false) {
103
+ _Toast.default.info(t('purchase.onDemandNotSupport'), {
104
+ persist: true
105
+ });
106
+ } else {
107
+ const name = 'serverless';
108
+ result.push({
109
+ name
110
+ });
111
+ }
112
+ if ((_window$blocklet = window.blocklet) !== null && _window$blocklet !== void 0 && (_window$blocklet = _window$blocklet.preferences) !== null && _window$blocklet !== void 0 && _window$blocklet.dedicatedPricingTableId) {
113
+ const name = 'dedicated';
114
+ result.push({
115
+ name
116
+ });
117
+ }
118
+ return result;
119
+ }, [launchState, t]);
120
+ (0, _react.useEffect)(() => {
121
+ const defaultType = productTypes.find(x => x.name === defaultProductTypeName) ? {
122
+ name: defaultProductTypeName
123
+ } : productTypes === null || productTypes === void 0 ? void 0 : productTypes[0];
124
+ if (defaultType) {
125
+ setState({
126
+ productType: defaultType
127
+ });
128
+ params.set('product_type', defaultType.name);
129
+ setParams(params, {
130
+ replace: true
131
+ });
132
+ }
133
+ }, [productTypes, defaultProductTypeName, params, setParams, setState]);
130
134
  const getPurchaseNewLink = (0, _react.useCallback)(() => {
131
- var _launchState$value;
132
- window.location = launchState === null || launchState === void 0 || (_launchState$value = launchState.value) === null || _launchState$value === void 0 || (_launchState$value = _launchState$value.app) === null || _launchState$value === void 0 ? void 0 : _launchState$value.appURL;
135
+ var _launchState$value2;
136
+ window.location = launchState === null || launchState === void 0 || (_launchState$value2 = launchState.value) === null || _launchState$value2 === void 0 || (_launchState$value2 = _launchState$value2.launch) === null || _launchState$value2 === void 0 || (_launchState$value2 = _launchState$value2.app) === null || _launchState$value2 === void 0 ? void 0 : _launchState$value2.appURL;
133
137
  const urlObj = new URL(window.location.href);
134
138
  urlObj.searchParams.delete('sessionId');
135
139
  return urlObj.href;
136
- }, [launchState === null || launchState === void 0 || (_launchState$value2 = launchState.value) === null || _launchState$value2 === void 0 || (_launchState$value2 = _launchState$value2.app) === null || _launchState$value2 === void 0 ? void 0 : _launchState$value2.appURL]);
140
+ }, [launchState === null || launchState === void 0 || (_launchState$value3 = launchState.value) === null || _launchState$value3 === void 0 || (_launchState$value3 = _launchState$value3.launch) === null || _launchState$value3 === void 0 || (_launchState$value3 = _launchState$value3.app) === null || _launchState$value3 === void 0 ? void 0 : _launchState$value3.appURL]);
137
141
  (0, _react.useEffect)(() => {
138
- const tmpLaunch = launchState.value;
142
+ var _launchState$value4;
143
+ const tmpLaunch = (_launchState$value4 = launchState.value) === null || _launchState$value4 === void 0 ? void 0 : _launchState$value4.launch;
139
144
  if (!tmpLaunch) {
140
145
  return;
141
146
  }
@@ -145,7 +150,7 @@ function Content(_ref) {
145
150
  replace: true
146
151
  });
147
152
  }
148
- }, [launchState.value, params, setParams]);
153
+ }, [(_launchState$value5 = launchState.value) === null || _launchState$value5 === void 0 ? void 0 : _launchState$value5.launch, params, setParams]);
149
154
  if (launchState.loading || blocklet.loading) {
150
155
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Center.default, {
151
156
  relative: "parent",
@@ -158,14 +163,15 @@ function Content(_ref) {
158
163
  const handlePaid = () => {
159
164
  navigate("/paid?&sessionId=".concat(launch._id, "&blocklet_meta_url=").concat(launch.blockletMetaUrl, "&from=").concat(from));
160
165
  };
161
- const handleChangeProductType = (a, newProductType) => {
162
- if (!newProductType) {
166
+ const handleChangeProductType = (_, typeName) => {
167
+ if (!typeName) {
163
168
  return;
164
169
  }
170
+ const newProductType = productTypes.find(x => x.name === typeName);
165
171
  setState({
166
172
  productType: newProductType
167
173
  });
168
- params.set('product_type', newProductType);
174
+ params.set('product_type', newProductType.name);
169
175
  setParams(params, {
170
176
  replace: true
171
177
  });
@@ -173,7 +179,7 @@ function Content(_ref) {
173
179
 
174
180
  // TODO: PaymentKitV2 处理支付失败的情况
175
181
 
176
- const launch = launchState.value;
182
+ const launch = (_launchState$value6 = launchState.value) === null || _launchState$value6 === void 0 ? void 0 : _launchState$value6.launch;
177
183
  if ([_constant.LAUNCH_STATUS.paid, _constant.LAUNCH_STATUS.nftMinted, _constant.LAUNCH_STATUS.allocated].includes(launch.status)) {
178
184
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_confirm.default, {
179
185
  title: t('purchase.unexpectedLaunchSession.paid'),
@@ -226,18 +232,24 @@ function Content(_ref) {
226
232
  children: [productTypes.length > 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ToggleButtonGroup.default, {
227
233
  orientation: "horizontal",
228
234
  color: "primary",
229
- value: state.productType,
235
+ value: (_state$productType = state.productType) === null || _state$productType === void 0 ? void 0 : _state$productType.name,
230
236
  size: "small",
231
237
  onChange: handleChangeProductType,
232
238
  exclusive: true,
233
- children: productTypes.map(type => {
239
+ sx: {
240
+ marginTop: '8px'
241
+ },
242
+ children: productTypes.map(_ref2 => {
243
+ let {
244
+ name
245
+ } = _ref2;
234
246
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ToggleButton.default, {
235
- value: type,
247
+ value: name,
236
248
  sx: {
237
249
  textTransform: 'capitalize'
238
250
  },
239
- children: t("purchase.productType.".concat(type))
240
- }, type);
251
+ children: t("purchase.productType.".concat(name))
252
+ }, name);
241
253
  })
242
254
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
243
255
  sx: {
@@ -251,7 +263,7 @@ function Content(_ref) {
251
263
  maxWidth: '100%'
252
264
  }
253
265
  },
254
- children: [state.productType === 'on-demand' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_onDemand.default, {
266
+ children: [((_state$productType2 = state.productType) === null || _state$productType2 === void 0 ? void 0 : _state$productType2.name) === 'serverless' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_onDemand.default, {
255
267
  launchSessionId: sessionId,
256
268
  handlePaid: handlePaid,
257
269
  components: (blocklet.components || []).map(x => ({
@@ -264,14 +276,16 @@ function Content(_ref) {
264
276
  logoPath: x.meta.logo
265
277
  })
266
278
  })),
267
- blockletStoreURL: (_ref2 = from !== 'did-spaces') !== null && _ref2 !== void 0 ? _ref2 : blocklet.registryUrl,
279
+ blockletStoreURL: (_ref3 = from !== 'did-spaces') !== null && _ref3 !== void 0 ? _ref3 : blocklet.registryUrl,
268
280
  connectApi: connectApi,
269
281
  session: session,
270
282
  t: t,
271
283
  locale: locale,
272
284
  api: launchSessionAPI,
273
- checkoutPath: "/payment/checkout"
274
- }), state.productType === 'dedicated' && ((_window$blocklet3 = window.blocklet) === null || _window$blocklet3 === void 0 || (_window$blocklet3 = _window$blocklet3.preferences) === null || _window$blocklet3 === void 0 ? void 0 : _window$blocklet3.dedicatedPricingTableId) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
285
+ freeTrialProducts: ((_launchState$value7 = launchState.value) === null || _launchState$value7 === void 0 || (_launchState$value7 = _launchState$value7.metadata) === null || _launchState$value7 === void 0 ? void 0 : _launchState$value7.freeTrialProducts) || [],
286
+ checkoutPath: "/payment/checkout",
287
+ minStakeAmount: (_launchState$value8 = launchState.value) === null || _launchState$value8 === void 0 || (_launchState$value8 = _launchState$value8.metadata) === null || _launchState$value8 === void 0 ? void 0 : _launchState$value8.minStakeAmount
288
+ }), ((_state$productType3 = state.productType) === null || _state$productType3 === void 0 ? void 0 : _state$productType3.name) === 'dedicated' && ((_window$blocklet2 = window.blocklet) === null || _window$blocklet2 === void 0 || (_window$blocklet2 = _window$blocklet2.preferences) === null || _window$blocklet2 === void 0 ? void 0 : _window$blocklet2.dedicatedPricingTableId) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
275
289
  sx: {
276
290
  display: 'flex',
277
291
  width: '100%',
@@ -308,13 +322,13 @@ function Content(_ref) {
308
322
  session: session,
309
323
  connect: connectApi,
310
324
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentReact.CheckoutTable, {
311
- id: (_window$blocklet4 = window.blocklet) === null || _window$blocklet4 === void 0 || (_window$blocklet4 = _window$blocklet4.preferences) === null || _window$blocklet4 === void 0 ? void 0 : _window$blocklet4.dedicatedPricingTableId,
325
+ id: (_window$blocklet3 = window.blocklet) === null || _window$blocklet3 === void 0 || (_window$blocklet3 = _window$blocklet3.preferences) === null || _window$blocklet3 === void 0 ? void 0 : _window$blocklet3.dedicatedPricingTableId,
312
326
  mode: "inline",
313
327
  extraParams: {
314
328
  'metadata.session_id': launch._id,
315
329
  'subscription_data.trial_end': (0, _util.getDefaultTrialEnd)(),
316
330
  'subscription_data.days_until_due': 0,
317
- 'subscription_data.days_until_cancel': ((_window$blocklet5 = window.blocklet) === null || _window$blocklet5 === void 0 || (_window$blocklet5 = _window$blocklet5.preferences) === null || _window$blocklet5 === void 0 ? void 0 : _window$blocklet5.daysUntilCancel) || 30
331
+ 'subscription_data.days_until_cancel': ((_window$blocklet4 = window.blocklet) === null || _window$blocklet4 === void 0 || (_window$blocklet4 = _window$blocklet4.preferences) === null || _window$blocklet4 === void 0 ? void 0 : _window$blocklet4.daysUntilCancel) || 30
318
332
  },
319
333
  onPaid: handlePaid
320
334
  })
@@ -342,10 +356,10 @@ function Content(_ref) {
342
356
  })
343
357
  });
344
358
  }
345
- function PreparePage(_ref3) {
359
+ function PreparePage(_ref4) {
346
360
  let {
347
361
  blocklet
348
- } = _ref3;
362
+ } = _ref4;
349
363
  const {
350
364
  t
351
365
  } = (0, _locale.useLocaleContext)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-workflow",
3
- "version": "2.3.32",
3
+ "version": "2.3.34",
4
4
  "description": "Purchase components for Launcher UI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -41,22 +41,22 @@
41
41
  "react": ">=18.1.0"
42
42
  },
43
43
  "dependencies": {
44
- "@arcblock/did-connect": "^2.10.3",
45
- "@arcblock/icons": "^2.10.3",
46
- "@arcblock/license": "^2.10.3",
47
- "@arcblock/react-hooks": "^2.10.3",
48
- "@arcblock/ux": "^2.10.3",
49
- "@blocklet/launcher-layout": "2.3.32",
50
- "@blocklet/launcher-util": "2.3.32",
51
- "@blocklet/launcher-ux": "2.3.32",
52
- "@blocklet/payment": "^1.13.289",
53
- "@blocklet/payment-react": "^1.13.289",
54
- "@emotion/react": "^11.11.4",
55
- "@emotion/styled": "^11.11.5",
56
- "@mui/icons-material": "^5.15.21",
57
- "@mui/lab": "^5.0.0-alpha.170",
58
- "@mui/material": "^5.15.21",
59
- "@ocap/util": "^1.18.124",
44
+ "@arcblock/did-connect": "^2.10.9",
45
+ "@arcblock/icons": "^2.10.9",
46
+ "@arcblock/license": "^2.10.9",
47
+ "@arcblock/react-hooks": "^2.10.9",
48
+ "@arcblock/ux": "^2.10.9",
49
+ "@blocklet/launcher-layout": "2.3.34",
50
+ "@blocklet/launcher-util": "2.3.34",
51
+ "@blocklet/launcher-ux": "2.3.34",
52
+ "@blocklet/payment": "^1.14.5",
53
+ "@blocklet/payment-react": "^1.14.5",
54
+ "@emotion/react": "^11.13.0",
55
+ "@emotion/styled": "^11.13.0",
56
+ "@mui/icons-material": "^5.16.5",
57
+ "@mui/lab": "^5.0.0-alpha.173",
58
+ "@mui/material": "^5.16.5",
59
+ "@ocap/util": "^1.18.126",
60
60
  "@splidejs/react-splide": "^0.7.12",
61
61
  "@splidejs/splide": "^4.1.4",
62
62
  "@splidejs/splide-extension-grid": "^0.4.1",
@@ -75,17 +75,17 @@
75
75
  "moment": "^2.30.1",
76
76
  "prop-types": "^15.8.1",
77
77
  "react-lottie-player": "^1.5.6",
78
- "react-router-dom": "^6.24.0",
79
- "react-use": "^17.5.0",
78
+ "react-router-dom": "^6.25.1",
79
+ "react-use": "^17.5.1",
80
80
  "url-join": "^4.0.1"
81
81
  },
82
82
  "devDependencies": {
83
- "@babel/cli": "^7.24.7",
84
- "@babel/core": "^7.24.7",
85
- "@babel/preset-env": "^7.24.7",
83
+ "@babel/cli": "^7.24.8",
84
+ "@babel/core": "^7.24.9",
85
+ "@babel/preset-env": "^7.25.0",
86
86
  "@babel/preset-react": "^7.24.7",
87
87
  "babel-plugin-inline-react-svg": "^2.0.2",
88
- "glob": "^10.4.2"
88
+ "glob": "^10.4.5"
89
89
  },
90
90
  "exports": {
91
91
  ".": {
@@ -105,5 +105,5 @@
105
105
  "require": "./lib/locales/index.js"
106
106
  }
107
107
  },
108
- "gitHead": "9f5402fdad12728aa1316e4d039dc4f30b7e5daf"
108
+ "gitHead": "54c8d4db562dd766ed25c2adb05b00f4430d2083"
109
109
  }