Skip to content

Commit 568bb96

Browse files
authored
Merge pull request #58 from hypercerts-org/fix/sds_record_queries
SDS record queries
2 parents d62f773 + 3dfaf35 commit 568bb96

File tree

7 files changed

+526
-21
lines changed

7 files changed

+526
-21
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hypercerts-org/sdk-core": patch
3+
---
4+
5+
Fix Agent service URL configuration to ensure queries are routed to the correct server (PDS or SDS). The Agent now explicitly uses the serverUrl provided to the Repository constructor, resolving "Could not find repo" errors when querying SDS repositories.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hypercerts-org/sdk-core": patch
3+
---
4+
5+
Fix collaborator permissions parsing to align with SDS API response format. The SDS API returns permissions as objects with boolean flags (`{ read: true, create: true, ... }`) rather than string arrays. This fix simplifies the permissions parser to handle only the actual format returned by the API.

.changeset/pagination-and-react-hooks-fix.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Add pagination support and fix React hooks for SDS operations
1414
- Support optional `limit` and `cursor` parameters for paginated queries
1515
- Update internal methods (`hasAccess`, `getRole`, `get`) to handle new pagination structure
1616

17+
**Bug Fixes (sdk-core):**
18+
- Fix permissions parsing in `CollaboratorOperationsImpl.list()` to match actual SDS API format (object with boolean flags)
19+
- Prevent `TypeError: permissionArray.includes is not a function` by correctly handling permissions as objects
20+
- Fix Agent service URL configuration to route queries to the correct server (PDS or SDS)
21+
- Resolve "Could not find repo" errors when querying SDS repositories by ensuring Agent uses SDS service endpoint
22+
- Update test mocks to use the actual SDS API response format
23+
1724
**Bug Fixes (sdk-react):**
1825
- Fix `useCollaborators` hook to correctly destructure paginated response
1926
- Fix `useOrganizations` hook to correctly destructure paginated response

packages/sdk-core/src/repository/CollaboratorOperationsImpl.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,24 @@ export class CollaboratorOperationsImpl implements CollaboratorOperations {
108108
}
109109

