@valbuild/next 0.65.0 → 0.65.2

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.
@@ -14,129 +14,157 @@ var version = require('../../dist/version-a9a6a619.cjs.prod.js');
14
14
  stega.SET_RSC(true);
15
15
  var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
16
16
  return function (selector) {
17
- var enabled = false;
18
- try {
19
- enabled = isEnabled();
20
- } catch (err) {
21
- 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);
22
- }
23
- if (enabled) {
24
- stega.SET_AUTO_TAG_JSX_ENABLED(true);
25
- var headers;
26
- try {
27
- headers = getHeaders();
28
- if (!(headers instanceof Headers)) {
29
- throw new Error("Expected an instance of Headers. Check Val rsc config.");
30
- }
31
- } catch (err) {
32
- console.error("Val: could not read headers! fetchVal can only be used server-side. Use useVal on clients.", err);
33
- headers = null;
34
- }
35
- var cookies = function () {
36
- try {
37
- return getCookies();
38
- } catch (err) {
39
- console.error("Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", err);
40
- return null;
41
- }
42
- }();
43
- var host = headers && getHost(headers);
44
- if (host && cookies) {
45
- return valServerPromise.then(/*#__PURE__*/function () {
46
- var _ref = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee(valServer) {
47
- var _cookies$get, _cookies$get2;
48
- var patchesRes, allPatches, treeRes, modules;
49
- return asyncToGenerator._regeneratorRuntime().wrap(function _callee$(_context) {
50
- while (1) switch (_context.prev = _context.next) {
51
- case 0:
52
- _context.next = 2;
53
- return valServer["/patches/~"]["GET"]({
54
- query: {
55
- omit_patch: true,
56
- author: undefined,
57
- patch_id: undefined,
58
- module_file_path: undefined
59
- },
60
- cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies$get = cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies$get === void 0 ? void 0 : _cookies$get.value)
61
- });
62
- case 2:
63
- patchesRes = _context.sent;
64
- if (!(patchesRes.status !== 200)) {
65
- _context.next = 6;
66
- break;
67
- }
68
- console.error("Val: could not fetch patches", patchesRes.json);
69
- throw Error(JSON.stringify(patchesRes.json, null, 2));
70
- case 6:
71
- allPatches = Object.keys(patchesRes.json.patches);
72
- _context.next = 9;
73
- return valServer["/sources"]["PUT"]({
74
- path: "/",
75
- query: {
76
- validate_sources: true,
77
- validate_all: false,
78
- validate_binary_files: false
79
- },
80
- body: {
81
- patchIds: allPatches
82
- },
83
- cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies$get2 = cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies$get2 === void 0 ? void 0 : _cookies$get2.value)
84
- });
85
- case 9:
86
- treeRes = _context.sent;
87
- if (!(treeRes.status === 200)) {
88
- _context.next = 15;
89
- break;
90
- }
91
- modules = treeRes.json.modules;
92
- return _context.abrupt("return", stega.stegaEncode(selector, {
93
- disabled: !enabled,
94
- getModule: function getModule(path) {
95
- var module = modules[path];
96
- if (module) {
97
- return module.source;
98
- }
99
- }
100
- }));
101
- case 15:
102
- if (!(treeRes.status === 401)) {
103
- _context.next = 19;
104
- break;
17
+ var exec = /*#__PURE__*/function () {
18
+ var _ref = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee() {
19
+ var enabled, headers, cookies, host, _cookies, _cookies3, valServer, patchesRes, allPatches, treeRes, modules;
20
+ return asyncToGenerator._regeneratorRuntime().wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ enabled = false;
24
+ _context.prev = 1;
25
+ _context.next = 4;
26
+ return isEnabled();
27
+ case 4:
28
+ enabled = _context.sent;
29
+ _context.next = 10;
30
+ break;
31
+ case 7:
32
+ _context.prev = 7;
33
+ _context.t0 = _context["catch"](1);
34
+ 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.", _context.t0);
35
+ case 10:
36
+ if (!enabled) {
37
+ _context.next = 58;
38
+ break;
39
+ }
40
+ stega.SET_AUTO_TAG_JSX_ENABLED(true);
41
+ _context.prev = 12;
42
+ _context.next = 15;
43
+ return getHeaders();
44
+ case 15:
45
+ headers = _context.sent;
46
+ if (!(typeof headers.get !== "function")) {
47
+ _context.next = 18;
48
+ break;
49
+ }
50
+ throw new Error("Invalid headers");
51
+ case 18:
52
+ _context.next = 24;
53
+ break;
54
+ case 20:
55
+ _context.prev = 20;
56
+ _context.t1 = _context["catch"](12);
57
+ console.error("Val: could not read headers! fetchVal can only be used server-side. Use useVal on clients.", _context.t1);
58
+ headers = null;
59
+ case 24:
60
+ _context.prev = 24;
61
+ _context.next = 27;
62
+ return getCookies();
63
+ case 27:
64
+ cookies = _context.sent;
65
+ _context.next = 34;
66
+ break;
67
+ case 30:
68
+ _context.prev = 30;
69
+ _context.t2 = _context["catch"](24);
70
+ console.error("Val: could not read cookies! fetchVal can only be used server-side. Use useVal on clients.", _context.t2);
71
+ cookies = null;
72
+ case 34:
73
+ host = headers && getHost(headers);
74
+ if (!(host && cookies)) {
75
+ _context.next = 58;
76
+ break;
77
+ }
78
+ _context.next = 38;
79
+ return valServerPromise;
80
+ case 38:
81
+ valServer = _context.sent;
82
+ _context.next = 41;
83
+ return valServer["/patches/~"]["GET"]({
84
+ query: {
85
+ omit_patch: true,
86
+ author: undefined,
87
+ patch_id: undefined,
88
+ module_file_path: undefined
89
+ },
90
+ cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies = cookies) === null || _cookies === void 0 || (_cookies = _cookies.get(internal.VAL_SESSION_COOKIE)) === null || _cookies === void 0 ? void 0 : _cookies.value)
91
+ });
92
+ case 41:
93
+ patchesRes = _context.sent;
94
+ if (!(patchesRes.status !== 200)) {
95
+ _context.next = 44;
96
+ break;
97
+ }
98
+ throw Error(JSON.stringify(patchesRes.json, null, 2));
99
+ case 44:
100
+ allPatches = Object.keys(patchesRes.json.patches);
101
+ _context.next = 47;
102
+ return valServer["/sources"]["PUT"]({
103
+ path: "/",
104
+ query: {
105
+ validate_sources: true,
106
+ validate_all: false,
107
+ validate_binary_files: false
108
+ },
109
+ body: {
110
+ patchIds: allPatches
111
+ },
112
+ cookies: objectSpread2._defineProperty({}, internal.VAL_SESSION_COOKIE, (_cookies3 = cookies) === null || _cookies3 === void 0 || (_cookies3 = _cookies3.get(internal.VAL_SESSION_COOKIE)) === null || _cookies3 === void 0 ? void 0 : _cookies3.value)
113
+ });
114
+ case 47:
115
+ treeRes = _context.sent;
116
+ if (!(treeRes.status === 200)) {
117
+ _context.next = 53;
118
+ break;
119
+ }
120
+ modules = treeRes.json.modules;
121
+ return _context.abrupt("return", stega.stegaEncode(selector, {
122
+ disabled: !enabled,
123
+ getModule: function getModule(path) {
124
+ var module = modules[path];
125
+ if (module) {
126
+ return module.source;
105
127
  }
106
- console.warn("Val: authentication error: ", treeRes.json.message);
107
- _context.next = 21;
108
- break;
109
- case 19:
110
- console.error("Val: could not fetch modules", treeRes.json);
111
- throw Error(JSON.stringify(treeRes.json, null, 2));
112
- case 21:
113
- case "end":
114
- return _context.stop();
128
+ }
129
+ }));
130
+ case 53:
131
+ if (!(treeRes.status === 401)) {
132
+ _context.next = 57;
133
+ break;
115
134
  }
116
- }, _callee);
117
- }));
118
- return function (_x) {
119
- return _ref.apply(this, arguments);
120
- };
121
- }())["catch"](function (err) {
122
- console.error("Val: failed while fetching modules", err);
123
- return stega.stegaEncode(selector, {});
124
- });
125
- }
126
- }
127
- return stega.stegaEncode(selector, {
128
- disabled: !enabled
135
+ console.warn("Val: authentication error: ", treeRes.json.message);
136
+ _context.next = 58;
137
+ break;
138
+ case 57:
139
+ throw Error(JSON.stringify(treeRes.json, null, 2));
140
+ case 58:
141
+ return _context.abrupt("return", stega.stegaEncode(selector, {
142
+ disabled: !enabled
143
+ }));
144
+ case 59:
145
+ case "end":
146
+ return _context.stop();
147
+ }
148
+ }, _callee, null, [[1, 7], [12, 20], [24, 30]]);
149
+ }));
150
+ return function exec() {
151
+ return _ref.apply(this, arguments);
152
+ };
153
+ }();
154
+ return exec()["catch"](function (err) {
155
+ console.error("Val: failed to fetch ", err);
156
+ return stega.stegaEncode(selector, {});
129
157
  });
