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