Skip to content

Commit 30a75e7

Browse files
committed
WIP base of structure
1 parent 965da31 commit 30a75e7

File tree

95 files changed

+4393
-794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4393
-794
lines changed

app/nuxt.config.ts

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,104 @@
11
import { extensions } from '@libertech-fr/teaket_common'
2+
import pugPlugin from 'vite-plugin-pug'
3+
import { resolve } from 'node:path'
24

35
// https://nuxt.com/docs/api/configuration/nuxt-config
46
export default defineNuxtConfig({
57
ssr: false,
68
telemetry: false,
9+
pages: true,
10+
srcDir: 'src',
11+
debug: !!process.env.DEBUG,
12+
devServer: {
13+
port: 8000,
14+
},
715
devtools: {
8-
enabled: true,
16+
enabled: process.env.NODE_ENV === 'development',
917
timeline: {
1018
enabled: true,
1119
},
1220
},
13-
modules: [...extensions.setup.app()],
21+
plugins: [
22+
{ src: '~/plugins/ofetch' },
23+
],
24+
components: {
25+
global: true,
26+
dirs: [{ path: '~/components', prefix: 'tk' }],
27+
},
28+
modules: [
29+
'nuxt-api-party',
30+
// '@hebilicious/authjs-nuxt',
31+
// '@nuxtjs/auth-next',
32+
'@sidebase/nuxt-auth',
33+
'nuxt-quasar-ui',
34+
...extensions.appSetup.default(),
35+
],
36+
auth: {
37+
baseURL: 'http://localhost:9000/core/auth',
38+
provider: {
39+
type: 'local',
40+
endpoints: {
41+
signIn: { path: '/login', method: 'post' },
42+
signOut: { path: '/logout', method: 'post' },
43+
signUp: { path: '/register', method: 'post' },
44+
getSession: { path: '/session', method: 'get' },
45+
},
46+
pages: {
47+
login: '/login',
48+
},
49+
},
50+
session: {
51+
enableRefreshOnWindowFocus: true,
52+
enableRefreshPeriodically: 5000,
53+
},
54+
globalAppMiddleware: {
55+
isEnabled: true,
56+
},
57+
},
58+
runtimeConfig: {
59+
authJs: {
60+
secret: process.env.AUTH_SECRET,
61+
},
62+
github: {
63+
clientId: process.env.NUXT_GITHUB_CLIENT_ID,
64+
clientSecret: process.env.NUXT_GITHUB_CLIENT_SECRET,
65+
},
66+
public: {
67+
authJs: {
68+
baseUrl: process.env.NUXT_NEXTAUTH_URL, // The URL of your deployed app (used for origin Check in production)
69+
verifyClientOnEveryRequest: true, // whether to hit the /auth/session endpoint on every client request
70+
},
71+
},
72+
},
73+
quasar: {},
74+
apiParty: {
75+
endpoints: {
76+
api: {
77+
url: `${process.env.NUXT_API_URL}`,
78+
schema: `${process.env.NUXT_API_URL}/swagger/json`,
79+
cookies: true,
80+
},
81+
},
82+
allowClient: true,
83+
},
84+
vite: {
85+
define: {
86+
'process.env.DEBUG': process.env.NODE_ENV === 'development',
87+
},
88+
plugins: [
89+
pugPlugin(<any>{
90+
pretty: true,
91+
}),
92+
],
93+
},
94+
alias: {
95+
cookie: resolve(__dirname, '../node_modules/cookie'),
96+
},
97+
experimental: {
98+
typescriptBundlerResolution: true,
99+
},
100+
typescript: {
101+
// typeCheck: 'build,
102+
shim: false,
103+
},
14104
})

app/package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@
66
"dev": "nuxt dev",
77
"generate": "nuxt generate",
88
"preview": "nuxt preview",
9-
"aa-postinstall": "nuxt prepare"
9+
"postinstall": "nuxt prepare"
1010
},
1111
"dependencies": {
12-
"@libertech-fr/teaket_common": "*"
12+
"@auth/core": "^0.12.0",
13+
"@hebilicious/authjs-nuxt": "^0.3.0-beta.2",
14+
"@libertech-fr/teaket_common": "*",
15+
"@nuxtjs/auth-next": "5.0.0-1667386184.dfbbb54",
16+
"@quasar/extras": "^1.16.6",
17+
"cookie": "^0.5.0",
18+
"quasar": "^2.12.5"
1319
},
1420
"devDependencies": {
15-
"@babel/plugin-transform-class-properties": "^7.22.5",
1621
"@nuxt/devtools": "latest",
22+
"@sidebase/nuxt-auth": "^0.6.0-beta.5",
1723
"@types/node": "^18.17.3",
18-
"nuxt": "^3.6.5"
24+
"nuxt": "^3.6.5",
25+
"nuxt-api-party": "^0.17.0",
26+
"nuxt-quasar-ui": "^2.0.5",
27+
"openapi-typescript": "^6.5.4",
28+
"vite-plugin-pug": "^0.3.2"
1929
}
2030
}

