@blocklet/sdk 1.8.42 → 1.8.43

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,9 +1,31 @@
1
1
  import Client from '@abtnode/client';
2
- declare type $TSFixMe = any;
3
- declare class AuthService extends Client {
4
- _blockletDid: string;
5
- setAuthAccessKey: $TSFixMe;
6
- constructor(httpEndpoint: string);
7
- _getAuthHeaders(): any;
2
+ declare type PartialDeep<T> = {
3
+ [K in keyof T]?: T[K] extends object ? PartialDeep<T[K]> : T[K];
4
+ };
5
+ declare type OmitTeamDid<T> = PartialDeep<Omit<T, 'teamDid'>>;
6
+ declare class AuthService {
7
+ constructor(httpEndpoint?: string);
8
+ }
9
+ interface AuthService {
10
+ getUser(did: string): Promise<Client.ResponseUser>;
11
+ getUsers(args?: OmitTeamDid<Client.RequestUsersInput>): Promise<Client.ResponseUsers>;
12
+ getOwner(): Promise<Client.ResponseUser>;
13
+ updateUserApproval(did: string, approved: boolean): Promise<Client.ResponseUser>;
14
+ issuePassportToUser(args: OmitTeamDid<Client.RequestIssuePassportToUserInput>): Promise<Client.ResponseUser>;
15
+ enableUserPassport(args: OmitTeamDid<Client.RequestRevokeUserPassportInput>): Promise<Client.ResponseUser>;
16
+ revokeUserPassport(args: OmitTeamDid<Client.RequestRevokeUserPassportInput>): Promise<Client.ResponseUser>;
17
+ getPermissionsByRole(role: string): Promise<Client.ResponsePermissions>;
18
+ getRoles(): Promise<Client.ResponseRoles>;
19
+ createRole(args: OmitTeamDid<Client.RequestCreateRoleInput>): Promise<Client.ResponseRole>;
20
+ updateRole(name: string, updates: Pick<Client.RoleInput, 'title' | 'description'>): Promise<Client.ResponseRole>;
21
+ deleteRole(name: string): Promise<Client.GeneralResponse>;
22
+ grantPermissionForRole(role: string, permission: string): Promise<Client.GeneralResponse>;
23
+ revokePermissionFromRole(role: string, permission: string): Promise<Client.GeneralResponse>;
24
+ updatePermissionsForRole(role: string, permissions: string): Promise<Client.ResponseRole>;
25
+ hasPermission(role: string, permission: string): Promise<ABTNodeClient.BooleanResponse>;
26
+ getPermissions(): Promise<Client.ResponsePermissions>;
27
+ createPermission(args: OmitTeamDid<Client.RequestCreatePermissionInput>): Promise<Client.ResponsePermission>;
28
+ updatePermission(args: OmitTeamDid<Client.PermissionInput>): Promise<Client.ResponsePermission>;
29
+ deletePermission(name: string): Promise<Client.GeneralResponse>;
8
30
  }
9
31
  export = AuthService;
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
+ /* eslint-disable max-classes-per-file */
14
15
  /* eslint-disable @typescript-eslint/indent */
15
16
  const pickBy_1 = __importDefault(require("lodash/pickBy"));
16
17
  const url_join_1 = __importDefault(require("url-join"));
@@ -22,10 +23,6 @@ const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env
22
23
  const version_1 = require("../version");
23
24
  const { NODE_SERVICES, WELLKNOWN_SERVICE_PATH_PREFIX, USER_AVATAR_URL_PREFIX, USER_AVATAR_PATH_PREFIX } = constant_1.default;
24
25
  const VERSION = version_1.version; // version of notification sdk
25
- // Auth 相关的功能 API 都在这里
26
- // core/state/lib/api/team.js L42
27
- // 所有可配置调用的函数在这里,如果需要额外增加,则需要在这里新增对应的函数
28
- // core/gql/lib/config.js L25
29
26
  const isNotNullOrUndefined = (x) => ![null, undefined].includes(x);
30
27
  const type = process.env.BLOCKLET_WALLET_TYPE !== 'eth'
31
28
  ? (0, wallet_1.WalletType)({ role: mcrypto_1.types.RoleType.ROLE_APPLICATION, pk: mcrypto_1.types.KeyType.ED25519, hash: mcrypto_1.types.HashType.SHA3 })
@@ -37,26 +34,39 @@ const fixAvatar = (user) => {
37
34
  }
38
35
  return user;
39
36
  };
