@forgecart/sdk 1.2.3 → 1.2.5
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/dist/admin-namespace.d.ts +25 -1
- package/dist/admin-namespace.js +71 -18
- package/dist/admin-types.d.ts +7 -3
- package/dist/shop-namespace.d.ts +25 -1
- package/dist/shop-namespace.js +67 -14
- package/package.json +1 -1
- package/src/admin-namespace.ts +73 -17
- package/src/admin-types.ts +8 -3
- package/src/shop-namespace.ts +69 -13
|
@@ -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-
|
|
7
|
+
* Generated at: 2025-12-17T10:24:29.306Z
|
|
8
8
|
* Generator version: 1.0.0
|
|
9
9
|
*
|
|
10
10
|
* 🤖 Generated with ForgeCart SDK Generator
|
|
@@ -28,6 +28,28 @@ export interface SDKConfig {
|
|
|
28
28
|
/** Enable debug logging with request timing (default: false) */
|
|
29
29
|
debug?: boolean;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* SDK Logger - Cross-platform logging with colors
|
|
33
|
+
* Respects debug flag for log/warn, errors are always visible
|
|
34
|
+
*/
|
|
35
|
+
export declare class SDKLogger {
|
|
36
|
+
private debug;
|
|
37
|
+
private prefix;
|
|
38
|
+
constructor(debug?: boolean);
|
|
39
|
+
private isNode;
|
|
40
|
+
/**
|
|
41
|
+
* Debug log - only outputs when debug: true
|
|
42
|
+
*/
|
|
43
|
+
log(message: string, ...args: unknown[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Warning log - only outputs when debug: true
|
|
46
|
+
*/
|
|
47
|
+
warn(message: string, ...args: unknown[]): void;
|
|
48
|
+
/**
|
|
49
|
+
* Error log - always outputs (errors should always be visible)
|
|
50
|
+
*/
|
|
51
|
+
error(message: string, ...args: unknown[]): void;
|
|
52
|
+
}
|
|
31
53
|
export type ActiveAdministratorQueryVariables = Types.ActiveAdministratorQueryVariables;
|
|
32
54
|
export type ActiveAdministratorQuery = Types.ActiveAdministratorQuery;
|
|
33
55
|
export type ActiveAdministratorQueryResult = Types.ActiveAdministratorQuery;
|
|
@@ -991,6 +1013,7 @@ declare class BaseGraphQLClient {
|
|
|
991
1013
|
private endpoint;
|
|
992
1014
|
private wsEndpoint;
|
|
993
1015
|
private config;
|
|
1016
|
+
private logger;
|
|
994
1017
|
constructor(config: SDKConfig);
|
|
995
1018
|
/**
|
|
996
1019
|
* Extract operation name from GraphQL document
|
|
@@ -2576,6 +2599,7 @@ declare class ZoneOperations {
|
|
|
2576
2599
|
*/
|
|
2577
2600
|
export declare class AdminNamespace {
|
|
2578
2601
|
private client;
|
|
2602
|
+
private logger;
|
|
2579
2603
|
readonly administrator: AdministratorOperations;
|
|
2580
2604
|
readonly asset: AssetOperations;
|
|
2581
2605
|
readonly blog: BlogOperations;
|
package/dist/admin-namespace.js
CHANGED
|
@@ -5,15 +5,66 @@
|
|
|
5
5
|
* This file was automatically generated and should not be manually edited.
|
|
6
6
|
* To regenerate, run: npm run codegen:ts
|
|
7
7
|
*
|
|
8
|
-
* Generated at: 2025-12-
|
|
8
|
+
* Generated at: 2025-12-17T10:24:29.306Z
|
|
9
9
|
* Generator version: 1.0.0
|
|
10
10
|
*
|
|
11
11
|
* 🤖 Generated with ForgeCart SDK Generator
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.AdminNamespace = exports.AllEvents = exports.CatalogEvents = exports.PaymentEvents = exports.FulfillmentEvents = exports.CustomerEvents = exports.OrderEvents = exports.ProductEvents = void 0;
|
|
14
|
+
exports.AdminNamespace = exports.AllEvents = exports.CatalogEvents = exports.PaymentEvents = exports.FulfillmentEvents = exports.CustomerEvents = exports.OrderEvents = exports.ProductEvents = exports.SDKLogger = void 0;
|
|
15
15
|
const graphql_request_1 = require("graphql-request");
|
|
16
16
|
const graphql_ws_1 = require("graphql-ws");
|
|
17
|
+
/**
|
|
18
|
+
* SDK Logger - Cross-platform logging with colors
|
|
19
|
+
* Respects debug flag for log/warn, errors are always visible
|
|
20
|
+
*/
|
|
21
|
+
class SDKLogger {
|
|
22
|
+
constructor(debug = false) {
|
|
23
|
+
this.prefix = '[ForgeCart SDK]';
|
|
24
|
+
this.debug = debug;
|
|
25
|
+
}
|
|
26
|
+
isNode() {
|
|
27
|
+
return typeof process !== 'undefined' && process.versions?.node != null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Debug log - only outputs when debug: true
|
|
31
|
+
*/
|
|
32
|
+
log(message, ...args) {
|
|
33
|
+
if (!this.debug)
|
|
34
|
+
return;
|
|
35
|
+
if (this.isNode()) {
|
|
36
|
+
console.log(`\x1b[36m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(`%c${this.prefix}%c ${message}`, 'color: #06b6d4; font-weight: bold', 'color: inherit', ...args);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Warning log - only outputs when debug: true
|
|
44
|
+
*/
|
|
45
|
+
warn(message, ...args) {
|
|
46
|
+
if (!this.debug)
|
|
47
|
+
return;
|
|
48
|
+
if (this.isNode()) {
|
|
49
|
+
console.warn(`\x1b[33m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.warn(`%c${this.prefix}%c ${message}`, 'color: #eab308; font-weight: bold', 'color: inherit', ...args);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Error log - always outputs (errors should always be visible)
|
|
57
|
+
*/
|
|
58
|
+
error(message, ...args) {
|
|
59
|
+
if (this.isNode()) {
|
|
60
|
+
console.error(`\x1b[31m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error(`%c${this.prefix}%c ${message}`, 'color: #ef4444; font-weight: bold', 'color: inherit', ...args);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.SDKLogger = SDKLogger;
|
|
17
68
|
const activeAdministratorDocument = `query activeAdministrator {
|
|
18
69
|
activeAdministrator {
|
|
19
70
|
id
|
|
@@ -6887,6 +6938,7 @@ class BaseGraphQLClient {
|
|
|
6887
6938
|
this.endpoint = config.endpoint || 'https://api.forgecart.com/admin-api';
|
|
6888
6939
|
this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/admin-api';
|
|
6889
6940
|
this.config = config;
|
|
6941
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
6890
6942
|
// Custom fetch that captures session token from response headers
|
|
6891
6943
|
const customFetch = async (url, options) => {
|
|
6892
6944
|
const response = await fetch(url, options);
|
|
@@ -6936,13 +6988,13 @@ class BaseGraphQLClient {
|
|
|
6936
6988
|
transport = 'WebSocket';
|
|
6937
6989
|
const result = await this.requestViaWebSocket(document, variables);
|
|
6938
6990
|
if (this.config.debug) {
|
|
6939
|
-
|
|
6991
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
6940
6992
|
}
|
|
6941
6993
|
return result;
|
|
6942
6994
|
}
|
|
6943
6995
|
catch (wsError) {
|
|
6944
6996
|
transport = 'WebSocket -> HTTP';
|
|
6945
|
-
|
|
6997
|
+
this.logger.warn('WebSocket request failed, falling back to HTTP:', wsError);
|
|
6946
6998
|
// Fall through to HTTP
|
|
6947
6999
|
}
|
|
6948
7000
|
}
|
|
@@ -6950,13 +7002,13 @@ class BaseGraphQLClient {
|
|
|
6950
7002
|
try {
|
|
6951
7003
|
const result = await this.httpClient.request(document, variables);
|
|
6952
7004
|
if (this.config.debug) {
|
|
6953
|
-
|
|
7005
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
6954
7006
|
}
|
|
6955
7007
|
return result;
|
|
6956
7008
|
}
|
|
6957
7009
|
catch (error) {
|
|
6958
7010
|
if (this.config.debug) {
|
|
6959
|
-
|
|
7011
|
+
this.logger.log(`${operationName} (${transport}) - FAILED after ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
6960
7012
|
}
|
|
6961
7013
|
this.handleError(error);
|
|
6962
7014
|
throw error;
|
|
@@ -6998,7 +7050,7 @@ class BaseGraphQLClient {
|
|
|
6998
7050
|
* Handle GraphQL errors
|
|
6999
7051
|
*/
|
|
7000
7052
|
handleError(error) {
|
|
7001
|
-
|
|
7053
|
+
this.logger.error('GraphQL Error:', error);
|
|
7002
7054
|
}
|
|
7003
7055
|
/**
|
|
7004
7056
|
* Get WebSocket implementation for current environment
|
|
@@ -7018,7 +7070,7 @@ class BaseGraphQLClient {
|
|
|
7018
7070
|
return require('ws');
|
|
7019
7071
|
}
|
|
7020
7072
|
catch (e) {
|
|
7021
|
-
|
|
7073
|
+
this.logger.warn('WebSocket not available. Install "ws" package for Node.js support or provide webSocketImpl in config.');
|
|
7022
7074
|
return undefined;
|
|
7023
7075
|
}
|
|
7024
7076
|
}
|
|
@@ -7037,7 +7089,7 @@ class BaseGraphQLClient {
|
|
|
7037
7089
|
}
|
|
7038
7090
|
const WebSocketImpl = this.getWebSocketImpl();
|
|
7039
7091
|
if (!WebSocketImpl) {
|
|
7040
|
-
|
|
7092
|
+
this.logger.warn('WebSocket not available. Will use HTTP fallback only.');
|
|
7041
7093
|
return;
|
|
7042
7094
|
}
|
|
7043
7095
|
this.wsInitializing = new Promise((resolve, reject) => {
|
|
@@ -7066,7 +7118,7 @@ class BaseGraphQLClient {
|
|
|
7066
7118
|
return params;
|
|
7067
7119
|
}
|
|
7068
7120
|
catch (error) {
|
|
7069
|
-
|
|
7121
|
+
this.logger.error('Error in connectionParams:', error);
|
|
7070
7122
|
return {};
|
|
7071
7123
|
}
|
|
7072
7124
|
},
|
|
@@ -7079,7 +7131,7 @@ class BaseGraphQLClient {
|
|
|
7079
7131
|
on: {
|
|
7080
7132
|
connected: () => {
|
|
7081
7133
|
this.wsConnected = true;
|
|
7082
|
-
|
|
7134
|
+
this.logger.log('WebSocket connected');
|
|
7083
7135
|
if (!isResolved) {
|
|
7084
7136
|
isResolved = true;
|
|
7085
7137
|
resolve();
|
|
@@ -7088,13 +7140,13 @@ class BaseGraphQLClient {
|
|
|
7088
7140
|
closed: () => {
|
|
7089
7141
|
this.wsConnected = false;
|
|
7090
7142
|
if (!this.isDisposing) {
|
|
7091
|
-
|
|
7143
|
+
this.logger.log('WebSocket disconnected');
|
|
7092
7144
|
}
|
|
7093
7145
|
},
|
|
7094
7146
|
error: (error) => {
|
|
7095
7147
|
// Suppress errors during disposal - they're expected
|
|
7096
7148
|
if (!this.isDisposing && this.wsConnected) {
|
|
7097
|
-
|
|
7149
|
+
this.logger.error('WebSocket error:', error);
|
|
7098
7150
|
}
|
|
7099
7151
|
// Don't fail the connection on errors - let retry logic handle it
|
|
7100
7152
|
// Only log errors if we're connected (unexpected errors)
|
|
@@ -7106,7 +7158,7 @@ class BaseGraphQLClient {
|
|
|
7106
7158
|
this.wsInitializing = null;
|
|
7107
7159
|
}
|
|
7108
7160
|
catch (error) {
|
|
7109
|
-
|
|
7161
|
+
this.logger.error('Failed to create WebSocket client:', error);
|
|
7110
7162
|
this.wsInitializing = null;
|
|
7111
7163
|
// Resolve anyway to not block - we'll fallback to HTTP
|
|
7112
7164
|
if (!isResolved) {
|
|
@@ -9441,6 +9493,7 @@ class AdminNamespace {
|
|
|
9441
9493
|
this.retryCount = 0;
|
|
9442
9494
|
this.abortController = null;
|
|
9443
9495
|
this.client = new BaseGraphQLClient(config);
|
|
9496
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
9444
9497
|
this.administrator = new AdministratorOperations(this.client);
|
|
9445
9498
|
this.asset = new AssetOperations(this.client);
|
|
9446
9499
|
this.blog = new BlogOperations(this.client);
|
|
@@ -9554,7 +9607,7 @@ class AdminNamespace {
|
|
|
9554
9607
|
}
|
|
9555
9608
|
catch (error) {
|
|
9556
9609
|
if (this.isListening) {
|
|
9557
|
-
|
|
9610
|
+
this.logger.error('Event subscription error:', error);
|
|
9558
9611
|
await this.handleReconnect();
|
|
9559
9612
|
}
|
|
9560
9613
|
}
|
|
@@ -9568,7 +9621,7 @@ class AdminNamespace {
|
|
|
9568
9621
|
// Calculate delay with exponential backoff
|
|
9569
9622
|
const delay = Math.min(baseDelayMs * Math.pow(backoffMultiplier, this.retryCount), maxDelayMs);
|
|
9570
9623
|
this.retryCount++;
|
|
9571
|
-
|
|
9624
|
+
this.logger.log(`Reconnecting in ${delay}ms (attempt ${this.retryCount}/${maxRetries})`);
|
|
9572
9625
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
9573
9626
|
await this.startSubscription();
|
|
9574
9627
|
}
|
|
@@ -9585,7 +9638,7 @@ class AdminNamespace {
|
|
|
9585
9638
|
handler(event);
|
|
9586
9639
|
}
|
|
9587
9640
|
catch (error) {
|
|
9588
|
-
|
|
9641
|
+
this.logger.error(`Error in event handler for ${eventName}:`, error);
|
|
9589
9642
|
}
|
|
9590
9643
|
}
|
|
9591
9644
|
}
|
|
@@ -9597,7 +9650,7 @@ class AdminNamespace {
|
|
|
9597
9650
|
await this.executeWithTimeout(handler(event), AdminNamespace.BLOCKING_TIMEOUT_MS, `Blocking handler for ${eventName} exceeded ${AdminNamespace.BLOCKING_TIMEOUT_MS}ms`);
|
|
9598
9651
|
}
|
|
9599
9652
|
catch (error) {
|
|
9600
|
-
|
|
9653
|
+
this.logger.error(`Error in blocking event handler for ${eventName}:`, error);
|
|
9601
9654
|
throw error; // Re-throw for blocking handlers
|
|
9602
9655
|
}
|
|
9603
9656
|
}
|
package/dist/admin-types.d.ts
CHANGED
|
@@ -973,6 +973,7 @@ export type CreateCustomerInput = {
|
|
|
973
973
|
};
|
|
974
974
|
export type CreateCustomerResult = Customer | EmailAddressConflictError;
|
|
975
975
|
export type CreateDeploymentInput = {
|
|
976
|
+
envVars?: InputMaybe<Array<EnvVarInput>>;
|
|
976
977
|
type: DeploymentType;
|
|
977
978
|
};
|
|
978
979
|
export type CreateFacetInput = {
|
|
@@ -1900,6 +1901,10 @@ export type EntityEventPayload = {
|
|
|
1900
1901
|
type: Scalars['String']['output'];
|
|
1901
1902
|
};
|
|
1902
1903
|
export type EntityEventType = 'assigned' | 'created' | 'deleted' | 'removed' | 'updated';
|
|
1904
|
+
export type EnvVarInput = {
|
|
1905
|
+
key: Scalars['String']['input'];
|
|
1906
|
+
value: Scalars['String']['input'];
|
|
1907
|
+
};
|
|
1903
1908
|
export type ErrorCode = 'ALREADY_REFUNDED_ERROR' | 'CANCEL_ACTIVE_ORDER_ERROR' | 'CANCEL_PAYMENT_ERROR' | 'CHANNEL_DEFAULT_LANGUAGE_ERROR' | 'COUPON_CODE_EXPIRED_ERROR' | 'COUPON_CODE_INVALID_ERROR' | 'COUPON_CODE_LIMIT_ERROR' | 'CREATE_FULFILLMENT_ERROR' | 'DUPLICATE_ENTITY_ERROR' | 'EMAIL_ADDRESS_CONFLICT_ERROR' | 'EMPTY_ORDER_LINE_SELECTION_ERROR' | 'FACET_IN_USE_ERROR' | 'FULFILLMENT_STATE_TRANSITION_ERROR' | 'GUEST_CHECKOUT_ERROR' | 'INELIGIBLE_SHIPPING_METHOD_ERROR' | 'INSUFFICIENT_STOCK_ERROR' | 'INSUFFICIENT_STOCK_ON_HAND_ERROR' | 'INVALID_CREDENTIALS_ERROR' | 'INVALID_FULFILLMENT_HANDLER_ERROR' | 'ITEMS_ALREADY_FULFILLED_ERROR' | 'LANGUAGE_NOT_AVAILABLE_ERROR' | 'MANUAL_PAYMENT_STATE_ERROR' | 'MIME_TYPE_ERROR' | 'MISSING_CONDITIONS_ERROR' | 'MULTIPLE_ORDER_ERROR' | 'NATIVE_AUTH_STRATEGY_ERROR' | 'NEGATIVE_QUANTITY_ERROR' | 'NOTHING_TO_REFUND_ERROR' | 'NO_ACTIVE_ORDER_ERROR' | 'NO_CHANGES_SPECIFIED_ERROR' | 'ORDER_INTERCEPTOR_ERROR' | 'ORDER_LIMIT_ERROR' | 'ORDER_MODIFICATION_ERROR' | 'ORDER_MODIFICATION_STATE_ERROR' | 'ORDER_STATE_TRANSITION_ERROR' | 'PAYMENT_METHOD_MISSING_ERROR' | 'PAYMENT_ORDER_MISMATCH_ERROR' | 'PAYMENT_STATE_TRANSITION_ERROR' | 'PRODUCT_OPTION_IN_USE_ERROR' | 'QUANTITY_TOO_GREAT_ERROR' | 'REFUND_AMOUNT_ERROR' | 'REFUND_ORDER_STATE_ERROR' | 'REFUND_PAYMENT_ID_MISSING_ERROR' | 'REFUND_STATE_TRANSITION_ERROR' | 'SETTLE_PAYMENT_ERROR' | 'UNKNOWN_ERROR';
|
|
1904
1909
|
export type ErrorResult = {
|
|
1905
1910
|
errorCode: ErrorCode;
|
|
@@ -6185,9 +6190,8 @@ export type SessionInput = {
|
|
|
6185
6190
|
};
|
|
6186
6191
|
export type SetCustomerForDraftOrderResult = EmailAddressConflictError | Order;
|
|
6187
6192
|
export type SetEnvInput = {
|
|
6188
|
-
|
|
6193
|
+
envVars: Array<EnvVarInput>;
|
|
6189
6194
|
type: DeploymentType;
|
|
6190
|
-
value: Scalars['String']['input'];
|
|
6191
6195
|
};
|
|
6192
6196
|
export type SetOrderCustomerInput = {
|
|
6193
6197
|
customerId: Scalars['ID']['input'];
|
|
@@ -6783,7 +6787,7 @@ export type TransitionFulfillmentToStateResult = Fulfillment | FulfillmentStateT
|
|
|
6783
6787
|
export type TransitionOrderToStateResult = Order | OrderStateTransitionError;
|
|
6784
6788
|
export type TransitionPaymentToStateResult = Payment | PaymentStateTransitionError;
|
|
6785
6789
|
export type UnsetEnvInput = {
|
|
6786
|
-
|
|
6790
|
+
keys: Array<Scalars['String']['input']>;
|
|
6787
6791
|
type: DeploymentType;
|
|
6788
6792
|
};
|
|
6789
6793
|
export type UpdateActiveAdministratorInput = {
|
package/dist/shop-namespace.d.ts
CHANGED
|
@@ -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-
|
|
7
|
+
* Generated at: 2025-12-17T10:24:29.175Z
|
|
8
8
|
* Generator version: 1.0.0
|
|
9
9
|
*
|
|
10
10
|
* 🤖 Generated with ForgeCart SDK Generator
|
|
@@ -28,6 +28,28 @@ export interface SDKConfig {
|
|
|
28
28
|
/** Enable debug logging with request timing (default: false) */
|
|
29
29
|
debug?: boolean;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* SDK Logger - Cross-platform logging with colors
|
|
33
|
+
* Respects debug flag for log/warn, errors are always visible
|
|
34
|
+
*/
|
|
35
|
+
export declare class SDKLogger {
|
|
36
|
+
private debug;
|
|
37
|
+
private prefix;
|
|
38
|
+
constructor(debug?: boolean);
|
|
39
|
+
private isNode;
|
|
40
|
+
/**
|
|
41
|
+
* Debug log - only outputs when debug: true
|
|
42
|
+
*/
|
|
43
|
+
log(message: string, ...args: unknown[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Warning log - only outputs when debug: true
|
|
46
|
+
*/
|
|
47
|
+
warn(message: string, ...args: unknown[]): void;
|
|
48
|
+
/**
|
|
49
|
+
* Error log - always outputs (errors should always be visible)
|
|
50
|
+
*/
|
|
51
|
+
error(message: string, ...args: unknown[]): void;
|
|
52
|
+
}
|
|
31
53
|
export type AssetQueryVariables = Types.AssetQueryVariables;
|
|
32
54
|
export type AssetQuery = Types.AssetQuery;
|
|
33
55
|
export type AssetQueryResult = Types.AssetQuery;
|
|
@@ -247,6 +269,7 @@ declare class BaseGraphQLClient {
|
|
|
247
269
|
private endpoint;
|
|
248
270
|
private wsEndpoint;
|
|
249
271
|
private config;
|
|
272
|
+
private logger;
|
|
250
273
|
constructor(config: SDKConfig);
|
|
251
274
|
/**
|
|
252
275
|
* Extract operation name from GraphQL document
|
|
@@ -663,6 +686,7 @@ declare class SearchOperations {
|
|
|
663
686
|
*/
|
|
664
687
|
export declare class ShopNamespace {
|
|
665
688
|
private client;
|
|
689
|
+
private logger;
|
|
666
690
|
readonly asset: AssetOperations;
|
|
667
691
|
readonly auth: AuthOperations;
|
|
668
692
|
readonly blog: BlogOperations;
|
package/dist/shop-namespace.js
CHANGED
|
@@ -5,15 +5,66 @@
|
|
|
5
5
|
* This file was automatically generated and should not be manually edited.
|
|
6
6
|
* To regenerate, run: npm run codegen:ts
|
|
7
7
|
*
|
|
8
|
-
* Generated at: 2025-12-
|
|
8
|
+
* Generated at: 2025-12-17T10:24:29.175Z
|
|
9
9
|
* Generator version: 1.0.0
|
|
10
10
|
*
|
|
11
11
|
* 🤖 Generated with ForgeCart SDK Generator
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ShopNamespace = void 0;
|
|
14
|
+
exports.ShopNamespace = exports.SDKLogger = void 0;
|
|
15
15
|
const graphql_request_1 = require("graphql-request");
|
|
16
16
|
const graphql_ws_1 = require("graphql-ws");
|
|
17
|
+
/**
|
|
18
|
+
* SDK Logger - Cross-platform logging with colors
|
|
19
|
+
* Respects debug flag for log/warn, errors are always visible
|
|
20
|
+
*/
|
|
21
|
+
class SDKLogger {
|
|
22
|
+
constructor(debug = false) {
|
|
23
|
+
this.prefix = '[ForgeCart SDK]';
|
|
24
|
+
this.debug = debug;
|
|
25
|
+
}
|
|
26
|
+
isNode() {
|
|
27
|
+
return typeof process !== 'undefined' && process.versions?.node != null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Debug log - only outputs when debug: true
|
|
31
|
+
*/
|
|
32
|
+
log(message, ...args) {
|
|
33
|
+
if (!this.debug)
|
|
34
|
+
return;
|
|
35
|
+
if (this.isNode()) {
|
|
36
|
+
console.log(`\x1b[36m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(`%c${this.prefix}%c ${message}`, 'color: #06b6d4; font-weight: bold', 'color: inherit', ...args);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Warning log - only outputs when debug: true
|
|
44
|
+
*/
|
|
45
|
+
warn(message, ...args) {
|
|
46
|
+
if (!this.debug)
|
|
47
|
+
return;
|
|
48
|
+
if (this.isNode()) {
|
|
49
|
+
console.warn(`\x1b[33m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.warn(`%c${this.prefix}%c ${message}`, 'color: #eab308; font-weight: bold', 'color: inherit', ...args);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Error log - always outputs (errors should always be visible)
|
|
57
|
+
*/
|
|
58
|
+
error(message, ...args) {
|
|
59
|
+
if (this.isNode()) {
|
|
60
|
+
console.error(`\x1b[31m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error(`%c${this.prefix}%c ${message}`, 'color: #ef4444; font-weight: bold', 'color: inherit', ...args);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.SDKLogger = SDKLogger;
|
|
17
68
|
const assetDocument = `query asset($id: ID!) {
|
|
18
69
|
asset(id: $id) {
|
|
19
70
|
id
|
|
@@ -2203,6 +2254,7 @@ class BaseGraphQLClient {
|
|
|
2203
2254
|
this.endpoint = config.endpoint || 'https://api.forgecart.com/shop-api';
|
|
2204
2255
|
this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/shop-api';
|
|
2205
2256
|
this.config = config;
|
|
2257
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
2206
2258
|
// Custom fetch that captures session token from response headers
|
|
2207
2259
|
const customFetch = async (url, options) => {
|
|
2208
2260
|
const response = await fetch(url, options);
|
|
@@ -2252,13 +2304,13 @@ class BaseGraphQLClient {
|
|
|
2252
2304
|
transport = 'WebSocket';
|
|
2253
2305
|
const result = await this.requestViaWebSocket(document, variables);
|
|
2254
2306
|
if (this.config.debug) {
|
|
2255
|
-
|
|
2307
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
2256
2308
|
}
|
|
2257
2309
|
return result;
|
|
2258
2310
|
}
|
|
2259
2311
|
catch (wsError) {
|
|
2260
2312
|
transport = 'WebSocket -> HTTP';
|
|
2261
|
-
|
|
2313
|
+
this.logger.warn('WebSocket request failed, falling back to HTTP:', wsError);
|
|
2262
2314
|
// Fall through to HTTP
|
|
2263
2315
|
}
|
|
2264
2316
|
}
|
|
@@ -2266,13 +2318,13 @@ class BaseGraphQLClient {
|
|
|
2266
2318
|
try {
|
|
2267
2319
|
const result = await this.httpClient.request(document, variables);
|
|
2268
2320
|
if (this.config.debug) {
|
|
2269
|
-
|
|
2321
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
2270
2322
|
}
|
|
2271
2323
|
return result;
|
|
2272
2324
|
}
|
|
2273
2325
|
catch (error) {
|
|
2274
2326
|
if (this.config.debug) {
|
|
2275
|
-
|
|
2327
|
+
this.logger.log(`${operationName} (${transport}) - FAILED after ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
2276
2328
|
}
|
|
2277
2329
|
this.handleError(error);
|
|
2278
2330
|
throw error;
|
|
@@ -2314,7 +2366,7 @@ class BaseGraphQLClient {
|
|
|
2314
2366
|
* Handle GraphQL errors
|
|
2315
2367
|
*/
|
|
2316
2368
|
handleError(error) {
|
|
2317
|
-
|
|
2369
|
+
this.logger.error('GraphQL Error:', error);
|
|
2318
2370
|
}
|
|
2319
2371
|
/**
|
|
2320
2372
|
* Get WebSocket implementation for current environment
|
|
@@ -2334,7 +2386,7 @@ class BaseGraphQLClient {
|
|
|
2334
2386
|
return require('ws');
|
|
2335
2387
|
}
|
|
2336
2388
|
catch (e) {
|
|
2337
|
-
|
|
2389
|
+
this.logger.warn('WebSocket not available. Install "ws" package for Node.js support or provide webSocketImpl in config.');
|
|
2338
2390
|
return undefined;
|
|
2339
2391
|
}
|
|
2340
2392
|
}
|
|
@@ -2353,7 +2405,7 @@ class BaseGraphQLClient {
|
|
|
2353
2405
|
}
|
|
2354
2406
|
const WebSocketImpl = this.getWebSocketImpl();
|
|
2355
2407
|
if (!WebSocketImpl) {
|
|
2356
|
-
|
|
2408
|
+
this.logger.warn('WebSocket not available. Will use HTTP fallback only.');
|
|
2357
2409
|
return;
|
|
2358
2410
|
}
|
|
2359
2411
|
this.wsInitializing = new Promise((resolve, reject) => {
|
|
@@ -2382,7 +2434,7 @@ class BaseGraphQLClient {
|
|
|
2382
2434
|
return params;
|
|
2383
2435
|
}
|
|
2384
2436
|
catch (error) {
|
|
2385
|
-
|
|
2437
|
+
this.logger.error('Error in connectionParams:', error);
|
|
2386
2438
|
return {};
|
|
2387
2439
|
}
|
|
2388
2440
|
},
|
|
@@ -2395,7 +2447,7 @@ class BaseGraphQLClient {
|
|
|
2395
2447
|
on: {
|
|
2396
2448
|
connected: () => {
|
|
2397
2449
|
this.wsConnected = true;
|
|
2398
|
-
|
|
2450
|
+
this.logger.log('WebSocket connected');
|
|
2399
2451
|
if (!isResolved) {
|
|
2400
2452
|
isResolved = true;
|
|
2401
2453
|
resolve();
|
|
@@ -2404,13 +2456,13 @@ class BaseGraphQLClient {
|
|
|
2404
2456
|
closed: () => {
|
|
2405
2457
|
this.wsConnected = false;
|
|
2406
2458
|
if (!this.isDisposing) {
|
|
2407
|
-
|
|
2459
|
+
this.logger.log('WebSocket disconnected');
|
|
2408
2460
|
}
|
|
2409
2461
|
},
|
|
2410
2462
|
error: (error) => {
|
|
2411
2463
|
// Suppress errors during disposal - they're expected
|
|
2412
2464
|
if (!this.isDisposing && this.wsConnected) {
|
|
2413
|
-
|
|
2465
|
+
this.logger.error('WebSocket error:', error);
|
|
2414
2466
|
}
|
|
2415
2467
|
// Don't fail the connection on errors - let retry logic handle it
|
|
2416
2468
|
// Only log errors if we're connected (unexpected errors)
|
|
@@ -2422,7 +2474,7 @@ class BaseGraphQLClient {
|
|
|
2422
2474
|
this.wsInitializing = null;
|
|
2423
2475
|
}
|
|
2424
2476
|
catch (error) {
|
|
2425
|
-
|
|
2477
|
+
this.logger.error('Failed to create WebSocket client:', error);
|
|
2426
2478
|
this.wsInitializing = null;
|
|
2427
2479
|
// Resolve anyway to not block - we'll fallback to HTTP
|
|
2428
2480
|
if (!isResolved) {
|
|
@@ -3034,6 +3086,7 @@ class SearchOperations {
|
|
|
3034
3086
|
class ShopNamespace {
|
|
3035
3087
|
constructor(config) {
|
|
3036
3088
|
this.client = new BaseGraphQLClient(config);
|
|
3089
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
3037
3090
|
this.asset = new AssetOperations(this.client);
|
|
3038
3091
|
this.auth = new AuthOperations(this.client);
|
|
3039
3092
|
this.blog = new BlogOperations(this.client);
|
package/package.json
CHANGED
package/src/admin-namespace.ts
CHANGED
|
@@ -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-
|
|
7
|
+
* Generated at: 2025-12-17T10:24:29.306Z
|
|
8
8
|
* Generator version: 1.0.0
|
|
9
9
|
*
|
|
10
10
|
* 🤖 Generated with ForgeCart SDK Generator
|
|
@@ -34,6 +34,58 @@ export interface SDKConfig {
|
|
|
34
34
|
debug?: boolean;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* SDK Logger - Cross-platform logging with colors
|
|
39
|
+
* Respects debug flag for log/warn, errors are always visible
|
|
40
|
+
*/
|
|
41
|
+
export class SDKLogger {
|
|
42
|
+
private debug: boolean;
|
|
43
|
+
private prefix = '[ForgeCart SDK]';
|
|
44
|
+
|
|
45
|
+
constructor(debug: boolean = false) {
|
|
46
|
+
this.debug = debug;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private isNode(): boolean {
|
|
50
|
+
return typeof process !== 'undefined' && process.versions?.node != null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Debug log - only outputs when debug: true
|
|
55
|
+
*/
|
|
56
|
+
log(message: string, ...args: unknown[]): void {
|
|
57
|
+
if (!this.debug) return;
|
|
58
|
+
if (this.isNode()) {
|
|
59
|
+
console.log(`\x1b[36m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
60
|
+
} else {
|
|
61
|
+
console.log(`%c${this.prefix}%c ${message}`, 'color: #06b6d4; font-weight: bold', 'color: inherit', ...args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Warning log - only outputs when debug: true
|
|
67
|
+
*/
|
|
68
|
+
warn(message: string, ...args: unknown[]): void {
|
|
69
|
+
if (!this.debug) return;
|
|
70
|
+
if (this.isNode()) {
|
|
71
|
+
console.warn(`\x1b[33m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
72
|
+
} else {
|
|
73
|
+
console.warn(`%c${this.prefix}%c ${message}`, 'color: #eab308; font-weight: bold', 'color: inherit', ...args);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Error log - always outputs (errors should always be visible)
|
|
79
|
+
*/
|
|
80
|
+
error(message: string, ...args: unknown[]): void {
|
|
81
|
+
if (this.isNode()) {
|
|
82
|
+
console.error(`\x1b[31m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
83
|
+
} else {
|
|
84
|
+
console.error(`%c${this.prefix}%c ${message}`, 'color: #ef4444; font-weight: bold', 'color: inherit', ...args);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
37
89
|
export type ActiveAdministratorQueryVariables = Types.ActiveAdministratorQueryVariables;
|
|
38
90
|
export type ActiveAdministratorQuery = Types.ActiveAdministratorQuery;
|
|
39
91
|
export type ActiveAdministratorQueryResult = Types.ActiveAdministratorQuery;
|
|
@@ -8172,11 +8224,13 @@ class BaseGraphQLClient {
|
|
|
8172
8224
|
private endpoint: string;
|
|
8173
8225
|
private wsEndpoint: string;
|
|
8174
8226
|
private config: SDKConfig;
|
|
8227
|
+
private logger: SDKLogger;
|
|
8175
8228
|
|
|
8176
8229
|
constructor(config: SDKConfig) {
|
|
8177
8230
|
this.endpoint = config.endpoint || 'https://api.forgecart.com/admin-api';
|
|
8178
8231
|
this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/admin-api';
|
|
8179
8232
|
this.config = config;
|
|
8233
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
8180
8234
|
|
|
8181
8235
|
// Custom fetch that captures session token from response headers
|
|
8182
8236
|
const customFetch = async (url: RequestInfo | URL, options?: RequestInit): Promise<Response> => {
|
|
@@ -8238,12 +8292,12 @@ class BaseGraphQLClient {
|
|
|
8238
8292
|
transport = 'WebSocket';
|
|
8239
8293
|
const result = await this.requestViaWebSocket<T>(document, variables);
|
|
8240
8294
|
if (this.config.debug) {
|
|
8241
|
-
|
|
8295
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
8242
8296
|
}
|
|
8243
8297
|
return result;
|
|
8244
8298
|
} catch (wsError) {
|
|
8245
8299
|
transport = 'WebSocket -> HTTP';
|
|
8246
|
-
|
|
8300
|
+
this.logger.warn('WebSocket request failed, falling back to HTTP:', wsError);
|
|
8247
8301
|
// Fall through to HTTP
|
|
8248
8302
|
}
|
|
8249
8303
|
}
|
|
@@ -8253,12 +8307,12 @@ class BaseGraphQLClient {
|
|
|
8253
8307
|
try {
|
|
8254
8308
|
const result = await this.httpClient.request<T>(document, variables);
|
|
8255
8309
|
if (this.config.debug) {
|
|
8256
|
-
|
|
8310
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
8257
8311
|
}
|
|
8258
8312
|
return result;
|
|
8259
8313
|
} catch (error) {
|
|
8260
8314
|
if (this.config.debug) {
|
|
8261
|
-
|
|
8315
|
+
this.logger.log(`${operationName} (${transport}) - FAILED after ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
8262
8316
|
}
|
|
8263
8317
|
this.handleError(error);
|
|
8264
8318
|
throw error;
|
|
@@ -8311,7 +8365,7 @@ class BaseGraphQLClient {
|
|
|
8311
8365
|
* Handle GraphQL errors
|
|
8312
8366
|
*/
|
|
8313
8367
|
private handleError(error: any): void {
|
|
8314
|
-
|
|
8368
|
+
this.logger.error('GraphQL Error:', error);
|
|
8315
8369
|
}
|
|
8316
8370
|
|
|
8317
8371
|
|
|
@@ -8334,7 +8388,7 @@ class BaseGraphQLClient {
|
|
|
8334
8388
|
// Dynamic import for Node.js
|
|
8335
8389
|
return require('ws');
|
|
8336
8390
|
} catch (e) {
|
|
8337
|
-
|
|
8391
|
+
this.logger.warn('WebSocket not available. Install "ws" package for Node.js support or provide webSocketImpl in config.');
|
|
8338
8392
|
return undefined;
|
|
8339
8393
|
}
|
|
8340
8394
|
}
|
|
@@ -8356,7 +8410,7 @@ class BaseGraphQLClient {
|
|
|
8356
8410
|
|
|
8357
8411
|
const WebSocketImpl = this.getWebSocketImpl();
|
|
8358
8412
|
if (!WebSocketImpl) {
|
|
8359
|
-
|
|
8413
|
+
this.logger.warn('WebSocket not available. Will use HTTP fallback only.');
|
|
8360
8414
|
return;
|
|
8361
8415
|
}
|
|
8362
8416
|
|
|
@@ -8389,7 +8443,7 @@ class BaseGraphQLClient {
|
|
|
8389
8443
|
|
|
8390
8444
|
return params;
|
|
8391
8445
|
} catch (error) {
|
|
8392
|
-
|
|
8446
|
+
this.logger.error('Error in connectionParams:', error);
|
|
8393
8447
|
return {};
|
|
8394
8448
|
}
|
|
8395
8449
|
},
|
|
@@ -8402,7 +8456,7 @@ class BaseGraphQLClient {
|
|
|
8402
8456
|
on: {
|
|
8403
8457
|
connected: () => {
|
|
8404
8458
|
this.wsConnected = true;
|
|
8405
|
-
|
|
8459
|
+
this.logger.log('WebSocket connected');
|
|
8406
8460
|
if (!isResolved) {
|
|
8407
8461
|
isResolved = true;
|
|
8408
8462
|
resolve();
|
|
@@ -8411,13 +8465,13 @@ class BaseGraphQLClient {
|
|
|
8411
8465
|
closed: () => {
|
|
8412
8466
|
this.wsConnected = false;
|
|
8413
8467
|
if (!this.isDisposing) {
|
|
8414
|
-
|
|
8468
|
+
this.logger.log('WebSocket disconnected');
|
|
8415
8469
|
}
|
|
8416
8470
|
},
|
|
8417
8471
|
error: (error) => {
|
|
8418
8472
|
// Suppress errors during disposal - they're expected
|
|
8419
8473
|
if (!this.isDisposing && this.wsConnected) {
|
|
8420
|
-
|
|
8474
|
+
this.logger.error('WebSocket error:', error);
|
|
8421
8475
|
}
|
|
8422
8476
|
// Don't fail the connection on errors - let retry logic handle it
|
|
8423
8477
|
// Only log errors if we're connected (unexpected errors)
|
|
@@ -8429,7 +8483,7 @@ class BaseGraphQLClient {
|
|
|
8429
8483
|
this.wsClient = createClient(wsOptions);
|
|
8430
8484
|
this.wsInitializing = null;
|
|
8431
8485
|
} catch (error) {
|
|
8432
|
-
|
|
8486
|
+
this.logger.error('Failed to create WebSocket client:', error);
|
|
8433
8487
|
this.wsInitializing = null;
|
|
8434
8488
|
// Resolve anyway to not block - we'll fallback to HTTP
|
|
8435
8489
|
if (!isResolved) {
|
|
@@ -11083,6 +11137,7 @@ class ZoneOperations {
|
|
|
11083
11137
|
*/
|
|
11084
11138
|
export class AdminNamespace {
|
|
11085
11139
|
private client: BaseGraphQLClient;
|
|
11140
|
+
private logger: SDKLogger;
|
|
11086
11141
|
|
|
11087
11142
|
readonly administrator: AdministratorOperations;
|
|
11088
11143
|
readonly asset: AssetOperations;
|
|
@@ -11141,6 +11196,7 @@ export class AdminNamespace {
|
|
|
11141
11196
|
|
|
11142
11197
|
constructor(config: SDKConfig) {
|
|
11143
11198
|
this.client = new BaseGraphQLClient(config);
|
|
11199
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
11144
11200
|
|
|
11145
11201
|
this.administrator = new AdministratorOperations(this.client);
|
|
11146
11202
|
this.asset = new AssetOperations(this.client);
|
|
@@ -11275,7 +11331,7 @@ export class AdminNamespace {
|
|
|
11275
11331
|
}
|
|
11276
11332
|
} catch (error) {
|
|
11277
11333
|
if (this.isListening) {
|
|
11278
|
-
|
|
11334
|
+
this.logger.error('Event subscription error:', error);
|
|
11279
11335
|
await this.handleReconnect();
|
|
11280
11336
|
}
|
|
11281
11337
|
}
|
|
@@ -11296,7 +11352,7 @@ export class AdminNamespace {
|
|
|
11296
11352
|
);
|
|
11297
11353
|
|
|
11298
11354
|
this.retryCount++;
|
|
11299
|
-
|
|
11355
|
+
this.logger.log(`Reconnecting in ${delay}ms (attempt ${this.retryCount}/${maxRetries})`);
|
|
11300
11356
|
|
|
11301
11357
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
11302
11358
|
await this.startSubscription();
|
|
@@ -11315,7 +11371,7 @@ export class AdminNamespace {
|
|
|
11315
11371
|
try {
|
|
11316
11372
|
handler(event);
|
|
11317
11373
|
} catch (error) {
|
|
11318
|
-
|
|
11374
|
+
this.logger.error(`Error in event handler for ${eventName}:`, error);
|
|
11319
11375
|
}
|
|
11320
11376
|
}
|
|
11321
11377
|
}
|
|
@@ -11331,7 +11387,7 @@ export class AdminNamespace {
|
|
|
11331
11387
|
`Blocking handler for ${eventName} exceeded ${AdminNamespace.BLOCKING_TIMEOUT_MS}ms`
|
|
11332
11388
|
);
|
|
11333
11389
|
} catch (error) {
|
|
11334
|
-
|
|
11390
|
+
this.logger.error(`Error in blocking event handler for ${eventName}:`, error);
|
|
11335
11391
|
throw error; // Re-throw for blocking handlers
|
|
11336
11392
|
}
|
|
11337
11393
|
}
|
package/src/admin-types.ts
CHANGED
|
@@ -1063,6 +1063,7 @@ export type CreateCustomerInput = {
|
|
|
1063
1063
|
export type CreateCustomerResult = Customer | EmailAddressConflictError;
|
|
1064
1064
|
|
|
1065
1065
|
export type CreateDeploymentInput = {
|
|
1066
|
+
envVars?: InputMaybe<Array<EnvVarInput>>;
|
|
1066
1067
|
type: DeploymentType;
|
|
1067
1068
|
};
|
|
1068
1069
|
|
|
@@ -2095,6 +2096,11 @@ export type EntityEventType =
|
|
|
2095
2096
|
| 'removed'
|
|
2096
2097
|
| 'updated';
|
|
2097
2098
|
|
|
2099
|
+
export type EnvVarInput = {
|
|
2100
|
+
key: Scalars['String']['input'];
|
|
2101
|
+
value: Scalars['String']['input'];
|
|
2102
|
+
};
|
|
2103
|
+
|
|
2098
2104
|
export type ErrorCode =
|
|
2099
2105
|
| 'ALREADY_REFUNDED_ERROR'
|
|
2100
2106
|
| 'CANCEL_ACTIVE_ORDER_ERROR'
|
|
@@ -7389,9 +7395,8 @@ export type SessionInput = {
|
|
|
7389
7395
|
export type SetCustomerForDraftOrderResult = EmailAddressConflictError | Order;
|
|
7390
7396
|
|
|
7391
7397
|
export type SetEnvInput = {
|
|
7392
|
-
|
|
7398
|
+
envVars: Array<EnvVarInput>;
|
|
7393
7399
|
type: DeploymentType;
|
|
7394
|
-
value: Scalars['String']['input'];
|
|
7395
7400
|
};
|
|
7396
7401
|
|
|
7397
7402
|
export type SetOrderCustomerInput = {
|
|
@@ -8078,7 +8083,7 @@ export type TransitionOrderToStateResult = Order | OrderStateTransitionError;
|
|
|
8078
8083
|
export type TransitionPaymentToStateResult = Payment | PaymentStateTransitionError;
|
|
8079
8084
|
|
|
8080
8085
|
export type UnsetEnvInput = {
|
|
8081
|
-
|
|
8086
|
+
keys: Array<Scalars['String']['input']>;
|
|
8082
8087
|
type: DeploymentType;
|
|
8083
8088
|
};
|
|
8084
8089
|
|
package/src/shop-namespace.ts
CHANGED
|
@@ -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-
|
|
7
|
+
* Generated at: 2025-12-17T10:24:29.175Z
|
|
8
8
|
* Generator version: 1.0.0
|
|
9
9
|
*
|
|
10
10
|
* 🤖 Generated with ForgeCart SDK Generator
|
|
@@ -34,6 +34,58 @@ export interface SDKConfig {
|
|
|
34
34
|
debug?: boolean;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* SDK Logger - Cross-platform logging with colors
|
|
39
|
+
* Respects debug flag for log/warn, errors are always visible
|
|
40
|
+
*/
|
|
41
|
+
export class SDKLogger {
|
|
42
|
+
private debug: boolean;
|
|
43
|
+
private prefix = '[ForgeCart SDK]';
|
|
44
|
+
|
|
45
|
+
constructor(debug: boolean = false) {
|
|
46
|
+
this.debug = debug;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private isNode(): boolean {
|
|
50
|
+
return typeof process !== 'undefined' && process.versions?.node != null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Debug log - only outputs when debug: true
|
|
55
|
+
*/
|
|
56
|
+
log(message: string, ...args: unknown[]): void {
|
|
57
|
+
if (!this.debug) return;
|
|
58
|
+
if (this.isNode()) {
|
|
59
|
+
console.log(`\x1b[36m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
60
|
+
} else {
|
|
61
|
+
console.log(`%c${this.prefix}%c ${message}`, 'color: #06b6d4; font-weight: bold', 'color: inherit', ...args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Warning log - only outputs when debug: true
|
|
67
|
+
*/
|
|
68
|
+
warn(message: string, ...args: unknown[]): void {
|
|
69
|
+
if (!this.debug) return;
|
|
70
|
+
if (this.isNode()) {
|
|
71
|
+
console.warn(`\x1b[33m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
72
|
+
} else {
|
|
73
|
+
console.warn(`%c${this.prefix}%c ${message}`, 'color: #eab308; font-weight: bold', 'color: inherit', ...args);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Error log - always outputs (errors should always be visible)
|
|
79
|
+
*/
|
|
80
|
+
error(message: string, ...args: unknown[]): void {
|
|
81
|
+
if (this.isNode()) {
|
|
82
|
+
console.error(`\x1b[31m${this.prefix}\x1b[0m ${message}`, ...args);
|
|
83
|
+
} else {
|
|
84
|
+
console.error(`%c${this.prefix}%c ${message}`, 'color: #ef4444; font-weight: bold', 'color: inherit', ...args);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
37
89
|
export type AssetQueryVariables = Types.AssetQueryVariables;
|
|
38
90
|
export type AssetQuery = Types.AssetQuery;
|
|
39
91
|
export type AssetQueryResult = Types.AssetQuery;
|
|
@@ -2496,11 +2548,13 @@ class BaseGraphQLClient {
|
|
|
2496
2548
|
private endpoint: string;
|
|
2497
2549
|
private wsEndpoint: string;
|
|
2498
2550
|
private config: SDKConfig;
|
|
2551
|
+
private logger: SDKLogger;
|
|
2499
2552
|
|
|
2500
2553
|
constructor(config: SDKConfig) {
|
|
2501
2554
|
this.endpoint = config.endpoint || 'https://api.forgecart.com/shop-api';
|
|
2502
2555
|
this.wsEndpoint = config.wsEndpoint || 'wss://api.forgecart.com/shop-api';
|
|
2503
2556
|
this.config = config;
|
|
2557
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
2504
2558
|
|
|
2505
2559
|
// Custom fetch that captures session token from response headers
|
|
2506
2560
|
const customFetch = async (url: RequestInfo | URL, options?: RequestInit): Promise<Response> => {
|
|
@@ -2562,12 +2616,12 @@ class BaseGraphQLClient {
|
|
|
2562
2616
|
transport = 'WebSocket';
|
|
2563
2617
|
const result = await this.requestViaWebSocket<T>(document, variables);
|
|
2564
2618
|
if (this.config.debug) {
|
|
2565
|
-
|
|
2619
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
2566
2620
|
}
|
|
2567
2621
|
return result;
|
|
2568
2622
|
} catch (wsError) {
|
|
2569
2623
|
transport = 'WebSocket -> HTTP';
|
|
2570
|
-
|
|
2624
|
+
this.logger.warn('WebSocket request failed, falling back to HTTP:', wsError);
|
|
2571
2625
|
// Fall through to HTTP
|
|
2572
2626
|
}
|
|
2573
2627
|
}
|
|
@@ -2577,12 +2631,12 @@ class BaseGraphQLClient {
|
|
|
2577
2631
|
try {
|
|
2578
2632
|
const result = await this.httpClient.request<T>(document, variables);
|
|
2579
2633
|
if (this.config.debug) {
|
|
2580
|
-
|
|
2634
|
+
this.logger.log(`${operationName} (${transport}) - ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
2581
2635
|
}
|
|
2582
2636
|
return result;
|
|
2583
2637
|
} catch (error) {
|
|
2584
2638
|
if (this.config.debug) {
|
|
2585
|
-
|
|
2639
|
+
this.logger.log(`${operationName} (${transport}) - FAILED after ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
2586
2640
|
}
|
|
2587
2641
|
this.handleError(error);
|
|
2588
2642
|
throw error;
|
|
@@ -2635,7 +2689,7 @@ class BaseGraphQLClient {
|
|
|
2635
2689
|
* Handle GraphQL errors
|
|
2636
2690
|
*/
|
|
2637
2691
|
private handleError(error: any): void {
|
|
2638
|
-
|
|
2692
|
+
this.logger.error('GraphQL Error:', error);
|
|
2639
2693
|
}
|
|
2640
2694
|
|
|
2641
2695
|
|
|
@@ -2658,7 +2712,7 @@ class BaseGraphQLClient {
|
|
|
2658
2712
|
// Dynamic import for Node.js
|
|
2659
2713
|
return require('ws');
|
|
2660
2714
|
} catch (e) {
|
|
2661
|
-
|
|
2715
|
+
this.logger.warn('WebSocket not available. Install "ws" package for Node.js support or provide webSocketImpl in config.');
|
|
2662
2716
|
return undefined;
|
|
2663
2717
|
}
|
|
2664
2718
|
}
|
|
@@ -2680,7 +2734,7 @@ class BaseGraphQLClient {
|
|
|
2680
2734
|
|
|
2681
2735
|
const WebSocketImpl = this.getWebSocketImpl();
|
|
2682
2736
|
if (!WebSocketImpl) {
|
|
2683
|
-
|
|
2737
|
+
this.logger.warn('WebSocket not available. Will use HTTP fallback only.');
|
|
2684
2738
|
return;
|
|
2685
2739
|
}
|
|
2686
2740
|
|
|
@@ -2713,7 +2767,7 @@ class BaseGraphQLClient {
|
|
|
2713
2767
|
|
|
2714
2768
|
return params;
|
|
2715
2769
|
} catch (error) {
|
|
2716
|
-
|
|
2770
|
+
this.logger.error('Error in connectionParams:', error);
|
|
2717
2771
|
return {};
|
|
2718
2772
|
}
|
|
2719
2773
|
},
|
|
@@ -2726,7 +2780,7 @@ class BaseGraphQLClient {
|
|
|
2726
2780
|
on: {
|
|
2727
2781
|
connected: () => {
|
|
2728
2782
|
this.wsConnected = true;
|
|
2729
|
-
|
|
2783
|
+
this.logger.log('WebSocket connected');
|
|
2730
2784
|
if (!isResolved) {
|
|
2731
2785
|
isResolved = true;
|
|
2732
2786
|
resolve();
|
|
@@ -2735,13 +2789,13 @@ class BaseGraphQLClient {
|
|
|
2735
2789
|
closed: () => {
|
|
2736
2790
|
this.wsConnected = false;
|
|
2737
2791
|
if (!this.isDisposing) {
|
|
2738
|
-
|
|
2792
|
+
this.logger.log('WebSocket disconnected');
|
|
2739
2793
|
}
|
|
2740
2794
|
},
|
|
2741
2795
|
error: (error) => {
|
|
2742
2796
|
// Suppress errors during disposal - they're expected
|
|
2743
2797
|
if (!this.isDisposing && this.wsConnected) {
|
|
2744
|
-
|
|
2798
|
+
this.logger.error('WebSocket error:', error);
|
|
2745
2799
|
}
|
|
2746
2800
|
// Don't fail the connection on errors - let retry logic handle it
|
|
2747
2801
|
// Only log errors if we're connected (unexpected errors)
|
|
@@ -2753,7 +2807,7 @@ class BaseGraphQLClient {
|
|
|
2753
2807
|
this.wsClient = createClient(wsOptions);
|
|
2754
2808
|
this.wsInitializing = null;
|
|
2755
2809
|
} catch (error) {
|
|
2756
|
-
|
|
2810
|
+
this.logger.error('Failed to create WebSocket client:', error);
|
|
2757
2811
|
this.wsInitializing = null;
|
|
2758
2812
|
// Resolve anyway to not block - we'll fallback to HTTP
|
|
2759
2813
|
if (!isResolved) {
|
|
@@ -3433,6 +3487,7 @@ class SearchOperations {
|
|
|
3433
3487
|
*/
|
|
3434
3488
|
export class ShopNamespace {
|
|
3435
3489
|
private client: BaseGraphQLClient;
|
|
3490
|
+
private logger: SDKLogger;
|
|
3436
3491
|
|
|
3437
3492
|
readonly asset: AssetOperations;
|
|
3438
3493
|
readonly auth: AuthOperations;
|
|
@@ -3450,6 +3505,7 @@ export class ShopNamespace {
|
|
|
3450
3505
|
|
|
3451
3506
|
constructor(config: SDKConfig) {
|
|
3452
3507
|
this.client = new BaseGraphQLClient(config);
|
|
3508
|
+
this.logger = new SDKLogger(config?.debug ?? false);
|
|
3453
3509
|
|
|
3454
3510
|
this.asset = new AssetOperations(this.client);
|
|
3455
3511
|
this.auth = new AuthOperations(this.client);
|