@valbuild/core 0.27.0 → 0.29.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.
@@ -1,4 +1,4 @@
1
- import { ApiPatchResponse, ApiTreeResponse } from "./index.js";
1
+ import { ApiGetPatchResponse, ApiPostPatchResponse, ApiTreeResponse } from "./index.js";
2
2
  import { result } from "./fp/index.js";
3
3
  import { PatchJSON } from "./patch/index.js";
4
4
  import { ModuleId } from "./val/index.js";
@@ -11,7 +11,12 @@ export declare class ValApi {
11
11
  constructor(host: string);
12
12
  getDisableUrl(): string;
13
13
  getEditUrl(): string;
14
- postPatches(moduleId: ModuleId, patches: PatchJSON, headers?: Record<string, string> | undefined): Promise<result.Result<ApiPatchResponse, FetchError>>;
14
+ getLoginUrl(redirectTo: string): string;
15
+ getPatches({ patchIds, headers, }: {
16
+ patchIds?: string[];
17
+ headers?: Record<string, string> | undefined;
18
+ }): Promise<result.Result<ApiGetPatchResponse, FetchError>>;
19
+ postPatches(moduleId: ModuleId, patches: PatchJSON, headers?: Record<string, string> | undefined): Promise<result.Result<ApiPostPatchResponse, FetchError>>;
15
20
  getSession(): Promise<result.Result<{
16
21
  mode: "proxy" | "local";
17
22
  member_role: "owner" | "developer" | "editor";
@@ -24,6 +24,7 @@ import { createValPathOfItem } from "./selector/SelectorProxy.js";
24
24
  import { getVal } from "./future/fetchVal.js";
25
25
  import type { Json } from "./Json.js";
26
26
  import { SerializedSchema } from "./schema/index.js";
27
+ import { PatchJSON } from "./patch/index.js";
27
28
  export { ValApi } from "./ValApi.js";
28
29
  export type { SerializedArraySchema } from "./schema/array.js";
29
30
  export type { SerializedObjectSchema } from "./schema/object.js";
@@ -56,7 +57,14 @@ export type ApiTreeResponse = {
56
57
  };
57
58
  }>;
58
59
  };
