@miniaxolotl/grove-server 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap.js +92 -1
- package/dist/bootstrap.js.map +4 -4
- package/dist/migrate.js +92 -1
- package/dist/migrate.js.map +4 -4
- package/dist/server.js +170 -24
- package/dist/server.js.map +4 -4
- package/dist/telemetry-build.json +1 -1
- package/dist/worker.js +115 -5
- package/dist/worker.js.map +3 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"enabled":true,"revision":"
|
|
1
|
+
{"enabled":true,"revision":"cb9b1a44ac8afee6d1c1aafd0f8a34e30c1e8d52","version":"1.10.0","component":"api"}
|
package/dist/worker.js
CHANGED
|
@@ -13,7 +13,7 @@ var __export = (target, all) => {
|
|
|
13
13
|
var define_GROVE_TELEMETRY_default;
|
|
14
14
|
var init_define_GROVE_TELEMETRY = __esm({
|
|
15
15
|
"<define:__GROVE_TELEMETRY__>"() {
|
|
16
|
-
define_GROVE_TELEMETRY_default = { enabled: true, revision: "
|
|
16
|
+
define_GROVE_TELEMETRY_default = { enabled: true, revision: "cb9b1a44ac8afee6d1c1aafd0f8a34e30c1e8d52", version: "1.10.0", component: "api", key: "phc_AqVrjhk7W2X2pFjyngY7uWxcSSRREfJhgr8mBmKbXYEh", cliDsn: "https://3f6d0711b5890dea4ce8e6ccf2a1a7fd@o4511632209346560.ingest.us.sentry.io/4512290791620608", apiDsn: "https://4524e8910e318110277babdfe818999b@o4511632209346560.ingest.us.sentry.io/4512290791489536" };
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -2645,6 +2645,97 @@ var publicSharing = {
|
|
|
2645
2645
|
}
|
|
2646
2646
|
};
|
|
2647
2647
|
|
|
2648
|
+
// lib/database/src/share-expiration-migration.ts
|
|
2649
|
+
init_define_GROVE_TELEMETRY();
|
|
2650
|
+
var shareExpiration = {
|
|
2651
|
+
name: "20261022_012_share_expiration",
|
|
2652
|
+
async up(db) {
|
|
2653
|
+
await db.raw(`
|
|
2654
|
+
ALTER TABLE public_shares
|
|
2655
|
+
ADD COLUMN duration text CHECK (duration IN ('1h','4h','1d','1w','2w','1mo')),
|
|
2656
|
+
ADD COLUMN expires_at timestamptz,
|
|
2657
|
+
ADD CONSTRAINT public_shares_expiration CHECK ((duration IS NULL) = (expires_at IS NULL));
|
|
2658
|
+
|
|
2659
|
+
CREATE OR REPLACE FUNCTION grove_public_share(
|
|
2660
|
+
secret_digest text, requested_kind text, requested_id uuid,
|
|
2661
|
+
after_id uuid, cursor_share uuid, cursor_version integer, page_size integer
|
|
2662
|
+
) RETURNS jsonb LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, public, pg_temp AS $$
|
|
2663
|
+
DECLARE link public_shares; owner_id uuid; permitted uuid[]; selected uuid;
|
|
2664
|
+
root_name text; notebook_name text; note memories; result jsonb; page jsonb; children jsonb;
|
|
2665
|
+
BEGIN
|
|
2666
|
+
IF page_size IS NULL OR page_size < 1 OR page_size > 100
|
|
2667
|
+
OR requested_kind IS NULL OR requested_kind NOT IN ('root', 'note', 'notebook') THEN RETURN NULL; END IF;
|
|
2668
|
+
SELECT account_id INTO owner_id FROM public_shares WHERE token_digest = secret_digest AND revoked_at IS NULL;
|
|
2669
|
+
IF owner_id IS NULL THEN RETURN NULL; END IF;
|
|
2670
|
+
-- Keep account-first locking. Wall-clock expiry must be checked AFTER a
|
|
2671
|
+
-- blocked reader acquires its locks, not against transaction-start now().
|
|
2672
|
+
PERFORM 1 FROM accounts WHERE id = owner_id AND status = 'active' FOR SHARE;
|
|
2673
|
+
IF NOT FOUND THEN RETURN NULL; END IF;
|
|
2674
|
+
SELECT * INTO link FROM public_shares WHERE account_id = owner_id
|
|
2675
|
+
AND token_digest = secret_digest AND revoked_at IS NULL FOR SHARE;
|
|
2676
|
+
IF NOT FOUND THEN RETURN NULL; END IF;
|
|
2677
|
+
IF link.expires_at IS NOT NULL AND link.expires_at <= clock_timestamp() THEN RETURN NULL; END IF;
|
|
2678
|
+
IF NOT grove_share_admit(link.id::text) THEN RETURN jsonb_build_object('limited', true); END IF;
|
|
2679
|
+
IF cursor_share IS NOT NULL AND (cursor_share <> link.id OR cursor_version IS DISTINCT FROM link.version)
|
|
2680
|
+
THEN RETURN jsonb_build_object('stale', true); END IF;
|
|
2681
|
+
IF link.project_id IS NOT NULL THEN
|
|
2682
|
+
WITH RECURSIVE scope(id) AS (
|
|
2683
|
+
SELECT id FROM projects WHERE account_id = owner_id AND id = link.project_id
|
|
2684
|
+
UNION
|
|
2685
|
+
SELECT p.id FROM projects p JOIN scope s ON p.parent_id = s.id
|
|
2686
|
+
WHERE p.account_id = owner_id AND link.include_descendants
|
|
2687
|
+
) SELECT array_agg(id) INTO permitted FROM scope;
|
|
2688
|
+
SELECT name INTO root_name FROM projects WHERE account_id = owner_id AND id = link.project_id;
|
|
2689
|
+
IF root_name IS NULL THEN RETURN NULL; END IF;
|
|
2690
|
+
ELSE
|
|
2691
|
+
SELECT * INTO note FROM memories WHERE account_id = owner_id AND id = link.memory_id
|
|
2692
|
+
AND status = 'active' AND (expires_at IS NULL OR expires_at > now());
|
|
2693
|
+
IF NOT FOUND THEN RETURN NULL; END IF;
|
|
2694
|
+
root_name := left(regexp_replace(split_part(trim(note.content), E'\\n', 1), '^#{1,6}\\s+', ''), 110);
|
|
2695
|
+
END IF;
|
|
2696
|
+
result := jsonb_build_object('shareId', link.id, 'shareVersion', link.version,
|
|
2697
|
+
'kind', CASE WHEN link.memory_id IS NULL THEN 'notebook' ELSE 'note' END,
|
|
2698
|
+
'root', jsonb_build_object('id', coalesce(link.project_id, link.memory_id), 'name', root_name),
|
|
2699
|
+
'notebook', NULL, 'note', NULL, 'notebooks', '[]'::jsonb, 'notes', '[]'::jsonb);
|
|
2700
|
+
IF requested_kind = 'note' OR (requested_kind = 'root' AND link.memory_id IS NOT NULL) THEN
|
|
2701
|
+
selected := CASE WHEN requested_kind = 'root' THEN link.memory_id ELSE requested_id END;
|
|
2702
|
+
SELECT * INTO note FROM memories WHERE account_id = owner_id AND id = selected
|
|
2703
|
+
AND (id = link.memory_id OR project_id = ANY(permitted))
|
|
2704
|
+
AND status = 'active' AND (expires_at IS NULL OR expires_at > now());
|
|
2705
|
+
IF NOT FOUND THEN RETURN NULL; END IF;
|
|
2706
|
+
SELECT coalesce(jsonb_agg(m.id), '[]'::jsonb) INTO page FROM memories m
|
|
2707
|
+
WHERE m.account_id = owner_id AND (m.id = link.memory_id OR m.project_id = ANY(permitted))
|
|
2708
|
+
AND m.status = 'active' AND (m.expires_at IS NULL OR m.expires_at > now())
|
|
2709
|
+
AND m.id IN (SELECT matches[1]::uuid FROM regexp_matches(note.content,
|
|
2710
|
+
'/app/memories/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})', 'g') AS matches);
|
|
2711
|
+
RETURN result || jsonb_build_object('note', jsonb_build_object('id', note.id,
|
|
2712
|
+
'title', left(regexp_replace(split_part(trim(note.content), E'\\n', 1), '^#{1,6}\\s+', ''), 110),
|
|
2713
|
+
'content', note.content, 'updatedAt', note.updated_at, 'linkedNoteIds', page));
|
|
2714
|
+
END IF;
|
|
2715
|
+
selected := CASE WHEN requested_kind = 'root' THEN link.project_id ELSE requested_id END;
|
|
2716
|
+
IF selected IS NULL OR NOT (selected = ANY(permitted)) OR permitted IS NULL THEN RETURN NULL; END IF;
|
|
2717
|
+
SELECT name INTO notebook_name FROM projects WHERE account_id = owner_id AND id = selected;
|
|
2718
|
+
SELECT coalesce(jsonb_agg(jsonb_build_object('id', p.id, 'name', p.name) ORDER BY p.name, p.id), '[]'::jsonb)
|
|
2719
|
+
INTO children FROM projects p WHERE p.account_id = owner_id AND p.parent_id = selected AND p.id = ANY(permitted);
|
|
2720
|
+
SELECT coalesce(jsonb_agg(jsonb_build_object('id', m.id,
|
|
2721
|
+
'title', left(regexp_replace(split_part(trim(m.content), E'\\n', 1), '^#{1,6}\\s+', ''), 110),
|
|
2722
|
+
'updatedAt', m.updated_at) ORDER BY m.id), '[]'::jsonb) INTO page FROM (
|
|
2723
|
+
SELECT id, content, updated_at FROM memories WHERE account_id = owner_id AND project_id = selected
|
|
2724
|
+
AND status = 'active' AND (expires_at IS NULL OR expires_at > now())
|
|
2725
|
+
AND (after_id IS NULL OR id > after_id) ORDER BY id LIMIT page_size + 1
|
|
2726
|
+
) m;
|
|
2727
|
+
RETURN result || jsonb_build_object('notebook', jsonb_build_object('id', selected, 'name', notebook_name),
|
|
2728
|
+
'notebooks', children, 'notes', page);
|
|
2729
|
+
END $$;
|
|
2730
|
+
REVOKE ALL ON FUNCTION grove_public_share(text,text,uuid,uuid,uuid,integer,integer) FROM PUBLIC;
|
|
2731
|
+
GRANT EXECUTE ON FUNCTION grove_public_share(text,text,uuid,uuid,uuid,integer,integer) TO grove_runtime;
|
|
2732
|
+
`);
|
|
2733
|
+
},
|
|
2734
|
+
async down() {
|
|
2735
|
+
throw new Error("Use a forward migration");
|
|
2736
|
+
}
|
|
2737
|
+
};
|
|
2738
|
+
|
|
2648
2739
|
// lib/database/src/migrations.ts
|
|
2649
2740
|
var migrations = [
|
|
2650
2741
|
{
|
|
@@ -2858,7 +2949,8 @@ var migrations = [
|
|
|
2858
2949
|
nestedNotebooks,
|
|
2859
2950
|
conversations,
|
|
2860
2951
|
relationships,
|
|
2861
|
-
publicSharing
|
|
2952
|
+
publicSharing,
|
|
2953
|
+
shareExpiration
|
|
2862
2954
|
];
|
|
2863
2955
|
var migrationSource = {
|
|
2864
2956
|
getMigrations: async () => migrations,
|
|
@@ -5739,7 +5831,20 @@ init_define_GROVE_TELEMETRY();
|
|
|
5739
5831
|
// lib/shared/src/sharing.ts
|
|
5740
5832
|
init_define_GROVE_TELEMETRY();
|
|
5741
5833
|
import { z as z7 } from "zod";
|
|
5834
|
+
|
|
5835
|
+
// lib/shared/src/share-durations.ts
|
|
5836
|
+
init_define_GROVE_TELEMETRY();
|
|
5837
|
+
|
|
5838
|
+
// lib/shared/src/sharing.ts
|
|
5742
5839
|
var shareTokenSchema = z7.string().regex(/^gsh_[A-Za-z0-9_-]{43}$/);
|
|
5840
|
+
var shareDurationSchema = z7.enum([
|
|
5841
|
+
"1h",
|
|
5842
|
+
"4h",
|
|
5843
|
+
"1d",
|
|
5844
|
+
"1w",
|
|
5845
|
+
"2w",
|
|
5846
|
+
"1mo"
|
|
5847
|
+
]);
|
|
5743
5848
|
var shareMutationSchema = z7.object({
|
|
5744
5849
|
operationId: operationSchema,
|
|
5745
5850
|
expectedVersion: z7.number().int().positive()
|
|
@@ -5747,11 +5852,16 @@ var shareMutationSchema = z7.object({
|
|
|
5747
5852
|
var shareEnableSchema = shareMutationSchema.extend({
|
|
5748
5853
|
expectedVersion: z7.number().int().min(0),
|
|
5749
5854
|
expectedTargetVersion: z7.number().int().positive(),
|
|
5750
|
-
includeDescendants: z7.boolean().default(false)
|
|
5855
|
+
includeDescendants: z7.boolean().default(false),
|
|
5856
|
+
duration: shareDurationSchema.nullable().optional()
|
|
5751
5857
|
});
|
|
5752
5858
|
var shareScopeSchema = shareMutationSchema.extend({
|
|
5753
|
-
includeDescendants: z7.boolean()
|
|
5754
|
-
|
|
5859
|
+
includeDescendants: z7.boolean().optional(),
|
|
5860
|
+
duration: shareDurationSchema.nullable().optional()
|
|
5861
|
+
}).refine(
|
|
5862
|
+
(value) => value.includeDescendants !== void 0 || value.duration !== void 0,
|
|
5863
|
+
"Choose a sharing setting to change"
|
|
5864
|
+
);
|
|
5755
5865
|
var publicShareQuerySchema = z7.object({
|
|
5756
5866
|
cursor: z7.string().max(2048).optional(),
|
|
5757
5867
|
limit: z7.coerce.number().int().min(1).max(100).default(30)
|