bitsnap-react 1.18.0 → 1.19.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/AGENTS.md +106 -0
- package/README.md +98 -0
- package/dist/BitsnapCart-E72W5RRZ.mjs +2 -0
- package/dist/BitsnapCart-LHJ6KOTV.css +2 -0
- package/dist/BitsnapCart-LHJ6KOTV.css.map +1 -0
- package/dist/BitsnapCart-Q2HER6GU.js +2 -0
- package/dist/BitsnapCart-Q2HER6GU.js.map +1 -0
- package/dist/CartProvider-677CE2FI.js +2 -0
- package/dist/CartProvider-677CE2FI.js.map +1 -0
- package/dist/CartProvider-YPDOFSYC.mjs +2 -0
- package/dist/{PanelModelFiles-JZFSF7BF.mjs → PanelModelFiles-4B2HYGIE.mjs} +2 -2
- package/dist/{PanelModelFiles-7HPXWONN.js → PanelModelFiles-EKQRLF46.js} +2 -2
- package/dist/PanelModelFiles-EKQRLF46.js.map +1 -0
- package/dist/analytics.js +1 -1
- package/dist/analytics.js.map +1 -1
- package/dist/analytics.mjs +1 -1
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/chat.css +2 -0
- package/dist/chat.css.map +1 -0
- package/dist/chat.d.mts +172 -0
- package/dist/chat.d.ts +172 -0
- package/dist/chat.js +2 -0
- package/dist/chat.js.map +1 -0
- package/dist/chat.mjs +2 -0
- package/dist/chat.mjs.map +1 -0
- package/dist/chunk-2FD2QP4Y.js +2 -0
- package/dist/chunk-2FD2QP4Y.js.map +1 -0
- package/dist/chunk-5JRUPLXY.mjs +2 -0
- package/dist/chunk-5JRUPLXY.mjs.map +1 -0
- package/dist/chunk-5M6M7FAR.mjs +2 -0
- package/dist/chunk-5M6M7FAR.mjs.map +1 -0
- package/dist/chunk-6Q3VGPSF.js.map +1 -1
- package/dist/chunk-AAC576BC.mjs +5 -0
- package/dist/chunk-AAC576BC.mjs.map +1 -0
- package/dist/{chunk-4OVOKGGS.mjs → chunk-AB37DWOK.mjs} +2 -2
- package/dist/{chunk-ZATPBYOA.js → chunk-BUYTK7KM.js} +2 -2
- package/dist/chunk-BUYTK7KM.js.map +1 -0
- package/dist/{chunk-DP2NOHCI.js → chunk-D2ASWUXM.js} +2 -2
- package/dist/chunk-D2ASWUXM.js.map +1 -0
- package/dist/chunk-DDIEFKNP.mjs +2 -0
- package/dist/{chunk-ZHTMK5TA.mjs.map → chunk-DDIEFKNP.mjs.map} +1 -1
- package/dist/{chunk-4HGZZJEL.js → chunk-DOJICJCQ.js} +2 -2
- package/dist/chunk-DOJICJCQ.js.map +1 -0
- package/dist/chunk-EMR4YXNY.mjs +2 -0
- package/dist/chunk-EMR4YXNY.mjs.map +1 -0
- package/dist/{chunk-JA62KNAQ.js → chunk-GJOGATP6.js} +2 -2
- package/dist/chunk-GJOGATP6.js.map +1 -0
- package/dist/chunk-GQ5OKU74.js +2 -0
- package/dist/chunk-GQ5OKU74.js.map +1 -0
- package/dist/chunk-JSDGZ4NY.js.map +1 -1
- package/dist/chunk-KHQEDQYF.js +5 -0
- package/dist/chunk-KHQEDQYF.js.map +1 -0
- package/dist/chunk-KOYBZORL.js.map +1 -1
- package/dist/chunk-LGPNJ5XE.js +2 -0
- package/dist/chunk-LGPNJ5XE.js.map +1 -0
- package/dist/chunk-MDAFPGPA.js +2 -0
- package/dist/chunk-MDAFPGPA.js.map +1 -0
- package/dist/{chunk-JHJ3ZZF4.mjs → chunk-MMLBQHBM.mjs} +2 -2
- package/dist/chunk-MWWEPEU2.js +2 -0
- package/dist/chunk-MWWEPEU2.js.map +1 -0
- package/dist/{chunk-GEBRXFT3.mjs → chunk-N523LFAM.mjs} +2 -2
- package/dist/chunk-NWXZ45TV.js +2 -0
- package/dist/chunk-NWXZ45TV.js.map +1 -0
- package/dist/chunk-OFPRIENJ.mjs +2 -0
- package/dist/chunk-OFPRIENJ.mjs.map +1 -0
- package/dist/chunk-OR566YJI.mjs +2 -0
- package/dist/chunk-OR566YJI.mjs.map +1 -0
- package/dist/chunk-Q337IQNA.js +2 -0
- package/dist/chunk-Q337IQNA.js.map +1 -0
- package/dist/chunk-SCEWYZUZ.mjs +2 -0
- package/dist/chunk-SCEWYZUZ.mjs.map +1 -0
- package/dist/{chunk-CF45RDMD.mjs → chunk-SSSF64M7.mjs} +2 -2
- package/dist/{chunk-CF45RDMD.mjs.map → chunk-SSSF64M7.mjs.map} +1 -1
- package/dist/chunk-W3RGQYPD.js.map +1 -1
- package/dist/chunk-WG54EHST.mjs +2 -0
- package/dist/chunk-WG54EHST.mjs.map +1 -0
- package/dist/chunk-XEXPQFKN.mjs +2 -0
- package/dist/chunk-XEXPQFKN.mjs.map +1 -0
- package/dist/chunk-YV2C276H.js +2 -0
- package/dist/chunk-YV2C276H.js.map +1 -0
- package/dist/consent.js.map +1 -1
- package/dist/course.d.mts +2 -14
- package/dist/course.d.ts +2 -14
- package/dist/course.js +1 -1
- package/dist/course.js.map +1 -1
- package/dist/course.mjs +1 -1
- package/dist/course.mjs.map +1 -1
- package/dist/embed/analytics.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +288 -4
- package/dist/index.d.ts +288 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/methods-64D5DD6K.js +2 -0
- package/dist/methods-64D5DD6K.js.map +1 -0
- package/dist/methods-NQA3DFLE.mjs +2 -0
- package/dist/methods-NQA3DFLE.mjs.map +1 -0
- package/dist/model-files-client-P4PORZJ6.js.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/returns.js +1 -1
- package/dist/returns.js.map +1 -1
- package/dist/returns.mjs +1 -1
- package/dist/texts-9kfgClsA.d.mts +14 -0
- package/dist/texts-9kfgClsA.d.ts +14 -0
- package/dist/{types-D6LsoycW.d.mts → types-B-sjyZQs.d.mts} +7 -1
- package/dist/{types-ClFCVzk_.d.ts → types-iRe6ix2y.d.ts} +7 -1
- package/dist/viewer3d.js.map +1 -1
- package/dist/viewer3d.mjs +1 -1
- package/dist/viewer3d.mjs.map +1 -1
- package/dist/widgets-BT2LN2Nq.d.mts +547 -0
- package/dist/widgets-BVOSj9fU.d.ts +547 -0
- package/package.json +18 -3
- package/dist/CartProvider-OEI526IN.js +0 -2
- package/dist/CartProvider-OEI526IN.js.map +0 -1
- package/dist/CartProvider-RYAA3JDA.mjs +0 -2
- package/dist/PanelModelFiles-7HPXWONN.js.map +0 -1
- package/dist/chunk-4HGZZJEL.js.map +0 -1
- package/dist/chunk-5X7TP3TQ.mjs +0 -2
- package/dist/chunk-5X7TP3TQ.mjs.map +0 -1
- package/dist/chunk-7RXW6XFY.js +0 -2
- package/dist/chunk-7RXW6XFY.js.map +0 -1
- package/dist/chunk-DP2NOHCI.js.map +0 -1
- package/dist/chunk-EVIDNS22.mjs +0 -2
- package/dist/chunk-EVIDNS22.mjs.map +0 -1
- package/dist/chunk-G4V2KWTV.js +0 -2
- package/dist/chunk-G4V2KWTV.js.map +0 -1
- package/dist/chunk-GWF3MRUP.js +0 -2
- package/dist/chunk-GWF3MRUP.js.map +0 -1
- package/dist/chunk-JA62KNAQ.js.map +0 -1
- package/dist/chunk-UPAOIY4R.mjs +0 -2
- package/dist/chunk-UPAOIY4R.mjs.map +0 -1
- package/dist/chunk-V5ECGBFW.js +0 -5
- package/dist/chunk-V5ECGBFW.js.map +0 -1
- package/dist/chunk-VNV5BD4X.js +0 -2
- package/dist/chunk-VNV5BD4X.js.map +0 -1
- package/dist/chunk-VNYHJT6V.mjs +0 -2
- package/dist/chunk-VNYHJT6V.mjs.map +0 -1
- package/dist/chunk-WJO5GSY3.mjs +0 -5
- package/dist/chunk-WJO5GSY3.mjs.map +0 -1
- package/dist/chunk-ZATPBYOA.js.map +0 -1
- package/dist/chunk-ZHTMK5TA.mjs +0 -2
- package/dist/methods-AULQDKVS.mjs +0 -2
- package/dist/methods-PMH5VQ25.js +0 -2
- package/dist/methods-PMH5VQ25.js.map +0 -1
- /package/dist/{CartProvider-RYAA3JDA.mjs.map → BitsnapCart-E72W5RRZ.mjs.map} +0 -0
- /package/dist/{methods-AULQDKVS.mjs.map → CartProvider-YPDOFSYC.mjs.map} +0 -0
- /package/dist/{PanelModelFiles-JZFSF7BF.mjs.map → PanelModelFiles-4B2HYGIE.mjs.map} +0 -0
- /package/dist/{chunk-4OVOKGGS.mjs.map → chunk-AB37DWOK.mjs.map} +0 -0
- /package/dist/{chunk-JHJ3ZZF4.mjs.map → chunk-MMLBQHBM.mjs.map} +0 -0
- /package/dist/{chunk-GEBRXFT3.mjs.map → chunk-N523LFAM.mjs.map} +0 -0
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { L as LocaleTables } from './texts-9kfgClsA.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Buyer side of the Bitsnap chat service (`bitsnap-messaging`): the shapes
|
|
6
|
+
* the library works with. The wire is snake_case JSON; `client.ts` maps it to
|
|
7
|
+
* these camelCase types. Times are ISO 8601 strings, `null` when absent.
|
|
8
|
+
*/
|
|
9
|
+
/** Default base URL of the chat service. */
|
|
10
|
+
declare const DEFAULT_CHAT_API_URL = "https://chat.bitsnap.pl";
|
|
11
|
+
/** Default NATS WebSocket URL, used when the realtime token lists no server. */
|
|
12
|
+
declare const DEFAULT_CHAT_REALTIME_URL = "wss://bitsnap-nats-queue-production.up.railway.app";
|
|
13
|
+
/** One paid order that gives a pack thread creator replies. */
|
|
14
|
+
type ChatPack = {
|
|
15
|
+
orderId: string;
|
|
16
|
+
productId?: string;
|
|
17
|
+
replies: number;
|
|
18
|
+
used: number;
|
|
19
|
+
left: number;
|
|
20
|
+
expiresAt: string | null;
|
|
21
|
+
expired: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** A stored message, or the pending answer of a send. */
|
|
24
|
+
type ChatMessage = {
|
|
25
|
+
id: string;
|
|
26
|
+
threadId: string;
|
|
27
|
+
authorEmail: string;
|
|
28
|
+
body: string;
|
|
29
|
+
attachmentKey?: string;
|
|
30
|
+
attachmentKind?: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
pinned: boolean;
|
|
33
|
+
/** Soft deleted: the body is empty. */
|
|
34
|
+
deleted: boolean;
|
|
35
|
+
/** A message of the service, such as the creator's away notice. */
|
|
36
|
+
system: boolean;
|
|
37
|
+
/** `"pending"` in the answer of a send: queued, not stored yet. */
|
|
38
|
+
status?: "pending";
|
|
39
|
+
};
|
|
40
|
+
/** The state of a conversation for the caller (`ThreadView` on the wire). */
|
|
41
|
+
type ChatThreadSummary = {
|
|
42
|
+
id: string;
|
|
43
|
+
kind: "pack" | "channel";
|
|
44
|
+
channelId?: string;
|
|
45
|
+
/** For a buyer, the creator's e-mail (pack) or the channel name. */
|
|
46
|
+
title: string;
|
|
47
|
+
lastMessage?: ChatMessage;
|
|
48
|
+
unread: number;
|
|
49
|
+
repliesTotal: number;
|
|
50
|
+
repliesUsed: number;
|
|
51
|
+
repliesLeft: number;
|
|
52
|
+
expiresAt: string | null;
|
|
53
|
+
/** The caller cannot write: every pack has expired. */
|
|
54
|
+
composerLocked: boolean;
|
|
55
|
+
productId?: string;
|
|
56
|
+
/** The creator's promise in hours ("odpowiedź w ciągu 48 h"), 0 for none. */
|
|
57
|
+
responseHours: number;
|
|
58
|
+
packs: ChatPack[];
|
|
59
|
+
muted: boolean;
|
|
60
|
+
};
|
|
61
|
+
/** A channel the caller may read. */
|
|
62
|
+
type ChatChannelSummary = {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
topic: string;
|
|
66
|
+
welcome: string;
|
|
67
|
+
whoCanPost: "creator" | "members";
|
|
68
|
+
productId: string;
|
|
69
|
+
/** `creator`, `member` or `muted`. */
|
|
70
|
+
role: string;
|
|
71
|
+
memberCount: number;
|
|
72
|
+
createdAt: string;
|
|
73
|
+
blockLinks: boolean;
|
|
74
|
+
blockMedia: boolean;
|
|
75
|
+
cooldownSeconds: number;
|
|
76
|
+
};
|
|
77
|
+
/** A pack the buyer holds and has not opened a thread for yet. */
|
|
78
|
+
type ChatPackEntitlement = {
|
|
79
|
+
productId: string;
|
|
80
|
+
name: string;
|
|
81
|
+
repliesLeftHint: number;
|
|
82
|
+
expiresAt: string | null;
|
|
83
|
+
};
|
|
84
|
+
/** A community product the buyer holds; `channelId` once a channel is bound. */
|
|
85
|
+
type ChatChannelEntitlement = {
|
|
86
|
+
productId: string;
|
|
87
|
+
channelId?: string;
|
|
88
|
+
};
|
|
89
|
+
/** `GET /v1/me`: the buyer's chat in one project. */
|
|
90
|
+
type ChatMe = {
|
|
91
|
+
email: string;
|
|
92
|
+
threads: ChatThreadSummary[];
|
|
93
|
+
entitlements: {
|
|
94
|
+
packs: ChatPackEntitlement[];
|
|
95
|
+
channels: ChatChannelEntitlement[];
|
|
96
|
+
};
|
|
97
|
+
channels: ChatChannelSummary[];
|
|
98
|
+
};
|
|
99
|
+
/** One page of history, newest first as the service answers it. */
|
|
100
|
+
type ChatMessagePage = {
|
|
101
|
+
messages: ChatMessage[];
|
|
102
|
+
hasMore: boolean;
|
|
103
|
+
};
|
|
104
|
+
/** The thread part of a send answer. */
|
|
105
|
+
type ChatThreadState = Pick<ChatThreadSummary, "id" | "kind" | "repliesTotal" | "repliesUsed" | "repliesLeft" | "expiresAt" | "composerLocked" | "responseHours">;
|
|
106
|
+
/** `POST /v1/threads/{id}/messages` answers 202 with the queued message. */
|
|
107
|
+
type ChatSendResult = {
|
|
108
|
+
message: ChatMessage;
|
|
109
|
+
thread: ChatThreadState;
|
|
110
|
+
};
|
|
111
|
+
type ChatReportReason = "spam" | "abuse" | "illegal" | "other";
|
|
112
|
+
/** `POST /v1/realtime/token`. */
|
|
113
|
+
type ChatRealtimeToken = {
|
|
114
|
+
jwt: string;
|
|
115
|
+
expiresAt: string;
|
|
116
|
+
servers: string[];
|
|
117
|
+
subjects: string[];
|
|
118
|
+
truncated: boolean;
|
|
119
|
+
};
|
|
120
|
+
/** Live events on the thread or channel subject. */
|
|
121
|
+
type ChatRealtimeEvent = {
|
|
122
|
+
type: "message.created";
|
|
123
|
+
message: ChatMessage;
|
|
124
|
+
} | {
|
|
125
|
+
type: "message.rejected";
|
|
126
|
+
id: string;
|
|
127
|
+
reason: string;
|
|
128
|
+
} | {
|
|
129
|
+
type: "message.deleted";
|
|
130
|
+
id: string;
|
|
131
|
+
} | {
|
|
132
|
+
type: "message.pinned";
|
|
133
|
+
id: string;
|
|
134
|
+
} | {
|
|
135
|
+
type: "message.unpinned";
|
|
136
|
+
id: string;
|
|
137
|
+
};
|
|
138
|
+
/** How a conversation hears about new messages. */
|
|
139
|
+
type ChatLiveMode = "connecting" | "live" | "polling" | "off";
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* An error answer of the chat service (`{"error":"<code>"}`), or `network`
|
|
143
|
+
* (status 0) when the request did not get an answer.
|
|
144
|
+
*
|
|
145
|
+
* Codes the buyer UI handles: `unauthorized` (401), `plan_required`,
|
|
146
|
+
* `locked`, `muted`, `blocked`, `forbidden`, `read_only` (403), `not_found`
|
|
147
|
+
* (404), `moderation_link`, `moderation_banned_word`, `moderation_media`
|
|
148
|
+
* (422), `cooldown` (429, with `retryAfter`), `unavailable` (503),
|
|
149
|
+
* `invalid_project` (400).
|
|
150
|
+
*/
|
|
151
|
+
declare class ChatError extends Error {
|
|
152
|
+
readonly code: string;
|
|
153
|
+
readonly status: number;
|
|
154
|
+
/** `cooldown`: seconds to wait before the next post. */
|
|
155
|
+
readonly retryAfter?: number;
|
|
156
|
+
/** Extra fields of the answer (`locked`: `product_id`, `price_cents`, `welcome`). */
|
|
157
|
+
readonly data: Record<string, unknown>;
|
|
158
|
+
constructor(code: string, status: number, data?: Record<string, unknown>);
|
|
159
|
+
}
|
|
160
|
+
type ChatClientOptions = {
|
|
161
|
+
/** Project id sent as `X-Bitsnap-Project`. */
|
|
162
|
+
projectId: string;
|
|
163
|
+
/** Bearer credential: the panel session token or a `bcht_` buyer token. */
|
|
164
|
+
token: string;
|
|
165
|
+
/** Base URL of the chat service. Defaults to `https://chat.bitsnap.pl`. */
|
|
166
|
+
baseUrl?: string;
|
|
167
|
+
/** Replaces `fetch` (tests, server rendering). */
|
|
168
|
+
fetch?: typeof fetch;
|
|
169
|
+
};
|
|
170
|
+
/** The buyer calls of the chat service HTTP API. */
|
|
171
|
+
type ChatClient = {
|
|
172
|
+
readonly baseUrl: string;
|
|
173
|
+
readonly projectId: string;
|
|
174
|
+
me(): Promise<ChatMe>;
|
|
175
|
+
/** Opens or returns the pack thread of a service product. */
|
|
176
|
+
openThread(productId: string): Promise<ChatThreadSummary>;
|
|
177
|
+
/** Newest first; `before` is a message id. */
|
|
178
|
+
messages(threadId: string, options?: {
|
|
179
|
+
before?: string;
|
|
180
|
+
limit?: number;
|
|
181
|
+
}): Promise<ChatMessagePage>;
|
|
182
|
+
/** Queues a message. The service answers 202 with `status: "pending"`. */
|
|
183
|
+
send(threadId: string, input: {
|
|
184
|
+
body: string;
|
|
185
|
+
clientId?: string;
|
|
186
|
+
}): Promise<ChatSendResult>;
|
|
187
|
+
deleteMessage(threadId: string, messageId: string): Promise<void>;
|
|
188
|
+
mute(threadId: string, muted: boolean): Promise<void>;
|
|
189
|
+
report(input: {
|
|
190
|
+
threadId: string;
|
|
191
|
+
messageId?: string;
|
|
192
|
+
reason: ChatReportReason;
|
|
193
|
+
note?: string;
|
|
194
|
+
}): Promise<void>;
|
|
195
|
+
markRead(threadId: string, messageId: string): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* A NATS token for every conversation the caller may read. The answer is
|
|
198
|
+
* kept until a minute and a half before it expires (the service mints one
|
|
199
|
+
* per caller every 10 s); `fresh` asks for a new one.
|
|
200
|
+
*/
|
|
201
|
+
realtimeToken(options?: {
|
|
202
|
+
fresh?: boolean;
|
|
203
|
+
}): Promise<ChatRealtimeToken>;
|
|
204
|
+
};
|
|
205
|
+
declare function createChatClient(options: ChatClientOptions): ChatClient;
|
|
206
|
+
/** Parses one live event of the thread or channel subject. */
|
|
207
|
+
declare function parseRealtimeEvent(raw: unknown): ChatRealtimeEvent | null;
|
|
208
|
+
|
|
209
|
+
/** The part of `@nats-io/nats-core` the chat uses. */
|
|
210
|
+
type NatsModule = {
|
|
211
|
+
wsconnect(options: {
|
|
212
|
+
servers: string[];
|
|
213
|
+
authenticator: unknown;
|
|
214
|
+
name?: string;
|
|
215
|
+
reconnect?: boolean;
|
|
216
|
+
maxReconnectAttempts?: number;
|
|
217
|
+
}): Promise<NatsConnectionLike>;
|
|
218
|
+
jwtAuthenticator(jwt: () => string): unknown;
|
|
219
|
+
};
|
|
220
|
+
type NatsConnectionLike = {
|
|
221
|
+
subscribe(subject: string, options: {
|
|
222
|
+
callback: (error: Error | null, msg: {
|
|
223
|
+
data: Uint8Array;
|
|
224
|
+
}) => void;
|
|
225
|
+
}): {
|
|
226
|
+
unsubscribe(): void;
|
|
227
|
+
};
|
|
228
|
+
closed(): Promise<void | Error>;
|
|
229
|
+
close(): Promise<void>;
|
|
230
|
+
};
|
|
231
|
+
type LiveOptions = {
|
|
232
|
+
client: ChatClient;
|
|
233
|
+
/** `thread` for a pack thread, `channel` for a channel. */
|
|
234
|
+
kind: "thread" | "channel";
|
|
235
|
+
/** Thread id (a channel thread has the channel's id). */
|
|
236
|
+
id: string;
|
|
237
|
+
onEvent: (event: ChatRealtimeEvent) => void;
|
|
238
|
+
onMode: (mode: ChatLiveMode) => void;
|
|
239
|
+
/** Loads the newest page: the fallback, and the catch-up after a connect. */
|
|
240
|
+
poll: () => Promise<void>;
|
|
241
|
+
/** Polling interval while the socket is down. Default 8 s. */
|
|
242
|
+
pollIntervalMs?: number;
|
|
243
|
+
/** Delay before the socket is tried again after a failure. Default 60 s. */
|
|
244
|
+
retryMs?: number;
|
|
245
|
+
/** Overrides the WebSocket servers of the realtime token. */
|
|
246
|
+
realtimeUrl?: string;
|
|
247
|
+
/** Replaces the NATS loader (tests). */
|
|
248
|
+
loadNats?: () => Promise<NatsModule>;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Listens to one conversation: a realtime token from the chat service, then
|
|
252
|
+
* a subscribe-only NATS WebSocket on the conversation's subject. When any
|
|
253
|
+
* step fails (no WebSocket, token refused, subject not granted, socket
|
|
254
|
+
* closed) it polls the newest page instead and tries the socket again later.
|
|
255
|
+
* Returns the stop function.
|
|
256
|
+
*/
|
|
257
|
+
declare function startLive(options: LiveOptions): () => void;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Every string of the chat (panel "Wiadomości", `ChatThread`, `Channel`).
|
|
261
|
+
* Pass a partial object through the `texts` prop to override any of them,
|
|
262
|
+
* whatever the locale. Placeholders like `{count}` stay in overrides.
|
|
263
|
+
*
|
|
264
|
+
* Counts use three forms (`One`, `Few`, `Many`) for Polish; English uses
|
|
265
|
+
* `One` and `Many`.
|
|
266
|
+
*/
|
|
267
|
+
type ChatTexts = {
|
|
268
|
+
inboxHeading: string;
|
|
269
|
+
inboxIntro: string;
|
|
270
|
+
inboxEmpty: string;
|
|
271
|
+
inboxError: string;
|
|
272
|
+
loading: string;
|
|
273
|
+
retry: string;
|
|
274
|
+
back: string;
|
|
275
|
+
selectConversation: string;
|
|
276
|
+
kindChat: string;
|
|
277
|
+
kindChannel: string;
|
|
278
|
+
startSection: string;
|
|
279
|
+
startChat: string;
|
|
280
|
+
openChannel: string;
|
|
281
|
+
channelNotReady: string;
|
|
282
|
+
chatFallbackTitle: string;
|
|
283
|
+
channelFallbackTitle: string;
|
|
284
|
+
/** Placeholder `{count}`. */
|
|
285
|
+
repliesLeftOne: string;
|
|
286
|
+
repliesLeftFew: string;
|
|
287
|
+
repliesLeftMany: string;
|
|
288
|
+
noRepliesLeft: string;
|
|
289
|
+
/** Placeholder `{date}`. */
|
|
290
|
+
expiresOn: string;
|
|
291
|
+
/** Placeholder `{date}`. */
|
|
292
|
+
expiredOn: string;
|
|
293
|
+
/** Placeholder `{hours}`. */
|
|
294
|
+
responseHours: string;
|
|
295
|
+
/** Placeholder `{count}`. */
|
|
296
|
+
unread: string;
|
|
297
|
+
/** Placeholder `{count}`. */
|
|
298
|
+
members: string;
|
|
299
|
+
mutedBadge: string;
|
|
300
|
+
noMessagesYet: string;
|
|
301
|
+
emptyThread: string;
|
|
302
|
+
emptyChannel: string;
|
|
303
|
+
privacyNote: string;
|
|
304
|
+
loadOlder: string;
|
|
305
|
+
you: string;
|
|
306
|
+
creator: string;
|
|
307
|
+
systemLabel: string;
|
|
308
|
+
pinned: string;
|
|
309
|
+
deletedPlaceholder: string;
|
|
310
|
+
attachment: string;
|
|
311
|
+
composerLabel: string;
|
|
312
|
+
composerPlaceholder: string;
|
|
313
|
+
send: string;
|
|
314
|
+
composerExpired: string;
|
|
315
|
+
composerCreatorOnly: string;
|
|
316
|
+
composerMuted: string;
|
|
317
|
+
composerReadOnly: string;
|
|
318
|
+
lockRepliesTitle: string;
|
|
319
|
+
lockRepliesBody: string;
|
|
320
|
+
lockExpiredTitle: string;
|
|
321
|
+
lockExpiredBody: string;
|
|
322
|
+
lockThreadTitle: string;
|
|
323
|
+
lockThreadBody: string;
|
|
324
|
+
lockChannelTitle: string;
|
|
325
|
+
lockChannelBody: string;
|
|
326
|
+
buyPack: string;
|
|
327
|
+
buyAccess: string;
|
|
328
|
+
buying: string;
|
|
329
|
+
buyError: string;
|
|
330
|
+
pending: string;
|
|
331
|
+
notConfirmed: string;
|
|
332
|
+
rejectedLink: string;
|
|
333
|
+
rejectedBannedWord: string;
|
|
334
|
+
rejectedMedia: string;
|
|
335
|
+
/** Placeholder `{seconds}`. */
|
|
336
|
+
rejectedCooldown: string;
|
|
337
|
+
rejectedBlocked: string;
|
|
338
|
+
rejectedMuted: string;
|
|
339
|
+
rejectedReadOnly: string;
|
|
340
|
+
rejectedPackEmpty: string;
|
|
341
|
+
rejectedForbidden: string;
|
|
342
|
+
rejectedGeneric: string;
|
|
343
|
+
failedNetwork: string;
|
|
344
|
+
editMessage: string;
|
|
345
|
+
retrySend: string;
|
|
346
|
+
dismiss: string;
|
|
347
|
+
messageActions: string;
|
|
348
|
+
deleteMessage: string;
|
|
349
|
+
deleteConfirm: string;
|
|
350
|
+
reportMessage: string;
|
|
351
|
+
conversationActions: string;
|
|
352
|
+
muteThread: string;
|
|
353
|
+
unmuteThread: string;
|
|
354
|
+
muteError: string;
|
|
355
|
+
reportConversation: string;
|
|
356
|
+
reportTitle: string;
|
|
357
|
+
reportConversationTitle: string;
|
|
358
|
+
reportReason: string;
|
|
359
|
+
reasonSpam: string;
|
|
360
|
+
reasonAbuse: string;
|
|
361
|
+
reasonIllegal: string;
|
|
362
|
+
reasonOther: string;
|
|
363
|
+
reportNote: string;
|
|
364
|
+
reportSend: string;
|
|
365
|
+
reportCancel: string;
|
|
366
|
+
reportSent: string;
|
|
367
|
+
reportError: string;
|
|
368
|
+
liveLabel: string;
|
|
369
|
+
pollingLabel: string;
|
|
370
|
+
errorNoToken: string;
|
|
371
|
+
errorUnauthorized: string;
|
|
372
|
+
errorPlan: string;
|
|
373
|
+
errorNotFound: string;
|
|
374
|
+
errorUnavailable: string;
|
|
375
|
+
errorGeneric: string;
|
|
376
|
+
};
|
|
377
|
+
declare const CHAT_TEXT_TABLES: LocaleTables<keyof ChatTexts>;
|
|
378
|
+
/** Chat strings for a locale (default: the library locale), with overrides. */
|
|
379
|
+
declare function getChatTexts(overrides?: Partial<ChatTexts>, locale?: string): ChatTexts;
|
|
380
|
+
|
|
381
|
+
/** What to open: a pack thread (by product or id) or a channel. */
|
|
382
|
+
type ConversationTarget = {
|
|
383
|
+
kind: "thread";
|
|
384
|
+
threadId?: string;
|
|
385
|
+
productId?: string;
|
|
386
|
+
} | {
|
|
387
|
+
kind: "channel";
|
|
388
|
+
channelId: string;
|
|
389
|
+
productId?: string;
|
|
390
|
+
};
|
|
391
|
+
/** The client-side state of a message the service has not stored. */
|
|
392
|
+
type LocalMessageState = {
|
|
393
|
+
state: "pending" | "unconfirmed" | "rejected" | "failed";
|
|
394
|
+
/** Error code or live reject reason. */
|
|
395
|
+
reason?: string;
|
|
396
|
+
retryAfter?: number;
|
|
397
|
+
/** An earlier send of this message may have been queued: retries keep its id. */
|
|
398
|
+
keepId?: boolean;
|
|
399
|
+
};
|
|
400
|
+
type ConversationMessage = ChatMessage & {
|
|
401
|
+
local?: LocalMessageState;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Why the buyer sees the lock: `replies` (no creator replies left, writing
|
|
405
|
+
* still works), `expired` (every pack expired), `no-pack` (no thread and no
|
|
406
|
+
* pack for the product), `no-access` (a paid channel without a grant).
|
|
407
|
+
*/
|
|
408
|
+
type ConversationLock = {
|
|
409
|
+
reason: "replies" | "expired" | "no-pack" | "no-access";
|
|
410
|
+
productId?: string;
|
|
411
|
+
priceCents?: number;
|
|
412
|
+
welcome?: string;
|
|
413
|
+
};
|
|
414
|
+
type ConversationState = {
|
|
415
|
+
status: "loading" | "ready" | "locked" | "error";
|
|
416
|
+
error?: ChatError;
|
|
417
|
+
threadId?: string;
|
|
418
|
+
/** The caller's e-mail, lowercased. */
|
|
419
|
+
me?: string;
|
|
420
|
+
thread?: ChatThreadSummary;
|
|
421
|
+
channel?: ChatChannelSummary;
|
|
422
|
+
lock?: ConversationLock;
|
|
423
|
+
/** Oldest first. */
|
|
424
|
+
messages: ConversationMessage[];
|
|
425
|
+
hasMore: boolean;
|
|
426
|
+
loadingOlder: boolean;
|
|
427
|
+
live: ChatLiveMode;
|
|
428
|
+
};
|
|
429
|
+
type ConversationActions = {
|
|
430
|
+
send(body: string): Promise<void>;
|
|
431
|
+
/** Sends a failed or refused message again. */
|
|
432
|
+
retry(id: string): Promise<void>;
|
|
433
|
+
/** Removes a message that was not stored. */
|
|
434
|
+
discard(id: string): void;
|
|
435
|
+
deleteMessage(id: string): Promise<void>;
|
|
436
|
+
report(input: {
|
|
437
|
+
messageId?: string;
|
|
438
|
+
reason: ChatReportReason;
|
|
439
|
+
note?: string;
|
|
440
|
+
}): Promise<void>;
|
|
441
|
+
setMuted(muted: boolean): Promise<void>;
|
|
442
|
+
loadOlder(): Promise<void>;
|
|
443
|
+
reload(): void;
|
|
444
|
+
};
|
|
445
|
+
type UseConversationOptions = {
|
|
446
|
+
/**
|
|
447
|
+
* `undefined` when there is no credential (the state is an error), `null`
|
|
448
|
+
* while the credential is still being looked up (the state stays loading).
|
|
449
|
+
*/
|
|
450
|
+
client: ChatClient | null | undefined;
|
|
451
|
+
target: ConversationTarget;
|
|
452
|
+
pollIntervalMs?: number;
|
|
453
|
+
realtimeUrl?: string;
|
|
454
|
+
loadNats?: () => Promise<NatsModule>;
|
|
455
|
+
/** A pending send counts as unconfirmed after this long. Default 45 s. */
|
|
456
|
+
confirmTimeoutMs?: number;
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* State and actions of one conversation: resolves the thread (opening a pack
|
|
460
|
+
* thread when the buyer holds a pack and has none yet), loads the newest
|
|
461
|
+
* page, listens live (or polls) and sends optimistically.
|
|
462
|
+
*/
|
|
463
|
+
declare function useConversation(options: UseConversationOptions): ConversationState & ConversationActions;
|
|
464
|
+
|
|
465
|
+
/** What the lock's buy action gets. */
|
|
466
|
+
type ChatBuyRequest = {
|
|
467
|
+
/** The product (or variant) to sell: `buyProductId`, else the locked product. */
|
|
468
|
+
productId: string;
|
|
469
|
+
/** `replies`, `expired`, `no-pack` or `no-access`. */
|
|
470
|
+
reason: ConversationLock["reason"];
|
|
471
|
+
/** Known for a locked channel (from the chat service). */
|
|
472
|
+
priceCents?: number;
|
|
473
|
+
};
|
|
474
|
+
/** Props shared by `ChatThread` and `Channel`. */
|
|
475
|
+
type ChatWidgetBaseProps = {
|
|
476
|
+
/**
|
|
477
|
+
* Public Bitsnap project id of the shop. The cart uses it, the panel
|
|
478
|
+
* session is looked up with it, and it is the `X-Bitsnap-Project` of the
|
|
479
|
+
* chat service unless `chatProjectID` is given.
|
|
480
|
+
*/
|
|
481
|
+
projectID: string;
|
|
482
|
+
/** Project id for the chat service, when it differs from `projectID`. */
|
|
483
|
+
chatProjectID?: string;
|
|
484
|
+
/**
|
|
485
|
+
* Bearer for the chat service: a `bcht_` buyer token from your server
|
|
486
|
+
* (`POST /api/v1/chat/buyer-token`). Defaults to the customer panel session
|
|
487
|
+
* of this browser (after `PanelLogin`).
|
|
488
|
+
*/
|
|
489
|
+
token?: string;
|
|
490
|
+
/** Chat service base URL. Defaults to `https://chat.bitsnap.pl`. */
|
|
491
|
+
apiUrl?: string;
|
|
492
|
+
/** NATS WebSocket URL overriding the one of the realtime token. */
|
|
493
|
+
realtimeUrl?: string;
|
|
494
|
+
/** Bitsnap host of the panel session (`setHost`), when not the default. */
|
|
495
|
+
host?: string;
|
|
496
|
+
/** Polling interval in ms while the live connection is down. Default 8000. */
|
|
497
|
+
pollIntervalMs?: number;
|
|
498
|
+
/** Language of the default texts; defaults to the library locale. */
|
|
499
|
+
locale?: string;
|
|
500
|
+
/** Text overrides, whatever the locale. */
|
|
501
|
+
texts?: Partial<ChatTexts>;
|
|
502
|
+
/** Heading of the conversation. */
|
|
503
|
+
title?: string;
|
|
504
|
+
/** Shows a back button in the header. */
|
|
505
|
+
onBack?: () => void;
|
|
506
|
+
/**
|
|
507
|
+
* The lock's "Kup pakiet" / "Kup dostęp". Default: add the product to the
|
|
508
|
+
* page cart and open it (mount `BitsnapCheckout` on the page). Throw to
|
|
509
|
+
* show the error line.
|
|
510
|
+
*/
|
|
511
|
+
onBuy?: (request: ChatBuyRequest) => Promise<void> | void;
|
|
512
|
+
/** The product or variant the buy action sells (e.g. the pack variant). */
|
|
513
|
+
buyProductId?: string;
|
|
514
|
+
className?: string;
|
|
515
|
+
/** A ready client (tests, custom transport). Replaces token and URLs. */
|
|
516
|
+
client?: ChatClient;
|
|
517
|
+
/** @internal Replaces the NATS loader (tests). */
|
|
518
|
+
loadNats?: () => Promise<NatsModule>;
|
|
519
|
+
};
|
|
520
|
+
type ChatThreadProps = ChatWidgetBaseProps & {
|
|
521
|
+
/** The service product of the pack: opens its thread, creating it if needed. */
|
|
522
|
+
productId?: string;
|
|
523
|
+
/** An existing thread. Give this or `productId`. */
|
|
524
|
+
threadId?: string;
|
|
525
|
+
};
|
|
526
|
+
type ChannelProps = ChatWidgetBaseProps & {
|
|
527
|
+
/** The channel (its id is also the id of its conversation). */
|
|
528
|
+
channelId: string;
|
|
529
|
+
/** The community product sold by the lock; defaults to the channel's own. */
|
|
530
|
+
productId?: string;
|
|
531
|
+
};
|
|
532
|
+
/**
|
|
533
|
+
* A buyer's pack thread for one service product: history, live updates,
|
|
534
|
+
* sending with pending and refused states, report and mute, and the lock
|
|
535
|
+
* with "Kup pakiet" when the replies are used up or the pack expired.
|
|
536
|
+
* Load `bitsnap-react/dist/index.css` once.
|
|
537
|
+
*/
|
|
538
|
+
declare function ChatThread(props: ChatThreadProps): react_jsx_runtime.JSX.Element;
|
|
539
|
+
/**
|
|
540
|
+
* A community channel: messages, live updates, posting when the channel
|
|
541
|
+
* allows it (with the channel's moderation refusals shown on the message),
|
|
542
|
+
* report, and the lock with "Kup dostęp" for a buyer without a grant.
|
|
543
|
+
* Load `bitsnap-react/dist/index.css` once.
|
|
544
|
+
*/
|
|
545
|
+
declare function Channel(props: ChannelProps): react_jsx_runtime.JSX.Element;
|
|
546
|
+
|
|
547
|
+
export { type ChatPackEntitlement as A, type ChatRealtimeEvent as B, type ChatTexts as C, DEFAULT_CHAT_API_URL as D, type ChatRealtimeToken as E, type ChatReportReason as F, type ChatSendResult as G, type ChatThreadState as H, type ChatThreadSummary as I, type LiveOptions as L, type UseConversationOptions as U, Channel as a, ChatThread as b, type ChannelProps as c, type ChatBuyRequest as d, type ChatThreadProps as e, type ChatWidgetBaseProps as f, ChatError as g, createChatClient as h, type ChatClient as i, type ChatClientOptions as j, type ConversationLock as k, type ConversationMessage as l, type ConversationTarget as m, CHAT_TEXT_TABLES as n, getChatTexts as o, parseRealtimeEvent as p, DEFAULT_CHAT_REALTIME_URL as q, type ChatChannelEntitlement as r, startLive as s, type ChatChannelSummary as t, useConversation as u, type ChatLiveMode as v, type ChatMe as w, type ChatMessage as x, type ChatMessagePage as y, type ChatPack as z };
|