-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from vtex-apps/feature/B2BTEAM-1287-add-token…
…-validation feat: add directive to validate auth token
- Loading branch information
Showing
11 changed files
with
209 additions
and
162 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import type { InstanceOptions, IOContext } from '@vtex/api' | ||
import { AppClient, GraphQLClient } from '@vtex/api' | ||
|
||
import { QUERIES } from '../resolvers/Routes/utils' | ||
import { getTokenToHeader } from './index' | ||
|
||
const getPersistedQuery = () => { | ||
return { | ||
persistedQuery: { | ||
provider: '[email protected]', | ||
sender: '[email protected]', | ||
}, | ||
} | ||
} | ||
|
||
export class OrganizationsGraphQLClient extends AppClient { | ||
protected graphql: GraphQLClient | ||
|
||
constructor(ctx: IOContext, options?: InstanceOptions) { | ||
super('[email protected]', ctx, options) | ||
this.graphql = new GraphQLClient(this.http) | ||
} | ||
|
||
public getOrganizationById = async (orgId: string): Promise<unknown> => { | ||
return this.query({ | ||
extensions: getPersistedQuery(), | ||
query: QUERIES.getOrganizationById, | ||
variables: { | ||
id: orgId, | ||
}, | ||
}) | ||
} | ||
|
||
public getB2BSettings = async (): Promise<unknown> => { | ||
return this.query({ | ||
extensions: getPersistedQuery(), | ||
query: QUERIES.getB2BSettings, | ||
variables: {}, | ||
}) | ||
} | ||
|
||
public getCostCenterById = async (costId: string): Promise<unknown> => { | ||
return this.query({ | ||
extensions: getPersistedQuery(), | ||
query: QUERIES.getCostCenterById, | ||
variables: { | ||
id: costId, | ||
}, | ||
}) | ||
} | ||
|
||
public getMarketingTags = async (costId: string): Promise<unknown> => { | ||
return this.query({ | ||
extensions: getPersistedQuery(), | ||
query: QUERIES.getMarketingTags, | ||
variables: { | ||
costId, | ||
}, | ||
}) | ||
} | ||
|
||
public getOrganizationsByEmail = async (email: string): Promise<unknown> => { | ||
return this.query({ | ||
extensions: getPersistedQuery(), | ||
query: QUERIES.getOrganizationsByEmail, | ||
variables: { email }, | ||
}) | ||
} | ||
|
||
private query = async (param: { | ||
query: string | ||
variables: any | ||
extensions: any | ||
}) => { | ||
const { query, variables, extensions } = param | ||
|
||
return this.graphql.query( | ||
{ query, variables, extensions }, | ||
{ | ||
params: { | ||
headers: getTokenToHeader(this.context), | ||
locale: this.context.locale, | ||
}, | ||
url: '/graphql', | ||
} | ||
) | ||
} | ||
} |
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
Oops, something went wrong.