@valbuild/shared 0.150.18 → 0.151.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +246 -0
  2. package/client/dist/valbuild-shared-client.cjs.dev.js +2 -1
  3. package/client/dist/valbuild-shared-client.cjs.prod.js +2 -1
  4. package/client/dist/valbuild-shared-client.esm.js +1 -1
  5. package/dist/declarations/src/internal/ApiRoutes.d.ts +253 -2
  6. package/dist/declarations/src/internal/content/applyChain.d.ts +124 -0
  7. package/dist/declarations/src/internal/content/buildRegistry.d.ts +36 -0
  8. package/dist/declarations/src/internal/content/jsonValuesOps.d.ts +110 -0
  9. package/dist/declarations/src/internal/content/moduleStore.d.ts +119 -0
  10. package/dist/declarations/src/internal/content/source.d.ts +71 -0
  11. package/dist/declarations/src/internal/content/version.d.ts +151 -0
  12. package/dist/declarations/src/internal/index.d.ts +8 -1
  13. package/dist/declarations/src/internal/publish/projectSource.d.ts +28 -0
  14. package/dist/declarations/src/internal/quickPreview.d.ts +17 -1
  15. package/dist/declarations/src/internal/search/searchIndex.d.ts +34 -3
  16. package/dist/declarations/src/internal/server/types.d.ts +9 -1
  17. package/dist/declarations/src/internal/valCanvasProtocol.d.ts +46 -0
  18. package/dist/declarations/src/internal/valClientHeader.d.ts +36 -0
  19. package/dist/declarations/src/publish/callJson.d.ts +15 -0
  20. package/dist/declarations/src/publish/jobClient.d.ts +7 -1
  21. package/dist/declarations/src/publish/publishClient.d.ts +2 -14
  22. package/dist/{getSitemapTree-7c848c94.esm.js → getSitemapTree-3c1b9e57.esm.js} +37 -4
  23. package/dist/{getSitemapTree-98642b57.cjs.dev.js → getSitemapTree-59c5ed5d.cjs.dev.js} +37 -3
  24. package/dist/{getSitemapTree-97713490.cjs.prod.js → getSitemapTree-6b9024d1.cjs.prod.js} +37 -3
  25. package/dist/{protocol-d0efb8cd.cjs.dev.js → projectSource-2a58ef15.cjs.dev.js} +221 -0
  26. package/dist/{protocol-55cfa3cf.esm.js → projectSource-7f0ee83c.esm.js} +216 -1
  27. package/dist/{protocol-b1055ef0.cjs.prod.js → projectSource-ed6aec39.cjs.prod.js} +221 -0
  28. package/internal/dist/valbuild-shared-internal.cjs.dev.js +2388 -189
  29. package/internal/dist/valbuild-shared-internal.cjs.prod.js +2388 -189
  30. package/internal/dist/valbuild-shared-internal.esm.js +2332 -172
  31. package/package.json +3 -3
  32. package/publish/dist/valbuild-shared-publish.cjs.dev.js +48 -155
  33. package/publish/dist/valbuild-shared-publish.cjs.prod.js +48 -155
  34. package/publish/dist/valbuild-shared-publish.esm.js +17 -123
  35. package/dist/declarations/src/internal/server/requestScopedMemo.d.ts +0 -49
@@ -1,9 +1,176 @@
1
1
  'use strict';
2
2
 
3
+ var createForOfIteratorHelper = require('./createForOfIteratorHelper-9ca2078d.cjs.prod.js');
3
4
  var wrapNativeSuper = require('./wrapNativeSuper-8673414f.cjs.prod.js');
4
5
  var zod = require('zod');
5
6
  var zodValidationError = require('zod-validation-error');
6
7
 
