Skip to content

Commit

Permalink
API_URL compatibility (#4923)
Browse files Browse the repository at this point in the history
* API_URL compatibility

* API_URL compatibility

* API_URL compatibility

* API_URL compatibility

* API_URL compatibility
  • Loading branch information
andrzejewsky authored Jun 10, 2024
1 parent be35676 commit f7bb80c
Show file tree
Hide file tree
Showing 27 changed files with 96 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-humans-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

The API_URI is no longer used across the codebase. API_URI stays in workflows for backward compatibility
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
API_URI=https://demo.saleor.io/graphql/
API_URL=https://demo.saleor.io/graphql/
APP_MOUNT_URI=/
APPS_MARKETPLACE_API_URI=https://apps.saleor.io/api/v2/saleor-apps
APPS_MARKETPLACE_API_URL=https://apps.saleor.io/api/v2/saleor-apps
LOCALE_CODE="EN"
DEMO_MODE=false

Expand Down
3 changes: 3 additions & 0 deletions .github/actions/e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ runs:
install: ${{inputs.install}}
browser: ${{inputs.browser}}
env:
## backward compatibility for older versions
API_URI: ${{inputs.apiUrl}}

API_URL: ${{inputs.apiUrl}}
APP_MOUNT_URI: ${{ inputs.appMountUri }}
BASE_URL: ${{inputs.baseUrl}}
CYPRESS_USER_NAME: ${{ inputs.userName }}
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/run-pw-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ runs:
- name: Run tests
shell: bash
env:
## backward compatibility for older versions
API_URI: ${{ inputs.API_URL }}

API_URL: ${{ inputs.API_URL }}
BASE_URL: ${{ inputs.BASE_URL }}
E2E_USER_NAME: ${{ inputs.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ inputs.E2E_USER_PASSWORD }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/cypress-repeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ jobs:
id: cypress
uses: cypress-io/github-action@v4
env:
## backward compatibility for older versions
API_URI: ${{ github.event.inputs.API_url}}

API_URL: ${{ github.event.inputs.API_url}}
APP_MOUNT_URI: ${{ secrets.APP_MOUNT_URI }}
BASE_URL: ${{ github.event.inputs.dashboard_url}}
CYPRESS_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/deploy-and-run-cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ jobs:
- name: Run build
env:
## backward compatibility for older versions
API_URI: ${{github.event.inputs.api_url}}

API_URL: ${{github.event.inputs.api_url}}
APP_MOUNT_URI: /
STATIC_URL: /
IS_CLOUD_INSTANCE: true
Expand Down Expand Up @@ -108,7 +111,10 @@ jobs:
- name: Cypress run critical
uses: cypress-io/github-action@v4
env:
## backward compatibility for older versions
API_URI: ${{github.event.inputs.api_url}}

API_URL: ${{github.event.inputs.api_url}}
APP_MOUNT_URI: ${{ secrets.APP_MOUNT_URI }}
BASE_URL: https://${{needs.deploy.outputs.base_URL}}
CYPRESS_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/deploy-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ jobs:
build:
runs-on: ubuntu-20.04
env:
## backward compatibility for older versions
APPS_MARKETPLACE_API_URI: "https://apps.saleor.io/api/v2/saleor-apps"
## backward compatibility for older versions
API_URI: /graphql/

API_URL: /graphql/
APP_MOUNT_URI: /dashboard/
STATIC_URL: /dashboard/static/
SENTRY_ORG: saleor
Expand All @@ -17,7 +22,7 @@ jobs:
REGION: ${{ github.event.client_payload.region }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
APPS_MARKETPLACE_API_URI: "https://apps.saleor.io/api/v2/saleor-apps"
APPS_MARKETPLACE_API_URL: "https://apps.saleor.io/api/v2/saleor-apps"
IS_CLOUD_INSTANCE: true
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ jobs:
build:
runs-on: ubuntu-20.04
env:
## backward compatibility for older versions
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
## backward compatibility for older versions
API_URI: /graphql/

API_URL: /graphql/
APP_MOUNT_URI: /dashboard/
STATIC_URL: /dashboard/static/
SENTRY_ORG: saleor
SENTRY_PROJECT: dashboard
SENTRY_URL_PREFIX: "~/dashboard/static"
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
APPS_MARKETPLACE_API_URL: "https://apps.staging.saleor.io/api/v2/saleor-apps"
IS_CLOUD_INSTANCE: true
steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/deploy-master-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ jobs:
build:
runs-on: ubuntu-20.04
env:
## backward compatibility for older versions
API_URI: /graphql/
## backward compatibility for older versions
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"

API_URL: /graphql/
APP_MOUNT_URI: /dashboard/
STATIC_URL: /dashboard/static/
SENTRY_ORG: saleor
SENTRY_PROJECT: dashboard
SENTRY_URL_PREFIX: "~/dashboard/static"
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
APPS_MARKETPLACE_API_URL: "https://apps.staging.saleor.io/api/v2/saleor-apps"
IS_CLOUD_INSTANCE: true
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/deploy-staging-and-prepare-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ jobs:
MINOR_VERSION: ${{ env.MINOR_VERSION }}
CUSTOM_VERSION: ${{ env.CUSTOM_VERSION || env.VERSION }}
env:
## backward compatibility for older versions
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
## backward compatibility for older versions
API_URI: /graphql/

API_URL: /graphql/
APP_MOUNT_URI: /dashboard/
STATIC_URL: /dashboard/static/
SENTRY_ORG: saleor
SENTRY_PROJECT: dashboard
SENTRY_URL_PREFIX: "~/dashboard/static"
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
APPS_MARKETPLACE_API_URL: "https://apps.staging.saleor.io/api/v2/saleor-apps"
VERSION: ${{ github.event.inputs.git_ref || github.ref_name }}
IS_CLOUD_INSTANCE: true
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ jobs:
id: set-domain
run: |
echo "domain=${{ env.GITHUB_HEAD_REF_SLUG_URL }}.dashboard.saleor.rocks" >> $GITHUB_OUTPUT
## backward compatibility for older versions
- name: Get API_URI
id: api_uri
# Search for API_URI in PR description and use default if not defined
Expand All @@ -107,13 +109,28 @@ jobs:
fallback_uri: ${{ secrets.CYPRESS_API_URI }}
run: |
echo "custom_api_uri=$(echo "$pull_request_body" | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1 | { read custom_uri; if [ -z "$custom_uri" ]; then echo "$fallback_uri"; else echo "$custom_uri"; fi })" >> $GITHUB_OUTPUT
- name: Get API_URL
id: api_url
env:
pull_request_body: ${{ github.event.pull_request.body }}
prefix: API_URL=
pattern: (http|https)://[a-zA-Z0-9.-]+/graphql/?
fallback_uri: ${{ secrets.CYPRESS_API_URL }}
run: |
echo "custom_api_url=$(echo "$pull_request_body" | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1 | { read custom_url; if [ -z "$custom_url" ]; then echo "$fallback_url"; else echo "$custom_url"; fi })" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v2

- name: Cypress run
uses: cypress-io/github-action@v4
env:
## backward compatibility for older versions
API_URI: ${{ steps.api_uri.outputs.custom_api_uri }}

API_URL: ${{ steps.api_url.outputs.custom_api_url }}
APP_MOUNT_URI: ${{ secrets.APP_MOUNT_URI }}
BASE_URL: https://${{ steps.set-domain.outputs.domain }}/
CYPRESS_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ jobs:

- name: Build dashboard
env:
## backward compatibility for older versions
API_URI: ${{ needs.initialize-cloud.outputs.API_URL }}

API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
APP_MOUNT_URI: /
STATIC_URL: /
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/tests-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,14 @@ jobs:
continue-on-error: true
uses: cypress-io/github-action@v6
env:
## backward compatibility for older versions
API_URI: ${{ needs.get-environment-variables.outputs.url }}graphql/
APP_MOUNT_URI: ${{ secrets.APP_MOUNT_URI }}
BASE_URL: ${{ needs.get-environment-variables.outputs.url }}dashboard/
## backward compatibility requires CYPRESS_baseUrl as env var name - can be removed when version lower than 3.17 are no longer supported
CYPRESS_baseUrl: ${{ needs.get-environment-variables.outputs.url }}dashboard/

API_URL: ${{ needs.get-environment-variables.outputs.url }}graphql/
APP_MOUNT_URI: ${{ secrets.APP_MOUNT_URI }}
BASE_URL: ${{ needs.get-environment-variables.outputs.url }}dashboard/
CYPRESS_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }}
CYPRESS_SECOND_USER_NAME: ${{ secrets.CYPRESS_SECOND_USER_NAME }}
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ COPY .featureFlags/ .featureFlags/

COPY src/ src/

ARG API_URI
ARG API_URL
ARG APP_MOUNT_URI
ARG APPS_MARKETPLACE_API_URI
ARG APPS_MARKETPLACE_API_URL
ARG APPS_TUNNEL_URL_KEYWORDS
ARG STATIC_URL
ARG SKIP_SOURCEMAPS
ARG LOCALE_CODE

ENV API_URI ${API_URI:-http://localhost:8000/graphql/}
ENV API_URL ${API_URL:-http://localhost:8000/graphql/}
ENV APP_MOUNT_URI ${APP_MOUNT_URI:-/dashboard/}
ENV APPS_MARKETPLACE_API_URI ${APPS_MARKETPLACE_API_URI:-https://apps.saleor.io/api/v2/saleor-apps}
ENV APPS_MARKETPLACE_API_URL ${APPS_MARKETPLACE_API_URL:-https://apps.saleor.io/api/v2/saleor-apps}
ENV APPS_TUNNEL_URL_KEYWORDS ${APPS_TUNNEL_URL_KEYWORDS}
ENV STATIC_URL ${STATIC_URL:-/dashboard/}
ENV SKIP_SOURCEMAPS ${SKIP_SOURCEMAPS:-true}
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"logo": "https://mirumee.com/img/opensource_saleor.jpg",
"keywords": ["saleor", "e-commerce", "dashboard"],
"env": {
"API_URI": {
"API_URL": {
"description": "URI of a running instance of Saleor GraphQL API",
"value": "https://demo.getsaleor.com/graphql/"
},
Expand Down
2 changes: 1 addition & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dotenv from "dotenv";
dotenv.config();

const config: CodegenConfig = {
schema: process.env.API_URI,
schema: process.env.API_URL,
generates: {
'./introspection.json': {
plugins: ['introspection']
Expand Down
2 changes: 1 addition & 1 deletion cypress/fixtures/urlList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const urlList = {
apiUri: Cypress.env("API_URI"),
apiUri: Cypress.env("API_URL"),
dashboard: "dashboard/",
addProduct: "products/add",
apps: "custom-apps/",
Expand Down
4 changes: 2 additions & 2 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = async (on, config) => {

require("dotenv").config();

config.env.API_URI = process.env.API_URI;
config.env.API_URL = process.env.API_URL;
config.env.APP_MOUNT_URI = process.env.APP_MOUNT_URI;
config.env.SHOP = await getShopInfo(process.env);
config.env.STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
Expand Down Expand Up @@ -61,7 +61,7 @@ function getShopInfo(envVariables) {
}
}`;

const client = new graphql.GraphQLClient(envVariables.API_URI, {
const client = new graphql.GraphQLClient(envVariables.API_URL, {
headers: {},
});

Expand Down
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ Run `cp .env.template .env` to create default configuration that will be connect

Create or edit `.env` file in a root directory or set environment variables with the following values:

- `API_URI` (required) - URI of Saleor GraphQL API instance.
If you are running Saleor locally with the default settings, set `API_URI` to: "http://localhost:8000/graphql/".
Make sure you have "/" at the end of `API_URI`.
- `API_URL` (required) - URI of Saleor GraphQL API instance.
If you are running Saleor locally with the default settings, set `API_URL` to: "http://localhost:8000/graphql/".
Make sure you have "/" at the end of `API_URL`.

- `APP_MOUNT_URI` - URI at which the Dashboard app will be mounted.
E.g., if you set `APP_MOUNT_URI` to "/dashboard/", your app will be mounted at "http://localhost:9000/dashboard/".

- `STATIC_URL` - URL where the static files are located.
E.g., if you use an S3 bucket, you should set it to the bucket's URL. By default, Saleor assumes you serve static files from the root of your site at "http://localhost:9000/".

- `APPS_MARKETPLACE_API_URI` - URI of Marketplace API to fetch list of Apps in JSON.
- `APPS_MARKETPLACE_API_URL` - URI of Marketplace API to fetch list of Apps in JSON.

- `APPS_TUNNEL_URL_KEYWORDS` - Custom apps tunnel URL keywords.
2 changes: 1 addition & 1 deletion playwright/api/basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class BasicApiService {
}
}
}`;
const loginResponse = await this.request.post(process.env.API_URI || "", {
const loginResponse = await this.request.post(process.env.API_URL || "", {
data: { query },
});
const loginResponseJson = await loginResponse.json();
Expand Down
2 changes: 1 addition & 1 deletion src/components/DevModePanel/DevModePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const DevModePanel: React.FC = () => {
const { rootStyle } = useDashboardTheme();
const { isDevModeVisible, variables, devModeContent, setDevModeVisibility } = useDevModeContext();
const fetcher = createGraphiQLFetcher({
url: process.env.API_URI,
url: process.env.API_URL,
fetch: authorizedFetch,
});
const overwriteCodeMirrorCSSVariables = {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const SW_INTERVAL = parseInt(process.env.SW_INTERVAL ?? "300", 10);
export const IS_CLOUD_INSTANCE = window.__SALEOR_CONFIG__.IS_CLOUD_INSTANCE === "true";

export const getAppsConfig = () => ({
marketplaceApiUri: window.__SALEOR_CONFIG__.APPS_MARKETPLACE_API_URI,
marketplaceApiUri: window.__SALEOR_CONFIG__.APPS_MARKETPLACE_API_URL,
tunnelUrlKeywords: window.__SALEOR_CONFIG__.APPS_TUNNEL_URL_KEYWORDS?.split(";") || [
".ngrok.io",
".saleor.live",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface WebhookSubscriptionQueryProps {
}

const fetcher = createGraphiQLFetcher({
url: process.env.API_URI,
url: process.env.API_URL,
});
const WebhookSubscriptionQuery: React.FC<WebhookSubscriptionQueryProps> = ({
errors,
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
window.__SALEOR_CONFIG__ = {
API_URL: "<%= API_URL %>",
APP_MOUNT_URI: "<%= APP_MOUNT_URI %>",
APPS_MARKETPLACE_API_URI: "<%= APPS_MARKETPLACE_API_URI %>",
APPS_MARKETPLACE_API_URL: "<%= APPS_MARKETPLACE_API_URL %>",
APPS_TUNNEL_URL_KEYWORDS: "<%= APPS_TUNNEL_URL_KEYWORDS %>",
IS_CLOUD_INSTANCE: "<%= IS_CLOUD_INSTANCE %>",
LOCALE_CODE: "<%= LOCALE_CODE %>",
Expand Down
2 changes: 1 addition & 1 deletion testUtils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ document.createRange = () => {
window.__SALEOR_CONFIG__ = {
API_URL: "http://localhost:8000/graphql/",
APP_MOUNT_URI: "/",
APPS_MARKETPLACE_API_URI: "http://localhost:3000",
APPS_MARKETPLACE_API_URL: "http://localhost:3000",
APPS_TUNNEL_URL_KEYWORDS: ".ngrok.io;.saleor.live",
IS_CLOUD_INSTANCE: "true",
LOCALE_CODE: "EN",
Expand Down
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare interface Window {
API_URL: string;
APP_MOUNT_URI: string;
LOCALE_CODE?: string;
APPS_MARKETPLACE_API_URI?: string;
APPS_MARKETPLACE_API_URL?: string;
APPS_TUNNEL_URL_KEYWORDS?: string;
IS_CLOUD_INSTANCE?: string;
};
Expand Down
Loading

0 comments on commit f7bb80c

Please sign in to comment.