@forgecart/sdk 1.0.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.
@@ -4,7 +4,7 @@
4
4
  * This file was automatically generated and should not be manually edited.
5
5
  * To regenerate, run: npm run codegen:ts
6
6
  *
7
- * Generated at: 2025-12-12T11:13:16.730Z
7
+ * Generated at: 2025-12-13T23:18:09.120Z
8
8
  * Generator version: 1.0.0
9
9
  *
10
10
  * 🤖 Generated with ForgeCart SDK Generator
@@ -23,6 +23,8 @@ export interface SDKConfig {
23
23
  headers?: Record<string, string>;
24
24
  /** Custom WebSocket implementation (optional, auto-detected if not provided) */
25
25
  webSocketImpl?: unknown;
26
+ /** Use HTTP only, skip WebSocket initialization (default: false) */
27
+ httpOnly?: boolean;
26
28
  }
27
29
  export type ActiveAdministratorQueryVariables = Types.ActiveAdministratorQueryVariables;
28
30
  export type ActiveAdministratorQuery = Types.ActiveAdministratorQuery;
@@ -4,7 +4,7 @@
4
4
  * This file was automatically generated and should not be manually edited.
5
5
  * To regenerate, run: npm run codegen:ts
6
6
  *
7
- * Generated at: 2025-12-12T11:13:16.730Z
7
+ * Generated at: 2025-12-13T23:18:09.120Z
8
8
  * Generator version: 1.0.0
9
9
  *
10
10
  * 🤖 Generated with ForgeCart SDK Generator
