Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClientType } from "../../../enums/clientType";
Comment thread
BTreston marked this conversation as resolved.
import { Utils } from "../../../misc/utils";
import { CaptchaProtectedRequest } from "../captchaProtectedRequest";
Comment thread
BTreston marked this conversation as resolved.
import { DeviceRequest } from "../deviceRequest";

Expand Down Expand Up @@ -30,5 +29,4 @@ export class PasswordTokenRequest extends TokenRequest implements CaptchaProtect

return obj;
}

}
3 changes: 1 addition & 2 deletions jslib/common/src/services/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const partialKeys = {
export class StateService<
TGlobalState extends GlobalState = GlobalState,
TAccount extends Account = Account,
> implements StateServiceAbstraction<TAccount>
{
> implements StateServiceAbstraction<TAccount> {
Comment thread
BTreston marked this conversation as resolved.
Comment thread
BTreston marked this conversation as resolved.
protected accountsSubject = new BehaviorSubject<{ [userId: string]: TAccount }>({});
accounts$ = this.accountsSubject.asObservable();

Expand Down
34 changes: 32 additions & 2 deletions jslib/node/src/cli/commands/update.command.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import * as fetch from "node-fetch";
import { components } from "@octokit/openapi-types";
Comment thread
BTreston marked this conversation as resolved.
import fetch from "node-fetch";

import { I18nService } from "@/jslib/common/src/abstractions/i18n.service";
import { PlatformUtilsService } from "@/jslib/common/src/abstractions/platformUtils.service";

import { Response } from "../models/response";
import { MessageResponse } from "../models/response/messageResponse";

type GitHubRelease = components["schemas"]["release"];
Comment thread
BTreston marked this conversation as resolved.
Comment thread
BTreston marked this conversation as resolved.

function isGitHubRelease(value: unknown): value is GitHubRelease {
if (typeof value !== "object" || value === null) {
return false;
}

const obj = value as Record<string, unknown>;

if (typeof obj.tag_name !== "string") {
return false;
}

if (obj.body !== undefined && obj.body !== null && typeof obj.body !== "string") {
return false;
}

if (obj.assets !== undefined && obj.assets !== null && !Array.isArray(obj.assets)) {
return false;
}

return true;
Comment thread
BTreston marked this conversation as resolved.
}

export class UpdateCommand {
inPkg = false;

Expand All @@ -22,11 +47,16 @@ export class UpdateCommand {
async run(): Promise<Response> {
const currentVersion = await this.platformUtilsService.getApplicationVersion();

const response = await fetch.default(
const response = await fetch(
Comment thread
BTreston marked this conversation as resolved.
"https://api.github.com/repos/bitwarden/" + this.repoName + "/releases/latest",
);
if (response.status === 200) {
const responseJson = await response.json();

if (!isGitHubRelease(responseJson)) {
return Response.error("Invalid response from GitHub API");
}

const res = new MessageResponse(null, null);

const tagName: string = responseJson.tag_name;
Expand Down
16 changes: 10 additions & 6 deletions jslib/node/src/services/nodeApi.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import * as FormData from "form-data";
import { HttpsProxyAgent } from "https-proxy-agent";
import * as fe from "node-fetch";
import fetch, {
Headers as NodeFetchHeaders,
Request as NodeFetchRequest,
Response as NodeFetchResponse,
} from "node-fetch";

import { AppIdService } from "@/jslib/common/src/abstractions/appId.service";
import { EnvironmentService } from "@/jslib/common/src/abstractions/environment.service";
import { PlatformUtilsService } from "@/jslib/common/src/abstractions/platformUtils.service";
import { TokenService } from "@/jslib/common/src/abstractions/token.service";
import { ApiService } from "@/jslib/common/src/services/api.service";

(global as any).fetch = fe.default;
(global as any).Request = fe.Request;
(global as any).Response = fe.Response;
(global as any).Headers = fe.Headers;
(global as any).fetch = fetch;
Comment thread
BTreston marked this conversation as resolved.
(global as any).Request = NodeFetchRequest;
(global as any).Response = NodeFetchResponse;
(global as any).Headers = NodeFetchHeaders;
(global as any).FormData = FormData;

export class NodeApiService extends ApiService {
Expand All @@ -38,6 +42,6 @@ export class NodeApiService extends ApiService {
if (proxy) {
(request as any).agent = new HttpsProxyAgent(proxy);
}
return fetch(request);
return fetch(request as any) as any;
Comment thread
BTreston marked this conversation as resolved.
}
}
Loading
Loading