Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-agent-service-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hypercerts-org/sdk-core": patch
---

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.
5 changes: 5 additions & 0 deletions .changeset/fix-collaborator-permissions-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hypercerts-org/sdk-core": patch
---

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.
7 changes: 7 additions & 0 deletions .changeset/pagination-and-react-hooks-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Add pagination support and fix React hooks for SDS operations
- Support optional `limit` and `cursor` parameters for paginated queries
- Update internal methods (`hasAccess`, `getRole`, `get`) to handle new pagination structure

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

**Bug Fixes (sdk-react):**
- Fix `useCollaborators` hook to correctly destructure paginated response
- Fix `useOrganizations` hook to correctly destructure paginated response
Expand Down
27 changes: 14 additions & 13 deletions packages/sdk-core/src/repository/CollaboratorOperationsImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,24 @@ export class CollaboratorOperationsImpl implements CollaboratorOperations {
}

/**
* Converts a permission string array to a permissions object.
* Normalizes permissions from SDS API format to SDK format.
*
* The SDS API returns permissions as an array of strings (e.g., ["read", "create"]).
* This method converts them to the boolean flag format used by the SDK.
* The SDS API returns permissions as an object with boolean flags
* (e.g., `{ read: true, create: true, update: false, ... }`).
* This method ensures all expected fields are present with default values.
*
* @param permissionArray - Array of permission strings from SDS API
* @returns Permission flags object
* @param permissions - Permissions object from SDS API
* @returns Normalized permission flags object
* @internal
*/
private parsePermissions(permissionArray: string[]): CollaboratorPermissions {
private parsePermissions(permissions: CollaboratorPermissions): CollaboratorPermissions {
return {
read: permissionArray.includes("read"),
create: permissionArray.includes("create"),
update: permissionArray.includes("update"),
delete: permissionArray.includes("delete"),
admin: permissionArray.includes("admin"),
owner: permissionArray.includes("owner"),
read: permissions.read ?? false,
create: permissions.create ?? false,
update: permissions.update ?? false,
delete: permissions.delete ?? false,
admin: permissions.admin ?? false,
owner: permissions.owner ?? false,
};
}

Expand Down Expand Up @@ -263,7 +264,7 @@ export class CollaboratorOperationsImpl implements CollaboratorOperations {
const collaborators = (data.collaborators || []).map(
(c: {
userDid: string;
permissions: string[]; // SDS API returns string array
permissions: CollaboratorPermissions; // SDS API returns object with boolean flags
grantedBy: string;
grantedAt: string;
revokedAt?: string;
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk-core/src/repository/Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ export class Repository {

// Create Agent with OAuth session
this.agent = new Agent(session);

// Configure Agent to use the specified server URL (PDS or SDS)
// This ensures queries are routed to the correct server
this.agent.api.xrpc.uri = new URL(serverUrl);

this.lexiconRegistry.addToAgent(this.agent);

// Register hypercert lexicons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { NetworkError } from "../../src/core/errors.js";

describe("CollaboratorOperationsImpl", () => {
let mockSession: any;

Check warning on line 6 in packages/sdk-core/tests/repository/CollaboratorOperationsImpl.test.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected any. Specify a different type
let collaboratorOps: CollaboratorOperationsImpl;
const repoDid = "did:plc:testdid123";
const serverUrl = "https://sds.example.com";
Expand Down Expand Up @@ -131,13 +131,13 @@
collaborators: [
{
userDid: "did:plc:user1",
permissions: ["read", "create", "update"],
permissions: { read: true, create: true, update: true, delete: false, admin: false, owner: false },
grantedBy: "did:plc:owner",
grantedAt: "2024-01-01T00:00:00Z",
},
{
userDid: "did:plc:user2",
permissions: ["read"],
permissions: { read: true, create: false, update: false, delete: false, admin: false, owner: false },
grantedBy: "did:plc:owner",
grantedAt: "2024-01-02T00:00:00Z",
},
Expand Down Expand Up @@ -171,13 +171,13 @@
collaborators: [
{
userDid: "did:plc:owner",
permissions: ["read", "create", "update", "delete", "admin", "owner"],
permissions: { read: true, create: true, update: true, delete: true, admin: true, owner: true },
grantedBy: "did:plc:system",
grantedAt: "2024-01-01T00:00:00Z",
},
{
userDid: "did:plc:admin",
permissions: ["read", "create", "update", "delete", "admin"],
permissions: { read: true, create: true, update: true, delete: true, admin: true, owner: false },
grantedBy: "did:plc:owner",
grantedAt: "2024-01-01T00:00:00Z",
},
Expand Down Expand Up @@ -209,7 +209,7 @@
collaborators: [
{
userDid: "did:plc:activeuser",
permissions: ["read"],
permissions: { read: true, create: false, update: false, delete: false, admin: false, owner: false },
grantedBy: "did:plc:owner",
grantedAt: "2024-01-01T00:00:00Z",
},
Expand Down Expand Up @@ -240,7 +240,7 @@
collaborators: [
{
userDid: "did:plc:revokeduser",
permissions: ["read"],
permissions: { read: true, create: false, update: false, delete: false, admin: false, owner: false },
grantedBy: "did:plc:owner",
grantedAt: "2024-01-01T00:00:00Z",
revokedAt: "2024-02-01T00:00:00Z",
Expand Down Expand Up @@ -271,7 +271,7 @@
collaborators: [
{
userDid: "did:plc:editor",
permissions: ["read", "create", "update"],
permissions: { read: true, create: true, update: true, delete: false, admin: false, owner: false },
grantedBy: "did:plc:owner",
grantedAt: "2024-01-01T00:00:00Z",
},
Expand Down Expand Up @@ -302,7 +302,7 @@
collaborators: [
{
userDid: "did:plc:revoked",
permissions: ["read", "create", "update"],
permissions: { read: true, create: true, update: true, delete: false, admin: false, owner: false },
grantedBy: "did:plc:owner",
grantedAt: "2024-01-01T00:00:00Z",
revokedAt: "2024-02-01T00:00:00Z",
Expand Down
Loading
Loading