-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from isinstock/browser-extension-installs
Browser extension installs
- Loading branch information
Showing
13 changed files
with
148 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+598 Bytes
(100%)
...codeproj/project.xcworkspace/xcuserdata/dewski.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
declare const VERSION: string | ||
declare const ISINSTOCK_URL: string | ||
declare const CHROME_EXTENSION_ID: string | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import fetchApi from '../utils/fetch-api' | ||
import {FetchError} from '../utils/fetch-error' | ||
|
||
export type BrowserExtensionInstallResponseToken = { | ||
token: string | ||
} | ||
|
||
export type BrowserExtensionInstallResponseError = { | ||
error: string | ||
} | ||
|
||
export type BrowserExtensionInstallResponse = | ||
| BrowserExtensionInstallResponseToken | ||
| BrowserExtensionInstallResponseError | ||
|
||
export async function createBrowserExtensionInstall(version: string): Promise<BrowserExtensionInstallResponseToken> { | ||
const body = JSON.stringify({version}) | ||
const response = await fetchApi('/api/browser-extension-installs', 'POST', body) | ||
if (!response.ok) { | ||
throw new FetchError(response) | ||
} | ||
|
||
return (await response.json()) as BrowserExtensionInstallResponseToken | ||
} | ||
|
||
export async function updateBrowserExtensionInstall( | ||
token: string, | ||
version: string, | ||
reason: string, | ||
): Promise<BrowserExtensionInstallResponseToken> { | ||
const path = `/api/browser-extension-installs/${token}` | ||
const body = JSON.stringify({version, reason}) | ||
const response = await fetchApi(path, 'PATCH', body) | ||
if (!response.ok) { | ||
throw new FetchError(response) | ||
} | ||
|
||
return (await response.json()) as BrowserExtensionInstallResponseToken | ||
} | ||
|
||
export async function browserExtensionStartup(token: string): Promise<boolean> { | ||
const path = `/api/browser-extension-installs/${token}/startup` | ||
const response = await fetchApi(path, 'POST') | ||
if (!response.ok) { | ||
throw new FetchError(response) | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import browser from 'webextension-polyfill' | ||
|
||
export async function setBrowserExtensionInstallToken(browserExtensionInstallToken: string) { | ||
await browser.storage.sync.set({browserExtensionInstallToken}) | ||
} | ||
|
||
export async function getBrowserExtensionInstallToken(): Promise<string> { | ||
const {browserExtensionInstallToken} = await browser.storage.sync.get({ | ||
browserExtensionInstallToken: '', | ||
}) | ||
|
||
return browserExtensionInstallToken | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export class FetchError extends Error { | ||
status: number | ||
response: Response | ||
|
||
constructor(response: Response) { | ||
super(`Could not fetch ${response.url} (${response.status})`) | ||
|
||
this.status = response.status | ||
this.response = response | ||
this.name = 'FetchError' | ||
} | ||
} |