-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose functions for experimental subject issuer support
- Loading branch information
Showing
5 changed files
with
78 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NotificationErrorResponse, NotificationRequest, NotificationResult, post } from '@sphereon/oid4vci-common'; | ||
|
||
import { CredentialRequestOpts } from '../CredentialRequestClient'; | ||
import { LOG } from '../types'; | ||
|
||
export async function sendNotification( | ||
credentialRequestOpts: CredentialRequestOpts, | ||
request: NotificationRequest, | ||
accessToken?: string, | ||
): Promise<NotificationResult> { | ||
LOG.info(`Sending status notification event '${request.event}' for id ${request.notification_id}`); | ||
if (!credentialRequestOpts.notificationEndpoint) { | ||
throw Error(`Cannot send notification when no notification endpoint is provided`); | ||
} | ||
const token = accessToken ?? credentialRequestOpts.token; | ||
const response = await post<NotificationErrorResponse>(credentialRequestOpts.notificationEndpoint, JSON.stringify(request), { | ||
bearerToken: token, | ||
}); | ||
const error = response.errorBody?.error !== undefined; | ||
const result = { | ||
error, | ||
response: error ? await response.errorBody?.json() : undefined, | ||
}; | ||
if (error) { | ||
LOG.warning( | ||
`Notification endpoint returned an error for event '${request.event}' and id ${request.notification_id}: ${await response.errorBody?.json()}`, | ||
); | ||
} else { | ||
LOG.debug(`Notification endpoint returned success for event '${request.event}' and id ${request.notification_id}`); | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters