@multisender.app/multisender-sdk 0.0.1
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 +21 -0
- package/README.md +410 -0
- package/dist/auth/api-key.d.ts +8 -0
- package/dist/auth/api-key.d.ts.map +1 -0
- package/dist/cli/commands/distribute.d.ts +3 -0
- package/dist/cli/commands/distribute.d.ts.map +1 -0
- package/dist/cli/commands/distributions.d.ts +3 -0
- package/dist/cli/commands/distributions.d.ts.map +1 -0
- package/dist/cli/commands/lists.d.ts +3 -0
- package/dist/cli/commands/lists.d.ts.map +1 -0
- package/dist/cli/index.cjs +4507 -0
- package/dist/cli/index.cjs.map +46 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +4514 -0
- package/dist/cli/index.js.map +46 -0
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/generated-transport.d.ts +3 -0
- package/dist/core/generated-transport.d.ts.map +1 -0
- package/dist/core/pagination.d.ts +4 -0
- package/dist/core/pagination.d.ts.map +1 -0
- package/dist/core/types.d.ts +19 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/gen/client/client.gen.d.ts +3 -0
- package/dist/gen/client/client.gen.d.ts.map +1 -0
- package/dist/gen/client/index.d.ts +9 -0
- package/dist/gen/client/index.d.ts.map +1 -0
- package/dist/gen/client/types.gen.d.ts +118 -0
- package/dist/gen/client/types.gen.d.ts.map +1 -0
- package/dist/gen/client/utils.gen.d.ts +34 -0
- package/dist/gen/client/utils.gen.d.ts.map +1 -0
- package/dist/gen/client.gen.d.ts +13 -0
- package/dist/gen/client.gen.d.ts.map +1 -0
- package/dist/gen/core/auth.gen.d.ts +19 -0
- package/dist/gen/core/auth.gen.d.ts.map +1 -0
- package/dist/gen/core/bodySerializer.gen.d.ts +26 -0
- package/dist/gen/core/bodySerializer.gen.d.ts.map +1 -0
- package/dist/gen/core/params.gen.d.ts +44 -0
- package/dist/gen/core/params.gen.d.ts.map +1 -0
- package/dist/gen/core/pathSerializer.gen.d.ts +34 -0
- package/dist/gen/core/pathSerializer.gen.d.ts.map +1 -0
- package/dist/gen/core/queryKeySerializer.gen.d.ts +19 -0
- package/dist/gen/core/queryKeySerializer.gen.d.ts.map +1 -0
- package/dist/gen/core/serverSentEvents.gen.d.ts +72 -0
- package/dist/gen/core/serverSentEvents.gen.d.ts.map +1 -0
- package/dist/gen/core/types.gen.d.ts +79 -0
- package/dist/gen/core/types.gen.d.ts.map +1 -0
- package/dist/gen/core/utils.gen.d.ts +20 -0
- package/dist/gen/core/utils.gen.d.ts.map +1 -0
- package/dist/gen/index.d.ts +3 -0
- package/dist/gen/index.d.ts.map +1 -0
- package/dist/gen/sdk.gen.d.ts +168 -0
- package/dist/gen/sdk.gen.d.ts.map +1 -0
- package/dist/gen/types.gen.d.ts +2501 -0
- package/dist/gen/types.gen.d.ts.map +1 -0
- package/dist/index.cjs +1648 -0
- package/dist/index.cjs.map +31 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1651 -0
- package/dist/index.js.map +31 -0
- package/dist/multisender.d.ts +46 -0
- package/dist/multisender.d.ts.map +1 -0
- package/dist/openapi-runtime.d.ts +10 -0
- package/dist/openapi-runtime.d.ts.map +1 -0
- package/dist/services/catalogs.d.ts +15 -0
- package/dist/services/catalogs.d.ts.map +1 -0
- package/dist/services/distributions.d.ts +17 -0
- package/dist/services/distributions.d.ts.map +1 -0
- package/dist/services/lists.d.ts +36 -0
- package/dist/services/lists.d.ts.map +1 -0
- package/dist/services/project.d.ts +19 -0
- package/dist/services/project.d.ts.map +1 -0
- package/dist/services/response-utils.d.ts +9 -0
- package/dist/services/response-utils.d.ts.map +1 -0
- package/dist/services/types.d.ts +33 -0
- package/dist/services/types.d.ts.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/csv.d.ts +9 -0
- package/dist/utils/csv.d.ts.map +1 -0
- package/dist/utils/validation.d.ts +7 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/package.json +64 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1651 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (from) => {
|
|
33
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
34
|
+
if (entry)
|
|
35
|
+
return entry;
|
|
36
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (var key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(entry, key))
|
|
40
|
+
__defProp(entry, key, {
|
|
41
|
+
get: __accessProp.bind(from, key),
|
|
42
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
__moduleCache.set(from, entry);
|
|
46
|
+
return entry;
|
|
47
|
+
};
|
|
48
|
+
var __moduleCache;
|
|
49
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
50
|
+
var __returnValue = (v) => v;
|
|
51
|
+
function __exportSetter(name, newValue) {
|
|
52
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
53
|
+
}
|
|
54
|
+
var __export = (target, all) => {
|
|
55
|
+
for (var name in all)
|
|
56
|
+
__defProp(target, name, {
|
|
57
|
+
get: all[name],
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
set: __exportSetter.bind(all, name)
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
64
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
65
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
66
|
+
}) : x)(function(x) {
|
|
67
|
+
if (typeof require !== "undefined")
|
|
68
|
+
return require.apply(this, arguments);
|
|
69
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// src/gen/core/bodySerializer.gen.ts
|
|
73
|
+
var jsonBodySerializer = {
|
|
74
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
75
|
+
};
|
|
76
|
+
// src/gen/core/params.gen.ts
|
|
77
|
+
var extraPrefixesMap = {
|
|
78
|
+
$body_: "body",
|
|
79
|
+
$headers_: "headers",
|
|
80
|
+
$path_: "path",
|
|
81
|
+
$query_: "query"
|
|
82
|
+
};
|
|
83
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
84
|
+
// src/gen/core/serverSentEvents.gen.ts
|
|
85
|
+
var createSseClient = ({
|
|
86
|
+
onRequest,
|
|
87
|
+
onSseError,
|
|
88
|
+
onSseEvent,
|
|
89
|
+
responseTransformer,
|
|
90
|
+
responseValidator,
|
|
91
|
+
sseDefaultRetryDelay,
|
|
92
|
+
sseMaxRetryAttempts,
|
|
93
|
+
sseMaxRetryDelay,
|
|
94
|
+
sseSleepFn,
|
|
95
|
+
url,
|
|
96
|
+
...options
|
|
97
|
+
}) => {
|
|
98
|
+
let lastEventId;
|
|
99
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
100
|
+
const createStream = async function* () {
|
|
101
|
+
let retryDelay = sseDefaultRetryDelay ?? 3000;
|
|
102
|
+
let attempt = 0;
|
|
103
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
104
|
+
while (true) {
|
|
105
|
+
if (signal.aborted)
|
|
106
|
+
break;
|
|
107
|
+
attempt++;
|
|
108
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
109
|
+
if (lastEventId !== undefined) {
|
|
110
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const requestInit = {
|
|
114
|
+
redirect: "follow",
|
|
115
|
+
...options,
|
|
116
|
+
body: options.serializedBody,
|
|
117
|
+
headers,
|
|
118
|
+
signal
|
|
119
|
+
};
|
|
120
|
+
let request = new Request(url, requestInit);
|
|
121
|
+
if (onRequest) {
|
|
122
|
+
request = await onRequest(url, requestInit);
|
|
123
|
+
}
|
|
124
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
125
|
+
const response = await _fetch(request);
|
|
126
|
+
if (!response.ok)
|
|
127
|
+
throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
128
|
+
if (!response.body)
|
|
129
|
+
throw new Error("No body in SSE response");
|
|
130
|
+
const reader = response.body.pipeThrough(new TextDecoderStream).getReader();
|
|
131
|
+
let buffer = "";
|
|
132
|
+
const abortHandler = () => {
|
|
133
|
+
try {
|
|
134
|
+
reader.cancel();
|
|
135
|
+
} catch {}
|
|
136
|
+
};
|
|
137
|
+
signal.addEventListener("abort", abortHandler);
|
|
138
|
+
try {
|
|
139
|
+
while (true) {
|
|
140
|
+
const { done, value } = await reader.read();
|
|
141
|
+
if (done)
|
|
142
|
+
break;
|
|
143
|
+
buffer += value;
|
|
144
|
+
buffer = buffer.replace(/\r\n/g, `
|
|
145
|
+
`).replace(/\r/g, `
|
|
146
|
+
`);
|
|
147
|
+
const chunks = buffer.split(`
|
|
148
|
+
|
|
149
|
+
`);
|
|
150
|
+
buffer = chunks.pop() ?? "";
|
|
151
|
+
for (const chunk of chunks) {
|
|
152
|
+
const lines = chunk.split(`
|
|
153
|
+
`);
|
|
154
|
+
const dataLines = [];
|
|
155
|
+
let eventName;
|
|
156
|
+
for (const line of lines) {
|
|
157
|
+
if (line.startsWith("data:")) {
|
|
158
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
159
|
+
} else if (line.startsWith("event:")) {
|
|
160
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
161
|
+
} else if (line.startsWith("id:")) {
|
|
162
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
163
|
+
} else if (line.startsWith("retry:")) {
|
|
164
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
165
|
+
if (!Number.isNaN(parsed)) {
|
|
166
|
+
retryDelay = parsed;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let data;
|
|
171
|
+
let parsedJson = false;
|
|
172
|
+
if (dataLines.length) {
|
|
173
|
+
const rawData = dataLines.join(`
|
|
174
|
+
`);
|
|
175
|
+
try {
|
|
176
|
+
data = JSON.parse(rawData);
|
|
177
|
+
parsedJson = true;
|
|
178
|
+
} catch {
|
|
179
|
+
data = rawData;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (parsedJson) {
|
|
183
|
+
if (responseValidator) {
|
|
184
|
+
await responseValidator(data);
|
|
185
|
+
}
|
|
186
|
+
if (responseTransformer) {
|
|
187
|
+
data = await responseTransformer(data);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
onSseEvent?.({
|
|
191
|
+
data,
|
|
192
|
+
event: eventName,
|
|
193
|
+
id: lastEventId,
|
|
194
|
+
retry: retryDelay
|
|
195
|
+
});
|
|
196
|
+
if (dataLines.length) {
|
|
197
|
+
yield data;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} finally {
|
|
202
|
+
signal.removeEventListener("abort", abortHandler);
|
|
203
|
+
reader.releaseLock();
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
onSseError?.(error);
|
|
208
|
+
if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
|
|
212
|
+
await sleep(backoff);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
const stream = createStream();
|
|
217
|
+
return { stream };
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/gen/core/pathSerializer.gen.ts
|
|
221
|
+
var separatorArrayExplode = (style) => {
|
|
222
|
+
switch (style) {
|
|
223
|
+
case "label":
|
|
224
|
+
return ".";
|
|
225
|
+
case "matrix":
|
|
226
|
+
return ";";
|
|
227
|
+
case "simple":
|
|
228
|
+
return ",";
|
|
229
|
+
default:
|
|
230
|
+
return "&";
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var separatorArrayNoExplode = (style) => {
|
|
234
|
+
switch (style) {
|
|
235
|
+
case "form":
|
|
236
|
+
return ",";
|
|
237
|
+
case "pipeDelimited":
|
|
238
|
+
return "|";
|
|
239
|
+
case "spaceDelimited":
|
|
240
|
+
return "%20";
|
|
241
|
+
default:
|
|
242
|
+
return ",";
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
var separatorObjectExplode = (style) => {
|
|
246
|
+
switch (style) {
|
|
247
|
+
case "label":
|
|
248
|
+
return ".";
|
|
249
|
+
case "matrix":
|
|
250
|
+
return ";";
|
|
251
|
+
case "simple":
|
|
252
|
+
return ",";
|
|
253
|
+
default:
|
|
254
|
+
return "&";
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var serializeArrayParam = ({
|
|
258
|
+
allowReserved,
|
|
259
|
+
explode,
|
|
260
|
+
name,
|
|
261
|
+
style,
|
|
262
|
+
value
|
|
263
|
+
}) => {
|
|
264
|
+
if (!explode) {
|
|
265
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
266
|
+
switch (style) {
|
|
267
|
+
case "label":
|
|
268
|
+
return `.${joinedValues2}`;
|
|
269
|
+
case "matrix":
|
|
270
|
+
return `;${name}=${joinedValues2}`;
|
|
271
|
+
case "simple":
|
|
272
|
+
return joinedValues2;
|
|
273
|
+
default:
|
|
274
|
+
return `${name}=${joinedValues2}`;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const separator = separatorArrayExplode(style);
|
|
278
|
+
const joinedValues = value.map((v) => {
|
|
279
|
+
if (style === "label" || style === "simple") {
|
|
280
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
281
|
+
}
|
|
282
|
+
return serializePrimitiveParam({
|
|
283
|
+
allowReserved,
|
|
284
|
+
name,
|
|
285
|
+
value: v
|
|
286
|
+
});
|
|
287
|
+
}).join(separator);
|
|
288
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
289
|
+
};
|
|
290
|
+
var serializePrimitiveParam = ({
|
|
291
|
+
allowReserved,
|
|
292
|
+
name,
|
|
293
|
+
value
|
|
294
|
+
}) => {
|
|
295
|
+
if (value === undefined || value === null) {
|
|
296
|
+
return "";
|
|
297
|
+
}
|
|
298
|
+
if (typeof value === "object") {
|
|
299
|
+
throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
300
|
+
}
|
|
301
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
302
|
+
};
|
|
303
|
+
var serializeObjectParam = ({
|
|
304
|
+
allowReserved,
|
|
305
|
+
explode,
|
|
306
|
+
name,
|
|
307
|
+
style,
|
|
308
|
+
value,
|
|
309
|
+
valueOnly
|
|
310
|
+
}) => {
|
|
311
|
+
if (value instanceof Date) {
|
|
312
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
313
|
+
}
|
|
314
|
+
if (style !== "deepObject" && !explode) {
|
|
315
|
+
let values = [];
|
|
316
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
317
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
318
|
+
});
|
|
319
|
+
const joinedValues2 = values.join(",");
|
|
320
|
+
switch (style) {
|
|
321
|
+
case "form":
|
|
322
|
+
return `${name}=${joinedValues2}`;
|
|
323
|
+
case "label":
|
|
324
|
+
return `.${joinedValues2}`;
|
|
325
|
+
case "matrix":
|
|
326
|
+
return `;${name}=${joinedValues2}`;
|
|
327
|
+
default:
|
|
328
|
+
return joinedValues2;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const separator = separatorObjectExplode(style);
|
|
332
|
+
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
333
|
+
allowReserved,
|
|
334
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
335
|
+
value: v
|
|
336
|
+
})).join(separator);
|
|
337
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// src/gen/core/utils.gen.ts
|
|
341
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
342
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
343
|
+
let url = _url;
|
|
344
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
345
|
+
if (matches) {
|
|
346
|
+
for (const match of matches) {
|
|
347
|
+
let explode = false;
|
|
348
|
+
let name = match.substring(1, match.length - 1);
|
|
349
|
+
let style = "simple";
|
|
350
|
+
if (name.endsWith("*")) {
|
|
351
|
+
explode = true;
|
|
352
|
+
name = name.substring(0, name.length - 1);
|
|
353
|
+
}
|
|
354
|
+
if (name.startsWith(".")) {
|
|
355
|
+
name = name.substring(1);
|
|
356
|
+
style = "label";
|
|
357
|
+
} else if (name.startsWith(";")) {
|
|
358
|
+
name = name.substring(1);
|
|
359
|
+
style = "matrix";
|
|
360
|
+
}
|
|
361
|
+
const value = path[name];
|
|
362
|
+
if (value === undefined || value === null) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (Array.isArray(value)) {
|
|
366
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (typeof value === "object") {
|
|
370
|
+
url = url.replace(match, serializeObjectParam({
|
|
371
|
+
explode,
|
|
372
|
+
name,
|
|
373
|
+
style,
|
|
374
|
+
value,
|
|
375
|
+
valueOnly: true
|
|
376
|
+
}));
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (style === "matrix") {
|
|
380
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
381
|
+
name,
|
|
382
|
+
value
|
|
383
|
+
})}`);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
387
|
+
url = url.replace(match, replaceValue);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return url;
|
|
391
|
+
};
|
|
392
|
+
var getUrl = ({
|
|
393
|
+
baseUrl,
|
|
394
|
+
path,
|
|
395
|
+
query,
|
|
396
|
+
querySerializer,
|
|
397
|
+
url: _url
|
|
398
|
+
}) => {
|
|
399
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
400
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
401
|
+
if (path) {
|
|
402
|
+
url = defaultPathSerializer({ path, url });
|
|
403
|
+
}
|
|
404
|
+
let search = query ? querySerializer(query) : "";
|
|
405
|
+
if (search.startsWith("?")) {
|
|
406
|
+
search = search.substring(1);
|
|
407
|
+
}
|
|
408
|
+
if (search) {
|
|
409
|
+
url += `?${search}`;
|
|
410
|
+
}
|
|
411
|
+
return url;
|
|
412
|
+
};
|
|
413
|
+
function getValidRequestBody(options) {
|
|
414
|
+
const hasBody = options.body !== undefined;
|
|
415
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
416
|
+
if (isSerializedBody) {
|
|
417
|
+
if ("serializedBody" in options) {
|
|
418
|
+
const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== "";
|
|
419
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
420
|
+
}
|
|
421
|
+
return options.body !== "" ? options.body : null;
|
|
422
|
+
}
|
|
423
|
+
if (hasBody) {
|
|
424
|
+
return options.body;
|
|
425
|
+
}
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/gen/core/auth.gen.ts
|
|
430
|
+
var getAuthToken = async (auth, callback) => {
|
|
431
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
432
|
+
if (!token) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (auth.scheme === "bearer") {
|
|
436
|
+
return `Bearer ${token}`;
|
|
437
|
+
}
|
|
438
|
+
if (auth.scheme === "basic") {
|
|
439
|
+
return `Basic ${btoa(token)}`;
|
|
440
|
+
}
|
|
441
|
+
return token;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// src/gen/client/utils.gen.ts
|
|
445
|
+
var createQuerySerializer = ({
|
|
446
|
+
parameters = {},
|
|
447
|
+
...args
|
|
448
|
+
} = {}) => {
|
|
449
|
+
const querySerializer = (queryParams) => {
|
|
450
|
+
const search = [];
|
|
451
|
+
if (queryParams && typeof queryParams === "object") {
|
|
452
|
+
for (const name in queryParams) {
|
|
453
|
+
const value = queryParams[name];
|
|
454
|
+
if (value === undefined || value === null) {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
const options = parameters[name] || args;
|
|
458
|
+
if (Array.isArray(value)) {
|
|
459
|
+
const serializedArray = serializeArrayParam({
|
|
460
|
+
allowReserved: options.allowReserved,
|
|
461
|
+
explode: true,
|
|
462
|
+
name,
|
|
463
|
+
style: "form",
|
|
464
|
+
value,
|
|
465
|
+
...options.array
|
|
466
|
+
});
|
|
467
|
+
if (serializedArray)
|
|
468
|
+
search.push(serializedArray);
|
|
469
|
+
} else if (typeof value === "object") {
|
|
470
|
+
const serializedObject = serializeObjectParam({
|
|
471
|
+
allowReserved: options.allowReserved,
|
|
472
|
+
explode: true,
|
|
473
|
+
name,
|
|
474
|
+
style: "deepObject",
|
|
475
|
+
value,
|
|
476
|
+
...options.object
|
|
477
|
+
});
|
|
478
|
+
if (serializedObject)
|
|
479
|
+
search.push(serializedObject);
|
|
480
|
+
} else {
|
|
481
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
482
|
+
allowReserved: options.allowReserved,
|
|
483
|
+
name,
|
|
484
|
+
value
|
|
485
|
+
});
|
|
486
|
+
if (serializedPrimitive)
|
|
487
|
+
search.push(serializedPrimitive);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return search.join("&");
|
|
492
|
+
};
|
|
493
|
+
return querySerializer;
|
|
494
|
+
};
|
|
495
|
+
var getParseAs = (contentType) => {
|
|
496
|
+
if (!contentType) {
|
|
497
|
+
return "stream";
|
|
498
|
+
}
|
|
499
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
500
|
+
if (!cleanContent) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
504
|
+
return "json";
|
|
505
|
+
}
|
|
506
|
+
if (cleanContent === "multipart/form-data") {
|
|
507
|
+
return "formData";
|
|
508
|
+
}
|
|
509
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
510
|
+
return "blob";
|
|
511
|
+
}
|
|
512
|
+
if (cleanContent.startsWith("text/")) {
|
|
513
|
+
return "text";
|
|
514
|
+
}
|
|
515
|
+
return;
|
|
516
|
+
};
|
|
517
|
+
var checkForExistence = (options, name) => {
|
|
518
|
+
if (!name) {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
return false;
|
|
525
|
+
};
|
|
526
|
+
var setAuthParams = async ({
|
|
527
|
+
security,
|
|
528
|
+
...options
|
|
529
|
+
}) => {
|
|
530
|
+
for (const auth of security) {
|
|
531
|
+
if (checkForExistence(options, auth.name)) {
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
const token = await getAuthToken(auth, options.auth);
|
|
535
|
+
if (!token) {
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
const name = auth.name ?? "Authorization";
|
|
539
|
+
switch (auth.in) {
|
|
540
|
+
case "query":
|
|
541
|
+
if (!options.query) {
|
|
542
|
+
options.query = {};
|
|
543
|
+
}
|
|
544
|
+
options.query[name] = token;
|
|
545
|
+
break;
|
|
546
|
+
case "cookie":
|
|
547
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
548
|
+
break;
|
|
549
|
+
case "header":
|
|
550
|
+
default:
|
|
551
|
+
options.headers.set(name, token);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
var buildUrl = (options) => getUrl({
|
|
557
|
+
baseUrl: options.baseUrl,
|
|
558
|
+
path: options.path,
|
|
559
|
+
query: options.query,
|
|
560
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
561
|
+
url: options.url
|
|
562
|
+
});
|
|
563
|
+
var mergeConfigs = (a, b) => {
|
|
564
|
+
const config = { ...a, ...b };
|
|
565
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
566
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
567
|
+
}
|
|
568
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
569
|
+
return config;
|
|
570
|
+
};
|
|
571
|
+
var headersEntries = (headers) => {
|
|
572
|
+
const entries = [];
|
|
573
|
+
headers.forEach((value, key) => {
|
|
574
|
+
entries.push([key, value]);
|
|
575
|
+
});
|
|
576
|
+
return entries;
|
|
577
|
+
};
|
|
578
|
+
var mergeHeaders = (...headers) => {
|
|
579
|
+
const mergedHeaders = new Headers;
|
|
580
|
+
for (const header of headers) {
|
|
581
|
+
if (!header) {
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
585
|
+
for (const [key, value] of iterator) {
|
|
586
|
+
if (value === null) {
|
|
587
|
+
mergedHeaders.delete(key);
|
|
588
|
+
} else if (Array.isArray(value)) {
|
|
589
|
+
for (const v of value) {
|
|
590
|
+
mergedHeaders.append(key, v);
|
|
591
|
+
}
|
|
592
|
+
} else if (value !== undefined) {
|
|
593
|
+
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return mergedHeaders;
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
class Interceptors {
|
|
601
|
+
fns = [];
|
|
602
|
+
clear() {
|
|
603
|
+
this.fns = [];
|
|
604
|
+
}
|
|
605
|
+
eject(id) {
|
|
606
|
+
const index = this.getInterceptorIndex(id);
|
|
607
|
+
if (this.fns[index]) {
|
|
608
|
+
this.fns[index] = null;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
exists(id) {
|
|
612
|
+
const index = this.getInterceptorIndex(id);
|
|
613
|
+
return Boolean(this.fns[index]);
|
|
614
|
+
}
|
|
615
|
+
getInterceptorIndex(id) {
|
|
616
|
+
if (typeof id === "number") {
|
|
617
|
+
return this.fns[id] ? id : -1;
|
|
618
|
+
}
|
|
619
|
+
return this.fns.indexOf(id);
|
|
620
|
+
}
|
|
621
|
+
update(id, fn) {
|
|
622
|
+
const index = this.getInterceptorIndex(id);
|
|
623
|
+
if (this.fns[index]) {
|
|
624
|
+
this.fns[index] = fn;
|
|
625
|
+
return id;
|
|
626
|
+
}
|
|
627
|
+
return false;
|
|
628
|
+
}
|
|
629
|
+
use(fn) {
|
|
630
|
+
this.fns.push(fn);
|
|
631
|
+
return this.fns.length - 1;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
var createInterceptors = () => ({
|
|
635
|
+
error: new Interceptors,
|
|
636
|
+
request: new Interceptors,
|
|
637
|
+
response: new Interceptors
|
|
638
|
+
});
|
|
639
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
640
|
+
allowReserved: false,
|
|
641
|
+
array: {
|
|
642
|
+
explode: true,
|
|
643
|
+
style: "form"
|
|
644
|
+
},
|
|
645
|
+
object: {
|
|
646
|
+
explode: true,
|
|
647
|
+
style: "deepObject"
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
var defaultHeaders = {
|
|
651
|
+
"Content-Type": "application/json"
|
|
652
|
+
};
|
|
653
|
+
var createConfig = (override = {}) => ({
|
|
654
|
+
...jsonBodySerializer,
|
|
655
|
+
headers: defaultHeaders,
|
|
656
|
+
parseAs: "auto",
|
|
657
|
+
querySerializer: defaultQuerySerializer,
|
|
658
|
+
...override
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
// src/gen/client/client.gen.ts
|
|
662
|
+
var createClient = (config = {}) => {
|
|
663
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
664
|
+
const getConfig = () => ({ ..._config });
|
|
665
|
+
const setConfig = (config2) => {
|
|
666
|
+
_config = mergeConfigs(_config, config2);
|
|
667
|
+
return getConfig();
|
|
668
|
+
};
|
|
669
|
+
const interceptors = createInterceptors();
|
|
670
|
+
const beforeRequest = async (options) => {
|
|
671
|
+
const opts = {
|
|
672
|
+
..._config,
|
|
673
|
+
...options,
|
|
674
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
675
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
676
|
+
serializedBody: undefined
|
|
677
|
+
};
|
|
678
|
+
if (opts.security) {
|
|
679
|
+
await setAuthParams({
|
|
680
|
+
...opts,
|
|
681
|
+
security: opts.security
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
if (opts.requestValidator) {
|
|
685
|
+
await opts.requestValidator(opts);
|
|
686
|
+
}
|
|
687
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
688
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
689
|
+
}
|
|
690
|
+
if (opts.body === undefined || opts.serializedBody === "") {
|
|
691
|
+
opts.headers.delete("Content-Type");
|
|
692
|
+
}
|
|
693
|
+
const url = buildUrl(opts);
|
|
694
|
+
return { opts, url };
|
|
695
|
+
};
|
|
696
|
+
const request = async (options) => {
|
|
697
|
+
const { opts, url } = await beforeRequest(options);
|
|
698
|
+
const requestInit = {
|
|
699
|
+
redirect: "follow",
|
|
700
|
+
...opts,
|
|
701
|
+
body: getValidRequestBody(opts)
|
|
702
|
+
};
|
|
703
|
+
let request2 = new Request(url, requestInit);
|
|
704
|
+
for (const fn of interceptors.request.fns) {
|
|
705
|
+
if (fn) {
|
|
706
|
+
request2 = await fn(request2, opts);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const _fetch = opts.fetch;
|
|
710
|
+
let response;
|
|
711
|
+
try {
|
|
712
|
+
response = await _fetch(request2);
|
|
713
|
+
} catch (error2) {
|
|
714
|
+
let finalError2 = error2;
|
|
715
|
+
for (const fn of interceptors.error.fns) {
|
|
716
|
+
if (fn) {
|
|
717
|
+
finalError2 = await fn(error2, undefined, request2, opts);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
finalError2 = finalError2 || {};
|
|
721
|
+
if (opts.throwOnError) {
|
|
722
|
+
throw finalError2;
|
|
723
|
+
}
|
|
724
|
+
return opts.responseStyle === "data" ? undefined : {
|
|
725
|
+
error: finalError2,
|
|
726
|
+
request: request2,
|
|
727
|
+
response: undefined
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
for (const fn of interceptors.response.fns) {
|
|
731
|
+
if (fn) {
|
|
732
|
+
response = await fn(response, request2, opts);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
const result = {
|
|
736
|
+
request: request2,
|
|
737
|
+
response
|
|
738
|
+
};
|
|
739
|
+
if (response.ok) {
|
|
740
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
741
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
742
|
+
let emptyData;
|
|
743
|
+
switch (parseAs) {
|
|
744
|
+
case "arrayBuffer":
|
|
745
|
+
case "blob":
|
|
746
|
+
case "text":
|
|
747
|
+
emptyData = await response[parseAs]();
|
|
748
|
+
break;
|
|
749
|
+
case "formData":
|
|
750
|
+
emptyData = new FormData;
|
|
751
|
+
break;
|
|
752
|
+
case "stream":
|
|
753
|
+
emptyData = response.body;
|
|
754
|
+
break;
|
|
755
|
+
case "json":
|
|
756
|
+
default:
|
|
757
|
+
emptyData = {};
|
|
758
|
+
break;
|
|
759
|
+
}
|
|
760
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
761
|
+
data: emptyData,
|
|
762
|
+
...result
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
let data;
|
|
766
|
+
switch (parseAs) {
|
|
767
|
+
case "arrayBuffer":
|
|
768
|
+
case "blob":
|
|
769
|
+
case "formData":
|
|
770
|
+
case "text":
|
|
771
|
+
data = await response[parseAs]();
|
|
772
|
+
break;
|
|
773
|
+
case "json": {
|
|
774
|
+
const text = await response.text();
|
|
775
|
+
data = text ? JSON.parse(text) : {};
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
case "stream":
|
|
779
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
780
|
+
data: response.body,
|
|
781
|
+
...result
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
if (parseAs === "json") {
|
|
785
|
+
if (opts.responseValidator) {
|
|
786
|
+
await opts.responseValidator(data);
|
|
787
|
+
}
|
|
788
|
+
if (opts.responseTransformer) {
|
|
789
|
+
data = await opts.responseTransformer(data);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return opts.responseStyle === "data" ? data : {
|
|
793
|
+
data,
|
|
794
|
+
...result
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
const textError = await response.text();
|
|
798
|
+
let jsonError;
|
|
799
|
+
try {
|
|
800
|
+
jsonError = JSON.parse(textError);
|
|
801
|
+
} catch {}
|
|
802
|
+
const error = jsonError ?? textError;
|
|
803
|
+
let finalError = error;
|
|
804
|
+
for (const fn of interceptors.error.fns) {
|
|
805
|
+
if (fn) {
|
|
806
|
+
finalError = await fn(error, response, request2, opts);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
finalError = finalError || {};
|
|
810
|
+
if (opts.throwOnError) {
|
|
811
|
+
throw finalError;
|
|
812
|
+
}
|
|
813
|
+
return opts.responseStyle === "data" ? undefined : {
|
|
814
|
+
error: finalError,
|
|
815
|
+
...result
|
|
816
|
+
};
|
|
817
|
+
};
|
|
818
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
819
|
+
const makeSseFn = (method) => async (options) => {
|
|
820
|
+
const { opts, url } = await beforeRequest(options);
|
|
821
|
+
return createSseClient({
|
|
822
|
+
...opts,
|
|
823
|
+
body: opts.body,
|
|
824
|
+
headers: opts.headers,
|
|
825
|
+
method,
|
|
826
|
+
onRequest: async (url2, init) => {
|
|
827
|
+
let request2 = new Request(url2, init);
|
|
828
|
+
for (const fn of interceptors.request.fns) {
|
|
829
|
+
if (fn) {
|
|
830
|
+
request2 = await fn(request2, opts);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return request2;
|
|
834
|
+
},
|
|
835
|
+
serializedBody: getValidRequestBody(opts),
|
|
836
|
+
url
|
|
837
|
+
});
|
|
838
|
+
};
|
|
839
|
+
return {
|
|
840
|
+
buildUrl,
|
|
841
|
+
connect: makeMethodFn("CONNECT"),
|
|
842
|
+
delete: makeMethodFn("DELETE"),
|
|
843
|
+
get: makeMethodFn("GET"),
|
|
844
|
+
getConfig,
|
|
845
|
+
head: makeMethodFn("HEAD"),
|
|
846
|
+
interceptors,
|
|
847
|
+
options: makeMethodFn("OPTIONS"),
|
|
848
|
+
patch: makeMethodFn("PATCH"),
|
|
849
|
+
post: makeMethodFn("POST"),
|
|
850
|
+
put: makeMethodFn("PUT"),
|
|
851
|
+
request,
|
|
852
|
+
setConfig,
|
|
853
|
+
sse: {
|
|
854
|
+
connect: makeSseFn("CONNECT"),
|
|
855
|
+
delete: makeSseFn("DELETE"),
|
|
856
|
+
get: makeSseFn("GET"),
|
|
857
|
+
head: makeSseFn("HEAD"),
|
|
858
|
+
options: makeSseFn("OPTIONS"),
|
|
859
|
+
patch: makeSseFn("PATCH"),
|
|
860
|
+
post: makeSseFn("POST"),
|
|
861
|
+
put: makeSseFn("PUT"),
|
|
862
|
+
trace: makeSseFn("TRACE")
|
|
863
|
+
},
|
|
864
|
+
trace: makeMethodFn("TRACE")
|
|
865
|
+
};
|
|
866
|
+
};
|
|
867
|
+
// src/openapi-runtime.ts
|
|
868
|
+
var DEFAULT_BASE_URL = "https://api.multisender.app";
|
|
869
|
+
var DEFAULT_TIMEOUT = 30000;
|
|
870
|
+
var defaultRuntimeConfig = {
|
|
871
|
+
apiKey: "",
|
|
872
|
+
baseUrl: DEFAULT_BASE_URL,
|
|
873
|
+
timeout: DEFAULT_TIMEOUT,
|
|
874
|
+
headers: {}
|
|
875
|
+
};
|
|
876
|
+
var mergeHeaders2 = (headers) => ({
|
|
877
|
+
...headers
|
|
878
|
+
});
|
|
879
|
+
var withTimeoutFetch = (timeoutMs) => {
|
|
880
|
+
const timeout = timeoutMs ?? DEFAULT_TIMEOUT;
|
|
881
|
+
return async (input, init) => {
|
|
882
|
+
if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
|
|
883
|
+
const timeoutSignal = AbortSignal.timeout(timeout);
|
|
884
|
+
if (!init?.signal) {
|
|
885
|
+
return fetch(input, { ...init, signal: timeoutSignal });
|
|
886
|
+
}
|
|
887
|
+
const controller2 = new AbortController;
|
|
888
|
+
const abort = () => controller2.abort();
|
|
889
|
+
timeoutSignal.addEventListener("abort", abort, { once: true });
|
|
890
|
+
init.signal.addEventListener("abort", abort, { once: true });
|
|
891
|
+
const signal2 = controller2.signal;
|
|
892
|
+
return fetch(input, { ...init, signal: signal2 });
|
|
893
|
+
}
|
|
894
|
+
const controller = new AbortController;
|
|
895
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
896
|
+
init?.signal?.addEventListener("abort", () => controller.abort(), { once: true });
|
|
897
|
+
const signal = controller.signal;
|
|
898
|
+
try {
|
|
899
|
+
return await fetch(input, { ...init, signal });
|
|
900
|
+
} finally {
|
|
901
|
+
clearTimeout(timer);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
};
|
|
905
|
+
var toClientConfig = (config) => ({
|
|
906
|
+
baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
|
|
907
|
+
fetch: withTimeoutFetch(config.timeout),
|
|
908
|
+
headers: {
|
|
909
|
+
...mergeHeaders2(config.headers),
|
|
910
|
+
...config.apiKey ? { "X-API-Key": config.apiKey } : {}
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
var setRuntimeConfig = (config) => {
|
|
914
|
+
return toClientConfig({
|
|
915
|
+
...defaultRuntimeConfig,
|
|
916
|
+
...config,
|
|
917
|
+
headers: {
|
|
918
|
+
...defaultRuntimeConfig.headers,
|
|
919
|
+
...mergeHeaders2(config.headers)
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
};
|
|
923
|
+
var createClientConfig = (override = {}) => ({
|
|
924
|
+
...toClientConfig(defaultRuntimeConfig),
|
|
925
|
+
...override,
|
|
926
|
+
headers: {
|
|
927
|
+
...toClientConfig(defaultRuntimeConfig).headers,
|
|
928
|
+
...override.headers ?? {}
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
// src/core/errors.ts
|
|
933
|
+
class MultisenderError extends Error {
|
|
934
|
+
constructor(message) {
|
|
935
|
+
super(message);
|
|
936
|
+
this.name = "MultisenderError";
|
|
937
|
+
Object.setPrototypeOf(this, MultisenderError.prototype);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
class ApiError extends MultisenderError {
|
|
942
|
+
status;
|
|
943
|
+
body;
|
|
944
|
+
constructor(status, body, message) {
|
|
945
|
+
super(message || `API request failed with status ${status}`);
|
|
946
|
+
this.status = status;
|
|
947
|
+
this.body = body;
|
|
948
|
+
this.name = "ApiError";
|
|
949
|
+
Object.setPrototypeOf(this, ApiError.prototype);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
class NetworkError extends MultisenderError {
|
|
954
|
+
cause;
|
|
955
|
+
constructor(message, cause) {
|
|
956
|
+
super(message);
|
|
957
|
+
this.cause = cause;
|
|
958
|
+
this.name = "NetworkError";
|
|
959
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
class ValidationError extends MultisenderError {
|
|
964
|
+
fields;
|
|
965
|
+
constructor(message, fields) {
|
|
966
|
+
super(message);
|
|
967
|
+
this.fields = fields;
|
|
968
|
+
this.name = "ValidationError";
|
|
969
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
class TimeoutError extends MultisenderError {
|
|
974
|
+
constructor(message = "Request timeout") {
|
|
975
|
+
super(message);
|
|
976
|
+
this.name = "TimeoutError";
|
|
977
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// src/core/generated-transport.ts
|
|
982
|
+
var isGeneratedHttpError = (error) => typeof error === "object" && error !== null && (("status" in error) || ("body" in error));
|
|
983
|
+
var isGeneratedWrappedResponse = (value) => typeof value === "object" && value !== null && ("data" in value);
|
|
984
|
+
var mapGeneratedError = (error) => {
|
|
985
|
+
if (error instanceof Error) {
|
|
986
|
+
if (error.name === "AbortError" || error.name === "TimeoutError") {
|
|
987
|
+
throw new TimeoutError("Request timeout");
|
|
988
|
+
}
|
|
989
|
+
throw new NetworkError(error.message, error);
|
|
990
|
+
}
|
|
991
|
+
if (isGeneratedHttpError(error)) {
|
|
992
|
+
throw new ApiError(error.status ?? 500, error.body ?? error);
|
|
993
|
+
}
|
|
994
|
+
if (typeof error === "string") {
|
|
995
|
+
throw new ApiError(500, { message: error }, error);
|
|
996
|
+
}
|
|
997
|
+
throw new ApiError(500, error, "Unexpected API error");
|
|
998
|
+
};
|
|
999
|
+
var executeGenerated = async (operation) => {
|
|
1000
|
+
try {
|
|
1001
|
+
const result = await operation;
|
|
1002
|
+
return isGeneratedWrappedResponse(result) ? result.data : result;
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
return mapGeneratedError(error);
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
// src/core/pagination.ts
|
|
1009
|
+
function buildPaginationQuery(params) {
|
|
1010
|
+
if (!params)
|
|
1011
|
+
return {};
|
|
1012
|
+
const query = {};
|
|
1013
|
+
if (params.page !== undefined) {
|
|
1014
|
+
query.page = params.page.toString();
|
|
1015
|
+
}
|
|
1016
|
+
if (params.limit !== undefined) {
|
|
1017
|
+
query.limit = params.limit.toString();
|
|
1018
|
+
}
|
|
1019
|
+
if (params.orderBy) {
|
|
1020
|
+
query.orderBy = params.orderBy;
|
|
1021
|
+
}
|
|
1022
|
+
if (params.orderDir) {
|
|
1023
|
+
query.orderDir = params.orderDir;
|
|
1024
|
+
}
|
|
1025
|
+
if (params.search) {
|
|
1026
|
+
query.search = params.search;
|
|
1027
|
+
}
|
|
1028
|
+
return query;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// src/gen/client.gen.ts
|
|
1032
|
+
var client = createClient(createClientConfig(createConfig()));
|
|
1033
|
+
|
|
1034
|
+
// src/gen/sdk.gen.ts
|
|
1035
|
+
var getProjectInfo = (options) => (options.client ?? client).get({ url: "/api/v1/project", ...options });
|
|
1036
|
+
var getProjectMembers = (options) => (options.client ?? client).get({ url: "/api/v1/project/members", ...options });
|
|
1037
|
+
var getApiKeys = (options) => (options.client ?? client).get({ url: "/api/v1/project/api-keys", ...options });
|
|
1038
|
+
var createApiKey = (options) => (options.client ?? client).post({
|
|
1039
|
+
url: "/api/v1/project/api-keys",
|
|
1040
|
+
...options,
|
|
1041
|
+
headers: {
|
|
1042
|
+
"Content-Type": "application/json",
|
|
1043
|
+
...options.headers
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
var deleteApiKey = (options) => (options.client ?? client).delete({ url: "/api/v1/project/api-keys/{apiKeyId}", ...options });
|
|
1047
|
+
var updateApiKey = (options) => (options.client ?? client).patch({
|
|
1048
|
+
url: "/api/v1/project/api-keys/{apiKeyId}",
|
|
1049
|
+
...options,
|
|
1050
|
+
headers: {
|
|
1051
|
+
"Content-Type": "application/json",
|
|
1052
|
+
...options.headers
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
var findAll = (options) => (options.client ?? client).get({ url: "/api/v1/lists", ...options });
|
|
1056
|
+
var create = (options) => (options.client ?? client).post({
|
|
1057
|
+
url: "/api/v1/lists",
|
|
1058
|
+
...options,
|
|
1059
|
+
headers: {
|
|
1060
|
+
"Content-Type": "application/json",
|
|
1061
|
+
...options.headers
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
var remove = (options) => (options.client ?? client).delete({ url: "/api/v1/lists/{listId}", ...options });
|
|
1065
|
+
var findOne = (options) => (options.client ?? client).get({ url: "/api/v1/lists/{listId}", ...options });
|
|
1066
|
+
var update = (options) => (options.client ?? client).patch({
|
|
1067
|
+
url: "/api/v1/lists/{listId}",
|
|
1068
|
+
...options,
|
|
1069
|
+
headers: {
|
|
1070
|
+
"Content-Type": "application/json",
|
|
1071
|
+
...options.headers
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
var getRecipients = (options) => (options.client ?? client).get({ url: "/api/v1/lists/{listId}/recipients", ...options });
|
|
1075
|
+
var addRecipient = (options) => (options.client ?? client).post({
|
|
1076
|
+
url: "/api/v1/lists/{listId}/recipients",
|
|
1077
|
+
...options,
|
|
1078
|
+
headers: {
|
|
1079
|
+
"Content-Type": "application/json",
|
|
1080
|
+
...options.headers
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
var addRecipientsBulk = (options) => (options.client ?? client).post({
|
|
1084
|
+
url: "/api/v1/lists/{listId}/recipients/bulk",
|
|
1085
|
+
...options,
|
|
1086
|
+
headers: {
|
|
1087
|
+
"Content-Type": "application/json",
|
|
1088
|
+
...options.headers
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
var removeRecipient = (options) => (options.client ?? client).delete({ url: "/api/v1/lists/{listId}/recipients/{recipientId}", ...options });
|
|
1092
|
+
var importFromFile = (options) => (options.client ?? client).post({ url: "/api/v1/lists/{listId}/import", ...options });
|
|
1093
|
+
var createDistributionList = (options) => (options.client ?? client).post({
|
|
1094
|
+
url: "/api/v1/lists/distribution",
|
|
1095
|
+
...options,
|
|
1096
|
+
headers: {
|
|
1097
|
+
"Content-Type": "application/json",
|
|
1098
|
+
...options.headers
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
var importCsvDistribution = (options) => (options.client ?? client).post({
|
|
1102
|
+
url: "/api/v1/lists/distribution/csv",
|
|
1103
|
+
...options,
|
|
1104
|
+
headers: {
|
|
1105
|
+
"Content-Type": "application/json",
|
|
1106
|
+
...options.headers
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
var distribute = (options) => (options.client ?? client).post({
|
|
1110
|
+
url: "/api/v1/distribute",
|
|
1111
|
+
...options,
|
|
1112
|
+
headers: {
|
|
1113
|
+
"Content-Type": "application/json",
|
|
1114
|
+
...options.headers
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
var findAll2 = (options) => (options.client ?? client).get({ url: "/api/v1/distributions", ...options });
|
|
1118
|
+
var findOne2 = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}", ...options });
|
|
1119
|
+
var getTransactions = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/transactions", ...options });
|
|
1120
|
+
var getStats = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/stats", ...options });
|
|
1121
|
+
var cancel = (options) => (options.client ?? client).post({ url: "/api/v1/distributions/{id}/cancel", ...options });
|
|
1122
|
+
var getChains = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/chains", ...options });
|
|
1123
|
+
var getChain = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/chains/{chainId}", ...options });
|
|
1124
|
+
var getTokens = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/tokens", ...options });
|
|
1125
|
+
var searchTokens = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/tokens/search", ...options });
|
|
1126
|
+
var getToken = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/tokens/{chainId}/{address}", ...options });
|
|
1127
|
+
// src/services/response-utils.ts
|
|
1128
|
+
function unwrapData(result) {
|
|
1129
|
+
const raw = result;
|
|
1130
|
+
if (raw?.data != null)
|
|
1131
|
+
return raw.data;
|
|
1132
|
+
return result;
|
|
1133
|
+
}
|
|
1134
|
+
function unwrapDistribution(result) {
|
|
1135
|
+
const raw = result;
|
|
1136
|
+
if (raw?.data?.distribution != null)
|
|
1137
|
+
return raw.data.distribution;
|
|
1138
|
+
if (raw?.distribution != null)
|
|
1139
|
+
return raw.distribution;
|
|
1140
|
+
return result;
|
|
1141
|
+
}
|
|
1142
|
+
function normalizePaginatedResponse(result, page, limit) {
|
|
1143
|
+
const raw = result;
|
|
1144
|
+
if ("meta" in raw && raw.meta != null && Array.isArray(raw.data)) {
|
|
1145
|
+
return raw;
|
|
1146
|
+
}
|
|
1147
|
+
const inner = raw.data && typeof raw.data === "object" && "data" in raw.data ? raw.data : null;
|
|
1148
|
+
const items = inner && Array.isArray(inner.data) ? inner.data : [];
|
|
1149
|
+
const total = inner && typeof inner.total === "number" ? inner.total : items.length;
|
|
1150
|
+
return {
|
|
1151
|
+
data: items,
|
|
1152
|
+
meta: {
|
|
1153
|
+
page,
|
|
1154
|
+
limit,
|
|
1155
|
+
total,
|
|
1156
|
+
totalPages: Math.ceil(total / limit) || 1
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// src/services/distributions.ts
|
|
1162
|
+
class DistributionsService {
|
|
1163
|
+
headers;
|
|
1164
|
+
client;
|
|
1165
|
+
constructor(headers, client2) {
|
|
1166
|
+
this.headers = headers;
|
|
1167
|
+
this.client = client2;
|
|
1168
|
+
}
|
|
1169
|
+
async distribute(request) {
|
|
1170
|
+
const result = await executeGenerated(distribute({
|
|
1171
|
+
body: request,
|
|
1172
|
+
client: this.client,
|
|
1173
|
+
headers: this.headers,
|
|
1174
|
+
throwOnError: true
|
|
1175
|
+
}));
|
|
1176
|
+
return unwrapDistribution(result);
|
|
1177
|
+
}
|
|
1178
|
+
async list(params) {
|
|
1179
|
+
const query = buildPaginationQuery(params);
|
|
1180
|
+
const page = params?.page ?? 1;
|
|
1181
|
+
const limit = params?.limit ?? 20;
|
|
1182
|
+
const result = await executeGenerated(findAll2({
|
|
1183
|
+
client: this.client,
|
|
1184
|
+
headers: this.headers,
|
|
1185
|
+
query,
|
|
1186
|
+
throwOnError: true
|
|
1187
|
+
}));
|
|
1188
|
+
return normalizePaginatedResponse(result, page, limit);
|
|
1189
|
+
}
|
|
1190
|
+
async get(id) {
|
|
1191
|
+
const result = await executeGenerated(findOne2({
|
|
1192
|
+
client: this.client,
|
|
1193
|
+
headers: this.headers,
|
|
1194
|
+
path: { id },
|
|
1195
|
+
throwOnError: true
|
|
1196
|
+
}));
|
|
1197
|
+
return unwrapData(result);
|
|
1198
|
+
}
|
|
1199
|
+
async getTransactions(id, params) {
|
|
1200
|
+
const query = buildPaginationQuery(params);
|
|
1201
|
+
const page = params?.page ?? 1;
|
|
1202
|
+
const limit = params?.limit ?? 20;
|
|
1203
|
+
const result = await executeGenerated(getTransactions({
|
|
1204
|
+
client: this.client,
|
|
1205
|
+
headers: this.headers,
|
|
1206
|
+
path: { id },
|
|
1207
|
+
query,
|
|
1208
|
+
throwOnError: true
|
|
1209
|
+
}));
|
|
1210
|
+
return normalizePaginatedResponse(result, page, limit);
|
|
1211
|
+
}
|
|
1212
|
+
async getStats(id) {
|
|
1213
|
+
const result = await executeGenerated(getStats({
|
|
1214
|
+
client: this.client,
|
|
1215
|
+
headers: this.headers,
|
|
1216
|
+
path: { id },
|
|
1217
|
+
throwOnError: true
|
|
1218
|
+
}));
|
|
1219
|
+
return unwrapData(result);
|
|
1220
|
+
}
|
|
1221
|
+
async cancel(id) {
|
|
1222
|
+
const result = await executeGenerated(cancel({
|
|
1223
|
+
client: this.client,
|
|
1224
|
+
headers: this.headers,
|
|
1225
|
+
path: { id },
|
|
1226
|
+
throwOnError: true
|
|
1227
|
+
}));
|
|
1228
|
+
return unwrapData(result);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// src/services/lists.ts
|
|
1233
|
+
class ListsService {
|
|
1234
|
+
headers;
|
|
1235
|
+
client;
|
|
1236
|
+
constructor(headers, client2) {
|
|
1237
|
+
this.headers = headers;
|
|
1238
|
+
this.client = client2;
|
|
1239
|
+
}
|
|
1240
|
+
async list(params) {
|
|
1241
|
+
const query = buildPaginationQuery(params);
|
|
1242
|
+
const page = params?.page ?? 1;
|
|
1243
|
+
const limit = params?.limit ?? 20;
|
|
1244
|
+
const result = await executeGenerated(findAll({
|
|
1245
|
+
client: this.client,
|
|
1246
|
+
headers: this.headers,
|
|
1247
|
+
query,
|
|
1248
|
+
throwOnError: true
|
|
1249
|
+
}));
|
|
1250
|
+
return normalizePaginatedResponse(result, page, limit);
|
|
1251
|
+
}
|
|
1252
|
+
async create(request) {
|
|
1253
|
+
const result = await executeGenerated(create({
|
|
1254
|
+
body: request,
|
|
1255
|
+
client: this.client,
|
|
1256
|
+
headers: this.headers,
|
|
1257
|
+
throwOnError: true
|
|
1258
|
+
}));
|
|
1259
|
+
return unwrapData(result);
|
|
1260
|
+
}
|
|
1261
|
+
async get(listId) {
|
|
1262
|
+
const result = await executeGenerated(findOne({
|
|
1263
|
+
client: this.client,
|
|
1264
|
+
headers: this.headers,
|
|
1265
|
+
path: { listId },
|
|
1266
|
+
throwOnError: true
|
|
1267
|
+
}));
|
|
1268
|
+
return unwrapData(result);
|
|
1269
|
+
}
|
|
1270
|
+
async update(listId, request) {
|
|
1271
|
+
const result = await executeGenerated(update({
|
|
1272
|
+
body: request,
|
|
1273
|
+
client: this.client,
|
|
1274
|
+
headers: this.headers,
|
|
1275
|
+
path: { listId },
|
|
1276
|
+
throwOnError: true
|
|
1277
|
+
}));
|
|
1278
|
+
return unwrapData(result);
|
|
1279
|
+
}
|
|
1280
|
+
async delete(listId) {
|
|
1281
|
+
await executeGenerated(remove({
|
|
1282
|
+
client: this.client,
|
|
1283
|
+
headers: this.headers,
|
|
1284
|
+
path: { listId },
|
|
1285
|
+
throwOnError: true
|
|
1286
|
+
}));
|
|
1287
|
+
}
|
|
1288
|
+
async getRecipients(listId, params) {
|
|
1289
|
+
const query = buildPaginationQuery(params);
|
|
1290
|
+
const page = params?.page ?? 1;
|
|
1291
|
+
const limit = params?.limit ?? 20;
|
|
1292
|
+
const result = await executeGenerated(getRecipients({
|
|
1293
|
+
client: this.client,
|
|
1294
|
+
headers: this.headers,
|
|
1295
|
+
path: { listId },
|
|
1296
|
+
query,
|
|
1297
|
+
throwOnError: true
|
|
1298
|
+
}));
|
|
1299
|
+
return normalizePaginatedResponse(result, page, limit);
|
|
1300
|
+
}
|
|
1301
|
+
async addRecipient(listId, request) {
|
|
1302
|
+
const result = await executeGenerated(addRecipient({
|
|
1303
|
+
body: request,
|
|
1304
|
+
client: this.client,
|
|
1305
|
+
headers: this.headers,
|
|
1306
|
+
path: { listId },
|
|
1307
|
+
throwOnError: true
|
|
1308
|
+
}));
|
|
1309
|
+
return unwrapData(result);
|
|
1310
|
+
}
|
|
1311
|
+
async addRecipientsBulk(listId, request) {
|
|
1312
|
+
const result = await executeGenerated(addRecipientsBulk({
|
|
1313
|
+
body: request,
|
|
1314
|
+
client: this.client,
|
|
1315
|
+
headers: this.headers,
|
|
1316
|
+
path: { listId },
|
|
1317
|
+
throwOnError: true
|
|
1318
|
+
}));
|
|
1319
|
+
return {
|
|
1320
|
+
added: result.added ?? 0,
|
|
1321
|
+
skippedAddresses: result.skippedAddresses ?? [],
|
|
1322
|
+
errors: result.errors ?? []
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
async removeRecipient(listId, recipientId) {
|
|
1326
|
+
await executeGenerated(removeRecipient({
|
|
1327
|
+
client: this.client,
|
|
1328
|
+
headers: this.headers,
|
|
1329
|
+
path: { listId, recipientId },
|
|
1330
|
+
throwOnError: true
|
|
1331
|
+
}));
|
|
1332
|
+
}
|
|
1333
|
+
async importFromCsv(listId, file) {
|
|
1334
|
+
if (!file) {
|
|
1335
|
+
throw new Error("importFromCsv: file is required");
|
|
1336
|
+
}
|
|
1337
|
+
const formData = new FormData;
|
|
1338
|
+
if (file instanceof Buffer) {
|
|
1339
|
+
formData.append("file", new Blob([new Uint8Array(file)]), "import.csv");
|
|
1340
|
+
} else {
|
|
1341
|
+
const f = file;
|
|
1342
|
+
formData.append("file", f, f.name);
|
|
1343
|
+
}
|
|
1344
|
+
const result = await executeGenerated(importFromFile({
|
|
1345
|
+
path: { listId },
|
|
1346
|
+
body: formData,
|
|
1347
|
+
bodySerializer: (b) => b,
|
|
1348
|
+
client: this.client,
|
|
1349
|
+
headers: this.headers,
|
|
1350
|
+
throwOnError: true
|
|
1351
|
+
}));
|
|
1352
|
+
return unwrapData(result);
|
|
1353
|
+
}
|
|
1354
|
+
async createDistributionList(request) {
|
|
1355
|
+
const result = await executeGenerated(createDistributionList({
|
|
1356
|
+
body: request,
|
|
1357
|
+
client: this.client,
|
|
1358
|
+
headers: this.headers,
|
|
1359
|
+
throwOnError: true
|
|
1360
|
+
}));
|
|
1361
|
+
const raw = unwrapData(result);
|
|
1362
|
+
if (raw?.list == null)
|
|
1363
|
+
throw new Error("API response missing list");
|
|
1364
|
+
return raw.list;
|
|
1365
|
+
}
|
|
1366
|
+
async importCsvDistribution(request) {
|
|
1367
|
+
const result = await executeGenerated(importCsvDistribution({
|
|
1368
|
+
body: request,
|
|
1369
|
+
client: this.client,
|
|
1370
|
+
headers: this.headers,
|
|
1371
|
+
throwOnError: true
|
|
1372
|
+
}));
|
|
1373
|
+
const raw = unwrapData(result);
|
|
1374
|
+
if (raw?.list == null)
|
|
1375
|
+
throw new Error("API response missing list");
|
|
1376
|
+
return raw.list;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// src/services/project.ts
|
|
1381
|
+
class ProjectService {
|
|
1382
|
+
headers;
|
|
1383
|
+
client;
|
|
1384
|
+
constructor(headers, client2) {
|
|
1385
|
+
this.headers = headers;
|
|
1386
|
+
this.client = client2;
|
|
1387
|
+
}
|
|
1388
|
+
async getInfo() {
|
|
1389
|
+
const result = await executeGenerated(getProjectInfo({
|
|
1390
|
+
client: this.client,
|
|
1391
|
+
headers: this.headers,
|
|
1392
|
+
throwOnError: true
|
|
1393
|
+
}));
|
|
1394
|
+
return unwrapData(result);
|
|
1395
|
+
}
|
|
1396
|
+
async getMembers() {
|
|
1397
|
+
const result = await executeGenerated(getProjectMembers({
|
|
1398
|
+
client: this.client,
|
|
1399
|
+
headers: this.headers,
|
|
1400
|
+
throwOnError: true
|
|
1401
|
+
}));
|
|
1402
|
+
const members = unwrapData(result);
|
|
1403
|
+
return Array.isArray(members) ? members : [members];
|
|
1404
|
+
}
|
|
1405
|
+
async listApiKeys() {
|
|
1406
|
+
const result = await executeGenerated(getApiKeys({
|
|
1407
|
+
client: this.client,
|
|
1408
|
+
headers: this.headers,
|
|
1409
|
+
throwOnError: true
|
|
1410
|
+
}));
|
|
1411
|
+
const data = unwrapData(result);
|
|
1412
|
+
return Array.isArray(data) ? data : result;
|
|
1413
|
+
}
|
|
1414
|
+
async createApiKey(request) {
|
|
1415
|
+
const result = await executeGenerated(createApiKey({
|
|
1416
|
+
body: request,
|
|
1417
|
+
client: this.client,
|
|
1418
|
+
headers: this.headers,
|
|
1419
|
+
throwOnError: true
|
|
1420
|
+
}));
|
|
1421
|
+
return unwrapData(result);
|
|
1422
|
+
}
|
|
1423
|
+
async updateApiKey(apiKeyId, request) {
|
|
1424
|
+
const result = await executeGenerated(updateApiKey({
|
|
1425
|
+
body: request,
|
|
1426
|
+
client: this.client,
|
|
1427
|
+
headers: this.headers,
|
|
1428
|
+
path: { apiKeyId },
|
|
1429
|
+
throwOnError: true
|
|
1430
|
+
}));
|
|
1431
|
+
return unwrapData(result);
|
|
1432
|
+
}
|
|
1433
|
+
async deleteApiKey(apiKeyId) {
|
|
1434
|
+
await executeGenerated(deleteApiKey({
|
|
1435
|
+
client: this.client,
|
|
1436
|
+
headers: this.headers,
|
|
1437
|
+
path: { apiKeyId },
|
|
1438
|
+
throwOnError: true
|
|
1439
|
+
}));
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// src/utils/validation.ts
|
|
1444
|
+
function validateEthereumAddress(address) {
|
|
1445
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
1446
|
+
}
|
|
1447
|
+
function validatePositiveNumber(value) {
|
|
1448
|
+
const num = typeof value === "string" ? parseFloat(value) : value;
|
|
1449
|
+
return !isNaN(num) && num > 0;
|
|
1450
|
+
}
|
|
1451
|
+
function validateChainId(chainId) {
|
|
1452
|
+
if (!Number.isInteger(chainId) || chainId <= 0) {
|
|
1453
|
+
throw new ValidationError("Chain ID must be a positive integer");
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
function validateRecipients(recipients) {
|
|
1457
|
+
if (!Array.isArray(recipients) || recipients.length === 0) {
|
|
1458
|
+
throw new ValidationError("Recipients must be a non-empty array");
|
|
1459
|
+
}
|
|
1460
|
+
for (let i = 0;i < recipients.length; i++) {
|
|
1461
|
+
const [address, amount] = recipients[i];
|
|
1462
|
+
if (!address || typeof address !== "string") {
|
|
1463
|
+
throw new ValidationError(`Invalid address at index ${i}`);
|
|
1464
|
+
}
|
|
1465
|
+
if (!validateEthereumAddress(address)) {
|
|
1466
|
+
throw new ValidationError(`Invalid Ethereum address at index ${i}: ${address}`);
|
|
1467
|
+
}
|
|
1468
|
+
if (!validatePositiveNumber(amount)) {
|
|
1469
|
+
throw new ValidationError(`Invalid amount at index ${i}: ${amount}`);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
function validateTokenAddress(address) {
|
|
1474
|
+
if (!validateEthereumAddress(address)) {
|
|
1475
|
+
throw new ValidationError(`Invalid token address: ${address}`);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
function validateApiKey(apiKey) {
|
|
1479
|
+
if (!apiKey || apiKey.trim().length < 10) {
|
|
1480
|
+
throw new ValidationError("Invalid API key format");
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// src/services/catalogs.ts
|
|
1485
|
+
class CatalogsService {
|
|
1486
|
+
headers;
|
|
1487
|
+
client;
|
|
1488
|
+
constructor(headers, client2) {
|
|
1489
|
+
this.headers = headers;
|
|
1490
|
+
this.client = client2;
|
|
1491
|
+
}
|
|
1492
|
+
async getChains() {
|
|
1493
|
+
return executeGenerated(getChains({
|
|
1494
|
+
client: this.client,
|
|
1495
|
+
headers: this.headers,
|
|
1496
|
+
throwOnError: true
|
|
1497
|
+
}));
|
|
1498
|
+
}
|
|
1499
|
+
async getChain(chainId) {
|
|
1500
|
+
const parsedChainId = Number(chainId);
|
|
1501
|
+
validateChainId(parsedChainId);
|
|
1502
|
+
return executeGenerated(getChain({
|
|
1503
|
+
client: this.client,
|
|
1504
|
+
headers: this.headers,
|
|
1505
|
+
path: { chainId: parsedChainId },
|
|
1506
|
+
throwOnError: true
|
|
1507
|
+
}));
|
|
1508
|
+
}
|
|
1509
|
+
async getTokens(chainId) {
|
|
1510
|
+
const parsedChainId = chainId !== undefined ? Number(chainId) : undefined;
|
|
1511
|
+
if (parsedChainId !== undefined)
|
|
1512
|
+
validateChainId(parsedChainId);
|
|
1513
|
+
return executeGenerated(getTokens({
|
|
1514
|
+
client: this.client,
|
|
1515
|
+
headers: this.headers,
|
|
1516
|
+
query: parsedChainId !== undefined ? { chainId: parsedChainId } : undefined,
|
|
1517
|
+
throwOnError: true
|
|
1518
|
+
}));
|
|
1519
|
+
}
|
|
1520
|
+
async getToken(chainId, address) {
|
|
1521
|
+
const parsedChainId = Number(chainId);
|
|
1522
|
+
validateChainId(parsedChainId);
|
|
1523
|
+
return executeGenerated(getToken({
|
|
1524
|
+
client: this.client,
|
|
1525
|
+
headers: this.headers,
|
|
1526
|
+
path: { address, chainId: parsedChainId },
|
|
1527
|
+
throwOnError: true
|
|
1528
|
+
}));
|
|
1529
|
+
}
|
|
1530
|
+
async searchTokens(symbol, chainId) {
|
|
1531
|
+
const parsedChainId = Number(chainId);
|
|
1532
|
+
validateChainId(parsedChainId);
|
|
1533
|
+
return executeGenerated(searchTokens({
|
|
1534
|
+
client: this.client,
|
|
1535
|
+
headers: this.headers,
|
|
1536
|
+
query: {
|
|
1537
|
+
chainId: parsedChainId,
|
|
1538
|
+
symbol
|
|
1539
|
+
},
|
|
1540
|
+
throwOnError: true
|
|
1541
|
+
}));
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
// src/multisender.ts
|
|
1546
|
+
class Multisender {
|
|
1547
|
+
distributions;
|
|
1548
|
+
lists;
|
|
1549
|
+
project;
|
|
1550
|
+
catalogs;
|
|
1551
|
+
client;
|
|
1552
|
+
authHeaders;
|
|
1553
|
+
constructor(config) {
|
|
1554
|
+
validateApiKey(config.apiKey);
|
|
1555
|
+
const resolvedConfig = {
|
|
1556
|
+
baseUrl: config.baseUrl || "https://api.multisender.app",
|
|
1557
|
+
apiKey: config.apiKey,
|
|
1558
|
+
timeout: config.timeout,
|
|
1559
|
+
headers: config.headers
|
|
1560
|
+
};
|
|
1561
|
+
this.client = createClient(setRuntimeConfig(resolvedConfig));
|
|
1562
|
+
this.authHeaders = { "X-API-Key": config.apiKey };
|
|
1563
|
+
this.client.interceptors.error.use((error, response) => {
|
|
1564
|
+
if (!response) {
|
|
1565
|
+
return error;
|
|
1566
|
+
}
|
|
1567
|
+
return {
|
|
1568
|
+
body: error,
|
|
1569
|
+
status: response.status
|
|
1570
|
+
};
|
|
1571
|
+
});
|
|
1572
|
+
this.distributions = new DistributionsService(this.authHeaders, this.client);
|
|
1573
|
+
this.lists = new ListsService(this.authHeaders, this.client);
|
|
1574
|
+
this.project = new ProjectService(this.authHeaders, this.client);
|
|
1575
|
+
this.catalogs = new CatalogsService(this.authHeaders, this.client);
|
|
1576
|
+
}
|
|
1577
|
+
static getVersion() {
|
|
1578
|
+
return "1.0.0";
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
// src/utils/csv.ts
|
|
1582
|
+
function parseCsv(csvData, options = {}) {
|
|
1583
|
+
const { delimiter = ",", skipRows = 0, hasHeader = true } = options;
|
|
1584
|
+
const lines = csvData.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
1585
|
+
if (lines.length === 0) {
|
|
1586
|
+
throw new ValidationError("CSV data is empty");
|
|
1587
|
+
}
|
|
1588
|
+
let startIndex = skipRows;
|
|
1589
|
+
if (hasHeader) {
|
|
1590
|
+
startIndex += 1;
|
|
1591
|
+
}
|
|
1592
|
+
const recipients = [];
|
|
1593
|
+
for (let i = startIndex;i < lines.length; i++) {
|
|
1594
|
+
const line = lines[i];
|
|
1595
|
+
const parts = line.split(delimiter).map((p) => p.trim());
|
|
1596
|
+
if (parts.length < 2) {
|
|
1597
|
+
throw new ValidationError(`Invalid CSV format at line ${i + 1}: expected at least 2 columns`);
|
|
1598
|
+
}
|
|
1599
|
+
const [address, amount] = parts;
|
|
1600
|
+
if (!address || !amount) {
|
|
1601
|
+
throw new ValidationError(`Invalid CSV format at line ${i + 1}: address and amount are required`);
|
|
1602
|
+
}
|
|
1603
|
+
recipients.push([address, amount]);
|
|
1604
|
+
}
|
|
1605
|
+
if (recipients.length === 0) {
|
|
1606
|
+
throw new ValidationError("CSV must contain at least one recipient");
|
|
1607
|
+
}
|
|
1608
|
+
return recipients;
|
|
1609
|
+
}
|
|
1610
|
+
function toCsv(recipients, includeHeader = true) {
|
|
1611
|
+
const lines = [];
|
|
1612
|
+
if (includeHeader) {
|
|
1613
|
+
lines.push("address,amount");
|
|
1614
|
+
}
|
|
1615
|
+
for (const [address, amount] of recipients) {
|
|
1616
|
+
lines.push(`${address},${amount}`);
|
|
1617
|
+
}
|
|
1618
|
+
return lines.join(`
|
|
1619
|
+
`);
|
|
1620
|
+
}
|
|
1621
|
+
function validateCsv(csvData, options = {}) {
|
|
1622
|
+
try {
|
|
1623
|
+
parseCsv(csvData, options);
|
|
1624
|
+
return true;
|
|
1625
|
+
} catch {
|
|
1626
|
+
return false;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
export {
|
|
1630
|
+
validateTokenAddress,
|
|
1631
|
+
validateRecipients,
|
|
1632
|
+
validatePositiveNumber,
|
|
1633
|
+
validateEthereumAddress,
|
|
1634
|
+
validateCsv,
|
|
1635
|
+
validateChainId,
|
|
1636
|
+
validateApiKey,
|
|
1637
|
+
toCsv,
|
|
1638
|
+
parseCsv,
|
|
1639
|
+
ValidationError,
|
|
1640
|
+
TimeoutError,
|
|
1641
|
+
ProjectService,
|
|
1642
|
+
NetworkError,
|
|
1643
|
+
MultisenderError,
|
|
1644
|
+
Multisender,
|
|
1645
|
+
ListsService,
|
|
1646
|
+
DistributionsService,
|
|
1647
|
+
CatalogsService,
|
|
1648
|
+
ApiError
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
//# debugId=0DD1B541289610CC64756E2164756E21
|