founder-schema 0.18.0 → 0.20.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.
Files changed (156) hide show
  1. package/README.md +110 -3
  2. package/dist/access/permissions.d.ts +3 -3
  3. package/dist/access/permissions.d.ts.map +1 -1
  4. package/dist/access/permissions.js.map +1 -1
  5. package/dist/core/common.d.ts +49 -28
  6. package/dist/core/common.d.ts.map +1 -1
  7. package/dist/core/common.js +65 -26
  8. package/dist/core/common.js.map +1 -1
  9. package/dist/core/deletion.d.ts +40 -0
  10. package/dist/core/deletion.d.ts.map +1 -0
  11. package/dist/core/deletion.js +39 -0
  12. package/dist/core/deletion.js.map +1 -0
  13. package/dist/core/limits.d.ts +25 -0
  14. package/dist/core/limits.d.ts.map +1 -1
  15. package/dist/core/limits.js +25 -0
  16. package/dist/core/limits.js.map +1 -1
  17. package/dist/core/validation.d.ts +13 -0
  18. package/dist/core/validation.d.ts.map +1 -1
  19. package/dist/core/validation.js +13 -0
  20. package/dist/core/validation.js.map +1 -1
  21. package/dist/domains/audit/audit.d.ts +36 -12
  22. package/dist/domains/audit/audit.d.ts.map +1 -1
  23. package/dist/domains/audit/audit.js +9 -10
  24. package/dist/domains/audit/audit.js.map +1 -1
  25. package/dist/domains/billing/billing.d.ts +29 -13
  26. package/dist/domains/billing/billing.d.ts.map +1 -1
  27. package/dist/domains/billing/billing.js +2 -3
  28. package/dist/domains/billing/billing.js.map +1 -1
  29. package/dist/domains/chat/chat.d.ts +19 -5
  30. package/dist/domains/chat/chat.d.ts.map +1 -1
  31. package/dist/domains/chat/chat.js +10 -10
  32. package/dist/domains/chat/chat.js.map +1 -1
  33. package/dist/domains/communities/communities.d.ts +95 -57
  34. package/dist/domains/communities/communities.d.ts.map +1 -1
  35. package/dist/domains/contributions/contributions.d.ts +28 -12
  36. package/dist/domains/contributions/contributions.d.ts.map +1 -1
  37. package/dist/domains/contributions/contributions.js +3 -0
  38. package/dist/domains/contributions/contributions.js.map +1 -1
  39. package/dist/domains/discover/discover.d.ts +2 -2
  40. package/dist/domains/feed/feed.d.ts +111 -63
  41. package/dist/domains/feed/feed.d.ts.map +1 -1
  42. package/dist/domains/feed/feed.js +3 -0
  43. package/dist/domains/feed/feed.js.map +1 -1
  44. package/dist/domains/location/areas.d.ts +338 -0
  45. package/dist/domains/location/areas.d.ts.map +1 -0
  46. package/dist/domains/location/areas.js +241 -0
  47. package/dist/domains/location/areas.js.map +1 -0
  48. package/dist/domains/location/india.d.ts +31 -123
  49. package/dist/domains/location/india.d.ts.map +1 -1
  50. package/dist/domains/location/india.js +98 -64
  51. package/dist/domains/location/india.js.map +1 -1
  52. package/dist/domains/media/media.d.ts +22 -0
  53. package/dist/domains/media/media.d.ts.map +1 -1
  54. package/dist/domains/media/media.js +20 -0
  55. package/dist/domains/media/media.js.map +1 -1
  56. package/dist/domains/members/members.d.ts +26 -9
  57. package/dist/domains/members/members.d.ts.map +1 -1
  58. package/dist/domains/members/members.js +9 -10
  59. package/dist/domains/members/members.js.map +1 -1
  60. package/dist/domains/membership/membership.d.ts +19 -0
  61. package/dist/domains/membership/membership.d.ts.map +1 -1
  62. package/dist/domains/membership/membership.js +10 -0
  63. package/dist/domains/membership/membership.js.map +1 -1
  64. package/dist/domains/moderation/moderation.d.ts +8 -2
  65. package/dist/domains/moderation/moderation.d.ts.map +1 -1
  66. package/dist/domains/moderation/moderation.js +3 -6
  67. package/dist/domains/moderation/moderation.js.map +1 -1
  68. package/dist/domains/notifications/notifications.d.ts +10 -6
  69. package/dist/domains/notifications/notifications.d.ts.map +1 -1
  70. package/dist/domains/onboarding/onboarding-answers.d.ts +9 -12
  71. package/dist/domains/onboarding/onboarding-answers.d.ts.map +1 -1
  72. package/dist/domains/onboarding/onboarding-answers.js +12 -19
  73. package/dist/domains/onboarding/onboarding-answers.js.map +1 -1
  74. package/dist/domains/onboarding/onboarding.d.ts +121 -98
  75. package/dist/domains/onboarding/onboarding.d.ts.map +1 -1
  76. package/dist/domains/onboarding/onboarding.js +30 -28
  77. package/dist/domains/onboarding/onboarding.js.map +1 -1
  78. package/dist/domains/people/person.d.ts +54 -0
  79. package/dist/domains/people/person.d.ts.map +1 -0
  80. package/dist/domains/people/person.js +73 -0
  81. package/dist/domains/people/person.js.map +1 -0
  82. package/dist/domains/products/products.d.ts +62 -33
  83. package/dist/domains/products/products.d.ts.map +1 -1
  84. package/dist/domains/products/products.js +3 -0
  85. package/dist/domains/products/products.js.map +1 -1
  86. package/dist/domains/profile/founder-profile.d.ts +93 -60
  87. package/dist/domains/profile/founder-profile.d.ts.map +1 -1
  88. package/dist/domains/profile/founder-profile.js +55 -25
  89. package/dist/domains/profile/founder-profile.js.map +1 -1
  90. package/dist/domains/reviews/reviews.d.ts +25 -15
  91. package/dist/domains/reviews/reviews.d.ts.map +1 -1
  92. package/dist/domains/support/support.d.ts +47 -10
  93. package/dist/domains/support/support.d.ts.map +1 -1
  94. package/dist/domains/support/support.js +4 -2
  95. package/dist/domains/support/support.js.map +1 -1
  96. package/dist/domains/team/team.d.ts +9 -3
  97. package/dist/domains/team/team.d.ts.map +1 -1
  98. package/dist/domains/team/team.js +3 -6
  99. package/dist/domains/team/team.js.map +1 -1
  100. package/dist/index.d.ts +13 -10
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js +17 -11
  103. package/dist/index.js.map +1 -1
  104. package/package.json +3 -2
  105. package/dist/account.d.ts +0 -40
  106. package/dist/account.d.ts.map +0 -1
  107. package/dist/account.js +0 -39
  108. package/dist/account.js.map +0 -1
  109. package/dist/chat.d.ts +0 -187
  110. package/dist/chat.d.ts.map +0 -1
  111. package/dist/chat.js +0 -189
  112. package/dist/chat.js.map +0 -1
  113. package/dist/common.d.ts +0 -304
  114. package/dist/common.d.ts.map +0 -1
  115. package/dist/common.js +0 -340
  116. package/dist/common.js.map +0 -1
  117. package/dist/discover.d.ts +0 -245
  118. package/dist/discover.d.ts.map +0 -1
  119. package/dist/discover.js +0 -68
  120. package/dist/discover.js.map +0 -1
  121. package/dist/errors.d.ts +0 -85
  122. package/dist/errors.d.ts.map +0 -1
  123. package/dist/errors.js +0 -89
  124. package/dist/errors.js.map +0 -1
  125. package/dist/feed.d.ts +0 -1658
  126. package/dist/feed.d.ts.map +0 -1
  127. package/dist/feed.js +0 -623
  128. package/dist/feed.js.map +0 -1
  129. package/dist/founder-profile.d.ts +0 -387
  130. package/dist/founder-profile.d.ts.map +0 -1
  131. package/dist/founder-profile.js +0 -180
  132. package/dist/founder-profile.js.map +0 -1
  133. package/dist/limits.d.ts +0 -76
  134. package/dist/limits.d.ts.map +0 -1
  135. package/dist/limits.js +0 -84
  136. package/dist/limits.js.map +0 -1
  137. package/dist/onboarding.d.ts +0 -1018
  138. package/dist/onboarding.d.ts.map +0 -1
  139. package/dist/onboarding.js +0 -717
  140. package/dist/onboarding.js.map +0 -1
  141. package/dist/responses/common.d.ts +0 -167
  142. package/dist/responses/common.d.ts.map +0 -1
  143. package/dist/responses/common.js +0 -67
  144. package/dist/responses/common.js.map +0 -1
  145. package/dist/responses/index.d.ts +0 -7
  146. package/dist/responses/index.d.ts.map +0 -1
  147. package/dist/responses/index.js +0 -7
  148. package/dist/responses/index.js.map +0 -1
  149. package/dist/uploads.d.ts +0 -113
  150. package/dist/uploads.d.ts.map +0 -1
  151. package/dist/uploads.js +0 -106
  152. package/dist/uploads.js.map +0 -1
  153. package/dist/validation.d.ts +0 -136
  154. package/dist/validation.d.ts.map +0 -1
  155. package/dist/validation.js +0 -142
  156. package/dist/validation.js.map +0 -1
