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