@holocronlab/botruntime-chat 0.5.5
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/LICENSE +8 -0
- package/README.md +64 -0
- package/dist/client.d.ts +363 -0
- package/dist/consts.d.ts +1 -0
- package/dist/errors.d.ts +20 -0
- package/dist/event-emitter.d.ts +10 -0
- package/dist/eventsource.d.ts +32 -0
- package/dist/gen/client/errors.d.ts +229 -0
- package/dist/gen/client/index.d.ts +77 -0
- package/dist/gen/client/models.d.ts +212 -0
- package/dist/gen/client/operations/addParticipant.d.ts +55 -0
- package/dist/gen/client/operations/createConversation.d.ts +39 -0
- package/dist/gen/client/operations/createEvent.d.ts +55 -0
- package/dist/gen/client/operations/createMessage.d.ts +294 -0
- package/dist/gen/client/operations/createUser.d.ts +66 -0
- package/dist/gen/client/operations/deleteConversation.d.ts +22 -0
- package/dist/gen/client/operations/deleteMessage.d.ts +22 -0
- package/dist/gen/client/operations/deleteUser.d.ts +21 -0
- package/dist/gen/client/operations/getConversation.d.ts +36 -0
- package/dist/gen/client/operations/getEvent.d.ts +46 -0
- package/dist/gen/client/operations/getMessage.d.ts +167 -0
- package/dist/gen/client/operations/getOrCreateConversation.d.ts +39 -0
- package/dist/gen/client/operations/getOrCreateUser.d.ts +62 -0
- package/dist/gen/client/operations/getParticipant.d.ts +52 -0
- package/dist/gen/client/operations/getUser.d.ts +50 -0
- package/dist/gen/client/operations/listConversations.d.ts +42 -0
- package/dist/gen/client/operations/listMessages.d.ts +171 -0
- package/dist/gen/client/operations/listParticipants.d.ts +55 -0
- package/dist/gen/client/operations/listenConversation.d.ts +22 -0
- package/dist/gen/client/operations/removeParticipant.d.ts +23 -0
- package/dist/gen/client/operations/updateUser.d.ts +62 -0
- package/dist/gen/client/to-axios.d.ts +16 -0
- package/dist/gen/signals/eventCreated.j.d.ts +3 -0
- package/dist/gen/signals/eventCreated.t.d.ts +28 -0
- package/dist/gen/signals/eventCreated.z.d.ts +47 -0
- package/dist/gen/signals/index.d.ts +924 -0
- package/dist/gen/signals/messageCreated.j.d.ts +3 -0
- package/dist/gen/signals/messageCreated.t.d.ts +149 -0
- package/dist/gen/signals/messageCreated.z.d.ts +780 -0
- package/dist/gen/signals/messageDeleted.j.d.ts +3 -0
- package/dist/gen/signals/messageDeleted.t.d.ts +8 -0
- package/dist/gen/signals/messageDeleted.z.d.ts +32 -0
- package/dist/gen/signals/participantAdded.j.d.ts +3 -0
- package/dist/gen/signals/participantAdded.t.d.ts +7 -0
- package/dist/gen/signals/participantAdded.z.d.ts +27 -0
- package/dist/gen/signals/participantRemoved.j.d.ts +3 -0
- package/dist/gen/signals/participantRemoved.t.d.ts +7 -0
- package/dist/gen/signals/participantRemoved.z.d.ts +27 -0
- package/dist/index.cjs +1660 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +138836 -0
- package/dist/index.mjs.map +7 -0
- package/dist/jsonwebtoken.d.ts +3 -0
- package/dist/listing.d.ts +16 -0
- package/dist/signal-listener.d.ts +51 -0
- package/dist/types.d.ts +41 -0
- package/dist/watchdog.d.ts +11 -0
- package/package.json +35 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1660 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AlreadyExistsError: () => AlreadyExistsError,
|
|
34
|
+
AuthenticatedClient: () => AuthenticatedClient,
|
|
35
|
+
BreakingChangesError: () => BreakingChangesError,
|
|
36
|
+
ChatClientError: () => ChatClientError,
|
|
37
|
+
ChatConfigError: () => ChatConfigError,
|
|
38
|
+
ChatHTTPError: () => ChatHTTPError,
|
|
39
|
+
Client: () => Client2,
|
|
40
|
+
ForbiddenError: () => ForbiddenError,
|
|
41
|
+
InternalError: () => InternalError,
|
|
42
|
+
InvalidDataFormatError: () => InvalidDataFormatError,
|
|
43
|
+
InvalidIdentifierError: () => InvalidIdentifierError,
|
|
44
|
+
InvalidJsonSchemaError: () => InvalidJsonSchemaError,
|
|
45
|
+
InvalidPayloadError: () => InvalidPayloadError,
|
|
46
|
+
InvalidQueryError: () => InvalidQueryError,
|
|
47
|
+
LimitExceededError: () => LimitExceededError,
|
|
48
|
+
MethodNotFoundError: () => MethodNotFoundError,
|
|
49
|
+
OperationTimeoutError: () => OperationTimeoutError,
|
|
50
|
+
PayloadTooLargeError: () => PayloadTooLargeError,
|
|
51
|
+
PaymentRequiredError: () => PaymentRequiredError,
|
|
52
|
+
QuotaExceededError: () => QuotaExceededError,
|
|
53
|
+
RateLimitedError: () => RateLimitedError,
|
|
54
|
+
ReferenceConstraintError: () => ReferenceConstraintError,
|
|
55
|
+
ReferenceNotFoundError: () => ReferenceNotFoundError,
|
|
56
|
+
RelationConflictError: () => RelationConflictError,
|
|
57
|
+
ResourceGoneError: () => ResourceGoneError,
|
|
58
|
+
ResourceLockedConflictError: () => ResourceLockedConflictError,
|
|
59
|
+
ResourceNotFoundError: () => ResourceNotFoundError,
|
|
60
|
+
RuntimeError: () => RuntimeError,
|
|
61
|
+
SignalListener: () => SignalListener,
|
|
62
|
+
UnauthorizedError: () => UnauthorizedError,
|
|
63
|
+
UnknownError: () => UnknownError,
|
|
64
|
+
UnsupportedMediaTypeError: () => UnsupportedMediaTypeError,
|
|
65
|
+
axios: () => axios4,
|
|
66
|
+
errorFrom: () => errorFrom,
|
|
67
|
+
isApiError: () => isApiError
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(index_exports);
|
|
70
|
+
var axios4 = __toESM(require("axios"));
|
|
71
|
+
|
|
72
|
+
// src/errors.ts
|
|
73
|
+
var import_axios = __toESM(require("axios"));
|
|
74
|
+
var import_verror = require("verror");
|
|
75
|
+
|
|
76
|
+
// src/gen/client/errors.ts
|
|
77
|
+
var import_crypto = __toESM(require("crypto"));
|
|
78
|
+
var cryptoLibPolyfill = {
|
|
79
|
+
// Fallback in case crypto isn't available.
|
|
80
|
+
getRandomValues: (array) => new Uint8Array(array.map(() => Math.floor(Math.random() * 256)))
|
|
81
|
+
};
|
|
82
|
+
var cryptoLib = typeof window !== "undefined" && typeof window.document !== "undefined" ? window.crypto : import_crypto.default;
|
|
83
|
+
if (!cryptoLib.getRandomValues) {
|
|
84
|
+
cryptoLib = cryptoLibPolyfill;
|
|
85
|
+
}
|
|
86
|
+
var BaseApiError = class _BaseApiError extends Error {
|
|
87
|
+
constructor(code, description, type, message, error, id, metadata) {
|
|
88
|
+
super(message);
|
|
89
|
+
this.code = code;
|
|
90
|
+
this.description = description;
|
|
91
|
+
this.type = type;
|
|
92
|
+
this.message = message;
|
|
93
|
+
this.error = error;
|
|
94
|
+
this.id = id;
|
|
95
|
+
this.metadata = metadata;
|
|
96
|
+
if (!this.id) {
|
|
97
|
+
this.id = _BaseApiError.generateId();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
isApiError = true;
|
|
101
|
+
format() {
|
|
102
|
+
return `[${this.type}] ${this.message} (Error ID: ${this.id})`;
|
|
103
|
+
}
|
|
104
|
+
toJSON() {
|
|
105
|
+
return {
|
|
106
|
+
id: this.id,
|
|
107
|
+
code: this.code,
|
|
108
|
+
type: this.type,
|
|
109
|
+
message: this.message,
|
|
110
|
+
metadata: this.metadata
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
static generateId() {
|
|
114
|
+
const prefix = this.getPrefix();
|
|
115
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[\-:TZ]/g, "").split(".")[0];
|
|
116
|
+
const randomSuffixByteLength = 4;
|
|
117
|
+
const randomHexSuffix = Array.from(cryptoLib.getRandomValues(new Uint8Array(randomSuffixByteLength))).map((x) => x.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
118
|
+
return `${prefix}_${timestamp}x${randomHexSuffix}`;
|
|
119
|
+
}
|
|
120
|
+
static getPrefix() {
|
|
121
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
122
|
+
return "err_bwsr";
|
|
123
|
+
}
|
|
124
|
+
return "err";
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var isObject = (obj) => typeof obj === "object" && !Array.isArray(obj) && obj !== null;
|
|
128
|
+
var isApiError = (thrown) => {
|
|
129
|
+
return thrown instanceof BaseApiError || isObject(thrown) && thrown.isApiError === true;
|
|
130
|
+
};
|
|
131
|
+
var UnknownError = class extends BaseApiError {
|
|
132
|
+
constructor(message, error, id, metadata) {
|
|
133
|
+
super(500, "An unknown error occurred", "Unknown", message, error, id, metadata);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var InternalError = class extends BaseApiError {
|
|
137
|
+
constructor(message, error, id, metadata) {
|
|
138
|
+
super(500, "An internal error occurred", "Internal", message, error, id, metadata);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var UnauthorizedError = class extends BaseApiError {
|
|
142
|
+
constructor(message, error, id, metadata) {
|
|
143
|
+
super(401, "The request requires to be authenticated.", "Unauthorized", message, error, id, metadata);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var ForbiddenError = class extends BaseApiError {
|
|
147
|
+
constructor(message, error, id, metadata) {
|
|
148
|
+
super(403, "The requested action can't be peform by this resource.", "Forbidden", message, error, id, metadata);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var PayloadTooLargeError = class extends BaseApiError {
|
|
152
|
+
constructor(message, error, id, metadata) {
|
|
153
|
+
super(413, "The request payload is too large.", "PayloadTooLarge", message, error, id, metadata);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var InvalidPayloadError = class extends BaseApiError {
|
|
157
|
+
constructor(message, error, id, metadata) {
|
|
158
|
+
super(400, "The request payload is invalid.", "InvalidPayload", message, error, id, metadata);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var UnsupportedMediaTypeError = class extends BaseApiError {
|
|
162
|
+
constructor(message, error, id, metadata) {
|
|
163
|
+
super(415, "The request is invalid because the content-type is not supported.", "UnsupportedMediaType", message, error, id, metadata);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var MethodNotFoundError = class extends BaseApiError {
|
|
167
|
+
constructor(message, error, id, metadata) {
|
|
168
|
+
super(405, "The requested method does not exist.", "MethodNotFound", message, error, id, metadata);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var ResourceNotFoundError = class extends BaseApiError {
|
|
172
|
+
constructor(message, error, id, metadata) {
|
|
173
|
+
super(404, "The requested resource does not exist.", "ResourceNotFound", message, error, id, metadata);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var InvalidJsonSchemaError = class extends BaseApiError {
|
|
177
|
+
constructor(message, error, id, metadata) {
|
|
178
|
+
super(400, "The provided JSON schema is invalid.", "InvalidJsonSchema", message, error, id, metadata);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var InvalidDataFormatError = class extends BaseApiError {
|
|
182
|
+
constructor(message, error, id, metadata) {
|
|
183
|
+
super(400, "The provided data doesn't respect the provided JSON schema.", "InvalidDataFormat", message, error, id, metadata);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var InvalidIdentifierError = class extends BaseApiError {
|
|
187
|
+
constructor(message, error, id, metadata) {
|
|
188
|
+
super(400, "The provided identifier is not valid. An identifier must start with a lowercase letter, be between 2 and 100 characters long and use only alphanumeric characters.", "InvalidIdentifier", message, error, id, metadata);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var RelationConflictError = class extends BaseApiError {
|
|
192
|
+
constructor(message, error, id, metadata) {
|
|
193
|
+
super(409, "The resource is related with a different resource that the one referenced in the request. This is usually caused when providing two resource identifiers that aren't linked together.", "RelationConflict", message, error, id, metadata);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var ReferenceConstraintError = class extends BaseApiError {
|
|
197
|
+
constructor(message, error, id, metadata) {
|
|
198
|
+
super(409, "The resource cannot be deleted because it's referenced by another resource", "ReferenceConstraint", message, error, id, metadata);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var ResourceLockedConflictError = class extends BaseApiError {
|
|
202
|
+
constructor(message, error, id, metadata) {
|
|
203
|
+
super(409, "The resource is current locked and cannot be operated on until the lock is released.", "ResourceLockedConflict", message, error, id, metadata);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var ResourceGoneError = class extends BaseApiError {
|
|
207
|
+
constructor(message, error, id, metadata) {
|
|
208
|
+
super(410, "The requested resource is no longer available.", "ResourceGone", message, error, id, metadata);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var ReferenceNotFoundError = class extends BaseApiError {
|
|
212
|
+
constructor(message, error, id, metadata) {
|
|
213
|
+
super(400, "The provided resource reference is missing. This is usually caused when providing an invalid id inside the payload of a request.", "ReferenceNotFound", message, error, id, metadata);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var InvalidQueryError = class extends BaseApiError {
|
|
217
|
+
constructor(message, error, id, metadata) {
|
|
218
|
+
super(400, "The provided query is invalid. This is usually caused when providing an invalid parameter for querying a resource.", "InvalidQuery", message, error, id, metadata);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
var RuntimeError = class extends BaseApiError {
|
|
222
|
+
constructor(message, error, id, metadata) {
|
|
223
|
+
super(400, "An error happened during the execution of a runtime (bot or integration).", "Runtime", message, error, id, metadata);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var AlreadyExistsError = class extends BaseApiError {
|
|
227
|
+
constructor(message, error, id, metadata) {
|
|
228
|
+
super(409, "The record attempted to be created already exists.", "AlreadyExists", message, error, id, metadata);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var RateLimitedError = class extends BaseApiError {
|
|
232
|
+
constructor(message, error, id, metadata) {
|
|
233
|
+
super(429, "The request has been rate limited.", "RateLimited", message, error, id, metadata);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var PaymentRequiredError = class extends BaseApiError {
|
|
237
|
+
constructor(message, error, id, metadata) {
|
|
238
|
+
super(402, "A payment is required to perform this request.", "PaymentRequired", message, error, id, metadata);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var QuotaExceededError = class extends BaseApiError {
|
|
242
|
+
constructor(message, error, id, metadata) {
|
|
243
|
+
super(403, "The request exceeds the allowed quota. Quotas are a soft limit that can be increased.", "QuotaExceeded", message, error, id, metadata);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var LimitExceededError = class extends BaseApiError {
|
|
247
|
+
constructor(message, error, id, metadata) {
|
|
248
|
+
super(413, "The request exceeds the allowed limit. Limits are a hard limit that cannot be increased.", "LimitExceeded", message, error, id, metadata);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var BreakingChangesError = class extends BaseApiError {
|
|
252
|
+
constructor(message, error, id, metadata) {
|
|
253
|
+
super(400, "Request payload contains breaking changes which is not allowed for this resource without a version increment.", "BreakingChanges", message, error, id, metadata);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var OperationTimeoutError = class extends BaseApiError {
|
|
257
|
+
constructor(message, error, id, metadata) {
|
|
258
|
+
super(504, "The operation timed out.", "OperationTimeout", message, error, id, metadata);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
var errorTypes = {
|
|
262
|
+
Unknown: UnknownError,
|
|
263
|
+
Internal: InternalError,
|
|
264
|
+
Unauthorized: UnauthorizedError,
|
|
265
|
+
Forbidden: ForbiddenError,
|
|
266
|
+
PayloadTooLarge: PayloadTooLargeError,
|
|
267
|
+
InvalidPayload: InvalidPayloadError,
|
|
268
|
+
UnsupportedMediaType: UnsupportedMediaTypeError,
|
|
269
|
+
MethodNotFound: MethodNotFoundError,
|
|
270
|
+
ResourceNotFound: ResourceNotFoundError,
|
|
271
|
+
InvalidJsonSchema: InvalidJsonSchemaError,
|
|
272
|
+
InvalidDataFormat: InvalidDataFormatError,
|
|
273
|
+
InvalidIdentifier: InvalidIdentifierError,
|
|
274
|
+
RelationConflict: RelationConflictError,
|
|
275
|
+
ReferenceConstraint: ReferenceConstraintError,
|
|
276
|
+
ResourceLockedConflict: ResourceLockedConflictError,
|
|
277
|
+
ResourceGone: ResourceGoneError,
|
|
278
|
+
ReferenceNotFound: ReferenceNotFoundError,
|
|
279
|
+
InvalidQuery: InvalidQueryError,
|
|
280
|
+
Runtime: RuntimeError,
|
|
281
|
+
AlreadyExists: AlreadyExistsError,
|
|
282
|
+
RateLimited: RateLimitedError,
|
|
283
|
+
PaymentRequired: PaymentRequiredError,
|
|
284
|
+
QuotaExceeded: QuotaExceededError,
|
|
285
|
+
LimitExceeded: LimitExceededError,
|
|
286
|
+
BreakingChanges: BreakingChangesError,
|
|
287
|
+
OperationTimeout: OperationTimeoutError
|
|
288
|
+
};
|
|
289
|
+
var errorFrom = (err) => {
|
|
290
|
+
if (isApiError(err)) {
|
|
291
|
+
return err;
|
|
292
|
+
} else if (err instanceof Error) {
|
|
293
|
+
return new UnknownError(err.message, err);
|
|
294
|
+
} else if (typeof err === "string") {
|
|
295
|
+
return new UnknownError(err);
|
|
296
|
+
} else {
|
|
297
|
+
return getApiErrorFromObject(err);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
function getApiErrorFromObject(err) {
|
|
301
|
+
if (typeof err === "object" && "code" in err && "type" in err && "id" in err && "message" in err && typeof err.type === "string" && typeof err.message === "string") {
|
|
302
|
+
const ErrorClass = errorTypes[err.type];
|
|
303
|
+
if (!ErrorClass) {
|
|
304
|
+
return new UnknownError(`An unclassified API error occurred: ${err.message} (Type: ${err.type}, Code: ${err.code})`);
|
|
305
|
+
}
|
|
306
|
+
return new ErrorClass(err.message, void 0, err.id || "UNKNOWN", err.metadata);
|
|
307
|
+
}
|
|
308
|
+
return new UnknownError("An invalid error occurred: " + JSON.stringify(err));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// src/errors.ts
|
|
312
|
+
var ChatClientError = class _ChatClientError extends import_verror.VError {
|
|
313
|
+
static wrap(thrown, message) {
|
|
314
|
+
const err = _ChatClientError.map(thrown);
|
|
315
|
+
return new _ChatClientError(err, message ?? "");
|
|
316
|
+
}
|
|
317
|
+
static map(thrown) {
|
|
318
|
+
if (thrown instanceof _ChatClientError) {
|
|
319
|
+
return thrown;
|
|
320
|
+
}
|
|
321
|
+
if (import_axios.default.isAxiosError(thrown)) {
|
|
322
|
+
return ChatHTTPError.fromAxios(thrown);
|
|
323
|
+
}
|
|
324
|
+
if (thrown instanceof Error) {
|
|
325
|
+
const { message } = thrown;
|
|
326
|
+
return new _ChatClientError(message);
|
|
327
|
+
}
|
|
328
|
+
return new _ChatClientError(String(thrown));
|
|
329
|
+
}
|
|
330
|
+
constructor(first, second) {
|
|
331
|
+
if (typeof first === "string") {
|
|
332
|
+
super(first);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
super(first, second);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
var ChatHTTPError = class _ChatHTTPError extends ChatClientError {
|
|
339
|
+
constructor(status, message) {
|
|
340
|
+
super(message);
|
|
341
|
+
this.status = status;
|
|
342
|
+
}
|
|
343
|
+
static fromAxios(e) {
|
|
344
|
+
const message = this._axiosMsg(e);
|
|
345
|
+
return new _ChatHTTPError(e.response?.status, message);
|
|
346
|
+
}
|
|
347
|
+
static _axiosMsg(e) {
|
|
348
|
+
let message = e.message;
|
|
349
|
+
if (e.response?.statusText) {
|
|
350
|
+
message += `
|
|
351
|
+
${e.response?.statusText}`;
|
|
352
|
+
}
|
|
353
|
+
if (e.response?.status && e.request?.method && e.request?.path) {
|
|
354
|
+
message += `
|
|
355
|
+
(${e.response?.status}) ${e.request.method} ${e.request.path}`;
|
|
356
|
+
}
|
|
357
|
+
if (e.response?.data?.message) {
|
|
358
|
+
message += `
|
|
359
|
+
${e.response?.data?.message}`;
|
|
360
|
+
}
|
|
361
|
+
return message;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
var ChatConfigError = class extends ChatClientError {
|
|
365
|
+
constructor(message) {
|
|
366
|
+
super(message);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/client.ts
|
|
371
|
+
var import_axios3 = __toESM(require("axios"));
|
|
372
|
+
var import_browser_or_node3 = require("browser-or-node");
|
|
373
|
+
|
|
374
|
+
// src/consts.ts
|
|
375
|
+
var defaultBaseApiUrl = "https://botruntime.ru";
|
|
376
|
+
|
|
377
|
+
// src/gen/client/index.ts
|
|
378
|
+
var import_axios2 = __toESM(require("axios"));
|
|
379
|
+
|
|
380
|
+
// src/gen/client/to-axios.ts
|
|
381
|
+
var import_qs = __toESM(require("qs"));
|
|
382
|
+
var isDefined = (pair) => pair[1] !== void 0;
|
|
383
|
+
var toAxiosRequest = (req) => {
|
|
384
|
+
const { method, path, query, headers: headerParams, body } = req;
|
|
385
|
+
const headerEntries = Object.entries(headerParams).filter(isDefined);
|
|
386
|
+
const headers = Object.fromEntries(headerEntries);
|
|
387
|
+
const queryString = import_qs.default.stringify(query, { encode: true, arrayFormat: "repeat", allowDots: true });
|
|
388
|
+
const url = queryString ? [path, queryString].join("?") : path;
|
|
389
|
+
const data = ["put", "post", "delete", "patch"].includes(method.toLowerCase()) ? body : void 0;
|
|
390
|
+
return {
|
|
391
|
+
method,
|
|
392
|
+
url,
|
|
393
|
+
headers,
|
|
394
|
+
data
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// src/gen/client/operations/getConversation.ts
|
|
399
|
+
var parseReq = (input) => {
|
|
400
|
+
return {
|
|
401
|
+
path: `/conversations/${encodeURIComponent(input["id"])}`,
|
|
402
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
403
|
+
query: {},
|
|
404
|
+
params: { "id": input["id"] },
|
|
405
|
+
body: {}
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// src/gen/client/operations/createConversation.ts
|
|
410
|
+
var parseReq2 = (input) => {
|
|
411
|
+
return {
|
|
412
|
+
path: `/conversations`,
|
|
413
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
414
|
+
query: {},
|
|
415
|
+
params: {},
|
|
416
|
+
body: { "id": input["id"] }
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
// src/gen/client/operations/getOrCreateConversation.ts
|
|
421
|
+
var parseReq3 = (input) => {
|
|
422
|
+
return {
|
|
423
|
+
path: `/conversations/get-or-create`,
|
|
424
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
425
|
+
query: {},
|
|
426
|
+
params: {},
|
|
427
|
+
body: { "id": input["id"] }
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// src/gen/client/operations/deleteConversation.ts
|
|
432
|
+
var parseReq4 = (input) => {
|
|
433
|
+
return {
|
|
434
|
+
path: `/conversations/${encodeURIComponent(input["id"])}`,
|
|
435
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
436
|
+
query: {},
|
|
437
|
+
params: { "id": input["id"] },
|
|
438
|
+
body: {}
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// src/gen/client/operations/listConversations.ts
|
|
443
|
+
var parseReq5 = (input) => {
|
|
444
|
+
return {
|
|
445
|
+
path: `/conversations`,
|
|
446
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
447
|
+
query: { "nextToken": input["nextToken"] },
|
|
448
|
+
params: {},
|
|
449
|
+
body: {}
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// src/gen/client/operations/listenConversation.ts
|
|
454
|
+
var parseReq6 = (input) => {
|
|
455
|
+
return {
|
|
456
|
+
path: `/conversations/${encodeURIComponent(input["id"])}/listen`,
|
|
457
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
458
|
+
query: {},
|
|
459
|
+
params: { "id": input["id"] },
|
|
460
|
+
body: {}
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
// src/gen/client/operations/listMessages.ts
|
|
465
|
+
var parseReq7 = (input) => {
|
|
466
|
+
return {
|
|
467
|
+
path: `/conversations/${encodeURIComponent(input["conversationId"])}/messages`,
|
|
468
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
469
|
+
query: { "nextToken": input["nextToken"] },
|
|
470
|
+
params: { "conversationId": input["conversationId"] },
|
|
471
|
+
body: {}
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// src/gen/client/operations/addParticipant.ts
|
|
476
|
+
var parseReq8 = (input) => {
|
|
477
|
+
return {
|
|
478
|
+
path: `/conversations/${encodeURIComponent(input["conversationId"])}/participants`,
|
|
479
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
480
|
+
query: {},
|
|
481
|
+
params: { "conversationId": input["conversationId"] },
|
|
482
|
+
body: { "userId": input["userId"] }
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// src/gen/client/operations/removeParticipant.ts
|
|
487
|
+
var parseReq9 = (input) => {
|
|
488
|
+
return {
|
|
489
|
+
path: `/conversations/${encodeURIComponent(input["conversationId"])}/participants/${encodeURIComponent(input["userId"])}`,
|
|
490
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
491
|
+
query: {},
|
|
492
|
+
params: { "conversationId": input["conversationId"], "userId": input["userId"] },
|
|
493
|
+
body: {}
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// src/gen/client/operations/getParticipant.ts
|
|
498
|
+
var parseReq10 = (input) => {
|
|
499
|
+
return {
|
|
500
|
+
path: `/conversations/${encodeURIComponent(input["conversationId"])}/participants/${encodeURIComponent(input["userId"])}`,
|
|
501
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
502
|
+
query: {},
|
|
503
|
+
params: { "conversationId": input["conversationId"], "userId": input["userId"] },
|
|
504
|
+
body: {}
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// src/gen/client/operations/listParticipants.ts
|
|
509
|
+
var parseReq11 = (input) => {
|
|
510
|
+
return {
|
|
511
|
+
path: `/conversations/${encodeURIComponent(input["conversationId"])}/participants`,
|
|
512
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
513
|
+
query: { "nextToken": input["nextToken"] },
|
|
514
|
+
params: { "conversationId": input["conversationId"] },
|
|
515
|
+
body: {}
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// src/gen/client/operations/getMessage.ts
|
|
520
|
+
var parseReq12 = (input) => {
|
|
521
|
+
return {
|
|
522
|
+
path: `/messages/${encodeURIComponent(input["id"])}`,
|
|
523
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
524
|
+
query: {},
|
|
525
|
+
params: { "id": input["id"] },
|
|
526
|
+
body: {}
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
// src/gen/client/operations/createMessage.ts
|
|
531
|
+
var parseReq13 = (input) => {
|
|
532
|
+
return {
|
|
533
|
+
path: `/messages`,
|
|
534
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
535
|
+
query: {},
|
|
536
|
+
params: {},
|
|
537
|
+
body: { "payload": input["payload"], "conversationId": input["conversationId"], "metadata": input["metadata"] }
|
|
538
|
+
};
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
// src/gen/client/operations/deleteMessage.ts
|
|
542
|
+
var parseReq14 = (input) => {
|
|
543
|
+
return {
|
|
544
|
+
path: `/messages/${encodeURIComponent(input["id"])}`,
|
|
545
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
546
|
+
query: {},
|
|
547
|
+
params: { "id": input["id"] },
|
|
548
|
+
body: {}
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
// src/gen/client/operations/getUser.ts
|
|
553
|
+
var parseReq15 = (input) => {
|
|
554
|
+
return {
|
|
555
|
+
path: `/users/me`,
|
|
556
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
557
|
+
query: {},
|
|
558
|
+
params: {},
|
|
559
|
+
body: {}
|
|
560
|
+
};
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
// src/gen/client/operations/createUser.ts
|
|
564
|
+
var parseReq16 = (input) => {
|
|
565
|
+
return {
|
|
566
|
+
path: `/users`,
|
|
567
|
+
headers: {},
|
|
568
|
+
query: {},
|
|
569
|
+
params: {},
|
|
570
|
+
body: { "name": input["name"], "pictureUrl": input["pictureUrl"], "profile": input["profile"], "id": input["id"] }
|
|
571
|
+
};
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// src/gen/client/operations/getOrCreateUser.ts
|
|
575
|
+
var parseReq17 = (input) => {
|
|
576
|
+
return {
|
|
577
|
+
path: `/users/get-or-create`,
|
|
578
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
579
|
+
query: {},
|
|
580
|
+
params: {},
|
|
581
|
+
body: { "name": input["name"], "pictureUrl": input["pictureUrl"], "profile": input["profile"] }
|
|
582
|
+
};
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/gen/client/operations/updateUser.ts
|
|
586
|
+
var parseReq18 = (input) => {
|
|
587
|
+
return {
|
|
588
|
+
path: `/users/me`,
|
|
589
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
590
|
+
query: {},
|
|
591
|
+
params: {},
|
|
592
|
+
body: { "name": input["name"], "pictureUrl": input["pictureUrl"], "profile": input["profile"] }
|
|
593
|
+
};
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
// src/gen/client/operations/deleteUser.ts
|
|
597
|
+
var parseReq19 = (input) => {
|
|
598
|
+
return {
|
|
599
|
+
path: `/users/me`,
|
|
600
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
601
|
+
query: {},
|
|
602
|
+
params: {},
|
|
603
|
+
body: {}
|
|
604
|
+
};
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// src/gen/client/operations/getEvent.ts
|
|
608
|
+
var parseReq20 = (input) => {
|
|
609
|
+
return {
|
|
610
|
+
path: `/events/${encodeURIComponent(input["id"])}`,
|
|
611
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
612
|
+
query: {},
|
|
613
|
+
params: { "id": input["id"] },
|
|
614
|
+
body: {}
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// src/gen/client/operations/createEvent.ts
|
|
619
|
+
var parseReq21 = (input) => {
|
|
620
|
+
return {
|
|
621
|
+
path: `/events`,
|
|
622
|
+
headers: { "x-user-key": input["x-user-key"] },
|
|
623
|
+
query: {},
|
|
624
|
+
params: {},
|
|
625
|
+
body: { "payload": input["payload"], "conversationId": input["conversationId"] }
|
|
626
|
+
};
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// src/gen/client/index.ts
|
|
630
|
+
var apiVersion = "0.7.6";
|
|
631
|
+
var Client = class {
|
|
632
|
+
constructor(axiosInstance, props = {}) {
|
|
633
|
+
this.axiosInstance = axiosInstance;
|
|
634
|
+
this.props = props;
|
|
635
|
+
}
|
|
636
|
+
getConversation = async (input) => {
|
|
637
|
+
const { path, headers, query, body } = parseReq(input);
|
|
638
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
639
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
640
|
+
const axiosReq = mapRequest({
|
|
641
|
+
method: "get",
|
|
642
|
+
path,
|
|
643
|
+
headers: { ...headers },
|
|
644
|
+
query: { ...query },
|
|
645
|
+
body
|
|
646
|
+
});
|
|
647
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
648
|
+
throw mapErrorResponse(e);
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
createConversation = async (input) => {
|
|
652
|
+
const { path, headers, query, body } = parseReq2(input);
|
|
653
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
654
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
655
|
+
const axiosReq = mapRequest({
|
|
656
|
+
method: "post",
|
|
657
|
+
path,
|
|
658
|
+
headers: { ...headers },
|
|
659
|
+
query: { ...query },
|
|
660
|
+
body
|
|
661
|
+
});
|
|
662
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
663
|
+
throw mapErrorResponse(e);
|
|
664
|
+
});
|
|
665
|
+
};
|
|
666
|
+
getOrCreateConversation = async (input) => {
|
|
667
|
+
const { path, headers, query, body } = parseReq3(input);
|
|
668
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
669
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
670
|
+
const axiosReq = mapRequest({
|
|
671
|
+
method: "post",
|
|
672
|
+
path,
|
|
673
|
+
headers: { ...headers },
|
|
674
|
+
query: { ...query },
|
|
675
|
+
body
|
|
676
|
+
});
|
|
677
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
678
|
+
throw mapErrorResponse(e);
|
|
679
|
+
});
|
|
680
|
+
};
|
|
681
|
+
deleteConversation = async (input) => {
|
|
682
|
+
const { path, headers, query, body } = parseReq4(input);
|
|
683
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
684
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
685
|
+
const axiosReq = mapRequest({
|
|
686
|
+
method: "delete",
|
|
687
|
+
path,
|
|
688
|
+
headers: { ...headers },
|
|
689
|
+
query: { ...query },
|
|
690
|
+
body
|
|
691
|
+
});
|
|
692
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
693
|
+
throw mapErrorResponse(e);
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
listConversations = async (input) => {
|
|
697
|
+
const { path, headers, query, body } = parseReq5(input);
|
|
698
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
699
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
700
|
+
const axiosReq = mapRequest({
|
|
701
|
+
method: "get",
|
|
702
|
+
path,
|
|
703
|
+
headers: { ...headers },
|
|
704
|
+
query: { ...query },
|
|
705
|
+
body
|
|
706
|
+
});
|
|
707
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
708
|
+
throw mapErrorResponse(e);
|
|
709
|
+
});
|
|
710
|
+
};
|
|
711
|
+
listenConversation = async (input) => {
|
|
712
|
+
const { path, headers, query, body } = parseReq6(input);
|
|
713
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
714
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
715
|
+
const axiosReq = mapRequest({
|
|
716
|
+
method: "get",
|
|
717
|
+
path,
|
|
718
|
+
headers: { ...headers },
|
|
719
|
+
query: { ...query },
|
|
720
|
+
body
|
|
721
|
+
});
|
|
722
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
723
|
+
throw mapErrorResponse(e);
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
listMessages = async (input) => {
|
|
727
|
+
const { path, headers, query, body } = parseReq7(input);
|
|
728
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
729
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
730
|
+
const axiosReq = mapRequest({
|
|
731
|
+
method: "get",
|
|
732
|
+
path,
|
|
733
|
+
headers: { ...headers },
|
|
734
|
+
query: { ...query },
|
|
735
|
+
body
|
|
736
|
+
});
|
|
737
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
738
|
+
throw mapErrorResponse(e);
|
|
739
|
+
});
|
|
740
|
+
};
|
|
741
|
+
addParticipant = async (input) => {
|
|
742
|
+
const { path, headers, query, body } = parseReq8(input);
|
|
743
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
744
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
745
|
+
const axiosReq = mapRequest({
|
|
746
|
+
method: "post",
|
|
747
|
+
path,
|
|
748
|
+
headers: { ...headers },
|
|
749
|
+
query: { ...query },
|
|
750
|
+
body
|
|
751
|
+
});
|
|
752
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
753
|
+
throw mapErrorResponse(e);
|
|
754
|
+
});
|
|
755
|
+
};
|
|
756
|
+
removeParticipant = async (input) => {
|
|
757
|
+
const { path, headers, query, body } = parseReq9(input);
|
|
758
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
759
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
760
|
+
const axiosReq = mapRequest({
|
|
761
|
+
method: "delete",
|
|
762
|
+
path,
|
|
763
|
+
headers: { ...headers },
|
|
764
|
+
query: { ...query },
|
|
765
|
+
body
|
|
766
|
+
});
|
|
767
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
768
|
+
throw mapErrorResponse(e);
|
|
769
|
+
});
|
|
770
|
+
};
|
|
771
|
+
getParticipant = async (input) => {
|
|
772
|
+
const { path, headers, query, body } = parseReq10(input);
|
|
773
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
774
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
775
|
+
const axiosReq = mapRequest({
|
|
776
|
+
method: "get",
|
|
777
|
+
path,
|
|
778
|
+
headers: { ...headers },
|
|
779
|
+
query: { ...query },
|
|
780
|
+
body
|
|
781
|
+
});
|
|
782
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
783
|
+
throw mapErrorResponse(e);
|
|
784
|
+
});
|
|
785
|
+
};
|
|
786
|
+
listParticipants = async (input) => {
|
|
787
|
+
const { path, headers, query, body } = parseReq11(input);
|
|
788
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
789
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
790
|
+
const axiosReq = mapRequest({
|
|
791
|
+
method: "get",
|
|
792
|
+
path,
|
|
793
|
+
headers: { ...headers },
|
|
794
|
+
query: { ...query },
|
|
795
|
+
body
|
|
796
|
+
});
|
|
797
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
798
|
+
throw mapErrorResponse(e);
|
|
799
|
+
});
|
|
800
|
+
};
|
|
801
|
+
getMessage = async (input) => {
|
|
802
|
+
const { path, headers, query, body } = parseReq12(input);
|
|
803
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
804
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
805
|
+
const axiosReq = mapRequest({
|
|
806
|
+
method: "get",
|
|
807
|
+
path,
|
|
808
|
+
headers: { ...headers },
|
|
809
|
+
query: { ...query },
|
|
810
|
+
body
|
|
811
|
+
});
|
|
812
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
813
|
+
throw mapErrorResponse(e);
|
|
814
|
+
});
|
|
815
|
+
};
|
|
816
|
+
createMessage = async (input) => {
|
|
817
|
+
const { path, headers, query, body } = parseReq13(input);
|
|
818
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
819
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
820
|
+
const axiosReq = mapRequest({
|
|
821
|
+
method: "post",
|
|
822
|
+
path,
|
|
823
|
+
headers: { ...headers },
|
|
824
|
+
query: { ...query },
|
|
825
|
+
body
|
|
826
|
+
});
|
|
827
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
828
|
+
throw mapErrorResponse(e);
|
|
829
|
+
});
|
|
830
|
+
};
|
|
831
|
+
deleteMessage = async (input) => {
|
|
832
|
+
const { path, headers, query, body } = parseReq14(input);
|
|
833
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
834
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
835
|
+
const axiosReq = mapRequest({
|
|
836
|
+
method: "delete",
|
|
837
|
+
path,
|
|
838
|
+
headers: { ...headers },
|
|
839
|
+
query: { ...query },
|
|
840
|
+
body
|
|
841
|
+
});
|
|
842
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
843
|
+
throw mapErrorResponse(e);
|
|
844
|
+
});
|
|
845
|
+
};
|
|
846
|
+
getUser = async (input) => {
|
|
847
|
+
const { path, headers, query, body } = parseReq15(input);
|
|
848
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
849
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
850
|
+
const axiosReq = mapRequest({
|
|
851
|
+
method: "get",
|
|
852
|
+
path,
|
|
853
|
+
headers: { ...headers },
|
|
854
|
+
query: { ...query },
|
|
855
|
+
body
|
|
856
|
+
});
|
|
857
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
858
|
+
throw mapErrorResponse(e);
|
|
859
|
+
});
|
|
860
|
+
};
|
|
861
|
+
createUser = async (input) => {
|
|
862
|
+
const { path, headers, query, body } = parseReq16(input);
|
|
863
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
864
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
865
|
+
const axiosReq = mapRequest({
|
|
866
|
+
method: "post",
|
|
867
|
+
path,
|
|
868
|
+
headers: { ...headers },
|
|
869
|
+
query: { ...query },
|
|
870
|
+
body
|
|
871
|
+
});
|
|
872
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
873
|
+
throw mapErrorResponse(e);
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
getOrCreateUser = async (input) => {
|
|
877
|
+
const { path, headers, query, body } = parseReq17(input);
|
|
878
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
879
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
880
|
+
const axiosReq = mapRequest({
|
|
881
|
+
method: "post",
|
|
882
|
+
path,
|
|
883
|
+
headers: { ...headers },
|
|
884
|
+
query: { ...query },
|
|
885
|
+
body
|
|
886
|
+
});
|
|
887
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
888
|
+
throw mapErrorResponse(e);
|
|
889
|
+
});
|
|
890
|
+
};
|
|
891
|
+
updateUser = async (input) => {
|
|
892
|
+
const { path, headers, query, body } = parseReq18(input);
|
|
893
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
894
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
895
|
+
const axiosReq = mapRequest({
|
|
896
|
+
method: "put",
|
|
897
|
+
path,
|
|
898
|
+
headers: { ...headers },
|
|
899
|
+
query: { ...query },
|
|
900
|
+
body
|
|
901
|
+
});
|
|
902
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
903
|
+
throw mapErrorResponse(e);
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
deleteUser = async (input) => {
|
|
907
|
+
const { path, headers, query, body } = parseReq19(input);
|
|
908
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
909
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
910
|
+
const axiosReq = mapRequest({
|
|
911
|
+
method: "delete",
|
|
912
|
+
path,
|
|
913
|
+
headers: { ...headers },
|
|
914
|
+
query: { ...query },
|
|
915
|
+
body
|
|
916
|
+
});
|
|
917
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
918
|
+
throw mapErrorResponse(e);
|
|
919
|
+
});
|
|
920
|
+
};
|
|
921
|
+
getEvent = async (input) => {
|
|
922
|
+
const { path, headers, query, body } = parseReq20(input);
|
|
923
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
924
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
925
|
+
const axiosReq = mapRequest({
|
|
926
|
+
method: "get",
|
|
927
|
+
path,
|
|
928
|
+
headers: { ...headers },
|
|
929
|
+
query: { ...query },
|
|
930
|
+
body
|
|
931
|
+
});
|
|
932
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
933
|
+
throw mapErrorResponse(e);
|
|
934
|
+
});
|
|
935
|
+
};
|
|
936
|
+
createEvent = async (input) => {
|
|
937
|
+
const { path, headers, query, body } = parseReq21(input);
|
|
938
|
+
const mapRequest = this.props.toAxiosRequest ?? toAxiosRequest;
|
|
939
|
+
const mapErrorResponse = this.props.toApiError ?? toApiError;
|
|
940
|
+
const axiosReq = mapRequest({
|
|
941
|
+
method: "post",
|
|
942
|
+
path,
|
|
943
|
+
headers: { ...headers },
|
|
944
|
+
query: { ...query },
|
|
945
|
+
body
|
|
946
|
+
});
|
|
947
|
+
return this.axiosInstance.request(axiosReq).then((res) => res.data).catch((e) => {
|
|
948
|
+
throw mapErrorResponse(e);
|
|
949
|
+
});
|
|
950
|
+
};
|
|
951
|
+
};
|
|
952
|
+
function toApiError(err) {
|
|
953
|
+
if (import_axios2.default.isAxiosError(err) && err.response?.data) {
|
|
954
|
+
return errorFrom(err.response.data);
|
|
955
|
+
}
|
|
956
|
+
return errorFrom(err);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
// src/jsonwebtoken.ts
|
|
960
|
+
var import_browser_or_node = require("browser-or-node");
|
|
961
|
+
var requireJwt = () => require("jsonwebtoken");
|
|
962
|
+
var packageModule = import_browser_or_node.isBrowser ? null : requireJwt();
|
|
963
|
+
var jsonwebtoken_default = packageModule;
|
|
964
|
+
|
|
965
|
+
// src/listing.ts
|
|
966
|
+
var AsyncCollection = class {
|
|
967
|
+
constructor(_list) {
|
|
968
|
+
this._list = _list;
|
|
969
|
+
}
|
|
970
|
+
async *[Symbol.asyncIterator]() {
|
|
971
|
+
let nextToken;
|
|
972
|
+
do {
|
|
973
|
+
const { items, meta } = await this._list({ nextToken });
|
|
974
|
+
nextToken = meta.nextToken;
|
|
975
|
+
for (const item of items) {
|
|
976
|
+
yield item;
|
|
977
|
+
}
|
|
978
|
+
} while (nextToken);
|
|
979
|
+
}
|
|
980
|
+
async collect(props = {}) {
|
|
981
|
+
const limit = props.limit ?? Number.POSITIVE_INFINITY;
|
|
982
|
+
const arr = [];
|
|
983
|
+
let count = 0;
|
|
984
|
+
for await (const item of this) {
|
|
985
|
+
arr.push(item);
|
|
986
|
+
count++;
|
|
987
|
+
if (count >= limit) {
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return arr;
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
// src/event-emitter.ts
|
|
996
|
+
var EventEmitter = class {
|
|
997
|
+
_listeners = {};
|
|
998
|
+
emit(type, event) {
|
|
999
|
+
const listeners = this._listeners[type];
|
|
1000
|
+
if (!listeners) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
for (const listener of [...listeners]) {
|
|
1004
|
+
listener(event);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
onceOrMore(type, listener) {
|
|
1008
|
+
const wrapped = (event) => {
|
|
1009
|
+
const status = listener(event);
|
|
1010
|
+
if (status === "stop-listening") {
|
|
1011
|
+
this.off(type, wrapped);
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
this.on(type, wrapped);
|
|
1015
|
+
}
|
|
1016
|
+
once(type, listener) {
|
|
1017
|
+
const wrapped = (event) => {
|
|
1018
|
+
this.off(type, wrapped);
|
|
1019
|
+
listener(event);
|
|
1020
|
+
};
|
|
1021
|
+
this.on(type, wrapped);
|
|
1022
|
+
}
|
|
1023
|
+
on(type, listener) {
|
|
1024
|
+
if (!this._listeners[type]) {
|
|
1025
|
+
this._listeners[type] = [];
|
|
1026
|
+
}
|
|
1027
|
+
this._listeners[type].push(listener);
|
|
1028
|
+
}
|
|
1029
|
+
off(type, listener) {
|
|
1030
|
+
const listeners = this._listeners[type];
|
|
1031
|
+
if (!listeners) {
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
const index = listeners.indexOf(listener);
|
|
1035
|
+
if (index !== -1) {
|
|
1036
|
+
listeners.splice(index, 1);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
cleanup() {
|
|
1040
|
+
this._listeners = {};
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
// src/eventsource.ts
|
|
1045
|
+
var import_browser_or_node2 = require("browser-or-node");
|
|
1046
|
+
var makeEventSource = (url, props = {}) => {
|
|
1047
|
+
if (import_browser_or_node2.isBrowser) {
|
|
1048
|
+
const module2 = require("event-source-polyfill");
|
|
1049
|
+
const ctor = module2.EventSourcePolyfill;
|
|
1050
|
+
const source = new ctor(url, { headers: props.headers });
|
|
1051
|
+
const emitter = new EventEmitter();
|
|
1052
|
+
source.onopen = (ev) => emitter.emit("open", ev);
|
|
1053
|
+
source.onmessage = (ev) => emitter.emit("message", ev);
|
|
1054
|
+
source.onerror = (ev) => emitter.emit("error", ev);
|
|
1055
|
+
return {
|
|
1056
|
+
emitter,
|
|
1057
|
+
source
|
|
1058
|
+
};
|
|
1059
|
+
} else {
|
|
1060
|
+
const module2 = require("eventsource");
|
|
1061
|
+
const source = new module2(url, { headers: props.headers });
|
|
1062
|
+
const emitter = new EventEmitter();
|
|
1063
|
+
source.onopen = (ev) => emitter.emit("open", ev);
|
|
1064
|
+
source.onmessage = (ev) => emitter.emit("message", ev);
|
|
1065
|
+
source.onerror = (ev) => emitter.emit("error", ev);
|
|
1066
|
+
return {
|
|
1067
|
+
emitter,
|
|
1068
|
+
source
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
var listenEventSource = async (url, props = {}) => {
|
|
1073
|
+
const { emitter, source } = makeEventSource(url, props);
|
|
1074
|
+
await new Promise((resolve, reject) => {
|
|
1075
|
+
emitter.on("open", () => {
|
|
1076
|
+
resolve();
|
|
1077
|
+
});
|
|
1078
|
+
emitter.on("error", (thrown) => {
|
|
1079
|
+
reject(thrown);
|
|
1080
|
+
});
|
|
1081
|
+
}).finally(() => emitter.cleanup());
|
|
1082
|
+
return {
|
|
1083
|
+
on: emitter.on.bind(emitter),
|
|
1084
|
+
close: () => {
|
|
1085
|
+
emitter.cleanup();
|
|
1086
|
+
source.close();
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// src/gen/signals/messageCreated.z.ts
|
|
1092
|
+
var import_zod = require("zod");
|
|
1093
|
+
var messageCreated_z_default = import_zod.z.object({
|
|
1094
|
+
type: import_zod.z.literal("message_created"),
|
|
1095
|
+
data: import_zod.z.object({
|
|
1096
|
+
id: import_zod.z.string().describe("Identifier of the [Message](#schema_message)"),
|
|
1097
|
+
createdAt: import_zod.z.string().datetime().describe(
|
|
1098
|
+
"Creation date of the [Message](#schema_message) in ISO 8601 format"
|
|
1099
|
+
),
|
|
1100
|
+
payload: import_zod.z.union([
|
|
1101
|
+
import_zod.z.object({ type: import_zod.z.literal("audio"), audioUrl: import_zod.z.string().min(1) }),
|
|
1102
|
+
import_zod.z.object({
|
|
1103
|
+
type: import_zod.z.literal("card"),
|
|
1104
|
+
title: import_zod.z.string().min(1),
|
|
1105
|
+
subtitle: import_zod.z.string().min(1).optional(),
|
|
1106
|
+
imageUrl: import_zod.z.string().min(1).optional(),
|
|
1107
|
+
actions: import_zod.z.array(
|
|
1108
|
+
import_zod.z.object({
|
|
1109
|
+
action: import_zod.z.enum(["postback", "url", "say"]),
|
|
1110
|
+
label: import_zod.z.string().min(1),
|
|
1111
|
+
value: import_zod.z.string().min(1)
|
|
1112
|
+
})
|
|
1113
|
+
)
|
|
1114
|
+
}),
|
|
1115
|
+
import_zod.z.object({
|
|
1116
|
+
type: import_zod.z.literal("carousel"),
|
|
1117
|
+
items: import_zod.z.array(
|
|
1118
|
+
import_zod.z.object({
|
|
1119
|
+
type: import_zod.z.literal("card"),
|
|
1120
|
+
title: import_zod.z.string().min(1),
|
|
1121
|
+
subtitle: import_zod.z.string().min(1).optional(),
|
|
1122
|
+
imageUrl: import_zod.z.string().min(1).optional(),
|
|
1123
|
+
actions: import_zod.z.array(
|
|
1124
|
+
import_zod.z.object({
|
|
1125
|
+
action: import_zod.z.enum(["postback", "url", "say"]),
|
|
1126
|
+
label: import_zod.z.string().min(1),
|
|
1127
|
+
value: import_zod.z.string().min(1)
|
|
1128
|
+
})
|
|
1129
|
+
)
|
|
1130
|
+
})
|
|
1131
|
+
)
|
|
1132
|
+
}),
|
|
1133
|
+
import_zod.z.object({
|
|
1134
|
+
text: import_zod.z.string().min(1),
|
|
1135
|
+
options: import_zod.z.array(
|
|
1136
|
+
import_zod.z.object({ label: import_zod.z.string().min(1), value: import_zod.z.string().min(1) })
|
|
1137
|
+
),
|
|
1138
|
+
type: import_zod.z.literal("choice")
|
|
1139
|
+
}),
|
|
1140
|
+
import_zod.z.object({
|
|
1141
|
+
text: import_zod.z.string().min(1),
|
|
1142
|
+
options: import_zod.z.array(
|
|
1143
|
+
import_zod.z.object({ label: import_zod.z.string().min(1), value: import_zod.z.string().min(1) })
|
|
1144
|
+
),
|
|
1145
|
+
type: import_zod.z.literal("dropdown")
|
|
1146
|
+
}),
|
|
1147
|
+
import_zod.z.object({
|
|
1148
|
+
type: import_zod.z.literal("file"),
|
|
1149
|
+
fileUrl: import_zod.z.string().min(1),
|
|
1150
|
+
title: import_zod.z.string().min(1).optional()
|
|
1151
|
+
}),
|
|
1152
|
+
import_zod.z.object({ type: import_zod.z.literal("image"), imageUrl: import_zod.z.string().min(1) }),
|
|
1153
|
+
import_zod.z.object({
|
|
1154
|
+
type: import_zod.z.literal("location"),
|
|
1155
|
+
latitude: import_zod.z.number(),
|
|
1156
|
+
longitude: import_zod.z.number(),
|
|
1157
|
+
address: import_zod.z.string().optional(),
|
|
1158
|
+
title: import_zod.z.string().optional()
|
|
1159
|
+
}),
|
|
1160
|
+
import_zod.z.object({ type: import_zod.z.literal("text"), text: import_zod.z.string().min(1) }),
|
|
1161
|
+
import_zod.z.object({ type: import_zod.z.literal("video"), videoUrl: import_zod.z.string().min(1) }),
|
|
1162
|
+
import_zod.z.object({
|
|
1163
|
+
type: import_zod.z.literal("markdown"),
|
|
1164
|
+
markdown: import_zod.z.string().min(1)
|
|
1165
|
+
}),
|
|
1166
|
+
import_zod.z.object({
|
|
1167
|
+
type: import_zod.z.literal("bloc"),
|
|
1168
|
+
items: import_zod.z.array(
|
|
1169
|
+
import_zod.z.union([
|
|
1170
|
+
import_zod.z.object({
|
|
1171
|
+
type: import_zod.z.literal("text"),
|
|
1172
|
+
text: import_zod.z.string().min(1)
|
|
1173
|
+
}),
|
|
1174
|
+
import_zod.z.object({
|
|
1175
|
+
type: import_zod.z.literal("markdown"),
|
|
1176
|
+
markdown: import_zod.z.string().min(1)
|
|
1177
|
+
}),
|
|
1178
|
+
import_zod.z.object({
|
|
1179
|
+
type: import_zod.z.literal("image"),
|
|
1180
|
+
imageUrl: import_zod.z.string().min(1)
|
|
1181
|
+
}),
|
|
1182
|
+
import_zod.z.object({
|
|
1183
|
+
type: import_zod.z.literal("audio"),
|
|
1184
|
+
audioUrl: import_zod.z.string().min(1)
|
|
1185
|
+
}),
|
|
1186
|
+
import_zod.z.object({
|
|
1187
|
+
type: import_zod.z.literal("video"),
|
|
1188
|
+
videoUrl: import_zod.z.string().min(1)
|
|
1189
|
+
}),
|
|
1190
|
+
import_zod.z.object({
|
|
1191
|
+
type: import_zod.z.literal("file"),
|
|
1192
|
+
fileUrl: import_zod.z.string().min(1),
|
|
1193
|
+
title: import_zod.z.string().min(1).optional()
|
|
1194
|
+
}),
|
|
1195
|
+
import_zod.z.object({
|
|
1196
|
+
type: import_zod.z.literal("location"),
|
|
1197
|
+
latitude: import_zod.z.number(),
|
|
1198
|
+
longitude: import_zod.z.number(),
|
|
1199
|
+
address: import_zod.z.string().optional(),
|
|
1200
|
+
title: import_zod.z.string().optional()
|
|
1201
|
+
})
|
|
1202
|
+
])
|
|
1203
|
+
)
|
|
1204
|
+
})
|
|
1205
|
+
]).describe("Payload is the content type of the message."),
|
|
1206
|
+
userId: import_zod.z.string().describe("ID of the [User](#schema_user)"),
|
|
1207
|
+
conversationId: import_zod.z.string().describe("ID of the [Conversation](#schema_conversation)"),
|
|
1208
|
+
metadata: import_zod.z.record(import_zod.z.union([import_zod.z.any(), import_zod.z.null()])).describe("Metadata of the message").optional(),
|
|
1209
|
+
isBot: import_zod.z.boolean().describe("Whether the message was created by the bot or not")
|
|
1210
|
+
})
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
// src/gen/signals/eventCreated.z.ts
|
|
1214
|
+
var import_zod2 = require("zod");
|
|
1215
|
+
var eventCreated_z_default = import_zod2.z.object({
|
|
1216
|
+
type: import_zod2.z.literal("event_created"),
|
|
1217
|
+
data: import_zod2.z.object({
|
|
1218
|
+
createdAt: import_zod2.z.string().datetime().describe(
|
|
1219
|
+
"Creation date of the custom [Event](#schema_event) in ISO 8601 format"
|
|
1220
|
+
),
|
|
1221
|
+
payload: import_zod2.z.record(import_zod2.z.any()).describe("Payload is the content of the custom event."),
|
|
1222
|
+
conversationId: import_zod2.z.string().describe("ID of the [Conversation](#schema_conversation)."),
|
|
1223
|
+
userId: import_zod2.z.string().describe("ID of the [User](#schema_user)."),
|
|
1224
|
+
id: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.null()]),
|
|
1225
|
+
isBot: import_zod2.z.boolean().describe("Whether the event was created by the bot or not")
|
|
1226
|
+
})
|
|
1227
|
+
});
|
|
1228
|
+
|
|
1229
|
+
// src/gen/signals/participantAdded.z.ts
|
|
1230
|
+
var import_zod3 = require("zod");
|
|
1231
|
+
var participantAdded_z_default = import_zod3.z.object({
|
|
1232
|
+
type: import_zod3.z.literal("participant_added"),
|
|
1233
|
+
data: import_zod3.z.object({ conversationId: import_zod3.z.string(), participantId: import_zod3.z.string() })
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
// src/gen/signals/participantRemoved.z.ts
|
|
1237
|
+
var import_zod4 = require("zod");
|
|
1238
|
+
var participantRemoved_z_default = import_zod4.z.object({
|
|
1239
|
+
type: import_zod4.z.literal("participant_removed"),
|
|
1240
|
+
data: import_zod4.z.object({ conversationId: import_zod4.z.string(), participantId: import_zod4.z.string() })
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
// src/gen/signals/messageDeleted.z.ts
|
|
1244
|
+
var import_zod5 = require("zod");
|
|
1245
|
+
var messageDeleted_z_default = import_zod5.z.object({
|
|
1246
|
+
type: import_zod5.z.literal("message_deleted"),
|
|
1247
|
+
data: import_zod5.z.object({
|
|
1248
|
+
id: import_zod5.z.string(),
|
|
1249
|
+
conversationId: import_zod5.z.string(),
|
|
1250
|
+
userId: import_zod5.z.string()
|
|
1251
|
+
})
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
// src/gen/signals/index.ts
|
|
1255
|
+
var zod = {
|
|
1256
|
+
messageCreated: messageCreated_z_default,
|
|
1257
|
+
eventCreated: eventCreated_z_default,
|
|
1258
|
+
participantAdded: participantAdded_z_default,
|
|
1259
|
+
participantRemoved: participantRemoved_z_default,
|
|
1260
|
+
messageDeleted: messageDeleted_z_default
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
// src/watchdog.ts
|
|
1264
|
+
var WatchDog = class _WatchDog {
|
|
1265
|
+
constructor(_ms) {
|
|
1266
|
+
this._ms = _ms;
|
|
1267
|
+
}
|
|
1268
|
+
_listeners = [];
|
|
1269
|
+
_handle = null;
|
|
1270
|
+
static init = (ms) => {
|
|
1271
|
+
const inst = new _WatchDog(ms);
|
|
1272
|
+
inst.reset();
|
|
1273
|
+
return inst;
|
|
1274
|
+
};
|
|
1275
|
+
reset() {
|
|
1276
|
+
if (this._handle) {
|
|
1277
|
+
clearTimeout(this._handle);
|
|
1278
|
+
}
|
|
1279
|
+
this._handle = setTimeout(() => {
|
|
1280
|
+
this._emitError(new Error("Client connection timed out"));
|
|
1281
|
+
}, this._ms);
|
|
1282
|
+
}
|
|
1283
|
+
on(_type, listener) {
|
|
1284
|
+
this._listeners.push(listener);
|
|
1285
|
+
}
|
|
1286
|
+
close() {
|
|
1287
|
+
if (this._handle) {
|
|
1288
|
+
clearTimeout(this._handle);
|
|
1289
|
+
}
|
|
1290
|
+
this._listeners = [];
|
|
1291
|
+
}
|
|
1292
|
+
_emitError(error) {
|
|
1293
|
+
for (const listener of this._listeners) {
|
|
1294
|
+
listener(error);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
|
|
1299
|
+
// src/signal-listener.ts
|
|
1300
|
+
var CONNECTION_TIMEOUT = 6e4;
|
|
1301
|
+
var DEFAULT_ERROR_MESSAGE = "unknown error";
|
|
1302
|
+
var SignalListener = class _SignalListener extends EventEmitter {
|
|
1303
|
+
constructor(_props) {
|
|
1304
|
+
super();
|
|
1305
|
+
this._props = _props;
|
|
1306
|
+
}
|
|
1307
|
+
_state = { status: "disconnected" };
|
|
1308
|
+
static listen = async (props) => {
|
|
1309
|
+
const inst = new _SignalListener(props);
|
|
1310
|
+
await inst.connect();
|
|
1311
|
+
return inst;
|
|
1312
|
+
};
|
|
1313
|
+
get status() {
|
|
1314
|
+
return this._state.status;
|
|
1315
|
+
}
|
|
1316
|
+
connect = async () => {
|
|
1317
|
+
if (this._state.status === "connected") {
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
if (this._state.status === "connecting") {
|
|
1321
|
+
await this._state.connectionPromise;
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
const connectionPromise = this._connect();
|
|
1325
|
+
this._state = { status: "connecting", connectionPromise };
|
|
1326
|
+
await connectionPromise;
|
|
1327
|
+
};
|
|
1328
|
+
disconnect = async () => {
|
|
1329
|
+
if (this._state.status === "disconnected") {
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
let source;
|
|
1333
|
+
let watchdog;
|
|
1334
|
+
if (this._state.status === "connecting") {
|
|
1335
|
+
source = await this._state.connectionPromise;
|
|
1336
|
+
} else {
|
|
1337
|
+
source = this._state.source;
|
|
1338
|
+
watchdog = this._state.watchdog;
|
|
1339
|
+
}
|
|
1340
|
+
this._disconnectSync(source, watchdog);
|
|
1341
|
+
};
|
|
1342
|
+
_connect = async () => {
|
|
1343
|
+
const source = await listenEventSource(`${this._props.url}/conversations/${this._props.conversationId}/listen`, {
|
|
1344
|
+
headers: { "x-user-key": this._props.userKey }
|
|
1345
|
+
});
|
|
1346
|
+
const watchdog = WatchDog.init(CONNECTION_TIMEOUT);
|
|
1347
|
+
source.on("message", this._handleMessage(source, watchdog));
|
|
1348
|
+
source.on("error", this._handleError(source, watchdog));
|
|
1349
|
+
watchdog.on("error", this._handleError(source, watchdog));
|
|
1350
|
+
this._state = { status: "connected", source, watchdog };
|
|
1351
|
+
return source;
|
|
1352
|
+
};
|
|
1353
|
+
_disconnectSync = (source, watchdog) => {
|
|
1354
|
+
source.close();
|
|
1355
|
+
watchdog?.close();
|
|
1356
|
+
this._state = { status: "disconnected" };
|
|
1357
|
+
};
|
|
1358
|
+
_handleMessage = (_source, watchdog) => (ev) => {
|
|
1359
|
+
watchdog.reset();
|
|
1360
|
+
const signal = this._parseSignal(ev.data);
|
|
1361
|
+
this.emit(signal.type, signal.data);
|
|
1362
|
+
};
|
|
1363
|
+
_handleError = (source, watchdog) => (ev) => {
|
|
1364
|
+
this._disconnectSync(source, watchdog);
|
|
1365
|
+
const err = this._toError(ev);
|
|
1366
|
+
this.emit("error", err);
|
|
1367
|
+
};
|
|
1368
|
+
_parseSignal = (data) => {
|
|
1369
|
+
for (const [schemaName, schema] of Object.entries(zod)) {
|
|
1370
|
+
this._debug("trying to parse", schemaName);
|
|
1371
|
+
const parsedData = this._safeJsonParse(data);
|
|
1372
|
+
const parseResult = schema.safeParse(parsedData);
|
|
1373
|
+
if (parseResult.success) {
|
|
1374
|
+
this._debug("parsing successfull", schemaName, parseResult.data);
|
|
1375
|
+
return parseResult.data;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return {
|
|
1379
|
+
type: "unknown",
|
|
1380
|
+
data
|
|
1381
|
+
};
|
|
1382
|
+
};
|
|
1383
|
+
_safeJsonParse = (x) => {
|
|
1384
|
+
try {
|
|
1385
|
+
return JSON.parse(x);
|
|
1386
|
+
} catch {
|
|
1387
|
+
return x;
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
_toError = (thrown) => {
|
|
1391
|
+
if (thrown instanceof Error) {
|
|
1392
|
+
return thrown;
|
|
1393
|
+
}
|
|
1394
|
+
if (typeof thrown === "string") {
|
|
1395
|
+
return new Error(thrown);
|
|
1396
|
+
}
|
|
1397
|
+
if (thrown === null) {
|
|
1398
|
+
return new Error(DEFAULT_ERROR_MESSAGE);
|
|
1399
|
+
}
|
|
1400
|
+
if (typeof thrown === "object" && "message" in thrown) {
|
|
1401
|
+
return this._toError(thrown.message);
|
|
1402
|
+
}
|
|
1403
|
+
try {
|
|
1404
|
+
const json = JSON.stringify(thrown);
|
|
1405
|
+
return new Error(json);
|
|
1406
|
+
} catch {
|
|
1407
|
+
return new Error(DEFAULT_ERROR_MESSAGE);
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
_debug = (...args) => {
|
|
1411
|
+
if (!this._props.debug) {
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
console.info(...args);
|
|
1415
|
+
};
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
// src/client.ts
|
|
1419
|
+
var _100mb = 100 * 1024 * 1024;
|
|
1420
|
+
var maxBodyLength = _100mb;
|
|
1421
|
+
var maxContentLength = _100mb;
|
|
1422
|
+
var defaultTimeout = 6e4;
|
|
1423
|
+
var _createAuthClient = Symbol("_createAuthClient");
|
|
1424
|
+
var Client2 = class _Client {
|
|
1425
|
+
constructor(props) {
|
|
1426
|
+
this.props = props;
|
|
1427
|
+
const axiosClient = _Client._createAxios(props);
|
|
1428
|
+
this._auto = new Client(axiosClient);
|
|
1429
|
+
}
|
|
1430
|
+
_connectionTested = false;
|
|
1431
|
+
_auto;
|
|
1432
|
+
get apiVersion() {
|
|
1433
|
+
return apiVersion;
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* Gets or creates a user based on the provided props and returns an authenticated client.
|
|
1437
|
+
*/
|
|
1438
|
+
static async connect(props) {
|
|
1439
|
+
const { userId, userKey, encryptionKey, ...clientProps } = props;
|
|
1440
|
+
const client = new _Client(clientProps);
|
|
1441
|
+
await client._testConnection();
|
|
1442
|
+
if (userKey) {
|
|
1443
|
+
const { user: user2 } = await client.getOrCreateUser({ "x-user-key": userKey });
|
|
1444
|
+
return AuthenticatedClient[_createAuthClient](client, { ...user2, key: userKey });
|
|
1445
|
+
}
|
|
1446
|
+
if (encryptionKey) {
|
|
1447
|
+
if (!jsonwebtoken_default) {
|
|
1448
|
+
const message = "Connecting with an encryption key is not supported in the browser; use in NodeJs or format the key manually with jsonwebtoken.";
|
|
1449
|
+
throw new ChatConfigError(message);
|
|
1450
|
+
}
|
|
1451
|
+
if (!userId) {
|
|
1452
|
+
throw new ChatConfigError(
|
|
1453
|
+
"userId is required when connecting with an encryption key. You may pick any userId of your choice that is not already taken by another user."
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
const userKey2 = jsonwebtoken_default.sign({ id: userId }, encryptionKey, { algorithm: "HS256" });
|
|
1457
|
+
const { user: user2 } = await client.getOrCreateUser({ "x-user-key": userKey2 });
|
|
1458
|
+
return AuthenticatedClient[_createAuthClient](client, { ...user2, key: userKey2 });
|
|
1459
|
+
}
|
|
1460
|
+
const { user, key } = await client.createUser({ id: userId });
|
|
1461
|
+
return AuthenticatedClient[_createAuthClient](client, { ...user, key });
|
|
1462
|
+
}
|
|
1463
|
+
createConversation = (x) => this._call("createConversation", x);
|
|
1464
|
+
getConversation = (x) => this._call("getConversation", x);
|
|
1465
|
+
getOrCreateConversation = (x) => this._call("getOrCreateConversation", x);
|
|
1466
|
+
deleteConversation = (x) => this._call("deleteConversation", x);
|
|
1467
|
+
listConversations = (x) => this._call("listConversations", x);
|
|
1468
|
+
listMessages = (x) => this._call("listMessages", x);
|
|
1469
|
+
addParticipant = (x) => this._call("addParticipant", x);
|
|
1470
|
+
removeParticipant = (x) => this._call("removeParticipant", x);
|
|
1471
|
+
getParticipant = (x) => this._call("getParticipant", x);
|
|
1472
|
+
listParticipants = (x) => this._call("listParticipants", x);
|
|
1473
|
+
createMessage = (x) => this._call("createMessage", x);
|
|
1474
|
+
getMessage = (x) => this._call("getMessage", x);
|
|
1475
|
+
deleteMessage = (x) => this._call("deleteMessage", x);
|
|
1476
|
+
createUser = (x) => this._call("createUser", x);
|
|
1477
|
+
getUser = (x) => this._call("getUser", x);
|
|
1478
|
+
getOrCreateUser = (x) => this._call("getOrCreateUser", x);
|
|
1479
|
+
updateUser = (x) => this._call("updateUser", x);
|
|
1480
|
+
deleteUser = (x) => this._call("deleteUser", x);
|
|
1481
|
+
createEvent = (x) => this._call("createEvent", x);
|
|
1482
|
+
getEvent = (x) => this._call("getEvent", x);
|
|
1483
|
+
get list() {
|
|
1484
|
+
return {
|
|
1485
|
+
conversations: (props) => new AsyncCollection(
|
|
1486
|
+
({ nextToken }) => this.listConversations({ nextToken, ...props }).then((r) => ({ ...r, items: r.conversations }))
|
|
1487
|
+
),
|
|
1488
|
+
messages: (props) => new AsyncCollection(
|
|
1489
|
+
({ nextToken }) => this.listMessages({ nextToken, ...props }).then((r) => ({ ...r, items: r.messages }))
|
|
1490
|
+
),
|
|
1491
|
+
participants: (props) => new AsyncCollection(
|
|
1492
|
+
({ nextToken }) => this.listParticipants({ nextToken, ...props }).then((r) => ({ ...r, items: r.participants }))
|
|
1493
|
+
)
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
listenConversation = async ({ id, "x-user-key": userKey }) => {
|
|
1497
|
+
const signalListener = await SignalListener.listen({
|
|
1498
|
+
url: this._apiUrl,
|
|
1499
|
+
conversationId: id,
|
|
1500
|
+
userKey,
|
|
1501
|
+
debug: this.props.debug ?? false
|
|
1502
|
+
});
|
|
1503
|
+
return signalListener;
|
|
1504
|
+
};
|
|
1505
|
+
_call = async (operation, args) => {
|
|
1506
|
+
try {
|
|
1507
|
+
await this._testConnection();
|
|
1508
|
+
const response = await this._auto[operation](args);
|
|
1509
|
+
const res = this._checkPayloadForError(response);
|
|
1510
|
+
return res;
|
|
1511
|
+
} catch (thrown) {
|
|
1512
|
+
if (isApiError(thrown)) {
|
|
1513
|
+
throw thrown;
|
|
1514
|
+
}
|
|
1515
|
+
throw ChatClientError.map(thrown);
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
/**
|
|
1519
|
+
* The Chat-API is called like any other integrations by sending requests to the bridge webhook endpoint.
|
|
1520
|
+
* This endpoint may return a successful status code even when the payload contains an error.
|
|
1521
|
+
* This method parses the payload to check for an error and throws an error if one is found.
|
|
1522
|
+
*/
|
|
1523
|
+
_checkPayloadForError = (response) => {
|
|
1524
|
+
if (typeof response !== "object" || response === null) {
|
|
1525
|
+
return response;
|
|
1526
|
+
}
|
|
1527
|
+
if (!("code" in response)) {
|
|
1528
|
+
return response;
|
|
1529
|
+
}
|
|
1530
|
+
const { code } = response;
|
|
1531
|
+
if (typeof code !== "number") {
|
|
1532
|
+
return response;
|
|
1533
|
+
}
|
|
1534
|
+
if (code < 400 || code >= 600) {
|
|
1535
|
+
return response;
|
|
1536
|
+
}
|
|
1537
|
+
const message = "message" in response ? String(response["message"]) : "An error occurred";
|
|
1538
|
+
throw new ChatHTTPError(code, message);
|
|
1539
|
+
};
|
|
1540
|
+
static _createAxios = (props) => {
|
|
1541
|
+
const headers = {
|
|
1542
|
+
...props.headers
|
|
1543
|
+
};
|
|
1544
|
+
const timeout = props.timeout ?? defaultTimeout;
|
|
1545
|
+
const withCredentials = import_browser_or_node3.isBrowser;
|
|
1546
|
+
const baseURL = this._getApiUrl(props);
|
|
1547
|
+
return import_axios3.default.create({
|
|
1548
|
+
baseURL,
|
|
1549
|
+
headers,
|
|
1550
|
+
withCredentials,
|
|
1551
|
+
timeout,
|
|
1552
|
+
maxBodyLength,
|
|
1553
|
+
maxContentLength,
|
|
1554
|
+
validateStatus: (status) => status >= 200 && status < 400
|
|
1555
|
+
});
|
|
1556
|
+
};
|
|
1557
|
+
get _apiUrl() {
|
|
1558
|
+
return _Client._getApiUrl(this.props);
|
|
1559
|
+
}
|
|
1560
|
+
static _getApiUrl = (props) => {
|
|
1561
|
+
if ("apiUrl" in props) {
|
|
1562
|
+
return props.apiUrl;
|
|
1563
|
+
}
|
|
1564
|
+
const baseApiUrl = props.baseApiUrl ?? defaultBaseApiUrl;
|
|
1565
|
+
const { webhookId } = props;
|
|
1566
|
+
return `${baseApiUrl}/${webhookId}`;
|
|
1567
|
+
};
|
|
1568
|
+
_testConnection = async () => {
|
|
1569
|
+
if (this._connectionTested) {
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
const url = `${this._apiUrl}/hello`;
|
|
1573
|
+
const axiosInstance = import_axios3.default.create({ baseURL: url });
|
|
1574
|
+
try {
|
|
1575
|
+
const response = await axiosInstance.get("/");
|
|
1576
|
+
this._checkPayloadForError(response.data);
|
|
1577
|
+
} catch (thrown) {
|
|
1578
|
+
throw ChatClientError.wrap(thrown, `Failed to connect to url "${this._apiUrl}"`);
|
|
1579
|
+
}
|
|
1580
|
+
this._connectionTested = true;
|
|
1581
|
+
};
|
|
1582
|
+
};
|
|
1583
|
+
var AuthenticatedClient = class _AuthenticatedClient {
|
|
1584
|
+
constructor(_client, user) {
|
|
1585
|
+
this._client = _client;
|
|
1586
|
+
this.user = user;
|
|
1587
|
+
}
|
|
1588
|
+
// can not be instantiated outside of this module
|
|
1589
|
+
static [_createAuthClient] = (client, user) => {
|
|
1590
|
+
return new _AuthenticatedClient(client, user);
|
|
1591
|
+
};
|
|
1592
|
+
get apiVersion() {
|
|
1593
|
+
return this._client.apiVersion;
|
|
1594
|
+
}
|
|
1595
|
+
createConversation = (x) => this._client.createConversation({ "x-user-key": this.user.key, ...x });
|
|
1596
|
+
getConversation = (x) => this._client.getConversation({ "x-user-key": this.user.key, ...x });
|
|
1597
|
+
getOrCreateConversation = (x) => this._client.getOrCreateConversation({ "x-user-key": this.user.key, ...x });
|
|
1598
|
+
deleteConversation = (x) => this._client.deleteConversation({ "x-user-key": this.user.key, ...x });
|
|
1599
|
+
listConversations = (x) => this._client.listConversations({ "x-user-key": this.user.key, ...x });
|
|
1600
|
+
listMessages = (x) => this._client.listMessages({ "x-user-key": this.user.key, ...x });
|
|
1601
|
+
listenConversation = (x) => this._client.listenConversation({ "x-user-key": this.user.key, ...x });
|
|
1602
|
+
addParticipant = (x) => this._client.addParticipant({ "x-user-key": this.user.key, ...x });
|
|
1603
|
+
removeParticipant = (x) => this._client.removeParticipant({ "x-user-key": this.user.key, ...x });
|
|
1604
|
+
getParticipant = (x) => this._client.getParticipant({ "x-user-key": this.user.key, ...x });
|
|
1605
|
+
listParticipants = (x) => this._client.listParticipants({ "x-user-key": this.user.key, ...x });
|
|
1606
|
+
createMessage = (x) => this._client.createMessage({ "x-user-key": this.user.key, ...x });
|
|
1607
|
+
getMessage = (x) => this._client.getMessage({ "x-user-key": this.user.key, ...x });
|
|
1608
|
+
deleteMessage = (x) => this._client.deleteMessage({ "x-user-key": this.user.key, ...x });
|
|
1609
|
+
getUser = (x) => this._client.getUser({ "x-user-key": this.user.key, ...x });
|
|
1610
|
+
updateUser = (x) => this._client.updateUser({ "x-user-key": this.user.key, ...x });
|
|
1611
|
+
deleteUser = (x) => this._client.deleteUser({ "x-user-key": this.user.key, ...x });
|
|
1612
|
+
createEvent = (x) => this._client.createEvent({ "x-user-key": this.user.key, ...x });
|
|
1613
|
+
getEvent = (x) => this._client.getEvent({ "x-user-key": this.user.key, ...x });
|
|
1614
|
+
get list() {
|
|
1615
|
+
return {
|
|
1616
|
+
conversations: (x) => this._client.list.conversations({ "x-user-key": this.user.key, ...x }),
|
|
1617
|
+
messages: (x) => this._client.list.messages({ "x-user-key": this.user.key, ...x }),
|
|
1618
|
+
participants: (x) => this._client.list.participants({ "x-user-key": this.user.key, ...x })
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1623
|
+
0 && (module.exports = {
|
|
1624
|
+
AlreadyExistsError,
|
|
1625
|
+
AuthenticatedClient,
|
|
1626
|
+
BreakingChangesError,
|
|
1627
|
+
ChatClientError,
|
|
1628
|
+
ChatConfigError,
|
|
1629
|
+
ChatHTTPError,
|
|
1630
|
+
Client,
|
|
1631
|
+
ForbiddenError,
|
|
1632
|
+
InternalError,
|
|
1633
|
+
InvalidDataFormatError,
|
|
1634
|
+
InvalidIdentifierError,
|
|
1635
|
+
InvalidJsonSchemaError,
|
|
1636
|
+
InvalidPayloadError,
|
|
1637
|
+
InvalidQueryError,
|
|
1638
|
+
LimitExceededError,
|
|
1639
|
+
MethodNotFoundError,
|
|
1640
|
+
OperationTimeoutError,
|
|
1641
|
+
PayloadTooLargeError,
|
|
1642
|
+
PaymentRequiredError,
|
|
1643
|
+
QuotaExceededError,
|
|
1644
|
+
RateLimitedError,
|
|
1645
|
+
ReferenceConstraintError,
|
|
1646
|
+
ReferenceNotFoundError,
|
|
1647
|
+
RelationConflictError,
|
|
1648
|
+
ResourceGoneError,
|
|
1649
|
+
ResourceLockedConflictError,
|
|
1650
|
+
ResourceNotFoundError,
|
|
1651
|
+
RuntimeError,
|
|
1652
|
+
SignalListener,
|
|
1653
|
+
UnauthorizedError,
|
|
1654
|
+
UnknownError,
|
|
1655
|
+
UnsupportedMediaTypeError,
|
|
1656
|
+
axios,
|
|
1657
|
+
errorFrom,
|
|
1658
|
+
isApiError
|
|
1659
|
+
});
|
|
1660
|
+
//# sourceMappingURL=index.cjs.map
|