Skip to content

Commit 6cbbd6d

Browse files
authored
Merge pull request #382 from medusajs/v2
chore: V2
2 parents c30bec3 + 2ae2cb4 commit 6cbbd6d

File tree

139 files changed

+5487
-8671
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+5487
-8671
lines changed

.env.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Your Medusa backend, should be updated to where you are hosting your server. Remember to update CORS settings for your server. See – https://docs.medusajs.com/usage/configurations#admin_cors-and-store_cors
22
NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost:9000
33

4+
# Your publishable key that can be attached to sales channels. See - https://docs.medusajs.com/development/publishable-api-keys
5+
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_test
6+
47
# Your store URL, should be updated to where you are hosting your storefront.
58
NEXT_PUBLIC_BASE_URL=http://localhost:8000
69

@@ -14,6 +17,7 @@ NEXT_PUBLIC_STRIPE_KEY=
1417
NEXT_PUBLIC_PAYPAL_CLIENT_ID=
1518

1619
# Your MeiliSearch / Algolia keys. See – https://docs.medusajs.com/add-plugins/meilisearch or https://docs.medusajs.com/add-plugins/algolia
20+
NEXT_PUBLIC_FEATURE_SEARCH_ENABLED=false
1721
NEXT_PUBLIC_SEARCH_APP_ID=
1822
NEXT_PUBLIC_SEARCH_ENDPOINT=http://127.0.0.1:7700
1923
NEXT_PUBLIC_SEARCH_API_KEY=

.github/scripts/medusa-config.js

Lines changed: 59 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,76 @@
1-
const dotenv = require("dotenv");
1+
const { defineConfig, loadEnv } = require("@medusajs/utils")
22

3-
let ENV_FILE_NAME = "";
4-
switch (process.env.NODE_ENV) {
5-
case "production":
6-
ENV_FILE_NAME = ".env.production";
7-
break;
8-
case "staging":
9-
ENV_FILE_NAME = ".env.staging";
10-
break;
11-
case "test":
12-
ENV_FILE_NAME = ".env.test";
13-
break;
14-
case "development":
15-
default:
16-
ENV_FILE_NAME = ".env";
17-
break;
18-
}
19-
20-
try {
21-
dotenv.config({ path: process.cwd() + "/" + ENV_FILE_NAME });
22-
} catch (e) {}
3+
loadEnv(process.env.NODE_ENV || "development", process.cwd())
234

245
// CORS when consuming Medusa from admin
25-
const ADMIN_CORS =
26-
process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001";
6+
// Medusa's docs are added for a better learning experience. Feel free to remove.
7+
const ADMIN_CORS = `${
8+
process.env.ADMIN_CORS?.length
9+
? `${process.env.ADMIN_CORS},`
10+
: "http://localhost:7000,http://localhost:7001,"
11+
}https://docs.medusajs.com,https://medusa-docs-v2-git-docs-v2-medusajs.vercel.app,https://medusa-resources-git-docs-v2-medusajs.vercel.app`
2712

2813
// CORS to avoid issues when consuming Medusa from a client
29-
const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000";
14+
// Medusa's docs are added for a better learning experience. Feel free to remove.
15+
const STORE_CORS = `${
16+
process.env.STORE_CORS?.length
17+
? `${process.env.STORE_CORS},`
18+
: "http://localhost:8000,"
19+
}https://docs.medusajs.com,https://medusa-docs-v2-git-docs-v2-medusajs.vercel.app,https://medusa-resources-git-docs-v2-medusajs.vercel.app`
3020

3121
const DATABASE_URL =
32-
process.env.DATABASE_URL || "postgres://medusa:password@localhost/medusa";
22+
process.env.DATABASE_URL || "postgres://medusa:password@localhost/medusa"
3323

34-
const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";
24+
const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379"
3525

