Skip to content

Commit ffbff87

Browse files
authored
Merge pull request #88 from magiclabs/jerryliu-sc-50572-admin-js-malformed-token-on-deployment
Add shims for atob
2 parents 7202159 + 82c65d4 commit ffbff87

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@
5050
"npm-run-all": "~4.1.5",
5151
"prettier": "^1.19.1",
5252
"rimraf": "~3.0.0",
53+
"ts-jest": "^27.1.3",
5354
"ts-node": "~8.5.2",
5455
"tslint": "~5.20.1",
55-
"typescript": "~3.8.3",
56-
"ts-jest": "^27.1.3"
56+
"typescript": "~3.8.3"
5757
},
5858
"dependencies": {
59+
"@types/atob": "^2.1.2",
60+
"atob": "^2.1.2",
5961
"ethereum-cryptography": "^1.0.1",
6062
"node-fetch": "^2.6.0"
6163
},

src/core/sdk.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../utils/shim';
12
import { TokenModule } from '../modules/token';
23
import { UsersModule } from '../modules/users';
34
import { UtilsModule } from '../modules/utils';

src/utils/shim.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import atob from 'atob';
2+
3+
// Shims for atob being undefined in node.js prior version 14
4+
if (!globalThis.atob) globalThis.atob = atob;

test/spec/utils/shim.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import atob from 'atob';
2+
3+
test('#01: Shim overwrites undefined global atob', async () => {
4+
globalThis.atob = undefined;
5+
6+
expect(globalThis.atob).toBeUndefined();
7+
8+
// eslint-disable-next-line global-require
9+
require('../../../src/utils/shim');
10+
11+
expect(globalThis.atob).toBe(atob);
12+
});
13+
14+
test('#02: Shim does not overwrite exisiting atob', async () => {
15+
const dummyFunc = () => '';
16+
globalThis.atob = dummyFunc;
17+
18+
expect(globalThis.atob).toBe(dummyFunc);
19+
20+
// eslint-disable-next-line global-require
21+
require('../../../src/utils/shim');
22+
23+
expect(globalThis.atob).toBe(dummyFunc);
24+
});

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@
821821
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
822822
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==
823823

824+
"@types/atob@^2.1.2":
825+
version "2.1.2"
826+
resolved "https://registry.yarnpkg.com/@types/atob/-/atob-2.1.2.tgz#157eb0cc46264a8c55f2273a836c7a1a644fb820"
827+
integrity sha512-8GAYQ1jDRUQkSpHzJUqXwAkYFOxuWAOGLhIR4aPd/Y/yL12Q/9m7LsKpHKlfKdNE/362Hc9wPI1Yh6opDfxVJg==
828+
824829
"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.14":
825830
version "7.1.18"
826831
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.18.tgz#1a29abcc411a9c05e2094c98f9a1b7da6cdf49f8"
@@ -1227,6 +1232,11 @@ asynckit@^0.4.0:
12271232
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
12281233
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
12291234

1235+
atob@^2.1.2:
1236+
version "2.1.2"
1237+
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
1238+
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
1239+
12301240
author-regex@^1.0.0:
12311241
version "1.0.0"
12321242
resolved "https://registry.yarnpkg.com/author-regex/-/author-regex-1.0.0.tgz#d08885be6b9bbf9439fe087c76287245f0a81450"

0 commit comments

Comments
 (0)