@oddington/sdk 0.1.71 → 0.1.73
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/dist/browser.js +560 -228
- package/dist/index.js +4 -4
- package/dist/types/shared/inbox-contract.d.ts +3 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -4890,6 +4890,56 @@ var require_CronExpressionParser = /* @__PURE__ */ __commonJS({
|
|
|
4890
4890
|
}
|
|
4891
4891
|
});
|
|
4892
4892
|
|
|
4893
|
+
function validRecordRef(value) {
|
|
4894
|
+
return typeof value == "string" && value.length <= 512 && /^[_a-zA-Z0-9][a-zA-Z0-9_-]*(\/[_a-zA-Z0-9][a-zA-Z0-9_-]*)+$/.test(value);
|
|
4895
|
+
}
|
|
4896
|
+
|
|
4897
|
+
function validDropboxRootPath(value) {
|
|
4898
|
+
return value === "" || typeof value == "string" && value.length <= 2048 && value.startsWith("/") && !/[\\\x00-\x1f\x7f]/.test(value) && value.slice(1).split("/").every((segment) => segment.length > 0 && segment.trim() === segment && segment !== "." && segment !== "..");
|
|
4899
|
+
}
|
|
4900
|
+
function validMicrosoftId(value) {
|
|
4901
|
+
return typeof value == "string" && /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(value);
|
|
4902
|
+
}
|
|
4903
|
+
function validMicrosoftMailbox(value) {
|
|
4904
|
+
return typeof value == "string" && value.length <= 254 && /^[^\s@/?#\\\x00-\x1f\x7f]+@[^\s@/?#\\\x00-\x1f\x7f]+\.[^\s@/?#\\\x00-\x1f\x7f]+$/.test(value);
|
|
4905
|
+
}
|
|
4906
|
+
function sharePointHost(value) {
|
|
4907
|
+
return /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.sharepoint\.com$/.test(value);
|
|
4908
|
+
}
|
|
4909
|
+
function canonicalSharePointSiteUrl(value) {
|
|
4910
|
+
if (!(typeof value != "string" || value.length > 2048 || /[\s\\?#\x00-\x1f\x7f]/.test(value) || !/^https:\/\/[^/:@]+(?:\/|$)/i.test(value)))
|
|
4911
|
+
try {
|
|
4912
|
+
let url = new URL(value);
|
|
4913
|
+
if (url.protocol !== "https:" || !sharePointHost(url.hostname) || url.username || url.password || url.port) return;
|
|
4914
|
+
let rawPath = value.replace(/^https:\/\/[^/]+/i, "") || "/", path = rawPath.endsWith("/") ? rawPath.slice(0, -1) : rawPath, segments = path.slice(1).split("/");
|
|
4915
|
+
if (path && segments.some((segment) => !segment)) return;
|
|
4916
|
+
let encoded = path ? segments.map((segment) => {
|
|
4917
|
+
let decoded = decodeURIComponent(segment);
|
|
4918
|
+
if (decoded === "." || decoded === ".." || /[/%\\?#\x00-\x1f\x7f]/.test(decoded)) throw new Error();
|
|
4919
|
+
return encodeURIComponent(decoded);
|
|
4920
|
+
}).join("/") : "", canonical = `https://${url.hostname}/${encoded}`;
|
|
4921
|
+
return canonical.length <= 2048 ? canonical : void 0;
|
|
4922
|
+
} catch {
|
|
4923
|
+
return;
|
|
4924
|
+
}
|
|
4925
|
+
}
|
|
4926
|
+
function validSharePointSiteId(value, siteUrl) {
|
|
4927
|
+
if (typeof value != "string" || value.length > 512) return !1;
|
|
4928
|
+
let [host, collection, site, extra] = value.split(",");
|
|
4929
|
+
return extra === void 0 && host === new URL(siteUrl).hostname && validMicrosoftId(collection) && validMicrosoftId(site);
|
|
4930
|
+
}
|
|
4931
|
+
function validGoogleScopes(value) {
|
|
4932
|
+
return Array.isArray(value) && value.length > 0 && value.length <= 32 && value.every((scope) => typeof scope == "string" && scope.length <= 256 && /^(https:\/\/www\.googleapis\.com\/auth\/[A-Za-z0-9._-]+|https:\/\/mail\.google\.com\/|openid|email|profile)$/.test(scope)) && new Set(value).size === value.length;
|
|
4933
|
+
}
|
|
4934
|
+
var DROPBOX_FILE_SCOPES = ["account_info.read", "files.metadata.read", "files.content.read", "files.content.write"];
|
|
4935
|
+
function validDropboxFileScopes(value) {
|
|
4936
|
+
return Array.isArray(value) && value.length === DROPBOX_FILE_SCOPES.length && new Set(value).size === value.length && DROPBOX_FILE_SCOPES.every((scope) => value.includes(scope));
|
|
4937
|
+
}
|
|
4938
|
+
|
|
4939
|
+
function validDataRepositoryName(value) {
|
|
4940
|
+
return typeof value == "string" && /^[a-z0-9][a-z0-9._-]{0,127}$/.test(value) && !value.includes("..");
|
|
4941
|
+
}
|
|
4942
|
+
|
|
4893
4943
|
var fileValidationReasons = {
|
|
4894
4944
|
invalid_metadata: "File metadata must contain only the supported fields.",
|
|
4895
4945
|
invalid_name: "File name must be 1\u2013255 characters, with no reserved names, path separators, control characters or trailing spaces/dots.",
|
|
@@ -5100,184 +5150,6 @@ function parseFileCreateMetadata(value, maxBytes) {
|
|
|
5100
5150
|
};
|
|
5101
5151
|
}
|
|
5102
5152
|
|
|
5103
|
-
var AppRoutineContractError = class extends Error {
|
|
5104
|
-
constructor(code) {
|
|
5105
|
-
super(code);
|
|
5106
|
-
this.code = code;
|
|
5107
|
-
}
|
|
5108
|
-
code;
|
|
5109
|
-
}, propertyName = /^[a-z][A-Za-z0-9]*(?![\s\S])/, stepId = /^[a-z0-9]+(?:-[a-z0-9]+)*(?![\s\S])/, routineName = /^[a-z0-9][a-z0-9-]{0,62}(?![\s\S])/;
|
|
5110
|
-
function isAppRoutineName(value) {
|
|
5111
|
-
return typeof value == "string" && routineName.test(value);
|
|
5112
|
-
}
|
|
5113
|
-
var owns = (value, key) => Object.hasOwn(value, key), invalidContract = () => {
|
|
5114
|
-
throw new AppRoutineContractError("invalid_contract");
|
|
5115
|
-
}, invalidValue = () => {
|
|
5116
|
-
throw new AppRoutineContractError("invalid_value");
|
|
5117
|
-
};
|
|
5118
|
-
function record(value) {
|
|
5119
|
-
return value !== null && typeof value == "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
5120
|
-
}
|
|
5121
|
-
function fields(value, required, optional = []) {
|
|
5122
|
-
return required.every((key) => owns(value, key)) && Object.keys(value).every((key) => required.includes(key) || optional.includes(key));
|
|
5123
|
-
}
|
|
5124
|
-
function denseArray(value) {
|
|
5125
|
-
return Array.isArray(value) && Object.keys(value).length === value.length && Array.from({ length: value.length }, (_, index) => owns(value, String(index))).every(Boolean);
|
|
5126
|
-
}
|
|
5127
|
-
function parseAppRoutineContract(value) {
|
|
5128
|
-
let properties = 0;
|
|
5129
|
-
function schema2(value2, depth = 1) {
|
|
5130
|
-
if (depth > 8 || !record(value2)) return invalidContract();
|
|
5131
|
-
switch (value2.type) {
|
|
5132
|
-
case "object": {
|
|
5133
|
-
if (!fields(value2, ["type", "properties", "additionalProperties"], ["required"]) || value2.additionalProperties !== !1 || !record(value2.properties)) return invalidContract();
|
|
5134
|
-
let entries = Object.entries(value2.properties);
|
|
5135
|
-
if (properties += entries.length, properties > 64 || entries.some(([key]) => !propertyName.test(key))) return invalidContract();
|
|
5136
|
-
let required;
|
|
5137
|
-
if (owns(value2, "required")) {
|
|
5138
|
-
if (!denseArray(value2.required) || value2.required.some((key) => typeof key != "string" || !owns(value2.properties, key)) || new Set(value2.required).size !== value2.required.length) return invalidContract();
|
|
5139
|
-
required = [...value2.required];
|
|
5140
|
-
}
|
|
5141
|
-
return {
|
|
5142
|
-
type: "object",
|
|
5143
|
-
properties: Object.fromEntries(entries.map(([key, child]) => [key, schema2(child, depth + 1)])),
|
|
5144
|
-
...required === void 0 ? {} : { required },
|
|
5145
|
-
additionalProperties: !1
|
|
5146
|
-
};
|
|
5147
|
-
}
|
|
5148
|
-
case "array":
|
|
5149
|
-
return !fields(value2, ["type", "items"], ["maxItems"]) || owns(value2, "maxItems") && (!Number.isSafeInteger(value2.maxItems) || value2.maxItems < 1) ? invalidContract() : {
|
|
5150
|
-
type: "array",
|
|
5151
|
-
items: schema2(value2.items, depth + 1),
|
|
5152
|
-
...owns(value2, "maxItems") ? { maxItems: value2.maxItems } : {}
|
|
5153
|
-
};
|
|
5154
|
-
case "boolean":
|
|
5155
|
-
return fields(value2, ["type"]) ? { type: value2.type } : invalidContract();
|
|
5156
|
-
case "file":
|
|
5157
|
-
return !fields(value2, ["type"], ["storage", "path"]) || owns(value2, "storage") && value2.storage !== "local" && value2.storage !== "remote" || owns(value2, "path") && !safeManagedFilePath(value2.path) ? invalidContract() : {
|
|
5158
|
-
type: "file",
|
|
5159
|
-
...owns(value2, "storage") ? { storage: value2.storage } : {},
|
|
5160
|
-
...owns(value2, "path") ? { path: value2.path } : {}
|
|
5161
|
-
};
|
|
5162
|
-
case "string":
|
|
5163
|
-
return !fields(value2, ["type"], ["maxLength"]) || owns(value2, "maxLength") && (!Number.isSafeInteger(value2.maxLength) || value2.maxLength < 0 || value2.maxLength > 4096) ? invalidContract() : { type: "string", ...owns(value2, "maxLength") ? { maxLength: value2.maxLength } : {} };
|
|
5164
|
-
case "integer":
|
|
5165
|
-
case "number": {
|
|
5166
|
-
let validNumber = value2.type === "integer" ? Number.isSafeInteger : Number.isFinite;
|
|
5167
|
-
return !fields(value2, ["type"], ["minimum", "maximum"]) || owns(value2, "minimum") && !validNumber(value2.minimum) || owns(value2, "maximum") && !validNumber(value2.maximum) || owns(value2, "minimum") && owns(value2, "maximum") && value2.minimum > value2.maximum ? invalidContract() : {
|
|
5168
|
-
type: value2.type,
|
|
5169
|
-
...owns(value2, "minimum") ? { minimum: value2.minimum } : {},
|
|
5170
|
-
...owns(value2, "maximum") ? { maximum: value2.maximum } : {}
|
|
5171
|
-
};
|
|
5172
|
-
}
|
|
5173
|
-
default:
|
|
5174
|
-
return invalidContract();
|
|
5175
|
-
}
|
|
5176
|
-
}
|
|
5177
|
-
if (!record(value) || !fields(value, ["routine", "input", "steps"], ["result"]) || !isAppRoutineName(value.routine) || !denseArray(value.steps) || value.steps.length < 1 || value.steps.length > 64) return invalidContract();
|
|
5178
|
-
let input = schema2(value.input), result2 = owns(value, "result") ? schema2(value.result) : void 0, ids = /* @__PURE__ */ new Set(), steps = value.steps.map((step) => !record(step) || !fields(step, ["id"], ["summary"]) || typeof step.id != "string" || !stepId.test(step.id) || ids.has(step.id) ? invalidContract() : (ids.add(step.id), { id: step.id, ...owns(step, "summary") ? { summary: schema2(step.summary) } : {} }));
|
|
5179
|
-
return { routine: value.routine, input, steps, ...result2 === void 0 ? {} : { result: result2 } };
|
|
5180
|
-
}
|
|
5181
|
-
function jsonData(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
5182
|
-
if (!(value === null || typeof value == "string" || typeof value == "boolean" || typeof value == "number" && Number.isFinite(value))) {
|
|
5183
|
-
if (!record(value) && !denseArray(value) || ancestors.has(value)) return invalidValue();
|
|
5184
|
-
ancestors.add(value);
|
|
5185
|
-
for (let child of Object.values(value)) jsonData(child, ancestors);
|
|
5186
|
-
ancestors.delete(value);
|
|
5187
|
-
}
|
|
5188
|
-
}
|
|
5189
|
-
function validateRoutineSchemaValue(schema2, value, rejected) {
|
|
5190
|
-
let type = (value2) => value2 === null ? "null" : Array.isArray(value2) ? "array" : ["object", "boolean", "string", "number"].includes(typeof value2) ? typeof value2 : "other";
|
|
5191
|
-
function check(schema3, value2, path) {
|
|
5192
|
-
let fail8 = (reason, extra = {}) => (rejected?.({ reason, path: path.length <= 256 ? path : "$", expected: schema3.type, received: type(value2), ...extra }), invalidValue());
|
|
5193
|
-
switch (schema3.type) {
|
|
5194
|
-
case "object":
|
|
5195
|
-
if (!record(value2)) return fail8("wrong_type");
|
|
5196
|
-
for (let key of schema3.required ?? []) if (!owns(value2, key)) return fail8("missing_field", {
|
|
5197
|
-
path: `${path}.${key}`.length <= 256 ? `${path}.${key}` : "$",
|
|
5198
|
-
expected: schema3.properties[key].type,
|
|
5199
|
-
received: "missing"
|
|
5200
|
-
});
|
|
5201
|
-
if (Object.keys(value2).some((key) => !owns(schema3.properties, key))) return fail8("unexpected_field");
|
|
5202
|
-
for (let [key, child] of Object.entries(value2)) check(schema3.properties[key], child, `${path}.${key}`);
|
|
5203
|
-
return;
|
|
5204
|
-
case "array":
|
|
5205
|
-
if (!denseArray(value2)) return fail8("wrong_type");
|
|
5206
|
-
if (schema3.maxItems !== void 0 && value2.length > schema3.maxItems)
|
|
5207
|
-
return fail8("out_of_bounds", { constraint: "maxItems", limit: schema3.maxItems });
|
|
5208
|
-
value2.forEach((child, index) => check(schema3.items, child, `${path}[${index}]`));
|
|
5209
|
-
return;
|
|
5210
|
-
case "boolean":
|
|
5211
|
-
return typeof value2 != "boolean" ? fail8("wrong_type") : void 0;
|
|
5212
|
-
case "string":
|
|
5213
|
-
return typeof value2 != "string" ? fail8("wrong_type") : Array.from(value2).length > (schema3.maxLength ?? 4096) ? fail8("out_of_bounds", { constraint: "maxLength", limit: schema3.maxLength ?? 4096 }) : void 0;
|
|
5214
|
-
case "integer":
|
|
5215
|
-
case "number":
|
|
5216
|
-
return typeof value2 != "number" || !(schema3.type === "integer" ? Number.isSafeInteger(value2) : Number.isFinite(value2)) ? fail8("wrong_type") : schema3.minimum !== void 0 && value2 < schema3.minimum ? fail8("out_of_bounds", { constraint: "minimum", limit: schema3.minimum }) : schema3.maximum !== void 0 && value2 > schema3.maximum ? fail8("out_of_bounds", { constraint: "maximum", limit: schema3.maximum }) : void 0;
|
|
5217
|
-
case "file": {
|
|
5218
|
-
let file2;
|
|
5219
|
-
try {
|
|
5220
|
-
jsonData(value2), file2 = parseFileDescriptor(value2);
|
|
5221
|
-
} catch {
|
|
5222
|
-
return fail8("invalid_file");
|
|
5223
|
-
}
|
|
5224
|
-
if (schema3.path !== void 0 && file2.path !== schema3.path) return fail8("invalid_file");
|
|
5225
|
-
}
|
|
5226
|
-
}
|
|
5227
|
-
}
|
|
5228
|
-
check(schema2, value, "$");
|
|
5229
|
-
}
|
|
5230
|
-
|
|
5231
|
-
function validRecordRef(value) {
|
|
5232
|
-
return typeof value == "string" && value.length <= 512 && /^[_a-zA-Z0-9][a-zA-Z0-9_-]*(\/[_a-zA-Z0-9][a-zA-Z0-9_-]*)+$/.test(value);
|
|
5233
|
-
}
|
|
5234
|
-
|
|
5235
|
-
function validDropboxRootPath(value) {
|
|
5236
|
-
return value === "" || typeof value == "string" && value.length <= 2048 && value.startsWith("/") && !/[\\\x00-\x1f\x7f]/.test(value) && value.slice(1).split("/").every((segment) => segment.length > 0 && segment.trim() === segment && segment !== "." && segment !== "..");
|
|
5237
|
-
}
|
|
5238
|
-
function validMicrosoftId(value) {
|
|
5239
|
-
return typeof value == "string" && /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(value);
|
|
5240
|
-
}
|
|
5241
|
-
function validMicrosoftMailbox(value) {
|
|
5242
|
-
return typeof value == "string" && value.length <= 254 && /^[^\s@/?#\\\x00-\x1f\x7f]+@[^\s@/?#\\\x00-\x1f\x7f]+\.[^\s@/?#\\\x00-\x1f\x7f]+$/.test(value);
|
|
5243
|
-
}
|
|
5244
|
-
function sharePointHost(value) {
|
|
5245
|
-
return /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.sharepoint\.com$/.test(value);
|
|
5246
|
-
}
|
|
5247
|
-
function canonicalSharePointSiteUrl(value) {
|
|
5248
|
-
if (!(typeof value != "string" || value.length > 2048 || /[\s\\?#\x00-\x1f\x7f]/.test(value) || !/^https:\/\/[^/:@]+(?:\/|$)/i.test(value)))
|
|
5249
|
-
try {
|
|
5250
|
-
let url = new URL(value);
|
|
5251
|
-
if (url.protocol !== "https:" || !sharePointHost(url.hostname) || url.username || url.password || url.port) return;
|
|
5252
|
-
let rawPath = value.replace(/^https:\/\/[^/]+/i, "") || "/", path = rawPath.endsWith("/") ? rawPath.slice(0, -1) : rawPath, segments = path.slice(1).split("/");
|
|
5253
|
-
if (path && segments.some((segment) => !segment)) return;
|
|
5254
|
-
let encoded = path ? segments.map((segment) => {
|
|
5255
|
-
let decoded = decodeURIComponent(segment);
|
|
5256
|
-
if (decoded === "." || decoded === ".." || /[/%\\?#\x00-\x1f\x7f]/.test(decoded)) throw new Error();
|
|
5257
|
-
return encodeURIComponent(decoded);
|
|
5258
|
-
}).join("/") : "", canonical = `https://${url.hostname}/${encoded}`;
|
|
5259
|
-
return canonical.length <= 2048 ? canonical : void 0;
|
|
5260
|
-
} catch {
|
|
5261
|
-
return;
|
|
5262
|
-
}
|
|
5263
|
-
}
|
|
5264
|
-
function validSharePointSiteId(value, siteUrl) {
|
|
5265
|
-
if (typeof value != "string" || value.length > 512) return !1;
|
|
5266
|
-
let [host, collection, site, extra] = value.split(",");
|
|
5267
|
-
return extra === void 0 && host === new URL(siteUrl).hostname && validMicrosoftId(collection) && validMicrosoftId(site);
|
|
5268
|
-
}
|
|
5269
|
-
function validGoogleScopes(value) {
|
|
5270
|
-
return Array.isArray(value) && value.length > 0 && value.length <= 32 && value.every((scope) => typeof scope == "string" && scope.length <= 256 && /^(https:\/\/www\.googleapis\.com\/auth\/[A-Za-z0-9._-]+|https:\/\/mail\.google\.com\/|openid|email|profile)$/.test(scope)) && new Set(value).size === value.length;
|
|
5271
|
-
}
|
|
5272
|
-
var DROPBOX_FILE_SCOPES = ["account_info.read", "files.metadata.read", "files.content.read", "files.content.write"];
|
|
5273
|
-
function validDropboxFileScopes(value) {
|
|
5274
|
-
return Array.isArray(value) && value.length === DROPBOX_FILE_SCOPES.length && new Set(value).size === value.length && DROPBOX_FILE_SCOPES.every((scope) => value.includes(scope));
|
|
5275
|
-
}
|
|
5276
|
-
|
|
5277
|
-
function validDataRepositoryName(value) {
|
|
5278
|
-
return typeof value == "string" && /^[a-z0-9][a-z0-9._-]{0,127}$/.test(value) && !value.includes("..");
|
|
5279
|
-
}
|
|
5280
|
-
|
|
5281
5153
|
var InboxContractError = class extends Error {
|
|
5282
5154
|
constructor(message2) {
|
|
5283
5155
|
super(message2), this.name = "InboxContractError";
|
|
@@ -5375,17 +5247,31 @@ function validateBlock(value) {
|
|
|
5375
5247
|
let asks = distinctIds(b.asks, "Ask IDs");
|
|
5376
5248
|
return asks.some((ask) => !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(ask)) && fail("Invalid Ask ID"), { kind: "asks", problem: text(b.problem, "problem"), asks };
|
|
5377
5249
|
}
|
|
5378
|
-
["record", "records", "files"].includes(b.kind) || fail("Unknown Block kind"), keys(b, ["kind", "label", "initiallyExpanded", ...b.kind === "record" ? ["record"] : b.kind === "records" ? ["records"] : ["files"]], "Block");
|
|
5250
|
+
["record", "records", "files"].includes(b.kind) || fail("Unknown Block kind"), keys(b, ["kind", "label", "initiallyExpanded", ...b.kind === "record" ? ["record", "fields"] : b.kind === "records" ? ["records", "previewCount"] : ["files", "previewCount"]], "Block");
|
|
5379
5251
|
let label = text(b.label, "Block label");
|
|
5380
5252
|
b.initiallyExpanded !== void 0 && typeof b.initiallyExpanded != "boolean" && fail("Invalid initiallyExpanded");
|
|
5381
5253
|
let expanded = b.initiallyExpanded === void 0 ? {} : { initiallyExpanded: b.initiallyExpanded };
|
|
5382
|
-
if (b.kind === "record")
|
|
5254
|
+
if (b.kind === "record") {
|
|
5255
|
+
let fields4 = b.fields === void 0 ? void 0 : array(b.fields, "fields").map((value2) => text(value2, "field name"));
|
|
5256
|
+
return fields4 && (!fields4.length || new Set(fields4).size !== fields4.length) && fail("Empty or duplicate fields"), {
|
|
5257
|
+
kind: "record",
|
|
5258
|
+
label,
|
|
5259
|
+
record: validateQualifiedRecordRef(b.record),
|
|
5260
|
+
...fields4 === void 0 ? {} : { fields: fields4 },
|
|
5261
|
+
...expanded
|
|
5262
|
+
};
|
|
5263
|
+
}
|
|
5264
|
+
let preview = (length) => {
|
|
5265
|
+
if (b.previewCount === void 0) return {};
|
|
5266
|
+
let previewCount = natural(b.previewCount, "previewCount", 1);
|
|
5267
|
+
return previewCount > length && fail("previewCount exceeds collection length"), { previewCount };
|
|
5268
|
+
};
|
|
5383
5269
|
if (b.kind === "records") {
|
|
5384
5270
|
let records = array(b.records, "records").map(validateQualifiedRecordRef);
|
|
5385
|
-
return (!records.length || new Set(records.map((r) => JSON.stringify([r.repository, r.ref]))).size !== records.length) && fail("Empty or duplicate records"), { kind: "records", label, records, ...expanded };
|
|
5271
|
+
return (!records.length || new Set(records.map((r) => JSON.stringify([r.repository, r.ref]))).size !== records.length) && fail("Empty or duplicate records"), { kind: "records", label, records, ...preview(records.length), ...expanded };
|
|
5386
5272
|
}
|
|
5387
5273
|
let files3 = array(b.files, "files").map(validateInboxFile);
|
|
5388
|
-
return (!files3.length || new Set(files3.map((file2) => file2.id)).size !== files3.length) && fail("Empty or duplicate files"), { kind: "files", label, files: files3, ...expanded };
|
|
5274
|
+
return (!files3.length || new Set(files3.map((file2) => file2.id)).size !== files3.length) && fail("Empty or duplicate files"), { kind: "files", label, files: files3, ...preview(files3.length), ...expanded };
|
|
5389
5275
|
}
|
|
5390
5276
|
function richTextBlock(value) {
|
|
5391
5277
|
return validateBlock({ ...value, kind: "rich-text" });
|
|
@@ -5517,7 +5403,7 @@ function question(value) {
|
|
|
5517
5403
|
let source2 = object(value, "question");
|
|
5518
5404
|
keys(source2, ["id", "to", "allowedResponders", "prompt", "instructions", "response", "handler"], "question");
|
|
5519
5405
|
let to = personReference(source2.to, "question assignee"), allowedResponders = source2.allowedResponders === void 0 ? [to] : distinctPeople(source2.allowedResponders, "allowed responders");
|
|
5520
|
-
return
|
|
5406
|
+
return {
|
|
5521
5407
|
id: id(source2.id, "question ID"),
|
|
5522
5408
|
to,
|
|
5523
5409
|
allowedResponders,
|
|
@@ -5632,6 +5518,414 @@ function createInboxPublisher(transport) {
|
|
|
5632
5518
|
};
|
|
5633
5519
|
}
|
|
5634
5520
|
|
|
5521
|
+
var RecordSelectionError = class extends InboxContractError {
|
|
5522
|
+
constructor(problem, source2) {
|
|
5523
|
+
let collection = `${source2.collection.repository}/${source2.collection.name}`, messages = {
|
|
5524
|
+
collection_unavailable: `The ${collection} collection is unavailable. Check the collection name and its schema.`,
|
|
5525
|
+
display_fields_invalid: `The label fields for ${collection} must be scalar fields in its schema. Check display.labelFields.`,
|
|
5526
|
+
filter_fields_invalid: `The filters for ${collection} must use scalar schema fields and matching values. Check the Question\u2019s where fields.`,
|
|
5527
|
+
ref_prefix_invalid: `The record reference prefix does not belong to ${collection}. Check refPrefix against the collection\u2019s record references.`,
|
|
5528
|
+
suggestion_unavailable: `A suggested record is missing or isn\u2019t eligible for ${collection}. Update the suggestions and try again.`,
|
|
5529
|
+
selected_record_unavailable: `The selected record is no longer available in ${collection}. Search again and choose a current record.`,
|
|
5530
|
+
label_unavailable: `A record in ${collection} has no value in the configured label fields. Update display.labelFields or the record.`
|
|
5531
|
+
};
|
|
5532
|
+
super(messages[problem]);
|
|
5533
|
+
this.problem = problem;
|
|
5534
|
+
this.name = "RecordSelectionError";
|
|
5535
|
+
}
|
|
5536
|
+
problem;
|
|
5537
|
+
};
|
|
5538
|
+
|
|
5539
|
+
var inboxPublicationRefusals = {
|
|
5540
|
+
"Publication retry changed": {
|
|
5541
|
+
error: "This request key was already used for different content. Use the original content or a new request key.",
|
|
5542
|
+
status: 409
|
|
5543
|
+
},
|
|
5544
|
+
"Active handlers unavailable": {
|
|
5545
|
+
error: "This routine's response handlers are not deployed. Deploy the routine before publishing this Ask.",
|
|
5546
|
+
status: 409
|
|
5547
|
+
},
|
|
5548
|
+
"Handler unavailable": {
|
|
5549
|
+
error: "A response handler used by this Ask is missing from the active routine deployment. Deploy the current routine before publishing again.",
|
|
5550
|
+
status: 409
|
|
5551
|
+
},
|
|
5552
|
+
"Person unavailable": {
|
|
5553
|
+
error: "A recipient or responder is no longer a current member of this workspace. Review the people on this publication and try again.",
|
|
5554
|
+
status: 409
|
|
5555
|
+
},
|
|
5556
|
+
"Linked Ask unavailable to publication": {
|
|
5557
|
+
error: "A linked Ask is unavailable in this workspace. Review the Digest's Ask links.",
|
|
5558
|
+
status: 409
|
|
5559
|
+
},
|
|
5560
|
+
"Linked prepared Ask audience unavailable": {
|
|
5561
|
+
error: "A Digest recipient cannot open one of its linked Asks. Give them access to the Ask or remove the link.",
|
|
5562
|
+
status: 409
|
|
5563
|
+
},
|
|
5564
|
+
"Record repository unavailable": {
|
|
5565
|
+
error: "A repository used by this publication is no longer available. Restore it or run the routine again.",
|
|
5566
|
+
status: 409
|
|
5567
|
+
},
|
|
5568
|
+
"Routine repository unavailable": {
|
|
5569
|
+
error: "This routine no longer has access to a repository used by the publication. Update the routine's repository grant and run it again.",
|
|
5570
|
+
status: 409
|
|
5571
|
+
},
|
|
5572
|
+
"Publisher repository unavailable": {
|
|
5573
|
+
error: "A repository used by this publication is no longer available in this workspace.",
|
|
5574
|
+
status: 409
|
|
5575
|
+
},
|
|
5576
|
+
"Declared repository access required": {
|
|
5577
|
+
error: "This publication needs repository access that the routine has not declared. Add the needed repository to access.repositories with read or write access.",
|
|
5578
|
+
status: 403
|
|
5579
|
+
},
|
|
5580
|
+
"Definition repository access required": {
|
|
5581
|
+
error: "This publication needs repository access that the routine has not declared. Add the needed repository to access.repositories with read or write access.",
|
|
5582
|
+
status: 403
|
|
5583
|
+
},
|
|
5584
|
+
"Retained file unavailable to publication": {
|
|
5585
|
+
error: "A file referenced by this publication is no longer available. Retain it again and retry.",
|
|
5586
|
+
status: 409
|
|
5587
|
+
},
|
|
5588
|
+
"Shared File unavailable to publication": {
|
|
5589
|
+
error: "A file referenced by this publication is no longer available with your current access. Review the file and retry.",
|
|
5590
|
+
status: 409
|
|
5591
|
+
}
|
|
5592
|
+
}, authoringMessages = /* @__PURE__ */ new Set([
|
|
5593
|
+
"Input must be losslessly serializable JSON",
|
|
5594
|
+
"Input cannot contain cycles",
|
|
5595
|
+
"Invalid Inbox file identity or metadata",
|
|
5596
|
+
"File exceeds supported size",
|
|
5597
|
+
"Invalid qualified Record reference",
|
|
5598
|
+
"Invalid Ask ID",
|
|
5599
|
+
"Unknown Block kind",
|
|
5600
|
+
"Invalid initiallyExpanded",
|
|
5601
|
+
"Empty or duplicate records",
|
|
5602
|
+
"Empty or duplicate files",
|
|
5603
|
+
"Invalid shared File descriptor",
|
|
5604
|
+
"Expected authored options",
|
|
5605
|
+
"Choices require at least one option",
|
|
5606
|
+
"Duplicate choice value",
|
|
5607
|
+
"Search permits at most eight unique published suggestions",
|
|
5608
|
+
"Choices require one to nine options",
|
|
5609
|
+
"Invalid Record identity",
|
|
5610
|
+
"Expected Record options",
|
|
5611
|
+
"Invalid collection name",
|
|
5612
|
+
"Invalid Record reference prefix",
|
|
5613
|
+
"Record filters require scalar equality",
|
|
5614
|
+
"Select one or two scalar label fields",
|
|
5615
|
+
"Suggestion belongs to another repository",
|
|
5616
|
+
"Record selection permits at most eight unique suggestions",
|
|
5617
|
+
"Expected a selection definition",
|
|
5618
|
+
"Unsupported option source",
|
|
5619
|
+
"Record belongs to another repository",
|
|
5620
|
+
"Choice was not published",
|
|
5621
|
+
"This choice does not accept a note",
|
|
5622
|
+
"Handler ID must be stable",
|
|
5623
|
+
"Handler results must be stable IDs",
|
|
5624
|
+
"Handler requires a run function",
|
|
5625
|
+
"Duplicate view ID",
|
|
5626
|
+
"Publication requires an explicit kind",
|
|
5627
|
+
"notifyImmediately must be a boolean",
|
|
5628
|
+
"Ask belongs to more than one problem",
|
|
5629
|
+
"Asks Blocks belong to Digests",
|
|
5630
|
+
"Duplicate question ID",
|
|
5631
|
+
"Ask requires at least one recipient",
|
|
5632
|
+
"Ask tag exceeds 64 UTF-8 bytes",
|
|
5633
|
+
"Ask tags exceed bounds or contain duplicates",
|
|
5634
|
+
"Ask Record references contain duplicates",
|
|
5635
|
+
"Unsupported handler transition",
|
|
5636
|
+
"continueAsk would strand the ask without viable work",
|
|
5637
|
+
"Expected revision must be a positive integer",
|
|
5638
|
+
"Initial ask publication must return revision 1",
|
|
5639
|
+
"Allowed responders must include the assignee",
|
|
5640
|
+
"View is unknown or unavailable to this workspace",
|
|
5641
|
+
"Invalid publication request key",
|
|
5642
|
+
"Publication request key is required",
|
|
5643
|
+
"Expected a publication request",
|
|
5644
|
+
"Unsupported publication request fields",
|
|
5645
|
+
"Executable Questions require a trusted routine and compatible handlers"
|
|
5646
|
+
]), authoringLabels = [
|
|
5647
|
+
"JSON array",
|
|
5648
|
+
"JSON input",
|
|
5649
|
+
"Inbox file",
|
|
5650
|
+
"Inbox file ID",
|
|
5651
|
+
"filename",
|
|
5652
|
+
"media type",
|
|
5653
|
+
"file size",
|
|
5654
|
+
"Record reference",
|
|
5655
|
+
"Block",
|
|
5656
|
+
"Rich text Block",
|
|
5657
|
+
"Markdown",
|
|
5658
|
+
"Asks Block",
|
|
5659
|
+
"Ask IDs",
|
|
5660
|
+
"problem",
|
|
5661
|
+
"Block label",
|
|
5662
|
+
"records",
|
|
5663
|
+
"files",
|
|
5664
|
+
"Files Block",
|
|
5665
|
+
"File",
|
|
5666
|
+
"selection",
|
|
5667
|
+
"response definition",
|
|
5668
|
+
"options",
|
|
5669
|
+
"choice",
|
|
5670
|
+
"choice note",
|
|
5671
|
+
"note placeholder",
|
|
5672
|
+
"choice value",
|
|
5673
|
+
"choice label",
|
|
5674
|
+
"choice description",
|
|
5675
|
+
"choice search",
|
|
5676
|
+
"search trigger label",
|
|
5677
|
+
"search placeholder",
|
|
5678
|
+
"search empty label",
|
|
5679
|
+
"suggestions",
|
|
5680
|
+
"suggestion value",
|
|
5681
|
+
"repository",
|
|
5682
|
+
"Record selection",
|
|
5683
|
+
"collection",
|
|
5684
|
+
"collection name",
|
|
5685
|
+
"Record reference prefix",
|
|
5686
|
+
"Record filter",
|
|
5687
|
+
"Record display",
|
|
5688
|
+
"label fields",
|
|
5689
|
+
"suggestion",
|
|
5690
|
+
"suggestion reason",
|
|
5691
|
+
"option source",
|
|
5692
|
+
"response",
|
|
5693
|
+
"response selection",
|
|
5694
|
+
"required note",
|
|
5695
|
+
"handler reference",
|
|
5696
|
+
"handler ID",
|
|
5697
|
+
"handler",
|
|
5698
|
+
"handler results",
|
|
5699
|
+
"question",
|
|
5700
|
+
"question assignee",
|
|
5701
|
+
"allowed responders",
|
|
5702
|
+
"question ID",
|
|
5703
|
+
"question prompt",
|
|
5704
|
+
"instructions",
|
|
5705
|
+
"views",
|
|
5706
|
+
"view",
|
|
5707
|
+
"view ID",
|
|
5708
|
+
"view name",
|
|
5709
|
+
"body",
|
|
5710
|
+
"title",
|
|
5711
|
+
"description",
|
|
5712
|
+
"publication",
|
|
5713
|
+
"digest recipients",
|
|
5714
|
+
"questions",
|
|
5715
|
+
"recipients",
|
|
5716
|
+
"Ask tags",
|
|
5717
|
+
"Ask tag",
|
|
5718
|
+
"Ask Record references",
|
|
5719
|
+
"Ask Record reference",
|
|
5720
|
+
"continueAsk",
|
|
5721
|
+
"resolution",
|
|
5722
|
+
"outcome",
|
|
5723
|
+
"evidence",
|
|
5724
|
+
"transition",
|
|
5725
|
+
"published resolution",
|
|
5726
|
+
"publication options",
|
|
5727
|
+
"publication request key",
|
|
5728
|
+
"ask",
|
|
5729
|
+
"published ask ID",
|
|
5730
|
+
"digest",
|
|
5731
|
+
"published digest ID",
|
|
5732
|
+
"ask ID"
|
|
5733
|
+
], INBOX_PUBLICATION_FAILURE = "Could not confirm publication. Retry with the same request key and content.", authoringAdvice = ". Review the Inbox definition and try again.", memberFailure = "A recipient or responder is not a current workspace member. Review the people on this publication and try again.", fixedMessages = /* @__PURE__ */ new Set([
|
|
5734
|
+
INBOX_PUBLICATION_FAILURE,
|
|
5735
|
+
INBOX_PUBLICATION_TOO_LARGE,
|
|
5736
|
+
memberFailure,
|
|
5737
|
+
...Object.values(inboxPublicationRefusals).map((value) => value.error),
|
|
5738
|
+
"Could not verify publication recipients. Retry with the same content.",
|
|
5739
|
+
"Sign in through the CLI",
|
|
5740
|
+
"Local OS changes require explicit publication",
|
|
5741
|
+
"Resolution requires the original publishing routine",
|
|
5742
|
+
"Publication access is unavailable",
|
|
5743
|
+
"Publication membership or routine context is unavailable",
|
|
5744
|
+
"Publication Run scope differs",
|
|
5745
|
+
"Publication identity or access changed",
|
|
5746
|
+
"Inbox access unavailable",
|
|
5747
|
+
"Invalid routine capability",
|
|
5748
|
+
"File integrity or current publication access unavailable; no item was published"
|
|
5749
|
+
]);
|
|
5750
|
+
function safeInboxPublicationMessage(value) {
|
|
5751
|
+
if (typeof value != "string" || value.length > 2048 || /[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u.test(value)) return;
|
|
5752
|
+
if (fixedMessages.has(value)) return value;
|
|
5753
|
+
let message2 = value.endsWith(authoringAdvice) ? value.slice(0, -authoringAdvice.length) : value;
|
|
5754
|
+
if (authoringMessages.has(message2)) return message2 + authoringAdvice;
|
|
5755
|
+
for (let label of authoringLabels) {
|
|
5756
|
+
if ([
|
|
5757
|
+
"must be a plain object",
|
|
5758
|
+
"must contain only JSON data",
|
|
5759
|
+
"must be nonempty text",
|
|
5760
|
+
"cannot have surrounding whitespace",
|
|
5761
|
+
"must be a dense array",
|
|
5762
|
+
"must not be empty",
|
|
5763
|
+
"contains duplicate IDs",
|
|
5764
|
+
"must be an integer >= 0",
|
|
5765
|
+
"contains an unsupported field"
|
|
5766
|
+
].some((reason) => message2 === `${label} ${reason}`)) return message2 + authoringAdvice;
|
|
5767
|
+
if (message2.startsWith(`${label} does not support `))
|
|
5768
|
+
return `${label} contains an unsupported field` + authoringAdvice;
|
|
5769
|
+
}
|
|
5770
|
+
if (/^.+ is not a current member of the [a-z0-9-]+ workspace$/.test(message2) || /^".+" must be a workspace member UUID or email address$/.test(message2)) return memberFailure;
|
|
5771
|
+
let size = /^Your (Ask|Digest) failed to publish\. Its content is ([0-9]+(?:\.[0-9]{1,2})?) MB, which exceeds the 1 MB limit\. (.+)$/.exec(message2);
|
|
5772
|
+
if (size && Number(size[2]) > 1 && Number(size[2]) <= Number.MAX_SAFE_INTEGER && size[3] === INBOX_PUBLICATION_TOO_LARGE.split("limit. ")[1]) return message2;
|
|
5773
|
+
let collection = /(?:The |for |to |in )([a-z0-9][a-z0-9._/-]{0,127}\/[a-zA-Z0-9_/-]+)(?: collection | must |\.|\? | has )/.exec(message2)?.[1];
|
|
5774
|
+
if (collection && collection.length <= 256) {
|
|
5775
|
+
let slash = collection.indexOf("/");
|
|
5776
|
+
try {
|
|
5777
|
+
let source2 = validateRecordSource({ type: "records", collection: {
|
|
5778
|
+
repository: collection.slice(0, slash),
|
|
5779
|
+
name: collection.slice(slash + 1)
|
|
5780
|
+
}, display: { labelFields: ["name"] } });
|
|
5781
|
+
for (let problem of [
|
|
5782
|
+
"collection_unavailable",
|
|
5783
|
+
"display_fields_invalid",
|
|
5784
|
+
"filter_fields_invalid",
|
|
5785
|
+
"ref_prefix_invalid",
|
|
5786
|
+
"suggestion_unavailable",
|
|
5787
|
+
"selected_record_unavailable",
|
|
5788
|
+
"label_unavailable"
|
|
5789
|
+
])
|
|
5790
|
+
if (new RecordSelectionError(problem, source2).message === message2) return message2;
|
|
5791
|
+
} catch {
|
|
5792
|
+
}
|
|
5793
|
+
}
|
|
5794
|
+
}
|
|
5795
|
+
var InboxPublicationError = class extends Error {
|
|
5796
|
+
constructor(message2) {
|
|
5797
|
+
super(safeInboxPublicationMessage(message2) ?? INBOX_PUBLICATION_FAILURE), this.name = "InboxPublicationError";
|
|
5798
|
+
}
|
|
5799
|
+
};
|
|
5800
|
+
|
|
5801
|
+
var AppRoutineContractError = class extends Error {
|
|
5802
|
+
constructor(code) {
|
|
5803
|
+
super(code);
|
|
5804
|
+
this.code = code;
|
|
5805
|
+
}
|
|
5806
|
+
code;
|
|
5807
|
+
}, propertyName = /^[a-z][A-Za-z0-9]*(?![\s\S])/, stepId = /^[a-z0-9]+(?:-[a-z0-9]+)*(?![\s\S])/, routineName = /^[a-z0-9][a-z0-9-]{0,62}(?![\s\S])/;
|
|
5808
|
+
function isAppRoutineName(value) {
|
|
5809
|
+
return typeof value == "string" && routineName.test(value);
|
|
5810
|
+
}
|
|
5811
|
+
var owns = (value, key) => Object.hasOwn(value, key), invalidContract = () => {
|
|
5812
|
+
throw new AppRoutineContractError("invalid_contract");
|
|
5813
|
+
}, invalidValue = () => {
|
|
5814
|
+
throw new AppRoutineContractError("invalid_value");
|
|
5815
|
+
};
|
|
5816
|
+
function record(value) {
|
|
5817
|
+
return value !== null && typeof value == "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
5818
|
+
}
|
|
5819
|
+
function fields(value, required, optional = []) {
|
|
5820
|
+
return required.every((key) => owns(value, key)) && Object.keys(value).every((key) => required.includes(key) || optional.includes(key));
|
|
5821
|
+
}
|
|
5822
|
+
function denseArray(value) {
|
|
5823
|
+
return Array.isArray(value) && Object.keys(value).length === value.length && Array.from({ length: value.length }, (_, index) => owns(value, String(index))).every(Boolean);
|
|
5824
|
+
}
|
|
5825
|
+
function parseAppRoutineContract(value) {
|
|
5826
|
+
let properties = 0;
|
|
5827
|
+
function schema2(value2, depth = 1) {
|
|
5828
|
+
if (depth > 8 || !record(value2)) return invalidContract();
|
|
5829
|
+
switch (value2.type) {
|
|
5830
|
+
case "object": {
|
|
5831
|
+
if (!fields(value2, ["type", "properties", "additionalProperties"], ["required"]) || value2.additionalProperties !== !1 || !record(value2.properties)) return invalidContract();
|
|
5832
|
+
let entries = Object.entries(value2.properties);
|
|
5833
|
+
if (properties += entries.length, properties > 64 || entries.some(([key]) => !propertyName.test(key))) return invalidContract();
|
|
5834
|
+
let required;
|
|
5835
|
+
if (owns(value2, "required")) {
|
|
5836
|
+
if (!denseArray(value2.required) || value2.required.some((key) => typeof key != "string" || !owns(value2.properties, key)) || new Set(value2.required).size !== value2.required.length) return invalidContract();
|
|
5837
|
+
required = [...value2.required];
|
|
5838
|
+
}
|
|
5839
|
+
return {
|
|
5840
|
+
type: "object",
|
|
5841
|
+
properties: Object.fromEntries(entries.map(([key, child]) => [key, schema2(child, depth + 1)])),
|
|
5842
|
+
...required === void 0 ? {} : { required },
|
|
5843
|
+
additionalProperties: !1
|
|
5844
|
+
};
|
|
5845
|
+
}
|
|
5846
|
+
case "array":
|
|
5847
|
+
return !fields(value2, ["type", "items"], ["maxItems"]) || owns(value2, "maxItems") && (!Number.isSafeInteger(value2.maxItems) || value2.maxItems < 1) ? invalidContract() : {
|
|
5848
|
+
type: "array",
|
|
5849
|
+
items: schema2(value2.items, depth + 1),
|
|
5850
|
+
...owns(value2, "maxItems") ? { maxItems: value2.maxItems } : {}
|
|
5851
|
+
};
|
|
5852
|
+
case "boolean":
|
|
5853
|
+
return fields(value2, ["type"]) ? { type: value2.type } : invalidContract();
|
|
5854
|
+
case "file":
|
|
5855
|
+
return !fields(value2, ["type"], ["storage", "path"]) || owns(value2, "storage") && value2.storage !== "local" && value2.storage !== "remote" || owns(value2, "path") && !safeManagedFilePath(value2.path) ? invalidContract() : {
|
|
5856
|
+
type: "file",
|
|
5857
|
+
...owns(value2, "storage") ? { storage: value2.storage } : {},
|
|
5858
|
+
...owns(value2, "path") ? { path: value2.path } : {}
|
|
5859
|
+
};
|
|
5860
|
+
case "string":
|
|
5861
|
+
return !fields(value2, ["type"], ["maxLength"]) || owns(value2, "maxLength") && (!Number.isSafeInteger(value2.maxLength) || value2.maxLength < 0 || value2.maxLength > 4096) ? invalidContract() : { type: "string", ...owns(value2, "maxLength") ? { maxLength: value2.maxLength } : {} };
|
|
5862
|
+
case "integer":
|
|
5863
|
+
case "number": {
|
|
5864
|
+
let validNumber = value2.type === "integer" ? Number.isSafeInteger : Number.isFinite;
|
|
5865
|
+
return !fields(value2, ["type"], ["minimum", "maximum"]) || owns(value2, "minimum") && !validNumber(value2.minimum) || owns(value2, "maximum") && !validNumber(value2.maximum) || owns(value2, "minimum") && owns(value2, "maximum") && value2.minimum > value2.maximum ? invalidContract() : {
|
|
5866
|
+
type: value2.type,
|
|
5867
|
+
...owns(value2, "minimum") ? { minimum: value2.minimum } : {},
|
|
5868
|
+
...owns(value2, "maximum") ? { maximum: value2.maximum } : {}
|
|
5869
|
+
};
|
|
5870
|
+
}
|
|
5871
|
+
default:
|
|
5872
|
+
return invalidContract();
|
|
5873
|
+
}
|
|
5874
|
+
}
|
|
5875
|
+
if (!record(value) || !fields(value, ["routine", "input", "steps"], ["result"]) || !isAppRoutineName(value.routine) || !denseArray(value.steps) || value.steps.length < 1 || value.steps.length > 64) return invalidContract();
|
|
5876
|
+
let input = schema2(value.input), result2 = owns(value, "result") ? schema2(value.result) : void 0, ids = /* @__PURE__ */ new Set(), steps = value.steps.map((step) => !record(step) || !fields(step, ["id"], ["summary"]) || typeof step.id != "string" || !stepId.test(step.id) || ids.has(step.id) ? invalidContract() : (ids.add(step.id), { id: step.id, ...owns(step, "summary") ? { summary: schema2(step.summary) } : {} }));
|
|
5877
|
+
return { routine: value.routine, input, steps, ...result2 === void 0 ? {} : { result: result2 } };
|
|
5878
|
+
}
|
|
5879
|
+
function jsonData(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
5880
|
+
if (!(value === null || typeof value == "string" || typeof value == "boolean" || typeof value == "number" && Number.isFinite(value))) {
|
|
5881
|
+
if (!record(value) && !denseArray(value) || ancestors.has(value)) return invalidValue();
|
|
5882
|
+
ancestors.add(value);
|
|
5883
|
+
for (let child of Object.values(value)) jsonData(child, ancestors);
|
|
5884
|
+
ancestors.delete(value);
|
|
5885
|
+
}
|
|
5886
|
+
}
|
|
5887
|
+
function validateRoutineSchemaValue(schema2, value, rejected) {
|
|
5888
|
+
let type = (value2) => value2 === null ? "null" : Array.isArray(value2) ? "array" : ["object", "boolean", "string", "number"].includes(typeof value2) ? typeof value2 : "other";
|
|
5889
|
+
function check(schema3, value2, path) {
|
|
5890
|
+
let fail8 = (reason, extra = {}) => (rejected?.({ reason, path: path.length <= 256 ? path : "$", expected: schema3.type, received: type(value2), ...extra }), invalidValue());
|
|
5891
|
+
switch (schema3.type) {
|
|
5892
|
+
case "object":
|
|
5893
|
+
if (!record(value2)) return fail8("wrong_type");
|
|
5894
|
+
for (let key of schema3.required ?? []) if (!owns(value2, key)) return fail8("missing_field", {
|
|
5895
|
+
path: `${path}.${key}`.length <= 256 ? `${path}.${key}` : "$",
|
|
5896
|
+
expected: schema3.properties[key].type,
|
|
5897
|
+
received: "missing"
|
|
5898
|
+
});
|
|
5899
|
+
if (Object.keys(value2).some((key) => !owns(schema3.properties, key))) return fail8("unexpected_field");
|
|
5900
|
+
for (let [key, child] of Object.entries(value2)) check(schema3.properties[key], child, `${path}.${key}`);
|
|
5901
|
+
return;
|
|
5902
|
+
case "array":
|
|
5903
|
+
if (!denseArray(value2)) return fail8("wrong_type");
|
|
5904
|
+
if (schema3.maxItems !== void 0 && value2.length > schema3.maxItems)
|
|
5905
|
+
return fail8("out_of_bounds", { constraint: "maxItems", limit: schema3.maxItems });
|
|
5906
|
+
value2.forEach((child, index) => check(schema3.items, child, `${path}[${index}]`));
|
|
5907
|
+
return;
|
|
5908
|
+
case "boolean":
|
|
5909
|
+
return typeof value2 != "boolean" ? fail8("wrong_type") : void 0;
|
|
5910
|
+
case "string":
|
|
5911
|
+
return typeof value2 != "string" ? fail8("wrong_type") : Array.from(value2).length > (schema3.maxLength ?? 4096) ? fail8("out_of_bounds", { constraint: "maxLength", limit: schema3.maxLength ?? 4096 }) : void 0;
|
|
5912
|
+
case "integer":
|
|
5913
|
+
case "number":
|
|
5914
|
+
return typeof value2 != "number" || !(schema3.type === "integer" ? Number.isSafeInteger(value2) : Number.isFinite(value2)) ? fail8("wrong_type") : schema3.minimum !== void 0 && value2 < schema3.minimum ? fail8("out_of_bounds", { constraint: "minimum", limit: schema3.minimum }) : schema3.maximum !== void 0 && value2 > schema3.maximum ? fail8("out_of_bounds", { constraint: "maximum", limit: schema3.maximum }) : void 0;
|
|
5915
|
+
case "file": {
|
|
5916
|
+
let file2;
|
|
5917
|
+
try {
|
|
5918
|
+
jsonData(value2), file2 = parseFileDescriptor(value2);
|
|
5919
|
+
} catch {
|
|
5920
|
+
return fail8("invalid_file");
|
|
5921
|
+
}
|
|
5922
|
+
if (schema3.path !== void 0 && file2.path !== schema3.path) return fail8("invalid_file");
|
|
5923
|
+
}
|
|
5924
|
+
}
|
|
5925
|
+
}
|
|
5926
|
+
check(schema2, value, "$");
|
|
5927
|
+
}
|
|
5928
|
+
|
|
5635
5929
|
var ROUTINE_DECLARATION_SCHEMA = "https://schemas.oddington.ai/routine/v1.json", ROUTINE_SOURCE_LIMITS = { files: 2e4, bytes: 256 * 1024 * 1024, declarationBytes: 64 * 1024 };
|
|
5636
5930
|
var invalid = (field) => {
|
|
5637
5931
|
throw new Error(`Invalid routine declaration: ${field}`);
|
|
@@ -6835,16 +7129,16 @@ function routineTransport() {
|
|
|
6835
7129
|
return installed;
|
|
6836
7130
|
}
|
|
6837
7131
|
|
|
6838
|
-
var memberContext, memberLifetime, retainedContext;
|
|
6839
|
-
function installMemberContext(resolve, retained = resolve) {
|
|
6840
|
-
return memberLifetime?.abort(), memberLifetime = new AbortController(), memberContext = resolve, retainedContext = retained, () => {
|
|
6841
|
-
memberContext === resolve && (memberLifetime?.abort(), memberContext = void 0, retainedContext = void 0);
|
|
7132
|
+
var memberContext, memberLifetime, retainedContext, inboxContext;
|
|
7133
|
+
function installMemberContext(resolve, retained = resolve, inbox2 = resolve) {
|
|
7134
|
+
return memberLifetime?.abort(), memberLifetime = new AbortController(), memberContext = resolve, retainedContext = retained, inboxContext = inbox2, () => {
|
|
7135
|
+
memberContext === resolve && (memberLifetime?.abort(), memberContext = void 0, retainedContext = void 0, inboxContext = void 0);
|
|
6842
7136
|
};
|
|
6843
7137
|
}
|
|
6844
|
-
async function resolveAppContext(retained = !1) {
|
|
7138
|
+
async function resolveAppContext(retained = !1, inbox2 = !1) {
|
|
6845
7139
|
let host = memberContext;
|
|
6846
7140
|
if (!host) throw new Error("App context unavailable.");
|
|
6847
|
-
let context = await (retained ? retainedContext : host)();
|
|
7141
|
+
let context = await (inbox2 ? inboxContext : retained ? retainedContext : host)();
|
|
6848
7142
|
if (host !== memberContext || !context.isCurrent() || context.expiresAt <= Date.now() || context.kind !== "local" && (typeof context.accessToken != "string" || !/^[^\s]{1,8192}$/.test(context.accessToken)))
|
|
6849
7143
|
throw new Error("App context unavailable.");
|
|
6850
7144
|
return context;
|
|
@@ -9848,7 +10142,9 @@ function parseInboxItem(value) {
|
|
|
9848
10142
|
}
|
|
9849
10143
|
}), array2(item.activity).forEach((value2) => {
|
|
9850
10144
|
let event = object8(value2);
|
|
9851
|
-
assert(integer(event.id) && text4(event.type) && (event.actorId === null || id2(event.actorId)) && (event.questionId === null || text4(event.questionId)) && integer(event.revision) && date(event.createdAt))
|
|
10145
|
+
assert(integer(event.id) && text4(event.type) && (event.actorId === null || id2(event.actorId)) && (event.questionId === null || text4(event.questionId)) && integer(event.revision) && date(event.createdAt));
|
|
10146
|
+
let data3 = object8(event.data);
|
|
10147
|
+
event.type === "recipient-added" && (keys6(data3, ["personId"]), assert(id2(event.actorId) && id2(data3.personId)));
|
|
9852
10148
|
}), array2(item.work).forEach((value2) => {
|
|
9853
10149
|
let work = object8(value2);
|
|
9854
10150
|
assert(id2(work.id) && text4(work.questionId) && text4(work.reason) && optionalDate(work.settledAt));
|
|
@@ -9987,42 +10283,59 @@ var InboxContextError = class extends Error {
|
|
|
9987
10283
|
}
|
|
9988
10284
|
status;
|
|
9989
10285
|
}, contexts = /* @__PURE__ */ new WeakMap();
|
|
9990
|
-
function resolveHostedInboxContext(host) {
|
|
10286
|
+
function resolveHostedInboxContext(host, mode = "fresh") {
|
|
9991
10287
|
if (!host.binding || !host.memberId) throw new Error("Inbox context unavailable");
|
|
9992
10288
|
let resolve = contexts.get(host.binding);
|
|
9993
|
-
return resolve || (resolve = hostedInboxContext(), contexts.set(host.binding, resolve)), resolve({ ...host, memberId: host.memberId });
|
|
10289
|
+
return resolve || (resolve = hostedInboxContext(), contexts.set(host.binding, resolve)), resolve({ ...host, memberId: host.memberId }, mode);
|
|
9994
10290
|
}
|
|
9995
10291
|
function hostedInboxContext() {
|
|
9996
|
-
let installed2, revision = 0, issued = 0, settled = 0;
|
|
9997
|
-
return async (host) => {
|
|
9998
|
-
let
|
|
10292
|
+
let installed2, retained, pending, denied, revision = 0, issued = 0, settled = 0;
|
|
10293
|
+
return async (host, mode = "fresh") => {
|
|
10294
|
+
let check = () => {
|
|
9999
10295
|
if (!host.isCurrent() || host.expiresAt <= Date.now()) throw new Error("Inbox context unavailable");
|
|
10000
10296
|
};
|
|
10001
10297
|
check();
|
|
10002
|
-
let
|
|
10003
|
-
|
|
10004
|
-
|
|
10005
|
-
|
|
10006
|
-
|
|
10007
|
-
|
|
10008
|
-
|
|
10009
|
-
}
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
10298
|
+
let matches2 = (entry2) => entry2.endpoint === host.endpoint && entry2.memberId === host.memberId && entry2.valid();
|
|
10299
|
+
if (mode === "list" && denied && matches2(denied)) throw new InboxContextError(denied.status);
|
|
10300
|
+
let bind = (value) => ({ ...value, isCurrent: () => host.isCurrent() && host.expiresAt > Date.now() && value.isCurrent() });
|
|
10301
|
+
if (mode === "list" && retained && matches2(retained)) return bind(retained.value);
|
|
10302
|
+
if (mode !== "fresh" && pending && matches2(pending)) {
|
|
10303
|
+
let value = await pending.result;
|
|
10304
|
+
return check(), bind(value);
|
|
10305
|
+
}
|
|
10306
|
+
let started = ++issued, valid = host.snapshot?.isCurrent ?? host.isCurrent, invalidate = (status) => {
|
|
10307
|
+
installed2 = void 0, retained = void 0, pending = void 0, denied = { endpoint: host.endpoint, memberId: host.memberId, valid, status }, revision++, settled = ++issued;
|
|
10308
|
+
}, result2 = (async () => {
|
|
10309
|
+
let response2 = await fetch(`${host.endpoint}/api/inbox/context`, {
|
|
10310
|
+
method: "GET",
|
|
10311
|
+
headers: { authorization: `Bearer ${host.accessToken}` },
|
|
10312
|
+
credentials: "omit",
|
|
10313
|
+
redirect: "error",
|
|
10314
|
+
cache: "no-store",
|
|
10315
|
+
signal: AbortSignal.timeout(15e3)
|
|
10316
|
+
});
|
|
10317
|
+
try {
|
|
10318
|
+
if (check(), (response2.status === 401 || response2.status === 403) && invalidate(response2.status), !response2.ok || response2.status !== 200) throw new InboxContextError(response2.status);
|
|
10319
|
+
let bytes = await limitedBody(response2, 4096);
|
|
10320
|
+
if (check(), !bytes) throw new Error("Inbox context unavailable");
|
|
10321
|
+
let value = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(bytes)), combined = value && typeof value == "object" && Object.keys(value).sort().join(",") === "context,current", context = parseInboxHostContext(combined ? value.context : value), current2 = combined ? parseInboxCurrent(value.current) : void 0;
|
|
10322
|
+
if (context.memberId !== host.memberId || context.kind === "inbox" && !current2 || current2 && (context.kind !== "inbox" || current2.viewer.id !== host.memberId || current2.workspace.id !== context.workspaceId || host.endpoint !== `https://${current2.workspace.slug}.oddington.ai`))
|
|
10323
|
+
throw new Error("Inbox context unavailable");
|
|
10017
10324
|
if (started < settled) throw new Error("Inbox context unavailable");
|
|
10018
|
-
installed2 = context, revision
|
|
10325
|
+
JSON.stringify(installed2) !== JSON.stringify(context) && (installed2 = context, revision++), settled = started, denied = void 0;
|
|
10326
|
+
let generation = revision, startup = Object.freeze({ context, current: current2, invalidate, isCurrent: () => valid() && generation === revision });
|
|
10327
|
+
return retained = current2 ? { value: startup, endpoint: host.endpoint, memberId: host.memberId, valid: startup.isCurrent } : void 0, startup;
|
|
10328
|
+
} finally {
|
|
10329
|
+
response2.body?.cancel().catch(() => {
|
|
10330
|
+
});
|
|
10019
10331
|
}
|
|
10020
|
-
|
|
10021
|
-
|
|
10022
|
-
|
|
10332
|
+
})(), entry = { result: result2, endpoint: host.endpoint, memberId: host.memberId, valid };
|
|
10333
|
+
mode !== "fresh" && (pending = entry);
|
|
10334
|
+
try {
|
|
10335
|
+
let value = await result2;
|
|
10336
|
+
return check(), bind(value);
|
|
10023
10337
|
} finally {
|
|
10024
|
-
|
|
10025
|
-
});
|
|
10338
|
+
pending === entry && (pending = void 0);
|
|
10026
10339
|
}
|
|
10027
10340
|
};
|
|
10028
10341
|
}
|
|
@@ -10475,9 +10788,9 @@ var WorkspaceAccessError = class extends Error {
|
|
|
10475
10788
|
|
|
10476
10789
|
var unavailable5 = () => new InboxOperationError(503, "unavailable"), stale = () => new InboxOperationError(401, "authority_unavailable"), contextFailure = (error) => error instanceof WorkspaceAccessError ? new InboxOperationError(error.status, error.status === 401 ? "authority_unavailable" : error.status === 403 ? "access_denied" : "unavailable") : stale();
|
|
10477
10790
|
function hostFailure(error, context) {
|
|
10478
|
-
return !context.isCurrent() || context.expiresAt <= Date.now() || error instanceof InboxContextError && error.status === 401 ? stale() : error instanceof InboxContextError && error.status === 403 ? new InboxOperationError(403, "access_denied") : unavailable5();
|
|
10791
|
+
return !context.isCurrent() || context.expiresAt <= Date.now() || error instanceof InboxContextError && error.status === 401 ? stale() : error instanceof InboxContextError && (error.status === 400 || error.status === 409) ? new InboxOperationError(error.status, error.status === 400 ? "invalid_input" : "conflict") : error instanceof InboxContextError && error.status === 403 ? new InboxOperationError(403, "access_denied") : unavailable5();
|
|
10479
10792
|
}
|
|
10480
|
-
async function send2(operation2, input, resolved) {
|
|
10793
|
+
async function send2(operation2, input, resolved, admitted) {
|
|
10481
10794
|
let envelope = parseInboxRequest({
|
|
10482
10795
|
operation: operation2,
|
|
10483
10796
|
input,
|
|
@@ -10510,7 +10823,7 @@ async function send2(operation2, input, resolved) {
|
|
|
10510
10823
|
let host;
|
|
10511
10824
|
if (!isAppQuestionOperation(operation2)) {
|
|
10512
10825
|
try {
|
|
10513
|
-
host = await resolveHostedInboxContext(context);
|
|
10826
|
+
host = admitted ?? await resolveHostedInboxContext(context);
|
|
10514
10827
|
} catch (error) {
|
|
10515
10828
|
throw hostFailure(error, context);
|
|
10516
10829
|
}
|
|
@@ -10563,22 +10876,41 @@ async function send2(operation2, input, resolved) {
|
|
|
10563
10876
|
}
|
|
10564
10877
|
return parsed;
|
|
10565
10878
|
} catch (error) {
|
|
10566
|
-
throw check(), error instanceof InboxOperationError ? error : unavailable5();
|
|
10879
|
+
throw check(), operation2 === "items.list" && error instanceof InboxOperationError && (error.status === 401 || error.status === 403) && host?.invalidate(error.status), error instanceof InboxOperationError ? error : unavailable5();
|
|
10567
10880
|
}
|
|
10568
10881
|
}
|
|
10569
10882
|
var inbox = {
|
|
10570
|
-
|
|
10883
|
+
async current() {
|
|
10884
|
+
let context;
|
|
10885
|
+
try {
|
|
10886
|
+
context = await resolveAppContext(!1, !0);
|
|
10887
|
+
} catch (error) {
|
|
10888
|
+
throw contextFailure(error);
|
|
10889
|
+
}
|
|
10890
|
+
if (context.kind === "local") throw new InboxOperationError(403, "access_denied");
|
|
10891
|
+
if (context.endpoint !== `https://${context.workspace}.oddington.ai` || ["auth", "www", "api", "os"].includes(context.workspace)) throw stale();
|
|
10892
|
+
let startup;
|
|
10893
|
+
try {
|
|
10894
|
+
startup = await resolveHostedInboxContext(context, "startup");
|
|
10895
|
+
} catch (error) {
|
|
10896
|
+
throw hostFailure(error, context);
|
|
10897
|
+
}
|
|
10898
|
+
if (!startup.isCurrent()) throw stale();
|
|
10899
|
+
if (startup.context.kind !== "inbox") throw new InboxOperationError(403, "access_denied");
|
|
10900
|
+
if (!startup.current) throw unavailable5();
|
|
10901
|
+
return startup.current;
|
|
10902
|
+
},
|
|
10571
10903
|
items: {
|
|
10572
10904
|
async list() {
|
|
10573
10905
|
let items = [], beforeNumber, initial;
|
|
10574
10906
|
try {
|
|
10575
|
-
initial = await resolveAppContext();
|
|
10907
|
+
initial = await resolveAppContext(!1, !0);
|
|
10576
10908
|
} catch (error) {
|
|
10577
10909
|
throw contextFailure(error);
|
|
10578
10910
|
}
|
|
10579
10911
|
let host;
|
|
10580
10912
|
try {
|
|
10581
|
-
host = initial.kind !== "local" && await resolveHostedInboxContext(initial);
|
|
10913
|
+
host = initial.kind !== "local" && await resolveHostedInboxContext(initial, "list");
|
|
10582
10914
|
} catch (error) {
|
|
10583
10915
|
throw hostFailure(error, initial);
|
|
10584
10916
|
}
|
|
@@ -10589,7 +10921,7 @@ var inbox = {
|
|
|
10589
10921
|
};
|
|
10590
10922
|
do {
|
|
10591
10923
|
check();
|
|
10592
|
-
let page = await send2("items.list", beforeNumber === void 0 ? {} : { beforeNumber });
|
|
10924
|
+
let page = await send2("items.list", beforeNumber === void 0 ? {} : { beforeNumber }, initial, host);
|
|
10593
10925
|
if (check(), beforeNumber !== void 0 && (page.items.some((item) => item.number >= beforeNumber) || page.nextBeforeNumber !== null && page.nextBeforeNumber >= beforeNumber)) throw unavailable5();
|
|
10594
10926
|
if (items.push(...page.items), page.nextBeforeNumber === null) return items;
|
|
10595
10927
|
beforeNumber = page.nextBeforeNumber;
|
|
@@ -10689,7 +11021,7 @@ function init({ auth: input }) {
|
|
|
10689
11021
|
requestRetainedRoutine: (key, suffix) => context.requestRetainedRoutine(key, suffix, signal),
|
|
10690
11022
|
requestAvailability: (key) => context.requestRoutine(key, "availability", { method: "GET", signal })
|
|
10691
11023
|
};
|
|
10692
|
-
}, resolve = async () => {
|
|
11024
|
+
}, resolve = async (inbox2 = !1) => {
|
|
10693
11025
|
if (local2) {
|
|
10694
11026
|
if (!active2) throw new Error("Local app context unavailable.");
|
|
10695
11027
|
let context = await local2.resolve();
|
|
@@ -10703,7 +11035,7 @@ function init({ auth: input }) {
|
|
|
10703
11035
|
let expiresAt = (session.expires_at ?? 0) * 1e3;
|
|
10704
11036
|
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() || !session.user.id)
|
|
10705
11037
|
throw new Error("Hosted Data context unavailable.");
|
|
10706
|
-
if (person = session.user.id, updateCredentials({ accessToken: session.access_token, expiresAt }), registered)
|
|
11038
|
+
if (person = session.user.id, updateCredentials({ accessToken: session.access_token, expiresAt }), registered && !inbox2)
|
|
10707
11039
|
try {
|
|
10708
11040
|
await registered.checkWorkspaceAccess();
|
|
10709
11041
|
} catch (error2) {
|
|
@@ -10739,7 +11071,7 @@ function init({ auth: input }) {
|
|
|
10739
11071
|
let context = await local2.retained();
|
|
10740
11072
|
if (!active2) throw new Error("Local app context unavailable.");
|
|
10741
11073
|
return owned(context);
|
|
10742
|
-
} : resolve), dispose = () => {
|
|
11074
|
+
} : resolve, () => resolve(!0)), dispose = () => {
|
|
10743
11075
|
active2 && (active2 = !1, installation.abort(), sharedLocal || local2?.dispose(), revision++, subscription?.unsubscribe(), stopDisposal?.(), uninstall(), installedDispose === dispose && (installedDispose = void 0));
|
|
10744
11076
|
};
|
|
10745
11077
|
installedDispose = dispose, stopDisposal = registered?.onDispose(dispose), active2 && (sharedLocal || (subscription = auth2.onAuthStateChange((event, session) => {
|
|
@@ -11838,7 +12170,7 @@ function routinePublicationClient2(options = {}) {
|
|
|
11838
12170
|
body: JSON.stringify(body),
|
|
11839
12171
|
signal
|
|
11840
12172
|
})), result2 = await response2.json();
|
|
11841
|
-
if (!response2.ok) throw new
|
|
12173
|
+
if (!response2.ok) throw new InboxPublicationError(result2.error);
|
|
11842
12174
|
return result2;
|
|
11843
12175
|
}
|
|
11844
12176
|
return {
|