130
158
  };
131
159
  };
132
160
  function getHost(headers) {
133
161
  var _headers$get;
134
162
  // TODO: does NextJs have a way to determine this?
135
- var host = headers.get("host");
163
+ var host = headers === null || headers === void 0 ? void 0 : headers.get("host");
136
164
  var proto = "https";
137
- if (headers.get("x-forwarded-proto") === "http") {
165
+ if ((headers === null || headers === void 0 ? void 0 : headers.get("x-forwarded-proto")) === "http") {
138
166
  proto = "http";
139
- } else if ((_headers$get = headers.get("referer")) !== null && _headers$get !== void 0 && _headers$get.startsWith("http://")) {
167
+ } else if (headers !== null && headers !== void 0 && (_headers$get = headers.get("referer")) !== null && _headers$get !== void 0 && _headers$get.startsWith("http://")) {
140
168
  proto = "http";
141
169
  } else if (host !== null && host !== void 0 && host.startsWith("localhost")) {
142
170
  proto = "http";
@@ -192,8 +220,11 @@ function initValRsc(config, valModules, rscNextConfig) {
192
220
  return asyncToGenerator._regeneratorRuntime().wrap(function _callee2$(_context2) {
193
221
  while (1) switch (_context2.prev = _context2.next) {
194
222
  case 0:
195
- return _context2.abrupt("return", rscNextConfig.draftMode().isEnabled);
196
- case 1:
223
+ _context2.next = 2;
224
+ return rscNextConfig.draftMode();
225
+ case 2:
226
+ return _context2.abrupt("return", _context2.sent.isEnabled);
227
+ case 3:
197
228
  case "end":
198
229
  return _context2.stop();
199
230
  }
@@ -205,8 +236,11 @@ function initValRsc(config, valModules, rscNextConfig) {
205
236
  return asyncToGenerator._regeneratorRuntime().wrap(function _callee3$(_context3) {
206
237
  while (1) switch (_context3.prev = _context3.next) {
207
238
  case 0:
208
- rscNextConfig.draftMode().enable();
209
- case 1:
239
+ _context3.next = 2;
240
+ return rscNextConfig.draftMode();
241
+ case 2:
242
+ _context3.sent.enable();
243
+ case 3:
210
244
  case "end":
211
245
  return _context3.stop();
212
246
  }
@@ -218,8 +252,11 @@ function initValRsc(config, valModules, rscNextConfig) {
218
252
  return asyncToGenerator._regeneratorRuntime().wrap(function _callee4$(_context4) {
219
253
  while (1) switch (_context4.prev = _context4.next) {
220
254
  case 0:
221
- rscNextConfig.draftMode().disable();
222
- case 1:
255
+ _context4.next = 2;
256
+ return rscNextConfig.draftMode();
257
+ case 2:
258
+ _context4.sent.disable();
259
+ case 3:
223
260
  case "end":
224
261
  return _context4.stop();
225
262
  }
@@ -230,13 +267,46 @@ function initValRsc(config, valModules, rscNextConfig) {
230
267
  return {
231
268
  fetchValStega: initFetchValStega(config, valApiEndpoints,
232
269
  // TODO: get from config
233
- valServerPromise, function () {
234
- return rscNextConfig.draftMode().isEnabled;
235
- }, function () {
236
- return rscNextConfig.headers();
237
- }, function () {
238
- return rscNextConfig.cookies();
239
- })
270
+ valServerPromise, /*#__PURE__*/asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee5() {
271
+ return asyncToGenerator._regeneratorRuntime().wrap(function _callee5$(_context5) {
272
+ while (1) switch (_context5.prev = _context5.next) {
273
+ case 0:
274
+ _context5.next = 2;
275
+ return rscNextConfig.draftMode();
276
+ case 2:
277
+ return _context5.abrupt("return", _context5.sent.isEnabled);
278
+ case 3:
279
+ case "end":
280
+ return _context5.stop();
281
+ }
282
+ }, _callee5);
283
+ })), /*#__PURE__*/asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee6() {
284
+ return asyncToGenerator._regeneratorRuntime().wrap(function _callee6$(_context6) {
285
+ while (1) switch (_context6.prev = _context6.next) {
286
+ case 0:
287
+ _context6.next = 2;
288
+ return rscNextConfig.headers();
289
+ case 2:
290
+ return _context6.abrupt("return", _context6.sent);
291
+ case 3:
292
+ case "end":
293
+ return _context6.stop();
294
+ }
295
+ }, _callee6);
296
+ })), /*#__PURE__*/asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee7() {
297
+ return asyncToGenerator._regeneratorRuntime().wrap(function _callee7$(_context7) {
298
+ while (1) switch (_context7.prev = _context7.next) {
299
+ case 0:
300
+ _context7.next = 2;
301
+ return rscNextConfig.cookies();
302
+ case 2:
303
+ return _context7.abrupt("return", _context7.sent);
304
+ case 3:
305
+ case "end":
306
+ return _context7.stop();
307
+ }
308
+ }, _callee7);
309
+ })))
240
310
  };
241
311
  }
242
312