-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass in handleClientError method from the strategy
- Loading branch information
1 parent
9f02294
commit d00eb03
Showing
7 changed files
with
53 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 7 additions & 10 deletions
17
packages/shopify-app-remix/src/server/authenticate/admin/helpers/create-admin-api-context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import {Session, ShopifyRestResources} from '@shopify/shopify-api'; | ||
|
||
import type {BasicParams} from '../../../types'; | ||
import {AdminApiContext, adminClientFactory} from '../../../clients/admin'; | ||
import {AuthorizationStrategy} from '../strategies/types'; | ||
|
||
import {handleClientErrorFactory} from './handle-client-error'; | ||
import { | ||
AdminApiContext, | ||
HandleAdminClientError, | ||
adminClientFactory, | ||
} from '../../../clients/admin'; | ||
|
||
export function createAdminApiContext< | ||
Resources extends ShopifyRestResources = ShopifyRestResources, | ||
>( | ||
request: Request, | ||
session: Session, | ||
params: BasicParams, | ||
authStrategy?: AuthorizationStrategy, | ||
handleClientError: HandleAdminClientError, | ||
): AdminApiContext<Resources> { | ||
return adminClientFactory<Resources>({ | ||
session, | ||
params, | ||
handleClientError: handleClientErrorFactory({ | ||
request, | ||
authStrategy, | ||
}), | ||
handleClientError, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 10 additions & 10 deletions
20
packages/shopify-app-remix/src/server/authenticate/admin/strategies/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import {Session} from '@shopify/shopify-api'; | ||
import {HttpResponseError, Session} from '@shopify/shopify-api'; | ||
|
||
import {HandleAdminClientError} from '../../../clients'; | ||
|
||
export interface SessionContext { | ||
shop: string; | ||
session?: Session; | ||
sessionToken?: string; | ||
} | ||
|
||
export interface HandleClientErrorOptions { | ||
export interface OnErrorOptions { | ||
request: Request; | ||
authStrategy?: AuthorizationStrategy; | ||
session: Session; | ||
error: HttpResponseError; | ||
} | ||
|
||
export interface HandleInvalidAccessTokenOptions { | ||
export interface HandleClientErrorOptions { | ||
request: Request; | ||
session: Session; | ||
error: any; | ||
onError?: ({session, error}: OnErrorOptions) => Promise<void | never>; | ||
} | ||
|
||
export interface AuthorizationStrategy { | ||
respondToOAuthRequests: (request: Request) => Promise<void | never>; | ||
authenticate: ( | ||
request: Request, | ||
sessionContext: SessionContext, | ||
) => Promise<Session | never>; | ||
handleInvalidAccessTokenError: ({ | ||
request, | ||
session, | ||
}: HandleInvalidAccessTokenOptions) => Promise<void | never>; | ||
handleClientError: (request: Request) => HandleAdminClientError; | ||
} |