@sdkgen/node-runtime 0.0.0-dev.20210924122820 → 1.6.1
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/dist/spec/rest/rest.spec.js +12 -12
- package/dist/spec/runtime/errors.spec.js +5 -5
- package/dist/spec/runtime/middleware.spec.js +24 -6
- package/dist/spec/simple/legacyNodeClient.js +2 -2
- package/dist/spec/simple/simple.spec.js +10 -10
- package/dist/spec/types.spec.js +47 -47
- package/dist/src/api-config.d.ts +13 -1
- package/dist/src/api-config.js +12 -1
- package/dist/src/encode-decode.js +0 -2
- package/dist/src/execute.js +4 -5
- package/dist/src/http-client.d.ts +1 -1
- package/dist/src/http-client.js +12 -26
- package/dist/src/http-server.js +52 -53
- package/dist/src/index.d.ts +7 -8
- package/dist/src/index.js +17 -18
- package/dist/src/swagger.js +2 -2
- package/dist/src/test-wrapper.js +5 -5
- package/dist/tsconfig.tsbuildinfo +2392 -1
- package/package.json +22 -19
- package/dist/src/context-storage.d.ts +0 -5
- package/dist/src/context-storage.js +0 -13
package/dist/src/http-server.js
CHANGED
|
@@ -35,7 +35,7 @@ class SdkgenHttpServer {
|
|
|
35
35
|
this.introspection = true;
|
|
36
36
|
this.hasSwagger = false;
|
|
37
37
|
this.ignoredUrlPrefix = "";
|
|
38
|
-
this.httpServer =
|
|
38
|
+
this.httpServer = http_1.createServer(this.handleRequest.bind(this));
|
|
39
39
|
this.enableCors();
|
|
40
40
|
this.attachRestHandlers();
|
|
41
41
|
const targetTable = [
|
|
@@ -82,7 +82,7 @@ class SdkgenHttpServer {
|
|
|
82
82
|
if (req.url) {
|
|
83
83
|
req.url = req.url.endsWith("/playground") ? req.url.replace(/\/playground/u, "/index.html") : req.url.replace(/\/playground/u, "");
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
serve_handler_1.default(req, res, {
|
|
86
86
|
cleanUrls: false,
|
|
87
87
|
directoryListing: false,
|
|
88
88
|
etag: true,
|
|
@@ -132,7 +132,7 @@ class SdkgenHttpServer {
|
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
async close() {
|
|
135
|
-
return
|
|
135
|
+
return util_1.promisify(this.httpServer.close.bind(this.httpServer))();
|
|
136
136
|
}
|
|
137
137
|
enableCors() {
|
|
138
138
|
this.addHeader("Access-Control-Allow-Methods", "DELETE, HEAD, PUT, POST, PATCH, GET, OPTIONS");
|
|
@@ -201,7 +201,7 @@ class SdkgenHttpServer {
|
|
|
201
201
|
continue;
|
|
202
202
|
}
|
|
203
203
|
if (!this.hasSwagger) {
|
|
204
|
-
|
|
204
|
+
swagger_1.setupSwagger(this);
|
|
205
205
|
this.hasSwagger = true;
|
|
206
206
|
}
|
|
207
207
|
const pathFragments = ann.path.split(/\{\w+\}/u);
|
|
@@ -222,7 +222,7 @@ class SdkgenHttpServer {
|
|
|
222
222
|
try {
|
|
223
223
|
const args = {};
|
|
224
224
|
const files = [];
|
|
225
|
-
const { pathname, query } =
|
|
225
|
+
const { pathname, query } = url_1.parse((_a = req.url) !== null && _a !== void 0 ? _a : "");
|
|
226
226
|
const match = pathname === null || pathname === void 0 ? void 0 : pathname.match(pathRegex);
|
|
227
227
|
if (!match) {
|
|
228
228
|
res.statusCode = 404;
|
|
@@ -234,7 +234,7 @@ class SdkgenHttpServer {
|
|
|
234
234
|
const argValue = match[i + 1];
|
|
235
235
|
simpleArgs.set(argName, argValue);
|
|
236
236
|
}
|
|
237
|
-
const parsedQuery = query ?
|
|
237
|
+
const parsedQuery = query ? querystring_1.parse(query) : {};
|
|
238
238
|
for (const argName of ann.queryVariables) {
|
|
239
239
|
const argValue = (_b = parsedQuery[argName]) !== null && _b !== void 0 ? _b : null;
|
|
240
240
|
if (argValue === null) {
|
|
@@ -250,7 +250,7 @@ class SdkgenHttpServer {
|
|
|
250
250
|
simpleArgs.set(argName, Array.isArray(argValue) ? argValue.join("") : argValue);
|
|
251
251
|
}
|
|
252
252
|
if (!ann.bodyVariable && ((_d = req.headers["content-type"]) === null || _d === void 0 ? void 0 : _d.match(/^application\/x-www-form-urlencoded/iu))) {
|
|
253
|
-
const parsedBody =
|
|
253
|
+
const parsedBody = querystring_1.parse(body.toString());
|
|
254
254
|
console.log("parsedBody", parsedBody);
|
|
255
255
|
for (const argName of ann.queryVariables) {
|
|
256
256
|
const argValue = (_e = parsedBody[argName]) !== null && _e !== void 0 ? _e : null;
|
|
@@ -269,15 +269,15 @@ class SdkgenHttpServer {
|
|
|
269
269
|
}
|
|
270
270
|
});
|
|
271
271
|
busboy.on("file", (_field, file, name) => {
|
|
272
|
-
const tempName =
|
|
273
|
-
const writeStream =
|
|
272
|
+
const tempName = crypto_1.randomBytes(32).toString("hex");
|
|
273
|
+
const writeStream = fs_1.createWriteStream(tempName);
|
|
274
274
|
filePromises.push(new Promise((resolve, reject) => {
|
|
275
275
|
writeStream.on("error", reject);
|
|
276
276
|
writeStream.on("close", () => {
|
|
277
|
-
const contents =
|
|
277
|
+
const contents = fs_1.createReadStream(tempName);
|
|
278
278
|
files.push({ contents, name });
|
|
279
279
|
contents.on("open", () => {
|
|
280
|
-
|
|
280
|
+
fs_1.unlink(tempName, err => {
|
|
281
281
|
if (err) {
|
|
282
282
|
reject(err);
|
|
283
283
|
}
|
|
@@ -383,7 +383,7 @@ class SdkgenHttpServer {
|
|
|
383
383
|
args[argName] = argValue;
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
const ip =
|
|
386
|
+
const ip = request_ip_1.getClientIp(req);
|
|
387
387
|
if (!ip) {
|
|
388
388
|
throw new Error("Couldn't determine client IP");
|
|
389
389
|
}
|
|
@@ -391,7 +391,7 @@ class SdkgenHttpServer {
|
|
|
391
391
|
args,
|
|
392
392
|
deviceInfo: {
|
|
393
393
|
fingerprint: null,
|
|
394
|
-
id:
|
|
394
|
+
id: crypto_1.randomBytes(16).toString("hex"),
|
|
395
395
|
language: null,
|
|
396
396
|
platform: null,
|
|
397
397
|
timezone: null,
|
|
@@ -401,7 +401,7 @@ class SdkgenHttpServer {
|
|
|
401
401
|
extra: {},
|
|
402
402
|
files,
|
|
403
403
|
headers: req.headers,
|
|
404
|
-
id:
|
|
404
|
+
id: crypto_1.randomBytes(16).toString("hex"),
|
|
405
405
|
ip,
|
|
406
406
|
name: op.name,
|
|
407
407
|
version: 3,
|
|
@@ -474,8 +474,7 @@ class SdkgenHttpServer {
|
|
|
474
474
|
.then(() => {
|
|
475
475
|
res.write(buffer);
|
|
476
476
|
res.end();
|
|
477
|
-
})
|
|
478
|
-
.catch(() => { });
|
|
477
|
+
});
|
|
479
478
|
}
|
|
480
479
|
else {
|
|
481
480
|
res.setHeader("content-type", "application/json");
|
|
@@ -531,8 +530,9 @@ class SdkgenHttpServer {
|
|
|
531
530
|
}
|
|
532
531
|
const body = [];
|
|
533
532
|
req.on("data", chunk => body.push(chunk));
|
|
533
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
534
534
|
req.on("end", () => {
|
|
535
|
-
this.handleRequestWithBody(req, res, Buffer.concat(body), hrStart).catch(
|
|
535
|
+
this.handleRequestWithBody(req, res, Buffer.concat(body), hrStart).catch(e => this.writeReply(res, null, { error: e }, hrStart));
|
|
536
536
|
});
|
|
537
537
|
}
|
|
538
538
|
log(message) {
|
|
@@ -540,7 +540,7 @@ class SdkgenHttpServer {
|
|
|
540
540
|
}
|
|
541
541
|
async handleRequestWithBody(req, res, body, hrStart) {
|
|
542
542
|
var _a, _b;
|
|
543
|
-
const { pathname, query } =
|
|
543
|
+
const { pathname, query } = url_1.parse((_a = req.url) !== null && _a !== void 0 ? _a : "");
|
|
544
544
|
let path = pathname !== null && pathname !== void 0 ? pathname : "";
|
|
545
545
|
if (path.startsWith(this.ignoredUrlPrefix)) {
|
|
546
546
|
path = path.slice(this.ignoredUrlPrefix.length);
|
|
@@ -565,8 +565,9 @@ class SdkgenHttpServer {
|
|
|
565
565
|
res.end();
|
|
566
566
|
return;
|
|
567
567
|
}
|
|
568
|
-
let ok
|
|
568
|
+
let ok;
|
|
569
569
|
try {
|
|
570
|
+
ok = await this.apiConfig.hook.onHealthCheck();
|
|
570
571
|
for (const healthCheck of this.healthChecks) {
|
|
571
572
|
if (!ok) {
|
|
572
573
|
break;
|
|
@@ -587,7 +588,7 @@ class SdkgenHttpServer {
|
|
|
587
588
|
res.end();
|
|
588
589
|
return;
|
|
589
590
|
}
|
|
590
|
-
const clientIp =
|
|
591
|
+
const clientIp = request_ip_1.getClientIp(req);
|
|
591
592
|
if (!clientIp) {
|
|
592
593
|
this.writeReply(res, null, {
|
|
593
594
|
error: new error_1.Fatal("Couldn't determine client IP"),
|
|
@@ -605,7 +606,7 @@ class SdkgenHttpServer {
|
|
|
605
606
|
}
|
|
606
607
|
async executeRequest(request, writeReply) {
|
|
607
608
|
const ctx = Object.assign(Object.assign({}, this.extraContext), { request });
|
|
608
|
-
writeReply(ctx, await
|
|
609
|
+
writeReply(ctx, await execute_1.executeRequest(ctx, this.apiConfig));
|
|
609
610
|
}
|
|
610
611
|
parseRequest(req, body, ip) {
|
|
611
612
|
switch (this.identifyRequestVersion(req, body)) {
|
|
@@ -621,13 +622,13 @@ class SdkgenHttpServer {
|
|
|
621
622
|
}
|
|
622
623
|
identifyRequestVersion(_req, body) {
|
|
623
624
|
const parsed = JSON.parse(body);
|
|
624
|
-
if (typeof parsed === "object" && parsed &&
|
|
625
|
+
if (typeof parsed === "object" && parsed && utils_1.has(parsed, "version") && typeof parsed.version === "number") {
|
|
625
626
|
return parsed.version;
|
|
626
627
|
}
|
|
627
|
-
else if (typeof parsed === "object" && parsed &&
|
|
628
|
+
else if (typeof parsed === "object" && parsed && utils_1.has(parsed, "requestId")) {
|
|
628
629
|
return 2;
|
|
629
630
|
}
|
|
630
|
-
else if (typeof parsed === "object" && parsed &&
|
|
631
|
+
else if (typeof parsed === "object" && parsed && utils_1.has(parsed, "device")) {
|
|
631
632
|
return 1;
|
|
632
633
|
}
|
|
633
634
|
return 3;
|
|
@@ -635,24 +636,23 @@ class SdkgenHttpServer {
|
|
|
635
636
|
// Old Sdkgen format
|
|
636
637
|
parseRequestV1(req, body, ip) {
|
|
637
638
|
var _a, _b;
|
|
638
|
-
const parsed =
|
|
639
|
+
const parsed = encode_decode_1.decode({
|
|
639
640
|
Request: {
|
|
640
641
|
args: "json",
|
|
641
|
-
device:
|
|
642
|
+
device: {
|
|
643
|
+
fingerprint: "string?",
|
|
644
|
+
id: "string?",
|
|
645
|
+
language: "string?",
|
|
646
|
+
platform: "json?",
|
|
647
|
+
timezone: "string?",
|
|
648
|
+
type: "string?",
|
|
649
|
+
version: "string?",
|
|
650
|
+
},
|
|
642
651
|
id: "string",
|
|
643
652
|
name: "string",
|
|
644
653
|
},
|
|
645
|
-
RequestDevice: {
|
|
646
|
-
fingerprint: "string?",
|
|
647
|
-
id: "string?",
|
|
648
|
-
language: "string?",
|
|
649
|
-
platform: "json?",
|
|
650
|
-
timezone: "string?",
|
|
651
|
-
type: "string?",
|
|
652
|
-
version: "string?",
|
|
653
|
-
},
|
|
654
654
|
}, "root", "Request", JSON.parse(body));
|
|
655
|
-
const deviceId = (_a = parsed.device.id) !== null && _a !== void 0 ? _a :
|
|
655
|
+
const deviceId = (_a = parsed.device.id) !== null && _a !== void 0 ? _a : crypto_1.randomBytes(20).toString("hex");
|
|
656
656
|
if (!parsed.args || Array.isArray(parsed.args) || typeof parsed.args !== "object") {
|
|
657
657
|
throw new Error("Expected 'args' to be an object");
|
|
658
658
|
}
|
|
@@ -679,22 +679,21 @@ class SdkgenHttpServer {
|
|
|
679
679
|
// Maxima sdkgen format
|
|
680
680
|
parseRequestV2(req, body, ip) {
|
|
681
681
|
var _a, _b;
|
|
682
|
-
const parsed =
|
|
682
|
+
const parsed = encode_decode_1.decode({
|
|
683
683
|
Request: {
|
|
684
684
|
args: "json",
|
|
685
685
|
deviceFingerprint: "string?",
|
|
686
686
|
deviceId: "string",
|
|
687
|
-
info:
|
|
687
|
+
info: {
|
|
688
|
+
browserUserAgent: "string?",
|
|
689
|
+
language: "string",
|
|
690
|
+
type: "string",
|
|
691
|
+
},
|
|
688
692
|
name: "string",
|
|
689
693
|
partnerId: "string?",
|
|
690
694
|
requestId: "string?",
|
|
691
695
|
sessionId: "string?",
|
|
692
696
|
},
|
|
693
|
-
RequestInfo: {
|
|
694
|
-
browserUserAgent: "string?",
|
|
695
|
-
language: "string",
|
|
696
|
-
type: "string",
|
|
697
|
-
},
|
|
698
697
|
}, "root", "Request", JSON.parse(body));
|
|
699
698
|
if (!parsed.args || Array.isArray(parsed.args) || typeof parsed.args !== "object") {
|
|
700
699
|
throw new Error("Expected 'args' to be an object");
|
|
@@ -718,7 +717,7 @@ class SdkgenHttpServer {
|
|
|
718
717
|
},
|
|
719
718
|
files: [],
|
|
720
719
|
headers: req.headers,
|
|
721
|
-
id: `${parsed.deviceId}-${(_b = parsed.requestId) !== null && _b !== void 0 ? _b :
|
|
720
|
+
id: `${parsed.deviceId}-${(_b = parsed.requestId) !== null && _b !== void 0 ? _b : crypto_1.randomBytes(16).toString("hex")}`,
|
|
722
721
|
ip,
|
|
723
722
|
name: parsed.name,
|
|
724
723
|
version: 2,
|
|
@@ -727,7 +726,7 @@ class SdkgenHttpServer {
|
|
|
727
726
|
// New sdkgen format
|
|
728
727
|
parseRequestV3(req, body, ip) {
|
|
729
728
|
var _a, _b, _c, _d;
|
|
730
|
-
const parsed =
|
|
729
|
+
const parsed = encode_decode_1.decode({
|
|
731
730
|
DeviceInfo: {
|
|
732
731
|
fingerprint: "string?",
|
|
733
732
|
id: "string?",
|
|
@@ -754,7 +753,7 @@ class SdkgenHttpServer {
|
|
|
754
753
|
type: null,
|
|
755
754
|
version: null,
|
|
756
755
|
};
|
|
757
|
-
const deviceId = (_b = deviceInfo.id) !== null && _b !== void 0 ? _b :
|
|
756
|
+
const deviceId = (_b = deviceInfo.id) !== null && _b !== void 0 ? _b : crypto_1.randomBytes(16).toString("hex");
|
|
758
757
|
if (!parsed.args || Array.isArray(parsed.args) || typeof parsed.args !== "object") {
|
|
759
758
|
throw new Error("Expected 'args' to be an object");
|
|
760
759
|
}
|
|
@@ -772,7 +771,7 @@ class SdkgenHttpServer {
|
|
|
772
771
|
extra: typeof parsed.extra === "object" ? Object.assign({}, parsed.extra) : {},
|
|
773
772
|
files: [],
|
|
774
773
|
headers: req.headers,
|
|
775
|
-
id: `${deviceId}-${(_d = parsed.requestId) !== null && _d !== void 0 ? _d :
|
|
774
|
+
id: `${deviceId}-${(_d = parsed.requestId) !== null && _d !== void 0 ? _d : crypto_1.randomBytes(16).toString("hex")}`,
|
|
776
775
|
ip,
|
|
777
776
|
name: parsed.name,
|
|
778
777
|
version: 3,
|
|
@@ -780,11 +779,11 @@ class SdkgenHttpServer {
|
|
|
780
779
|
}
|
|
781
780
|
makeResponseError(err) {
|
|
782
781
|
let type = "Fatal";
|
|
783
|
-
if (typeof err === "object" && err !== null &&
|
|
782
|
+
if (typeof err === "object" && err !== null && utils_1.has(err, "type") && typeof err.type === "string") {
|
|
784
783
|
({ type } = err);
|
|
785
784
|
}
|
|
786
785
|
let message;
|
|
787
|
-
if (typeof err === "object" && err !== null &&
|
|
786
|
+
if (typeof err === "object" && err !== null && utils_1.has(err, "message") && typeof err.message === "string") {
|
|
788
787
|
({ message } = err);
|
|
789
788
|
}
|
|
790
789
|
else if (err instanceof Error) {
|
|
@@ -797,14 +796,14 @@ class SdkgenHttpServer {
|
|
|
797
796
|
message = `${err}`;
|
|
798
797
|
}
|
|
799
798
|
let data;
|
|
800
|
-
if (typeof err === "object" && err !== null &&
|
|
799
|
+
if (typeof err === "object" && err !== null && utils_1.has(err, "data")) {
|
|
801
800
|
({ data } = err);
|
|
802
801
|
}
|
|
803
802
|
const error = this.apiConfig.ast.errors.find(x => x.name === type);
|
|
804
803
|
if (error) {
|
|
805
804
|
if (!(error.dataType instanceof parser_1.VoidPrimitiveType)) {
|
|
806
805
|
try {
|
|
807
|
-
data =
|
|
806
|
+
data = encode_decode_1.encode(this.apiConfig.astJson.typeTable, `error.${type}`, error.dataType.name, data);
|
|
808
807
|
}
|
|
809
808
|
catch (encodeError) {
|
|
810
809
|
message = `Failed to encode error ${type} because: ${encodeError}. Original message: ${message}`;
|
|
@@ -839,7 +838,7 @@ class SdkgenHttpServer {
|
|
|
839
838
|
deviceId: ctx.request.deviceInfo.id,
|
|
840
839
|
duration,
|
|
841
840
|
error: reply.error ? this.makeResponseError(reply.error) : null,
|
|
842
|
-
host:
|
|
841
|
+
host: os_1.hostname(),
|
|
843
842
|
id: ctx.request.id,
|
|
844
843
|
ok: !reply.error,
|
|
845
844
|
result: reply.error ? null : reply.result,
|
|
@@ -871,7 +870,7 @@ class SdkgenHttpServer {
|
|
|
871
870
|
const response = {
|
|
872
871
|
duration,
|
|
873
872
|
error: reply.error ? this.makeResponseError(reply.error) : null,
|
|
874
|
-
host:
|
|
873
|
+
host: os_1.hostname(),
|
|
875
874
|
result: reply.error ? null : reply.result,
|
|
876
875
|
};
|
|
877
876
|
if (response.error) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export { apiTestWrapper } from "./test-wrapper";
|
|
1
|
+
export * from "./api-config";
|
|
2
|
+
export * from "./context";
|
|
3
|
+
export * from "./encode-decode";
|
|
4
|
+
export * from "./error";
|
|
5
|
+
export * from "./http-client";
|
|
6
|
+
export * from "./http-server";
|
|
7
|
+
export * from "./test-wrapper";
|
package/dist/src/index.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
2
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, "Fatal", { enumerable: true, get: function () { return error_1.Fatal; } });
|
|
11
|
-
Object.defineProperty(exports, "SdkgenError", { enumerable: true, get: function () { return error_1.SdkgenError; } });
|
|
12
|
-
Object.defineProperty(exports, "SdkgenErrorWithData", { enumerable: true, get: function () { return error_1.SdkgenErrorWithData; } });
|
|
13
|
-
var context_storage_1 = require("./context-storage");
|
|
14
|
-
Object.defineProperty(exports, "useSdkgenContext", { enumerable: true, get: function () { return context_storage_1.useSdkgenContext; } });
|
|
15
|
-
var http_client_1 = require("./http-client");
|
|
16
|
-
Object.defineProperty(exports, "SdkgenHttpClient", { enumerable: true, get: function () { return http_client_1.SdkgenHttpClient; } });
|
|
17
|
-
var http_server_1 = require("./http-server");
|
|
18
|
-
Object.defineProperty(exports, "SdkgenHttpServer", { enumerable: true, get: function () { return http_server_1.SdkgenHttpServer; } });
|
|
19
|
-
var test_wrapper_1 = require("./test-wrapper");
|
|
20
|
-
Object.defineProperty(exports, "apiTestWrapper", { enumerable: true, get: function () { return test_wrapper_1.apiTestWrapper; } });
|
|
13
|
+
__exportStar(require("./api-config"), exports);
|
|
14
|
+
__exportStar(require("./context"), exports);
|
|
15
|
+
__exportStar(require("./encode-decode"), exports);
|
|
16
|
+
__exportStar(require("./error"), exports);
|
|
17
|
+
__exportStar(require("./http-client"), exports);
|
|
18
|
+
__exportStar(require("./http-server"), exports);
|
|
19
|
+
__exportStar(require("./test-wrapper"), exports);
|
package/dist/src/swagger.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.setupSwagger = void 0;
|
|
|
7
7
|
const parser_1 = require("@sdkgen/parser");
|
|
8
8
|
const serve_handler_1 = __importDefault(require("serve-handler"));
|
|
9
9
|
const swagger_ui_dist_1 = require("swagger-ui-dist");
|
|
10
|
-
const swaggerUiAssetPath =
|
|
10
|
+
const swaggerUiAssetPath = swagger_ui_dist_1.getAbsoluteFSPath();
|
|
11
11
|
function objectFromEntries(entries) {
|
|
12
12
|
return Object.assign({}, ...Array.from(entries, ([k, v]) => ({ [k]: v })));
|
|
13
13
|
}
|
|
@@ -201,7 +201,7 @@ function setupSwagger(server) {
|
|
|
201
201
|
req.url = req.url.replace(/\/swagger/u, "");
|
|
202
202
|
}
|
|
203
203
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
204
|
-
|
|
204
|
+
serve_handler_1.default(req, res, {
|
|
205
205
|
cleanUrls: false,
|
|
206
206
|
directoryListing: false,
|
|
207
207
|
etag: true,
|
package/dist/src/test-wrapper.js
CHANGED
|
@@ -15,12 +15,12 @@ function apiTestWrapper(api) {
|
|
|
15
15
|
for (const functionName of Object.keys(api.astJson.functionTable)) {
|
|
16
16
|
wrappedApi.fn[functionName] = async (ctx, args) => {
|
|
17
17
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
18
|
-
const encodedArgs =
|
|
18
|
+
const encodedArgs = encode_decode_1.encode(api.astJson.typeTable, `fn.${functionName}.args`, api.astJson.functionTable[functionName].args, args);
|
|
19
19
|
ctx.request = {
|
|
20
20
|
args: encodedArgs,
|
|
21
21
|
deviceInfo: (_b = (_a = ctx.request) === null || _a === void 0 ? void 0 : _a.deviceInfo) !== null && _b !== void 0 ? _b : {
|
|
22
22
|
fingerprint: null,
|
|
23
|
-
id:
|
|
23
|
+
id: crypto_1.randomBytes(16).toString("hex"),
|
|
24
24
|
language: null,
|
|
25
25
|
platform: null,
|
|
26
26
|
timezone: null,
|
|
@@ -30,17 +30,17 @@ function apiTestWrapper(api) {
|
|
|
30
30
|
extra: (_d = (_c = ctx.request) === null || _c === void 0 ? void 0 : _c.extra) !== null && _d !== void 0 ? _d : {},
|
|
31
31
|
files: (_f = (_e = ctx.request) === null || _e === void 0 ? void 0 : _e.files) !== null && _f !== void 0 ? _f : [],
|
|
32
32
|
headers: (_h = (_g = ctx.request) === null || _g === void 0 ? void 0 : _g.headers) !== null && _h !== void 0 ? _h : {},
|
|
33
|
-
id: (_k = (_j = ctx.request) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k :
|
|
33
|
+
id: (_k = (_j = ctx.request) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : crypto_1.randomBytes(16).toString("hex"),
|
|
34
34
|
ip: (_m = (_l = ctx.request) === null || _l === void 0 ? void 0 : _l.ip) !== null && _m !== void 0 ? _m : "0.0.0.0",
|
|
35
35
|
name: functionName,
|
|
36
36
|
version: 3,
|
|
37
37
|
};
|
|
38
|
-
const reply = await
|
|
38
|
+
const reply = await execute_1.executeRequest(ctx, api);
|
|
39
39
|
if (reply.error) {
|
|
40
40
|
throw reply.error;
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
const decodedRet =
|
|
43
|
+
const decodedRet = encode_decode_1.decode(api.astJson.typeTable, `fn.${functionName}.ret`, api.astJson.functionTable[functionName].ret, JSON.parse(JSON.stringify(reply.result)));
|
|
44
44
|
return decodedRet;
|
|
45
45
|
}
|
|
46
46
|
};
|