@slotchain/sdk 1.1.4 → 1.2.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/dist/index.cjs.js +184 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +262 -22
- package/dist/index.d.ts +262 -22
- package/dist/index.esm.js +184 -16
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -2
- package/src/clients/customer-client.ts +129 -29
- package/src/clients/customer-client.ts.bak +165 -0
- package/src/clients/document-client.ts +148 -0
- package/src/clients/tenant-client.ts +2 -3
- package/src/index.ts +16 -0
- package/src/types/api.ts +150 -1
- package/src/types/next-ambient.d.ts +29 -0
package/dist/index.cjs.js
CHANGED
|
@@ -49,11 +49,11 @@ var TenantClient = class {
|
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Get tenant configuration by slug
|
|
52
|
-
* GET /api/v1/
|
|
52
|
+
* GET /api/v1/tenants/:slug
|
|
53
53
|
*/
|
|
54
54
|
async getBySlug(slug) {
|
|
55
55
|
const response = await this.client.get(
|
|
56
|
-
`/api/v1/
|
|
56
|
+
`/api/v1/tenants/${slug}`
|
|
57
57
|
);
|
|
58
58
|
return response.data;
|
|
59
59
|
}
|
|
@@ -847,9 +847,6 @@ var CustomerClient = class {
|
|
|
847
847
|
/**
|
|
848
848
|
* Create a new customer
|
|
849
849
|
* POST /api/v1/customers
|
|
850
|
-
*
|
|
851
|
-
* @param data - Customer creation data (tenant_id, name, email required)
|
|
852
|
-
* @returns Created customer
|
|
853
850
|
*/
|
|
854
851
|
async create(data) {
|
|
855
852
|
const response = await this.client.post(
|
|
@@ -901,11 +898,8 @@ var CustomerClient = class {
|
|
|
901
898
|
return response.data;
|
|
902
899
|
}
|
|
903
900
|
/**
|
|
904
|
-
* Get autocomplete data from existing customers and bookings
|
|
905
|
-
* GET /api/v1/customers/autocomplete
|
|
906
|
-
*
|
|
907
|
-
* @param tenantId - Tenant ID (required)
|
|
908
|
-
* @returns Autocomplete data
|
|
901
|
+
* Get autocomplete data from existing customers and bookings.
|
|
902
|
+
* GET /api/v1/customers/autocomplete?tenantId=:tenantId
|
|
909
903
|
*/
|
|
910
904
|
async autocomplete(tenantId) {
|
|
911
905
|
const response = await this.client.get(
|
|
@@ -915,11 +909,8 @@ var CustomerClient = class {
|
|
|
915
909
|
return response.data;
|
|
916
910
|
}
|
|
917
911
|
/**
|
|
918
|
-
* Get all bookings for a customer
|
|
919
|
-
* GET /api/v1/customers/bookings
|
|
920
|
-
*
|
|
921
|
-
* @param params - Query parameters (email optional, userId optional, tenantId required)
|
|
922
|
-
* @returns Customer bookings data
|
|
912
|
+
* Get all bookings for a customer, grouped by slot.
|
|
913
|
+
* GET /api/v1/customers/bookings?tenantId=:id
|
|
923
914
|
*/
|
|
924
915
|
async getBookings(params) {
|
|
925
916
|
const response = await this.client.get(
|
|
@@ -928,6 +919,85 @@ var CustomerClient = class {
|
|
|
928
919
|
);
|
|
929
920
|
return response.data;
|
|
930
921
|
}
|
|
922
|
+
// ─── Atomic upsert ────────────────────────────────────────────────────────
|
|
923
|
+
/**
|
|
924
|
+
* Atomic upsert: find an existing customer by email within a tenant, or create one.
|
|
925
|
+
* POST /api/v1/customers/find-or-create
|
|
926
|
+
*/
|
|
927
|
+
async findOrCreate(options) {
|
|
928
|
+
const response = await this.client.post(
|
|
929
|
+
"/api/v1/customers/find-or-create",
|
|
930
|
+
options
|
|
931
|
+
);
|
|
932
|
+
return response.data;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Resolve a customer from an IDP identity or email.
|
|
936
|
+
* Tries idpId lookup (customer_users) first, then falls back to email.
|
|
937
|
+
* POST /api/v1/customers/resolve
|
|
938
|
+
*/
|
|
939
|
+
async resolve(options) {
|
|
940
|
+
const response = await this.client.post(
|
|
941
|
+
"/api/v1/customers/resolve",
|
|
942
|
+
options
|
|
943
|
+
);
|
|
944
|
+
return response.data;
|
|
945
|
+
}
|
|
946
|
+
// ─── IDP Identity Management ─────────────────────────────────────────────
|
|
947
|
+
/**
|
|
948
|
+
* Get a customer with their linked IDP identities (customer_users rows).
|
|
949
|
+
* GET /api/v1/customers/:id?include_identities=true
|
|
950
|
+
*/
|
|
951
|
+
async getWithIdentities(id) {
|
|
952
|
+
const response = await this.client.get(
|
|
953
|
+
`/api/v1/customers/${id}`,
|
|
954
|
+
{ params: { include_identities: true } }
|
|
955
|
+
);
|
|
956
|
+
return response.data;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Link an IDP user ID to a customer (creates a customer_users row).
|
|
960
|
+
* POST /api/v1/customers/:id/users
|
|
961
|
+
*/
|
|
962
|
+
async linkUser(customerId, idpId, options) {
|
|
963
|
+
const response = await this.client.post(
|
|
964
|
+
`/api/v1/customers/${customerId}/users`,
|
|
965
|
+
{ idp_id: idpId, role: options?.role ?? "member", is_primary: options?.is_primary ?? false }
|
|
966
|
+
);
|
|
967
|
+
return response.data;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Unlink an IDP user from a customer (deletes the customer_users row).
|
|
971
|
+
* DELETE /api/v1/customers/:id/users/:idpId
|
|
972
|
+
*/
|
|
973
|
+
async unlinkUser(customerId, idpId) {
|
|
974
|
+
const response = await this.client.delete(
|
|
975
|
+
`/api/v1/customers/${customerId}/users/${encodeURIComponent(idpId)}`
|
|
976
|
+
);
|
|
977
|
+
return response.data;
|
|
978
|
+
}
|
|
979
|
+
// ─── Notification Preferences ────────────────────────────────────────────
|
|
980
|
+
/**
|
|
981
|
+
* Get notification preferences for a customer.
|
|
982
|
+
* GET /api/v1/customers/:id/preferences/notifications
|
|
983
|
+
*/
|
|
984
|
+
async getNotificationPreferences(customerId) {
|
|
985
|
+
const response = await this.client.get(
|
|
986
|
+
`/api/v1/customers/${customerId}/preferences/notifications`
|
|
987
|
+
);
|
|
988
|
+
return response.data;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Update notification preferences for a customer (partial merge).
|
|
992
|
+
* PATCH /api/v1/customers/:id/preferences/notifications
|
|
993
|
+
*/
|
|
994
|
+
async updateNotificationPreferences(customerId, preferences) {
|
|
995
|
+
const response = await this.client.patch(
|
|
996
|
+
`/api/v1/customers/${customerId}/preferences/notifications`,
|
|
997
|
+
preferences
|
|
998
|
+
);
|
|
999
|
+
return response.data;
|
|
1000
|
+
}
|
|
931
1001
|
};
|
|
932
1002
|
|
|
933
1003
|
// src/clients/flow-client.ts
|
|
@@ -1358,6 +1428,103 @@ var OrganizationClient = class {
|
|
|
1358
1428
|
}
|
|
1359
1429
|
};
|
|
1360
1430
|
|
|
1431
|
+
// src/clients/document-client.ts
|
|
1432
|
+
var DocumentClient = class {
|
|
1433
|
+
constructor(client) {
|
|
1434
|
+
this.base = "/api/v1/artifacts";
|
|
1435
|
+
this.client = client;
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Upload a file artifact.
|
|
1439
|
+
* Sends as multipart/form-data.
|
|
1440
|
+
*/
|
|
1441
|
+
async upload(options) {
|
|
1442
|
+
const form = new FormData();
|
|
1443
|
+
let blob;
|
|
1444
|
+
if (options.file instanceof Blob) {
|
|
1445
|
+
blob = options.file;
|
|
1446
|
+
} else {
|
|
1447
|
+
blob = new Blob([options.file], { type: options.mime_type ?? "application/octet-stream" });
|
|
1448
|
+
}
|
|
1449
|
+
form.append("file", blob, options.filename);
|
|
1450
|
+
form.append("related_entity_type", options.related_entity_type);
|
|
1451
|
+
form.append("related_entity_id", options.related_entity_id);
|
|
1452
|
+
if (options.label) form.append("label", options.label);
|
|
1453
|
+
if (options.mime_type) form.append("mime_type", options.mime_type);
|
|
1454
|
+
if (options.metadata) form.append("metadata", JSON.stringify(options.metadata));
|
|
1455
|
+
const response = await this.client.post(this.base, form, {
|
|
1456
|
+
headers: { "Content-Type": "multipart/form-data" }
|
|
1457
|
+
});
|
|
1458
|
+
const { data } = response.data;
|
|
1459
|
+
if (!data) throw new Error("No artifact returned from upload");
|
|
1460
|
+
return data;
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* List artifacts for a specific entity.
|
|
1464
|
+
* Pass `signed: true` to get download URLs in each result.
|
|
1465
|
+
*/
|
|
1466
|
+
async listByEntity(entityType, entityId, options) {
|
|
1467
|
+
const response = await this.client.get(
|
|
1468
|
+
this.base,
|
|
1469
|
+
{
|
|
1470
|
+
params: {
|
|
1471
|
+
related_entity_type: entityType,
|
|
1472
|
+
related_entity_id: entityId,
|
|
1473
|
+
...options
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
);
|
|
1477
|
+
return response.data;
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* List artifacts with full filter options.
|
|
1481
|
+
*/
|
|
1482
|
+
async list(options) {
|
|
1483
|
+
const response = await this.client.get(
|
|
1484
|
+
this.base,
|
|
1485
|
+
{ params: options }
|
|
1486
|
+
);
|
|
1487
|
+
return response.data;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* Get a single artifact by ID.
|
|
1491
|
+
*/
|
|
1492
|
+
async get(id, signed = false) {
|
|
1493
|
+
const response = await this.client.get(
|
|
1494
|
+
`${this.base}/${id}`,
|
|
1495
|
+
{ params: signed ? { signed: true } : void 0 }
|
|
1496
|
+
);
|
|
1497
|
+
const { data } = response.data;
|
|
1498
|
+
if (!data) throw new Error(`Artifact ${id} not found`);
|
|
1499
|
+
return data;
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Get a signed download URL for an artifact.
|
|
1503
|
+
* Returns the full ArtifactWithUrl including `signed_url` and `signed_url_expires_at`.
|
|
1504
|
+
*/
|
|
1505
|
+
async getUrl(id) {
|
|
1506
|
+
return this.get(id, true);
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Delete an artifact and its stored file.
|
|
1510
|
+
*/
|
|
1511
|
+
async delete(id) {
|
|
1512
|
+
await this.client.delete(`${this.base}/${id}`);
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Update artifact label or metadata.
|
|
1516
|
+
*/
|
|
1517
|
+
async update(id, patch) {
|
|
1518
|
+
const response = await this.client.patch(
|
|
1519
|
+
`${this.base}/${id}`,
|
|
1520
|
+
patch
|
|
1521
|
+
);
|
|
1522
|
+
const { data } = response.data;
|
|
1523
|
+
if (!data) throw new Error(`Artifact ${id} not found`);
|
|
1524
|
+
return data;
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1361
1528
|
// src/errors.ts
|
|
1362
1529
|
var SlotlyApiError = class _SlotlyApiError extends Error {
|
|
1363
1530
|
constructor(code, message, statusCode, details) {
|
|
@@ -1690,7 +1857,8 @@ var useSlotly = (options) => {
|
|
|
1690
1857
|
studio: new StudioClient(client),
|
|
1691
1858
|
notification: new NotificationClient(client),
|
|
1692
1859
|
dataQuality: new DataQualityClient(client),
|
|
1693
|
-
organization: new OrganizationClient(client)
|
|
1860
|
+
organization: new OrganizationClient(client),
|
|
1861
|
+
document: new DocumentClient(client)
|
|
1694
1862
|
};
|
|
1695
1863
|
};
|
|
1696
1864
|
var index_default = useSlotly;
|