@valbuild/next 0.34.0 → 0.36.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 +163 -0
- package/rsc/dist/valbuild-next-rsc.cjs.js +7 -0
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +160 -0
- package/rsc/dist/valbuild-next-rsc.esm.js +159 -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
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { draftMode } from 'next/headers';
|
|
2
|
+
import { _ as _slicedToArray } from '../../dist/slicedToArray-62cd636a.esm.js';
|
|
3
|
+
import { createValApiRouter, createValServer } from '@valbuild/server';
|
|
4
|
+
import { NextResponse } from 'next/server';
|
|
6
5
|
|
|
7
6
|
function _regeneratorRuntime() {
|
|
8
7
|
_regeneratorRuntime = function () {
|
|
@@ -337,121 +336,85 @@ function _asyncToGenerator(fn) {
|
|
|
337
336
|
};
|
|
338
337
|
}
|
|
339
338
|
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
patch: true,
|
|
353
|
-
includeSource: true,
|
|
354
|
-
headers: getValHeaders()
|
|
355
|
-
}).then(function (res) {
|
|
356
|
-
if (result.isOk(res)) {
|
|
357
|
-
var modules = res.value.modules;
|
|
358
|
-
return stegaEncode(selector, {
|
|
359
|
-
getModule: function getModule(moduleId) {
|
|
360
|
-
var module = modules[moduleId];
|
|
361
|
-
if (module) {
|
|
362
|
-
return module.source;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
} else {
|
|
367
|
-
console.error("Val: could not fetch modules", res.error);
|
|
339
|
+
var initValNextAppRouter = function initValNextAppRouter(config, nextConfig) {
|
|
340
|
+
var route = "/api/val"; // TODO: get from config
|
|
341
|
+
return createValApiRouter(route, createValServer(route, config, {
|
|
342
|
+
isEnabled: function isEnabled() {
|
|
343
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
344
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
345
|
+
while (1) switch (_context.prev = _context.next) {
|
|
346
|
+
case 0:
|
|
347
|
+
return _context.abrupt("return", nextConfig.draftMode().isEnabled);
|
|
348
|
+
case 1:
|
|
349
|
+
case "end":
|
|
350
|
+
return _context.stop();
|
|
368
351
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
function getHost() {
|
|
382
|
-
return _getHost.apply(this, arguments);
|
|
383
|
-
}
|
|
384
|
-
function _getHost() {
|
|
385
|
-
_getHost = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
386
|
-
var _hs$get, _yield$import, headers, hs, host, proto;
|
|
387
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
388
|
-
while (1) switch (_context.prev = _context.next) {
|
|
389
|
-
case 0:
|
|
390
|
-
_context.prev = 0;
|
|
391
|
-
_context.next = 3;
|
|
392
|
-
return import('next/headers');
|
|
393
|
-
case 3:
|
|
394
|
-
_yield$import = _context.sent;
|
|
395
|
-
headers = _yield$import.headers;
|
|
396
|
-
hs = headers();
|
|
397
|
-
host = hs.get("host");
|
|
398
|
-
proto = "https";
|
|
399
|
-
if (hs.get("x-forwarded-proto") === "http") {
|
|
400
|
-
proto = "http";
|
|
401
|
-
} else if ((_hs$get = hs.get("referer")) !== null && _hs$get !== void 0 && _hs$get.startsWith("http://")) {
|
|
402
|
-
proto = "http";
|
|
403
|
-
} else if (host !== null && host !== void 0 && host.startsWith("localhost")) {
|
|
404
|
-
proto = "http";
|
|
352
|
+
}, _callee);
|
|
353
|
+
}))();
|
|
354
|
+
},
|
|
355
|
+
onEnable: function onEnable() {
|
|
356
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
357
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
358
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
359
|
+
case 0:
|
|
360
|
+
nextConfig.draftMode().enable();
|
|
361
|
+
case 1:
|
|
362
|
+
case "end":
|
|
363
|
+
return _context2.stop();
|
|
405
364
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
365
|
+
}, _callee2);
|
|
366
|
+
}))();
|
|
367
|
+
},
|
|
368
|
+
onDisable: function onDisable() {
|
|
369
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
370
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
371
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
372
|
+
case 0:
|
|
373
|
+
nextConfig.draftMode().disable();
|
|
374
|
+
case 1:
|
|
375
|
+
case "end":
|
|
376
|
+
return _context3.stop();
|
|
409
377
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return _getHost.apply(this, arguments);
|
|
425
|
-
}
|
|
426
|
-
function getValHeaders() {
|
|
427
|
-
try {
|
|
428
|
-
// const cs = cookies(); // TODO: simply get all headers?
|
|
429
|
-
var cs = {
|
|
430
|
-
get: function get(s) {
|
|
431
|
-
return {
|
|
432
|
-
value: s
|
|
433
|
-
};
|
|
378
|
+
}, _callee3);
|
|
379
|
+
}))();
|
|
380
|
+
}
|
|
381
|
+
}), function (valRes) {
|
|
382
|
+
var headers = "headers" in valRes ? new Headers(valRes.headers) : new Headers({});
|
|
383
|
+
if ("cookies" in valRes && valRes.cookies) {
|
|
384
|
+
headers.set("Set-Cookie", "");
|
|
385
|
+
for (var _i = 0, _Object$entries = Object.entries(valRes.cookies); _i < _Object$entries.length; _i++) {
|
|
386
|
+
var _cookie$options, _cookie$options2, _cookie$options3, _cookie$options4, _cookie$options5;
|
|
387
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
388
|
+
cookieName = _Object$entries$_i[0],
|
|
389
|
+
cookie = _Object$entries$_i[1];
|
|
390
|
+
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" : ""));
|
|
391
|
+
headers.append("Set-Cookie", cookieValue);
|
|
434
392
|
}
|
|
435
|
-
};
|
|
436
|
-
var session = cs.get(Internal.VAL_SESSION_COOKIE);
|
|
437
|
-
if (session) {
|
|
438
|
-
return {
|
|
439
|
-
Cookie: "".concat(Internal.VAL_SESSION_COOKIE, "=").concat(session.value)
|
|
440
|
-
};
|
|
441
393
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
394
|
+
if ("json" in valRes) {
|
|
395
|
+
headers.set("Content-Type", "application/json");
|
|
396
|
+
return NextResponse.json(valRes.json, {
|
|
397
|
+
headers: headers,
|
|
398
|
+
status: valRes.status
|
|
399
|
+
});
|
|
400
|
+
} else if (valRes.status === 302) {
|
|
401
|
+
headers.set("Location", valRes.redirectTo);
|
|
402
|
+
return NextResponse.redirect(valRes.redirectTo, {
|
|
403
|
+
status: valRes.status,
|
|
404
|
+
headers: headers
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
return new NextResponse("body" in valRes ? valRes.body : null, {
|
|
408
|
+
headers: headers,
|
|
409
|
+
status: valRes.status
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
414
|
+
function initValServer(config, nextConfig) {
|
|
415
|
+
return {
|
|
416
|
+
valNextAppRouter: initValNextAppRouter(config, nextConfig)
|
|
417
|
+
};
|
|
455
418
|
}
|
|
456
419
|
|
|
457
|
-
export {
|
|
420
|
+
export { initValServer };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { GenericSelector, SelectorOf, SelectorSource } from "@valbuild/core";
|
|
2
|
-
import { StegaOfSource } from "@valbuild/react/stega";
|
|
3
|
-
export declare function useVal<T extends SelectorSource>(selector: T): SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type StegaOfSource } from "@valbuild/react/stega";
|
|
2
|
-
import { SelectorSource, SelectorOf, GenericSelector } from "@valbuild/core";
|
|
3
|
-
export declare function fetchVal<T extends SelectorSource>(selector: T): SelectorOf<T> extends GenericSelector<infer S> ? Promise<StegaOfSource<S>> : never;
|