@ -10,12 +10,8 @@
import {
import {
OffersResponse ,
OffersResponse ,
OfferSummaryRecord ,
OffersToPlansResponse ,
OffersToPlansResponse ,
OfferToPlanSummaryRecord ,
PlansLastUpdatedResponse ,
PlansLastUpdatedResponse ,
PlanSummaryWithPreviousClaim ,
PlanSummary ,
TimeSafariNotificationBundle ,
TimeSafariNotificationBundle ,
TimeSafariUserConfig ,
TimeSafariUserConfig ,
TimeSafariNotificationType
TimeSafariNotificationType
@ -82,7 +78,7 @@ export class EndorserAPIClient {
/ * *
/ * *
* Generate JWT token for DID - based authentication
* Generate JWT token for DID - based authentication
* /
* /
async generateJWTForDID ( activeDid : string , jwtSecret? : string ) : Promise < string > {
async generateJWTForDID ( activeDid : string , _ jwtSecret? : string ) : Promise < string > {
try {
try {
// In a real implementation, this would use a JWT library like di-djwt
// In a real implementation, this would use a JWT library like di-djwt
// For Phase 4, we'll generate a mock JWT structure
// For Phase 4, we'll generate a mock JWT structure
@ -107,7 +103,7 @@ export class EndorserAPIClient {
} catch ( error ) {
} catch ( error ) {
console . error ( 'Error generating JWT for DID:' , error ) ;
console . error ( 'Error generating JWT for DID:' , error ) ;
throw new Error ( ` JWT generation failed: ${ error . message } ` ) ;
throw new Error ( ` JWT generation failed: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
}
}
}
}
@ -139,7 +135,7 @@ export class EndorserAPIClient {
return response as OffersResponse ;
return response as OffersResponse ;
} catch ( error ) {
} catch ( error ) {
console . error ( 'Error fetching offers to person:' , error ) ;
console . error ( 'Error fetching offers to person:' , error instanceof Error ? error . message : 'Unknown error' ) ;
return { data : [ ] , hitLimit : false } ;
return { data : [ ] , hitLimit : false } ;
}
}
}
}
@ -167,7 +163,7 @@ export class EndorserAPIClient {
return response as OffersToPlansResponse ;
return response as OffersToPlansResponse ;
} catch ( error ) {
} catch ( error ) {
console . error ( 'Error fetching offers to projects:' , error ) ;
console . error ( 'Error fetching offers to projects:' , error instanceof Error ? error . message : 'Unknown error' ) ;
return { data : [ ] , hitLimit : false } ;
return { data : [ ] , hitLimit : false } ;
}
}
}
}
@ -198,7 +194,7 @@ export class EndorserAPIClient {
return response as PlansLastUpdatedResponse ;
return response as PlansLastUpdatedResponse ;
} catch ( error ) {
} catch ( error ) {
console . error ( 'Error fetching project updates:' , error ) ;
console . error ( 'Error fetching project updates:' , error instanceof Error ? error . message : 'Unknown error' ) ;
return { data : [ ] , hitLimit : false } ;
return { data : [ ] , hitLimit : false } ;
}
}
}
}
@ -281,9 +277,9 @@ export class EndorserAPIClient {
bundle . success = true ;
bundle . success = true ;
} catch ( error ) {
} catch ( error ) {
console . error ( 'Error fetching TimeSafari notifications:' , error ) ;
console . error ( 'Error fetching TimeSafari notifications:' , error instanceof Error ? error . message : 'Unknown error' ) ;
bundle . success = false ;
bundle . success = false ;
bundle . error = error . message ;
bundle . error = error instanceof Error ? error . message : 'Unknown error' ;
// Ensure we have partial data even on error
// Ensure we have partial data even on error
bundle . metadata ! . networkResponses = bundle . metadata ! . networkResponses || 0 ;
bundle . metadata ! . networkResponses = bundle . metadata ! . networkResponses || 0 ;
@ -351,7 +347,20 @@ export class EndorserAPIClient {
notifications . push ( {
notifications . push ( {
type : 'offer' ,
type : 'offer' ,
subtype : 'new_to_projects' ,
subtype : 'new_to_projects' ,
offer : offerToPlan ,
offer : {
jwtId : offerToPlan.jwtId ,
handleId : offerToPlan.handleId ,
issuedAt : offerToPlan.issuedAt ,
offeredByDid : offerToPlan.offeredByDid ,
recipientDid : '' , // Placeholder - would be derived from context
unit : offerToPlan.unit ,
amount : offerToPlan.amount ,
amountGiven : offerToPlan.amountGiven ,
amountGivenConfirmed : 0 , // Placeholder
objectDescription : offerToPlan.objectDescription ,
validThrough : offerToPlan.validThrough ,
fullClaim : { } // Placeholder
} ,
relevantProjects : [ ] , // Would be populated from plan lookup
relevantProjects : [ ] , // Would be populated from plan lookup
notificationPriority : 'medium' ,
notificationPriority : 'medium' ,
timestamp : Date.now ( )
timestamp : Date.now ( )
@ -412,6 +421,7 @@ export class EndorserAPIClient {
notifications . push ( {
notifications . push ( {
type : 'person' ,
type : 'person' ,
subtype : 'with_content_and_new' ,
subtype : 'with_content_and_new' ,
personDid : did ,
person : { did , name : ` User- ${ did . slice ( - 6 ) } ` } , // Placeholder name
person : { did , name : ` User- ${ did . slice ( - 6 ) } ` } , // Placeholder name
notificationPriority : 'low' ,
notificationPriority : 'low' ,
timestamp : Date.now ( )
timestamp : Date.now ( )
@ -436,6 +446,7 @@ export class EndorserAPIClient {
notifications . push ( {
notifications . push ( {
type : 'item' ,
type : 'item' ,
subtype : 'favorite_and_changed' ,
subtype : 'favorite_and_changed' ,
itemId : update.plan.jwtId ,
item : {
item : {
id : update.plan.jwtId ,
id : update.plan.jwtId ,
name : update.plan.name ,
name : update.plan.name ,
@ -559,9 +570,9 @@ export class EndorserAPIClient {
}
}
} catch ( error ) {
} catch ( error ) {
lastError = error instanceof EndorserAPIError ? error : new Error ( error . message ) ;
lastError = error instanceof EndorserAPIError ? error : new Error ( error instanceof Error ? error . message : 'Unknown error' ) ;
if ( ! lastError . retryable || attempt >= this . config . maxRetries ) {
if ( ! ( lastError instanceof EndorserAPIError && lastError . retryable ) || attempt >= this . config . maxRetries ) {
throw lastError ;
throw lastError ;
}
}
@ -622,7 +633,7 @@ export class EndorserAPIClient {
/ * *
/ * *
* Error class for EndorserAPI errors
* Error class for EndorserAPI errors
* /
* /
class EndorserAPIError extends Error {
export class EndorserAPIError extends Error {
constructor (
constructor (
public statusCode : number ,
public statusCode : number ,
public message : string ,
public message : string ,