@iveri/contracts 0.81.0 → 0.82.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.
@@ -0,0 +1,7 @@
1
+ /** Who may start a conversation inside an outside app. */
2
+ export declare enum ChatAppConversationMode {
3
+ /** Only the app's server, through `PUT /server/conversations`. Its users use what it opened. */
4
+ SERVER = "server",
5
+ /** Its users too, naming each other by the app's own ids. There is no search and no contact list. */
6
+ USERS = "users"
7
+ }
@@ -0,0 +1,8 @@
1
+ /** Who may start a conversation inside an outside app. */
2
+ export var ChatAppConversationMode;
3
+ (function (ChatAppConversationMode) {
4
+ /** Only the app's server, through `PUT /server/conversations`. Its users use what it opened. */
5
+ ChatAppConversationMode["SERVER"] = "server";
6
+ /** Its users too, naming each other by the app's own ids. There is no search and no contact list. */
7
+ ChatAppConversationMode["USERS"] = "users";
8
+ })(ChatAppConversationMode || (ChatAppConversationMode = {}));
@@ -0,0 +1,12 @@
1
+ /** The `typ` claim of a socket ticket. A token without it is never read as a ticket. */
2
+ export declare const CHAT_SOCKET_TICKET_TYPE = "chat-socket";
3
+ /** What an app's secret looks like: this prefix, then 32 random bytes in base64url. */
4
+ export declare const CHAT_APP_SECRET_PREFIX = "bs_";
5
+ /** At most this many secrets of one app work at once, so a rotation never needs an outage and never piles up. */
6
+ export declare const CHAT_APP_MAX_ACTIVE_SECRETS = 2;
7
+ /** The longest an app's token may live, from `iat` to `exp`. */
8
+ export declare const CHAT_APP_TOKEN_MAX_TTL_SECONDS = 86400;
9
+ /** A minted token's lifetime when the server does not say. */
10
+ export declare const CHAT_APP_TOKEN_DEFAULT_TTL_SECONDS = 3600;
11
+ /** The longest id an app may give one of its users. */
12
+ export declare const CHAT_EXTERNAL_USER_ID_MAX_LENGTH = 255;
@@ -0,0 +1,12 @@
1
+ /** The `typ` claim of a socket ticket. A token without it is never read as a ticket. */
2
+ export const CHAT_SOCKET_TICKET_TYPE = 'chat-socket';
3
+ /** What an app's secret looks like: this prefix, then 32 random bytes in base64url. */
4
+ export const CHAT_APP_SECRET_PREFIX = 'bs_';
5
+ /** At most this many secrets of one app work at once, so a rotation never needs an outage and never piles up. */
6
+ export const CHAT_APP_MAX_ACTIVE_SECRETS = 2;
7
+ /** The longest an app's token may live, from `iat` to `exp`. */
8
+ export const CHAT_APP_TOKEN_MAX_TTL_SECONDS = 86_400;
9
+ /** A minted token's lifetime when the server does not say. */
10
+ export const CHAT_APP_TOKEN_DEFAULT_TTL_SECONDS = 3_600;
11
+ /** The longest id an app may give one of its users. */
12
+ export const CHAT_EXTERNAL_USER_ID_MAX_LENGTH = 255;
@@ -0,0 +1,140 @@
1
+ import type { IsoDateTime } from '../../type/iso-date-time.type.js';
2
+ import type { Nullable } from '../../type/nil.type.js';
3
+ import type { UUID } from '../../type/uuid.type.js';
4
+ import type { ChatAppConversationMode } from './chat-app-conversation-mode.enum.js';
5
+ import type { CHAT_SOCKET_TICKET_TYPE } from './chat-app.constant.js';
6
+ import type { OpenEmbeddedChatRequest } from './chat-embed.type.js';
7
+ import type { ChatMessageKind } from './chat-message-kind.enum.js';
8
+ import type { ChatPersonStatus } from './chat-person-status.enum.js';
9
+ /**
10
+ * Baasi inside another company's product. An app is its own Baasi tenant, so its users, conversations and
11
+ * moderation queue are kept apart from every other app's, and its id is the `iss` of every token signed for it.
12
+ */
13
+ export interface ChatApp {
14
+ id: UUID;
15
+ name: string;
16
+ conversationMode: ChatAppConversationMode;
17
+ /** Tokens signed before this moment are refused, for every user of the app. */
18
+ tokensNotBefore: Nullable<IsoDateTime>;
19
+ secrets: ChatAppSecretSummary[];
20
+ createdAt: IsoDateTime;
21
+ updatedAt: IsoDateTime;
22
+ }
23
+ /** A secret as it is listed afterwards: never the value, only enough to tell two apart. */
24
+ export interface ChatAppSecretSummary {
25
+ id: UUID;
26
+ /** The last four characters, so a person can tell which one a server holds. */
27
+ hint: string;
28
+ createdAt: IsoDateTime;
29
+ revokedAt: Nullable<IsoDateTime>;
30
+ }
31
+ /** `POST /apps/:appId/secrets`. The only answer that ever holds the value: it is not stored readable. */
32
+ export interface CreatedChatAppSecret extends ChatAppSecretSummary {
33
+ /** `bs_` and 32 random bytes in base64url. */
34
+ secret: string;
35
+ }
36
+ export interface CreateChatAppRequest {
37
+ name: string;
38
+ /** Omitted means `server`: only the company's server opens conversations. */
39
+ conversationMode?: ChatAppConversationMode;
40
+ }
41
+ export interface UpdateChatAppRequest {
42
+ name?: string;
43
+ conversationMode?: ChatAppConversationMode;
44
+ }
45
+ /** `PUT /server/users/:userId`, where `userId` is the app's own id for the person. */
46
+ export interface UpsertChatAppUserRequest {
47
+ displayName: string;
48
+ /** An address the app already serves publicly. `null` removes it. */
49
+ avatarUrl?: Nullable<string>;
50
+ }
51
+ /** A user of an app, as its server sees them. */
52
+ export interface ChatAppUser {
53
+ /** Baasi's own id for them, which every conversation and message names. */
54
+ userId: UUID;
55
+ externalId: string;
56
+ displayName: Nullable<string>;
57
+ avatarUrl: Nullable<string>;
58
+ status: ChatPersonStatus;
59
+ /** Their tokens signed before this moment are refused. */
60
+ tokensNotBefore: Nullable<IsoDateTime>;
61
+ createdAt: IsoDateTime;
62
+ }
63
+ /** `POST /server/tokens`. For a company that would rather not sign a token itself. */
64
+ export interface MintChatTokenRequest {
65
+ /** The app's own id for the person, 1 to 255 characters. */
66
+ userId: string;
67
+ /** Omitted means an hour. At most a day. */
68
+ ttlSeconds?: number;
69
+ }
70
+ export interface ChatToken {
71
+ token: string;
72
+ expiresAt: IsoDateTime;
73
+ }
74
+ /**
75
+ * `PUT /server/conversations`: the embed request, with each participant's `userId` read as the app's own id for
76
+ * them rather than a Baasi id.
77
+ */
78
+ export type OpenServerChatRequest = OpenEmbeddedChatRequest;
79
+ /** `GET /server/users/:userId/export`: everything Baasi holds about one user of an app. */
80
+ export interface ChatAppUserExport {
81
+ user: ChatAppUser;
82
+ conversations: ChatAppUserExportConversation[];
83
+ messages: ChatAppUserExportMessage[];
84
+ reactions: ChatAppUserExportReaction[];
85
+ devices: ChatAppUserExportDevice[];
86
+ exportedAt: IsoDateTime;
87
+ }
88
+ export interface ChatAppUserExportConversation {
89
+ conversationId: UUID;
90
+ kind: string;
91
+ title: Nullable<string>;
92
+ context: Nullable<{
93
+ product: string;
94
+ type: string;
95
+ id: string;
96
+ }>;
97
+ status: string;
98
+ joinedAt: IsoDateTime;
99
+ }
100
+ export interface ChatAppUserExportMessage {
101
+ messageId: UUID;
102
+ conversationId: UUID;
103
+ seq: number;
104
+ kind: ChatMessageKind;
105
+ text: Nullable<string>;
106
+ attachmentCount: number;
107
+ sentAt: IsoDateTime;
108
+ editedAt: Nullable<IsoDateTime>;
109
+ deletedAt: Nullable<IsoDateTime>;
110
+ }
111
+ export interface ChatAppUserExportReaction {
112
+ messageId: UUID;
113
+ emoji: string;
114
+ reactedAt: IsoDateTime;
115
+ }
116
+ export interface ChatAppUserExportDevice {
117
+ installationId: string;
118
+ platform: string;
119
+ locale: Nullable<string>;
120
+ registeredAt: IsoDateTime;
121
+ }
122
+ /**
123
+ * `POST /realtime/ticket`. What a socket presents to `chat-realtime` when the person signed in with an app's token,
124
+ * so the app's secret stays in `chat-api`.
125
+ */
126
+ export interface ChatSocketTicket {
127
+ ticket: string;
128
+ /** The presented token's own expiry: a ticket never outlives what it was traded for. */
129
+ expiresAt: IsoDateTime;
130
+ }
131
+ /** A socket ticket's claims, signed HS256 with the secret `chat-api` and `chat-realtime` share. */
132
+ export interface ChatSocketTicketClaims {
133
+ typ: typeof CHAT_SOCKET_TICKET_TYPE;
134
+ /** The tenant: an app's id, or an Iveri tenant. */
135
+ tid: UUID;
136
+ /** The person's Baasi id. */
137
+ sub: UUID;
138
+ iat: number;
139
+ exp: number;
140
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -103,20 +103,29 @@ export interface ChatInboxPage {
103
103
  }
104
104
  /** What `GET /conversations` can be narrowed to. */
105
105
  export type ChatInboxFolder = 'inbox' | 'requests' | 'archived';
106
+ /**
107
+ * Exactly one of the two. Inside an outside app that lets its users start conversations, a person names the
108
+ * other by the app's own id for them, since that is the only id the app knows.
109
+ */
106
110
  export interface StartDirectChatRequest {
107
- userId: UUID;
111
+ userId?: UUID;
112
+ externalUserId?: string;
108
113
  }
114
+ /** Exactly one of the two lists, as with {@link StartDirectChatRequest}. */
109
115
  export interface CreateGroupChatRequest {
110
116
  title: string;
111
- memberUserIds: UUID[];
117
+ memberUserIds?: UUID[];
118
+ memberExternalIds?: string[];
112
119
  }
113
120
  export interface UpdateGroupChatRequest {
114
121
  title?: string;
115
122
  /** An uploaded photo attachment. `null` removes the photograph. */
116
123
  avatarAttachmentId?: Nullable<UUID>;
117
124
  }
125
+ /** Exactly one of the two lists, as with {@link StartDirectChatRequest}. */
118
126
  export interface AddChatMembersRequest {
119
- userIds: UUID[];
127
+ userIds?: UUID[];
128
+ externalUserIds?: string[];
120
129
  }
121
130
  export interface UpdateChatMemberRequest {
122
131
  role: ChatParticipantRole;
@@ -75,6 +75,8 @@ export interface DecideChatCaseRequest {
75
75
  export interface ChatStaffPerson {
76
76
  userId: UUID;
77
77
  tenantId: UUID;
78
+ /** The id an outside app knows this person by. Null for everybody signed in through Iveri. */
79
+ externalId: Nullable<string>;
78
80
  handle: Nullable<string>;
79
81
  displayName: Nullable<string>;
80
82
  status: ChatPersonStatus;
@@ -6,6 +6,8 @@ import type { ChatPersonStatus } from './chat-person-status.enum.js';
6
6
  /** Somebody as another person sees them. Nothing here is an email address or a phone number. */
7
7
  export interface ChatPersonCard {
8
8
  userId: UUID;
9
+ /** The id an outside app knows this person by. Null for everybody signed in through Iveri. */
10
+ externalId: Nullable<string>;
9
11
  displayName: string;
10
12
  /** Only in the Baasi network. A person inside a product has none. */
11
13
  handle: Nullable<string>;
@@ -22,6 +24,8 @@ export interface ChatSettings {
22
24
  /** The signed-in person's own profile. */
23
25
  export interface ChatProfile {
24
26
  userId: UUID;
27
+ /** The id an outside app knows me by. Null for everybody signed in through Iveri. */
28
+ externalId: Nullable<string>;
25
29
  /** True in the Baasi tenant. Elsewhere a person only uses conversations their product opened. */
26
30
  isNetwork: boolean;
27
31
  /** False until a Baasi person has chosen a handle and a name. */
@@ -1,3 +1,6 @@
1
+ export * from './chat-app-conversation-mode.enum.js';
2
+ export * from './chat-app.constant.js';
3
+ export * from './chat-app.type.js';
1
4
  export * from './chat-attachment-kind.enum.js';
2
5
  export * from './chat-attachment.type.js';
3
6
  export * from './chat-case-decision.enum.js';
@@ -1,3 +1,6 @@
1
+ export * from './chat-app-conversation-mode.enum.js';
2
+ export * from './chat-app.constant.js';
3
+ export * from './chat-app.type.js';
1
4
  export * from './chat-attachment-kind.enum.js';
2
5
  export * from './chat-attachment.type.js';
3
6
  export * from './chat-case-decision.enum.js';
@@ -608,7 +608,12 @@ export declare enum UserPermission {
608
608
  /** Suspend, ban or reinstate somebody without a report behind it. */
609
609
  CHAT_PERSON_SANCTION = "chat:person:sanction",
610
610
  /** Read the record of what staff looked at and did. */
611
- CHAT_AUDIT_READ = "chat:audit:read"
611
+ CHAT_AUDIT_READ = "chat:audit:read",
612
+ /**
613
+ * Run Baasi inside another company's product: create its apps, issue and revoke their secrets, change who may
614
+ * start conversations, and refuse tokens signed before a moment. Held by that company's own staff.
615
+ */
616
+ CHAT_APP_MANAGE = "chat:app:manage"
612
617
  }
613
618
  /**
614
619
  * Every member, for seeding the owner role and validating custom-role input.
@@ -674,6 +674,11 @@ export var UserPermission;
674
674
  UserPermission["CHAT_PERSON_SANCTION"] = "chat:person:sanction";
675
675
  /** Read the record of what staff looked at and did. */
676
676
  UserPermission["CHAT_AUDIT_READ"] = "chat:audit:read";
677
+ /**
678
+ * Run Baasi inside another company's product: create its apps, issue and revoke their secrets, change who may
679
+ * start conversations, and refuse tokens signed before a moment. Held by that company's own staff.
680
+ */
681
+ UserPermission["CHAT_APP_MANAGE"] = "chat:app:manage";
677
682
  })(UserPermission || (UserPermission = {}));
678
683
  /**
679
684
  * Every member, for seeding the owner role and validating custom-role input.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iveri/contracts",
3
- "version": "0.81.0",
3
+ "version": "0.82.0",
4
4
  "description": "Wire contracts shared by every Iveri backend and frontend. Zero runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "repository": {