@forgecart/cli 1.0.1 → 2.0.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.
Files changed (155) hide show
  1. package/dist/bin/forgecart.d.ts +2 -0
  2. package/dist/bin/forgecart.js +4 -0
  3. package/dist/bin/forgecart.js.map +1 -0
  4. package/dist/src/cli.d.ts +14 -1
  5. package/dist/src/cli.js +30 -15
  6. package/dist/src/cli.js.map +1 -1
  7. package/dist/src/commands/init.d.ts +20 -2
  8. package/dist/src/commands/init.js +88 -255
  9. package/dist/src/commands/init.js.map +1 -1
  10. package/dist/src/commands/placeholders.d.ts +19 -0
  11. package/dist/src/commands/placeholders.js +109 -0
  12. package/dist/src/commands/placeholders.js.map +1 -0
  13. package/dist/src/output.d.ts +11 -0
  14. package/dist/src/output.js +16 -0
  15. package/dist/src/output.js.map +1 -0
  16. package/package.json +21 -11
  17. package/templates/storefront/.env.example +12 -0
  18. package/templates/storefront/.forgecartignore +2 -0
  19. package/templates/storefront/Procfile +1 -0
  20. package/templates/storefront/README.md +87 -0
  21. package/templates/storefront/next.config.js +14 -0
  22. package/templates/storefront/package.json +25 -0
  23. package/templates/storefront/postcss.config.js +6 -0
  24. package/templates/storefront/src/app/cart/page.tsx +110 -0
  25. package/templates/storefront/src/app/globals.css +13 -0
  26. package/templates/storefront/src/app/layout.tsx +30 -0
  27. package/templates/storefront/src/app/page.tsx +49 -0
  28. package/templates/storefront/src/app/products/[slug]/not-found.tsx +20 -0
  29. package/templates/storefront/src/app/products/[slug]/page.tsx +96 -0
  30. package/templates/storefront/src/app/products/page.tsx +27 -0
  31. package/templates/storefront/src/components/AddToCartButton.tsx +30 -0
  32. package/templates/storefront/src/components/Header.tsx +36 -0
  33. package/templates/storefront/src/components/ProductCard.tsx +43 -0
  34. package/templates/storefront/src/lib/cart-context.tsx +116 -0
  35. package/templates/storefront/src/lib/forgecart.ts +202 -0
  36. package/templates/storefront/tailwind.config.js +8 -0
  37. package/templates/storefront/tsconfig.json +23 -0
  38. package/LICENSE +0 -21
  39. package/README.md +0 -179
  40. package/bin/forgecart.js +0 -3
  41. package/dist/package.json +0 -49
  42. package/dist/src/cli.d.ts.map +0 -1
  43. package/dist/src/commands/delete.d.ts +0 -3
  44. package/dist/src/commands/delete.d.ts.map +0 -1
  45. package/dist/src/commands/delete.js +0 -58
  46. package/dist/src/commands/delete.js.map +0 -1
  47. package/dist/src/commands/deploy.d.ts +0 -3
  48. package/dist/src/commands/deploy.d.ts.map +0 -1
  49. package/dist/src/commands/deploy.js +0 -235
  50. package/dist/src/commands/deploy.js.map +0 -1
  51. package/dist/src/commands/env.d.ts +0 -3
  52. package/dist/src/commands/env.d.ts.map +0 -1
  53. package/dist/src/commands/env.js +0 -151
  54. package/dist/src/commands/env.js.map +0 -1
  55. package/dist/src/commands/init.d.ts.map +0 -1
  56. package/dist/src/commands/list.d.ts +0 -3
  57. package/dist/src/commands/list.d.ts.map +0 -1
  58. package/dist/src/commands/list.js +0 -63
  59. package/dist/src/commands/list.js.map +0 -1
  60. package/dist/src/commands/login.d.ts +0 -3
  61. package/dist/src/commands/login.d.ts.map +0 -1
  62. package/dist/src/commands/login.js +0 -120
  63. package/dist/src/commands/login.js.map +0 -1
  64. package/dist/src/commands/logs.d.ts +0 -3
  65. package/dist/src/commands/logs.d.ts.map +0 -1
  66. package/dist/src/commands/logs.js +0 -88
  67. package/dist/src/commands/logs.js.map +0 -1
  68. package/dist/src/commands/scale.d.ts +0 -3
  69. package/dist/src/commands/scale.d.ts.map +0 -1
  70. package/dist/src/commands/scale.js +0 -48
  71. package/dist/src/commands/scale.js.map +0 -1
  72. package/dist/src/commands/status.d.ts +0 -3
  73. package/dist/src/commands/status.d.ts.map +0 -1
  74. package/dist/src/commands/status.js +0 -87
  75. package/dist/src/commands/status.js.map +0 -1
  76. package/dist/src/commands/whoami.d.ts +0 -3
  77. package/dist/src/commands/whoami.d.ts.map +0 -1
  78. package/dist/src/commands/whoami.js +0 -57
  79. package/dist/src/commands/whoami.js.map +0 -1
  80. package/dist/src/index.d.ts +0 -3
  81. package/dist/src/index.d.ts.map +0 -1
  82. package/dist/src/index.js +0 -5
  83. package/dist/src/index.js.map +0 -1
  84. package/dist/src/lib/api-client.d.ts +0 -28
  85. package/dist/src/lib/api-client.d.ts.map +0 -1
  86. package/dist/src/lib/api-client.js +0 -137
  87. package/dist/src/lib/api-client.js.map +0 -1
  88. package/dist/src/lib/archive.d.ts +0 -9
  89. package/dist/src/lib/archive.d.ts.map +0 -1
  90. package/dist/src/lib/archive.js +0 -118
  91. package/dist/src/lib/archive.js.map +0 -1
  92. package/dist/src/lib/config-updater.d.ts +0 -10
  93. package/dist/src/lib/config-updater.d.ts.map +0 -1
  94. package/dist/src/lib/config-updater.js +0 -34
  95. package/dist/src/lib/config-updater.js.map +0 -1
  96. package/dist/src/lib/config.d.ts +0 -53
  97. package/dist/src/lib/config.d.ts.map +0 -1
  98. package/dist/src/lib/config.js +0 -162
  99. package/dist/src/lib/config.js.map +0 -1
  100. package/dist/src/lib/env-sync.d.ts +0 -36
  101. package/dist/src/lib/env-sync.d.ts.map +0 -1
  102. package/dist/src/lib/env-sync.js +0 -118
  103. package/dist/src/lib/env-sync.js.map +0 -1
  104. package/dist/src/lib/logger.d.ts +0 -15
  105. package/dist/src/lib/logger.d.ts.map +0 -1
  106. package/dist/src/lib/logger.js +0 -54
  107. package/dist/src/lib/logger.js.map +0 -1
  108. package/dist/src/lib/nx-generator.d.ts +0 -20
  109. package/dist/src/lib/nx-generator.d.ts.map +0 -1
  110. package/dist/src/lib/nx-generator.js +0 -338
  111. package/dist/src/lib/nx-generator.js.map +0 -1
  112. package/dist/src/lib/standalone.d.ts +0 -28
  113. package/dist/src/lib/standalone.d.ts.map +0 -1
  114. package/dist/src/lib/standalone.js +0 -107
  115. package/dist/src/lib/standalone.js.map +0 -1
  116. package/dist/src/types/index.d.ts +0 -80
  117. package/dist/src/types/index.d.ts.map +0 -1
  118. package/dist/src/types/index.js +0 -14
  119. package/dist/src/types/index.js.map +0 -1
  120. package/dist/src/utils/spinner.d.ts +0 -4
  121. package/dist/src/utils/spinner.d.ts.map +0 -1
  122. package/dist/src/utils/spinner.js +0 -20
  123. package/dist/src/utils/spinner.js.map +0 -1
  124. package/dist/src/utils/validation.d.ts +0 -12
  125. package/dist/src/utils/validation.d.ts.map +0 -1
  126. package/dist/src/utils/validation.js +0 -82
  127. package/dist/src/utils/validation.js.map +0 -1
  128. package/dist/templates/application-additions/.forgecartignore +0 -37
  129. package/dist/templates/application-additions/Procfile +0 -1
  130. package/dist/templates/application-additions/env.example +0 -7
  131. package/dist/templates/application-additions/src/app/app.module.ts +0 -16
  132. package/dist/templates/application-additions/src/services/forgecart.service.ts +0 -62
  133. package/dist/templates/application-additions/src/services/index.ts +0 -2
  134. package/dist/templates/application-additions/src/services/price-fetcher.service.ts +0 -71
  135. package/dist/templates/storefront-additions/.forgecartignore +0 -64
  136. package/dist/templates/storefront-additions/Procfile +0 -1
  137. package/dist/templates/storefront-additions/env.example +0 -3
  138. package/dist/templates/storefront-additions/package.json +0 -11
  139. package/dist/templates/storefront-additions/src/app/products/page.tsx +0 -66
  140. package/dist/templates/storefront-additions/src/lib/forgecart.ts +0 -22
  141. package/dist/templates/workspace/.nxignore +0 -2
  142. package/templates/application-additions/.forgecartignore +0 -37
  143. package/templates/application-additions/Procfile +0 -1
  144. package/templates/application-additions/env.example +0 -7
  145. package/templates/application-additions/src/app/app.module.ts +0 -16
  146. package/templates/application-additions/src/services/forgecart.service.ts +0 -62
  147. package/templates/application-additions/src/services/index.ts +0 -2
  148. package/templates/application-additions/src/services/price-fetcher.service.ts +0 -71
  149. package/templates/storefront-additions/.forgecartignore +0 -64
  150. package/templates/storefront-additions/Procfile +0 -1
  151. package/templates/storefront-additions/env.example +0 -3
  152. package/templates/storefront-additions/package.json +0 -11
  153. package/templates/storefront-additions/src/app/products/page.tsx +0 -66
  154. package/templates/storefront-additions/src/lib/forgecart.ts +0 -22
  155. package/templates/workspace/.nxignore +0 -2
