@blocklet/server-js 1.16.49-beta-20250821-102221-1b7283d6

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2018-2025 ArcBlock
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # ABT Node Client
2
+
3
+ Client library to connect webapp to Abt Node Daemon
4
+
5
+ ## Table of Contents
6
+
7
+ - [Development](#development)
8
+ - [Install](#install)
9
+ - [Usage](#usage)
10
+ - [Debugging](#debugging)
11
+ - [Documentation](#documentation)
12
+
13
+ ## Development
14
+
15
+ upgrade code: you need two shells
16
+
17
+ 1. start demo server
18
+
19
+ ```shell
20
+ cd ../gql
21
+ node demo.js
22
+ ```
23
+
24
+ 2. upgrade code
25
+
26
+ ```shell
27
+ npm run upgrade
28
+ ```
29
+
30
+ ## Install
31
+
32
+ ```shell
33
+ npm i @blocklet/server-js -S
34
+ # OR
35
+ yarn add @blocklet/server-js
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```js
41
+ const AbtNodeClient = require('@blocklet/server-js');
42
+
43
+ const client = new AbtNodeClient('http://localhost:3030/api/gql');
44
+ console.log({
45
+ queries: client.getQueries(),
46
+ subscriptions: client.getSubscriptions(),
47
+ mutations: client.getMutations(),
48
+ });
49
+
50
+ client.listBlocklets().then(console.log);
51
+ ```
52
+
53
+ ## Debugging
54
+
55
+ - If you are in Node.js: `DEBUG=@blocklet/server-js node script.js`
56
+ - If you are in Browser: `localStorage.setItem('DEBUG', '@blocklet/server-js')`
57
+
58
+ ## Documentation
59
+
60
+ Query arguments and response structure can be found: [QUERIES.md](./docs/QUERIES.md)
package/dist/base.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.regexp.exec.js");
4
+ require("core-js/modules/es.string.ends-with.js");
5
+ require("core-js/modules/es.string.replace.js");
6
+ /* eslint-disable no-underscore-dangle */
7
+ const BaseClient = require('@arcblock/sdk-util');
8
+ const dayjs = require('dayjs');
9
+ const timezone = require('dayjs/plugin/timezone');
10
+ dayjs.extend(timezone);
11
+ const schema = require('./schema/graphql.json');
12
+
13
+ /**
14
+ * Provides a readonly client to forge
15
+ * Its recommended to use this version in browser to get smaller bundle size
16
+ *
17
+ * @class ABTNodeClient
18
+ * @extends {BaseClient}
19
+ */
20
+ class ABTNodeClient extends BaseClient {
21
+ constructor() {
22
+ let httpEndpoint = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'http://localhost:4000/api';
23
+ let userAgent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
24
+ const config = {
25
+ dataSource: 'forge',
26
+ httpEndpoint,
27
+ socketEndpoint: () => this._getSocketEndpoint(httpEndpoint),
28
+ enableQuery: true,
29
+ enableSubscription: true,
30
+ enableMutation: true,
31
+ maxQueryDepth: 6
32
+ };
33
+ super(config);
34
+ this._endpoint = httpEndpoint;
35
+ this._authToken = null;
36
+ this._userAgent = userAgent;
37
+ }
38
+ setAuthToken(token) {
39
+ this._authToken = token;
40
+ }
41
+ _getSocketEndpoint(endpoint) {
42
+ let socketEndpoint = endpoint.replace(/https?:\/\//, 'ws://');
43
+ if (endpoint.indexOf('https://') === 0) {
44
+ socketEndpoint = socketEndpoint.replace('ws://', 'wss://');
45
+ }
46
+ return "".concat(socketEndpoint, "/socket");
47
+ }
48
+ _getSchema() {
49
+ return schema;
50
+ }
51
+
52
+ // eslint-disable-next-line
53
+ _getIgnoreFields(_ref) {
54
+ let {
55
+ name
56
+ } = _ref;
57
+ return [];
58
+ }
59
+ _getAuthHeaders() {
60
+ const headers = {};
61
+ const token = this._authToken;
62
+ if (token) {
63
+ const val = typeof token === 'function' ? token() : token;
64
+ headers.Authorization = "Bearer ".concat(encodeURIComponent(val));
65
+ }
66
+
67
+ // eslint-disable-next-line no-undef
68
+ if (typeof window !== 'undefined' && typeof window.location !== 'undefined') {
69
+ const {
70
+ hostname,
71
+ port,
72
+ protocol
73
+ } = window.location; // eslint-disable-line no-undef
74
+ headers['x-real-hostname'] = hostname;
75
+ headers['x-real-port'] = port;
76
+ headers['x-real-protocol'] = protocol.endsWith(':') ? protocol.substring(0, protocol.length - 1) : protocol;
77
+ }
78
+ if (this._userAgent) {
79
+ headers['User-Agent'] = this._userAgent;
80
+ }
81
+
82
+ // 获取时区
83
+ headers['x-timezone'] = dayjs.tz.guess();
84
+ return headers;
85
+ }
86
+ }
87
+ module.exports = ABTNodeClient;
88
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","names":["BaseClient","require","dayjs","timezone","extend","schema","ABTNodeClient","constructor","httpEndpoint","arguments","length","undefined","userAgent","config","dataSource","socketEndpoint","_getSocketEndpoint","enableQuery","enableSubscription","enableMutation","maxQueryDepth","_endpoint","_authToken","_userAgent","setAuthToken","token","endpoint","replace","indexOf","concat","_getSchema","_getIgnoreFields","_ref","name","_getAuthHeaders","headers","val","Authorization","encodeURIComponent","window","location","hostname","port","protocol","endsWith","substring","tz","guess","module","exports"],"sources":["../src/base.js"],"sourcesContent":["/* eslint-disable no-underscore-dangle */\nconst BaseClient = require('@arcblock/sdk-util');\nconst dayjs = require('dayjs');\nconst timezone = require('dayjs/plugin/timezone');\n\ndayjs.extend(timezone);\n\nconst schema = require('./schema/graphql.json');\n\n/**\n * Provides a readonly client to forge\n * Its recommended to use this version in browser to get smaller bundle size\n *\n * @class ABTNodeClient\n * @extends {BaseClient}\n */\nclass ABTNodeClient extends BaseClient {\n constructor(httpEndpoint = 'http://localhost:4000/api', userAgent = '') {\n const config = {\n dataSource: 'forge',\n httpEndpoint,\n socketEndpoint: () => this._getSocketEndpoint(httpEndpoint),\n enableQuery: true,\n enableSubscription: true,\n enableMutation: true,\n maxQueryDepth: 6,\n };\n\n super(config);\n\n this._endpoint = httpEndpoint;\n this._authToken = null;\n this._userAgent = userAgent;\n }\n\n setAuthToken(token) {\n this._authToken = token;\n }\n\n _getSocketEndpoint(endpoint) {\n let socketEndpoint = endpoint.replace(/https?:\\/\\//, 'ws://');\n if (endpoint.indexOf('https://') === 0) {\n socketEndpoint = socketEndpoint.replace('ws://', 'wss://');\n }\n\n return `${socketEndpoint}/socket`;\n }\n\n _getSchema() {\n return schema;\n }\n\n // eslint-disable-next-line\n _getIgnoreFields({ name }) {\n return [];\n }\n\n _getAuthHeaders() {\n const headers = {};\n const token = this._authToken;\n if (token) {\n const val = typeof token === 'function' ? token() : token;\n headers.Authorization = `Bearer ${encodeURIComponent(val)}`;\n }\n\n // eslint-disable-next-line no-undef\n if (typeof window !== 'undefined' && typeof window.location !== 'undefined') {\n const { hostname, port, protocol } = window.location; // eslint-disable-line no-undef\n headers['x-real-hostname'] = hostname;\n headers['x-real-port'] = port;\n headers['x-real-protocol'] = protocol.endsWith(':') ? protocol.substring(0, protocol.length - 1) : protocol;\n }\n\n if (this._userAgent) {\n headers['User-Agent'] = this._userAgent;\n }\n\n // 获取时区\n headers['x-timezone'] = dayjs.tz.guess();\n\n return headers;\n }\n}\n\nmodule.exports = ABTNodeClient;\n"],"mappings":";;;;;AAAA;AACA,MAAMA,UAAU,GAAGC,OAAO,CAAC,oBAAoB,CAAC;AAChD,MAAMC,KAAK,GAAGD,OAAO,CAAC,OAAO,CAAC;AAC9B,MAAME,QAAQ,GAAGF,OAAO,CAAC,uBAAuB,CAAC;AAEjDC,KAAK,CAACE,MAAM,CAACD,QAAQ,CAAC;AAEtB,MAAME,MAAM,GAAGJ,OAAO,CAAC,uBAAuB,CAAC;;AAE/C;AACA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