59
- export type ApiPatchResponse = Record<ModuleId, string[]>;
60
+ export type ApiGetPatchResponse = Record<ModuleId, {
61
+ patch: PatchJSON;
62
+ patch_id: string;
63
+ commit_sha: string;
64
+ author: string;
65
+ created_at: string;
66
+ }[]>;
67
+ export type ApiPostPatchResponse = Record<ModuleId, string[]>;
60
68
  declare const Internal: {
61
69
  convertFileSource: (src: import("./source/file.js").FileSource<import("./schema/image.js").ImageMetadata>) => {
62
70
  url: string;
@@ -1098,6 +1098,41 @@ var ValApi = /*#__PURE__*/function () {
1098
1098
  value: function getEditUrl() {
1099
1099
  return "".concat(this.host, "/static/edit");
1100
1100
  }
1101
+ }, {
1102
+ key: "getLoginUrl",
1103
+ value: function getLoginUrl(redirectTo) {
1104
+ return "".concat(this.host, "/authorize?redirect_to=").concat(encodeURIComponent(redirectTo));
1105
+ }
1106
+ }, {
1107
+ key: "getPatches",
1108
+ value: function () {
1109
+ var _getPatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
1110
+ var patchIds, headers, patchIdsParam;
1111
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1112
+ while (1) switch (_context.prev = _context.next) {
1113
+ case 0:
1114
+ patchIds = _ref.patchIds, headers = _ref.headers;
1115
+ patchIdsParam = patchIds ? "?".concat(patchIds.map(function (id) {
1116
+ return "".concat(id, "=").concat(encodeURIComponent(id));
1117
+ }).join("&")) : "";
1118
+ return _context.abrupt("return", fetch("".concat(this.host, "/patches/~").concat(patchIdsParam), {
1119
+ headers: headers || {
1120
+ "Content-Type": "application/json"
1121
+ }
1122
+ }).then(function (res) {
1123
+ return parse(res);
1124
+ }));
1125
+ case 3:
1126
+ case "end":
1127
+ return _context.stop();
1128
+ }
1129
+ }, _callee, this);
1130
+ }));
1131
+ function getPatches(_x) {
1132
+ return _getPatches.apply(this, arguments);
1133
+ }
1134
+ return getPatches;
1135
+ }()
1101
1136
  }, {
1102
1137
  key: "postPatches",
1103
1138
  value: function postPatches(moduleId, patches, headers) {
@@ -1120,16 +1155,16 @@ var ValApi = /*#__PURE__*/function () {
1120
1155
  }
1121
1156
  }, {
1122
1157
  key: "getModules",
1123
- value: function getModules(_ref) {
1124
- var _ref$patch = _ref.patch,
1125
- patch = _ref$patch === void 0 ? false : _ref$patch,
1126
- _ref$includeSchema = _ref.includeSchema,
1127
- includeSchema = _ref$includeSchema === void 0 ? false : _ref$includeSchema,
1128
- _ref$includeSource = _ref.includeSource,
1129
- includeSource = _ref$includeSource === void 0 ? false : _ref$includeSource,
1130
- _ref$treePath = _ref.treePath,
1131
- treePath = _ref$treePath === void 0 ? "/" : _ref$treePath,
1132
- headers = _ref.headers;
1158
+ value: function getModules(_ref2) {
1159
+ var _ref2$patch = _ref2.patch,
1160
+ patch = _ref2$patch === void 0 ? false : _ref2$patch,
1161
+ _ref2$includeSchema = _ref2.includeSchema,
1162
+ includeSchema = _ref2$includeSchema === void 0 ? false : _ref2$includeSchema,
1163
+ _ref2$includeSource = _ref2.includeSource,
1164
+ includeSource = _ref2$includeSource === void 0 ? false : _ref2$includeSource,
1165
+ _ref2$treePath = _ref2.treePath,
1166
+ treePath = _ref2$treePath === void 0 ? "/" : _ref2$treePath,
1167
+ headers = _ref2.headers;
1133
1168
  var params = new URLSearchParams();
1134
1169
  params.set("patch", patch.toString());
1135
1170
  params.set("schema", includeSchema.toString());
@@ -1145,51 +1180,51 @@ var ValApi = /*#__PURE__*/function () {
1145
1180
  }();
1146
1181
 
1147
1182
  // TODO: validate
1148
- function parse(_x) {
1183
+ function parse(_x2) {
1149
1184
  return _parse.apply(this, arguments);
1150
1185
  }
1151
1186
  function _parse() {
1152
- _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
1153
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1154
- while (1) switch (_context.prev = _context.next) {
1187
+ _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(res) {
1188
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1189
+ while (1) switch (_context2.prev = _context2.next) {
1155
1190
  case 0:
1156
- _context.prev = 0;
1191
+ _context2.prev = 0;
1157
1192
  if (!res.ok) {
1158
- _context.next = 9;
1193
+ _context2.next = 9;
1159
1194
  break;
1160
1195
  }
1161
- _context.t0 = result.result;
1162
- _context.next = 5;
1196
+ _context2.t0 = result.result;
1197
+ _context2.next = 5;
1163
1198
  return res.json();
1164
1199
  case 5:
1165
- _context.t1 = _context.sent;
1166
- return _context.abrupt("return", _context.t0.ok.call(_context.t0, _context.t1));
1200
+ _context2.t1 = _context2.sent;
1201
+ return _context2.abrupt("return", _context2.t0.ok.call(_context2.t0, _context2.t1));
1167
1202
  case 9:
1168
- _context.t2 = result.result;
1169
- _context.t3 = res.status;
1170
- _context.next = 13;
1203
+ _context2.t2 = result.result;
1204
+ _context2.t3 = res.status;
1205
+ _context2.next = 13;
1171
1206
  return res.text();
1172
1207
  case 13:
1173
- _context.t4 = _context.sent;
1174
- _context.t5 = {
1175
- statusCode: _context.t3,
1176
- message: _context.t4
1208
+ _context2.t4 = _context2.sent;
1209
+ _context2.t5 = {
1210
+ statusCode: _context2.t3,
1211
+ message: _context2.t4
1177
1212
  };
1178
- return _context.abrupt("return", _context.t2.err.call(_context.t2, _context.t5));
1213
+ return _context2.abrupt("return", _context2.t2.err.call(_context2.t2, _context2.t5));
1179
1214
  case 16:
1180
- _context.next = 21;
1215
+ _context2.next = 21;
1181
1216
  break;
1182
1217
  case 18:
1183
- _context.prev = 18;
1184
- _context.t6 = _context["catch"](0);
1185
- return _context.abrupt("return", result.err({
1186
- message: _context.t6 instanceof Error ? _context.t6.message : "Unknown error"
1218
+ _context2.prev = 18;
1219
+ _context2.t6 = _context2["catch"](0);
1220
+ return _context2.abrupt("return", result.err({
1221
+ message: _context2.t6 instanceof Error ? _context2.t6.message : "Unknown error"
1187
1222
  }));
1188
1223
  case 21:
1189
1224
  case "end":
1190
- return _context.stop();
1225
+ return _context2.stop();
1191
1226
  }
1192
- }, _callee, null, [[0, 18]]);
1227
+ }, _callee2, null, [[0, 18]]);
1193
1228
  }));
1194
1229
  return _parse.apply(this, arguments);
1195
1230
  }
@@ -1098,6 +1098,41 @@ var ValApi = /*#__PURE__*/function () {
1098
1098
  value: function getEditUrl() {
1099
1099
  return "".concat(this.host, "/static/edit");
1100
1100
  }
1101
+ }, {
1102
+ key: "getLoginUrl",
1103
+ value: function getLoginUrl(redirectTo) {
1104
+ return "".concat(this.host, "/authorize?redirect_to=").concat(encodeURIComponent(redirectTo));
1105
+ }
1106
+ }, {
1107
+ key: "getPatches",
1108
+ value: function () {
1109
+ var _getPatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
1110
+ var patchIds, headers, patchIdsParam;
1111
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1112
+ while (1) switch (_context.prev = _context.next) {
1113
+ case 0:
1114
+ patchIds = _ref.patchIds, headers = _ref.headers;
1115
+ patchIdsParam = patchIds ? "?".concat(patchIds.map(function (id) {
1116
+ return "".concat(id, "=").concat(encodeURIComponent(id));
1117
+ }).join("&")) : "";
1118
+ return _context.abrupt("return", fetch("".concat(this.host, "/patches/~").concat(patchIdsParam), {
1119
+ headers: headers || {
1120
+ "Content-Type": "application/json"
1121
+ }
1122
+ }).then(function (res) {
1123
+ return parse(res);
1124
+ }));
1125
+ case 3:
1126
+ case "end":
1127
+ return _context.stop();
1128
+ }
1129
+ }, _callee, this);
1130
+ }));
1131
+ function getPatches(_x) {
1132
+ return _getPatches.apply(this, arguments);
1133
+ }
1134
+ return getPatches;
1135
+ }()
1101
1136
  }, {
1102
1137
  key: "postPatches",
1103
1138
  value: function postPatches(moduleId, patches, headers) {
@@ -1120,16 +1155,16 @@ var ValApi = /*#__PURE__*/function () {
1120
1155
  }
1121
1156
  }, {
1122
1157
  key: "getModules",
1123
- value: function getModules(_ref) {
1124
- var _ref$patch = _ref.patch,
1125
- patch = _ref$patch === void 0 ? false : _ref$patch,
1126
- _ref$includeSchema = _ref.includeSchema,
1127
- includeSchema = _ref$includeSchema === void 0 ? false : _ref$includeSchema,
1128
- _ref$includeSource = _ref.includeSource,
1129
- includeSource = _ref$includeSource === void 0 ? false : _ref$includeSource,
1130
- _ref$treePath = _ref.treePath,
1131
- treePath = _ref$treePath === void 0 ? "/" : _ref$treePath,
1132
- headers = _ref.headers;
1158
+ value: function getModules(_ref2) {
1159
+ var _ref2$patch = _ref2.patch,
1160
+ patch = _ref2$patch === void 0 ? false : _ref2$patch,
1161
+ _ref2$includeSchema = _ref2.includeSchema,
1162
+ includeSchema = _ref2$includeSchema === void 0 ? false : _ref2$includeSchema,
1163
+ _ref2$includeSource = _ref2.includeSource,
1164
+ includeSource = _ref2$includeSource === void 0 ? false : _ref2$includeSource,
1165
+ _ref2$treePath = _ref2.treePath,
1166
+ treePath = _ref2$treePath === void 0 ? "/" : _ref2$treePath,
1167
+ headers = _ref2.headers;
1133
1168
  var params = new URLSearchParams();
1134
1169
  params.set("patch", patch.toString());
1135
1170
  params.set("schema", includeSchema.toString());
@@ -1145,51 +1180,51 @@ var ValApi = /*#__PURE__*/function () {
1145
1180
  }();
1146
1181
 
1147
1182
  // TODO: validate
1148
- function parse(_x) {
1183
+ function parse(_x2) {
1149
1184
  return _parse.apply(this, arguments);
1150
1185
  }
1151
1186
  function _parse() {
1152
- _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
1153
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1154
- while (1) switch (_context.prev = _context.next) {
1187
+ _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(res) {
1188
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1189
+ while (1) switch (_context2.prev = _context2.next) {
1155
1190
  case 0:
1156
- _context.prev = 0;
1191
+ _context2.prev = 0;
1157
1192
  if (!res.ok) {
1158
- _context.next = 9;
1193
+ _context2.next = 9;
1159
1194
  break;
1160
1195
  }
1161
- _context.t0 = result.result;
1162
- _context.next = 5;
1196
+ _context2.t0 = result.result;
1197
+ _context2.next = 5;
1163
1198
  return res.json();
1164
1199
  case 5:
1165
- _context.t1 = _context.sent;
1166
- return _context.abrupt("return", _context.t0.ok.call(_context.t0, _context.t1));
1200
+ _context2.t1 = _context2.sent;
1201
+ return _context2.abrupt("return", _context2.t0.ok.call(_context2.t0, _context2.t1));
1167
1202
  case 9:
1168
- _context.t2 = result.result;
1169
- _context.t3 = res.status;
1170
- _context.next = 13;
1203
+ _context2.t2 = result.result;
1204
+ _context2.t3 = res.status;
1205
+ _context2.next = 13;
1171
1206
  return res.text();
1172
1207
  case 13:
1173
- _context.t4 = _context.sent;
1174
- _context.t5 = {
1175
- statusCode: _context.t3,
1176
- message: _context.t4
1208
+ _context2.t4 = _context2.sent;
1209
+ _context2.t5 = {
1210
+ statusCode: _context2.t3,
1211
+ message: _context2.t4
1177
1212
  };
1178
- return _context.abrupt("return", _context.t2.err.call(_context.t2, _context.t5));
1213
+ return _context2.abrupt("return", _context2.t2.err.call(_context2.t2, _context2.t5));
1179
1214
  case 16:
1180
- _context.next = 21;
1215
+ _context2.next = 21;
1181
1216
  break;
1182
1217
  case 18:
1183
- _context.prev = 18;
1184
- _context.t6 = _context["catch"](0);
1185
- return _context.abrupt("return", result.err({
1186
- message: _context.t6 instanceof Error ? _context.t6.message : "Unknown error"
1218
+ _context2.prev = 18;
1219
+ _context2.t6 = _context2["catch"](0);
1220
+ return _context2.abrupt("return", result.err({
1221
+ message: _context2.t6 instanceof Error ? _context2.t6.message : "Unknown error"
1187
1222
  }));
1188
1223
  case 21:
1189
1224
  case "end":
1190
- return _context.stop();
1225
+ return _context2.stop();
1191
1226
  }
1192
- }, _callee, null, [[0, 18]]);
1227
+ }, _callee2, null, [[0, 18]]);
1193
1228
  }));
1194
1229
  return _parse.apply(this, arguments);
1195
1230
  }
@@ -1095,6 +1095,41 @@ var ValApi = /*#__PURE__*/function () {
1095
1095
  value: function getEditUrl() {
1096
1096
  return "".concat(this.host, "/static/edit");
1097
1097
  }
1098
+ }, {
1099
+ key: "getLoginUrl",
1100
+ value: function getLoginUrl(redirectTo) {
1101
+ return "".concat(this.host, "/authorize?redirect_to=").concat(encodeURIComponent(redirectTo));
1102
+ }
1103
+ }, {
1104
+ key: "getPatches",
1105
+ value: function () {
1106
+ var _getPatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
1107
+ var patchIds, headers, patchIdsParam;
1108
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1109
+ while (1) switch (_context.prev = _context.next) {
1110
+ case 0:
1111
+ patchIds = _ref.patchIds, headers = _ref.headers;
1112
+ patchIdsParam = patchIds ? "?".concat(patchIds.map(function (id) {
1113
+ return "".concat(id, "=").concat(encodeURIComponent(id));
1114
+ }).join("&")) : "";
1115
+ return _context.abrupt("return", fetch("".concat(this.host, "/patches/~").concat(patchIdsParam), {
1116
+ headers: headers || {
1117
+ "Content-Type": "application/json"
1118
+ }
1119
+ }).then(function (res) {
1120
+ return parse(res);
1121
+ }));
1122
+ case 3:
1123
+ case "end":
1124
+ return _context.stop();
1125
+ }
1126
+ }, _callee, this);
1127
+ }));
1128
+ function getPatches(_x) {
1129
+ return _getPatches.apply(this, arguments);
1130
+ }
1131
+ return getPatches;
1132
+ }()
1098
1133
  }, {
1099
1134
  key: "postPatches",
1100
1135
  value: function postPatches(moduleId, patches, headers) {
@@ -1117,16 +1152,16 @@ var ValApi = /*#__PURE__*/function () {
1117
1152
  }
1118
1153
  }, {
1119
1154
  key: "getModules",
1120
- value: function getModules(_ref) {
1121
- var _ref$patch = _ref.patch,
1122
- patch = _ref$patch === void 0 ? false : _ref$patch,
1123
- _ref$includeSchema = _ref.includeSchema,
1124
- includeSchema = _ref$includeSchema === void 0 ? false : _ref$includeSchema,
1125
- _ref$includeSource = _ref.includeSource,
1126
- includeSource = _ref$includeSource === void 0 ? false : _ref$includeSource,
1127
- _ref$treePath = _ref.treePath,
1128
- treePath = _ref$treePath === void 0 ? "/" : _ref$treePath,
1129
- headers = _ref.headers;
1155
+ value: function getModules(_ref2) {
1156
+ var _ref2$patch = _ref2.patch,
1157
+ patch = _ref2$patch === void 0 ? false : _ref2$patch,
1158
+ _ref2$includeSchema = _ref2.includeSchema,
1159
+ includeSchema = _ref2$includeSchema === void 0 ? false : _ref2$includeSchema,
1160
+ _ref2$includeSource = _ref2.includeSource,
1161
+ includeSource = _ref2$includeSource === void 0 ? false : _ref2$includeSource,
1162
+ _ref2$treePath = _ref2.treePath,
1163
+ treePath = _ref2$treePath === void 0 ? "/" : _ref2$treePath,
1164
+ headers = _ref2.headers;
1130
1165
  var params = new URLSearchParams();
1131
1166
  params.set("patch", patch.toString());
1132
1167
  params.set("schema", includeSchema.toString());
@@ -1142,51 +1177,51 @@ var ValApi = /*#__PURE__*/function () {
1142
1177
  }();
1143
1178
 
1144
1179
  // TODO: validate
1145
- function parse(_x) {
1180
+ function parse(_x2) {
1146
1181
  return _parse.apply(this, arguments);
1147
1182
  }
1148
1183
  function _parse() {
1149
- _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
1150
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1151
- while (1) switch (_context.prev = _context.next) {
1184
+ _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(res) {
1185
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1186
+ while (1) switch (_context2.prev = _context2.next) {
1152
1187
  case 0:
1153
- _context.prev = 0;
1188
+ _context2.prev = 0;
1154
1189
  if (!res.ok) {
1155
- _context.next = 9;
1190
+ _context2.next = 9;
1156
1191
  break;
1157
1192
  }
1158
- _context.t0 = result;
1159
- _context.next = 5;
1193
+ _context2.t0 = result;
1194
+ _context2.next = 5;
1160
1195
  return res.json();
1161
1196
  case 5:
1162
- _context.t1 = _context.sent;
1163
- return _context.abrupt("return", _context.t0.ok.call(_context.t0, _context.t1));
1197
+ _context2.t1 = _context2.sent;
1198
+ return _context2.abrupt("return", _context2.t0.ok.call(_context2.t0, _context2.t1));
1164
1199
  case 9:
1165
- _context.t2 = result;
1166
- _context.t3 = res.status;
1167
- _context.next = 13;
1200
+ _context2.t2 = result;
1201
+ _context2.t3 = res.status;
1202
+ _context2.next = 13;
1168
1203
  return res.text();
1169
1204
  case 13:
1170
- _context.t4 = _context.sent;
1171
- _context.t5 = {
1172
- statusCode: _context.t3,
1173
- message: _context.t4
1205
+ _context2.t4 = _context2.sent;
1206
+ _context2.t5 = {
1207
+ statusCode: _context2.t3,
1208
+ message: _context2.t4
1174
1209
  };
1175
- return _context.abrupt("return", _context.t2.err.call(_context.t2, _context.t5));
1210
+ return _context2.abrupt("return", _context2.t2.err.call(_context2.t2, _context2.t5));
1176
1211
  case 16:
1177
- _context.next = 21;
1212
+ _context2.next = 21;
1178
1213
  break;
1179
1214
  case 18:
1180
- _context.prev = 18;
1181
- _context.t6 = _context["catch"](0);
1182
- return _context.abrupt("return", err({
1183
- message: _context.t6 instanceof Error ? _context.t6.message : "Unknown error"
1215
+ _context2.prev = 18;
1216
+ _context2.t6 = _context2["catch"](0);
1217
+ return _context2.abrupt("return", err({
1218
+ message: _context2.t6 instanceof Error ? _context2.t6.message : "Unknown error"
1184
1219
  }));
1185
1220
  case 21:
1186
1221
  case "end":
1187
- return _context.stop();
1222
+ return _context2.stop();
1188
1223
  }
1189
- }, _callee, null, [[0, 18]]);
1224
+ }, _callee2, null, [[0, 18]]);
1190
1225
  }));
1191
1226
  return _parse.apply(this, arguments);
1192
1227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/core",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "private": false,
5
5
  "description": "Val - supercharged hard-coded content",
6
6
  "scripts": {