@multisender.app/multisender-sdk 0.0.1 → 0.0.2

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/dist/index.js CHANGED
@@ -70,6 +70,31 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
70
70
  });
71
71
 
72
72
  // src/gen/core/bodySerializer.gen.ts
73
+ var serializeFormDataPair = (data, key, value) => {
74
+ if (typeof value === "string" || value instanceof Blob) {
75
+ data.append(key, value);
76
+ } else if (value instanceof Date) {
77
+ data.append(key, value.toISOString());
78
+ } else {
79
+ data.append(key, JSON.stringify(value));
80
+ }
81
+ };
82
+ var formDataBodySerializer = {
83
+ bodySerializer: (body) => {
84
+ const data = new FormData;
85
+ Object.entries(body).forEach(([key, value]) => {
86
+ if (value === undefined || value === null) {
87
+ return;
88
+ }
89
+ if (Array.isArray(value)) {
90
+ value.forEach((v) => serializeFormDataPair(data, key, v));
91
+ } else {
92
+ serializeFormDataPair(data, key, value);
93
+ }
94
+ });
95
+ return data;
96
+ }
97
+ };
73
98
  var jsonBodySerializer = {
74
99
  bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
75
100
  };
@@ -1089,7 +1114,15 @@ var addRecipientsBulk = (options) => (options.client ?? client).post({
1089
1114
  }
1090
1115
  });
1091
1116
  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 });
1117
+ var importFromFile = (options) => (options.client ?? client).post({
1118
+ ...formDataBodySerializer,
1119
+ url: "/api/v1/lists/{listId}/import",
1120
+ ...options,
1121
+ headers: {
1122
+ "Content-Type": null,
1123
+ ...options.headers
1124
+ }
1125
+ });
1093
1126
  var createDistributionList = (options) => (options.client ?? client).post({
1094
1127
  url: "/api/v1/lists/distribution",
1095
1128
  ...options,
@@ -1115,10 +1148,51 @@ var distribute = (options) => (options.client ?? client).post({
1115
1148
  }
1116
1149
  });
1117
1150
  var findAll2 = (options) => (options.client ?? client).get({ url: "/api/v1/distributions", ...options });
1151
+ var create2 = (options) => (options.client ?? client).post({
1152
+ url: "/api/v1/distributions",
1153
+ ...options,
1154
+ headers: {
1155
+ "Content-Type": "application/json",
1156
+ ...options.headers
1157
+ }
1158
+ });
1118
1159
  var findOne2 = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}", ...options });
1160
+ var update2 = (options) => (options.client ?? client).patch({
1161
+ url: "/api/v1/distributions/{id}",
1162
+ ...options,
1163
+ headers: {
1164
+ "Content-Type": "application/json",
1165
+ ...options.headers
1166
+ }
1167
+ });
1168
+ var updateRecipients = (options) => (options.client ?? client).patch({
1169
+ url: "/api/v1/distributions/{id}/recipients",
1170
+ ...options,
1171
+ headers: {
1172
+ "Content-Type": "application/json",
1173
+ ...options.headers
1174
+ }
1175
+ });
1176
+ var prepareTransactions = (options) => (options.client ?? client).post({
1177
+ url: "/api/v1/distributions/{id}/prepare",
1178
+ ...options,
1179
+ headers: {
1180
+ "Content-Type": "application/json",
1181
+ ...options.headers
1182
+ }
1183
+ });
1119
1184
  var getTransactions = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/transactions", ...options });
1120
1185
  var getStats = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/stats", ...options });
1121
1186
  var cancel = (options) => (options.client ?? client).post({ url: "/api/v1/distributions/{id}/cancel", ...options });
1187
+ var getApproveCalldata = (options) => (options.client ?? client).post({
1188
+ url: "/api/v1/approve-calldata",
1189
+ ...options,
1190
+ headers: {
1191
+ "Content-Type": "application/json",
1192
+ ...options.headers
1193
+ }
1194
+ });
1195
+ var getApproveCalldataForDistribution = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/approve-calldata", ...options });
1122
1196
  var getChains = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/chains", ...options });
1123
1197
  var getChain = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/chains/{chainId}", ...options });
1124
1198
  var getTokens = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/tokens", ...options });
@@ -1139,21 +1213,36 @@ function unwrapDistribution(result) {
1139
1213
  return raw.distribution;
1140
1214
  return result;
1141
1215
  }
