@did-space/template 0.3.67 → 0.3.69
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/dist/schema/app.js +4 -0
- package/dist/template/app.d.ts +15 -1
- package/dist/template/app.js +31 -0
- package/package.json +7 -7
package/dist/schema/app.js
CHANGED
|
@@ -16,6 +16,10 @@ exports.AppSchema = validator_1.Joi.object({
|
|
|
16
16
|
backup: validator_1.Joi.array().items(app_backup_1.AppBackupSchema).optional().default([]),
|
|
17
17
|
restore: validator_1.Joi.array().items(app_restore_1.AppRestoreSchema).optional().default([]),
|
|
18
18
|
disconnected: validator_1.Joi.array().items(app_disconnected_1.AppDisconnectedSchema).optional().default([]),
|
|
19
|
+
permissions: validator_1.Joi.object()
|
|
20
|
+
.pattern(validator_1.Joi.string(), validator_1.Joi.object().pattern(validator_1.Joi.string(), validator_1.Joi.number()))
|
|
21
|
+
.optional()
|
|
22
|
+
.default({}),
|
|
19
23
|
createAt: validator_1.Joi.string()
|
|
20
24
|
.optional()
|
|
21
25
|
.default(() => new Date().toISOString()),
|
package/dist/template/app.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Space, App, AppBackup, AppRestore, AppConnected, AppDisconnected } from '@did-space/core';
|
|
1
|
+
import { Space, App, AppBackup, AppRestore, AppConnected, AppDisconnected, type AppPermissions } from '@did-space/core';
|
|
2
2
|
export interface AppTemplateOptions {
|
|
3
3
|
space: Space;
|
|
4
4
|
appDid: string;
|
|
@@ -29,4 +29,18 @@ export declare class AppTemplate {
|
|
|
29
29
|
updateAppBackupById(id: string, appBackup: Omit<AppBackup, 'id'>): Promise<AppBackup>;
|
|
30
30
|
addAppRestore(appRestore: AppRestore): Promise<AppRestore>;
|
|
31
31
|
updateAppRestoreById(id: string, appRestore: Omit<AppRestore, 'id'>): Promise<AppRestore>;
|
|
32
|
+
static readonly PermissionMap: {
|
|
33
|
+
listable: string;
|
|
34
|
+
readable: string;
|
|
35
|
+
writeable: string;
|
|
36
|
+
};
|
|
37
|
+
updateAppPermissions({ scope, authorizedAppDid, permission, }: {
|
|
38
|
+
scope: string;
|
|
39
|
+
authorizedAppDid: string;
|
|
40
|
+
permission: {
|
|
41
|
+
listable: boolean;
|
|
42
|
+
readable: boolean;
|
|
43
|
+
writeable: boolean;
|
|
44
|
+
};
|
|
45
|
+
}): Promise<AppPermissions>;
|
|
32
46
|
}
|
package/dist/template/app.js
CHANGED
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.AppTemplate = void 0;
|
|
16
|
+
/* eslint-disable no-bitwise */
|
|
16
17
|
const core_1 = require("@did-space/core");
|
|
17
18
|
const did_1 = require("@arcblock/did");
|
|
18
19
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
@@ -98,6 +99,7 @@ class AppTemplate {
|
|
|
98
99
|
return res.status === 200;
|
|
99
100
|
}
|
|
100
101
|
catch (error) {
|
|
102
|
+
console.error(error);
|
|
101
103
|
return false;
|
|
102
104
|
}
|
|
103
105
|
});
|
|
@@ -171,5 +173,34 @@ class AppTemplate {
|
|
|
171
173
|
return app.restore[index];
|
|
172
174
|
});
|
|
173
175
|
}
|
|
176
|
+
updateAppPermissions({ scope, authorizedAppDid, permission, }) {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
const app = yield this.get();
|
|
180
|
+
// 还没有任何授权就创建
|
|
181
|
+
app.permissions = (_a = app.permissions) !== null && _a !== void 0 ? _a : {};
|
|
182
|
+
// 获取当前的权限
|
|
183
|
+
let currentPermissionPriority = (_c = (_b = app.permissions[scope]) === null || _b === void 0 ? void 0 : _b[authorizedAppDid]) !== null && _c !== void 0 ? _c : 0;
|
|
184
|
+
Object.entries(permission).forEach(([key, value]) => {
|
|
185
|
+
var _a;
|
|
186
|
+
// @FIXME: 下面2行还不算很优雅,后续优化一下
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
const scopeKey = AppTemplate.PermissionMap[key];
|
|
189
|
+
// @ts-ignore
|
|
190
|
+
const permissionPriority = (_a = core_1.Scopes[scopeKey]) !== null && _a !== void 0 ? _a : 0;
|
|
191
|
+
currentPermissionPriority = value
|
|
192
|
+
? currentPermissionPriority | permissionPriority
|
|
193
|
+
: currentPermissionPriority & ~permissionPriority;
|
|
194
|
+
});
|
|
195
|
+
app.permissions[scope] = Object.assign(Object.assign({}, app.permissions[scope]), { [authorizedAppDid]: currentPermissionPriority });
|
|
196
|
+
yield this.set(app);
|
|
197
|
+
return app.permissions;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
174
200
|
}
|
|
175
201
|
exports.AppTemplate = AppTemplate;
|
|
202
|
+
AppTemplate.PermissionMap = {
|
|
203
|
+
listable: 'list:object',
|
|
204
|
+
readable: 'read:object',
|
|
205
|
+
writeable: 'write:object',
|
|
206
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-space/template",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.69",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
]
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@arcblock/did": "^1.18.
|
|
40
|
-
"@arcblock/validator": "^1.18.
|
|
41
|
-
"@did-space/core": "0.3.
|
|
42
|
-
"axios": "^1.6.
|
|
39
|
+
"@arcblock/did": "^1.18.113",
|
|
40
|
+
"@arcblock/validator": "^1.18.113",
|
|
41
|
+
"@did-space/core": "0.3.69",
|
|
42
|
+
"axios": "^1.6.8",
|
|
43
43
|
"is-url": "^1.2.4",
|
|
44
44
|
"joi": "^17.12.2",
|
|
45
45
|
"js-yaml": "^4.1.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/jest": "^28.1.8",
|
|
54
54
|
"@types/js-yaml": "^4.0.9",
|
|
55
55
|
"@types/json-stable-stringify": "^1.0.36",
|
|
56
|
-
"@types/lodash": "^4.
|
|
56
|
+
"@types/lodash": "^4.17.0",
|
|
57
57
|
"@types/node": "15.12.2",
|
|
58
58
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
59
59
|
"eslint": "^8.57.0",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"ts-jest": "^28.0.8",
|
|
63
63
|
"typescript": "^4.9.5"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "9af712519c6631420f7871d7ee2565a56ff899d0"
|
|
66
66
|
}
|