@blocklet/sdk 1.16.15-beta-e3a24907 → 1.16.15-beta-18951729

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.
@@ -19,6 +19,7 @@ const doCall = async ({ url, ...options }) => {
19
19
  ...options,
20
20
  headers: {
21
21
  'x-component-sig': (0, verify_sign_1.sign)(options.data),
22
+ 'x-component-did': process.env.BLOCKLET_COMPONENT_DID,
22
23
  },
23
24
  timeout: 60 * 1000,
24
25
  });
@@ -1,26 +1,47 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  const fs_1 = require("fs");
3
6
  const path_1 = require("path");
7
+ const url_join_1 = __importDefault(require("url-join"));
4
8
  const config_1 = require("../config");
5
9
  const fallback = (file, options = {}) => {
6
10
  const filePath = options.root ? (0, path_1.join)(options.root, file) : file;
7
11
  if ((0, fs_1.existsSync)(filePath) === false) {
8
12
  throw new Error(`Fallback file not found at: ${filePath}`);
9
13
  }
10
- const source = (0, fs_1.readFileSync)(filePath).toString();
14
+ let source = (0, fs_1.readFileSync)(filePath).toString();
11
15
  return (req, res, next) => {
12
16
  if ((req.method === 'GET' || req.method === 'HEAD') && req.accepts('html')) {
13
17
  res.type('html');
14
18
  const pageGroup = req.headers['x-page-group'] || '';
15
19
  const blockletJs = (0, config_1.getBlockletJs)(pageGroup);
20
+ // update page title
21
+ if (config_1.env.appName) {
22
+ if (source.indexOf('<title>') > -1) {
23
+ source = source.replace(/<title>(.+)<\/title>/, `<title>${config_1.env.appName}</title>`);
24
+ }
25
+ else {
26
+ source = source.replace('</head>', `<title>${config_1.env.appName}</title></head>`);
27
+ }
28
+ }
29
+ // inline blocklet.js
16
30
  if (blockletJs) {
17
- res.send(source
31
+ source = source
18
32
  .replace('<script src="__blocklet__.js"></script>', `<script>${blockletJs}</script>`)
19
- .replace('<script src="__meta__.js"></script>', `<script>${blockletJs}</script>`));
33
+ .replace('<script src="__meta__.js"></script>', `<script>${blockletJs}</script>`);
20
34
  }
21
- else {
22
- res.send(source);
35
+ // inject og meta
36
+ if (source.indexOf('meta property="og:image"') === -1 && config_1.env.appUrl) {
37
+ const og = `<meta property="og:title" content="${config_1.env.appName}" />
38
+ <meta property="og:description" content="${config_1.env.appDescription}" />
39
+ <meta property="og:type" content="website" />
40
+ <meta property="og:url" content="${config_1.env.appUrl}" />
41
+ <meta property="og:image" content="${(0, url_join_1.default)(config_1.env.appUrl, '/.well-known/service/blocklet/og.png')}" />`;
42
+ source = source.replace('</head>', `${og}</head>`);
23
43
  }
44
+ res.send(source);
24
45
  }
25
46
  else {
26
47
  next();
@@ -63,6 +63,6 @@ declare const _default: {
63
63
  keywords: string;
64
64
  stock_tickers: string;
65
65
  };
66
- }) => void) => Promise<void>) => (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: import("express").Response<any, Record<string, any>>) => Promise<void>;
66
+ }) => void, req?: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>) => Promise<void>) => (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: import("express").Response<any, Record<string, any>>) => Promise<void>;
67
67
  };
68
68
  export default _default;
@@ -38,6 +38,6 @@ type SitemapItem = {
38
38
  androidLink?: string;
39
39
  news?: News;
40
40
  };
41
- type GeneratorFn = (fn: (item: SitemapItem) => void) => Promise<void>;
41
+ type GeneratorFn = (fn: (item: SitemapItem) => void, req?: Request) => Promise<void>;
42
42
  declare const sitemap: (generatorFn: GeneratorFn) => (req: Request, res: Response) => Promise<void>;
43
43
  export = sitemap;
@@ -6,7 +6,7 @@ const sitemap = (generatorFn) => {
6
6
  res.header('Content-Type', 'application/xml');
7
7
  try {
8
8
  const stream = new sitemap_1.SitemapStream({ hostname: config_1.env.appUrl });
9
- await generatorFn(stream.write.bind(stream));
9
+ await generatorFn(stream.write.bind(stream), req);
10
10
  stream.end();
11
11
  const result = await (0, sitemap_1.streamToPromise)(stream).then((data) => data.toString());
12
12
  res.send(result);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.15-beta-e3a24907",
6
+ "version": "1.16.15-beta-18951729",
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,15 +26,15 @@
26
26
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
27
27
  "license": "Apache-2.0",
28
28
  "dependencies": {
29
- "@abtnode/client": "1.16.15-beta-e3a24907",
30
- "@abtnode/constant": "1.16.15-beta-e3a24907",
29
+ "@abtnode/client": "1.16.15-beta-18951729",
30
+ "@abtnode/constant": "1.16.15-beta-18951729",
31
31
  "@arcblock/did": "1.18.89",
32
32
  "@arcblock/did-auth": "1.18.89",
33
33
  "@arcblock/jwt": "1.18.89",
34
34
  "@arcblock/ws": "1.18.89",
35
- "@blocklet/constant": "1.16.15-beta-e3a24907",
36
- "@blocklet/env": "1.16.15-beta-e3a24907",
37
- "@blocklet/meta": "1.16.15-beta-e3a24907",
35
+ "@blocklet/constant": "1.16.15-beta-18951729",
36
+ "@blocklet/env": "1.16.15-beta-18951729",
37
+ "@blocklet/meta": "1.16.15-beta-18951729",
38
38
  "@did-connect/authenticator": "^2.2.0",
39
39
  "@did-connect/handler": "^2.2.0",
40
40
  "@nedb/core": "^2.1.5",
@@ -74,5 +74,5 @@
74
74
  "ts-node": "^10.9.1",
75
75
  "typescript": "^5.0.4"
76
76
  },
77
- "gitHead": "b87c810902571b8cdb8f12ef497286b1549888e9"
77
+ "gitHead": "6ba076bcc138a3b9948771deae0f723a5104f70f"
78
78
  }