perspectapi-ts-sdk 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +262 -1
- package/dist/index.d.ts +262 -1
- package/dist/index.js +183 -0
- package/dist/index.mjs +182 -0
- package/package.json +1 -1
- package/src/client/newsletter-client.ts +360 -0
- package/src/index.ts +9 -0
- package/src/perspect-api-client.ts +3 -0
- package/src/types/index.ts +77 -0
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __export(index_exports, {
|
|
|
28
28
|
ContactClient: () => ContactClient,
|
|
29
29
|
ContentClient: () => ContentClient,
|
|
30
30
|
HttpClient: () => HttpClient,
|
|
31
|
+
NewsletterClient: () => NewsletterClient,
|
|
31
32
|
OrganizationsClient: () => OrganizationsClient,
|
|
32
33
|
PerspectApiClient: () => PerspectApiClient,
|
|
33
34
|
ProductsClient: () => ProductsClient,
|
|
@@ -1267,6 +1268,185 @@ var ContactClient = class extends BaseClient {
|
|
|
1267
1268
|
}
|
|
1268
1269
|
};
|
|
1269
1270
|
|
|
1271
|
+
// src/client/newsletter-client.ts
|
|
1272
|
+
var NewsletterClient = class extends BaseClient {
|
|
1273
|
+
constructor(http) {
|
|
1274
|
+
super(http, "/api/v1");
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Build a newsletter endpoint scoped to a site (without /sites prefix)
|
|
1278
|
+
*/
|
|
1279
|
+
newsletterEndpoint(siteName, endpoint) {
|
|
1280
|
+
return this.siteScopedEndpoint(siteName, endpoint, { includeSitesSegment: false });
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Subscribe to newsletter
|
|
1284
|
+
*/
|
|
1285
|
+
async subscribe(siteName, data) {
|
|
1286
|
+
return this.create(
|
|
1287
|
+
this.newsletterEndpoint(siteName, "/newsletter/subscribe"),
|
|
1288
|
+
data
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Confirm newsletter subscription via token
|
|
1293
|
+
*/
|
|
1294
|
+
async confirmSubscription(siteName, token) {
|
|
1295
|
+
return this.getSingle(
|
|
1296
|
+
this.newsletterEndpoint(siteName, `/newsletter/confirm/${encodeURIComponent(token)}`)
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Unsubscribe from newsletter
|
|
1301
|
+
*/
|
|
1302
|
+
async unsubscribe(siteName, data) {
|
|
1303
|
+
return this.create(
|
|
1304
|
+
this.newsletterEndpoint(siteName, "/newsletter/unsubscribe"),
|
|
1305
|
+
data
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* One-click unsubscribe via token (GET request)
|
|
1310
|
+
*/
|
|
1311
|
+
async unsubscribeByToken(siteName, token) {
|
|
1312
|
+
return this.http.get(
|
|
1313
|
+
this.buildPath(this.newsletterEndpoint(siteName, `/newsletter/unsubscribe/${encodeURIComponent(token)}`))
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Update subscription preferences
|
|
1318
|
+
*/
|
|
1319
|
+
async updatePreferences(siteName, email, preferences) {
|
|
1320
|
+
return this.patch(
|
|
1321
|
+
this.newsletterEndpoint(siteName, "/newsletter/preferences"),
|
|
1322
|
+
{ email, ...preferences }
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Get available newsletter lists
|
|
1327
|
+
*/
|
|
1328
|
+
async getLists(siteName) {
|
|
1329
|
+
return this.getSingle(
|
|
1330
|
+
this.newsletterEndpoint(siteName, "/newsletter/lists")
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Check subscription status by email
|
|
1335
|
+
*/
|
|
1336
|
+
async getStatus(siteName, email) {
|
|
1337
|
+
return this.http.get(
|
|
1338
|
+
this.buildPath(this.newsletterEndpoint(siteName, "/newsletter/status")),
|
|
1339
|
+
{ email }
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
// Admin methods (require authentication)
|
|
1343
|
+
/**
|
|
1344
|
+
* Get all newsletter subscriptions (admin only)
|
|
1345
|
+
*/
|
|
1346
|
+
async getSubscriptions(siteName, params) {
|
|
1347
|
+
return this.getPaginated(
|
|
1348
|
+
this.newsletterEndpoint(siteName, "/newsletter/subscriptions"),
|
|
1349
|
+
params
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Get subscription by ID (admin only)
|
|
1354
|
+
*/
|
|
1355
|
+
async getSubscriptionById(siteName, id) {
|
|
1356
|
+
return this.getSingle(
|
|
1357
|
+
this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
|
|
1358
|
+
);
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Update subscription status (admin only)
|
|
1362
|
+
*/
|
|
1363
|
+
async updateSubscriptionStatus(siteName, id, status, notes) {
|
|
1364
|
+
return this.patch(
|
|
1365
|
+
this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`),
|
|
1366
|
+
{ status, notes }
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Delete subscription (admin only)
|
|
1371
|
+
*/
|
|
1372
|
+
async deleteSubscription(siteName, id) {
|
|
1373
|
+
return this.delete(
|
|
1374
|
+
this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Bulk update subscriptions (admin only)
|
|
1379
|
+
*/
|
|
1380
|
+
async bulkUpdateSubscriptions(siteName, data) {
|
|
1381
|
+
return this.create(
|
|
1382
|
+
this.newsletterEndpoint(siteName, "/newsletter/subscriptions/bulk-update"),
|
|
1383
|
+
data
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Create newsletter list (admin only)
|
|
1388
|
+
*/
|
|
1389
|
+
async createList(siteName, data) {
|
|
1390
|
+
return this.create(
|
|
1391
|
+
this.newsletterEndpoint(siteName, "/newsletter/lists"),
|
|
1392
|
+
data
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Update newsletter list (admin only)
|
|
1397
|
+
*/
|
|
1398
|
+
async updateList(siteName, listId, data) {
|
|
1399
|
+
return this.update(
|
|
1400
|
+
this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`),
|
|
1401
|
+
data
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Delete newsletter list (admin only)
|
|
1406
|
+
*/
|
|
1407
|
+
async deleteList(siteName, listId) {
|
|
1408
|
+
return this.delete(
|
|
1409
|
+
this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`)
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Get newsletter statistics (admin only)
|
|
1414
|
+
*/
|
|
1415
|
+
async getStatistics(siteName, params) {
|
|
1416
|
+
return this.http.get(
|
|
1417
|
+
this.buildPath(this.newsletterEndpoint(siteName, "/newsletter/statistics")),
|
|
1418
|
+
params
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Export newsletter subscriptions (admin only)
|
|
1423
|
+
*/
|
|
1424
|
+
async exportSubscriptions(siteName, params) {
|
|
1425
|
+
return this.create(
|
|
1426
|
+
this.newsletterEndpoint(siteName, "/newsletter/export"),
|
|
1427
|
+
params || {}
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Import newsletter subscriptions (admin only)
|
|
1432
|
+
*/
|
|
1433
|
+
async importSubscriptions(siteName, data) {
|
|
1434
|
+
return this.create(
|
|
1435
|
+
this.newsletterEndpoint(siteName, "/newsletter/import"),
|
|
1436
|
+
data
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Send test newsletter (admin only)
|
|
1441
|
+
*/
|
|
1442
|
+
async sendTestNewsletter(siteName, data) {
|
|
1443
|
+
return this.create(
|
|
1444
|
+
this.newsletterEndpoint(siteName, "/newsletter/test"),
|
|
1445
|
+
data
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1270
1450
|
// src/perspect-api-client.ts
|
|
1271
1451
|
var PerspectApiClient = class {
|
|
1272
1452
|
http;
|
|
@@ -1281,6 +1461,7 @@ var PerspectApiClient = class {
|
|
|
1281
1461
|
webhooks;
|
|
1282
1462
|
checkout;
|
|
1283
1463
|
contact;
|
|
1464
|
+
newsletter;
|
|
1284
1465
|
constructor(config) {
|
|
1285
1466
|
if (!config.baseUrl) {
|
|
1286
1467
|
throw new Error("baseUrl is required in PerspectApiConfig");
|
|
@@ -1296,6 +1477,7 @@ var PerspectApiClient = class {
|
|
|
1296
1477
|
this.webhooks = new WebhooksClient(this.http);
|
|
1297
1478
|
this.checkout = new CheckoutClient(this.http);
|
|
1298
1479
|
this.contact = new ContactClient(this.http);
|
|
1480
|
+
this.newsletter = new NewsletterClient(this.http);
|
|
1299
1481
|
}
|
|
1300
1482
|
/**
|
|
1301
1483
|
* Update authentication token
|
|
@@ -1758,6 +1940,7 @@ async function createCheckoutSession(options) {
|
|
|
1758
1940
|
ContactClient,
|
|
1759
1941
|
ContentClient,
|
|
1760
1942
|
HttpClient,
|
|
1943
|
+
NewsletterClient,
|
|
1761
1944
|
OrganizationsClient,
|
|
1762
1945
|
PerspectApiClient,
|
|
1763
1946
|
ProductsClient,
|
package/dist/index.mjs
CHANGED
|
@@ -1217,6 +1217,185 @@ var ContactClient = class extends BaseClient {
|
|
|
1217
1217
|
}
|
|
1218
1218
|
};
|
|
1219
1219
|
|
|
1220
|
+
// src/client/newsletter-client.ts
|
|
1221
|
+
var NewsletterClient = class extends BaseClient {
|
|
1222
|
+
constructor(http) {
|
|
1223
|
+
super(http, "/api/v1");
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Build a newsletter endpoint scoped to a site (without /sites prefix)
|
|
1227
|
+
*/
|
|
1228
|
+
newsletterEndpoint(siteName, endpoint) {
|
|
1229
|
+
return this.siteScopedEndpoint(siteName, endpoint, { includeSitesSegment: false });
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Subscribe to newsletter
|
|
1233
|
+
*/
|
|
1234
|
+
async subscribe(siteName, data) {
|
|
1235
|
+
return this.create(
|
|
1236
|
+
this.newsletterEndpoint(siteName, "/newsletter/subscribe"),
|
|
1237
|
+
data
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Confirm newsletter subscription via token
|
|
1242
|
+
*/
|
|
1243
|
+
async confirmSubscription(siteName, token) {
|
|
1244
|
+
return this.getSingle(
|
|
1245
|
+
this.newsletterEndpoint(siteName, `/newsletter/confirm/${encodeURIComponent(token)}`)
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Unsubscribe from newsletter
|
|
1250
|
+
*/
|
|
1251
|
+
async unsubscribe(siteName, data) {
|
|
1252
|
+
return this.create(
|
|
1253
|
+
this.newsletterEndpoint(siteName, "/newsletter/unsubscribe"),
|
|
1254
|
+
data
|
|
1255
|
+
);
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* One-click unsubscribe via token (GET request)
|
|
1259
|
+
*/
|
|
1260
|
+
async unsubscribeByToken(siteName, token) {
|
|
1261
|
+
return this.http.get(
|
|
1262
|
+
this.buildPath(this.newsletterEndpoint(siteName, `/newsletter/unsubscribe/${encodeURIComponent(token)}`))
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Update subscription preferences
|
|
1267
|
+
*/
|
|
1268
|
+
async updatePreferences(siteName, email, preferences) {
|
|
1269
|
+
return this.patch(
|
|
1270
|
+
this.newsletterEndpoint(siteName, "/newsletter/preferences"),
|
|
1271
|
+
{ email, ...preferences }
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Get available newsletter lists
|
|
1276
|
+
*/
|
|
1277
|
+
async getLists(siteName) {
|
|
1278
|
+
return this.getSingle(
|
|
1279
|
+
this.newsletterEndpoint(siteName, "/newsletter/lists")
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Check subscription status by email
|
|
1284
|
+
*/
|
|
1285
|
+
async getStatus(siteName, email) {
|
|
1286
|
+
return this.http.get(
|
|
1287
|
+
this.buildPath(this.newsletterEndpoint(siteName, "/newsletter/status")),
|
|
1288
|
+
{ email }
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
// Admin methods (require authentication)
|
|
1292
|
+
/**
|
|
1293
|
+
* Get all newsletter subscriptions (admin only)
|
|
1294
|
+
*/
|
|
1295
|
+
async getSubscriptions(siteName, params) {
|
|
1296
|
+
return this.getPaginated(
|
|
1297
|
+
this.newsletterEndpoint(siteName, "/newsletter/subscriptions"),
|
|
1298
|
+
params
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Get subscription by ID (admin only)
|
|
1303
|
+
*/
|
|
1304
|
+
async getSubscriptionById(siteName, id) {
|
|
1305
|
+
return this.getSingle(
|
|
1306
|
+
this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Update subscription status (admin only)
|
|
1311
|
+
*/
|
|
1312
|
+
async updateSubscriptionStatus(siteName, id, status, notes) {
|
|
1313
|
+
return this.patch(
|
|
1314
|
+
this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`),
|
|
1315
|
+
{ status, notes }
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Delete subscription (admin only)
|
|
1320
|
+
*/
|
|
1321
|
+
async deleteSubscription(siteName, id) {
|
|
1322
|
+
return this.delete(
|
|
1323
|
+
this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Bulk update subscriptions (admin only)
|
|
1328
|
+
*/
|
|
1329
|
+
async bulkUpdateSubscriptions(siteName, data) {
|
|
1330
|
+
return this.create(
|
|
1331
|
+
this.newsletterEndpoint(siteName, "/newsletter/subscriptions/bulk-update"),
|
|
1332
|
+
data
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Create newsletter list (admin only)
|
|
1337
|
+
*/
|
|
1338
|
+
async createList(siteName, data) {
|
|
1339
|
+
return this.create(
|
|
1340
|
+
this.newsletterEndpoint(siteName, "/newsletter/lists"),
|
|
1341
|
+
data
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Update newsletter list (admin only)
|
|
1346
|
+
*/
|
|
1347
|
+
async updateList(siteName, listId, data) {
|
|
1348
|
+
return this.update(
|
|
1349
|
+
this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`),
|
|
1350
|
+
data
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Delete newsletter list (admin only)
|
|
1355
|
+
*/
|
|
1356
|
+
async deleteList(siteName, listId) {
|
|
1357
|
+
return this.delete(
|
|
1358
|
+
this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`)
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Get newsletter statistics (admin only)
|
|
1363
|
+
*/
|
|
1364
|
+
async getStatistics(siteName, params) {
|
|
1365
|
+
return this.http.get(
|
|
1366
|
+
this.buildPath(this.newsletterEndpoint(siteName, "/newsletter/statistics")),
|
|
1367
|
+
params
|
|
1368
|
+
);
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Export newsletter subscriptions (admin only)
|
|
1372
|
+
*/
|
|
1373
|
+
async exportSubscriptions(siteName, params) {
|
|
1374
|
+
return this.create(
|
|
1375
|
+
this.newsletterEndpoint(siteName, "/newsletter/export"),
|
|
1376
|
+
params || {}
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Import newsletter subscriptions (admin only)
|
|
1381
|
+
*/
|
|
1382
|
+
async importSubscriptions(siteName, data) {
|
|
1383
|
+
return this.create(
|
|
1384
|
+
this.newsletterEndpoint(siteName, "/newsletter/import"),
|
|
1385
|
+
data
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Send test newsletter (admin only)
|
|
1390
|
+
*/
|
|
1391
|
+
async sendTestNewsletter(siteName, data) {
|
|
1392
|
+
return this.create(
|
|
1393
|
+
this.newsletterEndpoint(siteName, "/newsletter/test"),
|
|
1394
|
+
data
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1220
1399
|
// src/perspect-api-client.ts
|
|
1221
1400
|
var PerspectApiClient = class {
|
|
1222
1401
|
http;
|
|
@@ -1231,6 +1410,7 @@ var PerspectApiClient = class {
|
|
|
1231
1410
|
webhooks;
|
|
1232
1411
|
checkout;
|
|
1233
1412
|
contact;
|
|
1413
|
+
newsletter;
|
|
1234
1414
|
constructor(config) {
|
|
1235
1415
|
if (!config.baseUrl) {
|
|
1236
1416
|
throw new Error("baseUrl is required in PerspectApiConfig");
|
|
@@ -1246,6 +1426,7 @@ var PerspectApiClient = class {
|
|
|
1246
1426
|
this.webhooks = new WebhooksClient(this.http);
|
|
1247
1427
|
this.checkout = new CheckoutClient(this.http);
|
|
1248
1428
|
this.contact = new ContactClient(this.http);
|
|
1429
|
+
this.newsletter = new NewsletterClient(this.http);
|
|
1249
1430
|
}
|
|
1250
1431
|
/**
|
|
1251
1432
|
* Update authentication token
|
|
@@ -1707,6 +1888,7 @@ export {
|
|
|
1707
1888
|
ContactClient,
|
|
1708
1889
|
ContentClient,
|
|
1709
1890
|
HttpClient,
|
|
1891
|
+
NewsletterClient,
|
|
1710
1892
|
OrganizationsClient,
|
|
1711
1893
|
PerspectApiClient,
|
|
1712
1894
|
ProductsClient,
|