@openpeepshq/core 0.28.0 → 0.29.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "4a5587e2-755d-42e0-a8e0-4940132dbb19",
3
- "prevId": "cbe40fa6-6a27-404d-82fd-48551e54d6d2",
3
+ "prevId": "2638df33-a41a-4afe-ad09-e0c4d76d959d",
4
4
  "version": "7",
5
5
  "dialect": "postgresql",
6
6
  "tables": {
@@ -4712,6 +4712,132 @@
4712
4712
  "policies": {},
4713
4713
  "checkConstraints": {},
4714
4714
  "isRLSEnabled": false
4715
+ },
4716
+ "public.audit_logs": {
4717
+ "name": "audit_logs",
4718
+ "schema": "",
4719
+ "columns": {
4720
+ "id": {
4721
+ "name": "id",
4722
+ "type": "uuid",
4723
+ "primaryKey": true,
4724
+ "notNull": true
4725
+ },
4726
+ "actor_profile_id": {
4727
+ "name": "actor_profile_id",
4728
+ "type": "text",
4729
+ "primaryKey": false,
4730
+ "notNull": true
4731
+ },
4732
+ "actor_account_id": {
4733
+ "name": "actor_account_id",
4734
+ "type": "text",
4735
+ "primaryKey": false,
4736
+ "notNull": false
4737
+ },
4738
+ "actor_ip": {
4739
+ "name": "actor_ip",
4740
+ "type": "text",
4741
+ "primaryKey": false,
4742
+ "notNull": false
4743
+ },
4744
+ "action": {
4745
+ "name": "action",
4746
+ "type": "text",
4747
+ "primaryKey": false,
4748
+ "notNull": true
4749
+ },
4750
+ "target_type": {
4751
+ "name": "target_type",
4752
+ "type": "text",
4753
+ "primaryKey": false,
4754
+ "notNull": true
4755
+ },
4756
+ "target_id": {
4757
+ "name": "target_id",
4758
+ "type": "text",
4759
+ "primaryKey": false,
4760
+ "notNull": false
4761
+ },
4762
+ "target_label": {
4763
+ "name": "target_label",
4764
+ "type": "text",
4765
+ "primaryKey": false,
4766
+ "notNull": false
4767
+ },
4768
+ "metadata": {
4769
+ "name": "metadata",
4770
+ "type": "jsonb",
4771
+ "primaryKey": false,
4772
+ "notNull": false
4773
+ },
4774
+ "created_at": {
4775
+ "name": "created_at",
4776
+ "type": "timestamp with time zone",
4777
+ "primaryKey": false,
4778
+ "notNull": true,
4779
+ "default": "now()"
4780
+ }
4781
+ },
4782
+ "indexes": {
4783
+ "audit_logs_created_at_idx": {
4784
+ "name": "audit_logs_created_at_idx",
4785
+ "columns": [
4786
+ {
4787
+ "expression": "created_at",
4788
+ "isExpression": false,
4789
+ "asc": false,
4790
+ "nulls": "last"
4791
+ }
4792
+ ],
4793
+ "isUnique": false,
4794
+ "concurrently": false,
4795
+ "method": "btree",
4796
+ "with": {}
4797
+ },
4798
+ "audit_logs_actor_profile_idx": {
4799
+ "name": "audit_logs_actor_profile_idx",
4800
+ "columns": [
4801
+ {
4802
+ "expression": "actor_profile_id",
4803
+ "isExpression": false,
4804
+ "asc": true,
4805
+ "nulls": "last"
4806
+ }
4807
+ ],
4808
+ "isUnique": false,
4809
+ "concurrently": false,
4810
+ "method": "btree",
4811
+ "with": {}
4812
+ },
4813
+ "audit_logs_target_idx": {
4814
+ "name": "audit_logs_target_idx",
4815
+ "columns": [
4816
+ {
4817
+ "expression": "target_type",
4818
+ "isExpression": false,
4819
+ "asc": true,
4820
+ "nulls": "last"
4821
+ },
4822
+ {
4823
+ "expression": "target_id",
4824
+ "isExpression": false,
4825
+ "asc": true,
4826
+ "nulls": "last"
4827
+ }
4828
+ ],
4829
+ "isUnique": false,
4830
+ "concurrently": false,
4831
+ "method": "btree",
4832
+ "with": {}
4833
+ }
4834
+ },
4835
+ "foreignKeys": {},
4836
+ "compositePrimaryKeys": {},
4837
+ "uniqueConstraints": {},
4838
+ "policies": {},
4839
+ "checkConstraints": {},
4840
+ "isRLSEnabled": false
4715
4841
  }
4716
4842
  },
4717
4843
  "enums": {},
@@ -142,6 +142,13 @@
142
142
  "tag": "0019_posts_published_at",
143
143
  "breakpoints": true