app/src/components/hook.vue

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
1-
<template>
2-
<div>
3-
4-
</div>
1+
<!--suppress JSUnusedLocalSymbols -->
2+
<template lang='pug'>
3+
div(:id='"tk-hook:" + name')
4+
template(v-for="(customSlot, key) in customSlots")
5+
pre.bg-red.text-white(v-if='debug' v-html="JSON.stringify({name, customSlot, data}, null, 2)")
6+
component(
7+
v-if='customSlot.componentName'
8+
:key='key'
9+
:is="customSlot.componentName"
10+
v-bind="{...customSlot.data, ...data}"
11+
)
512
</template>
613

7-
<script>
8-
export default {
9-
name: 'TartineComponent',
10-
props: {
11-
name: string
12-
}
14+
<script lang='ts' setup>
15+
import { useAppConfig } from '#imports'
16+
import { sort } from 'radash'
17+
18+
//TODO: Convert to a sdk repository and publish it on npm for 3rd-party extensions
19+
interface CustomSlotInterface {
20+
componentName: string
21+
priority?: number
22+
data?: Record<string, any>
1323
}
24+
25+
const props = defineProps({
26+
name: {
27+
type: String,
28+
required: true,
29+
},
30+
data: {
31+
type: Object,
32+
default: () => ({}),
33+
},
34+
debug: {
35+
type: Boolean,
36+
default: false,
37+
},
38+
})
39+
40+
const config = useAppConfig()
41+
const customSlots = computed(() => {
42+
if (config.customSlots.hasOwnProperty(props.name)) {
43+
const configCustomSlots = config.customSlots as Record<string, CustomSlotInterface[]>
44+
return sort(configCustomSlots[props.name], (list: CustomSlotInterface) => list.priority || 0, true)
45+
}
46+
})
1447
</script>

app/src/components/tartine.vue

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

app/src/composables/useApiFetch.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { AllPaths, HttpMethod, IgnoreCase, OpenApiError, OpenApiResponse } from 'nuxt-api-party/dist/runtime/types'
2+
import { MaybeRefOrGetter } from 'nuxt-api-party/dist/runtime/utils'
3+
import { paths as Paths } from '#nuxt-api-party/api'
4+
import { UseOpenApiDataOptions } from 'nuxt-api-party/dist/runtime/composables/useApiData'
5+
import { AsyncData } from 'nuxt/app'
6+
import { FetchError } from 'ofetch'
7+
8+
// export function useApiFetch<P extends GETPlainPaths<Paths>>(
9+
// path: MaybeRefOrGetter<P>,
10+
// opts?: Omit<UseOpenApiDataOptions<Paths[`/${P}`]>, 'method'>,
11+
// ): AsyncData<OpenApiResponse<Paths[`/${P}`]['get']> | undefined, FetchError<OpenApiError<Paths[`/${P}`]['get']>>> {
12+
// return useApiData(path, {
13+
// ...opts,
14+
// cache: false,
15+
// client: true,
16+
// } as any)
17+
// }
18+
19+
export function useApiFetch<P extends AllPaths<Paths>, M extends IgnoreCase<keyof Paths[`/${P}`] & HttpMethod>>(
20+
path: MaybeRefOrGetter<P>,
21+
opts?: Omit<UseOpenApiDataOptions<Paths[`/${P}`], M>, 'method'> & {
22+
method: M;
23+
} & {
24+
/* @ts-ignore */
25+
body: Paths[`/${P}`][Lowercase<M>]['requestBody']['content']['application/json'],
26+
},
27+
// opts?: UseOpenApiDataOptions<Paths[`/${P}`], M> & {
28+
// method: M;
29+
// },
30+
/* @ts-ignore */
31+
body?: Paths[`/${P}`][Lowercase<M>]['requestBody']['content']['application/json'],
32+
): /* @ts-ignore */
33+
AsyncData<OpenApiResponse<Paths[`/${P}`][Lowercase<M>]> | undefined, FetchError<OpenApiError<Paths[`/${P}`][Lowercase<M>]>>> {
34+
return useApiData(path, {
35+
...opts,
36+
cache: false,
37+
client: true,
38+
body: {
39+
...opts?.body,
40+
...body,
41+
}
42+
} as any)
43+
}

app/src/pages/index.vue

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,88 @@
1-
<template>
2-
<div>
3-
<template v-for="(customSlot, key) in accueilCustomSlot">
4-
<component v-if='customSlot.componentName' :key='key' :is="customSlot.componentName"/>
5-
</template>
6-
<!-- <AccueilComponent/> -->
7-
<pre v-html="JSON.stringify(config)"></pre>
8-
accueil
9-
<hook name="index.accueil.bottom" v-bind="config"/>
10-
</div>
1+
<template lang='pug'>
2+
div
3+
tk-hook(name="accueil" :data='{exemple: 1}' debug)
4+
span Accueil
5+
tk-hook(name="index.accueil.bottom")
6+
q-btn(@click='signIn()') signIn
7+
q-btn(@click='signOut()') signOut
8+
q-btn(@click='call()') call
119
</template>
1210

13-
<script setup>
14-
import {resolveComponent, computed} from 'vue'
15-
import {useAppConfig} from '#imports'
16-
import {sort} from 'radash'
11+
<script lang='ts' setup>
12+
definePageMeta({ auth: true })
13+
// import { components } from '#nuxt-api-party/api'
1714
18-
const config = useAppConfig()
19-
const accueilCustomSlot = sort(config.customSlots.accueil, (list) => list.priority, true)
20-
// export default {
21-
// setup() {
22-
// const config = useAppConfig()
23-
// console.log('config', config)
24-
// return {
25-
// middleware: config.customSlots,
26-
// // accueilSlot: resolveComponent(config.customSlots.accueil)
27-
// }
28-
// },
29-
// data: () => ({
30-
// currentComponent: null,
31-
// }),
32-
// mounted() {
33-
// const config = useAppConfig()
34-
// console.log('config', config)
35-
// this.currentComponent = resolveComponent(config.customSlots.accueil)
36-
// }
37-
// }
15+
// import { useApiFetch } from '../../../docs/useApiFetch.ts'
16+
17+
import { useApiFetch } from '~/composables/useApiFetch'
18+
19+
const { signIn, signOut, session, status, cookies, getProviders, user, sessionToken } = useAuth()
20+
// type TicketCreateDto = components['schemas']['TicketCreateDto']
21+
22+
const formData = {
23+
subject: 'toto'
24+
}
25+
try {
26+
const { data } = await useApiData('tickets/ticket', {
27+
method: 'post',
28+
query: {
29+
aaaa: 1
30+
},
31+
body: {
32+
subject: 1
33+
},
34+
async onRequestError({ error }) {
35+
console.log(error)
36+
},
37+
})
38+
} catch (e) {
39+
console.log('e', e)
40+
}
41+
42+
const call = async () => {
43+
// const { data } = await useApiData('tickets/ticket', {
44+
// })
45+
try {
46+
const { data } = await useApiFetch2('tickets/ticket', {
47+
method: 'post',
48+
cache: false,
49+
client: true,
50+
// query: {
51+
// limit: 1
52+
// },
53+
// pathParams: {
54+
// id: '1'
55+
// },
56+
body: {
57+
subjecet: "1"
58+
},
59+
}, {
60+
subject: 'aaa'
61+
})
62+
} catch (e) {
63+
console.log('e', e)
64+
}
65+
// console.log('test', data)
66+
// onRequest(context: FetchContext): Promise<void> | void {
67+
// context.options.headers = {
68+
// 'Test': '1'
69+
// }
70+
// console.log('onRequest', context)
71+
// }
72+
// method: 'get',
73+
// // client: true,
74+
// // headers: {
75+
// // 'Test': '1'
76+
// // },
77+
// // body: formData,
78+
// // watch: {
79+
// // onRequest: {
80+
// // handler: () => {
81+
// // console.log('onRequest')
82+
// // },
83+
// // }
84+
// // }
85+
// })
86+
console.log('data', data)
87+
}
3888
</script>

0 commit comments

Comments
 (0)