-
Notifications
You must be signed in to change notification settings - Fork 85
/
sdk-environment.ts
34 lines (29 loc) · 1.04 KB
/
sdk-environment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import localForage from 'localforage';
import { ViewController } from './view-controller';
import { SDKBase } from './sdk';
import { WithExtensions } from '../modules/base-extension';
type ConstructorOf<C> = { new (...args: any[]): C };
/**
* A structure containing details about the current environment.
* This is guaranteed to be populated before the SDK is instantiated.
*/
export interface SDKEnvironment {
sdkName: 'magic-sdk' | '@magic-sdk/react-native';
version: string;
platform: 'web' | 'react-native';
defaultEndpoint: string;
ViewController: ConstructorOf<ViewController>;
configureStorage: () => Promise<typeof localForage>;
}
export const SDKEnvironment: SDKEnvironment = {} as any;
export function createSDK<SDK extends SDKBase>(
SDKBaseCtor: ConstructorOf<SDK>,
environment: SDKEnvironment,
): WithExtensions<SDK> {
Object.assign(SDKEnvironment, environment);
return SDKBaseCtor as any;
}
export const sdkNameToEnvName = {
'magic-sdk': 'magic-sdk' as const,
'@magic-sdk/react-native': 'magic-sdk-rn' as const,
};