diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8bb3d62..c8d3727 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -33,7 +33,17 @@ jobs: uses: actions/checkout@v4 - name: Install Worker Dependencies - run: npm install + run: npm ci + + - run: npm run deploy + - run: npm pack + - run: mv twitch-cloud-ebs*tgz twitch-cloud-ebs.tgz + - run: git log $(git describe --tags --abbrev=0 HEAD~1)..HEAD --oneline > changelog.txt + - uses: softprops/action-gh-release@v2 + with: + make_latest: true + body_path: changelog.txt + files: '*.tgz' - name: Compile Worker run: npx selflare compile diff --git a/.gitignore b/.gitignore index 97d74b6..6e16a00 100644 --- a/.gitignore +++ b/.gitignore @@ -175,4 +175,6 @@ Dockerfile # typescript output static/*.js -static/*.js.map \ No newline at end of file +static/*.js.map +static/*.d.ts +static/*.d.ts.map \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6df0da6..2cb56c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@sugoidogo/selflare": "^1.1.3", "@twurple/auth": "^7.4.0", "fetch-retry": "^6.0.0", - "typescript": "^5.5.2", + "typescript": "^5.9.3", "wrangler": "^4.43.0" } }, @@ -44,96 +44,6 @@ } } }, - "node_modules/@cloudflare/workerd-darwin-64": { - "version": "1.20251024.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20251024.0.tgz", - "integrity": "sha512-WOB1y6XFfUbGCaWz+EcSvdU+tm0I3enIt1+jsQNovddWSO903nmHQcaX1xLmQK8NmZz1/hodCCZkOQgb08/uGA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/workerd-darwin-arm64": { - "version": "1.20251024.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20251024.0.tgz", - "integrity": "sha512-vHhFUQf42pwOVg05L9uNBcNKoE9ZUNkbfDjC6J0brQqEgm32udyn/1dDR3tt6HajXijVYHmY5u/ir1+Y5r+ZjQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/workerd-linux-64": { - "version": "1.20251024.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20251024.0.tgz", - "integrity": "sha512-SA62TYclyApShlckJotmm+mgekTKd04Nkh5HYuYhW0yBiugN3HbQBIPPCYxC/oc4tPMwpocCqwk+uP8p8hWDog==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/workerd-linux-arm64": { - "version": "1.20251024.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20251024.0.tgz", - "integrity": "sha512-7oLQ04m3n/3BEI+BLc6cOkg6+fbtAFZht1ieTi9IJ8b7rcE6o7Pf+Nz5Mg3kEAIbnT94cHwgTLXgB9oh21ssRQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "linux" - ], - "peer": true, - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/workerd-windows-64": { - "version": "1.20251024.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20251024.0.tgz", - "integrity": "sha512-H0CeOA1NgLSuNrxBufObczGjl7xoXZvFlAOCHmSRyluZ6jSdm8Tb3FjPyMPLPyOF2jAeoKBTS6xzEK3Nmkq7sA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "win32" - ], - "peer": true, - "engines": { - "node": ">=16" - } - }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", @@ -2750,29 +2660,6 @@ "webidl-conversions": "^3.0.0" } }, - "node_modules/workerd": { - "version": "1.20251024.0", - "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20251024.0.tgz", - "integrity": "sha512-OfGf6pZEtE4syaHBA0Mmt2cLp8TRIoeV3XJufvrw3bC9l3STIwuTdrH5zT+K8r2hS/CBjNnCnmpj3YIPSN7T9A==", - "dev": true, - "hasInstallScript": true, - "license": "Apache-2.0", - "optional": true, - "peer": true, - "bin": { - "workerd": "bin/workerd" - }, - "engines": { - "node": ">=16" - }, - "optionalDependencies": { - "@cloudflare/workerd-darwin-64": "1.20251024.0", - "@cloudflare/workerd-darwin-arm64": "1.20251024.0", - "@cloudflare/workerd-linux-64": "1.20251024.0", - "@cloudflare/workerd-linux-arm64": "1.20251024.0", - "@cloudflare/workerd-windows-64": "1.20251024.0" - } - }, "node_modules/wrangler": { "version": "4.45.0", "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-4.45.0.tgz", diff --git a/package.json b/package.json index 4ff545f..fc98e17 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,11 @@ { "name": "twitch-cloud-ebs", "version": "0.0.0", - "private": true, + "files": [ + "static", + "static_src" + ], + "main": "static/index.js", "scripts": { "deploy": "wrangler deploy", "dev": "wrangler dev", @@ -11,7 +15,7 @@ "@sugoidogo/selflare": "^1.1.3", "@twurple/auth": "^7.4.0", "fetch-retry": "^6.0.0", - "typescript": "^5.5.2", + "typescript": "^5.9.3", "wrangler": "^4.43.0" } } diff --git a/static_src/SugoiAuthProvider.ts b/static_src/SugoiAuthProvider.ts index e1ca4ac..73361e8 100644 --- a/static_src/SugoiAuthProvider.ts +++ b/static_src/SugoiAuthProvider.ts @@ -31,8 +31,9 @@ export default class SugoiAuthProvider implements AuthProvider { #token: Token clientId: string; - constructor(client_id: string) { + constructor(client_id: string, proxy_origin = import.meta.url) { this.clientId = client_id + TwitchAuth.setProxyOrigin(proxy_origin) } #setToken = (token: Token) => { diff --git a/static_src/TwitchAuth.ts b/static_src/TwitchAuth.ts index bc4e500..c82758b 100644 --- a/static_src/TwitchAuth.ts +++ b/static_src/TwitchAuth.ts @@ -22,7 +22,15 @@ export interface AuthCode { } const redirect_uri = location.origin + location.pathname -const proxy_uri = new URL('/oauth2/token', import.meta.url) +let proxy_uri = new URL('/oauth2/token', import.meta.url) + +/** + * Changes the origin used for proxying oauth requests + * Required when using this as an npm module + */ +export function setProxyOrigin(proxy_origin: string) { + proxy_uri = new URL('/oauth2/token', proxy_origin) +} /** * Timestamp and return the token diff --git a/static_src/index.ts b/static_src/index.ts new file mode 100644 index 0000000..276a458 --- /dev/null +++ b/static_src/index.ts @@ -0,0 +1,2 @@ +export * as SugoiAuth from './SugoiAuthProvider' +export * as WebStorage from './WebStorage' \ No newline at end of file diff --git a/static_src/tsconfig.json b/static_src/tsconfig.json index 35d449c..f13e31a 100644 --- a/static_src/tsconfig.json +++ b/static_src/tsconfig.json @@ -4,6 +4,9 @@ "module": "es2020", "moduleResolution": "node", "allowImportingTsExtensions": true, - "noEmit": true, + "emitDeclarationOnly": true, + "declaration": true, + "declarationMap": true, + "declarationDir": "../static" } } \ No newline at end of file diff --git a/wrangler.jsonc b/wrangler.jsonc index f656a31..5e79546 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -35,6 +35,6 @@ } ], "build": { - "command": "esbuild static_src/*.ts --outdir=static --bundle --format=esm --minify --sourcemap --target=es2020" + "command": "tsc -p static_src/ && esbuild static_src/*.ts --outdir=static --bundle --format=esm --minify --sourcemap --target=es2020" } } \ No newline at end of file