@forgecart/sdk 0.1.0 → 1.2.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/README.md +90 -0
- package/dist/admin-namespace.d.ts +2493 -0
- package/dist/admin-namespace.js +9218 -0
- package/dist/admin-types.d.ts +15762 -0
- package/dist/admin-types.js +1 -0
- package/dist/admin.d.ts +8 -0
- package/dist/admin.js +7 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +74 -0
- package/dist/shop-namespace.d.ts +688 -0
- package/dist/shop-namespace.js +3043 -0
- package/dist/shop-types.d.ts +6271 -0
- package/dist/shop-types.js +1 -0
- package/dist/shop.d.ts +8 -0
- package/dist/shop.js +7 -0
- package/package.json +31 -40
- package/src/admin-namespace.ts +10812 -0
- package/src/{generated/types.ts → admin-types.ts} +2084 -15
- package/src/admin.ts +9 -0
- package/src/index.ts +106 -0
- package/src/shop-namespace.ts +3462 -0
- package/src/shop-types.ts +4640 -0
- package/src/shop.ts +9 -0
- package/src/generated/sdk.ts +0 -433
package/src/admin.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @forgecart/sdk - Auto-generated TypeScript SDK
|
|
3
|
+
*
|
|
4
|
+
* This file was automatically generated and should not be manually edited.
|
|
5
|
+
* To regenerate, run: npm run codegen:ts
|
|
6
|
+
*
|
|
7
|
+
* 🤖 Generated with ForgeCart SDK Generator
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { AdminNamespace, AdminSDKConfig } from './admin.js'
|
|
11
|
+
import { ShopNamespace, ShopSDKConfig } from './shop.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Unified SDK Configuration
|
|
15
|
+
*/
|
|
16
|
+
export interface ForgeCartSDKConfig {
|
|
17
|
+
/** Base API endpoint (e.g., 'https://api.forgecart.com') */
|
|
18
|
+
endpoint?: string
|
|
19
|
+
/** Channel token for Vendure multi-tenancy */
|
|
20
|
+
token?: string
|
|
21
|
+
/** Use HTTP only, skip WebSocket initialization (default: false) */
|
|
22
|
+
httpOnly?: boolean
|
|
23
|
+
/** Custom HTTP headers */
|
|
24
|
+
headers?: Record<string, string>
|
|
25
|
+
/** Custom WebSocket implementation (optional, auto-detected if not provided) */
|
|
26
|
+
webSocketImpl?: unknown
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Re-export individual namespace configs and classes
|
|
30
|
+
export type { AdminSDKConfig, ShopSDKConfig }
|
|
31
|
+
export { AdminNamespace, ShopNamespace }
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* ForgeCartSDK
|
|
35
|
+
* Unified SDK with categorized operations across multiple namespaces
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const sdk = new ForgeCartSDK({
|
|
40
|
+
* endpoint: 'https://api.forgecart.com',
|
|
41
|
+
* token: 'your-channel-token',
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Admin namespace → Category → Operations
|
|
45
|
+
* await sdk.admin.products.products({ take: 10 });
|
|
46
|
+
* await sdk.admin.customer.customer({ id: '1' });
|
|
47
|
+
*
|
|
48
|
+
* // Shop namespace → Category → Operations
|
|
49
|
+
* await sdk.shop.products.products({ take: 10 });
|
|
50
|
+
* await sdk.shop.order.addItemToOrder({ productVariantId: '1', quantity: 1 });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export class ForgeCartSDK {
|
|
54
|
+
readonly admin: AdminNamespace
|
|
55
|
+
readonly shop: ShopNamespace
|
|
56
|
+
|
|
57
|
+
constructor(config: ForgeCartSDKConfig = {}) {
|
|
58
|
+
const baseEndpoint = config.endpoint || 'https://api.forgecart.com'
|
|
59
|
+
const baseWsEndpoint = baseEndpoint.replace('http', 'ws')
|
|
60
|
+
|
|
61
|
+
// Build headers with token
|
|
62
|
+
const headers: Record<string, string> = {
|
|
63
|
+
...config.headers,
|
|
64
|
+
...(config.token ? { 'forge-token': config.token } : {}),
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const adminConfig: AdminSDKConfig = {
|
|
68
|
+
endpoint: `${baseEndpoint}/admin-api`,
|
|
69
|
+
wsEndpoint: `${baseWsEndpoint}/admin-api`,
|
|
70
|
+
headers,
|
|
71
|
+
webSocketImpl: config.webSocketImpl,
|
|
72
|
+
httpOnly: config.httpOnly,
|
|
73
|
+
}
|
|
74
|
+
this.admin = new AdminNamespace(adminConfig)
|
|
75
|
+
|
|
76
|
+
const shopConfig: ShopSDKConfig = {
|
|
77
|
+
endpoint: `${baseEndpoint}/shop-api`,
|
|
78
|
+
wsEndpoint: `${baseWsEndpoint}/shop-api`,
|
|
79
|
+
headers,
|
|
80
|
+
webSocketImpl: config.webSocketImpl,
|
|
81
|
+
httpOnly: config.httpOnly,
|
|
82
|
+
}
|
|
83
|
+
this.shop = new ShopNamespace(shopConfig)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setAdminAuthToken(token: string): void {
|
|
87
|
+
this.admin.setAuthToken(token)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
clearAdminAuthToken(): void {
|
|
91
|
+
this.admin.clearAuthToken()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setShopAuthToken(token: string): void {
|
|
95
|
+
this.shop.setAuthToken(token)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
clearShopAuthToken(): void {
|
|
99
|
+
this.shop.clearAuthToken()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
dispose(): void {
|
|
103
|
+
this.admin.dispose()
|
|
104
|
+
this.shop.dispose()
|
|
105
|
+
}
|
|
106
|
+
}
|