@forgecart/sdk 1.2.7 → 1.202607061936.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 +481 -33
- 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 +40 -1
- package/dist/client.generated.js +152 -6
- package/dist/documents.generated.d.ts +28 -6
- package/dist/documents.generated.js +517 -41
- package/dist/index.d.ts +1 -0
- package/dist/shop-types.generated.d.ts +205 -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 +1019 -96
- 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 +185 -5
- package/src/documents.generated.d.ts +473 -0
- package/src/documents.generated.ts +530 -32
- 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 +275 -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
|
@@ -20,25 +20,49 @@ import type * as Shop from './shop.generated';
|
|
|
20
20
|
|
|
21
21
|
export interface ForgeCartAdminClientConfig {
|
|
22
22
|
endpoint: string;
|
|
23
|
+
// Optional dedicated WebSocket endpoint. Defaults to `endpoint` with the
|
|
24
|
+
// scheme swapped to ws(s). Set when WS must bypass an HTTP-only proxy
|
|
25
|
+
// hop (e.g. the Angular dev-server) and connect to the API directly.
|
|
26
|
+
wsEndpoint?: string;
|
|
23
27
|
channelToken: string;
|
|
24
28
|
adminSecret?: string;
|
|
25
29
|
uploadEndpoint?: string;
|
|
26
30
|
headers?: Record<string, string>;
|
|
31
|
+
// Session preferences sent as forgecart-currency / forgecart-language
|
|
32
|
+
// headers on every request. Override later via setCurrencyCode() /
|
|
33
|
+
// setLanguageCode().
|
|
34
|
+
currencyCode?: string;
|
|
35
|
+
languageCode?: string;
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
export interface ForgeCartShopClientConfig {
|
|
30
39
|
endpoint: string;
|
|
40
|
+
// Optional dedicated WebSocket endpoint. Defaults to `endpoint` with the
|
|
41
|
+
// scheme swapped to ws(s). Set when WS must bypass an HTTP-only proxy
|
|
42
|
+
// hop (e.g. the Angular dev-server) and connect to the API directly.
|
|
43
|
+
wsEndpoint?: string;
|
|
31
44
|
channelToken: string;
|
|
32
45
|
uploadEndpoint?: string;
|
|
33
46
|
headers?: Record<string, string>;
|
|
47
|
+
// Session preferences sent as forgecart-currency / forgecart-language
|
|
48
|
+
// headers on every request. Override later via setCurrencyCode() /
|
|
49
|
+
// setLanguageCode().
|
|
50
|
+
currencyCode?: string;
|
|
51
|
+
languageCode?: string;
|
|
34
52
|
}
|
|
35
53
|
|
|
36
54
|
export interface ForgeCartClientConfig {
|
|
37
55
|
endpoint: string;
|
|
56
|
+
wsEndpoint?: string;
|
|
38
57
|
channelToken: string;
|
|
39
58
|
adminSecret?: string;
|
|
40
59
|
uploadEndpoint?: string;
|
|
41
60
|
headers?: Record<string, string>;
|
|
61
|
+
// Session preferences sent as forgecart-currency / forgecart-language
|
|
62
|
+
// headers on every request. Override later via setCurrencyCode() /
|
|
63
|
+
// setLanguageCode().
|
|
64
|
+
currencyCode?: string;
|
|
65
|
+
languageCode?: string;
|
|
42
66
|
}
|
|
43
67
|
|
|
44
68
|
export class SDKLogger {
|
|
@@ -120,14 +144,33 @@ export class BaseGraphQLClient {
|
|
|
120
144
|
private wsClientStale = false;
|
|
121
145
|
private authToken: string | null = null;
|
|
122
146
|
private transactionToken: string | null = null;
|
|
147
|
+
private currencyCode: string | null = null;
|
|
148
|
+
private languageCode: string | null = null;
|
|
123
149
|
private errorHandler: ErrorHandler | null = null;
|
|
150
|
+
private readonly persistSession: boolean;
|
|
151
|
+
private readonly tokenStorageKey: string;
|
|
124
152
|
|
|
125
153
|
constructor(
|
|
126
154
|
endpoint: string,
|
|
127
155
|
private readonly baseHeaders: Record<string, string>,
|
|
128
156
|
private readonly uploadEndpoint?: string,
|
|
157
|
+
options?: { persistSession?: boolean; currencyCode?: string; languageCode?: string; wsEndpoint?: string },
|
|
129
158
|
) {
|
|
130
|
-
this.endpoint = endpoint.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
|
|
159
|
+
this.endpoint = (options?.wsEndpoint ?? endpoint).replace(/^http:/, "ws:").replace(/^https:/, "wss:");
|
|
160
|
+
// Cross-tab session continuity: each new tab or reload builds a fresh
|
|
161
|
+
// client instance, so without a shared store every one would mint a new
|
|
162
|
+
// anonymous session server-side — and be counted as a new active user.
|
|
163
|
+
// Persist the captured token in localStorage (shared across same-origin
|
|
164
|
+
// tabs), keyed per endpoint + channel so separate stores never collide.
|
|
165
|
+
// Opt out with `{ persistSession: false }` when the host app owns token
|
|
166
|
+
// storage (e.g. the admin dashboard).
|
|
167
|
+
this.persistSession = options?.persistSession ?? true;
|
|
168
|
+
this.currencyCode = options?.currencyCode ?? null;
|
|
169
|
+
this.languageCode = options?.languageCode ?? null;
|
|
170
|
+
this.tokenStorageKey = `forgecart:auth:${this.endpoint}:${this.baseHeaders["forgecart-token"] ?? ""}`;
|
|
171
|
+
if (this.persistSession) {
|
|
172
|
+
this.authToken = this.readPersistedToken();
|
|
173
|
+
}
|
|
131
174
|
}
|
|
132
175
|
|
|
133
176
|
private getWsClient(): WsClient {
|
|
@@ -158,12 +201,19 @@ export class BaseGraphQLClient {
|
|
|
158
201
|
if (this.transactionToken) {
|
|
159
202
|
headers["forgecart-transaction-token"] = this.transactionToken;
|
|
160
203
|
}
|
|
204
|
+
if (this.currencyCode) {
|
|
205
|
+
headers["forgecart-currency"] = this.currencyCode;
|
|
206
|
+
}
|
|
207
|
+
if (this.languageCode) {
|
|
208
|
+
headers["forgecart-language"] = this.languageCode;
|
|
209
|
+
}
|
|
161
210
|
return headers;
|
|
162
211
|
}
|
|
163
212
|
|
|
164
213
|
setAuthToken(token: string): void {
|
|
165
214
|
if (this.authToken === token) return;
|
|
166
215
|
this.authToken = token;
|
|
216
|
+
this.persistToken(token);
|
|
167
217
|
this.disposeWsClient();
|
|
168
218
|
this.logger.info("Auth token set");
|
|
169
219
|
}
|
|
@@ -174,10 +224,42 @@ export class BaseGraphQLClient {
|
|
|
174
224
|
|
|
175
225
|
clearAuthToken(): void {
|
|
176
226
|
this.authToken = null;
|
|
227
|
+
this.persistToken(null);
|
|
177
228
|
this.disposeWsClient();
|
|
178
229
|
this.logger.info("Auth token cleared");
|
|
179
230
|
}
|
|
180
231
|
|
|
232
|
+
// Currency/language preferences ride the WebSocket connection params,
|
|
233
|
+
// so changing one disposes the connection — the next request reconnects
|
|
234
|
+
// with the new forgecart-currency / forgecart-language headers.
|
|
235
|
+
setCurrencyCode(currencyCode: string): void {
|
|
236
|
+
if (this.currencyCode === currencyCode) return;
|
|
237
|
+
this.currencyCode = currencyCode;
|
|
238
|
+
this.disposeWsClient();
|
|
239
|
+
this.logger.info("Currency code set");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
clearCurrencyCode(): void {
|
|
243
|
+
if (this.currencyCode === null) return;
|
|
244
|
+
this.currencyCode = null;
|
|
245
|
+
this.disposeWsClient();
|
|
246
|
+
this.logger.info("Currency code cleared");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
setLanguageCode(languageCode: string): void {
|
|
250
|
+
if (this.languageCode === languageCode) return;
|
|
251
|
+
this.languageCode = languageCode;
|
|
252
|
+
this.disposeWsClient();
|
|
253
|
+
this.logger.info("Language code set");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
clearLanguageCode(): void {
|
|
257
|
+
if (this.languageCode === null) return;
|
|
258
|
+
this.languageCode = null;
|
|
259
|
+
this.disposeWsClient();
|
|
260
|
+
this.logger.info("Language code cleared");
|
|
261
|
+
}
|
|
262
|
+
|
|
181
263
|
setTransactionToken(token: string): void {
|
|
182
264
|
this.transactionToken = token;
|
|
183
265
|
this.logger.info("Transaction token set");
|
|
@@ -281,6 +363,7 @@ export class BaseGraphQLClient {
|
|
|
281
363
|
const token = result.extensions["forgecart-auth-token"] as string | undefined;
|
|
282
364
|
if (token && !this.authToken) {
|
|
283
365
|
this.authToken = token;
|
|
366
|
+
this.persistToken(token);
|
|
284
367
|
this.wsClientStale = true;
|
|
285
368
|
this.logger.info("Session token captured from extensions");
|
|
286
369
|
}
|
|
@@ -291,11 +374,37 @@ export class BaseGraphQLClient {
|
|
|
291
374
|
const token = result.extensions["forgecart-auth-token"] as string | undefined;
|
|
292
375
|
if (token && !this.authToken) {
|
|
293
376
|
this.authToken = token;
|
|
377
|
+
this.persistToken(token);
|
|
294
378
|
this.wsClientStale = true;
|
|
295
379
|
this.logger.info("Session token captured from upload response");
|
|
296
380
|
}
|
|
297
381
|
}
|
|
298
382
|
|
|
383
|
+
private readPersistedToken(): string | null {
|
|
384
|
+
if (typeof localStorage === "undefined") return null;
|
|
385
|
+
try {
|
|
386
|
+
return localStorage.getItem(this.tokenStorageKey);
|
|
387
|
+
} catch {
|
|
388
|
+
// Storage can throw (Safari private mode, disabled cookies, quota).
|
|
389
|
+
// Falling back to an in-memory session keeps the SDK functional.
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
private persistToken(token: string | null): void {
|
|
395
|
+
if (!this.persistSession || typeof localStorage === "undefined") return;
|
|
396
|
+
try {
|
|
397
|
+
if (token === null) {
|
|
398
|
+
localStorage.removeItem(this.tokenStorageKey);
|
|
399
|
+
} else {
|
|
400
|
+
localStorage.setItem(this.tokenStorageKey, token);
|
|
401
|
+
}
|
|
402
|
+
} catch {
|
|
403
|
+
// Persistence is best-effort; a storage failure must never break a
|
|
404
|
+
// request. The in-memory token still serves the current page.
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
299
408
|
private containsFiles(obj: unknown): boolean {
|
|
300
409
|
if (obj === null || obj === undefined) return false;
|
|
301
410
|
if (typeof obj !== "object") return false;
|
|
@@ -326,6 +435,8 @@ export class BaseGraphQLClient {
|
|
|
326
435
|
const forked = new BaseGraphQLClient(this.endpoint, this.baseHeaders, this.uploadEndpoint);
|
|
327
436
|
forked.authToken = this.authToken;
|
|
328
437
|
forked.transactionToken = transactionToken;
|
|
438
|
+
forked.currencyCode = this.currencyCode;
|
|
439
|
+
forked.languageCode = this.languageCode;
|
|
329
440
|
forked.wsClient = this.wsClient;
|
|
330
441
|
forked.ownsWsClient = false;
|
|
331
442
|
return forked;
|
|
@@ -378,7 +489,11 @@ export class ForgeCartAdminClient {
|
|
|
378
489
|
if (config.adminSecret) {
|
|
379
490
|
headers['forgecart-secret'] = config.adminSecret;
|
|
380
491
|
}
|
|
381
|
-
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint
|
|
492
|
+
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint, {
|
|
493
|
+
wsEndpoint: config.wsEndpoint,
|
|
494
|
+
currencyCode: config.currencyCode,
|
|
495
|
+
languageCode: config.languageCode,
|
|
496
|
+
});
|
|
382
497
|
this._namespace = new AdminNamespace(this.client);
|
|
383
498
|
}
|
|
384
499
|
|
|
@@ -394,6 +509,22 @@ export class ForgeCartAdminClient {
|
|
|
394
509
|
this.client.clearAuthToken();
|
|
395
510
|
}
|
|
396
511
|
|
|
512
|
+
setCurrencyCode(currencyCode: string): void {
|
|
513
|
+
this.client.setCurrencyCode(currencyCode);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
clearCurrencyCode(): void {
|
|
517
|
+
this.client.clearCurrencyCode();
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
setLanguageCode(languageCode: string): void {
|
|
521
|
+
this.client.setLanguageCode(languageCode);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
clearLanguageCode(): void {
|
|
525
|
+
this.client.clearLanguageCode();
|
|
526
|
+
}
|
|
527
|
+
|
|
397
528
|
setTransactionToken(token: string): void {
|
|
398
529
|
this.client.setTransactionToken(token);
|
|
399
530
|
}
|
|
@@ -574,6 +705,9 @@ export class ForgeCartAdminClient {
|
|
|
574
705
|
get hook(): Admin.HookCategory {
|
|
575
706
|
return this._namespace.hook;
|
|
576
707
|
}
|
|
708
|
+
get market(): Admin.MarketCategory {
|
|
709
|
+
return this._namespace.market;
|
|
710
|
+
}
|
|
577
711
|
get marketingAttribution(): Admin.MarketingAttributionCategory {
|
|
578
712
|
return this._namespace.marketingAttribution;
|
|
579
713
|
}
|
|
@@ -583,6 +717,9 @@ export class ForgeCartAdminClient {
|
|
|
583
717
|
get marketingIdentity(): Admin.MarketingIdentityCategory {
|
|
584
718
|
return this._namespace.marketingIdentity;
|
|
585
719
|
}
|
|
720
|
+
get mission(): Admin.MissionCategory {
|
|
721
|
+
return this._namespace.mission;
|
|
722
|
+
}
|
|
586
723
|
get onboarding(): Admin.OnboardingCategory {
|
|
587
724
|
return this._namespace.onboarding;
|
|
588
725
|
}
|
|
@@ -669,7 +806,11 @@ export class ForgeCartShopClient {
|
|
|
669
806
|
|
|
670
807
|
constructor(config: ForgeCartShopClientConfig) {
|
|
671
808
|
const headers: Record<string, string> = { 'forgecart-token': config.channelToken, ...config.headers };
|
|
672
|
-
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint
|
|
809
|
+
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint, {
|
|
810
|
+
wsEndpoint: config.wsEndpoint,
|
|
811
|
+
currencyCode: config.currencyCode,
|
|
812
|
+
languageCode: config.languageCode,
|
|
813
|
+
});
|
|
673
814
|
this._namespace = new ShopNamespace(this.client);
|
|
674
815
|
}
|
|
675
816
|
|
|
@@ -685,6 +826,22 @@ export class ForgeCartShopClient {
|
|
|
685
826
|
this.client.clearAuthToken();
|
|
686
827
|
}
|
|
687
828
|
|
|
829
|
+
setCurrencyCode(currencyCode: string): void {
|
|
830
|
+
this.client.setCurrencyCode(currencyCode);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
clearCurrencyCode(): void {
|
|
834
|
+
this.client.clearCurrencyCode();
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
setLanguageCode(languageCode: string): void {
|
|
838
|
+
this.client.setLanguageCode(languageCode);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
clearLanguageCode(): void {
|
|
842
|
+
this.client.clearLanguageCode();
|
|
843
|
+
}
|
|
844
|
+
|
|
688
845
|
setTransactionToken(token: string): void {
|
|
689
846
|
this.client.setTransactionToken(token);
|
|
690
847
|
}
|
|
@@ -742,6 +899,9 @@ export class ForgeCartShopClient {
|
|
|
742
899
|
get cart(): Shop.CartCategory {
|
|
743
900
|
return this._namespace.cart;
|
|
744
901
|
}
|
|
902
|
+
get channel(): Shop.ChannelCategory {
|
|
903
|
+
return this._namespace.channel;
|
|
904
|
+
}
|
|
745
905
|
get checkout(): Shop.CheckoutCategory {
|
|
746
906
|
return this._namespace.checkout;
|
|
747
907
|
}
|
|
@@ -791,8 +951,8 @@ export class ForgeCartClient {
|
|
|
791
951
|
private readonly _shop: ForgeCartShopClient;
|
|
792
952
|
|
|
793
953
|
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 });
|
|
954
|
+
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 });
|
|
955
|
+
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
956
|
this._admin.setShopPeer(this._shop);
|
|
797
957
|
}
|
|
798
958
|
|
|
@@ -806,6 +966,26 @@ export class ForgeCartClient {
|
|
|
806
966
|
this._shop.clearAuthToken();
|
|
807
967
|
}
|
|
808
968
|
|
|
969
|
+
setCurrencyCode(currencyCode: string): void {
|
|
970
|
+
this._admin.setCurrencyCode(currencyCode);
|
|
971
|
+
this._shop.setCurrencyCode(currencyCode);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
clearCurrencyCode(): void {
|
|
975
|
+
this._admin.clearCurrencyCode();
|
|
976
|
+
this._shop.clearCurrencyCode();
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
setLanguageCode(languageCode: string): void {
|
|
980
|
+
this._admin.setLanguageCode(languageCode);
|
|
981
|
+
this._shop.setLanguageCode(languageCode);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
clearLanguageCode(): void {
|
|
985
|
+
this._admin.clearLanguageCode();
|
|
986
|
+
this._shop.clearLanguageCode();
|
|
987
|
+
}
|
|
988
|
+
|
|
809
989
|
setTransactionToken(token: string): void {
|
|
810
990
|
this._admin.setTransactionToken(token);
|
|
811
991
|
this._shop.setTransactionToken(token);
|