@forgecart/sdk 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -87
- package/dist/admin-types.generated.d.ts +9884 -0
- package/dist/admin.d.ts +55 -8
- package/dist/admin.generated.d.ts +790 -0
- package/dist/admin.generated.js +1801 -0
- package/dist/admin.js +112 -23
- package/dist/client.generated.d.ts +251 -0
- package/dist/client.generated.js +757 -0
- package/dist/documents.generated.d.ts +465 -0
- package/dist/documents.generated.js +24283 -0
- package/dist/error-utils.d.ts +25 -0
- package/dist/error-utils.js +59 -0
- package/dist/hook-event-map.generated.d.ts +243 -0
- package/dist/hook-event-map.generated.js +9 -0
- package/dist/index.d.ts +23 -59
- package/dist/index.js +35 -83
- package/dist/sdk-hook-subscription.generated.d.ts +29 -0
- package/dist/sdk-hook-subscription.generated.js +73 -0
- package/dist/sdk-plugin.generated.d.ts +38 -0
- package/dist/sdk-plugin.generated.js +31 -0
- package/dist/sdk-types.generated.d.ts +56 -0
- package/dist/sdk-types.generated.js +28 -0
- package/dist/shop-types.generated.d.ts +4776 -0
- package/dist/shop.d.ts +18 -8
- package/dist/shop.generated.d.ts +213 -0
- package/dist/shop.generated.js +465 -0
- package/dist/shop.js +37 -23
- package/dist/upload.d.ts +14 -0
- package/dist/upload.js +163 -0
- package/package.json +10 -25
- package/src/admin-types.generated.ts +28377 -0
- package/src/admin.generated.ts +1771 -0
- package/src/admin.ts +55 -9
- package/src/client.generated.ts +845 -0
- package/src/documents.generated.ts +24730 -0
- package/src/error-utils.ts +74 -0
- package/src/hook-event-map.generated.ts +252 -0
- package/src/index.ts +23 -115
- package/src/sdk-hook-subscription.generated.ts +93 -0
- package/src/sdk-plugin.generated.ts +59 -0
- package/src/sdk-types.generated.ts +79 -0
- package/src/shop-types.generated.ts +10400 -0
- package/src/shop.generated.ts +452 -0
- package/src/shop.ts +18 -9
- package/src/upload.ts +211 -0
- package/LICENSE +0 -21
- package/dist/admin-namespace.d.ts +0 -2688
- package/dist/admin-namespace.js +0 -9691
- package/dist/admin-types.d.ts +0 -16195
- package/dist/shop-namespace.d.ts +0 -718
- package/dist/shop-namespace.js +0 -3124
- package/dist/shop-types.d.ts +0 -6310
- package/src/admin-namespace.ts +0 -11428
- package/src/admin-types.ts +0 -10809
- package/src/shop-namespace.ts +0 -3547
- package/src/shop-types.ts +0 -4684
- /package/dist/{admin-types.js → admin-types.generated.js} +0 -0
- /package/dist/{shop-types.js → shop-types.generated.js} +0 -0
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* AUTO-GENERATED FILE — DO NOT EDIT
|
|
5
|
+
*
|
|
6
|
+
* This file was generated by @forgecart/client-sdk-generators.
|
|
7
|
+
* Any manual changes will be overwritten on the next generation run.
|
|
8
|
+
*/
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
36
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
37
|
+
var useValue = arguments.length > 2;
|
|
38
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
39
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
40
|
+
}
|
|
41
|
+
return useValue ? value : void 0;
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.ForgeCartGraphQLModule = exports.ForgeCartClient = exports.ForgeCartShopClient = exports.ForgeCartAdminClient = exports.TransactionContext = exports.BaseGraphQLClient = exports.QueryObservable = exports.ClientError = exports.SDKLogger = void 0;
|
|
45
|
+
exports.setAuthToken = setAuthToken;
|
|
46
|
+
exports.clearAuthToken = clearAuthToken;
|
|
47
|
+
exports.setTransactionToken = setTransactionToken;
|
|
48
|
+
exports.clearTransactionToken = clearTransactionToken;
|
|
49
|
+
const rxjs_1 = require("rxjs");
|
|
50
|
+
const graphql_ws_1 = require("graphql-ws");
|
|
51
|
+
const upload_1 = require("./upload");
|
|
52
|
+
const sdk_hook_subscription_generated_1 = require("./sdk-hook-subscription.generated");
|
|
53
|
+
const admin_generated_1 = require("./admin.generated");
|
|
54
|
+
const shop_generated_1 = require("./shop.generated");
|
|
55
|
+
class SDKLogger {
|
|
56
|
+
prefix = "[ForgeCartSDK]";
|
|
57
|
+
info(message, data) {
|
|
58
|
+
console.log(this.prefix, message, data ?? "");
|
|
59
|
+
}
|
|
60
|
+
warn(message, data) {
|
|
61
|
+
console.warn(this.prefix, message, data ?? "");
|
|
62
|
+
}
|
|
63
|
+
error(message, data) {
|
|
64
|
+
console.error(this.prefix, message, data ?? "");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.SDKLogger = SDKLogger;
|
|
68
|
+
class ClientError extends Error {
|
|
69
|
+
response;
|
|
70
|
+
constructor(response, message) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.response = response;
|
|
73
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.ClientError = ClientError;
|
|
77
|
+
/**
|
|
78
|
+
* An Observable that is also PromiseLike, so `await` resolves the first emitted value.
|
|
79
|
+
* Use `.subscribe()` for streaming, `await` for single-shot request-response.
|
|
80
|
+
*/
|
|
81
|
+
class QueryObservable extends rxjs_1.Observable {
|
|
82
|
+
then(onfulfilled, onrejected) {
|
|
83
|
+
return (0, rxjs_1.firstValueFrom)(this).then(onfulfilled, onrejected);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.QueryObservable = QueryObservable;
|
|
87
|
+
class BaseGraphQLClient {
|
|
88
|
+
baseHeaders;
|
|
89
|
+
uploadEndpoint;
|
|
90
|
+
logger = new SDKLogger();
|
|
91
|
+
endpoint;
|
|
92
|
+
wsClient = null;
|
|
93
|
+
ownsWsClient = true;
|
|
94
|
+
wsClientStale = false;
|
|
95
|
+
authToken = null;
|
|
96
|
+
transactionToken = null;
|
|
97
|
+
errorHandler = null;
|
|
98
|
+
constructor(endpoint, baseHeaders, uploadEndpoint) {
|
|
99
|
+
this.baseHeaders = baseHeaders;
|
|
100
|
+
this.uploadEndpoint = uploadEndpoint;
|
|
101
|
+
this.endpoint = endpoint.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
|
|
102
|
+
}
|
|
103
|
+
getWsClient() {
|
|
104
|
+
if (this.wsClient && this.wsClientStale) {
|
|
105
|
+
this.disposeWsClient();
|
|
106
|
+
this.wsClientStale = false;
|
|
107
|
+
}
|
|
108
|
+
if (!this.wsClient) {
|
|
109
|
+
this.wsClient = (0, graphql_ws_1.createClient)({
|
|
110
|
+
url: this.endpoint,
|
|
111
|
+
webSocketImpl: typeof WebSocket !== 'undefined'
|
|
112
|
+
? WebSocket
|
|
113
|
+
: require('ws'),
|
|
114
|
+
connectionParams: () => ({
|
|
115
|
+
headers: this.getHeaders(),
|
|
116
|
+
}),
|
|
117
|
+
lazyCloseTimeout: 15_000,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return this.wsClient;
|
|
121
|
+
}
|
|
122
|
+
getHeaders() {
|
|
123
|
+
const headers = { ...this.baseHeaders };
|
|
124
|
+
if (this.authToken) {
|
|
125
|
+
headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
126
|
+
}
|
|
127
|
+
if (this.transactionToken) {
|
|
128
|
+
headers["forgecart-transaction-token"] = this.transactionToken;
|
|
129
|
+
}
|
|
130
|
+
return headers;
|
|
131
|
+
}
|
|
132
|
+
setAuthToken(token) {
|
|
133
|
+
if (this.authToken === token)
|
|
134
|
+
return;
|
|
135
|
+
this.authToken = token;
|
|
136
|
+
this.disposeWsClient();
|
|
137
|
+
this.logger.info("Auth token set");
|
|
138
|
+
}
|
|
139
|
+
clearAuthToken() {
|
|
140
|
+
this.authToken = null;
|
|
141
|
+
this.disposeWsClient();
|
|
142
|
+
this.logger.info("Auth token cleared");
|
|
143
|
+
}
|
|
144
|
+
setTransactionToken(token) {
|
|
145
|
+
this.transactionToken = token;
|
|
146
|
+
this.logger.info("Transaction token set");
|
|
147
|
+
}
|
|
148
|
+
clearTransactionToken() {
|
|
149
|
+
this.transactionToken = null;
|
|
150
|
+
this.logger.info("Transaction token cleared");
|
|
151
|
+
}
|
|
152
|
+
setErrorHandler(handler) {
|
|
153
|
+
this.errorHandler = handler;
|
|
154
|
+
}
|
|
155
|
+
notifyErrorHandler(error) {
|
|
156
|
+
if (this.errorHandler) {
|
|
157
|
+
this.errorHandler(error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
query(document, variables) {
|
|
161
|
+
return new QueryObservable((subscriber) => {
|
|
162
|
+
const client = this.getWsClient();
|
|
163
|
+
let disposed = false;
|
|
164
|
+
const cleanup = client.subscribe({
|
|
165
|
+
query: document,
|
|
166
|
+
variables,
|
|
167
|
+
extensions: this.getPerOperationExtensions(),
|
|
168
|
+
}, {
|
|
169
|
+
next: (result) => {
|
|
170
|
+
if (disposed)
|
|
171
|
+
return;
|
|
172
|
+
if (result.errors && result.errors.length > 0) {
|
|
173
|
+
const response = {
|
|
174
|
+
errors: result.errors.map((e) => ({
|
|
175
|
+
message: e.message,
|
|
176
|
+
extensions: e.extensions,
|
|
177
|
+
})),
|
|
178
|
+
};
|
|
179
|
+
const error = new ClientError(response, result.errors[0].message);
|
|
180
|
+
this.notifyErrorHandler(error);
|
|
181
|
+
subscriber.error(error);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (result.data) {
|
|
185
|
+
this.captureSessionToken(result);
|
|
186
|
+
subscriber.next(result.data);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
error: (err) => {
|
|
190
|
+
if (disposed)
|
|
191
|
+
return;
|
|
192
|
+
subscriber.error(err);
|
|
193
|
+
},
|
|
194
|
+
complete: () => {
|
|
195
|
+
if (disposed)
|
|
196
|
+
return;
|
|
197
|
+
subscriber.complete();
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
return () => {
|
|
201
|
+
disposed = true;
|
|
202
|
+
cleanup();
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
mutate(document, variables) {
|
|
207
|
+
if (variables && this.containsFiles(variables)) {
|
|
208
|
+
return this.upload(document, variables);
|
|
209
|
+
}
|
|
210
|
+
return this.query(document, variables);
|
|
211
|
+
}
|
|
212
|
+
subscribe(document, variables) {
|
|
213
|
+
return this.query(document, variables);
|
|
214
|
+
}
|
|
215
|
+
upload(document, variables) {
|
|
216
|
+
return new QueryObservable((subscriber) => {
|
|
217
|
+
const endpoint = this.resolveUploadEndpoint();
|
|
218
|
+
(0, upload_1.uploadViaFetch)(endpoint, document, variables, this.getHeaders())
|
|
219
|
+
.then((result) => {
|
|
220
|
+
this.captureSessionTokenFromUpload(result);
|
|
221
|
+
subscriber.next(result.data);
|
|
222
|
+
subscriber.complete();
|
|
223
|
+
})
|
|
224
|
+
.catch((err) => subscriber.error(err));
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
getPerOperationExtensions() {
|
|
228
|
+
if (!this.transactionToken)
|
|
229
|
+
return undefined;
|
|
230
|
+
return { "forgecart-transaction-token": this.transactionToken };
|
|
231
|
+
}
|
|
232
|
+
captureSessionToken(result) {
|
|
233
|
+
if (!result.extensions)
|
|
234
|
+
return;
|
|
235
|
+
const token = result.extensions["forgecart-auth-token"];
|
|
236
|
+
if (token && !this.authToken) {
|
|
237
|
+
this.authToken = token;
|
|
238
|
+
this.wsClientStale = true;
|
|
239
|
+
this.logger.info("Session token captured from extensions");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
captureSessionTokenFromUpload(result) {
|
|
243
|
+
if (!result.extensions)
|
|
244
|
+
return;
|
|
245
|
+
const token = result.extensions["forgecart-auth-token"];
|
|
246
|
+
if (token && !this.authToken) {
|
|
247
|
+
this.authToken = token;
|
|
248
|
+
this.wsClientStale = true;
|
|
249
|
+
this.logger.info("Session token captured from upload response");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
containsFiles(obj) {
|
|
253
|
+
if (obj === null || obj === undefined)
|
|
254
|
+
return false;
|
|
255
|
+
if (typeof obj !== "object")
|
|
256
|
+
return false;
|
|
257
|
+
if (typeof File !== "undefined" && obj instanceof File)
|
|
258
|
+
return true;
|
|
259
|
+
if (typeof Blob !== "undefined" && obj instanceof Blob)
|
|
260
|
+
return true;
|
|
261
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(obj))
|
|
262
|
+
return true;
|
|
263
|
+
if (Array.isArray(obj))
|
|
264
|
+
return obj.some((item) => this.containsFiles(item));
|
|
265
|
+
return Object.values(obj).some((val) => this.containsFiles(val));
|
|
266
|
+
}
|
|
267
|
+
resolveUploadEndpoint() {
|
|
268
|
+
if (this.uploadEndpoint)
|
|
269
|
+
return this.uploadEndpoint;
|
|
270
|
+
return this.endpoint.replace(/^ws:/, "http:").replace(/^wss:/, "https:");
|
|
271
|
+
}
|
|
272
|
+
disposeWsClient() {
|
|
273
|
+
if (this.wsClient && this.ownsWsClient) {
|
|
274
|
+
this.wsClient.dispose();
|
|
275
|
+
this.wsClient = null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
dispose() {
|
|
279
|
+
this.disposeWsClient();
|
|
280
|
+
}
|
|
281
|
+
fork(transactionToken) {
|
|
282
|
+
const forked = new BaseGraphQLClient(this.endpoint, this.baseHeaders, this.uploadEndpoint);
|
|
283
|
+
forked.authToken = this.authToken;
|
|
284
|
+
forked.transactionToken = transactionToken;
|
|
285
|
+
forked.wsClient = this.wsClient;
|
|
286
|
+
forked.ownsWsClient = false;
|
|
287
|
+
return forked;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.BaseGraphQLClient = BaseGraphQLClient;
|
|
291
|
+
function setAuthToken(client, token) {
|
|
292
|
+
client.setAuthToken(token);
|
|
293
|
+
}
|
|
294
|
+
function clearAuthToken(client) {
|
|
295
|
+
client.clearAuthToken();
|
|
296
|
+
}
|
|
297
|
+
function setTransactionToken(client, token) {
|
|
298
|
+
client.setTransactionToken(token);
|
|
299
|
+
}
|
|
300
|
+
function clearTransactionToken(client) {
|
|
301
|
+
client.clearTransactionToken();
|
|
302
|
+
}
|
|
303
|
+
class TransactionContext {
|
|
304
|
+
_admin;
|
|
305
|
+
_shop;
|
|
306
|
+
constructor(admin, shop) {
|
|
307
|
+
this._admin = admin;
|
|
308
|
+
this._shop = shop;
|
|
309
|
+
}
|
|
310
|
+
get admin() {
|
|
311
|
+
return this._admin;
|
|
312
|
+
}
|
|
313
|
+
get shop() {
|
|
314
|
+
if (!this._shop) {
|
|
315
|
+
throw new Error('SHOP_NAMESPACE_NOT_AVAILABLE');
|
|
316
|
+
}
|
|
317
|
+
return this._shop;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.TransactionContext = TransactionContext;
|
|
321
|
+
class ForgeCartAdminClient {
|
|
322
|
+
client;
|
|
323
|
+
_namespace;
|
|
324
|
+
constructor(config) {
|
|
325
|
+
const headers = { 'forgecart-token': config.channelToken, ...config.headers };
|
|
326
|
+
if (config.adminSecret) {
|
|
327
|
+
headers['forgecart-secret'] = config.adminSecret;
|
|
328
|
+
}
|
|
329
|
+
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint);
|
|
330
|
+
this._namespace = new admin_generated_1.AdminNamespace(this.client);
|
|
331
|
+
}
|
|
332
|
+
setAuthToken(token) {
|
|
333
|
+
this.client.setAuthToken(token);
|
|
334
|
+
}
|
|
335
|
+
clearAuthToken() {
|
|
336
|
+
this.client.clearAuthToken();
|
|
337
|
+
}
|
|
338
|
+
setTransactionToken(token) {
|
|
339
|
+
this.client.setTransactionToken(token);
|
|
340
|
+
}
|
|
341
|
+
clearTransactionToken() {
|
|
342
|
+
this.client.clearTransactionToken();
|
|
343
|
+
}
|
|
344
|
+
setErrorHandler(handler) {
|
|
345
|
+
this.client.setErrorHandler(handler);
|
|
346
|
+
}
|
|
347
|
+
dispose() {
|
|
348
|
+
this.client.dispose();
|
|
349
|
+
}
|
|
350
|
+
query(document, variables) {
|
|
351
|
+
return this.client.query(document, variables);
|
|
352
|
+
}
|
|
353
|
+
mutate(document, variables) {
|
|
354
|
+
return this.client.mutate(document, variables);
|
|
355
|
+
}
|
|
356
|
+
shopPeer = null;
|
|
357
|
+
setShopPeer(shop) {
|
|
358
|
+
this.shopPeer = shop;
|
|
359
|
+
}
|
|
360
|
+
createScopedNamespace(transactionToken) {
|
|
361
|
+
return new admin_generated_1.AdminNamespace(this.client.fork(transactionToken));
|
|
362
|
+
}
|
|
363
|
+
async withTransaction(fn) {
|
|
364
|
+
const result = await (0, rxjs_1.firstValueFrom)(this.transaction.beginTransaction());
|
|
365
|
+
const token = result.beginTransaction.token;
|
|
366
|
+
const adminNs = this.createScopedNamespace(token);
|
|
367
|
+
const shopNs = this.shopPeer?.createScopedNamespace(token);
|
|
368
|
+
const ctx = new TransactionContext(adminNs, shopNs);
|
|
369
|
+
try {
|
|
370
|
+
const value = await fn(ctx);
|
|
371
|
+
await (0, rxjs_1.firstValueFrom)(this.transaction.commitTransaction({ token }));
|
|
372
|
+
return value;
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
await (0, rxjs_1.firstValueFrom)(this.transaction.rollbackTransaction({ token })).catch(() => { });
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
hookManager = null;
|
|
380
|
+
on(hookPoints, handler) {
|
|
381
|
+
if (!this.hookManager) {
|
|
382
|
+
this.hookManager = new sdk_hook_subscription_generated_1.HookSubscriptionManager((hp) => this.client.subscribe(sdk_hook_subscription_generated_1.hookDispatchDocument, { hookPoints: hp }), (id, subscriberId, error) => this.client.mutate(sdk_hook_subscription_generated_1.hookRespondDocument, { input: { id, subscriberId, error } }), (token) => {
|
|
383
|
+
const adminNs = this.createScopedNamespace(token);
|
|
384
|
+
const shopNs = this.shopPeer?.createScopedNamespace(token);
|
|
385
|
+
return new TransactionContext(adminNs, shopNs);
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return this.hookManager.on(hookPoints, handler);
|
|
389
|
+
}
|
|
390
|
+
async login(emailAddress, password) {
|
|
391
|
+
const result = await (0, rxjs_1.firstValueFrom)(this.auth.login({ input: { emailAddress, password } }));
|
|
392
|
+
this.client.setAuthToken(result.login.token);
|
|
393
|
+
if (this.shopPeer) {
|
|
394
|
+
this.shopPeer.setAuthToken(result.login.token);
|
|
395
|
+
}
|
|
396
|
+
return result.login;
|
|
397
|
+
}
|
|
398
|
+
async loginWithExternalStrategy(strategyCode, data) {
|
|
399
|
+
const result = await (0, rxjs_1.firstValueFrom)(this.auth.authenticateWithExternalStrategy({ input: { strategyCode, data } }));
|
|
400
|
+
this.client.setAuthToken(result.authenticateWithExternalStrategy.session.token);
|
|
401
|
+
if (this.shopPeer) {
|
|
402
|
+
this.shopPeer.setAuthToken(result.authenticateWithExternalStrategy.session.token);
|
|
403
|
+
}
|
|
404
|
+
return result.authenticateWithExternalStrategy;
|
|
405
|
+
}
|
|
406
|
+
async logout() {
|
|
407
|
+
await (0, rxjs_1.firstValueFrom)(this.auth.logout());
|
|
408
|
+
this.client.clearAuthToken();
|
|
409
|
+
if (this.shopPeer) {
|
|
410
|
+
this.shopPeer.clearAuthToken();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
get entry() {
|
|
414
|
+
return this._namespace.entry;
|
|
415
|
+
}
|
|
416
|
+
get fieldDefinition() {
|
|
417
|
+
return this._namespace.fieldDefinition;
|
|
418
|
+
}
|
|
419
|
+
get publish() {
|
|
420
|
+
return this._namespace.publish;
|
|
421
|
+
}
|
|
422
|
+
get acfSchema() {
|
|
423
|
+
return this._namespace.acfSchema;
|
|
424
|
+
}
|
|
425
|
+
get acf() {
|
|
426
|
+
return this._namespace.acf;
|
|
427
|
+
}
|
|
428
|
+
get administrator() {
|
|
429
|
+
return this._namespace.administrator;
|
|
430
|
+
}
|
|
431
|
+
get analyticsGateway() {
|
|
432
|
+
return this._namespace.analyticsGateway;
|
|
433
|
+
}
|
|
434
|
+
get asset() {
|
|
435
|
+
return this._namespace.asset;
|
|
436
|
+
}
|
|
437
|
+
get audienceMembership() {
|
|
438
|
+
return this._namespace.audienceMembership;
|
|
439
|
+
}
|
|
440
|
+
get audienceSegment() {
|
|
441
|
+
return this._namespace.audienceSegment;
|
|
442
|
+
}
|
|
443
|
+
get auth() {
|
|
444
|
+
return this._namespace.auth;
|
|
445
|
+
}
|
|
446
|
+
get settings() {
|
|
447
|
+
return this._namespace.settings;
|
|
448
|
+
}
|
|
449
|
+
get channel() {
|
|
450
|
+
return this._namespace.channel;
|
|
451
|
+
}
|
|
452
|
+
get collection() {
|
|
453
|
+
return this._namespace.collection;
|
|
454
|
+
}
|
|
455
|
+
get country() {
|
|
456
|
+
return this._namespace.country;
|
|
457
|
+
}
|
|
458
|
+
get address() {
|
|
459
|
+
return this._namespace.address;
|
|
460
|
+
}
|
|
461
|
+
get group() {
|
|
462
|
+
return this._namespace.group;
|
|
463
|
+
}
|
|
464
|
+
get customerGroup() {
|
|
465
|
+
return this._namespace.customerGroup;
|
|
466
|
+
}
|
|
467
|
+
get customer() {
|
|
468
|
+
return this._namespace.customer;
|
|
469
|
+
}
|
|
470
|
+
get deployment() {
|
|
471
|
+
return this._namespace.deployment;
|
|
472
|
+
}
|
|
473
|
+
get facet() {
|
|
474
|
+
return this._namespace.facet;
|
|
475
|
+
}
|
|
476
|
+
get fulfillmentRequest() {
|
|
477
|
+
return this._namespace.fulfillmentRequest;
|
|
478
|
+
}
|
|
479
|
+
get fulfillment() {
|
|
480
|
+
return this._namespace.fulfillment;
|
|
481
|
+
}
|
|
482
|
+
get hookDispatch() {
|
|
483
|
+
return this._namespace.hookDispatch;
|
|
484
|
+
}
|
|
485
|
+
get hook() {
|
|
486
|
+
return this._namespace.hook;
|
|
487
|
+
}
|
|
488
|
+
get marketingAttribution() {
|
|
489
|
+
return this._namespace.marketingAttribution;
|
|
490
|
+
}
|
|
491
|
+
get marketingEvent() {
|
|
492
|
+
return this._namespace.marketingEvent;
|
|
493
|
+
}
|
|
494
|
+
get marketingIdentity() {
|
|
495
|
+
return this._namespace.marketingIdentity;
|
|
496
|
+
}
|
|
497
|
+
get onboarding() {
|
|
498
|
+
return this._namespace.onboarding;
|
|
499
|
+
}
|
|
500
|
+
get coupon() {
|
|
501
|
+
return this._namespace.coupon;
|
|
502
|
+
}
|
|
503
|
+
get draft() {
|
|
504
|
+
return this._namespace.draft;
|
|
505
|
+
}
|
|
506
|
+
get modification() {
|
|
507
|
+
return this._namespace.modification;
|
|
508
|
+
}
|
|
509
|
+
get note() {
|
|
510
|
+
return this._namespace.note;
|
|
511
|
+
}
|
|
512
|
+
get orderModification() {
|
|
513
|
+
return this._namespace.orderModification;
|
|
514
|
+
}
|
|
515
|
+
get order() {
|
|
516
|
+
return this._namespace.order;
|
|
517
|
+
}
|
|
518
|
+
get payment() {
|
|
519
|
+
return this._namespace.payment;
|
|
520
|
+
}
|
|
521
|
+
get manageable() {
|
|
522
|
+
return this._namespace.manageable;
|
|
523
|
+
}
|
|
524
|
+
get plugin() {
|
|
525
|
+
return this._namespace.plugin;
|
|
526
|
+
}
|
|
527
|
+
get optionGroup() {
|
|
528
|
+
return this._namespace.optionGroup;
|
|
529
|
+
}
|
|
530
|
+
get option() {
|
|
531
|
+
return this._namespace.option;
|
|
532
|
+
}
|
|
533
|
+
get productOption() {
|
|
534
|
+
return this._namespace.productOption;
|
|
535
|
+
}
|
|
536
|
+
get productVariant() {
|
|
537
|
+
return this._namespace.productVariant;
|
|
538
|
+
}
|
|
539
|
+
get product() {
|
|
540
|
+
return this._namespace.product;
|
|
541
|
+
}
|
|
542
|
+
get promotion() {
|
|
543
|
+
return this._namespace.promotion;
|
|
544
|
+
}
|
|
545
|
+
get role() {
|
|
546
|
+
return this._namespace.role;
|
|
547
|
+
}
|
|
548
|
+
get scheduledJob() {
|
|
549
|
+
return this._namespace.scheduledJob;
|
|
550
|
+
}
|
|
551
|
+
get search() {
|
|
552
|
+
return this._namespace.search;
|
|
553
|
+
}
|
|
554
|
+
get seller() {
|
|
555
|
+
return this._namespace.seller;
|
|
556
|
+
}
|
|
557
|
+
get shipping() {
|
|
558
|
+
return this._namespace.shipping;
|
|
559
|
+
}
|
|
560
|
+
get stock() {
|
|
561
|
+
return this._namespace.stock;
|
|
562
|
+
}
|
|
563
|
+
get subscription() {
|
|
564
|
+
return this._namespace.subscription;
|
|
565
|
+
}
|
|
566
|
+
get tax() {
|
|
567
|
+
return this._namespace.tax;
|
|
568
|
+
}
|
|
569
|
+
get transaction() {
|
|
570
|
+
return this._namespace.transaction;
|
|
571
|
+
}
|
|
572
|
+
get zone() {
|
|
573
|
+
return this._namespace.zone;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
exports.ForgeCartAdminClient = ForgeCartAdminClient;
|
|
577
|
+
class ForgeCartShopClient {
|
|
578
|
+
client;
|
|
579
|
+
_namespace;
|
|
580
|
+
constructor(config) {
|
|
581
|
+
const headers = { 'forgecart-token': config.channelToken, ...config.headers };
|
|
582
|
+
this.client = new BaseGraphQLClient(config.endpoint, headers, config.uploadEndpoint);
|
|
583
|
+
this._namespace = new shop_generated_1.ShopNamespace(this.client);
|
|
584
|
+
}
|
|
585
|
+
setAuthToken(token) {
|
|
586
|
+
this.client.setAuthToken(token);
|
|
587
|
+
}
|
|
588
|
+
clearAuthToken() {
|
|
589
|
+
this.client.clearAuthToken();
|
|
590
|
+
}
|
|
591
|
+
setTransactionToken(token) {
|
|
592
|
+
this.client.setTransactionToken(token);
|
|
593
|
+
}
|
|
594
|
+
clearTransactionToken() {
|
|
595
|
+
this.client.clearTransactionToken();
|
|
596
|
+
}
|
|
597
|
+
setErrorHandler(handler) {
|
|
598
|
+
this.client.setErrorHandler(handler);
|
|
599
|
+
}
|
|
600
|
+
dispose() {
|
|
601
|
+
this.client.dispose();
|
|
602
|
+
}
|
|
603
|
+
query(document, variables) {
|
|
604
|
+
return this.client.query(document, variables);
|
|
605
|
+
}
|
|
606
|
+
mutate(document, variables) {
|
|
607
|
+
return this.client.mutate(document, variables);
|
|
608
|
+
}
|
|
609
|
+
createScopedNamespace(transactionToken) {
|
|
610
|
+
return new shop_generated_1.ShopNamespace(this.client.fork(transactionToken));
|
|
611
|
+
}
|
|
612
|
+
async login(emailAddress, password) {
|
|
613
|
+
const result = await (0, rxjs_1.firstValueFrom)(this.auth.login({ input: { emailAddress, password } }));
|
|
614
|
+
this.client.setAuthToken(result.login.token);
|
|
615
|
+
return result.login;
|
|
616
|
+
}
|
|
617
|
+
async loginWithExternalStrategy(strategyCode, data) {
|
|
618
|
+
const result = await (0, rxjs_1.firstValueFrom)(this.auth.authenticateWithExternalStrategy({ input: { strategyCode, data } }));
|
|
619
|
+
this.client.setAuthToken(result.authenticateWithExternalStrategy.token);
|
|
620
|
+
return result.authenticateWithExternalStrategy;
|
|
621
|
+
}
|
|
622
|
+
async logout() {
|
|
623
|
+
await (0, rxjs_1.firstValueFrom)(this.auth.logout());
|
|
624
|
+
this.client.clearAuthToken();
|
|
625
|
+
}
|
|
626
|
+
get acf() {
|
|
627
|
+
return this._namespace.acf;
|
|
628
|
+
}
|
|
629
|
+
get auth() {
|
|
630
|
+
return this._namespace.auth;
|
|
631
|
+
}
|
|
632
|
+
get cart() {
|
|
633
|
+
return this._namespace.cart;
|
|
634
|
+
}
|
|
635
|
+
get checkout() {
|
|
636
|
+
return this._namespace.checkout;
|
|
637
|
+
}
|
|
638
|
+
get collection() {
|
|
639
|
+
return this._namespace.collection;
|
|
640
|
+
}
|
|
641
|
+
get customer() {
|
|
642
|
+
return this._namespace.customer;
|
|
643
|
+
}
|
|
644
|
+
get facet() {
|
|
645
|
+
return this._namespace.facet;
|
|
646
|
+
}
|
|
647
|
+
get hookDispatch() {
|
|
648
|
+
return this._namespace.hookDispatch;
|
|
649
|
+
}
|
|
650
|
+
get hook() {
|
|
651
|
+
return this._namespace.hook;
|
|
652
|
+
}
|
|
653
|
+
get marketingEvent() {
|
|
654
|
+
return this._namespace.marketingEvent;
|
|
655
|
+
}
|
|
656
|
+
get marketingIdentity() {
|
|
657
|
+
return this._namespace.marketingIdentity;
|
|
658
|
+
}
|
|
659
|
+
get order() {
|
|
660
|
+
return this._namespace.order;
|
|
661
|
+
}
|
|
662
|
+
get payment() {
|
|
663
|
+
return this._namespace.payment;
|
|
664
|
+
}
|
|
665
|
+
get product() {
|
|
666
|
+
return this._namespace.product;
|
|
667
|
+
}
|
|
668
|
+
get search() {
|
|
669
|
+
return this._namespace.search;
|
|
670
|
+
}
|
|
671
|
+
get shipping() {
|
|
672
|
+
return this._namespace.shipping;
|
|
673
|
+
}
|
|
674
|
+
get subscription() {
|
|
675
|
+
return this._namespace.subscription;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
exports.ForgeCartShopClient = ForgeCartShopClient;
|
|
679
|
+
class ForgeCartClient {
|
|
680
|
+
_admin;
|
|
681
|
+
_shop;
|
|
682
|
+
constructor(config) {
|
|
683
|
+
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 });
|
|
684
|
+
this._shop = new ForgeCartShopClient({ endpoint: config.endpoint + '/shop-api', channelToken: config.channelToken, uploadEndpoint: config.uploadEndpoint ? config.uploadEndpoint + '/shop-api' : undefined, headers: config.headers });
|
|
685
|
+
this._admin.setShopPeer(this._shop);
|
|
686
|
+
}
|
|
687
|
+
setAuthToken(token) {
|
|
688
|
+
this._admin.setAuthToken(token);
|
|
689
|
+
this._shop.setAuthToken(token);
|
|
690
|
+
}
|
|
691
|
+
clearAuthToken() {
|
|
692
|
+
this._admin.clearAuthToken();
|
|
693
|
+
this._shop.clearAuthToken();
|
|
694
|
+
}
|
|
695
|
+
setTransactionToken(token) {
|
|
696
|
+
this._admin.setTransactionToken(token);
|
|
697
|
+
this._shop.setTransactionToken(token);
|
|
698
|
+
}
|
|
699
|
+
clearTransactionToken() {
|
|
700
|
+
this._admin.clearTransactionToken();
|
|
701
|
+
this._shop.clearTransactionToken();
|
|
702
|
+
}
|
|
703
|
+
get admin() {
|
|
704
|
+
return this._admin;
|
|
705
|
+
}
|
|
706
|
+
get shop() {
|
|
707
|
+
return this._shop;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
exports.ForgeCartClient = ForgeCartClient;
|
|
711
|
+
const common_1 = require("@nestjs/common");
|
|
712
|
+
let ForgeCartGraphQLModule = (() => {
|
|
713
|
+
let _classDecorators = [(0, common_1.Module)({})];
|
|
714
|
+
let _classDescriptor;
|
|
715
|
+
let _classExtraInitializers = [];
|
|
716
|
+
let _classThis;
|
|
717
|
+
var ForgeCartGraphQLModule = class {
|
|
718
|
+
static { _classThis = this; }
|
|
719
|
+
static {
|
|
720
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
721
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
722
|
+
ForgeCartGraphQLModule = _classThis = _classDescriptor.value;
|
|
723
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
724
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
725
|
+
}
|
|
726
|
+
static forAdmin(config) {
|
|
727
|
+
const client = new ForgeCartAdminClient(config);
|
|
728
|
+
return {
|
|
729
|
+
module: ForgeCartGraphQLModule,
|
|
730
|
+
providers: [{ provide: ForgeCartAdminClient, useValue: client }],
|
|
731
|
+
exports: [ForgeCartAdminClient],
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
static forShop(config) {
|
|
735
|
+
const client = new ForgeCartShopClient(config);
|
|
736
|
+
return {
|
|
737
|
+
module: ForgeCartGraphQLModule,
|
|
738
|
+
providers: [{ provide: ForgeCartShopClient, useValue: client }],
|
|
739
|
+
exports: [ForgeCartShopClient],
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
static forRoot(config) {
|
|
743
|
+
const client = new ForgeCartClient(config);
|
|
744
|
+
return {
|
|
745
|
+
module: ForgeCartGraphQLModule,
|
|
746
|
+
providers: [
|
|
747
|
+
{ provide: ForgeCartClient, useValue: client },
|
|
748
|
+
{ provide: ForgeCartAdminClient, useValue: client.admin },
|
|
749
|
+
{ provide: ForgeCartShopClient, useValue: client.shop },
|
|
750
|
+
],
|
|
751
|
+
exports: [ForgeCartClient, ForgeCartAdminClient, ForgeCartShopClient],
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
return ForgeCartGraphQLModule = _classThis;
|
|
756
|
+
})();
|
|
757
|
+
exports.ForgeCartGraphQLModule = ForgeCartGraphQLModule;
|