@hive-ng/web-sdk 0.1.0 → 0.1.1
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/dist/{chunk-NWQONJK2.js → chunk-IEKJNYXT.js} +132 -2
- package/dist/chunk-IEKJNYXT.js.map +1 -0
- package/dist/hive-ng.global.js +2 -2
- package/dist/hive-ng.global.js.map +1 -1
- package/dist/index.cjs +130 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -3
- package/dist/index.d.ts +35 -3
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +130 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-NWQONJK2.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -529,6 +529,63 @@ var PaymentApi = class {
|
|
|
529
529
|
unbind() {
|
|
530
530
|
this.client = null;
|
|
531
531
|
}
|
|
532
|
+
async listProducts(options) {
|
|
533
|
+
const market = requireMarket(options.market);
|
|
534
|
+
const appIdentifier = requireValue(options.appIdentifier, "appIdentifier");
|
|
535
|
+
const client = this.requireClient();
|
|
536
|
+
try {
|
|
537
|
+
const res = await client.listProducts({
|
|
538
|
+
market,
|
|
539
|
+
appIdentifier,
|
|
540
|
+
productType: optionalProductType(options.productType)
|
|
541
|
+
});
|
|
542
|
+
return res.products.map(mapProduct);
|
|
543
|
+
} catch (err) {
|
|
544
|
+
throw toHiveNgError(err);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
async startPurchase(options) {
|
|
548
|
+
const client = this.requireClient();
|
|
549
|
+
try {
|
|
550
|
+
const res = await client.startPurchase({
|
|
551
|
+
market: requireMarket(options.market),
|
|
552
|
+
appIdentifier: requireValue(options.appIdentifier, "appIdentifier"),
|
|
553
|
+
productId: requireValue(options.productId, "productId"),
|
|
554
|
+
productType: requireProductType(options.productType)
|
|
555
|
+
});
|
|
556
|
+
if (!res.purchaseIntentId) {
|
|
557
|
+
throw new HiveNgError("INTERNAL", "start purchase response missing purchaseIntentId");
|
|
558
|
+
}
|
|
559
|
+
return res.purchaseIntentId;
|
|
560
|
+
} catch (err) {
|
|
561
|
+
throw toHiveNgError(err);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
async verifyPurchase(options) {
|
|
565
|
+
const receiptPayload = options.receiptPayload ?? "";
|
|
566
|
+
const purchaseToken = options.purchaseToken ?? "";
|
|
567
|
+
if (!receiptPayload && !purchaseToken) {
|
|
568
|
+
throw new HiveNgError("INVALID_ARGUMENT", "receiptPayload or purchaseToken is required");
|
|
569
|
+
}
|
|
570
|
+
const client = this.requireClient();
|
|
571
|
+
try {
|
|
572
|
+
const res = await client.verifyPurchase({
|
|
573
|
+
market: requireMarket(options.market),
|
|
574
|
+
appIdentifier: requireValue(options.appIdentifier, "appIdentifier"),
|
|
575
|
+
productId: requireValue(options.productId, "productId"),
|
|
576
|
+
productType: requireProductType(options.productType),
|
|
577
|
+
receiptPayload,
|
|
578
|
+
purchaseToken,
|
|
579
|
+
purchaseIntentId: options.purchaseIntentId ?? ""
|
|
580
|
+
});
|
|
581
|
+
if (!res.purchase) {
|
|
582
|
+
throw new HiveNgError("INTERNAL", "verify purchase response missing purchase");
|
|
583
|
+
}
|
|
584
|
+
return mapPurchase(res.purchase);
|
|
585
|
+
} catch (err) {
|
|
586
|
+
throw toHiveNgError(err);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
532
589
|
async getPurchase(purchaseId) {
|
|
533
590
|
if (!purchaseId) {
|
|
534
591
|
throw new HiveNgError("INVALID_ARGUMENT", "purchaseId is required");
|
|
@@ -578,6 +635,21 @@ var PaymentApi = class {
|
|
|
578
635
|
return this.client;
|
|
579
636
|
}
|
|
580
637
|
};
|
|
638
|
+
function mapProduct(message) {
|
|
639
|
+
return {
|
|
640
|
+
projectId: message.projectId,
|
|
641
|
+
market: marketName(message.market),
|
|
642
|
+
appIdentifier: message.appIdentifier,
|
|
643
|
+
productId: message.productId,
|
|
644
|
+
productType: productTypeName(message.productType),
|
|
645
|
+
marketStatus: message.marketStatus,
|
|
646
|
+
title: message.title,
|
|
647
|
+
description: message.description,
|
|
648
|
+
consumePolicy: consumePolicyName(message.consumePolicy),
|
|
649
|
+
grantMode: grantModeName(message.grantMode),
|
|
650
|
+
enabled: message.enabled
|
|
651
|
+
};
|
|
652
|
+
}
|
|
581
653
|
function mapPurchase(message) {
|
|
582
654
|
return {
|
|
583
655
|
id: message.id,
|
|
@@ -598,6 +670,22 @@ function mapPurchase(message) {
|
|
|
598
670
|
verifiedAt: message.verifiedAt ? wkt.timestampDate(message.verifiedAt) : void 0
|
|
599
671
|
};
|
|
600
672
|
}
|
|
673
|
+
function requireMarket(value) {
|
|
674
|
+
const market = marketFromName(value);
|
|
675
|
+
if (market === 0 /* UNSPECIFIED */) {
|
|
676
|
+
throw new HiveNgError("INVALID_ARGUMENT", "market is required");
|
|
677
|
+
}
|
|
678
|
+
return market;
|
|
679
|
+
}
|
|
680
|
+
function marketFromName(value) {
|
|
681
|
+
const names = {
|
|
682
|
+
app_store: 2 /* APP_STORE */,
|
|
683
|
+
google_play: 1 /* GOOGLE_PLAY */,
|
|
684
|
+
steam: 5 /* STEAM */,
|
|
685
|
+
web: 6 /* WEB */
|
|
686
|
+
};
|
|
687
|
+
return names[value] ?? 0 /* UNSPECIFIED */;
|
|
688
|
+
}
|
|
601
689
|
function marketName(market) {
|
|
602
690
|
const names = {
|
|
603
691
|
[1 /* GOOGLE_PLAY */]: "google_play",
|
|
@@ -607,6 +695,26 @@ function marketName(market) {
|
|
|
607
695
|
};
|
|
608
696
|
return names[market] ?? "unspecified";
|
|
609
697
|
}
|
|
698
|
+
function requireProductType(value) {
|
|
699
|
+
const productType = productTypeFromName(value);
|
|
700
|
+
if (productType === 0 /* UNSPECIFIED */) {
|
|
701
|
+
throw new HiveNgError("INVALID_ARGUMENT", "productType is required");
|
|
702
|
+
}
|
|
703
|
+
return productType;
|
|
704
|
+
}
|
|
705
|
+
function optionalProductType(value) {
|
|
706
|
+
if (value === void 0 || value.trim() === "") {
|
|
707
|
+
return 0 /* UNSPECIFIED */;
|
|
708
|
+
}
|
|
709
|
+
return requireProductType(value);
|
|
710
|
+
}
|
|
711
|
+
function productTypeFromName(value) {
|
|
712
|
+
const names = {
|
|
713
|
+
one_time: 1 /* ONE_TIME */,
|
|
714
|
+
subscription: 2 /* SUBSCRIPTION */
|
|
715
|
+
};
|
|
716
|
+
return names[value] ?? 0 /* UNSPECIFIED */;
|
|
717
|
+
}
|
|
610
718
|
function productTypeName(productType) {
|
|
611
719
|
const names = {
|
|
612
720
|
[1 /* ONE_TIME */]: "one_time",
|
|
@@ -614,6 +722,21 @@ function productTypeName(productType) {
|
|
|
614
722
|
};
|
|
615
723
|
return names[productType] ?? "unspecified";
|
|
616
724
|
}
|
|
725
|
+
function consumePolicyName(policy) {
|
|
726
|
+
const names = {
|
|
727
|
+
1: "none",
|
|
728
|
+
2: "consume_after_grant"
|
|
729
|
+
};
|
|
730
|
+
return names[policy] ?? "unspecified";
|
|
731
|
+
}
|
|
732
|
+
function grantModeName(mode) {
|
|
733
|
+
const names = {
|
|
734
|
+
1: "webhook_required",
|
|
735
|
+
2: "no_grant",
|
|
736
|
+
3: "client_grant"
|
|
737
|
+
};
|
|
738
|
+
return names[mode] ?? "unspecified";
|
|
739
|
+
}
|
|
617
740
|
function purchaseStatusName(status) {
|
|
618
741
|
const names = {
|
|
619
742
|
[1 /* PENDING */]: "pending",
|
|
@@ -625,6 +748,13 @@ function purchaseStatusName(status) {
|
|
|
625
748
|
};
|
|
626
749
|
return names[status] ?? "unspecified";
|
|
627
750
|
}
|
|
751
|
+
function requireValue(value, fieldName) {
|
|
752
|
+
const normalized = value.trim();
|
|
753
|
+
if (!normalized) {
|
|
754
|
+
throw new HiveNgError("INVALID_ARGUMENT", `${fieldName} is required`);
|
|
755
|
+
}
|
|
756
|
+
return normalized;
|
|
757
|
+
}
|
|
628
758
|
function isGrantFinished(purchase) {
|
|
629
759
|
return purchase.grantStatus === "delivered" || purchase.grantStatus === "not_required";
|
|
630
760
|
}
|