@forgecart/cli 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -7
- package/bin/forgecart.js +1 -1
- package/dist/package.json +50 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/{cli.js → src/cli.js} +8 -6
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/delete.d.ts.map +1 -0
- package/dist/{commands → src/commands}/delete.js +8 -3
- package/dist/src/commands/delete.js.map +1 -0
- package/dist/src/commands/deploy.d.ts.map +1 -0
- package/dist/src/commands/deploy.js +243 -0
- package/dist/src/commands/deploy.js.map +1 -0
- package/dist/src/commands/env.d.ts.map +1 -0
- package/dist/{commands → src/commands}/env.js +70 -12
- package/dist/src/commands/env.js.map +1 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/{commands → src/commands}/init.js +103 -17
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/list.d.ts.map +1 -0
- package/dist/{commands → src/commands}/list.js +6 -2
- package/dist/src/commands/list.js.map +1 -0
- package/dist/src/commands/login.d.ts +3 -0
- package/dist/src/commands/login.d.ts.map +1 -0
- package/dist/src/commands/login.js +120 -0
- package/dist/src/commands/login.js.map +1 -0
- package/dist/src/commands/logs.d.ts.map +1 -0
- package/dist/src/commands/logs.js +88 -0
- package/dist/src/commands/logs.js.map +1 -0
- package/dist/src/commands/scale.d.ts.map +1 -0
- package/dist/{commands → src/commands}/scale.js +7 -3
- package/dist/src/commands/scale.js.map +1 -0
- package/dist/src/commands/status.d.ts.map +1 -0
- package/dist/{commands → src/commands}/status.js +7 -2
- package/dist/src/commands/status.js.map +1 -0
- package/dist/src/commands/whoami.d.ts.map +1 -0
- package/dist/{commands → src/commands}/whoami.js +20 -7
- package/dist/src/commands/whoami.js.map +1 -0
- package/dist/{index.d.ts.map → src/index.d.ts.map} +1 -1
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +34 -0
- package/dist/src/lib/api-client.d.ts.map +1 -0
- package/dist/src/lib/api-client.js +141 -0
- package/dist/src/lib/api-client.js.map +1 -0
- package/dist/{lib → src/lib}/archive.d.ts +2 -1
- package/dist/src/lib/archive.d.ts.map +1 -0
- package/dist/{lib → src/lib}/archive.js +27 -5
- package/dist/src/lib/archive.js.map +1 -0
- package/dist/src/lib/config-updater.d.ts +10 -0
- package/dist/src/lib/config-updater.d.ts.map +1 -0
- package/dist/src/lib/config-updater.js +34 -0
- package/dist/src/lib/config-updater.js.map +1 -0
- package/dist/src/lib/config.d.ts +53 -0
- package/dist/src/lib/config.d.ts.map +1 -0
- package/dist/src/lib/config.js +162 -0
- package/dist/src/lib/config.js.map +1 -0
- package/dist/src/lib/env-sync.d.ts +44 -0
- package/dist/src/lib/env-sync.d.ts.map +1 -0
- package/dist/src/lib/env-sync.js +207 -0
- package/dist/src/lib/env-sync.js.map +1 -0
- package/dist/src/lib/logger.d.ts.map +1 -0
- package/dist/src/lib/logger.js.map +1 -0
- package/dist/src/lib/nx-generator.d.ts +22 -0
- package/dist/src/lib/nx-generator.d.ts.map +1 -0
- package/dist/src/lib/nx-generator.js +345 -0
- package/dist/src/lib/nx-generator.js.map +1 -0
- package/dist/src/lib/standalone.d.ts +28 -0
- package/dist/src/lib/standalone.d.ts.map +1 -0
- package/dist/src/lib/standalone.js +107 -0
- package/dist/src/lib/standalone.js.map +1 -0
- package/dist/{types → src/types}/index.d.ts +10 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/spinner.d.ts +16 -0
- package/dist/src/utils/spinner.d.ts.map +1 -0
- package/dist/src/utils/spinner.js +88 -0
- package/dist/src/utils/spinner.js.map +1 -0
- package/dist/src/utils/validation.d.ts.map +1 -0
- package/dist/{utils → src/utils}/validation.js +18 -2
- package/dist/src/utils/validation.js.map +1 -0
- package/dist/templates/application-additions/.forgecartignore +1 -1
- package/dist/templates/application-additions/Procfile +1 -1
- package/dist/templates/application-additions/src/app/app.module.ts +16 -0
- package/dist/templates/application-additions/src/services/forgecart.service.ts +62 -0
- package/dist/templates/application-additions/src/services/index.ts +2 -0
- package/dist/templates/application-additions/src/services/product-event-listener.service.ts +150 -0
- package/dist/templates/application-e2e-additions/src/support/global-setup.ts +16 -0
- package/dist/templates/application-e2e-additions/src/support/test-setup.ts +9 -0
- package/dist/templates/storefront-additions/.forgecartignore +30 -6
- package/dist/templates/storefront-additions/Procfile +1 -1
- package/dist/templates/storefront-additions/package.json +11 -0
- package/dist/templates/storefront-additions/postcss.config.js +5 -0
- package/dist/templates/storefront-additions/src/app/cart/page.tsx +77 -0
- package/dist/templates/storefront-additions/src/app/global.css +1 -0
- package/dist/templates/storefront-additions/src/app/layout.tsx +25 -0
- package/dist/templates/storefront-additions/src/app/page.tsx +43 -0
- package/dist/templates/storefront-additions/src/components/AddToCartButton.tsx +29 -0
- package/dist/templates/storefront-additions/src/components/CartItem.tsx +82 -0
- package/dist/templates/storefront-additions/src/components/Header.tsx +42 -0
- package/dist/templates/storefront-additions/src/components/ProductCard.tsx +57 -0
- package/dist/templates/storefront-additions/src/components/QuantitySelector.tsx +35 -0
- package/dist/templates/storefront-additions/src/context/CartContext.tsx +158 -0
- package/dist/templates/storefront-additions/src/lib/forgecart.ts +19 -8
- package/dist/templates/storefront-additions/tailwind.config.js +8 -0
- package/dist/templates/storefront-e2e-additions/playwright.config.ts +26 -0
- package/dist/templates/storefront-e2e-additions/src/example.spec.ts +11 -0
- package/dist/templates/workspace/.nxignore +2 -0
- package/package.json +6 -28
- package/templates/application-additions/.forgecartignore +1 -1
- package/templates/application-additions/Procfile +1 -1
- package/templates/application-additions/src/app/app.module.ts +16 -0
- package/templates/application-additions/src/services/forgecart.service.ts +62 -0
- package/templates/application-additions/src/services/index.ts +2 -0
- package/templates/application-additions/src/services/product-event-listener.service.ts +150 -0
- package/templates/application-e2e-additions/src/support/global-setup.ts +16 -0
- package/templates/application-e2e-additions/src/support/test-setup.ts +9 -0
- package/templates/storefront-additions/.forgecartignore +30 -6
- package/templates/storefront-additions/Procfile +1 -1
- package/templates/storefront-additions/package.json +11 -0
- package/templates/storefront-additions/postcss.config.js +5 -0
- package/templates/storefront-additions/src/app/cart/page.tsx +77 -0
- package/templates/storefront-additions/src/app/global.css +1 -0
- package/templates/storefront-additions/src/app/layout.tsx +25 -0
- package/templates/storefront-additions/src/app/page.tsx +43 -0
- package/templates/storefront-additions/src/components/AddToCartButton.tsx +29 -0
- package/templates/storefront-additions/src/components/CartItem.tsx +82 -0
- package/templates/storefront-additions/src/components/Header.tsx +42 -0
- package/templates/storefront-additions/src/components/ProductCard.tsx +57 -0
- package/templates/storefront-additions/src/components/QuantitySelector.tsx +35 -0
- package/templates/storefront-additions/src/context/CartContext.tsx +158 -0
- package/templates/storefront-additions/src/lib/forgecart.ts +19 -8
- package/templates/storefront-additions/tailwind.config.js +8 -0
- package/templates/storefront-e2e-additions/playwright.config.ts +26 -0
- package/templates/storefront-e2e-additions/src/example.spec.ts +11 -0
- package/templates/workspace/.nxignore +2 -0
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/delete.d.ts.map +0 -1
- package/dist/commands/delete.js.map +0 -1
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js +0 -128
- package/dist/commands/deploy.js.map +0 -1
- package/dist/commands/env.d.ts.map +0 -1
- package/dist/commands/env.js.map +0 -1
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/list.d.ts.map +0 -1
- package/dist/commands/list.js.map +0 -1
- package/dist/commands/logs.d.ts.map +0 -1
- package/dist/commands/logs.js +0 -105
- package/dist/commands/logs.js.map +0 -1
- package/dist/commands/scale.d.ts.map +0 -1
- package/dist/commands/scale.js.map +0 -1
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/whoami.d.ts.map +0 -1
- package/dist/commands/whoami.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/api-client.d.ts +0 -21
- package/dist/lib/api-client.d.ts.map +0 -1
- package/dist/lib/api-client.js +0 -220
- package/dist/lib/api-client.js.map +0 -1
- package/dist/lib/archive.d.ts.map +0 -1
- package/dist/lib/archive.js.map +0 -1
- package/dist/lib/config.d.ts +0 -12
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -79
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/logger.d.ts.map +0 -1
- package/dist/lib/logger.js.map +0 -1
- package/dist/lib/nx-generator.d.ts +0 -8
- package/dist/lib/nx-generator.d.ts.map +0 -1
- package/dist/lib/nx-generator.js +0 -146
- package/dist/lib/nx-generator.js.map +0 -1
- package/dist/templates/application-additions/src/services/price-fetcher.service.ts +0 -72
- package/dist/templates/storefront-additions/src/app/products/page.tsx +0 -78
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/utils/spinner.d.ts +0 -4
- package/dist/utils/spinner.d.ts.map +0 -1
- package/dist/utils/spinner.js +0 -20
- package/dist/utils/spinner.js.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js.map +0 -1
- package/templates/application-additions/src/services/price-fetcher.service.ts +0 -72
- package/templates/storefront-additions/src/app/products/page.tsx +0 -78
- /package/dist/{cli.d.ts → src/cli.d.ts} +0 -0
- /package/dist/{commands → src/commands}/delete.d.ts +0 -0
- /package/dist/{commands → src/commands}/deploy.d.ts +0 -0
- /package/dist/{commands → src/commands}/env.d.ts +0 -0
- /package/dist/{commands → src/commands}/init.d.ts +0 -0
- /package/dist/{commands → src/commands}/list.d.ts +0 -0
- /package/dist/{commands → src/commands}/logs.d.ts +0 -0
- /package/dist/{commands → src/commands}/scale.d.ts +0 -0
- /package/dist/{commands → src/commands}/status.d.ts +0 -0
- /package/dist/{commands → src/commands}/whoami.d.ts +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{index.js → src/index.js} +0 -0
- /package/dist/{lib → src/lib}/logger.d.ts +0 -0
- /package/dist/{lib → src/lib}/logger.js +0 -0
- /package/dist/{types → src/types}/index.js +0 -0
- /package/dist/{utils → src/utils}/validation.d.ts +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig, devices } from '@playwright/test'
|
|
2
|
+
import { nxE2EPreset } from '@nx/playwright/preset'
|
|
3
|
+
|
|
4
|
+
import { workspaceRoot } from '@nx/devkit'
|
|
5
|
+
|
|
6
|
+
const baseURL = process.env['BASE_URL'] || 'http://localhost:4200'
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
...nxE2EPreset(__filename, { testDir: './src' }),
|
|
10
|
+
use: {
|
|
11
|
+
baseURL,
|
|
12
|
+
trace: 'on-first-retry',
|
|
13
|
+
},
|
|
14
|
+
webServer: {
|
|
15
|
+
command: 'npx nx run storefront:dev',
|
|
16
|
+
url: 'http://localhost:4200',
|
|
17
|
+
reuseExistingServer: !process.env.CI,
|
|
18
|
+
cwd: workspaceRoot,
|
|
19
|
+
},
|
|
20
|
+
projects: [
|
|
21
|
+
{
|
|
22
|
+
name: 'chromium',
|
|
23
|
+
use: { ...devices['Desktop Chrome'] },
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test'
|
|
2
|
+
|
|
3
|
+
test('has title', async ({ page }) => {
|
|
4
|
+
await page.goto('/')
|
|
5
|
+
expect(await page.locator('h1').innerText()).toContain('Our Products')
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
test('has cart link', async ({ page }) => {
|
|
9
|
+
await page.goto('/')
|
|
10
|
+
await expect(page.locator('a[href="/cart"]')).toBeVisible()
|
|
11
|
+
})
|
package/package.json
CHANGED
|
@@ -1,42 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgecart/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "CLI tool for deploying applications to
|
|
5
|
+
"description": "CLI tool for deploying applications to ForgeCart",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"forgecart": "./bin/forgecart.js"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"dev": "ts-node --esm src/index.ts",
|
|
13
|
-
"prepublishOnly": "npm run build"
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@forgecart/sdk": "1.2.5"
|
|
14
12
|
},
|
|
15
13
|
"files": [
|
|
16
14
|
"dist",
|
|
17
15
|
"bin",
|
|
18
16
|
"templates"
|
|
19
17
|
],
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"archiver": "^7.0.1",
|
|
22
|
-
"chalk": "^5.3.0",
|
|
23
|
-
"cli-table3": "^0.6.5",
|
|
24
|
-
"commander": "^12.1.0",
|
|
25
|
-
"form-data": "^4.0.0",
|
|
26
|
-
"graphql": "^16.8.1",
|
|
27
|
-
"graphql-request": "^6.1.0",
|
|
28
|
-
"inquirer": "^9.2.23",
|
|
29
|
-
"node-fetch": "^3.3.2",
|
|
30
|
-
"ora": "^8.0.1",
|
|
31
|
-
"ws": "^8.17.1"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@types/archiver": "^6.0.2",
|
|
35
|
-
"@types/inquirer": "^9.0.7",
|
|
36
|
-
"@types/node": "^20.11.5",
|
|
37
|
-
"@types/ws": "^8.5.10",
|
|
38
|
-
"typescript": "^5.9.3"
|
|
39
|
-
},
|
|
40
18
|
"engines": {
|
|
41
19
|
"node": ">=18.0.0"
|
|
42
20
|
},
|
|
@@ -47,6 +25,6 @@
|
|
|
47
25
|
"paas",
|
|
48
26
|
"nodejs"
|
|
49
27
|
],
|
|
50
|
-
"author": "
|
|
28
|
+
"author": "ForgeCart",
|
|
51
29
|
"license": "MIT"
|
|
52
|
-
}
|
|
30
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
web:
|
|
1
|
+
web: node main.js
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common'
|
|
2
|
+
import { ConfigModule } from '@nestjs/config'
|
|
3
|
+
import { AppController } from './app.controller'
|
|
4
|
+
import { AppService } from './app.service'
|
|
5
|
+
import { ForgeCartService, ProductEventListenerService } from '../services'
|
|
6
|
+
|
|
7
|
+
@Module({
|
|
8
|
+
imports: [
|
|
9
|
+
ConfigModule.forRoot({
|
|
10
|
+
isGlobal: true,
|
|
11
|
+
}),
|
|
12
|
+
],
|
|
13
|
+
controllers: [AppController],
|
|
14
|
+
providers: [AppService, ForgeCartService, ProductEventListenerService],
|
|
15
|
+
})
|
|
16
|
+
export class AppModule {}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'
|
|
2
|
+
import { ConfigService } from '@nestjs/config'
|
|
3
|
+
import { ForgeCartSDK } from '@forgecart/sdk'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ForgeCart SDK Service
|
|
7
|
+
*
|
|
8
|
+
* Singleton service that manages the ForgeCart SDK instance.
|
|
9
|
+
* The SDK is initialized once on module init to maintain
|
|
10
|
+
* persistent socket connections for real-time features.
|
|
11
|
+
*/
|
|
12
|
+
@Injectable()
|
|
13
|
+
export class ForgeCartService implements OnModuleInit, OnModuleDestroy {
|
|
14
|
+
private sdk: ForgeCartSDK | null = null
|
|
15
|
+
|
|
16
|
+
constructor(private configService: ConfigService) {}
|
|
17
|
+
|
|
18
|
+
onModuleInit(): void {
|
|
19
|
+
const endpoint = this.configService.get<string>('FORGECART_API_URL')
|
|
20
|
+
const token = this.configService.get<string>('FORGECART_CHANNEL_TOKEN')
|
|
21
|
+
|
|
22
|
+
if (!token) {
|
|
23
|
+
throw new Error('FORGECART_CHANNEL_TOKEN environment variable is required')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.sdk = new ForgeCartSDK({
|
|
27
|
+
endpoint: endpoint || 'http://localhost:3000',
|
|
28
|
+
token,
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onModuleDestroy(): void {
|
|
33
|
+
if (this.sdk) {
|
|
34
|
+
this.sdk.dispose()
|
|
35
|
+
}
|
|
36
|
+
this.sdk = null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the ForgeCart SDK instance
|
|
41
|
+
*/
|
|
42
|
+
getSDK(): ForgeCartSDK {
|
|
43
|
+
if (!this.sdk) {
|
|
44
|
+
throw new Error('ForgeCart SDK not initialized')
|
|
45
|
+
}
|
|
46
|
+
return this.sdk
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Access Shop API operations
|
|
51
|
+
*/
|
|
52
|
+
get shop() {
|
|
53
|
+
return this.getSDK().shop
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Access Admin API operations (requires admin token)
|
|
58
|
+
*/
|
|
59
|
+
get admin() {
|
|
60
|
+
return this.getSDK().admin
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Injectable,
|
|
3
|
+
OnModuleInit,
|
|
4
|
+
OnModuleDestroy,
|
|
5
|
+
Logger,
|
|
6
|
+
} from '@nestjs/common'
|
|
7
|
+
import { ConfigService } from '@nestjs/config'
|
|
8
|
+
import { ForgeCartService } from './forgecart.service'
|
|
9
|
+
|
|
10
|
+
interface EventSubscription {
|
|
11
|
+
unsubscribe: () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Injectable()
|
|
15
|
+
export class ProductEventListenerService
|
|
16
|
+
implements OnModuleInit, OnModuleDestroy
|
|
17
|
+
{
|
|
18
|
+
private readonly logger = new Logger(ProductEventListenerService.name)
|
|
19
|
+
private subscriptions: EventSubscription[] = []
|
|
20
|
+
private isAuthenticated = false
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly forgeCart: ForgeCartService,
|
|
24
|
+
private readonly configService: ConfigService
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
async onModuleInit(): Promise<void> {
|
|
28
|
+
await this.initialize()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
onModuleDestroy(): void {
|
|
32
|
+
this.cleanup()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private async initialize(): Promise<void> {
|
|
36
|
+
const username = this.configService.get<string>('FORGECART_ADMIN_USERNAME')
|
|
37
|
+
const password = this.configService.get<string>('FORGECART_ADMIN_PASSWORD')
|
|
38
|
+
|
|
39
|
+
// Skip if credentials are not provided
|
|
40
|
+
if (!username || !password) {
|
|
41
|
+
this.logger.warn(
|
|
42
|
+
'FORGECART_ADMIN_USERNAME and FORGECART_ADMIN_PASSWORD not set. ' +
|
|
43
|
+
'Product event listeners will not be registered.'
|
|
44
|
+
)
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// Login with admin credentials
|
|
50
|
+
const loginResult = await this.forgeCart.admin.administrator.login({
|
|
51
|
+
username,
|
|
52
|
+
password,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const login = (
|
|
56
|
+
loginResult as { login?: { __typename?: string; message?: string } }
|
|
57
|
+
)?.login
|
|
58
|
+
if (login?.__typename !== 'CurrentUser') {
|
|
59
|
+
this.logger.error(
|
|
60
|
+
'Admin login failed:',
|
|
61
|
+
login?.message || 'Unknown error'
|
|
62
|
+
)
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.isAuthenticated = true
|
|
67
|
+
this.logger.log('Successfully authenticated as admin')
|
|
68
|
+
|
|
69
|
+
// Register event handlers
|
|
70
|
+
this.registerEventHandlers()
|
|
71
|
+
} catch (error) {
|
|
72
|
+
this.logger.error('Failed to initialize product event listener:', error)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private registerEventHandlers(): void {
|
|
77
|
+
if (!this.isAuthenticated) return
|
|
78
|
+
|
|
79
|
+
const sdk = this.forgeCart.getSDK()
|
|
80
|
+
|
|
81
|
+
// Non-blocking handlers
|
|
82
|
+
const productUpdatedSub = sdk.admin.registerEventHandler(
|
|
83
|
+
'product.updated',
|
|
84
|
+
(event) => {
|
|
85
|
+
this.logger.log(`Product updated: ${JSON.stringify(event)}`)
|
|
86
|
+
this.handleProductUpdated(event)
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
this.subscriptions.push(productUpdatedSub)
|
|
90
|
+
|
|
91
|
+
const productCreatedSub = sdk.admin.registerEventHandler(
|
|
92
|
+
'product.created',
|
|
93
|
+
(event) => {
|
|
94
|
+
this.logger.log(`Product created: ${JSON.stringify(event)}`)
|
|
95
|
+
this.handleProductCreated(event)
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
this.subscriptions.push(productCreatedSub)
|
|
99
|
+
|
|
100
|
+
const productDeletedSub = sdk.admin.registerEventHandler(
|
|
101
|
+
'product.deleted',
|
|
102
|
+
(event) => {
|
|
103
|
+
this.logger.log(`Product deleted: ${JSON.stringify(event)}`)
|
|
104
|
+
this.handleProductDeleted(event)
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
this.subscriptions.push(productDeletedSub)
|
|
108
|
+
|
|
109
|
+
// Blocking handler (must complete within 1000ms)
|
|
110
|
+
const variantUpdatedSub = sdk.admin.registerBlockingEventHandler(
|
|
111
|
+
'product.variant.updated',
|
|
112
|
+
async (event) => {
|
|
113
|
+
this.logger.log(
|
|
114
|
+
`Product variant updated (blocking): ${JSON.stringify(event)}`
|
|
115
|
+
)
|
|
116
|
+
await this.handleVariantUpdated(event)
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
this.subscriptions.push(variantUpdatedSub)
|
|
120
|
+
|
|
121
|
+
this.logger.log('Product event handlers registered successfully')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private handleProductUpdated(event: unknown): void {
|
|
125
|
+
// Implement custom logic here
|
|
126
|
+
this.logger.debug('handleProductUpdated called', event)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private handleProductCreated(event: unknown): void {
|
|
130
|
+
// Implement custom logic here
|
|
131
|
+
this.logger.debug('handleProductCreated called', event)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private handleProductDeleted(event: unknown): void {
|
|
135
|
+
// Implement custom logic here
|
|
136
|
+
this.logger.debug('handleProductDeleted called', event)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private async handleVariantUpdated(event: unknown): Promise<void> {
|
|
140
|
+
// Blocking handler - must complete within 1000ms
|
|
141
|
+
this.logger.debug('handleVariantUpdated called', event)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private cleanup(): void {
|
|
145
|
+
for (const subscription of this.subscriptions) {
|
|
146
|
+
subscription.unsubscribe()
|
|
147
|
+
}
|
|
148
|
+
this.subscriptions = []
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { waitForPortOpen } from '@nx/node/utils'
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
var __TEARDOWN_MESSAGE__: string
|
|
5
|
+
|
|
6
|
+
module.exports = async function () {
|
|
7
|
+
// Start services that the app needs to run (e.g. database, docker-compose, etc.).
|
|
8
|
+
console.log('\nSetting up...\n')
|
|
9
|
+
|
|
10
|
+
const host = process.env.HOST ?? 'localhost'
|
|
11
|
+
const port = process.env.PORT ? Number(process.env.PORT) : 8080 // Match application's default port
|
|
12
|
+
await waitForPortOpen(port, { host })
|
|
13
|
+
|
|
14
|
+
// Hint: Use `globalThis` to pass variables to global teardown.
|
|
15
|
+
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n'
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import axios from 'axios'
|
|
3
|
+
|
|
4
|
+
module.exports = async function () {
|
|
5
|
+
// Configure axios for tests to use.
|
|
6
|
+
const host = process.env.HOST ?? 'localhost'
|
|
7
|
+
const port = process.env.PORT ?? '8080' // Match application's default port
|
|
8
|
+
axios.defaults.baseURL = `http://${host}:${port}`
|
|
9
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ForgeCart deployment ignore file
|
|
2
2
|
# Files and directories listed here will not be uploaded during deployment
|
|
3
3
|
|
|
4
|
-
# Dependencies (
|
|
5
|
-
node_modules/
|
|
4
|
+
# Dependencies - only exclude root node_modules (standalone has its own)
|
|
5
|
+
/node_modules/
|
|
6
6
|
|
|
7
7
|
# Development files
|
|
8
8
|
.git/
|
|
@@ -18,9 +18,17 @@ node_modules/
|
|
|
18
18
|
*.swp
|
|
19
19
|
*.swo
|
|
20
20
|
|
|
21
|
-
# Build artifacts (
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
# Build artifacts - exclude root level only (standalone has nested .next that must be kept)
|
|
22
|
+
/.next/cache/
|
|
23
|
+
/.next/server/
|
|
24
|
+
/.next/types/
|
|
25
|
+
/.next/trace
|
|
26
|
+
/.next/trace-build
|
|
27
|
+
/.next/dev/
|
|
28
|
+
/.next/build/
|
|
29
|
+
/.next/diagnostics/
|
|
30
|
+
# Keep .next/standalone/ and everything inside it
|
|
31
|
+
/out/
|
|
24
32
|
|
|
25
33
|
# Test files
|
|
26
34
|
__tests__/
|
|
@@ -29,6 +37,22 @@ __tests__/
|
|
|
29
37
|
*.spec.ts
|
|
30
38
|
*.spec.tsx
|
|
31
39
|
coverage/
|
|
40
|
+
specs/
|
|
41
|
+
|
|
42
|
+
# Source files - not needed for runtime
|
|
43
|
+
src/
|
|
44
|
+
|
|
45
|
+
# Config files not needed at runtime
|
|
46
|
+
tsconfig.json
|
|
47
|
+
tsconfig.spec.json
|
|
48
|
+
project.json
|
|
49
|
+
jest.config.cts
|
|
50
|
+
eslint.config.mjs
|
|
51
|
+
postcss.config.js
|
|
52
|
+
tailwind.config.js
|
|
53
|
+
.swcrc
|
|
54
|
+
index.d.ts
|
|
55
|
+
next-env.d.ts
|
|
32
56
|
|
|
33
57
|
# Documentation
|
|
34
58
|
README.md
|
|
@@ -1 +1 @@
|
|
|
1
|
-
web:
|
|
1
|
+
web: node .next/standalone/apps/storefront/server.js
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import Link from 'next/link'
|
|
4
|
+
import { useCart } from '../../context/CartContext'
|
|
5
|
+
import { CartItem } from '../../components/CartItem'
|
|
6
|
+
|
|
7
|
+
export default function CartPage() {
|
|
8
|
+
const { cart, loading, itemCount } = useCart()
|
|
9
|
+
|
|
10
|
+
if (loading && !cart) {
|
|
11
|
+
return (
|
|
12
|
+
<div className="max-w-4xl mx-auto px-4 py-8">
|
|
13
|
+
<h1 className="text-3xl font-bold mb-8 text-gray-900">Your Cart</h1>
|
|
14
|
+
<p className="text-gray-600">Loading cart...</p>
|
|
15
|
+
</div>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!cart || cart.lines.length === 0) {
|
|
20
|
+
return (
|
|
21
|
+
<div className="max-w-4xl mx-auto px-4 py-8">
|
|
22
|
+
<h1 className="text-3xl font-bold mb-8 text-gray-900">Your Cart</h1>
|
|
23
|
+
<p className="text-gray-600 mb-4">Your cart is empty.</p>
|
|
24
|
+
<Link
|
|
25
|
+
href="/"
|
|
26
|
+
className="inline-block bg-blue-600 text-white py-2 px-4 rounded-lg hover:bg-blue-700"
|
|
27
|
+
>
|
|
28
|
+
Continue Shopping
|
|
29
|
+
</Link>
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const subtotal = (cart.subTotalWithTax / 100).toFixed(2)
|
|
35
|
+
const total = (cart.totalWithTax / 100).toFixed(2)
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className="max-w-4xl mx-auto px-4 py-8">
|
|
39
|
+
<h1 className="text-3xl font-bold mb-8 text-gray-900">Your Cart</h1>
|
|
40
|
+
|
|
41
|
+
<div className="bg-white rounded-lg shadow p-6">
|
|
42
|
+
{cart.lines
|
|
43
|
+
.filter((line) => line.productVariant)
|
|
44
|
+
.map((line) => (
|
|
45
|
+
<CartItem key={line.id} line={line as never} />
|
|
46
|
+
))}
|
|
47
|
+
|
|
48
|
+
<div className="mt-6 pt-4 border-t">
|
|
49
|
+
<div className="flex justify-between text-lg mb-2">
|
|
50
|
+
<span className="text-gray-600">Subtotal ({itemCount} items)</span>
|
|
51
|
+
<span className="font-semibold">
|
|
52
|
+
{subtotal} {cart.currencyCode}
|
|
53
|
+
</span>
|
|
54
|
+
</div>
|
|
55
|
+
<div className="flex justify-between text-xl font-bold">
|
|
56
|
+
<span>Total</span>
|
|
57
|
+
<span>
|
|
58
|
+
{total} {cart.currencyCode}
|
|
59
|
+
</span>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div className="mt-6 flex gap-4">
|
|
64
|
+
<Link
|
|
65
|
+
href="/"
|
|
66
|
+
className="flex-1 text-center border border-gray-300 py-3 rounded-lg hover:bg-gray-50"
|
|
67
|
+
>
|
|
68
|
+
Continue Shopping
|
|
69
|
+
</Link>
|
|
70
|
+
<button className="flex-1 bg-blue-600 text-white py-3 rounded-lg hover:bg-blue-700">
|
|
71
|
+
Checkout
|
|
72
|
+
</button>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import './global.css'
|
|
2
|
+
import { CartProvider } from '../context/CartContext'
|
|
3
|
+
import { Header } from '../components/Header'
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
title: 'Store',
|
|
7
|
+
description: 'Your ecommerce store',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function RootLayout({
|
|
11
|
+
children,
|
|
12
|
+
}: {
|
|
13
|
+
children: React.ReactNode
|
|
14
|
+
}) {
|
|
15
|
+
return (
|
|
16
|
+
<html lang="en">
|
|
17
|
+
<body className="bg-gray-50 min-h-screen">
|
|
18
|
+
<CartProvider>
|
|
19
|
+
<Header />
|
|
20
|
+
<main>{children}</main>
|
|
21
|
+
</CartProvider>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ProductList, Product } from '@forgecart/sdk/shop'
|
|
2
|
+
import forgecart from '../lib/forgecart'
|
|
3
|
+
import { ProductCard } from '../components/ProductCard'
|
|
4
|
+
|
|
5
|
+
async function getProducts(): Promise<ProductList> {
|
|
6
|
+
try {
|
|
7
|
+
const result = await forgecart.shop.products.products({
|
|
8
|
+
options: {
|
|
9
|
+
take: 20,
|
|
10
|
+
},
|
|
11
|
+
})
|
|
12
|
+
return (result.products as ProductList) || { items: [], totalItems: 0 }
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error('Failed to fetch products:', error)
|
|
15
|
+
return {
|
|
16
|
+
items: [] as Product[],
|
|
17
|
+
totalItems: 0,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default async function HomePage() {
|
|
23
|
+
const products = await getProducts()
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className="max-w-7xl mx-auto px-4 py-8">
|
|
27
|
+
<h1 className="text-3xl font-bold mb-8 text-gray-900">Our Products</h1>
|
|
28
|
+
|
|
29
|
+
{products.items.length === 0 ? (
|
|
30
|
+
<p className="text-gray-600">
|
|
31
|
+
No products found. Make sure your ForgeCart channel is configured
|
|
32
|
+
correctly.
|
|
33
|
+
</p>
|
|
34
|
+
) : (
|
|
35
|
+
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
|
36
|
+
{products.items.map((product: Product) => (
|
|
37
|
+
<ProductCard key={product.id} product={product as never} />
|
|
38
|
+
))}
|
|
39
|
+
</div>
|
|
40
|
+
)}
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react'
|
|
4
|
+
import { useCart } from '../context/CartContext'
|
|
5
|
+
|
|
6
|
+
interface AddToCartButtonProps {
|
|
7
|
+
productVariantId: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AddToCartButton({ productVariantId }: AddToCartButtonProps) {
|
|
11
|
+
const { addToCart } = useCart()
|
|
12
|
+
const [isAdding, setIsAdding] = useState(false)
|
|
13
|
+
|
|
14
|
+
const handleClick = async () => {
|
|
15
|
+
setIsAdding(true)
|
|
16
|
+
await addToCart(productVariantId, 1)
|
|
17
|
+
setIsAdding(false)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<button
|
|
22
|
+
onClick={handleClick}
|
|
23
|
+
disabled={isAdding}
|
|
24
|
+
className="w-full bg-blue-600 text-white py-2 px-4 rounded-lg hover:bg-blue-700 disabled:bg-blue-300 disabled:cursor-not-allowed transition-colors"
|
|
25
|
+
>
|
|
26
|
+
{isAdding ? 'Adding...' : 'Add to Cart'}
|
|
27
|
+
</button>
|
|
28
|
+
)
|
|
29
|
+
}
|