@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/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @hypercerts-org/sdk-core@0.
|
|
2
|
+
> @hypercerts-org/sdk-core@0.3.0 build /home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core
|
|
3
3
|
> rollup -c
|
|
4
4
|
|
|
5
5
|
[36m
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
[7m [0m [96m ~~~~~[0m
|
|
155
155
|
'$link' is declared here.
|
|
156
156
|
[39m
|
|
157
|
-
[32mcreated [1mdist/errors.mjs, dist/errors.cjs[22m in [
|
|
157
|
+
[32mcreated [1mdist/errors.mjs, dist/errors.cjs[22m in [1m1.9s[22m[39m
|
|
158
158
|
[36m
|
|
159
159
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/lexicons.ts[22m → [1mdist/lexicons.mjs, dist/lexicons.cjs[22m...[39m
|
|
160
160
|
[1m[33m(!) [plugin typescript] src/repository/BlobOperationsImpl.ts (125:9): @rollup/plugin-typescript TS2741: Property '$link' is missing in type 'CID<unknown, number, number, Version>' but required in type '{ $link: string; }'.[39m[22m
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
[7m [0m [96m ~~~~~[0m
|
|
206
206
|
'$link' is declared here.
|
|
207
207
|
[39m
|
|
208
|
-
[32mcreated [1mdist/lexicons.mjs, dist/lexicons.cjs[22m in [1m1.
|
|
208
|
+
[32mcreated [1mdist/lexicons.mjs, dist/lexicons.cjs[22m in [1m1.9s[22m[39m
|
|
209
209
|
[36m
|
|
210
210
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/storage.ts[22m → [1mdist/storage.mjs, dist/storage.cjs[22m...[39m
|
|
211
211
|
[1m[33m(!) [plugin typescript] src/repository/BlobOperationsImpl.ts (125:9): @rollup/plugin-typescript TS2741: Property '$link' is missing in type 'CID<unknown, number, number, Version>' but required in type '{ $link: string; }'.[39m[22m
|
|
@@ -256,7 +256,7 @@
|
|
|
256
256
|
[7m [0m [96m ~~~~~[0m
|
|
257
257
|
'$link' is declared here.
|
|
258
258
|
[39m
|
|
259
|
-
[32mcreated [1mdist/storage.mjs, dist/storage.cjs[22m in [1m1.
|
|
259
|
+
[32mcreated [1mdist/storage.mjs, dist/storage.cjs[22m in [1m1.8s[22m[39m
|
|
260
260
|
[36m
|
|
261
261
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/testing.ts[22m → [1mdist/testing.mjs, dist/testing.cjs[22m...[39m
|
|
262
262
|
[1m[33m(!) [plugin typescript] src/repository/BlobOperationsImpl.ts (125:9): @rollup/plugin-typescript TS2741: Property '$link' is missing in type 'CID<unknown, number, number, Version>' but required in type '{ $link: string; }'.[39m[22m
|
|
@@ -307,22 +307,22 @@
|
|
|
307
307
|
[7m [0m [96m ~~~~~[0m
|
|
308
308
|
'$link' is declared here.
|
|
309
309
|
[39m
|
|
310
|
-
[32mcreated [1mdist/testing.mjs, dist/testing.cjs[22m in [
|
|
310
|
+
[32mcreated [1mdist/testing.mjs, dist/testing.cjs[22m in [1m2.3s[22m[39m
|
|
311
311
|
[36m
|
|
312
312
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/index.ts[22m → [1mdist/index.d.ts[22m...[39m
|
|
313
|
-
[32mcreated [1mdist/index.d.ts[22m in [1m1.
|
|
313
|
+
[32mcreated [1mdist/index.d.ts[22m in [1m1.3s[22m[39m
|
|
314
314
|
[36m
|
|
315
315
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/types.ts[22m → [1mdist/types.d.ts[22m...[39m
|
|
316
316
|
[32mcreated [1mdist/types.d.ts[22m in [1m1.2s[22m[39m
|
|
317
317
|
[36m
|
|
318
318
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/errors.ts[22m → [1mdist/errors.d.ts[22m...[39m
|
|
319
|
-
[32mcreated [1mdist/errors.d.ts[22m in [
|
|
319
|
+
[32mcreated [1mdist/errors.d.ts[22m in [1m484ms[22m[39m
|
|
320
320
|
[36m
|
|
321
321
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/lexicons.ts[22m → [1mdist/lexicons.d.ts[22m...[39m
|
|
322
|
-
[32mcreated [1mdist/lexicons.d.ts[22m in [
|
|
322
|
+
[32mcreated [1mdist/lexicons.d.ts[22m in [1m1.1s[22m[39m
|
|
323
323
|
[36m
|
|
324
324
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/storage.ts[22m → [1mdist/storage.d.ts[22m...[39m
|
|
325
|
-
[32mcreated [1mdist/storage.d.ts[22m in [
|
|
325
|
+
[32mcreated [1mdist/storage.d.ts[22m in [1m544ms[22m[39m
|
|
326
326
|
[36m
|
|
327
327
|
[1m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core/src/testing.ts[22m → [1mdist/testing.d.ts[22m...[39m
|
|
328
|
-
[32mcreated [1mdist/testing.d.ts[22m in [
|
|
328
|
+
[32mcreated [1mdist/testing.d.ts[22m in [1m723ms[22m[39m
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
> @hypercerts-org/sdk-core@0.
|
|
2
|
+
> @hypercerts-org/sdk-core@0.3.0 test /home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core
|
|
3
3
|
> vitest
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
[1m[46m RUN [49m[22m [36mv3.2.4 [39m[90m/home/runner/work/hypercerts-sdk/hypercerts-sdk/packages/sdk-core[39m
|
|
7
7
|
|
|
8
|
-
[32m✓[39m tests/repository/CollaboratorOperationsImpl.test.ts [2m([22m[
|
|
9
|
-
[32m✓[39m tests/repository/RecordOperationsImpl.test.ts [2m([22m[2m21 tests[22m[2m)[22m[32m
|
|
10
|
-
[32m✓[39m tests/repository/HypercertOperationsImpl.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m
|
|
11
|
-
[32m✓[39m tests/repository/ProfileOperationsImpl.test.ts [2m([22m[2m14 tests[22m[2m)[22m[32m
|
|
12
|
-
[32m✓[39m tests/repository/OrganizationOperationsImpl.test.ts [2m([22m[2m12 tests[22m[2m)[22m[32m
|
|
8
|
+
[32m✓[39m tests/repository/CollaboratorOperationsImpl.test.ts [2m([22m[2m25 tests[22m[2m)[22m[32m 26[2mms[22m[39m
|
|
9
|
+
[32m✓[39m tests/repository/RecordOperationsImpl.test.ts [2m([22m[2m21 tests[22m[2m)[22m[32m 35[2mms[22m[39m
|
|
10
|
+
[32m✓[39m tests/repository/HypercertOperationsImpl.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m 49[2mms[22m[39m
|
|
11
|
+
[32m✓[39m tests/repository/ProfileOperationsImpl.test.ts [2m([22m[2m14 tests[22m[2m)[22m[32m 24[2mms[22m[39m
|
|
12
|
+
[32m✓[39m tests/repository/OrganizationOperationsImpl.test.ts [2m([22m[2m12 tests[22m[2m)[22m[32m 20[2mms[22m[39m
|
|
13
13
|
[32m✓[39m tests/repository/LexiconRegistry.test.ts [2m([22m[2m16 tests[22m[2m)[22m[32m 18[2mms[22m[39m
|
|
14
14
|
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mconstructor[2m > [22m[2mshould initialize with valid config
|
|
15
15
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
@@ -51,50 +51,49 @@ No lock mechanism provided. Credentials might get revoked.
|
|
|
51
51
|
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mauthorize[2m > [22m[2mshould trim identifier
|
|
52
52
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrestoreSession[2m > [22m[2mshould throw ValidationError for empty DID
|
|
54
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mcallback[2m > [22m[2mshould throw AuthenticationError for OAuth error params
|
|
56
55
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
57
56
|
|
|
58
|
-
[90mstderr[2m | tests/
|
|
57
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mcallback[2m > [22m[2mshould throw AuthenticationError for missing code
|
|
59
58
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
60
59
|
|
|
61
|
-
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[
|
|
60
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mrestore[2m > [22m[2mshould return null for non-existent session
|
|
62
61
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
63
62
|
|
|
64
|
-
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[
|
|
63
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mrestore[2m > [22m[2mshould throw AuthenticationError for invalid DID
|
|
65
64
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
66
65
|
|
|
67
|
-
[90mstderr[2m | tests/
|
|
66
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mrevoke[2m > [22m[2mshould not throw for non-existent session
|
|
68
67
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
69
68
|
|
|
70
|
-
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[
|
|
69
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mstorage integration[2m > [22m[2mshould use provided session store
|
|
71
70
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
72
71
|
|
|
73
|
-
[90mstderr[2m | tests/
|
|
72
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mstorage integration[2m > [22m[2mshould use provided state store
|
|
74
73
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
75
74
|
|
|
76
|
-
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[
|
|
75
|
+
[90mstderr[2m | tests/auth/OAuthClient.test.ts[2m > [22m[2mOAuthClient[2m > [22m[2mlogger integration[2m > [22m[2mshould use provided logger
|
|
77
76
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
78
77
|
|
|
79
|
-
[
|
|
78
|
+
[32m✓[39m tests/auth/OAuthClient.test.ts [2m([22m[2m14 tests[22m[2m)[22m[33m 307[2mms[22m[39m
|
|
79
|
+
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrestoreSession[2m > [22m[2mshould throw ValidationError for empty DID
|
|
80
80
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
81
81
|
|
|
82
|
-
[90mstderr[2m | tests/
|
|
82
|
+
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrestoreSession[2m > [22m[2mshould handle non-existent session
|
|
83
83
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
84
84
|
|
|
85
|
-
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[
|
|
85
|
+
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrevokeSession[2m > [22m[2mshould throw ValidationError for empty DID
|
|
86
86
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
87
87
|
|
|
88
|
-
[90mstderr[2m | tests/
|
|
88
|
+
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrepository[2m > [22m[2mshould throw ValidationError when session is null
|
|
89
89
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
90
90
|
|
|
91
|
-
[90mstderr[2m | tests/
|
|
91
|
+
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrepository[2m > [22m[2mshould throw ValidationError when PDS not configured and no server specified
|
|
92
92
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
93
93
|
|
|
94
|
-
[90mstderr[2m | tests/
|
|
94
|
+
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrepository[2m > [22m[2mshould throw ValidationError when SDS not configured and server=sds
|
|
95
95
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
96
96
|
|
|
97
|
-
[32m✓[39m tests/auth/OAuthClient.test.ts [2m([22m[2m14 tests[22m[2m)[22m[33m 356[2mms[22m[39m
|
|
98
97
|
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2mrepository[2m > [22m[2mshould create repository with custom serverUrl
|
|
99
98
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
100
99
|
|
|
@@ -107,12 +106,13 @@ No lock mechanism provided. Credentials might get revoked.
|
|
|
107
106
|
[90mstderr[2m | tests/core/SDK.test.ts[2m > [22m[2mATProtoSDK[2m > [22m[2msetup examples[2m > [22m[2mshould work with custom storage implementations
|
|
108
107
|
[22m[39mNo lock mechanism provided. Credentials might get revoked.
|
|
109
108
|
|
|
110
|
-
[32m✓[39m tests/core/SDK.test.ts [2m([22m[2m19 tests[22m[2m)[22m[32m
|
|
111
|
-
[32m✓[39m tests/repository/
|
|
109
|
+
[32m✓[39m tests/core/SDK.test.ts [2m([22m[2m19 tests[22m[2m)[22m[32m 194[2mms[22m[39m
|
|
110
|
+
[32m✓[39m tests/repository/Repository.test.ts [2m([22m[2m12 tests[22m[2m)[22m[32m 85[2mms[22m[39m
|
|
111
|
+
[32m✓[39m tests/repository/BlobOperationsImpl.test.ts [2m([22m[2m9 tests[22m[2m)[22m[32m 14[2mms[22m[39m
|
|
112
112
|
[32m✓[39m tests/core/errors.test.ts [2m([22m[2m9 tests[22m[2m)[22m[32m 5[2mms[22m[39m
|
|
113
113
|
|
|
114
114
|
[2m Test Files [22m [1m[32m11 passed[39m[22m[90m (11)[39m
|
|
115
|
-
[2m Tests [22m [1m[
|
|
116
|
-
[2m Start at [22m
|
|
117
|
-
[2m Duration [22m 2.
|
|
115
|
+
[2m Tests [22m [1m[32m181 passed[39m[22m[90m (181)[39m
|
|
116
|
+
[2m Start at [22m 22:12:42
|
|
117
|
+
[2m Duration [22m 2.16s[2m (transform 475ms, setup 0ms, collect 2.58s, tests 777ms, environment 3ms, prepare 1.11s)[22m
|
|
118
118
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hypercerts-org/sdk-core
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.4.0-beta.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
### Patch Changes
|
|
13
13
|
|
|
14
|
+
- [#55](https://github.com/hypercerts-org/hypercerts-sdk/pull/55)
|
|
15
|
+
[`23c3d9a`](https://github.com/hypercerts-org/hypercerts-sdk/commit/23c3d9a3b71f326df68b65420c83f7ae42c2432d) Thanks
|
|
16
|
+
[@bitbeckers](https://github.com/bitbeckers)! - Fix endpoints and NSIDs for SDS operations in CollaboratorOperations
|
|
17
|
+
and OrganizationOperations
|
|
18
|
+
|
|
14
19
|
- Updated dependencies
|
|
15
|
-
[[`
|
|
16
|
-
|
|
20
|
+
[[`23c3d9a`](https://github.com/hypercerts-org/hypercerts-sdk/commit/23c3d9a3b71f326df68b65420c83f7ae42c2432d),
|
|
21
|
+
[`eda4ac2`](https://github.com/hypercerts-org/hypercerts-sdk/commit/eda4ac233e09764d83f042ba7df94d4c9884cc01)]:
|
|
22
|
+
- @hypercerts-org/lexicon@0.4.0-beta.0
|
package/README.md
CHANGED
|
@@ -77,14 +77,57 @@ const existingSession = await sdk.restoreSession("did:plc:...");
|
|
|
77
77
|
|
|
78
78
|
```
|
|
79
79
|
repo
|
|
80
|
-
├── .records
|
|
81
|
-
├── .blobs
|
|
82
|
-
├── .profile
|
|
83
|
-
├── .hypercerts
|
|
84
|
-
├── .collaborators → grant, revoke, list, hasAccess (SDS only)
|
|
80
|
+
├── .records → create, get, update, delete, list
|
|
81
|
+
├── .blobs → upload, get
|
|
82
|
+
├── .profile → get, update (PDS only)
|
|
83
|
+
├── .hypercerts → create, get, update, delete, list, addContribution, addMeasurement
|
|
84
|
+
├── .collaborators → grant, revoke, list, hasAccess, getRole, getPermissions, transferOwnership (SDS only)
|
|
85
85
|
└── .organizations → create, get, list (SDS only)
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
+
### Collaborator Operations (SDS only)
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Grant access to a user
|
|
92
|
+
await repo.collaborators.grant({
|
|
93
|
+
userDid: "did:plc:user123",
|
|
94
|
+
role: "editor", // viewer | editor | admin | owner
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Revoke access
|
|
98
|
+
await repo.collaborators.revoke({ userDid: "did:plc:user123" });
|
|
99
|
+
|
|
100
|
+
// List all collaborators
|
|
101
|
+
const collaborators = await repo.collaborators.list();
|
|
102
|
+
|
|
103
|
+
// Check if user has access
|
|
104
|
+
const hasAccess = await repo.collaborators.hasAccess("did:plc:user123");
|
|
105
|
+
|
|
106
|
+
// Get user's role
|
|
107
|
+
const role = await repo.collaborators.getRole("did:plc:user123");
|
|
108
|
+
|
|
109
|
+
// Get current user's permissions
|
|
110
|
+
const permissions = await repo.collaborators.getPermissions();
|
|
111
|
+
if (permissions.admin) {
|
|
112
|
+
// Can manage collaborators
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Transfer ownership (irreversible!)
|
|
116
|
+
await repo.collaborators.transferOwnership({
|
|
117
|
+
newOwnerDid: "did:plc:new-owner",
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### SDS vs PDS Operations
|
|
122
|
+
|
|
123
|
+
| Operation | PDS | SDS | Namespace |
|
|
124
|
+
|-----------|-----|-----|-----------|
|
|
125
|
+
| Records (CRUD) | ✅ | ✅ | `com.atproto.repo.*` |
|
|
126
|
+
| Blobs | ✅ | ✅ | `com.atproto.repo.uploadBlob`, `com.atproto.sync.getBlob` |
|
|
127
|
+
| Profile | ✅ | ❌ | `app.bsky.actor.profile` |
|
|
128
|
+
| Organizations | ❌ | ✅ | `com.sds.organization.*` |
|
|
129
|
+
| Collaborators | ❌ | ✅ | `com.sds.repo.*` |
|
|
130
|
+
|
|
88
131
|
## Errors
|
|
89
132
|
|
|
90
133
|
```typescript
|
package/dist/index.cjs
CHANGED
|
@@ -3041,9 +3041,11 @@ class HypercertOperationsImpl extends eventemitter3.EventEmitter {
|
|
|
3041
3041
|
* - `owner`: Full control including ownership management
|
|
3042
3042
|
*
|
|
3043
3043
|
* **SDS API Endpoints Used**:
|
|
3044
|
-
* - `com.
|
|
3045
|
-
* - `com.
|
|
3046
|
-
* - `com.
|
|
3044
|
+
* - `com.sds.repo.grantAccess`: Grant access to a user
|
|
3045
|
+
* - `com.sds.repo.revokeAccess`: Revoke access from a user
|
|
3046
|
+
* - `com.sds.repo.listCollaborators`: List all collaborators
|
|
3047
|
+
* - `com.sds.repo.getPermissions`: Get current user's permissions
|
|
3048
|
+
* - `com.sds.repo.transferOwnership`: Transfer repository ownership
|
|
3047
3049
|
*
|
|
3048
3050
|
* @example
|
|
3049
3051
|
* ```typescript
|
|
@@ -3145,7 +3147,7 @@ class CollaboratorOperationsImpl {
|
|
|
3145
3147
|
*/
|
|
3146
3148
|
async grant(params) {
|
|
3147
3149
|
const permissions = this.roleToPermissions(params.role);
|
|
3148
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3150
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.grantAccess`, {
|
|
3149
3151
|
method: "POST",
|
|
3150
3152
|
headers: { "Content-Type": "application/json" },
|
|
3151
3153
|
body: JSON.stringify({
|
|
@@ -3177,7 +3179,7 @@ class CollaboratorOperationsImpl {
|
|
|
3177
3179
|
* ```
|
|
3178
3180
|
*/
|
|
3179
3181
|
async revoke(params) {
|
|
3180
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3182
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.revokeAccess`, {
|
|
3181
3183
|
method: "POST",
|
|
3182
3184
|
headers: { "Content-Type": "application/json" },
|
|
3183
3185
|
body: JSON.stringify({
|
|
@@ -3216,7 +3218,7 @@ class CollaboratorOperationsImpl {
|
|
|
3216
3218
|
* ```
|
|
3217
3219
|
*/
|
|
3218
3220
|
async list() {
|
|
3219
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3221
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.listCollaborators?repo=${encodeURIComponent(this.repoDid)}`, { method: "GET" });
|
|
3220
3222
|
if (!response.ok) {
|
|
3221
3223
|
throw new NetworkError(`Failed to list collaborators: ${response.statusText}`);
|
|
3222
3224
|
}
|
|
@@ -3277,6 +3279,104 @@ class CollaboratorOperationsImpl {
|
|
|
3277
3279
|
const collab = collaborators.find((c) => c.userDid === userDid && !c.revokedAt);
|
|
3278
3280
|
return collab?.role ?? null;
|
|
3279
3281
|
}
|
|
3282
|
+
/**
|
|
3283
|
+
* Gets the current user's permissions for this repository.
|
|
3284
|
+
*
|
|
3285
|
+
* @returns Promise resolving to the permission flags
|
|
3286
|
+
* @throws {@link NetworkError} if the request fails
|
|
3287
|
+
*
|
|
3288
|
+
* @remarks
|
|
3289
|
+
* This is useful for checking what actions the current user can perform
|
|
3290
|
+
* before attempting operations that might fail due to insufficient permissions.
|
|
3291
|
+
*
|
|
3292
|
+
* @example
|
|
3293
|
+
* ```typescript
|
|
3294
|
+
* const permissions = await repo.collaborators.getPermissions();
|
|
3295
|
+
*
|
|
3296
|
+
* if (permissions.admin) {
|
|
3297
|
+
* // Show admin UI
|
|
3298
|
+
* console.log("You can manage collaborators");
|
|
3299
|
+
* }
|
|
3300
|
+
*
|
|
3301
|
+
* if (permissions.create) {
|
|
3302
|
+
* console.log("You can create records");
|
|
3303
|
+
* }
|
|
3304
|
+
* ```
|
|
3305
|
+
*
|
|
3306
|
+
* @example Conditional UI rendering
|
|
3307
|
+
* ```typescript
|
|
3308
|
+
* const permissions = await repo.collaborators.getPermissions();
|
|
3309
|
+
*
|
|
3310
|
+
* // Show/hide UI elements based on permissions
|
|
3311
|
+
* const canEdit = permissions.update;
|
|
3312
|
+
* const canDelete = permissions.delete;
|
|
3313
|
+
* const isAdmin = permissions.admin;
|
|
3314
|
+
* const isOwner = permissions.owner;
|
|
3315
|
+
* ```
|
|
3316
|
+
*/
|
|
3317
|
+
async getPermissions() {
|
|
3318
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.getPermissions?repo=${encodeURIComponent(this.repoDid)}`, { method: "GET" });
|
|
3319
|
+
if (!response.ok) {
|
|
3320
|
+
throw new NetworkError(`Failed to get permissions: ${response.statusText}`);
|
|
3321
|
+
}
|
|
3322
|
+
const data = await response.json();
|
|
3323
|
+
return data.permissions;
|
|
3324
|
+
}
|
|
3325
|
+
/**
|
|
3326
|
+
* Transfers repository ownership to another user.
|
|
3327
|
+
*
|
|
3328
|
+
* @param params - Transfer parameters
|
|
3329
|
+
* @param params.newOwnerDid - DID of the user to transfer ownership to
|
|
3330
|
+
* @throws {@link NetworkError} if the transfer fails
|
|
3331
|
+
*
|
|
3332
|
+
* @remarks
|
|
3333
|
+
* **IMPORTANT**: This action is irreversible. Once ownership is transferred:
|
|
3334
|
+
* - The new owner gains full control of the repository
|
|
3335
|
+
* - Your role will be changed to admin (or specified role)
|
|
3336
|
+
* - You cannot transfer ownership back without the new owner's approval
|
|
3337
|
+
*
|
|
3338
|
+
* **Requirements**:
|
|
3339
|
+
* - You must be the current owner
|
|
3340
|
+
* - The new owner must have an existing account
|
|
3341
|
+
* - The new owner will be notified of the ownership transfer
|
|
3342
|
+
*
|
|
3343
|
+
* @example
|
|
3344
|
+
* ```typescript
|
|
3345
|
+
* // Transfer ownership to another user
|
|
3346
|
+
* await repo.collaborators.transferOwnership({
|
|
3347
|
+
* newOwnerDid: "did:plc:new-owner",
|
|
3348
|
+
* });
|
|
3349
|
+
*
|
|
3350
|
+
* console.log("Ownership transferred successfully");
|
|
3351
|
+
* // You are now an admin, not the owner
|
|
3352
|
+
* ```
|
|
3353
|
+
*
|
|
3354
|
+
* @example With confirmation
|
|
3355
|
+
* ```typescript
|
|
3356
|
+
* const confirmTransfer = await askUser(
|
|
3357
|
+
* "Are you sure you want to transfer ownership? This cannot be undone."
|
|
3358
|
+
* );
|
|
3359
|
+
*
|
|
3360
|
+
* if (confirmTransfer) {
|
|
3361
|
+
* await repo.collaborators.transferOwnership({
|
|
3362
|
+
* newOwnerDid: "did:plc:new-owner",
|
|
3363
|
+
* });
|
|
3364
|
+
* }
|
|
3365
|
+
* ```
|
|
3366
|
+
*/
|
|
3367
|
+
async transferOwnership(params) {
|
|
3368
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.repo.transferOwnership`, {
|
|
3369
|
+
method: "POST",
|
|
3370
|
+
headers: { "Content-Type": "application/json" },
|
|
3371
|
+
body: JSON.stringify({
|
|
3372
|
+
repo: this.repoDid,
|
|
3373
|
+
newOwner: params.newOwnerDid,
|
|
3374
|
+
}),
|
|
3375
|
+
});
|
|
3376
|
+
if (!response.ok) {
|
|
3377
|
+
throw new NetworkError(`Failed to transfer ownership: ${response.statusText}`);
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3280
3380
|
}
|
|
3281
3381
|
|
|
3282
3382
|
/**
|
|
@@ -3303,8 +3403,8 @@ class CollaboratorOperationsImpl {
|
|
|
3303
3403
|
* {@link Repository.organizations} on an SDS-connected repository.
|
|
3304
3404
|
*
|
|
3305
3405
|
* **SDS API Endpoints Used**:
|
|
3306
|
-
* - `com.
|
|
3307
|
-
* - `com.
|
|
3406
|
+
* - `com.sds.organization.create`: Create a new organization
|
|
3407
|
+
* - `com.sds.organization.list`: List accessible organizations
|
|
3308
3408
|
*
|
|
3309
3409
|
* **Access Types**:
|
|
3310
3410
|
* - `"owner"`: User created or owns the organization
|
|
@@ -3382,7 +3482,7 @@ class OrganizationOperationsImpl {
|
|
|
3382
3482
|
* ```
|
|
3383
3483
|
*/
|
|
3384
3484
|
async create(params) {
|
|
3385
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3485
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.organization.create`, {
|
|
3386
3486
|
method: "POST",
|
|
3387
3487
|
headers: { "Content-Type": "application/json" },
|
|
3388
3488
|
body: JSON.stringify(params),
|
|
@@ -3472,7 +3572,7 @@ class OrganizationOperationsImpl {
|
|
|
3472
3572
|
* ```
|
|
3473
3573
|
*/
|
|
3474
3574
|
async list() {
|
|
3475
|
-
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.
|
|
3575
|
+
const response = await this.session.fetchHandler(`${this.serverUrl}/xrpc/com.sds.organization.list?userDid=${encodeURIComponent(this.session.did || this.session.sub)}`, { method: "GET" });
|
|
3476
3576
|
if (!response.ok) {
|
|
3477
3577
|
throw new NetworkError(`Failed to list organizations: ${response.statusText}`);
|
|
3478
3578
|
}
|