-
Notifications
You must be signed in to change notification settings - Fork 15
Feat(Shopify): headless account #1084
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
Open
yuriassuncx
wants to merge
14
commits into
deco-cx:main
Choose a base branch
from
yuriassuncx:shopify-headless-account
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
84d5729
feat: create address and send password reset email actions
yuriassuncx 3f21ed3
Merge branch 'deco-cx:main' into shopify-headless-account
yuriassuncx 25848a7
feat(Shopify): Add Shopify address management actions: delete, set de…
yuriassuncx 820c8e5
chore(Shopify): Update manifest to include address management actions
yuriassuncx 4a9c2ef
feat(Shopify): Implement loader for fetching user addresses and updat…
yuriassuncx ce19e18
fix(Shopify): Update address loader to fetch customer addresses inste…
yuriassuncx 261bd56
feat(Shopify): Add OrdersByCustomer query for fetching customer orders
yuriassuncx 8e589ac
feat(Shopify): Add orders list loader to manifest and reorganize imports
yuriassuncx 40a8d48
fix(address): Correct typo in 'province' field in createAddress and u…
yuriassuncx 6e6a768
refactor(address): Simplify address creation by using MailingAddressI…
yuriassuncx 644dacc
fix(address): Correct variable name in DeleteAddress mutation for con…
yuriassuncx 818992c
refactor(address): Update UpdateAddress mutation to use MailingAddres…
yuriassuncx 61709f6
refactor(customer): Simplify UpdateCustomerInfo mutation by using Cus…
yuriassuncx 673af77
fix(address): change id to identifier
yuriassuncx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import type { AppContext } from "../../mod.ts"; | ||
| import { CreateAddress } from "../../utils/storefront/queries.ts"; | ||
| import { | ||
| CustomerAddressCreatePayload, | ||
| MutationCustomerAddressCreateArgs, | ||
| } from "../../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { getUserCookie } from "../../utils/user.ts"; | ||
|
|
||
| interface Props { | ||
| address: string; | ||
| country: string; | ||
| province: string; | ||
| city: string; | ||
| zip: string; | ||
| } | ||
|
|
||
| /** | ||
| * @title Shopify Integration | ||
| * @description Create Address | ||
| */ | ||
| const action = async ( | ||
| props: Props, | ||
| req: Request, | ||
| ctx: AppContext, | ||
| ): Promise<CustomerAddressCreatePayload | null> => { | ||
| const customerAccessToken = getUserCookie(req.headers); | ||
|
|
||
| if (!customerAccessToken) return null; | ||
|
|
||
| const { storefront } = ctx; | ||
| const { address, ...rest } = props; | ||
|
|
||
| const data = await storefront.query< | ||
| CustomerAddressCreatePayload, | ||
| MutationCustomerAddressCreateArgs | ||
| >({ | ||
| variables: { | ||
| customerAccessToken, | ||
| address: { | ||
| address1: address, | ||
| ...rest, | ||
| }, | ||
| }, | ||
| ...CreateAddress, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| export default action; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { AppContext } from "../../mod.ts"; | ||
| import { DeleteAddress } from "../../utils/storefront/queries.ts"; | ||
| import { | ||
| CustomerAddressDeletePayload, | ||
| MutationCustomerAddressDeleteArgs, | ||
| } from "../../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { getUserCookie } from "../../utils/user.ts"; | ||
|
|
||
| interface Props { | ||
| addressId: string; | ||
| } | ||
|
|
||
| /** | ||
| * @title Shopify Integration | ||
| * @description Delete Address | ||
| */ | ||
| const action = async ( | ||
| props: Props, | ||
| req: Request, | ||
| ctx: AppContext, | ||
| ): Promise<CustomerAddressDeletePayload | null> => { | ||
| const customerAccessToken = getUserCookie(req.headers); | ||
|
|
||
| if (!customerAccessToken) return null; | ||
|
|
||
| const { addressId } = props; | ||
| const { storefront } = ctx; | ||
|
|
||
| const data = await storefront.query< | ||
| CustomerAddressDeletePayload, | ||
| MutationCustomerAddressDeleteArgs | ||
| >({ | ||
| variables: { | ||
| customerAccessToken, | ||
| id: addressId, | ||
| }, | ||
| ...DeleteAddress, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| export default action; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { AppContext } from "../../mod.ts"; | ||
| import { SetDefaultAddress } from "../../utils/storefront/queries.ts"; | ||
| import { | ||
| MutationCustomerDefaultAddressUpdateArgs, | ||
| CustomerDefaultAddressUpdatePayload, | ||
| } from "../../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { getUserCookie } from "../../utils/user.ts"; | ||
|
|
||
| interface Props { | ||
| addressId: string; | ||
| } | ||
|
|
||
| /** | ||
| * @title Shopify Integration | ||
| * @description Set Default Address | ||
| */ | ||
| const action = async ( | ||
| props: Props, | ||
| req: Request, | ||
| ctx: AppContext, | ||
| ): Promise<CustomerDefaultAddressUpdatePayload | null> => { | ||
| const customerAccessToken = getUserCookie(req.headers); | ||
|
|
||
| if (!customerAccessToken) return null; | ||
|
|
||
| const { addressId } = props; | ||
| const { storefront } = ctx; | ||
|
|
||
| const data = await storefront.query< | ||
| CustomerDefaultAddressUpdatePayload, | ||
| MutationCustomerDefaultAddressUpdateArgs | ||
| >({ | ||
| variables: { | ||
| customerAccessToken, | ||
| addressId | ||
| }, | ||
| ...SetDefaultAddress, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| export default action; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import type { AppContext } from "../../mod.ts"; | ||
| import { UpdateAddress } from "../../utils/storefront/queries.ts"; | ||
| import { | ||
| CustomerAddressUpdatePayload, | ||
| MutationCustomerAddressUpdateArgs, | ||
| } from "../../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { getUserCookie } from "../../utils/user.ts"; | ||
|
|
||
| interface Props { | ||
| addressId: string; | ||
| address: string; | ||
| country: string; | ||
| province: string; | ||
| city: string; | ||
| zip: string; | ||
| } | ||
|
|
||
| /** | ||
| * @title Shopify Integration | ||
| * @description Update Address | ||
| */ | ||
| const action = async ( | ||
| props: Props, | ||
| req: Request, | ||
| ctx: AppContext, | ||
| ): Promise<CustomerAddressUpdatePayload | null> => { | ||
| const customerAccessToken = getUserCookie(req.headers); | ||
|
|
||
| if (!customerAccessToken) return null; | ||
|
|
||
| const { | ||
| addressId, | ||
| address: address1, | ||
| country, | ||
| province, | ||
| city, | ||
| zip, | ||
| } = props; | ||
| const { storefront } = ctx; | ||
|
|
||
| const data = await storefront.query< | ||
| CustomerAddressUpdatePayload, | ||
| MutationCustomerAddressUpdateArgs | ||
| >({ | ||
| variables: { | ||
| id: addressId, | ||
| customerAccessToken, | ||
| address: { | ||
| address1, | ||
| country, | ||
| province, | ||
| city, | ||
| zip, | ||
| }, | ||
| }, | ||
| ...UpdateAddress, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| export default action; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { AppContext } from "../../mod.ts"; | ||
| import { SendPasswordResetEmail } from "../../utils/storefront/queries.ts"; | ||
| import { | ||
| MutationCustomerRecoverArgs, | ||
| CustomerRecoverPayload, | ||
| } from "../../utils/storefront/storefront.graphql.gen.ts"; | ||
|
|
||
| interface Props { | ||
| email: string; | ||
| } | ||
|
|
||
| /** | ||
| * @title Shopify Integration | ||
| * @description Send Password Reset Email | ||
| */ | ||
| const action = async ( | ||
| props: Props, | ||
| _req: Request, | ||
| ctx: AppContext, | ||
| ): Promise<CustomerRecoverPayload> => { | ||
| const { storefront } = ctx; | ||
|
|
||
| const data = await storefront.query< | ||
| CustomerRecoverPayload, | ||
| MutationCustomerRecoverArgs | ||
| >({ | ||
| variables: props, | ||
| ...SendPasswordResetEmail, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| export default action; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import type { AppContext } from "../../mod.ts"; | ||
| import { UpdateCustomerInfo } from "../../utils/storefront/queries.ts"; | ||
| import { | ||
| CustomerUpdatePayload, | ||
| MutationCustomerUpdateArgs, | ||
| } from "../../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { getUserCookie } from "../../utils/user.ts"; | ||
|
|
||
| interface Props { | ||
| email: string; | ||
| firstName: string; | ||
| lastName: string; | ||
| acceptsMarketing?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * @title Shopify Integration | ||
| * @description Update Customer Info | ||
| */ | ||
| const action = async ( | ||
| props: Props, | ||
| req: Request, | ||
| ctx: AppContext, | ||
| ): Promise<CustomerUpdatePayload | null> => { | ||
| const customerAccessToken = getUserCookie(req.headers); | ||
|
|
||
| if (!customerAccessToken) return null; | ||
|
|
||
| const { storefront } = ctx; | ||
|
|
||
| const data = await storefront.query< | ||
| CustomerUpdatePayload, | ||
| MutationCustomerUpdateArgs | ||
| >({ | ||
| variables: { | ||
| customerAccessToken, | ||
| customer: { ...props } | ||
| }, | ||
| ...UpdateCustomerInfo, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| export default action; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { PostalAddress } from "../../commerce/types.ts"; | ||
| import type { AppContext } from "../mod.ts"; | ||
| import { FetchCustomerAddresses } from "../utils/storefront/queries.ts"; | ||
| import { Customer } from "../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { getUserCookie } from "../utils/user.ts"; | ||
|
|
||
| /** | ||
| * @title Shopify Integration | ||
| * @description Get User Addresses | ||
| */ | ||
| const loader = async ( | ||
| _props: unknown, | ||
| req: Request, | ||
| ctx: AppContext, | ||
| ): Promise<PostalAddress[] | null> => { | ||
| const { storefront } = ctx; | ||
|
|
||
| const customerAccessToken = getUserCookie(req.headers); | ||
|
|
||
| if (!customerAccessToken) return null; | ||
|
|
||
| try { | ||
| const customer = await storefront.query< | ||
| { customer: Customer }, | ||
| { customerAccessToken: string } | ||
| >({ | ||
| variables: { customerAccessToken }, | ||
| ...FetchCustomerAddresses, | ||
| }).then((data) => data.customer); | ||
|
|
||
| if (!customer) return null; | ||
|
|
||
| const addresses = customer.addresses.edges; | ||
|
|
||
| return addresses.map((address) => ({ | ||
| "@type": "PostalAddress", | ||
| "@id": address.node.id, | ||
| addressLine1: address.node.address1 ?? "", | ||
| city: address.node.city ?? "", | ||
| country: address.node.country ?? "", | ||
| postalCode: address.node.zip ?? "", | ||
| state: address.node.province ?? "", | ||
| recipient: address.node.name ?? "", | ||
| })); | ||
| } catch { | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| export default loader; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.