-
Notifications
You must be signed in to change notification settings - Fork 86
/
index.ts
68 lines (52 loc) · 2.15 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
eslint-disable
global-require,
@typescript-eslint/no-var-requires
*/
/* istanbul ignore file */
import 'regenerator-runtime/runtime';
// Force-publish
import { createSDK } from '@magic-sdk/provider';
import * as processPolyfill from 'process';
import localForage from 'localforage';
import { URL as URLPolyfill, URLSearchParams as URLSearchParamsPolyfill } from 'whatwg-url';
import { Buffer } from 'buffer';
import * as _ from 'lodash';
import { driverWithoutSerialization } from '@aveq-research/localforage-asyncstorage-driver';
import * as memoryDriver from 'localforage-driver-memory';
import { ReactNativeWebViewController } from './react-native-webview-controller';
import { SDKBaseReactNative } from './react-native-sdk-base';
// Web3 assumes a browser context, so we need
// to provide `btoa` and `atob` shims.
// We expect `global.process` to be a Node Process for web3.js usage
// so we replace it here.
global.process = _.merge(global.process, processPolyfill);
(global.process as any).browser = false;
// WHATWG URL requires global `Buffer` access.
global.Buffer = Buffer;
// Setup global WHATWG URL polyfills
global.URL = URLPolyfill as any;
global.URLSearchParams = URLSearchParamsPolyfill as any;
/* istanbul ignore next */
global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');
/* istanbul ignore next */
global.atob = (b64Encoded) => Buffer.from(b64Encoded, 'base64').toString('binary');
export * from '@magic-sdk/commons';
export const Magic = createSDK(SDKBaseReactNative, {
platform: 'react-native',
sdkName: '@magic-sdk/react-native',
version: process.env.REACT_NATIVE_VERSION!,
defaultEndpoint: 'https://box.magic.link/',
ViewController: ReactNativeWebViewController,
configureStorage: /* istanbul ignore next */ async () => {
const lf = localForage.createInstance({
name: 'MagicAuthLocalStorageDB',
storeName: 'MagicAuthLocalStorage',
});
const driver = driverWithoutSerialization();
await Promise.all([lf.defineDriver(driver), lf.defineDriver(memoryDriver)]);
await lf.setDriver([driver._driver, memoryDriver._driver]);
return lf;
},
});
export type Magic = InstanceType<typeof Magic>;