mirror of https://github.com/bitwarden/cli.git
32 changed files with 58 additions and 352 deletions
@ -1 +1 @@
@@ -1 +1 @@
|
||||
Subproject commit 49e06e77c4913867fc468f7d9e0b2b1529c1d181 |
||||
Subproject commit 13a160fb795a69bad1edbb3fc5fd5c7c15396e03 |
||||
@ -1,81 +0,0 @@
@@ -1,81 +0,0 @@
|
||||
import * as program from 'commander'; |
||||
import * as fetch from 'node-fetch'; |
||||
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; |
||||
|
||||
import { Response } from '../models/response'; |
||||
import { MessageResponse } from '../models/response/messageResponse'; |
||||
|
||||
export class UpdateCommand { |
||||
inPkg: boolean = false; |
||||
|
||||
constructor(private platformUtilsService: PlatformUtilsService) { |
||||
this.inPkg = !!(process as any).pkg; |
||||
} |
||||
|
||||
async run(cmd: program.Command): Promise<Response> { |
||||
const currentVersion = this.platformUtilsService.getApplicationVersion(); |
||||
|
||||
const response = await fetch.default('https://api.github.com/repos/bitwarden/cli/releases/latest'); |
||||
if (response.status === 200) { |
||||
const responseJson = await response.json(); |
||||
const res = new MessageResponse(null, null); |
||||
|
||||
const tagName: string = responseJson.tag_name; |
||||
if (tagName === ('v' + currentVersion)) { |
||||
res.title = 'No update available.'; |
||||
res.noColor = true; |
||||
return Response.success(res); |
||||
} |
||||
|
||||
let downloadUrl: string = null; |
||||
if (responseJson.assets != null) { |
||||
for (const a of responseJson.assets) { |
||||
const download: string = a.browser_download_url; |
||||
if (download == null) { |
||||
continue; |
||||
} |
||||
|
||||
if (download.indexOf('.zip') === -1) { |
||||
continue; |
||||
} |
||||
|
||||
if (process.platform === 'win32' && download.indexOf('bw-windows') > -1) { |
||||
downloadUrl = download; |
||||
break; |
||||
} else if (process.platform === 'darwin' && download.indexOf('bw-macos') > -1) { |
||||
downloadUrl = download; |
||||
break; |
||||
} else if (process.platform === 'linux' && download.indexOf('bw-linux') > -1) { |
||||
downloadUrl = download; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
res.title = 'A new version is available: ' + tagName; |
||||
if (downloadUrl == null) { |
||||
downloadUrl = 'https://github.com/bitwarden/cli/releases'; |
||||
} else { |
||||
res.raw = downloadUrl; |
||||
} |
||||
res.message = ''; |
||||
if (responseJson.body != null && responseJson.body !== '') { |
||||
res.message = responseJson.body + '\n\n'; |
||||
} |
||||
|
||||
res.message += 'You can download this update at ' + downloadUrl; |
||||
|
||||
if (this.inPkg) { |
||||
res.message += '\n\nIf you installed this CLI through a package manager ' + |
||||
'you should probably update using its update command instead.'; |
||||
} else { |
||||
res.message += '\n\nIf you installed this CLI through NPM ' + |
||||
'you should update using `npm install -g @bitwarden/cli`'; |
||||
} |
||||
return Response.success(res); |
||||
} else { |
||||
return Response.error('Error contacting update API: ' + response.status); |
||||
} |
||||
} |
||||
} |
||||
@ -1,43 +0,0 @@
@@ -1,43 +0,0 @@
|
||||
import { BaseResponse } from './response/baseResponse'; |
||||
|
||||
export class Response { |
||||
static error(error: any): Response { |
||||
const res = new Response(); |
||||
res.success = false; |
||||
if (typeof (error) === 'string') { |
||||
res.message = error; |
||||
} else { |
||||
res.message = error.message != null ? error.message : error.toString(); |
||||
} |
||||
return res; |
||||
} |
||||
|
||||
static notFound(): Response { |
||||
return Response.error('Not found.'); |
||||
} |
||||
|
||||
static badRequest(message: string): Response { |
||||
return Response.error(message); |
||||
} |
||||
|
||||
static multipleResults(ids: string[]): Response { |
||||
let msg = 'More than one result was found. Try getting a specific object by `id` instead. ' + |
||||
'The following objects were found:'; |
||||
ids.forEach((id) => { |
||||
msg += '\n' + id; |
||||
}); |
||||
return Response.error(msg); |
||||
} |
||||
|
||||
static success(data?: BaseResponse): Response { |
||||
const res = new Response(); |
||||
res.success = true; |
||||
res.data = data; |
||||
return res; |
||||
} |
||||
|
||||
success: boolean; |
||||
message: string; |
||||
errorCode: number; |
||||
data: BaseResponse; |
||||
} |
||||
@ -1,3 +0,0 @@
@@ -1,3 +0,0 @@
|
||||
export interface BaseResponse { |
||||
object: string; |
||||
} |
||||
@ -1,11 +0,0 @@
@@ -1,11 +0,0 @@
|
||||
import { BaseResponse } from './baseResponse'; |
||||
|
||||
export class ListResponse implements BaseResponse { |
||||
object: string; |
||||
data: BaseResponse[]; |
||||
|
||||
constructor(data: BaseResponse[]) { |
||||
this.object = 'list'; |
||||
this.data = data; |
||||
} |
||||
} |
||||
@ -1,15 +0,0 @@
@@ -1,15 +0,0 @@
|
||||
import { BaseResponse } from './baseResponse'; |
||||
|
||||
export class MessageResponse implements BaseResponse { |
||||
object: string; |
||||
title: string; |
||||
message: string; |
||||
raw: string; |
||||
noColor = false; |
||||
|
||||
constructor(title: string, message: string) { |
||||
this.object = 'message'; |
||||
this.title = title; |
||||
this.message = message; |
||||
} |
||||
} |
||||
@ -1,11 +0,0 @@
@@ -1,11 +0,0 @@
|
||||
import { BaseResponse } from './baseResponse'; |
||||
|
||||
export class StringResponse implements BaseResponse { |
||||
object: string; |
||||
data: string; |
||||
|
||||
constructor(data: string) { |
||||
this.object = 'string'; |
||||
this.data = data; |
||||
} |
||||
} |
||||
@ -1,135 +0,0 @@
@@ -1,135 +0,0 @@
|
||||
|
||||
import { DeviceType } from 'jslib/enums/deviceType'; |
||||
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; |
||||
|
||||
// tslint:disable-next-line
|
||||
const pjson = require('../../package.json'); |
||||
|
||||
export class NodePlatformUtilsService implements PlatformUtilsService { |
||||
identityClientId: string; |
||||
|
||||
private deviceCache: DeviceType = null; |
||||
|
||||
constructor() { |
||||
this.identityClientId = 'cli'; |
||||
} |
||||
|
||||
getDevice(): DeviceType { |
||||
if (!this.deviceCache) { |
||||
switch (process.platform) { |
||||
case 'win32': |
||||
this.deviceCache = DeviceType.WindowsDesktop; |
||||
break; |
||||
case 'darwin': |
||||
this.deviceCache = DeviceType.MacOsDesktop; |
||||
break; |
||||
case 'linux': |
||||
default: |
||||
this.deviceCache = DeviceType.LinuxDesktop; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return this.deviceCache; |
||||
} |
||||
|
||||
getDeviceString(): string { |
||||
const device = DeviceType[this.getDevice()].toLowerCase(); |
||||
return device.replace('desktop', ''); |
||||
} |
||||
|
||||
isFirefox() { |
||||
return false; |
||||
} |
||||
|
||||
isChrome() { |
||||
return false; |
||||
} |
||||
|
||||
isEdge() { |
||||
return false; |
||||
} |
||||
|
||||
isOpera() { |
||||
return false; |
||||
} |
||||
|
||||
isVivaldi() { |
||||
return false; |
||||
} |
||||
|
||||
isSafari() { |
||||
return false; |
||||
} |
||||
|
||||
isIE() { |
||||
return false; |
||||
} |
||||
|
||||
isMacAppStore() { |
||||
return false; |
||||
} |
||||
|
||||
analyticsId() { |
||||
return null as string; |
||||
} |
||||
|
||||
isViewOpen() { |
||||
return false; |
||||
} |
||||
|
||||
lockTimeout(): number { |
||||
return null; |
||||
} |
||||
|
||||
launchUri(uri: string, options?: any): void { |
||||
throw new Error('Not implemented.'); |
||||
} |
||||
|
||||
saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void { |
||||
throw new Error('Not implemented.'); |
||||
} |
||||
|
||||
getApplicationVersion(): string { |
||||
return pjson.version; |
||||
} |
||||
|
||||
supportsU2f(win: Window) { |
||||
return false; |
||||
} |
||||
|
||||
supportsDuo(): boolean { |
||||
return false; |
||||
} |
||||
|
||||
showToast(type: 'error' | 'success' | 'warning' | 'info', title: string, text: string | string[], |
||||
options?: any): void { |
||||
throw new Error('Not implemented.'); |
||||
} |
||||
|
||||
showDialog(text: string, title?: string, confirmText?: string, cancelText?: string, type?: string): |
||||
Promise<boolean> { |
||||
throw new Error('Not implemented.'); |
||||
} |
||||
|
||||
eventTrack(action: string, label?: string, options?: any) { |
||||
throw new Error('Not implemented.'); |
||||
} |
||||
|
||||
isDev(): boolean { |
||||
return process.env.BWCLI_ENV === 'development'; |
||||
} |
||||
|
||||
isSelfHost(): boolean { |
||||
return false; |
||||
} |
||||
|
||||
copyToClipboard(text: string, options?: any): void { |
||||
throw new Error('Not implemented.'); |
||||
} |
||||
|
||||
readFromClipboard(options?: any): Promise<string> { |
||||
throw new Error('Not implemented.'); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue