@blocklet/sdk 1.16.52-beta-20251002-030549-0f91dab2 → 1.16.52-beta-20251005-235515-42ad5caf

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.
@@ -0,0 +1,16 @@
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>;
14
+ }
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;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cdn = exports.createTransformAssetHostMiddleware = exports.BlockletAssetHostTransformer = void 0;
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/';
53
+ function shouldProcessRequest(req) {
54
+ const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
55
+ if (!isProduction) {
56
+ return false;
57
+ }
58
+ if (!(req.method === 'GET' || req.method === 'HEAD')) {
59
+ return false;
60
+ }
61
+ if (req.path.includes('/.well-known/service/')) {
62
+ return false;
63
+ }
64
+ if (constant_1.RESOURCE_PATTERN.test(req.path)) {
65
+ return false;
66
+ }
67
+ const accepted = req.accepts(['html', 'text/html', 'application/xhtml+xml', '*/*']);
68
+ return Boolean(accepted);
69
+ }
70
+ const createTransformAssetHostMiddleware = (did) => {
71
+ const transformer = new BlockletAssetHostTransformer(did);
72
+ return (req, res, next) => {
73
+ const assetHost = process.env.ASSET_CDN_HOST;
74
+ if (!shouldProcessRequest(req) || !assetHost) {
75
+ next();
76
+ return;
77
+ }
78
+ const originalSend = res.send;
79
+ res.send = function send(body) {
80
+ if (typeof body === 'string') {
81
+ return originalSend.call(this, transformer.transform(body, assetHost));
82
+ }
83
+ if (Buffer.isBuffer(body)) {
84
+ return originalSend.call(this, transformer.transformBuffer(body, assetHost));
85
+ }
86
+ return originalSend.call(this, body);
87
+ };
88
+ next();
89
+ };
90
+ };
91
+ exports.createTransformAssetHostMiddleware = createTransformAssetHostMiddleware;
92
+ exports.cdn = (0, exports.createTransformAssetHostMiddleware)(process.env.BLOCKLET_COMPONENT_DID);
@@ -88,5 +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
92
  };
92
93
  export default _default;
@@ -18,6 +18,7 @@ const session_1 = __importDefault(require("./session"));
18
18
  exports.session = session_1.default;
19
19
  const csrf_1 = require("./csrf");
20
20
  Object.defineProperty(exports, "csrf", { enumerable: true, get: function () { return csrf_1.csrf; } });
21
+ const cdn_1 = require("./cdn");
21
22
  exports.default = {
22
23
  user: user_1.default,
23
24
  auth: auth_1.default,
@@ -26,4 +27,5 @@ exports.default = {
26
27
  sitemap: sitemap_1.default,
27
28
  csrf: csrf_1.csrf,
28
29
  session: session_1.default,
30
+ cdn: cdn_1.cdn,
29
31
  };
@@ -84,5 +84,11 @@ interface BlockletService {
84
84
  followUser(args: OmitTeamDid<Client.RequestFollowUserActionInput>): Promise<Client.GeneralResponse>;
85
85
  unfollowUser(args: OmitTeamDid<Client.RequestFollowUserActionInput>): Promise<Client.GeneralResponse>;
86
86
  getUserInvites(args: OmitTeamDid<Client.RequestUserRelationQueryInput>, options: RequestHeaders): Promise<Client.ResponseUsers>;
87
+ getOrg(params: OmitTeamDid<Client.RequestGetOrgInput>): Promise<Client.ResponseGetOrg>;
88
+ getOrgs(params: OmitTeamDid<Client.RequestGetOrgsInput>): Promise<Client.ResponseGetOrgs>;
89
+ createOrg(params: OmitTeamDid<Client.RequestCreateOrgInput>): Promise<Client.ResponseGetOrg>;
90
+ getOrgResource(params: OmitTeamDid<Client.RequestGetOrgResourceInput>): Promise<Client.ResponseGetOrgResource>;
91
+ addOrgResource(params: OmitTeamDid<Client.RequestAddOrgResourceInput>): Promise<Client.ResponseOrgResourceOperation>;
92
+ migrateOrgResource(params: OmitTeamDid<Client.RequestMigrateOrgResourceInput>): Promise<Client.ResponseOrgResourceOperation>;
87
93
  }
88
94
  export = BlockletService;
@@ -166,6 +166,13 @@ class BlockletService {
166
166
  'verifyAccessKey',
167
167
  'getAccessKeys',
168
168
  'getAccessKey',
169
+ // org
170
+ 'getOrg',
171
+ 'getOrgs',
172
+ 'createOrg',
173
+ 'getOrgResource',
174
+ 'addOrgResource',
175
+ 'migrateOrgResource',
169
176
  ];
170
177
  const teamDid = process.env.BLOCKLET_DID;
171
178
  const componentDid = process.env.BLOCKLET_COMPONENT_DID;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.52-beta-20251002-030549-0f91dab2",
6
+ "version": "1.16.52-beta-20251005-235515-42ad5caf",
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,18 +27,18 @@
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-20251002-030549-0f91dab2",
31
- "@abtnode/db-cache": "1.16.52-beta-20251002-030549-0f91dab2",
32
- "@abtnode/util": "1.16.52-beta-20251002-030549-0f91dab2",
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",
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-20251002-030549-0f91dab2",
38
- "@blocklet/env": "1.16.52-beta-20251002-030549-0f91dab2",
37
+ "@blocklet/constant": "1.16.52-beta-20251005-235515-42ad5caf",
38
+ "@blocklet/env": "1.16.52-beta-20251005-235515-42ad5caf",
39
39
  "@blocklet/error": "^0.2.5",
40
- "@blocklet/meta": "1.16.52-beta-20251002-030549-0f91dab2",
41
- "@blocklet/server-js": "1.16.52-beta-20251002-030549-0f91dab2",
40
+ "@blocklet/meta": "1.16.52-beta-20251005-235515-42ad5caf",
41
+ "@blocklet/server-js": "1.16.52-beta-20251005-235515-42ad5caf",
42
42
  "@blocklet/theme": "^3.1.44",
43
43
  "@did-connect/authenticator": "^2.2.8",
44
44
  "@did-connect/handler": "^2.2.8",
@@ -85,5 +85,5 @@
85
85
  "ts-node": "^10.9.1",
86
86
  "typescript": "^5.6.3"
87
87
  },
88
- "gitHead": "57e57e5edc99bfbb7e4591d682f1057ec05655a8"
88
+ "gitHead": "7b295929a123edac2cb292c43f2edda0d3e3e6b8"
89
89
  }