@oddington/sdk 0.1.80 → 0.1.82
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 +257 -174
- package/dist/index.js +8 -4
- package/dist/types/packages/sdk/src/public.d.ts +7 -1
- package/dist/types/shared/connection-runtime.d.ts +12 -2
- package/dist/types/shared/connections.d.ts +12 -1
- package/dist/types/shared/routine-error.d.ts +23 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -4931,6 +4931,16 @@ function validSharePointSiteId(value, siteUrl) {
|
|
|
4931
4931
|
function validGoogleScopes(value) {
|
|
4932
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
4933
|
}
|
|
4934
|
+
var XERO_SCOPES = [
|
|
4935
|
+
"offline_access",
|
|
4936
|
+
"accounting.invoices",
|
|
4937
|
+
"accounting.payments.read",
|
|
4938
|
+
"accounting.contacts",
|
|
4939
|
+
"accounting.settings.read"
|
|
4940
|
+
];
|
|
4941
|
+
function validXeroScopes(value) {
|
|
4942
|
+
return Array.isArray(value) && value.length === XERO_SCOPES.length && new Set(value).size === value.length && XERO_SCOPES.every((scope) => value.includes(scope));
|
|
4943
|
+
}
|
|
4934
4944
|
var DROPBOX_FILE_SCOPES = ["account_info.read", "files.metadata.read", "files.content.read", "files.content.write"];
|
|
4935
4945
|
function validDropboxFileScopes(value) {
|
|
4936
4946
|
return Array.isArray(value) && value.length === DROPBOX_FILE_SCOPES.length && new Set(value).size === value.length && DROPBOX_FILE_SCOPES.every((scope) => value.includes(scope));
|
|
@@ -6723,89 +6733,6 @@ function parseQueryExecutionPage(value) {
|
|
|
6723
6733
|
return !Array.isArray(v.items) || v.items.length > 500 || v.next !== void 0 && (typeof v.next != "string" || !v.next) ? invalid4() : { items: v.items.map(parseQueryExecution), ...v.next === void 0 ? {} : { next: v.next } };
|
|
6724
6734
|
}
|
|
6725
6735
|
|
|
6726
|
-
var name2 = /^[a-z0-9][a-z0-9-]{0,62}$/, uuid3 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, invalid5 = () => {
|
|
6727
|
-
throw new Error("Run state unavailable");
|
|
6728
|
-
}, record2 = (value) => value && typeof value == "object" && !Array.isArray(value) ? value : invalid5();
|
|
6729
|
-
function time(value) {
|
|
6730
|
-
return typeof value != "string" || value.length > 40 || !Number.isFinite(Date.parse(value)) ? invalid5() : value;
|
|
6731
|
-
}
|
|
6732
|
-
function times(value) {
|
|
6733
|
-
return {
|
|
6734
|
-
...value.startedAt === void 0 ? {} : { startedAt: time(value.startedAt) },
|
|
6735
|
-
...value.finishedAt === void 0 ? {} : { finishedAt: time(value.finishedAt) }
|
|
6736
|
-
};
|
|
6737
|
-
}
|
|
6738
|
-
function bounded(value) {
|
|
6739
|
-
return assertRoutineJson(value), new TextEncoder().encode(JSON.stringify(value)).byteLength > 256 * 1024 ? invalid5() : value;
|
|
6740
|
-
}
|
|
6741
|
-
function progress(value) {
|
|
6742
|
-
if (value === void 0) return {};
|
|
6743
|
-
let v = record2(value);
|
|
6744
|
-
return Object.keys(v).sort().join(",") !== "completed,total" || !Number.isSafeInteger(v.completed) || !Number.isSafeInteger(v.total) || v.completed < 1 || v.completed > v.total ? invalid5() : { progress: { completed: v.completed, total: v.total } };
|
|
6745
|
-
}
|
|
6746
|
-
function parseRunStep(value, expected) {
|
|
6747
|
-
let v = record2(value);
|
|
6748
|
-
if (typeof v.id != "string" || !name2.test(v.id) || expected !== void 0 && v.id !== expected || typeof v.title != "string" || !v.title.trim() || v.title.length > 256 || !["pending", "running", "completed", "failed", "skipped"].includes(v.status)) return invalid5();
|
|
6749
|
-
let output = captureRetainedStepOutput(v.id, {
|
|
6750
|
-
...Object.hasOwn(v, "summary") ? { summary: v.summary } : {},
|
|
6751
|
-
...Object.hasOwn(v, "data") ? { data: v.data } : {}
|
|
6752
|
-
});
|
|
6753
|
-
return {
|
|
6754
|
-
id: v.id,
|
|
6755
|
-
title: v.title,
|
|
6756
|
-
status: v.status,
|
|
6757
|
-
...times(v),
|
|
6758
|
-
...progress(v.progress),
|
|
6759
|
-
...Object.hasOwn(v, "summary") ? { summary: bounded(v.summary) } : {},
|
|
6760
|
-
...Object.hasOwn(output, "data") ? { data: output.data } : {}
|
|
6761
|
-
};
|
|
6762
|
-
}
|
|
6763
|
-
function parseRemoteRun(value, expected = {}) {
|
|
6764
|
-
let v = record2(value);
|
|
6765
|
-
if (typeof v.id != "string" || !uuid3.test(v.id) || expected.id !== void 0 && v.id !== expected.id || typeof v.routine != "string" || !name2.test(v.routine) || expected.routine !== void 0 && v.routine !== expected.routine || v.placement !== "remote" || !["queued", "running", "succeeded", "failed"].includes(v.status) || !Array.isArray(v.steps) || v.steps.length > 64) return invalid5();
|
|
6766
|
-
let steps = v.steps.map((value2) => {
|
|
6767
|
-
let step = record2(value2);
|
|
6768
|
-
return typeof step.detailAvailable != "boolean" || Object.hasOwn(step, "data") ? invalid5() : { ...parseRunStep(step), detailAvailable: step.detailAvailable };
|
|
6769
|
-
});
|
|
6770
|
-
if (new Set(steps.map((step) => step.id)).size !== steps.length) return invalid5();
|
|
6771
|
-
let failure;
|
|
6772
|
-
if (v.failure !== void 0) {
|
|
6773
|
-
let f = record2(v.failure);
|
|
6774
|
-
if (v.status !== "failed" || typeof f.message != "string" || !f.message || f.message.length > 512) return invalid5();
|
|
6775
|
-
if (f.code === "step_output_too_large") {
|
|
6776
|
-
let { code, message: message2, ...facts2 } = f, detail = parseRoutineStepOutputDetail(facts2);
|
|
6777
|
-
if (!steps.some((step) => step.id === detail.step && step.status === "failed") || message2 !== routineStepOutputMessage(detail)) return invalid5();
|
|
6778
|
-
failure = { code, message: message2, ...detail };
|
|
6779
|
-
} else failure = { message: f.message };
|
|
6780
|
-
}
|
|
6781
|
-
return Object.hasOwn(v, "result") && v.status !== "succeeded" ? invalid5() : {
|
|
6782
|
-
id: v.id,
|
|
6783
|
-
routine: v.routine,
|
|
6784
|
-
placement: "remote",
|
|
6785
|
-
status: v.status,
|
|
6786
|
-
createdAt: time(v.createdAt),
|
|
6787
|
-
...times(v),
|
|
6788
|
-
steps,
|
|
6789
|
-
...Object.hasOwn(v, "result") ? { result: bounded(v.result) } : {},
|
|
6790
|
-
...failure ? { failure } : {}
|
|
6791
|
-
};
|
|
6792
|
-
}
|
|
6793
|
-
|
|
6794
|
-
function routineRunHandle(operations2) {
|
|
6795
|
-
return Object.freeze({
|
|
6796
|
-
current: operations2.current,
|
|
6797
|
-
step: operations2.step,
|
|
6798
|
-
async *watch() {
|
|
6799
|
-
let previous;
|
|
6800
|
-
for (; ; ) {
|
|
6801
|
-
let state = await operations2.current(), encoded = JSON.stringify(state);
|
|
6802
|
-
if (encoded !== previous && (previous = encoded, yield state), state.status === "succeeded" || state.status === "failed" || state.status === "legacy") return;
|
|
6803
|
-
await (operations2.wait?.() ?? new Promise((resolve) => setTimeout(resolve, 100)));
|
|
6804
|
-
}
|
|
6805
|
-
}
|
|
6806
|
-
});
|
|
6807
|
-
}
|
|
6808
|
-
|
|
6809
6736
|
var fieldProblems = ["unknown", "missing", "invalid", "source_schema"], reasons = {
|
|
6810
6737
|
unknown: "unknown_field",
|
|
6811
6738
|
missing: "missing_field",
|
|
@@ -7021,6 +6948,209 @@ var DataOperationError = class extends Error {
|
|
|
7021
6948
|
detail;
|
|
7022
6949
|
};
|
|
7023
6950
|
|
|
6951
|
+
var identityPattern = /^(gmail|airtable|dropbox|outlook|sharepoint|xero)\/([a-z0-9][a-z0-9-]{0,62})$/, workspacePattern = /^[a-z0-9][a-z0-9-]{0,62}$/, providerNames = {
|
|
6952
|
+
gmail: "Gmail",
|
|
6953
|
+
airtable: "Airtable",
|
|
6954
|
+
dropbox: "Dropbox",
|
|
6955
|
+
outlook: "Outlook",
|
|
6956
|
+
sharepoint: "SharePoint",
|
|
6957
|
+
xero: "Xero"
|
|
6958
|
+
};
|
|
6959
|
+
function parseConnectionFailureDetail(value) {
|
|
6960
|
+
if (!value || typeof value != "object" || Array.isArray(value)) throw new Error("Invalid Connection failure");
|
|
6961
|
+
let v = value;
|
|
6962
|
+
if (Object.keys(v).some((key) => !["identity", "workspace", "code", "stage", "retryable", "attempts", "elapsedMs", "status"].includes(key)) || typeof v.identity != "string" || !identityPattern.test(v.identity) || v.workspace !== void 0 && (typeof v.workspace != "string" || !workspacePattern.test(v.workspace)) || !["temporarily_unavailable", "attention_required", "invalid_response"].includes(v.code) || !["authorization", "provider", "finalization", "transport", "validation"].includes(v.stage) || v.retryable !== (v.code === "temporarily_unavailable") || !Number.isSafeInteger(v.attempts) || v.attempts < 0 || v.attempts > 3 || !Number.isSafeInteger(v.elapsedMs) || v.elapsedMs < 0 || Object.hasOwn(v, "status") && (!Number.isSafeInteger(v.status) || v.status < 100 || v.status > 599))
|
|
6963
|
+
throw new Error("Invalid Connection failure");
|
|
6964
|
+
return {
|
|
6965
|
+
identity: v.identity,
|
|
6966
|
+
...v.workspace === void 0 ? {} : { workspace: v.workspace },
|
|
6967
|
+
code: v.code,
|
|
6968
|
+
stage: v.stage,
|
|
6969
|
+
retryable: v.retryable,
|
|
6970
|
+
attempts: v.attempts,
|
|
6971
|
+
elapsedMs: v.elapsedMs,
|
|
6972
|
+
...Object.hasOwn(v, "status") ? { status: v.status } : {}
|
|
6973
|
+
};
|
|
6974
|
+
}
|
|
6975
|
+
function connectionFailureMessage(value) {
|
|
6976
|
+
let detail = parseConnectionFailureDetail(value), [, provider2, name4] = identityPattern.exec(detail.identity), duration = detail.elapsedMs < 1e3 ? `${detail.elapsedMs}ms` : `${(detail.elapsedMs / 1e3).toFixed(1)}s`, explanation = `OS couldn\u2019t grant this Run access to ${providerNames[provider2]} connection ${name4}.
|
|
6977
|
+
${detail.attempts} ${detail.attempts === 1 ? "attempt" : "attempts"} in ${duration}.
|
|
6978
|
+
|
|
6979
|
+
The routine received no provider access through this lease and made no provider business request through it.`;
|
|
6980
|
+
return detail.code !== "attention_required" ? explanation : detail.workspace ? `${explanation}
|
|
6981
|
+
|
|
6982
|
+
Check it with:
|
|
6983
|
+
os connection test --workspace ${detail.workspace} --connection ${detail.identity}` : `${explanation}
|
|
6984
|
+
|
|
6985
|
+
Check or reconnect this Connection.`;
|
|
6986
|
+
}
|
|
6987
|
+
function connectionRunFailureMessage(detail, completedWork = !1) {
|
|
6988
|
+
return connectionFailureMessage(detail) + `
|
|
6989
|
+
|
|
6990
|
+
The Run stopped safely.` + (completedWork ? `
|
|
6991
|
+
|
|
6992
|
+
Work completed before this failure was kept.` : "");
|
|
6993
|
+
}
|
|
6994
|
+
var ConnectionOperationError = class extends Error {
|
|
6995
|
+
detail;
|
|
6996
|
+
get code() {
|
|
6997
|
+
return this.detail.code;
|
|
6998
|
+
}
|
|
6999
|
+
get stage() {
|
|
7000
|
+
return this.detail.stage;
|
|
7001
|
+
}
|
|
7002
|
+
get retryable() {
|
|
7003
|
+
return this.detail.retryable;
|
|
7004
|
+
}
|
|
7005
|
+
get attempts() {
|
|
7006
|
+
return this.detail.attempts;
|
|
7007
|
+
}
|
|
7008
|
+
get elapsedMs() {
|
|
7009
|
+
return this.detail.elapsedMs;
|
|
7010
|
+
}
|
|
7011
|
+
get status() {
|
|
7012
|
+
return this.detail.status;
|
|
7013
|
+
}
|
|
7014
|
+
constructor(identity3, workspace, facts2 = {
|
|
7015
|
+
code: "invalid_response",
|
|
7016
|
+
stage: "validation",
|
|
7017
|
+
retryable: !1,
|
|
7018
|
+
attempts: 0,
|
|
7019
|
+
elapsedMs: 0
|
|
7020
|
+
}) {
|
|
7021
|
+
let detail = parseConnectionFailureDetail({ ...facts2, identity: identity3, ...workspace === void 0 ? {} : { workspace } });
|
|
7022
|
+
super(connectionFailureMessage(detail)), this.name = "ConnectionOperationError", this.detail = detail;
|
|
7023
|
+
}
|
|
7024
|
+
};
|
|
7025
|
+
|
|
7026
|
+
var ROUTINE_ERROR_CODE_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
7027
|
+
function parseRoutineErrorDeclaration(value) {
|
|
7028
|
+
let invalid16 = () => {
|
|
7029
|
+
throw new TypeError("Invalid RoutineError");
|
|
7030
|
+
};
|
|
7031
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid16();
|
|
7032
|
+
let row = value;
|
|
7033
|
+
return Object.keys(row).some((key) => !["code", "message", "retryable"].includes(key)) || !Object.hasOwn(row, "code") || !Object.hasOwn(row, "message") || typeof row.code != "string" || !ROUTINE_ERROR_CODE_PATTERN.test(row.code) || typeof row.message != "string" || !row.message || row.message.startsWith(" ") || row.message.endsWith(" ") || /[\u0000-\u001f\u007f\u0085\u2028\u2029]/.test(row.message) || /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF])/.test(row.message) || new TextEncoder().encode(row.message).byteLength > 512 || Object.hasOwn(row, "retryable") && typeof row.retryable != "boolean" ? invalid16() : { code: row.code, message: row.message, retryable: row.retryable === !0 };
|
|
7034
|
+
}
|
|
7035
|
+
var RoutineError = class extends Error {
|
|
7036
|
+
code;
|
|
7037
|
+
retryable;
|
|
7038
|
+
constructor(options) {
|
|
7039
|
+
let declaration2 = parseRoutineErrorDeclaration(options);
|
|
7040
|
+
super(declaration2.message), this.name = "RoutineError", this.code = declaration2.code, this.retryable = declaration2.retryable;
|
|
7041
|
+
}
|
|
7042
|
+
};
|
|
7043
|
+
|
|
7044
|
+
var ROUTINE_RUN_COMPLETED_SUFFIX = `
|
|
7045
|
+
|
|
7046
|
+
Anything the routine completed before stopping is safe.`, ROUTINE_RUN_UNCERTAIN_SUFFIX = `
|
|
7047
|
+
|
|
7048
|
+
Some work may need review before you try again. Contact support.`;
|
|
7049
|
+
function parseRoutineAuthoredRunFailure(value) {
|
|
7050
|
+
let invalid16 = () => {
|
|
7051
|
+
throw new Error("Invalid authored Run failure");
|
|
7052
|
+
};
|
|
7053
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid16();
|
|
7054
|
+
let row = value;
|
|
7055
|
+
if (Object.keys(row).sort().join(",") !== "code,message,retryable" || typeof row.message != "string" || typeof row.retryable != "boolean") return invalid16();
|
|
7056
|
+
let authored = row.message.endsWith(ROUTINE_RUN_UNCERTAIN_SUFFIX) ? row.message.slice(0, -ROUTINE_RUN_UNCERTAIN_SUFFIX.length) : row.message.endsWith(ROUTINE_RUN_COMPLETED_SUFFIX) ? row.message.slice(0, -ROUTINE_RUN_COMPLETED_SUFFIX.length) : row.message;
|
|
7057
|
+
try {
|
|
7058
|
+
parseRoutineErrorDeclaration({ code: row.code, message: authored, retryable: row.retryable });
|
|
7059
|
+
} catch {
|
|
7060
|
+
return invalid16();
|
|
7061
|
+
}
|
|
7062
|
+
return { code: row.code, message: row.message, retryable: row.retryable };
|
|
7063
|
+
}
|
|
7064
|
+
|
|
7065
|
+
var name2 = /^[a-z0-9][a-z0-9-]{0,62}$/, uuid3 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, invalid5 = () => {
|
|
7066
|
+
throw new Error("Run state unavailable");
|
|
7067
|
+
}, record2 = (value) => value && typeof value == "object" && !Array.isArray(value) ? value : invalid5();
|
|
7068
|
+
function time(value) {
|
|
7069
|
+
return typeof value != "string" || value.length > 40 || !Number.isFinite(Date.parse(value)) ? invalid5() : value;
|
|
7070
|
+
}
|
|
7071
|
+
function times(value) {
|
|
7072
|
+
return {
|
|
7073
|
+
...value.startedAt === void 0 ? {} : { startedAt: time(value.startedAt) },
|
|
7074
|
+
...value.finishedAt === void 0 ? {} : { finishedAt: time(value.finishedAt) }
|
|
7075
|
+
};
|
|
7076
|
+
}
|
|
7077
|
+
function bounded(value) {
|
|
7078
|
+
return assertRoutineJson(value), new TextEncoder().encode(JSON.stringify(value)).byteLength > 256 * 1024 ? invalid5() : value;
|
|
7079
|
+
}
|
|
7080
|
+
function progress(value) {
|
|
7081
|
+
if (value === void 0) return {};
|
|
7082
|
+
let v = record2(value);
|
|
7083
|
+
return Object.keys(v).sort().join(",") !== "completed,total" || !Number.isSafeInteger(v.completed) || !Number.isSafeInteger(v.total) || v.completed < 1 || v.completed > v.total ? invalid5() : { progress: { completed: v.completed, total: v.total } };
|
|
7084
|
+
}
|
|
7085
|
+
function parseRunStep(value, expected) {
|
|
7086
|
+
let v = record2(value);
|
|
7087
|
+
if (typeof v.id != "string" || !name2.test(v.id) || expected !== void 0 && v.id !== expected || typeof v.title != "string" || !v.title.trim() || v.title.length > 256 || !["pending", "running", "completed", "failed", "skipped"].includes(v.status)) return invalid5();
|
|
7088
|
+
let output = captureRetainedStepOutput(v.id, {
|
|
7089
|
+
...Object.hasOwn(v, "summary") ? { summary: v.summary } : {},
|
|
7090
|
+
...Object.hasOwn(v, "data") ? { data: v.data } : {}
|
|
7091
|
+
});
|
|
7092
|
+
return {
|
|
7093
|
+
id: v.id,
|
|
7094
|
+
title: v.title,
|
|
7095
|
+
status: v.status,
|
|
7096
|
+
...times(v),
|
|
7097
|
+
...progress(v.progress),
|
|
7098
|
+
...Object.hasOwn(v, "summary") ? { summary: bounded(v.summary) } : {},
|
|
7099
|
+
...Object.hasOwn(output, "data") ? { data: output.data } : {}
|
|
7100
|
+
};
|
|
7101
|
+
}
|
|
7102
|
+
function parseRemoteRun(value, expected = {}) {
|
|
7103
|
+
let v = record2(value);
|
|
7104
|
+
if (typeof v.id != "string" || !uuid3.test(v.id) || expected.id !== void 0 && v.id !== expected.id || typeof v.routine != "string" || !name2.test(v.routine) || expected.routine !== void 0 && v.routine !== expected.routine || v.placement !== "remote" || !["queued", "running", "succeeded", "failed"].includes(v.status) || !Array.isArray(v.steps) || v.steps.length > 64) return invalid5();
|
|
7105
|
+
let steps = v.steps.map((value2) => {
|
|
7106
|
+
let step = record2(value2);
|
|
7107
|
+
return typeof step.detailAvailable != "boolean" || Object.hasOwn(step, "data") ? invalid5() : { ...parseRunStep(step), detailAvailable: step.detailAvailable };
|
|
7108
|
+
});
|
|
7109
|
+
if (new Set(steps.map((step) => step.id)).size !== steps.length) return invalid5();
|
|
7110
|
+
let failure;
|
|
7111
|
+
if (v.failure !== void 0) {
|
|
7112
|
+
let f = record2(v.failure);
|
|
7113
|
+
if (v.status !== "failed" || typeof f.message != "string" || !f.message || f.message.length > 512) return invalid5();
|
|
7114
|
+
if (f.code === "step_output_too_large") {
|
|
7115
|
+
let { code, message: message2, ...facts2 } = f, detail = parseRoutineStepOutputDetail(facts2);
|
|
7116
|
+
if (!steps.some((step) => step.id === detail.step && step.status === "failed") || message2 !== routineStepOutputMessage(detail)) return invalid5();
|
|
7117
|
+
failure = { code, message: message2, ...detail };
|
|
7118
|
+
} else if (f.code !== void 0 || Object.hasOwn(f, "retryable"))
|
|
7119
|
+
try {
|
|
7120
|
+
failure = parseRoutineAuthoredRunFailure(f);
|
|
7121
|
+
} catch {
|
|
7122
|
+
return invalid5();
|
|
7123
|
+
}
|
|
7124
|
+
else failure = { message: f.message };
|
|
7125
|
+
}
|
|
7126
|
+
return Object.hasOwn(v, "result") && v.status !== "succeeded" ? invalid5() : {
|
|
7127
|
+
id: v.id,
|
|
7128
|
+
routine: v.routine,
|
|
7129
|
+
placement: "remote",
|
|
7130
|
+
status: v.status,
|
|
7131
|
+
createdAt: time(v.createdAt),
|
|
7132
|
+
...times(v),
|
|
7133
|
+
steps,
|
|
7134
|
+
...Object.hasOwn(v, "result") ? { result: bounded(v.result) } : {},
|
|
7135
|
+
...failure ? { failure } : {}
|
|
7136
|
+
};
|
|
7137
|
+
}
|
|
7138
|
+
|
|
7139
|
+
function routineRunHandle(operations2) {
|
|
7140
|
+
return Object.freeze({
|
|
7141
|
+
current: operations2.current,
|
|
7142
|
+
step: operations2.step,
|
|
7143
|
+
async *watch() {
|
|
7144
|
+
let previous;
|
|
7145
|
+
for (; ; ) {
|
|
7146
|
+
let state = await operations2.current(), encoded = JSON.stringify(state);
|
|
7147
|
+
if (encoded !== previous && (previous = encoded, yield state), state.status === "succeeded" || state.status === "failed" || state.status === "legacy") return;
|
|
7148
|
+
await (operations2.wait?.() ?? new Promise((resolve) => setTimeout(resolve, 100)));
|
|
7149
|
+
}
|
|
7150
|
+
}
|
|
7151
|
+
});
|
|
7152
|
+
}
|
|
7153
|
+
|
|
7024
7154
|
var invalid6 = () => {
|
|
7025
7155
|
throw new DataOperationError("invalid_query");
|
|
7026
7156
|
}, dataText = (value) => typeof value == "string" && !/[\u0000\uD800-\uDFFF]/u.test(value), dataVersion = (value) => dataText(value) && value.length > 0 && new TextEncoder().encode(value).length <= 1024 && !/[\u0000-\u001f\u007f-\u009f]/.test(value) && !/^[0-9a-f]{40}$/i.test(value);
|
|
@@ -8289,80 +8419,6 @@ function validPair(value) {
|
|
|
8289
8419
|
return validProof(pair.credential) && validProof(pair.renewalCredential) && pair.credential !== pair.renewalCredential && validBinding(pair.context);
|
|
8290
8420
|
}
|
|
8291
8421
|
|
|
8292
|
-
var identityPattern = /^(gmail|airtable|dropbox|outlook|sharepoint)\/([a-z0-9][a-z0-9-]{0,62})$/, workspacePattern = /^[a-z0-9][a-z0-9-]{0,62}$/, providerNames = {
|
|
8293
|
-
gmail: "Gmail",
|
|
8294
|
-
airtable: "Airtable",
|
|
8295
|
-
dropbox: "Dropbox",
|
|
8296
|
-
outlook: "Outlook",
|
|
8297
|
-
sharepoint: "SharePoint"
|
|
8298
|
-
};
|
|
8299
|
-
function parseConnectionFailureDetail(value) {
|
|
8300
|
-
if (!value || typeof value != "object" || Array.isArray(value)) throw new Error("Invalid Connection failure");
|
|
8301
|
-
let v = value;
|
|
8302
|
-
if (Object.keys(v).some((key) => !["identity", "workspace", "code", "stage", "retryable", "attempts", "elapsedMs", "status"].includes(key)) || typeof v.identity != "string" || !identityPattern.test(v.identity) || v.workspace !== void 0 && (typeof v.workspace != "string" || !workspacePattern.test(v.workspace)) || !["temporarily_unavailable", "attention_required", "invalid_response"].includes(v.code) || !["authorization", "provider", "finalization", "transport", "validation"].includes(v.stage) || v.retryable !== (v.code === "temporarily_unavailable") || !Number.isSafeInteger(v.attempts) || v.attempts < 0 || v.attempts > 3 || !Number.isSafeInteger(v.elapsedMs) || v.elapsedMs < 0 || Object.hasOwn(v, "status") && (!Number.isSafeInteger(v.status) || v.status < 100 || v.status > 599))
|
|
8303
|
-
throw new Error("Invalid Connection failure");
|
|
8304
|
-
return {
|
|
8305
|
-
identity: v.identity,
|
|
8306
|
-
...v.workspace === void 0 ? {} : { workspace: v.workspace },
|
|
8307
|
-
code: v.code,
|
|
8308
|
-
stage: v.stage,
|
|
8309
|
-
retryable: v.retryable,
|
|
8310
|
-
attempts: v.attempts,
|
|
8311
|
-
elapsedMs: v.elapsedMs,
|
|
8312
|
-
...Object.hasOwn(v, "status") ? { status: v.status } : {}
|
|
8313
|
-
};
|
|
8314
|
-
}
|
|
8315
|
-
function connectionFailureMessage(value) {
|
|
8316
|
-
let detail = parseConnectionFailureDetail(value), [, provider2, name4] = identityPattern.exec(detail.identity), duration = detail.elapsedMs < 1e3 ? `${detail.elapsedMs}ms` : `${(detail.elapsedMs / 1e3).toFixed(1)}s`, explanation = `OS couldn\u2019t grant this Run access to ${providerNames[provider2]} connection ${name4}.
|
|
8317
|
-
${detail.attempts} ${detail.attempts === 1 ? "attempt" : "attempts"} in ${duration}.
|
|
8318
|
-
|
|
8319
|
-
The routine received no provider access through this lease and made no provider business request through it.`;
|
|
8320
|
-
return detail.code !== "attention_required" ? explanation : detail.workspace ? `${explanation}
|
|
8321
|
-
|
|
8322
|
-
Check it with:
|
|
8323
|
-
os connection test --workspace ${detail.workspace} --connection ${detail.identity}` : `${explanation}
|
|
8324
|
-
|
|
8325
|
-
Check or reconnect this Connection.`;
|
|
8326
|
-
}
|
|
8327
|
-
function connectionRunFailureMessage(detail, completedWork = !1) {
|
|
8328
|
-
return connectionFailureMessage(detail) + `
|
|
8329
|
-
|
|
8330
|
-
The Run stopped safely.` + (completedWork ? `
|
|
8331
|
-
|
|
8332
|
-
Work completed before this failure was kept.` : "");
|
|
8333
|
-
}
|
|
8334
|
-
var ConnectionOperationError = class extends Error {
|
|
8335
|
-
detail;
|
|
8336
|
-
get code() {
|
|
8337
|
-
return this.detail.code;
|
|
8338
|
-
}
|
|
8339
|
-
get stage() {
|
|
8340
|
-
return this.detail.stage;
|
|
8341
|
-
}
|
|
8342
|
-
get retryable() {
|
|
8343
|
-
return this.detail.retryable;
|
|
8344
|
-
}
|
|
8345
|
-
get attempts() {
|
|
8346
|
-
return this.detail.attempts;
|
|
8347
|
-
}
|
|
8348
|
-
get elapsedMs() {
|
|
8349
|
-
return this.detail.elapsedMs;
|
|
8350
|
-
}
|
|
8351
|
-
get status() {
|
|
8352
|
-
return this.detail.status;
|
|
8353
|
-
}
|
|
8354
|
-
constructor(identity3, workspace, facts2 = {
|
|
8355
|
-
code: "invalid_response",
|
|
8356
|
-
stage: "validation",
|
|
8357
|
-
retryable: !1,
|
|
8358
|
-
attempts: 0,
|
|
8359
|
-
elapsedMs: 0
|
|
8360
|
-
}) {
|
|
8361
|
-
let detail = parseConnectionFailureDetail({ ...facts2, identity: identity3, ...workspace === void 0 ? {} : { workspace } });
|
|
8362
|
-
super(connectionFailureMessage(detail)), this.name = "ConnectionOperationError", this.detail = detail;
|
|
8363
|
-
}
|
|
8364
|
-
};
|
|
8365
|
-
|
|
8366
8422
|
var routineOperationMessages = {
|
|
8367
8423
|
context_unavailable: "Routine operations require a current OS host context.",
|
|
8368
8424
|
unauthenticated: "Sign in to OS.",
|
|
@@ -8386,6 +8442,7 @@ var routineOperationMessages = {
|
|
|
8386
8442
|
location;
|
|
8387
8443
|
};
|
|
8388
8444
|
function routineOperationFailure(value) {
|
|
8445
|
+
if (value instanceof RoutineOperationError) return value;
|
|
8389
8446
|
let code = value?.code;
|
|
8390
8447
|
return new RoutineOperationError(code && Object.hasOwn(routineOperationMessages, code) ? code : "unavailable");
|
|
8391
8448
|
}
|
|
@@ -8457,7 +8514,23 @@ function routineOperations(routine, host) {
|
|
|
8457
8514
|
let selectedItem = (id5) => (value) => {
|
|
8458
8515
|
let item = parseQueueItem(value);
|
|
8459
8516
|
return id5 !== void 0 && item.id !== id5 && fail3("unavailable"), item;
|
|
8460
|
-
}
|
|
8517
|
+
};
|
|
8518
|
+
async function managedQueue(operation2, input, parse, local2 = !1) {
|
|
8519
|
+
let transport;
|
|
8520
|
+
try {
|
|
8521
|
+
transport = routineTransport() ?? (local2 ? void 0 : void 0);
|
|
8522
|
+
} catch {
|
|
8523
|
+
return fail3("context_unavailable");
|
|
8524
|
+
}
|
|
8525
|
+
if (!transport) return fail3("context_unavailable");
|
|
8526
|
+
try {
|
|
8527
|
+
let result2 = parse(await transport.request(operation2, input));
|
|
8528
|
+
return transport.isCurrent() || fail3("context_unavailable"), result2;
|
|
8529
|
+
} catch (error) {
|
|
8530
|
+
throw transport.isCurrent() || fail3("context_unavailable"), routineOperationFailure(error);
|
|
8531
|
+
}
|
|
8532
|
+
}
|
|
8533
|
+
let summary3 = (value) => {
|
|
8461
8534
|
let result2 = parseQueueSummary(value);
|
|
8462
8535
|
return result2.routineId !== routine && fail3("unavailable"), result2;
|
|
8463
8536
|
}, readRun = (id5) => (value) => parseRemoteRun(value, { routine, id: id5 }), runHandle = (id5) => routineRunHandle({
|
|
@@ -8474,22 +8547,11 @@ function routineOperations(routine, host) {
|
|
|
8474
8547
|
async add(input, options = {}) {
|
|
8475
8548
|
(!options || Object.keys(options).some((key) => key !== "idempotencyKey") || options.idempotencyKey !== void 0 && typeof options.idempotencyKey != "string") && fail3("invalid_input");
|
|
8476
8549
|
let body = { input, ...options };
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
} catch {
|
|
8482
|
-
return fail3("context_unavailable");
|
|
8483
|
-
}
|
|
8484
|
-
if (!transport) return fail3("context_unavailable");
|
|
8485
|
-
try {
|
|
8486
|
-
let result2 = selectedItem()(await transport.request("queue/add", { routineId: routine, ...body }));
|
|
8487
|
-
return transport.isCurrent() || fail3("context_unavailable"), result2;
|
|
8488
|
-
} catch (error) {
|
|
8489
|
-
throw transport.isCurrent() || fail3("context_unavailable"), routineOperationFailure(error);
|
|
8490
|
-
}
|
|
8550
|
+
return new TextEncoder().encode(json2(input)).byteLength > 262144 && fail3("invalid_input"), host ? request3(`${root}/queue/items`, selectedItem(), body) : managedQueue("queue/add", { routineId: routine, ...body }, selectedItem(), !0);
|
|
8551
|
+
},
|
|
8552
|
+
async remove(id5) {
|
|
8553
|
+
return id5 = identity2(id5), host ? request3(`${root}/queue/items/${id5}/remove`, selectedItem(id5), {}) : managedQueue("queue/remove", { routineId: routine, itemId: id5 }, selectedItem(id5));
|
|
8491
8554
|
},
|
|
8492
|
-
remove: (id5) => request3(`${root}/queue/items/${identity2(id5)}/remove`, selectedItem(id5), {}),
|
|
8493
8555
|
retry: (id5, options) => ((!options || Object.keys(options).join() !== "failureId") && fail3("invalid_input"), identity2(options.failureId), request3(`${root}/queue/items/${identity2(id5)}/retry`, selectedItem(id5), options))
|
|
8494
8556
|
},
|
|
8495
8557
|
queries: {
|
|
@@ -10917,13 +10979,24 @@ var files = {
|
|
|
10917
10979
|
|
|
10918
10980
|
var ROUTINE_CONNECTION_CREDENTIALS_ENV = "OS_ROUTINE_CONNECTION_CREDENTIALS";
|
|
10919
10981
|
function parseRoutineConnectionNames(value) {
|
|
10920
|
-
if (!Array.isArray(value) || value.some((name4) => typeof name4 != "string" || !/^(gmail|airtable|dropbox|outlook|sharepoint)\/[a-z0-9][a-z0-9-]{0,62}$/.test(name4)) || new Set(value).size !== value.length)
|
|
10982
|
+
if (!Array.isArray(value) || value.some((name4) => typeof name4 != "string" || !/^(gmail|airtable|dropbox|outlook|sharepoint|xero)\/[a-z0-9][a-z0-9-]{0,62}$/.test(name4)) || new Set(value).size !== value.length)
|
|
10921
10983
|
throw new Error("Invalid routine connections");
|
|
10922
10984
|
return value;
|
|
10923
10985
|
}
|
|
10924
10986
|
var connectionUuid = (v) => typeof v == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(v);
|
|
10925
10987
|
function runtimeConnection(lease) {
|
|
10926
10988
|
switch (lease.provider) {
|
|
10989
|
+
case "xero":
|
|
10990
|
+
return {
|
|
10991
|
+
id: `xero/${lease.name}`,
|
|
10992
|
+
provider: lease.provider,
|
|
10993
|
+
name: lease.name,
|
|
10994
|
+
tenantId: lease.tenantId,
|
|
10995
|
+
tenantName: lease.tenantName,
|
|
10996
|
+
scopes: [...lease.scopes],
|
|
10997
|
+
accessToken: lease.accessToken,
|
|
10998
|
+
expiresAt: lease.expiresAt
|
|
10999
|
+
};
|
|
10927
11000
|
case "outlook":
|
|
10928
11001
|
return {
|
|
10929
11002
|
id: `outlook/${lease.name}`,
|
|
@@ -10980,6 +11053,11 @@ function parseConnectionLease(raw, now = Date.now()) {
|
|
|
10980
11053
|
let v = raw;
|
|
10981
11054
|
if (!v || typeof v != "object" || Array.isArray(v) || !connectionUuid(v.connectionId) || !connectionUuid(v.runId) || typeof v.name != "string" || !/^[a-z0-9][a-z0-9-]{0,62}$/.test(v.name) || typeof v.accessToken != "string" || !/^[A-Za-z0-9._~+/-]{1,8192}={0,2}$/.test(v.accessToken))
|
|
10982
11055
|
throw new Error("Invalid connection credential");
|
|
11056
|
+
if (v.provider === "xero") {
|
|
11057
|
+
if (Object.keys(v).sort().join(",") !== "accessToken,connectionId,expiresAt,name,provider,runId,scopes,tenantId,tenantName" || typeof v.tenantId != "string" || !connectionUuid(v.tenantId.toLowerCase()) || typeof v.tenantName != "string" || !v.tenantName.trim() || !validXeroScopes(v.scopes) || typeof v.expiresAt != "string" || !Number.isFinite(Date.parse(v.expiresAt)) || Date.parse(v.expiresAt) <= now || Date.parse(v.expiresAt) > now + 18e5)
|
|
11058
|
+
throw new Error("Invalid connection credential");
|
|
11059
|
+
return v;
|
|
11060
|
+
}
|
|
10983
11061
|
if (v.provider === "outlook" || v.provider === "sharepoint") {
|
|
10984
11062
|
if (!(v.provider === "outlook" ? Object.keys(v).sort().join(",") === "accessToken,connectionId,expiresAt,mailboxEmail,name,provider,runId" && validMicrosoftMailbox(v.mailboxEmail) : Object.keys(v).sort().join(",") === "accessToken,connectionId,expiresAt,name,provider,runId,siteId,siteUrl" && typeof v.siteUrl == "string" && canonicalSharePointSiteUrl(v.siteUrl) === v.siteUrl && validSharePointSiteId(v.siteId, v.siteUrl)) || typeof v.expiresAt != "string" || !Number.isFinite(Date.parse(v.expiresAt)) || Date.parse(v.expiresAt) <= now || Date.parse(v.expiresAt) > now + 36e5)
|
|
10985
11063
|
throw new Error("Invalid connection credential");
|
|
@@ -12843,6 +12921,10 @@ function summary2(value, key, context, id5) {
|
|
|
12843
12921
|
return (!only(run, "id,routine,placement,status,createdAt,startedAt,finishedAt,steps,result,failure,local") || typeof run.id != "string" || !uuid6.test(run.id) || id5 !== void 0 && run.id !== id5 || run.routine !== key || run.placement !== "local" || !["queued", "running", "succeeded", "failed", "legacy"].includes(run.status) || !timestamp(run.createdAt) || !optionalTimes(run) || !Array.isArray(run.steps) || run.steps.length > 64 || run.steps.some((step) => !only(step, "id,title,status,startedAt,finishedAt,progress,summary,detailAvailable") || typeof step.detailAvailable != "boolean" || !validStep(step)) || new Set(run.steps.map((step) => step.id)).size !== run.steps.length || Object.hasOwn(run, "result") && (run.status !== "succeeded" || !bounded2(run.result)) || run.failure !== void 0 && (run.status !== "failed" || !validFailure(run.failure, run.steps, run)) || run.local !== void 0 && !validLocalActivity(run.local)) && fail8("execution_unavailable"), run;
|
|
12844
12922
|
}
|
|
12845
12923
|
function validFailure(value, steps, local2) {
|
|
12924
|
+
try {
|
|
12925
|
+
return parseRoutineAuthoredRunFailure(value), !0;
|
|
12926
|
+
} catch {
|
|
12927
|
+
}
|
|
12846
12928
|
if (local2 && only(value, "message,code,detail") && value.code !== void 0)
|
|
12847
12929
|
try {
|
|
12848
12930
|
let detail = parseConnectionFailureDetail(value.detail), completedWork = steps.some((step) => step.status === "completed") || !!local2.local?.effects.some((effect) => effect.status === "completed") || !!local2.local?.data.some((repository) => repository.created.length || repository.updated.length || repository.deleted.length);
|
|
@@ -13048,6 +13130,7 @@ export {
|
|
|
13048
13130
|
InboxContractError,
|
|
13049
13131
|
InboxOperationError,
|
|
13050
13132
|
AIError as RoutineAIError,
|
|
13133
|
+
RoutineError,
|
|
13051
13134
|
RoutineOperationError,
|
|
13052
13135
|
app,
|
|
13053
13136
|
asksBlock,
|