Skip to content

Commit

Permalink
skip when grants are not present in sync
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Aug 20, 2024
1 parent a0eb0be commit 0722666
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions packages/agent/src/sync-engine-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,20 @@ export class SyncEngineLevel implements SyncEngine {
let permissionGrantId: string | undefined;
let granteeDid: string | undefined;
if (delegateDid) {
const messagesReadGrant = await this._cachedPermissionsApi.getPermission({
connectedDid : did,
messageType : DwnInterface.MessagesRead,
delegateDid,
protocol,
});

permissionGrantId = messagesReadGrant.grant.id;
granteeDid = delegateDid;
try {
const messagesReadGrant = await this._cachedPermissionsApi.getPermission({
connectedDid : did,
messageType : DwnInterface.MessagesRead,
delegateDid,
protocol,
});

permissionGrantId = messagesReadGrant.grant.id;
granteeDid = delegateDid;
} catch(error:any) {
console.log('SyncEngineLevel: Error fetching permission grant for delegate DID', error);
continue;
}
}

const messagesRead = await this.agent.processDwnRequest({
Expand Down Expand Up @@ -394,15 +399,20 @@ export class SyncEngineLevel implements SyncEngine {
let granteeDid: string | undefined;
if (delegateDid) {
// fetch the grants for the delegate DID
const messagesQueryGrant = await this._cachedPermissionsApi.getPermission({
connectedDid : did,
messageType : DwnInterface.MessagesQuery,
delegateDid,
protocol,
});
try {
const messagesReadGrant = await this._cachedPermissionsApi.getPermission({
connectedDid : did,
messageType : DwnInterface.MessagesQuery,
delegateDid,
protocol,
});

permissionGrantId = messagesQueryGrant.grant.id;
granteeDid = delegateDid;
permissionGrantId = messagesReadGrant.grant.id;
granteeDid = delegateDid;
} catch(error:any) {
console.log('SyncEngineLevel: Error fetching permission grant for delegate DID', error);
return;
}
}

if (syncDirection === 'pull') {
Expand Down Expand Up @@ -460,15 +470,20 @@ export class SyncEngineLevel implements SyncEngine {
let granteeDid: string | undefined;

if (delegateDid) {
const messagesReadGrant = await this._cachedPermissionsApi.getPermission({
connectedDid : author,
messageType : DwnInterface.MessagesRead,
delegateDid,
protocol,
});
try {
const messagesReadGrant = await this._cachedPermissionsApi.getPermission({
connectedDid : author,
messageType : DwnInterface.MessagesRead,
delegateDid,
protocol,
});

permissionGrantId = messagesReadGrant.grant.id;
granteeDid = delegateDid;
permissionGrantId = messagesReadGrant.grant.id;
granteeDid = delegateDid;
} catch(error:any) {
console.log('SyncEngineLevel: Error fetching permission grant for delegate DID', error);
return;
}
}

let { reply } = await this.agent.dwn.processRequest({
Expand Down

0 comments on commit 0722666

Please sign in to comment.