@multisender.app/multisender-sdk 0.0.1 → 0.0.3

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,
@@ -1098,6 +1131,14 @@ var createDistributionList = (options) => (options.client ?? client).post({
1098
1131
  ...options.headers
1099
1132
  }
1100
1133
  });
1134
+ var validateDistributionRecipients = (options) => (options.client ?? client).post({
1135
+ url: "/api/v1/lists/distribution/validate",
1136
+ ...options,
1137
+ headers: {
1138
+ "Content-Type": "application/json",
1139
+ ...options.headers
1140
+ }
1141
+ });
1101
1142
  var importCsvDistribution = (options) => (options.client ?? client).post({
1102
1143
  url: "/api/v1/lists/distribution/csv",
1103
1144
  ...options,
@@ -1115,10 +1156,51 @@ var distribute = (options) => (options.client ?? client).post({
1115
1156
  }
1116
1157
  });
1117
1158
  var findAll2 = (options) => (options.client ?? client).get({ url: "/api/v1/distributions", ...options });
1159
+ var create2 = (options) => (options.client ?? client).post({
1160
+ url: "/api/v1/distributions",
1161
+ ...options,
1162
+ headers: {
1163
+ "Content-Type": "application/json",
1164
+ ...options.headers
1165
+ }
1166
+ });
1118
1167
  var findOne2 = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}", ...options });
1168
+ var update2 = (options) => (options.client ?? client).patch({
1169
+ url: "/api/v1/distributions/{id}",
1170
+ ...options,
1171
+ headers: {
1172
+ "Content-Type": "application/json",
1173
+ ...options.headers
1174
+ }
1175
+ });
1176
+ var updateRecipients = (options) => (options.client ?? client).patch({
1177
+ url: "/api/v1/distributions/{id}/recipients",
1178
+ ...options,
1179
+ headers: {
1180
+ "Content-Type": "application/json",
1181
+ ...options.headers
1182
+ }
1183
+ });
1184
+ var prepareTransactions = (options) => (options.client ?? client).post({
1185
+ url: "/api/v1/distributions/{id}/prepare",
1186
+ ...options,
1187
+ headers: {
1188
+ "Content-Type": "application/json",
1189
+ ...options.headers
1190
+ }
1191
+ });
1119
1192
  var getTransactions = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/transactions", ...options });
1120
1193
  var getStats = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/stats", ...options });
1121
1194
  var cancel = (options) => (options.client ?? client).post({ url: "/api/v1/distributions/{id}/cancel", ...options });
1195
+ var getApproveCalldata = (options) => (options.client ?? client).post({
1196
+ url: "/api/v1/approve-calldata",
1197
+ ...options,
1198
+ headers: {
1199
+ "Content-Type": "application/json",
1200
+ ...options.headers
1201
+ }
1202
+ });
1203
+ var getApproveCalldataForDistribution = (options) => (options.client ?? client).get({ url: "/api/v1/distributions/{id}/approve-calldata", ...options });
1122
1204
  var getChains = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/chains", ...options });
1123
1205
  var getChain = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/chains/{chainId}", ...options });
1124
1206
  var getTokens = (options) => (options.client ?? client).get({ url: "/api/v1/catalogs/tokens", ...options });
@@ -1139,21 +1221,36 @@ function unwrapDistribution(result) {
1139
1221
  return raw.distribution;
1140
1222
  return result;
1141
1223
  }
