import type { GraphQLFetcherResult } from '@commerce/api'; import type { HookFetcherContext } from '@commerce/utils/types'; import TokensNotRejectedError from '../../errors/TokensNotRejectedError'; import type { UserOAuthTokens } from '../../types'; import type { EmptyObjectResponse } from '@spree/storefront-api-v2-sdk/types/interfaces/EmptyObject'; const revokeUserTokens = async ( fetch: HookFetcherContext<{ data: any; }>['fetch'], userTokens: UserOAuthTokens ): Promise => { const spreeRevokeTokensResponses = await Promise.allSettled([ fetch>({ variables: { methodPath: 'authentication.revokeToken', arguments: [ { token: userTokens.refreshToken } ] } }), fetch>({ variables: { methodPath: 'authentication.revokeToken', arguments: [ { token: userTokens.accessToken } ] } }) ]); const anyRejected = spreeRevokeTokensResponses.some((response) => response.status === 'rejected'); if (anyRejected) { throw new TokensNotRejectedError('Some tokens could not be rejected in Spree.'); } return undefined; }; export default revokeUserTokens;