144
144
  },
145
+ {
146
+ "idx": 20,
147
+ "version": "7",
148
+ "when": 1795347885884,
149
+ "tag": "0020_add_audit_logs",
150
+ "breakpoints": true
151
+ },
145
152
  {
146
153
  "idx": 22,
147
154
  "version": "7",
@@ -150,4 +157,4 @@
150
157
  "breakpoints": true
151
158
  }
152
159
  ]
153
- }
160
+ }
@@ -40,3 +40,15 @@ export declare const updateJamRecording: (recordingId: string, recording: Partia
40
40
  _from: string;
41
41
  _to: string;
42
42
  }>;
43
+ /**
44
+ * Soft-deletes a jam chat message and blanks its content.
45
+ *
46
+ * Only the jam host, a jam moderator, or the message author may delete. The
47
+ * `deletedAt` soft-delete flag is what hides the row from every consumer
48
+ * (`listJamEvents`, attendance, export) — those all go through the
49
+ * soft-delete-filtered mappings; blanking `content` is belt-and-braces so no
50
+ * path that bypasses the flag can resurrect the text. `jamId` and `type` are
51
+ * re-checked server-side so an id pointing at a different jam or a non-message
52
+ * event (join/leave/start/…) is a 404, never a cross-jam write.
53
+ */
54
+ export declare const deleteJamEvent: (actorId: string, jamId: string, jamEventId: string) => Promise<boolean>;
@@ -1,4 +1,42 @@
1
+ import { jamFromEvent } from '@openpeepshq/common/lib';
2
+ import { forbidden, notFound } from '../errors/index.js';
1
3
  import { allpeepDb } from '../db/index.js';
4
+ import { findPost } from '../posts/index.js';
2
5
  import { jamEventsMapping, jamRecordingsMapping } from './mapping.js';
3
6
  export const createJamEvent = (jamEvent) => allpeepDb().then(({ db }) => jamEventsMapping.create(db, jamEvent));
4
7
  export const updateJamRecording = (recordingId, recording) => allpeepDb().then(({ db }) => jamRecordingsMapping.update(db, recordingId, recording));
8
+ /**
9
+ * Soft-deletes a jam chat message and blanks its content.
10
+ *
11
+ * Only the jam host, a jam moderator, or the message author may delete. The
12
+ * `deletedAt` soft-delete flag is what hides the row from every consumer
13
+ * (`listJamEvents`, attendance, export) — those all go through the
14
+ * soft-delete-filtered mappings; blanking `content` is belt-and-braces so no
15
+ * path that bypasses the flag can resurrect the text. `jamId` and `type` are
16
+ * re-checked server-side so an id pointing at a different jam or a non-message
17
+ * event (join/leave/start/…) is a 404, never a cross-jam write.
18
+ */
19
+ export const deleteJamEvent = async (actorId, jamId, jamEventId) => {
20
+ const { db } = await allpeepDb();
21
+ // ignoreSoftDelete: a re-delete must be a no-op 404, not a re-mutation.
22
+ const jamEvent = await jamEventsMapping.find(db, jamEventId, {
23
+ ignoreSoftDelete: true,
24
+ });
25
+ if (!jamEvent || jamEvent.jamId !== jamId || jamEvent.type !== 'message') {
26
+ throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
27
+ }
28
+ const jamPost = await findPost(jamId);
29
+ const jam = jamPost ? jamFromEvent(jamPost) : undefined;
30
+ if (!jamPost || !jam) {
31
+ throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
32
+ }
33
+ const isHost = jamPost.profile.id === actorId;
34
+ const isModerator = jam.moderators?.includes(actorId) ?? false;
35
+ const isAuthor = jamEvent.profileId === actorId;
36
+ if (!isHost && !isModerator && !isAuthor) {
37
+ throw forbidden({ errorKey: 'error.forbidden' });
38
+ }
39
+ await jamEventsMapping.update(db, jamEventId, { content: '' });
40
+ await jamEventsMapping.delete(db, jamEventId);
41
+ return true;
42
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "dependencies": {
@@ -37,10 +37,10 @@
37
37
  "type-fest": "^4.31.0",
38
38
  "uuidv7": "^1.0.2",
39
39
  "web-push": "^3.6.7",
40
- "@openpeepshq/common": "0.30.0",
40
+ "@openpeepshq/common": "0.31.0",
41
41
  "@openpeepshq/fetch-client": "^0.3.0",
42
- "@openpeepshq/geocoder": "^0.1.2",
43
- "@openpeepshq/i18n": "^0.31.0"
42
+ "@openpeepshq/i18n": "^0.32.0",
43
+ "@openpeepshq/geocoder": "^0.1.2"
44
44
  },
45
45
  "main": "dist/index.js",
46
46
  "types": "dist/index.d.ts",