@openpeepshq/common 0.14.0 → 0.16.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.
@@ -17,3 +17,31 @@ export declare const EVENT_HEADER_ASPECT_RATIO = "16:9";
17
17
  * with grey gaps.
18
18
  */
19
19
  export declare const PROFILE_GROUP_HEADER_ASPECT_RATIO = "3:1";
20
+ /**
21
+ * Max duration (seconds) of voice notes recorded in the post composers.
22
+ * Enforced on the client (web modal + RN sheet) and re-checked server-side
23
+ * during media processing, so it is the single source of truth for the cap.
24
+ *
25
+ * Boundary rule — clients auto-stop at `VOICE_NOTE_AUTO_STOP_SECONDS`, the
26
+ * server rejects with `>`: the recorders tick every 500 ms and the stop check
27
+ * runs against the *raw* wall-clock span, so a take can finish anywhere in
28
+ * [90.0 s, 90.5 s). The file's probed duration is that raw span, so stopping
29
+ * at exactly 90 s would let roughly half of honest cap-length takes probe
30
+ * above the server's `duration > 90` check and surface the 400 right after
31
+ * the recorder stopped itself. Auto-stopping at 89.5 s keeps every honest
32
+ * take strictly under 90 s (≤ 89.999 s), while a genuinely-overshot or
33
+ * crafted upload (≥ 90.5 s) still probes above the cap and is rejected —
34
+ * the two sides are pinned by tests (`transcodeAudio.test.ts`,
35
+ * `mediaDimensions.test.ts`, `VoiceRecorderModal.test.tsx`,
36
+ * `record-audio-sheet.test.tsx`) so they cannot drift apart — change either
37
+ * the threshold or the server operator only together with those tests.
38
+ */
39
+ export declare const VOICE_NOTE_MAX_SECONDS = 90;
40
+ /**
41
+ * The wall-clock moment the recorders auto-stop. Half a second *under*
42
+ * VOICE_NOTE_MAX_SECONDS: the coarse 500 ms tick that detects the threshold
43
+ * guarantees the actual file stays under the cap (see above), which is what
44
+ * makes the server's `duration > VOICE_NOTE_MAX_SECONDS` boundary safe for
45
+ * honest takes.
46
+ */
47
+ export declare const VOICE_NOTE_AUTO_STOP_SECONDS: number;
@@ -17,3 +17,31 @@ export const EVENT_HEADER_ASPECT_RATIO = '16:9';
17
17
  * with grey gaps.
18
18
  */
19
19
  export const PROFILE_GROUP_HEADER_ASPECT_RATIO = '3:1';
20
+ /**
21
+ * Max duration (seconds) of voice notes recorded in the post composers.
22
+ * Enforced on the client (web modal + RN sheet) and re-checked server-side
23
+ * during media processing, so it is the single source of truth for the cap.
24
+ *
25
+ * Boundary rule — clients auto-stop at `VOICE_NOTE_AUTO_STOP_SECONDS`, the
26
+ * server rejects with `>`: the recorders tick every 500 ms and the stop check
27
+ * runs against the *raw* wall-clock span, so a take can finish anywhere in
28
+ * [90.0 s, 90.5 s). The file's probed duration is that raw span, so stopping
29
+ * at exactly 90 s would let roughly half of honest cap-length takes probe
30
+ * above the server's `duration > 90` check and surface the 400 right after
31
+ * the recorder stopped itself. Auto-stopping at 89.5 s keeps every honest
32
+ * take strictly under 90 s (≤ 89.999 s), while a genuinely-overshot or
33
+ * crafted upload (≥ 90.5 s) still probes above the cap and is rejected —
34
+ * the two sides are pinned by tests (`transcodeAudio.test.ts`,
35
+ * `mediaDimensions.test.ts`, `VoiceRecorderModal.test.tsx`,
36
+ * `record-audio-sheet.test.tsx`) so they cannot drift apart — change either
37
+ * the threshold or the server operator only together with those tests.
38
+ */
39
+ export const VOICE_NOTE_MAX_SECONDS = 90;
40
+ /**
41
+ * The wall-clock moment the recorders auto-stop. Half a second *under*
42
+ * VOICE_NOTE_MAX_SECONDS: the coarse 500 ms tick that detects the threshold
43
+ * guarantees the actual file stays under the cap (see above), which is what
44
+ * makes the server's `duration > VOICE_NOTE_MAX_SECONDS` boundary safe for
45
+ * honest takes.
46
+ */
47
+ export const VOICE_NOTE_AUTO_STOP_SECONDS = VOICE_NOTE_MAX_SECONDS - 0.5;
@@ -1,120 +1,56 @@
1
1
  import { z } from 'zod';
