Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prorotypoe to provide buyer context by standard api to extension #2696

Draft
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type {
BuyerContextData,
RenderOrderStatusExtensionTarget,
} from '@shopify/ui-extensions/customer-account';

import {ExtensionHasNoFieldError} from '../errors';

import {useApi} from './api';

export function useBuyerContext<
Target extends RenderOrderStatusExtensionTarget = RenderOrderStatusExtensionTarget,
>(): BuyerContextData {
const api = useApi<Target>();
const extensionTarget = api.extension.target;
const buyerContext = api.buyerContext;

console.log({buyerContext});

if (!('selectedCountry' in buyerContext)) {
throw new ExtensionHasNoFieldError('buyerIdentity', extensionTarget);
}

return buyerContext;
}
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ export {
usePhone,
usePurchasingCompany,
} from './buyer-identity';
export {useBuyerContext} from './buyer-context';
export {useTranslate} from './translate';
export {useI18n} from './i18n';
export {useSessionToken} from './session-token';
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ export type {
TrackingConsentMetafieldChange,
VisitorConsent,
VisitorConsentChange,
BuyerContextData,
} from './api/shared';

export type {CartLineItemApi} from './api/cart-line/cart-line-item';
Original file line number Diff line number Diff line change
@@ -429,6 +429,10 @@ export interface SessionToken {
get(): Promise<string>;
}

export interface BuyerContextData {
selectedCountry?: string;
}

export interface AllowedProcessing {
/**
* Can collect customer analytics about how the shop was used and interactions made on the shop.
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import {
StorefrontApiVersion,
Ui,
SessionToken,
BuyerContextData,
CustomerPrivacy,
ApplyTrackingConsentChangeType,
} from '../shared';
@@ -78,6 +79,7 @@ export interface StandardApi<Target extends ExtensionTarget = ExtensionTarget> {
*/
sessionToken: SessionToken;

buyerContext: BuyerContextData;
/**
* The settings matching the settings definition written in the
* [`shopify.ui.extension.toml`](https://shopify.dev/docs/api/customer-account-ui-extensions/configuration) file.