Skip to content

Commit 716abfe

Browse files
committed
Centralize sample storefront configuration
1 parent 9580dc7 commit 716abfe

21 files changed

Lines changed: 1235 additions & 163 deletions

File tree

.env.example

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Checkout Kit sample storefront configuration.
2+
# Copy this file to .env, fill in local values, then run:
3+
# scripts/setup_storefront_env
4+
# Optional Apple Pay and Customer Account API values can stay blank.
5+
#
6+
# Do not commit real values from .env or generated platform config files.
7+
8+
# Storefront details
9+
STOREFRONT_DOMAIN=your-store.myshopify.com
10+
STOREFRONT_ACCESS_TOKEN=your-public-storefront-access-token
11+
STOREFRONT_MERCHANT_IDENTIFIER=
12+
13+
# Storefront API version
14+
API_VERSION=2025-07
15+
16+
# Customer Account API (optional)
17+
CUSTOMER_ACCOUNT_API_CLIENT_ID=
18+
CUSTOMER_ACCOUNT_API_SHOP_ID=
19+
CUSTOMER_ACCOUNT_API_VERSION=unstable
20+
21+
# Buyer identity defaults used by sample apps
22+
EMAIL=checkout-kit@example.com
23+
ADDRESS_1=650 King Street
24+
ADDRESS_2=Shopify HQ
25+
CITY=Toronto
26+
COMPANY=Shopify
27+
COUNTRY=CA
28+
FIRST_NAME=Evelyn
29+
LAST_NAME=Hartley
30+
PROVINCE=ON
31+
ZIP=M5V 1M7
32+
PHONE=+14165550100

.github/workflows/android-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ jobs:
4747
cache: 'gradle'
4848

4949
- name: Setup sample app environment
50-
run: cp .env.example .env
51-
working-directory: platforms/android/samples/MobileBuyIntegration
50+
run: ${{ github.workspace }}/scripts/setup_storefront_env --skip-optional-prompts
51+
env:
52+
STOREFRONT_DOMAIN: example.myshopify.com
53+
STOREFRONT_ACCESS_TOKEN: test-token
5254

5355
- name: Build Sample App
5456
run: ./gradlew assembleDebug

.github/workflows/rn-test-android.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ jobs:
5858
env:
5959
GRADLE_OPTS: -Xmx4g -XX:MaxMetaspaceSize=768m
6060
JAVA_HOME: ${{ steps.setup-java.outputs.path }}
61+
STOREFRONT_DOMAIN: example.myshopify.com
62+
STOREFRONT_ACCESS_TOKEN: test-token
6163
run: |
6264
echo "JAVA_HOME: $JAVA_HOME"
6365
java -version
6466
javac -version
65-
echo "STOREFRONT_DOMAIN=myshopify.com" > sample/.env
67+
${{ github.workspace }}/scripts/setup_storefront_env --skip-optional-prompts
6668
pnpm module build
6769
pnpm sample test:android --no-daemon

.github/workflows/swift-build-samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ jobs:
1313
with:
1414
test-path: ./Scripts/build_samples
1515
job-name: Build Sample Apps
16+
setup-storefront-env: true

.github/workflows/swift-test-workflow.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
required: false
99
type: string
1010
default: Run
11+
setup-storefront-env:
12+
required: false
13+
type: boolean
14+
default: false
1115

1216
permissions:
1317
contents: read
@@ -68,5 +72,12 @@ jobs:
6872
echo "CURRENT_SIMULATOR_UUID=$CURRENT_SIMULATOR_UUID" >> $GITHUB_ENV
6973
echo ""
7074
75+
- name: Setup sample app storefront configuration
76+
if: ${{ inputs.setup-storefront-env }}
77+
env:
78+
STOREFRONT_DOMAIN: example.myshopify.com
79+
STOREFRONT_ACCESS_TOKEN: test-token
80+
run: ${{ github.workspace }}/scripts/setup_storefront_env --skip-optional-prompts
81+
7182
- name: Run Tests
7283
run: ${{ inputs.test-path }}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
# Platform-local example for the Android sample. Prefer the repo-root
2+
# .env.example for shared setup, then run scripts/setup_storefront_env.
13
STOREFRONT_DOMAIN=<yourdomainhere.myshopify.com>
24
STOREFRONT_ACCESS_TOKEN=<storefront access token>
35
API_VERSION=2025-07
46

