Skip to content

Commit f6b0f39

Browse files
committed
Fixing issue with Axios and XMLHttpRequest
1 parent 6aea6f7 commit f6b0f39

File tree

5 files changed

+19
-324
lines changed

5 files changed

+19
-324
lines changed

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"comlink": "^4.4.2",
5252
"core-js": "^3.40.0",
5353
"mime": "^4.0.6",
54-
"sync-request": "^6.1.0"
54+
"xmlhttprequest-ssl": "^3.1.0"
5555
},
5656
"devDependencies": {
5757
"@rollup/plugin-replace": "^6.0.2",

sdk/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default networks.map((network) => {
2727
"node:fs",
2828
"node:crypto",
2929
"mime/lite",
30-
"sync-request",
30+
"xmlhttprequest-ssl",
3131

3232
// Used by the SDK
3333
"comlink",

sdk/rollup.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default networks.map((network) => {
3434
"node:fs",
3535
"node:crypto",
3636
"mime/lite",
37-
"sync-request",
37+
"xmlhttprequest-ssl",
3838

3939
// Used by the SDK
4040
"comlink",

sdk/src/polyfill/xmlhttprequest.ts

Lines changed: 3 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,6 @@
1-
import $request from "sync-request";
2-
1+
// @ts-ignore
2+
import $xmlhttprequest from "xmlhttprequest-ssl";
33

44
if (globalThis.XMLHttpRequest == null) {
5-
globalThis.XMLHttpRequest = class extends EventTarget implements XMLHttpRequest {
6-
public static readonly UNSENT = 0;
7-
public static readonly OPENED = 1;
8-
public static readonly HEADERS_RECEIVED = 2;
9-
public static readonly LOADING = 3;
10-
public static readonly DONE = 4;
11-
12-
public readonly UNSENT = XMLHttpRequest.UNSENT;
13-
public readonly OPENED = XMLHttpRequest.OPENED;
14-
public readonly HEADERS_RECEIVED = XMLHttpRequest.HEADERS_RECEIVED;
15-
public readonly LOADING = XMLHttpRequest.LOADING;
16-
public readonly DONE = XMLHttpRequest.DONE;
17-
18-
public responseType!: XMLHttpRequestResponseType;
19-
public withCredentials!: boolean;
20-
public timeout!: number;
21-
22-
public readonly readyState!: number;
23-
public readonly response!: ArrayBuffer | Blob | Document | string | null;
24-
public readonly responseText!: string;
25-
public readonly responseURL!: string;
26-
public readonly responseXML!: Document | null;
27-
public readonly status!: number;
28-
public readonly statusText!: string;
29-
public readonly upload!: XMLHttpRequestUpload;
30-
31-
private _url!: string | URL | null;
32-
private _mime!: string;
33-
34-
constructor() {
35-
super();
36-
37-
this._reset();
38-
39-
this._mime = "text/xml";
40-
}
41-
42-
private _reset() {
43-
(this as any).readyState = XMLHttpRequest.UNSENT;
44-
(this as any).response = null;
45-
(this as any).responseText = "";
46-
(this as any).responseType = "";
47-
(this as any).responseURL = "";
48-
(this as any).responseXML = null;
49-
(this as any).status = 0;
50-
(this as any).statusText = "";
51-
(this as any).timeout = 0;
52-
(this as any).upload = null;
53-
(this as any).withCredentials = false;
54-
55-
this._url = null;
56-
}
57-
58-
private _success() {
59-
(this as any).readyState = XMLHttpRequest.DONE;
60-
(this as any).status = 200;
61-
(this as any).statusText = "OK";
62-
}
63-
64-
public set onabort(value: () => void) {
65-
throw new Error("Not implemented");
66-
}
67-
68-
public set onerror(value: () => void) {
69-
throw new Error("Not implemented");
70-
}
71-
72-
public set onreadystatechange(value: () => void) {
73-
throw new Error("Not implemented");
74-
}
75-
76-
public set onloadstart(value: () => void) {
77-
throw new Error("Not implemented");
78-
}
79-
80-
public set onload(value: () => void) {
81-
throw new Error("Not implemented");
82-
}
83-
84-
public set onloadend(value: () => void) {
85-
throw new Error("Not implemented");
86-
}
87-
88-
public set onprogress(value: () => void) {
89-
throw new Error("Not implemented");
90-
}
91-
92-
public set ontimeout(value: () => void) {
93-
throw new Error("Not implemented");
94-
}
95-
96-
public abort() {
97-
throw new Error("Not implemented");
98-
}
99-
100-
public overrideMimeType(mime: string) {
101-
this._mime = mime;
102-
}
103-
104-
public getResponseHeader(): string | null {
105-
throw new Error("Not implemented");
106-
}
107-
108-
public getAllResponseHeaders(): string {
109-
throw new Error("Not implemented");
110-
}
111-
112-
public setRequestHeader() {
113-
throw new Error("Not implemented");
114-
}
115-
116-
public open(method: string, url: string | URL, async: boolean = true, username?: string | null | undefined, password?: string | null | undefined): void {
117-
if (async) {
118-
throw new Error("Async XMLHttpRequest is not implemented yet");
119-
}
120-
121-
if (method !== "GET") {
122-
throw new Error("Non-GET requests are not implemented yet");
123-
}
124-
125-
this._reset();
126-
127-
this._url = url;
128-
}
129-
130-
public send(body: null = null) {
131-
if (body !== null) {
132-
throw new Error("XMLHttpRequest send body is not implemented yet");
133-
}
134-
135-
if (!this._url) {
136-
throw new Error("You must call open before you call send");
137-
}
138-
139-
const response = $request("GET", this._url, {
140-
headers: {
141-
"Content-Type": this._mime,
142-
}
143-
});
144-
145-
const buffer = (response.body as Buffer).buffer as any;
146-
147-
const responseText = new TextDecoder("iso-8859-5", { fatal: true }).decode(buffer);
148-
149-
(this as any).response = (this as any).responseText = responseText;
150-
151-
this._url = null;
152-
153-
this._success();
154-
}
155-
};
5+
globalThis.XMLHttpRequest = $xmlhttprequest.XMLHttpRequest;
1566
}

0 commit comments

Comments
 (0)