@mframework/core 0.0.2 → 0.0.3
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/index.ts +5 -1
- package/package.json +1 -1
- package/src/adapters/auth.ts +6 -3
- package/src/adapters/commerce.ts +10 -0
- package/src/adapters/index.ts +9 -0
- package/src/adapters/search.ts +1 -0
- package/src/adapters/transport.ts +7 -0
- package/src/client/index.ts +13 -0
- package/src/registry/auth.ts +10 -0
- package/src/registry/commerce.ts +11 -0
- package/src/registry/index.ts +38 -0
- package/src/registry/search.ts +6 -0
- package/src/types/prisma-client.d.ts +1 -1
package/index.ts
CHANGED
|
@@ -115,4 +115,8 @@ export * from './src/normalizers/utils/i18n-redirects'
|
|
|
115
115
|
export * from './src/normalizers/utils/logger'
|
|
116
116
|
export * from './src/normalizers/utils/shared'
|
|
117
117
|
export * from './src/normalizers/utils/ssr'
|
|
118
|
-
export * from './src/normalizers/utils/wrap'
|
|
118
|
+
export * from './src/normalizers/utils/wrap'
|
|
119
|
+
|
|
120
|
+
export * from './src/client';
|
|
121
|
+
export * from './src/adapters';
|
|
122
|
+
export * from './src/registry';
|
package/package.json
CHANGED
package/src/adapters/auth.ts
CHANGED
|
@@ -5,7 +5,10 @@ export interface AuthAdapterConfig extends BaseAdapterConfig {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export interface AuthAdapter {
|
|
8
|
-
login(
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
login(input: LoginInput): Promise<Result<Session>>
|
|
9
|
+
register(input: RegisterInput): Promise<Result<Session>>
|
|
10
|
+
logout(): Promise<Result<true>>
|
|
11
|
+
getSession(): Promise<Result<Session>>
|
|
12
|
+
refresh(): Promise<Result<Session>>
|
|
13
|
+
getUser(): Promise<Result<User>>
|
|
11
14
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CommerceAdapter {
|
|
2
|
+
getProduct(id: string): Promise<Result<Product>>
|
|
3
|
+
listProducts(): Promise<Result<Product[]>>
|
|
4
|
+
|
|
5
|
+
getCart(): Promise<Result<Cart>>
|
|
6
|
+
addToCart(item: { productId: string; variantId?: string; quantity: number }): Promise<Result<Cart>>
|
|
7
|
+
updateCartItem(itemId: string, quantity: number): Promise<Result<Cart>>
|
|
8
|
+
removeCartItem(itemId: string): Promise<Result<Cart>>
|
|
9
|
+
clearCart(): Promise<Result<Cart>>
|
|
10
|
+
}
|
package/src/adapters/search.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { auth } from '../registry/auth'
|
|
2
|
+
import { commerce } from '../registry/commerce'
|
|
3
|
+
import { search } from '../registry/search'
|
|
4
|
+
import { getRegistry } from '../registry'
|
|
5
|
+
|
|
6
|
+
export const sdk = {
|
|
7
|
+
auth,
|
|
8
|
+
commerce,
|
|
9
|
+
search,
|
|
10
|
+
get transport() {
|
|
11
|
+
return getRegistry().transport
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getRegistry } from './index'
|
|
2
|
+
|
|
3
|
+
export const auth = {
|
|
4
|
+
login: (input: { email: string; password: string }) => getRegistry().auth?.login(input),
|
|
5
|
+
register: (input: { email: string; password: string; confirmPassword: string }) => getRegistry().auth?.register(input),
|
|
6
|
+
logout: () => getRegistry().auth?.logout(),
|
|
7
|
+
getSession: () => getRegistry().auth?.getSession(),
|
|
8
|
+
refresh: () => getRegistry().auth?.refresh(),
|
|
9
|
+
getUser: () => getRegistry().auth?.getUser()
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getRegistry } from './index'
|
|
2
|
+
|
|
3
|
+
export const commerce = {
|
|
4
|
+
getProduct: (id: string) => getRegistry().commerce?.getProduct(id),
|
|
5
|
+
listProducts: () => getRegistry().commerce?.listProducts(),
|
|
6
|
+
getCart: () => getRegistry().commerce?.getCart(),
|
|
7
|
+
addToCart: (item: { productId: string; variantId?: string; quantity: number }) => getRegistry().commerce?.addToCart(item),
|
|
8
|
+
updateCartItem: (id: string, qty: number) => getRegistry().commerce?.updateCartItem(id, qty),
|
|
9
|
+
removeCartItem: (id: string) => getRegistry().commerce?.removeCartItem(id),
|
|
10
|
+
clearCart: () => getRegistry().commerce?.clearCart()
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TransportAdapter,
|
|
3
|
+
AuthAdapter,
|
|
4
|
+
CommerceAdapter,
|
|
5
|
+
SearchAdapter
|
|
6
|
+
} from '../adapters'
|
|
7
|
+
|
|
8
|
+
export interface SDKRegistry {
|
|
9
|
+
transport: TransportAdapter
|
|
10
|
+
auth?: AuthAdapter
|
|
11
|
+
commerce?: CommerceAdapter
|
|
12
|
+
search?: SearchAdapter
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const registry: Partial<SDKRegistry> = {}
|
|
16
|
+
|
|
17
|
+
export const setTransport = (adapter: TransportAdapter) => {
|
|
18
|
+
registry.transport = adapter
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const setAuthAdapter = (adapter: AuthAdapter) => {
|
|
22
|
+
registry.auth = adapter
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const setCommerceAdapter = (adapter: CommerceAdapter) => {
|
|
26
|
+
registry.commerce = adapter
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const setSearchAdapter = (adapter: SearchAdapter) => {
|
|
30
|
+
registry.search = adapter
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const getRegistry = (): SDKRegistry => {
|
|
34
|
+
if (!registry.transport) {
|
|
35
|
+
throw new Error('Transport adapter not set')
|
|
36
|
+
}
|
|
37
|
+
return registry as SDKRegistry
|
|
38
|
+
}
|