57
CUSTOMER_ACCOUNT_API_CLIENT_ID=<configured customer account api client id>
6-
CUSTOMER_ACCOUNT_API_REDIRECT_URI=shop.<shop id>.app://callback
7-
8-
CUSTOMER_ACCOUNT_API_GRAPHQL_BASE_URL=https://shopify.com/<shop id>/account/customer/api/<api version>/graphql
9-
CUSTOMER_ACCOUNT_API_AUTH_BASE_URL=https://shopify.com/authentication/<shop id>
8+
# Android derives Customer Account redirect and API URLs from the shop ID and version.
9+
CUSTOMER_ACCOUNT_API_SHOP_ID=<shop id>
10+
CUSTOMER_ACCOUNT_API_VERSION=unstable
1011

1112
# Demo buyer identity used when the "Prefill checkout" toggle is enabled in Settings.
1213
# Phone must be in E.164 format (+1XXXXXXXXXX for Canada).
13-
PREFILL_EMAIL=test.buyer@example.com
14-
PREFILL_PHONE=+16135550123
14+
EMAIL=checkout-kit@example.com
15+
PHONE=+14165550100

platforms/android/samples/MobileBuyIntegration/app/build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,40 @@ def loadProperties() {
2020

2121
def properties = loadProperties()
2222

23+
def propertyOrDefault = { String key, String defaultValue ->
24+
def value = properties.getProperty(key)
25+
return value?.trim() ? value.trim() : defaultValue
26+
}
27+
2328
// Storefront API
2429
def storefrontDomain = properties.getProperty("STOREFRONT_DOMAIN")
2530
def accessToken = properties.getProperty("STOREFRONT_ACCESS_TOKEN")
2631
def apiVersion = properties.getProperty("API_VERSION", "2025-07")
2732

2833
// Customer Account API
2934
def customerAccountApiClientId = properties.getProperty("CUSTOMER_ACCOUNT_API_CLIENT_ID")
35+
def customerAccountApiShopId = properties.getProperty("CUSTOMER_ACCOUNT_API_SHOP_ID")
36+
def customerAccountApiVersion = propertyOrDefault("CUSTOMER_ACCOUNT_API_VERSION", "unstable")
3037
def customerAccountApiRedirectUri = properties.getProperty("CUSTOMER_ACCOUNT_API_REDIRECT_URI")
3138

3239
def customerAccountApiGraphQLBaseUrl = properties.getProperty("CUSTOMER_ACCOUNT_API_GRAPHQL_BASE_URL")
3340
def customerAccountApiAuthBaseUrl = properties.getProperty("CUSTOMER_ACCOUNT_API_AUTH_BASE_URL")
3441

42+
if (!customerAccountApiRedirectUri && customerAccountApiShopId) {
43+
customerAccountApiRedirectUri = "shop.${customerAccountApiShopId}.app://callback"
44+
}
45+
46+
if (!customerAccountApiGraphQLBaseUrl && customerAccountApiShopId) {
47+
customerAccountApiGraphQLBaseUrl = "https://shopify.com/${customerAccountApiShopId}/account/customer/api/${customerAccountApiVersion}/graphql"
48+
}
49+
50+
if (!customerAccountApiAuthBaseUrl && customerAccountApiShopId) {
51+
customerAccountApiAuthBaseUrl = "https://shopify.com/authentication/${customerAccountApiShopId}"
52+
}
53+
3554
// Demo buyer identity (prefill toggle in Settings)
36-
def prefillEmail = properties.getProperty("PREFILL_EMAIL", "test.buyer@example.com")
37-
def prefillPhone = properties.getProperty("PREFILL_PHONE", "+16135550123")
55+
def prefillEmail = properties.getProperty("EMAIL", properties.getProperty("PREFILL_EMAIL", "test.buyer@example.com"))
56+
def prefillPhone = properties.getProperty("PHONE", properties.getProperty("PREFILL_PHONE", "+14165550100"))
3857

3958
if (!storefrontDomain || !accessToken) {
4059
println("**** Please add a .env file with STOREFRONT_DOMAIN and STOREFRONT_ACCESS_TOKEN set *****")

platforms/android/scripts/apollo_download_schema

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,66 @@ set -euo pipefail
33

44
cd samples/MobileBuyIntegration
55

6-
if [ ! -f ".env" ]; then
6+
ENV_FILE=".env"
7+
8+
if [ ! -f "$ENV_FILE" ]; then
79
echo "❌ .env file not found in samples/MobileBuyIntegration/"
8-
echo " Run 'cp .env.example .env' and fill in your credentials."
10+
echo " Run scripts/setup_storefront_env from the repo root."
911
exit 1
1012
fi
1113

12-
npx -y dotenv-cli -e .env -- sh -c '
13-
DOMAIN="$STOREFRONT_DOMAIN"
14-
TOKEN="$STOREFRONT_ACCESS_TOKEN"
15-
VERSION="$API_VERSION"
16-
17-
if [ -z "$DOMAIN" ]; then
18-
echo "❌ STOREFRONT_DOMAIN is not set. Check your .env file."
19-
exit 1
20-
fi
21-
if [ -z "$TOKEN" ]; then
22-
echo "❌ STOREFRONT_ACCESS_TOKEN is not set. Check your .env file."
23-
exit 1
24-
fi
25-
if [ -z "$VERSION" ]; then
26-
echo "❌ API_VERSION is not set. Check your .env file."
27-
echo " Add API_VERSION=2025-07 to your .env"
28-
exit 1
29-
fi
30-
31-
echo "📡 Downloading schema for MobileBuyIntegration..."
32-
echo " Domain: $DOMAIN"
33-
echo " API Version: $VERSION"
34-
35-
rover graph introspect \
36-
"https://$DOMAIN/api/$VERSION/graphql" \
37-
--header="X-Shopify-Storefront-Access-Token: $TOKEN" \
38-
--output "app/src/main/graphql/schema.graphqls"
39-
40-
if [ $? -eq 0 ]; then
41-
echo "✅ Schema downloaded to app/src/main/graphql/schema.graphqls"
42-
else
43-
echo "❌ Schema download failed. Check your network connection and credentials."
44-
exit 1
45-
fi
46-
'
14+
read_env_value() {
15+
local key="$1"
16+
awk -v key="$key" '
17+
/^[[:space:]]*#/ || /^[[:space:]]*\/\// || /^[[:space:]]*$/ { next }
18+
$0 !~ /=/ { next }
19+
{
20+
line = $0
21+
sub(/^[[:space:]]*/, "", line)
22+
candidate = line
23+
sub(/=.*/, "", candidate)
24+
sub(/[[:space:]]*$/, "", candidate)
25+
if (candidate == key) {
26+
value = substr(line, index(line, "=") + 1)
27+
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
28+
if (value ~ /^".*"$/ || value ~ /^'\''.*'\''$/) {
29+
value = substr(value, 2, length(value) - 2)
30+
}
31+
print value
32+
exit
33+
}
34+
}
35+
' "$ENV_FILE"
36+
}
37+
38+
DOMAIN="$(read_env_value STOREFRONT_DOMAIN)"
39+
TOKEN="$(read_env_value STOREFRONT_ACCESS_TOKEN)"
40+
VERSION="$(read_env_value API_VERSION)"
41+
42+
if [ -z "$DOMAIN" ]; then
43+
echo "❌ STOREFRONT_DOMAIN is not set. Check your .env file."
44+
exit 1
45+
fi
46+
if [ -z "$TOKEN" ]; then
47+
echo "❌ STOREFRONT_ACCESS_TOKEN is not set. Check your .env file."
48+
exit 1
49+
fi
50+
if [ -z "$VERSION" ]; then
51+
echo "❌ API_VERSION is not set. Check your .env file."
52+
echo " Add API_VERSION=2025-07 to your .env"
53+
exit 1
54+
fi
55+
56+
echo "📡 Downloading schema for MobileBuyIntegration..."
57+
echo " Domain: $DOMAIN"
58+
echo " API Version: $VERSION"
59+
60+
if rover graph introspect \
61+
"https://$DOMAIN/api/$VERSION/graphql" \
62+
--header="X-Shopify-Storefront-Access-Token: $TOKEN" \
63+
--output "app/src/main/graphql/schema.graphqls"; then
64+
echo "✅ Schema downloaded to app/src/main/graphql/schema.graphqls"
65+
else
66+
echo "❌ Schema download failed. Check your network connection and credentials."
67+
exit 1
68+
fi
Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,7 @@
11
#!/bin/bash
22

3-
# Function to create .env file for a sample app
4-
create_env_file() {
5-
local app_name="$1"
6-
local env_path="./samples/${app_name}/.env"
3+
set -e
74

8-
if [ ! -f "$env_path" ]; then
9-
echo "Creating ${app_name} .env file..."
10-
cat >"$env_path" <<EOF
11-
STOREFRONT_DOMAIN=${STOREFRONT_DOMAIN}
12-
STOREFRONT_ACCESS_TOKEN=${STOREFRONT_ACCESS_TOKEN}
13-
EOF
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
146

15-
# Add optional authentication configuration if provided
16-
if [ -n "$SHOP_ID" ] && [ -n "$CUSTOMER_ACCOUNT_API_CLIENT_ID" ]; then
17-
cat >>"$env_path" <<EOF
18-
19-
CUSTOMER_ACCOUNT_API_CLIENT_ID=${CUSTOMER_ACCOUNT_API_CLIENT_ID}
20-
CUSTOMER_ACCOUNT_API_REDIRECT_URI=shop.${SHOP_ID}.app://callback
21-
22-
CUSTOMER_ACCOUNT_API_GRAPHQL_BASE_URL=https://shopify.com/${SHOP_ID}/account/customer/api/${CUSTOMER_ACCOUNT_API_VERSION}/graphql
23-
CUSTOMER_ACCOUNT_API_AUTH_BASE_URL=https://shopify.com/authentication/${SHOP_ID}
24-
EOF
25-
fi
26-
echo "✓ Created ${app_name} .env file"
27-
fi
28-
}
29-
30-
# Prompt for Shopify credentials
31-
echo "Setting up .env files for sample apps..."
32-
echo "Please provide your Shopify storefront credentials:"
33-
read -p "Storefront Domain (e.g., yourstore.myshopify.com): " STOREFRONT_DOMAIN
34-
read -p "Storefront Access Token: " STOREFRONT_ACCESS_TOKEN
35-
36-
if [ -z "$STOREFRONT_DOMAIN" ] || [ -z "$STOREFRONT_ACCESS_TOKEN" ]; then
37-
echo "Error: Both storefront domain and access token are required."
38-
exit 1
39-
fi
40-
41-
# Optional authentication configuration
42-
echo ""
43-
echo "Optional: Customer Account API configuration (needed for authentication features)"
44-
echo "Press Enter to skip if you don't need authentication features."
45-
read -p "Shop ID (optional): " SHOP_ID
46-
read -p "Customer Account API Client ID (optional): " CUSTOMER_ACCOUNT_API_CLIENT_ID
47-
read -p "Customer Account API Version (default: unstable): " CUSTOMER_ACCOUNT_API_VERSION
48-
49-
# Set default API version if not provided
50-
if [ -z "$CUSTOMER_ACCOUNT_API_VERSION" ]; then
51-
CUSTOMER_ACCOUNT_API_VERSION="unstable"
52-
fi
53-
54-
# Create .env files for both sample apps
55-
create_env_file "MobileBuyIntegration"
56-
57-
echo "✓ Sample app .env files are ready!"
7+
exec "$SCRIPT_DIR/../../../scripts/setup_storefront_env" "$@"

platforms/react-native/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ Here's an example of how to get started with Apollo:
212212

213213
```tsx
214214
import {ApolloClient, gql, ApolloProvider} from '@apollo/client';
215-
import {STOREFRONT_NAME, STOREFRONT_ACCESS_TOKEN} from '@env';
215+
import {API_VERSION, STOREFRONT_DOMAIN, STOREFRONT_ACCESS_TOKEN} from '@env';
216216

217217
// Create a new instance of the ApolloClient
218218
const client = new ApolloClient({
219-
uri: `https://${STOREFRONT_NAME}.myshopify.com/api/2025-07/graphql.json`,
219+
uri: `https://${STOREFRONT_DOMAIN}/api/${API_VERSION}/graphql.json`,
220220
headers: {
221221
'X-Shopify-Storefront-Access-Token': STOREFRONT_ACCESS_TOKEN,
222222
},

0 commit comments

Comments
 (0)