@valbuild/next 0.34.0 → 0.35.0
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 +1 -1
- package/client/dist/valbuild-next-client.cjs.dev.js +11 -58
- package/client/dist/valbuild-next-client.cjs.prod.js +11 -58
- package/client/dist/valbuild-next-client.esm.js +10 -57
- package/dist/ValNextProvider-3676dacc.esm.js +25 -0
- package/dist/ValNextProvider-ae031b12.cjs.dev.js +29 -0
- package/dist/ValNextProvider-fe84f6a9.cjs.js +7 -0
- package/dist/ValNextProvider-fe84f6a9.cjs.prod.js +29 -0
- package/dist/declarations/src/ValProvider.d.ts +4 -2
- package/dist/declarations/src/client/index.d.ts +1 -1
- package/dist/declarations/src/client/initValClient.d.ts +8 -0
- package/dist/declarations/src/initVal.d.ts +3 -1
- package/dist/declarations/src/rsc/index.d.ts +2 -0
- package/dist/declarations/src/rsc/initValRsc.d.ts +19 -0
- package/dist/declarations/src/server/index.d.ts +1 -1
- package/dist/declarations/src/server/initValServer.d.ts +11 -0
- package/dist/slicedToArray-1471796d.cjs.dev.js +58 -0
- package/dist/slicedToArray-4190fac1.cjs.prod.js +58 -0
- package/dist/slicedToArray-62cd636a.esm.js +56 -0
- package/dist/valbuild-next.cjs.dev.js +63 -4
- package/dist/valbuild-next.cjs.prod.js +63 -4
- package/dist/valbuild-next.esm.js +63 -5
- package/package.json +15 -6
- package/rsc/dist/valbuild-next-rsc.cjs.d.ts +2 -0
- package/rsc/dist/valbuild-next-rsc.cjs.d.ts.map +1 -0
- package/rsc/dist/valbuild-next-rsc.cjs.dev.js +159 -0
- package/rsc/dist/valbuild-next-rsc.cjs.js +7 -0
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +159 -0
- package/rsc/dist/valbuild-next-rsc.esm.js +155 -0
- package/rsc/package.json +4 -0
- package/server/dist/valbuild-next-server.cjs.dev.js +78 -133
- package/server/dist/valbuild-next-server.cjs.prod.js +78 -133
- package/server/dist/valbuild-next-server.esm.js +78 -115
- package/dist/declarations/src/client/useVal.d.ts +0 -3
- package/dist/declarations/src/server/fetchVal.d.ts +0 -3
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
|
|
3
|
+
import { ValApi, Internal } from '@valbuild/core';
|
|
4
|
+
import { result } from '@valbuild/core/fp';
|
|
5
|
+
|
|
6
|
+
function optimizeTreePath(ids) {
|
|
7
|
+
return findUpperDirectory(ids);
|
|
8
|
+
}
|
|
9
|
+
function findUpperDirectory(paths) {
|
|
10
|
+
if (paths.length === 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
var pathSegments = paths[0].split("/");
|
|
14
|
+
for (var i = 1; i < paths.length; i++) {
|
|
15
|
+
var currentPathSegments = paths[i].split("/");
|
|
16
|
+
// Find the minimum length of the two paths
|
|
17
|
+
var minLength = Math.min(pathSegments.length, currentPathSegments.length);
|
|
18
|
+
|
|
19
|
+
// Iterate through the segments and find the common prefix
|
|
20
|
+
var commonPrefix = "";
|
|
21
|
+
for (var j = 0; j < minLength; j++) {
|
|
22
|
+
if (pathSegments[j] === currentPathSegments[j]) {
|
|
23
|
+
commonPrefix += pathSegments[j] + "/";
|
|
24
|
+
} else {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
pathSegments = commonPrefix.split("/").slice(0, -1);
|
|
29
|
+
|
|
30
|
+
// If there is no common prefix, return /
|
|
31
|
+
if (pathSegments.length <= 1) {
|
|
32
|
+
return "/";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var upperDirectory = pathSegments.join("/");
|
|
36
|
+
return upperDirectory;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var initFetchValStega = function initFetchValStega(config, valApiEndpoints, isEnabled, getHeaders, getCookies) {
|
|
40
|
+
return function (selector) {
|
|
41
|
+
var enabled = false;
|
|
42
|
+
try {
|
|
43
|
+
enabled = isEnabled();
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error("Val: could not check if Val is enabled! This might be due to an error to check draftMode. fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
46
|
+
}
|
|
47
|
+
if (enabled) {
|
|
48
|
+
var headers;
|
|
49
|
+
try {
|
|
50
|
+
headers = getHeaders();
|
|
51
|
+
if (!(headers instanceof Headers)) {
|
|
52
|
+
throw new Error("Expected an instance of Headers. Check Val rsc config.");
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error("Val: could not read headers! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
56
|
+
headers = null;
|
|
57
|
+
}
|
|
58
|
+
var cookies;
|
|
59
|
+
try {
|
|
60
|
+
cookies = getCookies();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.error("Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
63
|
+
cookies = null;
|
|
64
|
+
}
|
|
65
|
+
var host = headers && getHost(headers);
|
|
66
|
+
if (host && cookies && isProxyMode(config)) {
|
|
67
|
+
var _optimizeTreePath;
|
|
68
|
+
var api = new ValApi("".concat(host).concat(valApiEndpoints));
|
|
69
|
+
var valModuleIds = getModuleIds(selector);
|
|
70
|
+
return api.getTree({
|
|
71
|
+
// TODO: get tree should probably have a list of ids instead
|
|
72
|
+
treePath: (_optimizeTreePath = optimizeTreePath(valModuleIds)) !== null && _optimizeTreePath !== void 0 ? _optimizeTreePath : undefined,
|
|
73
|
+
patch: true,
|
|
74
|
+
includeSource: true,
|
|
75
|
+
headers: getValAuthHeaders(cookies)
|
|
76
|
+
}).then(function (res) {
|
|
77
|
+
if (result.isOk(res)) {
|
|
78
|
+
var modules = res.value.modules;
|
|
79
|
+
return stegaEncode(selector, {
|
|
80
|
+
getModule: function getModule(moduleId) {
|
|
81
|
+
var module = modules[moduleId];
|
|
82
|
+
if (module) {
|
|
83
|
+
return module.source;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
console.error("Val: could not fetch modules", res.error);
|
|
89
|
+
}
|
|
90
|
+
return stegaEncode(selector, {});
|
|
91
|
+
})["catch"](function (err) {
|
|
92
|
+
console.error("Val: failed while checking modules", err);
|
|
93
|
+
return selector;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return stegaEncode(selector, {
|
|
98
|
+
disabled: !enabled
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
function getHost(headers) {
|
|
103
|
+
var _headers$get;
|
|
104
|
+
// TODO: does NextJs have a way to determine this?
|
|
105
|
+
var host = headers.get("host");
|
|
106
|
+
var proto = "https";
|
|
107
|
+
if (headers.get("x-forwarded-proto") === "http") {
|
|
108
|
+
proto = "http";
|
|
109
|
+
} else if ((_headers$get = headers.get("referer")) !== null && _headers$get !== void 0 && _headers$get.startsWith("http://")) {
|
|
110
|
+
proto = "http";
|
|
111
|
+
} else if (host !== null && host !== void 0 && host.startsWith("localhost")) {
|
|
112
|
+
proto = "http";
|
|
113
|
+
}
|
|
114
|
+
if (host && proto) {
|
|
115
|
+
return "".concat(proto, "://").concat(host);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function isProxyMode(opts) {
|
|
120
|
+
var maybeApiKey = opts.apiKey || process.env.VAL_API_KEY;
|
|
121
|
+
var maybeValSecret = opts.valSecret || process.env.VAL_SECRET;
|
|
122
|
+
var isProxyMode = opts.mode === "proxy" || opts.mode === undefined && (maybeApiKey || maybeValSecret);
|
|
123
|
+
return !!isProxyMode;
|
|
124
|
+
}
|
|
125
|
+
function getValAuthHeaders(cookies) {
|
|
126
|
+
try {
|
|
127
|
+
var session = cookies.get(Internal.VAL_SESSION_COOKIE);
|
|
128
|
+
if (session) {
|
|
129
|
+
return {
|
|
130
|
+
Cookie: "".concat(Internal.VAL_SESSION_COOKIE, "=").concat(encodeURIComponent(session.value))
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return {};
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.error("Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", err);
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
var valApiEndpoints = "/api/val";
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
141
|
+
function initValRsc(config, rscNextConfig) {
|
|
142
|
+
return {
|
|
143
|
+
fetchValStega: initFetchValStega(config, valApiEndpoints,
|
|
144
|
+
// TODO: get from config
|
|
145
|
+
function () {
|
|
146
|
+
return rscNextConfig.draftMode().isEnabled;
|
|
147
|
+
}, function () {
|
|
148
|
+
return rscNextConfig.headers();
|
|
149
|
+
}, function () {
|
|
150
|
+
return rscNextConfig.cookies();
|
|
151
|
+
})
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { initValRsc };
|
package/rsc/package.json
ADDED
|
@@ -3,28 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('server-only');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var headers = require('next/headers');
|
|
10
|
-
|
|
11
|
-
function _interopNamespace(e) {
|
|
12
|
-
if (e && e.__esModule) return e;
|
|
13
|
-
var n = Object.create(null);
|
|
14
|
-
if (e) {
|
|
15
|
-
Object.keys(e).forEach(function (k) {
|
|
16
|
-
if (k !== 'default') {
|
|
17
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () { return e[k]; }
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
n["default"] = e;
|
|
26
|
-
return Object.freeze(n);
|
|
27
|
-
}
|
|
6
|
+
var slicedToArray = require('../../dist/slicedToArray-1471796d.cjs.dev.js');
|
|
7
|
+
var server = require('@valbuild/server');
|
|
8
|
+
var server$1 = require('next/server');
|
|
28
9
|
|
|
29
10
|
function _regeneratorRuntime() {
|
|
30
11
|
_regeneratorRuntime = function () {
|
|
@@ -359,121 +340,85 @@ function _asyncToGenerator(fn) {
|
|
|
359
340
|
};
|
|
360
341
|
}
|
|
361
342
|
|
|
362
|
-
var
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
patch: true,
|
|
375
|
-
includeSource: true,
|
|
376
|
-
headers: getValHeaders()
|
|
377
|
-
}).then(function (res) {
|
|
378
|
-
if (fp.result.isOk(res)) {
|
|
379
|
-
var modules = res.value.modules;
|
|
380
|
-
return stega.stegaEncode(selector, {
|
|
381
|
-
getModule: function getModule(moduleId) {
|
|
382
|
-
var module = modules[moduleId];
|
|
383
|
-
if (module) {
|
|
384
|
-
return module.source;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
} else {
|
|
389
|
-
console.error("Val: could not fetch modules", res.error);
|
|
343
|
+
var initValNextAppRouter = function initValNextAppRouter(config, nextConfig) {
|
|
344
|
+
var route = "/api/val"; // TODO: get from config
|
|
345
|
+
return server.createValApiRouter(route, server.createValServer(route, config, {
|
|
346
|
+
isEnabled: function isEnabled() {
|
|
347
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
348
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
349
|
+
while (1) switch (_context.prev = _context.next) {
|
|
350
|
+
case 0:
|
|
351
|
+
return _context.abrupt("return", nextConfig.draftMode().isEnabled);
|
|
352
|
+
case 1:
|
|
353
|
+
case "end":
|
|
354
|
+
return _context.stop();
|
|
390
355
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
function getHost() {
|
|
404
|
-
return _getHost.apply(this, arguments);
|
|
405
|
-
}
|
|
406
|
-
function _getHost() {
|
|
407
|
-
_getHost = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
408
|
-
var _hs$get, _yield$import, headers, hs, host, proto;
|
|
409
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
410
|
-
while (1) switch (_context.prev = _context.next) {
|
|
411
|
-
case 0:
|
|
412
|
-
_context.prev = 0;
|
|
413
|
-
_context.next = 3;
|
|
414
|
-
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('next/headers')); });
|
|
415
|
-
case 3:
|
|
416
|
-
_yield$import = _context.sent;
|
|
417
|
-
headers = _yield$import.headers;
|
|
418
|
-
hs = headers();
|
|
419
|
-
host = hs.get("host");
|
|
420
|
-
proto = "https";
|
|
421
|
-
if (hs.get("x-forwarded-proto") === "http") {
|
|
422
|
-
proto = "http";
|
|
423
|
-
} else if ((_hs$get = hs.get("referer")) !== null && _hs$get !== void 0 && _hs$get.startsWith("http://")) {
|
|
424
|
-
proto = "http";
|
|
425
|
-
} else if (host !== null && host !== void 0 && host.startsWith("localhost")) {
|
|
426
|
-
proto = "http";
|
|
356
|
+
}, _callee);
|
|
357
|
+
}))();
|
|
358
|
+
},
|
|
359
|
+
onEnable: function onEnable() {
|
|
360
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
361
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
362
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
363
|
+
case 0:
|
|
364
|
+
nextConfig.draftMode().enable();
|
|
365
|
+
case 1:
|
|
366
|
+
case "end":
|
|
367
|
+
return _context2.stop();
|
|
427
368
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
369
|
+
}, _callee2);
|
|
370
|
+
}))();
|
|
371
|
+
},
|
|
372
|
+
onDisable: function onDisable() {
|
|
373
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
374
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
375
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
376
|
+
case 0:
|
|
377
|
+
nextConfig.draftMode().disable();
|
|
378
|
+
case 1:
|
|
379
|
+
case "end":
|
|
380
|
+
return _context3.stop();
|
|
431
381
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return _getHost.apply(this, arguments);
|
|
447
|
-
}
|
|
448
|
-
function getValHeaders() {
|
|
449
|
-
try {
|
|
450
|
-
// const cs = cookies(); // TODO: simply get all headers?
|
|
451
|
-
var cs = {
|
|
452
|
-
get: function get(s) {
|
|
453
|
-
return {
|
|
454
|
-
value: s
|
|
455
|
-
};
|
|
382
|
+
}, _callee3);
|
|
383
|
+
}))();
|
|
384
|
+
}
|
|
385
|
+
}), function (valRes) {
|
|
386
|
+
var headers = "headers" in valRes ? new Headers(valRes.headers) : new Headers({});
|
|
387
|
+
if ("cookies" in valRes && valRes.cookies) {
|
|
388
|
+
headers.set("Set-Cookie", "");
|
|
389
|
+
for (var _i = 0, _Object$entries = Object.entries(valRes.cookies); _i < _Object$entries.length; _i++) {
|
|
390
|
+
var _cookie$options, _cookie$options2, _cookie$options3, _cookie$options4, _cookie$options5;
|
|
391
|
+
var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2),
|
|
392
|
+
cookieName = _Object$entries$_i[0],
|
|
393
|
+
cookie = _Object$entries$_i[1];
|
|
394
|
+
var cookieValue = "".concat(cookieName, "=").concat(encodeURIComponent(cookie.value || "")).concat((_cookie$options = cookie.options) !== null && _cookie$options !== void 0 && _cookie$options.httpOnly ? "; HttpOnly" : "").concat((_cookie$options2 = cookie.options) !== null && _cookie$options2 !== void 0 && _cookie$options2.secure ? "; Secure" : "").concat((_cookie$options3 = cookie.options) !== null && _cookie$options3 !== void 0 && _cookie$options3.sameSite ? "; SameSite=".concat(cookie.options.sameSite) : "").concat((_cookie$options4 = cookie.options) !== null && _cookie$options4 !== void 0 && _cookie$options4.path ? "; Path=".concat(cookie.options.path) : "").concat((_cookie$options5 = cookie.options) !== null && _cookie$options5 !== void 0 && _cookie$options5.expires ? "; Expires=".concat(cookie.options.expires.toISOString()) : "".concat(!cookie.value ? "; Max-Age=0" : ""));
|
|
395
|
+
headers.append("Set-Cookie", cookieValue);
|
|
456
396
|
}
|
|
457
|
-
};
|
|
458
|
-
var session = cs.get(core.Internal.VAL_SESSION_COOKIE);
|
|
459
|
-
if (session) {
|
|
460
|
-
return {
|
|
461
|
-
Cookie: "".concat(core.Internal.VAL_SESSION_COOKIE, "=").concat(session.value)
|
|
462
|
-
};
|
|
463
397
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
398
|
+
if ("json" in valRes) {
|
|
399
|
+
headers.set("Content-Type", "application/json");
|
|
400
|
+
return server$1.NextResponse.json(valRes.json, {
|
|
401
|
+
headers: headers,
|
|
402
|
+
status: valRes.status
|
|
403
|
+
});
|
|
404
|
+
} else if (valRes.status === 302) {
|
|
405
|
+
headers.set("Location", valRes.redirectTo);
|
|
406
|
+
return server$1.NextResponse.redirect(valRes.redirectTo, {
|
|
407
|
+
status: valRes.status,
|
|
408
|
+
headers: headers
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return new server$1.NextResponse("body" in valRes ? valRes.body : null, {
|
|
412
|
+
headers: headers,
|
|
413
|
+
status: valRes.status
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
418
|
+
function initValServer(config, nextConfig) {
|
|
419
|
+
return {
|
|
420
|
+
valNextAppRouter: initValNextAppRouter(config, nextConfig)
|
|
421
|
+
};
|
|
477
422
|
}
|
|
478
423
|
|
|
479
|
-
exports.
|
|
424
|
+
exports.initValServer = initValServer;
|
|
@@ -3,28 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('server-only');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var headers = require('next/headers');
|
|
10
|
-
|
|
11
|
-
function _interopNamespace(e) {
|
|
12
|
-
if (e && e.__esModule) return e;
|
|
13
|
-
var n = Object.create(null);
|
|
14
|
-
if (e) {
|
|
15
|
-
Object.keys(e).forEach(function (k) {
|
|
16
|
-
if (k !== 'default') {
|
|
17
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () { return e[k]; }
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
n["default"] = e;
|
|
26
|
-
return Object.freeze(n);
|
|
27
|
-
}
|
|
6
|
+
var slicedToArray = require('../../dist/slicedToArray-4190fac1.cjs.prod.js');
|
|
7
|
+
var server = require('@valbuild/server');
|
|
8
|
+
var server$1 = require('next/server');
|
|
28
9
|
|
|
29
10
|
function _regeneratorRuntime() {
|
|
30
11
|
_regeneratorRuntime = function () {
|
|
@@ -359,121 +340,85 @@ function _asyncToGenerator(fn) {
|
|
|
359
340
|
};
|
|
360
341
|
}
|
|
361
342
|
|
|
362
|
-
var
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
patch: true,
|
|
375
|
-
includeSource: true,
|
|
376
|
-
headers: getValHeaders()
|
|
377
|
-
}).then(function (res) {
|
|
378
|
-
if (fp.result.isOk(res)) {
|
|
379
|
-
var modules = res.value.modules;
|
|
380
|
-
return stega.stegaEncode(selector, {
|
|
381
|
-
getModule: function getModule(moduleId) {
|
|
382
|
-
var module = modules[moduleId];
|
|
383
|
-
if (module) {
|
|
384
|
-
return module.source;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
} else {
|
|
389
|
-
console.error("Val: could not fetch modules", res.error);
|
|
343
|
+
var initValNextAppRouter = function initValNextAppRouter(config, nextConfig) {
|
|
344
|
+
var route = "/api/val"; // TODO: get from config
|
|
345
|
+
return server.createValApiRouter(route, server.createValServer(route, config, {
|
|
346
|
+
isEnabled: function isEnabled() {
|
|
347
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
348
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
349
|
+
while (1) switch (_context.prev = _context.next) {
|
|
350
|
+
case 0:
|
|
351
|
+
return _context.abrupt("return", nextConfig.draftMode().isEnabled);
|
|
352
|
+
case 1:
|
|
353
|
+
case "end":
|
|
354
|
+
return _context.stop();
|
|
390
355
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
function getHost() {
|
|
404
|
-
return _getHost.apply(this, arguments);
|
|
405
|
-
}
|
|
406
|
-
function _getHost() {
|
|
407
|
-
_getHost = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
408
|
-
var _hs$get, _yield$import, headers, hs, host, proto;
|
|
409
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
410
|
-
while (1) switch (_context.prev = _context.next) {
|
|
411
|
-
case 0:
|
|
412
|
-
_context.prev = 0;
|
|
413
|
-
_context.next = 3;
|
|
414
|
-
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('next/headers')); });
|
|
415
|
-
case 3:
|
|
416
|
-
_yield$import = _context.sent;
|
|
417
|
-
headers = _yield$import.headers;
|
|
418
|
-
hs = headers();
|
|
419
|
-
host = hs.get("host");
|
|
420
|
-
proto = "https";
|
|
421
|
-
if (hs.get("x-forwarded-proto") === "http") {
|
|
422
|
-
proto = "http";
|
|
423
|
-
} else if ((_hs$get = hs.get("referer")) !== null && _hs$get !== void 0 && _hs$get.startsWith("http://")) {
|
|
424
|
-
proto = "http";
|
|
425
|
-
} else if (host !== null && host !== void 0 && host.startsWith("localhost")) {
|
|
426
|
-
proto = "http";
|
|
356
|
+
}, _callee);
|
|
357
|
+
}))();
|
|
358
|
+
},
|
|
359
|
+
onEnable: function onEnable() {
|
|
360
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
361
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
362
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
363
|
+
case 0:
|
|
364
|
+
nextConfig.draftMode().enable();
|
|
365
|
+
case 1:
|
|
366
|
+
case "end":
|
|
367
|
+
return _context2.stop();
|
|
427
368
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
369
|
+
}, _callee2);
|
|
370
|
+
}))();
|
|
371
|
+
},
|
|
372
|
+
onDisable: function onDisable() {
|
|
373
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
374
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
375
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
376
|
+
case 0:
|
|
377
|
+
nextConfig.draftMode().disable();
|
|
378
|
+
case 1:
|
|
379
|
+
case "end":
|
|
380
|
+
return _context3.stop();
|
|
431
381
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return _getHost.apply(this, arguments);
|
|
447
|
-
}
|
|
448
|
-
function getValHeaders() {
|
|
449
|
-
try {
|
|
450
|
-
// const cs = cookies(); // TODO: simply get all headers?
|
|
451
|
-
var cs = {
|
|
452
|
-
get: function get(s) {
|
|
453
|
-
return {
|
|
454
|
-
value: s
|
|
455
|
-
};
|
|
382
|
+
}, _callee3);
|
|
383
|
+
}))();
|
|
384
|
+
}
|
|
385
|
+
}), function (valRes) {
|
|
386
|
+
var headers = "headers" in valRes ? new Headers(valRes.headers) : new Headers({});
|
|
387
|
+
if ("cookies" in valRes && valRes.cookies) {
|
|
388
|
+
headers.set("Set-Cookie", "");
|
|
389
|
+
for (var _i = 0, _Object$entries = Object.entries(valRes.cookies); _i < _Object$entries.length; _i++) {
|
|
390
|
+
var _cookie$options, _cookie$options2, _cookie$options3, _cookie$options4, _cookie$options5;
|
|
391
|
+
var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2),
|
|
392
|
+
cookieName = _Object$entries$_i[0],
|
|
393
|
+
cookie = _Object$entries$_i[1];
|
|
394
|
+
var cookieValue = "".concat(cookieName, "=").concat(encodeURIComponent(cookie.value || "")).concat((_cookie$options = cookie.options) !== null && _cookie$options !== void 0 && _cookie$options.httpOnly ? "; HttpOnly" : "").concat((_cookie$options2 = cookie.options) !== null && _cookie$options2 !== void 0 && _cookie$options2.secure ? "; Secure" : "").concat((_cookie$options3 = cookie.options) !== null && _cookie$options3 !== void 0 && _cookie$options3.sameSite ? "; SameSite=".concat(cookie.options.sameSite) : "").concat((_cookie$options4 = cookie.options) !== null && _cookie$options4 !== void 0 && _cookie$options4.path ? "; Path=".concat(cookie.options.path) : "").concat((_cookie$options5 = cookie.options) !== null && _cookie$options5 !== void 0 && _cookie$options5.expires ? "; Expires=".concat(cookie.options.expires.toISOString()) : "".concat(!cookie.value ? "; Max-Age=0" : ""));
|
|
395
|
+
headers.append("Set-Cookie", cookieValue);
|
|
456
396
|
}
|
|
457
|
-
};
|
|
458
|
-
var session = cs.get(core.Internal.VAL_SESSION_COOKIE);
|
|
459
|
-
if (session) {
|
|
460
|
-
return {
|
|
461
|
-
Cookie: "".concat(core.Internal.VAL_SESSION_COOKIE, "=").concat(session.value)
|
|
462
|
-
};
|
|
463
397
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
398
|
+
if ("json" in valRes) {
|
|
399
|
+
headers.set("Content-Type", "application/json");
|
|
400
|
+
return server$1.NextResponse.json(valRes.json, {
|
|
401
|
+
headers: headers,
|
|
402
|
+
status: valRes.status
|
|
403
|
+
});
|
|
404
|
+
} else if (valRes.status === 302) {
|
|
405
|
+
headers.set("Location", valRes.redirectTo);
|
|
406
|
+
return server$1.NextResponse.redirect(valRes.redirectTo, {
|
|
407
|
+
status: valRes.status,
|
|
408
|
+
headers: headers
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return new server$1.NextResponse("body" in valRes ? valRes.body : null, {
|
|
412
|
+
headers: headers,
|
|
413
|
+
status: valRes.status
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
418
|
+
function initValServer(config, nextConfig) {
|
|
419
|
+
return {
|
|
420
|
+
valNextAppRouter: initValNextAppRouter(config, nextConfig)
|
|
421
|
+
};
|
|
477
422
|
}
|
|
478
423
|
|
|
479
|
-
exports.
|
|
424
|
+
exports.initValServer = initValServer;
|