@blocklet/pages-kit 0.2.250 → 0.2.251
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/cjs/builtin/call.js +17 -0
- package/lib/esm/builtin/call.js +18 -1
- package/package.json +1 -1
package/lib/cjs/builtin/call.js
CHANGED
|
@@ -12,7 +12,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.call = void 0;
|
|
13
13
|
const utils_1 = require("./utils");
|
|
14
14
|
function call(input) {
|
|
15
|
+
var _a, _b;
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
// call component directly at server side
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
const { getComponentWebEndpoint } =
|
|
20
|
+
// eslint-disable-next-line global-require
|
|
21
|
+
require('@blocklet/sdk/lib/component');
|
|
22
|
+
const { sign } =
|
|
23
|
+
// eslint-disable-next-line global-require
|
|
24
|
+
require('@blocklet/sdk/lib/util/verify-sign');
|
|
25
|
+
return fetch((0, utils_1.withQuery)((0, utils_1.joinURL)(getComponentWebEndpoint('pages-kit'), input.path), (_a = input.query) !== null && _a !== void 0 ? _a : {}), {
|
|
26
|
+
method: input.method,
|
|
27
|
+
headers: Object.assign(Object.assign({}, input.headers), { 'x-component-sig': sign((_b = input.body) !== null && _b !== void 0 ? _b : {}), 'x-component-did': process.env.BLOCKLET_COMPONENT_DID, 'Content-Type': 'application/json' }),
|
|
28
|
+
body: typeof input.body !== 'undefined' && input.method.toLowerCase() !== 'get'
|
|
29
|
+
? JSON.stringify(input.body)
|
|
30
|
+
: undefined,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
16
33
|
const prefix = (0, utils_1.getComponentMountPoint)('pages-kit');
|
|
17
34
|
return fetch((0, utils_1.joinURL)(prefix, '/api/call'), {
|
|
18
35
|
method: 'POST',
|
package/lib/esm/builtin/call.js
CHANGED
|
@@ -7,9 +7,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { getComponentMountPoint, joinURL } from './utils';
|
|
10
|
+
import { getComponentMountPoint, joinURL, withQuery } from './utils';
|
|
11
11
|
export function call(input) {
|
|
12
|
+
var _a, _b;
|
|
12
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
// call component directly at server side
|
|
15
|
+
if (typeof window === 'undefined') {
|
|
16
|
+
const { getComponentWebEndpoint } =
|
|
17
|
+
// eslint-disable-next-line global-require
|
|
18
|
+
require('@blocklet/sdk/lib/component');
|
|
19
|
+
const { sign } =
|
|
20
|
+
// eslint-disable-next-line global-require
|
|
21
|
+
require('@blocklet/sdk/lib/util/verify-sign');
|
|
22
|
+
return fetch(withQuery(joinURL(getComponentWebEndpoint('pages-kit'), input.path), (_a = input.query) !== null && _a !== void 0 ? _a : {}), {
|
|
23
|
+
method: input.method,
|
|
24
|
+
headers: Object.assign(Object.assign({}, input.headers), { 'x-component-sig': sign((_b = input.body) !== null && _b !== void 0 ? _b : {}), 'x-component-did': process.env.BLOCKLET_COMPONENT_DID, 'Content-Type': 'application/json' }),
|
|
25
|
+
body: typeof input.body !== 'undefined' && input.method.toLowerCase() !== 'get'
|
|
26
|
+
? JSON.stringify(input.body)
|
|
27
|
+
: undefined,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
13
30
|
const prefix = getComponentMountPoint('pages-kit');
|
|
14
31
|
return fetch(joinURL(prefix, '/api/call'), {
|
|
15
32
|
method: 'POST',
|