36-
const plugins = [
37-
`medusa-fulfillment-manual`,
38-
`medusa-payment-manual`,
39-
{
40-
resolve: `@medusajs/file-local`,
41-
options: {
42-
upload_dir: "uploads",
43-
},
44-
},
45-
{
46-
resolve: "@medusajs/admin",
47-
/** @type {import('@medusajs/admin').PluginOptions} */
48-
options: {
49-
autoRebuild: true,
50-
develop: {
51-
open: process.env.OPEN_BROWSER !== "false",
26+
export default defineConfig({
27+
plugins: [
28+
`medusa-fulfillment-manual`,
29+
`medusa-payment-manual`,
30+
{
31+
resolve: `@medusajs/file-local`,
32+
options: {
33+
upload_dir: "uploads",
5234
},
5335
},
54-
},
55-
{
56-
resolve: `medusa-plugin-meilisearch`,
57-
options: {
58-
config: {
59-
host: process.env.MEILISEARCH_HOST,
60-
apiKey: process.env.MEILISEARCH_API_KEY,
61-
},
62-
settings: {
63-
products: {
64-
indexSettings: {
65-
searchableAttributes: [
66-
"title",
67-
"description",
68-
"variant_sku",
69-
],
70-
displayedAttributes: [
71-
"id",
72-
"title",
73-
"description",
74-
"variant_sku",
75-
"thumbnail",
76-
"handle",
77-
],
36+
{
37+
resolve: `medusa-plugin-meilisearch`,
38+
options: {
39+
config: {
40+
host: process.env.MEILISEARCH_HOST,
41+
apiKey: process.env.MEILISEARCH_API_KEY,
42+
},
43+
settings: {
44+
products: {
45+
indexSettings: {
46+
searchableAttributes: ["title", "description", "variant_sku"],
47+
displayedAttributes: [
48+
"id",
49+
"title",
50+
"description",
51+
"variant_sku",
52+
"thumbnail",
53+
"handle",
54+
],
55+
},
56+
primaryKey: "id",
7857
},
79-
primaryKey: "id",
8058
},
8159
},
8260
},
61+
],
62+
admin: {
63+
backendUrl: "http://localhost:9000",
8364
},
84-
];
85-
86-
const modules = {
87-
/*eventBus: {
88-
resolve: "@medusajs/event-bus-redis",
89-
options: {
90-
redisUrl: REDIS_URL
91-
}
65+
projectConfig: {
66+
databaseUrl: DATABASE_URL,
67+
http: {
68+
storeCors: STORE_CORS,
69+
adminCors: ADMIN_CORS,
70+
authCors: process.env.AUTH_CORS || ADMIN_CORS,
71+
jwtSecret: process.env.JWT_SECRET || "supersecret",
72+
cookieSecret: process.env.COOKIE_SECRET || "supersecret",
73+
},
74+
redisUrl: REDIS_URL,
9275
},
93-
cacheService: {
94-
resolve: "@medusajs/cache-redis",
95-
options: {
96-
redisUrl: REDIS_URL
97-
}
98-
},*/
99-
};
100-
101-
/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
102-
const projectConfig = {
103-
jwtSecret: process.env.JWT_SECRET,
104-
cookieSecret: process.env.COOKIE_SECRET,
105-
store_cors: STORE_CORS,
106-
database_url: DATABASE_URL,
107-
admin_cors: ADMIN_CORS,
108-
// Uncomment the following lines to enable REDIS
109-
redis_url: REDIS_URL
110-
};
111-
112-
/** @type {import('@medusajs/medusa').ConfigModule} */
113-
module.exports = {
114-
projectConfig,
115-
plugins,
116-
modules,
117-
};
76+
})

.github/workflows/test-e2e.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Use Node.js
8989
uses: actions/setup-node@v3
9090
with:
91-
node-version: "18"
91+
node-version: "20"
9292

9393
- name: Initialize PostgreSQL
9494
run: |
@@ -97,13 +97,15 @@ jobs:
9797
psql -h localhost -U postgres -d test -c "CREATE DATABASE ${{ env.TEST_POSTGRES_DATABASE }} OWNER ${{ env.TEST_POSTGRES_USER }};"
9898
9999
- name: Install Medusa CLI
100-
run: npm install @medusajs/medusa-cli -g
100+
run: npm install @medusajs/medusa-cli@preview -g
101101
- name: Setup medusa backend server
102102
working-directory: ../
103103
# https://docs.medusajs.com/cli/reference#options
104104
run: |
105105
medusa new backend \
106106
-y \
107+
--v2 \
108+
--branch feat/v2 \
107109
--skip-db \
108110
--skip-migrations \
109111
--skip-env \
@@ -113,10 +115,6 @@ jobs:
113115
--db-host ${{ env.TEST_POSTGRES_HOST }} \
114116
--db-port ${{ env.TEST_POSTGREST_PORT }}
115117
116-
- name: Build the backend
117-
working-directory: ../backend
118-
run: yarn build:admin
119-
120118
- name: Setup search in the backend
121119
working-directory: ../backend
122120
run: yarn add medusa-plugin-meilisearch
@@ -130,7 +128,7 @@ jobs:
130128

131129
- name: Run backend server
132130
working-directory: ../backend
133-
run: medusa develop &
131+
run: medusa develop
134132

135133
- name: Install packages
136134
run: yarn install -y

check-env-variables.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const c = require("ansi-colors")
2+
3+
const requiredEnvs = [
4+
{
5+
key: "NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY",
6+
// TODO: we need a good doc to point this to
7+
description:
8+
"Learn how to create a publishable key: https://docs.medusajs.com/v2/resources/storefront-development/publishable-api-keys",
9+
},
10+
]
11+
12+
function checkEnvVariables() {
13+
const missingEnvs = requiredEnvs.filter(function (env) {
14+
return !process.env[env.key]
15+
})
16+
17+
if (missingEnvs.length > 0) {
18+
console.error(
19+
c.red.bold("\n🚫 Error: Missing required environment variables\n")
20+
)
21+
22+
missingEnvs.forEach(function (env) {
23+
console.error(c.yellow(` ${c.bold(env.key)}`))
24+
if (env.description) {
25+
console.error(c.dim(` ${env.description}\n`))
26+
}
27+
})
28+
29+
console.error(
30+
c.yellow(
31+
"\nPlease set these variables in your .env file or environment before starting the application.\n"
32+
)
33+
)
34+
35+
process.exit(1)
36+
}
37+
}
38+
39+
module.exports = checkEnvVariables

netlify.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.
5+
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.

next.config.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const { withStoreConfig } = require("./store-config")
2-
const store = require("./store.config.json")
1+
const checkEnvVariables = require("./check-env-variables")
2+
3+
checkEnvVariables()
34

45
/**
56
* @type {import('next').NextConfig}
67
*/
7-
const nextConfig = withStoreConfig({
8-
features: store.features,
8+
const nextConfig = {
99
reactStrictMode: true,
1010
images: {
1111
remotePatterns: [
@@ -27,8 +27,6 @@ const nextConfig = withStoreConfig({
2727
},
2828
],
2929
},
30-
})
31-
32-
console.log("next.config.js", JSON.stringify(module.exports, null, 2))
30+
}
3331

3432
module.exports = nextConfig

package.json

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,11 @@
1515
"analyze": "ANALYZE=true next build",
1616
"test-e2e": "playwright test e2e"
1717
},
18-
"resolutions": {
19-
"webpack": "^5",
20-
"@types/react": "17.0.40"
21-
},
2218
"dependencies": {
2319
"@headlessui/react": "^1.6.1",
2420
"@hookform/error-message": "^2.0.0",
25-
"@medusajs/link-modules": "^0.2.3",
26-
"@medusajs/medusa-js": "^6.1.7",
27-
"@medusajs/modules-sdk": "^1.12.3",
28-
"@medusajs/pricing": "^0.1.4",
29-
"@medusajs/product": "^0.3.4",
30-
"@medusajs/ui": "^2.2.0",
21+
"@medusajs/js-sdk": "2.0.0",
22+
"@medusajs/ui": "2.0.0",
3123
"@meilisearch/instant-meilisearch": "^0.7.1",
3224
"@paypal/paypal-js": "^5.0.6",
3325
"@paypal/react-paypal-js": "^7.8.1",
@@ -36,29 +28,30 @@
3628
"algoliasearch": "^4.20.0",
3729
"axios": "^1.6.7",
3830
"lodash": "^4.17.21",
39-
"medusa-react": "^9.0.0",
4031
"next": "^14.0.0",
4132
"pg": "^8.11.3",
33+
"qs": "^6.12.1",
4234
"react": "^18.2.0",
4335
"react-country-flag": "^3.0.2",
4436
"react-dom": "^18.2.0",
4537
"react-instantsearch-hooks-web": "^6.29.0",
4638
"react-intersection-observer": "^9.3.4",
39+
"server-only": "^0.0.1",
4740
"tailwindcss-radix": "^2.8.0",
4841
"webpack": "^5"
4942
},
5043
"devDependencies": {
5144
"@babel/core": "^7.17.5",
52-
"@medusajs/client-types": "^0.2.2",
53-
"@medusajs/medusa": "^1.18.0",
54-
"@medusajs/ui-preset": "^1.0.2",
45+
"@medusajs/types": "2.0.0",
46+
"@medusajs/ui-preset": "2.0.0",
5547
"@playwright/test": "^1.41.1",
5648
"@types/lodash": "^4.14.195",
5749
"@types/node": "17.0.21",
5850
"@types/pg": "^8.11.0",
5951
"@types/react": "^18.2.42",
6052
"@types/react-dom": "^18.2.18",
6153
"@types/react-instantsearch-dom": "^6.12.3",
54+
"ansi-colors": "^4.1.3",
6255
"autoprefixer": "^10.4.2",
6356
"babel-loader": "^8.2.3",
6457
"eslint": "8.10.0",
@@ -67,5 +60,6 @@
6760
"prettier": "^2.8.8",
6861
"tailwindcss": "^3.0.23",
6962
"typescript": "^5.3.2"
70-
}
63+
},
64+
"packageManager": "[email protected]"
7165
}

0 commit comments

Comments
 (0)