founder-schema 0.10.0 → 0.12.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/README.md +98 -0
- package/dist/access/access.d.ts +10 -6
- package/dist/access/access.d.ts.map +1 -1
- package/dist/access/access.js +8 -1
- package/dist/access/access.js.map +1 -1
- package/dist/access/permissions.d.ts +60 -3
- package/dist/access/permissions.d.ts.map +1 -1
- package/dist/access/permissions.js +24 -0
- package/dist/access/permissions.js.map +1 -1
- package/dist/access/roles.d.ts +3 -3
- package/dist/access/standing.d.ts +59 -0
- package/dist/access/standing.d.ts.map +1 -0
- package/dist/access/standing.js +52 -0
- package/dist/access/standing.js.map +1 -0
- package/dist/core/errors.d.ts +47 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +82 -1
- package/dist/core/errors.js.map +1 -1
- package/dist/core/limits.d.ts +39 -3
- package/dist/core/limits.d.ts.map +1 -1
- package/dist/core/limits.js +41 -3
- package/dist/core/limits.js.map +1 -1
- package/dist/core/responses.d.ts +55 -0
- package/dist/core/responses.d.ts.map +1 -1
- package/dist/core/responses.js +6 -0
- package/dist/core/responses.js.map +1 -1
- package/dist/core/validation.d.ts +14 -0
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +14 -0
- package/dist/core/validation.js.map +1 -1
- package/dist/domains/audit/audit.d.ts +28 -7
- package/dist/domains/audit/audit.d.ts.map +1 -1
- package/dist/domains/audit/audit.js +17 -0
- package/dist/domains/audit/audit.js.map +1 -1
- package/dist/domains/billing/billing.d.ts +1179 -0
- package/dist/domains/billing/billing.d.ts.map +1 -0
- package/dist/domains/billing/billing.js +393 -0
- package/dist/domains/billing/billing.js.map +1 -0
- package/dist/domains/billing/gst.d.ts +229 -0
- package/dist/domains/billing/gst.d.ts.map +1 -0
- package/dist/domains/billing/gst.js +117 -0
- package/dist/domains/billing/gst.js.map +1 -0
- package/dist/domains/chat/chat.d.ts +85 -0
- package/dist/domains/chat/chat.d.ts.map +1 -1
- package/dist/domains/chat/chat.js +62 -0
- package/dist/domains/chat/chat.js.map +1 -1
- package/dist/domains/communities/communities.d.ts +11 -11
- package/dist/domains/dashboard/dashboard.d.ts +9 -1
- package/dist/domains/dashboard/dashboard.d.ts.map +1 -1
- package/dist/domains/dashboard/dashboard.js +15 -0
- package/dist/domains/dashboard/dashboard.js.map +1 -1
- package/dist/domains/feed/feed.d.ts.map +1 -1
- package/dist/domains/feed/feed.js +7 -1
- package/dist/domains/feed/feed.js.map +1 -1
- package/dist/domains/members/members.d.ts +30 -5
- package/dist/domains/members/members.d.ts.map +1 -1
- package/dist/domains/members/members.js +23 -0
- package/dist/domains/members/members.js.map +1 -1
- package/dist/domains/membership/membership.d.ts +239 -0
- package/dist/domains/membership/membership.d.ts.map +1 -0
- package/dist/domains/membership/membership.js +153 -0
- package/dist/domains/membership/membership.js.map +1 -0
- package/dist/domains/notifications/notifications.d.ts +43 -1
- package/dist/domains/notifications/notifications.d.ts.map +1 -1
- package/dist/domains/notifications/notifications.js +19 -0
- package/dist/domains/notifications/notifications.js.map +1 -1
- package/dist/domains/products/products.d.ts +44 -12
- package/dist/domains/products/products.d.ts.map +1 -1
- package/dist/domains/products/products.js +33 -3
- package/dist/domains/products/products.js.map +1 -1
- package/dist/domains/profile/founder-profile.d.ts +178 -0
- package/dist/domains/profile/founder-profile.d.ts.map +1 -1
- package/dist/domains/profile/founder-profile.js +77 -0
- package/dist/domains/profile/founder-profile.js.map +1 -1
- package/dist/domains/reviews/reviews.d.ts +3 -0
- package/dist/domains/reviews/reviews.d.ts.map +1 -1
- package/dist/domains/reviews/reviews.js +6 -1
- package/dist/domains/reviews/reviews.js.map +1 -1
- package/dist/domains/team/team.d.ts +4 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* founder-schema: GST, the states and the GSTIN (0.12.0)
|
|
3
|
+
*
|
|
4
|
+
* Its own module so both the billing contract and a member's membership
|
|
5
|
+
* (the billing details they last used, to prefill a checkout) can use it
|
|
6
|
+
* without importing each other.
|
|
7
|
+
*
|
|
8
|
+
* @module founder-schema/domains/billing/gst
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
/**
|
|
12
|
+
* India's states and union territories by their GST state code, the first
|
|
13
|
+
* two digits of every GSTIN registered there. The current codes only: 25
|
|
14
|
+
* (Daman and Diu) merged into 26 in 2020, and 28 (undivided Andhra Pradesh)
|
|
15
|
+
* gave way to 37.
|
|
16
|
+
*/
|
|
17
|
+
export declare const GST_STATES: readonly [{
|
|
18
|
+
readonly code: "01";
|
|
19
|
+
readonly name: "Jammu and Kashmir";
|
|
20
|
+
}, {
|
|
21
|
+
readonly code: "02";
|
|
22
|
+
readonly name: "Himachal Pradesh";
|
|
23
|
+
}, {
|
|
24
|
+
readonly code: "03";
|
|
25
|
+
readonly name: "Punjab";
|
|
26
|
+
}, {
|
|
27
|
+
readonly code: "04";
|
|
28
|
+
readonly name: "Chandigarh";
|
|
29
|
+
}, {
|
|
30
|
+
readonly code: "05";
|
|
31
|
+
readonly name: "Uttarakhand";
|
|
32
|
+
}, {
|
|
33
|
+
readonly code: "06";
|
|
34
|
+
readonly name: "Haryana";
|
|
35
|
+
}, {
|
|
36
|
+
readonly code: "07";
|
|
37
|
+
readonly name: "Delhi";
|
|
38
|
+
}, {
|
|
39
|
+
readonly code: "08";
|
|
40
|
+
readonly name: "Rajasthan";
|
|
41
|
+
}, {
|
|
42
|
+
readonly code: "09";
|
|
43
|
+
readonly name: "Uttar Pradesh";
|
|
44
|
+
}, {
|
|
45
|
+
readonly code: "10";
|
|
46
|
+
readonly name: "Bihar";
|
|
47
|
+
}, {
|
|
48
|
+
readonly code: "11";
|
|
49
|
+
readonly name: "Sikkim";
|
|
50
|
+
}, {
|
|
51
|
+
readonly code: "12";
|
|
52
|
+
readonly name: "Arunachal Pradesh";
|
|
53
|
+
}, {
|
|
54
|
+
readonly code: "13";
|
|
55
|
+
readonly name: "Nagaland";
|
|
56
|
+
}, {
|
|
57
|
+
readonly code: "14";
|
|
58
|
+
readonly name: "Manipur";
|
|
59
|
+
}, {
|
|
60
|
+
readonly code: "15";
|
|
61
|
+
readonly name: "Mizoram";
|
|
62
|
+
}, {
|
|
63
|
+
readonly code: "16";
|
|
64
|
+
readonly name: "Tripura";
|
|
65
|
+
}, {
|
|
66
|
+
readonly code: "17";
|
|
67
|
+
readonly name: "Meghalaya";
|
|
68
|
+
}, {
|
|
69
|
+
readonly code: "18";
|
|
70
|
+
readonly name: "Assam";
|
|
71
|
+
}, {
|
|
72
|
+
readonly code: "19";
|
|
73
|
+
readonly name: "West Bengal";
|
|
74
|
+
}, {
|
|
75
|
+
readonly code: "20";
|
|
76
|
+
readonly name: "Jharkhand";
|
|
77
|
+
}, {
|
|
78
|
+
readonly code: "21";
|
|
79
|
+
readonly name: "Odisha";
|
|
80
|
+
}, {
|
|
81
|
+
readonly code: "22";
|
|
82
|
+
readonly name: "Chhattisgarh";
|
|
83
|
+
}, {
|
|
84
|
+
readonly code: "23";
|
|
85
|
+
readonly name: "Madhya Pradesh";
|
|
86
|
+
}, {
|
|
87
|
+
readonly code: "24";
|
|
88
|
+
readonly name: "Gujarat";
|
|
89
|
+
}, {
|
|
90
|
+
readonly code: "26";
|
|
91
|
+
readonly name: "Dadra and Nagar Haveli and Daman and Diu";
|
|
92
|
+
}, {
|
|
93
|
+
readonly code: "27";
|
|
94
|
+
readonly name: "Maharashtra";
|
|
95
|
+
}, {
|
|
96
|
+
readonly code: "29";
|
|
97
|
+
readonly name: "Karnataka";
|
|
98
|
+
}, {
|
|
99
|
+
readonly code: "30";
|
|
100
|
+
readonly name: "Goa";
|
|
101
|
+
}, {
|
|
102
|
+
readonly code: "31";
|
|
103
|
+
readonly name: "Lakshadweep";
|
|
104
|
+
}, {
|
|
105
|
+
readonly code: "32";
|
|
106
|
+
readonly name: "Kerala";
|
|
107
|
+
}, {
|
|
108
|
+
readonly code: "33";
|
|
109
|
+
readonly name: "Tamil Nadu";
|
|
110
|
+
}, {
|
|
111
|
+
readonly code: "34";
|
|
112
|
+
readonly name: "Puducherry";
|
|
113
|
+
}, {
|
|
114
|
+
readonly code: "35";
|
|
115
|
+
readonly name: "Andaman and Nicobar Islands";
|
|
116
|
+
}, {
|
|
117
|
+
readonly code: "36";
|
|
118
|
+
readonly name: "Telangana";
|
|
119
|
+
}, {
|
|
120
|
+
readonly code: "37";
|
|
121
|
+
readonly name: "Andhra Pradesh";
|
|
122
|
+
}, {
|
|
123
|
+
readonly code: "38";
|
|
124
|
+
readonly name: "Ladakh";
|
|
125
|
+
}];
|
|
126
|
+
export type GstStateCode = (typeof GST_STATES)[number]['code'];
|
|
127
|
+
export declare const GST_STATE_CODE_VALUES: [GstStateCode, ...GstStateCode[]];
|
|
128
|
+
export declare const gstStateCodeSchema: z.ZodEnum<{
|
|
129
|
+
"01": "01";
|
|
130
|
+
"02": "02";
|
|
131
|
+
"03": "03";
|
|
132
|
+
"04": "04";
|
|
133
|
+
"05": "05";
|
|
134
|
+
"06": "06";
|
|
135
|
+
"07": "07";
|
|
136
|
+
"08": "08";
|
|
137
|
+
"09": "09";
|
|
138
|
+
10: "10";
|
|
139
|
+
11: "11";
|
|
140
|
+
12: "12";
|
|
141
|
+
13: "13";
|
|
142
|
+
14: "14";
|
|
143
|
+
15: "15";
|
|
144
|
+
16: "16";
|
|
145
|
+
17: "17";
|
|
146
|
+
18: "18";
|
|
147
|
+
19: "19";
|
|
148
|
+
20: "20";
|
|
149
|
+
21: "21";
|
|
150
|
+
22: "22";
|
|
151
|
+
23: "23";
|
|
152
|
+
24: "24";
|
|
153
|
+
26: "26";
|
|
154
|
+
27: "27";
|
|
155
|
+
29: "29";
|
|
156
|
+
30: "30";
|
|
157
|
+
31: "31";
|
|
158
|
+
32: "32";
|
|
159
|
+
33: "33";
|
|
160
|
+
34: "34";
|
|
161
|
+
35: "35";
|
|
162
|
+
36: "36";
|
|
163
|
+
37: "37";
|
|
164
|
+
38: "38";
|
|
165
|
+
}>;
|
|
166
|
+
/** The state's name for its code, as an invoice prints it. */
|
|
167
|
+
export declare function gstStateName(code: GstStateCode): string;
|
|
168
|
+
/** GST is 18% on these services, inside every price. */
|
|
169
|
+
export declare const GST_RATE_PERCENT = 18;
|
|
170
|
+
/**
|
|
171
|
+
* Whether a GSTIN's 15th character is the check character of the first 14
|
|
172
|
+
* (the GSTN's base-36 Luhn variant). Catches a mistyped digit, which the
|
|
173
|
+
* pattern alone does not: a B2B invoice with a wrong GSTIN costs the buyer
|
|
174
|
+
* their input credit.
|
|
175
|
+
*/
|
|
176
|
+
export declare function gstinChecksumValid(gstin: string): boolean;
|
|
177
|
+
/** A GSTIN, upper-cased, pattern AND check character. */
|
|
178
|
+
export declare const gstinSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
179
|
+
/**
|
|
180
|
+
* Who is buying, for the invoice. The state is the place of supply and
|
|
181
|
+
* decides the tax. With a GSTIN (a business claiming input credit) the
|
|
182
|
+
* invoice is B2B: it must carry the buyer's legal name and address, and the
|
|
183
|
+
* state is the GSTIN's own.
|
|
184
|
+
*/
|
|
185
|
+
export declare const billingDetailsSchema: z.ZodObject<{
|
|
186
|
+
stateCode: z.ZodEnum<{
|
|
187
|
+
"01": "01";
|
|
188
|
+
"02": "02";
|
|
189
|
+
"03": "03";
|
|
190
|
+
"04": "04";
|
|
191
|
+
"05": "05";
|
|
192
|
+
"06": "06";
|
|
193
|
+
"07": "07";
|
|
194
|
+
"08": "08";
|
|
195
|
+
"09": "09";
|
|
196
|
+
10: "10";
|
|
197
|
+
11: "11";
|
|
198
|
+
12: "12";
|
|
199
|
+
13: "13";
|
|
200
|
+
14: "14";
|
|
201
|
+
15: "15";
|
|
202
|
+
16: "16";
|
|
203
|
+
17: "17";
|
|
204
|
+
18: "18";
|
|
205
|
+
19: "19";
|
|
206
|
+
20: "20";
|
|
207
|
+
21: "21";
|
|
208
|
+
22: "22";
|
|
209
|
+
23: "23";
|
|
210
|
+
24: "24";
|
|
211
|
+
26: "26";
|
|
212
|
+
27: "27";
|
|
213
|
+
29: "29";
|
|
214
|
+
30: "30";
|
|
215
|
+
31: "31";
|
|
216
|
+
32: "32";
|
|
217
|
+
33: "33";
|
|
218
|
+
34: "34";
|
|
219
|
+
35: "35";
|
|
220
|
+
36: "36";
|
|
221
|
+
37: "37";
|
|
222
|
+
38: "38";
|
|
223
|
+
}>;
|
|
224
|
+
gstin: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
225
|
+
legalName: z.ZodOptional<z.ZodString>;
|
|
226
|
+
address: z.ZodOptional<z.ZodString>;
|
|
227
|
+
}, z.core.$strip>;
|
|
228
|
+
export type BillingDetails = z.infer<typeof billingDetailsSchema>;
|
|
229
|
+
//# sourceMappingURL=gst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gst.d.ts","sourceRoot":"","sources":["../../../src/domains/billing/gst.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCb,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,eAAO,MAAM,qBAAqB,EAAoC,CACpE,YAAY,EACZ,GAAG,YAAY,EAAE,CAClB,CAAC;AACF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAgC,CAAC;AAEhE,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAEvD;AAED,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAKnC;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAUzD;AAED,yDAAyD;AACzD,eAAO,MAAM,WAAW,wDAIiD,CAAC;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkB7B,CAAC;AACL,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* founder-schema: GST, the states and the GSTIN (0.12.0)
|
|
3
|
+
*
|
|
4
|
+
* Its own module so both the billing contract and a member's membership
|
|
5
|
+
* (the billing details they last used, to prefill a checkout) can use it
|
|
6
|
+
* without importing each other.
|
|
7
|
+
*
|
|
8
|
+
* @module founder-schema/domains/billing/gst
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { BILLING_ADDRESS_MAX, BILLING_NAME_MAX } from '../../core/limits.js';
|
|
12
|
+
import { VALIDATION_MESSAGE } from '../../core/validation.js';
|
|
13
|
+
// ─── GST: states and the GSTIN ───────────────────────────────────────────────
|
|
14
|
+
/**
|
|
15
|
+
* India's states and union territories by their GST state code, the first
|
|
16
|
+
* two digits of every GSTIN registered there. The current codes only: 25
|
|
17
|
+
* (Daman and Diu) merged into 26 in 2020, and 28 (undivided Andhra Pradesh)
|
|
18
|
+
* gave way to 37.
|
|
19
|
+
*/
|
|
20
|
+
export const GST_STATES = [
|
|
21
|
+
{ code: '01', name: 'Jammu and Kashmir' },
|
|
22
|
+
{ code: '02', name: 'Himachal Pradesh' },
|
|
23
|
+
{ code: '03', name: 'Punjab' },
|
|
24
|
+
{ code: '04', name: 'Chandigarh' },
|
|
25
|
+
{ code: '05', name: 'Uttarakhand' },
|
|
26
|
+
{ code: '06', name: 'Haryana' },
|
|
27
|
+
{ code: '07', name: 'Delhi' },
|
|
28
|
+
{ code: '08', name: 'Rajasthan' },
|
|
29
|
+
{ code: '09', name: 'Uttar Pradesh' },
|
|
30
|
+
{ code: '10', name: 'Bihar' },
|
|
31
|
+
{ code: '11', name: 'Sikkim' },
|
|
32
|
+
{ code: '12', name: 'Arunachal Pradesh' },
|
|
33
|
+
{ code: '13', name: 'Nagaland' },
|
|
34
|
+
{ code: '14', name: 'Manipur' },
|
|
35
|
+
{ code: '15', name: 'Mizoram' },
|
|
36
|
+
{ code: '16', name: 'Tripura' },
|
|
37
|
+
{ code: '17', name: 'Meghalaya' },
|
|
38
|
+
{ code: '18', name: 'Assam' },
|
|
39
|
+
{ code: '19', name: 'West Bengal' },
|
|
40
|
+
{ code: '20', name: 'Jharkhand' },
|
|
41
|
+
{ code: '21', name: 'Odisha' },
|
|
42
|
+
{ code: '22', name: 'Chhattisgarh' },
|
|
43
|
+
{ code: '23', name: 'Madhya Pradesh' },
|
|
44
|
+
{ code: '24', name: 'Gujarat' },
|
|
45
|
+
{ code: '26', name: 'Dadra and Nagar Haveli and Daman and Diu' },
|
|
46
|
+
{ code: '27', name: 'Maharashtra' },
|
|
47
|
+
{ code: '29', name: 'Karnataka' },
|
|
48
|
+
{ code: '30', name: 'Goa' },
|
|
49
|
+
{ code: '31', name: 'Lakshadweep' },
|
|
50
|
+
{ code: '32', name: 'Kerala' },
|
|
51
|
+
{ code: '33', name: 'Tamil Nadu' },
|
|
52
|
+
{ code: '34', name: 'Puducherry' },
|
|
53
|
+
{ code: '35', name: 'Andaman and Nicobar Islands' },
|
|
54
|
+
{ code: '36', name: 'Telangana' },
|
|
55
|
+
{ code: '37', name: 'Andhra Pradesh' },
|
|
56
|
+
{ code: '38', name: 'Ladakh' },
|
|
57
|
+
];
|
|
58
|
+
export const GST_STATE_CODE_VALUES = GST_STATES.map((s) => s.code);
|
|
59
|
+
export const gstStateCodeSchema = z.enum(GST_STATE_CODE_VALUES);
|
|
60
|
+
/** The state's name for its code, as an invoice prints it. */
|
|
61
|
+
export function gstStateName(code) {
|
|
62
|
+
return GST_STATES.find((s) => s.code === code)?.name ?? code;
|
|
63
|
+
}
|
|
64
|
+
/** GST is 18% on these services, inside every price. */
|
|
65
|
+
export const GST_RATE_PERCENT = 18;
|
|
66
|
+
const GSTIN_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
67
|
+
const GSTIN_PATTERN = /^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/;
|
|
68
|
+
/**
|
|
69
|
+
* Whether a GSTIN's 15th character is the check character of the first 14
|
|
70
|
+
* (the GSTN's base-36 Luhn variant). Catches a mistyped digit, which the
|
|
71
|
+
* pattern alone does not: a B2B invoice with a wrong GSTIN costs the buyer
|
|
72
|
+
* their input credit.
|
|
73
|
+
*/
|
|
74
|
+
export function gstinChecksumValid(gstin) {
|
|
75
|
+
if (!GSTIN_PATTERN.test(gstin))
|
|
76
|
+
return false;
|
|
77
|
+
let sum = 0;
|
|
78
|
+
for (let i = 0; i < 14; i++) {
|
|
79
|
+
const value = GSTIN_CHARS.indexOf(gstin.charAt(i));
|
|
80
|
+
const product = value * (i % 2 === 0 ? 1 : 2);
|
|
81
|
+
sum += Math.floor(product / 36) + (product % 36);
|
|
82
|
+
}
|
|
83
|
+
const check = (36 - (sum % 36)) % 36;
|
|
84
|
+
return gstin.charAt(14) === GSTIN_CHARS.charAt(check);
|
|
85
|
+
}
|
|
86
|
+
/** A GSTIN, upper-cased, pattern AND check character. */
|
|
87
|
+
export const gstinSchema = z
|
|
88
|
+
.string()
|
|
89
|
+
.trim()
|
|
90
|
+
.transform((v) => v.toUpperCase())
|
|
91
|
+
.refine(gstinChecksumValid, { error: VALIDATION_MESSAGE.gstinInvalid });
|
|
92
|
+
/**
|
|
93
|
+
* Who is buying, for the invoice. The state is the place of supply and
|
|
94
|
+
* decides the tax. With a GSTIN (a business claiming input credit) the
|
|
95
|
+
* invoice is B2B: it must carry the buyer's legal name and address, and the
|
|
96
|
+
* state is the GSTIN's own.
|
|
97
|
+
*/
|
|
98
|
+
export const billingDetailsSchema = z
|
|
99
|
+
.object({
|
|
100
|
+
stateCode: gstStateCodeSchema,
|
|
101
|
+
gstin: gstinSchema.optional(),
|
|
102
|
+
legalName: z.string().trim().min(2).max(BILLING_NAME_MAX).optional(),
|
|
103
|
+
address: z.string().trim().min(10).max(BILLING_ADDRESS_MAX).optional(),
|
|
104
|
+
})
|
|
105
|
+
.refine((body) => !body.gstin || body.gstin.slice(0, 2) === body.stateCode, {
|
|
106
|
+
path: ['stateCode'],
|
|
107
|
+
error: VALIDATION_MESSAGE.gstinStateMismatch,
|
|
108
|
+
})
|
|
109
|
+
.refine((body) => !body.gstin || body.legalName !== undefined, {
|
|
110
|
+
path: ['legalName'],
|
|
111
|
+
error: VALIDATION_MESSAGE.gstinNeedsNameAndAddress,
|
|
112
|
+
})
|
|
113
|
+
.refine((body) => !body.gstin || body.address !== undefined, {
|
|
114
|
+
path: ['address'],
|
|
115
|
+
error: VALIDATION_MESSAGE.gstinNeedsNameAndAddress,
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=gst.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gst.js","sourceRoot":"","sources":["../../../src/domains/billing/gst.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,EAAE,IAAI,EAAE,IAA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","sourcesContent":["/**\n * founder-schema: GST, the states and the GSTIN (0.12.0)\n *\n * Its own module so both the billing contract and a member's membership\n * (the billing details they last used, to prefill a checkout) can use it\n * without importing each other.\n *\n * @module founder-schema/domains/billing/gst\n */\n\nimport { z } from 'zod';\nimport { BILLING_ADDRESS_MAX, BILLING_NAME_MAX } from '../../core/limits.js';\nimport { VALIDATION_MESSAGE } from '../../core/validation.js';\n\n// ─── GST: states and the GSTIN ───────────────────────────────────────────────\n\n/**\n * India's states and union territories by their GST state code, the first\n * two digits of every GSTIN registered there. The current codes only: 25\n * (Daman and Diu) merged into 26 in 2020, and 28 (undivided Andhra Pradesh)\n * gave way to 37.\n */\nexport const GST_STATES = [\n { code: '01', name: 'Jammu and Kashmir' },\n { code: '02', name: 'Himachal Pradesh' },\n { code: '03', name: 'Punjab' },\n { code: '04', name: 'Chandigarh' },\n { code: '05', name: 'Uttarakhand' },\n { code: '06', name: 'Haryana' },\n { code: '07', name: 'Delhi' },\n { code: '08', name: 'Rajasthan' },\n { code: '09', name: 'Uttar Pradesh' },\n { code: '10', name: 'Bihar' },\n { code: '11', name: 'Sikkim' },\n { code: '12', name: 'Arunachal Pradesh' },\n { code: '13', name: 'Nagaland' },\n { code: '14', name: 'Manipur' },\n { code: '15', name: 'Mizoram' },\n { code: '16', name: 'Tripura' },\n { code: '17', name: 'Meghalaya' },\n { code: '18', name: 'Assam' },\n { code: '19', name: 'West Bengal' },\n { code: '20', name: 'Jharkhand' },\n { code: '21', name: 'Odisha' },\n { code: '22', name: 'Chhattisgarh' },\n { code: '23', name: 'Madhya Pradesh' },\n { code: '24', name: 'Gujarat' },\n { code: '26', name: 'Dadra and Nagar Haveli and Daman and Diu' },\n { code: '27', name: 'Maharashtra' },\n { code: '29', name: 'Karnataka' },\n { code: '30', name: 'Goa' },\n { code: '31', name: 'Lakshadweep' },\n { code: '32', name: 'Kerala' },\n { code: '33', name: 'Tamil Nadu' },\n { code: '34', name: 'Puducherry' },\n { code: '35', name: 'Andaman and Nicobar Islands' },\n { code: '36', name: 'Telangana' },\n { code: '37', name: 'Andhra Pradesh' },\n { code: '38', name: 'Ladakh' },\n] as const;\nexport type GstStateCode = (typeof GST_STATES)[number]['code'];\nexport const GST_STATE_CODE_VALUES = GST_STATES.map((s) => s.code) as [\n GstStateCode,\n ...GstStateCode[],\n];\nexport const gstStateCodeSchema = z.enum(GST_STATE_CODE_VALUES);\n\n/** The state's name for its code, as an invoice prints it. */\nexport function gstStateName(code: GstStateCode): string {\n return GST_STATES.find((s) => s.code === code)?.name ?? code;\n}\n\n/** GST is 18% on these services, inside every price. */\nexport const GST_RATE_PERCENT = 18;\n\nconst GSTIN_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';\nconst GSTIN_PATTERN = /^\\d{2}[A-Z]{5}\\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/;\n\n/**\n * Whether a GSTIN's 15th character is the check character of the first 14\n * (the GSTN's base-36 Luhn variant). Catches a mistyped digit, which the\n * pattern alone does not: a B2B invoice with a wrong GSTIN costs the buyer\n * their input credit.\n */\nexport function gstinChecksumValid(gstin: string): boolean {\n if (!GSTIN_PATTERN.test(gstin)) return false;\n let sum = 0;\n for (let i = 0; i < 14; i++) {\n const value = GSTIN_CHARS.indexOf(gstin.charAt(i));\n const product = value * (i % 2 === 0 ? 1 : 2);\n sum += Math.floor(product / 36) + (product % 36);\n }\n const check = (36 - (sum % 36)) % 36;\n return gstin.charAt(14) === GSTIN_CHARS.charAt(check);\n}\n\n/** A GSTIN, upper-cased, pattern AND check character. */\nexport const gstinSchema = z\n .string()\n .trim()\n .transform((v) => v.toUpperCase())\n .refine(gstinChecksumValid, { error: VALIDATION_MESSAGE.gstinInvalid });\n\n/**\n * Who is buying, for the invoice. The state is the place of supply and\n * decides the tax. With a GSTIN (a business claiming input credit) the\n * invoice is B2B: it must carry the buyer's legal name and address, and the\n * state is the GSTIN's own.\n */\nexport const billingDetailsSchema = z\n .object({\n stateCode: gstStateCodeSchema,\n gstin: gstinSchema.optional(),\n legalName: z.string().trim().min(2).max(BILLING_NAME_MAX).optional(),\n address: z.string().trim().min(10).max(BILLING_ADDRESS_MAX).optional(),\n })\n .refine((body) => !body.gstin || body.gstin.slice(0, 2) === body.stateCode, {\n path: ['stateCode'],\n error: VALIDATION_MESSAGE.gstinStateMismatch,\n })\n .refine((body) => !body.gstin || body.legalName !== undefined, {\n path: ['legalName'],\n error: VALIDATION_MESSAGE.gstinNeedsNameAndAddress,\n })\n .refine((body) => !body.gstin || body.address !== undefined, {\n path: ['address'],\n error: VALIDATION_MESSAGE.gstinNeedsNameAndAddress,\n });\nexport type BillingDetails = z.infer<typeof billingDetailsSchema>;\n"]}
|
|
@@ -121,8 +121,21 @@ export type ChatAuthToken = z.infer<typeof chatAuthTokenSchema>;
|
|
|
121
121
|
*/
|
|
122
122
|
export declare const openChatBodySchema: z.ZodObject<{
|
|
123
123
|
userId: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
124
|
+
useAllowance: z.ZodOptional<z.ZodBoolean>;
|
|
124
125
|
}, z.core.$strip>;
|
|
125
126
|
export type OpenChatBody = z.infer<typeof openChatBodySchema>;
|
|
127
|
+
/**
|
|
128
|
+
* How a conversation came to be allowed (0.12.0): they know each other, it
|
|
129
|
+
* used the opener's allowance, or the opener was acting as a staff role,
|
|
130
|
+
* which reaches anyone. ⚠ Stored: append only.
|
|
131
|
+
*/
|
|
132
|
+
export declare const CHAT_OPENED_VIA_VALUES: readonly ["contact", "allowance", "staff"];
|
|
133
|
+
export declare const chatOpenedViaSchema: z.ZodEnum<{
|
|
134
|
+
staff: "staff";
|
|
135
|
+
contact: "contact";
|
|
136
|
+
allowance: "allowance";
|
|
137
|
+
}>;
|
|
138
|
+
export type ChatOpenedVia = z.infer<typeof chatOpenedViaSchema>;
|
|
126
139
|
/**
|
|
127
140
|
* The conversation to navigate to. `201` with `wasCreated: true` the first
|
|
128
141
|
* time, `200` and `false` on every later open of the same pair.
|
|
@@ -130,8 +143,79 @@ export type OpenChatBody = z.infer<typeof openChatBodySchema>;
|
|
|
130
143
|
export declare const openChatResponseSchema: z.ZodObject<{
|
|
131
144
|
conversationId: z.ZodString;
|
|
132
145
|
wasCreated: z.ZodBoolean;
|
|
146
|
+
via: z.ZodEnum<{
|
|
147
|
+
staff: "staff";
|
|
148
|
+
contact: "contact";
|
|
149
|
+
allowance: "allowance";
|
|
150
|
+
}>;
|
|
133
151
|
}, z.core.$strip>;
|
|
134
152
|
export type OpenChatResponse = z.infer<typeof openChatResponseSchema>;
|
|
153
|
+
/**
|
|
154
|
+
* Whether opening a conversation with someone would work, and what it would
|
|
155
|
+
* cost, so the button can say so BEFORE it is tapped
|
|
156
|
+
* (`GET /api/v1/chat/reach/:userId`):
|
|
157
|
+
*
|
|
158
|
+
* contact they know each other: free
|
|
159
|
+
* allowance uses one of `left` new people this month: confirm first
|
|
160
|
+
* allowance_exhausted none left this month (`resetsAt`)
|
|
161
|
+
* plan_required they do not know each other and the asker has no plan
|
|
162
|
+
* membership_required the asker cannot chat at all (a viewer)
|
|
163
|
+
* not_accepted the other person takes conversations only from people
|
|
164
|
+
* they know, or cannot chat (one answer for both)
|
|
165
|
+
* staff the asker acts as a staff role, which starts a
|
|
166
|
+
* conversation with anyone who can chat: free, past
|
|
167
|
+
* their "people I know only" (the user, 2026-10-12)
|
|
168
|
+
*/
|
|
169
|
+
export declare const CHAT_REACH_VALUES: readonly ["contact", "allowance", "allowance_exhausted", "plan_required", "membership_required", "not_accepted", "staff"];
|
|
170
|
+
export declare const chatReachKindSchema: z.ZodEnum<{
|
|
171
|
+
staff: "staff";
|
|
172
|
+
contact: "contact";
|
|
173
|
+
allowance: "allowance";
|
|
174
|
+
allowance_exhausted: "allowance_exhausted";
|
|
175
|
+
plan_required: "plan_required";
|
|
176
|
+
membership_required: "membership_required";
|
|
177
|
+
not_accepted: "not_accepted";
|
|
178
|
+
}>;
|
|
179
|
+
export type ChatReachKind = z.infer<typeof chatReachKindSchema>;
|
|
180
|
+
export declare const chatReachSchema: z.ZodObject<{
|
|
181
|
+
reach: z.ZodEnum<{
|
|
182
|
+
staff: "staff";
|
|
183
|
+
contact: "contact";
|
|
184
|
+
allowance: "allowance";
|
|
185
|
+
allowance_exhausted: "allowance_exhausted";
|
|
186
|
+
plan_required: "plan_required";
|
|
187
|
+
membership_required: "membership_required";
|
|
188
|
+
not_accepted: "not_accepted";
|
|
189
|
+
}>;
|
|
190
|
+
left: z.ZodNullable<z.ZodNumber>;
|
|
191
|
+
resetsAt: z.ZodNullable<z.ZodISODateTime>;
|
|
192
|
+
}, z.core.$strip>;
|
|
193
|
+
export type ChatReach = z.infer<typeof chatReachSchema>;
|
|
194
|
+
export declare const chatReachParamsSchema: z.ZodObject<{
|
|
195
|
+
userId: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
196
|
+
}, z.core.$strip>;
|
|
197
|
+
export type ChatReachParams = z.infer<typeof chatReachParamsSchema>;
|
|
198
|
+
/**
|
|
199
|
+
* Who may start a conversation with me (0.12.0). People I know always may.
|
|
200
|
+
* ⚠ Stored: append only.
|
|
201
|
+
*
|
|
202
|
+
* contacts only people I know
|
|
203
|
+
* contacts_and_plans also Premium and Business members (the default)
|
|
204
|
+
*/
|
|
205
|
+
export declare const MESSAGE_FROM_VALUES: readonly ["contacts", "contacts_and_plans"];
|
|
206
|
+
export declare const messageFromSchema: z.ZodEnum<{
|
|
207
|
+
contacts: "contacts";
|
|
208
|
+
contacts_and_plans: "contacts_and_plans";
|
|
209
|
+
}>;
|
|
210
|
+
export type MessageFrom = z.infer<typeof messageFromSchema>;
|
|
211
|
+
/** `GET` and `PUT /api/v1/me/messaging`. */
|
|
212
|
+
export declare const messagingSettingsSchema: z.ZodObject<{
|
|
213
|
+
from: z.ZodEnum<{
|
|
214
|
+
contacts: "contacts";
|
|
215
|
+
contacts_and_plans: "contacts_and_plans";
|
|
216
|
+
}>;
|
|
217
|
+
}, z.core.$strip>;
|
|
218
|
+
export type MessagingSettings = z.infer<typeof messagingSettingsSchema>;
|
|
135
219
|
/**
|
|
136
220
|
* `POST /api/v1/chat/participants`: names and avatars for the people in the
|
|
137
221
|
* viewer's conversations.
|
|
@@ -170,6 +254,7 @@ export type ChatParticipantsResponse = z.infer<typeof chatParticipantsResponseSc
|
|
|
170
254
|
*/
|
|
171
255
|
export declare const chatInvitationBodySchema: z.ZodObject<{
|
|
172
256
|
userId: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
257
|
+
useAllowance: z.ZodOptional<z.ZodBoolean>;
|
|
173
258
|
}, z.core.$strip>;
|
|
174
259
|
/** @deprecated Since 0.2.0: use `OpenChatBody`. */
|
|
175
260
|
export type ChatInvitationBody = OpenChatBody;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/domains/chat/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,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAIhE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB;;;;;iBAQ3B,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAI1D;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,KAAK,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,QAAU,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,mBAAmB;;;;;iBAQ9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CA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;;;;;iBAEzC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAStF;;;GAGG;AACH,eAAO,MAAM,wBAAwB;;;iBAAqB,CAAC;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"}
|
|
@@ -130,7 +130,21 @@ export const chatAuthTokenSchema = z.object({
|
|
|
130
130
|
export const openChatBodySchema = z.object({
|
|
131
131
|
/** The OTHER participant. The viewer is taken from the credential, never the body. */
|
|
132
132
|
userId: objectIdSchema,
|
|
133
|
+
/**
|
|
134
|
+
* Agreement to use one of this month's allowance (0.12.0), when they do
|
|
135
|
+
* not know the other person. Without it such an open is refused with
|
|
136
|
+
* `MESSAGE_ALLOWANCE_UNCONFIRMED` and nothing is spent: an allowance is
|
|
137
|
+
* never used by accident. Ignored for someone they know.
|
|
138
|
+
*/
|
|
139
|
+
useAllowance: z.boolean().optional(),
|
|
133
140
|
});
|
|
141
|
+
/**
|
|
142
|
+
* How a conversation came to be allowed (0.12.0): they know each other, it
|
|
143
|
+
* used the opener's allowance, or the opener was acting as a staff role,
|
|
144
|
+
* which reaches anyone. ⚠ Stored: append only.
|
|
145
|
+
*/
|
|
146
|
+
export const CHAT_OPENED_VIA_VALUES = ['contact', 'allowance', 'staff'];
|
|
147
|
+
export const chatOpenedViaSchema = z.enum(CHAT_OPENED_VIA_VALUES);
|
|
134
148
|
/**
|
|
135
149
|
* The conversation to navigate to. `201` with `wasCreated: true` the first
|
|
136
150
|
* time, `200` and `false` on every later open of the same pair.
|
|
@@ -138,7 +152,55 @@ export const openChatBodySchema = z.object({
|
|
|
138
152
|
export const openChatResponseSchema = z.object({
|
|
139
153
|
conversationId: z.string().min(1),
|
|
140
154
|
wasCreated: z.boolean(),
|
|
155
|
+
/** 0.12.0. Every later open of the same pair is `contact`: they have a conversation now. */
|
|
156
|
+
via: chatOpenedViaSchema,
|
|
157
|
+
});
|
|
158
|
+
// ─── Who may start a conversation with whom (0.12.0) ─────────────────────────
|
|
159
|
+
/**
|
|
160
|
+
* Whether opening a conversation with someone would work, and what it would
|
|
161
|
+
* cost, so the button can say so BEFORE it is tapped
|
|
162
|
+
* (`GET /api/v1/chat/reach/:userId`):
|
|
163
|
+
*
|
|
164
|
+
* contact they know each other: free
|
|
165
|
+
* allowance uses one of `left` new people this month: confirm first
|
|
166
|
+
* allowance_exhausted none left this month (`resetsAt`)
|
|
167
|
+
* plan_required they do not know each other and the asker has no plan
|
|
168
|
+
* membership_required the asker cannot chat at all (a viewer)
|
|
169
|
+
* not_accepted the other person takes conversations only from people
|
|
170
|
+
* they know, or cannot chat (one answer for both)
|
|
171
|
+
* staff the asker acts as a staff role, which starts a
|
|
172
|
+
* conversation with anyone who can chat: free, past
|
|
173
|
+
* their "people I know only" (the user, 2026-10-12)
|
|
174
|
+
*/
|
|
175
|
+
export const CHAT_REACH_VALUES = [
|
|
176
|
+
'contact',
|
|
177
|
+
'allowance',
|
|
178
|
+
'allowance_exhausted',
|
|
179
|
+
'plan_required',
|
|
180
|
+
'membership_required',
|
|
181
|
+
'not_accepted',
|
|
182
|
+
'staff',
|
|
183
|
+
];
|
|
184
|
+
export const chatReachKindSchema = z.enum(CHAT_REACH_VALUES);
|
|
185
|
+
export const chatReachSchema = z.object({
|
|
186
|
+
reach: chatReachKindSchema,
|
|
187
|
+
/** For `allowance`: how many new people are left this month, this one included. */
|
|
188
|
+
left: z.number().int().nonnegative().nullable(),
|
|
189
|
+
/** For `allowance` and `allowance_exhausted`: when the month's count starts again. */
|
|
190
|
+
resetsAt: z.iso.datetime().nullable(),
|
|
141
191
|
});
|
|
192
|
+
export const chatReachParamsSchema = z.object({ userId: objectIdSchema });
|
|
193
|
+
/**
|
|
194
|
+
* Who may start a conversation with me (0.12.0). People I know always may.
|
|
195
|
+
* ⚠ Stored: append only.
|
|
196
|
+
*
|
|
197
|
+
* contacts only people I know
|
|
198
|
+
* contacts_and_plans also Premium and Business members (the default)
|
|
199
|
+
*/
|
|
200
|
+
export const MESSAGE_FROM_VALUES = ['contacts', 'contacts_and_plans'];
|
|
201
|
+
export const messageFromSchema = z.enum(MESSAGE_FROM_VALUES);
|
|
202
|
+
/** `GET` and `PUT /api/v1/me/messaging`. */
|
|
203
|
+
export const messagingSettingsSchema = z.object({ from: messageFromSchema });
|
|
142
204
|
// ─── Participants ────────────────────────────────────────────────────────────
|
|
143
205
|
/**
|
|
144
206
|
* `POST /api/v1/chat/participants`: names and avatars for the people in the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../src/domains/chat/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAyB,CAAC;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAG9D,gFAAgF;AAEhF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,yEAAyE;IACzE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACvB,sDAAsD;IACtD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,mEAAmE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,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,QAAQ,EAAE,cAAc;IACxB,2EAA2E;IAC3E,SAAS,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAGH;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,MAAM,CAAC;IACrD,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,qBAAqB,CAAC;CAC1D,CAAC,CAAC;AAGH,gFAAgF;AAChF,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,0BAA0B;AAE1B;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;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/domains/chat\n */\n\nimport { z } from 'zod';\nimport { objectIdSchema, usernameSchema } from '../../core/common.js';\nimport { CHAT_PARTICIPANTS_MAX } from '../../core/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"]}
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../src/domains/chat/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAyB,CAAC;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAG9D,gFAAgF;AAEhF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,yEAAyE;IACzE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACvB,sDAAsD;IACtD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,mEAAmE;IACnE,SAAS,EAAE,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,CAAC,CAAC;AAGH,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,QAAQ,EAAE,cAAc;IACxB,2EAA2E;IAC3E,SAAS,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAGH;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,MAAM,CAAC;IACrD,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,qBAAqB,CAAC;CAC1D,CAAC,CAAC;AAGH,gFAAgF;AAChF,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,0BAA0B;AAE1B;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;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/domains/chat\n */\n\nimport { z } from 'zod';\nimport { objectIdSchema, usernameSchema } from '../../core/common.js';\nimport { CHAT_PARTICIPANTS_MAX } from '../../core/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 /**\n * Agreement to use one of this month's allowance (0.12.0), when they do\n * not know the other person. Without it such an open is refused with\n * `MESSAGE_ALLOWANCE_UNCONFIRMED` and nothing is spent: an allowance is\n * never used by accident. Ignored for someone they know.\n */\n useAllowance: z.boolean().optional(),\n});\nexport type OpenChatBody = z.infer<typeof openChatBodySchema>;\n\n/**\n * How a conversation came to be allowed (0.12.0): they know each other, it\n * used the opener's allowance, or the opener was acting as a staff role,\n * which reaches anyone. ⚠ Stored: append only.\n */\nexport const CHAT_OPENED_VIA_VALUES = ['contact', 'allowance', 'staff'] as const;\nexport const chatOpenedViaSchema = z.enum(CHAT_OPENED_VIA_VALUES);\nexport type ChatOpenedVia = z.infer<typeof chatOpenedViaSchema>;\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 /** 0.12.0. Every later open of the same pair is `contact`: they have a conversation now. */\n via: chatOpenedViaSchema,\n});\nexport type OpenChatResponse = z.infer<typeof openChatResponseSchema>;\n\n// ─── Who may start a conversation with whom (0.12.0) ─────────────────────────\n\n/**\n * Whether opening a conversation with someone would work, and what it would\n * cost, so the button can say so BEFORE it is tapped\n * (`GET /api/v1/chat/reach/:userId`):\n *\n * contact they know each other: free\n * allowance uses one of `left` new people this month: confirm first\n * allowance_exhausted none left this month (`resetsAt`)\n * plan_required they do not know each other and the asker has no plan\n * membership_required the asker cannot chat at all (a viewer)\n * not_accepted the other person takes conversations only from people\n * they know, or cannot chat (one answer for both)\n * staff the asker acts as a staff role, which starts a\n * conversation with anyone who can chat: free, past\n * their \"people I know only\" (the user, 2026-10-12)\n */\nexport const CHAT_REACH_VALUES = [\n 'contact',\n 'allowance',\n 'allowance_exhausted',\n 'plan_required',\n 'membership_required',\n 'not_accepted',\n 'staff',\n] as const;\nexport const chatReachKindSchema = z.enum(CHAT_REACH_VALUES);\nexport type ChatReachKind = z.infer<typeof chatReachKindSchema>;\n\nexport const chatReachSchema = z.object({\n reach: chatReachKindSchema,\n /** For `allowance`: how many new people are left this month, this one included. */\n left: z.number().int().nonnegative().nullable(),\n /** For `allowance` and `allowance_exhausted`: when the month's count starts again. */\n resetsAt: z.iso.datetime().nullable(),\n});\nexport type ChatReach = z.infer<typeof chatReachSchema>;\n\nexport const chatReachParamsSchema = z.object({ userId: objectIdSchema });\nexport type ChatReachParams = z.infer<typeof chatReachParamsSchema>;\n\n/**\n * Who may start a conversation with me (0.12.0). People I know always may.\n * ⚠ Stored: append only.\n *\n * contacts only people I know\n * contacts_and_plans also Premium and Business members (the default)\n */\nexport const MESSAGE_FROM_VALUES = ['contacts', 'contacts_and_plans'] as const;\nexport const messageFromSchema = z.enum(MESSAGE_FROM_VALUES);\nexport type MessageFrom = z.infer<typeof messageFromSchema>;\n\n/** `GET` and `PUT /api/v1/me/messaging`. */\nexport const messagingSettingsSchema = z.object({ from: messageFromSchema });\nexport type MessagingSettings = z.infer<typeof messagingSettingsSchema>;\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"]}
|