@witnium-tech/witniumchain 0.6.2 → 0.8.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 +905 -1
- package/dist/index.d.ts +905 -1
- package/dist/index.js +138 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -119,6 +119,8 @@ var WitniumchainClient = class {
|
|
|
119
119
|
oauth;
|
|
120
120
|
/** MFA self-management. Accessed as `client.mfa.totp.*` and `client.mfa.recoveryCodes.*`. */
|
|
121
121
|
mfa;
|
|
122
|
+
/** Session-cookie team management (org-admin only). `client.orgUsers.*`. */
|
|
123
|
+
orgUsers;
|
|
122
124
|
constructor(config) {
|
|
123
125
|
if (!config.baseUrl) {
|
|
124
126
|
throw new Error("WitniumchainClient: baseUrl is required");
|
|
@@ -127,12 +129,13 @@ var WitniumchainClient = class {
|
|
|
127
129
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
128
130
|
this.chainBaseUrl = config.chainBaseUrl?.replace(/\/$/, "");
|
|
129
131
|
this.timeout = config.timeout ?? 3e4;
|
|
130
|
-
|
|
131
|
-
if (!
|
|
132
|
+
const resolvedFetch = config.fetch ?? (globalThis.fetch ? globalThis.fetch.bind(globalThis) : void 0);
|
|
133
|
+
if (!resolvedFetch) {
|
|
132
134
|
throw new Error(
|
|
133
135
|
"WitniumchainClient: no fetch implementation available. Pass `config.fetch`."
|
|
134
136
|
);
|
|
135
137
|
}
|
|
138
|
+
this.fetchImpl = resolvedFetch;
|
|
136
139
|
this.accessToken = config.accessToken;
|
|
137
140
|
this.oauthClientId = config.oauthClientId;
|
|
138
141
|
this.verifierStorage = config.verifierStorage;
|
|
@@ -141,6 +144,7 @@ var WitniumchainClient = class {
|
|
|
141
144
|
this.keys = new SigningKeys(this);
|
|
142
145
|
this.oauth = new OauthNamespace(this);
|
|
143
146
|
this.mfa = new MfaNamespace(this);
|
|
147
|
+
this.orgUsers = new OrgMembers(this);
|
|
144
148
|
}
|
|
145
149
|
/**
|
|
146
150
|
* Convenience alias for {@link getAccount} — returns the authenticated
|
|
@@ -168,6 +172,53 @@ var WitniumchainClient = class {
|
|
|
168
172
|
createOrg(body) {
|
|
169
173
|
return this.req("POST", "/v1/orgs", { auth: "Public", body });
|
|
170
174
|
}
|
|
175
|
+
// ── Team management (session-cookie; org-admin only) ──────────────────────
|
|
176
|
+
// Backing methods for the `orgUsers` namespace. All resolve the caller's
|
|
177
|
+
// org + org-admin role server-side from the session — no orgId in the path.
|
|
178
|
+
listMembers() {
|
|
179
|
+
return this.req("GET", "/v1/orgs/me/members", { auth: "SessionCookie" });
|
|
180
|
+
}
|
|
181
|
+
inviteMember(body) {
|
|
182
|
+
return this.req("POST", "/v1/orgs/me/members/invite", {
|
|
183
|
+
auth: "SessionCookie",
|
|
184
|
+
body
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
suspendMember(userId) {
|
|
188
|
+
return this.req(
|
|
189
|
+
"POST",
|
|
190
|
+
`/v1/orgs/me/members/${encodeURIComponent(userId)}/suspend`,
|
|
191
|
+
{ auth: "SessionCookie" }
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
unsuspendMember(userId) {
|
|
195
|
+
return this.req(
|
|
196
|
+
"POST",
|
|
197
|
+
`/v1/orgs/me/members/${encodeURIComponent(userId)}/unsuspend`,
|
|
198
|
+
{ auth: "SessionCookie" }
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
setMemberRole(userId, body) {
|
|
202
|
+
return this.req(
|
|
203
|
+
"PUT",
|
|
204
|
+
`/v1/orgs/me/members/${encodeURIComponent(userId)}/role`,
|
|
205
|
+
{ auth: "SessionCookie", body }
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
removeMember(userId) {
|
|
209
|
+
return this.req(
|
|
210
|
+
"DELETE",
|
|
211
|
+
`/v1/orgs/me/members/${encodeURIComponent(userId)}`,
|
|
212
|
+
{ auth: "SessionCookie" }
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
resendMemberInvite(userId) {
|
|
216
|
+
return this.req(
|
|
217
|
+
"POST",
|
|
218
|
+
`/v1/orgs/me/members/${encodeURIComponent(userId)}/resend-invite`,
|
|
219
|
+
{ auth: "SessionCookie" }
|
|
220
|
+
);
|
|
221
|
+
}
|
|
171
222
|
verifyEmail(token) {
|
|
172
223
|
return this.req("GET", "/v1/auth/verify", {
|
|
173
224
|
auth: "Public",
|
|
@@ -1240,6 +1291,40 @@ var MfaNamespace = class {
|
|
|
1240
1291
|
this.recoveryCodes = new MfaRecoveryCodes(client);
|
|
1241
1292
|
}
|
|
1242
1293
|
};
|
|
1294
|
+
var OrgMembers = class {
|
|
1295
|
+
constructor(client) {
|
|
1296
|
+
this.client = client;
|
|
1297
|
+
}
|
|
1298
|
+
client;
|
|
1299
|
+
/** List the caller's org members (role, suspendedAt, isOwner, keys). */
|
|
1300
|
+
list() {
|
|
1301
|
+
return this.client.listMembers();
|
|
1302
|
+
}
|
|
1303
|
+
/** Invite a member by email (default role `member`). */
|
|
1304
|
+
invite(body) {
|
|
1305
|
+
return this.client.inviteMember(body);
|
|
1306
|
+
}
|
|
1307
|
+
/** Suspend a member (reversible). The owner cannot be suspended. */
|
|
1308
|
+
suspend(userId) {
|
|
1309
|
+
return this.client.suspendMember(userId);
|
|
1310
|
+
}
|
|
1311
|
+
/** Lift a member's suspension. */
|
|
1312
|
+
unsuspend(userId) {
|
|
1313
|
+
return this.client.unsuspendMember(userId);
|
|
1314
|
+
}
|
|
1315
|
+
/** Set a member's role. Refuses to demote the owner. */
|
|
1316
|
+
setRole(userId, role) {
|
|
1317
|
+
return this.client.setMemberRole(userId, { role });
|
|
1318
|
+
}
|
|
1319
|
+
/** Remove a member (terminal; revokes their delegated keys). Owner protected. */
|
|
1320
|
+
remove(userId) {
|
|
1321
|
+
return this.client.removeMember(userId);
|
|
1322
|
+
}
|
|
1323
|
+
/** Re-mint an email-verify token for a pending member. */
|
|
1324
|
+
resendInvite(userId) {
|
|
1325
|
+
return this.client.resendMemberInvite(userId);
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1243
1328
|
var MfaTotp = class {
|
|
1244
1329
|
constructor(client) {
|
|
1245
1330
|
this.client = client;
|
|
@@ -1392,7 +1477,7 @@ var WitniumchainChainAdminClient = class {
|
|
|
1392
1477
|
this.adminToken = config.adminToken;
|
|
1393
1478
|
this.adminTokenProvider = config.adminTokenProvider;
|
|
1394
1479
|
this.timeout = config.timeout ?? 3e4;
|
|
1395
|
-
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
1480
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
1396
1481
|
}
|
|
1397
1482
|
async deployContract(body) {
|
|
1398
1483
|
return this.req("POST", "/v5/contracts/deploy", body);
|
|
@@ -1513,6 +1598,50 @@ var OrgUsers = class {
|
|
|
1513
1598
|
}
|
|
1514
1599
|
};
|
|
1515
1600
|
|
|
1516
|
-
|
|
1601
|
+
// src/owner-ops.ts
|
|
1602
|
+
var OWNER_OP = {
|
|
1603
|
+
addSigningKey: 1,
|
|
1604
|
+
revokeSigningKey: 2,
|
|
1605
|
+
pause: 3,
|
|
1606
|
+
unpause: 4
|
|
1607
|
+
};
|
|
1608
|
+
function build(op, contractAddress, nonce, payload = {}) {
|
|
1609
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(contractAddress)) {
|
|
1610
|
+
throw new Error("contractAddress must be 0x + 40 hex chars");
|
|
1611
|
+
}
|
|
1612
|
+
if (!Number.isInteger(nonce) || nonce < 0) {
|
|
1613
|
+
throw new Error("nonce must be a non-negative integer");
|
|
1614
|
+
}
|
|
1615
|
+
return JSON.stringify({
|
|
1616
|
+
op,
|
|
1617
|
+
contract: contractAddress.toLowerCase(),
|
|
1618
|
+
nonce,
|
|
1619
|
+
...payload
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
function buildPausePayload(args) {
|
|
1623
|
+
return build(OWNER_OP.pause, args.contractAddress, args.nonce);
|
|
1624
|
+
}
|
|
1625
|
+
function buildUnpausePayload(args) {
|
|
1626
|
+
return build(OWNER_OP.unpause, args.contractAddress, args.nonce);
|
|
1627
|
+
}
|
|
1628
|
+
function buildAddSigningKeyPayload(args) {
|
|
1629
|
+
if (!/^[0-9a-fA-F]{64}$/.test(args.newKey)) {
|
|
1630
|
+
throw new Error("newKey must be 64 hex chars (no 0x)");
|
|
1631
|
+
}
|
|
1632
|
+
return build(OWNER_OP.addSigningKey, args.contractAddress, args.nonce, {
|
|
1633
|
+
newKey: args.newKey
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
function buildRevokeSigningKeyPayload(args) {
|
|
1637
|
+
if (!/^[0-9a-fA-F]{64}$/.test(args.key)) {
|
|
1638
|
+
throw new Error("key must be 64 hex chars (no 0x)");
|
|
1639
|
+
}
|
|
1640
|
+
return build(OWNER_OP.revokeSigningKey, args.contractAddress, args.nonce, {
|
|
1641
|
+
key: args.key
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
export { DelegatedKeys, MfaNamespace, MfaRecoveryCodes, MfaTotp, OWNER_OP, OauthNamespace, OauthSessions, OrgMembers, OrgUsers, SigningKeys, Subscriptions, WitniumchainAdminClient, WitniumchainApiError, WitniumchainChainAdminClient, WitniumchainClient, WitniumchainOrgClient, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage };
|
|
1517
1646
|
//# sourceMappingURL=index.mjs.map
|
|
1518
1647
|
//# sourceMappingURL=index.mjs.map
|