@forgecart/sdk 1.2.5 → 1.2.6

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 (58) hide show
  1. package/README.md +2 -87
  2. package/dist/admin-types.generated.d.ts +9884 -0
  3. package/dist/admin.d.ts +55 -8
  4. package/dist/admin.generated.d.ts +790 -0
  5. package/dist/admin.generated.js +1801 -0
  6. package/dist/admin.js +112 -23
  7. package/dist/client.generated.d.ts +251 -0
  8. package/dist/client.generated.js +757 -0
  9. package/dist/documents.generated.d.ts +465 -0
  10. package/dist/documents.generated.js +24283 -0
  11. package/dist/error-utils.d.ts +25 -0
  12. package/dist/error-utils.js +59 -0
  13. package/dist/hook-event-map.generated.d.ts +243 -0
  14. package/dist/hook-event-map.generated.js +9 -0
  15. package/dist/index.d.ts +23 -59
  16. package/dist/index.js +35 -83
  17. package/dist/sdk-hook-subscription.generated.d.ts +29 -0
  18. package/dist/sdk-hook-subscription.generated.js +73 -0
  19. package/dist/sdk-plugin.generated.d.ts +38 -0
  20. package/dist/sdk-plugin.generated.js +31 -0
  21. package/dist/sdk-types.generated.d.ts +56 -0
  22. package/dist/sdk-types.generated.js +28 -0
  23. package/dist/shop-types.generated.d.ts +4776 -0
  24. package/dist/shop.d.ts +18 -8
  25. package/dist/shop.generated.d.ts +213 -0
  26. package/dist/shop.generated.js +465 -0
  27. package/dist/shop.js +37 -23
  28. package/dist/upload.d.ts +14 -0
  29. package/dist/upload.js +163 -0
  30. package/package.json +10 -25
  31. package/src/admin-types.generated.ts +28377 -0
  32. package/src/admin.generated.ts +1771 -0
  33. package/src/admin.ts +55 -9
  34. package/src/client.generated.ts +845 -0
  35. package/src/documents.generated.ts +24730 -0
  36. package/src/error-utils.ts +74 -0
  37. package/src/hook-event-map.generated.ts +252 -0
  38. package/src/index.ts +23 -115
  39. package/src/sdk-hook-subscription.generated.ts +93 -0
  40. package/src/sdk-plugin.generated.ts +59 -0
  41. package/src/sdk-types.generated.ts +79 -0
  42. package/src/shop-types.generated.ts +10400 -0
  43. package/src/shop.generated.ts +452 -0
  44. package/src/shop.ts +18 -9
  45. package/src/upload.ts +211 -0
  46. package/LICENSE +0 -21
  47. package/dist/admin-namespace.d.ts +0 -2688
  48. package/dist/admin-namespace.js +0 -9691
  49. package/dist/admin-types.d.ts +0 -16195
  50. package/dist/shop-namespace.d.ts +0 -718
  51. package/dist/shop-namespace.js +0 -3124
  52. package/dist/shop-types.d.ts +0 -6310
  53. package/src/admin-namespace.ts +0 -11428
  54. package/src/admin-types.ts +0 -10809
  55. package/src/shop-namespace.ts +0 -3547
  56. package/src/shop-types.ts +0 -4684
  57. /package/dist/{admin-types.js → admin-types.generated.js} +0 -0
  58. /package/dist/{shop-types.js → shop-types.generated.js} +0 -0
