@ancha-labs/cli 0.1.5 → 0.1.6
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/lib/ancha.mjs +485 -258
- package/lib/assets/docs/cloud.md +3 -3
- package/lib/assets/docs/run.md +7 -1
- package/lib/assets/harbor/companion.mjs +257 -195
- package/lib/assets/ui/app.js +28 -18
- package/lib/assets/ui/style.css +2 -0
- package/lib/mcp-entry.mjs +74 -12
- package/lib/worker.mjs +332 -210
- package/lib/world-server.mjs +257 -195
- package/package.json +1 -1
package/lib/worker.mjs
CHANGED
|
@@ -18,9 +18,9 @@ var __commonJS = (cb, mod) => function __require2() {
|
|
|
18
18
|
throw mod = 0, e;
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
var __export = (target4,
|
|
22
|
-
for (var name5 in
|
|
23
|
-
__defProp(target4, name5, { get:
|
|
21
|
+
var __export = (target4, all8) => {
|
|
22
|
+
for (var name5 in all8)
|
|
23
|
+
__defProp(target4, name5, { get: all8[name5], enumerable: true });
|
|
24
24
|
};
|
|
25
25
|
var __copyProps = (to, from, except, desc) => {
|
|
26
26
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -55927,6 +55927,111 @@ function toErrorJson(e) {
|
|
|
55927
55927
|
return { code: "INTERNAL", message: e instanceof Error ? e.message : String(e) };
|
|
55928
55928
|
}
|
|
55929
55929
|
|
|
55930
|
+
// packages/core/src/execution-support.ts
|
|
55931
|
+
var all = { local: true, container: true, managed: true };
|
|
55932
|
+
var sceneOnly = { local: true, container: true, managed: false };
|
|
55933
|
+
var EXECUTION_SUPPORT = {
|
|
55934
|
+
"input.scene": { ...sceneOnly, reason: "scene worlds cannot be imported without changing their semantics" },
|
|
55935
|
+
"input.test": { ...sceneOnly, reason: "local test worlds cannot be equated with saved managed worlds" },
|
|
55936
|
+
"input.managed-task": { local: false, container: false, managed: true, reason: "explicit saved-world tasks use runs start or the console" },
|
|
55937
|
+
"managed.world-reference": { local: false, container: false, managed: true, reason: "an explicit reference to an existing managed world, not an imported local world" },
|
|
55938
|
+
"id": all,
|
|
55939
|
+
"title": all,
|
|
55940
|
+
"task": sceneOnly,
|
|
55941
|
+
"start.task": all,
|
|
55942
|
+
"attempts": all,
|
|
55943
|
+
"twins": sceneOnly,
|
|
55944
|
+
"world": sceneOnly,
|
|
55945
|
+
"start_time": sceneOnly,
|
|
55946
|
+
"time_scale": sceneOnly,
|
|
55947
|
+
"seed": sceneOnly,
|
|
55948
|
+
"world_rules": sceneOnly,
|
|
55949
|
+
"people": sceneOnly,
|
|
55950
|
+
"until": sceneOnly,
|
|
55951
|
+
"deadline": sceneOnly,
|
|
55952
|
+
"start.message": sceneOnly,
|
|
55953
|
+
"pass": sceneOnly,
|
|
55954
|
+
"scene.timeout": sceneOnly,
|
|
55955
|
+
"test.timeout": all,
|
|
55956
|
+
"checks.state": all,
|
|
55957
|
+
"checks.trace": all,
|
|
55958
|
+
"checks.process": all,
|
|
55959
|
+
"checks.judge": sceneOnly,
|
|
55960
|
+
"agent.input.command": all,
|
|
55961
|
+
"agent.input.per_event": sceneOnly,
|
|
55962
|
+
"agent.input.events": { local: true, container: false, managed: false },
|
|
55963
|
+
"agent.input.http": all,
|
|
55964
|
+
"agent.endpoint": { local: true, container: false, managed: false },
|
|
55965
|
+
"agent.slack_transport.feed": sceneOnly,
|
|
55966
|
+
"agent.slack_transport.http": { local: true, container: false, managed: false },
|
|
55967
|
+
"agent.slack_transport.socket": { local: true, container: false, managed: false },
|
|
55968
|
+
"agent.env": sceneOnly,
|
|
55969
|
+
"agent.pass_env": sceneOnly,
|
|
55970
|
+
"agent.execution": sceneOnly,
|
|
55971
|
+
"judge": sceneOnly,
|
|
55972
|
+
"min_pass_rate": sceneOnly,
|
|
55973
|
+
"--agent": all,
|
|
55974
|
+
"--trials": all,
|
|
55975
|
+
"--parallel": all,
|
|
55976
|
+
"--idempotency-key": all,
|
|
55977
|
+
"--on": all,
|
|
55978
|
+
"--json": all,
|
|
55979
|
+
"--agent-url": { local: true, container: false, managed: false },
|
|
55980
|
+
"--compare": sceneOnly,
|
|
55981
|
+
"--min-pass-rate": sceneOnly,
|
|
55982
|
+
"--strict": sceneOnly,
|
|
55983
|
+
"--seed": sceneOnly,
|
|
55984
|
+
"--out": sceneOnly,
|
|
55985
|
+
"--detach": sceneOnly,
|
|
55986
|
+
"--pass-env": sceneOnly,
|
|
55987
|
+
"--inherit-env": sceneOnly,
|
|
55988
|
+
"--upload": sceneOnly,
|
|
55989
|
+
"--upload-required": sceneOnly
|
|
55990
|
+
};
|
|
55991
|
+
|
|
55992
|
+
// packages/core/src/verdict.ts
|
|
55993
|
+
var VERDICT_VERSION = 2;
|
|
55994
|
+
function countTrials(requested2, outcomes) {
|
|
55995
|
+
const count3 = (kind) => outcomes.filter((outcome3) => outcome3 === kind).length;
|
|
55996
|
+
const passed = count3("passed"), failed = count3("failed"), invalid25 = count3("invalid"), skipped = count3("skipped");
|
|
55997
|
+
const counts = { requested: requested2, completed: passed + failed + invalid25 + skipped, valid: passed + failed, passed, invalid: invalid25, skipped };
|
|
55998
|
+
assertTrialCounts(counts);
|
|
55999
|
+
return counts;
|
|
56000
|
+
}
|
|
56001
|
+
function assertTrialCounts(counts) {
|
|
56002
|
+
if (!counts || !["requested", "completed", "valid", "passed", "invalid", "skipped"].every((key3) => Number.isSafeInteger(counts[key3]) && counts[key3] >= 0) || counts.completed > counts.requested || counts.valid + counts.invalid + counts.skipped !== counts.completed || counts.passed > counts.valid) {
|
|
56003
|
+
throw new Error("Invalid requested trial counts; rerun the evaluation and save a fresh baseline.");
|
|
56004
|
+
}
|
|
56005
|
+
}
|
|
56006
|
+
function allTrialsPassed(counts) {
|
|
56007
|
+
return counts.requested > 0 && counts.completed === counts.requested && counts.valid === counts.requested && counts.passed === counts.requested && counts.invalid === 0 && counts.skipped === 0;
|
|
56008
|
+
}
|
|
56009
|
+
function minimumPassingTrials(requested2, rate) {
|
|
56010
|
+
if (!Number.isSafeInteger(requested2) || requested2 < 0 || !Number.isFinite(rate) || rate < 0 || rate > 1) throw new Error("Invalid requested trial count or minimum pass rate.");
|
|
56011
|
+
const [mantissa, exponent = "0"] = rate.toString().split("e");
|
|
56012
|
+
const [whole2, fractional = ""] = mantissa.split(".");
|
|
56013
|
+
const scale = fractional.length - Number(exponent);
|
|
56014
|
+
const numerator = BigInt(whole2 + fractional) * (scale < 0 ? 10n ** BigInt(-scale) : 1n);
|
|
56015
|
+
const denominator = scale > 0 ? 10n ** BigInt(scale) : 1n;
|
|
56016
|
+
return Number((BigInt(requested2) * numerator + denominator - 1n) / denominator);
|
|
56017
|
+
}
|
|
56018
|
+
function meetsPassRate(counts, rate) {
|
|
56019
|
+
assertTrialCounts(counts);
|
|
56020
|
+
return counts.requested > 0 && counts.passed >= minimumPassingTrials(counts.requested, rate);
|
|
56021
|
+
}
|
|
56022
|
+
function trialOutcome(trial) {
|
|
56023
|
+
if (trial.valid === false || trial.exit === "invalid" || trial.outcome === "invalid") return "invalid";
|
|
56024
|
+
if (trial.outcome === "skipped" || trial.outcome === "xfailed") return "skipped";
|
|
56025
|
+
return trial.passed === true ? "passed" : "failed";
|
|
56026
|
+
}
|
|
56027
|
+
function verifiedCounts(summary, scene2) {
|
|
56028
|
+
if (summary.verdictVersion !== VERDICT_VERSION || !scene2.counts) throw new Error("Incompatible baseline/report verdict version or requested trial counts; rerun and save a fresh baseline.");
|
|
56029
|
+
const counts = scene2.counts;
|
|
56030
|
+
assertTrialCounts(counts);
|
|
56031
|
+
if (counts.passed !== scene2.passed || counts.completed !== scene2.trials || counts.invalid !== (scene2.invalidTrials ?? 0)) throw new Error("Inconsistent baseline/report trial counts; rerun and save a fresh baseline.");
|
|
56032
|
+
return counts;
|
|
56033
|
+
}
|
|
56034
|
+
|
|
55930
56035
|
// packages/core/src/agent-environment.ts
|
|
55931
56036
|
function isPrivateAgentEnvironmentName(name5) {
|
|
55932
56037
|
return /^(?:ANCHA_(?:PEOPLE_|RESULTS_|CONSOLE_|CONTROL_|WORKSPACE_)|GATEWAY_|SIDECAR_|TENANT_)/i.test(name5) || /^(?:ANCHA_API_KEY|ANCHA_SERVER_URL|ANCHA_CREDENTIALS_FILE|OPENROUTER_MANAGEMENT_KEY|OPENROUTER_PROVISIONING_KEY)$/i.test(name5);
|
|
@@ -78945,15 +79050,15 @@ var NotionSeedSchema = external_exports.strictObject({
|
|
|
78945
79050
|
databases: external_exports.array(database).max(200).default([])
|
|
78946
79051
|
}).superRefine((seed40, ctx) => {
|
|
78947
79052
|
const issue5 = (path6, message5) => ctx.addIssue({ code: "custom", path: path6, message: message5 });
|
|
78948
|
-
const users4 = /* @__PURE__ */ new Set(), pages = /* @__PURE__ */ new Set(),
|
|
79053
|
+
const users4 = /* @__PURE__ */ new Set(), pages = /* @__PURE__ */ new Set(), all8 = /* @__PURE__ */ new Set();
|
|
78949
79054
|
seed40.users.forEach((u, i) => {
|
|
78950
79055
|
if (users4.has(u.ref)) issue5(["users", i, "ref"], "duplicate user ref");
|
|
78951
79056
|
users4.add(u.ref);
|
|
78952
79057
|
});
|
|
78953
79058
|
const declare = (r, path6) => {
|
|
78954
79059
|
if (r === void 0) return;
|
|
78955
|
-
if (
|
|
78956
|
-
|
|
79060
|
+
if (all8.has(r) || users4.has(r)) issue5(path6, `duplicate ref ${r}`);
|
|
79061
|
+
all8.add(r);
|
|
78957
79062
|
};
|
|
78958
79063
|
seed40.pages.forEach((p2, i) => {
|
|
78959
79064
|
declare(p2.ref, ["pages", i, "ref"]);
|
|
@@ -86719,11 +86824,11 @@ var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
|
86719
86824
|
var __getProtoOf2 = Object.getPrototypeOf;
|
|
86720
86825
|
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
86721
86826
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
86722
|
-
var __exportAll = (
|
|
86827
|
+
var __exportAll = (all8, symbols) => {
|
|
86723
86828
|
let target4 = {};
|
|
86724
|
-
for (var name5 in
|
|
86829
|
+
for (var name5 in all8) {
|
|
86725
86830
|
__defProp2(target4, name5, {
|
|
86726
|
-
get:
|
|
86831
|
+
get: all8[name5],
|
|
86727
86832
|
enumerable: true
|
|
86728
86833
|
});
|
|
86729
86834
|
}
|
|
@@ -104660,9 +104765,9 @@ function inspectPredicate(env, predicate, atMs) {
|
|
|
104660
104765
|
const expected = predicateWords(predicate);
|
|
104661
104766
|
const outcome3 = (passed, actual, explanation = actual) => ({ passed, expected, actual, explanation });
|
|
104662
104767
|
if ("all" in predicate || "any" in predicate) {
|
|
104663
|
-
const
|
|
104664
|
-
const children2 = (
|
|
104665
|
-
return outcome3(
|
|
104768
|
+
const all8 = "all" in predicate;
|
|
104769
|
+
const children2 = (all8 ? predicate.all : predicate.any).map((child2) => inspectPredicate(env, child2, atMs));
|
|
104770
|
+
return outcome3(all8 ? children2.every((child2) => child2.passed) : children2.some((child2) => child2.passed), children2.map((child2) => child2.actual).join("; "));
|
|
104666
104771
|
}
|
|
104667
104772
|
if ("not" in predicate) {
|
|
104668
104773
|
const child2 = inspectPredicate(env, predicate.not, atMs);
|
|
@@ -108998,10 +109103,10 @@ var bufferToFormData = (arrayBuffer, contentType) => {
|
|
|
108998
109103
|
var MAX_NESTED_OBJECTS = 1e4;
|
|
108999
109104
|
var isRawRequest = (request2) => "headers" in request2;
|
|
109000
109105
|
var parseBody = async (request2, options3 = /* @__PURE__ */ Object.create(null)) => {
|
|
109001
|
-
const { all:
|
|
109106
|
+
const { all: all8 = false, dot = false } = options3;
|
|
109002
109107
|
const mediaType2 = (isRawRequest(request2) ? request2.headers : request2.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
109003
109108
|
if (mediaType2 === "multipart/form-data" || mediaType2 === "application/x-www-form-urlencoded") return parseFormData(request2, {
|
|
109004
|
-
all:
|
|
109109
|
+
all: all8,
|
|
109005
109110
|
dot
|
|
109006
109111
|
});
|
|
109007
109112
|
return {};
|
|
@@ -110906,8 +111011,8 @@ function properties(type, record10) {
|
|
|
110906
111011
|
function project3(ctx, type, record10, selected2, historyFields, associationObjects) {
|
|
110907
111012
|
const names3 = selected2 ?? defaultProperties[type];
|
|
110908
111013
|
for (const name5 of [...names3, ...historyFields ?? []]) checkProperty(type, name5);
|
|
110909
|
-
const
|
|
110910
|
-
const output2 = { id: record10.id, properties: Object.fromEntries(keys5.filter((key3) =>
|
|
111014
|
+
const all8 = properties(type, record10), keys5 = [.../* @__PURE__ */ new Set([...names3, "hs_object_id", "createdate", type === "contacts" ? "lastmodifieddate" : "hs_lastmodifieddate"])];
|
|
111015
|
+
const output2 = { id: record10.id, properties: Object.fromEntries(keys5.filter((key3) => all8[key3] !== void 0).map((key3) => [key3, all8[key3]])), createdAt: record10.createdAt, updatedAt: record10.updatedAt, archived: record10.archived, ...record10.archived && { archivedAt: record10.archivedAt } };
|
|
110911
111016
|
if (historyFields?.length) {
|
|
110912
111017
|
const versions2 = ctx.store.db.prepare("SELECT data,operation FROM hubspot_versions WHERE type=? AND id=? ORDER BY ordinal").all(type, record10.id).map((row) => ({ ...row, record: JSON.parse(row.data) }));
|
|
110913
111018
|
output2.propertiesWithHistory = Object.fromEntries(historyFields.map((name5) => {
|
|
@@ -111323,9 +111428,9 @@ function dispatch(ctx, method2, url3, body6) {
|
|
|
111323
111428
|
permission3(ctx, type2);
|
|
111324
111429
|
queryParams(url3, ["archived"]);
|
|
111325
111430
|
if (boolean5(url3.searchParams.get("archived"))) unsupported3("archived pipelines");
|
|
111326
|
-
const
|
|
111327
|
-
if (!match2[2]) return { status: 200, body: { results:
|
|
111328
|
-
const pipeline =
|
|
111431
|
+
const all8 = config2(ctx).pipelines;
|
|
111432
|
+
if (!match2[2]) return { status: 200, body: { results: all8.map((p2) => ({ ...p2, archived: false })) } };
|
|
111433
|
+
const pipeline = all8.find((p2) => p2.id === decodeURIComponent(match2[2]));
|
|
111329
111434
|
if (!pipeline) throw new HubError(404, "OBJECT_NOT_FOUND", "Pipeline not found.");
|
|
111330
111435
|
if (path6.includes("/stages")) {
|
|
111331
111436
|
if (!match2[3]) return { status: 200, body: { results: pipeline.stages.map((stage2) => ({ ...stage2, createdAt: pipeline.createdAt, updatedAt: pipeline.updatedAt, archived: false })) } };
|
|
@@ -111761,7 +111866,7 @@ function initializeCatalogIntegrations(env) {
|
|
|
111761
111866
|
}
|
|
111762
111867
|
function reconcileCatalogIntegrations(env) {
|
|
111763
111868
|
if (!hasTable5(env, "world_catalog_cursor")) return { activity: false };
|
|
111764
|
-
const
|
|
111869
|
+
const all8 = entries(env), before = env.events.tail;
|
|
111765
111870
|
let cursor4 = env.store.db.prepare("SELECT cursor FROM world_catalog_cursor WHERE id = 1").get().cursor;
|
|
111766
111871
|
let activity2 = false;
|
|
111767
111872
|
scan: for (let batch3 = env.events.list(cursor4, 100); batch3.length; batch3 = env.events.list(cursor4, 100)) {
|
|
@@ -111773,7 +111878,7 @@ function reconcileCatalogIntegrations(env) {
|
|
|
111773
111878
|
}
|
|
111774
111879
|
cursor4 = event3.cursor;
|
|
111775
111880
|
const view3 = catalogEvent(event3);
|
|
111776
|
-
for (const entry2 of
|
|
111881
|
+
for (const entry2 of all8) {
|
|
111777
111882
|
if (!matches(entry2.integration, view3)) continue;
|
|
111778
111883
|
const delay = entry2.integration.delay === void 0 ? 0 : parseDuration(entry2.integration.delay);
|
|
111779
111884
|
if (delay > 0) env.scheduler.enqueue({ atMs: env.clock.elapsedMs() + delay, kind: "integration.catalog", payload: { integration: entry2.ordinal, event: event3.cursor } });
|
|
@@ -122315,11 +122420,11 @@ function listPermissions(call2) {
|
|
|
122315
122420
|
const pageSize2 = integerParameter(params9, "pageSize", 100, 1, 100);
|
|
122316
122421
|
const binding2 = JSON.stringify(["permissions", file3.id]);
|
|
122317
122422
|
const offset16 = readPageToken(params9.get("pageToken"), binding2);
|
|
122318
|
-
const
|
|
122423
|
+
const all8 = effectivePermissions(call2.ctx, file3);
|
|
122319
122424
|
return json8(project8({
|
|
122320
122425
|
kind: "drive#permissionList",
|
|
122321
|
-
...offset16 + pageSize2 <
|
|
122322
|
-
permissions:
|
|
122426
|
+
...offset16 + pageSize2 < all8.length && { nextPageToken: pageToken(offset16 + pageSize2, binding2) },
|
|
122427
|
+
permissions: all8.slice(offset16, offset16 + pageSize2).map((entry2) => permissionResource(call2.ctx, entry2.grant))
|
|
122323
122428
|
}, mask(params9, "kind,nextPageToken,permissions(kind,id,type,role,allowFileDiscovery)", ["kind", "nextPageToken", "permissions"], { permissions: PERMISSION_FIELDS })));
|
|
122324
122429
|
}
|
|
122325
122430
|
function getPermission(call2) {
|
|
@@ -123057,10 +123162,10 @@ function leaves(part) {
|
|
|
123057
123162
|
return part.parts.length ? part.parts.flatMap(leaves) : [part];
|
|
123058
123163
|
}
|
|
123059
123164
|
function bodyText(root2) {
|
|
123060
|
-
const
|
|
123061
|
-
const plain3 =
|
|
123165
|
+
const all8 = leaves(root2).filter((p2) => !isAttachment(p2));
|
|
123166
|
+
const plain3 = all8.filter((p2) => p2.mimeType === "text/plain");
|
|
123062
123167
|
if (plain3.length) return plain3.map(partText).join("\n");
|
|
123063
|
-
return
|
|
123168
|
+
return all8.filter((p2) => p2.mimeType === "text/html").map((p2) => htmlToText(partText(p2))).join("\n");
|
|
123064
123169
|
}
|
|
123065
123170
|
function htmlToText(html2) {
|
|
123066
123171
|
return html2.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi, " ").replace(/<br\s*\/?>|<\/(p|div|li|h\d)>/gi, "\n").replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
@@ -123762,9 +123867,9 @@ function searchFor(r) {
|
|
|
123762
123867
|
function filterFor(r, labelIds = []) {
|
|
123763
123868
|
const search9 = searchFor(r), mailbox2 = r.caller.mailbox.address;
|
|
123764
123869
|
for (const id12 of labelIds) if (!getLabel2(r.ctx, mailbox2, id12)) invalid10(`Invalid label: ${id12}`);
|
|
123765
|
-
const
|
|
123766
|
-
const trashOk =
|
|
123767
|
-
const spamOk =
|
|
123870
|
+
const all8 = bool2(r.query, "includeSpamTrash");
|
|
123871
|
+
const trashOk = all8 || search9.includesTrash || labelIds.includes("TRASH");
|
|
123872
|
+
const spamOk = all8 || search9.includesSpam || labelIds.includes("SPAM");
|
|
123768
123873
|
return (row) => {
|
|
123769
123874
|
const ids2 = labelIdsOf(r.ctx, mailbox2, row.id);
|
|
123770
123875
|
if (!trashOk && ids2.includes("TRASH")) return false;
|
|
@@ -124809,12 +124914,12 @@ function listBuckets(call2) {
|
|
|
124809
124914
|
const limit2 = max === void 0 ? 1e4 : Number(max);
|
|
124810
124915
|
if (!Number.isInteger(limit2) || limit2 < 1 || limit2 > 1e4) throw new S3Error("InvalidArgument", "Argument max-buckets must be an integer between 1 and 10000", { ArgumentName: "max-buckets", ArgumentValue: max ?? "" });
|
|
124811
124916
|
const after = token2 === void 0 ? "" : Buffer.from(token2, "base64url").toString("utf8");
|
|
124812
|
-
const
|
|
124813
|
-
const page15 =
|
|
124917
|
+
const all8 = call2.ctx.store.db.prepare("SELECT * FROM s3_buckets ORDER BY name").all().filter((bucket2) => bucket2.name.startsWith(prefix2) && (region === void 0 || bucket2.region === region) && bucket2.name > after);
|
|
124918
|
+
const page15 = all8.slice(0, limit2);
|
|
124814
124919
|
return xml(call2, node3("ListAllMyBucketsResult", [
|
|
124815
124920
|
owner(call2.ctx),
|
|
124816
124921
|
node3("Buckets", page15.map((bucket2) => node3("Bucket", [el("Name", bucket2.name), el("CreationDate", iso3(bucket2.created_ms)), el("BucketRegion", bucket2.region)]))),
|
|
124817
|
-
...
|
|
124922
|
+
...all8.length > limit2 ? [el("ContinuationToken", Buffer.from(page15.at(-1).name).toString("base64url"))] : [],
|
|
124818
124923
|
...prefix2 ? [el("Prefix", prefix2)] : []
|
|
124819
124924
|
], true));
|
|
124820
124925
|
}
|
|
@@ -125453,7 +125558,7 @@ function migrate16(db2) {
|
|
|
125453
125558
|
db2.exec(SCHEMA7);
|
|
125454
125559
|
}
|
|
125455
125560
|
var one = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
125456
|
-
var
|
|
125561
|
+
var all2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
125457
125562
|
var org = (ctx) => one(ctx, "SELECT * FROM linear_org");
|
|
125458
125563
|
var userById = (ctx, id12) => one(ctx, "SELECT * FROM linear_users WHERE id = ?", id12);
|
|
125459
125564
|
var teamById = (ctx, id12) => one(ctx, "SELECT * FROM linear_teams WHERE id = ?", id12);
|
|
@@ -125462,17 +125567,17 @@ var labelById = (ctx, id12) => one(ctx, "SELECT * FROM linear_labels WHERE id =
|
|
|
125462
125567
|
var projectById = (ctx, id12) => one(ctx, "SELECT * FROM linear_projects WHERE id = ?", id12);
|
|
125463
125568
|
var issueById = (ctx, id12) => one(ctx, "SELECT * FROM linear_issues WHERE id = ?", id12);
|
|
125464
125569
|
var commentById = (ctx, id12) => one(ctx, "SELECT * FROM linear_comments WHERE id = ?", id12);
|
|
125465
|
-
var allUsers = (ctx) =>
|
|
125466
|
-
var allTeams = (ctx) =>
|
|
125467
|
-
var allStates = (ctx) =>
|
|
125468
|
-
var allLabels = (ctx) =>
|
|
125469
|
-
var allProjects = (ctx) =>
|
|
125470
|
-
var allIssues = (ctx) =>
|
|
125471
|
-
var allComments = (ctx) =>
|
|
125472
|
-
var teamMemberIds = (ctx, teamId) =>
|
|
125473
|
-
var userTeamIds = (ctx, userId) =>
|
|
125474
|
-
var issueLabelIds = (ctx, issueId) =>
|
|
125475
|
-
var projectTeamIds = (ctx, projectId) =>
|
|
125570
|
+
var allUsers = (ctx) => all2(ctx, "SELECT * FROM linear_users ORDER BY rowid");
|
|
125571
|
+
var allTeams = (ctx) => all2(ctx, "SELECT * FROM linear_teams ORDER BY rowid");
|
|
125572
|
+
var allStates = (ctx) => all2(ctx, "SELECT * FROM linear_states ORDER BY rowid");
|
|
125573
|
+
var allLabels = (ctx) => all2(ctx, "SELECT * FROM linear_labels ORDER BY rowid");
|
|
125574
|
+
var allProjects = (ctx) => all2(ctx, "SELECT * FROM linear_projects ORDER BY rowid");
|
|
125575
|
+
var allIssues = (ctx) => all2(ctx, "SELECT * FROM linear_issues ORDER BY rowid");
|
|
125576
|
+
var allComments = (ctx) => all2(ctx, "SELECT * FROM linear_comments ORDER BY rowid");
|
|
125577
|
+
var teamMemberIds = (ctx, teamId) => all2(ctx, "SELECT user_id FROM linear_team_members WHERE team_id = ? ORDER BY rowid", teamId).map((r) => r.user_id);
|
|
125578
|
+
var userTeamIds = (ctx, userId) => all2(ctx, "SELECT team_id FROM linear_team_members WHERE user_id = ? ORDER BY rowid", userId).map((r) => r.team_id);
|
|
125579
|
+
var issueLabelIds = (ctx, issueId) => all2(ctx, "SELECT label_id FROM linear_issue_labels WHERE issue_id = ? ORDER BY rowid", issueId).map((r) => r.label_id);
|
|
125580
|
+
var projectTeamIds = (ctx, projectId) => all2(ctx, "SELECT team_id FROM linear_project_teams WHERE project_id = ? ORDER BY rowid", projectId).map((r) => r.team_id);
|
|
125476
125581
|
function uuid5(ctx) {
|
|
125477
125582
|
const hex5 = ctx.ids.hex(32).split("");
|
|
125478
125583
|
hex5[12] = "4";
|
|
@@ -125514,7 +125619,7 @@ function gap3(what) {
|
|
|
125514
125619
|
var scalar = (comparator, column) => ({ kind: "scalar", comparator, get: (_, row) => row[column] });
|
|
125515
125620
|
var ts = (column) => scalar("date", column);
|
|
125516
125621
|
var db = (r) => r.ctx.store.db;
|
|
125517
|
-
var
|
|
125622
|
+
var all3 = (r, sql, ...args) => db(r).prepare(sql).all(...args);
|
|
125518
125623
|
var SPECS = {
|
|
125519
125624
|
Issue: {
|
|
125520
125625
|
id: scalar("id", "id"),
|
|
@@ -125537,10 +125642,10 @@ ${row.description ?? ""}` },
|
|
|
125537
125642
|
assignee: { kind: "one", type: "User", get: (r, row) => row.assignee_id ? userById(r.ctx, row.assignee_id) : void 0 },
|
|
125538
125643
|
creator: { kind: "one", type: "User", get: (r, row) => row.creator_id ? userById(r.ctx, row.creator_id) : void 0 },
|
|
125539
125644
|
project: { kind: "one", type: "Project", get: (r, row) => row.project_id ? projectById(r.ctx, row.project_id) : void 0 },
|
|
125540
|
-
parent: { kind: "one", type: "Issue", get: (r, row) => row.parent_id ?
|
|
125645
|
+
parent: { kind: "one", type: "Issue", get: (r, row) => row.parent_id ? all3(r, "SELECT * FROM linear_issues WHERE id = ?", row.parent_id)[0] : void 0 },
|
|
125541
125646
|
labels: { kind: "many", type: "IssueLabel", get: (r, row) => issueLabelIds(r.ctx, row.id).map((id12) => labelById(r.ctx, id12)) },
|
|
125542
|
-
children: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125543
|
-
comments: { kind: "many", type: "Comment", get: (r, row) =>
|
|
125647
|
+
children: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE parent_id = ? ORDER BY rowid", row.id) },
|
|
125648
|
+
comments: { kind: "many", type: "Comment", get: (r, row) => all3(r, "SELECT * FROM linear_comments WHERE issue_id = ? ORDER BY rowid", row.id) }
|
|
125544
125649
|
},
|
|
125545
125650
|
Team: {
|
|
125546
125651
|
id: scalar("id", "id"),
|
|
@@ -125551,7 +125656,7 @@ ${row.description ?? ""}` },
|
|
|
125551
125656
|
createdAt: ts("created_at"),
|
|
125552
125657
|
updatedAt: ts("updated_at"),
|
|
125553
125658
|
members: { kind: "many", type: "User", get: (r, row) => teamMemberIds(r.ctx, row.id).map((id12) => userById(r.ctx, id12)) },
|
|
125554
|
-
issues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125659
|
+
issues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE team_id = ? ORDER BY rowid", row.id) }
|
|
125555
125660
|
},
|
|
125556
125661
|
User: {
|
|
125557
125662
|
id: scalar("id", "id"),
|
|
@@ -125564,7 +125669,7 @@ ${row.description ?? ""}` },
|
|
|
125564
125669
|
app: { kind: "scalar", comparator: "boolean", get: () => false },
|
|
125565
125670
|
createdAt: ts("created_at"),
|
|
125566
125671
|
updatedAt: ts("updated_at"),
|
|
125567
|
-
assignedIssues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125672
|
+
assignedIssues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE assignee_id = ? ORDER BY rowid", row.id) }
|
|
125568
125673
|
},
|
|
125569
125674
|
WorkflowState: {
|
|
125570
125675
|
id: scalar("id", "id"),
|
|
@@ -125575,7 +125680,7 @@ ${row.description ?? ""}` },
|
|
|
125575
125680
|
createdAt: ts("created_at"),
|
|
125576
125681
|
updatedAt: ts("updated_at"),
|
|
125577
125682
|
team: { kind: "one", type: "Team", get: (r, row) => teamById(r.ctx, row.team_id) },
|
|
125578
|
-
issues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125683
|
+
issues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE state_id = ? ORDER BY rowid", row.id) }
|
|
125579
125684
|
},
|
|
125580
125685
|
IssueLabel: {
|
|
125581
125686
|
id: scalar("id", "id"),
|
|
@@ -125591,9 +125696,9 @@ ${row.description ?? ""}` },
|
|
|
125591
125696
|
body: scalar("string", "body"),
|
|
125592
125697
|
createdAt: ts("created_at"),
|
|
125593
125698
|
updatedAt: ts("updated_at"),
|
|
125594
|
-
issue: { kind: "one", type: "Issue", get: (r, row) =>
|
|
125699
|
+
issue: { kind: "one", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE id = ?", row.issue_id)[0] },
|
|
125595
125700
|
user: { kind: "one", type: "User", get: (r, row) => userById(r.ctx, row.user_id) },
|
|
125596
|
-
parent: { kind: "one", type: "Comment", get: (r, row) => row.parent_id ?
|
|
125701
|
+
parent: { kind: "one", type: "Comment", get: (r, row) => row.parent_id ? all3(r, "SELECT * FROM linear_comments WHERE id = ?", row.parent_id)[0] : void 0 }
|
|
125597
125702
|
},
|
|
125598
125703
|
Project: {
|
|
125599
125704
|
id: scalar("id", "id"),
|
|
@@ -125610,7 +125715,7 @@ ${row.description ?? ""}` },
|
|
|
125610
125715
|
searchableContent: { kind: "scalar", comparator: "content", get: (_, row) => `${row.name}
|
|
125611
125716
|
${row.description ?? ""}` },
|
|
125612
125717
|
lead: { kind: "one", type: "User", get: (r, row) => row.lead_id ? userById(r.ctx, row.lead_id) : void 0 },
|
|
125613
|
-
issues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125718
|
+
issues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE project_id = ? ORDER BY rowid", row.id) }
|
|
125614
125719
|
}
|
|
125615
125720
|
};
|
|
125616
125721
|
function dateValue2(r, value4) {
|
|
@@ -126492,8 +126597,8 @@ function seed17(ctx) {
|
|
|
126492
126597
|
states.set(s.name.toLowerCase(), stateId);
|
|
126493
126598
|
db2.prepare("INSERT INTO linear_states (id, team_id, name, type, color, position, description, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)").run(stateId, id12, s.name, s.type, s.color ?? "#bec2c8", position, ("description" in s ? s.description : void 0) ?? null, workspaceCreated, workspaceCreated);
|
|
126494
126599
|
});
|
|
126495
|
-
const
|
|
126496
|
-
const initial = t.default_state ?? (
|
|
126600
|
+
const all8 = t.states ?? LINEAR_DEFAULT_STATES;
|
|
126601
|
+
const initial = t.default_state ?? (all8.find((s) => s.type === "backlog") ?? all8.find((s) => s.type === "unstarted")).name;
|
|
126497
126602
|
db2.prepare("UPDATE linear_teams SET default_state_id = ? WHERE id = ?").run(states.get(initial.toLowerCase()), id12);
|
|
126498
126603
|
for (const l of t.labels) {
|
|
126499
126604
|
const labelId = uuid5(ctx);
|
|
@@ -127721,7 +127826,7 @@ function save6(ctx, value4) {
|
|
|
127721
127826
|
db2.prepare("INSERT OR REPLACE INTO stripe_objects (id, type, seq, created, customer, json) VALUES (?, ?, ?, ?, ?, ?)").run(value4.id, value4.object, seq2, typeof value4.created === "number" ? value4.created : 0, customer3, JSON.stringify(value4));
|
|
127722
127827
|
return value4;
|
|
127723
127828
|
}
|
|
127724
|
-
function
|
|
127829
|
+
function all4(ctx, type) {
|
|
127725
127830
|
return ctx.store.db.prepare("SELECT json FROM stripe_objects WHERE type = ? ORDER BY created DESC, seq DESC").all(type).map((r) => JSON.parse(r.json));
|
|
127726
127831
|
}
|
|
127727
127832
|
var BASE622 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
@@ -129041,7 +129146,7 @@ function markPaid(ctx, inv, at2, amount3 = inv.amount_remaining, offStripe = fal
|
|
|
129041
129146
|
const sub2 = inv.parent?.subscription_details?.subscription ? load(ctx, inv.parent.subscription_details.subscription) : void 0;
|
|
129042
129147
|
if (sub2 && (sub2.status === "past_due" || sub2.status === "unpaid" || sub2.status === "incomplete") && !openInvoices(ctx, sub2.id).some((i) => i.id !== inv.id)) save6(ctx, { ...sub2, status: "active" });
|
|
129043
129148
|
}
|
|
129044
|
-
var openInvoices = (ctx, subscription2) =>
|
|
129149
|
+
var openInvoices = (ctx, subscription2) => all4(ctx, "invoice").filter((i) => i.status === "open" && i.parent?.subscription_details?.subscription === subscription2);
|
|
129045
129150
|
function pay(ctx, inv, o) {
|
|
129046
129151
|
if (inv.status === "paid") invalid11("Invoice is already paid");
|
|
129047
129152
|
if (inv.status === "void") invalid11("You cannot pay a void invoice.");
|
|
@@ -129075,7 +129180,7 @@ function voidInvoice(ctx, inv) {
|
|
|
129075
129180
|
if (inv.status === "void") invalid11("This invoice is already void.", void 0, "invoice_not_editable");
|
|
129076
129181
|
const at2 = nowSeconds(ctx);
|
|
129077
129182
|
Object.assign(inv, { status: "void", amount_remaining: 0, next_payment_attempt: null, auto_advance: false, status_transitions: { ...inv.status_transitions, voided_at: at2 } });
|
|
129078
|
-
for (const item2 of
|
|
129183
|
+
for (const item2 of all4(ctx, "invoiceitem").filter((i) => i.invoice === inv.id)) save6(ctx, item2);
|
|
129079
129184
|
return save6(ctx, inv);
|
|
129080
129185
|
}
|
|
129081
129186
|
function prorate(ctx, sub2, item2, oldPrice, oldQuantity, newPrice, newQuantity) {
|
|
@@ -129162,7 +129267,7 @@ function searchCustomers(ctx, params9, present2) {
|
|
|
129162
129267
|
const limit2 = int2(params9.limit, "limit") ?? 10;
|
|
129163
129268
|
if (limit2 < 1 || limit2 > 100) invalid11("Invalid limit: must be between 1 and 100.", "limit");
|
|
129164
129269
|
const { clauses: tests, or } = clauses(query10);
|
|
129165
|
-
const matches7 =
|
|
129270
|
+
const matches7 = all4(ctx, "customer").filter((c) => !c.deleted && (or ? tests.some((t) => t(c)) : tests.every((t) => t(c))));
|
|
129166
129271
|
const token2 = str(params9.page, "page");
|
|
129167
129272
|
const offset16 = token2 === void 0 ? 0 : Number(/^page_(\d+)$/.exec(token2)?.[1] ?? NaN);
|
|
129168
129273
|
if (!Number.isSafeInteger(offset16)) invalid11(`Invalid page: ${token2}`, "page");
|
|
@@ -129236,7 +129341,7 @@ function customerFields(r, c) {
|
|
|
129236
129341
|
function presentCustomer(ctx, c) {
|
|
129237
129342
|
if (c.deleted) return deletedStub(c);
|
|
129238
129343
|
const now10 = nowSeconds(ctx);
|
|
129239
|
-
return { ...c, delinquent:
|
|
129344
|
+
return { ...c, delinquent: all4(ctx, "invoice").some((i) => i.customer === c.id && i.status === "open" && (i.due_date !== null && i.due_date < now10 || i.attempt_count > 0)) };
|
|
129240
129345
|
}
|
|
129241
129346
|
var read4 = (path6, supported3, run5, notes6) => ({ method: "GET", path: path6, supported: supported3, run: run5, coverage: notes6 ? { status: "partial", notes: notes6 } : { status: "supported" } });
|
|
129242
129347
|
var write3 = (method2, path6, supported3, run5, notes6) => ({ method: method2, path: path6, supported: supported3, run: run5, coverage: notes6 ? { status: "partial", notes: notes6 } : { status: "supported" } });
|
|
@@ -129250,7 +129355,7 @@ var stripeRoutes = [
|
|
|
129250
129355
|
}, "invoice_settings supports default_payment_method only; addresses, shipping, tax ids and cash balances are gaps"),
|
|
129251
129356
|
read4("/v1/customers", ["email", "created", ...PAGE], (r) => {
|
|
129252
129357
|
const email10 = str(r.params.email, "email", 512);
|
|
129253
|
-
const items = filterCreated(
|
|
129358
|
+
const items = filterCreated(all4(r.ctx, "customer").filter((c) => !c.deleted && (email10 === void 0 || c.email === email10)), r.params);
|
|
129254
129359
|
const result = page7(items, r.params, "/v1/customers", "customer");
|
|
129255
129360
|
return { ...result, data: result.data.map((c) => presentCustomer(r.ctx, c)) };
|
|
129256
129361
|
}),
|
|
@@ -129263,7 +129368,7 @@ var stripeRoutes = [
|
|
|
129263
129368
|
}),
|
|
129264
129369
|
write3("DELETE", "/v1/customers/:id", [], (r) => {
|
|
129265
129370
|
const c = liveCustomer(r.ctx, r.id, "id");
|
|
129266
|
-
for (const sub2 of
|
|
129371
|
+
for (const sub2 of all4(r.ctx, "subscription").filter((s) => s.customer === c.id && s.status !== "canceled")) {
|
|
129267
129372
|
const at2 = nowSeconds(r.ctx);
|
|
129268
129373
|
save6(r.ctx, { ...sub2, status: "canceled", canceled_at: at2, ended_at: at2, cancellation_details: { ...sub2.cancellation_details, reason: "cancellation_requested" } });
|
|
129269
129374
|
}
|
|
@@ -129273,20 +129378,20 @@ var stripeRoutes = [
|
|
|
129273
129378
|
/* ----------------------------- products and prices ---------------------------- */
|
|
129274
129379
|
read4("/v1/products", ["active", "ids", "created", ...PAGE], (r) => {
|
|
129275
129380
|
const active2 = bool3(r.params.active, "active"), ids2 = list9(r.params.ids, "ids")?.map((v, i) => str(v, `ids[${i}]`));
|
|
129276
|
-
return page7(filterCreated(
|
|
129381
|
+
return page7(filterCreated(all4(r.ctx, "product").filter((p2) => (active2 === void 0 || p2.active === active2) && (!ids2 || ids2.includes(p2.id))), r.params), r.params, "/v1/products", "product");
|
|
129277
129382
|
}),
|
|
129278
129383
|
read4("/v1/products/:id", [], (r) => find4(r.ctx, "product", r.id)),
|
|
129279
129384
|
read4("/v1/prices", ["product", "active", "type", "currency", "lookup_keys", "created", ...PAGE], (r) => {
|
|
129280
129385
|
const product2 = str(r.params.product, "product"), active2 = bool3(r.params.active, "active"), type = oneOf(r.params.type, "type", ["one_time", "recurring"]);
|
|
129281
129386
|
const currency = str(r.params.currency, "currency")?.toLowerCase(), keys5 = list9(r.params.lookup_keys, "lookup_keys")?.map((v, i) => str(v, `lookup_keys[${i}]`));
|
|
129282
|
-
return page7(filterCreated(
|
|
129387
|
+
return page7(filterCreated(all4(r.ctx, "price").filter((p2) => (!product2 || p2.product === product2) && (active2 === void 0 || p2.active === active2) && (!type || p2.type === type) && (!currency || p2.currency === currency) && (!keys5 || keys5.includes(p2.lookup_key))), r.params), r.params, "/v1/prices", "price");
|
|
129283
129388
|
}),
|
|
129284
129389
|
read4("/v1/prices/:id", [], (r) => find4(r.ctx, "price", r.id)),
|
|
129285
129390
|
/* --------------------------------- subscriptions ------------------------------- */
|
|
129286
129391
|
read4("/v1/subscriptions", ["customer", "price", "status", "created", ...PAGE], (r) => {
|
|
129287
129392
|
const customer3 = str(r.params.customer, "customer"), priceId = str(r.params.price, "price");
|
|
129288
129393
|
const status4 = oneOf(r.params.status, "status", ["active", "all", "canceled", "ended", "incomplete", "incomplete_expired", "past_due", "paused", "trialing", "unpaid"]);
|
|
129289
|
-
const items =
|
|
129394
|
+
const items = all4(r.ctx, "subscription").filter((s) => (!customer3 || s.customer === customer3) && (!priceId || s.items.data.some((i) => i.price.id === priceId)) && (status4 === "all" || (status4 === void 0 ? s.status !== "canceled" && s.status !== "incomplete_expired" : status4 === "ended" ? s.status === "canceled" : s.status === status4)));
|
|
129290
129395
|
return page7(filterCreated(items, r.params), r.params, "/v1/subscriptions", "subscription");
|
|
129291
129396
|
}, "without status, canceled subscriptions are left out, as Stripe does"),
|
|
129292
129397
|
read4("/v1/subscriptions/:id", [], (r) => find4(r.ctx, "subscription", r.id)),
|
|
@@ -129369,7 +129474,7 @@ var stripeRoutes = [
|
|
|
129369
129474
|
read4("/v1/invoices", ["customer", "subscription", "status", "collection_method", "created", ...PAGE], (r) => {
|
|
129370
129475
|
const customer3 = str(r.params.customer, "customer"), subscription2 = str(r.params.subscription, "subscription");
|
|
129371
129476
|
const status4 = oneOf(r.params.status, "status", ["draft", "open", "paid", "uncollectible", "void"]), method2 = oneOf(r.params.collection_method, "collection_method", ["charge_automatically", "send_invoice"]);
|
|
129372
|
-
return page7(filterCreated(
|
|
129477
|
+
return page7(filterCreated(all4(r.ctx, "invoice").filter((i) => (!customer3 || i.customer === customer3) && (!subscription2 || i.parent?.subscription_details?.subscription === subscription2) && (!status4 || i.status === status4) && (!method2 || i.collection_method === method2)), r.params), r.params, "/v1/invoices", "invoice");
|
|
129373
129478
|
}),
|
|
129374
129479
|
read4("/v1/invoices/:id", [], (r) => find4(r.ctx, "invoice", r.id)),
|
|
129375
129480
|
write3("POST", "/v1/invoices", ["customer", "auto_advance", "collection_method", "days_until_due", "due_date", "description", "footer", "custom_fields", "metadata", "currency", "pending_invoice_items_behavior", "subscription"], (r) => {
|
|
@@ -129401,7 +129506,7 @@ var stripeRoutes = [
|
|
|
129401
129506
|
period: { start: now10, end: now10 }
|
|
129402
129507
|
});
|
|
129403
129508
|
save6(r.ctx, inv);
|
|
129404
|
-
if (behavior === "include") for (const item2 of
|
|
129509
|
+
if (behavior === "include") for (const item2 of all4(r.ctx, "invoiceitem").filter((i) => i.customer === c.id && i.invoice === null && (!sub2 || i.parent?.subscription_details?.subscription === sub2.id)).reverse()) addLine(r.ctx, inv, item2);
|
|
129405
129510
|
return save6(r.ctx, recalc(inv));
|
|
129406
129511
|
}, "pending invoice items are included only with pending_invoice_items_behavior=include, the default for new API versions"),
|
|
129407
129512
|
write3("POST", "/v1/invoices/:id", ["description", "footer", "custom_fields", "metadata", "auto_advance", "days_until_due", "due_date"], (r) => {
|
|
@@ -129477,7 +129582,7 @@ var stripeRoutes = [
|
|
|
129477
129582
|
read4("/v1/invoiceitems", ["customer", "invoice", "pending", "created", ...PAGE], (r) => {
|
|
129478
129583
|
const customer3 = str(r.params.customer, "customer"), invoiceId = str(r.params.invoice, "invoice"), pending = bool3(r.params.pending, "pending");
|
|
129479
129584
|
return page7(
|
|
129480
|
-
filterCreated(
|
|
129585
|
+
filterCreated(all4(r.ctx, "invoiceitem").filter((i) => (!customer3 || i.customer === customer3) && (!invoiceId || i.invoice === invoiceId) && (pending === void 0 || i.invoice === null === pending)), r.params, "date"),
|
|
129481
129586
|
r.params,
|
|
129482
129587
|
"/v1/invoiceitems",
|
|
129483
129588
|
"invoiceitem"
|
|
@@ -129517,7 +129622,7 @@ var stripeRoutes = [
|
|
|
129517
129622
|
}, "card payments with a saved payment method or a test token such as pm_card_visa; pm_card_chargeDeclined* tokens decline; 3D Secure, manual capture and other methods are gaps"),
|
|
129518
129623
|
read4("/v1/payment_intents", ["customer", "created", ...PAGE], (r) => {
|
|
129519
129624
|
const customer3 = str(r.params.customer, "customer");
|
|
129520
|
-
return page7(filterCreated(
|
|
129625
|
+
return page7(filterCreated(all4(r.ctx, "payment_intent").filter((pi) => !customer3 || pi.customer === customer3), r.params), r.params, "/v1/payment_intents", "payment_intent");
|
|
129521
129626
|
}),
|
|
129522
129627
|
read4("/v1/payment_intents/:id", ["client_secret"], (r) => find4(r.ctx, "payment_intent", r.id)),
|
|
129523
129628
|
write3("POST", "/v1/payment_intents/:id/confirm", ["payment_method", "off_session", "receipt_email"], (r) => {
|
|
@@ -129540,7 +129645,7 @@ var stripeRoutes = [
|
|
|
129540
129645
|
/* -------------------------------- charges, refunds ------------------------------- */
|
|
129541
129646
|
read4("/v1/charges", ["customer", "payment_intent", "created", ...PAGE], (r) => {
|
|
129542
129647
|
const customer3 = str(r.params.customer, "customer"), intent = str(r.params.payment_intent, "payment_intent");
|
|
129543
|
-
return page7(filterCreated(
|
|
129648
|
+
return page7(filterCreated(all4(r.ctx, "charge").filter((ch) => (!customer3 || ch.customer === customer3) && (!intent || ch.payment_intent === intent)), r.params), r.params, "/v1/charges", "charge");
|
|
129544
129649
|
}),
|
|
129545
129650
|
read4("/v1/charges/:id", [], (r) => find4(r.ctx, "charge", r.id)),
|
|
129546
129651
|
write3("POST", "/v1/refunds", ["charge", "payment_intent", "amount", "reason", "metadata"], (r) => {
|
|
@@ -129558,7 +129663,7 @@ var stripeRoutes = [
|
|
|
129558
129663
|
}, "card refunds settle at once (status succeeded)"),
|
|
129559
129664
|
read4("/v1/refunds", ["charge", "payment_intent", "created", ...PAGE], (r) => {
|
|
129560
129665
|
const chargeId = str(r.params.charge, "charge"), intent = str(r.params.payment_intent, "payment_intent");
|
|
129561
|
-
return page7(filterCreated(
|
|
129666
|
+
return page7(filterCreated(all4(r.ctx, "refund").filter((re) => (!chargeId || re.charge === chargeId) && (!intent || re.payment_intent === intent)), r.params), r.params, "/v1/refunds", "refund");
|
|
129562
129667
|
}),
|
|
129563
129668
|
read4("/v1/refunds/:id", [], (r) => find4(r.ctx, "refund", r.id)),
|
|
129564
129669
|
read4("/v1/balance", [], (r) => load(r.ctx, "__balance"), "available and pending card funds; payouts and fees are not modeled")
|
|
@@ -129726,7 +129831,7 @@ function seed19(ctx) {
|
|
|
129726
129831
|
save6(ctx, row);
|
|
129727
129832
|
}
|
|
129728
129833
|
}
|
|
129729
|
-
if (sub2) save6(ctx, { ...load(ctx, sub2.id), latest_invoice:
|
|
129834
|
+
if (sub2) save6(ctx, { ...load(ctx, sub2.id), latest_invoice: all4(ctx, "invoice").find((i) => i.parent?.subscription_details?.subscription === sub2.id)?.id ?? null });
|
|
129730
129835
|
}
|
|
129731
129836
|
for (const p2 of data5.payments) {
|
|
129732
129837
|
const cus = p2.customer ? load(ctx, customers.get(p2.customer).id) : null, t = at2(p2.created);
|
|
@@ -129750,7 +129855,7 @@ function credentials18(ctx) {
|
|
|
129750
129855
|
|
|
129751
129856
|
// packages/server/src/twins/stripe/state.ts
|
|
129752
129857
|
function dumpState18(ctx) {
|
|
129753
|
-
const of = (type) => present(
|
|
129858
|
+
const of = (type) => present(all4(ctx, type).reverse());
|
|
129754
129859
|
return {
|
|
129755
129860
|
balance: present(load(ctx, "__balance")),
|
|
129756
129861
|
customers: of("customer"),
|
|
@@ -130382,8 +130487,8 @@ var flagUser = (column, value4) => (call2) => {
|
|
|
130382
130487
|
function userMemberships(call2) {
|
|
130383
130488
|
const query10 = params7(call2, ["limit", "offset"]);
|
|
130384
130489
|
const user8 = userFor2(call2);
|
|
130385
|
-
const
|
|
130386
|
-
return respond3(call2, 200, { data: list10(
|
|
130490
|
+
const all8 = call2.ctx.store.db.prepare("SELECT * FROM clerk_memberships WHERE user_id = ? ORDER BY created_ms, id").all(user8.id);
|
|
130491
|
+
return respond3(call2, 200, { data: list10(all8, query10).map((member4) => membershipJson(call2.ctx, member4)), total_count: all8.length });
|
|
130387
130492
|
}
|
|
130388
130493
|
function orgFor(call2) {
|
|
130389
130494
|
const org5 = getOrg(call2.ctx, call2.ids[0]);
|
|
@@ -132769,7 +132874,7 @@ function migrate22(db2) {
|
|
|
132769
132874
|
db2.exec(SCHEMA13);
|
|
132770
132875
|
}
|
|
132771
132876
|
var one2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
132772
|
-
var
|
|
132877
|
+
var all5 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
132773
132878
|
var run2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).run(...args);
|
|
132774
132879
|
function uuid9(ctx) {
|
|
132775
132880
|
const h = ctx.ids.hex(32).split("");
|
|
@@ -132995,7 +133100,7 @@ function primary(ctx, attr, data5) {
|
|
|
132995
133100
|
}
|
|
132996
133101
|
}
|
|
132997
133102
|
function currentValues(ctx, parentId, attributeId) {
|
|
132998
|
-
return
|
|
133103
|
+
return all5(ctx, "SELECT * FROM attio_values WHERE parent_id = ? AND attribute_id = ? AND active_until IS NULL ORDER BY id", parentId, attributeId);
|
|
132999
133104
|
}
|
|
133000
133105
|
function writeValues(ctx, parentId, attr, items, by2, replace, now10 = attioTime(ctx.clock.nowMs())) {
|
|
133001
133106
|
const current = currentValues(ctx, parentId, attr.id);
|
|
@@ -133071,7 +133176,7 @@ function findObject(ctx, key3) {
|
|
|
133071
133176
|
function findList(ctx, key3) {
|
|
133072
133177
|
return one2(ctx, "SELECT * FROM attio_lists WHERE api_slug = ? OR id = ?", key3, key3) ?? notFound9(`List with slug/ID "${key3}" not found.`);
|
|
133073
133178
|
}
|
|
133074
|
-
var attributesOf = (ctx, parentId) =>
|
|
133179
|
+
var attributesOf = (ctx, parentId) => all5(ctx, "SELECT * FROM attio_attributes WHERE parent_id = ? ORDER BY position", parentId);
|
|
133075
133180
|
var listParent = (list14) => `list:${list14.id}`;
|
|
133076
133181
|
function objectShape(ctx, o) {
|
|
133077
133182
|
return { id: { workspace_id: workspaceId(ctx), object_id: o.id }, api_slug: o.api_slug, singular_noun: o.singular_noun, plural_noun: o.plural_noun, created_at: o.created_at };
|
|
@@ -133101,7 +133206,7 @@ function memberShape(ctx, m) {
|
|
|
133101
133206
|
return { id: { workspace_id: workspaceId(ctx), workspace_member_id: m.id }, first_name: m.first_name, last_name: m.last_name, avatar_url: null, email_address: m.email, created_at: m.created_at, access_level: m.access_level };
|
|
133102
133207
|
}
|
|
133103
133208
|
function valuesOf(ctx, parentId, attributes2, computed) {
|
|
133104
|
-
const rows7 =
|
|
133209
|
+
const rows7 = all5(ctx, "SELECT * FROM attio_values WHERE parent_id = ? AND active_until IS NULL ORDER BY id", parentId);
|
|
133105
133210
|
return Object.fromEntries(attributes2.map((a) => [a.api_slug, computed(a) ?? rows7.filter((r) => r.attribute_id === a.id).map((r) => valueObject(ctx, a, r))]));
|
|
133106
133211
|
}
|
|
133107
133212
|
function recordShape(ctx, r) {
|
|
@@ -133119,7 +133224,7 @@ function recordShape(ctx, r) {
|
|
|
133119
133224
|
if (o.api_slug === "companies" && a.api_slug === "team") {
|
|
133120
133225
|
const people3 = one2(ctx, "SELECT * FROM attio_objects WHERE api_slug = 'people'");
|
|
133121
133226
|
const company = one2(ctx, "SELECT * FROM attio_attributes WHERE parent_id = ? AND api_slug = 'company'", people3.id);
|
|
133122
|
-
return
|
|
133227
|
+
return all5(ctx, "SELECT * FROM attio_values WHERE attribute_id = ? AND active_until IS NULL AND json_extract(data, '$.target_record_id') = ? ORDER BY id", company.id, r.id).map((v) => ({ active_from: v.active_from, active_until: null, created_by_actor: JSON.parse(v.created_by), target_object: "people", target_record_id: v.parent_id, attribute_type: "record-reference" }));
|
|
133123
133228
|
}
|
|
133124
133229
|
return void 0;
|
|
133125
133230
|
})
|
|
@@ -133187,7 +133292,7 @@ function writeAll(r, parentId, attributes2, values2, mode, objectSlug) {
|
|
|
133187
133292
|
const items = list14.map((v) => parseValue(r.ctx, attr, v));
|
|
133188
133293
|
if (attr.is_unique) for (const item2 of items) {
|
|
133189
133294
|
const key4 = primary(r.ctx, attr, item2);
|
|
133190
|
-
const clash =
|
|
133295
|
+
const clash = all5(r.ctx, "SELECT * FROM attio_values WHERE attribute_id = ? AND active_until IS NULL AND parent_id != ?", attr.id, parentId).find((v) => primary(r.ctx, attr, JSON.parse(v.data)) === key4);
|
|
133191
133296
|
if (clash) invalid15(`A record with the value "${String(key4)}" for the unique attribute "${attr.api_slug}" already exists.`, "uniqueness_conflict");
|
|
133192
133297
|
}
|
|
133193
133298
|
writeValues(r.ctx, parentId, attr, items, tokenActor(r), mode !== "append" || !attr.is_multiselect);
|
|
@@ -133239,7 +133344,7 @@ function query8(r, rows7, attributes2) {
|
|
|
133239
133344
|
const { limit: limit2, offset: offset16 } = limitOffset(r.body);
|
|
133240
133345
|
return kept.slice(offset16, offset16 + limit2);
|
|
133241
133346
|
}
|
|
133242
|
-
var records = (r, object14) =>
|
|
133347
|
+
var records = (r, object14) => all5(r.ctx, "SELECT * FROM attio_records WHERE object_id = ? ORDER BY created_at, rowid", object14.id);
|
|
133243
133348
|
function memberRef(r, value4) {
|
|
133244
133349
|
const key3 = value4?.referenced_actor_id ?? value4?.workspace_member_email_address;
|
|
133245
133350
|
const m = typeof key3 === "string" ? one2(r.ctx, "SELECT * FROM attio_members WHERE id = ? OR lower(email) = lower(?)", key3, key3) : void 0;
|
|
@@ -133281,7 +133386,7 @@ var attioRoutes = [
|
|
|
133281
133386
|
workspace_logo_url: null
|
|
133282
133387
|
};
|
|
133283
133388
|
} },
|
|
133284
|
-
{ method: "GET", path: "/v2/objects", coverage: { status: "supported" }, run: (r) => ({ data:
|
|
133389
|
+
{ method: "GET", path: "/v2/objects", coverage: { status: "supported" }, run: (r) => ({ data: all5(r.ctx, "SELECT * FROM attio_objects ORDER BY rowid").map((o) => objectShape(r.ctx, o)) }) },
|
|
133285
133390
|
{ method: "GET", path: "/v2/objects/:object", coverage: { status: "supported" }, run: (r) => ({ data: objectShape(r.ctx, findObject(r.ctx, r.param("object"))) }) },
|
|
133286
133391
|
{ method: "GET", path: "/v2/:target/:identifier/attributes", query: { known: ["limit", "offset", "show_archived"], supported: ["limit", "offset", "show_archived"] }, coverage: { status: "supported" }, run: (r) => {
|
|
133287
133392
|
const target4 = r.param("target");
|
|
@@ -133322,7 +133427,7 @@ var attioRoutes = [
|
|
|
133322
133427
|
const given = (r.data.values ?? {})[attr.api_slug] ?? (r.data.values ?? {})[attr.id];
|
|
133323
133428
|
if (given === void 0) invalid15(`The values must include the matching attribute "${attr.api_slug}".`, "missing_value");
|
|
133324
133429
|
const wanted = (Array.isArray(given) ? given : [given]).map((v) => primary(r.ctx, attr, parseValue(r.ctx, attr, v)));
|
|
133325
|
-
const owners = new Set(
|
|
133430
|
+
const owners = new Set(all5(r.ctx, "SELECT * FROM attio_values WHERE attribute_id = ? AND active_until IS NULL", attr.id).filter((v) => wanted.includes(primary(r.ctx, attr, JSON.parse(v.data)))).map((v) => v.parent_id));
|
|
133326
133431
|
if (owners.size > 1) invalid15("More than one record matches the given value.", "multiple_match_results");
|
|
133327
133432
|
if (!owners.size) return { data: recordShape(r.ctx, createRecord3(r, object14, r.data.values)) };
|
|
133328
133433
|
const id12 = [...owners][0];
|
|
@@ -133355,7 +133460,7 @@ var attioRoutes = [
|
|
|
133355
133460
|
},
|
|
133356
133461
|
{ method: "DELETE", path: RECORD_PATH, coverage: { status: "supported" }, run: (r) => {
|
|
133357
133462
|
const rec = findRecord(r, findObject(r.ctx, r.param("object")));
|
|
133358
|
-
for (const e of
|
|
133463
|
+
for (const e of all5(r.ctx, "SELECT * FROM attio_entries WHERE record_id = ?", rec.id)) {
|
|
133359
133464
|
run2(r.ctx, "DELETE FROM attio_values WHERE parent_id = ?", e.id);
|
|
133360
133465
|
run2(r.ctx, "DELETE FROM attio_entries WHERE id = ?", e.id);
|
|
133361
133466
|
}
|
|
@@ -133372,7 +133477,7 @@ var attioRoutes = [
|
|
|
133372
133477
|
const object14 = findObject(r.ctx, r.param("object")), rec = findRecord(r, object14);
|
|
133373
133478
|
const attr = attributesOf(r.ctx, object14.id).find((a) => a.api_slug === r.param("attribute") || a.id === r.param("attribute")) ?? notFound9(`Attribute with slug/ID "${r.param("attribute")}" not found.`);
|
|
133374
133479
|
const historic = r.query.get("show_historic") === "true";
|
|
133375
|
-
const rows7 =
|
|
133480
|
+
const rows7 = all5(r.ctx, `SELECT * FROM attio_values WHERE parent_id = ? AND attribute_id = ? ${historic ? "" : "AND active_until IS NULL"} ORDER BY id`, rec.id, attr.id);
|
|
133376
133481
|
const { limit: limit2, offset: offset16 } = limitOffset({ limit: r.query.get("limit") ?? void 0, offset: r.query.get("offset") ?? void 0 });
|
|
133377
133482
|
return { data: rows7.slice(offset16, offset16 + limit2).map((v) => valueObject(r.ctx, attr, v)) };
|
|
133378
133483
|
}
|
|
@@ -133384,11 +133489,11 @@ var attioRoutes = [
|
|
|
133384
133489
|
coverage: { status: "supported" },
|
|
133385
133490
|
run: (r) => {
|
|
133386
133491
|
const rec = findRecord(r, findObject(r.ctx, r.param("object")));
|
|
133387
|
-
return { data:
|
|
133492
|
+
return { data: all5(r.ctx, "SELECT e.*, l.api_slug FROM attio_entries e JOIN attio_lists l ON l.id = e.list_id WHERE e.record_id = ? ORDER BY e.created_at", rec.id).map((e) => ({ list_id: e.list_id, list_api_slug: e.api_slug, entry_id: e.id, created_at: e.created_at })) };
|
|
133388
133493
|
}
|
|
133389
133494
|
},
|
|
133390
133495
|
/* ------------------------------------ lists ------------------------------------ */
|
|
133391
|
-
{ method: "GET", path: "/v2/lists", coverage: { status: "supported" }, run: (r) => ({ data:
|
|
133496
|
+
{ method: "GET", path: "/v2/lists", coverage: { status: "supported" }, run: (r) => ({ data: all5(r.ctx, "SELECT * FROM attio_lists ORDER BY rowid").map((l) => listShape(r.ctx, l)) }) },
|
|
133392
133497
|
{ method: "GET", path: "/v2/lists/:list", coverage: { status: "supported" }, run: (r) => ({ data: listShape(r.ctx, findList(r.ctx, r.param("list"))) }) },
|
|
133393
133498
|
{
|
|
133394
133499
|
method: "POST",
|
|
@@ -133396,7 +133501,7 @@ var attioRoutes = [
|
|
|
133396
133501
|
coverage: { status: "partial", notes: "filters and sorts on the list's own attributes" },
|
|
133397
133502
|
run: (r) => {
|
|
133398
133503
|
const list14 = findList(r.ctx, r.param("list"));
|
|
133399
|
-
return { data: query8(r,
|
|
133504
|
+
return { data: query8(r, all5(r.ctx, "SELECT * FROM attio_entries WHERE list_id = ? ORDER BY created_at, rowid", list14.id), attributesOf(r.ctx, listParent(list14))).map((e) => entryShape(r.ctx, e)) };
|
|
133400
133505
|
}
|
|
133401
133506
|
},
|
|
133402
133507
|
{
|
|
@@ -133435,7 +133540,7 @@ var attioRoutes = [
|
|
|
133435
133540
|
return {};
|
|
133436
133541
|
} },
|
|
133437
133542
|
/* ------------------------------- members, notes, tasks ----------------------------- */
|
|
133438
|
-
{ method: "GET", path: "/v2/workspace_members", coverage: { status: "supported" }, run: (r) => ({ data:
|
|
133543
|
+
{ method: "GET", path: "/v2/workspace_members", coverage: { status: "supported" }, run: (r) => ({ data: all5(r.ctx, "SELECT * FROM attio_members ORDER BY rowid").map((m) => memberShape(r.ctx, m)) }) },
|
|
133439
133544
|
{
|
|
133440
133545
|
method: "GET",
|
|
133441
133546
|
path: "/v2/workspace_members/:id",
|
|
@@ -133450,7 +133555,7 @@ var attioRoutes = [
|
|
|
133450
133555
|
run: (r) => {
|
|
133451
133556
|
const object14 = r.query.get("parent_object"), record10 = r.query.get("parent_record_id");
|
|
133452
133557
|
const objectSlug = object14 ? findObject(r.ctx, object14).api_slug : void 0;
|
|
133453
|
-
const notes6 =
|
|
133558
|
+
const notes6 = all5(r.ctx, "SELECT * FROM attio_notes ORDER BY created_at, rowid").filter((n) => (!objectSlug || n.parent_object === objectSlug) && (!record10 || n.parent_record_id === record10));
|
|
133454
133559
|
const { limit: limit2, offset: offset16 } = limitOffset({ limit: r.query.get("limit") ?? void 0, offset: r.query.get("offset") ?? void 0 }, 10);
|
|
133455
133560
|
return { data: notes6.slice(offset16, offset16 + limit2).map((n) => noteShape2(r.ctx, n)) };
|
|
133456
133561
|
}
|
|
@@ -133502,7 +133607,7 @@ var attioRoutes = [
|
|
|
133502
133607
|
const linkedObject = q.get("linked_object") ? findObject(r.ctx, q.get("linked_object")).id : void 0;
|
|
133503
133608
|
const assignee = q.get("assignee") ? one2(r.ctx, "SELECT * FROM attio_members WHERE id = ? OR lower(email) = lower(?)", q.get("assignee"), q.get("assignee"))?.id ?? "__none__" : void 0;
|
|
133504
133609
|
const done = q.get("is_completed");
|
|
133505
|
-
let tasks =
|
|
133610
|
+
let tasks = all5(r.ctx, "SELECT * FROM attio_tasks ORDER BY created_at, rowid").filter((t) => {
|
|
133506
133611
|
const linked = JSON.parse(t.linked);
|
|
133507
133612
|
return (!linkedObject || linked.some((l) => l.target_object_id === linkedObject)) && (!q.get("linked_record_id") || linked.some((l) => l.target_record_id === q.get("linked_record_id"))) && (!assignee || JSON.parse(t.assignees).some((a) => a.referenced_actor_id === assignee)) && (done === null || String(!!t.is_completed) === done);
|
|
133508
133613
|
});
|
|
@@ -133678,7 +133783,7 @@ function seed23(ctx) {
|
|
|
133678
133783
|
run2(ctx, "INSERT INTO attio_records (id, object_id, created_at, created_by) VALUES (?, ?, ?, ?)", id12, objectIds.get(slug11), at2(r.created), JSON.stringify(actor(members4.get(data5.agent))));
|
|
133679
133784
|
}
|
|
133680
133785
|
const write4 = (parentId, parent2, values2, when11, by2) => {
|
|
133681
|
-
const attributes2 =
|
|
133786
|
+
const attributes2 = all5(ctx, "SELECT * FROM attio_attributes WHERE parent_id = ? ORDER BY position", parent2);
|
|
133682
133787
|
for (const [slug11, raw3] of Object.entries(values2)) {
|
|
133683
133788
|
const attr = attributes2.find((a) => a.api_slug === slug11);
|
|
133684
133789
|
if (!attr) throw new AnchaError("SCENE_INVALID", `seed.attio: no attribute "${slug11}"`);
|
|
@@ -133736,9 +133841,9 @@ function credentials22(ctx) {
|
|
|
133736
133841
|
function dumpState22(ctx) {
|
|
133737
133842
|
const flat2 = (parentId, attributes2) => Object.fromEntries(attributes2.map((a) => [
|
|
133738
133843
|
a.api_slug,
|
|
133739
|
-
|
|
133844
|
+
all5(ctx, "SELECT * FROM attio_values WHERE parent_id = ? AND attribute_id = ? AND active_until IS NULL ORDER BY id", parentId, a.id).map((v) => primary(ctx, a, JSON.parse(v.data)))
|
|
133740
133845
|
]).filter(([, v]) => v.length));
|
|
133741
|
-
const objects =
|
|
133846
|
+
const objects = all5(ctx, "SELECT * FROM attio_objects ORDER BY rowid");
|
|
133742
133847
|
const name5 = (recordId) => {
|
|
133743
133848
|
const r = one2(ctx, "SELECT * FROM attio_records WHERE id = ?", recordId);
|
|
133744
133849
|
if (!r) return recordId;
|
|
@@ -133750,18 +133855,18 @@ function dumpState22(ctx) {
|
|
|
133750
133855
|
return m ? `${m.first_name} ${m.last_name}`.trim() : id12;
|
|
133751
133856
|
};
|
|
133752
133857
|
return {
|
|
133753
|
-
members:
|
|
133858
|
+
members: all5(ctx, "SELECT id, first_name, last_name, email, access_level FROM attio_members ORDER BY rowid"),
|
|
133754
133859
|
objects: objects.map((o) => ({ id: o.id, api_slug: o.api_slug, attributes: attributesOf(ctx, o.id).map((a) => ({ api_slug: a.api_slug, type: a.type })) })),
|
|
133755
|
-
records:
|
|
133756
|
-
lists:
|
|
133860
|
+
records: all5(ctx, "SELECT * FROM attio_records ORDER BY created_at, rowid").map((r) => ({ id: r.id, object: objects.find((o) => o.id === r.object_id).api_slug, created_at: r.created_at, values: flat2(r.id, attributesOf(ctx, r.object_id)) })),
|
|
133861
|
+
lists: all5(ctx, "SELECT * FROM attio_lists ORDER BY rowid").map((l) => ({
|
|
133757
133862
|
id: l.id,
|
|
133758
133863
|
api_slug: l.api_slug,
|
|
133759
133864
|
name: l.name,
|
|
133760
133865
|
parent_object: l.parent_object,
|
|
133761
|
-
entries:
|
|
133866
|
+
entries: all5(ctx, "SELECT * FROM attio_entries WHERE list_id = ? ORDER BY created_at, rowid", l.id).map((e) => ({ id: e.id, record_id: e.record_id, record: name5(e.record_id), values: flat2(e.id, attributesOf(ctx, listParent(l))) }))
|
|
133762
133867
|
})),
|
|
133763
|
-
notes:
|
|
133764
|
-
tasks:
|
|
133868
|
+
notes: all5(ctx, "SELECT * FROM attio_notes ORDER BY created_at, rowid").map((n) => ({ ...noteShape2(ctx, n), parent_label: name5(n.parent_record_id), author: member4(JSON.parse(n.created_by).id) })),
|
|
133869
|
+
tasks: all5(ctx, "SELECT * FROM attio_tasks ORDER BY created_at, rowid").map((t) => taskShape(ctx, t))
|
|
133765
133870
|
};
|
|
133766
133871
|
}
|
|
133767
133872
|
|
|
@@ -134044,7 +134149,7 @@ function listing(ctx, cursor4) {
|
|
|
134044
134149
|
}
|
|
134045
134150
|
function page9(ctx, cursor4) {
|
|
134046
134151
|
if (cursor4.o >= 0) {
|
|
134047
|
-
const
|
|
134152
|
+
const all8 = listing(ctx, cursor4), slice = all8.slice(cursor4.o, cursor4.o + cursor4.l), more = cursor4.o + cursor4.l < all8.length;
|
|
134048
134153
|
return json15({ entries: slice, cursor: encodeCursor3(more ? { ...cursor4, o: cursor4.o + cursor4.l } : { ...cursor4, o: -1 }), has_more: more });
|
|
134049
134154
|
}
|
|
134050
134155
|
const changed = ctx.store.db.prepare("SELECT path_lower, MAX(seq) AS seq FROM dbx_changes WHERE seq > ? GROUP BY path_lower ORDER BY MAX(seq)").all(cursor4.s).map((row) => row.path_lower).filter((key3) => cursor4.p === "" ? cursor4.r || !key3.slice(1).includes("/") : key3.startsWith(`${cursor4.p}/`) && (cursor4.r || !key3.slice(cursor4.p.length + 1).includes("/")));
|
|
@@ -136081,15 +136186,15 @@ function search6(call2, query10) {
|
|
|
136081
136186
|
odata(call2, ["$top", "$skiptoken", "$orderby"]);
|
|
136082
136187
|
const tokens2 = query10.toLowerCase().split(/\s+/).filter(Boolean);
|
|
136083
136188
|
if (!tokens2.length) throw invalid17("The search query is empty.");
|
|
136084
|
-
const scope2 = target3(call2),
|
|
136189
|
+
const scope2 = target3(call2), all8 = [];
|
|
136085
136190
|
const visit3 = (node5) => {
|
|
136086
136191
|
for (const child2 of childrenOf2(call2.ctx, node5.id)) {
|
|
136087
|
-
|
|
136192
|
+
all8.push(child2);
|
|
136088
136193
|
if (child2.kind === "folder") visit3(child2);
|
|
136089
136194
|
}
|
|
136090
136195
|
};
|
|
136091
136196
|
visit3(scope2);
|
|
136092
|
-
const matches7 =
|
|
136197
|
+
const matches7 = all8.filter((item2) => {
|
|
136093
136198
|
const text21 = `${item2.name}
|
|
136094
136199
|
${textOf2(item2) ?? ""}`.toLowerCase();
|
|
136095
136200
|
return tokens2.every((token2) => text21.includes(token2));
|
|
@@ -136350,7 +136455,7 @@ function save8(ctx, kind, doc, parent2 = null) {
|
|
|
136350
136455
|
ctx.store.db.prepare("INSERT INTO shopify_objects (gid, kind, num, parent, json) VALUES (?, ?, ?, ?, ?) ON CONFLICT (gid) DO UPDATE SET json = excluded.json").run(doc.gid, kind, numOf(doc.gid) ?? 0, parent2, JSON.stringify(doc));
|
|
136351
136456
|
return doc;
|
|
136352
136457
|
}
|
|
136353
|
-
function
|
|
136458
|
+
function all6(ctx, kind) {
|
|
136354
136459
|
return ctx.store.db.prepare("SELECT json FROM shopify_objects WHERE kind = ? ORDER BY num").all(kind).map((r) => JSON.parse(r.json));
|
|
136355
136460
|
}
|
|
136356
136461
|
function childrenOf3(ctx, parent2, kind) {
|
|
@@ -136424,7 +136529,7 @@ function level2(ctx, item2, location) {
|
|
|
136424
136529
|
}
|
|
136425
136530
|
function committed(ctx, item2, location) {
|
|
136426
136531
|
let n = 0;
|
|
136427
|
-
for (const fo of
|
|
136532
|
+
for (const fo of all6(ctx, "FulfillmentOrder")) {
|
|
136428
136533
|
if (fo.location !== location) continue;
|
|
136429
136534
|
const order4 = load3(ctx, fo.order);
|
|
136430
136535
|
if (order4.cancelled_ms !== null) continue;
|
|
@@ -136698,7 +136803,7 @@ function connection2(items, args, key3, shape3) {
|
|
|
136698
136803
|
var byNum = (d) => ({ id: numOf(d.gid) });
|
|
136699
136804
|
var pathOf3 = (path6) => path6 ? [...pathOf3(path6.prev), path6.key] : [];
|
|
136700
136805
|
var firstOf = (items, n) => typeof n === "number" ? items.slice(0, Math.max(0, n)) : items;
|
|
136701
|
-
var currencyOf = (ctx) =>
|
|
136806
|
+
var currencyOf = (ctx) => all6(ctx, "Shop")[0].currency;
|
|
136702
136807
|
var bag = (ctx, c) => {
|
|
136703
136808
|
const m = { amount: decimal2(c), currencyCode: currencyOf(ctx) };
|
|
136704
136809
|
return { shopMoney: m, presentmentMoney: m };
|
|
@@ -136798,7 +136903,7 @@ function distance(ms) {
|
|
|
136798
136903
|
return years === 1 ? "about 1 year" : `about ${years} years`;
|
|
136799
136904
|
}
|
|
136800
136905
|
function shopShape(req) {
|
|
136801
|
-
const s =
|
|
136906
|
+
const s = all6(req.ctx, "Shop")[0], host = `${s.domain}.myshopify.com`;
|
|
136802
136907
|
return {
|
|
136803
136908
|
__typename: "Shop",
|
|
136804
136909
|
id: s.gid,
|
|
@@ -136825,7 +136930,7 @@ function shopShape(req) {
|
|
|
136825
136930
|
};
|
|
136826
136931
|
}
|
|
136827
136932
|
function locationShape(req, l) {
|
|
136828
|
-
const primary3 =
|
|
136933
|
+
const primary3 = all6(req.ctx, "Location")[0].gid === l.gid, a = l.address, country = a.country_code ?? "US";
|
|
136829
136934
|
return {
|
|
136830
136935
|
__typename: "Location",
|
|
136831
136936
|
id: l.gid,
|
|
@@ -136905,7 +137010,7 @@ function itemShape(req, item2) {
|
|
|
136905
137010
|
};
|
|
136906
137011
|
}
|
|
136907
137012
|
function variantStock(req, v) {
|
|
136908
|
-
const levels3 = levelsOf(req.ctx, { item: v.item }), locations = new Map(
|
|
137013
|
+
const levels3 = levelsOf(req.ctx, { item: v.item }), locations = new Map(all6(req.ctx, "Location").map((l) => [l.gid, l]));
|
|
136909
137014
|
const active2 = levels3.filter((l) => locations.get(l.location)?.active);
|
|
136910
137015
|
return { available: active2.reduce((n, l) => n + l.available, 0), online: active2.filter((l) => locations.get(l.location).fulfills_online_orders).reduce((n, l) => n + Math.max(0, l.available), 0) };
|
|
136911
137016
|
}
|
|
@@ -136960,7 +137065,7 @@ function productShape(req, p2) {
|
|
|
136960
137065
|
const variants = () => childrenOf3(req.ctx, p2.gid, "ProductVariant");
|
|
136961
137066
|
const tracked2 = () => variants().filter((v) => load3(req.ctx, v.item).tracked);
|
|
136962
137067
|
const prices = () => variants().map((v) => v.price_cents);
|
|
136963
|
-
const host = `${
|
|
137068
|
+
const host = `${all6(req.ctx, "Shop")[0].domain}.myshopify.com`;
|
|
136964
137069
|
return {
|
|
136965
137070
|
__typename: "Product",
|
|
136966
137071
|
id: p2.gid,
|
|
@@ -137004,7 +137109,7 @@ function productShape(req, p2) {
|
|
|
137004
137109
|
};
|
|
137005
137110
|
}
|
|
137006
137111
|
function customerShape(req, c) {
|
|
137007
|
-
const orders = () =>
|
|
137112
|
+
const orders = () => all6(req.ctx, "Order").filter((o) => o.customer === c.gid);
|
|
137008
137113
|
const name5 = [c.first_name, c.last_name].filter(Boolean).join(" ");
|
|
137009
137114
|
return {
|
|
137010
137115
|
__typename: "Customer",
|
|
@@ -137042,7 +137147,7 @@ function orderShape(req, o) {
|
|
|
137042
137147
|
let cached2;
|
|
137043
137148
|
const facts = () => cached2 ??= orderFacts(req.ctx, o);
|
|
137044
137149
|
const sm = (pick4) => () => bag(req.ctx, pick4(facts()));
|
|
137045
|
-
const shop =
|
|
137150
|
+
const shop = all6(req.ctx, "Shop")[0];
|
|
137046
137151
|
const fos = () => childrenOf3(req.ctx, o.gid, "FulfillmentOrder");
|
|
137047
137152
|
return {
|
|
137048
137153
|
__typename: "Order",
|
|
@@ -137413,7 +137518,7 @@ function ordersConnection(req, orders, args, path6) {
|
|
|
137413
137518
|
function productsConnection(req, args, path6) {
|
|
137414
137519
|
const variants = (p2) => childrenOf3(req.ctx, p2.gid, "ProductVariant");
|
|
137415
137520
|
const inventory = (p2) => variants(p2).filter((v) => load3(req.ctx, v.item).tracked).reduce((n, v) => n + variantStock(req, v).available, 0);
|
|
137416
|
-
let found = filter3(req, "products",
|
|
137521
|
+
let found = filter3(req, "products", all6(req.ctx, "Product"), args, path6, {
|
|
137417
137522
|
default: { text: (p2) => [p2.title, p2.vendor, p2.product_type, p2.handle, ...p2.tags, ...variants(p2).map((v) => v.sku)] },
|
|
137418
137523
|
id: { number: num2 },
|
|
137419
137524
|
title: { text: (p2) => [p2.title], words: true },
|
|
@@ -137451,7 +137556,7 @@ function productsConnection(req, args, path6) {
|
|
|
137451
137556
|
}
|
|
137452
137557
|
function variantsConnection(req, args, path6) {
|
|
137453
137558
|
const product2 = (v) => load3(req.ctx, v.product);
|
|
137454
|
-
const found = filter3(req, "productVariants",
|
|
137559
|
+
const found = filter3(req, "productVariants", all6(req.ctx, "ProductVariant"), args, path6, {
|
|
137455
137560
|
default: { text: (v) => [product2(v).title, variantTitle(v), v.sku, v.barcode] },
|
|
137456
137561
|
id: { number: num2 },
|
|
137457
137562
|
sku: { text: (v) => [v.sku] },
|
|
@@ -137480,9 +137585,9 @@ function variantsConnection(req, args, path6) {
|
|
|
137480
137585
|
return connection2(items, args, (v) => ({ id: num2(v), value: key3(v) }), (v) => variantShape(req, v));
|
|
137481
137586
|
}
|
|
137482
137587
|
function customersConnection(req, args, path6) {
|
|
137483
|
-
const orders = (c) =>
|
|
137588
|
+
const orders = (c) => all6(req.ctx, "Order").filter((o) => o.customer === c.gid);
|
|
137484
137589
|
const fullName = (c) => [c.first_name, c.last_name].filter(Boolean).join(" ");
|
|
137485
|
-
const found = filter3(req, "customers",
|
|
137590
|
+
const found = filter3(req, "customers", all6(req.ctx, "Customer"), args, path6, {
|
|
137486
137591
|
default: { text: (c) => [fullName(c), c.email, c.phone, c.address?.company ?? null, ...c.tags] },
|
|
137487
137592
|
id: { number: num2 },
|
|
137488
137593
|
email: { text: (c) => [c.email] },
|
|
@@ -137509,7 +137614,7 @@ function customersConnection(req, args, path6) {
|
|
|
137509
137614
|
return connection2(items, args, (c) => ({ id: num2(c), value: key3(c) }), (c) => customerShape(req, c));
|
|
137510
137615
|
}
|
|
137511
137616
|
function locationsConnection(req, args, path6) {
|
|
137512
|
-
const found = filter3(req, "locations",
|
|
137617
|
+
const found = filter3(req, "locations", all6(req.ctx, "Location").filter((l) => args.includeInactive || l.active), args, path6, {
|
|
137513
137618
|
default: { text: (l) => [l.name, l.address.city, l.address.address1, l.address.zip] },
|
|
137514
137619
|
id: { number: num2 },
|
|
137515
137620
|
location_id: { number: num2 },
|
|
@@ -137559,7 +137664,7 @@ function queryRoot(req) {
|
|
|
137559
137664
|
};
|
|
137560
137665
|
return {
|
|
137561
137666
|
shop: () => shopShape(req),
|
|
137562
|
-
orders: (args, _r, info) => ordersConnection(req,
|
|
137667
|
+
orders: (args, _r, info) => ordersConnection(req, all6(ctx, "Order"), args, pathOf3(info.path)),
|
|
137563
137668
|
order: one7("Order", orderShape),
|
|
137564
137669
|
products: (args, _r, info) => productsConnection(req, args, pathOf3(info.path)),
|
|
137565
137670
|
product: one7("Product", productShape),
|
|
@@ -137570,7 +137675,7 @@ function queryRoot(req) {
|
|
|
137570
137675
|
locations: (args, _r, info) => locationsConnection(req, args, pathOf3(info.path)),
|
|
137571
137676
|
// Without an id, Shopify returns the primary location.
|
|
137572
137677
|
location: ({ id: id12 }) => {
|
|
137573
|
-
const d = id12 === void 0 || id12 === null ?
|
|
137678
|
+
const d = id12 === void 0 || id12 === null ? all6(ctx, "Location")[0] : loadKind(ctx, "Location", checkId(id12));
|
|
137574
137679
|
return d ? locationShape(req, d) : null;
|
|
137575
137680
|
},
|
|
137576
137681
|
inventoryItem: one7("InventoryItem", itemShape),
|
|
@@ -137761,7 +137866,7 @@ function mutationRoot(req) {
|
|
|
137761
137866
|
}
|
|
137762
137867
|
if (data5.handle !== void 0 && data5.handle !== null) {
|
|
137763
137868
|
const handle30 = slug8(data5.handle);
|
|
137764
|
-
if (
|
|
137869
|
+
if (all6(ctx, "Product").some((x) => x.gid !== p2.gid && x.handle === handle30)) errors2.push({ field: ["handle"], message: `Handle '${handle30}' already in use. Please provide a new handle.` });
|
|
137765
137870
|
else next2.handle = handle30;
|
|
137766
137871
|
}
|
|
137767
137872
|
if (errors2.length) return { product: null, userErrors: errors2 };
|
|
@@ -137818,7 +137923,7 @@ function refundCreate(req, input2) {
|
|
|
137818
137923
|
const found = orderOrError(req, input2.orderId, ["orderId"]);
|
|
137819
137924
|
if ("errors" in found) return fail6(found.errors);
|
|
137820
137925
|
const o = found.order, facts = orderFacts(ctx, o);
|
|
137821
|
-
if (input2.currency && input2.currency !==
|
|
137926
|
+
if (input2.currency && input2.currency !== all6(ctx, "Shop")[0].currency) gap4("refunds in a presentment currency");
|
|
137822
137927
|
const errors2 = [];
|
|
137823
137928
|
const items = [];
|
|
137824
137929
|
(input2.refundLineItems ?? []).forEach((i, n) => {
|
|
@@ -138024,7 +138129,7 @@ function customerWrite(req, input2, create2) {
|
|
|
138024
138129
|
updated_ms: at2
|
|
138025
138130
|
};
|
|
138026
138131
|
const errors2 = [];
|
|
138027
|
-
const others =
|
|
138132
|
+
const others = all6(ctx, "Customer").filter((x) => x.gid !== c.gid);
|
|
138028
138133
|
if (input2.email !== void 0) {
|
|
138029
138134
|
if (input2.email !== null && !EMAIL17.test(input2.email)) errors2.push({ field: ["email"], message: "Email is invalid" });
|
|
138030
138135
|
else if (input2.email !== null && others.some((x) => x.email?.toLowerCase() === input2.email.toLowerCase())) errors2.push({ field: ["email"], message: "Email has already been taken" });
|
|
@@ -138436,13 +138541,13 @@ function credentials26(ctx) {
|
|
|
138436
138541
|
var when8 = (ms) => ms === null ? null : iso8(ms);
|
|
138437
138542
|
var oneLine = (a) => a ? [a.company, a.address1, a.address2, a.city, [a.province_code, a.zip].filter(Boolean).join(" "), a.country_code].filter(Boolean).join(", ") : null;
|
|
138438
138543
|
function dumpState26(ctx) {
|
|
138439
|
-
const shop =
|
|
138544
|
+
const shop = all6(ctx, "Shop")[0], locations = all6(ctx, "Location");
|
|
138440
138545
|
const locationName = (id12) => id12 ? locations.find((l) => l.gid === id12)?.name ?? null : null;
|
|
138441
138546
|
const sku = (lineId) => load3(ctx, lineId)?.sku ?? null;
|
|
138442
138547
|
return {
|
|
138443
138548
|
shop: { name: shop.name, domain: `${shop.domain}.myshopify.com`, email: shop.email, currency: shop.currency },
|
|
138444
138549
|
locations: locations.map((l) => ({ id: l.gid, name: l.name, city: l.address.city, active: l.active, fulfills_online_orders: l.fulfills_online_orders })),
|
|
138445
|
-
products:
|
|
138550
|
+
products: all6(ctx, "Product").map((p2) => ({
|
|
138446
138551
|
id: p2.gid,
|
|
138447
138552
|
title: p2.title,
|
|
138448
138553
|
handle: p2.handle,
|
|
@@ -138469,7 +138574,7 @@ function dumpState26(ctx) {
|
|
|
138469
138574
|
};
|
|
138470
138575
|
})
|
|
138471
138576
|
})),
|
|
138472
|
-
customers:
|
|
138577
|
+
customers: all6(ctx, "Customer").map((c) => ({
|
|
138473
138578
|
id: c.gid,
|
|
138474
138579
|
name: [c.first_name, c.last_name].filter(Boolean).join(" ") || null,
|
|
138475
138580
|
email: c.email,
|
|
@@ -138478,9 +138583,9 @@ function dumpState26(ctx) {
|
|
|
138478
138583
|
note: c.note,
|
|
138479
138584
|
state: c.state,
|
|
138480
138585
|
accepts_marketing: c.accepts_marketing,
|
|
138481
|
-
orders:
|
|
138586
|
+
orders: all6(ctx, "Order").filter((o) => o.customer === c.gid).length
|
|
138482
138587
|
})),
|
|
138483
|
-
orders:
|
|
138588
|
+
orders: all6(ctx, "Order").map((o) => {
|
|
138484
138589
|
const f = orderFacts(ctx, o), customer3 = o.customer ? load3(ctx, o.customer) : void 0;
|
|
138485
138590
|
return {
|
|
138486
138591
|
id: o.gid,
|
|
@@ -138536,7 +138641,7 @@ function dumpState26(ctx) {
|
|
|
138536
138641
|
transactions: f.transactions.map((t) => ({ id: t.gid, kind: t.kind, status: t.status, gateway: t.gateway, amount: decimal2(t.cents), created_at: iso8(t.created_ms), error_code: t.error_code }))
|
|
138537
138642
|
};
|
|
138538
138643
|
}),
|
|
138539
|
-
inventory_adjustments:
|
|
138644
|
+
inventory_adjustments: all6(ctx, "InventoryAdjustmentGroup").map((g) => ({
|
|
138540
138645
|
id: g.gid,
|
|
138541
138646
|
reason: g.reason,
|
|
138542
138647
|
reference: g.reference,
|
|
@@ -140711,14 +140816,14 @@ var billingRoutes = [
|
|
|
140711
140816
|
path: "/v1/catalogs/products",
|
|
140712
140817
|
coverage: { status: "supported" },
|
|
140713
140818
|
run: (r) => {
|
|
140714
|
-
const { size, n, total } = page11(r, 20),
|
|
140715
|
-
return { products:
|
|
140819
|
+
const { size, n, total } = page11(r, 20), all8 = allOf2(r.ctx, "product");
|
|
140820
|
+
return { products: all8.slice((n - 1) * size, n * size).map((p2) => ({
|
|
140716
140821
|
id: p2.id,
|
|
140717
140822
|
name: p2.name,
|
|
140718
140823
|
description: p2.description ?? void 0,
|
|
140719
140824
|
create_time: iso10(p2.create_ms),
|
|
140720
140825
|
links: [link4(`${r.base}/v1/catalogs/products/${p2.id}`, "self")]
|
|
140721
|
-
})), ...total && { total_items:
|
|
140826
|
+
})), ...total && { total_items: all8.length, total_pages: Math.ceil(all8.length / size) }, links: [] };
|
|
140722
140827
|
}
|
|
140723
140828
|
},
|
|
140724
140829
|
{
|
|
@@ -140745,10 +140850,10 @@ var billingRoutes = [
|
|
|
140745
140850
|
coverage: { status: "supported" },
|
|
140746
140851
|
run: (r) => {
|
|
140747
140852
|
const { size, n, total } = page11(r, 20), ids2 = r.query.get("plan_ids")?.split(",").filter(Boolean), product2 = r.query.get("product_id");
|
|
140748
|
-
const
|
|
140853
|
+
const all8 = allOf2(r.ctx, "plan").filter((p2) => (!product2 || p2.product_id === product2) && (!ids2 || ids2.includes(p2.id)));
|
|
140749
140854
|
return {
|
|
140750
|
-
plans:
|
|
140751
|
-
...total && { total_items:
|
|
140855
|
+
plans: all8.slice((n - 1) * size, n * size).map((p2) => planShape(r, p2, false)),
|
|
140856
|
+
...total && { total_items: all8.length, total_pages: Math.ceil(all8.length / size) },
|
|
140752
140857
|
links: [link4(`${r.base}/v1/billing/plans?page_size=${size}&page=${n}`, "self")]
|
|
140753
140858
|
};
|
|
140754
140859
|
}
|
|
@@ -140818,8 +140923,8 @@ var billingRoutes = [
|
|
|
140818
140923
|
run: (r) => {
|
|
140819
140924
|
const { size, n } = page11(r, 20), plans = r.query.get("plan_ids")?.split(",").filter(Boolean), statuses = r.query.get("statuses")?.split(",").filter(Boolean);
|
|
140820
140925
|
for (const key3 of ["created_after", "created_before", "status_updated_after", "status_updated_before", "filter", "customer_ids"]) if (r.query.get(key3)) unsupported23(`the ${key3} filter on subscriptions`);
|
|
140821
|
-
const
|
|
140822
|
-
return { subscriptions:
|
|
140926
|
+
const all8 = allOf2(r.ctx, "subscription").filter((s) => (!plans || plans.includes(s.plan_id)) && (!statuses || statuses.includes(s.status)));
|
|
140927
|
+
return { subscriptions: all8.slice((n - 1) * size, n * size).map((s) => subscriptionShape(r, s)), total_items: all8.length, total_pages: Math.ceil(all8.length / size), links: [] };
|
|
140823
140928
|
}
|
|
140824
140929
|
},
|
|
140825
140930
|
{ method: "GET", path: "/v1/billing/subscriptions/:id", coverage: { status: "supported" }, run: (r) => subscriptionShape(r, subscriptionOr404(r)) },
|
|
@@ -144573,7 +144678,7 @@ function load5(ctx, kind, id12) {
|
|
|
144573
144678
|
const row = ctx.store.db.prepare("SELECT json FROM intercom_objects WHERE kind = ? AND id = ?").get(kind, id12);
|
|
144574
144679
|
return row && JSON.parse(row.json);
|
|
144575
144680
|
}
|
|
144576
|
-
function
|
|
144681
|
+
function all7(ctx, kind) {
|
|
144577
144682
|
return ctx.store.db.prepare("SELECT json FROM intercom_objects WHERE kind = ? ORDER BY seq").all(kind).map((r) => JSON.parse(r.json));
|
|
144578
144683
|
}
|
|
144579
144684
|
function save10(ctx, kind, doc) {
|
|
@@ -144697,7 +144802,7 @@ function byPage(items, r, dflt, key3, body6) {
|
|
|
144697
144802
|
}
|
|
144698
144803
|
var numeric2 = (id12) => id12 === null ? null : Number(id12);
|
|
144699
144804
|
function adminShape(r, a) {
|
|
144700
|
-
const teams =
|
|
144805
|
+
const teams = all7(r.ctx, "team").filter((t) => t.admin_ids.includes(a.id)).map((t) => Number(t.id));
|
|
144701
144806
|
return {
|
|
144702
144807
|
type: "admin",
|
|
144703
144808
|
id: a.id,
|
|
@@ -144727,7 +144832,7 @@ var tagRef = (r, t) => {
|
|
|
144727
144832
|
};
|
|
144728
144833
|
function contactShape2(r, c) {
|
|
144729
144834
|
const list14 = (type, ids2, path6) => ({ type: "list", data: ids2.map((id12) => ({ type, id: id12, url: `/${type === "company" ? "companies" : `${type}s`}/${id12}` })), url: `/contacts/${c.id}/${path6}`, total_count: ids2.length, has_more: false });
|
|
144730
|
-
const notes6 =
|
|
144835
|
+
const notes6 = all7(r.ctx, "note").filter((n) => n.contact_id === c.id).map((n) => n.id);
|
|
144731
144836
|
return {
|
|
144732
144837
|
type: "contact",
|
|
144733
144838
|
id: c.id,
|
|
@@ -144786,7 +144891,7 @@ function contactShape2(r, c) {
|
|
|
144786
144891
|
};
|
|
144787
144892
|
}
|
|
144788
144893
|
function companyShape(r, co) {
|
|
144789
|
-
const users4 =
|
|
144894
|
+
const users4 = all7(r.ctx, "contact").filter((c) => c.companies.includes(co.id)).length;
|
|
144790
144895
|
return {
|
|
144791
144896
|
type: "company",
|
|
144792
144897
|
id: co.id,
|
|
@@ -145054,9 +145159,9 @@ function applyContact(r, c, b) {
|
|
|
145054
145159
|
}
|
|
145055
145160
|
}
|
|
145056
145161
|
function conflictOnEmail(r, c) {
|
|
145057
|
-
const dup = c.email &&
|
|
145162
|
+
const dup = c.email && all7(r.ctx, "contact").find((x) => x.id !== c.id && x.role === "user" && c.role === "user" && x.email?.toLowerCase() === c.email.toLowerCase());
|
|
145058
145163
|
if (dup) fail3(409, "conflict", `A contact matching those details already exists with id=${dup.id}`);
|
|
145059
|
-
const ext = c.external_id &&
|
|
145164
|
+
const ext = c.external_id && all7(r.ctx, "contact").find((x) => x.id !== c.id && x.external_id === c.external_id);
|
|
145060
145165
|
if (ext) fail3(409, "conflict", `A contact matching those details already exists with id=${ext.id}`);
|
|
145061
145166
|
}
|
|
145062
145167
|
function tagOn(r, doc, tagId, adminId) {
|
|
@@ -145078,7 +145183,7 @@ var intercomRoutes = [
|
|
|
145078
145183
|
return { ...adminShape(r, r.me), app: { type: "app", id_code: w.id, name: w.name, created_at: w.created_at, secure: false, identity_verification: false, timezone: "America/Los_Angeles", region: "US" } };
|
|
145079
145184
|
}
|
|
145080
145185
|
},
|
|
145081
|
-
{ method: "GET", path: "/admins", coverage: { status: "supported" }, run: (r) => ({ type: "admin.list", admins:
|
|
145186
|
+
{ method: "GET", path: "/admins", coverage: { status: "supported" }, run: (r) => ({ type: "admin.list", admins: all7(r.ctx, "admin").map((a) => adminShape(r, a)) }) },
|
|
145082
145187
|
{ method: "GET", path: "/admins/:id", coverage: { status: "supported" }, run: (r) => adminShape(r, load5(r.ctx, "admin", r.param("id")) ?? notFound15("Admin")) },
|
|
145083
145188
|
{
|
|
145084
145189
|
method: "PUT",
|
|
@@ -145090,7 +145195,7 @@ var intercomRoutes = [
|
|
|
145090
145195
|
return adminShape(r, save10(r.ctx, "admin", { ...a, away: r.body.away_mode_enabled, reassign: !!r.body.away_mode_reassign }));
|
|
145091
145196
|
}
|
|
145092
145197
|
},
|
|
145093
|
-
{ method: "GET", path: "/teams", coverage: { status: "supported" }, run: (r) => ({ type: "team.list", teams:
|
|
145198
|
+
{ method: "GET", path: "/teams", coverage: { status: "supported" }, run: (r) => ({ type: "team.list", teams: all7(r.ctx, "team").map((t) => ({ type: "team", id: t.id, name: t.name, admin_ids: t.admin_ids.map(Number), admin_priority_level: {} })) }) },
|
|
145094
145199
|
{
|
|
145095
145200
|
method: "GET",
|
|
145096
145201
|
path: "/teams/:id",
|
|
@@ -145101,7 +145206,7 @@ var intercomRoutes = [
|
|
|
145101
145206
|
}
|
|
145102
145207
|
},
|
|
145103
145208
|
{ method: "GET", path: "/contacts", coverage: { status: "supported" }, run: (r) => {
|
|
145104
|
-
const l = listOf("list", "data",
|
|
145209
|
+
const l = listOf("list", "data", all7(r.ctx, "contact").filter((c) => !c.archived), r);
|
|
145105
145210
|
return { ...l, data: l.data.map((c) => contactShape2(r, c)) };
|
|
145106
145211
|
} },
|
|
145107
145212
|
{
|
|
@@ -145110,7 +145215,7 @@ var intercomRoutes = [
|
|
|
145110
145215
|
coverage: { status: "partial", notes: "common contact fields, tags, companies and custom attributes; segments and device fields are gaps" },
|
|
145111
145216
|
run: (r) => {
|
|
145112
145217
|
const ok = matcher(contactFields(r), CONTACT_DOCUMENTED, r.body.query, "contacts");
|
|
145113
|
-
const l = listOf("list", "data",
|
|
145218
|
+
const l = listOf("list", "data", all7(r.ctx, "contact").filter((c) => !c.archived && ok(c)), r, 50, r.body);
|
|
145114
145219
|
return { ...l, data: l.data.map((c) => contactShape2(r, c)) };
|
|
145115
145220
|
}
|
|
145116
145221
|
},
|
|
@@ -145151,7 +145256,7 @@ var intercomRoutes = [
|
|
|
145151
145256
|
method: "GET",
|
|
145152
145257
|
path: "/contacts/find_by_external_id/:id",
|
|
145153
145258
|
coverage: { status: "supported" },
|
|
145154
|
-
run: (r) => contactShape2(r,
|
|
145259
|
+
run: (r) => contactShape2(r, all7(r.ctx, "contact").find((c) => c.external_id === r.param("id")) ?? notFound15("User"))
|
|
145155
145260
|
},
|
|
145156
145261
|
{ method: "GET", path: "/contacts/:id", coverage: { status: "supported" }, run: (r) => contactShape2(r, contactOr404(r)) },
|
|
145157
145262
|
{
|
|
@@ -145228,7 +145333,7 @@ var intercomRoutes = [
|
|
|
145228
145333
|
coverage: { status: "supported" },
|
|
145229
145334
|
run: (r) => {
|
|
145230
145335
|
const c = contactOr404(r);
|
|
145231
|
-
const l = byPage(
|
|
145336
|
+
const l = byPage(all7(r.ctx, "note").filter((n) => n.contact_id === c.id).reverse(), r, 50, "data");
|
|
145232
145337
|
return { ...l, data: l.data.map((n) => noteShape3(r, n)) };
|
|
145233
145338
|
}
|
|
145234
145339
|
},
|
|
@@ -145281,13 +145386,13 @@ var intercomRoutes = [
|
|
|
145281
145386
|
run: (r) => {
|
|
145282
145387
|
const id12 = r.query.get("company_id"), name5 = r.query.get("name");
|
|
145283
145388
|
for (const key3 of ["segment_id", "tag_id"]) if (r.query.get(key3)) unsupported26(`listing companies by ${key3}`);
|
|
145284
|
-
if (id12 || name5) return companyShape(r,
|
|
145285
|
-
const l = byPage(
|
|
145389
|
+
if (id12 || name5) return companyShape(r, all7(r.ctx, "company").find((co) => id12 && co.company_id === id12 || name5 && co.name.toLowerCase() === name5.toLowerCase()) ?? notFound15("Company"));
|
|
145390
|
+
const l = byPage(all7(r.ctx, "company"), r, 15, "data");
|
|
145286
145391
|
return { ...l, data: l.data.map((co) => companyShape(r, co)) };
|
|
145287
145392
|
}
|
|
145288
145393
|
},
|
|
145289
145394
|
{ method: "POST", path: "/companies/list", coverage: { status: "supported" }, run: (r) => {
|
|
145290
|
-
const l = byPage(
|
|
145395
|
+
const l = byPage(all7(r.ctx, "company"), r, 15, "data", { page: r.body.page ?? r.query.get("page") ?? 1, per_page: r.body.per_page ?? r.query.get("per_page") ?? 15 });
|
|
145291
145396
|
return { ...l, data: l.data.map((co) => companyShape(r, co)) };
|
|
145292
145397
|
} },
|
|
145293
145398
|
{
|
|
@@ -145297,7 +145402,7 @@ var intercomRoutes = [
|
|
|
145297
145402
|
run: (r) => {
|
|
145298
145403
|
const b = r.body;
|
|
145299
145404
|
if (!b.company_id && !b.name) fail3(400, "parameter_invalid", "company_id or name is required");
|
|
145300
|
-
const at2 = now8(r), existing2 =
|
|
145405
|
+
const at2 = now8(r), existing2 = all7(r.ctx, "company").find((co2) => co2.company_id === (b.company_id ?? b.name));
|
|
145301
145406
|
const co = existing2 ?? { id: r.ctx.ids.hex(24), company_id: b.company_id ?? b.name, name: b.name ?? b.company_id, plan: null, plan_id: null, size: null, website: null, industry: null, monthly_spend: 0, custom_attributes: {}, created_at: b.remote_created_at ?? at2, updated_at: at2 };
|
|
145302
145407
|
for (const key3 of ["name", "size", "website", "industry", "monthly_spend"]) if (b[key3] !== void 0) co[key3] = b[key3];
|
|
145303
145408
|
if (b.plan !== void 0) {
|
|
@@ -145329,7 +145434,7 @@ var intercomRoutes = [
|
|
|
145329
145434
|
coverage: { status: "supported" },
|
|
145330
145435
|
run: (r) => {
|
|
145331
145436
|
const co = load5(r.ctx, "company", r.param("id")) ?? notFound15("Company");
|
|
145332
|
-
const l = listOf("list", "data",
|
|
145437
|
+
const l = listOf("list", "data", all7(r.ctx, "contact").filter((c) => c.companies.includes(co.id)), r);
|
|
145333
145438
|
return { ...l, data: l.data.map((c) => contactShape2(r, c)) };
|
|
145334
145439
|
}
|
|
145335
145440
|
},
|
|
@@ -145338,7 +145443,7 @@ var intercomRoutes = [
|
|
|
145338
145443
|
path: "/conversations",
|
|
145339
145444
|
coverage: { status: "supported", notes: "newest activity first" },
|
|
145340
145445
|
run: (r) => {
|
|
145341
|
-
const l = listOf("conversation.list", "conversations",
|
|
145446
|
+
const l = listOf("conversation.list", "conversations", all7(r.ctx, "conversation").sort((a, b) => b.updated_at - a.updated_at), r, 20);
|
|
145342
145447
|
return { ...l, conversations: l.conversations.map((c) => conversationShape(r, c, false)) };
|
|
145343
145448
|
}
|
|
145344
145449
|
},
|
|
@@ -145348,7 +145453,7 @@ var intercomRoutes = [
|
|
|
145348
145453
|
coverage: { status: "partial", notes: "state, assignment, tags, contacts, source and timestamps; ratings, AI agent and statistics fields are gaps" },
|
|
145349
145454
|
run: (r) => {
|
|
145350
145455
|
const ok = matcher(conversationFields(), CONVERSATION_DOCUMENTED, r.body.query, "conversations");
|
|
145351
|
-
const l = listOf("conversation.list", "conversations",
|
|
145456
|
+
const l = listOf("conversation.list", "conversations", all7(r.ctx, "conversation").filter(ok).sort((a, b) => b.updated_at - a.updated_at), r, 20, r.body);
|
|
145352
145457
|
return { ...l, conversations: l.conversations.map((c) => conversationShape(r, c, false)) };
|
|
145353
145458
|
}
|
|
145354
145459
|
},
|
|
@@ -145419,7 +145524,7 @@ var intercomRoutes = [
|
|
|
145419
145524
|
}
|
|
145420
145525
|
} else if (b.type === "user") {
|
|
145421
145526
|
if (b.message_type !== "comment") fail3(400, "parameter_invalid", "a contact can only reply with a comment");
|
|
145422
|
-
const contact = load5(r.ctx, "contact", String(b.intercom_user_id ?? "")) ??
|
|
145527
|
+
const contact = load5(r.ctx, "contact", String(b.intercom_user_id ?? "")) ?? all7(r.ctx, "contact").find((c) => b.user_id && c.external_id === b.user_id || b.email && c.email?.toLowerCase() === String(b.email).toLowerCase());
|
|
145423
145528
|
if (!contact || contact.id !== conv.contact_id) fail3(404, "not_found", "User Not Found");
|
|
145424
145529
|
addPart(r, conv, { type: "comment", body: html(b.body), author: { type: "user", id: contact.id } });
|
|
145425
145530
|
if (conv.state !== "open") {
|
|
@@ -145500,7 +145605,7 @@ var intercomRoutes = [
|
|
|
145500
145605
|
return { type: "tag", id: tag3.id, name: tag3.name };
|
|
145501
145606
|
}
|
|
145502
145607
|
},
|
|
145503
|
-
{ method: "GET", path: "/tags", coverage: { status: "supported" }, run: (r) => ({ type: "list", data:
|
|
145608
|
+
{ method: "GET", path: "/tags", coverage: { status: "supported" }, run: (r) => ({ type: "list", data: all7(r.ctx, "tag").map((t) => ({ type: "tag", id: t.id, name: t.name })) }) },
|
|
145504
145609
|
{
|
|
145505
145610
|
method: "POST",
|
|
145506
145611
|
path: "/tags",
|
|
@@ -145514,7 +145619,7 @@ var intercomRoutes = [
|
|
|
145514
145619
|
save10(r.ctx, "tag", { ...t2, name: b.name });
|
|
145515
145620
|
return { type: "tag", id: t2.id, name: b.name };
|
|
145516
145621
|
}
|
|
145517
|
-
const existing2 =
|
|
145622
|
+
const existing2 = all7(r.ctx, "tag").find((t2) => t2.name.toLowerCase() === b.name.toLowerCase());
|
|
145518
145623
|
const t = existing2 ?? save10(r.ctx, "tag", { id: nextId5(r.ctx, "tag"), name: b.name });
|
|
145519
145624
|
return { type: "tag", id: t.id, name: t.name };
|
|
145520
145625
|
}
|
|
@@ -145529,14 +145634,14 @@ var intercomRoutes = [
|
|
|
145529
145634
|
coverage: { status: "supported" },
|
|
145530
145635
|
run: (r) => {
|
|
145531
145636
|
const t = load5(r.ctx, "tag", r.param("id")) ?? notFound15("Tag");
|
|
145532
|
-
const used = [...
|
|
145637
|
+
const used = [...all7(r.ctx, "contact"), ...all7(r.ctx, "conversation")].some((x) => x.tags.some((y) => y.id === t.id));
|
|
145533
145638
|
if (used) fail3(400, "tag_has_dependent_objects", "Unable to delete Tag with dependent objects.");
|
|
145534
145639
|
remove3(r.ctx, "tag", t.id);
|
|
145535
145640
|
return void 0;
|
|
145536
145641
|
}
|
|
145537
145642
|
},
|
|
145538
145643
|
{ method: "GET", path: "/articles", coverage: { status: "supported" }, run: (r) => {
|
|
145539
|
-
const l = byPage(
|
|
145644
|
+
const l = byPage(all7(r.ctx, "article"), r, 50, "data");
|
|
145540
145645
|
return { ...l, data: l.data.map((a) => articleShape(r, a)) };
|
|
145541
145646
|
} },
|
|
145542
145647
|
{
|
|
@@ -145546,7 +145651,7 @@ var intercomRoutes = [
|
|
|
145546
145651
|
run: (r) => {
|
|
145547
145652
|
const words4 = (r.query.get("phrase") ?? "").toLowerCase().split(/\W+/).filter(Boolean), state3 = r.query.get("state");
|
|
145548
145653
|
if (r.query.get("help_center_id")) unsupported26("searching one help center of several");
|
|
145549
|
-
const found =
|
|
145654
|
+
const found = all7(r.ctx, "article").filter((a) => (!state3 || state3 === "all" || a.state === state3) && words4.every((w) => `${a.title} ${a.description} ${plain2(a.body)}`.toLowerCase().includes(w)));
|
|
145550
145655
|
return { type: "list", total_count: found.length, data: { articles: found.map((a) => articleShape(r, a)), highlights: [] }, pages: { type: "pages", page: 1, per_page: Math.max(found.length, 1), total_pages: 1 } };
|
|
145551
145656
|
}
|
|
145552
145657
|
},
|
|
@@ -145722,11 +145827,11 @@ function dumpState31(ctx) {
|
|
|
145722
145827
|
const contact = (id12) => load5(ctx, "contact", id12);
|
|
145723
145828
|
return {
|
|
145724
145829
|
workspace: workspace(ctx).name,
|
|
145725
|
-
admins:
|
|
145726
|
-
teams:
|
|
145727
|
-
tags:
|
|
145728
|
-
companies:
|
|
145729
|
-
contacts:
|
|
145830
|
+
admins: all7(ctx, "admin").map((a) => ({ id: a.id, name: a.name, email: a.email, away: a.away })),
|
|
145831
|
+
teams: all7(ctx, "team").map((t) => ({ id: t.id, name: t.name, members: t.admin_ids.map(admin) })),
|
|
145832
|
+
tags: all7(ctx, "tag").map((t) => t.name),
|
|
145833
|
+
companies: all7(ctx, "company").map((co) => ({ id: co.id, name: co.name, company_id: co.company_id, plan: co.plan })),
|
|
145834
|
+
contacts: all7(ctx, "contact").map((c) => ({
|
|
145730
145835
|
id: c.id,
|
|
145731
145836
|
name: c.name,
|
|
145732
145837
|
email: c.email,
|
|
@@ -145738,9 +145843,9 @@ function dumpState31(ctx) {
|
|
|
145738
145843
|
companies: c.companies.map((id12) => load5(ctx, "company", id12)?.name ?? null),
|
|
145739
145844
|
tags: c.tags.map(tag3),
|
|
145740
145845
|
custom_attributes: c.custom_attributes,
|
|
145741
|
-
notes:
|
|
145846
|
+
notes: all7(ctx, "note").filter((n) => n.contact_id === c.id).map((n) => ({ author: admin(n.author), body: plain2(n.body), created_at: iso13(n.created_at) }))
|
|
145742
145847
|
})),
|
|
145743
|
-
conversations:
|
|
145848
|
+
conversations: all7(ctx, "conversation").map((v) => ({
|
|
145744
145849
|
id: v.id,
|
|
145745
145850
|
contact: contact(v.contact_id)?.name ?? null,
|
|
145746
145851
|
contact_email: contact(v.contact_id)?.email ?? null,
|
|
@@ -145764,7 +145869,7 @@ function dumpState31(ctx) {
|
|
|
145764
145869
|
...p2.assigned_to && { assigned_to: p2.assigned_to.type === "admin" ? admin(p2.assigned_to.id) : load5(ctx, "team", p2.assigned_to.id)?.name ?? null }
|
|
145765
145870
|
}))
|
|
145766
145871
|
})),
|
|
145767
|
-
articles:
|
|
145872
|
+
articles: all7(ctx, "article").map((a) => ({ id: a.id, title: a.title, state: a.state }))
|
|
145768
145873
|
};
|
|
145769
145874
|
}
|
|
145770
145875
|
|
|
@@ -146264,9 +146369,9 @@ function macroJson(ctx, macro2) {
|
|
|
146264
146369
|
};
|
|
146265
146370
|
}
|
|
146266
146371
|
function viewJson(ctx, view3) {
|
|
146267
|
-
const
|
|
146372
|
+
const all8 = [{ field: "status", operator: "less_than", value: "solved" }], statuses = JSON.parse(view3.statuses);
|
|
146268
146373
|
const conditions = [
|
|
146269
|
-
...statuses.join() === "new,open,pending,hold" ?
|
|
146374
|
+
...statuses.join() === "new,open,pending,hold" ? all8 : statuses.map((status4) => ({ field: "status", operator: "is", value: status4 })),
|
|
146270
146375
|
...view3.assignee === "none" ? [{ field: "assignee_id", operator: "is", value: null }] : view3.assignee === "me" ? [{ field: "assignee_id", operator: "is", value: "current_user" }] : [],
|
|
146271
146376
|
...view3.group_id === null ? [] : [{ field: "group_id", operator: "is", value: String(view3.group_id) }]
|
|
146272
146377
|
];
|
|
@@ -149502,9 +149607,9 @@ function permissionsIn(ctx, userId, channel3) {
|
|
|
149502
149607
|
if (ctx.store.meta.get("discord.owner") === userId) return ALL;
|
|
149503
149608
|
const member4 = getMember(ctx, userId);
|
|
149504
149609
|
if (!member4) return 0n;
|
|
149505
|
-
const
|
|
149610
|
+
const all8 = roles(ctx), mine = new Set(JSON.parse(member4.roles)), everyone = guildId(ctx);
|
|
149506
149611
|
let permissions = 0n;
|
|
149507
|
-
for (const role3 of
|
|
149612
|
+
for (const role3 of all8) if (role3.id === everyone || mine.has(role3.id)) permissions |= BigInt(role3.permissions);
|
|
149508
149613
|
if (permissions & BITS.ADMINISTRATOR) return ALL;
|
|
149509
149614
|
const target4 = channel3?.type === PUBLIC_THREAD ? getChannel(ctx, channel3.parent_id) : channel3;
|
|
149510
149615
|
if (!target4 || target4.type === DM) return permissions;
|
|
@@ -149835,8 +149940,8 @@ function members3(call2) {
|
|
|
149835
149940
|
guildFor(call2);
|
|
149836
149941
|
const params9 = call2.url.searchParams, limit2 = Number(params9.get("limit") ?? 1), after = params9.get("after") ?? "0";
|
|
149837
149942
|
if (!Number.isInteger(limit2) || limit2 < 1 || limit2 > 1e3) throw invalidForm("limit", "NUMBER_TYPE_MAX", "int value should be between 1 and 1000");
|
|
149838
|
-
const
|
|
149839
|
-
return json27(
|
|
149943
|
+
const all8 = call2.ctx.store.db.prepare("SELECT * FROM dc_members").all().sort((a, b) => BigInt(a.user_id) < BigInt(b.user_id) ? -1 : 1);
|
|
149944
|
+
return json27(all8.filter((member4) => BigInt(member4.user_id) > BigInt(after)).slice(0, limit2).map((member4) => memberJson(call2.ctx, member4)));
|
|
149840
149945
|
}
|
|
149841
149946
|
function member2(call2) {
|
|
149842
149947
|
guildFor(call2);
|
|
@@ -149860,15 +149965,15 @@ function listMessages2(call2) {
|
|
|
149860
149965
|
const anchors = ["before", "after", "around"].filter((name5) => params9.has(name5));
|
|
149861
149966
|
if (anchors.length > 1) throw invalidForm(anchors[1], "BASE_TYPE_BAD_ARGUMENT", "Only one of before, after or around may be given");
|
|
149862
149967
|
if (!canRead(call2, channel3)) return json27([]);
|
|
149863
|
-
const
|
|
149968
|
+
const all8 = call2.ctx.store.db.prepare("SELECT * FROM dc_messages WHERE channel_id = ? AND deleted_ms IS NULL").all(channel3.id).sort((a, b) => BigInt(b.id) > BigInt(a.id) ? 1 : -1);
|
|
149864
149969
|
const at2 = (name5) => BigInt(params9.get(name5));
|
|
149865
149970
|
let page15;
|
|
149866
|
-
if (params9.has("before")) page15 =
|
|
149867
|
-
else if (params9.has("after")) page15 =
|
|
149971
|
+
if (params9.has("before")) page15 = all8.filter((row) => BigInt(row.id) < at2("before")).slice(0, limit2);
|
|
149972
|
+
else if (params9.has("after")) page15 = all8.filter((row) => BigInt(row.id) > at2("after")).slice(-limit2);
|
|
149868
149973
|
else if (params9.has("around")) {
|
|
149869
|
-
const older =
|
|
149974
|
+
const older = all8.filter((row) => BigInt(row.id) <= at2("around")).slice(0, Math.ceil(limit2 / 2)), newer = all8.filter((row) => BigInt(row.id) > at2("around")).slice(-Math.floor(limit2 / 2));
|
|
149870
149975
|
page15 = [...newer, ...older];
|
|
149871
|
-
} else page15 =
|
|
149976
|
+
} else page15 = all8.slice(0, limit2);
|
|
149872
149977
|
return json27(page15.map((row) => messageJson2(call2.ctx, row)));
|
|
149873
149978
|
}
|
|
149874
149979
|
function showMessage(call2) {
|
|
@@ -152264,8 +152369,8 @@ var AirtableBase = class _AirtableBase {
|
|
|
152264
152369
|
}
|
|
152265
152370
|
/** A table by id or name, as the URL gives it. */
|
|
152266
152371
|
table(ref20) {
|
|
152267
|
-
const
|
|
152268
|
-
const found =
|
|
152372
|
+
const all8 = this.tables();
|
|
152373
|
+
const found = all8.find((item2) => item2.id === ref20) ?? all8.find((item2) => item2.name === ref20) ?? all8.find((item2) => item2.name.toLowerCase() === ref20.toLowerCase());
|
|
152269
152374
|
if (!found) throw modelNotFound();
|
|
152270
152375
|
return found;
|
|
152271
152376
|
}
|
|
@@ -152279,8 +152384,8 @@ var AirtableBase = class _AirtableBase {
|
|
|
152279
152384
|
}
|
|
152280
152385
|
/** A field by id or exact name; `loose` also matches names regardless of case (as formulas do). */
|
|
152281
152386
|
field(tableId, ref20, loose = false) {
|
|
152282
|
-
const
|
|
152283
|
-
return
|
|
152387
|
+
const all8 = this.fields(tableId);
|
|
152388
|
+
return all8.find((item2) => item2.id === ref20) ?? all8.find((item2) => item2.name === ref20) ?? (loose ? all8.find((item2) => item2.name.toLowerCase() === ref20.toLowerCase()) : void 0);
|
|
152284
152389
|
}
|
|
152285
152390
|
fieldById(id12) {
|
|
152286
152391
|
for (const table3 of this.tables()) {
|
|
@@ -152665,13 +152770,13 @@ var AirtableBase = class _AirtableBase {
|
|
|
152665
152770
|
}
|
|
152666
152771
|
}
|
|
152667
152772
|
#person(value4, typecast, bad3) {
|
|
152668
|
-
const
|
|
152773
|
+
const all8 = this.users(), lower4 = (text21) => String(text21).trim().toLowerCase();
|
|
152669
152774
|
let found;
|
|
152670
152775
|
if (value4 && typeof value4 === "object" && !Array.isArray(value4)) {
|
|
152671
152776
|
const ref20 = value4;
|
|
152672
|
-
found = ref20.id !== void 0 ?
|
|
152777
|
+
found = ref20.id !== void 0 ? all8.find((item2) => item2.id === ref20.id) : ref20.email !== void 0 ? all8.find((item2) => item2.email.toLowerCase() === lower4(ref20.email)) : void 0;
|
|
152673
152778
|
} else if (typeof value4 === "string") {
|
|
152674
|
-
found =
|
|
152779
|
+
found = all8.find((item2) => item2.id === value4) ?? all8.find((item2) => item2.email.toLowerCase() === lower4(value4)) ?? (typecast ? all8.find((item2) => item2.name.toLowerCase() === lower4(value4)) : void 0);
|
|
152675
152780
|
}
|
|
152676
152781
|
if (!found) throw bad3();
|
|
152677
152782
|
return found.id;
|
|
@@ -153012,11 +153117,11 @@ function commentsOf3(call2, writing) {
|
|
|
153012
153117
|
var liveComments = (ctx, recordId) => ctx.store.db.prepare("SELECT * FROM at_comments WHERE record_id = ? AND deleted_ms IS NULL ORDER BY created_ms DESC, id DESC").all(recordId);
|
|
153013
153118
|
function listComments3(call2) {
|
|
153014
153119
|
const { model, record: record10 } = commentsOf3(call2, false), pageSize2 = whole(call2.url.searchParams.get("pageSize") ?? void 0, "pageSize", 1, 100) ?? 100;
|
|
153015
|
-
const
|
|
153016
|
-
const from = offset16 === null ? 0 :
|
|
153120
|
+
const all8 = liveComments(call2.ctx, record10.id), offset16 = call2.url.searchParams.get("offset");
|
|
153121
|
+
const from = offset16 === null ? 0 : all8.findIndex((row) => row.id === offset16);
|
|
153017
153122
|
if (from < 0) throw new AirtableError(422, "LIST_RECORDS_ITERATOR_NOT_AVAILABLE");
|
|
153018
|
-
const page15 =
|
|
153019
|
-
return json29({ comments: page15.map((row) => commentJson2(model, row)), offset:
|
|
153123
|
+
const page15 = all8.slice(from, from + pageSize2);
|
|
153124
|
+
return json29({ comments: page15.map((row) => commentJson2(model, row)), offset: all8[from + pageSize2]?.id ?? null });
|
|
153020
153125
|
}
|
|
153021
153126
|
function commentText(body6) {
|
|
153022
153127
|
if (typeof body6.text !== "string" || !body6.text.trim()) throw invalidRequest("Invalid request: text is required");
|
|
@@ -157013,13 +157118,15 @@ function traceExcerpt(trace, evidence) {
|
|
|
157013
157118
|
return trace.filter((e) => wanted.has(e.seq)).map(excerptOf);
|
|
157014
157119
|
}
|
|
157015
157120
|
var trialIssues = (t) => t.harnessIssues ?? collectHarnessIssues(t.trace, t.checks);
|
|
157016
|
-
var trialValid = (t) => !trialIssues(t).some((i) => i.owner === "harness");
|
|
157017
|
-
|
|
157121
|
+
var trialValid = (t) => t.valid !== false && t.exit !== "invalid" && !trialIssues(t).some((i) => i.owner === "harness");
|
|
157122
|
+
var outcomeOf2 = (t) => trialOutcome({ ...t, valid: trialValid(t), outcome: t.checks.some((check3) => check3.required && check3.status === "skipped") ? "skipped" : t.outcome });
|
|
157123
|
+
function summarizeScene(sceneId, trials, requestedTrials = trials.length) {
|
|
157124
|
+
const counts = countTrials(requestedTrials, trials.map(outcomeOf2));
|
|
157018
157125
|
const checks = {};
|
|
157019
157126
|
const failures = [];
|
|
157020
157127
|
const agentIssues = [];
|
|
157021
157128
|
const harnessIssues = [];
|
|
157022
|
-
|
|
157129
|
+
const invalidTrials = counts.invalid;
|
|
157023
157130
|
let skippedJudges = 0;
|
|
157024
157131
|
const warnings = [];
|
|
157025
157132
|
const gaps2 = /* @__PURE__ */ new Map();
|
|
@@ -157027,7 +157134,6 @@ function summarizeScene(sceneId, trials) {
|
|
|
157027
157134
|
let totalMs = 0;
|
|
157028
157135
|
for (const t of trials) {
|
|
157029
157136
|
totalMs += t.realMs;
|
|
157030
|
-
if (!trialValid(t)) invalidTrials++;
|
|
157031
157137
|
for (const issue5 of trialIssues(t)) {
|
|
157032
157138
|
if (harnessIssues.length < MAX_FAILURES_PER_SCENE) harnessIssues.push({ ...issue5, sceneId, trial: t.trial });
|
|
157033
157139
|
}
|
|
@@ -157067,13 +157173,14 @@ function summarizeScene(sceneId, trials) {
|
|
|
157067
157173
|
}
|
|
157068
157174
|
}
|
|
157069
157175
|
}
|
|
157070
|
-
const passed =
|
|
157176
|
+
const passed = counts.passed;
|
|
157071
157177
|
return {
|
|
157072
157178
|
sceneId,
|
|
157179
|
+
counts,
|
|
157073
157180
|
trials: trials.length,
|
|
157074
157181
|
passed,
|
|
157075
|
-
passRate:
|
|
157076
|
-
passAllK:
|
|
157182
|
+
passRate: counts.requested === 0 ? 0 : round4(passed / counts.requested),
|
|
157183
|
+
passAllK: allTrialsPassed(counts),
|
|
157077
157184
|
checks,
|
|
157078
157185
|
agentIssues,
|
|
157079
157186
|
harnessIssues,
|
|
@@ -157084,18 +157191,19 @@ function summarizeScene(sceneId, trials) {
|
|
|
157084
157191
|
coverageGaps: [...gaps2.values()],
|
|
157085
157192
|
meanRealMs: trials.length === 0 ? 0 : Math.round(totalMs / trials.length),
|
|
157086
157193
|
agentCalls: agentCalls2,
|
|
157087
|
-
trialsDetail: trials.map((t) => ({ trial: t.trial, passed: t
|
|
157194
|
+
trialsDetail: trials.map((t) => ({ trial: t.trial, passed: outcomeOf2(t) === "passed", valid: trialValid(t), ...outcomeOf2(t) === "skipped" ? { outcome: "skipped" } : t.outcome ? { outcome: t.outcome } : {}, ...t.checks.some((c) => c.status === "skipped") && { skippedJudges: t.checks.filter((c) => c.status === "skipped").length }, exit: t.exit, exitCode: t.exitCode, realMs: t.realMs, ...t.simMs !== void 0 && { simMs: t.simMs }, ...t.playOut !== void 0 && { playOut: t.playOut }, ...t.sessionId !== void 0 && { sessionId: t.sessionId }, dir: t.dir }))
|
|
157088
157195
|
};
|
|
157089
157196
|
}
|
|
157090
157197
|
function summarize(run5, agent, minPassRate) {
|
|
157091
|
-
const scenes = [...run5.results].map(([sceneId, value4]) => ({ ...summarizeScene(sceneId, value4.trials), ...value4.case && { scenarioId: value4.scene.id, case: value4.case } }));
|
|
157198
|
+
const scenes = [...run5.results].map(([sceneId, value4]) => ({ ...summarizeScene(sceneId, value4.trials, value4.requestedTrials), ...value4.case && { scenarioId: value4.scene.id, case: value4.case } }));
|
|
157092
157199
|
return {
|
|
157200
|
+
verdictVersion: VERDICT_VERSION,
|
|
157093
157201
|
runId: run5.runId,
|
|
157094
157202
|
startedAt: run5.startedAt,
|
|
157095
157203
|
finishedAt: run5.finishedAt,
|
|
157096
157204
|
agent,
|
|
157097
157205
|
minPassRate,
|
|
157098
|
-
verdict: scenes.every((s) => s.invalidTrials === 0 && s.
|
|
157206
|
+
verdict: scenes.every((s) => s.invalidTrials === 0 && meetsPassRate(s.counts, minPassRate)) ? "pass" : "fail",
|
|
157099
157207
|
scenes,
|
|
157100
157208
|
...[...run5.results.values()].some((value4) => value4.case) && { caseFingerprints: Object.fromEntries([...run5.results].flatMap(([id12, value4]) => value4.case ? [[id12, value4.case.fingerprint]] : [])) },
|
|
157101
157209
|
sceneFingerprints: Object.fromEntries([...run5.results].map(([id12, { scene: scene2 }]) => [id12, sceneFingerprint(scene2)])),
|
|
@@ -157156,10 +157264,10 @@ function renderSummaryText(s, opts = {}) {
|
|
|
157156
157264
|
if (s.pytest) lines.push(`pytest ${s.pytest.nodeId}: ${s.pytest.outcome}${s.pytest.invalid ? " [invalid]" : !s.pytest.graded ? " (ungraded)" : ""}`);
|
|
157157
157265
|
for (const scene2 of s.scenes) {
|
|
157158
157266
|
const invalid25 = scene2.invalidTrials ?? 0;
|
|
157159
|
-
const ok = invalid25 === 0 && scene2.
|
|
157267
|
+
const ok = invalid25 === 0 && !!scene2.counts && meetsPassRate(scene2.counts, s.minPassRate);
|
|
157160
157268
|
const excluded2 = scene2.trialsDetail.filter((trial) => trial.outcome === "skipped" || trial.outcome === "xfailed").length;
|
|
157161
157269
|
if (s.pytest && !s.pytest.graded) lines.push(`\u2014 ${scene2.sceneId} ungraded${excluded2 ? ` (${excluded2} excluded)` : ""}${invalid25 ? " [invalid]" : ""}`);
|
|
157162
|
-
else lines.push(`${ok ? "\u2713" : "\u2717"} ${scene2.sceneId} ${scene2.passed}/${scene2.
|
|
157270
|
+
else lines.push(`${ok ? "\u2713" : "\u2717"} ${scene2.sceneId} ${scene2.passed}/${scene2.counts?.requested ?? scene2.trials} (${pct(scene2.passRate)}%)${invalid25 > 0 ? " [invalid]" : ""}${excluded2 ? ` (${excluded2} excluded)` : ""}`);
|
|
157163
157271
|
if (invalid25 > 0) lines.push(` \u2717 harness failure: ${invalid25}/${scene2.trials} trials invalid`);
|
|
157164
157272
|
if ((scene2.skippedJudges ?? 0) > 0) lines.push(` judge grading skipped: ${scene2.skippedJudges} check(s)`);
|
|
157165
157273
|
for (const warning of scene2.warnings ?? []) lines.push(` warning: trial ${warning.trial} ${warning.check}: ${warning.message.replaceAll("\n", "\n ")}`);
|
|
@@ -182774,7 +182882,7 @@ async function executeRun(opts) {
|
|
|
182774
182882
|
const frozen = cases.map((item2) => {
|
|
182775
182883
|
const value4 = { id: item2.id, scenarioId: item2.scene.id, seed: seedOf(item2), compiledFingerprint: sceneFingerprint(item2.scene), identity: item2.identity ?? {} };
|
|
182776
182884
|
const record10 = { ...value4, fingerprint: sceneFingerprint(value4) };
|
|
182777
|
-
results.set(item2.id, { scene: item2.scene, trials: [], ...explicitCases && { case: record10 } });
|
|
182885
|
+
results.set(item2.id, { scene: item2.scene, trials: [], requestedTrials: trials, ...explicitCases && { case: record10 } });
|
|
182778
182886
|
return record10;
|
|
182779
182887
|
});
|
|
182780
182888
|
let finished = 0;
|
|
@@ -182930,6 +183038,14 @@ function validateTrialCounts(scene2) {
|
|
|
182930
183038
|
if (!Number.isFinite(scene2.passRate) || scene2.passRate < 0 || scene2.passRate > 1) throw new AnchaError("USAGE", `invalid pass rate for scene ${scene2.sceneId}`);
|
|
182931
183039
|
}
|
|
182932
183040
|
function assertComparableSummaries(current, baseline) {
|
|
183041
|
+
try {
|
|
183042
|
+
for (const scene2 of baseline.scenes) {
|
|
183043
|
+
const counts = verifiedCounts(baseline, scene2);
|
|
183044
|
+
if (counts.invalid || counts.skipped || counts.completed !== counts.requested) throw new Error("The baseline contains invalid harness, skipped or unfinished trials; rerun and save a fresh baseline.");
|
|
183045
|
+
}
|
|
183046
|
+
} catch (error63) {
|
|
183047
|
+
throw new AnchaError("USAGE", error63 instanceof Error ? error63.message : "Incompatible baseline counts", { hint: "Rerun the reference evaluation and save a fresh baseline with this CLI." });
|
|
183048
|
+
}
|
|
182933
183049
|
if (current.runId === baseline.runId) throw new AnchaError("USAGE", "a run cannot be compared with itself");
|
|
182934
183050
|
const ids2 = (s) => s.scenes.map((scene2) => scene2.sceneId).sort();
|
|
182935
183051
|
const currentIds = ids2(current), baselineIds = ids2(baseline);
|
|
@@ -182961,8 +183077,14 @@ function compareSummaries(current, baseline) {
|
|
|
182961
183077
|
const droppedChecks = [];
|
|
182962
183078
|
const scenes = current.scenes.map((scene2) => {
|
|
182963
183079
|
const beforeScene = baseline.scenes.find((s) => s.sceneId === scene2.sceneId);
|
|
183080
|
+
try {
|
|
183081
|
+
verifiedCounts(current, scene2);
|
|
183082
|
+
} catch (error63) {
|
|
183083
|
+
throw new AnchaError("USAGE", error63 instanceof Error ? error63.message : "Incompatible current counts");
|
|
183084
|
+
}
|
|
182964
183085
|
validateTrialCounts(scene2);
|
|
182965
|
-
const
|
|
183086
|
+
const beforeTrials = beforeScene.counts.requested, afterTrials = scene2.counts.requested;
|
|
183087
|
+
const { numerator, denominator } = rateChange(beforeScene.passed, beforeTrials, scene2.passed, afterTrials);
|
|
182966
183088
|
if (numerator < 0n) regressed = true;
|
|
182967
183089
|
const checks = [];
|
|
182968
183090
|
for (const [check3, after] of Object.entries(scene2.checks)) {
|
|
@@ -182978,7 +183100,7 @@ function compareSummaries(current, baseline) {
|
|
|
182978
183100
|
droppedChecks.push(delta);
|
|
182979
183101
|
}
|
|
182980
183102
|
}
|
|
182981
|
-
return { sceneId: scene2.sceneId, before: beforeScene.passed /
|
|
183103
|
+
return { sceneId: scene2.sceneId, before: beforeScene.passed / beforeTrials, after: scene2.passed / afterTrials, delta: Number(numerator) / Number(denominator), beforeTrials, afterTrials, ...checks.length > 0 && { checks } };
|
|
182982
183104
|
});
|
|
182983
183105
|
return { baselineRunId: baseline.runId, regressed, droppedChecks, scenes };
|
|
182984
183106
|
}
|