Skip to content

Commit 2ef25e5

Browse files
feat: init app with checkout ui extension
0 parents  commit 2ef25e5

16 files changed

+610
-0
lines changed

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Environment Configuration
2+
.env
3+
.env.*
4+
5+
# Dependency directory
6+
node_modules
7+
8+
# Test coverage directory
9+
coverage
10+
11+
# Ignore Apple macOS Desktop Services Store
12+
.DS_Store
13+
14+
# Logs
15+
logs
16+
*.log
17+
18+
# extensions build output
19+
extensions/*/build
20+
21+
# lock files

.graphqlrc.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("node:fs");
2+
3+
function getConfig() {
4+
const config = {
5+
projects: {},
6+
};
7+
8+
let extensions = [];
9+
try {
10+
extensions = fs.readdirSync("./extensions");
11+
} catch {
12+
// ignore if no extensions
13+
}
14+
15+
for (const entry of extensions) {
16+
const extensionPath = `./extensions/${entry}`;
17+
const schema = `${extensionPath}/schema.graphql`;
18+
if (!fs.existsSync(schema)) {
19+
continue;
20+
}
21+
config.projects[entry] = {
22+
schema,
23+
documents: [`${extensionPath}/**/*.graphql`],
24+
};
25+
}
26+
27+
return config;
28+
}
29+
30+
module.exports = getConfig();

.npmrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
engine-strict=true
2+
auto-install-peers=true
3+
shamefully-hoist=true

.vscode/extensions.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"graphql.vscode-graphql"
4+
]
5+
}

README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Shopify App Template - None (app with extensions only)
2+
3+
This is a template for building a [Shopify app](https://shopify.dev/docs/apps/getting-started) that includes no app home UI. It contains the basics for building a Shopify app that uses only app extensions.
4+
5+
**If you plan for your app to load its own page in the Shopify Admin, then you'll want to choose one of our other templates.**
6+
7+
Whether you choose to use this template or another one, you can use your preferred package manager and the Shopify CLI with [these steps](#installing-the-template).
8+
9+
## Benefits
10+
11+
Shopify apps are built on a variety of Shopify tools to create a great merchant experience. The [create an app](https://shopify.dev/docs/apps/getting-started/create) tutorial in our developer documentation will guide you through creating a Shopify app.
12+
13+
This app template does little more than install the CLI and scaffold a respository.
14+
15+
## Getting started
16+
17+
### Requirements
18+
19+
1. You must [download and install Node.js](https://nodejs.org/en/download/) if you don't already have it.
20+
1. You must [create a Shopify partner account](https://partners.shopify.com/signup) if you don’t have one.
21+
1. You must create a store for testing if you don't have one, either a [development store](https://help.shopify.com/en/partners/dashboard/development-stores#create-a-development-store) or a [Shopify Plus sandbox store](https://help.shopify.com/en/partners/dashboard/managing-stores/plus-sandbox-store).
22+
23+
### Installing the template
24+
25+
This template can be installed using your preferred package manager:
26+
27+
Using yarn:
28+
29+
```shell
30+
yarn create @shopify/app
31+
```
32+
33+
Using npm:
34+
35+
```shell
36+
npm init @shopify/app@latest
37+
```
38+
39+
Using pnpm:
40+
41+
```shell
42+
pnpm create @shopify/app@latest
43+
```
44+
45+
This will clone the template and install the required dependencies.
46+
47+
#### Local Development
48+
49+
[The Shopify CLI](https://shopify.dev/docs/apps/tools/cli) connects to an app in your Partners dashboard. It provides environment variables and runs commands in parallel..
50+
51+
You can develop locally using your preferred package manager. Run one of the following commands from the root of your app.
52+
53+
Using yarn:
54+
55+
```shell
56+
yarn dev
57+
```
58+
59+
Using npm:
60+
61+
```shell
62+
npm run dev
63+
```
64+
65+
Using pnpm:
66+
67+
```shell
68+
pnpm run dev
69+
```
70+
71+
Open the URL generated in your console. Once you grant permission to the app, you can start development (such as generating extensions).
72+
73+
## Developer resources
74+
75+
- [Introduction to Shopify apps](https://shopify.dev/docs/apps/getting-started)
76+
- [App authentication](https://shopify.dev/docs/apps/auth)
77+
- [Shopify CLI](https://shopify.dev/docs/apps/tools/cli)
78+
- [Shopify API Library documentation](https://github.com/Shopify/shopify-api-js#readme)

SECURITY.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Security Policy
2+
3+
## Supported versions
4+
5+
### New features
6+
7+
New features will only be added to the master branch and will not be made available in point releases.
8+
9+
### Bug fixes
10+
11+
Only the latest release series will receive bug fixes. When enough bugs are fixed and its deemed worthy to release a new gem, this is the branch it happens from.
12+
13+
### Security issues
14+
15+
Only the latest release series will receive patches and new versions in case of a security issue.
16+
17+
### Severe security issues
18+
19+
For severe security issues we will provide new versions as above, and also the last major release series will receive patches and new versions. The classification of the security issue is judged by the core team.
20+
21+
### Unsupported Release Series
22+
23+
When a release series is no longer supported, it's your own responsibility to deal with bugs and security issues. If you are not comfortable maintaining your own versions, you should upgrade to a supported version.
24+
25+
## Reporting a bug
26+
27+
All security bugs in shopify repositories should be reported to [our hackerone program](https://hackerone.com/shopify)
28+
Shopify's whitehat program is our way to reward security researchers for finding serious security vulnerabilities in the In Scope properties listed at the bottom of this page, including our core application (all functionality associated with a Shopify store, particularly your-store.myshopify.com/admin) and certain ancillary applications.
29+
30+
## Disclosure Policy
31+
32+
We look forward to working with all security researchers and strive to be respectful, always assume the best and treat others as peers. We expect the same in return from all participants. To achieve this, our team strives to:
33+
34+
- Reply to all reports within one business day and triage within two business days (if applicable)
35+
- Be as transparent as possible, answering all inquires about our report decisions and adding hackers to duplicate HackerOne reports
36+
- Award bounties within a week of resolution (excluding extenuating circumstances)
37+
- Only close reports as N/A when the issue reported is included in Known Issues, Ineligible Vulnerabilities Types or lacks evidence of a vulnerability
38+
39+
**The following rules must be followed in order for any rewards to be paid:**
40+
41+
- You may only test against shops you have created which include your HackerOne YOURHANDLE @ wearehackerone.com registered email address.
42+
- You must not attempt to gain access to, or interact with, any shops other than those created by you.
43+
- The use of commercial scanners is prohibited (e.g., Nessus).
44+
- Rules for reporting must be followed.
45+
- Do not disclose any issues publicly before they have been resolved.
46+
- Shopify reserves the right to modify the rules for this program or deem any submissions invalid at any time. Shopify may cancel the whitehat program without notice at any time.
47+
- Contacting Shopify Support over chat, email or phone about your HackerOne report is not allowed. We may disqualify you from receiving a reward, or from participating in the program altogether.
48+
- You are not an employee of Shopify; employees should report bugs to the internal bug bounty program.
49+
- You hereby represent, warrant and covenant that any content you submit to Shopify is an original work of authorship and that you are legally entitled to grant the rights and privileges conveyed by these terms. You further represent, warrant and covenant that the consent of no other person or entity is or will be necessary for Shopify to use the submitted content.
50+
- By submitting content to Shopify, you irrevocably waive all moral rights which you may have in the content.
51+
- All content submitted by you to Shopify under this program is licensed under the MIT License.
52+
- You must report any discovered vulnerability to Shopify as soon as you have validated the vulnerability.
53+
- Failure to follow any of the foregoing rules will disqualify you from participating in this program.
54+
55+
\*\* Please see our [Hackerone Profile](https://hackerone.com/shopify) for full details
56+
57+
## Receiving Security Updates
58+
59+
To receive all general updates to vulnerabilities, please subscribe to our hackerone [Hacktivity](https://hackerone.com/shopify/hacktivity)

extensions/.gitkeep

Whitespace-only changes.

extensions/checkout-ui/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Checkout UI Extension
2+
3+
Checkout UI extensions let app developers build custom functionality that merchants can install at defined targets in the checkout flow. You can learn more about checkout UI extensions in Shopify’s [developer documentation](https://shopify.dev/api/checkout-extensions/checkout).
4+
5+
## Prerequisites
6+
7+
Before you start building your extension, make sure that you’ve created a [development store](https://shopify.dev/docs/apps/tools/development-stores) with the [checkout extensibility developer preview](https://shopify.dev/docs/api/release-notes/developer-previews#previewing-new-features).
8+
9+
## Your new Extension
10+
11+
Your new extension contains the following files:
12+
13+
- `README.md`, the file you are reading right now.
14+
- `shopify.extension.toml`, the configuration file for your extension. This file defines your extension’s name, where it will appear in the checkout, and other metadata.
15+
- `src/Checkout.jsx`, the source code for your extension.
16+
- `locales/en.default.json` and `locales/fr.json`, which contain translations used to [localized your extension](https://shopify.dev/docs/apps/checkout/best-practices/localizing-ui-extensions).
17+
18+
By default, your extension is configured to target the `purchase.checkout.block.render` [extension target](https://shopify.dev/docs/api/checkout-ui-extensions/extension-targets-overview). You will find the target both in your `shopify.extension.toml`, and in the source code of your extension. The default target allows the merchant to configure where in the checkout *they* want your extension to appear. If you are building an extension that is tied to existing UI element in the checkout, such as the cart lines or shipping options, you can change the extension target so that your UI extension will render in the correct location. Check out the list of [all available extension targets](https://shopify.dev/docs/api/checkout-ui-extensions/extension-targets-overview) to get some inspiration for the kinds of content you can provide with checkout UI extensions.
19+
20+
To build your extension, you will need to use APIs provided by Shopify that let you render content, and to read and write data in the checkout. The following resources will help you get started with checkout extensions:
21+
22+
- [APIs by extension target](https://shopify.dev/docs/api/checkout-ui-extensions/targets)
23+
- [All APIs for reading and writing checkout data](https://shopify.dev/docs/api/checkout-ui-extensions/apis)
24+
- [Available components and their properties](https://shopify.dev/docs/api/checkout-ui-extensions/components)
25+
26+
## Useful Links
27+
28+
- [Checkout app documentation](https://shopify.dev/apps/checkout)
29+
- [Checkout UI extension documentation](https://shopify.dev/api/checkout-extensions)
30+
- [Configuration](https://shopify.dev/docs/api/checkout-ui-extensions/configuration)
31+
- [Extension Targets](https://shopify.dev/docs/api/checkout-ui-extensions/targets)
32+
- [API Reference](https://shopify.dev/docs/api/checkout-ui-extensions/apis)
33+
- [UI Components](https://shopify.dev/docs/api/checkout-ui-extensions/components)
34+
- [Checkout UI extension tutorials](https://shopify.dev/docs/apps/checkout)
35+
- [Enable extended delivery instructions](https://shopify.dev/apps/checkout/delivery-instructions)
36+
- [Creating a custom banner](https://shopify.dev/apps/checkout/custom-banners)
37+
- [Thank you and order status pages](https://shopify.dev/docs/apps/checkout/thank-you-order-status)
38+
- [Adding field validation](https://shopify.dev/apps/checkout/validation)
39+
- [Localizing an extension](https://shopify.dev/apps/checkout/localize-ui-extensions)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"welcome": "Welcome to the {{target}} extension!",
3+
"iWouldLikeAFreeGiftWithMyOrder": "I would like to receive a free gift with my order",
4+
"attributeChangesAreNotSupported": "Attribute changes are not supported in this checkout"
5+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"welcome": "Bienvenue dans l'extension {{target}}!",
3+
"iWouldLikeAFreeGiftWithMyOrder": "Je souhaite recevoir un cadeau gratuit avec ma commande",
4+
"attributeChangesAreNotSupported": "Les modifications d'attribut ne sont pas prises en charge dans cette commande"
5+
}

extensions/checkout-ui/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "checkout-ui",
3+
"private": true,
4+
"version": "1.0.0",
5+
"license": "UNLICENSED",
6+
"dependencies": {
7+
"react": "^18.0.0",
8+
"@shopify/ui-extensions": "2024.7.x",
9+
"@shopify/ui-extensions-react": "2024.7.x"
10+
},
11+
"devDependencies": {
12+
"@types/react": "^18.0.0",
13+
"react-reconciler": "0.29.0"
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Learn more about configuring your checkout UI extension:
2+
# https://shopify.dev/api/checkout-extensions/checkout/configuration
3+
4+
# The version of APIs your extension will receive. Learn more:
5+
# https://shopify.dev/docs/api/usage/versioning
6+
api_version = "2024-07"
7+
8+
[[extensions]]
9+
name = "checkout-ui"
10+
handle = "checkout-ui"
11+
type = "ui_extension"
12+
13+
14+
# Controls where in Shopify your extension will be injected,
15+
# and the file that contains your extension’s source code. Learn more:
16+
# https://shopify.dev/docs/api/checkout-ui-extensions/unstable/extension-targets-overview
17+
18+
[[extensions.targeting]]
19+
module = "./src/Checkout.jsx"
20+
target = "purchase.checkout.block.render"
21+
22+
[extensions.capabilities]
23+
# Gives your extension access to directly query Shopify’s storefront API.
24+
# https://shopify.dev/docs/api/checkout-ui-extensions/unstable/configuration#api-access
25+
api_access = true
26+
27+
# Gives your extension access to make external network calls, using the
28+
# JavaScript `fetch()` API. Learn more:
29+
# https://shopify.dev/docs/api/checkout-ui-extensions/unstable/configuration#network-access
30+
# network_access = true
31+
32+
# Loads metafields on checkout resources, including the cart,
33+
# products, customers, and more. Learn more:
34+
# https://shopify.dev/docs/api/checkout-ui-extensions/unstable/configuration#metafields
35+
36+
# [[extensions.metafields]]
37+
# namespace = "my_namespace"
38+
# key = "my_key"
39+
# [[extensions.metafields]]
40+
# namespace = "my_namespace"
41+
# key = "my_other_key"
42+
43+
# Defines settings that will be collected from merchants installing
44+
# your extension. Learn more:
45+
# https://shopify.dev/docs/api/checkout-ui-extensions/unstable/configuration#settings-definition
46+
47+
# [extensions.settings]
48+
# [[extensions.settings.fields]]
49+
# key = "banner_title"
50+
# type = "single_line_text_field"
51+
# name = "Banner title"
52+
# description = "Enter a title for the banner"
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {
2+
reactExtension,
3+
Banner,
4+
BlockStack,
5+
Checkbox,
6+
Text,
7+
useApi,
8+
useApplyAttributeChange,
9+
useInstructions,
10+
useTranslate,
11+
} from "@shopify/ui-extensions-react/checkout";
12+
13+
// 1. Choose an extension target
14+
export default reactExtension("purchase.checkout.block.render", () => (
15+
<Extension />
16+
));
17+
18+
function Extension() {
19+
const translate = useTranslate();
20+
const { extension } = useApi();
21+
const instructions = useInstructions();
22+
const applyAttributeChange = useApplyAttributeChange();
23+
24+
25+
// 2. Check instructions for feature availability, see https://shopify.dev/docs/api/checkout-ui-extensions/apis/cart-instructions for details
26+
if (!instructions.attributes.canUpdateAttributes) {
27+
// For checkouts such as draft order invoices, cart attributes may not be allowed
28+
// Consider rendering a fallback UI or nothing at all, if the feature is unavailable
29+
return (
30+
<Banner title="checkout-ui" status="warning">
31+
{translate("attributeChangesAreNotSupported")}
32+
</Banner>
33+
);
34+
}
35+
36+
// 3. Render a UI
37+
return (
38+
<BlockStack border={"dotted"} padding={"tight"}>
39+
<Banner title="checkout-ui">
40+
{translate("welcome", {
41+
target: <Text emphasis="italic">{extension.target}</Text>,
42+
})}
43+
</Banner>
44+
<Checkbox onChange={onCheckboxChange}>
45+
{translate("iWouldLikeAFreeGiftWithMyOrder")}
46+
</Checkbox>
47+
</BlockStack>
48+
);
49+
50+
async function onCheckboxChange(isChecked) {
51+
// 4. Call the API to modify checkout
52+
const result = await applyAttributeChange({
53+
key: "requestedFreeGift",
54+
type: "updateAttribute",
55+
value: isChecked ? "yes" : "no",
56+
});
57+
console.log("applyAttributeChange result", result);
58+
}
59+
}

0 commit comments

Comments
 (0)