1216
+ function unwrapDistributeResult(result) {
1217
+ const raw = result;
1218
+ if (raw?.data != null)
1219
+ return raw.data;
1220
+ return result;
1221
+ }
1222
+ function unwrapDistributionList(result) {
1223
+ if (result?.list == null) {
1224
+ throw new Error("API response missing list");
1225
+ }
1226
+ return result.list;
1227
+ }
1142
1228
  function normalizePaginatedResponse(result, page, limit) {
1143
1229
  const raw = result;
1144
1230
  if ("meta" in raw && raw.meta != null && Array.isArray(raw.data)) {
1145
1231
  return raw;
1146
1232
  }
1147
- const inner = raw.data && typeof raw.data === "object" && "data" in raw.data ? raw.data : null;
1233
+ const inner = raw.data && typeof raw.data === "object" && !Array.isArray(raw.data) && "data" in raw.data ? raw.data : Array.isArray(raw.data) ? raw : null;
1148
1234
  const items = inner && Array.isArray(inner.data) ? inner.data : [];
1149
1235
  const total = inner && typeof inner.total === "number" ? inner.total : items.length;
1236
+ const resolvedPage = inner && typeof inner.page === "number" ? inner.page : page;
1237
+ const resolvedLimit = inner && typeof inner.limit === "number" ? inner.limit : limit;
1238
+ const resolvedTotalPages = inner && typeof inner.totalPages === "number" ? inner.totalPages : Math.ceil(total / resolvedLimit) || 1;
1150
1239
  return {
1151
1240
  data: items,
1152
1241
  meta: {
1153
- page,
1154
- limit,
1242
+ page: resolvedPage,
1243
+ limit: resolvedLimit,
1155
1244
  total,
1156
- totalPages: Math.ceil(total / limit) || 1
1245
+ totalPages: resolvedTotalPages
1157
1246
  }
1158
1247
  };
1159
1248
  }
@@ -1167,13 +1256,74 @@ class DistributionsService {
1167
1256
  this.client = client2;
1168
1257
  }
1169
1258
  async distribute(request) {
1259
+ const result = await this.distributeDetailed(request);
1260
+ return unwrapDistribution(result);
1261
+ }
1262
+ async distributeDetailed(request) {
1170
1263
  const result = await executeGenerated(distribute({
1171
1264
  body: request,
1172
1265
  client: this.client,
1173
1266
  headers: this.headers,
1174
1267
  throwOnError: true
1175
1268
  }));
1176
- return unwrapDistribution(result);
1269
+ return unwrapDistributeResult(result);
1270
+ }
1271
+ async createDraft(request) {
1272
+ const result = await executeGenerated(create2({
1273
+ body: request,
1274
+ client: this.client,
1275
+ headers: this.headers,
1276
+ throwOnError: true
1277
+ }));
1278
+ return unwrapData(result);
1279
+ }
1280
+ async updateDraft(id, request) {
1281
+ const result = await executeGenerated(update2({
1282
+ body: request,
1283
+ client: this.client,
1284
+ headers: this.headers,
1285
+ path: { id },
1286
+ throwOnError: true
1287
+ }));
1288
+ return unwrapData(result);
1289
+ }
1290
+ async replaceRecipients(id, request) {
1291
+ const result = await executeGenerated(updateRecipients({
1292
+ body: request,
1293
+ client: this.client,
1294
+ headers: this.headers,
1295
+ path: { id },
1296
+ throwOnError: true
1297
+ }));
1298
+ return unwrapData(result);
1299
+ }
1300
+ async prepare(id, request) {
1301
+ const result = await executeGenerated(prepareTransactions({
1302
+ body: request,
1303
+ client: this.client,
1304
+ headers: this.headers,
1305
+ path: { id },
1306
+ throwOnError: true
1307
+ }));
1308
+ return unwrapData(result);
1309
+ }
1310
+ async getApproveCalldata(request) {
1311
+ const result = await executeGenerated(getApproveCalldata({
1312
+ body: request,
1313
+ client: this.client,
1314
+ headers: this.headers,
1315
+ throwOnError: true
1316
+ }));
1317
+ return unwrapData(result);
1318
+ }
1319
+ async getApproveCalldataForDistribution(id) {
1320
+ const result = await executeGenerated(getApproveCalldataForDistribution({
1321
+ client: this.client,
1322
+ headers: this.headers,
1323
+ path: { id },
1324
+ throwOnError: true
1325
+ }));
1326
+ return unwrapData(result);
1177
1327
  }