@@ -0,0 +1,25 @@
1
+ export interface ExtractedError {
2
+ code: string;
3
+ variables: Record<string, string>;
4
+ classification: string;
5
+ message?: string;
6
+ }
7
+ /**
8
+ * Extract the structured error code from a ClientError.
9
+ * Returns null if the error has no GraphQL error code.
10
+ */
11
+ export declare function extractErrorCode(error: unknown): string | null;
12
+ /**
13
+ * Extract full structured error info from a ClientError.
14
+ * Returns null if the error has no GraphQL extensions.
15
+ */
16
+ export declare function extractError(error: unknown): ExtractedError | null;
17
+ /**
18
+ * Extract the localized error message from a ClientError.
19
+ * Returns null if the error has no localized message.
20
+ */
21
+ export declare function extractErrorMessage(error: unknown): string | null;
22
+ /**
23
+ * Check if an error has a specific error code.
24
+ */
25
+ export declare function isErrorCode(error: unknown, code: string): boolean;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractErrorCode = extractErrorCode;
4
+ exports.extractError = extractError;
5
+ exports.extractErrorMessage = extractErrorMessage;
6
+ exports.isErrorCode = isErrorCode;
7
+ /**
8
+ * Get the first GraphQL error from an error object.
9
+ * Uses duck-typing so it works across bundler boundaries where instanceof fails.
10
+ */
11
+ function getFirstGraphQLError(error) {
12
+ const err = error;
13
+ const errors = err?.response?.errors;
14
+ if (!Array.isArray(errors) || errors.length === 0) {
15
+ return null;
16
+ }
17
+ return errors[0] ?? null;
18
+ }
19
+ /**
20
+ * Extract the structured error code from a ClientError.
21
+ * Returns null if the error has no GraphQL error code.
22
+ */
23
+ function extractErrorCode(error) {
24
+ const firstError = getFirstGraphQLError(error);
25
+ if (!firstError?.extensions?.['code']) {
26
+ return null;
27
+ }
28
+ return firstError.extensions['code'];
29
+ }
30
+ /**
31
+ * Extract full structured error info from a ClientError.
32
+ * Returns null if the error has no GraphQL extensions.
33
+ */
34
+ function extractError(error) {
35
+ const firstError = getFirstGraphQLError(error);
36
+ if (!firstError?.extensions) {
37
+ return null;
38
+ }
39
+ return {
40
+ code: firstError.extensions['code'] ?? firstError.message,
41
+ variables: firstError.extensions['variables'] ?? {},
42
+ classification: firstError.extensions['classification'] ?? 'UNKNOWN',
43
+ message: firstError.extensions['message'] ?? undefined,
44
+ };
45
+ }
46
+ /**
47
+ * Extract the localized error message from a ClientError.
48
+ * Returns null if the error has no localized message.
49
+ */
50
+ function extractErrorMessage(error) {
51
+ const firstError = getFirstGraphQLError(error);
52
+ return firstError?.extensions?.['message'] ?? null;
53
+ }
54
+ /**
55
+ * Check if an error has a specific error code.
56
+ */
57
+ function isErrorCode(error, code) {
58
+ return extractErrorCode(error) === code;
59
+ }
@@ -0,0 +1,243 @@
1
+ /**
2
+ * AUTO-GENERATED FILE — DO NOT EDIT
3
+ *
4
+ * This file was generated by @forgecart/client-sdk-generators.
5
+ * Any manual changes will be overwritten on the next generation run.
6
+ */
7
+ import type { AddIdentityToSegmentInput, Administrator, Asset, AudienceMembership, AudienceSegment, Channel, ChannelPlugin, Collection, Country, CreateAdministratorInput, CreateAssetInput, CreateAudienceSegmentInput, CreateChannelInput, CreateCollectionInput, CreateCountryInput, CreateCustomerGroupInput, CreateCustomerInput, CreateFacetInput, CreateFacetValueInput, CreateFulfillmentInput, CreateProductInput, CreateProductVariantInput, CreatePromotionInput, CreateRoleInput, CreateSellerInput, CreateStockLocationInput, CreateTaxCategoryInput, CreateTaxRateInput, CreateZoneInput, Customer, CustomerGroup, Facet, FacetValue, Fulfillment, HistoryEntry, Order, Product, ProductVariant, Promotion, RegisterCustomerInput, RemoveIdentityFromSegmentInput, Role, Seller, StockLocation, TaxCategory, TaxRate, UpdateAdministratorInput, UpdateAssetInput, UpdateAudienceSegmentInput, UpdateChannelInput, UpdateChannelPluginConfigInput, UpdateCollectionInput, UpdateCountryInput, UpdateCustomerGroupInput, UpdateCustomerInput, UpdateFacetInput, UpdateFacetValueInput, UpdateProductInput, UpdateProductVariantInput, UpdatePromotionInput, UpdateRoleInput, UpdateSellerInput, UpdateStockLocationInput, UpdateTaxCategoryInput, UpdateTaxRateInput, UpdateZoneInput, Zone } from './admin-types.generated';
8
+ import type { TransactionContext } from './client.generated';
9
+ export interface AdminHookEventMap {
10
+ 'asset.create.before': CreateAssetInput;
11
+ 'asset.create.after': Asset;
12
+ 'asset.create.async': Asset;
13
+ 'asset.update.before': UpdateAssetInput;
14
+ 'asset.update.after': Asset;
15
+ 'asset.update.async': Asset;
16
+ 'asset.executeSingleAssetDelete.before': void;
17
+ 'asset.executeSingleAssetDelete.after': Asset;
18
+ 'asset.executeSingleAssetDelete.async': Asset;
19
+ 'asset.createFromUrl.before': string;
20
+ 'asset.createFromUrl.after': Asset;
21
+ 'asset.createFromUrl.async': Asset;
22
+ 'administrator.create.before': CreateAdministratorInput;
23
+ 'administrator.create.after': Administrator;
24
+ 'administrator.create.async': Administrator;
25
+ 'administrator.update.before': UpdateAdministratorInput;
26
+ 'administrator.update.after': Administrator;
27
+ 'administrator.update.async': Administrator;
28
+ 'administrator.softDelete.before': string;
29
+ 'administrator.softDelete.after': Administrator;
30
+ 'administrator.softDelete.async': Administrator;
31
+ 'administrator.inviteExistingUser.before': void;
32
+ 'administrator.inviteExistingUser.after': Administrator;
33
+ 'administrator.inviteExistingUser.async': Administrator;
34
+ 'administrator.inviteNewUser.before': void;
35
+ 'administrator.inviteNewUser.after': Administrator;
36
+ 'administrator.inviteNewUser.async': Administrator;
37
+ 'authentication.attemptLogin.before': unknown;
38
+ 'authentication.attemptLogin.after': unknown;
39
+ 'authentication.attemptLogin.async': unknown;
40
+ 'role.create.before': CreateRoleInput;
41
+ 'role.create.after': Role;
42
+ 'role.create.async': Role;
43
+ 'role.update.before': UpdateRoleInput;
44
+ 'role.update.after': Role;
45
+ 'role.update.async': Role;
46
+ 'role.executeRoleDelete.before': void;
47
+ 'role.executeRoleDelete.after': Role;
48
+ 'role.executeRoleDelete.async': Role;
49
+ 'collection.create.before': CreateCollectionInput;
50
+ 'collection.create.after': Collection;
51
+ 'collection.create.async': Collection;
52
+ 'collection.update.before': UpdateCollectionInput;
53
+ 'collection.update.after': Collection;
54
+ 'collection.update.async': Collection;
55
+ 'collection.executeCollectionDelete.before': void;
56
+ 'collection.executeCollectionDelete.after': Collection;
57
+ 'collection.executeCollectionDelete.async': Collection;
58
+ 'facet.create.before': CreateFacetInput;
59
+ 'facet.create.after': Facet;
60
+ 'facet.create.async': Facet;
61
+ 'facet.update.before': UpdateFacetInput;
62
+ 'facet.update.after': Facet;
63
+ 'facet.update.async': Facet;
64
+ 'facet.executeFacetDelete.before': void;
65
+ 'facet.executeFacetDelete.after': Facet;
66
+ 'facet.executeFacetDelete.async': Facet;
67
+ 'facetValue.create.before': CreateFacetValueInput;
68
+ 'facetValue.create.after': FacetValue;
69
+ 'facetValue.create.async': FacetValue;
70
+ 'facetValue.update.before': UpdateFacetValueInput;
71
+ 'facetValue.update.after': FacetValue;
72
+ 'facetValue.update.async': FacetValue;
73
+ 'facetValue.executeFacetValueDelete.before': void;
74
+ 'facetValue.executeFacetValueDelete.after': FacetValue;
75
+ 'facetValue.executeFacetValueDelete.async': FacetValue;
76
+ 'channel.create.before': CreateChannelInput;
77
+ 'channel.create.after': Channel;
78
+ 'channel.create.async': Channel;
79
+ 'channel.update.before': UpdateChannelInput;
80
+ 'channel.update.after': Channel;
81
+ 'channel.update.async': Channel;
82
+ 'channel.delete.before': string;
83
+ 'channel.delete.after': Channel;
84
+ 'channel.delete.async': Channel;
85
+ 'customer.create.before': CreateCustomerInput;
86
+ 'customer.create.after': Customer;
87
+ 'customer.create.async': Customer;
88
+ 'customer.update.before': UpdateCustomerInput;
89
+ 'customer.update.after': Customer;
90
+ 'customer.update.async': Customer;
91
+ 'customer.performSoftDelete.before': string;
92
+ 'customer.performSoftDelete.after': Customer;
93
+ 'customer.performSoftDelete.async': Customer;
94
+ 'customer.registerCustomerAccount.before': RegisterCustomerInput;
95
+ 'customer.registerCustomerAccount.after': Customer;
96
+ 'customer.registerCustomerAccount.async': Customer;
97
+ 'customer.createCustomerForRegistration.before': void;
98
+ 'customer.createCustomerForRegistration.after': Customer;
99
+ 'customer.createCustomerForRegistration.async': Customer;
100
+ 'customerGroup.create.before': CreateCustomerGroupInput;
101
+ 'customerGroup.create.after': CustomerGroup;
102
+ 'customerGroup.create.async': CustomerGroup;
103
+ 'customerGroup.update.before': UpdateCustomerGroupInput;
104
+ 'customerGroup.update.after': CustomerGroup;
105
+ 'customerGroup.update.async': CustomerGroup;
106
+ 'customerGroup.executeCustomerGroupDelete.before': void;
107
+ 'customerGroup.executeCustomerGroupDelete.after': CustomerGroup;
108
+ 'customerGroup.executeCustomerGroupDelete.async': CustomerGroup;
109
+ 'country.create.before': CreateCountryInput;
110
+ 'country.create.after': Country;
111
+ 'country.create.async': Country;
112
+ 'country.update.before': UpdateCountryInput;
113
+ 'country.update.after': Country;
114
+ 'country.update.async': Country;
115
+ 'country.executeCountryDelete.before': void;
116
+ 'country.executeCountryDelete.after': Country;
117
+ 'country.executeCountryDelete.async': Country;
118
+ 'zone.create.before': CreateZoneInput;
119
+ 'zone.create.after': Zone;
120
+ 'zone.create.async': Zone;
121
+ 'zone.update.before': UpdateZoneInput;
122
+ 'zone.update.after': Zone;
123
+ 'zone.update.async': Zone;
124
+ 'zone.delete.before': string;
125
+ 'zone.delete.after': Zone;
126
+ 'zone.delete.async': Zone;
127
+ 'product.create.before': CreateProductInput;
128
+ 'product.create.after': Product;
129
+ 'product.create.async': Product;
130
+ 'product.update.before': UpdateProductInput;
131
+ 'product.update.after': Product;
132
+ 'product.update.async': Product;
133
+ 'product.executeProductDelete.before': void;
134
+ 'product.executeProductDelete.after': Product;
135
+ 'product.executeProductDelete.async': Product;
136
+ 'productVariant.createSingleVariant.before': CreateProductVariantInput;
137
+ 'productVariant.createSingleVariant.after': ProductVariant;
138
+ 'productVariant.createSingleVariant.async': ProductVariant;
139
+ 'productVariant.updateSingleVariant.before': UpdateProductVariantInput;
140
+ 'productVariant.updateSingleVariant.after': ProductVariant;
141
+ 'productVariant.updateSingleVariant.async': ProductVariant;
142
+ 'productVariant.deleteSingleVariant.before': string;
143
+ 'productVariant.deleteSingleVariant.after': ProductVariant;
144
+ 'productVariant.deleteSingleVariant.async': ProductVariant;
145
+ 'promotion.create.before': CreatePromotionInput;
146
+ 'promotion.create.after': Promotion;
147
+ 'promotion.create.async': Promotion;
148
+ 'promotion.update.before': UpdatePromotionInput;
149
+ 'promotion.update.after': Promotion;
150
+ 'promotion.update.async': Promotion;
151
+ 'promotion.executePromotionDelete.before': void;
152
+ 'promotion.executePromotionDelete.after': Promotion;
153
+ 'promotion.executePromotionDelete.async': Promotion;
154
+ 'seller.create.before': CreateSellerInput;
155
+ 'seller.create.after': Seller;
156
+ 'seller.create.async': Seller;
157
+ 'seller.update.before': UpdateSellerInput;
158
+ 'seller.update.after': Seller;
159
+ 'seller.update.async': Seller;
160
+ 'seller.softDelete.before': string;
161
+ 'seller.softDelete.after': Seller;
162
+ 'seller.softDelete.async': Seller;
163
+ 'stockLocation.create.before': CreateStockLocationInput;
164
+ 'stockLocation.create.after': StockLocation;
165
+ 'stockLocation.create.async': StockLocation;
166
+ 'stockLocation.update.before': UpdateStockLocationInput;
167
+ 'stockLocation.update.after': StockLocation;
168
+ 'stockLocation.update.async': StockLocation;
169
+ 'stockLocation.executeStockLocationDelete.before': void;
170
+ 'stockLocation.executeStockLocationDelete.after': StockLocation;
171
+ 'stockLocation.executeStockLocationDelete.async': StockLocation;
172
+ 'taxCategory.create.before': CreateTaxCategoryInput;
173
+ 'taxCategory.create.after': TaxCategory;
174
+ 'taxCategory.create.async': TaxCategory;
175
+ 'taxCategory.update.before': UpdateTaxCategoryInput;
176
+ 'taxCategory.update.after': TaxCategory;
177
+ 'taxCategory.update.async': TaxCategory;
178
+ 'taxCategory.executeTaxCategoryDelete.before': void;
179
+ 'taxCategory.executeTaxCategoryDelete.after': TaxCategory;
180
+ 'taxCategory.executeTaxCategoryDelete.async': TaxCategory;
181
+ 'taxRate.create.before': CreateTaxRateInput;
182
+ 'taxRate.create.after': TaxRate;
183
+ 'taxRate.create.async': TaxRate;
184
+ 'taxRate.update.before': UpdateTaxRateInput;
185
+ 'taxRate.update.after': TaxRate;
186
+ 'taxRate.update.async': TaxRate;
187
+ 'taxRate.delete.before': string;
188
+ 'taxRate.delete.after': TaxRate;
189
+ 'taxRate.delete.async': TaxRate;
190
+ 'fulfillment.createFulfillment.before': CreateFulfillmentInput;
191
+ 'fulfillment.createFulfillment.after': Fulfillment;
192
+ 'fulfillment.createFulfillment.async': Fulfillment;
193
+ 'fulfillment.executeFulfillmentTransition.before': unknown;
194
+ 'fulfillment.executeFulfillmentTransition.after': unknown;
195
+ 'fulfillment.executeFulfillmentTransition.async': unknown;
196
+ 'order.createDraft.before': void;
197
+ 'order.createDraft.after': Order;
198
+ 'order.createDraft.async': Order;
199
+ 'order.create.before': void;
200
+ 'order.create.after': Order;
201
+ 'order.create.async': Order;
202
+ 'payment.executePaymentTransition.before': unknown;
203
+ 'payment.executePaymentTransition.after': unknown;
204
+ 'payment.executePaymentTransition.async': unknown;
205
+ 'channelPlugin.enable.before': string;
206
+ 'channelPlugin.enable.after': ChannelPlugin;
207
+ 'channelPlugin.enable.async': ChannelPlugin;
208
+ 'channelPlugin.disable.before': string;
209
+ 'channelPlugin.disable.after': ChannelPlugin;
210
+ 'channelPlugin.disable.async': ChannelPlugin;
211
+ 'channelPlugin.updateConfiguration.before': UpdateChannelPluginConfigInput;
212
+ 'channelPlugin.updateConfiguration.after': ChannelPlugin;
213
+ 'channelPlugin.updateConfiguration.async': ChannelPlugin;
214
+ 'history.createForOrder.before': unknown;
215
+ 'history.createForOrder.after': HistoryEntry;
216
+ 'history.createForOrder.async': HistoryEntry;
217
+ 'history.createForCustomer.before': unknown;
218
+ 'history.createForCustomer.after': HistoryEntry;
219
+ 'history.createForCustomer.async': HistoryEntry;
220
+ 'history.updateEntry.before': unknown;
221
+ 'history.updateEntry.after': HistoryEntry;
222
+ 'history.updateEntry.async': HistoryEntry;
223
+ 'history.deleteEntry.before': string;
224
+ 'history.deleteEntry.after': HistoryEntry;
225
+ 'history.deleteEntry.async': HistoryEntry;
226
+ 'audienceSegment.create.before': CreateAudienceSegmentInput;
227
+ 'audienceSegment.create.after': AudienceSegment;
228
+ 'audienceSegment.create.async': AudienceSegment;
229
+ 'audienceSegment.update.before': UpdateAudienceSegmentInput;
230
+ 'audienceSegment.update.after': AudienceSegment;
231
+ 'audienceSegment.update.async': AudienceSegment;
232
+ 'audienceSegment.delete.before': string;
233
+ 'audienceSegment.delete.after': AudienceSegment;
234
+ 'audienceSegment.delete.async': AudienceSegment;
235
+ 'audienceMembership.addIdentityToSegment.before': AddIdentityToSegmentInput;
236
+ 'audienceMembership.addIdentityToSegment.after': AudienceMembership;
237
+ 'audienceMembership.addIdentityToSegment.async': AudienceMembership;
238
+ 'audienceMembership.removeIdentityFromSegment.before': RemoveIdentityFromSegmentInput;
239
+ 'audienceMembership.removeIdentityFromSegment.after': AudienceMembership;
240
+ 'audienceMembership.removeIdentityFromSegment.async': AudienceMembership;
241
+ }
242
+ export type AdminHookPoint = keyof AdminHookEventMap;
243
+ export type AdminHookHandler<K extends AdminHookPoint> = AdminHookEventMap[K] extends void ? (ctx: TransactionContext) => Promise<void> : (ctx: TransactionContext, payload: AdminHookEventMap[K]) => Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /**
4
+ * AUTO-GENERATED FILE — DO NOT EDIT
5
+ *
6
+ * This file was generated by @forgecart/client-sdk-generators.
7
+ * Any manual changes will be overwritten on the next generation run.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,59 +1,23 @@
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
- import { AdminNamespace, AdminSDKConfig } from './admin.js';
10
- import { ShopNamespace, ShopSDKConfig } from './shop.js';
11
- /**
12
- * Unified SDK Configuration
13
- */
14
- export interface ForgeCartSDKConfig {
15
- /** Base API endpoint (e.g., 'https://api.forgecart.com') */
16
- endpoint?: string;
17
- /** Channel token for Vendure multi-tenancy (required) */
18
- token: string;
19
- /** Use HTTP only, skip WebSocket initialization (default: false) */
20
- httpOnly?: boolean;
21
- /** Enable debug logging with request timing (default: false) */
22
- debug?: 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
- export type { AdminSDKConfig, ShopSDKConfig };
29
- export { AdminNamespace, ShopNamespace };
30
- /**
31
- * ForgeCartSDK
32
- * Unified SDK with categorized operations across multiple namespaces
33
- *
34
- * @example
35
- * ```typescript
36
- * const sdk = new ForgeCartSDK({
37
- * endpoint: 'https://api.forgecart.com',
38
- * token: 'your-channel-token',
39
- * });
40
- *
41
- * // Admin namespace → Category → Operations
42
- * await sdk.admin.products.products({ take: 10 });
43
- * await sdk.admin.customer.customer({ id: '1' });
44
- *
45
- * // Shop namespace → Category → Operations
46
- * await sdk.shop.products.products({ take: 10 });
47
- * await sdk.shop.order.addItemToOrder({ productVariantId: '1', quantity: 1 });
48
- * ```
49
- */
50
- export declare class ForgeCartSDK {
51
- readonly admin: AdminNamespace;
52
- readonly shop: ShopNamespace;
53
- constructor(config: ForgeCartSDKConfig);
54
- setAdminAuthToken(token: string): void;
55
- clearAdminAuthToken(): void;
56
- setShopAuthToken(token: string): void;
57
- clearShopAuthToken(): void;
58
- dispose(): void;
59
- }
1
+ export { ForgeCartAdminClient } from './client.generated';
2
+ export { ForgeCartShopClient } from './client.generated';
3
+ export { ForgeCartClient, ClientError, QueryObservable } from './client.generated';
4
+ export type { GraphQLErrorResponse } from './client.generated';
5
+ export type { ForgeCartAdminClientConfig } from './client.generated';
6
+ export type { ForgeCartShopClientConfig } from './client.generated';
7
+ export type { ForgeCartClientConfig } from './client.generated';
8
+ export { TransactionContext } from './client.generated';
9
+ export { ForgeCartGraphQLModule } from './client.generated';
10
+ export { AdminNamespace } from './admin.generated';
11
+ export { ShopNamespace } from './shop.generated';
12
+ export type { ID, Type, ApiExtension, IRequestContext, HookHandler } from './sdk-types.generated';
13
+ export type { IFulfillmentHandler, FulfillmentHandlerCapabilities, OrderLineInput } from './sdk-types.generated';
14
+ export { SdkError, SdkErrorCode } from './sdk-types.generated';
15
+ export type { ConfigurationItem, ManageableConfig, IHookRegistry } from './sdk-plugin.generated';
16
+ export { ForgeCartPlugin } from './sdk-plugin.generated';
17
+ export type { HookDispatchEvent, HookSubscription } from './sdk-hook-subscription.generated';
18
+ export { hookDispatchDocument, hookRespondDocument, HookSubscriptionManager } from './sdk-hook-subscription.generated';
19
+ export type { AdminHookEventMap, AdminHookPoint, AdminHookHandler } from './hook-event-map.generated';
20
+ export type { AcfFieldType } from './admin-types.generated';
21
+ export { extractErrorCode, extractError, extractErrorMessage, isErrorCode } from './error-utils';
22
+ export type { ExtractedError } from './error-utils';
23
+ export { Observable, firstValueFrom, lastValueFrom } from 'rxjs';
package/dist/index.js CHANGED
@@ -1,85 +1,37 @@
1
1
  "use strict";
2
- /**
3
- * @forgecart/sdk - Auto-generated TypeScript SDK
4
- *
5
- * This file was automatically generated and should not be manually edited.
6
- * To regenerate, run: npm run codegen:ts
7
- *
8
- * 🤖 Generated with ForgeCart SDK Generator
9
- */
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.ForgeCartSDK = exports.ShopNamespace = exports.AdminNamespace = void 0;
12
- const admin_js_1 = require("./admin.js");
13
- Object.defineProperty(exports, "AdminNamespace", { enumerable: true, get: function () { return admin_js_1.AdminNamespace; } });
14
- const shop_js_1 = require("./shop.js");
15
- Object.defineProperty(exports, "ShopNamespace", { enumerable: true, get: function () { return shop_js_1.ShopNamespace; } });
16
- /**
17
- * ForgeCartSDK
18
- * Unified SDK with categorized operations across multiple namespaces
19
- *
20
- * @example
21
- * ```typescript
22
- * const sdk = new ForgeCartSDK({
23
- * endpoint: 'https://api.forgecart.com',
24
- * token: 'your-channel-token',
25
- * });
26
- *
27
- * // Admin namespace Category Operations
28
- * await sdk.admin.products.products({ take: 10 });
29
- * await sdk.admin.customer.customer({ id: '1' });
30
- *
31
- * // Shop namespace → Category → Operations
32
- * await sdk.shop.products.products({ take: 10 });
33
- * await sdk.shop.order.addItemToOrder({ productVariantId: '1', quantity: 1 });
34
- * ```
35
- */
36
- class ForgeCartSDK {
37
- constructor(config) {
38
- // Validate channel token is provided
39
- if (!config.token || config.token.trim() === '') {
40
- throw new Error('ForgeCartSDK: Channel token is required. Please provide a valid "token" in the configuration.');
41
- }
42
- const baseEndpoint = config.endpoint || 'https://api.forgecart.com';
43
- const baseWsEndpoint = baseEndpoint.replace('http', 'ws');
44
- // Build headers with token
45
- const headers = {
46
- ...config.headers,
47
- 'forge-token': config.token,
48
- };
49
- const adminConfig = {
50
- endpoint: `${baseEndpoint}/admin-api`,
51
- wsEndpoint: `${baseWsEndpoint}/admin-api`,
52
- headers,
53
- webSocketImpl: config.webSocketImpl,
54
- httpOnly: config.httpOnly,
55
- debug: config.debug,
56
- };
57
- this.admin = new admin_js_1.AdminNamespace(adminConfig);
58
- const shopConfig = {
59
- endpoint: `${baseEndpoint}/shop-api`,
60
- wsEndpoint: `${baseWsEndpoint}/shop-api`,
61
- headers,
62
- webSocketImpl: config.webSocketImpl,
63
- httpOnly: config.httpOnly,
64
- debug: config.debug,
65
- };
66
- this.shop = new shop_js_1.ShopNamespace(shopConfig);
67
- }
68
- setAdminAuthToken(token) {
69
- this.admin.setAuthToken(token);
70
- }
71
- clearAdminAuthToken() {
72
- this.admin.clearAuthToken();
73
- }
74
- setShopAuthToken(token) {
75
- this.shop.setAuthToken(token);
76
- }
77
- clearShopAuthToken() {
78
- this.shop.clearAuthToken();
79
- }
80
- dispose() {
81
- this.admin.dispose();
82
- this.shop.dispose();
83
- }
84
- }
85
- exports.ForgeCartSDK = ForgeCartSDK;
3
+ exports.lastValueFrom = exports.firstValueFrom = exports.Observable = exports.isErrorCode = exports.extractErrorMessage = exports.extractError = exports.extractErrorCode = exports.HookSubscriptionManager = exports.hookRespondDocument = exports.hookDispatchDocument = exports.ForgeCartPlugin = exports.SdkErrorCode = exports.SdkError = exports.ShopNamespace = exports.AdminNamespace = exports.ForgeCartGraphQLModule = exports.TransactionContext = exports.QueryObservable = exports.ClientError = exports.ForgeCartClient = exports.ForgeCartShopClient = exports.ForgeCartAdminClient = void 0;
4
+ var client_generated_1 = require("./client.generated");
5
+ Object.defineProperty(exports, "ForgeCartAdminClient", { enumerable: true, get: function () { return client_generated_1.ForgeCartAdminClient; } });
6
+ var client_generated_2 = require("./client.generated");
7
+ Object.defineProperty(exports, "ForgeCartShopClient", { enumerable: true, get: function () { return client_generated_2.ForgeCartShopClient; } });
8
+ var client_generated_3 = require("./client.generated");
9
+ Object.defineProperty(exports, "ForgeCartClient", { enumerable: true, get: function () { return client_generated_3.ForgeCartClient; } });
10
+ Object.defineProperty(exports, "ClientError", { enumerable: true, get: function () { return client_generated_3.ClientError; } });
11
+ Object.defineProperty(exports, "QueryObservable", { enumerable: true, get: function () { return client_generated_3.QueryObservable; } });
12
+ var client_generated_4 = require("./client.generated");
13
+ Object.defineProperty(exports, "TransactionContext", { enumerable: true, get: function () { return client_generated_4.TransactionContext; } });
14
+ var client_generated_5 = require("./client.generated");
15
+ Object.defineProperty(exports, "ForgeCartGraphQLModule", { enumerable: true, get: function () { return client_generated_5.ForgeCartGraphQLModule; } });
16
+ var admin_generated_1 = require("./admin.generated");
17
+ Object.defineProperty(exports, "AdminNamespace", { enumerable: true, get: function () { return admin_generated_1.AdminNamespace; } });
18
+ var shop_generated_1 = require("./shop.generated");
19
+ Object.defineProperty(exports, "ShopNamespace", { enumerable: true, get: function () { return shop_generated_1.ShopNamespace; } });
20
+ var sdk_types_generated_1 = require("./sdk-types.generated");
21
+ Object.defineProperty(exports, "SdkError", { enumerable: true, get: function () { return sdk_types_generated_1.SdkError; } });
22
+ Object.defineProperty(exports, "SdkErrorCode", { enumerable: true, get: function () { return sdk_types_generated_1.SdkErrorCode; } });
23
+ var sdk_plugin_generated_1 = require("./sdk-plugin.generated");
24
+ Object.defineProperty(exports, "ForgeCartPlugin", { enumerable: true, get: function () { return sdk_plugin_generated_1.ForgeCartPlugin; } });
25
+ var sdk_hook_subscription_generated_1 = require("./sdk-hook-subscription.generated");
26
+ Object.defineProperty(exports, "hookDispatchDocument", { enumerable: true, get: function () { return sdk_hook_subscription_generated_1.hookDispatchDocument; } });
27
+ Object.defineProperty(exports, "hookRespondDocument", { enumerable: true, get: function () { return sdk_hook_subscription_generated_1.hookRespondDocument; } });
28
+ Object.defineProperty(exports, "HookSubscriptionManager", { enumerable: true, get: function () { return sdk_hook_subscription_generated_1.HookSubscriptionManager; } });
29
+ var error_utils_1 = require("./error-utils");
30
+ Object.defineProperty(exports, "extractErrorCode", { enumerable: true, get: function () { return error_utils_1.extractErrorCode; } });
31
+ Object.defineProperty(exports, "extractError", { enumerable: true, get: function () { return error_utils_1.extractError; } });
32
+ Object.defineProperty(exports, "extractErrorMessage", { enumerable: true, get: function () { return error_utils_1.extractErrorMessage; } });
33
+ Object.defineProperty(exports, "isErrorCode", { enumerable: true, get: function () { return error_utils_1.isErrorCode; } });
34
+ var rxjs_1 = require("rxjs");
35
+ Object.defineProperty(exports, "Observable", { enumerable: true, get: function () { return rxjs_1.Observable; } });
36
+ Object.defineProperty(exports, "firstValueFrom", { enumerable: true, get: function () { return rxjs_1.firstValueFrom; } });
37
+ Object.defineProperty(exports, "lastValueFrom", { enumerable: true, get: function () { return rxjs_1.lastValueFrom; } });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * AUTO-GENERATED FILE — DO NOT EDIT
3
+ *
4
+ * This file was generated by @forgecart/client-sdk-generators.
5
+ * Any manual changes will be overwritten on the next generation run.
6
+ */
7
+ import { Observable } from 'rxjs';
8
+ export interface HookDispatchEvent {
9
+ id: string;
10
+ hookPoint: string;
11
+ transactionToken: string;
12
+ subscriberId: string;
13
+ args: unknown[];
14
+ }
15
+ export declare const hookDispatchDocument = "\n subscription OnHookDispatch($hookPoints: [String!]!) {\n hookDispatched(hookPoints: $hookPoints) {\n id\n hookPoint\n transactionToken\n subscriberId\n args\n }\n }\n";
16
+ export declare const hookRespondDocument = "\n mutation RespondToHook($input: RespondToHookDispatchInput!) {\n respondToHookDispatch(input: $input)\n }\n";
17
+ export interface HookSubscription {
18
+ unsubscribe(): void;
19
+ readonly closed: Promise<void>;
20
+ }
21
+ export declare class HookSubscriptionManager<TContext = unknown> {
22
+ private readonly subscribeFn;
23
+ private readonly respondFn;
24
+ private readonly createContext;
25
+ constructor(subscribeFn: (hookPoints: string[]) => Observable<{
26
+ hookDispatched: HookDispatchEvent;
27
+ }>, respondFn: (id: string, subscriberId: string, error?: string) => Observable<unknown>, createContext: (transactionToken: string) => TContext);
28
+ on(hookPoints: string[], handler: (ctx: TContext, payload?: unknown) => Promise<void>): HookSubscription;
29
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /**
4
+ * AUTO-GENERATED FILE — DO NOT EDIT
5
+ *
6
+ * This file was generated by @forgecart/client-sdk-generators.
7
+ * Any manual changes will be overwritten on the next generation run.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.HookSubscriptionManager = exports.hookRespondDocument = exports.hookDispatchDocument = void 0;
11
+ const rxjs_1 = require("rxjs");
12
+ exports.hookDispatchDocument = `
13
+ subscription OnHookDispatch($hookPoints: [String!]!) {
14
+ hookDispatched(hookPoints: $hookPoints) {
15
+ id
16
+ hookPoint
17
+ transactionToken
18
+ subscriberId
19
+ args
20
+ }
21
+ }
22
+ `;
23
+ exports.hookRespondDocument = `
24
+ mutation RespondToHook($input: RespondToHookDispatchInput!) {
25
+ respondToHookDispatch(input: $input)
26
+ }
27
+ `;
28
+ class HookSubscriptionManager {
29
+ subscribeFn;
30
+ respondFn;
31
+ createContext;
32
+ constructor(subscribeFn, respondFn, createContext) {
33
+ this.subscribeFn = subscribeFn;
34
+ this.respondFn = respondFn;
35
+ this.createContext = createContext;
36
+ }
37
+ on(hookPoints, handler) {
38
+ let resolveClose;
39
+ const closed = new Promise((resolve) => { resolveClose = resolve; });
40
+ const subscription = this.subscribeFn(hookPoints).subscribe({
41
+ next: async (value) => {
42
+ const event = value.hookDispatched;
43
+ const suffix = event.hookPoint.split('.').pop();
44
+ const ctx = this.createContext(event.transactionToken);
45
+ const payload = Array.isArray(event.args) && event.args.length > 0
46
+ ? event.args[0]
47
+ : undefined;
48
+ try {
49
+ await handler(ctx, payload);
50
+ if (suffix === 'before' || suffix === 'after') {
51
+ await (0, rxjs_1.firstValueFrom)(this.respondFn(event.id, event.subscriberId));
52
+ }
53
+ }
54
+ catch (error) {
55
+ if (suffix === 'before' || suffix === 'after') {
56
+ await (0, rxjs_1.firstValueFrom)(this.respondFn(event.id, event.subscriberId, error instanceof Error ? error.message : String(error)));
57
+ }
58
+ }
59
+ },
60
+ error: () => {
61
+ resolveClose?.();
62
+ },
63
+ complete: () => {
64
+ resolveClose?.();
65
+ },
66
+ });
67
+ return {
68
+ unsubscribe: () => { subscription.unsubscribe(); },
69
+ closed,
70
+ };
71
+ }
72
+ }
73
+ exports.HookSubscriptionManager = HookSubscriptionManager;