@blocklet/sdk 1.16.19-beta-7d3ef675 → 1.16.19-beta-630ac853

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.
@@ -1,6 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { AxiosResponse, Method } from 'axios';
3
3
  import { IncomingMessage } from 'http';
4
+ import * as Util from './util';
5
+ import type { Resource } from './util';
4
6
  declare const getChildWebEndpoint: (name: string) => string;
5
7
  declare const getParentWebEndpoint: () => string;
6
8
  declare const getComponentWebEndpoint: (keyword: string) => string;
@@ -10,6 +12,9 @@ type CallComponentOptions<D = any, P = any> = {
10
12
  path: string;
11
13
  data?: D;
12
14
  params?: P;
15
+ headers?: {
16
+ [key: string]: any;
17
+ };
13
18
  };
14
19
  type CallComponent = {
15
20
  (options: CallComponentOptions & {
@@ -24,11 +29,16 @@ declare const getResourceExportDir: ({ projectId, releaseId }?: {
24
29
  projectId: string;
25
30
  releaseId?: string;
26
31
  }) => string;
32
+ declare const getResources: ({ types, skipRunningCheck, }?: {
33
+ types?: string[];
34
+ skipRunningCheck?: boolean;
35
+ }) => Resource[];
27
36
  export { call };
28
37
  export { getUrl };
29
38
  export { getComponentMountPoint };
30
39
  export { getComponentWebEndpoint };
31
40
  export { getResourceExportDir };
41
+ export { getResources };
32
42
  export { getChildWebEndpoint };
33
43
  export { getParentWebEndpoint };
34
44
  declare const _default: {
@@ -40,6 +50,10 @@ declare const _default: {
40
50
  projectId: string;
41
51
  releaseId?: string;
42
52
  }) => string;
53
+ getResources: ({ types, skipRunningCheck, }?: {
54
+ types?: string[];
55
+ skipRunningCheck?: boolean;
56
+ }) => Util.Resource[];
43
57
  getChildWebEndpoint: (name: string) => string;
44
58
  getParentWebEndpoint: () => string;
45
59
  };
@@ -1,9 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getResourceExportDir = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
29
+ exports.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getResources = exports.getResourceExportDir = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
7
30
  const path_1 = require("path");
8
31
  const util_1 = require("@blocklet/meta/lib/util");
9
32
  const axios_1 = __importDefault(require("axios"));
@@ -13,13 +36,15 @@ const url_join_1 = __importDefault(require("url-join"));
13
36
  const constant_1 = require("@blocklet/constant");
14
37
  const config_1 = require("../config");
15
38
  const verify_sign_1 = require("../util/verify-sign");
16
- const doCall = async ({ url, ...options }) => {
39
+ const Util = __importStar(require("./util"));
40
+ const doCall = async ({ url, headers = {}, ...options }) => {
17
41
  try {
18
42
  const resp = await (0, axios_1.default)({
19
43
  url,
20
44
  timeout: 60 * 1000,
21
45
  ...options,
22
46
  headers: {
47
+ ...(headers || {}),
23
48
  'x-component-sig': (0, verify_sign_1.sign)(options.data),
24
49
  'x-component-did': process.env.BLOCKLET_COMPONENT_DID,
25
50
  },
@@ -113,12 +138,17 @@ const getResourceExportDir = ({ projectId, releaseId } = { projectId: '' }) => {
113
138
  return dir;
114
139
  };
115
140
  exports.getResourceExportDir = getResourceExportDir;
141
+ const getResources = ({ types, skipRunningCheck, } = {}) => {
142
+ return Util.getResources({ components: config_1.components, types, skipRunningCheck });
143
+ };
144
+ exports.getResources = getResources;
116
145
  exports.default = {
117
146
  call,
118
147
  getUrl,
119
148
  getComponentMountPoint,
120
149
  getComponentWebEndpoint,
121
150
  getResourceExportDir,
151
+ getResources,
122
152
  getChildWebEndpoint,
123
153
  getParentWebEndpoint, // deprecated
124
154
  };
@@ -0,0 +1,19 @@
1
+ import type { TComponent } from '../config';
2
+ type Resource = {
3
+ title: string;
4
+ did: string;
5
+ version: string;
6
+ status?: number;
7
+ path?: string;
8
+ };
9
+ declare function getResources({ components, types, skipRunningCheck, }?: {
10
+ components: TComponent[];
11
+ types?: string[];
12
+ skipRunningCheck?: boolean;
13
+ }): Resource[];
14
+ export { getResources };
15
+ export { Resource };
16
+ declare const _default: {
17
+ getResources: typeof getResources;
18
+ };
19
+ export default _default;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getResources = void 0;
7
+ const pick_1 = __importDefault(require("lodash/pick"));
8
+ const constant_1 = require("@blocklet/constant");
9
+ function getResources({ components, types, skipRunningCheck, } = {
10
+ components: [],
11
+ }) {
12
+ const list = [];
13
+ components
14
+ .filter((x) => skipRunningCheck || x.status === constant_1.BlockletStatus.running)
15
+ .forEach((component) => {
16
+ const resource = component.resources?.find((x) => (types || []).some((type) => x.endsWith(type)));
17
+ if (resource) {
18
+ list.push({
19
+ ...(0, pick_1.default)(component, ['title', 'did', 'version', 'status']),
20
+ path: resource,
21
+ });
22
+ }
23
+ });
24
+ return list;
25
+ }
26
+ exports.getResources = getResources;
27
+ exports.default = {
28
+ getResources,
29
+ };
package/lib/index.d.ts CHANGED
@@ -28,35 +28,36 @@ export { Component as component };
28
28
  export { Component };
29
29
  export { Security };
30
30
  export { config };
31
+ export interface WindowBlocklet {
32
+ [x: string]: any;
33
+ appId: string;
34
+ appIds: string[];
35
+ appPid: string;
36
+ appName: string;
37
+ appDescription: string;
38
+ appLogo: string;
39
+ appLogoRect: string;
40
+ appUrl: string;
41
+ isComponent: boolean;
42
+ prefix: string;
43
+ groupPrefix: string;
44
+ pageGroup: string;
45
+ version: string;
46
+ theme: TTheme;
47
+ navigation: TNavigation[];
48
+ preferences: Record<string, any>;
49
+ languages: {
50
+ code: string;
51
+ name: string;
52
+ }[];
53
+ passportColor: string;
54
+ componentMountPoints: TComponent[];
55
+ alsoKnownAs: string[];
56
+ trustedFactories: string[];
57
+ }
31
58
  declare global {
32
59
  interface Window {
33
- blocklet: {
34
- [x: string]: any;
35
- appId: string;
36
- appIds: string[];
37
- appPid: string;
38
- appName: string;
39
- appDescription: string;
40
- appLogo: string;
41
- appLogoRect: string;
42
- appUrl: string;
43
- isComponent: boolean;
44
- prefix: string;
45
- groupPrefix: string;
46
- pageGroup: string;
47
- version: string;
48
- theme: TTheme;
49
- navigation: TNavigation[];
50
- preferences: Record<string, any>;
51
- languages: {
52
- code: string;
53
- name: string;
54
- }[];
55
- passportColor: string;
56
- componentMountPoints: TComponent[];
57
- alsoKnownAs: string[];
58
- trustedFactories: string[];
59
- };
60
+ blocklet: WindowBlocklet;
60
61
  }
61
62
  }
62
63
  export * from './component';
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.19-beta-7d3ef675",
6
+ "version": "1.16.19-beta-630ac853",
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.19-beta-7d3ef675",
30
- "@abtnode/constant": "1.16.19-beta-7d3ef675",
29
+ "@abtnode/client": "1.16.19-beta-630ac853",
30
+ "@abtnode/constant": "1.16.19-beta-630ac853",
31
31
  "@arcblock/did": "1.18.95",
32
32
  "@arcblock/did-auth": "1.18.95",
33
33
  "@arcblock/jwt": "1.18.95",
34
34
  "@arcblock/ws": "1.18.95",
35
- "@blocklet/constant": "1.16.19-beta-7d3ef675",
36
- "@blocklet/env": "1.16.19-beta-7d3ef675",
37
- "@blocklet/meta": "1.16.19-beta-7d3ef675",
35
+ "@blocklet/constant": "1.16.19-beta-630ac853",
36
+ "@blocklet/env": "1.16.19-beta-630ac853",
37
+ "@blocklet/meta": "1.16.19-beta-630ac853",
38
38
  "@did-connect/authenticator": "^2.2.1",
39
39
  "@did-connect/handler": "^2.2.1",
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": "af968e7bab22e67bd42d3dc93ff3ce827b9a91fe"
77
+ "gitHead": "a4feb519d9122ef75873dd8d657486afca2d4ac9"
78
78
  }