1224
+ function unwrapDistributeResult(result) {
1225
+ const raw = result;
1226
+ if (raw?.data != null)
1227
+ return raw.data;
1228
+ return result;
1229
+ }
1230
+ function unwrapDistributionList(result) {
1231
+ if (result?.list == null) {
1232
+ throw new Error("API response missing list");
1233
+ }
1234
+ return result.list;
1235
+ }
1142
1236
  function normalizePaginatedResponse(result, page, limit) {
1143
1237
  const raw = result;
1144
1238
  if ("meta" in raw && raw.meta != null && Array.isArray(raw.data)) {
1145
1239
  return raw;
1146
1240
  }
1147
- const inner = raw.data && typeof raw.data === "object" && "data" in raw.data ? raw.data : null;
1241
+ 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
1242
  const items = inner && Array.isArray(inner.data) ? inner.data : [];
1149
1243
  const total = inner && typeof inner.total === "number" ? inner.total : items.length;
1244
+ const resolvedPage = inner && typeof inner.page === "number" ? inner.page : page;
1245
+ const resolvedLimit = inner && typeof inner.limit === "number" ? inner.limit : limit;
1246
+ const resolvedTotalPages = inner && typeof inner.totalPages === "number" ? inner.totalPages : Math.ceil(total / resolvedLimit) || 1;
1150
1247
  return {
1151
1248
  data: items,
1152
1249
  meta: {
1153
- page,
1154
- limit,
1250
+ page: resolvedPage,
1251
+ limit: resolvedLimit,
1155
1252
  total,
1156
- totalPages: Math.ceil(total / limit) || 1
1253
+ totalPages: resolvedTotalPages
1157
1254
  }
1158
1255
  };
1159
1256
  }
@@ -1167,13 +1264,74 @@ class DistributionsService {
1167
1264
  this.client = client2;
1168
1265
  }
1169
1266
  async distribute(request) {
1267
+ const result = await this.distributeDetailed(request);
1268
+ return unwrapDistribution(result);
1269
+ }
1270
+ async distributeDetailed(request) {
1170
1271
  const result = await executeGenerated(distribute({
1171
1272
  body: request,
1172
1273
  client: this.client,
1173
1274
  headers: this.headers,
1174
1275
  throwOnError: true
1175
1276
  }));
1176
- return unwrapDistribution(result);
1277
+ return unwrapDistributeResult(result);
1278
+ }
1279
+ async createDraft(request) {
1280
+ const result = await executeGenerated(create2({
1281
+ body: request,
1282
+ client: this.client,
1283
+ headers: this.headers,
1284
+ throwOnError: true
1285
+ }));
1286
+ return unwrapData(result);
1287
+ }
1288
+ async updateDraft(id, request) {
1289
+ const result = await executeGenerated(update2({
1290
+ body: request,
1291
+ client: this.client,
1292
+ headers: this.headers,
1293
+ path: { id },
1294
+ throwOnError: true
1295
+ }));
1296
+ return unwrapData(result);
1297
+ }
1298
+ async replaceRecipients(id, request) {
1299
+ const result = await executeGenerated(updateRecipients({
1300
+ body: request,
1301
+ client: this.client,
1302
+ headers: this.headers,
1303
+ path: { id },
1304
+ throwOnError: true
1305
+ }));
1306
+ return unwrapData(result);
1307
+ }
1308
+ async prepare(id, request) {
1309
+ const result = await executeGenerated(prepareTransactions({
1310
+ body: request,
1311
+ client: this.client,
1312
+ headers: this.headers,
1313
+ path: { id },
1314
+ throwOnError: true
1315
+ }));
1316
+ return unwrapData(result);
1317
+ }
1318
+ async getApproveCalldata(request) {
1319
+ const result = await executeGenerated(getApproveCalldata({
1320
+ body: request,
1321
+ client: this.client,
1322
+ headers: this.headers,
1323
+ throwOnError: true
1324
+ }));
1325
+ return unwrapData(result);
1326
+ }
1327
+ async getApproveCalldataForDistribution(id) {
1328
+ const result = await executeGenerated(getApproveCalldataForDistribution({
1329
+ client: this.client,
1330
+ headers: this.headers,
1331
+ path: { id },
1332
+ throwOnError: true
1333
+ }));
1334
+ return unwrapData(result);
1177
1335
  }
1178
1336
  async list(params) {
1179
1337
  const query = buildPaginationQuery(params);
@@ -1185,7 +1343,7 @@ class DistributionsService {
1185
1343
  query,
1186
1344
  throwOnError: true
1187
1345
  }));
1188
- return normalizePaginatedResponse(result, page, limit);
1346
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1189
1347
  }
