Admin Customer — TypeScript SDK
End-customer (bizUser) lifecycle: list, create, delete.
Overview
The admin Customer resource manages end-customers (the bizUser layer — the actual paying users under the admin's tenant), distinct from admin operators themselves. For partner_admin, the scope is the admin's own tenant; for sys_admin, scope is broader per backend policy.
Accessed via admin.customer.
Available Operations
| Method | Description |
|---|---|
list() | List end-customers under the admin's scope |
create() | Create a new end-customer |
delete() | Delete an end-customer by id |
list
List end-customers under the current admin's scope, paginated. Supports fuzzy search by userName.
Example Usage
const result = await admin.customer.list({ pageNum: 1, pageSize: 20 });
console.log(`total: ${result.total}`);
for (const it of result.list) {
console.log(it.id, it.userName, it.email);
}
Search by name:
const result = await admin.customer.list({ userName: 'acme', pageNum: 1, pageSize: 10 });
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| pageNum | number | No | 1 | Page number, starting from 1 |
| pageSize | number | No | 10 | Items per page |
| userName | string | No | -- | Fuzzy search by userName |
Response
Returns an object with total, list, totalPages, currentPage, pageSize. Each item exposes id, userName, email, phone, timezone, createdAtUtc, updatedAtUtc, userType, parentId, etc.
Errors
| Code | Exception | When |
|---|---|---|
2007 | PermissionError | Admin lacks Customer Management permission |
3001 | AuthenticationError | Session expired and refresh failed |
create
Create a new end-customer under the current admin's tenant. Returns true on success; the created id is not echoed — recover it via list() with the matching userName if needed.
Example Usage
const ok = await admin.customer.create({
userName: 'acme-user-1',
password: 'StrongPass!',
email: 'user1@acme.example',
});
console.log(ok); // true
Recover the created id:
const result = await admin.customer.list({ userName: 'acme-user-1', pageNum: 1, pageSize: 1 });
const newId = result.list[0].id;
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| userName | string | Yes | -- | New customer userName (must be unique in scope) |
| password | string | Yes | -- | Initial password (server-side bcrypt-hashed) |
| string | No | -- | Contact email | |
| phone | string | No | -- | Contact phone |
| timezone | string | No | Asia/Shanghai | IANA timezone |
Response
Returns boolean — true on success. On failure throws the appropriate exception.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Missing required field, weak password, or bad email format |
2007 | PermissionError | Admin lacks Customer Management permission |
3001 | AuthenticationError | Session expired and refresh failed |
| Server 4xx | WltError | Duplicate userName in the tenant scope |
delete
Delete an end-customer by id.
Example Usage
const ok = await admin.customer.delete(42);
console.log(ok); // true
// Verify no residue
const remaining = await admin.customer.list({ userName: 'acme-user-1', pageNum: 1, pageSize: 10 });
console.assert(remaining.list.length === 0);
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| userId | number | Yes | -- | End-customer id to delete (positional argument) |
Response
Returns boolean — true on success.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Invalid userId |
2007 | PermissionError | Admin lacks Customer Management permission |
3001 | AuthenticationError | Session expired and refresh failed |
| Server 4xx | WltError | Customer does not exist or is out of scope |
Typical lifecycle
The full create → verify → delete → verify pattern (useful for provisioning scripts and integration tests):
const temp = 'provisioning-test';
const ok = await admin.customer.create({ userName: temp, password: 'StrongPass!', email: 't@example.com' });
const found = await admin.customer.list({ userName: temp, pageNum: 1, pageSize: 1 });
const newId = found.list[0].id;
// ... do work under `newId` ...
await admin.customer.delete(newId);
const after = await admin.customer.list({ userName: temp, pageNum: 1, pageSize: 10 });
console.assert(after.list.length === 0);