1178
1328
  async list(params) {
1179
1329
  const query = buildPaginationQuery(params);
@@ -1185,7 +1335,7 @@ class DistributionsService {
1185
1335
  query,
1186
1336
  throwOnError: true
1187
1337
  }));
1188
- return normalizePaginatedResponse(result, page, limit);
1338
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1189
1339
  }
1190
1340
  async get(id) {
1191
1341
  const result = await executeGenerated(findOne2({
@@ -1207,7 +1357,7 @@ class DistributionsService {
1207
1357
  query,
1208
1358
  throwOnError: true
1209
1359
  }));
1210
- return normalizePaginatedResponse(result, page, limit);
1360
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1211
1361
  }
1212
1362
  async getStats(id) {
1213
1363
  const result = await executeGenerated(getStats({
@@ -1230,6 +1380,17 @@ class DistributionsService {
1230
1380
  }
1231
1381
 
1232
1382
  // src/services/lists.ts
1383
+ var createImportFormData = (file) => {
1384
+ const formData = new FormData;
1385
+ if (file instanceof Buffer) {
1386
+ formData.append("file", new Blob([new Uint8Array(file)]), "import.csv");
1387
+ return formData;
1388
+ }
1389
+ const browserFile = file;
1390
+ formData.append("file", browserFile, browserFile.name);
1391
+ return formData;
1392
+ };
1393
+
1233
1394
  class ListsService {
1234
1395
  headers;
1235
1396
  client;
@@ -1247,7 +1408,7 @@ class ListsService {
1247
1408
  query,
1248
1409
  throwOnError: true
1249
1410
  }));
1250
- return normalizePaginatedResponse(result, page, limit);
1411
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1251
1412
  }
1252
1413
  async create(request) {
1253
1414
  const result = await executeGenerated(create({
@@ -1278,12 +1439,16 @@ class ListsService {
1278
1439
  return unwrapData(result);
1279
1440
  }
1280
1441
  async delete(listId) {
1281
- await executeGenerated(remove({
1442
+ await this.deleteDetailed(listId);
1443
+ }
1444
+ async deleteDetailed(listId) {
1445
+ const result = await executeGenerated(remove({
1282
1446
  client: this.client,
1283
1447
  headers: this.headers,
1284
1448
  path: { listId },
1285
1449
  throwOnError: true
1286
1450
  }));
1451
+ return unwrapData(result);
1287
1452
  }
1288
1453
  async getRecipients(listId, params) {
1289
1454
  const query = buildPaginationQuery(params);
@@ -1296,7 +1461,7 @@ class ListsService {
1296
1461
  query,
1297
1462
  throwOnError: true
1298
1463
  }));
1299
- return normalizePaginatedResponse(result, page, limit);
1464
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1300
1465
  }
1301
1466
  async addRecipient(listId, request) {
1302
1467
  const result = await executeGenerated(addRecipient({
@@ -1316,31 +1481,25 @@ class ListsService {
1316
1481
  path: { listId },
1317
1482
  throwOnError: true
1318
1483
  }));
1319
- return {
1320
- added: result.added ?? 0,
1321
- skippedAddresses: result.skippedAddresses ?? [],
1322
- errors: result.errors ?? []
1323
- };
1484
+ return unwrapData(result);
1324
1485
  }
1325
1486
  async removeRecipient(listId, recipientId) {
1326
- await executeGenerated(removeRecipient({
1487
+ await this.removeRecipientDetailed(listId, recipientId);
1488
+ }
1489
+ async removeRecipientDetailed(listId, recipientId) {
1490
+ const result = await executeGenerated(removeRecipient({
1327
1491
  client: this.client,
1328
1492
  headers: this.headers,
1329
1493
  path: { listId, recipientId },
1330
1494
  throwOnError: true
1331
1495
  }));
1496
+ return unwrapData(result);
1332
1497
  }
1333
1498
  async importFromCsv(listId, file) {
1334
1499
  if (!file) {
1335
1500
  throw new Error("importFromCsv: file is required");
1336
1501
  }
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
- }
1502
+ const formData = createImportFormData(file);
1344
1503
  const result = await executeGenerated(importFromFile({
1345
1504
  path: { listId },
1346
1505
  body: formData,
@@ -1352,28 +1511,30 @@ class ListsService {
1352
1511
  return unwrapData(result);
1353
1512
  }
1354
1513
  async createDistributionList(request) {
1514
+ const result = await this.createDistributionListDetailed(request);
1515
+ return unwrapDistributionList(result);
1516
+ }
1517
+ async createDistributionListDetailed(request) {
1355
1518
  const result = await executeGenerated(createDistributionList({
1356
1519
  body: request,
1357
1520
  client: this.client,
1358
1521
  headers: this.headers,
1359
1522
  throwOnError: true
1360
1523
  }));
1361
- const raw = unwrapData(result);
1362
- if (raw?.list == null)
1363
- throw new Error("API response missing list");
1364
- return raw.list;
1524
+ return unwrapData(result);
1365
1525
  }
1366
1526
  async importCsvDistribution(request) {
1527
+ const result = await this.importCsvDistributionDetailed(request);
1528
+ return unwrapDistributionList(result);
1529
+ }
1530
+ async importCsvDistributionDetailed(request) {
1367
1531
  const result = await executeGenerated(importCsvDistribution({
1368
1532
  body: request,
1369
1533
  client: this.client,
1370
1534
  headers: this.headers,
1371
1535
  throwOnError: true
1372
1536
  }));
1373
- const raw = unwrapData(result);
1374
- if (raw?.list == null)
1375
- throw new Error("API response missing list");
1376
- return raw.list;
1537
+ return unwrapData(result);
1377
1538
  }
1378
1539
  }
1379
1540
 
@@ -1399,8 +1560,7 @@ class ProjectService {
1399
1560
  headers: this.headers,
1400
1561
  throwOnError: true
1401
1562
  }));
1402
- const members = unwrapData(result);
1403
- return Array.isArray(members) ? members : [members];
1563
+ return unwrapData(result);
1404
1564
  }
1405
1565
  async listApiKeys() {
1406
1566
  const result = await executeGenerated(getApiKeys({
@@ -1408,8 +1568,7 @@ class ProjectService {
1408
1568
  headers: this.headers,
1409
1569
  throwOnError: true
1410
1570
  }));
1411
- const data = unwrapData(result);
1412
- return Array.isArray(data) ? data : result;
1571
+ return unwrapData(result);
1413
1572
  }
1414
1573
  async createApiKey(request) {
1415
1574
  const result = await executeGenerated(createApiKey({
@@ -1431,12 +1590,16 @@ class ProjectService {
1431
1590
  return unwrapData(result);
1432
1591
  }
1433
1592
  async deleteApiKey(apiKeyId) {
1434
- await executeGenerated(deleteApiKey({
1593
+ await this.deleteApiKeyDetailed(apiKeyId);
1594
+ }
1595
+ async deleteApiKeyDetailed(apiKeyId) {
1596
+ const result = await executeGenerated(deleteApiKey({
1435
1597
  client: this.client,
1436
1598
  headers: this.headers,
1437
1599
  path: { apiKeyId },
1438
1600
  throwOnError: true
1439
1601
  }));
1602
+ return unwrapData(result);
1440
1603
  }
1441
1604
  }
1442
1605
 
@@ -1528,14 +1691,15 @@ class CatalogsService {
1528
1691
  }));
1529
1692
  }
1530
1693
  async searchTokens(symbol, chainId) {
1531
- const parsedChainId = Number(chainId);
1532
- validateChainId(parsedChainId);
1694
+ const parsedChainId = chainId !== undefined ? Number(chainId) : undefined;
1695
+ if (parsedChainId !== undefined)
1696
+ validateChainId(parsedChainId);
1533
1697
  return executeGenerated(searchTokens({
1534
1698
  client: this.client,
1535
1699
  headers: this.headers,
1536
1700
  query: {
1537
- chainId: parsedChainId,
1538
- symbol
1701
+ symbol,
1702
+ ...parsedChainId !== undefined ? { chainId: parsedChainId } : {}
1539
1703
  },
1540
1704
  throwOnError: true
1541
1705
  }));
@@ -1648,4 +1812,4 @@ export {
1648
1812
  ApiError
1649
1813
  };
1650
1814
 
1651
- //# debugId=0DD1B541289610CC64756E2164756E21
1815
+ //# debugId=923BC22549D237F064756E2164756E21