mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Updated login operation
This commit is contained in:
parent
1086fce6bd
commit
4412d8e66c
@ -3,7 +3,8 @@ import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
import type { LoginMutation, LoginMutationVariables } from '../../schema'
|
||||
import type { LoginOperation } from '../../types/login'
|
||||
import type { LoginMutation } from '../../schema'
|
||||
import type { RecursivePartial } from '../utils/types'
|
||||
import concatHeader from '../utils/concat-cookie'
|
||||
import type { BigcommerceConfig, Provider } from '..'
|
||||
@ -16,24 +17,20 @@ export const loginMutation = /* GraphQL */ `
|
||||
}
|
||||
`
|
||||
|
||||
export type LoginResult<T extends { result?: any } = { result?: string }> = T
|
||||
|
||||
export type LoginVariables = LoginMutationVariables
|
||||
|
||||
function loginOperation({ commerce }: OperationContext<Provider>) {
|
||||
async function login(opts: {
|
||||
variables: LoginVariables
|
||||
variables: LoginOperation['variables']
|
||||
config?: BigcommerceConfig
|
||||
res: ServerResponse
|
||||
}): Promise<LoginResult>
|
||||
}): Promise<LoginOperation['data']>
|
||||
|
||||
async function login<T extends { result?: any }, V = any>(
|
||||
async function login<T extends LoginOperation>(
|
||||
opts: {
|
||||
variables: V
|
||||
variables: T['variables']
|
||||
config?: BigcommerceConfig
|
||||
res: ServerResponse
|
||||
} & OperationOptions
|
||||
): Promise<LoginResult<T>>
|
||||
): Promise<T['data']>
|
||||
|
||||
async function login({
|
||||
query = loginMutation,
|
||||
@ -42,10 +39,10 @@ function loginOperation({ commerce }: OperationContext<Provider>) {
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables: LoginVariables
|
||||
variables: LoginOperation['variables']
|
||||
res: ServerResponse
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<LoginResult> {
|
||||
}): Promise<LoginOperation['data']> {
|
||||
config = commerce.getConfig(config)
|
||||
|
||||
const { data, res } = await config.fetch<RecursivePartial<LoginMutation>>(
|
||||
|
@ -1 +1,8 @@
|
||||
import * as Core from '@commerce/types/login'
|
||||
import type { LoginMutationVariables } from '../schema'
|
||||
|
||||
export * from '@commerce/types/login'
|
||||
|
||||
export type LoginOperation = Core.LoginOperation & {
|
||||
variables: LoginMutationVariables
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import type { LoginOperation } from '../types/login'
|
||||
import type { GetAllPagesResult } from '../types/page'
|
||||
import type { ServerResponse } from 'http'
|
||||
import type { APIProvider, CommerceAPI, CommerceAPICore } from '.'
|
||||
|
||||
@ -14,23 +16,34 @@ export const defaultOperations = OPERATIONS.reduce((ops, k) => {
|
||||
|
||||
export type AllowedOperations = typeof OPERATIONS[number]
|
||||
|
||||
export type LoginResult<T extends { result?: any } = { result?: string }> = T
|
||||
|
||||
export type Operations<P extends APIProvider> = {
|
||||
login: {
|
||||
(opts: {
|
||||
variables: any
|
||||
<T extends LoginOperation>(opts: {
|
||||
variables: T['variables']
|
||||
config?: P['config']
|
||||
res: ServerResponse
|
||||
}): Promise<LoginResult>
|
||||
}): Promise<T['data']>
|
||||
|
||||
<T extends { result?: any }, V = any>(
|
||||
<T extends LoginOperation>(
|
||||
opts: {
|
||||
variables: V
|
||||
variables: T['variables']
|
||||
config?: P['config']
|
||||
res: ServerResponse
|
||||
} & OperationOptions
|
||||
): Promise<LoginResult<T>>
|
||||
): Promise<T['data']>
|
||||
}
|
||||
getAllPages: {
|
||||
(opts?: {
|
||||
config?: P['config']
|
||||
preview?: boolean
|
||||
}): Promise<GetAllPagesResult>
|
||||
|
||||
<T extends GetAllPagesResult>(
|
||||
opts: {
|
||||
config?: P['config']
|
||||
preview?: boolean
|
||||
} & OperationOptions
|
||||
): Promise<T>
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,3 +18,8 @@ export type LoginSchema<T extends LoginTypes = LoginTypes> = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type LoginOperation = {
|
||||
data: { result?: string }
|
||||
variables: unknown
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user