Skip to content

Commit 34494f3

Browse files
authored
Consolidate KittyCAD API token environment variables (#7665)
* Consolidate KittyCAD API token environment variables * Remove duplicate variable in type definition * Remove unnecessary intermediate steps * Keep base label for concatenation functions
1 parent df62562 commit 34494f3

18 files changed

+46
-58
lines changed

.env.development

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
NODE_ENV=development
44
DEV=true
55

6+
# App
67
VITE_KC_API_WS_MODELING_URL=wss://api.dev.zoo.dev/ws/modeling/commands
7-
VITE_KC_API_BASE_URL=https://api.dev.zoo.dev
8+
VITE_KITTYCAD_API_BASE_URL=https://api.dev.zoo.dev
89
VITE_KC_SITE_BASE_URL=https://dev.zoo.dev
910
VITE_KC_SITE_APP_URL=https://app.dev.zoo.dev
1011
VITE_KC_CONNECTION_TIMEOUT_MS=5000
11-
#VITE_WASM_URL="optional way of overriding the wasm url, particular for unit tests which need this if you running not on the default 3000 port"
12-
#VITE_KC_DEV_TOKEN="optional token to skip auth in the app"
13-
#token="required token for playwright. TODO: clean up env vars in #3973"
12+
#VITE_WASM_URL="optional override of Wasm URL if not on default port 3000"
13+
#VITE_KITTYCAD_API_TOKEN="required for testing, optional to skip auth in the app"
14+
FAIL_ON_CONSOLE_ERRORS=true
1415

16+
# KCL
1517
RUST_BACKTRACE=1
1618
PYO3_PYTHON=/usr/local/bin/python3
17-
#KITTYCAD_API_TOKEN="required token for engine testing"
18-
19-
FAIL_ON_CONSOLE_ERRORS=true
19+
#KITTYCAD_API_TOKEN=$VITE_KITTYCAD_API_TOKEN

.env.production

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
NODE_ENV=production
2+
3+
# App
24
VITE_KC_API_WS_MODELING_URL=wss://api.zoo.dev/ws/modeling/commands
3-
VITE_KC_API_BASE_URL=https://api.zoo.dev
5+
VITE_KITTYCAD_API_BASE_URL=https://api.zoo.dev
46
VITE_KC_SITE_BASE_URL=https://zoo.dev
57
VITE_KC_SITE_APP_URL=https://app.zoo.dev
68
VITE_KC_CONNECTION_TIMEOUT_MS=15000

.github/workflows/e2e-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ jobs:
157157
timeout_minutes: 5
158158
max_attempts: 5
159159
env:
160-
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
160+
VITE_KITTYCAD_API_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
161161
TAB_API_URL: ${{ secrets.TAB_API_URL }}
162162
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
163163
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
@@ -169,7 +169,7 @@ jobs:
169169
if: always()
170170
run: npm run test:snapshots -- --last-failed --update-snapshots
171171
env:
172-
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
172+
VITE_KITTYCAD_API_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
173173
TAB_API_URL: ${{ secrets.TAB_API_URL }}
174174
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
175175
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
@@ -284,7 +284,7 @@ jobs:
284284
timeout_minutes: 5
285285
max_attempts: 5
286286
env:
287-
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
287+
VITE_KITTYCAD_API_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
288288
TAB_API_URL: ${{ secrets.TAB_API_URL }}
289289
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
290290
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
@@ -410,7 +410,7 @@ jobs:
410410
max_attempts: 9
411411
env:
412412
FAIL_ON_CONSOLE_ERRORS: true
413-
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
413+
VITE_KITTYCAD_API_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
414414
TAB_API_URL: ${{ secrets.TAB_API_URL }}
415415
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
416416
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
6363
run: xvfb-run -a npm run test:unit
6464
env:
65-
VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
65+
VITE_KITTYCAD_API_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
6666

6767
- name: Check for changes
6868
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ If you're not a Zoo employee you won't be able to access the dev environment, yo
6565

6666
### Development environment variables
6767

68-
The Copilot LSP plugin in the editor requires a Zoo API token to run. In production, we authenticate this with a token via cookie in the browser and device auth token in the desktop environment, but this token is inaccessible in the dev browser version because the cookie is considered "cross-site" (from `localhost` to `zoo.dev`). There is an optional environment variable called `VITE_KC_DEV_TOKEN` that you can populate with a dev token in a `.env.development.local` file to not check it into Git, which will use that token instead of other methods for the LSP service.
68+
The Copilot LSP plugin in the editor requires a Zoo API token to run. In production, we authenticate this with a token via cookie in the browser and device auth token in the desktop environment, but this token is inaccessible in the dev browser version because the cookie is considered "cross-site" (from `localhost` to `zoo.dev`). There is an optional environment variable called `VITE_KITTYCAD_API_TOKEN` that you can populate with a dev token in a `.env.development.local` file to not check it into Git, which will use that token instead of other methods for the LSP service.
6969

7070
### Developing in Chrome
7171

@@ -96,7 +96,7 @@ To package the app for your platform with electron-builder, run `npm run tronb:p
9696

9797
Prepare these system dependencies:
9898

99-
- Set $token from https://zoo.dev/account/api-tokens
99+
- Set `$VITE_KITTYCAD_API_TOKEN` from https://zoo.dev/account/api-tokens
100100

101101
#### Snapshot tests (Google Chrome on Ubuntu only)
102102

@@ -259,7 +259,7 @@ If the application needs to overwrite the known file on disk use this pattern. T
259259
- `npm run circular-deps:overwrite`
260260
- `npm run url-checker:overwrite`
261261

262-
#### Diff baseline and current
262+
#### Diff baseline and current
263263

264264
These commands will write a /tmp/ file on disk and compare it to the known file in the repository. This command will also be used in the CI CD pipeline for automated checks
265265

e2e/playwright/auth.spec.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect, test } from '@e2e/playwright/zoo-test'
22

3-
// test file is for testing auth functionality
43
test.describe('Authentication tests', () => {
54
test(
65
`The user can sign out and back in`,
@@ -13,22 +12,12 @@ test.describe('Authentication tests', () => {
1312
await page.setBodyDimensions({ width: 1000, height: 500 })
1413
await homePage.projectSection.waitFor()
1514

16-
// This is only needed as an override to test-utils' setup() for this test
17-
await page.addInitScript(() => {
18-
localStorage.setItem('TOKEN_PERSIST_KEY', '')
19-
})
20-
2115
await test.step('Click on sign out and expect sign in page', async () => {
2216
await toolbar.userSidebarButton.click()
2317
await toolbar.signOutButton.click()
2418
await expect(signInPage.signInButton).toBeVisible()
2519
})
2620

27-
await test.step("Refresh doesn't log the user back in", async () => {
28-
await page.reload()
29-
await expect(signInPage.signInButton).toBeVisible()
30-
})
31-
3221
await test.step('Click on sign in and cancel, click again and expect different code', async () => {
3322
await signInPage.signInButton.click()
3423
await expect(signInPage.userCode).toBeVisible()

e2e/playwright/test-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import dotenv from 'dotenv'
1717

1818
const NODE_ENV = process.env.NODE_ENV || 'development'
1919
dotenv.config({ path: [`.env.${NODE_ENV}.local`, `.env.${NODE_ENV}`] })
20-
export const token = process.env.token || ''
20+
export const token = process.env.VITE_KITTYCAD_API_TOKEN || ''
2121

2222
import type { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration'
2323

interface.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ export interface IElectronAPI {
7373
process: {
7474
env: {
7575
IS_PLAYWRIGHT: string
76-
VITE_KC_DEV_TOKEN: string
76+
VITE_KITTYCAD_API_TOKEN: string
7777
VITE_KC_API_WS_MODELING_URL: string
78-
VITE_KC_API_BASE_URL: string
78+
VITE_KITTYCAD_API_BASE_URL: string
7979
VITE_KC_SITE_BASE_URL: string
8080
VITE_KC_SITE_APP_URL: string
8181
VITE_KC_CONNECTION_TIMEOUT_MS: string
82-
VITE_KC_DEV_TOKEN: string
8382
NODE_ENV: string
8483
PROD: string
8584
DEV: string

src/env.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ export const NODE_ENV = env.NODE_ENV as string | undefined
88
export const VITE_KC_API_WS_MODELING_URL = env.VITE_KC_API_WS_MODELING_URL as
99
| string
1010
| undefined
11-
export const VITE_KC_API_BASE_URL = env.VITE_KC_API_BASE_URL
11+
export const VITE_KITTYCAD_API_BASE_URL = env.VITE_KITTYCAD_API_BASE_URL
1212
export const VITE_KC_SITE_BASE_URL = env.VITE_KC_SITE_BASE_URL
1313
export const VITE_KC_SITE_APP_URL = env.VITE_KC_SITE_APP_URL
1414
export const VITE_KC_CONNECTION_TIMEOUT_MS =
1515
env.VITE_KC_CONNECTION_TIMEOUT_MS as string | undefined
16-
export const VITE_KC_DEV_TOKEN = env.VITE_KC_DEV_TOKEN as string | undefined
16+
export const VITE_KITTYCAD_API_TOKEN = env.VITE_KITTYCAD_API_TOKEN as
17+
| string
18+
| undefined
1719
export const PROD = env.PROD as string | undefined
1820
export const TEST = env.TEST as string | undefined
1921
export const DEV = env.DEV as string | undefined

src/lang/modifyAst/addEdgeTreatment.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VITE_KC_DEV_TOKEN } from '@src/env'
1+
import { VITE_KITTYCAD_API_TOKEN } from '@src/env'
22

33
import { createLiteral } from '@src/lang/create'
44
import type {
@@ -40,10 +40,9 @@ import { isOverlap } from '@src/lib/utils'
4040
beforeAll(async () => {
4141
await initPromise
4242

43-
// THESE TEST WILL FAIL without VITE_KC_DEV_TOKEN set in .env.development.local
4443
await new Promise((resolve) => {
4544
engineCommandManager.start({
46-
token: VITE_KC_DEV_TOKEN,
45+
token: VITE_KITTYCAD_API_TOKEN,
4746
width: 256,
4847
height: 256,
4948
setMediaStream: () => {},

0 commit comments

Comments
 (0)