@@ -1,82 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { DeploymentType } from '../types/index.js';
4
- export function isValidProjectName(name) {
5
- // Must start with letter, can contain letters, numbers, hyphens
6
- return /^[a-z][a-z0-9-]*$/.test(name);
7
- }
8
- export function detectProjectType(dir) {
9
- // Check for Next.js project
10
- const nextConfig = path.join(dir, 'next.config.js');
11
- const nextConfigMjs = path.join(dir, 'next.config.mjs');
12
- if (fs.existsSync(nextConfig) || fs.existsSync(nextConfigMjs)) {
13
- return DeploymentType.STOREFRONT;
14
- }
15
- // Check for NestJS project
16
- const nestCliJson = path.join(dir, 'nest-cli.json');
17
- if (fs.existsSync(nestCliJson)) {
18
- return DeploymentType.APPLICATION;
19
- }
20
- // Check package.json for hints
21
- const packageJson = path.join(dir, 'package.json');
22
- if (fs.existsSync(packageJson)) {
23
- try {
24
- const pkg = JSON.parse(fs.readFileSync(packageJson, 'utf-8'));
25
- const deps = { ...pkg.dependencies, ...pkg.devDependencies };
26
- if (deps['next']) {
27
- return DeploymentType.STOREFRONT;
28
- }
29
- if (deps['@nestjs/core']) {
30
- return DeploymentType.APPLICATION;
31
- }
32
- }
33
- catch {
34
- // Ignore parse errors
35
- }
36
- }
37
- // Check for Nx monorepo NestJS project (no nest-cli.json or local package.json)
38
- // Look for src/main.ts with NestJS imports
39
- const mainTs = path.join(dir, 'src', 'main.ts');
40
- if (fs.existsSync(mainTs)) {
41
- try {
42
- const content = fs.readFileSync(mainTs, 'utf-8');
43
- if (content.includes('@nestjs/core') || content.includes('NestFactory')) {
44
- return DeploymentType.APPLICATION;
45
- }
46
- }
47
- catch {
48
- // Ignore read errors
49
- }
50
- }
51
- return null;
52
- }
53
- export function validateChannelToken(token) {
54
- // Basic validation - tokens should be non-empty strings
55
- return typeof token === 'string' && token.length > 0;
56
- }
57
- export function isNxWorkspace(dir) {
58
- return fs.existsSync(path.join(dir, 'nx.json'));
59
- }
60
- export function hasStorefront(projectRoot, storefrontPath) {
61
- const fullPath = path.join(projectRoot, storefrontPath);
62
- return (fs.existsSync(fullPath) &&
63
- detectProjectType(fullPath) === DeploymentType.STOREFRONT);
64
- }
65
- export function hasApplication(projectRoot, applicationPath) {
66
- const fullPath = path.join(projectRoot, applicationPath);
67
- return (fs.existsSync(fullPath) &&
68
- detectProjectType(fullPath) === DeploymentType.APPLICATION);
69
- }
70
- export function getCurrentAppDir(projectRoot) {
71
- const cwd = process.cwd();
72
- // Check if we're in apps/storefront
73
- if (cwd.includes(path.join(projectRoot, 'apps', 'storefront'))) {
74
- return { type: DeploymentType.STOREFRONT, path: cwd };
75
- }
76
- // Check if we're in apps/application
77
- if (cwd.includes(path.join(projectRoot, 'apps', 'application'))) {
78
- return { type: DeploymentType.APPLICATION, path: cwd };
79
- }
80
- return null;
81
- }
82
- //# sourceMappingURL=validation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,gEAAgE;IAChE,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,4BAA4B;IAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;IACnD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAA;IACvD,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAC9D,OAAO,cAAc,CAAC,UAAU,C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Ac,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;IACvD,CAAC;IAED,qCAAqC;IACrC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC;QAChE,OAAO,EAAE,IAAI,EAAE,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;IACxD,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -1,37 +0,0 @@
1
- # ForgeCart deployment ignore file
2
- # Files and directories listed here will not be uploaded during deployment
3
-
4
- # Dependencies (will be installed during build)
5
- node_modules/
6
-
7
- # Development files
8
- .git/
9
- .gitignore
10
- .env
11
- .env.local
12
- .env.development
13
-
14
- # IDE
15
- .idea/
16
- .vscode/
17
- *.swp
18
- *.swo
19
-
20
- # Build artifacts (we build on the server)
21
- dist/
22
-
23
- # Test files
24
- __tests__/
25
- test/
26
- *.test.ts
27
- *.spec.ts
28
- coverage/
29
-
30
- # Documentation
31
- README.md
32
- CHANGELOG.md
33
- docs/
34
-
35
- # OS files
36
- .DS_Store
37
- Thumbs.db
@@ -1 +0,0 @@
1
- web: node main.js
@@ -1,7 +0,0 @@
1
- # Server Configuration
2
- PORT=3030
3
- NODE_ENV=development
4
-
5
- # ForgeCart API Configuration
6
- FORGECART_API_URL=http://localhost:3000
7
- FORGECART_CHANNEL_TOKEN=your-channel-token-here
@@ -1,16 +0,0 @@
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, PriceFetcherService } from '../services';
6
-
7
- @Module({
8
- imports: [
9
- ConfigModule.forRoot({
10
- isGlobal: true,
11
- }),
12
- ],
13
- controllers: [AppController],
14
- providers: [AppService, ForgeCartService, PriceFetcherService],
15
- })
16
- export class AppModule {}
@@ -1,62 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export { ForgeCartService } from './forgecart.service'
2
- export { PriceFetcherService } from './price-fetcher.service'
@@ -1,71 +0,0 @@
1
- import { Injectable } from '@nestjs/common'
2
- import { ForgeCartService } from './forgecart.service'
3
-
4
- /**
5
- * Example service demonstrating ForgeCart SDK integration
6
- *
7
- * This can be used for custom backend tasks like:
8
- * - Scheduled price updates
9
- * - Inventory synchronization
10
- * - Custom order processing
11
- * - Third-party integrations
12
- */
13
- @Injectable()
14
- export class PriceFetcherService {
15
- constructor(private readonly forgeCart: ForgeCartService) {}
16
-
17
- async getProductPrices(productIds: string[]): Promise<
18
- Array<{
19
- productId: string
20
- name: string
21
- price: number
22
- }>
23
- > {
24
- const prices = []
25
-
26
- for (const productId of productIds) {
27
- try {
28
- const result = await this.forgeCart.shop.products.product({
29
- id: productId,
30
- })
31
- const product = result.product
32
- if (product && product.variants?.[0]) {
33
- prices.push({
34
- productId,
35
- name: product.name,
36
- price: product.variants[0].price,
37
- })
38
- }
39
- } catch (error) {
40
- console.error(`Failed to fetch price for product ${productId}:`, error)
41
- }
42
- }
43
-
44
- return prices
45
- }
46
-
47
- async syncInventory(): Promise<{ synced: number; errors: number }> {
48
- // Example: Sync inventory with external system
49
- // This is a placeholder for custom business logic
50
- let synced = 0
51
- let errors = 0
52
-
53
- try {
54
- const result = await this.forgeCart.shop.products.products({
55
- options: { take: 100 },
56
- })
57
-
58
- for (const product of result.products.items || []) {
59
- // Here you would implement your custom sync logic
60
- // e.g., update external ERP, sync with warehouse system, etc.
61
- console.log(`Syncing product: ${product.name}`)
62
- synced++
63
- }
64
- } catch (error) {
65
- console.error('Inventory sync failed:', error)
66
- errors++
67
- }
68
-
69
- return { synced, errors }
70
- }
71
- }
@@ -1,64 +0,0 @@
1
- # ForgeCart deployment ignore file
2
- # Files and directories listed here will not be uploaded during deployment
3
-
4
- # Dependencies - only exclude root node_modules (standalone has its own)
5
- /node_modules/
6
-
7
- # Development files
8
- .git/
9
- .gitignore
10
- .env
11
- .env.local
12
- .env.development
13
- .env.development.local
14
-
15
- # IDE
16
- .idea/
17
- .vscode/
18
- *.swp
19
- *.swo
20
-
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/
32
-
33
- # Test files
34
- __tests__/
35
- *.test.ts
36
- *.test.tsx
37
- *.spec.ts
38
- *.spec.tsx
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
56
-
57
- # Documentation
58
- README.md
59
- CHANGELOG.md
60
- docs/
61
-
62
- # OS files
63
- .DS_Store
64
- Thumbs.db
@@ -1 +0,0 @@
1
- web: node .next/standalone/apps/storefront/server.js
@@ -1,3 +0,0 @@
1
- # ForgeCart API Configuration
2
- NEXT_PUBLIC_FORGECART_API_URL=http://localhost:3000
3
- NEXT_PUBLIC_FORGECART_CHANNEL_TOKEN=your-channel-token-here
@@ -1,11 +0,0 @@
1
- {
2
- "name": "storefront",
3
- "version": "1.0.0",
4
- "private": true,
5
- "engines": {
6
- "node": ">=20.0.0"
7
- },
8
- "scripts": {
9
- "start": "node .next/standalone/apps/storefront/server.js"
10
- }
11
- }
@@ -1,66 +0,0 @@
1
- import { ProductList, Product } from '@forgecart/sdk/shop'
2
- import forgecart from '../../lib/forgecart'
3
-
4
- async function getProducts(): Promise<ProductList> {
5
- try {
6
- // Fetch products from ForgeCart API
7
- const result = await forgecart.shop.products.products({
8
- options: {
9
- take: 10,
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 ProductsPage() {
23
- const products = await getProducts()
24
-
25
- return (
26
- <div className="container mx-auto px-4 py-8">
27
- <h1 className="text-3xl font-bold mb-8">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 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
36
- {products.items.map((product: Product) => (
37
- <div
38
- key={product.id}
39
- className="border rounded-lg overflow-hidden shadow-sm hover:shadow-md transition-shadow"
40
- >
41
- {product.featuredAsset && (
42
- <img
43
- src={product.featuredAsset.preview}
44
- alt={product.name}
45
- className="w-full h-48 object-cover"
46
- />
47
- )}
48
- <div className="p-4">
49
- <h2 className="text-lg font-semibold mb-2">{product.name}</h2>
50
- <p className="text-gray-600 text-sm mb-3 line-clamp-2">
51
- {product.description}
52
- </p>
53
- {product.variants[0] && (
54
- <p className="text-lg font-bold text-blue-600">
55
- {(product.variants[0].price / 100).toFixed(2)}{' '}
56
- {product.variants[0].currencyCode}
57
- </p>
58
- )}
59
- </div>
60
- </div>
61
- ))}
62
- </div>
63
- )}
64
- </div>
65
- )
66
- }
@@ -1,22 +0,0 @@
1
- import { ForgeCartSDK } from '@forgecart/sdk'
2
-
3
- // Singleton instance of the ForgeCart SDK
4
- // Initialized once to maintain socket connection
5
- let sdkInstance: ForgeCartSDK | null = null
6
-
7
- export function getForgeCartSDK(): ForgeCartSDK {
8
- if (!sdkInstance) {
9
- sdkInstance = new ForgeCartSDK({
10
- endpoint:
11
- process.env.NEXT_PUBLIC_FORGECART_API_URL ||
12
- 'https://api.forgecart.com',
13
- token: process.env.NEXT_PUBLIC_FORGECART_CHANNEL_TOKEN || '',
14
- })
15
- }
16
- return sdkInstance
17
- }
18
-
19
- // Export singleton instance for convenience
20
- export const forgecart = getForgeCartSDK()
21
-
22
- export default forgecart
@@ -1,2 +0,0 @@
1
- # ForgeCart deployment directories - exclude from Nx project detection
2
- .forgecart
@@ -1,37 +0,0 @@
1
- # ForgeCart deployment ignore file
2
- # Files and directories listed here will not be uploaded during deployment
3
-
4
- # Dependencies (will be installed during build)
5
- node_modules/
6
-
7
- # Development files
8
- .git/
9
- .gitignore
10
- .env
11
- .env.local
12
- .env.development
13
-
14
- # IDE
15
- .idea/
16
- .vscode/
17
- *.swp
18
- *.swo
19
-
20
- # Build artifacts (we build on the server)
21
- dist/
22
-
23
- # Test files
24
- __tests__/
25
- test/
26
- *.test.ts
27
- *.spec.ts
28
- coverage/
29
-
30
- # Documentation
31
- README.md
32
- CHANGELOG.md
33
- docs/
34
-
35
- # OS files
36
- .DS_Store
37
- Thumbs.db
@@ -1 +0,0 @@
1
- web: node main.js
@@ -1,7 +0,0 @@
1
- # Server Configuration
2
- PORT=3030
3
- NODE_ENV=development
4
-
5
- # ForgeCart API Configuration
6
- FORGECART_API_URL=http://localhost:3000
7
- FORGECART_CHANNEL_TOKEN=your-channel-token-here
@@ -1,16 +0,0 @@
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, PriceFetcherService } from '../services';
6
-
7
- @Module({
8
- imports: [
9
- ConfigModule.forRoot({
10
- isGlobal: true,
11
- }),
12
- ],
13
- controllers: [AppController],
14
- providers: [AppService, ForgeCartService, PriceFetcherService],
15
- })
16
- export class AppModule {}
@@ -1,62 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export { ForgeCartService } from './forgecart.service'
2
- export { PriceFetcherService } from './price-fetcher.service'
@@ -1,71 +0,0 @@
1
- import { Injectable } from '@nestjs/common'
2
- import { ForgeCartService } from './forgecart.service'
3
-
4
- /**
5
- * Example service demonstrating ForgeCart SDK integration
6
- *
7
- * This can be used for custom backend tasks like:
8
- * - Scheduled price updates
9
- * - Inventory synchronization
10
- * - Custom order processing
11
- * - Third-party integrations
12
- */
13
- @Injectable()
14
- export class PriceFetcherService {
15
- constructor(private readonly forgeCart: ForgeCartService) {}
16
-
17
- async getProductPrices(productIds: string[]): Promise<
18
- Array<{
19
- productId: string
20
- name: string
21
- price: number
22
- }>
23
- > {
24
- const prices = []
25
-
26
- for (const productId of productIds) {
27
- try {
28
- const result = await this.forgeCart.shop.products.product({
29
- id: productId,
30
- })
31
- const product = result.product
32
- if (product && product.variants?.[0]) {
33
- prices.push({
34
- productId,
35
- name: product.name,
36
- price: product.variants[0].price,
37
- })
38
- }
39
- } catch (error) {
40
- console.error(`Failed to fetch price for product ${productId}:`, error)
41
- }
42
- }
43
-
44
- return prices
45
- }
46
-
47
- async syncInventory(): Promise<{ synced: number; errors: number }> {
48
- // Example: Sync inventory with external system
49
- // This is a placeholder for custom business logic
50
- let synced = 0
51
- let errors = 0
52
-
53
- try {
54
- const result = await this.forgeCart.shop.products.products({
55
- options: { take: 100 },
56
- })
57
-
58
- for (const product of result.products.items || []) {
59
- // Here you would implement your custom sync logic
60
- // e.g., update external ERP, sync with warehouse system, etc.
61
- console.log(`Syncing product: ${product.name}`)
62
- synced++
63
- }
64
- } catch (error) {
65
- console.error('Inventory sync failed:', error)
66
- errors++
67
- }
68
-
69
- return { synced, errors }
70
- }
71
- }