@blocklet/sdk 1.16.52-beta-20251005-235515-42ad5caf → 1.16.52-beta-20251008-094601-8a853b5b

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/config.d.ts CHANGED
@@ -41,6 +41,7 @@ declare const env: {
41
41
  appStorageEndpoint: string;
42
42
  serverVersion: string;
43
43
  sessionSalt: string;
44
+ assetCdnHost: string;
44
45
  languages: {
45
46
  code: string;
46
47
  name: string;
@@ -123,6 +124,7 @@ declare const _default: {
123
124
  appStorageEndpoint: string;
124
125
  serverVersion: string;
125
126
  sessionSalt: string;
127
+ assetCdnHost: string;
126
128
  languages: {
127
129
  code: string;
128
130
  name: string;
package/lib/config.js CHANGED
@@ -51,6 +51,7 @@ const AppConfigKeyMap = {
51
51
  BLOCKLET_APP_SALT: 'sessionSalt',
52
52
  ABT_NODE_VERSION: 'serverVersion',
53
53
  ABT_NODE: 'serverVersion', // for backup compatibility
54
+ ASSET_CDN_HOST: 'assetCdnHost',
54
55
  };
55
56
  // eslint-disable-next-line import/no-mutable-exports
56
57
  let logger = {
@@ -109,6 +110,7 @@ const env = {
109
110
  mode: process.env.BLOCKLET_MODE,
110
111
  tenantMode: process.env.BLOCKLET_APP_TENANT_MODE,
111
112
  sessionSalt: process.env.BLOCKLET_APP_SALT || '',
113
+ assetCdnHost: process.env.ASSET_CDN_HOST,
112
114
  preferences: {
113
115
  ...env_1.default.preferences,
114
116
  ...appEnvFromDisk.preferences,
@@ -393,7 +395,7 @@ if (inRuntimeEnv && !process.env.BLOCKLET_HOOK_NAME && process.env.BLOCKLET_MODE
393
395
  notification_1.default.on(constant_1.BlockletInternalEvents.componentInstalled, runInServer(_handleComponentInstalled, 'new'));
394
396
  notification_1.default.on(constant_1.BlockletInternalEvents.componentUpgraded, runInServer(_handleComponentUpdated, 'new'));
395
397
  notification_1.default.on(constant_1.BlockletInternalEvents.componentUpdated, runInServer(_handleComponentUpdated, 'new'));
396
- notification_1.default.on(constant_1.BlockletInternalEvents.componentStarted, runInServer(_handleComponentStarted, 'new'));
398
+ notification_1.default.on(constant_1.BlockletInternalEvents.componentStarted, runInServer(_handleComponentUpdated, 'new'));
397
399
  notification_1.default.on(constant_1.BlockletInternalEvents.componentStopped, runInServer(_handleComponentStopped, 'new'));
398
400
  notification_1.default.on(constant_1.BlockletInternalEvents.componentRemoved, runInServer(_handleComponentRemoved, 'new'));
399
401
  notification_1.default.on(constant_1.BlockletInternalEvents.componentInstalled, runInServer(refreshBlockletContext, 'new'));
@@ -1,16 +1,6 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
- export declare class BlockletAssetHostTransformer {
3
- private static readonly HTML_TAG_INDICATOR;
4
- private static readonly BLOCKLET_PROXY_PREFIX;
5
- private readonly assetBase;
6
- private readonly quotedAssetBase;
7
- private readonly quotedAssetBasePattern;
8
- constructor(did: string);
9
- private static escapeForRegex;
10
- private static normalizeAssetHost;
11
- static containsHtmlMarkup(payload: string): boolean;
12
- transform(html: string, assetHost: string): string;
13
- transformBuffer(body: Buffer, assetHost: string): Buffer<ArrayBufferLike>;
2
+ export interface CdnOptions {
3
+ did?: string;
4
+ getAssetCdnHost?: () => string;
14
5
  }
15
- export declare const createTransformAssetHostMiddleware: (did: string) => (req: Request, res: Response, next: NextFunction) => void;
16
- export declare const cdn: (req: Request, res: Response, next: NextFunction) => void;
6
+ export declare const cdn: ({ did, getAssetCdnHost }?: CdnOptions) => (req: Request, res: Response, next: NextFunction) => void;
@@ -1,55 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cdn = exports.createTransformAssetHostMiddleware = exports.BlockletAssetHostTransformer = void 0;
3
+ exports.cdn = void 0;
4
4
  const constant_1 = require("@blocklet/constant");
5
- class BlockletAssetHostTransformer {
6
- constructor(did) {
7
- this.assetBase = `${BlockletAssetHostTransformer.BLOCKLET_PROXY_PREFIX}${did}/`;
8
- this.quotedAssetBase = `"${this.assetBase}`;
9
- this.quotedAssetBasePattern = new RegExp(BlockletAssetHostTransformer.escapeForRegex(this.quotedAssetBase), 'g');
10
- }
11
- static escapeForRegex(value) {
12
- const pattern = /[.*+?^${}()|[\]\\]/g;
13
- return value.replace(pattern, '\\$&');
14
- }
15
- static normalizeAssetHost(assetHost) {
16
- if (!assetHost) {
17
- return null;
18
- }
19
- const trimmed = assetHost.trim();
20
- if (!trimmed) {
21
- return null;
22
- }
23
- return trimmed.replace(/\/+$/, '').replace(/^https?:\/\//, '');
24
- }
25
- static containsHtmlMarkup(payload) {
26
- return payload.includes(BlockletAssetHostTransformer.HTML_TAG_INDICATOR);
27
- }
28
- transform(html, assetHost) {
29
- const host = BlockletAssetHostTransformer.normalizeAssetHost(assetHost);
30
- if (!host) {
31
- return html;
32
- }
33
- if (!BlockletAssetHostTransformer.containsHtmlMarkup(html)) {
34
- return html;
35
- }
36
- return html.replace(this.quotedAssetBasePattern, `"//${host}${this.assetBase}`);
37
- }
38
- transformBuffer(body, assetHost) {
39
- const bodyAsString = body.toString('utf8');
40
- if (!BlockletAssetHostTransformer.containsHtmlMarkup(bodyAsString)) {
41
- return body;
42
- }
43
- const transformed = this.transform(bodyAsString, assetHost);
44
- if (transformed === bodyAsString) {
45
- return body;
46
- }
47
- return Buffer.from(transformed);
48
- }
49
- }
50
- exports.BlockletAssetHostTransformer = BlockletAssetHostTransformer;
51
- BlockletAssetHostTransformer.HTML_TAG_INDICATOR = '<html';
52
- BlockletAssetHostTransformer.BLOCKLET_PROXY_PREFIX = '/.blocklet/proxy/';
5
+ const config_1 = require("../config");
6
+ const asset_host_transformer_1 = require("../util/asset-host-transformer");
53
7
  function shouldProcessRequest(req) {
54
8
  const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
55
9
  if (!isProduction) {
@@ -67,10 +21,13 @@ function shouldProcessRequest(req) {
67
21
  const accepted = req.accepts(['html', 'text/html', 'application/xhtml+xml', '*/*']);
68
22
  return Boolean(accepted);
69
23
  }
70
- const createTransformAssetHostMiddleware = (did) => {
71
- const transformer = new BlockletAssetHostTransformer(did);
24
+ const cdn = ({ did = config_1.env.componentDid, getAssetCdnHost } = {}) => {
25
+ if (!did) {
26
+ throw new Error('did is required');
27
+ }
28
+ const transformer = new asset_host_transformer_1.AssetHostTransformer(`/.blocklet/proxy/${did}/`);
72
29
  return (req, res, next) => {
73
- const assetHost = process.env.ASSET_CDN_HOST;
30
+ const assetHost = getAssetCdnHost ? getAssetCdnHost() : config_1.env.assetCdnHost;
74
31
  if (!shouldProcessRequest(req) || !assetHost) {
75
32
  next();
76
33
  return;
@@ -88,5 +45,4 @@ const createTransformAssetHostMiddleware = (did) => {
88
45
  next();
89
46
  };
90
47
  };
91
- exports.createTransformAssetHostMiddleware = createTransformAssetHostMiddleware;
92
- exports.cdn = (0, exports.createTransformAssetHostMiddleware)(process.env.BLOCKLET_COMPONENT_DID);
48
+ exports.cdn = cdn;
@@ -88,6 +88,6 @@ declare const _default: {
88
88
  }) => (req: import("express").Request & {
89
89
  user?: import("../util/login").SessionUser;
90
90
  }, res: import("express").Response, next: import("express").NextFunction) => Promise<void>;
91
- cdn: (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction) => void;
91
+ cdn: ({ did, getAssetCdnHost }?: import("./cdn").CdnOptions) => (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction) => void;
92
92
  };
93
93
  export default _default;
@@ -3,7 +3,7 @@ import { LOGIN_PROVIDER } from '@blocklet/constant';
3
3
  type PartialDeep<T> = {
4
4
  [K in keyof T]?: T[K] extends object ? PartialDeep<T[K]> : T[K];
5
5
  };
6
- type OmitTeamDid<T> = PartialDeep<Omit<T, 'teamDid'>>;
6
+ type OmitTeamDid<T> = PartialDeep<Omit<T, 'teamDid' | 'did'>>;
7
7
  type RequestHeaders = {
8
8
  headers: {
9
9
  cookie: string;
@@ -90,5 +90,7 @@ interface BlockletService {
90
90
  getOrgResource(params: OmitTeamDid<Client.RequestGetOrgResourceInput>): Promise<Client.ResponseGetOrgResource>;
91
91
  addOrgResource(params: OmitTeamDid<Client.RequestAddOrgResourceInput>): Promise<Client.ResponseOrgResourceOperation>;
92
92
  migrateOrgResource(params: OmitTeamDid<Client.RequestMigrateOrgResourceInput>): Promise<Client.ResponseOrgResourceOperation>;
93
+ configBlocklet(params: OmitTeamDid<Client.RequestConfigBlockletInput>): Promise<Client.ResponseBlocklet>;
94
+ configNavigations(params: OmitTeamDid<Client.RequestConfigNavigationsInput>): Promise<Client.ResponseBlocklet>;
93
95
  }
94
96
  export = BlockletService;
@@ -173,6 +173,9 @@ class BlockletService {
173
173
  'getOrgResource',
174
174
  'addOrgResource',
175
175
  'migrateOrgResource',
176
+ // config
177
+ 'configBlocklet',
178
+ 'configNavigations',
176
179
  ];
177
180
  const teamDid = process.env.BLOCKLET_DID;
178
181
  const componentDid = process.env.BLOCKLET_COMPONENT_DID;
@@ -207,17 +210,19 @@ class BlockletService {
207
210
  getBlocklet: (fn) => (attachRuntimeInfo = false, useCache = true) => fn({ input: { did: teamDid, attachRuntimeInfo, useCache } }, { ignoreFields: ['blocklet.settings.navigations'] }),
208
211
  createAccessKey: (fn) => (params) => fn({
209
212
  input: {
210
- teamDid,
211
213
  authType: 'simple',
212
214
  createdVia: 'sdk',
213
215
  passport: constant_1.SERVER_ROLES.GUEST,
214
216
  ...params,
215
217
  componentDid,
218
+ teamDid,
216
219
  },
217
220
  }),
218
- verifyAccessKey: (fn) => (params) => fn({ input: { teamDid, ...params } }),
219
- getAccessKeys: (fn) => (params) => fn({ input: { teamDid, ...params, componentDid } }),
220
- getAccessKey: (fn) => (params) => fn({ input: { teamDid, ...params } }),
221
+ verifyAccessKey: (fn) => (params) => fn({ input: { ...params, teamDid } }),
222
+ getAccessKeys: (fn) => (params) => fn({ input: { ...params, teamDid, componentDid } }),
223
+ getAccessKey: (fn) => (params) => fn({ input: { ...params, teamDid } }),
224
+ configBlocklet: (fn) => (params) => fn({ input: { ...params, did: [teamDid] } }),
225
+ configNavigations: (fn) => (params) => fn({ input: { ...params, did: [teamDid] } }),
221
226
  };
222
227
  apiList.forEach((api) => {
223
228
  const fn = client[api];
@@ -0,0 +1,11 @@
1
+ export declare class AssetHostTransformer {
2
+ private static readonly HTML_TAG_INDICATOR;
3
+ private readonly assetBase;
4
+ private readonly quotedAssetBasePattern;
5
+ constructor(assetBase: string);
6
+ private static escapeForRegex;
7
+ private static normalizeAssetHost;
8
+ static containsHtmlMarkup(payload: string): boolean;
9
+ transform(html: string, assetHost: string): string;
10
+ transformBuffer(body: Buffer, assetHost: string): Buffer<ArrayBufferLike>;
11
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AssetHostTransformer = void 0;
4
+ const ufo_1 = require("ufo");
5
+ class AssetHostTransformer {
6
+ constructor(assetBase) {
7
+ this.assetBase = (0, ufo_1.withLeadingSlash)((0, ufo_1.withTrailingSlash)(assetBase));
8
+ this.quotedAssetBasePattern = new RegExp(AssetHostTransformer.escapeForRegex(`"${this.assetBase}`), 'g');
9
+ }
10
+ static escapeForRegex(value) {
11
+ const pattern = /[.*+?^${}()|[\]\\]/g;
12
+ return value.replace(pattern, '\\$&');
13
+ }
14
+ static normalizeAssetHost(assetHost) {
15
+ if (!assetHost) {
16
+ return null;
17
+ }
18
+ const trimmed = assetHost.trim();
19
+ if (!trimmed) {
20
+ return null;
21
+ }
22
+ return trimmed.replace(/\/+$/, '').replace(/^https?:\/\//, '');
23
+ }
24
+ static containsHtmlMarkup(payload) {
25
+ return payload.includes(AssetHostTransformer.HTML_TAG_INDICATOR);
26
+ }
27
+ transform(html, assetHost) {
28
+ const host = AssetHostTransformer.normalizeAssetHost(assetHost);
29
+ if (!host) {
30
+ return html;
31
+ }
32
+ if (!AssetHostTransformer.containsHtmlMarkup(html)) {
33
+ return html;
34
+ }
35
+ return html.replace(this.quotedAssetBasePattern, `"//${host}${this.assetBase}`);
36
+ }
37
+ transformBuffer(body, assetHost) {
38
+ const bodyAsString = body.toString('utf8');
39
+ if (!AssetHostTransformer.containsHtmlMarkup(bodyAsString)) {
40
+ return body;
41
+ }
42
+ const transformed = this.transform(bodyAsString, assetHost);
43
+ if (transformed === bodyAsString) {
44
+ return body;
45
+ }
46
+ return Buffer.from(transformed);
47
+ }
48
+ }
49
+ exports.AssetHostTransformer = AssetHostTransformer;
50
+ AssetHostTransformer.HTML_TAG_INDICATOR = '<html';
@@ -35,8 +35,8 @@ function verifyLoginToken({ token, strictMode }) {
35
35
  resolve(null);
36
36
  return;
37
37
  }
38
- const { did, role, fullName, provider = constant_1.LOGIN_PROVIDER.WALLET, walletOS, kyc = 0 } = decoded;
39
- resolve({
38
+ const { did, role, fullName, provider = constant_1.LOGIN_PROVIDER.WALLET, walletOS, kyc = 0, org = '' } = decoded;
39
+ const loginUser = {
40
40
  did,
41
41
  role,
42
42
  fullName,
@@ -44,7 +44,11 @@ function verifyLoginToken({ token, strictMode }) {
44
44
  walletOS,
45
45
  ...(0, login_1.decodeKycStatus)(Number(kyc) || 0),
46
46
  method: 'loginToken',
47
- });
47
+ };
48
+ if (org) {
49
+ loginUser.org = org;
50
+ }
51
+ resolve(loginUser);
48
52
  });
49
53
  });
50
54
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.52-beta-20251005-235515-42ad5caf",
6
+ "version": "1.16.52-beta-20251008-094601-8a853b5b",
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,19 +27,19 @@
27
27
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@abtnode/constant": "1.16.52-beta-20251005-235515-42ad5caf",
31
- "@abtnode/db-cache": "1.16.52-beta-20251005-235515-42ad5caf",
32
- "@abtnode/util": "1.16.52-beta-20251005-235515-42ad5caf",
30
+ "@abtnode/constant": "1.16.52-beta-20251008-094601-8a853b5b",
31
+ "@abtnode/db-cache": "1.16.52-beta-20251008-094601-8a853b5b",
32
+ "@abtnode/util": "1.16.52-beta-20251008-094601-8a853b5b",
33
33
  "@arcblock/did": "1.25.6",
34
34
  "@arcblock/did-connect-js": "1.25.6",
35
35
  "@arcblock/jwt": "1.25.6",
36
36
  "@arcblock/ws": "1.25.6",
37
- "@blocklet/constant": "1.16.52-beta-20251005-235515-42ad5caf",
38
- "@blocklet/env": "1.16.52-beta-20251005-235515-42ad5caf",
37
+ "@blocklet/constant": "1.16.52-beta-20251008-094601-8a853b5b",
38
+ "@blocklet/env": "1.16.52-beta-20251008-094601-8a853b5b",
39
39
  "@blocklet/error": "^0.2.5",
40
- "@blocklet/meta": "1.16.52-beta-20251005-235515-42ad5caf",
41
- "@blocklet/server-js": "1.16.52-beta-20251005-235515-42ad5caf",
42
- "@blocklet/theme": "^3.1.44",
40
+ "@blocklet/meta": "1.16.52-beta-20251008-094601-8a853b5b",
41
+ "@blocklet/server-js": "1.16.52-beta-20251008-094601-8a853b5b",
42
+ "@blocklet/theme": "^3.1.45",
43
43
  "@did-connect/authenticator": "^2.2.8",
44
44
  "@did-connect/handler": "^2.2.8",
45
45
  "@nedb/core": "^2.1.5",
@@ -85,5 +85,5 @@
85
85
  "ts-node": "^10.9.1",
86
86
  "typescript": "^5.6.3"
87
87
  },
88
- "gitHead": "7b295929a123edac2cb292c43f2edda0d3e3e6b8"
88
+ "gitHead": "355bb7832b143453d20acad991d728dac69fcf07"
89
89
  }