@@ -6782,9 +6782,29 @@ class BaseGraphQLClient {
6782
6782
  this.endpoint = config.endpoint || 'https://api.forgecart.com/admin-api';
6783
6783
  this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/admin-api';
6784
6784
  this.config = config;
6785
- // Initialize HTTP client (as fallback)
6785
+ // Custom fetch that captures session token from response headers
6786
+ const customFetch = async (url, options) => {
6787
+ const response = await fetch(url, options);
6788
+ // Capture session token from response header
6789
+ const authToken = response.headers.get('forge-auth-token');
6790
+ if (authToken && authToken !== this.authToken) {
6791
+ this.authToken = authToken;
6792
+ // Reconnect WebSocket with new token
6793
+ if (this.wsClient) {
6794
+ this.wsConnected = false;
6795
+ this.wsClient.dispose();
6796
+ this.wsClient = null;
6797
+ this.wsInitializing = null;
6798
+ this.initializeWebSocket();
6799
+ }
6800
+ }
6801
+ return response;
6802
+ };
6803
+ // Initialize HTTP client with custom fetch
6786
6804
  this.httpClient = new GraphQLClient(this.endpoint, {
6787
6805
  headers: config.headers || {},
6806
+ credentials: 'include',
6807
+ fetch: customFetch,
6788
6808
  });
6789
6809
  // Initialize WebSocket connection immediately
6790
6810
  this.initializeWebSocket();
@@ -6878,6 +6898,10 @@ class BaseGraphQLClient {
6878
6898
  * Connects immediately and tracks connection state
6879
6899
  */
6880
6900
  initializeWebSocket() {
6901
+ // Skip WebSocket if httpOnly mode is enabled
6902
+ if (this.config.httpOnly) {
6903
+ return;
6904
+ }
6881
6905
  // Prevent multiple simultaneous initializations
6882
6906
  if (this.wsClient || this.wsInitializing) {
6883
6907
  return;
@@ -6897,7 +6921,20 @@ class BaseGraphQLClient {
6897
6921
  keepAlive: 10000, // Send keep-alive pings every 10 seconds
6898
6922
  connectionParams: async () => {
6899
6923
  try {
6900
- return this.authToken ? { Authorization: `Bearer ${this.authToken}` } : {};
6924
+ const params = {};
6925
+ // Add session token if available
6926
+ if (this.authToken) {
6927
+ params.Authorization = `bearer ${this.authToken}`;
6928
+ }
6929
+ // Pass all configured headers (including forge-token for channel)
6930
+ if (this.config.headers) {
6931
+ Object.entries(this.config.headers).forEach(([key, value]) => {
6932
+ if (value) {
6933
+ params[key] = value;
6934
+ }
6935
+ });
6936
+ }
6937
+ return params;
6901
6938
  }
6902
6939
  catch (error) {
6903
6940
  console.error('Error in connectionParams:', error);
package/dist/index.d.ts CHANGED
@@ -12,14 +12,12 @@ import { ShopNamespace, ShopSDKConfig } from './shop.js';
12
12
  * Unified SDK Configuration
13
13
  */
14
14
  export interface ForgeCartSDKConfig {
15
- /** GraphQL HTTP endpoint for admin API */
16
- adminEndpoint?: string;
17
- /** WebSocket endpoint for admin subscriptions */
18
- adminWsEndpoint?: string;
19
- /** GraphQL HTTP endpoint for shop API */
20
- shopEndpoint?: string;
21
- /** WebSocket endpoint for shop subscriptions */
22
- shopWsEndpoint?: string;
15
+ /** Base API endpoint (e.g., 'https://api.forgecart.com') */
16
+ endpoint?: string;
17
+ /** Channel token for Vendure multi-tenancy */
18
+ token?: string;
19
+ /** Use HTTP only, skip WebSocket initialization (default: false) */
20
+ httpOnly?: boolean;
23
21
  /** Custom HTTP headers */
24
22
  headers?: Record<string, string>;
25
23
  /** Custom WebSocket implementation (optional, auto-detected if not provided) */
@@ -34,8 +32,8 @@ export { AdminNamespace, ShopNamespace };
34
32
  * @example
35
33
  * ```typescript
36
34
  * const sdk = new ForgeCartSDK({
37
- * adminEndpoint: 'https://api.forgecart.com/admin-api',
38
- * shopEndpoint: 'https://api.forgecart.com/shop-api'
35
+ * endpoint: 'https://api.forgecart.com',
36
+ * token: 'your-channel-token',
39
37
  * });
40
38
  *
41
39
  * // Admin namespace → Category → Operations
package/dist/index.js CHANGED
@@ -16,8 +16,8 @@ export { AdminNamespace, ShopNamespace };
16
16
  * @example
17
17
  * ```typescript
18
18
  * const sdk = new ForgeCartSDK({
19
- * adminEndpoint: 'https://api.forgecart.com/admin-api',
20
- * shopEndpoint: 'https://api.forgecart.com/shop-api'
19
+ * endpoint: 'https://api.forgecart.com',
20
+ * token: 'your-channel-token',
21
21
  * });
22
22
  *
23
23
  * // Admin namespace → Category → Operations
@@ -31,18 +31,27 @@ export { AdminNamespace, ShopNamespace };
31
31
  */
32
32
  export class ForgeCartSDK {
33
33
  constructor(config = {}) {
34
+ const baseEndpoint = config.endpoint || 'https://api.forgecart.com';
35
+ const baseWsEndpoint = baseEndpoint.replace('http', 'ws');
36
+ // Build headers with token
37
+ const headers = {
38
+ ...config.headers,
39
+ ...(config.token ? { 'forge-token': config.token } : {}),
40
+ };
34
41
  const adminConfig = {
35
- endpoint: config.adminEndpoint || 'https://api.forgecart.com/admin-api',
36
- wsEndpoint: config.adminWsEndpoint || 'wss://api.forgecart.com/admin-api',
37
- headers: config.headers,
42
+ endpoint: `${baseEndpoint}/admin-api`,
43
+ wsEndpoint: `${baseWsEndpoint}/admin-api`,
44
+ headers,
38
45
  webSocketImpl: config.webSocketImpl,
46
+ httpOnly: config.httpOnly,
39
47
  };
40
48
  this.admin = new AdminNamespace(adminConfig);
41
49
  const shopConfig = {
42
- endpoint: config.shopEndpoint || 'https://api.forgecart.com/shop-api',
43
- wsEndpoint: config.shopWsEndpoint || 'wss://api.forgecart.com/shop-api',
44
- headers: config.headers,
50
+ endpoint: `${baseEndpoint}/shop-api`,
51
+ wsEndpoint: `${baseWsEndpoint}/shop-api`,
52
+ headers,
45
53
  webSocketImpl: config.webSocketImpl,
54
+ httpOnly: config.httpOnly,
46
55
  };
47
56
  this.shop = new ShopNamespace(shopConfig);
48
57
  }
@@ -4,7 +4,7 @@
4
4
  * This file was automatically generated and should not be manually edited.
5
5
  * To regenerate, run: npm run codegen:ts
6
6
  *
7
- * Generated at: 2025-12-12T11:13:16.603Z
7
+ * Generated at: 2025-12-13T23:18:09.300Z
8
8
  * Generator version: 1.0.0
9
9
  *
10
10
  * 🤖 Generated with ForgeCart SDK Generator
@@ -23,6 +23,8 @@ export interface SDKConfig {
23
23
  headers?: Record<string, string>;
24
24
  /** Custom WebSocket implementation (optional, auto-detected if not provided) */
25
25
  webSocketImpl?: unknown;
26
+ /** Use HTTP only, skip WebSocket initialization (default: false) */
27
+ httpOnly?: boolean;
26
28
  }
27
29
  export type AssetQueryVariables = Types.AssetQueryVariables;
28
30
  export type AssetQuery = Types.AssetQuery;
@@ -4,7 +4,7 @@
4
4
  * This file was automatically generated and should not be manually edited.
5
5
  * To regenerate, run: npm run codegen:ts
6
6
  *
7
- * Generated at: 2025-12-12T11:13:16.603Z
7
+ * Generated at: 2025-12-13T23:18:09.300Z
8
8
  * Generator version: 1.0.0
9
9
  *
10
10
  * 🤖 Generated with ForgeCart SDK Generator
@@ -2200,9 +2200,29 @@ class BaseGraphQLClient {
2200
2200
  this.endpoint = config.endpoint || 'https://api.forgecart.com/shop-api';
2201
2201
  this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/shop-api';
2202
2202
  this.config = config;
2203
- // Initialize HTTP client (as fallback)
2203
+ // Custom fetch that captures session token from response headers
2204
+ const customFetch = async (url, options) => {
2205
+ const response = await fetch(url, options);
2206
+ // Capture session token from response header
2207
+ const authToken = response.headers.get('forge-auth-token');
2208
+ if (authToken && authToken !== this.authToken) {
2209
+ this.authToken = authToken;
2210
+ // Reconnect WebSocket with new token
2211
+ if (this.wsClient) {
2212
+ this.wsConnected = false;
2213
+ this.wsClient.dispose();
2214
+ this.wsClient = null;
2215
+ this.wsInitializing = null;
2216
+ this.initializeWebSocket();
2217
+ }
2218
+ }
2219
+ return response;
2220
+ };
2221
+ // Initialize HTTP client with custom fetch
2204
2222
  this.httpClient = new GraphQLClient(this.endpoint, {
2205
2223
  headers: config.headers || {},
2224
+ credentials: 'include',
2225
+ fetch: customFetch,
2206
2226
  });
2207
2227
  // Initialize WebSocket connection immediately
2208
2228
  this.initializeWebSocket();
@@ -2296,6 +2316,10 @@ class BaseGraphQLClient {
2296
2316
  * Connects immediately and tracks connection state
2297
2317
  */
2298
2318
  initializeWebSocket() {
2319
+ // Skip WebSocket if httpOnly mode is enabled
2320
+ if (this.config.httpOnly) {
2321
+ return;
2322
+ }
2299
2323
  // Prevent multiple simultaneous initializations
2300
2324
  if (this.wsClient || this.wsInitializing) {
2301
2325
  return;
@@ -2315,7 +2339,20 @@ class BaseGraphQLClient {
2315
2339
  keepAlive: 10000, // Send keep-alive pings every 10 seconds
2316
2340
  connectionParams: async () => {
2317
2341
  try {
2318
- return this.authToken ? { Authorization: `Bearer ${this.authToken}` } : {};
2342
+ const params = {};
2343
+ // Add session token if available
2344
+ if (this.authToken) {
2345
+ params.Authorization = `bearer ${this.authToken}`;
2346
+ }
2347
+ // Pass all configured headers (including forge-token for channel)
2348
+ if (this.config.headers) {
2349
+ Object.entries(this.config.headers).forEach(([key, value]) => {
2350
+ if (value) {
2351
+ params[key] = value;
2352
+ }
2353
+ });
2354
+ }
2355
+ return params;
2319
2356
  }
2320
2357
  catch (error) {
2321
2358
  console.error('Error in connectionParams:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgecart/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "TypeScript SDK for ForgeCart API - Auto-generated GraphQL client",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -4,7 +4,7 @@
4
4
  * This file was automatically generated and should not be manually edited.
5
5
  * To regenerate, run: npm run codegen:ts
6
6
  *
7
- * Generated at: 2025-12-12T11:13:16.730Z
7
+ * Generated at: 2025-12-13T23:18:09.120Z
8
8
  * Generator version: 1.0.0
9
9
  *
10
10
  * 🤖 Generated with ForgeCart SDK Generator
@@ -28,6 +28,8 @@ export interface SDKConfig {
28
28
  headers?: Record<string, string>;
29
29
  /** Custom WebSocket implementation (optional, auto-detected if not provided) */
30
30
  webSocketImpl?: unknown;
31
+ /** Use HTTP only, skip WebSocket initialization (default: false) */
32
+ httpOnly?: boolean;
31
33
  }
32
34
 
33
35
  export type ActiveAdministratorQueryVariables = Types.ActiveAdministratorQueryVariables;
@@ -8020,9 +8022,32 @@ class BaseGraphQLClient {
8020
8022
  this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/admin-api';
8021
8023
  this.config = config;
8022
8024
 
8023
- // Initialize HTTP client (as fallback)
8025
+ // Custom fetch that captures session token from response headers
8026
+ const customFetch = async (url: RequestInfo | URL, options?: RequestInit): Promise<Response> => {
8027
+ const response = await fetch(url, options);
8028
+
8029
+ // Capture session token from response header
8030
+ const authToken = response.headers.get('forge-auth-token');
8031
+ if (authToken && authToken !== this.authToken) {
8032
+ this.authToken = authToken;
8033
+ // Reconnect WebSocket with new token
8034
+ if (this.wsClient) {
8035
+ this.wsConnected = false;
8036
+ this.wsClient.dispose();
8037
+ this.wsClient = null;
8038
+ this.wsInitializing = null;
8039
+ this.initializeWebSocket();
8040
+ }
8041
+ }
8042
+
8043
+ return response;
8044
+ };
8045
+
8046
+ // Initialize HTTP client with custom fetch
8024
8047
  this.httpClient = new GraphQLClient(this.endpoint, {
8025
8048
  headers: config.headers || {},
8049
+ credentials: 'include',
8050
+ fetch: customFetch,
8026
8051
  });
8027
8052
 
8028
8053
  // Initialize WebSocket connection immediately
@@ -8137,6 +8162,11 @@ class BaseGraphQLClient {
8137
8162
  * Connects immediately and tracks connection state
8138
8163
  */
8139
8164
  private initializeWebSocket(): void {
8165
+ // Skip WebSocket if httpOnly mode is enabled
8166
+ if (this.config.httpOnly) {
8167
+ return;
8168
+ }
8169
+
8140
8170
  // Prevent multiple simultaneous initializations
8141
8171
  if (this.wsClient || this.wsInitializing) {
8142
8172
  return;
@@ -8159,7 +8189,23 @@ class BaseGraphQLClient {
8159
8189
  keepAlive: 10_000, // Send keep-alive pings every 10 seconds
8160
8190
  connectionParams: async () => {
8161
8191
  try {
8162
- return this.authToken ? { Authorization: `Bearer ${this.authToken}` } : {};
8192
+ const params: Record<string, string> = {};
8193
+
8194
+ // Add session token if available
8195
+ if (this.authToken) {
8196
+ params.Authorization = `bearer ${this.authToken}`;
8197
+ }
8198
+
8199
+ // Pass all configured headers (including forge-token for channel)
8200
+ if (this.config.headers) {
8201
+ Object.entries(this.config.headers).forEach(([key, value]) => {
8202
+ if (value) {
8203
+ params[key] = value;
8204
+ }
8205
+ });
8206
+ }
8207
+
8208
+ return params;
8163
8209
  } catch (error) {
8164
8210
  console.error('Error in connectionParams:', error);
8165
8211
  return {};
package/src/index.ts CHANGED
@@ -14,14 +14,12 @@ import { ShopNamespace, ShopSDKConfig } from './shop.js'
14
14
  * Unified SDK Configuration
15
15
  */
16
16
  export interface ForgeCartSDKConfig {
17
- /** GraphQL HTTP endpoint for admin API */
18
- adminEndpoint?: string
19
- /** WebSocket endpoint for admin subscriptions */
20
- adminWsEndpoint?: string
21
- /** GraphQL HTTP endpoint for shop API */
22
- shopEndpoint?: string
23
- /** WebSocket endpoint for shop subscriptions */
24
- shopWsEndpoint?: string
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
25
23
  /** Custom HTTP headers */
26
24
  headers?: Record<string, string>
27
25
  /** Custom WebSocket implementation (optional, auto-detected if not provided) */
@@ -39,8 +37,8 @@ export { AdminNamespace, ShopNamespace }
39
37
  * @example
40
38
  * ```typescript
41
39
  * const sdk = new ForgeCartSDK({
42
- * adminEndpoint: 'https://api.forgecart.com/admin-api',
43
- * shopEndpoint: 'https://api.forgecart.com/shop-api'
40
+ * endpoint: 'https://api.forgecart.com',
41
+ * token: 'your-channel-token',
44
42
  * });
45
43
  *
46
44
  * // Admin namespace → Category → Operations
@@ -57,19 +55,30 @@ export class ForgeCartSDK {
57
55
  readonly shop: ShopNamespace
58
56
 
59
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
+
60
67
  const adminConfig: AdminSDKConfig = {
61
- endpoint: config.adminEndpoint || 'https://api.forgecart.com/admin-api',
62
- wsEndpoint: config.adminWsEndpoint || 'wss://api.forgecart.com/admin-api',
63
- headers: config.headers,
68
+ endpoint: `${baseEndpoint}/admin-api`,
69
+ wsEndpoint: `${baseWsEndpoint}/admin-api`,
70
+ headers,
64
71
  webSocketImpl: config.webSocketImpl,
72
+ httpOnly: config.httpOnly,
65
73
  }
66
74
  this.admin = new AdminNamespace(adminConfig)
67
75
 
68
76
  const shopConfig: ShopSDKConfig = {
69
- endpoint: config.shopEndpoint || 'https://api.forgecart.com/shop-api',
70
- wsEndpoint: config.shopWsEndpoint || 'wss://api.forgecart.com/shop-api',
71
- headers: config.headers,
77
+ endpoint: `${baseEndpoint}/shop-api`,
78
+ wsEndpoint: `${baseWsEndpoint}/shop-api`,
79
+ headers,
72
80
  webSocketImpl: config.webSocketImpl,
81
+ httpOnly: config.httpOnly,
73
82
  }
74
83
  this.shop = new ShopNamespace(shopConfig)
75
84
  }
@@ -4,7 +4,7 @@
4
4
  * This file was automatically generated and should not be manually edited.
5
5
  * To regenerate, run: npm run codegen:ts
6
6
  *
7
- * Generated at: 2025-12-12T11:13:16.603Z
7
+ * Generated at: 2025-12-13T23:18:09.300Z
8
8
  * Generator version: 1.0.0
9
9
  *
10
10
  * 🤖 Generated with ForgeCart SDK Generator
@@ -28,6 +28,8 @@ export interface SDKConfig {
28
28
  headers?: Record<string, string>;
29
29
  /** Custom WebSocket implementation (optional, auto-detected if not provided) */
30
30
  webSocketImpl?: unknown;
31
+ /** Use HTTP only, skip WebSocket initialization (default: false) */
32
+ httpOnly?: boolean;
31
33
  }
32
34
 
33
35
  export type AssetQueryVariables = Types.AssetQueryVariables;
@@ -2498,9 +2500,32 @@ class BaseGraphQLClient {
2498
2500
  this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/shop-api';
2499
2501
  this.config = config;
2500
2502
 
2501
- // Initialize HTTP client (as fallback)
2503
+ // Custom fetch that captures session token from response headers
2504
+ const customFetch = async (url: RequestInfo | URL, options?: RequestInit): Promise<Response> => {
2505
+ const response = await fetch(url, options);
2506
+
2507
+ // Capture session token from response header
2508
+ const authToken = response.headers.get('forge-auth-token');
2509
+ if (authToken && authToken !== this.authToken) {
2510
+ this.authToken = authToken;
2511
+ // Reconnect WebSocket with new token
2512
+ if (this.wsClient) {
2513
+ this.wsConnected = false;
2514
+ this.wsClient.dispose();
2515
+ this.wsClient = null;
2516
+ this.wsInitializing = null;
2517
+ this.initializeWebSocket();
2518
+ }
2519
+ }
2520
+
2521
+ return response;
2522
+ };
2523
+
2524
+ // Initialize HTTP client with custom fetch
2502
2525
  this.httpClient = new GraphQLClient(this.endpoint, {
2503
2526
  headers: config.headers || {},
2527
+ credentials: 'include',
2528
+ fetch: customFetch,
2504
2529
  });
2505
2530
 
2506
2531
  // Initialize WebSocket connection immediately
@@ -2615,6 +2640,11 @@ class BaseGraphQLClient {
2615
2640
  * Connects immediately and tracks connection state
2616
2641
  */
2617
2642
  private initializeWebSocket(): void {
2643
+ // Skip WebSocket if httpOnly mode is enabled
2644
+ if (this.config.httpOnly) {
2645
+ return;
2646
+ }
2647
+
2618
2648
  // Prevent multiple simultaneous initializations
2619
2649
  if (this.wsClient || this.wsInitializing) {
2620
2650
  return;
@@ -2637,7 +2667,23 @@ class BaseGraphQLClient {
2637
2667
  keepAlive: 10_000, // Send keep-alive pings every 10 seconds
2638
2668
  connectionParams: async () => {
2639
2669
  try {
2640
- return this.authToken ? { Authorization: `Bearer ${this.authToken}` } : {};
2670
+ const params: Record<string, string> = {};
2671
+
2672
+ // Add session token if available
2673
+ if (this.authToken) {
2674
+ params.Authorization = `bearer ${this.authToken}`;
2675
+ }
2676
+
2677
+ // Pass all configured headers (including forge-token for channel)
2678
+ if (this.config.headers) {
2679
+ Object.entries(this.config.headers).forEach(([key, value]) => {
2680
+ if (value) {
2681
+ params[key] = value;
2682
+ }
2683
+ });
2684
+ }
2685
+
2686
+ return params;
2641
2687
  } catch (error) {
2642
2688
  console.error('Error in connectionParams:', error);
2643
2689
  return {};