Skip to content

Commit df7a047

Browse files
committed
Adding node polyfills for fetch and storage
1 parent 33021ec commit df7a047

File tree

11 files changed

+162
-119
lines changed

11 files changed

+162
-119
lines changed

.vscode/launch.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
{
5+
"name": "Express",
6+
"program": "${workspaceRoot}/example/express/app.js",
7+
"request": "launch",
8+
"preLaunchTask": "npm: build",
9+
"cwd": "${workspaceRoot}/example/express",
10+
"skipFiles": [
11+
"<node_internals>/**"
12+
],
13+
"type": "pwa-node"
14+
},
415
{
516
"name": "Test",
617
"request": "launch",
@@ -32,18 +43,6 @@
3243
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
3344
},
3445
"cwd": "${workspaceRoot}"
35-
},
36-
{
37-
"name": "Express",
38-
"request": "launch",
39-
"type": "node",
40-
"program": "${workspaceRoot}/example/express/app.js",
41-
"runtimeArgs": [
42-
"--nolazy"
43-
],
44-
"console": "integratedTerminal",
45-
"sourceMaps": true,
46-
"cwd": "${workspaceRoot}"
4746
}
4847
]
4948
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"settings":{"@@UserAgentBotPatterns":"*bot*,*crawler*,*spider*,*aolbuild*,*teoma*,*yahoo*","@@log:*":"info","@@log:":"info","@@DataExclusions":"*Password*, *Bearer*,"}}

example/express/.exceptionless/settings.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/express/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ await Exceptionless.startup((c) => {
77
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw";
88
c.serverUrl = "http://localhost:5000";
99
c.useDebugLogger();
10+
c.useLocalStorage();
11+
c.usePersistedQueueStorage = true;
1012

1113
c.defaultTags.push("Example", "Node");
1214

package-lock.json

Lines changed: 123 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/storage/LocalStorage.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { IStorage } from "./IStorage.js";
22

33
export class LocalStorage implements IStorage {
4-
constructor(private prefix: string = "exceptionless:") { }
4+
constructor(private prefix: string = "exceptionless-", private storage: Storage = globalThis.localStorage) { }
55

66
public length(): Promise<number> {
77
return Promise.resolve(this.getKeys().length);
88
}
99

1010
public clear(): Promise<void> {
1111
for (const key of this.getKeys()) {
12-
localStorage.removeItem(this.getKey(key));
12+
this.storage.removeItem(this.getKey(key));
1313
}
1414

1515
return Promise.resolve();
1616
}
1717

1818
public getItem(key: string): Promise<string> {
19-
return Promise.resolve(localStorage.getItem(this.getKey(key)));
19+
return Promise.resolve(this.storage.getItem(this.getKey(key)));
2020
}
2121

2222
public key(index: number): Promise<string> {
@@ -29,17 +29,17 @@ export class LocalStorage implements IStorage {
2929
}
3030

3131
public removeItem(key: string): Promise<void> {
32-
localStorage.removeItem(this.getKey(key));
32+
this.storage.removeItem(this.getKey(key));
3333
return Promise.resolve();
3434
}
3535

3636
public setItem(key: string, value: string): Promise<void> {
37-
localStorage.setItem(this.getKey(key), value);
37+
this.storage.setItem(this.getKey(key), value);
3838
return Promise.resolve();
3939
}
4040

4141
private getKeys(): string[] {
42-
return Object.keys(localStorage)
42+
return Object.keys(this.storage)
4343
.filter(key => key.startsWith(this.prefix))
4444
.map(key => key?.substr(this.prefix.length));
4545
}

packages/core/src/submission/DefaultSubmissionClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class DefaultSubmissionClient implements ISubmissionClient {
1313
protected readonly ConfigurationVersionHeader: string =
1414
"x-exceptionless-configversion";
1515

16-
public constructor(protected config: Configuration) { }
16+
public constructor(protected config: Configuration, private fetch = globalThis.fetch) { }
1717

1818
public getSettings(version: number): Promise<Response<ServerSettings>> {
1919
const url = `${this.config.serverUrl}/api/v2/projects/config?v=${version}`;
@@ -80,7 +80,7 @@ export class DefaultSubmissionClient implements ISubmissionClient {
8080
requestOptions.headers["Content-Type"] = "application/json";
8181
}
8282

83-
const response = await fetch(url, requestOptions);
83+
const response = await this.fetch(url, requestOptions);
8484
const rateLimitRemaining: number = parseInt(response.headers.get(this.RateLimitRemainingHeader) || "", 10);
8585
const settingsVersion: number = parseInt(response.headers.get(this.ConfigurationVersionHeader) || "", 10);
8686

packages/node/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
},
6363
"dependencies": {
6464
"@exceptionless/core": "2.0.0-dev",
65-
"node-fetch": "2.6.1",
65+
"node-fetch": "^3.0.0-beta.9",
66+
"node-localstorage": "^2.1.6",
6667
"stack-trace": "1.0.0-pre1"
6768
}
6869
}

0 commit comments

Comments
 (0)