40
- // FIXME: types from @abtnode/types
41
- class AuthService extends client_1.default {
37
+ class AuthClient extends client_1.default {
42
38
  constructor(httpEndpoint) {
43
39
  (0, check_blocklet_env_1.default)();
44
- // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 2.
45
40
  super(httpEndpoint || `http://127.0.0.1:${process.env.ABT_NODE_PORT}/api/gql`.trim(), `BlockletSDK/${VERSION}`);
46
41
  this.setAuthAccessKey({
47
42
  accessKeyId: process.env.BLOCKLET_APP_ID,
48
43
  accessKeySecret: process.env.BLOCKLET_APP_SK,
49
44
  type,
50
45
  });
51
- this._blockletDid = process.env.BLOCKLET_DID;
46
+ }
47
+ _getAuthHeaders() {
48
+ const headers = super._getAuthHeaders();
49
+ headers['x-access-blocklet'] = process.env.BLOCKLET_DID;
50
+ // x-access-service is not used since 1.8.35
51
+ headers['x-access-service'] = NODE_SERVICES.AUTH_SERVICE;
52
+ return headers;
53
+ }
54
+ }
55
+ // Auth 相关的功能 API 都在这里
56
+ // core/state/lib/api/team.js L42
57
+ // 所有可配置调用的函数在这里,如果需要额外增加,则需要在这里新增对应的函数
58
+ // core/gql/lib/config.js L25
59
+ class AuthService {
60
+ constructor(httpEndpoint) {
61
+ const client = new AuthClient(httpEndpoint);
52
62
  const apiList = [
53
63
  // user
54
64
  'getUsers',
55
65
  'getUser',
56
66
  'getOwner',
57
67
  // 'removeUser',
58
- 'updateUserRole',
59
- // 'updateUserApproval',
68
+ // 'updateUserRole',
69
+ 'updateUserApproval',
60
70
  // invitation
61
71
  // 'getInvitations',
62
72
  // 'createMemberInvitation',
@@ -86,9 +96,9 @@ class AuthService extends client_1.default {
86
96
  // disabled in current
87
97
  // 'configTrustedPassports',
88
98
  ];
89
- const teamDid = this._blockletDid;
99
+ const teamDid = process.env.BLOCKLET_DID;
90
100
  const apiFallback = (fn) => (params = {}, ...args) => fn(Object.assign({ input: Object.assign(Object.assign({}, params), { teamDid }) }, args));
91
- const apiConvertDid = (fn) => (did) => fn({ input: { user: { did }, teamDid } });
101
+ // const apiConvertDid = (fn: Function) => (did: string) => fn({ input: { user: { did }, teamDid } });
92
102
  const apiFnMap = {
93
103
  getUser: (fn) => (did) => __awaiter(this, void 0, void 0, function* () {
94
104
  const res = yield fn({ input: { user: { did }, teamDid } });
@@ -100,8 +110,8 @@ class AuthService extends client_1.default {
100
110
  (res.users || []).forEach(fixAvatar);
101
111
  return res;
102
112
  }),
103
- removeUser: apiConvertDid,
104
- updateUserRole: (fn) => (did, role) => fn({ input: { user: { did, role }, teamDid } }),
113
+ // removeUser: apiConvertDid,
114
+ // updateUserRole: (fn: Function) => (did: string, role: string) => fn({ input: { user: { did, role }, teamDid } }),
105
115
  updateUserApproval: (fn) => (did, approved) => fn({ input: { user: { did, approved }, teamDid } }),
106
116
  getPermissionsByRole: (fn) => (name) => fn({ input: { role: { name }, teamDid } }),
107
117
  createRole: (fn) => ({ name, title, description }) => fn({ input: Object.assign(Object.assign({}, (0, pickBy_1.default)({ name, title, description }, isNotNullOrUndefined)), { teamDid }) }),
@@ -116,13 +126,12 @@ class AuthService extends client_1.default {
116
126
  hasPermission: (fn) => (role, permission) => fn({ input: { teamDid, role, permission } }),
117
127
  };
118
128
  apiList.forEach((api) => {
119
- const fn = this[api];
129
+ const fn = client[api];
120
130
  this[api] = apiFnMap[api] ? apiFnMap[api](fn) : apiFallback(fn);
121
131
  });
122
132
  // eslint-disable-next-line no-constructor-return
123
133
  return new Proxy(this, {
124
134
  get(target, propKey) {
125
- // @ts-expect-error TS(2345) FIXME: Argument of type 'string | symbol' is not assignab... Remove this comment to see the full error message
126
135
  if (!apiList.includes(propKey)) {
127
136
  return undefined;
128
137
  }
@@ -130,13 +139,5 @@ class AuthService extends client_1.default {
130
139
  },
131
140
  });
132
141
  }
133
- _getAuthHeaders() {
134
- // @ts-expect-error TS(2339) FIXME: Property '_getAuthHeaders' does not exist on type ... Remove this comment to see the full error message
135
- const headers = super._getAuthHeaders();
136
- headers['x-access-blocklet'] = this._blockletDid;
137
- // x-access-service is not used since 1.8.35
138
- headers['x-access-service'] = NODE_SERVICES.AUTH_SERVICE;
139
- return headers;
140
- }
141
142
  }
142
143
  module.exports = AuthService;
package/lib/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const version = "1.8.42";
1
+ declare const version = "1.8.43";
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.8.42';
4
+ const version = '1.8.43';
5
5
  exports.version = version;
6
6
  exports.default = { version };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.42",
6
+ "version": "1.8.43",
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",
@@ -26,21 +26,21 @@
26
26
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@abtnode/client": "1.8.42",
30
- "@abtnode/constant": "1.8.42",
31
- "@arcblock/did-auth": "1.18.26",
32
- "@arcblock/jwt": "1.18.26",
33
- "@arcblock/ws": "1.18.26",
34
- "@blocklet/constant": "1.8.42",
35
- "@blocklet/meta": "1.8.42",
36
- "@did-connect/authenticator": "^2.1.26",
37
- "@did-connect/handler": "^2.1.26",
29
+ "@abtnode/client": "1.8.43",
30
+ "@abtnode/constant": "1.8.43",
31
+ "@arcblock/did-auth": "1.18.30",
32
+ "@arcblock/jwt": "1.18.30",
33
+ "@arcblock/ws": "1.18.30",
34
+ "@blocklet/constant": "1.8.43",
35
+ "@blocklet/meta": "1.8.43",
36
+ "@did-connect/authenticator": "^2.1.29",
37
+ "@did-connect/handler": "^2.1.29",
38
38
  "@nedb/core": "^2.0.5",
39
- "@ocap/mcrypto": "1.18.26",
40
- "@ocap/wallet": "1.18.26",
39
+ "@ocap/mcrypto": "1.18.30",
40
+ "@ocap/wallet": "1.18.30",
41
41
  "axios": "^0.27.2",
42
42
  "fs-extra": "^10.1.0",
43
- "joi": "17.6.3",
43
+ "joi": "17.7.0",
44
44
  "json-stable-stringify": "^1.0.1",
45
45
  "lodash": "^4.17.21",
46
46
  "lru-cache": "^6.0.0",
@@ -69,5 +69,5 @@
69
69
  "ts-node": "^10.9.1",
70
70
  "typescript": "^4.8.4"
71
71
  },
72
- "gitHead": "04771ed44e11deb3f214b637be6e3b78ca2b9245"
72
+ "gitHead": "5c6b7b09f6252a83523594aead6c722bf4ba0d0c"
73
73
  }