-
Notifications
You must be signed in to change notification settings - Fork 482
[Feature] Productionize Record Scanner Interface #1182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iamalwaysuncomfortable
wants to merge
7
commits into
mainnet
Choose a base branch
from
feature/libsodium-rss
base: mainnet
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+978
−158
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
635df69
Add encrypted registration to the record scanner
iamalwaysuncomfortable ce81450
Update record scanner flow to handle error responses from the registr…
iamalwaysuncomfortable 846baf3
Add record scanner URL secret to CI
iamalwaysuncomfortable dabe3b0
Add stored cookie to DPS calls
iamalwaysuncomfortable 360389b
Isolate registration error
iamalwaysuncomfortable 0d8b7e3
Add cached vks to RecordScanner implementation, add separate /owned e…
iamalwaysuncomfortable 36f97f4
Add a safe method for the encrypted endpoint
iamalwaysuncomfortable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,16 @@ | ||
| import type { RecordScannerErrorBody } from "./error.js"; | ||
| import type { EncryptedRecord } from "../record-provider/encryptedRecord.js"; | ||
|
|
||
| export interface EncryptedRecordsSuccess { | ||
| ok: true; | ||
| data: EncryptedRecord[]; | ||
| } | ||
|
|
||
| export interface EncryptedRecordsFailure { | ||
| ok: false; | ||
| status: number; | ||
| error: RecordScannerErrorBody; | ||
| } | ||
|
|
||
| export type EncryptedRecordsResult = EncryptedRecordsSuccess | EncryptedRecordsFailure; | ||
|
|
||
8 changes: 8 additions & 0 deletions
8
sdk/src/models/record-scanner/encryptedRegistrationRequest.ts
This file contains hidden or 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,8 @@ | ||
| /** | ||
| * Payload for the /register/encrypted record scanner endpoint. | ||
| * Contains the ephemeral key id and the sealed ciphertext of the registration request. | ||
| */ | ||
| export interface EncryptedRegistrationRequest { | ||
| key_id: string; | ||
| ciphertext: string; | ||
| } |
This file contains hidden or 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,39 @@ | ||
| import { OwnedFilter } from "./ownedFilter"; | ||
|
|
||
| /** | ||
| * Error thrown when a record scanner request fails (e.g. /register, /register/encrypted). | ||
| * Includes HTTP status so callers can handle 422 vs 500 etc. | ||
| */ | ||
| export class RecordScannerRequestError extends Error { | ||
| readonly status: number; | ||
|
|
||
| constructor(message: string, status: number) { | ||
| super(message); | ||
| this.name = "RecordScannerRequestError"; | ||
| this.status = status; | ||
| Object.setPrototypeOf(this, RecordScannerRequestError.prototype); | ||
| } | ||
| } | ||
|
|
||
| /** Error thrown when a record scanner request fails due to an invalid response. */ | ||
| export class UUIDError extends Error { | ||
| readonly uuid?: string; | ||
| readonly filter?: OwnedFilter; | ||
|
|
||
| constructor(message: string, uuid?: string, filter?: OwnedFilter) { | ||
| super(message); | ||
| this.name = "InvalidResponseError"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change the name here to "UUIDError" for consistency?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed |
||
| this.uuid = uuid; | ||
| this.filter = filter; | ||
| Object.setPrototypeOf(this, UUIDError.prototype); | ||
| } | ||
| } | ||
|
|
||
| /** General error payload returned from record-scanner endpoints on failure. */ | ||
| export interface RecordScannerErrorBody { | ||
| /** Raw error text returned by the service. */ | ||
| message: string; | ||
| /** HTTP status code from the response. */ | ||
| status: number; | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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,29 @@ | ||
| import type { RecordScannerErrorBody } from "./error.js"; | ||
| import type { OwnedRecord } from "../record-provider/ownedRecord.js"; | ||
|
|
||
| /** | ||
| * Success variant of ownedRecords() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always true for this interface variant. | ||
| * @property data - List of owned records corresponding to the filter used. | ||
| */ | ||
| export interface OwnedRecordsSuccess { | ||
| ok: true; | ||
| data: OwnedRecord[]; | ||
| } | ||
|
|
||
| /** | ||
| * Failure variant of ownedRecords() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always false for this interface variant. | ||
| * @property status - HTTP status code returned by the server. | ||
| * @property error - Error payload returned by the server. | ||
| */ | ||
| export interface OwnedRecordsFailure { | ||
| ok: false; | ||
| status: number; | ||
| error: RecordScannerErrorBody; | ||
| } | ||
|
|
||
| export type OwnedRecordsResult = OwnedRecordsSuccess | OwnedRecordsFailure; | ||
|
|
This file contains hidden or 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,18 @@ | ||
| import type { RegistrationResponse } from "./registrationResponse.js"; | ||
| import type { RecordScannerErrorBody } from "./error.js"; | ||
|
|
||
| /** Success variant of registration result. */ | ||
| export interface RegisterSuccess { | ||
| ok: true; | ||
| data: RegistrationResponse; | ||
| } | ||
|
|
||
| /** Failure variant of registration result. */ | ||
| export interface RegisterFailure { | ||
| ok: false; | ||
| status: number; | ||
| error: RecordScannerErrorBody; | ||
| } | ||
|
|
||
| /** Result of register() and registerEncrypted(); never throws on HTTP error. */ | ||
| export type RegisterResult = RegisterSuccess | RegisterFailure; |
This file contains hidden or 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,31 @@ | ||
| import type { RecordScannerErrorBody } from "./error.js"; | ||
|
|
||
| /** | ||
| * Success variant of serialNumbers() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always true for this interface. | ||
| * @property data - A map of serial numbers to whether they are owned by the account. | ||
| */ | ||
| export interface SerialNumbersSuccess { | ||
| ok: true; | ||
| data: Record<string, boolean>; | ||
| } | ||
|
|
||
| /** | ||
| * Failure variant of serialNumbers() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always false for this interface. | ||
| * @property status - HTTP status code returned by the server. | ||
| * @property error - Error payload returned by the server. | ||
| */ | ||
| export interface SerialNumbersFailure { | ||
| ok: false; | ||
| status: number; | ||
| error: RecordScannerErrorBody; | ||
| } | ||
|
|
||
| /** | ||
| * Success or failure variant of serialNumbers() result. | ||
| */ | ||
| export type SerialNumbersResult = SerialNumbersSuccess | SerialNumbersFailure; | ||
|
|
This file contains hidden or 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,29 @@ | ||
| import type { RecordScannerErrorBody } from "./error.js"; | ||
| import type { StatusResponse } from "./statusResponse.js"; | ||
|
|
||
| /** | ||
| * Success variant of status() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always true for this interface variant. | ||
| * @property data - StatusResponse returned by the server. | ||
| */ | ||
| export interface StatusSuccess { | ||
| ok: true; | ||
| data: StatusResponse; | ||
| } | ||
|
|
||
| /** | ||
| * Failure variant of status() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always false for this interface variant. | ||
| * @property status - HTTP status code returned by the server. | ||
| * @property error - Error payload returned by the server. | ||
| */ | ||
| export interface StatusFailure { | ||
| ok: false; | ||
| status: number; | ||
| error: RecordScannerErrorBody; | ||
| } | ||
|
|
||
| export type StatusResult = StatusSuccess | StatusFailure; | ||
|
|
This file contains hidden or 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,28 @@ | ||
| import type { RecordScannerErrorBody } from "./error.js"; | ||
|
|
||
| /** | ||
| * Success variant of tags() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always true for this interface variant. | ||
| * @property data - A map of tags to whether they are owned by the account. | ||
| */ | ||
| export interface TagsSuccess { | ||
| ok: true; | ||
| data: Record<string, boolean>; | ||
| } | ||
|
|
||
| /** | ||
| * Failure variant of tags() result. | ||
| * | ||
| * @property ok - Whether the request was successful, always false for this interface variant. | ||
| * @property status - HTTP status code returned by the server. | ||
| * @property error - Error payload returned by the server. | ||
| */ | ||
| export interface TagsFailure { | ||
| ok: false; | ||
| status: number; | ||
| error: RecordScannerErrorBody; | ||
| } | ||
|
|
||
| export type TagsResult = TagsSuccess | TagsFailure; | ||
|
|
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new result types seem to use
status: numberbut the SDK convention (perprovingResponse.tsand others) isstatus: bigint | number. Should we align with the existing pattern for consistency or is this difference intentional?