Skip to content

Commit

Permalink
better handling of window global
Browse files Browse the repository at this point in the history
  • Loading branch information
binarykitchen committed Nov 2, 2024
1 parent e095f18 commit e4bc187
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@storybook/theming": "8.4.1",
"@tsconfig/node22": "22.0.0",
"@tsconfig/strictest": "2.0.5",
"@types/defined": "1.0.2",
"@types/node": "22.8.6",
"@types/superagent": "8.1.9",
"@types/ua-parser-js": "0.7.39",
Expand Down
11 changes: 6 additions & 5 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import Response from "superagent/lib/node/response";
import VideomailError from "./util/error/VideomailError";
import { FormInputs, FormMethod } from "./wrappers/form";

const timezoneId = window.Intl.DateTimeFormat().resolvedOptions().timeZone;

class Resource {
private readonly options: VideomailClientOptions;
private readonly timezoneId: string;

constructor(options: VideomailClientOptions) {
this.options = options;

this.timezoneId = window.Intl.DateTimeFormat().resolvedOptions().timeZone;
}

private applyDefaultValue(videomail: PartialVideomail, name: string) {
Expand Down Expand Up @@ -45,7 +46,7 @@ class Resource {
const request = await superagent("get", url)
.type("json")
.set("Accept", "application/json")
.set("Timezone-Id", timezoneId)
.set("Timezone-Id", this.timezoneId)
.set(Constants.SITE_NAME_LABEL, this.options.siteName)
.timeout(this.options.timeouts.connection);

Expand All @@ -69,7 +70,7 @@ class Resource {
try {
const request = await superagent(method, url)
.query(queryParams)
.set("Timezone-Id", timezoneId)
.set("Timezone-Id", this.timezoneId)
.send(videomail)
.timeout(this.options.timeouts.connection);

Expand Down Expand Up @@ -158,7 +159,7 @@ class Resource {
const res = await superagent
.post(url)
.type(formType)
.set("Timezone-Id", timezoneId)
.set("Timezone-Id", this.timezoneId)
.send(formData)
.timeout(this.options.timeouts.connection);

Expand Down
6 changes: 1 addition & 5 deletions src/util/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class Browser {
public constructor(options: VideomailClientOptions) {
this.options = options;

const ua = defined(
options.fakeUaString,
typeof window !== "undefined" && window.navigator.userAgent,
"",
);
const ua = defined(options.fakeUaString, window.navigator.userAgent, "");

const userAgentParser = new UAParser(ua);

Expand Down

0 comments on commit e4bc187

Please sign in to comment.