@forgecart/sdk 1.202608121449.0 → 1.202608161317.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,7 +57,7 @@ const order = await client.shop.cart.addItemToOrder({ variantId, quantity: 1 });
57
57
  ## Namespaces
58
58
 
59
59
  - `client.admin` — entry, fieldDefinition, publish, acfSchema, acf, administrator, analyticsGateway, asset, audienceMembership, audienceSegment, auth, automation, settings, channel, chat, collection, country, address, group, customerAnalytics, customer, deployment, designerTask, experiment, facet, fulfillmentRequest, fulfillment, hookDispatch, hook, market, marketingAttribution, marketingEvent, marketingIdentity, mission, onboarding, coupon, draft, modification, note, orderAnalytics, order, payment, manageable, plugin, optionGroup, option, productVariant, product, promotion, role, scheduledJob, search, seller, sellingPlan, shipping, stockAnalytics, stock, storefrontRouteTree, subscriptionAnalytics, subscription, tax, transaction, zone
60
- - `client.shop` — acf, auth, cart, channel, checkout, collection, country, customer, experiment, facet, hookDispatch, hook, marketingEvent, marketingIdentity, order, payment, product, search, sellingPlan, shipping, subscription
60
+ - `client.shop` — acf, address, auth, cart, channel, checkout, collection, country, customer, experiment, facet, hookDispatch, hook, marketingEvent, marketingIdentity, order, payment, product, search, sellingPlan, shipping, subscription
61
61
 
62
62
  ## NestJS Integration
63
63
 
