@blocklet/sdk 1.16.27 → 1.16.28-beta-bfbab430

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.
@@ -27,6 +27,10 @@ declare const getResourceExportDir: ({ projectId, releaseId }?: {
27
27
  projectId: string;
28
28
  releaseId?: string;
29
29
  }) => string;
30
+ declare const getReleaseExportDir: ({ projectId, releaseId }: {
31
+ projectId: string;
32
+ releaseId?: string;
33
+ }) => string;
30
34
  declare const getResources: ({ scope, types, skipRunningCheck, }?: {
31
35
  scope?: 'all' | 'pack' | 'excludePack';
32
36
  did?: string;
@@ -49,6 +53,7 @@ export { getComponentMountPoint };
49
53
  export { getComponentWebEndpoint };
50
54
  export { waitForComponentRunning };
51
55
  export { getResourceExportDir };
56
+ export { getReleaseExportDir };
52
57
  export { getResources };
53
58
  export { getPackResources };
54
59
  declare const _default: {
@@ -61,6 +66,10 @@ declare const _default: {
61
66
  projectId: string;
62
67
  releaseId?: string;
63
68
  }) => string;
69
+ getReleaseExportDir: ({ projectId, releaseId }: {
70
+ projectId: string;
71
+ releaseId?: string;
72
+ }) => string;
64
73
  getResources: ({ scope, types, skipRunningCheck, }?: {
65
74
  scope?: "all" | "pack" | "excludePack";
66
75
  did?: string;
@@ -26,11 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getPackResources = exports.getResources = exports.getResourceExportDir = exports.waitForComponentRunning = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
29
+ exports.getPackResources = exports.getResources = exports.getReleaseExportDir = exports.getResourceExportDir = exports.waitForComponentRunning = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
30
30
  const path_1 = require("path");
31
31
  const axios_1 = __importDefault(require("axios"));
32
32
  const get_1 = __importDefault(require("lodash/get"));
33
- const url_join_1 = __importDefault(require("url-join"));
33
+ const ufo_1 = require("ufo");
34
34
  const wait_port_1 = __importDefault(require("wait-port"));
35
35
  const constant_1 = require("@blocklet/constant");
36
36
  const config_1 = require("../config");
@@ -82,7 +82,7 @@ const call = async ({ name, method = 'POST', path: _path, ...options }) => {
82
82
  if (!baseURL) {
83
83
  throw new Error(`can not find web endpoint for ${name}`);
84
84
  }
85
- const url = (0, url_join_1.default)(baseURL, _path);
85
+ const url = (0, ufo_1.joinURL)(baseURL, _path);
86
86
  try {
87
87
  const resp = await doCall({ url, method, ...options });
88
88
  return resp;
@@ -103,7 +103,7 @@ exports.getComponentMountPoint = getComponentMountPoint;
103
103
  const getUrl = (...parts) => {
104
104
  const { BLOCKLET_COMPONENT_DID, BLOCKLET_APP_URL } = process.env;
105
105
  const mountPoint = getComponentMountPoint(BLOCKLET_COMPONENT_DID);
106
- return (0, url_join_1.default)(BLOCKLET_APP_URL, mountPoint === '/' ? '' : mountPoint, ...parts);
106
+ return (0, ufo_1.joinURL)(BLOCKLET_APP_URL, mountPoint === '/' ? '' : mountPoint, ...parts);
107
107
  };
108
108
  exports.getUrl = getUrl;
109
109
  const getResourceExportDir = ({ projectId, releaseId } = { projectId: '' }) => {
@@ -119,6 +119,18 @@ const getResourceExportDir = ({ projectId, releaseId } = { projectId: '' }) => {
119
119
  return dir;
120
120
  };
121
121
  exports.getResourceExportDir = getResourceExportDir;
122
+ const getReleaseExportDir = ({ projectId, releaseId }) => {
123
+ if (!projectId) {
124
+ throw new Error('getReleaseExportDir: projectId is required');
125
+ }
126
+ const dirArr = [process.env.BLOCKLET_APP_DATA_DIR, constant_1.PROJECT.DIR, projectId];
127
+ if (releaseId) {
128
+ dirArr.push(constant_1.PROJECT.RELEASE_DIR, releaseId || '/');
129
+ }
130
+ const dir = (0, path_1.join)(...dirArr);
131
+ return dir;
132
+ };
133
+ exports.getReleaseExportDir = getReleaseExportDir;
122
134
  const getResources = ({ scope = 'all', types, skipRunningCheck, } = {}) => {
123
135
  return Util.getResources({ components: config_1.components, scope, types, skipRunningCheck });
124
136
  };
@@ -137,10 +149,13 @@ const waitForComponentRunning = async (name, timeout = 30000, interval = 250) =>
137
149
  throw new Error(`can not find port for component ${name}`);
138
150
  }
139
151
  const result = await (0, wait_port_1.default)({ host: '127.0.0.1', port, timeout, interval });
140
- if (result.open) {
152
+ if (typeof result === 'boolean' && result) {
153
+ return true;
154
+ }
155
+ if (typeof result.open === 'boolean' && result.open) {
141
156
  return true;
142
157
  }
143
- throw new Error(`component ${name} is not running not unreachable`);
158
+ throw new Error(`component ${name} is not running or unreachable`);
144
159
  };
145
160
  exports.waitForComponentRunning = waitForComponentRunning;
146
161
  exports.default = {
@@ -150,6 +165,7 @@ exports.default = {
150
165
  getComponentWebEndpoint,
151
166
  waitForComponentRunning,
152
167
  getResourceExportDir,
168
+ getReleaseExportDir,
153
169
  getResources,
154
170
  getPackResources,
155
171
  };
package/lib/config.js CHANGED
@@ -8,7 +8,7 @@ exports._handleComponentConfigUpdate = exports._handleComponentRemoved = exports
8
8
  /* eslint-disable no-console */
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = __importDefault(require("fs"));
11
- const url_join_1 = __importDefault(require("url-join"));
11
+ const ufo_1 = require("ufo");
12
12
  const events_1 = __importDefault(require("events"));
13
13
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
14
14
  const throttle_1 = __importDefault(require("lodash/throttle"));
@@ -229,7 +229,7 @@ const fetchBlockletJs = async () => {
229
229
  const componentDid = process.env.BLOCKLET_COMPONENT_DID;
230
230
  try {
231
231
  const { mountPoint } = componentStore.find((x) => x.did === componentDid);
232
- const res = await axios_1.default.get((0, url_join_1.default)(env.appUrl, mountPoint === '/' ? '' : mountPoint, `__blocklet__.js?force=1&t=${Date.now()}`), {
232
+ const res = await axios_1.default.get((0, ufo_1.joinURL)(env.appUrl, mountPoint === '/' ? '' : mountPoint, `__blocklet__.js?force=1&t=${Date.now()}`), {
233
233
  timeout: 8000,
234
234
  headers: {
235
235
  'User-Agent': `BlockletSDK/${version_1.version}`,
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
- const url_join_1 = __importDefault(require("url-join"));
7
+ const ufo_1 = require("ufo");
8
8
  const escape_1 = __importDefault(require("lodash/escape"));
9
9
  const config_1 = require("../config");
10
10
  const fallback = (file, options = {}) => {
@@ -22,7 +22,7 @@ const fallback = (file, options = {}) => {
22
22
  const pageData = typeof options.getPageData === 'function' ? await options.getPageData(req) : {};
23
23
  pageData.title = (0, escape_1.default)(pageData.title || config_1.env.appName);
24
24
  pageData.description = (0, escape_1.default)(pageData.description || config_1.env.appDescription);
25
- pageData.ogImage = pageData.ogImage || (0, url_join_1.default)(config_1.env.appUrl || '/', '/.well-known/service/blocklet/og.png');
25
+ pageData.ogImage = pageData.ogImage || (0, ufo_1.joinURL)(config_1.env.appUrl || '/', '/.well-known/service/blocklet/og.png');
26
26
  let source = sourceRaw.slice(0);
27
27
  // inject seo title
28
28
  if (pageData.title) {
@@ -59,5 +59,6 @@ interface AuthService {
59
59
  deletePermission(name: string): Promise<Client.GeneralResponse>;
60
60
  getBlocklet(attachRuntimeInfo?: boolean): Promise<Client.ResponseBlocklet>;
61
61
  clearCache(args?: OmitTeamDid<Client.RequestClearCacheInput>): Promise<Client.ResponseClearCache>;
62
+ getComponent(did: string): Promise<Client.ComponentState>;
62
63
  }
63
64
  export = AuthService;
@@ -6,7 +6,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  /* eslint-disable max-classes-per-file */
7
7
  /* eslint-disable @typescript-eslint/indent */
8
8
  const pickBy_1 = __importDefault(require("lodash/pickBy"));
9
- const url_join_1 = __importDefault(require("url-join"));
9
+ const ufo_1 = require("ufo");
10
10
  const client_1 = __importDefault(require("@abtnode/client"));
11
11
  const semver_1 = __importDefault(require("semver"));
12
12
  const mcrypto_1 = require("@ocap/mcrypto");
@@ -14,6 +14,7 @@ const wallet_1 = require("@ocap/wallet");
14
14
  const env_1 = require("@blocklet/env");
15
15
  const constant_1 = __importDefault(require("@abtnode/constant"));
16
16
  const constant_2 = require("@blocklet/constant");
17
+ const util_1 = require("@blocklet/meta/lib/util");
17
18
  const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env"));
18
19
  const version_1 = require("../version");
19
20
  const wallet_2 = __importDefault(require("../wallet"));
@@ -29,7 +30,7 @@ const type = chainType !== 'ethereum' && chainType !== 'eth'
29
30
  const fixAvatar = (user) => {
30
31
  const avatar = user?.avatar;
31
32
  if (avatar && avatar.startsWith(USER_AVATAR_URL_PREFIX)) {
32
- user.avatar = (0, url_join_1.default)(WELLKNOWN_SERVICE_PATH_PREFIX, USER_AVATAR_PATH_PREFIX, avatar.replace(USER_AVATAR_URL_PREFIX, ''));
33
+ user.avatar = (0, ufo_1.joinURL)(WELLKNOWN_SERVICE_PATH_PREFIX, USER_AVATAR_PATH_PREFIX, avatar.replace(USER_AVATAR_URL_PREFIX, ''));
33
34
  }
34
35
  return user;
35
36
  };
@@ -64,10 +65,11 @@ class AuthService {
64
65
  constructor(httpEndpoint) {
65
66
  const client = new AuthClient(httpEndpoint);
66
67
  const apiList = [
67
- // user
68
+ // session
68
69
  'login',
69
70
  'switchProfile',
70
71
  'refreshSession',
72
+ // user
71
73
  'getUsers',
72
74
  'getUsersCount',
73
75
  'getUsersCountPerRole',
@@ -115,6 +117,7 @@ class AuthService {
115
117
  // 'configTrustedFactories',
116
118
  // blocklet
117
119
  'getBlocklet',
120
+ 'getComponent',
118
121
  'clearCache',
119
122
  ];
120
123
  const teamDid = process.env.BLOCKLET_DID;
@@ -185,6 +188,10 @@ class AuthService {
185
188
  throw new Error(err.response ? err.response.data : err.message);
186
189
  }
187
190
  };
191
+ this.getComponent = async (did) => {
192
+ const { blocklet } = await this.getBlocklet();
193
+ return (0, util_1.findComponentByIdV2)(blocklet, did);
194
+ };
188
195
  // eslint-disable-next-line no-constructor-return
189
196
  return new Proxy(this, {
190
197
  get(target, propKey) {
@@ -111,6 +111,7 @@ export interface TSendOptions {
111
111
  * Any Property
112
112
  */
113
113
  [x: string]: any;
114
+ channels?: ('app' | 'email' | 'push' | 'webhook')[];
114
115
  keepForOfflineUser?: boolean;
115
116
  locale?: string;
116
117
  }
@@ -33,6 +33,7 @@ const JWT = __importStar(require("@arcblock/jwt"));
33
33
  const constant_1 = __importDefault(require("@abtnode/constant"));
34
34
  const channel_1 = require("@blocklet/meta/lib/channel");
35
35
  const did_1 = require("@arcblock/did");
36
+ const ufo_1 = require("ufo");
36
37
  const index_1 = require("../validators/index");
37
38
  const constants_1 = require("./constants");
38
39
  const version_1 = require("../version");
@@ -53,7 +54,7 @@ const getRequestHeaders = () => ({ 'User-Agent': `BlockletSDK/${VERSION}` });
53
54
  * @returns
54
55
  */
55
56
  const sendToUser = async (receiver, notification, { appDid, appSk, type }, port = process.env.ABT_NODE_SERVICE_PORT, options = {}, pathname = 'send-to-user') => {
56
- if (pathname === 'send-to-user') {
57
+ if (['send-to-user', 'send-to-push-kit'].includes(pathname)) {
57
58
  await (0, index_1.validateReceiver)(receiver);
58
59
  }
59
60
  if (pathname === 'send-to-mail') {
@@ -65,7 +66,7 @@ const sendToUser = async (receiver, notification, { appDid, appSk, type }, port
65
66
  await (0, index_1.validateNotification)(notification);
66
67
  }
67
68
  try {
68
- const { data: res } = await axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/api/${pathname}`, {
69
+ const { data: res } = await axios.post((0, ufo_1.joinURL)(`http://127.0.0.1:${port}`, constants_1.SERVICE_PREFIX, 'api', pathname), {
69
70
  apiVersion: VERSION,
70
71
  data: {
71
72
  sender: {
@@ -1,9 +1,10 @@
1
1
  import { DIDTypeShortcut } from '@arcblock/did';
2
- declare const verify: (data: object, sig: string, { type, appSk }?: {
2
+ declare const verify: (data: object, sig: string, { type, appSk, appPk, }?: {
3
3
  type?: DIDTypeShortcut;
4
4
  appSk?: string;
5
- }) => boolean;
6
- declare const sign: (data: object, { type, appSk }?: {
5
+ appPk?: string;
6
+ }) => any;
7
+ declare const sign: (data: object, { type, appSk, }?: {
7
8
  type?: DIDTypeShortcut;
8
9
  appSk?: string;
9
10
  }) => string;
@@ -2,19 +2,48 @@
2
2
  /*
3
3
  * @Description: 用于 sdk 中调用 blocklet-service 接口时的加解密工具库
4
4
  */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
5
28
  var __importDefault = (this && this.__importDefault) || function (mod) {
6
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
7
30
  };
8
31
  Object.defineProperty(exports, "__esModule", { value: true });
9
32
  exports.sign = exports.verify = void 0;
10
33
  const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
11
- const wallet_1 = __importDefault(require("../wallet"));
12
- const verify = (data, sig, { type, appSk } = {}) => {
34
+ const wallet_1 = __importStar(require("../wallet"));
35
+ const verify = (data, sig, { type, appSk, appPk, } = {}) => {
13
36
  try {
14
37
  if (!sig) {
15
38
  throw new Error('empty sig');
16
39
  }
17
- const wallet = (0, wallet_1.default)(type, appSk);
40
+ let wallet;
41
+ if (appPk) {
42
+ wallet = (0, wallet_1.getPkWallet)(type, appPk);
43
+ }
44
+ else {
45
+ wallet = (0, wallet_1.default)(type, appSk);
46
+ }
18
47
  const verified = wallet.verify((0, json_stable_stringify_1.default)(data || {}), sig);
19
48
  return verified;
20
49
  }
@@ -23,7 +52,7 @@ const verify = (data, sig, { type, appSk } = {}) => {
23
52
  }
24
53
  };
25
54
  exports.verify = verify;
26
- const sign = (data, { type, appSk } = {}) => {
55
+ const sign = (data, { type, appSk, } = {}) => {
27
56
  const wallet = (0, wallet_1.default)(type, appSk);
28
57
  return wallet.sign((0, json_stable_stringify_1.default)(data || {}));
29
58
  };
@@ -206,6 +206,7 @@ const inputReceiverSchema = Joi.array().items(receiverSchema).single().required(
206
206
  const optionSchema = Joi.object({
207
207
  keepForOfflineUser: Joi.boolean(),
208
208
  locale: Joi.string(),
209
+ channels: Joi.array().items(Joi.allow('app', 'email', 'push', 'webhook')).optional(),
209
210
  })
210
211
  .unknown()
211
212
  .meta({ className: 'TSendOptions', unknownType: 'any' });
package/lib/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const version = "1.16.27";
1
+ declare const version = "1.16.28";
2
2
  export { version };
3
3
  declare const _default: {
4
4
  version: string;
package/lib/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- const version = '1.16.27';
4
+ const version = '1.16.28';
5
5
  exports.version = version;
6
6
  exports.default = { version };
package/lib/wallet.d.ts CHANGED
@@ -9,5 +9,6 @@ declare const getWallet: {
9
9
  (type?: DIDTypeShortcut, appSk?: string): WalletObject;
10
10
  getPermanentWallet: () => WalletObject<string>;
11
11
  getEthereumWallet: (permanent?: boolean) => WalletObject<string>;
12
+ getPkWallet(type?: DIDTypeShortcut, appPk?: string): WalletObject<string>;
12
13
  };
13
14
  export = getWallet;
package/lib/wallet.js CHANGED
@@ -28,4 +28,20 @@ const getPermanentWallet = () => getWallet(process.env.CHAIN_TYPE || process.env
28
28
  const getEthereumWallet = (permanent = false) => getWallet('ethereum', permanent ? process.env.BLOCKLET_APP_PSK : process.env.BLOCKLET_APP_SK);
29
29
  getWallet.getPermanentWallet = getPermanentWallet;
30
30
  getWallet.getEthereumWallet = getEthereumWallet;
31
+ getWallet.getPkWallet = (type, appPk = process.env.BLOCKLET_APP_PK) => {
32
+ let t;
33
+ let sk;
34
+ // BLOCKLET_WALLET_TYPE is for backward compatibility
35
+ // eslint-disable-next-line no-param-reassign
36
+ type = type || process.env.CHAIN_TYPE || process.env.BLOCKLET_WALLET_TYPE;
37
+ if ((0, did_1.isEthereumType)((0, did_1.DidType)(type))) {
38
+ sk = appPk.slice(0, 66);
39
+ t = (0, wallet_1.WalletType)(type);
40
+ }
41
+ else {
42
+ sk = appPk;
43
+ t = (0, wallet_1.WalletType)({ role: mcrypto_1.types.RoleType.ROLE_APPLICATION, pk: mcrypto_1.types.KeyType.ED25519, hash: mcrypto_1.types.HashType.SHA3 });
44
+ }
45
+ return (0, wallet_1.fromPublicKey)(sk, t);
46
+ };
31
47
  module.exports = getWallet;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.27",
6
+ "version": "1.16.28-beta-bfbab430",
7
7
  "description": "graphql client to read/write data on abt node",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
@@ -27,15 +27,15 @@
27
27
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@abtnode/client": "1.16.27",
31
- "@abtnode/constant": "1.16.27",
30
+ "@abtnode/client": "1.16.28-beta-bfbab430",
31
+ "@abtnode/constant": "1.16.28-beta-bfbab430",
32
32
  "@arcblock/did": "1.18.123",
33
33
  "@arcblock/did-auth": "1.18.123",
34
34
  "@arcblock/jwt": "1.18.123",
35
35
  "@arcblock/ws": "1.18.123",
36
- "@blocklet/constant": "1.16.27",
37
- "@blocklet/env": "1.16.27",
38
- "@blocklet/meta": "1.16.27",
36
+ "@blocklet/constant": "1.16.28-beta-bfbab430",
37
+ "@blocklet/env": "1.16.28-beta-bfbab430",
38
+ "@blocklet/meta": "1.16.28-beta-bfbab430",
39
39
  "@did-connect/authenticator": "^2.2.4",
40
40
  "@did-connect/handler": "^2.2.4",
41
41
  "@nedb/core": "^2.1.5",
@@ -51,7 +51,6 @@
51
51
  "semver": "^7.3.8",
52
52
  "sitemap": "^7.1.1",
53
53
  "ufo": "^1.1.1",
54
- "url-join": "^4.0.1",
55
54
  "wait-port": "^1.1.0"
56
55
  },
57
56
  "resolutions": {
@@ -76,5 +75,5 @@
76
75
  "ts-node": "^10.9.1",
77
76
  "typescript": "^5.0.4"
78
77
  },
79
- "gitHead": "b7dcd46b040c5ad3a273b14b1a411fafc1390828"
78
+ "gitHead": "f1fbf0752de46be00d1faa0d54eb7d28016e0bb9"
80
79
  }