-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
971 lines (912 loc) · 27.3 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
import axios, { AxiosRequestConfig, Method } from "axios";
/**
* @constant baseUrl
* @description The base URL of the Tebex Headless API
*
* @type {string}
*/
const baseUrl: string = "https://headless.tebex.io";
/**
* @type {Data}
* @description The data returned from the Tebex Headless API
*
* @type {T} The type of data to be returned
*/
export type Data<T> = {
data: T;
}
/**
* @type {Message}
* @description The message returned from the Tebex Headless API
*
* @param {boolean} success Whether the request was successful
* @param {string} message The message returned from the Tebex Headless API
*/
export type Message = {
success: boolean;
message: string;
}
/**
* @type {GenericObject}
* @description A generic object
*/
export type GenericObject = string | number | boolean | null | undefined;
/**
* @type {Route}
* @description The route of the Tebex Headless API
*
* @param {string} accounts The accounts route
* @param {string} baskets The baskets route
*/
export type Route = "accounts" | "baskets";
/**
* @type {ApplyType}
* @description The type of the apply request
*
* @param {string} coupons The coupons type
* @param {string} giftcards The giftcards type
* @param {string} creator-codes The creator codes type
*/
export type ApplyType = "coupons" | "giftcards" | "creator-codes";
/**
* @type {KeyValuePair}
* @description A key value pair
*
* @type {K} The type of the key
* @type {V} The type of the value
*/
export type KeyValuePair<K extends string | number, V> = {
[key in K]: V;
};
/**
* @type {BaseItem}
* @description The base item object for the package and category objects
*
* @param {number} id The ID of the base item
* @param {string} name The name of the base item
*/
export type BaseItem = {
id: number;
name: string;
}
/**
* @type {CouponCodeBody}
* @description The coupon code object for the body of the request
*
* @param {string} coupon_code The coupon code to apply or remove
*/
export type CouponCode = {
coupon_code: string;
}
/**
* @type {GiftCardCodeBody}
* @description The gift card code object for the body of the request
*
* @param {string} card_number The gift card code to apply or remove
*/
export type GiftCardCode = {
card_number: string;
}
/**
* @type {CreatorCodeBody}
* @description The creator code object for the body of the request
*
* @param {string} creator_code The creator code to apply or remove
*/
export type CreatorCode = {
creator_code: string;
}
/**
* @function Request
* @description A function to make a request to the Tebex Headless API
*
* @param {Method | string} method The method of the request
* @param {Route} route The route of the request
* @param {string} path The path of the request
* @param {KeyValuePair<string, GenericObject>} params The parameters of the request
*
* @returns {Promise<T>}
*/
export async function Request<T, Body>(
webstoreIdentifier: string,
privateKey: string | undefined,
method: Method,
identifier: string | null,
route: Route,
path?: string,
params?: KeyValuePair<string, GenericObject>,
body?: Body
): Promise<T> {
if (params) {
for (const [key, value] of Object.entries(params)) {
if (typeof value === "boolean") {
params[key] = value ? 1 : 0;
}
}
}
const config: AxiosRequestConfig = {
url: `${baseUrl}/api/${route}/${identifier}${path ?? ""}`,
params: params,
method: method,
data: body,
headers: {
"Content-Type": "application/json",
},
};
if (webstoreIdentifier && privateKey) {
config.auth = {
username: webstoreIdentifier,
password: privateKey,
};
}
const response = await axios.request<T>(config);
return response.data;
}
/**
* @type {Category}
* @description The category object returned from the Tebex Headless API
*
* @param {number} id The ID of the category
* @param {string} name The name of the category
* @param {string} description The description of the category
* @param {Category | null} parent The parent category of the category
* @param {number} order The order of the category
* @param {Package[]} packages The packages in the category
* @param {"grid" | "list" | string} display_type The display type of the category
* @param {string | null} slug The slug of the category
*/
export type Category = BaseItem & {
description: string;
parent: Category | null;
order: number;
packages: Package[];
display_type: "grid" | "list";
slug: string | null;
};
/**
* @type {ApplyTypeToInterface}
* @description The type of the apply request
*
* @param {string} coupons The coupons type
* @param {string} giftcards The giftcards type
* @param {string} creator-codes The creator codes type
*
* @returns {CouponCode | GiftCardCode | CreatorCode}
*/
export type ApplyTypeToInterface<T extends ApplyType> = T extends "coupons"
? CouponCode
: T extends "giftcards"
? GiftCardCode
: T extends "creator-codes"
? CreatorCode
: never;
/**
* @type {PackageType}
* @description The type of the package
*
* @param {string} subscription The subscription type
* @param {string} single The single type
*/
export type PackageType = "subscription" | "single" | "both";
/**
* @type {Package}
* @description The package object returned from the Tebex Headless API
*
* @param {number} id The ID of the package
* @param {string} name The name of the package
* @param {string} description The description of the package
* @param {PackageType} type The type of the package
* @param {boolean} disable_gifting Whether gifting is disabled for the package
* @param {boolean} disable_quantity Whether quantity is disabled for the package
* @param {string | null} expiration_date The expiration date of the package
* @param {ShortCategory} category The category of the package
* @param {number} base_price The base price of the package
* @param {number} sales_tax The sales tax of the package
* @param {number} total_price The total price of the package
* @param {number} discount The discount of the package
* @param {string | null} image The image of the package
* @param {string} created_at The date the package was created
* @param {string} updated_at The date the package was updated
* @param {number} order The order this package should be sorted in
*/
export type Package = BaseItem & {
description: string;
type: PackageType;
disable_gifting: boolean;
disable_quantity: boolean;
expiration_date: string | null;
currency: string;
category: BaseItem;
base_price: number;
sales_tax: number;
total_price: number;
discount: number;
image: string | null;
created_at: string;
updated_at: string;
order: number;
};
/**
* @type {InBasket}
* @description The in_basket object inside a basket package object
*
* @param {number} quantity The quantity of the package in the basket
* @param {number} price The price of the package in the basket
* @param {string | null} gift_username_id The ID of the user the package is gifted to
* @param {string | null} gift_username The username of the user the package is gifted to
*/
export type InBasket = {
quantity: number;
price: number;
gift_username_id: string | null;
gift_username: string | null;
}
/**
* @type {BasketPackage}
* @description The basket package object returned from the Tebex Headless API
*
* @param {number} id The ID of the package
* @param {string} name The name of the package
* @param {string} description The description of the package
* @param {InBasket} in_basket The in_basket object inside the basket package object
* @param {string | null} image The image of the package
*/
export type BasketPackage = BaseItem & {
description: string;
in_basket: InBasket;
image: string | null;
};
/**
* @type {Code}
* @description The code object inside the basket coupons object
*
* @param {string} code The code of the object
*/
export type Code = {
code: string;
}
/**
* @type {Links}
* @description The links object inside the basket object
*
* @param {string} checkout The checkout link of the basket
*/
export type Links = {
checkout: string;
[key: string]: string;
}
/**
* @type {Basket}
* @description The basket object returned from the Tebex Headless API
*
* @param {string} ident The identifier of the basket
* @param {boolean} complete Whether the basket is complete
* @param {number} id The ID of the basket
* @param {string} country The country of the basket
* @param {string} ip The IP address of the user
* @param {string | null} username_id The ID of the user
* @param {string | null} username The username of the user
* @param {string} cancel_url The cancel url of the basket
* @param {string} complete_url The complete url of the basket
* @param {boolean} complete_auto_redirect Whether the basket should automatically redirect to the complete url
* @param {number} base_price The base price of the basket
* @param {number} sales_tax The sales tax of the basket
* @param {number} total_price The total price of the basket
* @param {string} email The email of the basket
* @param {string} currency The currency of the basket
* @param {BasketPackage[]} packages The packages in the basket
* @param {Code[]} coupons The coupons in the basket
* @param {GiftCardCode[]} giftcards The giftcards in the basket
* @param {string} creator_code The creator code of the basket
* @param {Links} links The links of the basket
* @param {KeyValuePair<string, any>} custom The custom object of the basket
*/
export type Basket = {
ident: string;
complete: boolean;
id: number;
country: string;
ip: string;
username_id: string | null;
username: string | null;
cancel_url: string;
complete_url: string;
complete_auto_redirect: boolean;
base_price: number;
sales_tax: number;
total_price: number;
email: string;
currency: string;
packages: BasketPackage[];
coupons: Code[];
giftcards: GiftCardCode[];
creator_code: string;
links: Links;
custom: KeyValuePair<string, any>;
}
/**
* @type {Urls}
* @description The url object for the complete and cancel urls
*
* @param {string} complete_url The complete url
* @param {string} cancel_url The cancel url
*/
export type Urls = {
complete_url: string;
cancel_url: string;
custom?: KeyValuePair<string, any>;
complete_auto_redirect?: boolean;
};
/**
* @type {AuthUrl}
* @description The auth url object returned from the Tebex Headless API
*
* @param {string} name The name of the auth url
* @param {string} url The url of the auth url
*/
export type AuthUrl = {
name: string;
url: string;
}
/**
* @type {PackageBody}
* @description The package object for the body of the request
*
* @param {number} package_id The ID of the package
* @param {number} quantity The quantity of the package
* @param {PackageType} type The type of the package
*/
export type PackageBody = {
package_id: number;
quantity: number;
type: PackageType;
}
/**
* @type {Webstore}
* @description The webstore object returned from the Tebex Headless API
*
* @param {number} id The ID of the webstore
* @param {string} description The description of the webstore
* @param {string} name The name of the webstore
* @param {string} webstore_url The webstore url of the webstore
* @param {string} currency The currency of the webstore
* @param {string} lang The language of the webstore
* @param {string} logo The logo of the webstore
* @param {string} platform_type The platform type of the webstore
* @param {number} platform_type_id The platform type ID of the webstore
* @param {string} created_at The date the webstore was created
*/
export type Webstore = {
id: number;
description: string;
name: string;
webstore_url: string;
currency: string;
lang: string;
logo: string;
platform_type: string;
platform_type_id: number;
created_at: string;
}
/**
* @type {Page}
* @description The page object returned from the Tebex Headless API
*
* @param {number} id The ID of the page
* @param {string} created_at The date the page was created
* @param {string} updated_at The date the page was updated
* @param {number} account_id The ID of the account
* @param {string} title The title of the page
* @param {string} slug The slug of the page
* @param {boolean} private Whether the page is private
* @param {boolean} hidden Whether the page is hidden
* @param {boolean} disabled Whether the page is disabled
* @param {boolean} sequence Whether the page is in a sequence
* @param {string} content The content of the page
*/
export type Page = {
id: number;
created_at: string;
updated_at: string;
account_id: number;
title: string;
slug: string;
private: boolean;
hidden: boolean;
disabled: boolean;
sequence: boolean;
content: string;
}
export class TebexHeadless {
constructor(
/**
* @constant webstoreIdentifier
* @description A function to set the webstore identifier
*
* @param {string} identifier The identifier of the webstore
*
* @returns {void}
*/
readonly webstoreIdentifier: string,
/**
* @private {privateKey}
* @description A function to set the private key
*
* @param {string} key The private key of the webstore
*
* @returns {void}
*/
private privateKey?: string
) {}
/**
* @function getCategories
* @description A function to get the categories from the Tebex Headless API
*
* @param {boolean} includePackages Whether to include the packages in the categories
* @param {string} basketIdent The identifier of the basket
* @param {string} ipAddress The IP address of the user
*
* @returns {Promise<Category[]>}
*/
async getCategories(
includePackages?: boolean,
basketIdent?: string,
ipAddress?: string
): Promise<Category[]> {
const { data }: Data<Category[]> = await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts",
"/categories",
{
includePackages,
basketIdent,
ipAddress,
}
);
return data;
}
/**
* @function getCategory
* @description A function to get a category from the Tebex Headless API
*
* @param {number} id The ID of the category
* @param {boolean} includePackages Whether to include the packages in the category
* @param {string} basketIdent The identifier of the basket
* @param {string} ipAddress The IP address of the user
*
* @returns {Promise<Category>}
*/
async getCategory(
id: number,
includePackages?: boolean,
basketIdent?: string,
ipAddress?: string
): Promise<Category> {
const { data }: Data<Category> = await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts",
`/categories/${id}`,
{
includePackages,
basketIdent,
ipAddress,
}
);
return data;
}
/**
* @function apply
* @description A function to apply a coupon, giftcard or creator code to a basket
*
* @param {A} body The body of the request
* @param {string} basketIdent The identifier of the basket
* @param {ApplyType} type The type of the apply request
*
* @returns {Promise<Message>}
*/
async apply<T extends ApplyType, A extends ApplyTypeToInterface<T>>(
basketIdent: string,
type: T,
body: A
): Promise<Message> {
return await Request<Message, A>(
this.webstoreIdentifier,
this.privateKey,
"post",
this.webstoreIdentifier,
"accounts",
`/baskets/${basketIdent}/${type}`,
{},
body
);
}
/**
* @function remove
* @description A function to remove a coupon, giftcard or creator code from a basket
*
* @param {A} body The body of the request
* @param {string} basketIdent The identifier of the basket
* @param {ApplyType} type The type of the apply request
*
* @returns {Promise<Message>}
*/
async remove<T extends ApplyType, A extends ApplyTypeToInterface<T>>(
basketIdent: string,
type: T,
body: A
): Promise<Message> {
return await Request<Message, A>(
this.webstoreIdentifier,
this.privateKey,
"post",
this.webstoreIdentifier,
"accounts",
`/baskets/${basketIdent}/${type}/remove`,
{},
body
);
}
/**
* @function getPackage
* @description A function to get a package from the Tebex Headless API
*
* @param {number} id The ID of the package
* @param {string} basketIdent The identifier of the basket
* @param {string} ipAddress The IP address of the user
*
* @returns {Promise<Package>}
*/
async getPackage(
id: number,
basketIdent?: string,
ipAddress?: string
): Promise<Package> {
const { data }: Data<Package> = await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts",
`/packages/${id}`,
{
basketIdent,
ipAddress,
}
);
return data;
}
/**
* @function getPackages
* @description A function to get all packages from the Tebex Headless API
*
* @param {string} basketIdent The identifier of the basket
* @param {string} ipAddress The IP address of the user
*
* @returns {Promise<Package[]>}
*/
async getPackages(
basketIdent?: string,
ipAddress?: string
): Promise<Package[]> {
const { data }: Data<Package[]> = await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts",
`/packages`,
{
basketIdent,
ipAddress,
}
);
return data;
}
/**
* @function getBasket
* @description A function to get a basket from the Tebex Headless API
*
* @param {string} basketIdent The identifier of the basket
*
* @returns {Promise<Package[]>}
*/
async getBasket(basketIdent: string): Promise<Basket> {
const { data }: Data<Basket> = await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts",
`/baskets/${basketIdent}`
);
return data;
}
/**
* @function createBasket
* @description A function to create a basket from the Tebex Headless API
*
* @param {string} complete_url The complete url
* @param {string} cancel_url The cancel url
* @param {KeyValuePair<string, any>} custom The custom object of the basket
* @param {boolean} complete_auto_redirect Whether the basket should automatically redirect to the complete url
* @param {string} ip_address The IP address of the user
*
* @returns {Promise<Basket>}
*/
async createBasket(
complete_url: string,
cancel_url: string,
custom?: KeyValuePair<string, any>,
complete_auto_redirect?: boolean,
ip_address?: string
): Promise<Basket> {
const { data }: Data<Basket> = await Request(
this.webstoreIdentifier,
this.privateKey,
"post",
this.webstoreIdentifier,
"accounts",
"/baskets",
{
ip_address,
},
{
complete_url,
cancel_url,
custom,
complete_auto_redirect,
}
);
return data;
}
/**
* @function createMinecraftBasket
* @description A function to create a minecraft basket from the Tebex Headless API
*
* @param {string} username The username of the user
* @param {string} complete_url The complete url
* @param {string} cancel_url The cancel url
* @param {KeyValuePair<string, any>} custom The custom object of the basket
* @param {boolean} complete_auto_redirect Whether the basket should automatically redirect to the complete url
* @param {string} ip_address The IP address of the user
*
* @returns {Promise<Basket>}
*/
async createMinecraftBasket(
username: string,
complete_url: string,
cancel_url: string,
custom?: KeyValuePair<string, any>,
complete_auto_redirect?: boolean,
ip_address?: string
): Promise<Basket> {
const { data }: Data<Basket> = await Request(
this.webstoreIdentifier,
this.privateKey,
"post",
this.webstoreIdentifier,
"accounts",
"/baskets",
{
ip_address,
},
{
username,
complete_url,
cancel_url,
custom,
complete_auto_redirect,
}
);
return data;
}
/**
* @function getBasketAuthUrl
* @description A function to get the auth url of a basket from the Tebex Headless API
*
* @param {string} basketIdent The identifier of the basket
* @param {string} returnUrl The return url of the basket
*
* @returns {Promise<AuthUrl[]>} The data returned or an axios error
*/
async getBasketAuthUrl(
basketIdent: string,
returnUrl: string
): Promise<AuthUrl[]> {
return await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts",
`/baskets/${basketIdent}/auth`,
{
returnUrl,
}
);
}
/**
* @function addPackageToBasket
* @description A function to add a package to a basket from the Tebex Headless API
*
* @param {string} basketIdent The identifier of the basket
* @param {number} package_id The ID of the package
* @param {number} quantity The quantity of the package
* @param {PackageType} type The type of the package
* @param {KeyValuePair<string, any>} variable_data The variable data of the package
*
* @returns {Promise<Basket>}
*/
async addPackageToBasket(
basketIdent: string,
package_id: number,
quantity: number,
type?: PackageType,
variable_data?: KeyValuePair<string, any>
): Promise<Basket> {
const { data }: Data<Basket> = await Request(
this.webstoreIdentifier,
this.privateKey,
"post",
basketIdent,
"baskets",
"/packages",
{},
{
package_id,
quantity,
type,
variable_data,
}
);
return data;
}
/**
* @function giftPackage
* @description A function to gift a package to a user from the Tebex Headless API
*
* @param {string} basketIdent The identifier of the basket
* @param {number} package_id The ID of the package
* @param {string} target_username_id The ID of the user to gift the package to
*
* @returns {Promise<Basket>}
*/
async giftPackage(
basketIdent: string,
package_id: number,
target_username_id: string
): Promise<Basket> {
const { data }: Data<Basket> = await Request(
this.webstoreIdentifier,
this.privateKey,
"post",
basketIdent,
"baskets",
"/packages",
{},
{
package_id,
target_username_id,
}
);
return data;
}
/**
* @function removePackage
* @description A function to remove a package from a basket from the Tebex Headless API
*
* @param {string} basketIdent The identifier of the basket
* @param {number} package_id The ID of the package
*
* @returns {Promise<Basket>}
*/
async removePackage(
basketIdent: string,
package_id: number
): Promise<Basket> {
const { data }: Data<Basket> = await Request(
this.webstoreIdentifier,
this.privateKey,
"post",
basketIdent,
"baskets",
"/packages/remove",
{},
{
package_id,
}
);
return data;
}
/**
* @function updateQuantity
* @description A function to update the quantity of a package in a basket from the Tebex Headless API
*
* @param {string} basketIdent The identifier of the basket
* @param {number} package_id The ID of the package
* @param {number} quantity The quantity of the package
*
* @returns {Promise<Basket>}
*/
async updateQuantity(
basketIdent: string,
package_id: number,
quantity: number
): Promise<Basket> {
const { data }: Data<Basket> = await Request(
this.webstoreIdentifier,
this.privateKey,
"put",
basketIdent,
"baskets",
`/packages/${package_id}`,
{},
{
quantity,
}
);
return data;
}
/**
* @function getWebstore
* @description A function to get the webstore from the Tebex Headless API
*
* @returns {Promise<Webstore>}
*/
async getWebstore(): Promise<Webstore> {
const { data }: Data<Webstore> = await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts"
);
return data;
}
/**
* @function getPages
* @description A function to get the pages from the Tebex Headless API
*
* @returns {Promise<Page>}
*/
async getPages(): Promise<Array<Page>> {
const { data }: Data<Array<Page>> = await Request(
this.webstoreIdentifier,
this.privateKey,
"get",
this.webstoreIdentifier,
"accounts",
"/pages"
);
return data;
}
/**
* @function updateTier
* @description Update an tier of an package
*
* @param {unknown} tierId The ID of the tier
* @param {number} package_id The ID of the package
*
* @returns {Promise<Message>}
*/
async updateTier(tierId: unknown, package_id: number): Promise<Message> {
return await Request(
this.webstoreIdentifier,
this.privateKey,
"patch",
this.webstoreIdentifier,
"accounts",
`/tiers/${tierId}`,
{},
{
package_id,
}
);
}
}