@dcl/sdk-commands 7.26.1-32251692034.commit-9055b4b → 7.26.1-32736599590.commit-6286b33
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.
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { Router } from '@well-known-components/http-server';
|
|
2
|
+
import { IHttpServerComponent } from '@well-known-components/interfaces';
|
|
2
3
|
import { ChainId } from '@dcl/schemas';
|
|
3
4
|
import { AuthChain } from '@dcl/crypto';
|
|
4
5
|
import { CliComponents } from '../components';
|
|
6
|
+
export declare function forwardedHeaders(request: IHttpServerComponent.IRequest, overrides: Record<string, string>): Record<string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Builds the headers returned to the linker-dapp client from a proxied fetch response.
|
|
9
|
+
*
|
|
10
|
+
* undici transparently decompresses the body but leaves the upstream `content-encoding` and
|
|
11
|
+
* `content-length` in place; forwarding them would make the client re-decode an already-decoded
|
|
12
|
+
* body or truncate it at the wrong length, so both are dropped and the framing is recomputed
|
|
13
|
+
* downstream.
|
|
14
|
+
*/
|
|
15
|
+
export declare function proxiedResponseHeaders(headers: Headers): Record<string, string>;
|
|
5
16
|
/**
|
|
6
17
|
* Set common routes to use on Linker dApp
|
|
7
18
|
* @param components Server components
|
|
@@ -1,10 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forwardedHeaders = forwardedHeaders;
|
|
4
|
+
exports.proxiedResponseHeaders = proxiedResponseHeaders;
|
|
3
5
|
exports.setRoutes = setRoutes;
|
|
4
6
|
const path_1 = require("path");
|
|
5
7
|
const stream_1 = require("stream");
|
|
6
8
|
const undici_1 = require("undici");
|
|
7
9
|
const http_server_1 = require("@well-known-components/http-server");
|
|
10
|
+
const STRIPPED_REQUEST_HEADERS = new Set([
|
|
11
|
+
'connection',
|
|
12
|
+
'content-length',
|
|
13
|
+
'keep-alive',
|
|
14
|
+
'proxy-authenticate',
|
|
15
|
+
'proxy-authorization',
|
|
16
|
+
'te',
|
|
17
|
+
'trailer',
|
|
18
|
+
'transfer-encoding',
|
|
19
|
+
'upgrade'
|
|
20
|
+
]);
|
|
21
|
+
function forwardedHeaders(request, overrides) {
|
|
22
|
+
const overriddenNames = new Set(Object.keys(overrides).map((name) => name.toLowerCase()));
|
|
23
|
+
const forwarded = {};
|
|
24
|
+
for (const [key, value] of request.headers) {
|
|
25
|
+
const name = key.toLowerCase();
|
|
26
|
+
if (STRIPPED_REQUEST_HEADERS.has(name) || overriddenNames.has(name))
|
|
27
|
+
continue;
|
|
28
|
+
forwarded[name] = value;
|
|
29
|
+
}
|
|
30
|
+
return { ...forwarded, ...overrides };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Builds the headers returned to the linker-dapp client from a proxied fetch response.
|
|
34
|
+
*
|
|
35
|
+
* undici transparently decompresses the body but leaves the upstream `content-encoding` and
|
|
36
|
+
* `content-length` in place; forwarding them would make the client re-decode an already-decoded
|
|
37
|
+
* body or truncate it at the wrong length, so both are dropped and the framing is recomputed
|
|
38
|
+
* downstream.
|
|
39
|
+
*/
|
|
40
|
+
function proxiedResponseHeaders(headers) {
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, value] of headers) {
|
|
43
|
+
const name = key.toLowerCase();
|
|
44
|
+
if (['content-encoding', 'content-length'].includes(name))
|
|
45
|
+
continue;
|
|
46
|
+
result[name] = value;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
8
50
|
/**
|
|
9
51
|
* Set common routes to use on Linker dApp
|
|
10
52
|
* @param components Server components
|
|
@@ -15,8 +57,6 @@ function setRoutes(components, info, mainRoute = '/') {
|
|
|
15
57
|
const { fs } = components;
|
|
16
58
|
const router = new http_server_1.Router();
|
|
17
59
|
const linkerDapp = (0, path_1.dirname)(require.resolve('@dcl/linker-dapp/package.json'));
|
|
18
|
-
// Dispatcher used by the /auth proxy below to skip TLS verification, mirroring the
|
|
19
|
-
// previous `new https.Agent({ rejectUnauthorized: false })` behavior with native fetch.
|
|
20
60
|
const insecureDispatcher = new undici_1.Agent({ connect: { rejectUnauthorized: false } });
|
|
21
61
|
router.get(mainRoute, async () => ({
|
|
22
62
|
headers: { 'Content-Type': 'text/html' },
|
|
@@ -36,44 +76,26 @@ function setRoutes(components, info, mainRoute = '/') {
|
|
|
36
76
|
body: fs.createReadStream((0, path_1.resolve)(linkerDapp, 'assets', ctx.params.path))
|
|
37
77
|
};
|
|
38
78
|
});
|
|
39
|
-
/* This route acts as a proxy to handle the auth flow with the Decentraland auth dApp,
|
|
40
|
-
* because this latest one validates the communication be on the same domain.
|
|
41
|
-
*/
|
|
42
79
|
router.get('/auth/(.*)', async (ctx) => {
|
|
43
80
|
try {
|
|
44
81
|
const domain = 'decentraland.org';
|
|
45
82
|
const url = `https://${domain}${ctx.url.pathname}${ctx.url.search}`;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
duplex: 'half', // Required by native fetch when streaming a request body.
|
|
57
|
-
dispatcher: insecureDispatcher // Skip TLS verification.
|
|
83
|
+
const response = await components.fetch.fetch(url, {
|
|
84
|
+
method: ctx.request.method,
|
|
85
|
+
headers: forwardedHeaders(ctx.request, {
|
|
86
|
+
host: domain,
|
|
87
|
+
referer: url,
|
|
88
|
+
origin: url
|
|
89
|
+
}),
|
|
90
|
+
body: ctx.request.body,
|
|
91
|
+
duplex: 'half',
|
|
92
|
+
dispatcher: insecureDispatcher
|
|
58
93
|
});
|
|
59
|
-
|
|
60
|
-
// place; forwarding them would make the client re-decode or truncate the body.
|
|
61
|
-
// The headers on a fetch() Response are immutable (mutating them throws
|
|
62
|
-
// `TypeError: immutable`), so build a filtered copy instead of deleting in place.
|
|
63
|
-
const headers = {};
|
|
64
|
-
for (const [key, value] of resp.headers) {
|
|
65
|
-
const name = key.toLowerCase();
|
|
66
|
-
if (name === 'content-encoding' || name === 'content-length')
|
|
67
|
-
continue;
|
|
68
|
-
headers[key] = value;
|
|
69
|
-
}
|
|
70
|
-
// Return the proxied response, including body, status, and headers.
|
|
71
|
-
// `resp.body` is a web ReadableStream; convert it to a Node stream so the
|
|
72
|
-
// http-server can pipe it (it only handles Node streams / Buffers / strings).
|
|
94
|
+
const responseHeaders = proxiedResponseHeaders(response.headers);
|
|
73
95
|
return {
|
|
74
|
-
body:
|
|
75
|
-
status:
|
|
76
|
-
headers
|
|
96
|
+
body: response.body ? stream_1.Readable.fromWeb(response.body) : undefined,
|
|
97
|
+
status: response.status,
|
|
98
|
+
headers: responseHeaders
|
|
77
99
|
};
|
|
78
100
|
}
|
|
79
101
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/linker-dapp/routes.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/linker-dapp/routes.ts"],"names":[],"mappings":";;AAsBA,4CAcC;AAUD,wDAUC;AAQD,8BA0EC;AA1ID,+BAAuC;AACvC,mCAAiC;AACjC,mCAA8B;AAC9B,oEAA2D;AAO3D,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACvC,YAAY;IACZ,gBAAgB;IAChB,YAAY;IACZ,oBAAoB;IACpB,qBAAqB;IACrB,IAAI;IACJ,SAAS;IACT,mBAAmB;IACnB,SAAS;CACV,CAAC,CAAA;AAEF,SAAgB,gBAAgB,CAC9B,OAAsC,EACtC,SAAiC;IAEjC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;IACzF,MAAM,SAAS,GAA2B,EAAE,CAAA;IAE5C,KAAK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,IAAI;KACX,CAAC,CAAC,CAAA;IAEH,OAAO,EAAE,MAAM,EAAE,CAAA;AACnB,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK;YACR,OAAO,UAAU,CAAA;QACnB,KAAK,IAAI;YACP,OAAO,gBAAgB,CAAA;QACzB,KAAK,OAAO,CAAC;QACb;YACE,OAAO,YAAY,CAAA;IACvB,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAY;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;IACjC,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,KAAK;YACR,OAAO,UAAU,CAAA;QACnB,KAAK,IAAI;YACP,OAAO,wBAAwB,CAAA;QACjC,KAAK,OAAO,CAAC;QACb;YACE,OAAO,YAAY,CAAA;IACvB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/sdk-commands",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "7.26.1-
|
|
4
|
+
"version": "7.26.1-32736599590.commit-6286b33",
|
|
5
5
|
"author": "Decentraland",
|
|
6
6
|
"bin": {
|
|
7
7
|
"sdk-commands": "./dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@dcl/crypto": "^3.4.4",
|
|
11
|
-
"@dcl/ecs": "7.26.1-
|
|
11
|
+
"@dcl/ecs": "7.26.1-32736599590.commit-6286b33",
|
|
12
12
|
"@dcl/gltf-validator-ts": "1.0.14",
|
|
13
13
|
"@dcl/hashing": "1.1.3",
|
|
14
14
|
"@dcl/inspector": "7.36.3",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"displayName": "SDK",
|
|
75
75
|
"tsconfig": "./tsconfig.json"
|
|
76
76
|
},
|
|
77
|
-
"commit": "
|
|
77
|
+
"commit": "6286b337296da99f8381ad6bb70013de1e7ba89a"
|
|
78
78
|
}
|