2
- /** Data a user can download as their account export. */
3
- export declare const accountExportSchema: z.ZodObject<{
4
- account: z.ZodObject<{
5
- id: z.ZodUUID;
6
- email: z.ZodEmail;
7
- emailValidated: z.ZodDefault<z.ZodBoolean>;
8
- }, z.core.$strip>;
9
- profiles: z.ZodArray<z.ZodObject<{
10
- id: z.ZodString;
11
- type: z.ZodEnum<{
12
- local: "local";
13
- guest: "guest";
14
- federated: "federated";
15
- }>;
16
- createdAt: z.ZodString;
17
- updatedAt: z.ZodString;
18
- deletedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
19
- handle: z.ZodString;
20
- avatar: z.ZodOptional<z.ZodNullable<z.ZodString>>;
21
- header: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
- displayName: z.ZodOptional<z.ZodString>;
23
- bio: z.ZodOptional<z.ZodString>;
24
- location: z.ZodOptional<z.ZodObject<{
25
- text: z.ZodString;
26
- coordinates: z.ZodOptional<z.ZodObject<{
27
- lat: z.ZodNumber;
28
- lng: z.ZodNumber;
29
- alt: z.ZodOptional<z.ZodNumber>;
30
- }, z.core.$strip>>;
31
- }, z.core.$strip>>;
32
- locked: z.ZodOptional<z.ZodBoolean>;
33
- bot: z.ZodOptional<z.ZodBoolean>;
34
- discoverable: z.ZodOptional<z.ZodBoolean>;
35
- roles: z.ZodOptional<z.ZodArray<z.ZodObject<{
36
- key: z.ZodString;
37
- displayName: z.ZodString;
38
- }, z.core.$strip>>>;
39
- memberships: z.ZodPipe<z.ZodOptional<z.ZodArray<z.ZodObject<{
40
- roles: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodEnum<{
41
- none: "none";
42
- local: "local";
43
- member: "member";
44
- moderator: "moderator";
45
- admin: "admin";
46
- owner: "owner";
47
- invited: "invited";
48
- }>>>>;
49
- group: z.ZodObject<{
50
- handle: z.ZodString;
51
- avatar: z.ZodOptional<z.ZodNullable<z.ZodString>>;
52
- header: z.ZodOptional<z.ZodNullable<z.ZodString>>;
53
- displayName: z.ZodOptional<z.ZodString>;
54
- description: z.ZodOptional<z.ZodString>;
55
- rules: z.ZodOptional<z.ZodString>;
56
- pinnedPostId: z.ZodOptional<z.ZodString>;
57
- discoverable: z.ZodOptional<z.ZodBoolean>;
58
- capabilities: z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodObject<{
59
- add: z.ZodOptional<z.ZodArray<z.ZodString>>;
60
- remove: z.ZodOptional<z.ZodArray<z.ZodString>>;
61
- }, z.core.$strip>>>;
62
- id: z.ZodUUID;
63
- createdAt: z.ZodISODateTime;
64
- updatedAt: z.ZodISODateTime;
65
- deletedAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
66
- }, z.core.$strip>;
67
- }, z.core.$strip>>>, z.ZodTransform<{
68
- group: {
69
- handle: string;
70
- capabilities: Record<string, {
71
- add?: string[] | undefined;
72
- remove?: string[] | undefined;
73
- } | undefined>;
74
- id: string;
75
- createdAt: string;
76
- updatedAt: string;
77
- avatar?: string | null | undefined;
78
- header?: string | null | undefined;
79
- displayName?: string | undefined;
80
- description?: string | undefined;
81
- rules?: string | undefined;
82
- pinnedPostId?: string | undefined;
83
- discoverable?: boolean | undefined;
84
- deletedAt?: string | null | undefined;
85
- };
86
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
87
- }[] | undefined, {
88
- group: {
89
- handle: string;
90
- capabilities: Record<string, {
91
- add?: string[] | undefined;
92
- remove?: string[] | undefined;
93
- } | undefined>;
94
- id: string;
95
- createdAt: string;
96
- updatedAt: string;
97
- avatar?: string | null | undefined;
98
- header?: string | null | undefined;
99
- displayName?: string | undefined;
100
- description?: string | undefined;
101
- rules?: string | undefined;
102
- pinnedPostId?: string | undefined;
103
- discoverable?: boolean | undefined;
104
- deletedAt?: string | null | undefined;
105
- };
106
- roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
107
- }[] | undefined>>;
108
- fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
109
- name: z.ZodString;
110
- value: z.ZodString;
111
- }, z.core.$strip>>>;
112
- profileStats: z.ZodOptional<z.ZodObject<{
113
- followersCount: z.ZodNumber;
114
- followingCount: z.ZodNumber;
115
- }, z.core.$strip>>;
116
- pinnedPostId: z.ZodOptional<z.ZodString>;
117
- blockedByMe: z.ZodOptional<z.ZodBoolean>;
118
- }, z.core.$strip>>;
2
+ /**
3
+ * Full personal data export (GDPR-style). Requested via `POST`, assembled
4
+ * asynchronously by a worker job, downloaded via a short-lived token.
5
+ */
6
+ export declare const accountExportJobSchema: z.ZodObject<{
7
+ jobId: z.ZodUUID;
119
8
  }, z.core.$strip>;
