@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/world-server.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") {
|
|
@@ -55837,11 +55837,11 @@ var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
|
55837
55837
|
var __getProtoOf2 = Object.getPrototypeOf;
|
|
55838
55838
|
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
55839
55839
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
55840
|
-
var __exportAll = (
|
|
55840
|
+
var __exportAll = (all8, symbols) => {
|
|
55841
55841
|
let target4 = {};
|
|
55842
|
-
for (var name5 in
|
|
55842
|
+
for (var name5 in all8) {
|
|
55843
55843
|
__defProp2(target4, name5, {
|
|
55844
|
-
get:
|
|
55844
|
+
get: all8[name5],
|
|
55845
55845
|
enumerable: true
|
|
55846
55846
|
});
|
|
55847
55847
|
}
|
|
@@ -91899,6 +91899,68 @@ function toErrorJson(e) {
|
|
|
91899
91899
|
return { code: "INTERNAL", message: e instanceof Error ? e.message : String(e) };
|
|
91900
91900
|
}
|
|
91901
91901
|
|
|
91902
|
+
// packages/core/src/execution-support.ts
|
|
91903
|
+
var all = { local: true, container: true, managed: true };
|
|
91904
|
+
var sceneOnly = { local: true, container: true, managed: false };
|
|
91905
|
+
var EXECUTION_SUPPORT = {
|
|
91906
|
+
"input.scene": { ...sceneOnly, reason: "scene worlds cannot be imported without changing their semantics" },
|
|
91907
|
+
"input.test": { ...sceneOnly, reason: "local test worlds cannot be equated with saved managed worlds" },
|
|
91908
|
+
"input.managed-task": { local: false, container: false, managed: true, reason: "explicit saved-world tasks use runs start or the console" },
|
|
91909
|
+
"managed.world-reference": { local: false, container: false, managed: true, reason: "an explicit reference to an existing managed world, not an imported local world" },
|
|
91910
|
+
"id": all,
|
|
91911
|
+
"title": all,
|
|
91912
|
+
"task": sceneOnly,
|
|
91913
|
+
"start.task": all,
|
|
91914
|
+
"attempts": all,
|
|
91915
|
+
"twins": sceneOnly,
|
|
91916
|
+
"world": sceneOnly,
|
|
91917
|
+
"start_time": sceneOnly,
|
|
91918
|
+
"time_scale": sceneOnly,
|
|
91919
|
+
"seed": sceneOnly,
|
|
91920
|
+
"world_rules": sceneOnly,
|
|
91921
|
+
"people": sceneOnly,
|
|
91922
|
+
"until": sceneOnly,
|
|
91923
|
+
"deadline": sceneOnly,
|
|
91924
|
+
"start.message": sceneOnly,
|
|
91925
|
+
"pass": sceneOnly,
|
|
91926
|
+
"scene.timeout": sceneOnly,
|
|
91927
|
+
"test.timeout": all,
|
|
91928
|
+
"checks.state": all,
|
|
91929
|
+
"checks.trace": all,
|
|
91930
|
+
"checks.process": all,
|
|
91931
|
+
"checks.judge": sceneOnly,
|
|
91932
|
+
"agent.input.command": all,
|
|
91933
|
+
"agent.input.per_event": sceneOnly,
|
|
91934
|
+
"agent.input.events": { local: true, container: false, managed: false },
|
|
91935
|
+
"agent.input.http": all,
|
|
91936
|
+
"agent.endpoint": { local: true, container: false, managed: false },
|
|
91937
|
+
"agent.slack_transport.feed": sceneOnly,
|
|
91938
|
+
"agent.slack_transport.http": { local: true, container: false, managed: false },
|
|
91939
|
+
"agent.slack_transport.socket": { local: true, container: false, managed: false },
|
|
91940
|
+
"agent.env": sceneOnly,
|
|
91941
|
+
"agent.pass_env": sceneOnly,
|
|
91942
|
+
"agent.execution": sceneOnly,
|
|
91943
|
+
"judge": sceneOnly,
|
|
91944
|
+
"min_pass_rate": sceneOnly,
|
|
91945
|
+
"--agent": all,
|
|
91946
|
+
"--trials": all,
|
|
91947
|
+
"--parallel": all,
|
|
91948
|
+
"--idempotency-key": all,
|
|
91949
|
+
"--on": all,
|
|
91950
|
+
"--json": all,
|
|
91951
|
+
"--agent-url": { local: true, container: false, managed: false },
|
|
91952
|
+
"--compare": sceneOnly,
|
|
91953
|
+
"--min-pass-rate": sceneOnly,
|
|
91954
|
+
"--strict": sceneOnly,
|
|
91955
|
+
"--seed": sceneOnly,
|
|
91956
|
+
"--out": sceneOnly,
|
|
91957
|
+
"--detach": sceneOnly,
|
|
91958
|
+
"--pass-env": sceneOnly,
|
|
91959
|
+
"--inherit-env": sceneOnly,
|
|
91960
|
+
"--upload": sceneOnly,
|
|
91961
|
+
"--upload-required": sceneOnly
|
|
91962
|
+
};
|
|
91963
|
+
|
|
91902
91964
|
// packages/core/src/relay.ts
|
|
91903
91965
|
function relayRefusal(status4, body6) {
|
|
91904
91966
|
const error63 = typeof body6 === "object" && body6 !== null ? body6.error : void 0;
|
|
@@ -95190,15 +95252,15 @@ var NotionSeedSchema = external_exports.strictObject({
|
|
|
95190
95252
|
databases: external_exports.array(database).max(200).default([])
|
|
95191
95253
|
}).superRefine((seed40, ctx) => {
|
|
95192
95254
|
const issue5 = (path4, message5) => ctx.addIssue({ code: "custom", path: path4, message: message5 });
|
|
95193
|
-
const users4 = /* @__PURE__ */ new Set(), pages = /* @__PURE__ */ new Set(),
|
|
95255
|
+
const users4 = /* @__PURE__ */ new Set(), pages = /* @__PURE__ */ new Set(), all8 = /* @__PURE__ */ new Set();
|
|
95194
95256
|
seed40.users.forEach((u, i) => {
|
|
95195
95257
|
if (users4.has(u.ref)) issue5(["users", i, "ref"], "duplicate user ref");
|
|
95196
95258
|
users4.add(u.ref);
|
|
95197
95259
|
});
|
|
95198
95260
|
const declare = (r, path4) => {
|
|
95199
95261
|
if (r === void 0) return;
|
|
95200
|
-
if (
|
|
95201
|
-
|
|
95262
|
+
if (all8.has(r) || users4.has(r)) issue5(path4, `duplicate ref ${r}`);
|
|
95263
|
+
all8.add(r);
|
|
95202
95264
|
};
|
|
95203
95265
|
seed40.pages.forEach((p2, i) => {
|
|
95204
95266
|
declare(p2.ref, ["pages", i, "ref"]);
|
|
@@ -104369,9 +104431,9 @@ function inspectPredicate(env, predicate, atMs) {
|
|
|
104369
104431
|
const expected = predicateWords(predicate);
|
|
104370
104432
|
const outcome3 = (passed, actual, explanation = actual) => ({ passed, expected, actual, explanation });
|
|
104371
104433
|
if ("all" in predicate || "any" in predicate) {
|
|
104372
|
-
const
|
|
104373
|
-
const children2 = (
|
|
104374
|
-
return outcome3(
|
|
104434
|
+
const all8 = "all" in predicate;
|
|
104435
|
+
const children2 = (all8 ? predicate.all : predicate.any).map((child2) => inspectPredicate(env, child2, atMs));
|
|
104436
|
+
return outcome3(all8 ? children2.every((child2) => child2.passed) : children2.some((child2) => child2.passed), children2.map((child2) => child2.actual).join("; "));
|
|
104375
104437
|
}
|
|
104376
104438
|
if ("not" in predicate) {
|
|
104377
104439
|
const child2 = inspectPredicate(env, predicate.not, atMs);
|
|
@@ -108707,10 +108769,10 @@ var bufferToFormData = (arrayBuffer, contentType) => {
|
|
|
108707
108769
|
var MAX_NESTED_OBJECTS = 1e4;
|
|
108708
108770
|
var isRawRequest = (request) => "headers" in request;
|
|
108709
108771
|
var parseBody = async (request, options3 = /* @__PURE__ */ Object.create(null)) => {
|
|
108710
|
-
const { all:
|
|
108772
|
+
const { all: all8 = false, dot = false } = options3;
|
|
108711
108773
|
const mediaType2 = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
108712
108774
|
if (mediaType2 === "multipart/form-data" || mediaType2 === "application/x-www-form-urlencoded") return parseFormData(request, {
|
|
108713
|
-
all:
|
|
108775
|
+
all: all8,
|
|
108714
108776
|
dot
|
|
108715
108777
|
});
|
|
108716
108778
|
return {};
|
|
@@ -110615,8 +110677,8 @@ function properties(type, record8) {
|
|
|
110615
110677
|
function project3(ctx, type, record8, selected2, historyFields, associationObjects) {
|
|
110616
110678
|
const names3 = selected2 ?? defaultProperties[type];
|
|
110617
110679
|
for (const name5 of [...names3, ...historyFields ?? []]) checkProperty(type, name5);
|
|
110618
|
-
const
|
|
110619
|
-
const output2 = { id: record8.id, properties: Object.fromEntries(keys5.filter((key3) =>
|
|
110680
|
+
const all8 = properties(type, record8), keys5 = [.../* @__PURE__ */ new Set([...names3, "hs_object_id", "createdate", type === "contacts" ? "lastmodifieddate" : "hs_lastmodifieddate"])];
|
|
110681
|
+
const output2 = { id: record8.id, properties: Object.fromEntries(keys5.filter((key3) => all8[key3] !== void 0).map((key3) => [key3, all8[key3]])), createdAt: record8.createdAt, updatedAt: record8.updatedAt, archived: record8.archived, ...record8.archived && { archivedAt: record8.archivedAt } };
|
|
110620
110682
|
if (historyFields?.length) {
|
|
110621
110683
|
const versions2 = ctx.store.db.prepare("SELECT data,operation FROM hubspot_versions WHERE type=? AND id=? ORDER BY ordinal").all(type, record8.id).map((row) => ({ ...row, record: JSON.parse(row.data) }));
|
|
110622
110684
|
output2.propertiesWithHistory = Object.fromEntries(historyFields.map((name5) => {
|
|
@@ -111032,9 +111094,9 @@ function dispatch(ctx, method2, url3, body6) {
|
|
|
111032
111094
|
permission3(ctx, type2);
|
|
111033
111095
|
queryParams(url3, ["archived"]);
|
|
111034
111096
|
if (boolean5(url3.searchParams.get("archived"))) unsupported3("archived pipelines");
|
|
111035
|
-
const
|
|
111036
|
-
if (!match2[2]) return { status: 200, body: { results:
|
|
111037
|
-
const pipeline =
|
|
111097
|
+
const all8 = config2(ctx).pipelines;
|
|
111098
|
+
if (!match2[2]) return { status: 200, body: { results: all8.map((p2) => ({ ...p2, archived: false })) } };
|
|
111099
|
+
const pipeline = all8.find((p2) => p2.id === decodeURIComponent(match2[2]));
|
|
111038
111100
|
if (!pipeline) throw new HubError(404, "OBJECT_NOT_FOUND", "Pipeline not found.");
|
|
111039
111101
|
if (path4.includes("/stages")) {
|
|
111040
111102
|
if (!match2[3]) return { status: 200, body: { results: pipeline.stages.map((stage2) => ({ ...stage2, createdAt: pipeline.createdAt, updatedAt: pipeline.updatedAt, archived: false })) } };
|
|
@@ -111470,7 +111532,7 @@ function initializeCatalogIntegrations(env) {
|
|
|
111470
111532
|
}
|
|
111471
111533
|
function reconcileCatalogIntegrations(env) {
|
|
111472
111534
|
if (!hasTable5(env, "world_catalog_cursor")) return { activity: false };
|
|
111473
|
-
const
|
|
111535
|
+
const all8 = entries(env), before = env.events.tail;
|
|
111474
111536
|
let cursor4 = env.store.db.prepare("SELECT cursor FROM world_catalog_cursor WHERE id = 1").get().cursor;
|
|
111475
111537
|
let activity2 = false;
|
|
111476
111538
|
scan: for (let batch3 = env.events.list(cursor4, 100); batch3.length; batch3 = env.events.list(cursor4, 100)) {
|
|
@@ -111482,7 +111544,7 @@ function reconcileCatalogIntegrations(env) {
|
|
|
111482
111544
|
}
|
|
111483
111545
|
cursor4 = event3.cursor;
|
|
111484
111546
|
const view3 = catalogEvent(event3);
|
|
111485
|
-
for (const entry2 of
|
|
111547
|
+
for (const entry2 of all8) {
|
|
111486
111548
|
if (!matches(entry2.integration, view3)) continue;
|
|
111487
111549
|
const delay = entry2.integration.delay === void 0 ? 0 : parseDuration(entry2.integration.delay);
|
|
111488
111550
|
if (delay > 0) env.scheduler.enqueue({ atMs: env.clock.elapsedMs() + delay, kind: "integration.catalog", payload: { integration: entry2.ordinal, event: event3.cursor } });
|
|
@@ -122024,11 +122086,11 @@ function listPermissions(call2) {
|
|
|
122024
122086
|
const pageSize2 = integerParameter(params9, "pageSize", 100, 1, 100);
|
|
122025
122087
|
const binding2 = JSON.stringify(["permissions", file3.id]);
|
|
122026
122088
|
const offset16 = readPageToken(params9.get("pageToken"), binding2);
|
|
122027
|
-
const
|
|
122089
|
+
const all8 = effectivePermissions(call2.ctx, file3);
|
|
122028
122090
|
return json8(project8({
|
|
122029
122091
|
kind: "drive#permissionList",
|
|
122030
|
-
...offset16 + pageSize2 <
|
|
122031
|
-
permissions:
|
|
122092
|
+
...offset16 + pageSize2 < all8.length && { nextPageToken: pageToken(offset16 + pageSize2, binding2) },
|
|
122093
|
+
permissions: all8.slice(offset16, offset16 + pageSize2).map((entry2) => permissionResource(call2.ctx, entry2.grant))
|
|
122032
122094
|
}, mask(params9, "kind,nextPageToken,permissions(kind,id,type,role,allowFileDiscovery)", ["kind", "nextPageToken", "permissions"], { permissions: PERMISSION_FIELDS })));
|
|
122033
122095
|
}
|
|
122034
122096
|
function getPermission(call2) {
|
|
@@ -122766,10 +122828,10 @@ function leaves(part) {
|
|
|
122766
122828
|
return part.parts.length ? part.parts.flatMap(leaves) : [part];
|
|
122767
122829
|
}
|
|
122768
122830
|
function bodyText(root2) {
|
|
122769
|
-
const
|
|
122770
|
-
const plain3 =
|
|
122831
|
+
const all8 = leaves(root2).filter((p2) => !isAttachment(p2));
|
|
122832
|
+
const plain3 = all8.filter((p2) => p2.mimeType === "text/plain");
|
|
122771
122833
|
if (plain3.length) return plain3.map(partText).join("\n");
|
|
122772
|
-
return
|
|
122834
|
+
return all8.filter((p2) => p2.mimeType === "text/html").map((p2) => htmlToText(partText(p2))).join("\n");
|
|
122773
122835
|
}
|
|
122774
122836
|
function htmlToText(html2) {
|
|
122775
122837
|
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, "&");
|
|
@@ -123471,9 +123533,9 @@ function searchFor(r) {
|
|
|
123471
123533
|
function filterFor(r, labelIds = []) {
|
|
123472
123534
|
const search9 = searchFor(r), mailbox2 = r.caller.mailbox.address;
|
|
123473
123535
|
for (const id12 of labelIds) if (!getLabel2(r.ctx, mailbox2, id12)) invalid10(`Invalid label: ${id12}`);
|
|
123474
|
-
const
|
|
123475
|
-
const trashOk =
|
|
123476
|
-
const spamOk =
|
|
123536
|
+
const all8 = bool2(r.query, "includeSpamTrash");
|
|
123537
|
+
const trashOk = all8 || search9.includesTrash || labelIds.includes("TRASH");
|
|
123538
|
+
const spamOk = all8 || search9.includesSpam || labelIds.includes("SPAM");
|
|
123477
123539
|
return (row) => {
|
|
123478
123540
|
const ids2 = labelIdsOf(r.ctx, mailbox2, row.id);
|
|
123479
123541
|
if (!trashOk && ids2.includes("TRASH")) return false;
|
|
@@ -124518,12 +124580,12 @@ function listBuckets(call2) {
|
|
|
124518
124580
|
const limit = max === void 0 ? 1e4 : Number(max);
|
|
124519
124581
|
if (!Number.isInteger(limit) || limit < 1 || limit > 1e4) throw new S3Error("InvalidArgument", "Argument max-buckets must be an integer between 1 and 10000", { ArgumentName: "max-buckets", ArgumentValue: max ?? "" });
|
|
124520
124582
|
const after = token2 === void 0 ? "" : Buffer.from(token2, "base64url").toString("utf8");
|
|
124521
|
-
const
|
|
124522
|
-
const page15 =
|
|
124583
|
+
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);
|
|
124584
|
+
const page15 = all8.slice(0, limit);
|
|
124523
124585
|
return xml(call2, node3("ListAllMyBucketsResult", [
|
|
124524
124586
|
owner(call2.ctx),
|
|
124525
124587
|
node3("Buckets", page15.map((bucket2) => node3("Bucket", [el("Name", bucket2.name), el("CreationDate", iso3(bucket2.created_ms)), el("BucketRegion", bucket2.region)]))),
|
|
124526
|
-
...
|
|
124588
|
+
...all8.length > limit ? [el("ContinuationToken", Buffer.from(page15.at(-1).name).toString("base64url"))] : [],
|
|
124527
124589
|
...prefix2 ? [el("Prefix", prefix2)] : []
|
|
124528
124590
|
], true));
|
|
124529
124591
|
}
|
|
@@ -125162,7 +125224,7 @@ function migrate16(db2) {
|
|
|
125162
125224
|
db2.exec(SCHEMA7);
|
|
125163
125225
|
}
|
|
125164
125226
|
var one = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
125165
|
-
var
|
|
125227
|
+
var all2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
125166
125228
|
var org = (ctx) => one(ctx, "SELECT * FROM linear_org");
|
|
125167
125229
|
var userById = (ctx, id12) => one(ctx, "SELECT * FROM linear_users WHERE id = ?", id12);
|
|
125168
125230
|
var teamById = (ctx, id12) => one(ctx, "SELECT * FROM linear_teams WHERE id = ?", id12);
|
|
@@ -125171,17 +125233,17 @@ var labelById = (ctx, id12) => one(ctx, "SELECT * FROM linear_labels WHERE id =
|
|
|
125171
125233
|
var projectById = (ctx, id12) => one(ctx, "SELECT * FROM linear_projects WHERE id = ?", id12);
|
|
125172
125234
|
var issueById = (ctx, id12) => one(ctx, "SELECT * FROM linear_issues WHERE id = ?", id12);
|
|
125173
125235
|
var commentById = (ctx, id12) => one(ctx, "SELECT * FROM linear_comments WHERE id = ?", id12);
|
|
125174
|
-
var allUsers = (ctx) =>
|
|
125175
|
-
var allTeams = (ctx) =>
|
|
125176
|
-
var allStates = (ctx) =>
|
|
125177
|
-
var allLabels = (ctx) =>
|
|
125178
|
-
var allProjects = (ctx) =>
|
|
125179
|
-
var allIssues = (ctx) =>
|
|
125180
|
-
var allComments = (ctx) =>
|
|
125181
|
-
var teamMemberIds = (ctx, teamId) =>
|
|
125182
|
-
var userTeamIds = (ctx, userId) =>
|
|
125183
|
-
var issueLabelIds = (ctx, issueId) =>
|
|
125184
|
-
var projectTeamIds = (ctx, projectId) =>
|
|
125236
|
+
var allUsers = (ctx) => all2(ctx, "SELECT * FROM linear_users ORDER BY rowid");
|
|
125237
|
+
var allTeams = (ctx) => all2(ctx, "SELECT * FROM linear_teams ORDER BY rowid");
|
|
125238
|
+
var allStates = (ctx) => all2(ctx, "SELECT * FROM linear_states ORDER BY rowid");
|
|
125239
|
+
var allLabels = (ctx) => all2(ctx, "SELECT * FROM linear_labels ORDER BY rowid");
|
|
125240
|
+
var allProjects = (ctx) => all2(ctx, "SELECT * FROM linear_projects ORDER BY rowid");
|
|
125241
|
+
var allIssues = (ctx) => all2(ctx, "SELECT * FROM linear_issues ORDER BY rowid");
|
|
125242
|
+
var allComments = (ctx) => all2(ctx, "SELECT * FROM linear_comments ORDER BY rowid");
|
|
125243
|
+
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);
|
|
125244
|
+
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);
|
|
125245
|
+
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);
|
|
125246
|
+
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);
|
|
125185
125247
|
function uuid5(ctx) {
|
|
125186
125248
|
const hex5 = ctx.ids.hex(32).split("");
|
|
125187
125249
|
hex5[12] = "4";
|
|
@@ -125223,7 +125285,7 @@ function gap3(what) {
|
|
|
125223
125285
|
var scalar = (comparator, column) => ({ kind: "scalar", comparator, get: (_, row) => row[column] });
|
|
125224
125286
|
var ts = (column) => scalar("date", column);
|
|
125225
125287
|
var db = (r) => r.ctx.store.db;
|
|
125226
|
-
var
|
|
125288
|
+
var all3 = (r, sql, ...args) => db(r).prepare(sql).all(...args);
|
|
125227
125289
|
var SPECS = {
|
|
125228
125290
|
Issue: {
|
|
125229
125291
|
id: scalar("id", "id"),
|
|
@@ -125246,10 +125308,10 @@ ${row.description ?? ""}` },
|
|
|
125246
125308
|
assignee: { kind: "one", type: "User", get: (r, row) => row.assignee_id ? userById(r.ctx, row.assignee_id) : void 0 },
|
|
125247
125309
|
creator: { kind: "one", type: "User", get: (r, row) => row.creator_id ? userById(r.ctx, row.creator_id) : void 0 },
|
|
125248
125310
|
project: { kind: "one", type: "Project", get: (r, row) => row.project_id ? projectById(r.ctx, row.project_id) : void 0 },
|
|
125249
|
-
parent: { kind: "one", type: "Issue", get: (r, row) => row.parent_id ?
|
|
125311
|
+
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 },
|
|
125250
125312
|
labels: { kind: "many", type: "IssueLabel", get: (r, row) => issueLabelIds(r.ctx, row.id).map((id12) => labelById(r.ctx, id12)) },
|
|
125251
|
-
children: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125252
|
-
comments: { kind: "many", type: "Comment", get: (r, row) =>
|
|
125313
|
+
children: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE parent_id = ? ORDER BY rowid", row.id) },
|
|
125314
|
+
comments: { kind: "many", type: "Comment", get: (r, row) => all3(r, "SELECT * FROM linear_comments WHERE issue_id = ? ORDER BY rowid", row.id) }
|
|
125253
125315
|
},
|
|
125254
125316
|
Team: {
|
|
125255
125317
|
id: scalar("id", "id"),
|
|
@@ -125260,7 +125322,7 @@ ${row.description ?? ""}` },
|
|
|
125260
125322
|
createdAt: ts("created_at"),
|
|
125261
125323
|
updatedAt: ts("updated_at"),
|
|
125262
125324
|
members: { kind: "many", type: "User", get: (r, row) => teamMemberIds(r.ctx, row.id).map((id12) => userById(r.ctx, id12)) },
|
|
125263
|
-
issues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125325
|
+
issues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE team_id = ? ORDER BY rowid", row.id) }
|
|
125264
125326
|
},
|
|
125265
125327
|
User: {
|
|
125266
125328
|
id: scalar("id", "id"),
|
|
@@ -125273,7 +125335,7 @@ ${row.description ?? ""}` },
|
|
|
125273
125335
|
app: { kind: "scalar", comparator: "boolean", get: () => false },
|
|
125274
125336
|
createdAt: ts("created_at"),
|
|
125275
125337
|
updatedAt: ts("updated_at"),
|
|
125276
|
-
assignedIssues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125338
|
+
assignedIssues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE assignee_id = ? ORDER BY rowid", row.id) }
|
|
125277
125339
|
},
|
|
125278
125340
|
WorkflowState: {
|
|
125279
125341
|
id: scalar("id", "id"),
|
|
@@ -125284,7 +125346,7 @@ ${row.description ?? ""}` },
|
|
|
125284
125346
|
createdAt: ts("created_at"),
|
|
125285
125347
|
updatedAt: ts("updated_at"),
|
|
125286
125348
|
team: { kind: "one", type: "Team", get: (r, row) => teamById(r.ctx, row.team_id) },
|
|
125287
|
-
issues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125349
|
+
issues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE state_id = ? ORDER BY rowid", row.id) }
|
|
125288
125350
|
},
|
|
125289
125351
|
IssueLabel: {
|
|
125290
125352
|
id: scalar("id", "id"),
|
|
@@ -125300,9 +125362,9 @@ ${row.description ?? ""}` },
|
|
|
125300
125362
|
body: scalar("string", "body"),
|
|
125301
125363
|
createdAt: ts("created_at"),
|
|
125302
125364
|
updatedAt: ts("updated_at"),
|
|
125303
|
-
issue: { kind: "one", type: "Issue", get: (r, row) =>
|
|
125365
|
+
issue: { kind: "one", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE id = ?", row.issue_id)[0] },
|
|
125304
125366
|
user: { kind: "one", type: "User", get: (r, row) => userById(r.ctx, row.user_id) },
|
|
125305
|
-
parent: { kind: "one", type: "Comment", get: (r, row) => row.parent_id ?
|
|
125367
|
+
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 }
|
|
125306
125368
|
},
|
|
125307
125369
|
Project: {
|
|
125308
125370
|
id: scalar("id", "id"),
|
|
@@ -125319,7 +125381,7 @@ ${row.description ?? ""}` },
|
|
|
125319
125381
|
searchableContent: { kind: "scalar", comparator: "content", get: (_, row) => `${row.name}
|
|
125320
125382
|
${row.description ?? ""}` },
|
|
125321
125383
|
lead: { kind: "one", type: "User", get: (r, row) => row.lead_id ? userById(r.ctx, row.lead_id) : void 0 },
|
|
125322
|
-
issues: { kind: "many", type: "Issue", get: (r, row) =>
|
|
125384
|
+
issues: { kind: "many", type: "Issue", get: (r, row) => all3(r, "SELECT * FROM linear_issues WHERE project_id = ? ORDER BY rowid", row.id) }
|
|
125323
125385
|
}
|
|
125324
125386
|
};
|
|
125325
125387
|
function dateValue2(r, value4) {
|
|
@@ -126201,8 +126263,8 @@ function seed17(ctx) {
|
|
|
126201
126263
|
states.set(s.name.toLowerCase(), stateId);
|
|
126202
126264
|
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);
|
|
126203
126265
|
});
|
|
126204
|
-
const
|
|
126205
|
-
const initial = t.default_state ?? (
|
|
126266
|
+
const all8 = t.states ?? LINEAR_DEFAULT_STATES;
|
|
126267
|
+
const initial = t.default_state ?? (all8.find((s) => s.type === "backlog") ?? all8.find((s) => s.type === "unstarted")).name;
|
|
126206
126268
|
db2.prepare("UPDATE linear_teams SET default_state_id = ? WHERE id = ?").run(states.get(initial.toLowerCase()), id12);
|
|
126207
126269
|
for (const l of t.labels) {
|
|
126208
126270
|
const labelId = uuid5(ctx);
|
|
@@ -127430,7 +127492,7 @@ function save6(ctx, value4) {
|
|
|
127430
127492
|
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));
|
|
127431
127493
|
return value4;
|
|
127432
127494
|
}
|
|
127433
|
-
function
|
|
127495
|
+
function all4(ctx, type) {
|
|
127434
127496
|
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));
|
|
127435
127497
|
}
|
|
127436
127498
|
var BASE622 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
@@ -128750,7 +128812,7 @@ function markPaid(ctx, inv, at2, amount3 = inv.amount_remaining, offStripe = fal
|
|
|
128750
128812
|
const sub2 = inv.parent?.subscription_details?.subscription ? load(ctx, inv.parent.subscription_details.subscription) : void 0;
|
|
128751
128813
|
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" });
|
|
128752
128814
|
}
|
|
128753
|
-
var openInvoices = (ctx, subscription2) =>
|
|
128815
|
+
var openInvoices = (ctx, subscription2) => all4(ctx, "invoice").filter((i) => i.status === "open" && i.parent?.subscription_details?.subscription === subscription2);
|
|
128754
128816
|
function pay(ctx, inv, o) {
|
|
128755
128817
|
if (inv.status === "paid") invalid11("Invoice is already paid");
|
|
128756
128818
|
if (inv.status === "void") invalid11("You cannot pay a void invoice.");
|
|
@@ -128784,7 +128846,7 @@ function voidInvoice(ctx, inv) {
|
|
|
128784
128846
|
if (inv.status === "void") invalid11("This invoice is already void.", void 0, "invoice_not_editable");
|
|
128785
128847
|
const at2 = nowSeconds(ctx);
|
|
128786
128848
|
Object.assign(inv, { status: "void", amount_remaining: 0, next_payment_attempt: null, auto_advance: false, status_transitions: { ...inv.status_transitions, voided_at: at2 } });
|
|
128787
|
-
for (const item2 of
|
|
128849
|
+
for (const item2 of all4(ctx, "invoiceitem").filter((i) => i.invoice === inv.id)) save6(ctx, item2);
|
|
128788
128850
|
return save6(ctx, inv);
|
|
128789
128851
|
}
|
|
128790
128852
|
function prorate(ctx, sub2, item2, oldPrice, oldQuantity, newPrice, newQuantity) {
|
|
@@ -128871,7 +128933,7 @@ function searchCustomers(ctx, params9, present2) {
|
|
|
128871
128933
|
const limit = int2(params9.limit, "limit") ?? 10;
|
|
128872
128934
|
if (limit < 1 || limit > 100) invalid11("Invalid limit: must be between 1 and 100.", "limit");
|
|
128873
128935
|
const { clauses: tests, or } = clauses(query10);
|
|
128874
|
-
const matches7 =
|
|
128936
|
+
const matches7 = all4(ctx, "customer").filter((c) => !c.deleted && (or ? tests.some((t) => t(c)) : tests.every((t) => t(c))));
|
|
128875
128937
|
const token2 = str(params9.page, "page");
|
|
128876
128938
|
const offset16 = token2 === void 0 ? 0 : Number(/^page_(\d+)$/.exec(token2)?.[1] ?? NaN);
|
|
128877
128939
|
if (!Number.isSafeInteger(offset16)) invalid11(`Invalid page: ${token2}`, "page");
|
|
@@ -128945,7 +129007,7 @@ function customerFields(r, c) {
|
|
|
128945
129007
|
function presentCustomer(ctx, c) {
|
|
128946
129008
|
if (c.deleted) return deletedStub(c);
|
|
128947
129009
|
const now10 = nowSeconds(ctx);
|
|
128948
|
-
return { ...c, delinquent:
|
|
129010
|
+
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)) };
|
|
128949
129011
|
}
|
|
128950
129012
|
var read4 = (path4, supported3, run3, notes6) => ({ method: "GET", path: path4, supported: supported3, run: run3, coverage: notes6 ? { status: "partial", notes: notes6 } : { status: "supported" } });
|
|
128951
129013
|
var write3 = (method2, path4, supported3, run3, notes6) => ({ method: method2, path: path4, supported: supported3, run: run3, coverage: notes6 ? { status: "partial", notes: notes6 } : { status: "supported" } });
|
|
@@ -128959,7 +129021,7 @@ var stripeRoutes = [
|
|
|
128959
129021
|
}, "invoice_settings supports default_payment_method only; addresses, shipping, tax ids and cash balances are gaps"),
|
|
128960
129022
|
read4("/v1/customers", ["email", "created", ...PAGE], (r) => {
|
|
128961
129023
|
const email10 = str(r.params.email, "email", 512);
|
|
128962
|
-
const items = filterCreated(
|
|
129024
|
+
const items = filterCreated(all4(r.ctx, "customer").filter((c) => !c.deleted && (email10 === void 0 || c.email === email10)), r.params);
|
|
128963
129025
|
const result = page7(items, r.params, "/v1/customers", "customer");
|
|
128964
129026
|
return { ...result, data: result.data.map((c) => presentCustomer(r.ctx, c)) };
|
|
128965
129027
|
}),
|
|
@@ -128972,7 +129034,7 @@ var stripeRoutes = [
|
|
|
128972
129034
|
}),
|
|
128973
129035
|
write3("DELETE", "/v1/customers/:id", [], (r) => {
|
|
128974
129036
|
const c = liveCustomer(r.ctx, r.id, "id");
|
|
128975
|
-
for (const sub2 of
|
|
129037
|
+
for (const sub2 of all4(r.ctx, "subscription").filter((s) => s.customer === c.id && s.status !== "canceled")) {
|
|
128976
129038
|
const at2 = nowSeconds(r.ctx);
|
|
128977
129039
|
save6(r.ctx, { ...sub2, status: "canceled", canceled_at: at2, ended_at: at2, cancellation_details: { ...sub2.cancellation_details, reason: "cancellation_requested" } });
|
|
128978
129040
|
}
|
|
@@ -128982,20 +129044,20 @@ var stripeRoutes = [
|
|
|
128982
129044
|
/* ----------------------------- products and prices ---------------------------- */
|
|
128983
129045
|
read4("/v1/products", ["active", "ids", "created", ...PAGE], (r) => {
|
|
128984
129046
|
const active2 = bool3(r.params.active, "active"), ids2 = list9(r.params.ids, "ids")?.map((v, i) => str(v, `ids[${i}]`));
|
|
128985
|
-
return page7(filterCreated(
|
|
129047
|
+
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");
|
|
128986
129048
|
}),
|
|
128987
129049
|
read4("/v1/products/:id", [], (r) => find4(r.ctx, "product", r.id)),
|
|
128988
129050
|
read4("/v1/prices", ["product", "active", "type", "currency", "lookup_keys", "created", ...PAGE], (r) => {
|
|
128989
129051
|
const product2 = str(r.params.product, "product"), active2 = bool3(r.params.active, "active"), type = oneOf(r.params.type, "type", ["one_time", "recurring"]);
|
|
128990
129052
|
const currency = str(r.params.currency, "currency")?.toLowerCase(), keys5 = list9(r.params.lookup_keys, "lookup_keys")?.map((v, i) => str(v, `lookup_keys[${i}]`));
|
|
128991
|
-
return page7(filterCreated(
|
|
129053
|
+
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");
|
|
128992
129054
|
}),
|
|
128993
129055
|
read4("/v1/prices/:id", [], (r) => find4(r.ctx, "price", r.id)),
|
|
128994
129056
|
/* --------------------------------- subscriptions ------------------------------- */
|
|
128995
129057
|
read4("/v1/subscriptions", ["customer", "price", "status", "created", ...PAGE], (r) => {
|
|
128996
129058
|
const customer3 = str(r.params.customer, "customer"), priceId = str(r.params.price, "price");
|
|
128997
129059
|
const status4 = oneOf(r.params.status, "status", ["active", "all", "canceled", "ended", "incomplete", "incomplete_expired", "past_due", "paused", "trialing", "unpaid"]);
|
|
128998
|
-
const items =
|
|
129060
|
+
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)));
|
|
128999
129061
|
return page7(filterCreated(items, r.params), r.params, "/v1/subscriptions", "subscription");
|
|
129000
129062
|
}, "without status, canceled subscriptions are left out, as Stripe does"),
|
|
129001
129063
|
read4("/v1/subscriptions/:id", [], (r) => find4(r.ctx, "subscription", r.id)),
|
|
@@ -129078,7 +129140,7 @@ var stripeRoutes = [
|
|
|
129078
129140
|
read4("/v1/invoices", ["customer", "subscription", "status", "collection_method", "created", ...PAGE], (r) => {
|
|
129079
129141
|
const customer3 = str(r.params.customer, "customer"), subscription2 = str(r.params.subscription, "subscription");
|
|
129080
129142
|
const status4 = oneOf(r.params.status, "status", ["draft", "open", "paid", "uncollectible", "void"]), method2 = oneOf(r.params.collection_method, "collection_method", ["charge_automatically", "send_invoice"]);
|
|
129081
|
-
return page7(filterCreated(
|
|
129143
|
+
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");
|
|
129082
129144
|
}),
|
|
129083
129145
|
read4("/v1/invoices/:id", [], (r) => find4(r.ctx, "invoice", r.id)),
|
|
129084
129146
|
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) => {
|
|
@@ -129110,7 +129172,7 @@ var stripeRoutes = [
|
|
|
129110
129172
|
period: { start: now10, end: now10 }
|
|
129111
129173
|
});
|
|
129112
129174
|
save6(r.ctx, inv);
|
|
129113
|
-
if (behavior === "include") for (const item2 of
|
|
129175
|
+
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);
|
|
129114
129176
|
return save6(r.ctx, recalc(inv));
|
|
129115
129177
|
}, "pending invoice items are included only with pending_invoice_items_behavior=include, the default for new API versions"),
|
|
129116
129178
|
write3("POST", "/v1/invoices/:id", ["description", "footer", "custom_fields", "metadata", "auto_advance", "days_until_due", "due_date"], (r) => {
|
|
@@ -129186,7 +129248,7 @@ var stripeRoutes = [
|
|
|
129186
129248
|
read4("/v1/invoiceitems", ["customer", "invoice", "pending", "created", ...PAGE], (r) => {
|
|
129187
129249
|
const customer3 = str(r.params.customer, "customer"), invoiceId = str(r.params.invoice, "invoice"), pending = bool3(r.params.pending, "pending");
|
|
129188
129250
|
return page7(
|
|
129189
|
-
filterCreated(
|
|
129251
|
+
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"),
|
|
129190
129252
|
r.params,
|
|
129191
129253
|
"/v1/invoiceitems",
|
|
129192
129254
|
"invoiceitem"
|
|
@@ -129226,7 +129288,7 @@ var stripeRoutes = [
|
|
|
129226
129288
|
}, "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"),
|
|
129227
129289
|
read4("/v1/payment_intents", ["customer", "created", ...PAGE], (r) => {
|
|
129228
129290
|
const customer3 = str(r.params.customer, "customer");
|
|
129229
|
-
return page7(filterCreated(
|
|
129291
|
+
return page7(filterCreated(all4(r.ctx, "payment_intent").filter((pi) => !customer3 || pi.customer === customer3), r.params), r.params, "/v1/payment_intents", "payment_intent");
|
|
129230
129292
|
}),
|
|
129231
129293
|
read4("/v1/payment_intents/:id", ["client_secret"], (r) => find4(r.ctx, "payment_intent", r.id)),
|
|
129232
129294
|
write3("POST", "/v1/payment_intents/:id/confirm", ["payment_method", "off_session", "receipt_email"], (r) => {
|
|
@@ -129249,7 +129311,7 @@ var stripeRoutes = [
|
|
|
129249
129311
|
/* -------------------------------- charges, refunds ------------------------------- */
|
|
129250
129312
|
read4("/v1/charges", ["customer", "payment_intent", "created", ...PAGE], (r) => {
|
|
129251
129313
|
const customer3 = str(r.params.customer, "customer"), intent = str(r.params.payment_intent, "payment_intent");
|
|
129252
|
-
return page7(filterCreated(
|
|
129314
|
+
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");
|
|
129253
129315
|
}),
|
|
129254
129316
|
read4("/v1/charges/:id", [], (r) => find4(r.ctx, "charge", r.id)),
|
|
129255
129317
|
write3("POST", "/v1/refunds", ["charge", "payment_intent", "amount", "reason", "metadata"], (r) => {
|
|
@@ -129267,7 +129329,7 @@ var stripeRoutes = [
|
|
|
129267
129329
|
}, "card refunds settle at once (status succeeded)"),
|
|
129268
129330
|
read4("/v1/refunds", ["charge", "payment_intent", "created", ...PAGE], (r) => {
|
|
129269
129331
|
const chargeId = str(r.params.charge, "charge"), intent = str(r.params.payment_intent, "payment_intent");
|
|
129270
|
-
return page7(filterCreated(
|
|
129332
|
+
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");
|
|
129271
129333
|
}),
|
|
129272
129334
|
read4("/v1/refunds/:id", [], (r) => find4(r.ctx, "refund", r.id)),
|
|
129273
129335
|
read4("/v1/balance", [], (r) => load(r.ctx, "__balance"), "available and pending card funds; payouts and fees are not modeled")
|
|
@@ -129435,7 +129497,7 @@ function seed19(ctx) {
|
|
|
129435
129497
|
save6(ctx, row);
|
|
129436
129498
|
}
|
|
129437
129499
|
}
|
|
129438
|
-
if (sub2) save6(ctx, { ...load(ctx, sub2.id), latest_invoice:
|
|
129500
|
+
if (sub2) save6(ctx, { ...load(ctx, sub2.id), latest_invoice: all4(ctx, "invoice").find((i) => i.parent?.subscription_details?.subscription === sub2.id)?.id ?? null });
|
|
129439
129501
|
}
|
|
129440
129502
|
for (const p2 of data5.payments) {
|
|
129441
129503
|
const cus = p2.customer ? load(ctx, customers.get(p2.customer).id) : null, t = at2(p2.created);
|
|
@@ -129459,7 +129521,7 @@ function credentials18(ctx) {
|
|
|
129459
129521
|
|
|
129460
129522
|
// packages/server/src/twins/stripe/state.ts
|
|
129461
129523
|
function dumpState18(ctx) {
|
|
129462
|
-
const of = (type) => present(
|
|
129524
|
+
const of = (type) => present(all4(ctx, type).reverse());
|
|
129463
129525
|
return {
|
|
129464
129526
|
balance: present(load(ctx, "__balance")),
|
|
129465
129527
|
customers: of("customer"),
|
|
@@ -130091,8 +130153,8 @@ var flagUser = (column, value4) => (call2) => {
|
|
|
130091
130153
|
function userMemberships(call2) {
|
|
130092
130154
|
const query10 = params7(call2, ["limit", "offset"]);
|
|
130093
130155
|
const user8 = userFor2(call2);
|
|
130094
|
-
const
|
|
130095
|
-
return respond3(call2, 200, { data: list10(
|
|
130156
|
+
const all8 = call2.ctx.store.db.prepare("SELECT * FROM clerk_memberships WHERE user_id = ? ORDER BY created_ms, id").all(user8.id);
|
|
130157
|
+
return respond3(call2, 200, { data: list10(all8, query10).map((member4) => membershipJson(call2.ctx, member4)), total_count: all8.length });
|
|
130096
130158
|
}
|
|
130097
130159
|
function orgFor(call2) {
|
|
130098
130160
|
const org5 = getOrg(call2.ctx, call2.ids[0]);
|
|
@@ -132478,7 +132540,7 @@ function migrate22(db2) {
|
|
|
132478
132540
|
db2.exec(SCHEMA13);
|
|
132479
132541
|
}
|
|
132480
132542
|
var one2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
132481
|
-
var
|
|
132543
|
+
var all5 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
132482
132544
|
var run2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).run(...args);
|
|
132483
132545
|
function uuid9(ctx) {
|
|
132484
132546
|
const h = ctx.ids.hex(32).split("");
|
|
@@ -132704,7 +132766,7 @@ function primary(ctx, attr, data5) {
|
|
|
132704
132766
|
}
|
|
132705
132767
|
}
|
|
132706
132768
|
function currentValues(ctx, parentId, attributeId) {
|
|
132707
|
-
return
|
|
132769
|
+
return all5(ctx, "SELECT * FROM attio_values WHERE parent_id = ? AND attribute_id = ? AND active_until IS NULL ORDER BY id", parentId, attributeId);
|
|
132708
132770
|
}
|
|
132709
132771
|
function writeValues(ctx, parentId, attr, items, by2, replace, now10 = attioTime(ctx.clock.nowMs())) {
|
|
132710
132772
|
const current = currentValues(ctx, parentId, attr.id);
|
|
@@ -132780,7 +132842,7 @@ function findObject(ctx, key3) {
|
|
|
132780
132842
|
function findList(ctx, key3) {
|
|
132781
132843
|
return one2(ctx, "SELECT * FROM attio_lists WHERE api_slug = ? OR id = ?", key3, key3) ?? notFound9(`List with slug/ID "${key3}" not found.`);
|
|
132782
132844
|
}
|
|
132783
|
-
var attributesOf = (ctx, parentId) =>
|
|
132845
|
+
var attributesOf = (ctx, parentId) => all5(ctx, "SELECT * FROM attio_attributes WHERE parent_id = ? ORDER BY position", parentId);
|
|
132784
132846
|
var listParent = (list14) => `list:${list14.id}`;
|
|
132785
132847
|
function objectShape(ctx, o) {
|
|
132786
132848
|
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 };
|
|
@@ -132810,7 +132872,7 @@ function memberShape(ctx, m) {
|
|
|
132810
132872
|
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 };
|
|
132811
132873
|
}
|
|
132812
132874
|
function valuesOf(ctx, parentId, attributes2, computed) {
|
|
132813
|
-
const rows7 =
|
|
132875
|
+
const rows7 = all5(ctx, "SELECT * FROM attio_values WHERE parent_id = ? AND active_until IS NULL ORDER BY id", parentId);
|
|
132814
132876
|
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))]));
|
|
132815
132877
|
}
|
|
132816
132878
|
function recordShape(ctx, r) {
|
|
@@ -132828,7 +132890,7 @@ function recordShape(ctx, r) {
|
|
|
132828
132890
|
if (o.api_slug === "companies" && a.api_slug === "team") {
|
|
132829
132891
|
const people3 = one2(ctx, "SELECT * FROM attio_objects WHERE api_slug = 'people'");
|
|
132830
132892
|
const company = one2(ctx, "SELECT * FROM attio_attributes WHERE parent_id = ? AND api_slug = 'company'", people3.id);
|
|
132831
|
-
return
|
|
132893
|
+
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" }));
|
|
132832
132894
|
}
|
|
132833
132895
|
return void 0;
|
|
132834
132896
|
})
|
|
@@ -132896,7 +132958,7 @@ function writeAll(r, parentId, attributes2, values2, mode, objectSlug) {
|
|
|
132896
132958
|
const items = list14.map((v) => parseValue(r.ctx, attr, v));
|
|
132897
132959
|
if (attr.is_unique) for (const item2 of items) {
|
|
132898
132960
|
const key4 = primary(r.ctx, attr, item2);
|
|
132899
|
-
const clash =
|
|
132961
|
+
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);
|
|
132900
132962
|
if (clash) invalid15(`A record with the value "${String(key4)}" for the unique attribute "${attr.api_slug}" already exists.`, "uniqueness_conflict");
|
|
132901
132963
|
}
|
|
132902
132964
|
writeValues(r.ctx, parentId, attr, items, tokenActor(r), mode !== "append" || !attr.is_multiselect);
|
|
@@ -132948,7 +133010,7 @@ function query8(r, rows7, attributes2) {
|
|
|
132948
133010
|
const { limit, offset: offset16 } = limitOffset(r.body);
|
|
132949
133011
|
return kept.slice(offset16, offset16 + limit);
|
|
132950
133012
|
}
|
|
132951
|
-
var records = (r, object13) =>
|
|
133013
|
+
var records = (r, object13) => all5(r.ctx, "SELECT * FROM attio_records WHERE object_id = ? ORDER BY created_at, rowid", object13.id);
|
|
132952
133014
|
function memberRef(r, value4) {
|
|
132953
133015
|
const key3 = value4?.referenced_actor_id ?? value4?.workspace_member_email_address;
|
|
132954
133016
|
const m = typeof key3 === "string" ? one2(r.ctx, "SELECT * FROM attio_members WHERE id = ? OR lower(email) = lower(?)", key3, key3) : void 0;
|
|
@@ -132990,7 +133052,7 @@ var attioRoutes = [
|
|
|
132990
133052
|
workspace_logo_url: null
|
|
132991
133053
|
};
|
|
132992
133054
|
} },
|
|
132993
|
-
{ method: "GET", path: "/v2/objects", coverage: { status: "supported" }, run: (r) => ({ data:
|
|
133055
|
+
{ 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)) }) },
|
|
132994
133056
|
{ method: "GET", path: "/v2/objects/:object", coverage: { status: "supported" }, run: (r) => ({ data: objectShape(r.ctx, findObject(r.ctx, r.param("object"))) }) },
|
|
132995
133057
|
{ method: "GET", path: "/v2/:target/:identifier/attributes", query: { known: ["limit", "offset", "show_archived"], supported: ["limit", "offset", "show_archived"] }, coverage: { status: "supported" }, run: (r) => {
|
|
132996
133058
|
const target4 = r.param("target");
|
|
@@ -133031,7 +133093,7 @@ var attioRoutes = [
|
|
|
133031
133093
|
const given = (r.data.values ?? {})[attr.api_slug] ?? (r.data.values ?? {})[attr.id];
|
|
133032
133094
|
if (given === void 0) invalid15(`The values must include the matching attribute "${attr.api_slug}".`, "missing_value");
|
|
133033
133095
|
const wanted = (Array.isArray(given) ? given : [given]).map((v) => primary(r.ctx, attr, parseValue(r.ctx, attr, v)));
|
|
133034
|
-
const owners = new Set(
|
|
133096
|
+
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));
|
|
133035
133097
|
if (owners.size > 1) invalid15("More than one record matches the given value.", "multiple_match_results");
|
|
133036
133098
|
if (!owners.size) return { data: recordShape(r.ctx, createRecord3(r, object13, r.data.values)) };
|
|
133037
133099
|
const id12 = [...owners][0];
|
|
@@ -133064,7 +133126,7 @@ var attioRoutes = [
|
|
|
133064
133126
|
},
|
|
133065
133127
|
{ method: "DELETE", path: RECORD_PATH, coverage: { status: "supported" }, run: (r) => {
|
|
133066
133128
|
const rec = findRecord(r, findObject(r.ctx, r.param("object")));
|
|
133067
|
-
for (const e of
|
|
133129
|
+
for (const e of all5(r.ctx, "SELECT * FROM attio_entries WHERE record_id = ?", rec.id)) {
|
|
133068
133130
|
run2(r.ctx, "DELETE FROM attio_values WHERE parent_id = ?", e.id);
|
|
133069
133131
|
run2(r.ctx, "DELETE FROM attio_entries WHERE id = ?", e.id);
|
|
133070
133132
|
}
|
|
@@ -133081,7 +133143,7 @@ var attioRoutes = [
|
|
|
133081
133143
|
const object13 = findObject(r.ctx, r.param("object")), rec = findRecord(r, object13);
|
|
133082
133144
|
const attr = attributesOf(r.ctx, object13.id).find((a) => a.api_slug === r.param("attribute") || a.id === r.param("attribute")) ?? notFound9(`Attribute with slug/ID "${r.param("attribute")}" not found.`);
|
|
133083
133145
|
const historic = r.query.get("show_historic") === "true";
|
|
133084
|
-
const rows7 =
|
|
133146
|
+
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);
|
|
133085
133147
|
const { limit, offset: offset16 } = limitOffset({ limit: r.query.get("limit") ?? void 0, offset: r.query.get("offset") ?? void 0 });
|
|
133086
133148
|
return { data: rows7.slice(offset16, offset16 + limit).map((v) => valueObject(r.ctx, attr, v)) };
|
|
133087
133149
|
}
|
|
@@ -133093,11 +133155,11 @@ var attioRoutes = [
|
|
|
133093
133155
|
coverage: { status: "supported" },
|
|
133094
133156
|
run: (r) => {
|
|
133095
133157
|
const rec = findRecord(r, findObject(r.ctx, r.param("object")));
|
|
133096
|
-
return { data:
|
|
133158
|
+
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 })) };
|
|
133097
133159
|
}
|
|
133098
133160
|
},
|
|
133099
133161
|
/* ------------------------------------ lists ------------------------------------ */
|
|
133100
|
-
{ method: "GET", path: "/v2/lists", coverage: { status: "supported" }, run: (r) => ({ data:
|
|
133162
|
+
{ 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)) }) },
|
|
133101
133163
|
{ method: "GET", path: "/v2/lists/:list", coverage: { status: "supported" }, run: (r) => ({ data: listShape(r.ctx, findList(r.ctx, r.param("list"))) }) },
|
|
133102
133164
|
{
|
|
133103
133165
|
method: "POST",
|
|
@@ -133105,7 +133167,7 @@ var attioRoutes = [
|
|
|
133105
133167
|
coverage: { status: "partial", notes: "filters and sorts on the list's own attributes" },
|
|
133106
133168
|
run: (r) => {
|
|
133107
133169
|
const list14 = findList(r.ctx, r.param("list"));
|
|
133108
|
-
return { data: query8(r,
|
|
133170
|
+
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)) };
|
|
133109
133171
|
}
|
|
133110
133172
|
},
|
|
133111
133173
|
{
|
|
@@ -133144,7 +133206,7 @@ var attioRoutes = [
|
|
|
133144
133206
|
return {};
|
|
133145
133207
|
} },
|
|
133146
133208
|
/* ------------------------------- members, notes, tasks ----------------------------- */
|
|
133147
|
-
{ method: "GET", path: "/v2/workspace_members", coverage: { status: "supported" }, run: (r) => ({ data:
|
|
133209
|
+
{ 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)) }) },
|
|
133148
133210
|
{
|
|
133149
133211
|
method: "GET",
|
|
133150
133212
|
path: "/v2/workspace_members/:id",
|
|
@@ -133159,7 +133221,7 @@ var attioRoutes = [
|
|
|
133159
133221
|
run: (r) => {
|
|
133160
133222
|
const object13 = r.query.get("parent_object"), record8 = r.query.get("parent_record_id");
|
|
133161
133223
|
const objectSlug = object13 ? findObject(r.ctx, object13).api_slug : void 0;
|
|
133162
|
-
const notes6 =
|
|
133224
|
+
const notes6 = all5(r.ctx, "SELECT * FROM attio_notes ORDER BY created_at, rowid").filter((n) => (!objectSlug || n.parent_object === objectSlug) && (!record8 || n.parent_record_id === record8));
|
|
133163
133225
|
const { limit, offset: offset16 } = limitOffset({ limit: r.query.get("limit") ?? void 0, offset: r.query.get("offset") ?? void 0 }, 10);
|
|
133164
133226
|
return { data: notes6.slice(offset16, offset16 + limit).map((n) => noteShape2(r.ctx, n)) };
|
|
133165
133227
|
}
|
|
@@ -133211,7 +133273,7 @@ var attioRoutes = [
|
|
|
133211
133273
|
const linkedObject = q.get("linked_object") ? findObject(r.ctx, q.get("linked_object")).id : void 0;
|
|
133212
133274
|
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;
|
|
133213
133275
|
const done = q.get("is_completed");
|
|
133214
|
-
let tasks =
|
|
133276
|
+
let tasks = all5(r.ctx, "SELECT * FROM attio_tasks ORDER BY created_at, rowid").filter((t) => {
|
|
133215
133277
|
const linked = JSON.parse(t.linked);
|
|
133216
133278
|
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);
|
|
133217
133279
|
});
|
|
@@ -133387,7 +133449,7 @@ function seed23(ctx) {
|
|
|
133387
133449
|
run2(ctx, "INSERT INTO attio_records (id, object_id, created_at, created_by) VALUES (?, ?, ?, ?)", id12, objectIds.get(slug10), at2(r.created), JSON.stringify(actor(members4.get(data5.agent))));
|
|
133388
133450
|
}
|
|
133389
133451
|
const write4 = (parentId, parent2, values2, when11, by2) => {
|
|
133390
|
-
const attributes2 =
|
|
133452
|
+
const attributes2 = all5(ctx, "SELECT * FROM attio_attributes WHERE parent_id = ? ORDER BY position", parent2);
|
|
133391
133453
|
for (const [slug10, raw3] of Object.entries(values2)) {
|
|
133392
133454
|
const attr = attributes2.find((a) => a.api_slug === slug10);
|
|
133393
133455
|
if (!attr) throw new AnchaError("SCENE_INVALID", `seed.attio: no attribute "${slug10}"`);
|
|
@@ -133445,9 +133507,9 @@ function credentials22(ctx) {
|
|
|
133445
133507
|
function dumpState22(ctx) {
|
|
133446
133508
|
const flat2 = (parentId, attributes2) => Object.fromEntries(attributes2.map((a) => [
|
|
133447
133509
|
a.api_slug,
|
|
133448
|
-
|
|
133510
|
+
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)))
|
|
133449
133511
|
]).filter(([, v]) => v.length));
|
|
133450
|
-
const objects =
|
|
133512
|
+
const objects = all5(ctx, "SELECT * FROM attio_objects ORDER BY rowid");
|
|
133451
133513
|
const name5 = (recordId) => {
|
|
133452
133514
|
const r = one2(ctx, "SELECT * FROM attio_records WHERE id = ?", recordId);
|
|
133453
133515
|
if (!r) return recordId;
|
|
@@ -133459,18 +133521,18 @@ function dumpState22(ctx) {
|
|
|
133459
133521
|
return m ? `${m.first_name} ${m.last_name}`.trim() : id12;
|
|
133460
133522
|
};
|
|
133461
133523
|
return {
|
|
133462
|
-
members:
|
|
133524
|
+
members: all5(ctx, "SELECT id, first_name, last_name, email, access_level FROM attio_members ORDER BY rowid"),
|
|
133463
133525
|
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 })) })),
|
|
133464
|
-
records:
|
|
133465
|
-
lists:
|
|
133526
|
+
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)) })),
|
|
133527
|
+
lists: all5(ctx, "SELECT * FROM attio_lists ORDER BY rowid").map((l) => ({
|
|
133466
133528
|
id: l.id,
|
|
133467
133529
|
api_slug: l.api_slug,
|
|
133468
133530
|
name: l.name,
|
|
133469
133531
|
parent_object: l.parent_object,
|
|
133470
|
-
entries:
|
|
133532
|
+
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))) }))
|
|
133471
133533
|
})),
|
|
133472
|
-
notes:
|
|
133473
|
-
tasks:
|
|
133534
|
+
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) })),
|
|
133535
|
+
tasks: all5(ctx, "SELECT * FROM attio_tasks ORDER BY created_at, rowid").map((t) => taskShape(ctx, t))
|
|
133474
133536
|
};
|
|
133475
133537
|
}
|
|
133476
133538
|
|
|
@@ -133753,7 +133815,7 @@ function listing(ctx, cursor4) {
|
|
|
133753
133815
|
}
|
|
133754
133816
|
function page9(ctx, cursor4) {
|
|
133755
133817
|
if (cursor4.o >= 0) {
|
|
133756
|
-
const
|
|
133818
|
+
const all8 = listing(ctx, cursor4), slice = all8.slice(cursor4.o, cursor4.o + cursor4.l), more = cursor4.o + cursor4.l < all8.length;
|
|
133757
133819
|
return json15({ entries: slice, cursor: encodeCursor3(more ? { ...cursor4, o: cursor4.o + cursor4.l } : { ...cursor4, o: -1 }), has_more: more });
|
|
133758
133820
|
}
|
|
133759
133821
|
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("/")));
|
|
@@ -135790,15 +135852,15 @@ function search6(call2, query10) {
|
|
|
135790
135852
|
odata(call2, ["$top", "$skiptoken", "$orderby"]);
|
|
135791
135853
|
const tokens2 = query10.toLowerCase().split(/\s+/).filter(Boolean);
|
|
135792
135854
|
if (!tokens2.length) throw invalid17("The search query is empty.");
|
|
135793
|
-
const scope2 = target3(call2),
|
|
135855
|
+
const scope2 = target3(call2), all8 = [];
|
|
135794
135856
|
const visit3 = (node5) => {
|
|
135795
135857
|
for (const child2 of childrenOf2(call2.ctx, node5.id)) {
|
|
135796
|
-
|
|
135858
|
+
all8.push(child2);
|
|
135797
135859
|
if (child2.kind === "folder") visit3(child2);
|
|
135798
135860
|
}
|
|
135799
135861
|
};
|
|
135800
135862
|
visit3(scope2);
|
|
135801
|
-
const matches7 =
|
|
135863
|
+
const matches7 = all8.filter((item2) => {
|
|
135802
135864
|
const text21 = `${item2.name}
|
|
135803
135865
|
${textOf2(item2) ?? ""}`.toLowerCase();
|
|
135804
135866
|
return tokens2.every((token2) => text21.includes(token2));
|
|
@@ -136059,7 +136121,7 @@ function save8(ctx, kind, doc, parent2 = null) {
|
|
|
136059
136121
|
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));
|
|
136060
136122
|
return doc;
|
|
136061
136123
|
}
|
|
136062
|
-
function
|
|
136124
|
+
function all6(ctx, kind) {
|
|
136063
136125
|
return ctx.store.db.prepare("SELECT json FROM shopify_objects WHERE kind = ? ORDER BY num").all(kind).map((r) => JSON.parse(r.json));
|
|
136064
136126
|
}
|
|
136065
136127
|
function childrenOf3(ctx, parent2, kind) {
|
|
@@ -136133,7 +136195,7 @@ function level2(ctx, item2, location) {
|
|
|
136133
136195
|
}
|
|
136134
136196
|
function committed(ctx, item2, location) {
|
|
136135
136197
|
let n = 0;
|
|
136136
|
-
for (const fo of
|
|
136198
|
+
for (const fo of all6(ctx, "FulfillmentOrder")) {
|
|
136137
136199
|
if (fo.location !== location) continue;
|
|
136138
136200
|
const order4 = load3(ctx, fo.order);
|
|
136139
136201
|
if (order4.cancelled_ms !== null) continue;
|
|
@@ -136407,7 +136469,7 @@ function connection2(items, args, key3, shape3) {
|
|
|
136407
136469
|
var byNum = (d) => ({ id: numOf(d.gid) });
|
|
136408
136470
|
var pathOf2 = (path4) => path4 ? [...pathOf2(path4.prev), path4.key] : [];
|
|
136409
136471
|
var firstOf = (items, n) => typeof n === "number" ? items.slice(0, Math.max(0, n)) : items;
|
|
136410
|
-
var currencyOf = (ctx) =>
|
|
136472
|
+
var currencyOf = (ctx) => all6(ctx, "Shop")[0].currency;
|
|
136411
136473
|
var bag = (ctx, c) => {
|
|
136412
136474
|
const m = { amount: decimal2(c), currencyCode: currencyOf(ctx) };
|
|
136413
136475
|
return { shopMoney: m, presentmentMoney: m };
|
|
@@ -136507,7 +136569,7 @@ function distance(ms) {
|
|
|
136507
136569
|
return years === 1 ? "about 1 year" : `about ${years} years`;
|
|
136508
136570
|
}
|
|
136509
136571
|
function shopShape(req) {
|
|
136510
|
-
const s =
|
|
136572
|
+
const s = all6(req.ctx, "Shop")[0], host = `${s.domain}.myshopify.com`;
|
|
136511
136573
|
return {
|
|
136512
136574
|
__typename: "Shop",
|
|
136513
136575
|
id: s.gid,
|
|
@@ -136534,7 +136596,7 @@ function shopShape(req) {
|
|
|
136534
136596
|
};
|
|
136535
136597
|
}
|
|
136536
136598
|
function locationShape(req, l) {
|
|
136537
|
-
const primary3 =
|
|
136599
|
+
const primary3 = all6(req.ctx, "Location")[0].gid === l.gid, a = l.address, country = a.country_code ?? "US";
|
|
136538
136600
|
return {
|
|
136539
136601
|
__typename: "Location",
|
|
136540
136602
|
id: l.gid,
|
|
@@ -136614,7 +136676,7 @@ function itemShape(req, item2) {
|
|
|
136614
136676
|
};
|
|
136615
136677
|
}
|
|
136616
136678
|
function variantStock(req, v) {
|
|
136617
|
-
const levels3 = levelsOf(req.ctx, { item: v.item }), locations = new Map(
|
|
136679
|
+
const levels3 = levelsOf(req.ctx, { item: v.item }), locations = new Map(all6(req.ctx, "Location").map((l) => [l.gid, l]));
|
|
136618
136680
|
const active2 = levels3.filter((l) => locations.get(l.location)?.active);
|
|
136619
136681
|
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) };
|
|
136620
136682
|
}
|
|
@@ -136669,7 +136731,7 @@ function productShape(req, p2) {
|
|
|
136669
136731
|
const variants = () => childrenOf3(req.ctx, p2.gid, "ProductVariant");
|
|
136670
136732
|
const tracked2 = () => variants().filter((v) => load3(req.ctx, v.item).tracked);
|
|
136671
136733
|
const prices = () => variants().map((v) => v.price_cents);
|
|
136672
|
-
const host = `${
|
|
136734
|
+
const host = `${all6(req.ctx, "Shop")[0].domain}.myshopify.com`;
|
|
136673
136735
|
return {
|
|
136674
136736
|
__typename: "Product",
|
|
136675
136737
|
id: p2.gid,
|
|
@@ -136713,7 +136775,7 @@ function productShape(req, p2) {
|
|
|
136713
136775
|
};
|
|
136714
136776
|
}
|
|
136715
136777
|
function customerShape(req, c) {
|
|
136716
|
-
const orders = () =>
|
|
136778
|
+
const orders = () => all6(req.ctx, "Order").filter((o) => o.customer === c.gid);
|
|
136717
136779
|
const name5 = [c.first_name, c.last_name].filter(Boolean).join(" ");
|
|
136718
136780
|
return {
|
|
136719
136781
|
__typename: "Customer",
|
|
@@ -136751,7 +136813,7 @@ function orderShape(req, o) {
|
|
|
136751
136813
|
let cached2;
|
|
136752
136814
|
const facts = () => cached2 ??= orderFacts(req.ctx, o);
|
|
136753
136815
|
const sm = (pick4) => () => bag(req.ctx, pick4(facts()));
|
|
136754
|
-
const shop =
|
|
136816
|
+
const shop = all6(req.ctx, "Shop")[0];
|
|
136755
136817
|
const fos = () => childrenOf3(req.ctx, o.gid, "FulfillmentOrder");
|
|
136756
136818
|
return {
|
|
136757
136819
|
__typename: "Order",
|
|
@@ -137122,7 +137184,7 @@ function ordersConnection(req, orders, args, path4) {
|
|
|
137122
137184
|
function productsConnection(req, args, path4) {
|
|
137123
137185
|
const variants = (p2) => childrenOf3(req.ctx, p2.gid, "ProductVariant");
|
|
137124
137186
|
const inventory = (p2) => variants(p2).filter((v) => load3(req.ctx, v.item).tracked).reduce((n, v) => n + variantStock(req, v).available, 0);
|
|
137125
|
-
let found = filter3(req, "products",
|
|
137187
|
+
let found = filter3(req, "products", all6(req.ctx, "Product"), args, path4, {
|
|
137126
137188
|
default: { text: (p2) => [p2.title, p2.vendor, p2.product_type, p2.handle, ...p2.tags, ...variants(p2).map((v) => v.sku)] },
|
|
137127
137189
|
id: { number: num2 },
|
|
137128
137190
|
title: { text: (p2) => [p2.title], words: true },
|
|
@@ -137160,7 +137222,7 @@ function productsConnection(req, args, path4) {
|
|
|
137160
137222
|
}
|
|
137161
137223
|
function variantsConnection(req, args, path4) {
|
|
137162
137224
|
const product2 = (v) => load3(req.ctx, v.product);
|
|
137163
|
-
const found = filter3(req, "productVariants",
|
|
137225
|
+
const found = filter3(req, "productVariants", all6(req.ctx, "ProductVariant"), args, path4, {
|
|
137164
137226
|
default: { text: (v) => [product2(v).title, variantTitle(v), v.sku, v.barcode] },
|
|
137165
137227
|
id: { number: num2 },
|
|
137166
137228
|
sku: { text: (v) => [v.sku] },
|
|
@@ -137189,9 +137251,9 @@ function variantsConnection(req, args, path4) {
|
|
|
137189
137251
|
return connection2(items, args, (v) => ({ id: num2(v), value: key3(v) }), (v) => variantShape(req, v));
|
|
137190
137252
|
}
|
|
137191
137253
|
function customersConnection(req, args, path4) {
|
|
137192
|
-
const orders = (c) =>
|
|
137254
|
+
const orders = (c) => all6(req.ctx, "Order").filter((o) => o.customer === c.gid);
|
|
137193
137255
|
const fullName = (c) => [c.first_name, c.last_name].filter(Boolean).join(" ");
|
|
137194
|
-
const found = filter3(req, "customers",
|
|
137256
|
+
const found = filter3(req, "customers", all6(req.ctx, "Customer"), args, path4, {
|
|
137195
137257
|
default: { text: (c) => [fullName(c), c.email, c.phone, c.address?.company ?? null, ...c.tags] },
|
|
137196
137258
|
id: { number: num2 },
|
|
137197
137259
|
email: { text: (c) => [c.email] },
|
|
@@ -137218,7 +137280,7 @@ function customersConnection(req, args, path4) {
|
|
|
137218
137280
|
return connection2(items, args, (c) => ({ id: num2(c), value: key3(c) }), (c) => customerShape(req, c));
|
|
137219
137281
|
}
|
|
137220
137282
|
function locationsConnection(req, args, path4) {
|
|
137221
|
-
const found = filter3(req, "locations",
|
|
137283
|
+
const found = filter3(req, "locations", all6(req.ctx, "Location").filter((l) => args.includeInactive || l.active), args, path4, {
|
|
137222
137284
|
default: { text: (l) => [l.name, l.address.city, l.address.address1, l.address.zip] },
|
|
137223
137285
|
id: { number: num2 },
|
|
137224
137286
|
location_id: { number: num2 },
|
|
@@ -137268,7 +137330,7 @@ function queryRoot(req) {
|
|
|
137268
137330
|
};
|
|
137269
137331
|
return {
|
|
137270
137332
|
shop: () => shopShape(req),
|
|
137271
|
-
orders: (args, _r, info) => ordersConnection(req,
|
|
137333
|
+
orders: (args, _r, info) => ordersConnection(req, all6(ctx, "Order"), args, pathOf2(info.path)),
|
|
137272
137334
|
order: one7("Order", orderShape),
|
|
137273
137335
|
products: (args, _r, info) => productsConnection(req, args, pathOf2(info.path)),
|
|
137274
137336
|
product: one7("Product", productShape),
|
|
@@ -137279,7 +137341,7 @@ function queryRoot(req) {
|
|
|
137279
137341
|
locations: (args, _r, info) => locationsConnection(req, args, pathOf2(info.path)),
|
|
137280
137342
|
// Without an id, Shopify returns the primary location.
|
|
137281
137343
|
location: ({ id: id12 }) => {
|
|
137282
|
-
const d = id12 === void 0 || id12 === null ?
|
|
137344
|
+
const d = id12 === void 0 || id12 === null ? all6(ctx, "Location")[0] : loadKind(ctx, "Location", checkId(id12));
|
|
137283
137345
|
return d ? locationShape(req, d) : null;
|
|
137284
137346
|
},
|
|
137285
137347
|
inventoryItem: one7("InventoryItem", itemShape),
|
|
@@ -137470,7 +137532,7 @@ function mutationRoot(req) {
|
|
|
137470
137532
|
}
|
|
137471
137533
|
if (data5.handle !== void 0 && data5.handle !== null) {
|
|
137472
137534
|
const handle30 = slug8(data5.handle);
|
|
137473
|
-
if (
|
|
137535
|
+
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.` });
|
|
137474
137536
|
else next2.handle = handle30;
|
|
137475
137537
|
}
|
|
137476
137538
|
if (errors2.length) return { product: null, userErrors: errors2 };
|
|
@@ -137527,7 +137589,7 @@ function refundCreate(req, input2) {
|
|
|
137527
137589
|
const found = orderOrError(req, input2.orderId, ["orderId"]);
|
|
137528
137590
|
if ("errors" in found) return fail6(found.errors);
|
|
137529
137591
|
const o = found.order, facts = orderFacts(ctx, o);
|
|
137530
|
-
if (input2.currency && input2.currency !==
|
|
137592
|
+
if (input2.currency && input2.currency !== all6(ctx, "Shop")[0].currency) gap4("refunds in a presentment currency");
|
|
137531
137593
|
const errors2 = [];
|
|
137532
137594
|
const items = [];
|
|
137533
137595
|
(input2.refundLineItems ?? []).forEach((i, n) => {
|
|
@@ -137733,7 +137795,7 @@ function customerWrite(req, input2, create2) {
|
|
|
137733
137795
|
updated_ms: at2
|
|
137734
137796
|
};
|
|
137735
137797
|
const errors2 = [];
|
|
137736
|
-
const others =
|
|
137798
|
+
const others = all6(ctx, "Customer").filter((x) => x.gid !== c.gid);
|
|
137737
137799
|
if (input2.email !== void 0) {
|
|
137738
137800
|
if (input2.email !== null && !EMAIL17.test(input2.email)) errors2.push({ field: ["email"], message: "Email is invalid" });
|
|
137739
137801
|
else if (input2.email !== null && others.some((x) => x.email?.toLowerCase() === input2.email.toLowerCase())) errors2.push({ field: ["email"], message: "Email has already been taken" });
|
|
@@ -138145,13 +138207,13 @@ function credentials26(ctx) {
|
|
|
138145
138207
|
var when8 = (ms) => ms === null ? null : iso8(ms);
|
|
138146
138208
|
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;
|
|
138147
138209
|
function dumpState26(ctx) {
|
|
138148
|
-
const shop =
|
|
138210
|
+
const shop = all6(ctx, "Shop")[0], locations = all6(ctx, "Location");
|
|
138149
138211
|
const locationName = (id12) => id12 ? locations.find((l) => l.gid === id12)?.name ?? null : null;
|
|
138150
138212
|
const sku = (lineId) => load3(ctx, lineId)?.sku ?? null;
|
|
138151
138213
|
return {
|
|
138152
138214
|
shop: { name: shop.name, domain: `${shop.domain}.myshopify.com`, email: shop.email, currency: shop.currency },
|
|
138153
138215
|
locations: locations.map((l) => ({ id: l.gid, name: l.name, city: l.address.city, active: l.active, fulfills_online_orders: l.fulfills_online_orders })),
|
|
138154
|
-
products:
|
|
138216
|
+
products: all6(ctx, "Product").map((p2) => ({
|
|
138155
138217
|
id: p2.gid,
|
|
138156
138218
|
title: p2.title,
|
|
138157
138219
|
handle: p2.handle,
|
|
@@ -138178,7 +138240,7 @@ function dumpState26(ctx) {
|
|
|
138178
138240
|
};
|
|
138179
138241
|
})
|
|
138180
138242
|
})),
|
|
138181
|
-
customers:
|
|
138243
|
+
customers: all6(ctx, "Customer").map((c) => ({
|
|
138182
138244
|
id: c.gid,
|
|
138183
138245
|
name: [c.first_name, c.last_name].filter(Boolean).join(" ") || null,
|
|
138184
138246
|
email: c.email,
|
|
@@ -138187,9 +138249,9 @@ function dumpState26(ctx) {
|
|
|
138187
138249
|
note: c.note,
|
|
138188
138250
|
state: c.state,
|
|
138189
138251
|
accepts_marketing: c.accepts_marketing,
|
|
138190
|
-
orders:
|
|
138252
|
+
orders: all6(ctx, "Order").filter((o) => o.customer === c.gid).length
|
|
138191
138253
|
})),
|
|
138192
|
-
orders:
|
|
138254
|
+
orders: all6(ctx, "Order").map((o) => {
|
|
138193
138255
|
const f = orderFacts(ctx, o), customer3 = o.customer ? load3(ctx, o.customer) : void 0;
|
|
138194
138256
|
return {
|
|
138195
138257
|
id: o.gid,
|
|
@@ -138245,7 +138307,7 @@ function dumpState26(ctx) {
|
|
|
138245
138307
|
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 }))
|
|
138246
138308
|
};
|
|
138247
138309
|
}),
|
|
138248
|
-
inventory_adjustments:
|
|
138310
|
+
inventory_adjustments: all6(ctx, "InventoryAdjustmentGroup").map((g) => ({
|
|
138249
138311
|
id: g.gid,
|
|
138250
138312
|
reason: g.reason,
|
|
138251
138313
|
reference: g.reference,
|
|
@@ -140420,14 +140482,14 @@ var billingRoutes = [
|
|
|
140420
140482
|
path: "/v1/catalogs/products",
|
|
140421
140483
|
coverage: { status: "supported" },
|
|
140422
140484
|
run: (r) => {
|
|
140423
|
-
const { size, n, total } = page11(r, 20),
|
|
140424
|
-
return { products:
|
|
140485
|
+
const { size, n, total } = page11(r, 20), all8 = allOf2(r.ctx, "product");
|
|
140486
|
+
return { products: all8.slice((n - 1) * size, n * size).map((p2) => ({
|
|
140425
140487
|
id: p2.id,
|
|
140426
140488
|
name: p2.name,
|
|
140427
140489
|
description: p2.description ?? void 0,
|
|
140428
140490
|
create_time: iso10(p2.create_ms),
|
|
140429
140491
|
links: [link4(`${r.base}/v1/catalogs/products/${p2.id}`, "self")]
|
|
140430
|
-
})), ...total && { total_items:
|
|
140492
|
+
})), ...total && { total_items: all8.length, total_pages: Math.ceil(all8.length / size) }, links: [] };
|
|
140431
140493
|
}
|
|
140432
140494
|
},
|
|
140433
140495
|
{
|
|
@@ -140454,10 +140516,10 @@ var billingRoutes = [
|
|
|
140454
140516
|
coverage: { status: "supported" },
|
|
140455
140517
|
run: (r) => {
|
|
140456
140518
|
const { size, n, total } = page11(r, 20), ids2 = r.query.get("plan_ids")?.split(",").filter(Boolean), product2 = r.query.get("product_id");
|
|
140457
|
-
const
|
|
140519
|
+
const all8 = allOf2(r.ctx, "plan").filter((p2) => (!product2 || p2.product_id === product2) && (!ids2 || ids2.includes(p2.id)));
|
|
140458
140520
|
return {
|
|
140459
|
-
plans:
|
|
140460
|
-
...total && { total_items:
|
|
140521
|
+
plans: all8.slice((n - 1) * size, n * size).map((p2) => planShape(r, p2, false)),
|
|
140522
|
+
...total && { total_items: all8.length, total_pages: Math.ceil(all8.length / size) },
|
|
140461
140523
|
links: [link4(`${r.base}/v1/billing/plans?page_size=${size}&page=${n}`, "self")]
|
|
140462
140524
|
};
|
|
140463
140525
|
}
|
|
@@ -140527,8 +140589,8 @@ var billingRoutes = [
|
|
|
140527
140589
|
run: (r) => {
|
|
140528
140590
|
const { size, n } = page11(r, 20), plans = r.query.get("plan_ids")?.split(",").filter(Boolean), statuses = r.query.get("statuses")?.split(",").filter(Boolean);
|
|
140529
140591
|
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`);
|
|
140530
|
-
const
|
|
140531
|
-
return { subscriptions:
|
|
140592
|
+
const all8 = allOf2(r.ctx, "subscription").filter((s) => (!plans || plans.includes(s.plan_id)) && (!statuses || statuses.includes(s.status)));
|
|
140593
|
+
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: [] };
|
|
140532
140594
|
}
|
|
140533
140595
|
},
|
|
140534
140596
|
{ method: "GET", path: "/v1/billing/subscriptions/:id", coverage: { status: "supported" }, run: (r) => subscriptionShape(r, subscriptionOr404(r)) },
|
|
@@ -144282,7 +144344,7 @@ function load5(ctx, kind, id12) {
|
|
|
144282
144344
|
const row = ctx.store.db.prepare("SELECT json FROM intercom_objects WHERE kind = ? AND id = ?").get(kind, id12);
|
|
144283
144345
|
return row && JSON.parse(row.json);
|
|
144284
144346
|
}
|
|
144285
|
-
function
|
|
144347
|
+
function all7(ctx, kind) {
|
|
144286
144348
|
return ctx.store.db.prepare("SELECT json FROM intercom_objects WHERE kind = ? ORDER BY seq").all(kind).map((r) => JSON.parse(r.json));
|
|
144287
144349
|
}
|
|
144288
144350
|
function save10(ctx, kind, doc) {
|
|
@@ -144406,7 +144468,7 @@ function byPage(items, r, dflt, key3, body6) {
|
|
|
144406
144468
|
}
|
|
144407
144469
|
var numeric2 = (id12) => id12 === null ? null : Number(id12);
|
|
144408
144470
|
function adminShape(r, a) {
|
|
144409
|
-
const teams =
|
|
144471
|
+
const teams = all7(r.ctx, "team").filter((t) => t.admin_ids.includes(a.id)).map((t) => Number(t.id));
|
|
144410
144472
|
return {
|
|
144411
144473
|
type: "admin",
|
|
144412
144474
|
id: a.id,
|
|
@@ -144436,7 +144498,7 @@ var tagRef = (r, t) => {
|
|
|
144436
144498
|
};
|
|
144437
144499
|
function contactShape2(r, c) {
|
|
144438
144500
|
const list14 = (type, ids2, path4) => ({ type: "list", data: ids2.map((id12) => ({ type, id: id12, url: `/${type === "company" ? "companies" : `${type}s`}/${id12}` })), url: `/contacts/${c.id}/${path4}`, total_count: ids2.length, has_more: false });
|
|
144439
|
-
const notes6 =
|
|
144501
|
+
const notes6 = all7(r.ctx, "note").filter((n) => n.contact_id === c.id).map((n) => n.id);
|
|
144440
144502
|
return {
|
|
144441
144503
|
type: "contact",
|
|
144442
144504
|
id: c.id,
|
|
@@ -144495,7 +144557,7 @@ function contactShape2(r, c) {
|
|
|
144495
144557
|
};
|
|
144496
144558
|
}
|
|
144497
144559
|
function companyShape(r, co) {
|
|
144498
|
-
const users4 =
|
|
144560
|
+
const users4 = all7(r.ctx, "contact").filter((c) => c.companies.includes(co.id)).length;
|
|
144499
144561
|
return {
|
|
144500
144562
|
type: "company",
|
|
144501
144563
|
id: co.id,
|
|
@@ -144763,9 +144825,9 @@ function applyContact(r, c, b) {
|
|
|
144763
144825
|
}
|
|
144764
144826
|
}
|
|
144765
144827
|
function conflictOnEmail(r, c) {
|
|
144766
|
-
const dup = c.email &&
|
|
144828
|
+
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());
|
|
144767
144829
|
if (dup) fail3(409, "conflict", `A contact matching those details already exists with id=${dup.id}`);
|
|
144768
|
-
const ext = c.external_id &&
|
|
144830
|
+
const ext = c.external_id && all7(r.ctx, "contact").find((x) => x.id !== c.id && x.external_id === c.external_id);
|
|
144769
144831
|
if (ext) fail3(409, "conflict", `A contact matching those details already exists with id=${ext.id}`);
|
|
144770
144832
|
}
|
|
144771
144833
|
function tagOn(r, doc, tagId, adminId) {
|
|
@@ -144787,7 +144849,7 @@ var intercomRoutes = [
|
|
|
144787
144849
|
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" } };
|
|
144788
144850
|
}
|
|
144789
144851
|
},
|
|
144790
|
-
{ method: "GET", path: "/admins", coverage: { status: "supported" }, run: (r) => ({ type: "admin.list", admins:
|
|
144852
|
+
{ method: "GET", path: "/admins", coverage: { status: "supported" }, run: (r) => ({ type: "admin.list", admins: all7(r.ctx, "admin").map((a) => adminShape(r, a)) }) },
|
|
144791
144853
|
{ method: "GET", path: "/admins/:id", coverage: { status: "supported" }, run: (r) => adminShape(r, load5(r.ctx, "admin", r.param("id")) ?? notFound15("Admin")) },
|
|
144792
144854
|
{
|
|
144793
144855
|
method: "PUT",
|
|
@@ -144799,7 +144861,7 @@ var intercomRoutes = [
|
|
|
144799
144861
|
return adminShape(r, save10(r.ctx, "admin", { ...a, away: r.body.away_mode_enabled, reassign: !!r.body.away_mode_reassign }));
|
|
144800
144862
|
}
|
|
144801
144863
|
},
|
|
144802
|
-
{ method: "GET", path: "/teams", coverage: { status: "supported" }, run: (r) => ({ type: "team.list", teams:
|
|
144864
|
+
{ 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: {} })) }) },
|
|
144803
144865
|
{
|
|
144804
144866
|
method: "GET",
|
|
144805
144867
|
path: "/teams/:id",
|
|
@@ -144810,7 +144872,7 @@ var intercomRoutes = [
|
|
|
144810
144872
|
}
|
|
144811
144873
|
},
|
|
144812
144874
|
{ method: "GET", path: "/contacts", coverage: { status: "supported" }, run: (r) => {
|
|
144813
|
-
const l = listOf("list", "data",
|
|
144875
|
+
const l = listOf("list", "data", all7(r.ctx, "contact").filter((c) => !c.archived), r);
|
|
144814
144876
|
return { ...l, data: l.data.map((c) => contactShape2(r, c)) };
|
|
144815
144877
|
} },
|
|
144816
144878
|
{
|
|
@@ -144819,7 +144881,7 @@ var intercomRoutes = [
|
|
|
144819
144881
|
coverage: { status: "partial", notes: "common contact fields, tags, companies and custom attributes; segments and device fields are gaps" },
|
|
144820
144882
|
run: (r) => {
|
|
144821
144883
|
const ok = matcher(contactFields(r), CONTACT_DOCUMENTED, r.body.query, "contacts");
|
|
144822
|
-
const l = listOf("list", "data",
|
|
144884
|
+
const l = listOf("list", "data", all7(r.ctx, "contact").filter((c) => !c.archived && ok(c)), r, 50, r.body);
|
|
144823
144885
|
return { ...l, data: l.data.map((c) => contactShape2(r, c)) };
|
|
144824
144886
|
}
|
|
144825
144887
|
},
|
|
@@ -144860,7 +144922,7 @@ var intercomRoutes = [
|
|
|
144860
144922
|
method: "GET",
|
|
144861
144923
|
path: "/contacts/find_by_external_id/:id",
|
|
144862
144924
|
coverage: { status: "supported" },
|
|
144863
|
-
run: (r) => contactShape2(r,
|
|
144925
|
+
run: (r) => contactShape2(r, all7(r.ctx, "contact").find((c) => c.external_id === r.param("id")) ?? notFound15("User"))
|
|
144864
144926
|
},
|
|
144865
144927
|
{ method: "GET", path: "/contacts/:id", coverage: { status: "supported" }, run: (r) => contactShape2(r, contactOr404(r)) },
|
|
144866
144928
|
{
|
|
@@ -144937,7 +144999,7 @@ var intercomRoutes = [
|
|
|
144937
144999
|
coverage: { status: "supported" },
|
|
144938
145000
|
run: (r) => {
|
|
144939
145001
|
const c = contactOr404(r);
|
|
144940
|
-
const l = byPage(
|
|
145002
|
+
const l = byPage(all7(r.ctx, "note").filter((n) => n.contact_id === c.id).reverse(), r, 50, "data");
|
|
144941
145003
|
return { ...l, data: l.data.map((n) => noteShape3(r, n)) };
|
|
144942
145004
|
}
|
|
144943
145005
|
},
|
|
@@ -144990,13 +145052,13 @@ var intercomRoutes = [
|
|
|
144990
145052
|
run: (r) => {
|
|
144991
145053
|
const id12 = r.query.get("company_id"), name5 = r.query.get("name");
|
|
144992
145054
|
for (const key3 of ["segment_id", "tag_id"]) if (r.query.get(key3)) unsupported26(`listing companies by ${key3}`);
|
|
144993
|
-
if (id12 || name5) return companyShape(r,
|
|
144994
|
-
const l = byPage(
|
|
145055
|
+
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"));
|
|
145056
|
+
const l = byPage(all7(r.ctx, "company"), r, 15, "data");
|
|
144995
145057
|
return { ...l, data: l.data.map((co) => companyShape(r, co)) };
|
|
144996
145058
|
}
|
|
144997
145059
|
},
|
|
144998
145060
|
{ method: "POST", path: "/companies/list", coverage: { status: "supported" }, run: (r) => {
|
|
144999
|
-
const l = byPage(
|
|
145061
|
+
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 });
|
|
145000
145062
|
return { ...l, data: l.data.map((co) => companyShape(r, co)) };
|
|
145001
145063
|
} },
|
|
145002
145064
|
{
|
|
@@ -145006,7 +145068,7 @@ var intercomRoutes = [
|
|
|
145006
145068
|
run: (r) => {
|
|
145007
145069
|
const b = r.body;
|
|
145008
145070
|
if (!b.company_id && !b.name) fail3(400, "parameter_invalid", "company_id or name is required");
|
|
145009
|
-
const at2 = now8(r), existing2 =
|
|
145071
|
+
const at2 = now8(r), existing2 = all7(r.ctx, "company").find((co2) => co2.company_id === (b.company_id ?? b.name));
|
|
145010
145072
|
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 };
|
|
145011
145073
|
for (const key3 of ["name", "size", "website", "industry", "monthly_spend"]) if (b[key3] !== void 0) co[key3] = b[key3];
|
|
145012
145074
|
if (b.plan !== void 0) {
|
|
@@ -145038,7 +145100,7 @@ var intercomRoutes = [
|
|
|
145038
145100
|
coverage: { status: "supported" },
|
|
145039
145101
|
run: (r) => {
|
|
145040
145102
|
const co = load5(r.ctx, "company", r.param("id")) ?? notFound15("Company");
|
|
145041
|
-
const l = listOf("list", "data",
|
|
145103
|
+
const l = listOf("list", "data", all7(r.ctx, "contact").filter((c) => c.companies.includes(co.id)), r);
|
|
145042
145104
|
return { ...l, data: l.data.map((c) => contactShape2(r, c)) };
|
|
145043
145105
|
}
|
|
145044
145106
|
},
|
|
@@ -145047,7 +145109,7 @@ var intercomRoutes = [
|
|
|
145047
145109
|
path: "/conversations",
|
|
145048
145110
|
coverage: { status: "supported", notes: "newest activity first" },
|
|
145049
145111
|
run: (r) => {
|
|
145050
|
-
const l = listOf("conversation.list", "conversations",
|
|
145112
|
+
const l = listOf("conversation.list", "conversations", all7(r.ctx, "conversation").sort((a, b) => b.updated_at - a.updated_at), r, 20);
|
|
145051
145113
|
return { ...l, conversations: l.conversations.map((c) => conversationShape(r, c, false)) };
|
|
145052
145114
|
}
|
|
145053
145115
|
},
|
|
@@ -145057,7 +145119,7 @@ var intercomRoutes = [
|
|
|
145057
145119
|
coverage: { status: "partial", notes: "state, assignment, tags, contacts, source and timestamps; ratings, AI agent and statistics fields are gaps" },
|
|
145058
145120
|
run: (r) => {
|
|
145059
145121
|
const ok = matcher(conversationFields(), CONVERSATION_DOCUMENTED, r.body.query, "conversations");
|
|
145060
|
-
const l = listOf("conversation.list", "conversations",
|
|
145122
|
+
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);
|
|
145061
145123
|
return { ...l, conversations: l.conversations.map((c) => conversationShape(r, c, false)) };
|
|
145062
145124
|
}
|
|
145063
145125
|
},
|
|
@@ -145128,7 +145190,7 @@ var intercomRoutes = [
|
|
|
145128
145190
|
}
|
|
145129
145191
|
} else if (b.type === "user") {
|
|
145130
145192
|
if (b.message_type !== "comment") fail3(400, "parameter_invalid", "a contact can only reply with a comment");
|
|
145131
|
-
const contact = load5(r.ctx, "contact", String(b.intercom_user_id ?? "")) ??
|
|
145193
|
+
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());
|
|
145132
145194
|
if (!contact || contact.id !== conv.contact_id) fail3(404, "not_found", "User Not Found");
|
|
145133
145195
|
addPart(r, conv, { type: "comment", body: html(b.body), author: { type: "user", id: contact.id } });
|
|
145134
145196
|
if (conv.state !== "open") {
|
|
@@ -145209,7 +145271,7 @@ var intercomRoutes = [
|
|
|
145209
145271
|
return { type: "tag", id: tag3.id, name: tag3.name };
|
|
145210
145272
|
}
|
|
145211
145273
|
},
|
|
145212
|
-
{ method: "GET", path: "/tags", coverage: { status: "supported" }, run: (r) => ({ type: "list", data:
|
|
145274
|
+
{ 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 })) }) },
|
|
145213
145275
|
{
|
|
145214
145276
|
method: "POST",
|
|
145215
145277
|
path: "/tags",
|
|
@@ -145223,7 +145285,7 @@ var intercomRoutes = [
|
|
|
145223
145285
|
save10(r.ctx, "tag", { ...t2, name: b.name });
|
|
145224
145286
|
return { type: "tag", id: t2.id, name: b.name };
|
|
145225
145287
|
}
|
|
145226
|
-
const existing2 =
|
|
145288
|
+
const existing2 = all7(r.ctx, "tag").find((t2) => t2.name.toLowerCase() === b.name.toLowerCase());
|
|
145227
145289
|
const t = existing2 ?? save10(r.ctx, "tag", { id: nextId5(r.ctx, "tag"), name: b.name });
|
|
145228
145290
|
return { type: "tag", id: t.id, name: t.name };
|
|
145229
145291
|
}
|
|
@@ -145238,14 +145300,14 @@ var intercomRoutes = [
|
|
|
145238
145300
|
coverage: { status: "supported" },
|
|
145239
145301
|
run: (r) => {
|
|
145240
145302
|
const t = load5(r.ctx, "tag", r.param("id")) ?? notFound15("Tag");
|
|
145241
|
-
const used = [...
|
|
145303
|
+
const used = [...all7(r.ctx, "contact"), ...all7(r.ctx, "conversation")].some((x) => x.tags.some((y) => y.id === t.id));
|
|
145242
145304
|
if (used) fail3(400, "tag_has_dependent_objects", "Unable to delete Tag with dependent objects.");
|
|
145243
145305
|
remove3(r.ctx, "tag", t.id);
|
|
145244
145306
|
return void 0;
|
|
145245
145307
|
}
|
|
145246
145308
|
},
|
|
145247
145309
|
{ method: "GET", path: "/articles", coverage: { status: "supported" }, run: (r) => {
|
|
145248
|
-
const l = byPage(
|
|
145310
|
+
const l = byPage(all7(r.ctx, "article"), r, 50, "data");
|
|
145249
145311
|
return { ...l, data: l.data.map((a) => articleShape(r, a)) };
|
|
145250
145312
|
} },
|
|
145251
145313
|
{
|
|
@@ -145255,7 +145317,7 @@ var intercomRoutes = [
|
|
|
145255
145317
|
run: (r) => {
|
|
145256
145318
|
const words4 = (r.query.get("phrase") ?? "").toLowerCase().split(/\W+/).filter(Boolean), state2 = r.query.get("state");
|
|
145257
145319
|
if (r.query.get("help_center_id")) unsupported26("searching one help center of several");
|
|
145258
|
-
const found =
|
|
145320
|
+
const found = all7(r.ctx, "article").filter((a) => (!state2 || state2 === "all" || a.state === state2) && words4.every((w) => `${a.title} ${a.description} ${plain2(a.body)}`.toLowerCase().includes(w)));
|
|
145259
145321
|
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 } };
|
|
145260
145322
|
}
|
|
145261
145323
|
},
|
|
@@ -145431,11 +145493,11 @@ function dumpState31(ctx) {
|
|
|
145431
145493
|
const contact = (id12) => load5(ctx, "contact", id12);
|
|
145432
145494
|
return {
|
|
145433
145495
|
workspace: workspace(ctx).name,
|
|
145434
|
-
admins:
|
|
145435
|
-
teams:
|
|
145436
|
-
tags:
|
|
145437
|
-
companies:
|
|
145438
|
-
contacts:
|
|
145496
|
+
admins: all7(ctx, "admin").map((a) => ({ id: a.id, name: a.name, email: a.email, away: a.away })),
|
|
145497
|
+
teams: all7(ctx, "team").map((t) => ({ id: t.id, name: t.name, members: t.admin_ids.map(admin) })),
|
|
145498
|
+
tags: all7(ctx, "tag").map((t) => t.name),
|
|
145499
|
+
companies: all7(ctx, "company").map((co) => ({ id: co.id, name: co.name, company_id: co.company_id, plan: co.plan })),
|
|
145500
|
+
contacts: all7(ctx, "contact").map((c) => ({
|
|
145439
145501
|
id: c.id,
|
|
145440
145502
|
name: c.name,
|
|
145441
145503
|
email: c.email,
|
|
@@ -145447,9 +145509,9 @@ function dumpState31(ctx) {
|
|
|
145447
145509
|
companies: c.companies.map((id12) => load5(ctx, "company", id12)?.name ?? null),
|
|
145448
145510
|
tags: c.tags.map(tag3),
|
|
145449
145511
|
custom_attributes: c.custom_attributes,
|
|
145450
|
-
notes:
|
|
145512
|
+
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) }))
|
|
145451
145513
|
})),
|
|
145452
|
-
conversations:
|
|
145514
|
+
conversations: all7(ctx, "conversation").map((v) => ({
|
|
145453
145515
|
id: v.id,
|
|
145454
145516
|
contact: contact(v.contact_id)?.name ?? null,
|
|
145455
145517
|
contact_email: contact(v.contact_id)?.email ?? null,
|
|
@@ -145473,7 +145535,7 @@ function dumpState31(ctx) {
|
|
|
145473
145535
|
...p2.assigned_to && { assigned_to: p2.assigned_to.type === "admin" ? admin(p2.assigned_to.id) : load5(ctx, "team", p2.assigned_to.id)?.name ?? null }
|
|
145474
145536
|
}))
|
|
145475
145537
|
})),
|
|
145476
|
-
articles:
|
|
145538
|
+
articles: all7(ctx, "article").map((a) => ({ id: a.id, title: a.title, state: a.state }))
|
|
145477
145539
|
};
|
|
145478
145540
|
}
|
|
145479
145541
|
|
|
@@ -145973,9 +146035,9 @@ function macroJson(ctx, macro2) {
|
|
|
145973
146035
|
};
|
|
145974
146036
|
}
|
|
145975
146037
|
function viewJson(ctx, view3) {
|
|
145976
|
-
const
|
|
146038
|
+
const all8 = [{ field: "status", operator: "less_than", value: "solved" }], statuses = JSON.parse(view3.statuses);
|
|
145977
146039
|
const conditions = [
|
|
145978
|
-
...statuses.join() === "new,open,pending,hold" ?
|
|
146040
|
+
...statuses.join() === "new,open,pending,hold" ? all8 : statuses.map((status4) => ({ field: "status", operator: "is", value: status4 })),
|
|
145979
146041
|
...view3.assignee === "none" ? [{ field: "assignee_id", operator: "is", value: null }] : view3.assignee === "me" ? [{ field: "assignee_id", operator: "is", value: "current_user" }] : [],
|
|
145980
146042
|
...view3.group_id === null ? [] : [{ field: "group_id", operator: "is", value: String(view3.group_id) }]
|
|
145981
146043
|
];
|
|
@@ -149211,9 +149273,9 @@ function permissionsIn(ctx, userId, channel3) {
|
|
|
149211
149273
|
if (ctx.store.meta.get("discord.owner") === userId) return ALL;
|
|
149212
149274
|
const member4 = getMember(ctx, userId);
|
|
149213
149275
|
if (!member4) return 0n;
|
|
149214
|
-
const
|
|
149276
|
+
const all8 = roles(ctx), mine = new Set(JSON.parse(member4.roles)), everyone = guildId(ctx);
|
|
149215
149277
|
let permissions = 0n;
|
|
149216
|
-
for (const role3 of
|
|
149278
|
+
for (const role3 of all8) if (role3.id === everyone || mine.has(role3.id)) permissions |= BigInt(role3.permissions);
|
|
149217
149279
|
if (permissions & BITS.ADMINISTRATOR) return ALL;
|
|
149218
149280
|
const target4 = channel3?.type === PUBLIC_THREAD ? getChannel(ctx, channel3.parent_id) : channel3;
|
|
149219
149281
|
if (!target4 || target4.type === DM) return permissions;
|
|
@@ -149544,8 +149606,8 @@ function members3(call2) {
|
|
|
149544
149606
|
guildFor(call2);
|
|
149545
149607
|
const params9 = call2.url.searchParams, limit = Number(params9.get("limit") ?? 1), after = params9.get("after") ?? "0";
|
|
149546
149608
|
if (!Number.isInteger(limit) || limit < 1 || limit > 1e3) throw invalidForm("limit", "NUMBER_TYPE_MAX", "int value should be between 1 and 1000");
|
|
149547
|
-
const
|
|
149548
|
-
return json27(
|
|
149609
|
+
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);
|
|
149610
|
+
return json27(all8.filter((member4) => BigInt(member4.user_id) > BigInt(after)).slice(0, limit).map((member4) => memberJson(call2.ctx, member4)));
|
|
149549
149611
|
}
|
|
149550
149612
|
function member2(call2) {
|
|
149551
149613
|
guildFor(call2);
|
|
@@ -149569,15 +149631,15 @@ function listMessages2(call2) {
|
|
|
149569
149631
|
const anchors = ["before", "after", "around"].filter((name5) => params9.has(name5));
|
|
149570
149632
|
if (anchors.length > 1) throw invalidForm(anchors[1], "BASE_TYPE_BAD_ARGUMENT", "Only one of before, after or around may be given");
|
|
149571
149633
|
if (!canRead(call2, channel3)) return json27([]);
|
|
149572
|
-
const
|
|
149634
|
+
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);
|
|
149573
149635
|
const at2 = (name5) => BigInt(params9.get(name5));
|
|
149574
149636
|
let page15;
|
|
149575
|
-
if (params9.has("before")) page15 =
|
|
149576
|
-
else if (params9.has("after")) page15 =
|
|
149637
|
+
if (params9.has("before")) page15 = all8.filter((row) => BigInt(row.id) < at2("before")).slice(0, limit);
|
|
149638
|
+
else if (params9.has("after")) page15 = all8.filter((row) => BigInt(row.id) > at2("after")).slice(-limit);
|
|
149577
149639
|
else if (params9.has("around")) {
|
|
149578
|
-
const older =
|
|
149640
|
+
const older = all8.filter((row) => BigInt(row.id) <= at2("around")).slice(0, Math.ceil(limit / 2)), newer = all8.filter((row) => BigInt(row.id) > at2("around")).slice(-Math.floor(limit / 2));
|
|
149579
149641
|
page15 = [...newer, ...older];
|
|
149580
|
-
} else page15 =
|
|
149642
|
+
} else page15 = all8.slice(0, limit);
|
|
149581
149643
|
return json27(page15.map((row) => messageJson2(call2.ctx, row)));
|
|
149582
149644
|
}
|
|
149583
149645
|
function showMessage(call2) {
|
|
@@ -151973,8 +152035,8 @@ var AirtableBase = class _AirtableBase {
|
|
|
151973
152035
|
}
|
|
151974
152036
|
/** A table by id or name, as the URL gives it. */
|
|
151975
152037
|
table(ref20) {
|
|
151976
|
-
const
|
|
151977
|
-
const found =
|
|
152038
|
+
const all8 = this.tables();
|
|
152039
|
+
const found = all8.find((item2) => item2.id === ref20) ?? all8.find((item2) => item2.name === ref20) ?? all8.find((item2) => item2.name.toLowerCase() === ref20.toLowerCase());
|
|
151978
152040
|
if (!found) throw modelNotFound();
|
|
151979
152041
|
return found;
|
|
151980
152042
|
}
|
|
@@ -151988,8 +152050,8 @@ var AirtableBase = class _AirtableBase {
|
|
|
151988
152050
|
}
|
|
151989
152051
|
/** A field by id or exact name; `loose` also matches names regardless of case (as formulas do). */
|
|
151990
152052
|
field(tableId, ref20, loose = false) {
|
|
151991
|
-
const
|
|
151992
|
-
return
|
|
152053
|
+
const all8 = this.fields(tableId);
|
|
152054
|
+
return all8.find((item2) => item2.id === ref20) ?? all8.find((item2) => item2.name === ref20) ?? (loose ? all8.find((item2) => item2.name.toLowerCase() === ref20.toLowerCase()) : void 0);
|
|
151993
152055
|
}
|
|
151994
152056
|
fieldById(id12) {
|
|
151995
152057
|
for (const table3 of this.tables()) {
|
|
@@ -152374,13 +152436,13 @@ var AirtableBase = class _AirtableBase {
|
|
|
152374
152436
|
}
|
|
152375
152437
|
}
|
|
152376
152438
|
#person(value4, typecast, bad3) {
|
|
152377
|
-
const
|
|
152439
|
+
const all8 = this.users(), lower4 = (text21) => String(text21).trim().toLowerCase();
|
|
152378
152440
|
let found;
|
|
152379
152441
|
if (value4 && typeof value4 === "object" && !Array.isArray(value4)) {
|
|
152380
152442
|
const ref20 = value4;
|
|
152381
|
-
found = ref20.id !== void 0 ?
|
|
152443
|
+
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;
|
|
152382
152444
|
} else if (typeof value4 === "string") {
|
|
152383
|
-
found =
|
|
152445
|
+
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);
|
|
152384
152446
|
}
|
|
152385
152447
|
if (!found) throw bad3();
|
|
152386
152448
|
return found.id;
|
|
@@ -152721,11 +152783,11 @@ function commentsOf3(call2, writing) {
|
|
|
152721
152783
|
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);
|
|
152722
152784
|
function listComments3(call2) {
|
|
152723
152785
|
const { model, record: record8 } = commentsOf3(call2, false), pageSize2 = whole(call2.url.searchParams.get("pageSize") ?? void 0, "pageSize", 1, 100) ?? 100;
|
|
152724
|
-
const
|
|
152725
|
-
const from = offset16 === null ? 0 :
|
|
152786
|
+
const all8 = liveComments(call2.ctx, record8.id), offset16 = call2.url.searchParams.get("offset");
|
|
152787
|
+
const from = offset16 === null ? 0 : all8.findIndex((row) => row.id === offset16);
|
|
152726
152788
|
if (from < 0) throw new AirtableError(422, "LIST_RECORDS_ITERATOR_NOT_AVAILABLE");
|
|
152727
|
-
const page15 =
|
|
152728
|
-
return json29({ comments: page15.map((row) => commentJson2(model, row)), offset:
|
|
152789
|
+
const page15 = all8.slice(from, from + pageSize2);
|
|
152790
|
+
return json29({ comments: page15.map((row) => commentJson2(model, row)), offset: all8[from + pageSize2]?.id ?? null });
|
|
152729
152791
|
}
|
|
152730
152792
|
function commentText(body6) {
|
|
152731
152793
|
if (typeof body6.text !== "string" || !body6.text.trim()) throw invalidRequest("Invalid request: text is required");
|