@forgecart/sdk 1.2.6 → 1.202606151453.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 +84 -1
- package/dist/admin-types.generated.d.ts +593 -33
- package/dist/admin.d.ts +4 -0
- package/dist/admin.generated.d.ts +82 -26
- package/dist/admin.generated.js +122 -2
- package/dist/admin.js +49 -43
- package/dist/client.generated.d.ts +40 -7
- package/dist/client.generated.js +162 -87
- package/dist/documents.generated.d.ts +38 -8
- package/dist/documents.generated.js +594 -36
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -3
- package/dist/nest.generated.d.ts +13 -0
- package/dist/nest.generated.js +92 -0
- package/dist/shop-types.generated.d.ts +200 -13
- package/dist/shop.d.ts +2 -0
- package/dist/shop.generated.d.ts +13 -4
- package/dist/shop.generated.js +19 -1
- package/dist/shop.js +17 -15
- package/package.json +21 -4
- package/src/admin-types.generated.d.ts +10013 -0
- package/src/admin-types.generated.ts +1210 -88
- package/src/admin.generated.d.ts +806 -0
- package/src/admin.generated.ts +151 -27
- package/src/admin.ts +5 -1
- package/src/client.generated.d.ts +249 -0
- package/src/client.generated.ts +188 -39
- package/src/documents.generated.d.ts +473 -0
- package/src/documents.generated.ts +615 -27
- package/src/error-utils.d.ts +25 -0
- package/src/hook-event-map.generated.d.ts +243 -0
- package/src/index.d.ts +22 -0
- package/src/index.ts +1 -1
- package/src/nest.generated.ts +45 -0
- package/src/sdk-hook-subscription.generated.d.ts +29 -0
- package/src/sdk-plugin.generated.d.ts +38 -0
- package/src/sdk-types.generated.d.ts +56 -0
- package/src/shop-types.generated.d.ts +4786 -0
- package/src/shop-types.generated.ts +271 -13
- package/src/shop.generated.d.ts +213 -0
- package/src/shop.generated.ts +22 -5
- package/src/shop.ts +3 -1
- package/src/upload.d.ts +14 -0
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
import type { HookSubscription } from './sdk-hook-subscription.generated';
|
|
9
|
+
import type { AdminHookPoint, AdminHookHandler } from './hook-event-map.generated';
|
|
10
|
+
import { AdminNamespace } from './admin.generated';
|
|
11
|
+
import type * as Admin from './admin.generated';
|
|
12
|
+
import { ShopNamespace } from './shop.generated';
|
|
13
|
+
import type * as Shop from './shop.generated';
|
|
14
|
+
export interface ForgeCartAdminClientConfig {
|
|
15
|
+
endpoint: string;
|
|
16
|
+
channelToken: string;
|
|
17
|
+
adminSecret?: string;
|
|
18
|
+
uploadEndpoint?: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export interface ForgeCartShopClientConfig {
|
|
22
|
+
endpoint: string;
|
|
23
|
+
channelToken: string;
|
|
24
|
+
uploadEndpoint?: string;
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
export interface ForgeCartClientConfig {
|
|
28
|
+
endpoint: string;
|
|
29
|
+
channelToken: string;
|
|
30
|
+
adminSecret?: string;
|
|
31
|
+
uploadEndpoint?: string;
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
export declare class SDKLogger {
|
|
35
|
+
private readonly prefix;
|
|
36
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
37
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
38
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
39
|
+
}
|
|
40
|
+
export interface GraphQLErrorResponse {
|
|
41
|
+
errors: Array<{
|
|
42
|
+
message: string;
|
|
43
|
+
extensions?: Record<string, unknown>;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export declare class ClientError extends Error {
|
|
47
|
+
readonly response: GraphQLErrorResponse;
|
|
48
|
+
constructor(response: GraphQLErrorResponse, message: string);
|
|
49
|
+
}
|
|
50
|
+
export type ErrorHandler = (error: ClientError) => void;
|
|
51
|
+
/**
|
|
52
|
+
* An Observable that is also PromiseLike, so `await` resolves the first emitted value.
|
|
53
|
+
* Use `.subscribe()` for streaming, `await` for single-shot request-response.
|
|
54
|
+
*/
|
|
55
|
+
export declare class QueryObservable<T> extends Observable<T> implements PromiseLike<T> {
|
|
56
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
57
|
+
}
|
|
58
|
+
export interface LoginSessionChannel {
|
|
59
|
+
id: string;
|
|
60
|
+
token: string;
|
|
61
|
+
code: string;
|
|
62
|
+
permissions: string[];
|
|
63
|
+
}
|
|
64
|
+
export interface LoginSession {
|
|
65
|
+
id: string;
|
|
66
|
+
token: string;
|
|
67
|
+
channels: LoginSessionChannel[];
|
|
68
|
+
}
|
|
69
|
+
export interface AdminLoginAdministrator {
|
|
70
|
+
id: string;
|
|
71
|
+
firstName: string;
|
|
72
|
+
lastName: string;
|
|
73
|
+
emailAddress: string;
|
|
74
|
+
avatarUrl: string | null;
|
|
75
|
+
}
|
|
76
|
+
export interface AdminExternalAuthResult {
|
|
77
|
+
session: LoginSession;
|
|
78
|
+
administrator: AdminLoginAdministrator;
|
|
79
|
+
requiresOnboarding: boolean;
|
|
80
|
+
}
|
|
81
|
+
export declare class BaseGraphQLClient {
|
|
82
|
+
private readonly baseHeaders;
|
|
83
|
+
private readonly uploadEndpoint?;
|
|
84
|
+
private readonly logger;
|
|
85
|
+
private readonly endpoint;
|
|
86
|
+
private wsClient;
|
|
87
|
+
private ownsWsClient;
|
|
88
|
+
private wsClientStale;
|
|
89
|
+
private authToken;
|
|
90
|
+
private transactionToken;
|
|
91
|
+
private errorHandler;
|
|
92
|
+
constructor(endpoint: string, baseHeaders: Record<string, string>, uploadEndpoint?: string | undefined);
|
|
93
|
+
private getWsClient;
|
|
94
|
+
private getHeaders;
|
|
95
|
+
setAuthToken(token: string): void;
|
|
96
|
+
getAuthToken(): string | null;
|
|
97
|
+
clearAuthToken(): void;
|
|
98
|
+
setTransactionToken(token: string): void;
|
|
99
|
+
clearTransactionToken(): void;
|
|
100
|
+
setErrorHandler(handler: ErrorHandler): void;
|
|
101
|
+
private notifyErrorHandler;
|
|
102
|
+
query<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
|
|
103
|
+
mutate<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
|
|
104
|
+
subscribe<T>(document: string, variables?: Record<string, unknown>): Observable<T>;
|
|
105
|
+
upload<T>(document: string, variables: Record<string, unknown>): QueryObservable<T>;
|
|
106
|
+
private getPerOperationExtensions;
|
|
107
|
+
private captureSessionToken;
|
|
108
|
+
private captureSessionTokenFromUpload;
|
|
109
|
+
private containsFiles;
|
|
110
|
+
private resolveUploadEndpoint;
|
|
111
|
+
private disposeWsClient;
|
|
112
|
+
dispose(): void;
|
|
113
|
+
fork(transactionToken: string): BaseGraphQLClient;
|
|
114
|
+
}
|
|
115
|
+
export declare function setAuthToken(client: BaseGraphQLClient, token: string): void;
|
|
116
|
+
export declare function clearAuthToken(client: BaseGraphQLClient): void;
|
|
117
|
+
export declare function setTransactionToken(client: BaseGraphQLClient, token: string): void;
|
|
118
|
+
export declare function clearTransactionToken(client: BaseGraphQLClient): void;
|
|
119
|
+
export declare class TransactionContext {
|
|
120
|
+
private readonly _admin;
|
|
121
|
+
private readonly _shop;
|
|
122
|
+
constructor(admin: AdminNamespace, shop?: ShopNamespace);
|
|
123
|
+
get admin(): AdminNamespace;
|
|
124
|
+
get shop(): ShopNamespace;
|
|
125
|
+
}
|
|
126
|
+
export declare class ForgeCartAdminClient {
|
|
127
|
+
private readonly client;
|
|
128
|
+
private readonly _namespace;
|
|
129
|
+
constructor(config: ForgeCartAdminClientConfig);
|
|
130
|
+
setAuthToken(token: string): void;
|
|
131
|
+
getAuthToken(): string | null;
|
|
132
|
+
clearAuthToken(): void;
|
|
133
|
+
setTransactionToken(token: string): void;
|
|
134
|
+
clearTransactionToken(): void;
|
|
135
|
+
setErrorHandler(handler: ErrorHandler): void;
|
|
136
|
+
dispose(): void;
|
|
137
|
+
query<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
|
|
138
|
+
mutate<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
|
|
139
|
+
private shopPeer;
|
|
140
|
+
setShopPeer(shop: ForgeCartShopClient): void;
|
|
141
|
+
createScopedNamespace(transactionToken: string): AdminNamespace;
|
|
142
|
+
withTransaction<T>(fn: (ctx: TransactionContext) => Promise<T>): Promise<T>;
|
|
143
|
+
private hookManager;
|
|
144
|
+
on<K extends AdminHookPoint>(hookPoints: K[], handler: AdminHookHandler<K>): HookSubscription;
|
|
145
|
+
login(emailAddress: string, password: string): Promise<LoginSession>;
|
|
146
|
+
loginWithExternalStrategy(strategyCode: string, data: Record<string, unknown>): Promise<AdminExternalAuthResult>;
|
|
147
|
+
logout(): Promise<void>;
|
|
148
|
+
get entry(): Admin.EntryCategory;
|
|
149
|
+
get fieldDefinition(): Admin.FieldDefinitionCategory;
|
|
150
|
+
get publish(): Admin.PublishCategory;
|
|
151
|
+
get acfSchema(): Admin.AcfSchemaCategory;
|
|
152
|
+
get acf(): Admin.AcfCategory;
|
|
153
|
+
get administrator(): Admin.AdministratorCategory;
|
|
154
|
+
get analyticsGateway(): Admin.AnalyticsGatewayCategory;
|
|
155
|
+
get asset(): Admin.AssetCategory;
|
|
156
|
+
get audienceMembership(): Admin.AudienceMembershipCategory;
|
|
157
|
+
get audienceSegment(): Admin.AudienceSegmentCategory;
|
|
158
|
+
get auth(): Admin.AuthCategory;
|
|
159
|
+
get settings(): Admin.SettingsCategory;
|
|
160
|
+
get channel(): Admin.ChannelCategory;
|
|
161
|
+
get chat(): Admin.ChatCategory;
|
|
162
|
+
get collection(): Admin.CollectionCategory;
|
|
163
|
+
get country(): Admin.CountryCategory;
|
|
164
|
+
get address(): Admin.AddressCategory;
|
|
165
|
+
get group(): Admin.GroupCategory;
|
|
166
|
+
get customerGroup(): Admin.CustomerGroupCategory;
|
|
167
|
+
get customer(): Admin.CustomerCategory;
|
|
168
|
+
get deployment(): Admin.DeploymentCategory;
|
|
169
|
+
get facet(): Admin.FacetCategory;
|
|
170
|
+
get fulfillmentRequest(): Admin.FulfillmentRequestCategory;
|
|
171
|
+
get fulfillment(): Admin.FulfillmentCategory;
|
|
172
|
+
get hookDispatch(): Admin.HookDispatchCategory;
|
|
173
|
+
get hook(): Admin.HookCategory;
|
|
174
|
+
get marketingAttribution(): Admin.MarketingAttributionCategory;
|
|
175
|
+
get marketingEvent(): Admin.MarketingEventCategory;
|
|
176
|
+
get marketingIdentity(): Admin.MarketingIdentityCategory;
|
|
177
|
+
get onboarding(): Admin.OnboardingCategory;
|
|
178
|
+
get coupon(): Admin.CouponCategory;
|
|
179
|
+
get draft(): Admin.DraftCategory;
|
|
180
|
+
get modification(): Admin.ModificationCategory;
|
|
181
|
+
get note(): Admin.NoteCategory;
|
|
182
|
+
get orderModification(): Admin.OrderModificationCategory;
|
|
183
|
+
get order(): Admin.OrderCategory;
|
|
184
|
+
get payment(): Admin.PaymentCategory;
|
|
185
|
+
get manageable(): Admin.ManageableCategory;
|
|
186
|
+
get plugin(): Admin.PluginCategory;
|
|
187
|
+
get optionGroup(): Admin.OptionGroupCategory;
|
|
188
|
+
get option(): Admin.OptionCategory;
|
|
189
|
+
get productOption(): Admin.ProductOptionCategory;
|
|
190
|
+
get productVariant(): Admin.ProductVariantCategory;
|
|
191
|
+
get product(): Admin.ProductCategory;
|
|
192
|
+
get promotion(): Admin.PromotionCategory;
|
|
193
|
+
get role(): Admin.RoleCategory;
|
|
194
|
+
get scheduledJob(): Admin.ScheduledJobCategory;
|
|
195
|
+
get search(): Admin.SearchCategory;
|
|
196
|
+
get seller(): Admin.SellerCategory;
|
|
197
|
+
get shipping(): Admin.ShippingCategory;
|
|
198
|
+
get stock(): Admin.StockCategory;
|
|
199
|
+
get subscription(): Admin.SubscriptionCategory;
|
|
200
|
+
get tax(): Admin.TaxCategory;
|
|
201
|
+
get transaction(): Admin.TransactionCategory;
|
|
202
|
+
get zone(): Admin.ZoneCategory;
|
|
203
|
+
}
|
|
204
|
+
export declare class ForgeCartShopClient {
|
|
205
|
+
private readonly client;
|
|
206
|
+
private readonly _namespace;
|
|
207
|
+
constructor(config: ForgeCartShopClientConfig);
|
|
208
|
+
setAuthToken(token: string): void;
|
|
209
|
+
getAuthToken(): string | null;
|
|
210
|
+
clearAuthToken(): void;
|
|
211
|
+
setTransactionToken(token: string): void;
|
|
212
|
+
clearTransactionToken(): void;
|
|
213
|
+
setErrorHandler(handler: ErrorHandler): void;
|
|
214
|
+
dispose(): void;
|
|
215
|
+
query<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
|
|
216
|
+
mutate<T>(document: string, variables?: Record<string, unknown>): QueryObservable<T>;
|
|
217
|
+
createScopedNamespace(transactionToken: string): ShopNamespace;
|
|
218
|
+
login(emailAddress: string, password: string): Promise<LoginSession>;
|
|
219
|
+
loginWithExternalStrategy(strategyCode: string, data: Record<string, unknown>): Promise<LoginSession>;
|
|
220
|
+
logout(): Promise<void>;
|
|
221
|
+
get acf(): Shop.AcfCategory;
|
|
222
|
+
get auth(): Shop.AuthCategory;
|
|
223
|
+
get cart(): Shop.CartCategory;
|
|
224
|
+
get checkout(): Shop.CheckoutCategory;
|
|
225
|
+
get collection(): Shop.CollectionCategory;
|
|
226
|
+
get customer(): Shop.CustomerCategory;
|
|
227
|
+
get facet(): Shop.FacetCategory;
|
|
228
|
+
get hookDispatch(): Shop.HookDispatchCategory;
|
|
229
|
+
get hook(): Shop.HookCategory;
|
|
230
|
+
get marketingEvent(): Shop.MarketingEventCategory;
|
|
231
|
+
get marketingIdentity(): Shop.MarketingIdentityCategory;
|
|
232
|
+
get order(): Shop.OrderCategory;
|
|
233
|
+
get payment(): Shop.PaymentCategory;
|
|
234
|
+
get product(): Shop.ProductCategory;
|
|
235
|
+
get search(): Shop.SearchCategory;
|
|
236
|
+
get shipping(): Shop.ShippingCategory;
|
|
237
|
+
get subscription(): Shop.SubscriptionCategory;
|
|
238
|
+
}
|
|
239
|
+
export declare class ForgeCartClient {
|
|
240
|
+
private readonly _admin;
|
|
241
|
+
private readonly _shop;
|
|
242
|
+
constructor(config: ForgeCartClientConfig);
|
|
243
|
+
setAuthToken(token: string): void;
|
|
244
|
+
clearAuthToken(): void;
|
|
245
|
+
setTransactionToken(token: string): void;
|
|
246
|
+
clearTransactionToken(): void;
|
|
247
|
+
get admin(): ForgeCartAdminClient;
|
|
248
|
+
get shop(): ForgeCartShopClient;
|
|
249
|
+
}
|
package/src/client.generated.ts
CHANGED
|
@@ -24,6 +24,11 @@ export interface ForgeCartAdminClientConfig {
|
|
|
24
24
|
adminSecret?: string;
|
|
25
25
|
uploadEndpoint?: string;
|
|
26
26
|
headers?: Record<string, string>;
|
|
27
|
+
// Session preferences sent as forgecart-currency / forgecart-language
|
|
28
|
+
// headers on every request. Override later via setCurrencyCode() /
|
|
29
|
+
// setLanguageCode().
|
|
30
|
+
currencyCode?: string;
|
|
31
|
+
languageCode?: string;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
export interface ForgeCartShopClientConfig {
|
|
@@ -31,6 +36,11 @@ export interface ForgeCartShopClientConfig {
|
|
|
31
36
|
channelToken: string;
|
|
32
37
|
uploadEndpoint?: string;
|
|
33
38
|
headers?: Record<string, string>;
|
|
39
|
+
// Session preferences sent as forgecart-currency / forgecart-language
|
|
40
|
+
// headers on every request. Override later via setCurrencyCode() /
|
|
41
|
+
// setLanguageCode().
|
|
42
|
+
currencyCode?: string;
|
|
43
|
+
languageCode?: string;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
export interface ForgeCartClientConfig {
|
|
@@ -39,6 +49,11 @@ export interface ForgeCartClientConfig {
|
|
|
39
49
|
adminSecret?: string;
|
|
40
50
|
uploadEndpoint?: string;
|
|
41
51
|
headers?: Record<string, string>;
|
|
52
|
+
// Session preferences sent as forgecart-currency / forgecart-language
|
|
53
|
+
// headers on every request. Override later via setCurrencyCode() /
|
|
54
|
+
// setLanguageCode().
|
|
55
|
+
currencyCode?: string;
|
|
56
|
+
languageCode?: string;
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
export class SDKLogger {
|
|
@@ -120,14 +135,33 @@ export class BaseGraphQLClient {
|
|
|
120
135
|
private wsClientStale = false;
|
|
121
136
|
private authToken: string | null = null;
|
|
122
137
|
private transactionToken: string | null = null;
|
|
138
|
+
private currencyCode: string | null = null;
|
|
139
|
+
private languageCode: string | null = null;
|
|
123
140
|
private errorHandler: ErrorHandler | null = null;
|
|
141
|
+
private readonly persistSession: boolean;
|
|
142
|
+
private readonly tokenStorageKey: string;
|
|
124
143
|
|
|
125
144
|
constructor(
|
|
126
145
|
endpoint: string,
|
|
127
146
|
private readonly baseHeaders: Record<string, string>,
|
|
128
147
|
private readonly uploadEndpoint?: string,
|
|
148
|
+
options?: { persistSession?: boolean; currencyCode?: string; languageCode?: string },
|
|
129
149
|
) {
|
|
130
150
|
this.endpoint = endpoint.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
|
|
151
|
+
// Cross-tab session continuity: each new tab or reload builds a fresh
|
|
152
|
+
// client instance, so without a shared store every one would mint a new
|
|
153
|
+
// anonymous session server-side — and be counted as a new active user.
|
|
154
|
+
// Persist the captured token in localStorage (shared across same-origin
|
|
155
|
+
// tabs), keyed per endpoint + channel so separate stores never collide.
|
|
156
|
+
// Opt out with `{ persistSession: false }` when the host app owns token
|
|
157
|
+
// storage (e.g. the admin dashboard).
|
|
158
|
+
this.persistSession = options?.persistSession ?? true;
|
|
159
|
+
this.currencyCode = options?.currencyCode ?? null;
|
|
160
|
+
this.languageCode = options?.languageCode ?? null;
|
|
161
|
+
this.tokenStorageKey = `forgecart:auth:${this.endpoint}:${this.baseHeaders["forgecart-token"] ?? ""}`;
|
|
162
|
+
if (this.persistSession) {
|
|
163
|
+
this.authToken = this.readPersistedToken();
|
|
164
|
+
}
|
|
131
165
|
}
|
|
132
166
|
|
|
133
167
|
private getWsClient(): WsClient {
|
|
@@ -158,22 +192,65 @@ export class BaseGraphQLClient {
|
|
|
158
192
|
if (this.transactionToken) {
|
|
159
193
|
headers["forgecart-transaction-token"] = this.transactionToken;
|
|
160
194
|
}
|
|
195
|
+
if (this.currencyCode) {
|
|
196
|
+
headers["forgecart-currency"] = this.currencyCode;
|
|
197
|
+
}
|
|
198
|
+
if (this.languageCode) {
|
|
199
|
+
headers["forgecart-language"] = this.languageCode;
|
|
200
|
+
}
|
|
161
201
|
return headers;
|
|
162
202
|
}
|
|
163
203
|
|
|
164
204
|
setAuthToken(token: string): void {
|
|
165
205
|
if (this.authToken === token) return;
|
|
166
206
|
this.authToken = token;
|
|
207
|
+
this.persistToken(token);
|
|
167
208
|
this.disposeWsClient();
|
|
168
209
|
this.logger.info("Auth token set");
|
|
169
210
|
}
|
|
170
211
|
|
|
212
|
+
getAuthToken(): string | null {
|
|
213
|
+
return this.authToken;
|
|
214
|
+
}
|
|
215
|
+
|
|
171
216
|
clearAuthToken(): void {
|
|
172
217
|
this.authToken = null;
|
|
218
|
+
this.persistToken(null);
|
|
173
219
|
this.disposeWsClient();
|
|
174
220
|
this.logger.info("Auth token cleared");
|
|
175
221
|
}
|
|
176
222
|
|
|
223
|
+
// Currency/language preferences ride the WebSocket connection params,
|
|
224
|
+
// so changing one disposes the connection — the next request reconnects
|
|
225
|
+
// with the new forgecart-currency / forgecart-language headers.
|
|
226
|
+
setCurrencyCode(currencyCode: string): void {
|
|
227
|
+
if (this.currencyCode === currencyCode) return;
|
|
228
|
+
this.currencyCode = currencyCode;
|
|
229
|
+
this.disposeWsClient();
|
|
230
|
+
this.logger.info("Currency code set");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
clearCurrencyCode(): void {
|
|
234
|
+
if (this.currencyCode === null) return;
|
|
235
|
+
this.currencyCode = null;
|
|
236
|
+
this.disposeWsClient();
|
|
237
|
+
this.logger.info("Currency code cleared");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
setLanguageCode(languageCode: string): void {
|
|
241
|
+
if (this.languageCode === languageCode) return;
|
|
242
|
+
this.languageCode = languageCode;
|
|
243
|
+
this.disposeWsClient();
|
|
244
|
+
this.logger.info("Language code set");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
clearLanguageCode(): void {
|
|
248
|
+
if (this.languageCode === null) return;
|
|
249
|
+
this.languageCode = null;
|
|
250
|
+
this.disposeWsClient();
|
|
251
|
+
this.logger.info("Language code cleared");
|
|
252
|
+
}
|
|
253
|
+
|
|
177
254
|
setTransactionToken(token: string): void {
|
|
178
255
|
this.transactionToken = token;
|
|
179
256
|
this.logger.info("Transaction token set");
|
|
@@ -277,6 +354,7 @@ export class BaseGraphQLClient {
|
|
|
277
354
|
const token = result.extensions["forgecart-auth-token"] as string | undefined;
|
|
278
355
|
if (token && !this.authToken) {
|
|
279
356
|
this.authToken = token;
|
|
357
|
+
this.persistToken(token);
|
|
280
358
|
this.wsClientStale = true;
|
|
281
359
|
this.logger.info("Session token captured from extensions");
|
|
282
360
|
}
|
|
@@ -287,11 +365,37 @@ export class BaseGraphQLClient {
|
|
|
287
365
|
const token = result.extensions["forgecart-auth-token"] as string | undefined;
|
|
288
366
|
if (token && !this.authToken) {
|
|
289
367
|
this.authToken = token;
|
|
368
|
+
this.persistToken(token);
|
|
290
369
|
this.wsClientStale = true;
|
|
291
370
|
this.logger.info("Session token captured from upload response");
|
|
292
371
|
}
|
|
293
372
|
}
|
|
294
373
|
|
|
374
|
+
private readPersistedToken(): string | null {
|
|
375
|
+
if (typeof localStorage === "undefined") return null;
|
|
376
|
+
try {
|
|
377
|
+
return localStorage.getItem(this.tokenStorageKey);
|
|
378
|
+
} catch {
|
|
379
|
+
// Storage can throw (Safari private mode, disabled cookies, quota).
|
|
380
|
+
// Falling back to an in-memory session keeps the SDK functional.
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
private persistToken(token: string | null): void {
|
|
386
|
+
if (!this.persistSession || typeof localStorage === "undefined") return;
|
|
387
|
+
try {
|
|
388
|
+
if (token === null) {
|
|
389
|
+
localStorage.removeItem(this.tokenStorageKey);
|
|
390
|
+
} else {
|
|
391
|
+
localStorage.setItem(this.tokenStorageKey, token);
|
|
392
|
+
}
|
|
393
|
+
} catch {
|
|
394
|
+
// Persistence is best-effort; a storage failure must never break a
|
|
395
|
+
// request. The in-memory token still serves the current page.
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
295
399
|
private containsFiles(obj: unknown): boolean {
|
|
296
400
|
if (obj === null || obj === undefined) return false;
|
|
297
401
|
if (typeof obj !== "object") return false;
|
|
@@ -322,6 +426,8 @@ export class BaseGraphQLClient {
|
|
|
322
426
|
const forked = new BaseGraphQLClient(this.endpoint, this.baseHeaders, this.uploadEndpoint);
|
|
323
427
|
forked.authToken = this.authToken;
|
|
324
428
|
forked.transactionToken = transactionToken;
|
|
429
|
+
forked.currencyCode = this.currencyCode;
|
|
430
|
+
forked.languageCode = this.languageCode;
|
|
325
431
|
forked.wsClient = this.wsClient;
|
|
326
432
|
forked.ownsWsClient = false;
|
|
327
433
|
return forked;
|
|
@@ -374,7 +480,10 @@ export class ForgeCartAdminClient {
|
|
|
374
480
|
if (config.adminSecret) {
|
|
375
481
|
headers['forgecart-secret'] = config.adminSecret;
|
|
376
482
|
}
|
|
377
|
-
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint
|
|
483
|
+
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint, {
|
|
484
|
+
currencyCode: config.currencyCode,
|
|
485
|
+
languageCode: config.languageCode,
|
|
486
|
+
});
|
|
378
487
|
this._namespace = new AdminNamespace(this.client);
|
|
379
488
|
}
|
|
380
489
|
|
|
@@ -382,10 +491,30 @@ export class ForgeCartAdminClient {
|
|
|
382
491
|
this.client.setAuthToken(token);
|
|
383
492
|
}
|
|
384
493
|
|
|
494
|
+
getAuthToken(): string | null {
|
|
495
|
+
return this.client.getAuthToken();
|
|
496
|
+
}
|
|
497
|
+
|
|
385
498
|
clearAuthToken(): void {
|
|
386
499
|
this.client.clearAuthToken();
|
|
387
500
|
}
|
|
388
501
|
|
|
502
|
+
setCurrencyCode(currencyCode: string): void {
|
|
503
|
+
this.client.setCurrencyCode(currencyCode);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
clearCurrencyCode(): void {
|
|
507
|
+
this.client.clearCurrencyCode();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
setLanguageCode(languageCode: string): void {
|
|
511
|
+
this.client.setLanguageCode(languageCode);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
clearLanguageCode(): void {
|
|
515
|
+
this.client.clearLanguageCode();
|
|
516
|
+
}
|
|
517
|
+
|
|
389
518
|
setTransactionToken(token: string): void {
|
|
390
519
|
this.client.setTransactionToken(token);
|
|
391
520
|
}
|
|
@@ -527,6 +656,9 @@ export class ForgeCartAdminClient {
|
|
|
527
656
|
get channel(): Admin.ChannelCategory {
|
|
528
657
|
return this._namespace.channel;
|
|
529
658
|
}
|
|
659
|
+
get chat(): Admin.ChatCategory {
|
|
660
|
+
return this._namespace.chat;
|
|
661
|
+
}
|
|
530
662
|
get collection(): Admin.CollectionCategory {
|
|
531
663
|
return this._namespace.collection;
|
|
532
664
|
}
|
|
@@ -563,6 +695,9 @@ export class ForgeCartAdminClient {
|
|
|
563
695
|
get hook(): Admin.HookCategory {
|
|
564
696
|
return this._namespace.hook;
|
|
565
697
|
}
|
|
698
|
+
get market(): Admin.MarketCategory {
|
|
699
|
+
return this._namespace.market;
|
|
700
|
+
}
|
|
566
701
|
get marketingAttribution(): Admin.MarketingAttributionCategory {
|
|
567
702
|
return this._namespace.marketingAttribution;
|
|
568
703
|
}
|
|
@@ -572,6 +707,9 @@ export class ForgeCartAdminClient {
|
|
|
572
707
|
get marketingIdentity(): Admin.MarketingIdentityCategory {
|
|
573
708
|
return this._namespace.marketingIdentity;
|
|
574
709
|
}
|
|
710
|
+
get mission(): Admin.MissionCategory {
|
|
711
|
+
return this._namespace.mission;
|
|
712
|
+
}
|
|
575
713
|
get onboarding(): Admin.OnboardingCategory {
|
|
576
714
|
return this._namespace.onboarding;
|
|
577
715
|
}
|
|
@@ -658,7 +796,10 @@ export class ForgeCartShopClient {
|
|
|
658
796
|
|
|
659
797
|
constructor(config: ForgeCartShopClientConfig) {
|
|
660
798
|
const headers: Record<string, string> = { 'forgecart-token': config.channelToken, ...config.headers };
|
|
661
|
-
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint
|
|
799
|
+
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint, {
|
|
800
|
+
currencyCode: config.currencyCode,
|
|
801
|
+
languageCode: config.languageCode,
|
|
802
|
+
});
|
|
662
803
|
this._namespace = new ShopNamespace(this.client);
|
|
663
804
|
}
|
|
664
805
|
|
|
@@ -666,10 +807,30 @@ export class ForgeCartShopClient {
|
|
|
666
807
|
this.client.setAuthToken(token);
|
|
667
808
|
}
|
|
668
809
|
|
|
810
|
+
getAuthToken(): string | null {
|
|
811
|
+
return this.client.getAuthToken();
|
|
812
|
+
}
|
|
813
|
+
|
|
669
814
|
clearAuthToken(): void {
|
|
670
815
|
this.client.clearAuthToken();
|
|
671
816
|
}
|
|
672
817
|
|
|
818
|
+
setCurrencyCode(currencyCode: string): void {
|
|
819
|
+
this.client.setCurrencyCode(currencyCode);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
clearCurrencyCode(): void {
|
|
823
|
+
this.client.clearCurrencyCode();
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
setLanguageCode(languageCode: string): void {
|
|
827
|
+
this.client.setLanguageCode(languageCode);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
clearLanguageCode(): void {
|
|
831
|
+
this.client.clearLanguageCode();
|
|
832
|
+
}
|
|
833
|
+
|
|
673
834
|
setTransactionToken(token: string): void {
|
|
674
835
|
this.client.setTransactionToken(token);
|
|
675
836
|
}
|
|
@@ -727,6 +888,9 @@ export class ForgeCartShopClient {
|
|
|
727
888
|
get cart(): Shop.CartCategory {
|
|
728
889
|
return this._namespace.cart;
|
|
729
890
|
}
|
|
891
|
+
get channel(): Shop.ChannelCategory {
|
|
892
|
+
return this._namespace.channel;
|
|
893
|
+
}
|
|
730
894
|
get checkout(): Shop.CheckoutCategory {
|
|
731
895
|
return this._namespace.checkout;
|
|
732
896
|
}
|
|
@@ -776,8 +940,8 @@ export class ForgeCartClient {
|
|
|
776
940
|
private readonly _shop: ForgeCartShopClient;
|
|
777
941
|
|
|
778
942
|
constructor(config: ForgeCartClientConfig) {
|
|
779
|
-
this._admin = new ForgeCartAdminClient({ endpoint: config.endpoint + '/admin-api', channelToken: config.channelToken, adminSecret: config.adminSecret, uploadEndpoint: config.uploadEndpoint ? config.uploadEndpoint + '/admin-api' : undefined, headers: config.headers });
|
|
780
|
-
this._shop = new ForgeCartShopClient({ endpoint: config.endpoint + '/shop-api', channelToken: config.channelToken, uploadEndpoint: config.uploadEndpoint ? config.uploadEndpoint + '/shop-api' : undefined, headers: config.headers });
|
|
943
|
+
this._admin = new ForgeCartAdminClient({ endpoint: config.endpoint + '/admin-api', channelToken: config.channelToken, adminSecret: config.adminSecret, uploadEndpoint: config.uploadEndpoint ? config.uploadEndpoint + '/admin-api' : undefined, headers: config.headers, currencyCode: config.currencyCode, languageCode: config.languageCode });
|
|
944
|
+
this._shop = new ForgeCartShopClient({ endpoint: config.endpoint + '/shop-api', channelToken: config.channelToken, uploadEndpoint: config.uploadEndpoint ? config.uploadEndpoint + '/shop-api' : undefined, headers: config.headers, currencyCode: config.currencyCode, languageCode: config.languageCode });
|
|
781
945
|
this._admin.setShopPeer(this._shop);
|
|
782
946
|
}
|
|
783
947
|
|
|
@@ -791,6 +955,26 @@ export class ForgeCartClient {
|
|
|
791
955
|
this._shop.clearAuthToken();
|
|
792
956
|
}
|
|
793
957
|
|
|
958
|
+
setCurrencyCode(currencyCode: string): void {
|
|
959
|
+
this._admin.setCurrencyCode(currencyCode);
|
|
960
|
+
this._shop.setCurrencyCode(currencyCode);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
clearCurrencyCode(): void {
|
|
964
|
+
this._admin.clearCurrencyCode();
|
|
965
|
+
this._shop.clearCurrencyCode();
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
setLanguageCode(languageCode: string): void {
|
|
969
|
+
this._admin.setLanguageCode(languageCode);
|
|
970
|
+
this._shop.setLanguageCode(languageCode);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
clearLanguageCode(): void {
|
|
974
|
+
this._admin.clearLanguageCode();
|
|
975
|
+
this._shop.clearLanguageCode();
|
|
976
|
+
}
|
|
977
|
+
|
|
794
978
|
setTransactionToken(token: string): void {
|
|
795
979
|
this._admin.setTransactionToken(token);
|
|
796
980
|
this._shop.setTransactionToken(token);
|
|
@@ -807,39 +991,4 @@ export class ForgeCartClient {
|
|
|
807
991
|
get shop(): ForgeCartShopClient {
|
|
808
992
|
return this._shop;
|
|
809
993
|
}
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
import { Module, type DynamicModule } from '@nestjs/common';
|
|
813
|
-
|
|
814
|
-
@Module({})
|
|
815
|
-
export class ForgeCartGraphQLModule {
|
|
816
|
-
static forAdmin(config: ForgeCartAdminClientConfig): DynamicModule {
|
|
817
|
-
const client = new ForgeCartAdminClient(config);
|
|
818
|
-
return {
|
|
819
|
-
module: ForgeCartGraphQLModule,
|
|
820
|
-
providers: [{ provide: ForgeCartAdminClient, useValue: client }],
|
|
821
|
-
exports: [ForgeCartAdminClient],
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
static forShop(config: ForgeCartShopClientConfig): DynamicModule {
|
|
825
|
-
const client = new ForgeCartShopClient(config);
|
|
826
|
-
return {
|
|
827
|
-
module: ForgeCartGraphQLModule,
|
|
828
|
-
providers: [{ provide: ForgeCartShopClient, useValue: client }],
|
|
829
|
-
exports: [ForgeCartShopClient],
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
static forRoot(config: ForgeCartClientConfig): DynamicModule {
|
|
834
|
-
const client = new ForgeCartClient(config);
|
|
835
|
-
return {
|
|
836
|
-
module: ForgeCartGraphQLModule,
|
|
837
|
-
providers: [
|
|
838
|
-
{ provide: ForgeCartClient, useValue: client },
|
|
839
|
-
{ provide: ForgeCartAdminClient, useValue: client.admin },
|
|
840
|
-
{ provide: ForgeCartShopClient, useValue: client.shop },
|
|
841
|
-
],
|
|
842
|
-
exports: [ForgeCartClient, ForgeCartAdminClient, ForgeCartShopClient],
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
994
|
}
|