Skip to content

Commit 78777c3

Browse files
chore: wip
1 parent 6922a17 commit 78777c3

File tree

3 files changed

+40
-37
lines changed

3 files changed

+40
-37
lines changed

app/Actions/Billable/CheckoutAction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default new Action({
88
description: 'Checkout Action',
99
method: 'POST',
1010
async handle(request: RequestInstance) {
11-
const user = request.user()
11+
const user = await request.user()
1212

1313
if (!user) {
1414
return response.json({ message: 'User not found' }, 404)
@@ -19,8 +19,8 @@ export default new Action({
1919
cancel_url: 'https://localhost:3000/cancel',
2020
}
2121

22-
const checkout = await manageCheckout.create(user, params)
22+
const session = await manageCheckout.create(user, params)
2323

24-
return response.json({ message: 'Category deleted successfully' })
24+
return response.json({ url: session.url })
2525
},
2626
})

storage/framework/core/config/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { overrides } from './overrides'
55

66
// merged defaults and overrides
77
export const config: StacksOptions = {
8-
...defaults,
8+
// ...defaults,
99
...overrides,
1010
}
1111

storage/framework/core/env/src/types.ts

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Infer, VineBoolean, VineEnum, VineNumber, VineString } from '@stacksjs/validation'
2-
import type { SchemaTypes } from '@vinejs/vine/types'
1+
import type { BooleanValidatorType, EnumValidatorType, NumberValidatorType, StringValidatorType, ValidationType } from '@stacksjs/ts-validation'
32
import type { EnvKey } from '../../../env'
43
import { schema } from '@stacksjs/validation'
54
import env from '~/config/env'
@@ -17,76 +16,79 @@ export const envEnum: EnumObject = {
1716
}
1817

1918
interface StringEnvConfig {
20-
validation: VineString
19+
validation: StringValidatorType
2120
default: string
2221
}
2322

2423
interface NumberEnvConfig {
25-
validation: VineNumber
24+
validation: NumberValidatorType
2625
default: number
2726
}
2827

2928
interface BooleanEnvConfig {
30-
validation: VineBoolean
29+
validation: BooleanValidatorType
3130
default: boolean
3231
}
3332

3433
interface EnumEnvConfig {
35-
validation: VineEnum<any>
34+
validation: EnumValidatorType<string>
3635
default: string
3736
}
3837

3938
type EnvValueConfig = StringEnvConfig | NumberEnvConfig | BooleanEnvConfig | EnumEnvConfig
4039

4140
export type EnvConfig = Partial<Record<EnvKey, EnvValueConfig>>
4241

43-
type EnvMap = Record<string, SchemaTypes>
42+
type EnvMap = Record<string, string>
43+
44+
type TypeFromString<T extends string> = T extends 'string'
45+
? string
46+
: T extends 'number'
47+
? number
48+
: T extends 'boolean'
49+
? boolean
50+
: T extends 'enum'
51+
? string
52+
: never
53+
54+
type Infer<T extends Record<string, string>> = {
55+
[K in keyof T]: TypeFromString<T[K]>
56+
}
4457

4558
const envStructure: EnvMap = Object.entries(env).reduce((acc, [key, value]) => {
4659
if (typeof value === 'object' && value !== null && 'validation' in value) {
47-
acc[key] = (value as EnvValueConfig).validation
60+
acc[key] = (value as EnvValueConfig).validation.name
4861
return acc
4962
}
5063

51-
let validatorType: SchemaTypes
64+
let typeName: string
5265
switch (typeof value) {
5366
case 'string':
54-
validatorType = schema.string()
67+
typeName = 'string'
5568
break
5669
case 'number':
57-
validatorType = schema.number()
70+
typeName = 'number'
5871
break
5972
case 'boolean':
60-
validatorType = schema.boolean()
73+
typeName = 'boolean'
6174
break
6275
default:
6376
if (Array.isArray(value)) {
64-
validatorType = schema.enum(value as string[])
77+
typeName = 'enum'
6578
break
6679
}
6780

6881
// check if is on object
6982
if (typeof value === 'object' && value !== null) {
70-
const schemaNameSymbol = Symbol.for('schema_name')
71-
const schemaName = (value as { [key: symbol]: string })[schemaNameSymbol]
72-
73-
if (schemaName === 'vine.string') {
74-
validatorType = schema.string()
75-
break
76-
}
83+
const schemaName = (value as { name: string }).name
7784

78-
if (schemaName === 'vine.number') {
79-
validatorType = schema.number()
80-
break
81-
}
82-
83-
if (schemaName === 'vine.boolean') {
84-
validatorType = schema.boolean()
85+
if (schemaName === 'string' || schemaName === 'number' || schemaName === 'boolean') {
86+
typeName = schemaName
8587
break
8688
}
8789

8890
if (!schemaName && key in envEnum) {
89-
validatorType = schema.enum(envEnum[key as keyof typeof envEnum])
91+
typeName = 'enum'
9092
break
9193
}
9294

@@ -96,14 +98,15 @@ const envStructure: EnvMap = Object.entries(env).reduce((acc, [key, value]) => {
9698
throw new Error(`Invalid env value for ${key}`)
9799
}
98100

99-
acc[key] = validatorType
101+
acc[key] = typeName
100102
return acc
101-
}, {} as EnvMap)
103+
}, {} as Record<string, string>)
102104

103-
export const envSchema: ReturnType<typeof schema.object> = schema.object(envStructure)
104-
export type Env = Infer<typeof envSchema>
105+
export type Env = {
106+
[K in keyof typeof envStructure]: typeof envStructure[K]
107+
}
105108

106-
export type EnvOptions = Env
109+
export type EnvSchema = ReturnType<typeof schema.object<typeof envStructure>>
107110

108111
export interface FrontendEnv {
109112
FRONTEND_APP_ENV: 'local' | 'development' | 'staging' | 'production'

0 commit comments

Comments
 (0)