@forgecart/sdk 1.2.7 → 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 +2 -2
- package/dist/admin-types.generated.d.ts +460 -29
- package/dist/admin.d.ts +2 -0
- package/dist/admin.generated.d.ts +67 -27
- package/dist/admin.generated.js +88 -4
- package/dist/admin.js +35 -31
- package/dist/client.generated.d.ts +36 -1
- package/dist/client.generated.js +149 -5
- package/dist/documents.generated.d.ts +27 -5
- package/dist/documents.generated.js +492 -39
- package/dist/index.d.ts +1 -0
- package/dist/shop-types.generated.d.ts +190 -13
- package/dist/shop.d.ts +1 -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 +8 -4
- package/src/admin-types.generated.d.ts +10013 -0
- package/src/admin-types.generated.ts +979 -92
- package/src/admin.generated.d.ts +806 -0
- package/src/admin.generated.ts +117 -29
- package/src/admin.ts +2 -0
- package/src/client.generated.d.ts +249 -0
- package/src/client.generated.ts +173 -4
- package/src/documents.generated.d.ts +473 -0
- package/src/documents.generated.ts +505 -30
- 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 -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 +259 -13
- package/src/shop.generated.d.ts +213 -0
- package/src/shop.generated.ts +22 -5
- package/src/shop.ts +1 -0
- 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,12 +192,19 @@ 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
|
}
|
|
@@ -174,10 +215,42 @@ export class BaseGraphQLClient {
|
|
|
174
215
|
|
|
175
216
|
clearAuthToken(): void {
|
|
176
217
|
this.authToken = null;
|
|
218
|
+
this.persistToken(null);
|
|
177
219
|
this.disposeWsClient();
|
|
178
220
|
this.logger.info("Auth token cleared");
|
|
179
221
|
}
|
|
180
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
|
+
|
|
181
254
|
setTransactionToken(token: string): void {
|
|
182
255
|
this.transactionToken = token;
|
|
183
256
|
this.logger.info("Transaction token set");
|
|
@@ -281,6 +354,7 @@ export class BaseGraphQLClient {
|
|
|
281
354
|
const token = result.extensions["forgecart-auth-token"] as string | undefined;
|
|
282
355
|
if (token && !this.authToken) {
|
|
283
356
|
this.authToken = token;
|
|
357
|
+
this.persistToken(token);
|
|
284
358
|
this.wsClientStale = true;
|
|
285
359
|
this.logger.info("Session token captured from extensions");
|
|
286
360
|
}
|
|
@@ -291,11 +365,37 @@ export class BaseGraphQLClient {
|
|
|
291
365
|
const token = result.extensions["forgecart-auth-token"] as string | undefined;
|
|
292
366
|
if (token && !this.authToken) {
|
|
293
367
|
this.authToken = token;
|
|
368
|
+
this.persistToken(token);
|
|
294
369
|
this.wsClientStale = true;
|
|
295
370
|
this.logger.info("Session token captured from upload response");
|
|
296
371
|
}
|
|
297
372
|
}
|
|
298
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
|
+
|
|
299
399
|
private containsFiles(obj: unknown): boolean {
|
|
300
400
|
if (obj === null || obj === undefined) return false;
|
|
301
401
|
if (typeof obj !== "object") return false;
|
|
@@ -326,6 +426,8 @@ export class BaseGraphQLClient {
|
|
|
326
426
|
const forked = new BaseGraphQLClient(this.endpoint, this.baseHeaders, this.uploadEndpoint);
|
|
327
427
|
forked.authToken = this.authToken;
|
|
328
428
|
forked.transactionToken = transactionToken;
|
|
429
|
+
forked.currencyCode = this.currencyCode;
|
|
430
|
+
forked.languageCode = this.languageCode;
|
|
329
431
|
forked.wsClient = this.wsClient;
|
|
330
432
|
forked.ownsWsClient = false;
|
|
331
433
|
return forked;
|
|
@@ -378,7 +480,10 @@ export class ForgeCartAdminClient {
|
|
|
378
480
|
if (config.adminSecret) {
|
|
379
481
|
headers['forgecart-secret'] = config.adminSecret;
|
|
380
482
|
}
|
|
381
|
-
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
|
+
});
|
|
382
487
|
this._namespace = new AdminNamespace(this.client);
|
|
383
488
|
}
|
|
384
489
|
|
|
@@ -394,6 +499,22 @@ export class ForgeCartAdminClient {
|
|
|
394
499
|
this.client.clearAuthToken();
|
|
395
500
|
}
|
|
396
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
|
+
|
|
397
518
|
setTransactionToken(token: string): void {
|
|
398
519
|
this.client.setTransactionToken(token);
|
|
399
520
|
}
|
|
@@ -574,6 +695,9 @@ export class ForgeCartAdminClient {
|
|
|
574
695
|
get hook(): Admin.HookCategory {
|
|
575
696
|
return this._namespace.hook;
|
|
576
697
|
}
|
|
698
|
+
get market(): Admin.MarketCategory {
|
|
699
|
+
return this._namespace.market;
|
|
700
|
+
}
|
|
577
701
|
get marketingAttribution(): Admin.MarketingAttributionCategory {
|
|
578
702
|
return this._namespace.marketingAttribution;
|
|
579
703
|
}
|
|
@@ -583,6 +707,9 @@ export class ForgeCartAdminClient {
|
|
|
583
707
|
get marketingIdentity(): Admin.MarketingIdentityCategory {
|
|
584
708
|
return this._namespace.marketingIdentity;
|
|
585
709
|
}
|
|
710
|
+
get mission(): Admin.MissionCategory {
|
|
711
|
+
return this._namespace.mission;
|
|
712
|
+
}
|
|
586
713
|
get onboarding(): Admin.OnboardingCategory {
|
|
587
714
|
return this._namespace.onboarding;
|
|
588
715
|
}
|
|
@@ -669,7 +796,10 @@ export class ForgeCartShopClient {
|
|
|
669
796
|
|
|
670
797
|
constructor(config: ForgeCartShopClientConfig) {
|
|
671
798
|
const headers: Record<string, string> = { 'forgecart-token': config.channelToken, ...config.headers };
|
|
672
|
-
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
|
+
});
|
|
673
803
|
this._namespace = new ShopNamespace(this.client);
|
|
674
804
|
}
|
|
675
805
|
|
|
@@ -685,6 +815,22 @@ export class ForgeCartShopClient {
|
|
|
685
815
|
this.client.clearAuthToken();
|
|
686
816
|
}
|
|
687
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
|
+
|
|
688
834
|
setTransactionToken(token: string): void {
|
|
689
835
|
this.client.setTransactionToken(token);
|
|
690
836
|
}
|
|
@@ -742,6 +888,9 @@ export class ForgeCartShopClient {
|
|
|
742
888
|
get cart(): Shop.CartCategory {
|
|
743
889
|
return this._namespace.cart;
|
|
744
890
|
}
|
|
891
|
+
get channel(): Shop.ChannelCategory {
|
|
892
|
+
return this._namespace.channel;
|
|
893
|
+
}
|
|
745
894
|
get checkout(): Shop.CheckoutCategory {
|
|
746
895
|
return this._namespace.checkout;
|
|
747
896
|
}
|
|
@@ -791,8 +940,8 @@ export class ForgeCartClient {
|
|
|
791
940
|
private readonly _shop: ForgeCartShopClient;
|
|
792
941
|
|
|
793
942
|
constructor(config: ForgeCartClientConfig) {
|
|
794
|
-
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 });
|
|
795
|
-
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 });
|
|
796
945
|
this._admin.setShopPeer(this._shop);
|
|
797
946
|
}
|
|
798
947
|
|
|
@@ -806,6 +955,26 @@ export class ForgeCartClient {
|
|
|
806
955
|
this._shop.clearAuthToken();
|
|
807
956
|
}
|
|
808
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
|
+
|
|
809
978
|
setTransactionToken(token: string): void {
|
|
810
979
|
this._admin.setTransactionToken(token);
|
|
811
980
|
this._shop.setTransactionToken(token);
|