1190
1348
  async get(id) {
1191
1349
  const result = await executeGenerated(findOne2({
@@ -1207,7 +1365,7 @@ class DistributionsService {
1207
1365
  query,
1208
1366
  throwOnError: true
1209
1367
  }));
1210
- return normalizePaginatedResponse(result, page, limit);
1368
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1211
1369
  }
1212
1370
  async getStats(id) {
1213
1371
  const result = await executeGenerated(getStats({
@@ -1230,6 +1388,17 @@ class DistributionsService {
1230
1388
  }
1231
1389
 
1232
1390
  // src/services/lists.ts
1391
+ var createImportFormData = (file) => {
1392
+ const formData = new FormData;
1393
+ if (file instanceof Buffer) {
1394
+ formData.append("file", new Blob([new Uint8Array(file)]), "import.csv");
1395
+ return formData;
1396
+ }
1397
+ const browserFile = file;
1398
+ formData.append("file", browserFile, browserFile.name);
1399
+ return formData;
1400
+ };
1401
+
1233
1402
  class ListsService {
1234
1403
  headers;
1235
1404
  client;
@@ -1247,7 +1416,7 @@ class ListsService {
1247
1416
  query,
1248
1417
  throwOnError: true
1249
1418
  }));
1250
- return normalizePaginatedResponse(result, page, limit);
1419
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1251
1420
  }
1252
1421
  async create(request) {
1253
1422
  const result = await executeGenerated(create({
@@ -1278,12 +1447,16 @@ class ListsService {
1278
1447
  return unwrapData(result);
1279
1448
  }
1280
1449
  async delete(listId) {
1281
- await executeGenerated(remove({
1450
+ await this.deleteDetailed(listId);
1451
+ }
1452
+ async deleteDetailed(listId) {
1453
+ const result = await executeGenerated(remove({
1282
1454
  client: this.client,
1283
1455
  headers: this.headers,
1284
1456
  path: { listId },
1285
1457
  throwOnError: true
1286
1458
  }));
1459
+ return unwrapData(result);
1287
1460
  }
1288
1461
  async getRecipients(listId, params) {
1289
1462
  const query = buildPaginationQuery(params);
@@ -1296,7 +1469,7 @@ class ListsService {
1296
1469
  query,
1297
1470
  throwOnError: true
1298
1471
  }));
1299
- return normalizePaginatedResponse(result, page, limit);
1472
+ return normalizePaginatedResponse(unwrapData(result), page, limit);
1300
1473
  }
1301
1474
  async addRecipient(listId, request) {
1302
1475
  const result = await executeGenerated(addRecipient({
@@ -1316,31 +1489,25 @@ class ListsService {
1316
1489
  path: { listId },
1317
1490
  throwOnError: true
1318
1491
  }));
1319
- return {
1320
- added: result.added ?? 0,
1321
- skippedAddresses: result.skippedAddresses ?? [],
1322
- errors: result.errors ?? []
1323
- };
1492
+ return unwrapData(result);
1324
1493
  }
1325
1494
  async removeRecipient(listId, recipientId) {
1326
- await executeGenerated(removeRecipient({
1495
+ await this.removeRecipientDetailed(listId, recipientId);
1496
+ }
1497
+ async removeRecipientDetailed(listId, recipientId) {
1498
+ const result = await executeGenerated(removeRecipient({
1327
1499
  client: this.client,
1328
1500
  headers: this.headers,
1329
1501
  path: { listId, recipientId },
1330
1502
  throwOnError: true
1331
1503
  }));
1504
+ return unwrapData(result);
1332
1505
  }
1333
1506
  async importFromCsv(listId, file) {
1334
1507
  if (!file) {
1335
1508
  throw new Error("importFromCsv: file is required");
1336
1509
  }
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
- }
1510
+ const formData = createImportFormData(file);
1344
1511
  const result = await executeGenerated(importFromFile({
1345
1512
  path: { listId },
1346
1513
  body: formData,
@@ -1352,28 +1519,30 @@ class ListsService {
1352
1519
  return unwrapData(result);
1353
1520
  }
1354
1521
  async createDistributionList(request) {
1522
+ const result = await this.createDistributionListDetailed(request);
1523
+ return unwrapDistributionList(result);
1524
+ }
1525
+ async createDistributionListDetailed(request) {
1355
1526
  const result = await executeGenerated(createDistributionList({
1356
1527
  body: request,
1357
1528
  client: this.client,
1358
1529
  headers: this.headers,
1359
1530
  throwOnError: true
1360
1531
  }));
1361
- const raw = unwrapData(result);
1362
- if (raw?.list == null)
1363
- throw new Error("API response missing list");
1364
- return raw.list;
1532
+ return unwrapData(result);
1365
1533
  }
1366
1534
  async importCsvDistribution(request) {
1535
+ const result = await this.importCsvDistributionDetailed(request);
1536
+ return unwrapDistributionList(result);
1537
+ }
1538
+ async importCsvDistributionDetailed(request) {
1367
1539
  const result = await executeGenerated(importCsvDistribution({
1368
1540
  body: request,
1369
1541
  client: this.client,
1370
1542
  headers: this.headers,
1371
1543
  throwOnError: true
1372
1544
  }));
1373
- const raw = unwrapData(result);
1374
- if (raw?.list == null)
1375
- throw new Error("API response missing list");
1376
- return raw.list;
1545
+ return unwrapData(result);
1377
1546
  }
1378
1547
  }
1379
1548
 
@@ -1399,8 +1568,7 @@ class ProjectService {
1399
1568
  headers: this.headers,
1400
1569
  throwOnError: true
1401
1570
  }));
1402
- const members = unwrapData(result);
1403
- return Array.isArray(members) ? members : [members];
1571
+ return unwrapData(result);
1404
1572
  }
1405
1573
  async listApiKeys() {
1406
1574
  const result = await executeGenerated(getApiKeys({
@@ -1408,8 +1576,7 @@ class ProjectService {
1408
1576
  headers: this.headers,
1409
1577
  throwOnError: true
1410
1578
  }));
1411
- const data = unwrapData(result);
1412
- return Array.isArray(data) ? data : result;
1579
+ return unwrapData(result);
1413
1580
  }
1414
1581
  async createApiKey(request) {
1415
1582
  const result = await executeGenerated(createApiKey({
@@ -1431,12 +1598,16 @@ class ProjectService {
1431
1598
  return unwrapData(result);
1432
1599
  }
1433
1600
  async deleteApiKey(apiKeyId) {
1434
- await executeGenerated(deleteApiKey({
1601
+ await this.deleteApiKeyDetailed(apiKeyId);
1602
+ }
1603
+ async deleteApiKeyDetailed(apiKeyId) {
1604
+ const result = await executeGenerated(deleteApiKey({
1435
1605
  client: this.client,
1436
1606
  headers: this.headers,
1437
1607
  path: { apiKeyId },
1438
1608
  throwOnError: true
1439
1609
  }));
1610
+ return unwrapData(result);
1440
1611
  }
1441
1612
  }
1442
1613
 
@@ -1528,14 +1699,15 @@ class CatalogsService {
1528
1699
  }));
1529
1700
  }
1530
1701
  async searchTokens(symbol, chainId) {
1531
- const parsedChainId = Number(chainId);
1532
- validateChainId(parsedChainId);
1702
+ const parsedChainId = chainId !== undefined ? Number(chainId) : undefined;
1703
+ if (parsedChainId !== undefined)
1704
+ validateChainId(parsedChainId);
1533
1705
  return executeGenerated(searchTokens({
1534
1706
  client: this.client,
1535
1707
  headers: this.headers,
1536
1708
  query: {
1537
- chainId: parsedChainId,
1538
- symbol
1709
+ symbol,
1710
+ ...parsedChainId !== undefined ? { chainId: parsedChainId } : {}
1539
1711
  },
1540
1712
  throwOnError: true
1541
1713
  }));
@@ -1648,4 +1820,4 @@ export {
1648
1820
  ApiError
1649
1821
  };
1650
1822
 
1651
- //# debugId=0DD1B541289610CC64756E2164756E21
1823
+ //# debugId=8D95037D2CD3081F64756E2164756E21