Skip to content

Commit

Permalink
renamed type CustomerClient
Browse files Browse the repository at this point in the history
  • Loading branch information
michenly committed Jan 26, 2024
1 parent a4ad330 commit 52b022d
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 114 deletions.
7 changes: 7 additions & 0 deletions .changeset/rude-waves-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'skeleton': patch
'@shopify/hydrogen': patch
'@shopify/cli-hydrogen': patch
---

♻️ `CustomerClient` type is deprecated and replaced by `CustomerAccount`
8 changes: 6 additions & 2 deletions examples/third-party-queries-caching/remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Enhance TypeScript's built-in typings.
import '@total-typescript/ts-reset';

import type {Storefront, CustomerClient, HydrogenCart} from '@shopify/hydrogen';
import type {
Storefront,
CustomerAccount,
HydrogenCart,
} from '@shopify/hydrogen';
import type {AppSession} from '~/lib/session';
import {createRickAndMortyClient} from './app/lib/createRickAndMortyClient.server';

Expand Down Expand Up @@ -37,7 +41,7 @@ declare module '@shopify/remix-oxygen' {
env: Env;
cart: HydrogenCart;
storefront: Storefront;
customerAccount: CustomerClient;
customerAccount: CustomerAccount;
rickAndMorty: ReturnType<typeof createRickAndMortyClient>;
session: AppSession;
waitUntil: ExecutionContext['waitUntil'];
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/setups/i18n/replacers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('i18n replacers', () => {
import type {
Storefront,
CustomerClient,
CustomerAccount,
HydrogenCart,
} from "@shopify/hydrogen";
import type {
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('i18n replacers', () => {
env: Env;
cart: HydrogenCart;
storefront: Storefront<I18nLocale>;
customerAccount: CustomerClient;
customerAccount: CustomerAccount;
session: AppSession;
waitUntil: ExecutionContext["waitUntil"];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

- Add [Subrequest Profiler](https://shopify.dev/docs/custom-storefronts/hydrogen/debugging/subrequest-profiler) developer tool to enable better observability of server-side network requests and caching behaviors ([#1511](https://github.com/Shopify/hydrogen/pull/1511)) by [@wizardlyhel](https://github.com/wizardlyhel)

- Introduce the new [`createCustomerAccountClient`](https://shopify.dev/docs/api/hydrogen/2024-01/utilities/createcustomeraccountclient) for interacting with the Customer Account API ([#1606](https://github.com/Shopify/hydrogen/pull/1606)) by [@michenly](https://github.com/michenly)
- Introduce the new [`createCustomerAccountClient`](https://shopify.dev/docs/api/hydrogen/2024-01/utilities/createCustomerAccountClient) for interacting with the Customer Account API ([#1606](https://github.com/Shopify/hydrogen/pull/1606)) by [@michenly](https://github.com/michenly)

### Patch Changes

Expand Down
182 changes: 91 additions & 91 deletions packages/hydrogen/docs/generated/generated_docs_data.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/hydrogen/src/customer/customer.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ The \`createCustomerAccountClient\` function creates a GraphQL client for queryi
definitions: [
{
title: 'createCustomerAccountClient(options)',
type: 'CustomerClientOptions',
type: 'CustomerAccountOptions',
description: '',
},
{
title: 'Returns',
type: 'CustomerClientForDocs',
type: 'CustomerAccountForDocs',
description: '',
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen/src/customer/customer.example.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {CustomerClient} from '@shopify/hydrogen';
import type {CustomerAccount} from '@shopify/hydrogen';
import {
createCustomerAccountClient,
type HydrogenSession,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {CustomerClient} from '@shopify/hydrogen';
import type {CustomerAccount} from '@shopify/hydrogen';
import {type HydrogenSession} from '@shopify/hydrogen';
import {
createCookieSessionStorage,
Expand All @@ -18,7 +18,7 @@ declare module '@shopify/remix-oxygen' {
* Declare local additions to the Remix loader context.
*/
export interface AppLoadContext {
customerAccount: CustomerClient;
customerAccount: CustomerAccount;
session: AppSession;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/hydrogen/src/customer/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
type StackInfo,
} from '../utils/callsites';
import {getRedirectUrl} from '../utils/get-redirect-url';
import type {CustomerClientOptions, CustomerClient} from './types';
import type {CustomerAccountOptions, CustomerAccount} from './types';

const DEFAULT_LOGIN_URL = '/account/login';
const DEFAULT_AUTH_URL = '/account/authorize';
Expand All @@ -65,7 +65,7 @@ export function createCustomerAccountClient({
waitUntil,
authUrl = DEFAULT_AUTH_URL,
customAuthStatusHandler,
}: CustomerClientOptions): CustomerClient {
}: CustomerAccountOptions): CustomerAccount {
if (customerApiVersion !== DEFAULT_CUSTOMER_API_VERSION) {
console.warn(
`[h2:warn:createCustomerAccountClient] You are using Customer Account API version ${customerApiVersion} when this version of Hydrogen was built for ${DEFAULT_CUSTOMER_API_VERSION}.`,
Expand Down
12 changes: 6 additions & 6 deletions packages/hydrogen/src/customer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface CustomerAccountMutations {
// '#graphql mutation m1 {...}': {return: M1Mutation; variables: M1MutationVariables};
}

export type CustomerClient = {
export type CustomerAccount = {
/** 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) */
login: () => Promise<Response>;
/** 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. */
Expand Down Expand Up @@ -87,7 +87,7 @@ export type CustomerClient = {
>;
};

export type CustomerClientOptions = {
export type CustomerAccountOptions = {
/** The client requires a session to persist the auth and refresh token. By default Hydrogen ships with cookie session storage, but you can use [another session storage](https://remix.run/docs/en/main/utils/sessions) implementation. */
session: HydrogenSession;
/** Unique UUID prefixed with `shp_` associated with the application, this should be visible in the customer account api settings in the Hydrogen admin channel. Mock.shop doesn't automatically supply customerAccountId. Use `h2 env pull` to link your store credentials. */
Expand All @@ -108,7 +108,7 @@ export type CustomerClientOptions = {

/** Below are types meant for documentation only. Ensure it stay in sync with the type above. */

export type CustomerClientForDocs = {
export type CustomerAccountForDocs = {
/** 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) */
login?: () => Promise<Response>;
/** 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. */
Expand All @@ -124,16 +124,16 @@ export type CustomerClientForDocs = {
/** Execute a GraphQL query against the Customer Account API. This method execute `handleAuthStatus()` ahead of query. */
query?: <TData = any>(
query: string,
options: CustomerClientQueryOptionsForDocs,
options: CustomerAccountQueryOptionsForDocs,
) => Promise<TData>;
/** Execute a GraphQL mutation against the Customer Account API. This method execute `handleAuthStatus()` ahead of mutation. */
mutate?: <TData = any>(
mutation: string,
options: CustomerClientQueryOptionsForDocs,
options: CustomerAccountQueryOptionsForDocs,
) => Promise<TData>;
};

export type CustomerClientQueryOptionsForDocs = {
export type CustomerAccountQueryOptionsForDocs = {
/** The variables for the GraphQL statement. */
variables?: Record<string, unknown>;
};
4 changes: 3 additions & 1 deletion packages/hydrogen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export type {SeoHandleFunction} from './seo/seo';
export {Pagination, getPaginationVariables} from './pagination/Pagination';
export {createCustomerAccountClient} from './customer/customer';
export type {
CustomerClient,
CustomerAccount,
// CustomerClient is a deprecated type that will be remove after 2024-01
CustomerAccount as CustomerClient,
CustomerAccountQueries,
CustomerAccountMutations,
} from './customer/types';
Expand Down
4 changes: 2 additions & 2 deletions templates/demo-store/remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <reference types="@shopify/oxygen-workers-types" />

import type {WithCache, HydrogenCart} from '@shopify/hydrogen';
import type {Storefront, CustomerClient} from '~/lib/type';
import type {Storefront, CustomerAccount} from '~/lib/type';
import type {AppSession} from '~/lib/session.server';

declare global {
Expand Down Expand Up @@ -34,7 +34,7 @@ declare module '@shopify/remix-oxygen' {
waitUntil: ExecutionContext['waitUntil'];
session: AppSession;
storefront: Storefront;
customerAccount: CustomerClient;
customerAccount: CustomerAccount;
cart: HydrogenCart;
env: Env;
}
Expand Down
8 changes: 6 additions & 2 deletions templates/skeleton/remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Enhance TypeScript's built-in typings.
import '@total-typescript/ts-reset';

import type {Storefront, CustomerClient, HydrogenCart} from '@shopify/hydrogen';
import type {
Storefront,
CustomerAccount,
HydrogenCart,
} from '@shopify/hydrogen';
import type {AppSession} from '~/lib/session';

declare global {
Expand Down Expand Up @@ -36,7 +40,7 @@ declare module '@shopify/remix-oxygen' {
env: Env;
cart: HydrogenCart;
storefront: Storefront;
customerAccount: CustomerClient;
customerAccount: CustomerAccount;
session: AppSession;
waitUntil: ExecutionContext['waitUntil'];
}
Expand Down

0 comments on commit 52b022d

Please sign in to comment.