@be-link/pos-cli-nodejs 1.0.239 → 1.0.241
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/README.md +17 -10
- package/index.d.ts +2 -2
- package/index.js +2 -4
- package/package.json +1 -1
- package/pos/modules/orderQuery/advisor.js +1 -1
- package/pos/modules/orderQuery/advisorHttpSender.d.ts +2 -2
- package/pos/modules/orderQuery/advisorHttpSender.js +8 -7
- package/pos/modules/orderQuery/advisorProtection.d.ts +11 -51
- package/pos/modules/orderQuery/advisorProtection.js +29 -166
- package/pos/modules/orderQuery/advisorTypes.d.ts +3 -6
package/README.md
CHANGED
|
@@ -9,16 +9,23 @@
|
|
|
9
9
|
返回值不包装完整订单 Proxy;金额 `remainingFeeCent` 是小管家的“合计”
|
|
10
10
|
(原单 remainFee),quantity 是剩余份数,不是差价数量或实付累计。
|
|
11
11
|
|
|
12
|
-
这组方法只向 transport
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
这组方法只向 transport 提供四条准确协议路径。保留 `new AdvisorQueryService(transport)`,
|
|
13
|
+
使用 `createAdvisorTokenTransport({origin, send})` 装配,send 通常由
|
|
14
|
+
`createAdvisorHttpsSender({origin, timeoutMs, maxResponseBytes})` 创建。
|
|
15
|
+
origin 必须显式配置为 HTTPS;本轮不修改旧 BaseService 的环境/目标选择。
|
|
16
|
+
transport 只允许准确协议相对路径及同 origin 的准确绝对 URL,不接受 query/hash、路径归一化或跨 origin。
|
|
17
|
+
|
|
18
|
+
每次请求动态读取 `process.env.authorizationTokenInside`(Shield Token),不缓存,缺失/空值时在 HTTP 前拒绝。
|
|
19
|
+
仅发送既有 SDK 鉴权 headers:`x-belink-accessType: authorizationTokenInside` 和
|
|
20
|
+
`x-belink-authorization: <当前 token>`。不使用旅顾独立签名、私钥或 actor 票据。
|
|
21
|
+
`canonicalAdvisorJson` 仍用于严格 JSON 快照;原签名/验签 API 已移除。
|
|
22
|
+
调用方身份与旅顾资格由服务端 Shield 和业务授权校验;SDK 不提供认证或资格证明。
|
|
23
|
+
业务 body 不接受 caller、actor、买家身份等额外字段。
|
|
24
|
+
|
|
25
|
+
HTTPS sender 保留显式 timeoutMs、maxResponseBytes,验证证书,不使用环境代理,
|
|
26
|
+
不跟随重定向、不重试,不允许额外自报鉴权 headers;响应容量仅为技术容量。
|
|
27
|
+
已知契约业务错误码保真,未知异常统一脱敏,不复制凭据或底层 HTTP 配置。
|
|
28
|
+
离线检查使用 mock HTTPS,未验证真实网络、代理、证书或服务端联调;未安装或发布新 SDK。
|
|
22
29
|
|
|
23
30
|
专用sender离线检查:
|
|
24
31
|
```bash
|
package/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export type { AdvisorBusinessCode } from './pos/modules/orderQuery/advisorBusine
|
|
|
3
3
|
export { AdvisorQueryService } from './pos/modules/orderQuery/advisor';
|
|
4
4
|
export { createAdvisorHttpsSender } from './pos/modules/orderQuery/advisorHttpSender';
|
|
5
5
|
export type { AdvisorHttpSenderOptions } from './pos/modules/orderQuery/advisorHttpSender';
|
|
6
|
-
export { canonicalAdvisorJson,
|
|
7
|
-
export type {
|
|
6
|
+
export { canonicalAdvisorJson, createAdvisorTokenTransport } from './pos/modules/orderQuery/advisorProtection';
|
|
7
|
+
export type { AdvisorTokenHeaders, AdvisorTokenSender, AdvisorTokenTransportOptions } from './pos/modules/orderQuery/advisorProtection';
|
|
8
8
|
export type { AdvisorOrderFacts, AdvisorOrderListRequest, AdvisorOrderRequest, AdvisorOrderBatchRequest, AdvisorOrderPage, AdvisorAdjustmentCreateFacts, AdvisorQueryController, AdvisorQueryMethod, AdvisorProtectedRequest, AdvisorProtectedTransport, AdvisorResponseEnvelope, } from './pos/modules/orderQuery/advisorTypes';
|
|
9
9
|
import * as PosConstants from 'vitality-meta/enums/pos';
|
|
10
10
|
import * as PosDto from './types';
|
package/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.VenueInfoProxy = exports.ComboInfoProxy = exports.SkuInfoProxy = exports.ItemInfoProxy = exports.PosProxyFactory = exports.BizError = exports.PosDto = exports.PosConstants = exports.tongchengService = exports.orderRoomShareService = exports.orderAbnormalFollowService = exports.orderTouristMaterialService = exports.dataMigrateService = exports.orderJobService = exports.orderNoteService = exports.queryByPandoraService = exports.queryBySupplierService = exports.queryByWebService = exports.queryByUserService = exports.queryByStoreService = exports.queryByCommodityService = exports.orderFulfillService = exports.orderCoreService = exports.
|
|
29
|
+
exports.VenueInfoProxy = exports.ComboInfoProxy = exports.SkuInfoProxy = exports.ItemInfoProxy = exports.PosProxyFactory = exports.BizError = exports.PosDto = exports.PosConstants = exports.tongchengService = exports.orderRoomShareService = exports.orderAbnormalFollowService = exports.orderTouristMaterialService = exports.dataMigrateService = exports.orderJobService = exports.orderNoteService = exports.queryByPandoraService = exports.queryBySupplierService = exports.queryByWebService = exports.queryByUserService = exports.queryByStoreService = exports.queryByCommodityService = exports.orderFulfillService = exports.orderCoreService = exports.createAdvisorTokenTransport = exports.canonicalAdvisorJson = exports.createAdvisorHttpsSender = exports.AdvisorQueryService = exports.AdvisorBusinessError = void 0;
|
|
30
30
|
var advisorBusinessError_1 = require("./pos/modules/orderQuery/advisorBusinessError");
|
|
31
31
|
Object.defineProperty(exports, "AdvisorBusinessError", { enumerable: true, get: function () { return advisorBusinessError_1.AdvisorBusinessError; } });
|
|
32
32
|
var advisor_1 = require("./pos/modules/orderQuery/advisor");
|
|
@@ -35,9 +35,7 @@ var advisorHttpSender_1 = require("./pos/modules/orderQuery/advisorHttpSender");
|
|
|
35
35
|
Object.defineProperty(exports, "createAdvisorHttpsSender", { enumerable: true, get: function () { return advisorHttpSender_1.createAdvisorHttpsSender; } });
|
|
36
36
|
var advisorProtection_1 = require("./pos/modules/orderQuery/advisorProtection");
|
|
37
37
|
Object.defineProperty(exports, "canonicalAdvisorJson", { enumerable: true, get: function () { return advisorProtection_1.canonicalAdvisorJson; } });
|
|
38
|
-
Object.defineProperty(exports, "
|
|
39
|
-
Object.defineProperty(exports, "createAdvisorRequestVerifier", { enumerable: true, get: function () { return advisorProtection_1.createAdvisorRequestVerifier; } });
|
|
40
|
-
Object.defineProperty(exports, "createSignedAdvisorTransport", { enumerable: true, get: function () { return advisorProtection_1.createSignedAdvisorTransport; } });
|
|
38
|
+
Object.defineProperty(exports, "createAdvisorTokenTransport", { enumerable: true, get: function () { return advisorProtection_1.createAdvisorTokenTransport; } });
|
|
41
39
|
const PosConstants = __importStar(require("vitality-meta/enums/pos"));
|
|
42
40
|
exports.PosConstants = PosConstants;
|
|
43
41
|
const PosDto = __importStar(require("./types"));
|
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@ function body(request, allowed) {
|
|
|
31
31
|
id(result.advisorId);
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
34
|
-
// Separate from queryByUserService:
|
|
34
|
+
// Separate from queryByUserService: explicit transport, with no legacy HTTP fallback.
|
|
35
35
|
class AdvisorQueryService extends service_1.default {
|
|
36
36
|
constructor(transport) {
|
|
37
37
|
super();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AdvisorTokenSender } from './advisorProtection';
|
|
2
2
|
export type AdvisorHttpSenderOptions = {
|
|
3
3
|
origin: string;
|
|
4
4
|
timeoutMs: number;
|
|
5
5
|
maxResponseBytes: number;
|
|
6
6
|
};
|
|
7
|
-
export declare function createAdvisorHttpsSender(options: AdvisorHttpSenderOptions):
|
|
7
|
+
export declare function createAdvisorHttpsSender(options: AdvisorHttpSenderOptions): AdvisorTokenSender;
|
|
@@ -38,16 +38,17 @@ function createAdvisorHttpsSender(options) {
|
|
|
38
38
|
return (input) => __awaiter(this, void 0, void 0, function* () {
|
|
39
39
|
let url;
|
|
40
40
|
let body;
|
|
41
|
-
let
|
|
41
|
+
let token;
|
|
42
42
|
try {
|
|
43
43
|
url = new URL(input.url);
|
|
44
44
|
if (input.method !== 'POST' || url.protocol !== 'https:' || url.origin !== origin ||
|
|
45
|
-
url.username || url.password || url.search || url.hash || !paths.includes(url.pathname) ||
|
|
46
|
-
!input.headers || Object.keys(input.headers).length !==
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
url.username || url.password || url.search || url.hash || !paths.includes(url.pathname) || input.url !== origin + url.pathname ||
|
|
46
|
+
!input.headers || Object.keys(input.headers).length !== 2 ||
|
|
47
|
+
input.headers['x-belink-accessType'] !== 'authorizationTokenInside' ||
|
|
48
|
+
typeof input.headers['x-belink-authorization'] !== 'string' ||
|
|
49
|
+
!input.headers['x-belink-authorization'] || input.headers['x-belink-authorization'].trim() !== input.headers['x-belink-authorization'] || /[\r\n]/.test(input.headers['x-belink-authorization']))
|
|
49
50
|
throw failed();
|
|
50
|
-
|
|
51
|
+
token = input.headers['x-belink-authorization'];
|
|
51
52
|
body = (0, advisorProtection_1.canonicalAdvisorJson)(input.body);
|
|
52
53
|
}
|
|
53
54
|
catch (_b) {
|
|
@@ -73,7 +74,7 @@ function createAdvisorHttpsSender(options) {
|
|
|
73
74
|
method: 'POST', agent: false, rejectUnauthorized: true,
|
|
74
75
|
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json',
|
|
75
76
|
'Accept-Encoding': 'identity', 'Content-Length': Buffer.byteLength(body),
|
|
76
|
-
'x-
|
|
77
|
+
'x-belink-accessType': 'authorizationTokenInside', 'x-belink-authorization': token },
|
|
77
78
|
}, (res) => {
|
|
78
79
|
if (settled) {
|
|
79
80
|
res.destroy();
|
|
@@ -1,63 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import { KeyObject } from 'crypto';
|
|
3
|
-
import { AdvisorProtectedTransport, AdvisorQueryMethod, AdvisorResponseEnvelope } from './advisorTypes';
|
|
1
|
+
import { AdvisorProtectedTransport, AdvisorResponseEnvelope } from './advisorTypes';
|
|
4
2
|
export declare const advisorActionPaths: {
|
|
5
3
|
readonly queryAdvisorShareOrderList: "/query/user/query-advisor-share-order-list";
|
|
6
4
|
readonly getAdvisorShareOrderFacts: "/query/user/get-advisor-share-order-facts";
|
|
7
5
|
readonly getAdvisorShareOrderFactsBatch: "/query/user/get-advisor-share-order-facts-batch";
|
|
8
6
|
readonly getAdvisorShareAdjustmentCreateFacts: "/query/user/get-advisor-share-adjustment-create-facts";
|
|
9
7
|
};
|
|
10
|
-
export type AdvisorCaller = 'DistributionService' | 'VitalityService';
|
|
11
|
-
export type AdvisorActor = Readonly<{
|
|
12
|
-
advisorId: string;
|
|
13
|
-
name: string;
|
|
14
|
-
}>;
|
|
15
|
-
export type AdvisorSignedRequest = {
|
|
16
|
-
method: string;
|
|
17
|
-
path: string;
|
|
18
|
-
action: AdvisorQueryMethod;
|
|
19
|
-
body: Readonly<Record<string, unknown>>;
|
|
20
|
-
};
|
|
21
|
-
export type AdvisorVerifiedContext = {
|
|
22
|
-
issuer: AdvisorCaller;
|
|
23
|
-
actor: AdvisorActor;
|
|
24
|
-
action: AdvisorQueryMethod;
|
|
25
|
-
expiresAt: number;
|
|
26
|
-
};
|
|
27
|
-
export type AdvisorVerificationConfig = {
|
|
28
|
-
audience: string;
|
|
29
|
-
environment: string;
|
|
30
|
-
maxTtlSeconds: number;
|
|
31
|
-
clockSkewSeconds: number;
|
|
32
|
-
keys: ReadonlyArray<{
|
|
33
|
-
issuer: AdvisorCaller;
|
|
34
|
-
kid: string;
|
|
35
|
-
publicKey: KeyObject;
|
|
36
|
-
}>;
|
|
37
|
-
now: () => number;
|
|
38
|
-
};
|
|
39
8
|
export declare function canonicalAdvisorJson(input: unknown): string;
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
privateKey: KeyObject;
|
|
46
|
-
ttlSeconds: number;
|
|
47
|
-
now: () => number;
|
|
48
|
-
}): (request: AdvisorSignedRequest, identity: AdvisorActor) => string;
|
|
49
|
-
export declare function createAdvisorRequestVerifier(config: AdvisorVerificationConfig): (request: AdvisorSignedRequest, assertion: string) => AdvisorVerifiedContext;
|
|
50
|
-
export type AdvisorAssertionSender = (request: Readonly<{
|
|
9
|
+
export type AdvisorTokenHeaders = Readonly<{
|
|
10
|
+
'x-belink-accessType': 'authorizationTokenInside';
|
|
11
|
+
'x-belink-authorization': string;
|
|
12
|
+
}>;
|
|
13
|
+
export type AdvisorTokenSender = (request: Readonly<{
|
|
51
14
|
method: 'POST';
|
|
52
15
|
url: string;
|
|
53
16
|
body: Readonly<Record<string, unknown>>;
|
|
54
|
-
headers:
|
|
55
|
-
'x-advisor-assertion': string;
|
|
56
|
-
}>;
|
|
17
|
+
headers: AdvisorTokenHeaders;
|
|
57
18
|
}>) => Promise<AdvisorResponseEnvelope<unknown>>;
|
|
58
|
-
export
|
|
19
|
+
export type AdvisorTokenTransportOptions = {
|
|
59
20
|
origin: string;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}): AdvisorProtectedTransport;
|
|
21
|
+
send: AdvisorTokenSender;
|
|
22
|
+
};
|
|
23
|
+
export declare function createAdvisorTokenTransport(options: AdvisorTokenTransportOptions): AdvisorProtectedTransport;
|
|
@@ -9,8 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const crypto_1 = require("crypto");
|
|
12
|
+
exports.createAdvisorTokenTransport = exports.canonicalAdvisorJson = exports.advisorActionPaths = void 0;
|
|
14
13
|
const advisorBusinessError_1 = require("./advisorBusinessError");
|
|
15
14
|
exports.advisorActionPaths = {
|
|
16
15
|
queryAdvisorShareOrderList: '/query/user/query-advisor-share-order-list',
|
|
@@ -30,27 +29,7 @@ function object(value) {
|
|
|
30
29
|
reject();
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
if (typeof value !== 'string' || !value || value.trim() !== value)
|
|
35
|
-
reject();
|
|
36
|
-
}
|
|
37
|
-
function exact(value, keys) {
|
|
38
|
-
if (Object.keys(value).sort().join(',') !== keys.sort().join(','))
|
|
39
|
-
reject();
|
|
40
|
-
}
|
|
41
|
-
function actor(value) {
|
|
42
|
-
object(value);
|
|
43
|
-
exact(value, ['advisorId', 'name']);
|
|
44
|
-
text(value.advisorId);
|
|
45
|
-
if (typeof value.name !== 'string')
|
|
46
|
-
reject();
|
|
47
|
-
return Object.freeze({ advisorId: value.advisorId, name: value.name });
|
|
48
|
-
}
|
|
49
|
-
function caller(value) {
|
|
50
|
-
if (value !== 'DistributionService' && value !== 'VitalityService')
|
|
51
|
-
reject();
|
|
52
|
-
}
|
|
53
|
-
// Protocol v1: plain JSON only, UTF-16 key ordering, no omitted/undefined values,
|
|
32
|
+
// Strict JSON snapshot: plain JSON only, UTF-16 key ordering, no omitted/undefined values,
|
|
54
33
|
// accessors, symbols, sparse arrays, cycles, non-finite numbers or unsafe integers.
|
|
55
34
|
function canonicalAdvisorJson(input) {
|
|
56
35
|
const ancestors = new Set();
|
|
@@ -94,164 +73,48 @@ function canonicalAdvisorJson(input) {
|
|
|
94
73
|
return visit(input);
|
|
95
74
|
}
|
|
96
75
|
exports.canonicalAdvisorJson = canonicalAdvisorJson;
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
function actionAllowed(issuer, action) {
|
|
101
|
-
if (!Object.prototype.hasOwnProperty.call(exports.advisorActionPaths, action))
|
|
102
|
-
reject();
|
|
103
|
-
if (action === 'queryAdvisorShareOrderList' && issuer !== 'DistributionService')
|
|
104
|
-
reject();
|
|
105
|
-
if (action === 'getAdvisorShareAdjustmentCreateFacts' && issuer !== 'VitalityService')
|
|
76
|
+
function createAdvisorTokenTransport(options) {
|
|
77
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.send) !== 'function')
|
|
106
78
|
reject();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (request.method !== 'POST' || request.path !== exports.advisorActionPaths[request.action])
|
|
111
|
-
reject();
|
|
112
|
-
object(request.body);
|
|
113
|
-
if (request.body.advisorId !== identity.advisorId)
|
|
114
|
-
reject();
|
|
115
|
-
}
|
|
116
|
-
function seconds(now) {
|
|
117
|
-
const value = now();
|
|
118
|
-
if (!Number.isSafeInteger(value) || value < 0)
|
|
119
|
-
reject();
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
function encode(value) { return value.toString('base64url'); }
|
|
123
|
-
function decode(value) {
|
|
124
|
-
if (!/^[A-Za-z0-9_-]+$/.test(value))
|
|
125
|
-
reject();
|
|
126
|
-
const result = Buffer.from(value, 'base64url');
|
|
127
|
-
if (encode(result) !== value)
|
|
128
|
-
reject();
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
function keyCheck(key, type) {
|
|
132
|
-
if (!(key instanceof crypto_1.KeyObject) || key.type !== type || key.asymmetricKeyType !== 'ed25519')
|
|
133
|
-
reject();
|
|
134
|
-
}
|
|
135
|
-
function createAdvisorRequestSigner(config) {
|
|
136
|
-
caller(config === null || config === void 0 ? void 0 : config.issuer);
|
|
137
|
-
text(config.kid);
|
|
138
|
-
text(config.audience);
|
|
139
|
-
text(config.environment);
|
|
140
|
-
keyCheck(config.privateKey, 'private');
|
|
141
|
-
if (!Number.isSafeInteger(config.ttlSeconds) || config.ttlSeconds < 1 || typeof config.now !== 'function')
|
|
142
|
-
reject();
|
|
143
|
-
// Capture all configuration and key material before any asynchronous sender runs.
|
|
144
|
-
const { issuer, kid, audience, environment, ttlSeconds, now } = config;
|
|
145
|
-
const key = (0, crypto_1.createPrivateKey)({ key: config.privateKey.export({ format: 'der', type: 'pkcs8' }), format: 'der', type: 'pkcs8' });
|
|
146
|
-
return (request, identity) => {
|
|
147
|
-
const identitySnapshot = actor(identity);
|
|
148
|
-
requestCheck(request, issuer, identitySnapshot);
|
|
149
|
-
const iat = seconds(now);
|
|
150
|
-
const exp = iat + ttlSeconds;
|
|
151
|
-
if (!Number.isSafeInteger(exp))
|
|
152
|
-
reject();
|
|
153
|
-
const payload = {
|
|
154
|
-
version: 1, kid, issuer, audience, environment, actor: identitySnapshot,
|
|
155
|
-
action: request.action, method: request.method, path: request.path,
|
|
156
|
-
bodyDigest: digest(request.body), iat, exp,
|
|
157
|
-
};
|
|
158
|
-
const value = `v1.${encode(Buffer.from(canonicalAdvisorJson(payload)))}`;
|
|
159
|
-
return `${value}.${encode((0, crypto_1.sign)(null, Buffer.from(`pos:advisor-request:${value}`), key))}`;
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
exports.createAdvisorRequestSigner = createAdvisorRequestSigner;
|
|
163
|
-
function createAdvisorRequestVerifier(config) {
|
|
164
|
-
text(config === null || config === void 0 ? void 0 : config.audience);
|
|
165
|
-
text(config.environment);
|
|
166
|
-
if (!Number.isSafeInteger(config.maxTtlSeconds) || config.maxTtlSeconds < 1 ||
|
|
167
|
-
!Number.isSafeInteger(config.clockSkewSeconds) || config.clockSkewSeconds < 0 ||
|
|
168
|
-
typeof config.now !== 'function' || !Array.isArray(config.keys) || !config.keys.length)
|
|
169
|
-
reject();
|
|
170
|
-
const { audience, environment, maxTtlSeconds, clockSkewSeconds, now } = config;
|
|
171
|
-
const trusted = new Map();
|
|
172
|
-
for (const entry of config.keys) {
|
|
173
|
-
caller(entry === null || entry === void 0 ? void 0 : entry.issuer);
|
|
174
|
-
text(entry.kid);
|
|
175
|
-
keyCheck(entry.publicKey, 'public');
|
|
176
|
-
const key = JSON.stringify([entry.issuer, entry.kid]);
|
|
177
|
-
if (trusted.has(key))
|
|
178
|
-
reject();
|
|
179
|
-
trusted.set(key, (0, crypto_1.createPublicKey)({ key: entry.publicKey.export({ format: 'der', type: 'spki' }), format: 'der', type: 'spki' }));
|
|
79
|
+
let endpoint;
|
|
80
|
+
try {
|
|
81
|
+
endpoint = new URL(options.origin);
|
|
180
82
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const parts = assertion.split('.');
|
|
186
|
-
if (parts.length !== 3 || parts[0] !== 'v1')
|
|
187
|
-
reject();
|
|
188
|
-
const serialized = decode(parts[1]).toString('utf8');
|
|
189
|
-
const claim = JSON.parse(serialized);
|
|
190
|
-
object(claim);
|
|
191
|
-
exact(claim, ['version', 'kid', 'issuer', 'audience', 'environment', 'actor', 'action', 'method', 'path', 'bodyDigest', 'iat', 'exp']);
|
|
192
|
-
if (canonicalAdvisorJson(claim) !== serialized)
|
|
193
|
-
reject();
|
|
194
|
-
caller(claim.issuer);
|
|
195
|
-
text(claim.kid);
|
|
196
|
-
const key = trusted.get(JSON.stringify([claim.issuer, claim.kid]));
|
|
197
|
-
if (!key || !(0, crypto_1.verify)(null, Buffer.from(`pos:advisor-request:${parts[0]}.${parts[1]}`), key, decode(parts[2])))
|
|
198
|
-
reject();
|
|
199
|
-
if (claim.version !== 1 || claim.audience !== audience || claim.environment !== environment)
|
|
200
|
-
reject();
|
|
201
|
-
const current = seconds(now);
|
|
202
|
-
if (typeof claim.iat !== 'number' || typeof claim.exp !== 'number' ||
|
|
203
|
-
!Number.isSafeInteger(claim.iat) || !Number.isSafeInteger(claim.exp) || claim.iat < 0 ||
|
|
204
|
-
claim.exp <= claim.iat || claim.exp - claim.iat > maxTtlSeconds ||
|
|
205
|
-
claim.iat > current + clockSkewSeconds || claim.exp <= current - clockSkewSeconds)
|
|
206
|
-
reject();
|
|
207
|
-
const identity = actor(claim.actor);
|
|
208
|
-
requestCheck(request, claim.issuer, identity);
|
|
209
|
-
if (claim.action !== request.action || claim.method !== request.method || claim.path !== request.path ||
|
|
210
|
-
claim.bodyDigest !== digest(request.body))
|
|
211
|
-
reject();
|
|
212
|
-
return Object.freeze({ issuer: claim.issuer, actor: identity, action: request.action, expiresAt: claim.exp });
|
|
213
|
-
}
|
|
214
|
-
catch (_a) {
|
|
215
|
-
return reject();
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
exports.createAdvisorRequestVerifier = createAdvisorRequestVerifier;
|
|
220
|
-
function createSignedAdvisorTransport(options) {
|
|
221
|
-
if (typeof (options === null || options === void 0 ? void 0 : options.signer) !== 'function' || typeof options.send !== 'function')
|
|
222
|
-
reject();
|
|
223
|
-
const endpoint = new URL(options.origin);
|
|
224
|
-
if (!['https:', 'http:'].includes(endpoint.protocol) || endpoint.username || endpoint.password ||
|
|
83
|
+
catch (_a) {
|
|
84
|
+
return reject();
|
|
85
|
+
}
|
|
86
|
+
if (endpoint.protocol !== 'https:' || endpoint.username || endpoint.password ||
|
|
225
87
|
endpoint.search || endpoint.hash || endpoint.pathname !== '/')
|
|
226
88
|
reject();
|
|
227
89
|
const origin = endpoint.origin;
|
|
228
|
-
const
|
|
229
|
-
const { signer, send } = options;
|
|
90
|
+
const { send } = options;
|
|
230
91
|
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
92
|
+
const path = Object.prototype.hasOwnProperty.call(exports.advisorActionPaths, request.action)
|
|
93
|
+
? exports.advisorActionPaths[request.action] : undefined;
|
|
94
|
+
// Compare raw input before parsing: do not normalize dot segments or escapes.
|
|
95
|
+
if (request.method !== 'POST' || typeof path !== 'string' ||
|
|
96
|
+
(request.url !== path && request.url !== origin + path))
|
|
236
97
|
reject();
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
98
|
+
// Read on every invocation so Shield rotation is visible without recreating services.
|
|
99
|
+
const token = process.env.authorizationTokenInside;
|
|
100
|
+
if (typeof token !== 'string' || !token || token.trim() !== token || /[\r\n]/.test(token))
|
|
240
101
|
reject();
|
|
241
|
-
|
|
102
|
+
object(request.body);
|
|
242
103
|
const body = JSON.parse(canonicalAdvisorJson(request.body));
|
|
243
|
-
const assertion = signer({ method: request.method, path: url.pathname, action: request.action, body }, identity);
|
|
244
104
|
try {
|
|
245
|
-
return yield send(Object.freeze({ method: 'POST', url:
|
|
246
|
-
headers: Object.freeze({ 'x-
|
|
105
|
+
return yield send(Object.freeze({ method: 'POST', url: origin + path, body: deepFreeze(body),
|
|
106
|
+
headers: Object.freeze({ 'x-belink-accessType': 'authorizationTokenInside',
|
|
107
|
+
'x-belink-authorization': token }) }));
|
|
247
108
|
}
|
|
248
109
|
catch (error) {
|
|
249
|
-
|
|
250
|
-
|
|
110
|
+
const rejection = (0, advisorBusinessError_1.copyAdvisorBusinessError)(error);
|
|
111
|
+
if (rejection)
|
|
112
|
+
throw rejection;
|
|
113
|
+
throw new Error('ADVISOR_PROTECTED_TRANSPORT_FAILED');
|
|
251
114
|
}
|
|
252
115
|
});
|
|
253
116
|
}
|
|
254
|
-
exports.
|
|
117
|
+
exports.createAdvisorTokenTransport = createAdvisorTokenTransport;
|
|
255
118
|
function deepFreeze(value) {
|
|
256
119
|
if (value && typeof value === 'object') {
|
|
257
120
|
for (const child of Object.values(value))
|
|
@@ -70,11 +70,8 @@ export type AdvisorResponseEnvelope<T> = {
|
|
|
70
70
|
requestId?: string;
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* sanitize errors/logs. createSignedAdvisorTransport implements protocol v1;
|
|
77
|
-
* real sender, trust configuration and protected POS routes still require assembly.
|
|
78
|
-
* A shared inside token or a client-supplied caller name is not sufficient.
|
|
73
|
+
* Explicit transport integration boundary. createAdvisorTokenTransport reads the
|
|
74
|
+
* current Shield authorizationTokenInside on every call; caller/actor authorization
|
|
75
|
+
* remains a server responsibility. Custom senders must sanitize errors and never retry.
|
|
79
76
|
*/
|
|
80
77
|
export type AdvisorProtectedTransport = (request: AdvisorProtectedRequest) => Promise<AdvisorResponseEnvelope<unknown>>;
|