Skip to content

Commit 2eaa746

Browse files
committed
pr feedback
1 parent 3405d60 commit 2eaa746

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

packages/mobile-sdk-alpha/src/client.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defaultConfig } from './config/defaults';
22
import { mergeConfig } from './config/merge';
3-
import { notImplemented } from './errors';
3+
import { notImplemented, sdkError } from './errors';
44
import type {
55
Adapters,
66
Config,
@@ -44,7 +44,13 @@ const optionalDefaults: Partial<Adapters> = {
4444
* @param param0.adapters - Implementations of required SDK adapters.
4545
* @returns Initialized client exposing document scanning, validation, and proof APIs.
4646
*/
47-
export function createSelfClient({ config, adapters }: { config: Config; adapters: Partial<Adapters> }): SelfClient {
47+
export function createSelfClient({
48+
config,
49+
adapters,
50+
}: {
51+
config: Partial<Config>;
52+
adapters: Partial<Adapters>;
53+
}): SelfClient {
4854
const cfg = mergeConfig(defaultConfig, config);
4955
const required: (keyof Adapters)[] = ['scanner', 'network', 'crypto'];
5056
for (const name of required) {
@@ -134,7 +140,9 @@ export function createSelfClient({ config, adapters }: { config: Config; adapter
134140
if (!adapters.network) throw notImplemented('network');
135141
if (!adapters.crypto) throw notImplemented('crypto');
136142
const timeoutMs = opts.timeoutMs ?? cfg.timeouts?.proofMs ?? defaultConfig.timeouts.proofMs;
137-
void _adapters.clock.sleep(timeoutMs!, opts.signal).then(() => emit('error', new Error('timeout')));
143+
void _adapters.clock
144+
.sleep(timeoutMs!, opts.signal)
145+
.then(() => emit('error', sdkError('timeout', 'SELF_ERR_PROOF_TIMEOUT', 'proof', true)));
138146
return {
139147
id: 'stub',
140148
status: 'pending',

packages/mobile-sdk-alpha/src/types/public.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
import type { SdkError } from '../errors';
2+
13
export type { PassportData } from '@selfxyz/common/utils/types';
24
export type { PassportValidationCallbacks } from '../validation/document';
5+
6+
// Platform-neutral HTTP shapes
7+
export type RequestLike = string | URL;
8+
export interface RequestInitLike {
9+
method?: string;
10+
headers?: Record<string, string>;
11+
body?: string | ArrayBuffer | ArrayBufferView | Uint8Array;
12+
}
13+
export interface HttpResponseLike {
14+
status: number;
15+
headers: Record<string, string>;
16+
text(): Promise<string>;
17+
json<T = unknown>(): Promise<T>;
18+
arrayBuffer(): Promise<ArrayBuffer>;
19+
}
20+
321
/**
422
* Runtime configuration options for the SDK.
523
*/
@@ -25,7 +43,7 @@ export interface CryptoAdapter {
2543
* Minimal wrapper around `fetch` used for HTTP requests.
2644
*/
2745
export interface HttpAdapter {
28-
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
46+
fetch(input: RequestLike, init?: RequestInitLike): Promise<HttpResponseLike>;
2947
}
3048
/**
3149
* Parsed machine-readable zone (MRZ) details from a passport.
@@ -132,7 +150,7 @@ export interface RegistrationStatus {
132150
export interface SDKEventMap {
133151
progress: Progress;
134152
state: string;
135-
error: Error;
153+
error: SdkError;
136154
}
137155
/**
138156
* Names of events emitted by {@link SelfClient}.

packages/mobile-sdk-alpha/tests/client.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ const scanner: ScannerAdapter = {
8484
};
8585

8686
const network: NetworkAdapter = {
87-
http: { fetch: async () => new Response(null) },
87+
http: {
88+
fetch: async () => ({
89+
status: 200,
90+
headers: {},
91+
text: async () => '',
92+
json: async () => ({}),
93+
arrayBuffer: async () => new ArrayBuffer(0),
94+
}),
95+
},
8896
ws: {
8997
connect: () => ({
9098
send: () => {},

0 commit comments

Comments
 (0)