Skip to content

Commit 658f779

Browse files
Use getBillingInfo from typescript sdk (#245)
* WIP: more billing tests * Lil refactor removing deps and added all test cases * Add 4xx error code handler and test cases * Fix up types * Be more rigorous in type checking and simplify reasoning about tier type * Link up to KittyCAD/kittycad.ts#365 * Clean up * Point to react-shared instead with react-shared#15 * Bump after upstream publishing --------- Co-authored-by: lee-at-zoo-corp <[email protected]>
1 parent f78d748 commit 658f779

File tree

4 files changed

+22
-146
lines changed

4 files changed

+22
-146
lines changed

package-lock.json

Lines changed: 8 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"type": "module",
5252
"dependencies": {
5353
"@kittycad/lib": "^3.0.2",
54-
"@kittycad/react-shared": "^0.1.4",
54+
"@kittycad/react-shared": "^0.1.6",
5555
"@threlte/core": "^6.1.0",
5656
"@threlte/extras": "^7.3.0",
5757
"@types/core-js": "^2.5.8",

src/lib/billing.ts

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/routes/(sidebarLayout)/+layout.server.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { DOMAIN, PLAYWRIGHT_MOCKING_HEADER } from '$lib/consts.js'
22
import { getCookieName } from '$lib/cookies.js'
33
import { hooksUserMocks, isUserMock } from '$lib/mocks.js'
44
import { SIGN_OUT_PARAM } from '$lib/paths.js'
5-
import { redirect } from '@sveltejs/kit'
5+
import { redirect, type ServerLoadEvent } from '@sveltejs/kit'
66
import { env } from '$lib/env'
7-
import { getBillingInfo, isErr } from '$lib/billing'
87
import { users } from '@kittycad/lib'
8+
import { getBillingInfo, BillingError } from '@kittycad/react-shared'
99
import { createZooClient } from '$lib/zooClient'
1010

11-
export const load = async ({ cookies, request, url, fetch }) => {
11+
export const load = async (args: ServerLoadEvent) => {
12+
const { cookies, request, url, fetch } = args
13+
1214
if (url.searchParams.get(SIGN_OUT_PARAM)) {
1315
signOut()
1416
}
@@ -20,12 +22,11 @@ export const load = async ({ cookies, request, url, fetch }) => {
2022
signOut()
2123
}
2224

23-
const currentUser = await users
24-
.get_user_self({ client: createZooClient({ token, fetch }) })
25-
.catch((e) => {
26-
console.error('Error fetching user:', e)
27-
signOut()
28-
})
25+
const client = createZooClient({ token, fetch })
26+
const currentUser = await users.get_user_self({ client }).catch((e) => {
27+
console.error('Error fetching user:', e)
28+
signOut()
29+
})
2930

3031
if (!currentUser) {
3132
signOut()
@@ -41,9 +42,9 @@ export const load = async ({ cookies, request, url, fetch }) => {
4142
}
4243
}
4344

44-
const billing = await getBillingInfo(token)
45-
if (isErr(billing)) {
46-
console.error('Error fetching billing info:', billing)
45+
const billing = await getBillingInfo(client)
46+
if (BillingError.from(billing)) {
47+
console.error('Error fetching billing info:', billing.error)
4748
return {
4849
user: currentUser,
4950
token: token
@@ -53,7 +54,6 @@ export const load = async ({ cookies, request, url, fetch }) => {
5354
return {
5455
user: currentUser,
5556
token: token,
56-
tier: billing.tier,
5757
credits: billing.credits,
5858
allowance: billing.allowance
5959
}

0 commit comments

Comments
 (0)