120
- export type AccountExport = z.infer<typeof accountExportSchema>;
9
+ export type AccountExportJob = z.infer<typeof accountExportJobSchema>;
10
+ /**
11
+ * Lifecycle states of an account export, as reported by the status endpoint:
12
+ * - `building` — the worker has not (yet) written a record, or is assembling
13
+ * the archive; the client keeps polling.
14
+ * - `ready` — the archive exists; the response carries the single-use
15
+ * `downloadToken` and its `expiresAt`. The client stops polling and offers
16
+ * the download.
17
+ * - `error` — assembly failed; the response carries `error`. Stop polling.
18
+ * - `expired` — the record's token lapsed or the archive was cleaned up; the
19
+ * client stops polling and asks the user to start a new export.
20
+ * - `not-found` — no record for the given `jobId` (unknown to this account).
21
+ */
22
+ export declare const accountExportStateSchema: z.ZodEnum<{
23
+ error: "error";
24
+ ready: "ready";
25
+ building: "building";
26
+ expired: "expired";
27
+ "not-found": "not-found";
28
+ }>;
29
+ export type AccountExportState = z.infer<typeof accountExportStateSchema>;
30
+ /** `GET /accounts/current/export/status?jobId=…` */
31
+ export declare const accountExportStatusSchema: z.ZodObject<{
32
+ jobId: z.ZodUUID;
33
+ state: z.ZodEnum<{
34
+ error: "error";
35
+ ready: "ready";
36
+ building: "building";
37
+ expired: "expired";
38
+ "not-found": "not-found";
39
+ }>;
40
+ downloadToken: z.ZodOptional<z.ZodString>;
41
+ expiresAt: z.ZodOptional<z.ZodString>;
42
+ error: z.ZodOptional<z.ZodString>;
43
+ }, z.core.$strip>;
44
+ export type AccountExportStatus = z.infer<typeof accountExportStatusSchema>;
45
+ /**
46
+ * The "ready" payload shared by every producer of a finished export — the
47
+ * worker that assembles the archive and the status endpoint that reports it.
48
+ * Single-sourcing the `state`/`downloadToken`/`expiresAt` triple here keeps the
49
+ * two from drifting as the API grows (adding a field to the shape now means
50
+ * touching one type instead of both construction sites). Type-only: it mirrors
51
+ * `AccountExportStatus`'s ready fields, so it changes no runtime surface.
52
+ */
53
+ export type AccountExportReady = Pick<AccountExportStatus, 'downloadToken' | 'expiresAt'> & {
54
+ /** The ready state, as a literal — the only state that carries the fields. */
55
+ state: 'ready';
56
+ };
@@ -1,7 +1,37 @@
1
1
  import { z } from 'zod';