110110
/**
111-
* Converts a permission string array to a permissions object.
111+
* Normalizes permissions from SDS API format to SDK format.
112112
*
113-
* The SDS API returns permissions as an array of strings (e.g., ["read", "create"]).
114-
* This method converts them to the boolean flag format used by the SDK.
113+
* The SDS API returns permissions as an object with boolean flags
114+
* (e.g., `{ read: true, create: true, update: false, ... }`).
115+
* This method ensures all expected fields are present with default values.
115116
*
116-
* @param permissionArray - Array of permission strings from SDS API
117-
* @returns Permission flags object
117+
* @param permissions - Permissions object from SDS API
118+
* @returns Normalized permission flags object
118119
* @internal
119120
*/
120-
private parsePermissions(permissionArray: string[]): CollaboratorPermissions {
121+
private parsePermissions(permissions: CollaboratorPermissions): CollaboratorPermissions {
121122
return {
122-
read: permissionArray.includes("read"),
123-
create: permissionArray.includes("create"),
124-
update: permissionArray.includes("update"),
125-
delete: permissionArray.includes("delete"),
126-
admin: permissionArray.includes("admin"),
127-
owner: permissionArray.includes("owner"),
123+
read: permissions.read ?? false,
124+
create: permissions.create ?? false,
125+
update: permissions.update ?? false,
126+
delete: permissions.delete ?? false,
127+
admin: permissions.admin ?? false,
128+
owner: permissions.owner ?? false,
128129
};
129130
}
130131

@@ -263,7 +264,7 @@ export class CollaboratorOperationsImpl implements CollaboratorOperations {
263264
const collaborators = (data.collaborators || []).map(
264265
(c: {
265266
userDid: string;
266-
permissions: string[]; // SDS API returns string array
267+
permissions: CollaboratorPermissions; // SDS API returns object with boolean flags
267268
grantedBy: string;
268269
grantedAt: string;
269270
revokedAt?: string;

packages/sdk-core/src/repository/Repository.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ export class Repository {
181181

182182
// Create Agent with OAuth session
183183
this.agent = new Agent(session);
184+
185+
// Configure Agent to use the specified server URL (PDS or SDS)
186+
// This ensures queries are routed to the correct server
187+
this.agent.api.xrpc.uri = new URL(serverUrl);
188+
184189
this.lexiconRegistry.addToAgent(this.agent);
185190

186191
// Register hypercert lexicons

packages/sdk-core/tests/repository/CollaboratorOperationsImpl.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ describe("CollaboratorOperationsImpl", () => {
131131
collaborators: [
132132
{
133133
userDid: "did:plc:user1",
134-
permissions: ["read", "create", "update"],
134+
permissions: { read: true, create: true, update: true, delete: false, admin: false, owner: false },
135135
grantedBy: "did:plc:owner",
136136
grantedAt: "2024-01-01T00:00:00Z",
137137
},
138138
{
139139
userDid: "did:plc:user2",
140-
permissions: ["read"],
140+
permissions: { read: true, create: false, update: false, delete: false, admin: false, owner: false },
141141
grantedBy: "did:plc:owner",
142142
grantedAt: "2024-01-02T00:00:00Z",
143143
},
@@ -171,13 +171,13 @@ describe("CollaboratorOperationsImpl", () => {
171171
collaborators: [
172172
{
173173
userDid: "did:plc:owner",
174-
permissions: ["read", "create", "update", "delete", "admin", "owner"],
174+
permissions: { read: true, create: true, update: true, delete: true, admin: true, owner: true },
175175
grantedBy: "did:plc:system",
176176
grantedAt: "2024-01-01T00:00:00Z",
177177
},
178178
{
179179
userDid: "did:plc:admin",
180-
permissions: ["read", "create", "update", "delete", "admin"],
180+
permissions: { read: true, create: true, update: true, delete: true, admin: true, owner: false },
181181
grantedBy: "did:plc:owner",
182182
grantedAt: "2024-01-01T00:00:00Z",
183183
},
@@ -209,7 +209,7 @@ describe("CollaboratorOperationsImpl", () => {
209209
collaborators: [
210210
{
211211
userDid: "did:plc:activeuser",
212-
permissions: ["read"],
212+
permissions: { read: true, create: false, update: false, delete: false, admin: false, owner: false },
213213
grantedBy: "did:plc:owner",
214214
grantedAt: "2024-01-01T00:00:00Z",
215215
},
@@ -240,7 +240,7 @@ describe("CollaboratorOperationsImpl", () => {
240240
collaborators: [
241241
{
242242
userDid: "did:plc:revokeduser",
243-
permissions: ["read"],
243+
permissions: { read: true, create: false, update: false, delete: false, admin: false, owner: false },
244244
grantedBy: "did:plc:owner",
245245
grantedAt: "2024-01-01T00:00:00Z",
246246
revokedAt: "2024-02-01T00:00:00Z",
@@ -271,7 +271,7 @@ describe("CollaboratorOperationsImpl", () => {
271271
collaborators: [
272272
{
273273
userDid: "did:plc:editor",
274-
permissions: ["read", "create", "update"],
274+
permissions: { read: true, create: true, update: true, delete: false, admin: false, owner: false },
275275
grantedBy: "did:plc:owner",
276276
grantedAt: "2024-01-01T00:00:00Z",
277277
},
@@ -302,7 +302,7 @@ describe("CollaboratorOperationsImpl", () => {
302302
collaborators: [
303303
{
304304
userDid: "did:plc:revoked",
305-
permissions: ["read", "create", "update"],
305+
permissions: { read: true, create: true, update: true, delete: false, admin: false, owner: false },
306306
grantedBy: "did:plc:owner",
307307
grantedAt: "2024-01-01T00:00:00Z",
308308
revokedAt: "2024-02-01T00:00:00Z",

0 commit comments

Comments
 (0)