@blocklet/meta 1.8.37 → 1.8.38

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/lib/did.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  /// <reference types="node" />
2
- import { TBlockletMeta } from './types';
3
2
  declare const toBlockletDid: {
4
3
  (name: string | Buffer): string;
5
4
  toExternalBlocklet(name: string, userDid: string, { didOnly, nameOnly }?: {
6
5
  didOnly?: boolean;
7
6
  nameOnly?: boolean;
8
- }): Pick<TBlockletMeta, 'did' | 'name'> | string;
7
+ }): string | {
8
+ did: string;
9
+ name: string;
10
+ };
9
11
  };
10
12
  export = toBlockletDid;
package/lib/fix.js CHANGED
@@ -37,11 +37,8 @@ Object.defineProperty(exports, "fixService", { enumerable: true, get: function (
37
37
  const constants_1 = __importDefault(require("./constants"));
38
38
  const debug = (0, debug_1.default)('@blocklet/meta:fix');
39
39
  const { BLOCKLET_DEFAULT_VERSION, BLOCKLET_DEFAULT_PORT_NAME, BLOCKLET_DYNAMIC_PATH_PREFIX, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_INTERFACE_PUBLIC, } = constants_1.default;
40
- // Assign sensible defaults: name/description/main/group/version/public_url
40
+ // Assign sensible defaults: description/main/group/version/public_url
41
41
  const fixRequired = (data, dir) => {
42
- if (!data.name) {
43
- data.name = path_1.default.basename(dir);
44
- }
45
42
  if (!data.description) {
46
43
  data.description = `Blocklet from ${dir}`;
47
44
  }
package/lib/index.d.ts CHANGED
@@ -63,7 +63,10 @@ declare const _default: {
63
63
  toExternalBlocklet(name: string, userDid: string, { didOnly, nameOnly }?: {
64
64
  didOnly?: boolean;
65
65
  nameOnly?: boolean;
66
- }): string | Pick<import("./types").TBlockletMeta, "name" | "did">;
66
+ }): string | {
67
+ did: string;
68
+ name: string;
69
+ };
67
70
  };
68
71
  getBlockletWallet: (blockletDid: string, nodeSk?: string, type?: import("@arcblock/did").DIDType, index?: number) => import("@ocap/wallet").WalletObject<string>;
69
72
  getBlockletInfo: (state: import("@abtnode/client").BlockletState, nodeSk?: string, { returnWallet }?: {
@@ -71,6 +74,7 @@ declare const _default: {
71
74
  }) => {
72
75
  did: string;
73
76
  name: string;
77
+ version: string;
74
78
  description: string;
75
79
  passportColor?: string;
76
80
  appUrl: string;
package/lib/info.d.ts CHANGED
@@ -5,6 +5,7 @@ declare const getBlockletInfo: (state: BlockletState, nodeSk?: string, { returnW
5
5
  }) => {
6
6
  did: string;
7
7
  name: string;
8
+ version: string;
8
9
  description: string;
9
10
  passportColor?: string;
10
11
  appUrl: string;
package/lib/info.js CHANGED
@@ -14,7 +14,7 @@ const getBlockletInfo = (state, nodeSk, { returnWallet = true } = {}) => {
14
14
  const customDescription = envs.find((x) => x.key === 'BLOCKLET_APP_DESCRIPTION');
15
15
  const customPassportColor = envs.find((x) => x.key === 'BLOCKLET_PASSPORT_COLOR');
16
16
  const customAppUrl = envs.find((x) => x.key === 'BLOCKLET_APP_URL');
17
- const { did } = state.meta;
17
+ const { did, version } = state.meta;
18
18
  const name = (0, util_1.getDisplayName)(state);
19
19
  const description = (0, get_1.default)(customDescription, 'value', state.meta.description);
20
20
  const passportColor = (0, get_1.default)(customPassportColor, 'value', 'auto');
@@ -22,6 +22,7 @@ const getBlockletInfo = (state, nodeSk, { returnWallet = true } = {}) => {
22
22
  if (!returnWallet) {
23
23
  return {
24
24
  did,
25
+ version,
25
26
  name,
26
27
  description,
27
28
  appUrl,
@@ -51,6 +52,7 @@ const getBlockletInfo = (state, nodeSk, { returnWallet = true } = {}) => {
51
52
  }
52
53
  return {
53
54
  did,
55
+ version,
54
56
  name,
55
57
  description,
56
58
  passportColor,
package/lib/parse.js CHANGED
@@ -8,7 +8,6 @@ const js_yaml_1 = __importDefault(require("js-yaml"));
8
8
  const camelCase_1 = __importDefault(require("lodash/camelCase"));
9
9
  const debug_1 = __importDefault(require("debug"));
10
10
  const constants_1 = __importDefault(require("./constants"));
11
- const did_1 = __importDefault(require("./did"));
12
11
  const schema_1 = require("./schema");
13
12
  const fix_1 = require("./fix");
14
13
  const debug = (0, debug_1.default)('@blocklet/meta:parse');
@@ -67,7 +66,6 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
67
66
  debug('fix', result);
68
67
  // We will overwrite did anyway
69
68
  result.path = `/${result.group}/${result.name}`;
70
- result.did = (0, did_1.default)(Buffer.from(result.name, 'utf8'));
71
69
  // Ensure camelCase
72
70
  result = Object.keys(result).reduce((acc, k) => {
73
71
  acc[(0, camelCase_1.default)(k)] = result[k];
package/lib/schema.d.ts CHANGED
@@ -4,6 +4,7 @@ declare const descriptionSchema: JOI.StringSchema<string>;
4
4
  declare const logoSchema: JOI.StringSchema<string>;
5
5
  declare const mountPointSchema: JOI.StringSchema<string>;
6
6
  declare const blockletNameSchema: JOI.StringSchema<string>;
7
+ declare const environmentNameSchema: JOI.StringSchema<string>;
7
8
  declare const environmentSchema: JOI.ObjectSchema<any>;
8
9
  declare const scriptsSchema: JOI.ObjectSchema<any>;
9
10
  declare const serviceSchema: JOI.ObjectSchema<any>;
@@ -18,13 +19,14 @@ declare const signatureSchema: JOI.ObjectSchema<any>;
18
19
  declare const navigationItemSchema: JOI.ObjectSchema<any>;
19
20
  declare const navigationSchema: JOI.ArraySchema<any[]>;
20
21
  declare const themeSchema: JOI.ObjectSchema<any>;
22
+ declare const authConfigSchema: JOI.ObjectSchema<any>;
21
23
  declare const blockletMetaSchema: JOI.ObjectSchema<any>;
22
24
  declare const createBlockletSchema: (baseDir: string, { ensureMain, ensureFiles, ensureDist, ...schemaOptions }?: {
23
25
  ensureMain?: boolean;
24
26
  ensureFiles?: boolean;
25
27
  ensureDist?: boolean;
26
28
  }) => JOI.ObjectSchema;
27
- export { blockletMetaSchema, blockletNameSchema, componentSchema, createBlockletSchema, descriptionSchema, distSchema, endpointSchema, engineSchema, environmentSchema, interfaceSchema, logoSchema, mountPointSchema, navigationItemSchema, navigationSchema, personSchema, scriptsSchema, serviceSchema, signatureSchema, themeSchema, titleSchema, statsSchema, };
29
+ export { blockletMetaSchema, blockletNameSchema, componentSchema, createBlockletSchema, descriptionSchema, distSchema, endpointSchema, engineSchema, environmentSchema, environmentNameSchema, interfaceSchema, logoSchema, mountPointSchema, navigationItemSchema, navigationSchema, personSchema, scriptsSchema, serviceSchema, signatureSchema, themeSchema, titleSchema, statsSchema, authConfigSchema, };
28
30
  declare const _default: {
29
31
  blockletNameSchema: JOI.StringSchema<string>;
30
32
  componentSchema: JOI.ObjectSchema<any>;
@@ -37,6 +39,7 @@ declare const _default: {
37
39
  }) => JOI.ObjectSchema<any>;
38
40
  interfaceSchema: JOI.ObjectSchema<any>;
39
41
  environmentSchema: JOI.ObjectSchema<any>;
42
+ environmentNameSchema: JOI.StringSchema<string>;
40
43
  scriptsSchema: JOI.ObjectSchema<any>;
41
44
  personSchema: JOI.ObjectSchema<any>;
42
45
  distSchema: JOI.ObjectSchema<any>;
@@ -46,5 +49,6 @@ declare const _default: {
46
49
  navigationSchema: JOI.ArraySchema<any[]>;
47
50
  themeSchema: JOI.ObjectSchema<any>;
48
51
  mountPointSchema: JOI.StringSchema<string>;
52
+ authConfigSchema: JOI.ObjectSchema<any>;
49
53
  };
50
54
  export default _default;
package/lib/schema.js CHANGED
@@ -14,19 +14,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.statsSchema = exports.titleSchema = exports.themeSchema = exports.signatureSchema = exports.serviceSchema = exports.scriptsSchema = exports.personSchema = exports.navigationSchema = exports.navigationItemSchema = exports.mountPointSchema = exports.logoSchema = exports.interfaceSchema = exports.environmentSchema = exports.engineSchema = exports.endpointSchema = exports.distSchema = exports.descriptionSchema = exports.createBlockletSchema = exports.componentSchema = exports.blockletNameSchema = exports.blockletMetaSchema = void 0;
17
+ exports.authConfigSchema = exports.statsSchema = exports.titleSchema = exports.themeSchema = exports.signatureSchema = exports.serviceSchema = exports.scriptsSchema = exports.personSchema = exports.navigationSchema = exports.navigationItemSchema = exports.mountPointSchema = exports.logoSchema = exports.interfaceSchema = exports.environmentNameSchema = exports.environmentSchema = exports.engineSchema = exports.endpointSchema = exports.distSchema = exports.descriptionSchema = exports.createBlockletSchema = exports.componentSchema = exports.blockletNameSchema = exports.blockletMetaSchema = void 0;
18
18
  const fs_1 = __importDefault(require("fs"));
19
19
  const joi_1 = __importDefault(require("joi"));
20
- const constant_1 = require("@abtnode/constant");
21
20
  // eslint-disable-next-line import/no-named-default
22
21
  const cjk_length_1 = __importDefault(require("cjk-length"));
23
22
  const is_glob_1 = __importDefault(require("is-glob"));
24
23
  const joi_extension_semver_1 = require("joi-extension-semver");
24
+ const did_1 = __importDefault(require("./did"));
25
25
  const extension_1 = require("./extension");
26
26
  const name_1 = require("./name");
27
27
  const constants_1 = __importDefault(require("./constants"));
28
28
  const cjkLength = cjk_length_1.default.default;
29
- const { BLOCKLET_GROUPS, BLOCKLET_PLATFORMS, BLOCKLET_ARCHITECTURES, BLOCKLET_INTERFACE_TYPES, BLOCKLET_INTERFACE_PROTOCOLS, BLOCKLET_ENTRY_FILE, BLOCKLET_BUNDLE_FILE, BLOCKLET_DEFAULT_PORT_NAME, BLOCKLET_DYNAMIC_PATH_PREFIX, BlockletGroup, BLOCKLET_LATEST_REQUIREMENT_SERVER, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_INTERFACE_TYPE_WELLKNOWN, BLOCKLET_APP_STORAGE_ENDPOINTS, } = constants_1.default;
29
+ const { BLOCKLET_GROUPS, BLOCKLET_PLATFORMS, BLOCKLET_ARCHITECTURES, BLOCKLET_INTERFACE_TYPES, BLOCKLET_INTERFACE_PROTOCOLS, BLOCKLET_ENTRY_FILE, BLOCKLET_BUNDLE_FILE, BLOCKLET_DEFAULT_PORT_NAME, BLOCKLET_DYNAMIC_PATH_PREFIX, BlockletGroup, BLOCKLET_LATEST_REQUIREMENT_SERVER, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_INTERFACE_TYPE_WELLKNOWN, BLOCKLET_APP_SPACE_ENDPOINTS, BLOCKLET_CONFIGURABLE_KEY, } = constants_1.default;
30
30
  const WELLKNOWN_PATH_PREFIX = '/.well-known';
31
31
  const MAX_TITLE_LENGTH = 24;
32
32
  const MAX_NAME_LENGTH = 32;
@@ -62,8 +62,40 @@ const blockletNameSchema = Joi.string()
62
62
  .max(MAX_NAME_LENGTH)
63
63
  .meta({ className: 'TBlockletName' });
64
64
  exports.blockletNameSchema = blockletNameSchema;
65
+ const ENV_NAME_WHITE_LIST = [BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_WALLET_TYPE];
66
+ const environmentNameSchema = Joi.string()
67
+ .trim()
68
+ .min(1)
69
+ .max(50)
70
+ .required()
71
+ .custom((name, helper) => {
72
+ if (name.startsWith('BLOCKLET')) {
73
+ if (!ENV_NAME_WHITE_LIST.includes(name)) {
74
+ // @ts-expect-error
75
+ return helper.message('Env name can not start with BLOCKLET_');
76
+ }
77
+ }
78
+ if (name.startsWith('COMPONENT')) {
79
+ // @ts-expect-error
80
+ return helper.message('Env name can not start with COMPONENT_');
81
+ }
82
+ if (name.startsWith('ABTNODE')) {
83
+ // @ts-expect-error
84
+ return helper.message('Env name can not start with ABTNODE_');
85
+ }
86
+ if (/[^\w]/.test(name)) {
87
+ // @ts-expect-error
88
+ return helper.message('Env name can include only numbers or letters or "_"');
89
+ }
90
+ return name;
91
+ })
92
+ .meta({
93
+ className: 'TEnvironmentName',
94
+ unknownType: 'any',
95
+ });
96
+ exports.environmentNameSchema = environmentNameSchema;
65
97
  const environmentSchema = Joi.object({
66
- name: Joi.string().trim().required(),
98
+ name: environmentNameSchema.required(),
67
99
  description: Joi.string().trim().required(),
68
100
  default: Joi.string().optional().allow('').default(''),
69
101
  required: Joi.boolean().default(false),
@@ -72,10 +104,6 @@ const environmentSchema = Joi.object({
72
104
  shared: Joi.boolean().default((parent) => !parent.secure),
73
105
  })
74
106
  .custom((x, helper) => {
75
- if (x.name.startsWith(constant_1.BLOCKLET_PREFERENCE_PREFIX)) {
76
- // @ts-expect-error
77
- return helper.message(`Env name can not start with ${constant_1.BLOCKLET_PREFERENCE_PREFIX}`);
78
- }
79
107
  if (x.secure && x.default) {
80
108
  // @ts-expect-error
81
109
  return helper.message(`Cannot declare default value for secure env ${x.name}`);
@@ -308,6 +336,20 @@ const themeSchema = Joi.object({
308
336
  unknownType: 'any',
309
337
  });
310
338
  exports.themeSchema = themeSchema;
339
+ const authConfigSchema = Joi.object({
340
+ whoCanAccess: Joi.string().valid('owner', 'invited', 'all'),
341
+ profileFields: Joi.array().items(Joi.string().valid('fullName', 'email', 'avatar', 'phone')).unique(),
342
+ ignoreUrls: Joi.array().items(Joi.string().min(1)),
343
+ allowSwitchProfile: Joi.boolean(),
344
+ blockUnauthenticated: Joi.boolean(),
345
+ blockUnauthorized: Joi.boolean(),
346
+ })
347
+ .options({ stripUnknown: true })
348
+ .meta({
349
+ className: 'TAuthConfig',
350
+ unknownType: 'any',
351
+ });
352
+ exports.authConfigSchema = authConfigSchema;
311
353
  const blockletMetaProps = {
312
354
  did: Joi.DID().trim().required(),
313
355
  version: Joi.semver().valid().required(),
@@ -450,7 +492,20 @@ const blockletMetaProps = {
450
492
  })
451
493
  .default([]),
452
494
  // environments
453
- environments: Joi.array().items(environmentSchema).default([]).optional(),
495
+ environments: Joi.array()
496
+ .items(environmentSchema)
497
+ .default([])
498
+ .optional()
499
+ .custom((data, helper) => {
500
+ if (data && data.length) {
501
+ const duplicates = data.filter((x, index) => data.findIndex((y) => y.name === x.name) !== index);
502
+ if (duplicates.length) {
503
+ // @ts-expect-error
504
+ return helper.message(`find duplicate environment names ${duplicates.map((x) => x.name).join(', ')}`);
505
+ }
506
+ }
507
+ return data;
508
+ }),
454
509
  // scripts & hooks
455
510
  scripts: scriptsSchema,
456
511
  // capabilities
@@ -458,8 +513,8 @@ const blockletMetaProps = {
458
513
  clusterMode: Joi.boolean().default(false),
459
514
  // added in 1.2.2
460
515
  component: Joi.boolean().default(true),
461
- didStorage: Joi.string()
462
- .valid(...Object.values(BLOCKLET_APP_STORAGE_ENDPOINTS))
516
+ didSpace: Joi.string()
517
+ .valid(...Object.values(BLOCKLET_APP_SPACE_ENDPOINTS))
463
518
  .optional(),
464
519
  }).default({
465
520
  clusterMode: false,
@@ -516,7 +571,15 @@ const createBlockletSchema = (baseDir, _a = {}) => {
516
571
  : Joi.string().trim())
517
572
  .optional(), dist: ensureDist ? distSchema.required() : distSchema.optional() }))
518
573
  .options(Object.assign({ stripUnknown: true, noDefaults: false }, schemaOptions))
519
- .rename('children', 'components');
574
+ .rename('children', 'components')
575
+ .custom((data, helper) => {
576
+ const { did, name } = data;
577
+ if ((0, did_1.default)(name) !== did) {
578
+ // @ts-expect-error
579
+ return helper.message(`name "${name}" does not match with did "${did}"`);
580
+ }
581
+ return data;
582
+ });
520
583
  };
521
584
  exports.createBlockletSchema = createBlockletSchema;
522
585
  exports.default = {
@@ -527,6 +590,7 @@ exports.default = {
527
590
  createBlockletSchema,
528
591
  interfaceSchema,
529
592
  environmentSchema,
593
+ environmentNameSchema,
530
594
  scriptsSchema,
531
595
  personSchema,
532
596
  distSchema,
@@ -536,4 +600,5 @@ exports.default = {
536
600
  navigationSchema,
537
601
  themeSchema,
538
602
  mountPointSchema,
603
+ authConfigSchema,
539
604
  };
package/lib/service.d.ts CHANGED
@@ -1,26 +1,27 @@
1
- declare const setService: (meta: any) => void;
2
- declare const getServiceMetas: ({ stringifySchema }?: {
3
- stringifySchema?: boolean;
4
- }) => any[];
1
+ declare const setService: (meta: {
2
+ name: string;
3
+ schema: any;
4
+ default: any;
5
+ }) => void;
5
6
  declare const getServiceConfig: (serviceName: string, customConfig: any, { validate }?: {
6
7
  validate?: any;
7
8
  }) => any;
8
9
  declare const getDefaultServiceConfig: (serviceName: string) => any;
9
10
  declare const findService: (services: any[], name: string) => any;
10
- export { getServiceMetas };
11
11
  export { getServiceConfig };
12
12
  export { getDefaultServiceConfig };
13
13
  export { findService };
14
14
  export { setService };
15
15
  declare const _default: {
16
- getServiceMetas: ({ stringifySchema }?: {
17
- stringifySchema?: boolean;
18
- }) => any[];
19
16
  getServiceConfig: (serviceName: string, customConfig: any, { validate }?: {
20
17
  validate?: any;
21
18
  }) => any;
22
19
  getDefaultServiceConfig: (serviceName: string) => any;
23
20
  findService: (services: any[], name: string) => any;
24
- setService: (meta: any) => void;
21
+ setService: (meta: {
22
+ name: string;
23
+ schema: any;
24
+ default: any;
25
+ }) => void;
25
26
  };
26
27
  export default _default;
package/lib/service.js CHANGED
@@ -3,43 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setService = exports.findService = exports.getDefaultServiceConfig = exports.getServiceConfig = exports.getServiceMetas = void 0;
6
+ exports.setService = exports.findService = exports.getDefaultServiceConfig = exports.getServiceConfig = void 0;
7
7
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
8
- const ajv_1 = __importDefault(require("ajv"));
9
8
  const constant_1 = __importDefault(require("@abtnode/constant"));
10
- const auth_json_1 = __importDefault(require("./service-configs/auth.json"));
9
+ const schema_1 = require("./schema");
11
10
  const { NODE_SERVICES } = constant_1.default;
12
- const ajv = new ajv_1.default({
13
- useDefaults: true,
14
- removeAdditional: 'all',
15
- });
16
11
  const SERVICES = {};
17
12
  const setService = (meta) => {
18
- const validate = ajv.compile(meta.schema.JSONSchema);
19
- // parse empty custom config to get default config
20
- const defaultConfig = {};
21
- validate(defaultConfig);
22
13
  SERVICES[meta.name] = {
23
- meta,
24
- validate,
25
- defaultConfig,
14
+ validate: meta.schema.validate.bind(meta.schema),
15
+ defaultConfig: meta.default,
26
16
  };
27
17
  };
28
18
  exports.setService = setService;
29
- setService(auth_json_1.default);
19
+ setService({
20
+ name: 'auth',
21
+ schema: schema_1.authConfigSchema,
22
+ default: {},
23
+ });
30
24
  // backward compatible
31
25
  SERVICES[NODE_SERVICES.AUTH_SERVICE] = Object.assign(Object.assign({}, SERVICES[NODE_SERVICES.AUTH]), { meta: Object.assign(Object.assign({}, SERVICES[NODE_SERVICES.AUTH].meta), { name: NODE_SERVICES.AUTH_SERVICE }) });
32
- const getServiceMetas = ({ stringifySchema = false } = {}) => {
33
- const list = Object.values(SERVICES).map(({ meta }) => {
34
- const data = (0, cloneDeep_1.default)(meta);
35
- if (stringifySchema) {
36
- data.schema = JSON.stringify(meta.schema);
37
- }
38
- return data;
39
- });
40
- return list;
41
- };
42
- exports.getServiceMetas = getServiceMetas;
43
26
  const getService = (serviceName) => {
44
27
  if (!serviceName) {
45
28
  throw new Error('service name should not be empty');
@@ -53,13 +36,11 @@ const getService = (serviceName) => {
53
36
  const getServiceConfig = (serviceName, customConfig, { validate } = {}) => {
54
37
  const service = getService(serviceName);
55
38
  const data = (0, cloneDeep_1.default)(customConfig || {});
56
- // this method may have side effect thar will fill default value to customConfig
57
- const valid = service.validate(data || {});
58
- if (validate && !valid) {
59
- const message = service.validate.errors.map((x) => `${x.instancePath} ${x.message}`).join(', ');
60
- throw new Error(`Invalid blocklet service config: ${message}`);
39
+ const { value, error } = service.validate(data);
40
+ if (validate && error) {
41
+ throw new Error(`Invalid blocklet service config: ${error.details.map((x) => x.message).join(', ')}`);
61
42
  }
62
- return data;
43
+ return value;
63
44
  };
64
45
  exports.getServiceConfig = getServiceConfig;
65
46
  const getDefaultServiceConfig = (serviceName) => {
@@ -77,7 +58,6 @@ const findService = (services, name) => {
77
58
  };
78
59
  exports.findService = findService;
79
60
  exports.default = {
80
- getServiceMetas,
81
61
  getServiceConfig,
82
62
  getDefaultServiceConfig,
83
63
  findService,
@@ -1,3 +1,11 @@
1
+ export interface TAuthConfig {
2
+ allowSwitchProfile?: boolean;
3
+ blockUnauthenticated?: boolean;
4
+ blockUnauthorized?: boolean;
5
+ ignoreUrls?: string[];
6
+ profileFields?: ('fullName' | 'email' | 'avatar' | 'phone')[];
7
+ whoCanAccess?: 'owner' | 'invited' | 'all';
8
+ }
1
9
  export interface TBlockletMeta {
2
10
  author?: TPerson;
3
11
  bundleDid?: string;
@@ -5,7 +13,7 @@ export interface TBlockletMeta {
5
13
  capabilities?: {
6
14
  clusterMode?: boolean;
7
15
  component?: boolean;
8
- didStorage?: 'required' | 'optional';
16
+ didSpace?: 'required' | 'optional';
9
17
  };
10
18
  community?: string;
11
19
  components?: TComponent[];
@@ -139,12 +147,13 @@ export interface TEngine {
139
147
  export interface TEnvironment {
140
148
  default?: string;
141
149
  description: string;
142
- name: string;
150
+ name: TEnvironmentName;
143
151
  required?: boolean;
144
152
  secure?: boolean;
145
153
  shared?: boolean;
146
154
  validation?: string;
147
155
  }
156
+ export declare type TEnvironmentName = string;
148
157
  export interface TInterface {
149
158
  endpoints?: TEndpoint[];
150
159
  name: string;
package/lib/util.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { BlockletState, ComponentState } from '@abtnode/client';
2
2
  import { Request } from 'express';
3
3
  import { TBlockletMeta, TEnvironment } from './types';
4
+ declare type TConfig = TEnvironment & {
5
+ key: string;
6
+ };
4
7
  declare const getComponentId: (component?: {
5
8
  meta?: {
6
9
  did?: string;
@@ -49,14 +52,13 @@ declare const forEachBlocklet: (blocklet: BlockletState | ComponentState, cb: Fu
49
52
  declare const forEachBlockletSync: (blocklet: any, cb: Function) => Promise<unknown>;
50
53
  declare const forEachChild: (blocklet: any, cb: Function, params?: any) => Promise<any>;
51
54
  declare const forEachChildSync: (blocklet: BlockletState, cb: Function) => Promise<any>;
52
- declare const findComponentById: (blocklet: BlockletState | ComponentState, componentId: string, { _ancestors, returnAncestors, }?: {
55
+ declare const findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | Array<string>, { _ancestors, returnAncestors, }?: {
53
56
  _ancestors?: any[];
54
57
  returnAncestors?: boolean;
55
58
  }) => any;
56
- declare const isEnvShareable: (env?: TEnvironment & {
57
- key: string;
58
- }) => boolean;
59
+ declare const isEnvShareable: (env?: TConfig) => boolean;
59
60
  declare const getSharedConfigObj: (component: BlockletState, ancestors?: any[]) => any;
61
+ declare const isPreferenceKey: (x: TConfig) => Boolean;
60
62
  declare const getAppMissingConfigs: (blocklet?: any) => any[];
61
63
  declare const getComponentMissingConfigs: (component?: any, ancestors?: any[]) => any[];
62
64
  declare const isFreeBlocklet: (meta: TBlockletMeta) => boolean;
@@ -84,6 +86,9 @@ declare const replaceSlotToIp: (url?: string, ip?: string) => string;
84
86
  declare const urlFriendly: (name: string) => string;
85
87
  declare const getChainInfo: (env: Record<string, string>) => Record<string, string>;
86
88
  declare const isExternalBlocklet: (blocklet?: BlockletState) => boolean;
89
+ declare const getRolesFromAuthConfig: (config: {
90
+ whoCanAccess: string;
91
+ }) => Array<string>;
87
92
  export { isFreeBlocklet };
88
93
  export { isFreeComponent };
89
94
  export { isComponentBlocklet };
@@ -113,6 +118,8 @@ export { getParentComponentName };
113
118
  export { getConnectAppUrl };
114
119
  export { getChainInfo };
115
120
  export { isExternalBlocklet };
121
+ export { isPreferenceKey };
122
+ export { getRolesFromAuthConfig };
116
123
  declare const _default: {
117
124
  isFreeBlocklet: (meta: TBlockletMeta) => boolean;
118
125
  isFreeComponent: (meta: TBlockletMeta) => boolean;
@@ -134,9 +141,7 @@ declare const _default: {
134
141
  getSharedConfigObj: (component: BlockletState, ancestors?: any[]) => any;
135
142
  getAppMissingConfigs: (blocklet?: any) => any[];
136
143
  getComponentMissingConfigs: (component?: any, ancestors?: any[]) => any[];
137
- isEnvShareable: (env?: TEnvironment & {
138
- key: string;
139
- }) => boolean;
144
+ isEnvShareable: (env?: TConfig) => boolean;
140
145
  wipeSensitiveData: (blocklet?: BlockletState) => BlockletState;
141
146
  hasRunnableComponent: (blocklet: BlockletState) => boolean;
142
147
  getDisplayName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
@@ -170,7 +175,7 @@ declare const _default: {
170
175
  version: string;
171
176
  };
172
177
  }) => string;
173
- findComponentById: (blocklet: BlockletState | ComponentState, componentId: string, { _ancestors, returnAncestors, }?: {
178
+ findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | string[], { _ancestors, returnAncestors, }?: {
174
179
  _ancestors?: any[];
175
180
  returnAncestors?: boolean;
176
181
  }) => any;
@@ -181,5 +186,9 @@ declare const _default: {
181
186
  }) => string;
182
187
  getChainInfo: (env: Record<string, string>) => Record<string, string>;
183
188
  isExternalBlocklet: (blocklet?: BlockletState) => boolean;
189
+ isPreferenceKey: (x: TConfig) => Boolean;
190
+ getRolesFromAuthConfig: (config: {
191
+ whoCanAccess: string;
192
+ }) => string[];
184
193
  };
185
194
  export default _default;
package/lib/util.js CHANGED
@@ -12,16 +12,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.urlFriendly = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterface = exports.fixBlockletStatus = exports.getDisplayName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
15
+ exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.urlFriendly = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterface = exports.fixBlockletStatus = exports.getDisplayName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
16
16
  /* eslint-disable no-await-in-loop */
17
17
  const get_1 = __importDefault(require("lodash/get"));
18
18
  const slugify_1 = __importDefault(require("slugify"));
19
19
  const url_join_1 = __importDefault(require("url-join"));
20
20
  const constant_1 = __importDefault(require("@abtnode/constant"));
21
- const constant_2 = require("@blocklet/constant");
22
21
  const constants_1 = __importDefault(require("./constants"));
23
- const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE, WHO_CAN_ACCESS } = constant_1.default;
24
- const { BlockletGroup, fromBlockletStatus, fromBlockletSource, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_CONFIGURABLE_KEY, CHAIN_INFO_CONFIG, } = constants_1.default;
22
+ const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE, WHO_CAN_ACCESS, WHO_CAN_ACCESS_PREFIX_ROLES } = constant_1.default;
23
+ const { BlockletGroup, fromBlockletStatus, fromBlockletSource, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_CONFIGURABLE_KEY, CHAIN_INFO_CONFIG, BLOCKLET_PREFERENCE_PREFIX, } = constants_1.default;
25
24
  const getComponentId = (component, ancestors = []) => `${ancestors.map((x) => (x && x.meta ? x.meta.did : '')).join('/')}${ancestors.length ? '/' : ''}${component && component.meta ? component.meta.did : ''}`;
26
25
  exports.getComponentId = getComponentId;
27
26
  const getComponentName = (component, ancestors = []) => `${ancestors.map((x) => (x && x.meta ? x.meta.name : '')).join('/')}${ancestors.length ? '/' : ''}${component && component.meta ? component.meta.name : ''}`;
@@ -152,6 +151,10 @@ exports.forEachChild = forEachChild;
152
151
  const forEachChildSync = (blocklet, cb) => forEachChild(blocklet, cb, { sync: true });
153
152
  exports.forEachChildSync = forEachChildSync;
154
153
  const findComponentById = (blocklet, componentId, { _ancestors = [], returnAncestors = false, } = {}) => {
154
+ if (Array.isArray(componentId)) {
155
+ // eslint-disable-next-line no-param-reassign
156
+ componentId = componentId.join('/');
157
+ }
155
158
  const id = getComponentId(blocklet, _ancestors);
156
159
  if (componentId === id) {
157
160
  if (returnAncestors) {
@@ -206,6 +209,8 @@ const getSharedConfigObj = (component, ancestors) => {
206
209
  return res;
207
210
  };
208
211
  exports.getSharedConfigObj = getSharedConfigObj;
212
+ const isPreferenceKey = (x) => x.key.startsWith(BLOCKLET_PREFERENCE_PREFIX) === true;
213
+ exports.isPreferenceKey = isPreferenceKey;
209
214
  const getAppMissingConfigs = (blocklet = {}) => {
210
215
  const missingConfigs = [];
211
216
  forEachBlockletSync(blocklet, (b, { ancestors }) => {
@@ -217,7 +222,7 @@ const getAppMissingConfigs = (blocklet = {}) => {
217
222
  }
218
223
  });
219
224
  });
220
- return missingConfigs.filter((x) => x.key.startsWith(constant_2.BLOCKLET_PREFERENCE_PREFIX) === false);
225
+ return missingConfigs.filter((x) => !isPreferenceKey(x));
221
226
  };
222
227
  exports.getAppMissingConfigs = getAppMissingConfigs;
223
228
  const getComponentMissingConfigs = (component = {}, ancestors = []) => {
@@ -260,7 +265,7 @@ const wipeSensitiveData = (blocklet) => {
260
265
  }
261
266
  forEachBlocklet(blocklet, (d) => {
262
267
  if (d.configs) {
263
- d.configs = d.configs.filter((x) => x.key.startsWith(constant_2.BLOCKLET_PREFERENCE_PREFIX) === false);
268
+ d.configs = d.configs.filter((x) => !isPreferenceKey(x));
264
269
  d.configs.forEach((x) => {
265
270
  if (x.secure) {
266
271
  x.value = x.value ? '__encrypted__' : '';
@@ -412,6 +417,13 @@ const getChainInfo = (env) => Object.entries(CHAIN_INFO_CONFIG).reduce((info, x)
412
417
  exports.getChainInfo = getChainInfo;
413
418
  const isExternalBlocklet = (blocklet) => !!(blocklet === null || blocklet === void 0 ? void 0 : blocklet.controller);
414
419
  exports.isExternalBlocklet = isExternalBlocklet;
420
+ const getRolesFromAuthConfig = (config) => {
421
+ if (!config.whoCanAccess.startsWith(WHO_CAN_ACCESS_PREFIX_ROLES)) {
422
+ return [];
423
+ }
424
+ return config.whoCanAccess.substring(WHO_CAN_ACCESS_PREFIX_ROLES.length).split(',');
425
+ };
426
+ exports.getRolesFromAuthConfig = getRolesFromAuthConfig;
415
427
  exports.default = {
416
428
  isFreeBlocklet,
417
429
  isFreeComponent,
@@ -442,4 +454,6 @@ exports.default = {
442
454
  getConnectAppUrl,
443
455
  getChainInfo,
444
456
  isExternalBlocklet,
457
+ isPreferenceKey,
458
+ getRolesFromAuthConfig,
445
459
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.37",
6
+ "version": "1.8.38",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "./lib/index.js",
9
9
  "typings": "./lib/index.d.ts",
@@ -24,19 +24,19 @@
24
24
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@abtnode/client": "1.8.37",
28
- "@abtnode/constant": "1.8.37",
29
- "@abtnode/util": "1.8.37",
30
- "@arcblock/did": "1.18.15",
31
- "@arcblock/did-ext": "1.18.15",
32
- "@arcblock/did-util": "1.18.15",
33
- "@arcblock/jwt": "1.18.15",
34
- "@blocklet/constant": "1.8.37",
35
- "@ocap/asset": "1.18.15",
36
- "@ocap/mcrypto": "1.18.15",
37
- "@ocap/types": "1.18.15",
38
- "@ocap/util": "1.18.15",
39
- "@ocap/wallet": "1.18.15",
27
+ "@abtnode/client": "1.8.38",
28
+ "@abtnode/constant": "1.8.38",
29
+ "@abtnode/util": "1.8.38",
30
+ "@arcblock/did": "1.18.18",
31
+ "@arcblock/did-ext": "1.18.18",
32
+ "@arcblock/did-util": "1.18.18",
33
+ "@arcblock/jwt": "1.18.18",
34
+ "@blocklet/constant": "1.8.38",
35
+ "@ocap/asset": "1.18.18",
36
+ "@ocap/mcrypto": "1.18.18",
37
+ "@ocap/types": "1.18.18",
38
+ "@ocap/util": "1.18.18",
39
+ "@ocap/wallet": "1.18.18",
40
40
  "ajv": "^8.11.0",
41
41
  "axios": "^0.27.2",
42
42
  "cjk-length": "^1.0.0",
@@ -56,7 +56,7 @@
56
56
  "validate-npm-package-name": "^3.0.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@abtnode/client": "^1.8.36",
59
+ "@abtnode/client": "^1.8.37",
60
60
  "@arcblock/eslint-config-ts": "^0.2.3",
61
61
  "@types/express": "^4.17.14",
62
62
  "@types/jest": "^29.2.2",
@@ -77,5 +77,5 @@
77
77
  "ts-node": "^10.9.1",
78
78
  "typescript": "^4.8.4"
79
79
  },
80
- "gitHead": "f26f451c6e2b1168b36f78269eafdf3f671236bf"
80
+ "gitHead": "cbb88f107eb6b403c8cd47a765920575860c7bc7"
81
81
  }
@@ -1,66 +0,0 @@
1
- {
2
- "name": "auth",
3
- "description": "Neat and easy to use user authentication and authorization service for blocklets",
4
- "version": "1.0.0",
5
- "schema": {
6
- "JSONSchema": {
7
- "title": "Config Auth Service",
8
- "description": "Customize how Auth Service works",
9
- "type": "object",
10
- "required": ["profileFields", "webWalletUrl"],
11
- "properties": {
12
- "whoCanAccess": {
13
- "type": "string",
14
- "title": "Who can access the blocklet?",
15
- "enum": ["owner", "invited", "all"],
16
- "default": "all"
17
- },
18
- "profileFields": {
19
- "type": "array",
20
- "title": "What info do you want user to provide when login?",
21
- "items": {
22
- "type": "string",
23
- "enum": ["fullName", "email", "avatar", "phone"]
24
- },
25
- "default": ["fullName", "email", "avatar"],
26
- "uniqueItems": true
27
- },
28
- "allowSwitchProfile": {
29
- "type": "boolean",
30
- "title": "Does you app allow user to switch profile?",
31
- "default": true
32
- },
33
- "webWalletUrl": {
34
- "type": "string",
35
- "title": "The URL of your preferred web wallet instance",
36
- "pattern": "^https?://",
37
- "default": "https://web.abtwallet.io"
38
- },
39
- "ignoreUrls": {
40
- "type": "array",
41
- "title": "Which URLs do not need to be protected. e.g: /public/**",
42
- "items": {
43
- "type": "string",
44
- "minLength": 1
45
- },
46
- "default": []
47
- },
48
- "blockUnauthenticated": {
49
- "type": "boolean",
50
- "title": "Do you want Auth Service block unauthenticated requests for you?",
51
- "default": false
52
- },
53
- "blockUnauthorized": {
54
- "type": "boolean",
55
- "title": "Do you want Auth Service block unauthorized requests for you?",
56
- "default": false
57
- }
58
- }
59
- },
60
- "UISchema": {
61
- "profileFields": {
62
- "ui:widget": "checkboxes"
63
- }
64
- }
65
- }
66
- }