2
- import { publicAccountSchema, publicProfileSchema } from './api.js';
3
- /** Data a user can download as their account export. */
4
- export const accountExportSchema = z.object({
5
- account: publicAccountSchema,
6
- profiles: publicProfileSchema.array(),
2
+ /**
3
+ * Full personal data export (GDPR-style). Requested via `POST`, assembled
4
+ * asynchronously by a worker job, downloaded via a short-lived token.
5
+ */
6
+ export const accountExportJobSchema = z.object({
7
+ jobId: z.uuid(),
8
+ });
9
+ /**
10
+ * Lifecycle states of an account export, as reported by the status endpoint:
11
+ * - `building` — the worker has not (yet) written a record, or is assembling
12
+ * the archive; the client keeps polling.
13
+ * - `ready` — the archive exists; the response carries the single-use
14
+ * `downloadToken` and its `expiresAt`. The client stops polling and offers
15
+ * the download.
16
+ * - `error` — assembly failed; the response carries `error`. Stop polling.
17
+ * - `expired` — the record's token lapsed or the archive was cleaned up; the
18
+ * client stops polling and asks the user to start a new export.
19
+ * - `not-found` — no record for the given `jobId` (unknown to this account).
20
+ */
21
+ export const accountExportStateSchema = z.enum([
22
+ 'building',
23
+ 'ready',
24
+ 'error',
25
+ 'expired',
26
+ 'not-found',
27
+ ]);
28
+ /** `GET /accounts/current/export/status?jobId=…` */
29
+ export const accountExportStatusSchema = z.object({
30
+ jobId: z.uuid(),
31
+ state: accountExportStateSchema,
32
+ /** Present once `state === 'ready'`. Pass to the download endpoint. */
33
+ downloadToken: z.string().optional(),
34
+ /** When `state === 'ready'`, the download token stops working after this. */
35
+ expiresAt: z.string().datetime().optional(),
36
+ error: z.string().optional(),
7
37
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/common",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -19,3 +19,33 @@ export const EVENT_HEADER_ASPECT_RATIO = '16:9';
19
19
  * with grey gaps.
20
20
  */
21
21
  export const PROFILE_GROUP_HEADER_ASPECT_RATIO = '3:1';
22
+
23
+ /**
24
+ * Max duration (seconds) of voice notes recorded in the post composers.
25
+ * Enforced on the client (web modal + RN sheet) and re-checked server-side
26
+ * during media processing, so it is the single source of truth for the cap.
27
+ *
28
+ * Boundary rule — clients auto-stop at `VOICE_NOTE_AUTO_STOP_SECONDS`, the
29
+ * server rejects with `>`: the recorders tick every 500 ms and the stop check
30
+ * runs against the *raw* wall-clock span, so a take can finish anywhere in
31
+ * [90.0 s, 90.5 s). The file's probed duration is that raw span, so stopping
32
+ * at exactly 90 s would let roughly half of honest cap-length takes probe
33
+ * above the server's `duration > 90` check and surface the 400 right after
34
+ * the recorder stopped itself. Auto-stopping at 89.5 s keeps every honest
35
+ * take strictly under 90 s (≤ 89.999 s), while a genuinely-overshot or
36
+ * crafted upload (≥ 90.5 s) still probes above the cap and is rejected —
37
+ * the two sides are pinned by tests (`transcodeAudio.test.ts`,
38
+ * `mediaDimensions.test.ts`, `VoiceRecorderModal.test.tsx`,
39
+ * `record-audio-sheet.test.tsx`) so they cannot drift apart — change either
40
+ * the threshold or the server operator only together with those tests.
41
+ */
42
+ export const VOICE_NOTE_MAX_SECONDS = 90;
43
+
44
+ /**
45
+ * The wall-clock moment the recorders auto-stop. Half a second *under*
46
+ * VOICE_NOTE_MAX_SECONDS: the coarse 500 ms tick that detects the threshold
47
+ * guarantees the actual file stays under the cap (see above), which is what
48
+ * makes the server's `duration > VOICE_NOTE_MAX_SECONDS` boundary safe for
49
+ * honest takes.
50
+ */
51
+ export const VOICE_NOTE_AUTO_STOP_SECONDS = VOICE_NOTE_MAX_SECONDS - 0.5;
@@ -1,10 +1,60 @@
1
1
  import { z } from 'zod';
2
- import { publicAccountSchema, publicProfileSchema } from './api';
3
2
 
4
- /** Data a user can download as their account export. */
5
- export const accountExportSchema = z.object({
6
- account: publicAccountSchema,
7
- profiles: publicProfileSchema.array(),
3
+ /**
4
+ * Full personal data export (GDPR-style). Requested via `POST`, assembled
5
+ * asynchronously by a worker job, downloaded via a short-lived token.
6
+ */
7
+
8
+ export const accountExportJobSchema = z.object({
9
+ jobId: z.uuid(),
10
+ });
11
+ export type AccountExportJob = z.infer<typeof accountExportJobSchema>;
12
+
13
+ /**
14
+ * Lifecycle states of an account export, as reported by the status endpoint:
15
+ * - `building` — the worker has not (yet) written a record, or is assembling
16
+ * the archive; the client keeps polling.
17
+ * - `ready` — the archive exists; the response carries the single-use
18
+ * `downloadToken` and its `expiresAt`. The client stops polling and offers
19
+ * the download.
20
+ * - `error` — assembly failed; the response carries `error`. Stop polling.
21
+ * - `expired` — the record's token lapsed or the archive was cleaned up; the
22
+ * client stops polling and asks the user to start a new export.
23
+ * - `not-found` — no record for the given `jobId` (unknown to this account).
24
+ */
25
+ export const accountExportStateSchema = z.enum([
26
+ 'building',
27
+ 'ready',
28
+ 'error',
29
+ 'expired',
30
+ 'not-found',
31
+ ]);
32
+ export type AccountExportState = z.infer<typeof accountExportStateSchema>;
33
+
34
+ /** `GET /accounts/current/export/status?jobId=…` */
35
+ export const accountExportStatusSchema = z.object({
36
+ jobId: z.uuid(),
37
+ state: accountExportStateSchema,
38
+ /** Present once `state === 'ready'`. Pass to the download endpoint. */
39
+ downloadToken: z.string().optional(),
40
+ /** When `state === 'ready'`, the download token stops working after this. */
41
+ expiresAt: z.string().datetime().optional(),
42
+ error: z.string().optional(),
8
43
  });
44
+ export type AccountExportStatus = z.infer<typeof accountExportStatusSchema>;
9
45
 
10
- export type AccountExport = z.infer<typeof accountExportSchema>;
46
+ /**
47
+ * The "ready" payload shared by every producer of a finished export — the
48
+ * worker that assembles the archive and the status endpoint that reports it.
49
+ * Single-sourcing the `state`/`downloadToken`/`expiresAt` triple here keeps the
50
+ * two from drifting as the API grows (adding a field to the shape now means
51
+ * touching one type instead of both construction sites). Type-only: it mirrors
52
+ * `AccountExportStatus`'s ready fields, so it changes no runtime surface.
53
+ */
54
+ export type AccountExportReady = Pick<
55
+ AccountExportStatus,
56
+ 'downloadToken' | 'expiresAt'
57
+ > & {
58
+ /** The ready state, as a literal — the only state that carries the fields. */
59
+ state: 'ready';
60
+ };