package/dist/chat.d.ts DELETED
@@ -1,187 +0,0 @@
1
- /**
2
- * founder-schema — Chat: config, auth token, opening a conversation, participants
3
- *
4
- * Founder Circle does not run a chat server. It uses the shared one, which
5
- * serves several products, and that is the whole reason this file is careful:
6
- * when one server serves many tenants, the failure mode is SILENT. A push once
7
- * returned success having sent nothing, because the caller held the wrong
8
- * product's key and nothing in the exchange said which product it was for.
9
- *
10
- * So the rule these shapes exist to hold: TENANCY COMES FROM THE CREDENTIAL,
11
- * never from a request body. The token says which product it is for, the chat
12
- * server resolves the product from the token and from nothing else, and a
13
- * Founder Circle token cannot address another product's conversation even when
14
- * handed a valid-looking id.
15
- *
16
- * ⚠️ TEXT ONLY. There is deliberately no `callsEnabled` flag here, and its
17
- * absence is the feature: the user ruled chat is text only, there is no call
18
- * code to branch on, and the browser is told to deny camera and microphone
19
- * outright. A boolean that can never be true is an invitation to turn it on.
20
- *
21
- * @module founder-schema/chat
22
- */
23
- import { z } from 'zod';
24
- /**
25
- * The product this package speaks for.
26
- *
27
- * Typed as a LITERAL on purpose. If the shared chat server ever hands back a
28
- * config or a token minted for a different product, parsing fails loudly here
29
- * rather than the client quietly talking to the wrong tenant. That is exactly
30
- * the class of bug this file exists to prevent, so it should be impossible to
31
- * carry past the first parse.
32
- */
33
- export declare const CHAT_PRODUCT_ID: "founder-circle";
34
- export declare const chatProductIdSchema: z.ZodLiteral<"founder-circle">;
35
- export type ChatProductId = z.infer<typeof chatProductIdSchema>;
36
- /**
37
- * What the client needs before it can open a socket.
38
- *
39
- * ⚠️ `enabled` IS MANDATORY AND IS NOT DERIVED FROM `url`. "Messaging is not
40
- * switched on yet" is a first-class state, not a failure: a 404 is the expected
41
- * answer today, and the client collapses a disabled flag, a null url, a non-2xx
42
- * and a thrown fetch to the same quiet "not on yet" rather than an error. If
43
- * `enabled` were inferred from a missing url, "off" and "broken" would be the
44
- * same wire shape and the inbox could not tell a member which one it was.
45
- *
46
- * ⚠️ `userId` is required and is the field nothing works without. The client
47
- * needs to know WHO THE VIEWER IS to decide which side a bubble sits on, to
48
- * filter the viewer out of presence and typing, to pick the other participant
49
- * for a row's name and avatar, and to tell its own optimistic message from one
50
- * echoed back. Without it every conversation renders as though the viewer were
51
- * nobody. It was missing from the first sketch of this endpoint.
52
- */
53
- export declare const chatConfigSchema: z.ZodObject<{
54
- enabled: z.ZodBoolean;
55
- url: z.ZodNullable<z.ZodURL>;
56
- userId: z.ZodString;
57
- productId: z.ZodLiteral<"founder-circle">;
58
- }, z.core.$strip>;
59
- export type ChatConfig = z.infer<typeof chatConfigSchema>;
60
- /**
61
- * How long before expiry the client re-mints, in seconds.
62
- *
63
- * Exported because it is a contract detail and not an implementation one: a
64
- * token handed over with two seconds left is a socket that authenticates and is
65
- * closed again immediately, so the minting side needs to know the consuming
66
- * side will not use the last minute of a token's life.
67
- */
68
- export declare const CHAT_TOKEN_REFRESH_MARGIN_SECONDS = 60;
69
- /**
70
- * How often the live socket re-authenticates, in seconds.
71
- *
72
- * Auth is an EVENT on the open socket rather than a handshake parameter, so
73
- * re-authenticating does not drop the connection.
74
- *
75
- * ⚠️ THIS MUST STAY BELOW THE REAL TOKEN LIFETIME, by more than the refresh
76
- * margin. It assumes a 15 minute token. A re-auth interval longer than the
77
- * lifetime is a socket that dies every quarter of an hour with no explanation,
78
- * and the symptom appears far from the cause. If the issued lifetime changes,
79
- * this number moves with it or the two silently disagree.
80
- */
81
- export declare const CHAT_SOCKET_REAUTH_SECONDS: number;
82
- /**
83
- * A short-lived token for the shared chat server.
84
- *
85
- * ⚠️ BOTH TIME FIELDS ARE KEPT, and they are not redundant, because two
86
- * different parties read them with two different clocks:
87
- *
88
- * `expiresAt` an absolute instant, for the SERVER. The chat server holds the
89
- * authoritative clock and must reject an expired token on its
90
- * own, whatever any client believes.
91
- * `expiresIn` a duration in seconds, for the CLIENT. Scheduling a refresh
92
- * from `receivedAt + expiresIn` uses only the client's own
93
- * elapsed time, so a device whose absolute clock is wrong still
94
- * refreshes correctly. Scheduling from `expiresAt` instead means
95
- * a browser an hour fast treats every fresh token as already
96
- * expired and re-mints forever.
97
- *
98
- * Dropping either one breaks the party that reads it. This is the same reason
99
- * OAuth carries `expires_in` on the wire while the token itself carries `exp`.
100
- *
101
- * ⚠️ AND THE CLIENT IS NOT THE ENFORCER. Its margin is an optimisation to avoid
102
- * a pointless round trip. A wrong clock, a tab asleep for an hour, or a modified
103
- * client all defeat anything the client does, so the chat server rejects an
104
- * expired token on its own.
105
- */
106
- export declare const chatAuthTokenSchema: z.ZodObject<{
107
- token: z.ZodString;
108
- expiresAt: z.ZodISODateTime;
109
- expiresIn: z.ZodNumber;
110
- productId: z.ZodLiteral<"founder-circle">;
111
- }, z.core.$strip>;
112
- export type ChatAuthToken = z.infer<typeof chatAuthTokenSchema>;
113
- /**
114
- * `POST /api/v1/chat/open`: start (or find) the direct conversation with
115
- * another member.
116
- *
117
- * Our backend decides who may talk to whom, because only it knows this
118
- * product's rules, and it does the whole exchange with the chat server itself:
119
- * it mints the viewer's token and an invitation naming both participants, and
120
- * redeems them server to server. No credential reaches the browser.
121
- */
122
- export declare const openChatBodySchema: z.ZodObject<{
123
- userId: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
124
- }, z.core.$strip>;
125
- export type OpenChatBody = z.infer<typeof openChatBodySchema>;
126
- /**
127
- * The conversation to navigate to. `201` with `wasCreated: true` the first
128
- * time, `200` and `false` on every later open of the same pair.
129
- */
130
- export declare const openChatResponseSchema: z.ZodObject<{
131
- conversationId: z.ZodString;
132
- wasCreated: z.ZodBoolean;
133
- }, z.core.$strip>;
134
- export type OpenChatResponse = z.infer<typeof openChatResponseSchema>;
135
- /**
136
- * `POST /api/v1/chat/participants`: names and avatars for the people in the
137
- * viewer's conversations.
138
- *
139
- * The chat server knows ids and nothing about who anybody is, because it serves
140
- * several products and identity belongs to each; so the conversation list asks
141
- * here, once per screen. Bounded by `CHAT_PARTICIPANTS_MAX`, so it cannot page
142
- * through the directory.
143
- */
144
- export declare const chatParticipantsBodySchema: z.ZodObject<{
145
- userIds: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
146
- }, z.core.$strip>;
147
- export type ChatParticipantsBody = z.infer<typeof chatParticipantsBodySchema>;
148
- /** The public card fields any member already sees, and nothing more. */
149
- export declare const chatParticipantSchema: z.ZodObject<{
150
- displayName: z.ZodString;
151
- username: z.ZodString;
152
- avatarUrl: z.ZodNullable<z.ZodURL>;
153
- }, z.core.$strip>;
154
- export type ChatParticipant = z.infer<typeof chatParticipantSchema>;
155
- /**
156
- * Keyed by user id. ⚠ An id with no active, onboarded profile is ABSENT, not
157
- * an error: the client renders it as a former member rather than guessing.
158
- */
159
- export declare const chatParticipantsResponseSchema: z.ZodObject<{
160
- participants: z.ZodRecord<z.ZodString, z.ZodObject<{
161
- displayName: z.ZodString;
162
- username: z.ZodString;
163
- avatarUrl: z.ZodNullable<z.ZodURL>;
164
- }, z.core.$strip>>;
165
- }, z.core.$strip>;
166
- export type ChatParticipantsResponse = z.infer<typeof chatParticipantsResponseSchema>;
167
- /**
168
- * @deprecated Since 0.2.0: use `openChatBodySchema`, the same shape under the
169
- * name of the route that takes it.
170
- */
171
- export declare const chatInvitationBodySchema: z.ZodObject<{
172
- userId: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
173
- }, z.core.$strip>;
174
- /** @deprecated Since 0.2.0: use `OpenChatBody`. */
175
- export type ChatInvitationBody = OpenChatBody;
176
- /**
177
- * @deprecated Since 0.2.0, and it describes nothing that exists. The browser
178
- * never holds an invitation: `/chat/open` mints and redeems it server to
179
- * server. The old `/invitation` route that handed one out could never have
180
- * worked and is gone.
181
- */
182
- export declare const chatInvitationSchema: z.ZodObject<{
183
- invitationToken: z.ZodString;
184
- }, z.core.$strip>;
185
- /** @deprecated Since 0.2.0. */
186
- export type ChatInvitation = z.infer<typeof chatInvitationSchema>;
187
- //# sourceMappingURL=chat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,EAAG,gBAAyB,CAAC;AACzD,eAAO,MAAM,mBAAmB,gCAA6B,CAAC;AAC9D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAA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;AAC3D,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;iBAE/B,CAAC;AACH,+BAA+B;AAC/B,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
package/dist/chat.js DELETED
@@ -1,189 +0,0 @@
1
- /**
2
- * founder-schema — Chat: config, auth token, opening a conversation, participants
3
- *
4
- * Founder Circle does not run a chat server. It uses the shared one, which
5
- * serves several products, and that is the whole reason this file is careful:
6
- * when one server serves many tenants, the failure mode is SILENT. A push once
7
- * returned success having sent nothing, because the caller held the wrong
8
- * product's key and nothing in the exchange said which product it was for.
9
- *
10
- * So the rule these shapes exist to hold: TENANCY COMES FROM THE CREDENTIAL,
11
- * never from a request body. The token says which product it is for, the chat
12
- * server resolves the product from the token and from nothing else, and a
13
- * Founder Circle token cannot address another product's conversation even when
14
- * handed a valid-looking id.
15
- *
16
- * ⚠️ TEXT ONLY. There is deliberately no `callsEnabled` flag here, and its
17
- * absence is the feature: the user ruled chat is text only, there is no call
18
- * code to branch on, and the browser is told to deny camera and microphone
19
- * outright. A boolean that can never be true is an invitation to turn it on.
20
- *
21
- * @module founder-schema/chat
22
- */
23
- import { z } from 'zod';
24
- import { objectIdSchema, usernameSchema } from './common.js';
25
- import { CHAT_PARTICIPANTS_MAX } from './limits.js';
26
- /**
27
- * The product this package speaks for.
28
- *
29
- * Typed as a LITERAL on purpose. If the shared chat server ever hands back a
30
- * config or a token minted for a different product, parsing fails loudly here
31
- * rather than the client quietly talking to the wrong tenant. That is exactly
32
- * the class of bug this file exists to prevent, so it should be impossible to
33
- * carry past the first parse.
34
- */
35
- export const CHAT_PRODUCT_ID = 'founder-circle';
36
- export const chatProductIdSchema = z.literal(CHAT_PRODUCT_ID);
37
- // ─── Config ──────────────────────────────────────────────────────────────────
38
- /**
39
- * What the client needs before it can open a socket.
40
- *
41
- * ⚠️ `enabled` IS MANDATORY AND IS NOT DERIVED FROM `url`. "Messaging is not
42
- * switched on yet" is a first-class state, not a failure: a 404 is the expected
43
- * answer today, and the client collapses a disabled flag, a null url, a non-2xx
44
- * and a thrown fetch to the same quiet "not on yet" rather than an error. If
45
- * `enabled` were inferred from a missing url, "off" and "broken" would be the
46
- * same wire shape and the inbox could not tell a member which one it was.
47
- *
48
- * ⚠️ `userId` is required and is the field nothing works without. The client
49
- * needs to know WHO THE VIEWER IS to decide which side a bubble sits on, to
50
- * filter the viewer out of presence and typing, to pick the other participant
51
- * for a row's name and avatar, and to tell its own optimistic message from one
52
- * echoed back. Without it every conversation renders as though the viewer were
53
- * nobody. It was missing from the first sketch of this endpoint.
54
- */
55
- export const chatConfigSchema = z.object({
56
- enabled: z.boolean(),
57
- /** Null whenever chat is not switched on. Never a placeholder string. */
58
- url: z.url().nullable(),
59
- /** The VIEWER's id, as the chat server knows them. */
60
- userId: z.string(),
61
- /** Which product this config is for. See `chatProductIdSchema`. */
62
- productId: chatProductIdSchema,
63
- });
64
- // ─── Auth token ──────────────────────────────────────────────────────────────
65
- /**
66
- * How long before expiry the client re-mints, in seconds.
67
- *
68
- * Exported because it is a contract detail and not an implementation one: a
69
- * token handed over with two seconds left is a socket that authenticates and is
70
- * closed again immediately, so the minting side needs to know the consuming
71
- * side will not use the last minute of a token's life.
72
- */
73
- export const CHAT_TOKEN_REFRESH_MARGIN_SECONDS = 60;
74
- /**
75
- * How often the live socket re-authenticates, in seconds.
76
- *
77
- * Auth is an EVENT on the open socket rather than a handshake parameter, so
78
- * re-authenticating does not drop the connection.
79
- *
80
- * ⚠️ THIS MUST STAY BELOW THE REAL TOKEN LIFETIME, by more than the refresh
81
- * margin. It assumes a 15 minute token. A re-auth interval longer than the
82
- * lifetime is a socket that dies every quarter of an hour with no explanation,
83
- * and the symptom appears far from the cause. If the issued lifetime changes,
84
- * this number moves with it or the two silently disagree.
85
- */
86
- export const CHAT_SOCKET_REAUTH_SECONDS = 10 * 60;
87
- /**
88
- * A short-lived token for the shared chat server.
89
- *
90
- * ⚠️ BOTH TIME FIELDS ARE KEPT, and they are not redundant, because two
91
- * different parties read them with two different clocks:
92
- *
93
- * `expiresAt` an absolute instant, for the SERVER. The chat server holds the
94
- * authoritative clock and must reject an expired token on its
95
- * own, whatever any client believes.
96
- * `expiresIn` a duration in seconds, for the CLIENT. Scheduling a refresh
97
- * from `receivedAt + expiresIn` uses only the client's own
98
- * elapsed time, so a device whose absolute clock is wrong still
99
- * refreshes correctly. Scheduling from `expiresAt` instead means
100
- * a browser an hour fast treats every fresh token as already
101
- * expired and re-mints forever.
102
- *
103
- * Dropping either one breaks the party that reads it. This is the same reason
104
- * OAuth carries `expires_in` on the wire while the token itself carries `exp`.
105
- *
106
- * ⚠️ AND THE CLIENT IS NOT THE ENFORCER. Its margin is an optimisation to avoid
107
- * a pointless round trip. A wrong clock, a tab asleep for an hour, or a modified
108
- * client all defeat anything the client does, so the chat server rejects an
109
- * expired token on its own.
110
- */
111
- export const chatAuthTokenSchema = z.object({
112
- token: z.string().min(1),
113
- /** ISO 8601. Parsed with `Date.parse`, never an epoch number. */
114
- expiresAt: z.iso.datetime(),
115
- /** Seconds from issue. See the note above on why both exist. */
116
- expiresIn: z.number().int().positive(),
117
- /** The product this token is scoped to. A mismatch must fail loudly. */
118
- productId: chatProductIdSchema,
119
- });
120
- // ─── Opening a conversation ──────────────────────────────────────────────────
121
- /**
122
- * `POST /api/v1/chat/open`: start (or find) the direct conversation with
123
- * another member.
124
- *
125
- * Our backend decides who may talk to whom, because only it knows this
126
- * product's rules, and it does the whole exchange with the chat server itself:
127
- * it mints the viewer's token and an invitation naming both participants, and
128
- * redeems them server to server. No credential reaches the browser.
129
- */
130
- export const openChatBodySchema = z.object({
131
- /** The OTHER participant. The viewer is taken from the credential, never the body. */
132
- userId: objectIdSchema,
133
- });
134
- /**
135
- * The conversation to navigate to. `201` with `wasCreated: true` the first
136
- * time, `200` and `false` on every later open of the same pair.
137
- */
138
- export const openChatResponseSchema = z.object({
139
- conversationId: z.string().min(1),
140
- wasCreated: z.boolean(),
141
- });
142
- // ─── Participants ────────────────────────────────────────────────────────────
143
- /**
144
- * `POST /api/v1/chat/participants`: names and avatars for the people in the
145
- * viewer's conversations.
146
- *
147
- * The chat server knows ids and nothing about who anybody is, because it serves
148
- * several products and identity belongs to each; so the conversation list asks
149
- * here, once per screen. Bounded by `CHAT_PARTICIPANTS_MAX`, so it cannot page
150
- * through the directory.
151
- */
152
- export const chatParticipantsBodySchema = z.object({
153
- userIds: z.array(objectIdSchema).min(1).max(CHAT_PARTICIPANTS_MAX),
154
- });
155
- /** The public card fields any member already sees, and nothing more. */
156
- export const chatParticipantSchema = z.object({
157
- displayName: z.string(),
158
- username: usernameSchema,
159
- /** Null when the member has no photo. Ours, or from the login provider. */
160
- avatarUrl: z.url().nullable(),
161
- });
162
- /**
163
- * Keyed by user id. ⚠ An id with no active, onboarded profile is ABSENT, not
164
- * an error: the client renders it as a former member rather than guessing.
165
- */
166
- export const chatParticipantsResponseSchema = z.object({
167
- participants: z.record(z.string(), chatParticipantSchema),
168
- });
169
- // ─── Deprecated ──────────────────────────────────────────────────────────────
170
- //
171
- // Unused by every consumer, and still exported: removing an export trips the
172
- // publish rule that refuses a release missing anything the live one has, so it
173
- // is the user's decision, not a side effect. They were meant to go in 0.3.0;
174
- // that release kept them.
175
- /**
176
- * @deprecated Since 0.2.0: use `openChatBodySchema`, the same shape under the
177
- * name of the route that takes it.
178
- */
179
- export const chatInvitationBodySchema = openChatBodySchema;
180
- /**
181
- * @deprecated Since 0.2.0, and it describes nothing that exists. The browser
182
- * never holds an invitation: `/chat/open` mints and redeems it server to
183
- * server. The old `/invitation` route that handed one out could never have
184
- * worked and is gone.
185
- */
186
- export const chatInvitationSchema = z.object({
187
- invitationToken: z.string().min(1),
188
- });
189
- //# sourceMappingURL=chat.js.map
package/dist/chat.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat.js","sourceRoot":"","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C;AAI3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACnC,CAAC,CAAC","sourcesContent":["/**\n * founder-schema — Chat: config, auth token, opening a conversation, participants\n *\n * Founder Circle does not run a chat server. It uses the shared one, which\n * serves several products, and that is the whole reason this file is careful:\n * when one server serves many tenants, the failure mode is SILENT. A push once\n * returned success having sent nothing, because the caller held the wrong\n * product's key and nothing in the exchange said which product it was for.\n *\n * So the rule these shapes exist to hold: TENANCY COMES FROM THE CREDENTIAL,\n * never from a request body. The token says which product it is for, the chat\n * server resolves the product from the token and from nothing else, and a\n * Founder Circle token cannot address another product's conversation even when\n * handed a valid-looking id.\n *\n * ⚠️ TEXT ONLY. There is deliberately no `callsEnabled` flag here, and its\n * absence is the feature: the user ruled chat is text only, there is no call\n * code to branch on, and the browser is told to deny camera and microphone\n * outright. A boolean that can never be true is an invitation to turn it on.\n *\n * @module founder-schema/chat\n */\n\nimport { z } from 'zod';\nimport { objectIdSchema, usernameSchema } from './common.js';\nimport { CHAT_PARTICIPANTS_MAX } from './limits.js';\n\n/**\n * The product this package speaks for.\n *\n * Typed as a LITERAL on purpose. If the shared chat server ever hands back a\n * config or a token minted for a different product, parsing fails loudly here\n * rather than the client quietly talking to the wrong tenant. That is exactly\n * the class of bug this file exists to prevent, so it should be impossible to\n * carry past the first parse.\n */\nexport const CHAT_PRODUCT_ID = 'founder-circle' as const;\nexport const chatProductIdSchema = z.literal(CHAT_PRODUCT_ID);\nexport type ChatProductId = z.infer<typeof chatProductIdSchema>;\n\n// ─── Config ──────────────────────────────────────────────────────────────────\n\n/**\n * What the client needs before it can open a socket.\n *\n * ⚠️ `enabled` IS MANDATORY AND IS NOT DERIVED FROM `url`. \"Messaging is not\n * switched on yet\" is a first-class state, not a failure: a 404 is the expected\n * answer today, and the client collapses a disabled flag, a null url, a non-2xx\n * and a thrown fetch to the same quiet \"not on yet\" rather than an error. If\n * `enabled` were inferred from a missing url, \"off\" and \"broken\" would be the\n * same wire shape and the inbox could not tell a member which one it was.\n *\n * ⚠️ `userId` is required and is the field nothing works without. The client\n * needs to know WHO THE VIEWER IS to decide which side a bubble sits on, to\n * filter the viewer out of presence and typing, to pick the other participant\n * for a row's name and avatar, and to tell its own optimistic message from one\n * echoed back. Without it every conversation renders as though the viewer were\n * nobody. It was missing from the first sketch of this endpoint.\n */\nexport const chatConfigSchema = z.object({\n enabled: z.boolean(),\n /** Null whenever chat is not switched on. Never a placeholder string. */\n url: z.url().nullable(),\n /** The VIEWER's id, as the chat server knows them. */\n userId: z.string(),\n /** Which product this config is for. See `chatProductIdSchema`. */\n productId: chatProductIdSchema,\n});\nexport type ChatConfig = z.infer<typeof chatConfigSchema>;\n\n// ─── Auth token ──────────────────────────────────────────────────────────────\n\n/**\n * How long before expiry the client re-mints, in seconds.\n *\n * Exported because it is a contract detail and not an implementation one: a\n * token handed over with two seconds left is a socket that authenticates and is\n * closed again immediately, so the minting side needs to know the consuming\n * side will not use the last minute of a token's life.\n */\nexport const CHAT_TOKEN_REFRESH_MARGIN_SECONDS = 60;\n\n/**\n * How often the live socket re-authenticates, in seconds.\n *\n * Auth is an EVENT on the open socket rather than a handshake parameter, so\n * re-authenticating does not drop the connection.\n *\n * ⚠️ THIS MUST STAY BELOW THE REAL TOKEN LIFETIME, by more than the refresh\n * margin. It assumes a 15 minute token. A re-auth interval longer than the\n * lifetime is a socket that dies every quarter of an hour with no explanation,\n * and the symptom appears far from the cause. If the issued lifetime changes,\n * this number moves with it or the two silently disagree.\n */\nexport const CHAT_SOCKET_REAUTH_SECONDS = 10 * 60;\n\n/**\n * A short-lived token for the shared chat server.\n *\n * ⚠️ BOTH TIME FIELDS ARE KEPT, and they are not redundant, because two\n * different parties read them with two different clocks:\n *\n * `expiresAt` an absolute instant, for the SERVER. The chat server holds the\n * authoritative clock and must reject an expired token on its\n * own, whatever any client believes.\n * `expiresIn` a duration in seconds, for the CLIENT. Scheduling a refresh\n * from `receivedAt + expiresIn` uses only the client's own\n * elapsed time, so a device whose absolute clock is wrong still\n * refreshes correctly. Scheduling from `expiresAt` instead means\n * a browser an hour fast treats every fresh token as already\n * expired and re-mints forever.\n *\n * Dropping either one breaks the party that reads it. This is the same reason\n * OAuth carries `expires_in` on the wire while the token itself carries `exp`.\n *\n * ⚠️ AND THE CLIENT IS NOT THE ENFORCER. Its margin is an optimisation to avoid\n * a pointless round trip. A wrong clock, a tab asleep for an hour, or a modified\n * client all defeat anything the client does, so the chat server rejects an\n * expired token on its own.\n */\nexport const chatAuthTokenSchema = z.object({\n token: z.string().min(1),\n /** ISO 8601. Parsed with `Date.parse`, never an epoch number. */\n expiresAt: z.iso.datetime(),\n /** Seconds from issue. See the note above on why both exist. */\n expiresIn: z.number().int().positive(),\n /** The product this token is scoped to. A mismatch must fail loudly. */\n productId: chatProductIdSchema,\n});\nexport type ChatAuthToken = z.infer<typeof chatAuthTokenSchema>;\n\n// ─── Opening a conversation ──────────────────────────────────────────────────\n\n/**\n * `POST /api/v1/chat/open`: start (or find) the direct conversation with\n * another member.\n *\n * Our backend decides who may talk to whom, because only it knows this\n * product's rules, and it does the whole exchange with the chat server itself:\n * it mints the viewer's token and an invitation naming both participants, and\n * redeems them server to server. No credential reaches the browser.\n */\nexport const openChatBodySchema = z.object({\n /** The OTHER participant. The viewer is taken from the credential, never the body. */\n userId: objectIdSchema,\n});\nexport type OpenChatBody = z.infer<typeof openChatBodySchema>;\n\n/**\n * The conversation to navigate to. `201` with `wasCreated: true` the first\n * time, `200` and `false` on every later open of the same pair.\n */\nexport const openChatResponseSchema = z.object({\n conversationId: z.string().min(1),\n wasCreated: z.boolean(),\n});\nexport type OpenChatResponse = z.infer<typeof openChatResponseSchema>;\n\n// ─── Participants ────────────────────────────────────────────────────────────\n\n/**\n * `POST /api/v1/chat/participants`: names and avatars for the people in the\n * viewer's conversations.\n *\n * The chat server knows ids and nothing about who anybody is, because it serves\n * several products and identity belongs to each; so the conversation list asks\n * here, once per screen. Bounded by `CHAT_PARTICIPANTS_MAX`, so it cannot page\n * through the directory.\n */\nexport const chatParticipantsBodySchema = z.object({\n userIds: z.array(objectIdSchema).min(1).max(CHAT_PARTICIPANTS_MAX),\n});\nexport type ChatParticipantsBody = z.infer<typeof chatParticipantsBodySchema>;\n\n/** The public card fields any member already sees, and nothing more. */\nexport const chatParticipantSchema = z.object({\n displayName: z.string(),\n username: usernameSchema,\n /** Null when the member has no photo. Ours, or from the login provider. */\n avatarUrl: z.url().nullable(),\n});\nexport type ChatParticipant = z.infer<typeof chatParticipantSchema>;\n\n/**\n * Keyed by user id. ⚠ An id with no active, onboarded profile is ABSENT, not\n * an error: the client renders it as a former member rather than guessing.\n */\nexport const chatParticipantsResponseSchema = z.object({\n participants: z.record(z.string(), chatParticipantSchema),\n});\nexport type ChatParticipantsResponse = z.infer<typeof chatParticipantsResponseSchema>;\n\n// ─── Deprecated ──────────────────────────────────────────────────────────────\n//\n// Unused by every consumer, and still exported: removing an export trips the\n// publish rule that refuses a release missing anything the live one has, so it\n// is the user's decision, not a side effect. They were meant to go in 0.3.0;\n// that release kept them.\n\n/**\n * @deprecated Since 0.2.0: use `openChatBodySchema`, the same shape under the\n * name of the route that takes it.\n */\nexport const chatInvitationBodySchema = openChatBodySchema;\n/** @deprecated Since 0.2.0: use `OpenChatBody`. */\nexport type ChatInvitationBody = OpenChatBody;\n\n/**\n * @deprecated Since 0.2.0, and it describes nothing that exists. The browser\n * never holds an invitation: `/chat/open` mints and redeems it server to\n * server. The old `/invitation` route that handed one out could never have\n * worked and is gone.\n */\nexport const chatInvitationSchema = z.object({\n invitationToken: z.string().min(1),\n});\n/** @deprecated Since 0.2.0. */\nexport type ChatInvitation = z.infer<typeof chatInvitationSchema>;\n"]}