Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async searchText => {
const idsOfProductsMatchingSearchText =
this.props.pimIndexerState === pimIndexerStates.INDEXED
? await this.props.pimSearchProductIds(searchText)
: [];
const canViewProducts = hasSomePermissions(
['ViewProducts', 'ManageProducts'],
this.props.applicationContext.permissions
);
return this.query(QuickAccessQuery, {
searchText: sanitize(searchText),
target: GRAPHQL_TARGETS.COMMERCETOOLS_PLATFORM,
// Pass conditional arguments to disable some of the queries
canViewProducts,
productsWhereClause: `id in (${idsOfProductsMatchingSearchText
.map(id => JSON.stringify(id))
.join(', ')})`,
includeProductsByIds: Boolean(
canViewProducts && idsOfProductsMatchingSearchText.length > 0
),
}).then(data => {
const commands = [];
if (containsMatchByVariantKey(data)) {
const productId = data.productByVariantKey.id;
const variantId =
data.productByVariantKey.masterData.staged.variant.id;
commands.push({
it('should support the `ctp` GraphQL target', () => {
expect(
getDoesGraphQLTargetSupportTokenRetry({
'X-Graphql-Target': GRAPHQL_TARGETS.COMMERCETOOLS_PLATFORM,
})
).toBe(true);
});
export const createProductVariantListSubCommands = ({
applicationContext,
intl,
query,
productId,
}) =>
hasSomePermissions(
[permissions.ViewProducts, permissions.ManageProducts],
applicationContext.permissions
)
? query(QuickAccessProductQuery, {
productId,
target: GRAPHQL_TARGETS.COMMERCETOOLS_PLATFORM,
}).then(data =>
data.product.masterData.staged.allVariants.map(variant => ({
id: `go/product(${productId})/variant(${variant.id})`,
text: formatVariantMessage(variant, intl),
subCommands: createProductVariantSubCommands({
intl,
applicationContext,
productId,
variantId: variant.id,
}),
action: {
type: 'go',
to: `/${applicationContext.project.key}/products/${productId}/variants/${variant.id}`,
},
}))
)
export const getDoesGraphQLTargetSupportTokenRetry = requestHeaders =>
[
GRAPHQL_TARGETS.COMMERCETOOLS_PLATFORM,
GRAPHQL_TARGETS.ADMINISTRATION_SERVICE,
].includes(requestHeaders['X-Graphql-Target']);
const createMatchlessSearchMock = (searchText, variables = {}) => ({
request: {
query: QuickAccessQuery,
variables: {
searchText,
target: GRAPHQL_TARGETS.COMMERCETOOLS_PLATFORM,
canViewProducts: true,
productsWhereClause: 'id in ()',
includeProductsByIds: false,
...variables,
},
},
result: {
data: {
productsById: null,
productById: null,
productByKey: null,
productByVariantSku: null,
productByVariantKey: null,
},
},
});
const headerLink = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
'X-Graphql-Target': GRAPHQL_TARGETS.COMMERCETOOLS_PLATFORM,
},
});
return forward(operation);
});
debugLink = new ApolloLink((operation, forward) => {