@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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mframework/core",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "The core and robust API module serving as a wrapper around Prisma for the M Framework.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -5,7 +5,10 @@ export interface AuthAdapterConfig extends BaseAdapterConfig {
5
5
  }
6
6
 
7
7
  export interface AuthAdapter {
8
- login(payload: unknown): Promise<unknown>
9
- logout(): Promise<void>
10
- getSession(): Promise<unknown | null>
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
+ }
@@ -0,0 +1,9 @@
1
+ export * from './transport'
2
+ export * from './auth'
3
+ export * from './commerce'
4
+ export * from './search'
5
+ export * from './registry'
6
+ export * from './cart'
7
+ export * from './catalog'
8
+ export * from './common'
9
+ export * from './lists'
@@ -23,4 +23,5 @@ export interface SearchAdapter<TItem = unknown>
23
23
  type: 'search'
24
24
  search(query: SearchQuery): Promise<SearchResult<TItem>>
25
25
  suggest?(term: string): Promise<string[]>
26
+ facets(query: SearchQuery): Promise<Result<Facet[]>>
26
27
  }
@@ -0,0 +1,7 @@
1
+ export interface TransportAdapter {
2
+ request<T = unknown>(
3
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
4
+ path: string,
5
+ options?: RequestOptions
6
+ ): Promise<APIResponse<T>>
7
+ }
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ import { getRegistry } from './index'
2
+
3
+ export const search = {
4
+ search: (query: SearchQuery) => getRegistry().search?.search(query),
5
+ facets: (query: SearchQuery) => getRegistry().search?.facets(query)
6
+ }
@@ -1,4 +1,4 @@
1
- declare module '@mframework/api/prisma' {
1
+ declare module '@mframework/core/prisma' {
2
2
  // Re-export the generated PrismaClient type from the shared generated client
3
3
  import type { PrismaClient as GeneratedPrismaClient } from '../../prisma/generated/client'
4
4