Creates a function that accepts an array of strings and adds the gift card codes to a cart
import {cartGiftCardCodesUpdateDefault} from '@shopify/hydrogen';
const cartGiftCardCodes = cartGiftCardCodesUpdateDefault({
storefront,
getCartId,
});
const result = await cartGiftCardCodes(['GIFT_CARD_CODE_123']);
options: CartQueryOptions
export function cartGiftCardCodesUpdateDefault( options: CartQueryOptions, ): CartGiftCardCodesUpdateFunction { return async (giftCardCodes, optionalParams) => { // Ensure the gift card codes are unique const uniqueCodes = giftCardCodes.filter((value, index, array) => { return array.indexOf(value) === index; }); const {cartGiftCardCodesUpdate, errors} = await options.storefront.mutate<{ cartGiftCardCodesUpdate: CartQueryData; errors: StorefrontApiErrors; }>(CART_GIFT_CARD_CODE_UPDATE_MUTATION(options.cartFragment), { variables: { cartId: options.getCartId(), giftCardCodes: uniqueCodes, ...optionalParams, }, }); return formatAPIResult(cartGiftCardCodesUpdate, errors); }; }
The cart fragment to override the one used in this query.
The customer account instance created by [`createCustomerAccount`](docs/api/hydrogen/latest/customer/createcustomeraccount).
A function that returns the cart ID.
The storefront client instance created by [`createStorefrontClient`](docs/api/hydrogen/latest/utilities/createstorefrontclient).
On successful login, the customer redirects back to your app. This function validates the OAuth response and exchanges the authorization code for an access token and refresh token. It also persists the tokens on your session. This function should be called and returned from the Remix loader configured as the redirect URI within the Customer Account API settings in admin.
Returns CustomerAccessToken if the customer is logged in. It also run a expiry check and does a token refresh if needed.
Creates the fully-qualified URL to your store's GraphQL endpoint.
Check for a not logged in customer and redirect customer to login page. The redirect can be overwritten with `customAuthStatusHandler` option.
Returns if the customer is logged in. It also checks if the access token is expired and refreshes it if needed.
Start the OAuth login flow. This function should be called and returned from a Remix action. It redirects the customer to a Shopify login domain. It also defined the final path the customer lands on at the end of the oAuth flow with the value of the `return_to` query param. (This is automatically setup unless `customAuthStatusHandler` option is in use)
Logout the customer by clearing the session and redirecting to the login domain. It should be called and returned from a Remix action. The path app should redirect to after logout can be setup in Customer Account API settings in admin.
Execute a GraphQL mutation against the Customer Account API. This method execute `handleAuthStatus()` ahead of mutation.
Execute a GraphQL query against the Customer Account API. This method execute `handleAuthStatus()` ahead of query.
UNSTABLE feature. Get buyer token and company location id from session.
UNSTABLE feature. Set buyer information into session.
Response | NonNullable<unknown> | null
export interface CustomerAccountMutations { // Example of how a generated mutation type looks like: // '#graphql mutation m1 {...}': {return: M1Mutation; variables: M1MutationVariables}; }
If an error can be associated to a particular point in the requested GraphQL document, it should contain a list of locations.
If an error can be associated to a particular field in the GraphQL result, it _must_ contain an entry with the key `path` that details the path of the response field which experienced the error. This allows clients to identify whether a null result is intentional or caused by a runtime error.
Reserved for implementors to extend the protocol however they see fit, and hence there are no additional restrictions on its contents.
Note: `toString()` is internally used by `console.log(...)` / `console.error(...)` when ingesting logs in Oxygen production. Therefore, we want to make sure that the error message is as informative as possible instead of `[object Object]`.
Note: toJSON` is internally used by `JSON.stringify(...)`. The most common scenario when this error instance is going to be stringified is when it's passed to Remix' `json` and `defer` functions: e.g. `defer({promise: storefront.query(...)})`. In this situation, we don't want to expose private error information to the browser so we only do it in development.
export interface CustomerAccountQueries { // Example of how a generated query type looks like: // '#graphql query q1 {...}': {return: Q1Query; variables: Q1QueryVariables}; }
Interface to interact with the Storefront API.
Override options for a cache strategy.
The maximum amount of time in seconds that a resource will be considered fresh. See `max-age` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#:~:text=Response%20Directives-,max%2Dage,-The%20max%2Dage).
The caching mode, generally `public`, `private`, or `no-store`.
Similar to `maxAge` but specific to shared caches. See `s-maxage` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#s-maxage).
Indicate that the cache should serve the stale response if an error occurs while revalidating the cache. See `stale-if-error` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error).
Indicate that the cache should serve the stale response in the background while revalidating the cache. See `stale-while-revalidate` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate).
Maps all the mutations found in the project to variables and return types.
export interface StorefrontMutations { // Example of how a generated mutation type looks like: // '#graphql mutation m1 {...}': {return: M1Mutation; variables: M1MutationVariables}; }
'country' | 'language'
JsonGraphQLError[] | undefined
ReturnType<GraphQLError['toJSON']>
Maps all the queries found in the project to variables and return types.
export interface StorefrontQueries { // Example of how a generated query type looks like: // '#graphql query q1 {...}': {return: Q1Query; variables: Q1QueryVariables}; }
StorefrontCommonExtraParams & { query: string; mutation?: never; cache?: CachingStrategy; }
Use the `CachingStrategy` to define a custom caching mechanism for your data. Or use one of the pre-defined caching strategies: CacheNone, CacheShort, CacheLong.
The maximum amount of time in seconds that a resource will be considered fresh. See `max-age` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#:~:text=Response%20Directives-,max%2Dage,-The%20max%2Dage).
The caching mode, generally `public`, `private`, or `no-store`.
Similar to `maxAge` but specific to shared caches. See `s-maxage` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#s-maxage).
Indicate that the cache should serve the stale response if an error occurs while revalidating the cache. See `stale-if-error` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error).
Indicate that the cache should serve the stale response in the background while revalidating the cache. See `stale-while-revalidate` in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate).
giftCardCodes: string[]
optionalParams: CartOptionalInput
export type CartGiftCardCodesUpdateFunction = ( giftCardCodes: string[], optionalParams?: CartOptionalInput, ) => Promise<CartQueryDataReturn>;
The cart id.
The country code.
The language code.
CartQueryData & { errors?: StorefrontApiErrors; }
Cart
CartUserError
MetafieldsSetUserError
MetafieldDeleteUserError