@raucheacho/phono-web 0.0.0-stage → 0.1.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/src/types.ts ADDED
@@ -0,0 +1,339 @@
1
+ // Les formes que renvoie l'API Phono.
2
+
3
+ export type IdentityKind = "human" | "agent" | "guest";
4
+
5
+ export interface PublicHandle {
6
+ id: string;
7
+ handle: string;
8
+ display_name: string;
9
+ kind: IdentityKind;
10
+ /** La photo de profil, s'il y en a une : GET /v1/avatars/{avatar_id}, sans jeton. */
11
+ avatar_id?: string;
12
+ }
13
+
14
+ /** `GET /v1/me` : l'identité, et son organisation. */
15
+ export interface Me {
16
+ handle: PublicHandle;
17
+ /** `kind` : « company » (transcription comprise) ou « personal ». */
18
+ org: { id: string; slug: string; name?: string; kind?: "company" | "personal"; record_calls: boolean };
19
+ }
20
+
21
+ export type ParticipantState = "invited" | "joined" | "left" | "declined" | "missed";
22
+
23
+ export interface Participant {
24
+ handle: PublicHandle;
25
+ state: ParticipantState;
26
+ recording_media_id?: string;
27
+ joined_at?: string;
28
+ left_at?: string;
29
+ }
30
+
31
+ export interface TranscriptLine {
32
+ speaker: string;
33
+ handle_id: string;
34
+ start_ms: number;
35
+ end_ms: number;
36
+ text: string;
37
+ }
38
+
39
+ export interface Call {
40
+ id: string;
41
+ initiated_by: PublicHandle;
42
+ status: "ringing" | "active" | "ended";
43
+ end_reason?: "completed" | "declined" | "missed" | "cancelled";
44
+ recorded: boolean;
45
+ transcript?: TranscriptLine[];
46
+ created_at: string;
47
+ answered_at?: string;
48
+ ended_at?: string;
49
+ participants: Participant[];
50
+ }
51
+
52
+ /** Ce qu'il faut pour rejoindre l'audio d'un appel. */
53
+ export interface AudioCredentials {
54
+ url: string;
55
+ token: string;
56
+ topic: string;
57
+ binary_mode: "multiplex";
58
+ event: string;
59
+ }
60
+
61
+ /** La réponse des routes qui créent ou décrochent un appel. */
62
+ export interface CallEnvelope {
63
+ call: Call;
64
+ audio?: AudioCredentials;
65
+ }
66
+
67
+ export interface Message {
68
+ id: string;
69
+ conversation_id: string;
70
+ sender_id: string;
71
+ kind: "text" | "voice" | "image" | "file" | "location" | "system";
72
+ body: string;
73
+ media_id?: string;
74
+ duration_ms?: number;
75
+ transcript?: string;
76
+ created_at: string;
77
+ read_at?: string;
78
+ /** Les réactions, une par personne. */
79
+ reactions?: Reaction[];
80
+ /** La forme d'onde d'un vocal : des niveaux de 0 à 100. */
81
+ waveform?: number[];
82
+ /** Le message auquel celui-ci répond, en résumé. */
83
+ reply_to?: MessageRef;
84
+ /** Une image ou un fichier (GET /v1/media/{media_id}). */
85
+ attachment?: Attachment;
86
+ /** Une position partagée. */
87
+ location?: Location;
88
+ delivered_at?: string;
89
+ edited_at?: string;
90
+ /** Supprimé pour tout le monde : il n'en reste que l'auteur et la date. */
91
+ deleted_at?: string;
92
+ /** Il passe la sourdine et réveille le téléphone. */
93
+ urgent?: boolean;
94
+ }
95
+
96
+ export interface MessageRef {
97
+ id: string;
98
+ sender_id: string;
99
+ kind: Message["kind"];
100
+ body: string;
101
+ deleted?: boolean;
102
+ }
103
+
104
+ export interface Attachment {
105
+ content_type: string;
106
+ filename?: string;
107
+ size_bytes: number;
108
+ width?: number;
109
+ height?: number;
110
+ }
111
+
112
+ export interface Location {
113
+ lat: number;
114
+ lng: number;
115
+ label?: string;
116
+ }
117
+
118
+ export interface GroupRef {
119
+ id: string;
120
+ title: string;
121
+ }
122
+
123
+ export interface Group extends GroupRef {
124
+ members: (PublicHandle & { role: "admin" | "member"; joined_at: string })[];
125
+ created_at: string;
126
+ }
127
+
128
+ export interface SearchHit {
129
+ message: Message;
130
+ peer?: PublicHandle;
131
+ group?: GroupRef;
132
+ }
133
+
134
+ export interface Transfer {
135
+ id: string;
136
+ conversation_id: string;
137
+ from: PublicHandle;
138
+ to: PublicHandle;
139
+ peer: PublicHandle;
140
+ note?: string;
141
+ created_at: string;
142
+ }
143
+
144
+ /** La réponse d'absence. `hours.days` : {"1": ["09:00", "18:00"]}, 1 = lundi. */
145
+ export interface Away {
146
+ message: string;
147
+ always?: boolean;
148
+ hours?: { tz: string; days: Record<string, [string, string]> };
149
+ }
150
+
151
+ /** Un emoji posé sur un message. */
152
+ export interface Reaction {
153
+ handle_id: string;
154
+ emoji: string;
155
+ }
156
+
157
+ /** Ce que l'on fait dans une conversation (événement `conversation.activity`). */
158
+ export type Activity = "typing" | "recording" | "idle";
159
+
160
+ /** `message.reacted` : `emoji` vide, la réaction de `reactor` a été retirée. */
161
+ export interface ReactionEventData {
162
+ message_id: string;
163
+ conversation_id: string;
164
+ reactor: PublicHandle;
165
+ emoji: string;
166
+ reactions: Reaction[];
167
+ }
168
+
169
+ /** `conversation.activity` : sans nouvelle après quelques secondes, considérez que c'est fini. */
170
+ export interface ActivityEventData {
171
+ from: PublicHandle;
172
+ state: Activity;
173
+ }
174
+
175
+ export interface Conversation {
176
+ id: string;
177
+ /** « direct » (`peer`) ou « group » (`group`). */
178
+ kind?: "direct" | "group";
179
+ peer?: PublicHandle;
180
+ group?: GroupRef;
181
+ last_message?: Message;
182
+ unread: number;
183
+ last_message_at: string;
184
+ muted_until?: string;
185
+ archived?: boolean;
186
+ }
187
+
188
+ /** `GET /v1/contacts` : l'équipe, les contacts établis hors de l'organisation,
189
+ * et les gens avec qui on a parlé récemment. */
190
+ export interface Contacts {
191
+ team: Contact[];
192
+ contacts: Contact[];
193
+ recent: Contact[];
194
+ }
195
+
196
+ /**
197
+ * Ce qu'est un identifiant pour vous. Hors de son organisation, on n'écrit et
198
+ * on n'appelle qu'un `contact` : une demande, que l'autre accepte.
199
+ */
200
+ export type Relation = "team" | "contact" | "outgoing" | "incoming" | "blocked" | "none";
201
+
202
+ /** `GET /v1/handles/{handle}` : l'identifiant, et votre relation avec lui. */
203
+ export interface LookedUpHandle extends PublicHandle {
204
+ relation: Relation;
205
+ }
206
+
207
+ /** Une demande de contact, reçue ou envoyée — ou un identifiant bloqué. */
208
+ export interface ContactRequest extends PublicHandle {
209
+ note?: string;
210
+ created_at: string;
211
+ }
212
+
213
+ export interface ContactRequests {
214
+ incoming: ContactRequest[];
215
+ outgoing: ContactRequest[];
216
+ }
217
+
218
+ /** `contact.requested` (from, note) et `contact.accepted` (by). */
219
+ export interface ContactEventData {
220
+ from?: PublicHandle;
221
+ by?: PublicHandle;
222
+ note?: string | null;
223
+ recipient: PublicHandle;
224
+ }
225
+
226
+ export interface Contact extends PublicHandle {
227
+ /** Le dernier échange, pour les contacts récents. */
228
+ last_at?: string;
229
+ }
230
+
231
+ /** L'enveloppe d'un événement : temps réel et webhooks. */
232
+ export interface PhonoEvent<T = unknown> {
233
+ id: string;
234
+ type: EventType;
235
+ created_at: string;
236
+ data: T;
237
+ }
238
+
239
+ export interface MessageEventData {
240
+ message: Message;
241
+ sender: PublicHandle;
242
+ recipient: PublicHandle;
243
+ }
244
+
245
+ export type EventType =
246
+ | "message.created"
247
+ | "message.transcribed"
248
+ | "message.read"
249
+ | "message.reacted"
250
+ | "conversation.activity"
251
+ | "message.updated"
252
+ | "message.deleted"
253
+ | "message.delivered"
254
+ | "conversation.transferred"
255
+ | "group.updated"
256
+ | "call.ringing"
257
+ | "call.updated"
258
+ | "call.answered"
259
+ | "call.ended"
260
+ | "call.transcribed"
261
+ | "contact.requested"
262
+ | "contact.accepted"
263
+ | "channel.updated"
264
+ | "channel.deleted"
265
+ | "channel.floor"
266
+ | "channel.invited"
267
+ | "transmission.created"
268
+ | "transmission.transcribed"
269
+ | (string & {});
270
+
271
+ // --- Le talkie ----------------------------------------------------------------------
272
+
273
+ export interface ChannelMember extends PublicHandle {
274
+ role: "admin" | "member";
275
+ /** « invited » tant que l'invitation n'est pas acceptée : il n'entend rien. */
276
+ status: "invited" | "active";
277
+ joined_at: string;
278
+ }
279
+
280
+ /**
281
+ * Un canal fermé, où l'on parle à tour de rôle. Celui d'une entreprise réunit
282
+ * son équipe ; celui d'un compte personnel, des contacts qui ont accepté son
283
+ * invitation (12 au plus).
284
+ */
285
+ export interface Channel {
286
+ id: string;
287
+ name: string;
288
+ personal: boolean;
289
+ max_members: number;
290
+ record: boolean;
291
+ created_at: string;
292
+ members: ChannelMember[];
293
+ last_transmission?: Transmission;
294
+ }
295
+
296
+ /** Une prise de parole : de la prise du canal à sa remise. */
297
+ export interface Transmission {
298
+ id: string;
299
+ channel_id: string;
300
+ speaker?: PublicHandle;
301
+ media_id?: string;
302
+ duration_ms: number;
303
+ gaps: number;
304
+ transcript?: string;
305
+ /** La forme de la voix, comme pour un vocal. */
306
+ waveform?: number[];
307
+ started_at: string;
308
+ ended_at: string;
309
+ }
310
+
311
+ /** De quoi rejoindre un canal sur Konet. */
312
+ export interface ChannelAudioCredentials {
313
+ url: string;
314
+ token: string;
315
+ topic: string;
316
+ binary_mode: "exclusive";
317
+ event: string;
318
+ expires_at: string;
319
+ }
320
+
321
+ /**
322
+ * Une annonce d'opérateur, jouée chez l'appelant quand un appel n'aboutit pas :
323
+ * - `busy` : « votre correspondant est actuellement en ligne » ;
324
+ * - `unavailable` : « … n'est pas disponible » (pas de réponse, refusé, pas en contact) ;
325
+ * - `not_assigned` : « l'identifiant Phono que vous avez demandé n'est pas attribué ».
326
+ */
327
+ export type AnnouncementCode = "busy" | "unavailable" | "not_assigned";
328
+
329
+ export interface Announcement {
330
+ code: AnnouncementCode;
331
+ lang: string;
332
+ /** Un Ogg Opus public : celui de votre organisation, ou celui de Phono. */
333
+ url: string;
334
+ }
335
+
336
+ export interface Announcements {
337
+ lang: string;
338
+ announcements: Record<AnnouncementCode, Announcement>;
339
+ }