@blocklet/payment-vendor 1.20.6
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 +935 -0
- package/examples/usage-example.ts +321 -0
- package/lib/auth.d.ts +58 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +138 -0
- package/lib/auth.js.map +1 -0
- package/lib/index.d.ts +70 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +79 -0
- package/lib/index.js.map +1 -0
- package/lib/logger.d.ts +11 -0
- package/lib/logger.d.ts.map +1 -0
- package/lib/logger.js +13 -0
- package/lib/logger.js.map +1 -0
- package/lib/middleware.d.ts +31 -0
- package/lib/middleware.d.ts.map +1 -0
- package/lib/middleware.js +274 -0
- package/lib/middleware.js.map +1 -0
- package/lib/types.d.ts +114 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/whitelist.d.ts +26 -0
- package/lib/whitelist.d.ts.map +1 -0
- package/lib/whitelist.js +90 -0
- package/lib/whitelist.js.map +1 -0
- package/package.json +86 -0
package/lib/logger.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Logger {
|
|
2
|
+
debug: (...args: any[]) => void;
|
|
3
|
+
info: (...args: any[]) => void;
|
|
4
|
+
error: (...args: any[]) => void;
|
|
5
|
+
warn: (...args: any[]) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const logger: Logger;
|
|
8
|
+
export default logger;
|
|
9
|
+
declare const setupAccessLogger: any;
|
|
10
|
+
export { setupAccessLogger };
|
|
11
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,UAAU,MAAM;IACd,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC/B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAChC;AAOD,QAAA,MAAM,MAAM,QAAqB,CAAC;AAElC,eAAe,MAAM,CAAC;AAEtB,QAAA,MAAQ,iBAAiB,KAAiB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupAccessLogger = void 0;
|
|
4
|
+
const createLogger = require('@blocklet/logger');
|
|
5
|
+
const init = (label) => {
|
|
6
|
+
const instance = createLogger(label || '');
|
|
7
|
+
return instance;
|
|
8
|
+
};
|
|
9
|
+
const logger = init('vendor-sdk');
|
|
10
|
+
exports.default = logger;
|
|
11
|
+
const { setupAccessLogger } = createLogger;
|
|
12
|
+
exports.setupAccessLogger = setupAccessLogger;
|
|
13
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AASjD,MAAM,IAAI,GAAG,CAAC,KAAa,EAAU,EAAE;IACrC,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;AAElC,kBAAe,MAAM,CAAC;AAEtB,MAAM,EAAE,iBAAiB,EAAE,GAAG,YAAY,CAAC;AAClC,8CAAiB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
+
import type { AuthMiddlewareOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* app.use('/api/vendor', ensureVendorAuth());
|
|
6
|
+
*/
|
|
7
|
+
export declare function ensureVendorAuth(options?: AuthMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
8
|
+
/**
|
|
9
|
+
* @example
|
|
10
|
+
* app.get('/health', healthCheck());
|
|
11
|
+
* app.get('/vendor/health', healthCheck({ service: 'launcher-vendor' }));
|
|
12
|
+
*/
|
|
13
|
+
export declare function healthCheck(options?: {
|
|
14
|
+
service?: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
includeDetails?: boolean;
|
|
17
|
+
}): (req: Request, res: Response) => void;
|
|
18
|
+
/**
|
|
19
|
+
* @example
|
|
20
|
+
* app.use(errorHandler());
|
|
21
|
+
*/
|
|
22
|
+
export declare function errorHandler(): (error: any, req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
23
|
+
/**
|
|
24
|
+
* @example
|
|
25
|
+
* app.use('/api/vendor', rateLimiter({
|
|
26
|
+
* windowMs: 60000, // 1分钟
|
|
27
|
+
* defaultLimit: 100
|
|
28
|
+
* }));
|
|
29
|
+
*/
|
|
30
|
+
export declare function rateLimiter(): (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
31
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI/D,OAAO,KAAK,EAAE,qBAAqB,EAA4C,MAAM,SAAS,CAAC;AAE/F;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,qBAA0B,SAC/C,OAAO,OAAO,QAAQ,QAAQ,YAAY,wDAkI9D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CACrB,SAEO,OAAO,OAAO,QAAQ,UAkCpC;AAED;;;GAGG;AACH,wBAAgB,YAAY,YACX,GAAG,OAAO,OAAO,OAAO,QAAQ,QAAQ,YAAY,+CAyCpE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,UAKZ,OAAO,OAAO,QAAQ,QAAQ,YAAY,+CAgDxD"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable import/prefer-default-export */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ensureVendorAuth = ensureVendorAuth;
|
|
8
|
+
exports.healthCheck = healthCheck;
|
|
9
|
+
exports.errorHandler = errorHandler;
|
|
10
|
+
exports.rateLimiter = rateLimiter;
|
|
11
|
+
const auth_1 = require("./auth");
|
|
12
|
+
const whitelist_1 = require("./whitelist");
|
|
13
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
14
|
+
/**
|
|
15
|
+
* @example
|
|
16
|
+
* app.use('/api/vendor', ensureVendorAuth());
|
|
17
|
+
*/
|
|
18
|
+
function ensureVendorAuth(options = {}) {
|
|
19
|
+
return async (req, res, next) => {
|
|
20
|
+
try {
|
|
21
|
+
// 1. check the header
|
|
22
|
+
const sig = req.headers['x-broker-sig'];
|
|
23
|
+
const brokerDid = req.headers['x-broker-did'];
|
|
24
|
+
if (!sig) {
|
|
25
|
+
// Security: Log missing authentication signature
|
|
26
|
+
logger_1.default.warn('Authentication failed: Missing signature header', { url: req.url });
|
|
27
|
+
return res.status(400).json({
|
|
28
|
+
error: 'Server signature is required',
|
|
29
|
+
code: 'MISSING_SIGNATURE',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (!brokerDid) {
|
|
33
|
+
// Security: Log missing broker identification
|
|
34
|
+
logger_1.default.warn('Authentication failed: Missing broker DID header', { url: req.url });
|
|
35
|
+
return res.status(400).json({
|
|
36
|
+
error: 'Broker DID is required',
|
|
37
|
+
code: 'MISSING_BROKER_DID',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// 2. analysis the request body
|
|
41
|
+
const isGetRequest = req.method === 'GET';
|
|
42
|
+
const requestBody = isGetRequest ? req.query : req.body;
|
|
43
|
+
if (!requestBody || typeof requestBody !== 'object') {
|
|
44
|
+
return res.status(400).json({
|
|
45
|
+
error: 'Valid request body is required',
|
|
46
|
+
code: 'INVALID_REQUEST_BODY',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (!isGetRequest) {
|
|
50
|
+
// 3. check required field
|
|
51
|
+
const requiredFields = ['userInfo'];
|
|
52
|
+
const missingFields = requiredFields.filter((field) => !requestBody[field]);
|
|
53
|
+
if (missingFields.length > 0) {
|
|
54
|
+
return res.status(400).json({
|
|
55
|
+
error: `Missing required fields: ${missingFields.join(', ')}`,
|
|
56
|
+
code: 'MISSING_REQUIRED_FIELDS',
|
|
57
|
+
details: { missingFields },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// 4. check timestamp (optional)
|
|
61
|
+
if (!options.skipTimestamp && requestBody.timestamp) {
|
|
62
|
+
const maxAge = options.maxAge || 300000; // 默认5分钟
|
|
63
|
+
if (!auth_1.VendorAuth.validateTimestamp(requestBody.timestamp, maxAge)) {
|
|
64
|
+
// Security: Log timestamp validation failure for replay attack detection
|
|
65
|
+
logger_1.default.warn('Authentication failed: Request timestamp expired', {
|
|
66
|
+
url: req.url,
|
|
67
|
+
age: Date.now() - requestBody.timestamp,
|
|
68
|
+
maxAge,
|
|
69
|
+
});
|
|
70
|
+
return res.status(401).json({
|
|
71
|
+
error: 'Request timestamp expired',
|
|
72
|
+
code: 'TIMESTAMP_EXPIRED',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// 5. check the whitelist
|
|
78
|
+
const broker = await whitelist_1.WhitelistManager.getBrokerByPublicKey(brokerDid);
|
|
79
|
+
if (!broker) {
|
|
80
|
+
// Security: Log unauthorized broker access attempt
|
|
81
|
+
logger_1.default.warn('Authorization failed: Broker not in whitelist', {
|
|
82
|
+
url: req.url,
|
|
83
|
+
brokerDid: `${brokerDid.substring(0, 10)}...`,
|
|
84
|
+
});
|
|
85
|
+
return res.status(403).json({
|
|
86
|
+
error: 'Broker not in whitelist',
|
|
87
|
+
code: 'BROKER_NOT_ALLOWED',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// 6. Verify the signature
|
|
91
|
+
const signedRequest = { ...requestBody, signature: sig };
|
|
92
|
+
const verified = await auth_1.VendorAuth.verifyRequest(signedRequest, broker.publicKey);
|
|
93
|
+
if (!verified) {
|
|
94
|
+
// Security: Log signature verification failure
|
|
95
|
+
logger_1.default.warn('Authentication failed: Invalid request signature', {
|
|
96
|
+
url: req.url,
|
|
97
|
+
brokerId: broker.id,
|
|
98
|
+
path: requestBody.path,
|
|
99
|
+
});
|
|
100
|
+
return res.status(401).json({
|
|
101
|
+
error: 'Invalid request signature',
|
|
102
|
+
code: 'INVALID_SIGNATURE',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// 7. custom validator (optional)
|
|
106
|
+
if (options.customValidator) {
|
|
107
|
+
const customValid = await options.customValidator(req);
|
|
108
|
+
if (!customValid) {
|
|
109
|
+
return res.status(403).json({
|
|
110
|
+
error: 'Custom validation failed',
|
|
111
|
+
code: 'CUSTOM_VALIDATION_FAILED',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// 8. check success, set request info
|
|
116
|
+
req.broker = broker;
|
|
117
|
+
req.vendorRequest = signedRequest;
|
|
118
|
+
// 8. check success, continue to process the request
|
|
119
|
+
return next();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// Critical: Log authentication middleware errors
|
|
123
|
+
logger_1.default.error('Authentication middleware error', {
|
|
124
|
+
url: req.url,
|
|
125
|
+
error: error.message,
|
|
126
|
+
stack: error.stack,
|
|
127
|
+
});
|
|
128
|
+
return res.status(500).json({
|
|
129
|
+
error: 'Authentication failed',
|
|
130
|
+
code: 'AUTHENTICATION_ERROR',
|
|
131
|
+
details: process.env.NODE_ENV === 'development' ? error.message : undefined,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @example
|
|
138
|
+
* app.get('/health', healthCheck());
|
|
139
|
+
* app.get('/vendor/health', healthCheck({ service: 'launcher-vendor' }));
|
|
140
|
+
*/
|
|
141
|
+
function healthCheck(options = {}) {
|
|
142
|
+
return (req, res) => {
|
|
143
|
+
try {
|
|
144
|
+
const response = {
|
|
145
|
+
status: 'healthy',
|
|
146
|
+
timestamp: new Date().toISOString(),
|
|
147
|
+
service: options.service || 'vendor-api',
|
|
148
|
+
};
|
|
149
|
+
if (options.version) {
|
|
150
|
+
response.version = options.version;
|
|
151
|
+
}
|
|
152
|
+
if (options.includeDetails) {
|
|
153
|
+
response.details = {
|
|
154
|
+
uptime: process.uptime(),
|
|
155
|
+
memory: process.memoryUsage(),
|
|
156
|
+
nodejs: process.version,
|
|
157
|
+
platform: process.platform,
|
|
158
|
+
pid: process.pid,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
res.json(response);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
// Error: Log health check failures
|
|
165
|
+
logger_1.default.error('Health check failed', { url: req.url, error: error.message });
|
|
166
|
+
res.status(500).json({
|
|
167
|
+
status: 'unhealthy',
|
|
168
|
+
timestamp: new Date().toISOString(),
|
|
169
|
+
service: options.service || 'vendor-api',
|
|
170
|
+
error: error.message,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* @example
|
|
177
|
+
* app.use(errorHandler());
|
|
178
|
+
*/
|
|
179
|
+
function errorHandler() {
|
|
180
|
+
return (error, req, res, next) => {
|
|
181
|
+
// Critical: Log unhandled errors in vendor API
|
|
182
|
+
logger_1.default.error('Unhandled error in vendor API', {
|
|
183
|
+
url: req.url,
|
|
184
|
+
method: req.method,
|
|
185
|
+
error: error.message,
|
|
186
|
+
stack: error.stack,
|
|
187
|
+
brokerId: req.broker?.id,
|
|
188
|
+
});
|
|
189
|
+
if (res.headersSent) {
|
|
190
|
+
return next(error);
|
|
191
|
+
}
|
|
192
|
+
let statusCode = 500;
|
|
193
|
+
let errorCode = 'INTERNAL_ERROR';
|
|
194
|
+
if (error.name === 'ValidationError') {
|
|
195
|
+
statusCode = 400;
|
|
196
|
+
errorCode = 'VALIDATION_ERROR';
|
|
197
|
+
}
|
|
198
|
+
else if (error.name === 'UnauthorizedError') {
|
|
199
|
+
statusCode = 401;
|
|
200
|
+
errorCode = 'UNAUTHORIZED';
|
|
201
|
+
}
|
|
202
|
+
else if (error.name === 'ForbiddenError') {
|
|
203
|
+
statusCode = 403;
|
|
204
|
+
errorCode = 'FORBIDDEN';
|
|
205
|
+
}
|
|
206
|
+
else if (error.name === 'NotFoundError') {
|
|
207
|
+
statusCode = 404;
|
|
208
|
+
errorCode = 'NOT_FOUND';
|
|
209
|
+
}
|
|
210
|
+
return res.status(statusCode).json({
|
|
211
|
+
success: false,
|
|
212
|
+
path: req.vendorRequest?.path,
|
|
213
|
+
message: 'Internal server error',
|
|
214
|
+
error: {
|
|
215
|
+
code: errorCode,
|
|
216
|
+
details: process.env.NODE_ENV === 'development' ? error.message : 'An error occurred',
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @example
|
|
223
|
+
* app.use('/api/vendor', rateLimiter({
|
|
224
|
+
* windowMs: 60000, // 1分钟
|
|
225
|
+
* defaultLimit: 100
|
|
226
|
+
* }));
|
|
227
|
+
*/
|
|
228
|
+
function rateLimiter() {
|
|
229
|
+
const windowMs = parseInt(process.env.RATE_LIMIT_WINDOW_MS || '60000', 10);
|
|
230
|
+
const defaultLimit = parseInt(process.env.RATE_LIMIT_DEFAULT_LIMIT || '100', 10);
|
|
231
|
+
const requestCounts = new Map();
|
|
232
|
+
return (req, res, next) => {
|
|
233
|
+
// only for authenticated requests
|
|
234
|
+
if (!req.broker) {
|
|
235
|
+
return next();
|
|
236
|
+
}
|
|
237
|
+
const brokerId = req.broker.id;
|
|
238
|
+
const now = Date.now();
|
|
239
|
+
const limit = req.broker.rateLimit || defaultLimit;
|
|
240
|
+
// get or create counter
|
|
241
|
+
let counter = requestCounts.get(brokerId);
|
|
242
|
+
if (!counter || now > counter.resetTime) {
|
|
243
|
+
counter = { count: 0, resetTime: now + windowMs };
|
|
244
|
+
requestCounts.set(brokerId, counter);
|
|
245
|
+
}
|
|
246
|
+
// check if exceed the limit
|
|
247
|
+
if (counter.count >= limit) {
|
|
248
|
+
// Security: Log rate limit violations
|
|
249
|
+
logger_1.default.warn('Rate limit exceeded', {
|
|
250
|
+
url: req.url,
|
|
251
|
+
brokerId,
|
|
252
|
+
count: counter.count,
|
|
253
|
+
limit,
|
|
254
|
+
});
|
|
255
|
+
return res.status(429).json({
|
|
256
|
+
error: 'Rate limit exceeded',
|
|
257
|
+
code: 'RATE_LIMIT_EXCEEDED',
|
|
258
|
+
details: {
|
|
259
|
+
limit,
|
|
260
|
+
windowMs,
|
|
261
|
+
resetTime: counter.resetTime,
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
counter.count++;
|
|
266
|
+
res.set({
|
|
267
|
+
'X-RateLimit-Limit': limit.toString(),
|
|
268
|
+
'X-RateLimit-Remaining': (limit - counter.count).toString(),
|
|
269
|
+
'X-RateLimit-Reset': new Date(counter.resetTime).toISOString(),
|
|
270
|
+
});
|
|
271
|
+
return next();
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;;;AAYjD,4CAmIC;AAOD,kCAyCC;AAMD,oCA0CC;AASD,kCAqDC;AA1SD,iCAAoC;AACpC,2CAA+C;AAC/C,sDAA8B;AAG9B;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,UAAiC,EAAE;IAClE,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAC/D,IAAI,CAAC;YACH,sBAAsB;YACtB,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,CAAW,CAAC;YAClD,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,CAAW,CAAC;YAExD,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,iDAAiD;gBACjD,gBAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBACjF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBAC1B,KAAK,EAAE,8BAA8B;oBACrC,IAAI,EAAE,mBAAmB;iBAC1B,CAAC,CAAC;YACL,CAAC;YAED,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,8CAA8C;gBAC9C,gBAAM,CAAC,IAAI,CAAC,kDAAkD,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBAClF,OAAO,GAAG,CAA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EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;QAED,4BAA4B;QAC5B,IAAI,OAAO,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;YAC3B,sCAAsC;YACtC,gBAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE;gBACjC,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,QAAQ;gBACR,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,KAAK;aACN,CAAC,CAAC;YAEH,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,KAAK,EAAE,qBAAqB;gBAC5B,IAAI,EAAE,qBAAqB;gBAC3B,OAAO,EAAE;oBACP,KAAK;oBACL,QAAQ;oBACR,SAAS,EAAE,OAAO,CAAC,SAAS;iBAC7B;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,CAAC,KAAK,EAAE,CAAC;QAEhB,GAAG,CAAC,GAAG,CAAC;YACN,mBAAmB,EAAE,KAAK,CAAC,QAAQ,EAAE;YACrC,uBAAuB,EAAE,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;YAC3D,mBAAmB,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;SAC/D,CAAC,CAAC;QAEH,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type VendorOrderStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled' | 'return_requested';
|
|
2
|
+
export type BrokerStatus = 'active' | 'inactive';
|
|
3
|
+
export interface DeliveryRequest {
|
|
4
|
+
description: string;
|
|
5
|
+
userInfo: {
|
|
6
|
+
userDid: string;
|
|
7
|
+
email: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
};
|
|
10
|
+
deliveryParams: {
|
|
11
|
+
instanceName: string;
|
|
12
|
+
blockletMetaUrl?: string;
|
|
13
|
+
productId?: string;
|
|
14
|
+
customParams?: Record<string, any>;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export type VendorRequest = Record<string, any>;
|
|
18
|
+
export interface VendorSignedRequest extends VendorRequest {
|
|
19
|
+
signature: string;
|
|
20
|
+
}
|
|
21
|
+
export interface VendorResponse {
|
|
22
|
+
success: boolean;
|
|
23
|
+
orderId: string;
|
|
24
|
+
status?: VendorOrderStatus;
|
|
25
|
+
message?: string;
|
|
26
|
+
data?: {
|
|
27
|
+
fulfillmentId?: string;
|
|
28
|
+
serviceUrl?: string;
|
|
29
|
+
instanceId?: string;
|
|
30
|
+
progress?: number;
|
|
31
|
+
estimatedTime?: number;
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
};
|
|
34
|
+
error?: {
|
|
35
|
+
code: string;
|
|
36
|
+
details: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface BrokerConfig {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
publicKey: string;
|
|
43
|
+
status: BrokerStatus;
|
|
44
|
+
rateLimit?: number;
|
|
45
|
+
createdAt?: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface SigningOptions {
|
|
49
|
+
brokerSk: string;
|
|
50
|
+
brokerPk: string;
|
|
51
|
+
}
|
|
52
|
+
export interface AuthMiddlewareOptions {
|
|
53
|
+
skipTimestamp?: boolean;
|
|
54
|
+
maxAge?: number;
|
|
55
|
+
customValidator?: (req: any) => Promise<boolean>;
|
|
56
|
+
}
|
|
57
|
+
export interface VendorOrder {
|
|
58
|
+
id: string;
|
|
59
|
+
orderId: string;
|
|
60
|
+
brokerId: string;
|
|
61
|
+
status: VendorOrderStatus;
|
|
62
|
+
params: Record<string, any>;
|
|
63
|
+
result?: any;
|
|
64
|
+
error?: {
|
|
65
|
+
code: string;
|
|
66
|
+
message: string;
|
|
67
|
+
details?: any;
|
|
68
|
+
};
|
|
69
|
+
retryCount?: number;
|
|
70
|
+
maxRetries?: number;
|
|
71
|
+
createdAt: Date;
|
|
72
|
+
updatedAt: Date;
|
|
73
|
+
completedAt?: Date;
|
|
74
|
+
failedAt?: Date;
|
|
75
|
+
}
|
|
76
|
+
export interface VendorHooks {
|
|
77
|
+
onOrderCreated?: (order: VendorOrder) => Promise<void>;
|
|
78
|
+
onProcessOrder: (order: VendorOrder) => Promise<any>;
|
|
79
|
+
onOrderCompleted?: (order: VendorOrder, result: any) => Promise<void>;
|
|
80
|
+
onOrderFailed?: (order: VendorOrder, error: Error) => Promise<void>;
|
|
81
|
+
onOrderRetry?: (order: VendorOrder, retryCount: number) => Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
export interface VendorStorage {
|
|
84
|
+
createOrder(orderData: Partial<VendorOrder>): Promise<VendorOrder>;
|
|
85
|
+
getOrder(orderId: string): Promise<VendorOrder | null>;
|
|
86
|
+
updateOrderStatus(orderId: string, status: VendorOrderStatus, data?: any): Promise<void>;
|
|
87
|
+
updateOrder(orderId: string, updates: Partial<VendorOrder>): Promise<void>;
|
|
88
|
+
listOrders(filters?: {
|
|
89
|
+
brokerId?: string;
|
|
90
|
+
status?: VendorOrderStatus;
|
|
91
|
+
limit?: number;
|
|
92
|
+
offset?: number;
|
|
93
|
+
}): Promise<VendorOrder[]>;
|
|
94
|
+
}
|
|
95
|
+
declare global {
|
|
96
|
+
namespace Express {
|
|
97
|
+
interface Request {
|
|
98
|
+
broker?: BrokerConfig;
|
|
99
|
+
vendorRequest?: VendorSignedRequest;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export type CreateOrderParams = Pick<VendorOrder, 'orderId' | 'brokerId' | 'params'> & {
|
|
104
|
+
maxRetries?: number;
|
|
105
|
+
};
|
|
106
|
+
export type UpdateOrderParams = Partial<Pick<VendorOrder, 'status' | 'result' | 'error' | 'retryCount'>>;
|
|
107
|
+
export interface HealthCheckResponse {
|
|
108
|
+
status: 'healthy' | 'unhealthy';
|
|
109
|
+
timestamp: string;
|
|
110
|
+
service: string;
|
|
111
|
+
version?: string;
|
|
112
|
+
details?: Record<string, any>;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,kBAAkB,CAAC;AAErH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEjD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE;QACR,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,cAAc,EAAE;QACd,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACpC,CAAC;CACH;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEhD,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACxD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE;QACL,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MA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AAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CAC5B;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,MAAM,CAAC,EAAE,YAAY,CAAC;YACtB,aAAa,CAAC,EAAE,mBAAmB,CAAC;SACrC;KACF;CACF;AAED,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC,GAAG;IACrF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC;AAEzG,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BrokerConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @example
|
|
4
|
+
* WhitelistManager.setBrokers([{ id: 'payment-kit', name: 'Payment Kit', publicKey: '...', status: 'active' }]);
|
|
5
|
+
* WhitelistManager.setBrokers(() => fetchBrokersFromAPI());
|
|
6
|
+
* const broker = await WhitelistManager.getBroker('payment-kit');
|
|
7
|
+
*/
|
|
8
|
+
export declare class WhitelistManager {
|
|
9
|
+
private static brokers;
|
|
10
|
+
private static brokerGetter?;
|
|
11
|
+
/**
|
|
12
|
+
* @example
|
|
13
|
+
* VendorSDK.setBrokers([{ id: 'payment-kit', ... }]);
|
|
14
|
+
* VendorSDK.setBrokers(() => parseMyConfig());
|
|
15
|
+
*/
|
|
16
|
+
static setBrokers(brokersOrGetter: BrokerConfig[] | (() => BrokerConfig[] | Promise<BrokerConfig[]>)): void;
|
|
17
|
+
static getWhitelist(): Promise<BrokerConfig[]>;
|
|
18
|
+
static getActiveBrokers(): Promise<BrokerConfig[]>;
|
|
19
|
+
static clearBrokers(): void;
|
|
20
|
+
private static validateBrokers;
|
|
21
|
+
static getBroker(brokerId: string): Promise<BrokerConfig | null>;
|
|
22
|
+
static getBrokerByPublicKey(brokerPublicKey: string): Promise<BrokerConfig | null>;
|
|
23
|
+
static checkBrokerPermission(brokerId: string): Promise<boolean>;
|
|
24
|
+
static listActiveBrokers(): Promise<BrokerConfig[]>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=whitelist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whitelist.d.ts","sourceRoot":"","sources":["../src/whitelist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAC,OAAO,CAAsB;IAE5C,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAiD;IAE7E;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,GAAG,IAAI;WAqB9F,YAAY,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;WAcvC,gBAAgB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAKxD,MAAM,CAAC,YAAY,IAAI,IAAI;IAI3B,OAAO,CAAC,MAAM,CAAC,eAAe;WAgBjB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;WAMzD,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;WAM3E,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOtE,MAAM,CAAC,iBAAiB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;CAGpD"}
|
package/lib/whitelist.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhitelistManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* WhitelistManager.setBrokers([{ id: 'payment-kit', name: 'Payment Kit', publicKey: '...', status: 'active' }]);
|
|
7
|
+
* WhitelistManager.setBrokers(() => fetchBrokersFromAPI());
|
|
8
|
+
* const broker = await WhitelistManager.getBroker('payment-kit');
|
|
9
|
+
*/
|
|
10
|
+
class WhitelistManager {
|
|
11
|
+
/**
|
|
12
|
+
* @example
|
|
13
|
+
* VendorSDK.setBrokers([{ id: 'payment-kit', ... }]);
|
|
14
|
+
* VendorSDK.setBrokers(() => parseMyConfig());
|
|
15
|
+
*/
|
|
16
|
+
static setBrokers(brokersOrGetter) {
|
|
17
|
+
if (!brokersOrGetter) {
|
|
18
|
+
this.brokers = [];
|
|
19
|
+
this.brokerGetter = undefined;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (typeof brokersOrGetter === 'function') {
|
|
23
|
+
this.brokerGetter = brokersOrGetter;
|
|
24
|
+
this.brokers = [];
|
|
25
|
+
}
|
|
26
|
+
else if (Array.isArray(brokersOrGetter)) {
|
|
27
|
+
this.validateBrokers(brokersOrGetter);
|
|
28
|
+
this.brokers = brokersOrGetter;
|
|
29
|
+
this.brokerGetter = undefined;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error(`Invalid parameter type for setBrokers. Expected array or function, got: ${typeof brokersOrGetter}. Value: ${JSON.stringify(brokersOrGetter)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
static async getWhitelist() {
|
|
36
|
+
if (this.brokerGetter) {
|
|
37
|
+
try {
|
|
38
|
+
const brokers = await this.brokerGetter();
|
|
39
|
+
this.validateBrokers(brokers);
|
|
40
|
+
return brokers;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return this.brokers || [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return this.brokers || [];
|
|
47
|
+
}
|
|
48
|
+
static async getActiveBrokers() {
|
|
49
|
+
const whitelist = await this.getWhitelist();
|
|
50
|
+
return whitelist.filter((item) => item.status === 'active');
|
|
51
|
+
}
|
|
52
|
+
static clearBrokers() {
|
|
53
|
+
this.brokers = [];
|
|
54
|
+
}
|
|
55
|
+
static validateBrokers(brokers) {
|
|
56
|
+
if (!Array.isArray(brokers)) {
|
|
57
|
+
throw new Error('Brokers must be an array');
|
|
58
|
+
}
|
|
59
|
+
for (const config of brokers) {
|
|
60
|
+
if (!config.id || !config.name || !config.publicKey) {
|
|
61
|
+
throw new Error('Invalid broker: missing required fields (id, name, publicKey)');
|
|
62
|
+
}
|
|
63
|
+
if (!['active', 'inactive'].includes(config.status)) {
|
|
64
|
+
throw new Error('Invalid broker: status must be "active" or "inactive"');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
static async getBroker(brokerId) {
|
|
69
|
+
const whitelist = await this.getWhitelist();
|
|
70
|
+
const broker = whitelist.find((b) => b.id === brokerId && b.status === 'active');
|
|
71
|
+
return broker || null;
|
|
72
|
+
}
|
|
73
|
+
static async getBrokerByPublicKey(brokerPublicKey) {
|
|
74
|
+
const whitelist = await this.getWhitelist();
|
|
75
|
+
const broker = whitelist.find((b) => b.publicKey === brokerPublicKey && b.status === 'active');
|
|
76
|
+
return broker || null;
|
|
77
|
+
}
|
|
78
|
+
static async checkBrokerPermission(brokerId) {
|
|
79
|
+
const broker = await WhitelistManager.getBroker(brokerId);
|
|
80
|
+
if (!broker)
|
|
81
|
+
return false;
|
|
82
|
+
return broker.status === 'active';
|
|
83
|
+
}
|
|
84
|
+
static listActiveBrokers() {
|
|
85
|
+
return this.getActiveBrokers();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.WhitelistManager = WhitelistManager;
|
|
89
|
+
WhitelistManager.brokers = [];
|
|
90
|
+
//# sourceMappingURL=whitelist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whitelist.js","sourceRoot":"","sources":["../src/whitelist.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,MAAa,gBAAgB;IAK3B;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,eAAkF;QAClG,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;YAClB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE,CAAC;YAC1C,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC;YACpC,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QACpB,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;YACtC,IAAI,CAAC,OAAO,GAAG,eAAe,CAAC;YAC/B,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,2EAA2E,OAAO,eAAe,YAAY,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAC/I,CAAC;QACJ,CAAC;IACH,CAA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