@hypercerts-org/sdk-core 0.2.0-beta.0 → 0.4.0-beta.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/.turbo/turbo-build.log +10 -10
- package/.turbo/turbo-test.log +27 -27
- package/CHANGELOG.md +9 -3
- package/README.md +48 -5
- package/dist/index.cjs +110 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -10
- package/dist/index.mjs +110 -10
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +29 -10
- package/package.json +2 -2
- package/src/repository/CollaboratorOperationsImpl.ts +114 -6
- package/src/repository/OrganizationOperationsImpl.ts +4 -4
- package/src/repository/interfaces.ts +29 -0
- package/tests/repository/CollaboratorOperationsImpl.test.ts +123 -8
- package/tests/repository/OrganizationOperationsImpl.test.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1089,16 +1089,6 @@ interface HypercertWithMetadata {
|
|
|
1089
1089
|
record: HypercertClaim;
|
|
1090
1090
|
}
|
|
1091
1091
|
|
|
1092
|
-
/**
|
|
1093
|
-
* Repository interfaces - Operation contracts for repository functionality.
|
|
1094
|
-
*
|
|
1095
|
-
* This module defines the interfaces for all repository operations,
|
|
1096
|
-
* providing clear contracts for record management, blob handling,
|
|
1097
|
-
* profile management, and domain-specific operations.
|
|
1098
|
-
*
|
|
1099
|
-
* @packageDocumentation
|
|
1100
|
-
*/
|
|
1101
|
-
|
|
1102
1092
|
/**
|
|
1103
1093
|
* Parameters for creating a new hypercert.
|
|
1104
1094
|
*
|
|
@@ -1845,6 +1835,17 @@ interface HypercertOperations extends EventEmitter<HypercertEvents> {
|
|
|
1845
1835
|
* const hasAccess = await repo.collaborators.hasAccess("did:plc:someone");
|
|
1846
1836
|
* const role = await repo.collaborators.getRole("did:plc:someone");
|
|
1847
1837
|
*
|
|
1838
|
+
* // Get current user permissions
|
|
1839
|
+
* const permissions = await repo.collaborators.getPermissions();
|
|
1840
|
+
* if (permissions.admin) {
|
|
1841
|
+
* // Can manage collaborators
|
|
1842
|
+
* }
|
|
1843
|
+
*
|
|
1844
|
+
* // Transfer ownership
|
|
1845
|
+
* await repo.collaborators.transferOwnership({
|
|
1846
|
+
* newOwnerDid: "did:plc:new-owner",
|
|
1847
|
+
* });
|
|
1848
|
+
*
|
|
1848
1849
|
* // Revoke access
|
|
1849
1850
|
* await repo.collaborators.revoke({ userDid: "did:plc:former-user" });
|
|
1850
1851
|
* ```
|
|
@@ -1890,6 +1891,24 @@ interface CollaboratorOperations {
|
|
|
1890
1891
|
* @returns Promise resolving to role, or `null` if no access
|
|
1891
1892
|
*/
|
|
1892
1893
|
getRole(userDid: string): Promise<RepositoryRole | null>;
|
|
1894
|
+
/**
|
|
1895
|
+
* Gets the current user's permissions for this repository.
|
|
1896
|
+
*
|
|
1897
|
+
* @returns Promise resolving to permission flags
|
|
1898
|
+
*/
|
|
1899
|
+
getPermissions(): Promise<CollaboratorPermissions>;
|
|
1900
|
+
/**
|
|
1901
|
+
* Transfers repository ownership to another user.
|
|
1902
|
+
*
|
|
1903
|
+
* **WARNING**: This action is irreversible. The new owner will have
|
|
1904
|
+
* full control of the repository.
|
|
1905
|
+
*
|
|
1906
|
+
* @param params - Transfer parameters
|
|
1907
|
+
* @param params.newOwnerDid - DID of the user to transfer ownership to
|
|
1908
|
+
*/
|
|
1909
|
+
transferOwnership(params: {
|
|
1910
|
+
newOwnerDid: string;
|
|
1911
|
+
}): Promise<void>;
|
|
1893
1912
|
}
|
|
1894
1913
|
/**
|
|
1895
1914
|
* Organization operations for SDS organization management.
|
package/dist/index.mjs
CHANGED
|
@@ -3040,9 +3040,11 @@ class HypercertOperationsImpl extends EventEmitter {
|
|
|
3040
3040
|
* - `owner`: Full control including ownership management
|
|
3041
3041
|
*
|
|
3042
3042
|
* **SDS API Endpoints Used**:
|
|
3043
|
-
* - `com.
|
|
3044
|
-
* - `com.
|
|
3045
|
-
* - `com.
|
|
3043
|
+
* - `com.sds.repo.grantAccess`: Grant access to a user
|
|
3044
|
+
* - `com.sds.repo.revokeAccess`: Revoke access from a user
|
|
3045
|
+
* - `com.sds.repo.listCollaborators`: List all collaborators
|
|
3046
|
+
* - `com.sds.repo.getPermissions`: Get current user's permissions
|
|
3047
|
+
* - `com.sds.repo.transferOwnership`: Transfer repository ownership
|
|
3046
3048
|
*
|
|
3047
3049
|
* @example
|
|
3048
3050
|
* ```typescript
|
|
@@ -3144,7 +3146,7 @@ class CollaboratorOperationsImpl {
|
|
|
3144
3146
|
*/
|
|
3145
3147
|
async grant(params) {
|
|
3146
3148
|
const permissions = this.roleToPermissions(params.role);
|
|
3147
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3149
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.grantAccess`, {
|
|
3148
3150
|
method: "POST",
|
|
3149
3151
|
headers: { "Content-Type": "application/json" },
|
|
3150
3152
|
body: JSON.stringify({
|
|
@@ -3176,7 +3178,7 @@ class CollaboratorOperationsImpl {
|
|
|
3176
3178
|
* ```
|
|
3177
3179
|
*/
|
|
3178
3180
|
async revoke(params) {
|
|
3179
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3181
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.revokeAccess`, {
|
|
3180
3182
|
method: "POST",
|
|
3181
3183
|
headers: { "Content-Type": "application/json" },
|
|
3182
3184
|
body: JSON.stringify({
|
|
@@ -3215,7 +3217,7 @@ class CollaboratorOperationsImpl {
|
|
|
3215
3217
|
* ```
|
|
3216
3218
|
*/
|
|
3217
3219
|
async list() {
|
|
3218
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3220
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.listCollaborators?repo=${encodeURIComponent(this.repoDid)}`, { method: "GET" });
|
|
3219
3221
|
if (!response.ok) {
|
|
3220
3222
|
throw new NetworkError(`Failed to list collaborators: ${response.statusText}`);
|
|
3221
3223
|
}
|
|
@@ -3276,6 +3278,104 @@ class CollaboratorOperationsImpl {
|
|
|
3276
3278
|
const collab = collaborators.find((c) => c.userDid === userDid && !c.revokedAt);
|
|
3277
3279
|
return collab?.role ?? null;
|
|
3278
3280
|
}
|
|
3281
|
+
/**
|
|
3282
|
+
* Gets the current user's permissions for this repository.
|
|
3283
|
+
*
|
|
3284
|
+
* @returns Promise resolving to the permission flags
|
|
3285
|
+
* @throws {@link NetworkError} if the request fails
|
|
3286
|
+
*
|
|
3287
|
+
* @remarks
|
|
3288
|
+
* This is useful for checking what actions the current user can perform
|
|
3289
|
+
* before attempting operations that might fail due to insufficient permissions.
|
|
3290
|
+
*
|
|
3291
|
+
* @example
|
|
3292
|
+
* ```typescript
|
|
3293
|
+
* const permissions = await repo.collaborators.getPermissions();
|
|
3294
|
+
*
|
|
3295
|
+
* if (permissions.admin) {
|
|
3296
|
+
* // Show admin UI
|
|
3297
|
+
* console.log("You can manage collaborators");
|
|
3298
|
+
* }
|
|
3299
|
+
*
|
|
3300
|
+
* if (permissions.create) {
|
|
3301
|
+
* console.log("You can create records");
|
|
3302
|
+
* }
|
|
3303
|
+
* ```
|
|
3304
|
+
*
|
|
3305
|
+
* @example Conditional UI rendering
|
|
3306
|
+
* ```typescript
|
|
3307
|
+
* const permissions = await repo.collaborators.getPermissions();
|
|
3308
|
+
*
|
|
3309
|
+
* // Show/hide UI elements based on permissions
|
|
3310
|
+
* const canEdit = permissions.update;
|
|
3311
|
+
* const canDelete = permissions.delete;
|
|
3312
|
+
* const isAdmin = permissions.admin;
|
|
3313
|
+
* const isOwner = permissions.owner;
|
|
3314
|
+
* ```
|
|
3315
|
+
*/
|
|
3316
|
+
async getPermissions() {
|
|
3317
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.getPermissions?repo=${encodeURIComponent(this.repoDid)}`, { method: "GET" });
|
|
3318
|
+
if (!response.ok) {
|
|
3319
|
+
throw new NetworkError(`Failed to get permissions: ${response.statusText}`);
|
|
3320
|
+
}
|
|
3321
|
+
const data = await response.json();
|
|
3322
|
+
return data.permissions;
|
|
3323
|
+
}
|
|
3324
|
+
/**
|
|
3325
|
+
* Transfers repository ownership to another user.
|
|
3326
|
+
*
|
|
3327
|
+
* @param params - Transfer parameters
|
|
3328
|
+
* @param params.newOwnerDid - DID of the user to transfer ownership to
|
|
3329
|
+
* @throws {@link NetworkError} if the transfer fails
|
|
3330
|
+
*
|
|
3331
|
+
* @remarks
|
|
3332
|
+
* **IMPORTANT**: This action is irreversible. Once ownership is transferred:
|
|
3333
|
+
* - The new owner gains full control of the repository
|
|
3334
|
+
* - Your role will be changed to admin (or specified role)
|
|
3335
|
+
* - You cannot transfer ownership back without the new owner's approval
|
|
3336
|
+
*
|
|
3337
|
+
* **Requirements**:
|
|
3338
|
+
* - You must be the current owner
|
|
3339
|
+
* - The new owner must have an existing account
|
|
3340
|
+
* - The new owner will be notified of the ownership transfer
|
|
3341
|
+
*
|
|
3342
|
+
* @example
|
|
3343
|
+
* ```typescript
|
|
3344
|
+
* // Transfer ownership to another user
|
|
3345
|
+
* await repo.collaborators.transferOwnership({
|
|
3346
|
+
* newOwnerDid: "did:plc:new-owner",
|
|
3347
|
+
* });
|
|
3348
|
+
*
|
|
3349
|
+
* console.log("Ownership transferred successfully");
|
|
3350
|
+
* // You are now an admin, not the owner
|
|
3351
|
+
* ```
|
|
3352
|
+
*
|
|
3353
|
+
* @example With confirmation
|
|
3354
|
+
* ```typescript
|
|
3355
|
+
* const confirmTransfer = await askUser(
|
|
3356
|
+
* "Are you sure you want to transfer ownership? This cannot be undone."
|
|
3357
|
+
* );
|
|
3358
|
+
*
|
|
3359
|
+
* if (confirmTransfer) {
|
|
3360
|
+
* await repo.collaborators.transferOwnership({
|
|
3361
|
+
* newOwnerDid: "did:plc:new-owner",
|
|
3362
|
+
* });
|
|
3363
|
+
* }
|
|
3364
|
+
* ```
|
|
3365
|
+
*/
|
|
3366
|
+
async transferOwnership(params) {
|
|
3367
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.transferOwnership`, {
|
|
3368
|
+
method: "POST",
|
|
3369
|
+
headers: { "Content-Type": "application/json" },
|
|
3370
|
+
body: JSON.stringify({
|
|
3371
|
+
repo: this.repoDid,
|
|
3372
|
+
newOwner: params.newOwnerDid,
|
|
3373
|
+
}),
|
|
3374
|
+
});
|
|
3375
|
+
if (!response.ok) {
|
|
3376
|
+
throw new NetworkError(`Failed to transfer ownership: ${response.statusText}`);
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3279
3379
|
}
|
|
3280
3380
|
|
|
3281
3381
|
/**
|
|
@@ -3302,8 +3402,8 @@ class CollaboratorOperationsImpl {
|
|
|
3302
3402
|
* {@link Repository.organizations} on an SDS-connected repository.
|
|
3303
3403
|
*
|
|
3304
3404
|
* **SDS API Endpoints Used**:
|
|
3305
|
-
* - `com.
|
|
3306
|
-
* - `com.
|
|
3405
|
+
* - `com.sds.organization.create`: Create a new organization
|
|
3406
|
+
* - `com.sds.organization.list`: List accessible organizations
|
|
3307
3407
|
*
|
|
3308
3408
|
* **Access Types**:
|
|
3309
3409
|
* - `"owner"`: User created or owns the organization
|
|
@@ -3381,7 +3481,7 @@ class OrganizationOperationsImpl {
|
|
|
3381
3481
|
* ```
|
|
3382
3482
|
*/
|
|
3383
3483
|
async create(params) {
|
|
3384
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3484
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.organization.create`, {
|
|
3385
3485
|
method: "POST",
|
|
3386
3486
|
headers: { "Content-Type": "application/json" },
|
|
3387
3487
|
body: JSON.stringify(params),
|
|
@@ -3471,7 +3571,7 @@ class OrganizationOperationsImpl {
|
|
|
3471
3571
|
* ```
|
|
3472
3572
|
*/
|
|
3473
3573
|
async list() {
|
|
3474
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3574
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.organization.list?userDid=${encodeURIComponent(this.session.did || this.session.sub)}`, { method: "GET" });
|
|
3475
3575
|
if (!response.ok) {
|
|
3476
3576
|
throw new NetworkError(`Failed to list organizations: ${response.statusText}`);
|
|
3477
3577
|
}
|