@dev.smartpricing/platform-layer 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -89,6 +89,8 @@ interface ApiClientOptions {
|
|
|
89
89
|
csrf?: ApiClientCsrfConfig
|
|
90
90
|
auth?: ApiClientAuthConfig
|
|
91
91
|
errorSerializer?: (context: { status: number; statusText: string; data: unknown }) => unknown
|
|
92
|
+
onRequest?: FetchHook<FetchContext>
|
|
93
|
+
onResponseError?: FetchHook<FetchContext & { response: Response }>
|
|
92
94
|
}
|
|
93
95
|
```
|
|
94
96
|
|
|
@@ -98,6 +100,8 @@ interface ApiClientOptions {
|
|
|
98
100
|
| `csrf` | `ApiClientCsrfConfig` | CSRF token injection config. |
|
|
99
101
|
| `auth` | `ApiClientAuthConfig` | Auth config for token refresh and MFA. When omitted, returns a raw `$fetch` instance with no auth handling. |
|
|
100
102
|
| `errorSerializer` | `(context) => unknown` | Custom error serializer. Receives `{ status, statusText, data }` from [`FetchError`](https://github.com/unjs/ofetch#%EF%B8%8F-access-to-raw-response). |
|
|
103
|
+
| `onRequest` | `FetchHook<FetchContext>` | Custom [`onRequest` interceptor](https://github.com/unjs/ofetch#%EF%B8%8F-interceptors) appended after built-in hooks (cookie forwarding, CSRF). |
|
|
104
|
+
| `onResponseError` | `FetchHook<FetchContext & { response: Response }>` | Custom [`onResponseError` interceptor](https://github.com/unjs/ofetch#%EF%B8%8F-interceptors) called after auth/MFA handling. |
|
|
101
105
|
|
|
102
106
|
#### CSRF Config
|
|
103
107
|
|
package/_shared/mfa.ts
CHANGED
|
@@ -58,6 +58,30 @@ export const MfaRegenerateRecoveryCodesResponseSchema = z.object({
|
|
|
58
58
|
recovery_codes: z.array(z.string()),
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
+
// ── Send email code ────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
export const MfaSendEmailCodeRequestSchema = z.object({
|
|
64
|
+
enrollmentId: z.string(),
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
export const MfaSendEmailCodeResponseSchema = z.object({
|
|
68
|
+
sent: z.literal(true),
|
|
69
|
+
email_masked: z.string(),
|
|
70
|
+
expires_in_seconds: z.number(),
|
|
71
|
+
retry_after_seconds: z.number(),
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
// ── Verify email ───────────────────────────────────────────────────
|
|
75
|
+
|
|
76
|
+
export const MfaVerifyEmailRequestSchema = z.object({
|
|
77
|
+
enrollmentId: z.string(),
|
|
78
|
+
emailCode: z.string(),
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
export const MfaVerifyEmailResponseSchema = z.object({
|
|
82
|
+
verified: z.literal(true),
|
|
83
|
+
})
|
|
84
|
+
|
|
61
85
|
// ── Types ───────────────────────────────────────────────────────────
|
|
62
86
|
|
|
63
87
|
export type MfaStepUpRequest = z.infer<typeof MfaStepUpRequestSchema>
|
|
@@ -73,3 +97,9 @@ export type MfaDisableResponse = z.infer<typeof MfaDisableResponseSchema>
|
|
|
73
97
|
|
|
74
98
|
export type MfaRegenerateRecoveryCodesRequest = z.infer<typeof MfaRegenerateRecoveryCodesRequestSchema>
|
|
75
99
|
export type MfaRegenerateRecoveryCodesResponse = z.infer<typeof MfaRegenerateRecoveryCodesResponseSchema>
|
|
100
|
+
|
|
101
|
+
export type MfaSendEmailCodeRequest = z.infer<typeof MfaSendEmailCodeRequestSchema>
|
|
102
|
+
export type MfaSendEmailCodeResponse = z.infer<typeof MfaSendEmailCodeResponseSchema>
|
|
103
|
+
|
|
104
|
+
export type MfaVerifyEmailRequest = z.infer<typeof MfaVerifyEmailRequestSchema>
|
|
105
|
+
export type MfaVerifyEmailResponse = z.infer<typeof MfaVerifyEmailResponseSchema>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MfaSendEmailCodeRequest, MfaSendEmailCodeResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useMfaSendEmailCodeMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: MfaSendEmailCodeRequest) =>
|
|
8
|
+
client<MfaSendEmailCodeResponse>('/api/auth/mfa/send-email-code', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MfaVerifyEmailRequest, MfaVerifyEmailResponse } from '@package/platform-shared'
|
|
2
|
+
|
|
3
|
+
export function useMfaVerifyEmailMutation() {
|
|
4
|
+
const client = useApiClient()
|
|
5
|
+
|
|
6
|
+
return useMutation({
|
|
7
|
+
mutation: (body: MfaVerifyEmailRequest) =>
|
|
8
|
+
client<MfaVerifyEmailResponse>('/api/auth/mfa/verify-email', { method: 'POST', body }),
|
|
9
|
+
})
|
|
10
|
+
}
|
package/nuxt.config.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { dirname, join } from 'node:path'
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
2
3
|
import { fileURLToPath } from 'node:url'
|
|
3
4
|
|
|
4
5
|
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
6
|
+
const sharedDir = join(currentDir, '_shared')
|
|
5
7
|
|
|
6
8
|
export default defineNuxtConfig({
|
|
7
9
|
extends: ['nuxt-ui-layer'],
|
|
8
10
|
|
|
9
11
|
alias: {
|
|
10
|
-
|
|
12
|
+
// _shared exists only in published tarball (created by prepack script)
|
|
13
|
+
...(existsSync(sharedDir) && { '@package/platform-shared': sharedDir }),
|
|
11
14
|
},
|
|
12
15
|
|
|
13
16
|
modules: [
|