@@ -0,0 +1,97 @@
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 { AdminNamespace } from './admin.generated';
8
+ import type * as Admin from './admin.generated';
9
+ import type { AdminExternalAuthResult, ErrorHandler, ForgeCartAdminClientConfig, LoginSession, QueryObservable } from './client.generated';
10
+ import type { HookSubscription } from './sdk-hook-subscription.generated';
11
+ import type { AdminHookPoint, AdminHookHandler } from './hook-event-map.generated';
12
+ import type { ShopNamespace } from './shop.generated';
13
+ import type { ForgeCartShopClient } from './shop-client.generated';
14
+ export declare class TransactionContext {
15
+ private readonly _admin;
16
+ private readonly _shop;
17
+ constructor(admin: AdminNamespace, shop?: ShopNamespace);
18
+ get admin(): AdminNamespace;
19
+ get shop(): ShopNamespace;
20
+ }
21
+ export declare class ForgeCartAdminClient {
22
+ private readonly client;
23
+ private readonly _namespace;
24
+ constructor(config: ForgeCartAdminClientConfig);
25
+ setAuthToken(token: string): void;
26
+ getAuthToken(): string | null;
27
+ clearAuthToken(): void;
28
+ setCurrencyCode(currencyCode: string): void;
29
+ clearCurrencyCode(): void;
30
+ setLanguageCode(languageCode: string): void;
31
+ clearLanguageCode(): void;
32
+ setTransactionToken(token: string): void;
33
+ clearTransactionToken(): void;
34
+ setErrorHandler(handler: ErrorHandler): void;
35
+ dispose(): void;
36
+ query<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
37
+ mutate<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
38
+ private shopPeer;
39
+ setShopPeer(shop: ForgeCartShopClient): void;
40
+ createScopedNamespace(transactionToken: string): AdminNamespace;
41
+ withTransaction<T>(fn: (ctx: TransactionContext) => Promise<T>): Promise<T>;
42
+ private hookManager;
43
+ on<K extends AdminHookPoint>(hookPoints: K[], handler: AdminHookHandler<K>): HookSubscription;
44
+ login(emailAddress: string, password: string): Promise<LoginSession>;
45
+ loginWithExternalStrategy(strategyCode: string, data: Record<string, unknown>): Promise<AdminExternalAuthResult>;
46
+ logout(): Promise<void>;
47
+ get acf(): Admin.AcfCategory;
48
+ get acfSchema(): Admin.AcfSchemaCategory;
49
+ get administrator(): Admin.AdministratorCategory;
50
+ get analyticsGateway(): Admin.AnalyticsGatewayCategory;
51
+ get asset(): Admin.AssetCategory;
52
+ get audienceMembership(): Admin.AudienceMembershipCategory;
53
+ get audienceSegment(): Admin.AudienceSegmentCategory;
54
+ get auth(): Admin.AuthCategory;
55
+ get automation(): Admin.AutomationCategory;
56
+ get channel(): Admin.ChannelCategory;
57
+ get chat(): Admin.ChatCategory;
58
+ get collection(): Admin.CollectionCategory;
59
+ get country(): Admin.CountryCategory;
60
+ get customer(): Admin.CustomerCategory;
61
+ get customerAnalytics(): Admin.CustomerAnalyticsCategory;
62
+ get deployment(): Admin.DeploymentCategory;
63
+ get designerTask(): Admin.DesignerTaskCategory;
64
+ get experiment(): Admin.ExperimentCategory;
65
+ get facet(): Admin.FacetCategory;
66
+ get fulfillment(): Admin.FulfillmentCategory;
67
+ get fulfillmentRequest(): Admin.FulfillmentRequestCategory;
68
+ get hook(): Admin.HookCategory;
69
+ get hookDispatch(): Admin.HookDispatchCategory;
70
+ get market(): Admin.MarketCategory;
71
+ get marketingAttribution(): Admin.MarketingAttributionCategory;
72
+ get marketingEvent(): Admin.MarketingEventCategory;
73
+ get marketingIdentity(): Admin.MarketingIdentityCategory;
74
+ get mission(): Admin.MissionCategory;
75
+ get onboarding(): Admin.OnboardingCategory;
76
+ get order(): Admin.OrderCategory;
77
+ get orderAnalytics(): Admin.OrderAnalyticsCategory;
78
+ get payment(): Admin.PaymentCategory;
79
+ get plugin(): Admin.PluginCategory;
80
+ get product(): Admin.ProductCategory;
81
+ get productVariant(): Admin.ProductVariantCategory;
82
+ get promotion(): Admin.PromotionCategory;
83
+ get role(): Admin.RoleCategory;
84
+ get scheduledJob(): Admin.ScheduledJobCategory;
85
+ get search(): Admin.SearchCategory;
86
+ get seller(): Admin.SellerCategory;
87
+ get sellingPlan(): Admin.SellingPlanCategory;
88
+ get shipping(): Admin.ShippingCategory;
89
+ get stock(): Admin.StockCategory;
90
+ get stockAnalytics(): Admin.StockAnalyticsCategory;
91
+ get storefrontRouteTree(): Admin.StorefrontRouteTreeCategory;
92
+ get subscription(): Admin.SubscriptionCategory;
93
+ get subscriptionAnalytics(): Admin.SubscriptionAnalyticsCategory;
94
+ get tax(): Admin.TaxCategory;
95
+ get transaction(): Admin.TransactionCategory;
96
+ get zone(): Admin.ZoneCategory;
97
+ }
@@ -0,0 +1,295 @@
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.ForgeCartAdminClient = exports.TransactionContext = void 0;
11
+ const rxjs_1 = require("rxjs");
12
+ const admin_generated_1 = require("./admin.generated");
13
+ const client_generated_1 = require("./client.generated");
14
+ const sdk_hook_subscription_generated_1 = require("./sdk-hook-subscription.generated");
15
+ class TransactionContext {
16
+ _admin;
17
+ _shop;
18
+ constructor(admin, shop) {
19
+ this._admin = admin;
20
+ this._shop = shop;
21
+ }
22
+ get admin() {
23
+ return this._admin;
24
+ }
25
+ get shop() {
26
+ if (!this._shop) {
27
+ throw new Error('SHOP_NAMESPACE_NOT_AVAILABLE');
28
+ }
29
+ return this._shop;
30
+ }
31
+ }
32
+ exports.TransactionContext = TransactionContext;
33
+ class ForgeCartAdminClient {
34
+ client;
35
+ _namespace;
36
+ constructor(config) {
37
+ const headers = { 'forgecart-token': config.channelToken, ...config.headers };
38
+ if (config.adminSecret) {
39
+ headers['forgecart-secret'] = config.adminSecret;
40
+ }
41
+ this.client = new client_generated_1.BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint, {
42
+ wsEndpoint: config.wsEndpoint,
43
+ currencyCode: config.currencyCode,
44
+ languageCode: config.languageCode,
45
+ });
46
+ this._namespace = new admin_generated_1.AdminNamespace(this.client);
47
+ }
48
+ setAuthToken(token) {
49
+ this.client.setAuthToken(token);
50
+ }
51
+ getAuthToken() {
52
+ return this.client.getAuthToken();
53
+ }
54
+ clearAuthToken() {
55
+ this.client.clearAuthToken();
56
+ }
57
+ setCurrencyCode(currencyCode) {
58
+ this.client.setCurrencyCode(currencyCode);
59
+ }
60
+ clearCurrencyCode() {
61
+ this.client.clearCurrencyCode();
62
+ }
63
+ setLanguageCode(languageCode) {
64
+ this.client.setLanguageCode(languageCode);
65
+ }
66
+ clearLanguageCode() {
67
+ this.client.clearLanguageCode();
68
+ }
69
+ setTransactionToken(token) {
70
+ this.client.setTransactionToken(token);
71
+ }
72
+ clearTransactionToken() {
73
+ this.client.clearTransactionToken();
74
+ }
75
+ setErrorHandler(handler) {
76
+ this.client.setErrorHandler(handler);
77
+ }
78
+ dispose() {
79
+ this.client.dispose();
80
+ }
81
+ query(document, variables) {
82
+ return this.client.query(document, variables);
83
+ }
84
+ mutate(document, variables) {
85
+ return this.client.mutate(document, variables);
86
+ }
87
+ shopPeer = null;
88
+ setShopPeer(shop) {
89
+ this.shopPeer = shop;
90
+ }
91
+ createScopedNamespace(transactionToken) {
92
+ return new admin_generated_1.AdminNamespace(this.client.fork(transactionToken));
93
+ }
94
+ async withTransaction(fn) {
95
+ const result = await (0, rxjs_1.firstValueFrom)(this.transaction.beginTransaction());
96
+ const token = result.beginTransaction.token;
97
+ const adminNs = this.createScopedNamespace(token);
98
+ const shopNs = this.shopPeer?.createScopedNamespace(token);
99
+ const ctx = new TransactionContext(adminNs, shopNs);
100
+ try {
101
+ const value = await fn(ctx);
102
+ await (0, rxjs_1.firstValueFrom)(this.transaction.commitTransaction({ token }));
103
+ return value;
104
+ }
105
+ catch (error) {
106
+ await (0, rxjs_1.firstValueFrom)(this.transaction.rollbackTransaction({ token })).catch(() => { });
107
+ throw error;
108
+ }
109
+ }
110
+ hookManager = null;
111
+ on(hookPoints, handler) {
112
+ if (!this.hookManager) {
113
+ this.hookManager = new sdk_hook_subscription_generated_1.HookSubscriptionManager((hp) => this.client.subscribe(sdk_hook_subscription_generated_1.hookDispatchDocument, { hookPoints: hp }), (id, subscriberId, error) => this.client.mutate(sdk_hook_subscription_generated_1.hookRespondDocument, { input: { id, subscriberId, error } }), (token) => {
114
+ const adminNs = this.createScopedNamespace(token);
115
+ const shopNs = this.shopPeer?.createScopedNamespace(token);
116
+ return new TransactionContext(adminNs, shopNs);
117
+ });
118
+ }
119
+ return this.hookManager.on(hookPoints, handler);
120
+ }
121
+ async login(emailAddress, password) {
122
+ const result = await (0, rxjs_1.firstValueFrom)(this.auth.login({ input: { emailAddress, password } }));
123
+ this.client.setAuthToken(result.login.token);
124
+ if (this.shopPeer) {
125
+ this.shopPeer.setAuthToken(result.login.token);
126
+ }
127
+ return result.login;
128
+ }
129
+ async loginWithExternalStrategy(strategyCode, data) {
130
+ const result = await (0, rxjs_1.firstValueFrom)(this.auth.authenticateWithExternalStrategy({ input: { strategyCode, data } }));
131
+ this.client.setAuthToken(result.authenticateWithExternalStrategy.session.token);
132
+ if (this.shopPeer) {
133
+ this.shopPeer.setAuthToken(result.authenticateWithExternalStrategy.session.token);
134
+ }
135
+ return result.authenticateWithExternalStrategy;
136
+ }
137
+ async logout() {
138
+ await (0, rxjs_1.firstValueFrom)(this.auth.logout());
139
+ this.client.clearAuthToken();
140
+ if (this.shopPeer) {
141
+ this.shopPeer.clearAuthToken();
142
+ }
143
+ }
144
+ get acf() {
145
+ return this._namespace.acf;
146
+ }
147
+ get acfSchema() {
148
+ return this._namespace.acfSchema;
149
+ }
150
+ get administrator() {
151
+ return this._namespace.administrator;
152
+ }
153
+ get analyticsGateway() {
154
+ return this._namespace.analyticsGateway;
155
+ }
156
+ get asset() {
157
+ return this._namespace.asset;
158
+ }
159
+ get audienceMembership() {
160
+ return this._namespace.audienceMembership;
161
+ }
162
+ get audienceSegment() {
163
+ return this._namespace.audienceSegment;
164
+ }
165
+ get auth() {
166
+ return this._namespace.auth;
167
+ }
168
+ get automation() {
169
+ return this._namespace.automation;
170
+ }
171
+ get channel() {
172
+ return this._namespace.channel;
173
+ }
174
+ get chat() {
175
+ return this._namespace.chat;
176
+ }
177
+ get collection() {
178
+ return this._namespace.collection;
179
+ }
180
+ get country() {
181
+ return this._namespace.country;
182
+ }
183
+ get customer() {
184
+ return this._namespace.customer;
185
+ }
186
+ get customerAnalytics() {
187
+ return this._namespace.customerAnalytics;
188
+ }
189
+ get deployment() {
190
+ return this._namespace.deployment;
191
+ }
192
+ get designerTask() {
193
+ return this._namespace.designerTask;
194
+ }
195
+ get experiment() {
196
+ return this._namespace.experiment;
197
+ }
198
+ get facet() {
199
+ return this._namespace.facet;
200
+ }
201
+ get fulfillment() {
202
+ return this._namespace.fulfillment;
203
+ }
204
+ get fulfillmentRequest() {
205
+ return this._namespace.fulfillmentRequest;
206
+ }
207
+ get hook() {
208
+ return this._namespace.hook;
209
+ }
210
+ get hookDispatch() {
211
+ return this._namespace.hookDispatch;
212
+ }
213
+ get market() {
214
+ return this._namespace.market;
215
+ }
216
+ get marketingAttribution() {
217
+ return this._namespace.marketingAttribution;
218
+ }
219
+ get marketingEvent() {
220
+ return this._namespace.marketingEvent;
221
+ }
222
+ get marketingIdentity() {
223
+ return this._namespace.marketingIdentity;
224
+ }
225
+ get mission() {
226
+ return this._namespace.mission;
227
+ }
228
+ get onboarding() {
229
+ return this._namespace.onboarding;
230
+ }
231
+ get order() {
232
+ return this._namespace.order;
233
+ }
234
+ get orderAnalytics() {
235
+ return this._namespace.orderAnalytics;
236
+ }
237
+ get payment() {
238
+ return this._namespace.payment;
239
+ }
240
+ get plugin() {
241
+ return this._namespace.plugin;
242
+ }
243
+ get product() {
244
+ return this._namespace.product;
245
+ }
246
+ get productVariant() {
247
+ return this._namespace.productVariant;
248
+ }
249
+ get promotion() {
250
+ return this._namespace.promotion;
251
+ }
252
+ get role() {
253
+ return this._namespace.role;
254
+ }
255
+ get scheduledJob() {
256
+ return this._namespace.scheduledJob;
257
+ }
258
+ get search() {
259
+ return this._namespace.search;
260
+ }
261
+ get seller() {
262
+ return this._namespace.seller;
263
+ }
264
+ get sellingPlan() {
265
+ return this._namespace.sellingPlan;
266
+ }
267
+ get shipping() {
268
+ return this._namespace.shipping;
269
+ }
270
+ get stock() {
271
+ return this._namespace.stock;
272
+ }
273
+ get stockAnalytics() {
274
+ return this._namespace.stockAnalytics;
275
+ }
276
+ get storefrontRouteTree() {
277
+ return this._namespace.storefrontRouteTree;
278
+ }
279
+ get subscription() {
280
+ return this._namespace.subscription;
281
+ }
282
+ get subscriptionAnalytics() {
283
+ return this._namespace.subscriptionAnalytics;
284
+ }
285
+ get tax() {
286
+ return this._namespace.tax;
287
+ }
288
+ get transaction() {
289
+ return this._namespace.transaction;
290
+ }
291
+ get zone() {
292
+ return this._namespace.zone;
293
+ }
294
+ }
295
+ exports.ForgeCartAdminClient = ForgeCartAdminClient;