8
+ /*
9
+ * The one JSON call the Studio makes through its own origin's publish proxy,
10
+ * and the errors it throws. Apart from `publishClient.ts` (which re-exports
11
+ * all three) so that a worker can make the same call without importing the
12
+ * publish client's parsers, and `@valbuild/shared` with them.
13
+ */
14
+
15
+ /**
16
+ * Who hears of a refusal's body before it is thrown: the Studio's shell, which
17
+ * says a refusal of the project's plan with the next step (`planRefusal.ts` in
18
+ * `@valbuild/ui`). One listener; setting it again replaces it.
19
+ */
20
+ var refusalListener = null;
21
+ function onPublishRefusal(listener) {
22
+ refusalListener = listener;
23
+ }
24
+
25
+ /** The publish API refused, and said why. */
26
+ var StudioPublishError = /*#__PURE__*/function (_Error) {
27
+ function StudioPublishError(statusCode, message, body) {
28
+ var _this;
29
+ wrapNativeSuper._classCallCheck(this, StudioPublishError);
30
+ _this = wrapNativeSuper._callSuper(this, StudioPublishError, [message]);
31
+ createForOfIteratorHelper._defineProperty(_this, "statusCode", void 0);
32
+ createForOfIteratorHelper._defineProperty(_this, "body", void 0);
33
+ _this.name = "StudioPublishError";
34
+ _this.statusCode = statusCode;
35
+ _this.body = body;
36
+ return _this;
37
+ }
38
+ wrapNativeSuper._inherits(StudioPublishError, _Error);
39
+ return wrapNativeSuper._createClass(StudioPublishError);
40
+ }(/*#__PURE__*/wrapNativeSuper._wrapNativeSuper(Error));
41
+
42
+ /**
43
+ * Was this a failure that asking again could get past?
44
+ *
45
+ * No answer at all (the request never got through) and the answers that mean
46
+ * "not now" -- a timeout, too many requests, a server or gateway error. Every
47
+ * other status is content answering, and the same request gets the same
48
+ * answer.
49
+ */
50
+ function isTransientPublishError(error) {
51
+ if (!(error instanceof StudioPublishError)) return true;
52
+ return error.statusCode >= 500 || error.statusCode === 408 || error.statusCode === 429;
53
+ }
54
+
55
+ /**
56
+ * One JSON call through this origin, with the session cookie: its body, or a
57
+ * `StudioPublishError` carrying the answer's own message.
58
+ */
59
+ function callJson(_x, _x2, _x3, _x4) {
60
+ return _callJson.apply(this, arguments);
61
+ }
62
+
63
+ /**
64
+ * One JSON READ through this origin, BY VERSION: `held` is the answer the
65
+ * caller holds, with its `ETag`, which goes as `If-None-Match`. While the
66
+ * answer is still that one (a 304, with no body) it is `held` again;
67
+ * otherwise the new body, `parse`d, with its `ETag` -- `null` when the answer
68
+ * named none, so there is nothing to hold it by. Errors as {@link callJson}
69
+ * throws them.
70
+ */
71
+ function _callJson() {
72
+ _callJson = createForOfIteratorHelper._asyncToGenerator(/*#__PURE__*/createForOfIteratorHelper._regenerator().m(function _callee(fetchImpl, url, method, body) {
73
+ var res;
74
+ return createForOfIteratorHelper._regenerator().w(function (_context) {
75
+ while (1) switch (_context.n) {
76
+ case 0:
77
+ _context.n = 1;
78
+ return fetchImpl(url, createForOfIteratorHelper._objectSpread2({
79
+ method: method,
80
+ // The session cookie is the whole credential this end has.
81
+ credentials: "same-origin"
82
+ }, body === undefined ? {} : {
83
+ headers: {
84
+ "Content-Type": "application/json"
85
+ },
86
+ body: JSON.stringify(body)
87
+ }));
88
+ case 1:
89
+ res = _context.v;
90
+ return _context.a(2, answerOf(res));
91
+ }
92
+ }, _callee);
93
+ }));
94
+ return _callJson.apply(this, arguments);
95
+ }
96
+ function readJsonByVersion(_x5, _x6, _x7, _x8) {
97
+ return _readJsonByVersion.apply(this, arguments);
98
+ }
99
+
100
+ /** An answer's JSON body, or a `StudioPublishError` with its own message. */
101
+ function _readJsonByVersion() {
102
+ _readJsonByVersion = createForOfIteratorHelper._asyncToGenerator(/*#__PURE__*/createForOfIteratorHelper._regenerator().m(function _callee2(fetchImpl, url, held, parse) {
103
+ var res, value, _t;
104
+ return createForOfIteratorHelper._regenerator().w(function (_context2) {
105
+ while (1) switch (_context2.n) {
106
+ case 0:
107
+ _context2.n = 1;
108
+ return fetchImpl(url, createForOfIteratorHelper._objectSpread2({
109
+ method: "GET",
110
+ // The session cookie is the whole credential this end has.
111
+ credentials: "same-origin"
112
+ }, held !== null ? {
113
+ headers: {
114
+ "If-None-Match": held.etag
115
+ }
116
+ } : {}));
117
+ case 1:
118
+ res = _context2.v;
119
+ if (!(res.status === 304 && held !== null)) {
120
+ _context2.n = 2;
121
+ break;
122
+ }
123
+ return _context2.a(2, held);
124
+ case 2:
125
+ _t = parse;
126
+ _context2.n = 3;
127
+ return answerOf(res);
128
+ case 3:
129
+ value = _t(_context2.v);
130
+ return _context2.a(2, {
131
+ etag: res.headers.get("etag"),
132
+ value: value
133
+ });
134
+ }
135
+ }, _callee2);
136
+ }));
137
+ return _readJsonByVersion.apply(this, arguments);
138
+ }
139
+ function answerOf(_x9) {
140
+ return _answerOf.apply(this, arguments);
141
+ }
142
+ function _answerOf() {
143
+ _answerOf = createForOfIteratorHelper._asyncToGenerator(/*#__PURE__*/createForOfIteratorHelper._regenerator().m(function _callee3(res) {
144
+ var text, parsed, _refusalListener, message;
145
+ return createForOfIteratorHelper._regenerator().w(function (_context3) {
146
+ while (1) switch (_context3.n) {
147
+ case 0:
148
+ _context3.n = 1;
149
+ return res.text();
150
+ case 1:
151
+ text = _context3.v;
152
+ try {
153
+ parsed = text === "" ? undefined : JSON.parse(text);
154
+ } catch (_unused) {
155
+ parsed = undefined;
156
+ }
157
+ if (res.ok) {
158
+ _context3.n = 2;
159
+ break;
160
+ }
161
+ // A publish the plan does not allow (a trial's 3 publishes, a trial that
162
+ // ended): the shell says it, with the next step. See `planRefusal`.
163
+ (_refusalListener = refusalListener) === null || _refusalListener === void 0 || _refusalListener(parsed);
164
+ message = createForOfIteratorHelper._typeof(parsed) === "object" && parsed !== null && "message" in parsed && typeof parsed.message === "string" ? parsed.message : "The publish API answered ".concat(res.status, ".");
165
+ throw new StudioPublishError(res.status, message, parsed);
166
+ case 2:
167
+ return _context3.a(2, parsed);
168
+ }
169
+ }, _callee3);
170
+ }));
171
+ return _answerOf.apply(this, arguments);
172
+ }
173
+
7
174
  function _objectWithoutPropertiesLoose(r, e) {
8
175
  if (null == r) return {};
9
176
  var t = {};
@@ -412,8 +579,61 @@ function parse(schema, body, call) {
412
579
  return parsed.data;
413
580
  }
414
581
 
582
+ /**
583
+ * Where content's publish API is reached: through Val's proxy on this origin
584
+ * (`api`, the Studio), or directly (`publishApi`, `<content>/v1`: home's
585
+ * upgrade page, whose `fetchImpl` adds the project token).
586
+ */
587
+
588
+ function publishApiOf(at) {
589
+ return "publishApi" in at ? at.publishApi.replace(/\/+$/, "") : "".concat(at.api.replace(/\/+$/, ""), "/publish-api");
590
+ }
591
+
592
+ /**
593
+ * The site's live source, BY VERSION: for a reader that asks again and again
594
+ * over a long life -- the Studio's code tools, on every tool call -- rather
595
+ * than once per deploy, as {@link createStudioPublishClient}'s memo does.
596
+ *
597
+ * Each call asks `/project-source` with the `ETag` of the answer it holds
598
+ * (`If-None-Match`), and content answers 304 while it is still that one
599
+ * (valbuild/home sends the tag: the sha256 of its answer). So a publish in
600
+ * between is seen on the next call, and the whole source is sent only when
601
+ * it changed. An answer without a tag (an older content service) is not
602
+ * held: every call reads it again, which is right, if dearer.
603
+ */
604
+ function createProjectSourceReader(options) {
605
+ var _options$fetchImpl;
606
+ var fetchImpl = (_options$fetchImpl = options.fetchImpl) !== null && _options$fetchImpl !== void 0 ? _options$fetchImpl : fetch;
607
+ var url = "".concat(publishApiOf(options), "/project-source");
608
+ var held = null;
609
+ return /*#__PURE__*/createForOfIteratorHelper._asyncToGenerator(/*#__PURE__*/createForOfIteratorHelper._regenerator().m(function _callee() {
610
+ var answer;
611
+ return createForOfIteratorHelper._regenerator().w(function (_context) {
612
+ while (1) switch (_context.n) {
613
+ case 0:
614
+ _context.n = 1;
615
+ return readJsonByVersion(fetchImpl, url, held, function (body) {
616
+ return parseProjectSource(body).files;
617
+ });
618
+ case 1:
619
+ answer = _context.v;
620
+ held = answer.etag !== null ? {
621
+ etag: answer.etag,
622
+ value: answer.value
623
+ } : null;
624
+ return _context.a(2, answer.value);
625
+ }
626
+ }, _callee);
627
+ }));
628
+ }
629
+
415
630
  exports.PublishProtocolError = PublishProtocolError;
631
+ exports.StudioPublishError = StudioPublishError;
416
632
  exports._objectWithoutProperties = _objectWithoutProperties;
633
+ exports.callJson = callJson;
634
+ exports.createProjectSourceReader = createProjectSourceReader;
635
+ exports.isTransientPublishError = isTransientPublishError;
636
+ exports.onPublishRefusal = onPublishRefusal;
417
637
  exports.parseArtifacts = parseArtifacts;
418
638
  exports.parseBuildTarget = parseBuildTarget;
419
639
  exports.parseCancel = parseCancel;
@@ -431,3 +651,4 @@ exports.parseRequestStatus = parseRequestStatus;
431
651
  exports.parseStatus = parseStatus;
432
652
  exports.parseUpdateTarget = parseUpdateTarget;
433
653
  exports.parseVerify = parseVerify;
654
+ exports.publishApiOf = publishApiOf;