@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/index.d.cts CHANGED
@@ -1191,7 +1191,7 @@ type Purchase = Message<"hiveng.v1.Purchase"> & {
1191
1191
  /**
1192
1192
  * @generated from message hiveng.v1.PaymentProduct
1193
1193
  */
1194
- type PaymentProduct = Message<"hiveng.v1.PaymentProduct"> & {
1194
+ type PaymentProduct$1 = Message<"hiveng.v1.PaymentProduct"> & {
1195
1195
  /**
1196
1196
  * @generated from field: string project_id = 1;
1197
1197
  */
@@ -1278,7 +1278,7 @@ type ListProductsResponse = Message<"hiveng.v1.ListProductsResponse"> & {
1278
1278
  /**
1279
1279
  * @generated from field: repeated hiveng.v1.PaymentProduct products = 1;
1280
1280
  */
1281
- products: PaymentProduct[];
1281
+ products: PaymentProduct$1[];
1282
1282
  };
1283
1283
  /**
1284
1284
  * Describes the message hiveng.v1.ListProductsResponse.
@@ -1646,11 +1646,43 @@ interface PaymentPurchase {
1646
1646
  purchasedAt?: Date;
1647
1647
  verifiedAt?: Date;
1648
1648
  }
1649
+ interface PaymentProduct {
1650
+ projectId: string;
1651
+ market: string;
1652
+ appIdentifier: string;
1653
+ productId: string;
1654
+ productType: string;
1655
+ marketStatus: string;
1656
+ title: string;
1657
+ description: string;
1658
+ consumePolicy: string;
1659
+ grantMode: string;
1660
+ enabled: boolean;
1661
+ }
1662
+ interface ListPaymentProductsOptions {
1663
+ market: string;
1664
+ appIdentifier: string;
1665
+ productType?: string;
1666
+ }
1667
+ interface StartPaymentPurchaseOptions {
1668
+ market: string;
1669
+ appIdentifier: string;
1670
+ productId: string;
1671
+ productType: string;
1672
+ }
1673
+ interface VerifyPaymentPurchaseOptions extends StartPaymentPurchaseOptions {
1674
+ receiptPayload?: string;
1675
+ purchaseToken?: string;
1676
+ purchaseIntentId?: string;
1677
+ }
1649
1678
  type PaymentClient = Client<typeof PaymentService>;
1650
1679
  declare class PaymentApi {
1651
1680
  private client;
1652
1681
  bind(client: PaymentClient): void;
1653
1682
  unbind(): void;
1683
+ listProducts(options: ListPaymentProductsOptions): Promise<PaymentProduct[]>;
1684
+ startPurchase(options: StartPaymentPurchaseOptions): Promise<string>;
1685
+ verifyPurchase(options: VerifyPaymentPurchaseOptions): Promise<PaymentPurchase>;
1654
1686
  getPurchase(purchaseId: string): Promise<PaymentPurchase>;
1655
1687
  waitForPaymentGrant(purchaseId: string, timeoutMillis?: number): Promise<PaymentPurchase>;
1656
1688
  private requireClient;
@@ -1673,4 +1705,4 @@ declare class HiveNgClient {
1673
1705
  }
1674
1706
  declare function createHiveNg(config: HiveNgConfig): HiveNgClient;
1675
1707
 
1676
- export { BannedError, type CheckNewMailResult, ErrorCode, HiveNgClient, type HiveNgConfig, HiveNgError, IdentityProvider, type ListMailOptions, type ListMailResult, type LoginProviders, type Mail, MailType, MaintenanceError, type Notice, type PaymentPurchase, type Player, type TransportFactory, type TransportFactoryOptions, createHiveNg, errorCodeOf, errorDetailOf };
1708
+ export { BannedError, type CheckNewMailResult, ErrorCode, HiveNgClient, type HiveNgConfig, HiveNgError, IdentityProvider, type ListMailOptions, type ListMailResult, type ListPaymentProductsOptions, type LoginProviders, type Mail, MailType, MaintenanceError, type Notice, type PaymentProduct, type PaymentPurchase, type Player, type StartPaymentPurchaseOptions, type TransportFactory, type TransportFactoryOptions, type VerifyPaymentPurchaseOptions, createHiveNg, errorCodeOf, errorDetailOf };
package/dist/index.d.ts CHANGED
@@ -1191,7 +1191,7 @@ type Purchase = Message<"hiveng.v1.Purchase"> & {
1191
1191
  /**
1192
1192
  * @generated from message hiveng.v1.PaymentProduct
1193
1193
  */
1194
- type PaymentProduct = Message<"hiveng.v1.PaymentProduct"> & {
1194
+ type PaymentProduct$1 = Message<"hiveng.v1.PaymentProduct"> & {
1195
1195
  /**
1196
1196
  * @generated from field: string project_id = 1;
1197
1197
  */
@@ -1278,7 +1278,7 @@ type ListProductsResponse = Message<"hiveng.v1.ListProductsResponse"> & {
1278
1278
  /**
1279
1279
  * @generated from field: repeated hiveng.v1.PaymentProduct products = 1;
1280
1280
  */
1281
- products: PaymentProduct[];
1281
+ products: PaymentProduct$1[];
1282
1282
  };
1283
1283
  /**
1284
1284
  * Describes the message hiveng.v1.ListProductsResponse.
@@ -1646,11 +1646,43 @@ interface PaymentPurchase {
1646
1646
  purchasedAt?: Date;
1647
1647
  verifiedAt?: Date;
1648
1648
  }
1649
+ interface PaymentProduct {
1650
+ projectId: string;
1651
+ market: string;
1652
+ appIdentifier: string;
1653
+ productId: string;
1654
+ productType: string;
1655
+ marketStatus: string;
1656
+ title: string;
1657
+ description: string;
1658
+ consumePolicy: string;
1659
+ grantMode: string;
1660
+ enabled: boolean;
1661
+ }
1662
+ interface ListPaymentProductsOptions {
1663
+ market: string;
1664
+ appIdentifier: string;
1665
+ productType?: string;
1666
+ }
1667
+ interface StartPaymentPurchaseOptions {
1668
+ market: string;
1669
+ appIdentifier: string;
1670
+ productId: string;
1671
+ productType: string;
1672
+ }
1673
+ interface VerifyPaymentPurchaseOptions extends StartPaymentPurchaseOptions {
1674
+ receiptPayload?: string;
1675
+ purchaseToken?: string;
1676
+ purchaseIntentId?: string;
1677
+ }
1649
1678
  type PaymentClient = Client<typeof PaymentService>;
1650
1679
  declare class PaymentApi {
1651
1680
  private client;
1652
1681
  bind(client: PaymentClient): void;
1653
1682
  unbind(): void;
1683
+ listProducts(options: ListPaymentProductsOptions): Promise<PaymentProduct[]>;
1684
+ startPurchase(options: StartPaymentPurchaseOptions): Promise<string>;
1685
+ verifyPurchase(options: VerifyPaymentPurchaseOptions): Promise<PaymentPurchase>;
1654
1686
  getPurchase(purchaseId: string): Promise<PaymentPurchase>;
1655
1687
  waitForPaymentGrant(purchaseId: string, timeoutMillis?: number): Promise<PaymentPurchase>;
1656
1688
  private requireClient;
@@ -1673,4 +1705,4 @@ declare class HiveNgClient {
1673
1705
  }
1674
1706
  declare function createHiveNg(config: HiveNgConfig): HiveNgClient;
1675
1707
 
1676
- export { BannedError, type CheckNewMailResult, ErrorCode, HiveNgClient, type HiveNgConfig, HiveNgError, IdentityProvider, type ListMailOptions, type ListMailResult, type LoginProviders, type Mail, MailType, MaintenanceError, type Notice, type PaymentPurchase, type Player, type TransportFactory, type TransportFactoryOptions, createHiveNg, errorCodeOf, errorDetailOf };
1708
+ export { BannedError, type CheckNewMailResult, ErrorCode, HiveNgClient, type HiveNgConfig, HiveNgError, IdentityProvider, type ListMailOptions, type ListMailResult, type ListPaymentProductsOptions, type LoginProviders, type Mail, MailType, MaintenanceError, type Notice, type PaymentProduct, type PaymentPurchase, type Player, type StartPaymentPurchaseOptions, type TransportFactory, type TransportFactoryOptions, type VerifyPaymentPurchaseOptions, createHiveNg, errorCodeOf, errorDetailOf };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { BannedError, ErrorCode, HiveNgClient, HiveNgError, IdentityProvider, MailType, MaintenanceError, createHiveNg, errorCodeOf, errorDetailOf } from './chunk-NWQONJK2.js';
1
+ export { BannedError, ErrorCode, HiveNgClient, HiveNgError, IdentityProvider, MailType, MaintenanceError, createHiveNg, errorCodeOf, errorDetailOf } from './chunk-IEKJNYXT.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
@@ -512,6 +512,63 @@ var PaymentApi = class {
512
512
  unbind() {
513
513
  this.client = null;
514
514
  }
515
+ async listProducts(options) {
516
+ const market = requireMarket(options.market);
517
+ const appIdentifier = requireValue(options.appIdentifier, "appIdentifier");
518
+ const client = this.requireClient();
519
+ try {
520
+ const res = await client.listProducts({
521
+ market,
522
+ appIdentifier,
523
+ productType: optionalProductType(options.productType)
524
+ });
525
+ return res.products.map(mapProduct);
526
+ } catch (err) {
527
+ throw toHiveNgError(err);
528
+ }
529
+ }
530
+ async startPurchase(options) {
531
+ const client = this.requireClient();
532
+ try {
533
+ const res = await client.startPurchase({
534
+ market: requireMarket(options.market),
535
+ appIdentifier: requireValue(options.appIdentifier, "appIdentifier"),
536
+ productId: requireValue(options.productId, "productId"),
537
+ productType: requireProductType(options.productType)
538
+ });
539
+ if (!res.purchaseIntentId) {
540
+ throw new HiveNgError("INTERNAL", "start purchase response missing purchaseIntentId");
541
+ }
542
+ return res.purchaseIntentId;
543
+ } catch (err) {
544
+ throw toHiveNgError(err);
545
+ }
546
+ }
547
+ async verifyPurchase(options) {
548
+ const receiptPayload = options.receiptPayload ?? "";
549
+ const purchaseToken = options.purchaseToken ?? "";
550
+ if (!receiptPayload && !purchaseToken) {
551
+ throw new HiveNgError("INVALID_ARGUMENT", "receiptPayload or purchaseToken is required");
552
+ }
553
+ const client = this.requireClient();
554
+ try {
555
+ const res = await client.verifyPurchase({
556
+ market: requireMarket(options.market),
557
+ appIdentifier: requireValue(options.appIdentifier, "appIdentifier"),
558
+ productId: requireValue(options.productId, "productId"),
559
+ productType: requireProductType(options.productType),
560
+ receiptPayload,
561
+ purchaseToken,
562
+ purchaseIntentId: options.purchaseIntentId ?? ""
563
+ });
564
+ if (!res.purchase) {
565
+ throw new HiveNgError("INTERNAL", "verify purchase response missing purchase");
566
+ }
567
+ return mapPurchase(res.purchase);
568
+ } catch (err) {
569
+ throw toHiveNgError(err);
570
+ }
571
+ }
515
572
  async getPurchase(purchaseId) {
516
573
  if (!purchaseId) {
517
574
  throw new HiveNgError("INVALID_ARGUMENT", "purchaseId is required");
@@ -561,6 +618,21 @@ var PaymentApi = class {
561
618
  return this.client;
562
619
  }
563
620
  };
621
+ function mapProduct(message) {
622
+ return {
623
+ projectId: message.projectId,
624
+ market: marketName(message.market),
625
+ appIdentifier: message.appIdentifier,
626
+ productId: message.productId,
627
+ productType: productTypeName(message.productType),
628
+ marketStatus: message.marketStatus,
629
+ title: message.title,
630
+ description: message.description,
631
+ consumePolicy: consumePolicyName(message.consumePolicy),
632
+ grantMode: grantModeName(message.grantMode),
633
+ enabled: message.enabled
634
+ };
635
+ }
564
636
  function mapPurchase(message) {
565
637
  return {
566
638
  id: message.id,
@@ -581,6 +653,22 @@ function mapPurchase(message) {
581
653
  verifiedAt: message.verifiedAt ? wkt.timestampDate(message.verifiedAt) : void 0
582
654
  };
583
655
  }
656
+ function requireMarket(value) {
657
+ const market = marketFromName(value);
658
+ if (market === 0 /* UNSPECIFIED */) {
659
+ throw new HiveNgError("INVALID_ARGUMENT", "market is required");
660
+ }
661
+ return market;
662
+ }
663
+ function marketFromName(value) {
664
+ const names = {
665
+ app_store: 2 /* APP_STORE */,
666
+ google_play: 1 /* GOOGLE_PLAY */,
667
+ steam: 5 /* STEAM */,
668
+ web: 6 /* WEB */
669
+ };
670
+ return names[value] ?? 0 /* UNSPECIFIED */;
671
+ }
584
672
  function marketName(market) {
585
673
  const names = {
586
674
  [1 /* GOOGLE_PLAY */]: "google_play",
@@ -590,6 +678,26 @@ function marketName(market) {
590
678
  };
591
679
  return names[market] ?? "unspecified";
592
680
  }
681
+ function requireProductType(value) {
682
+ const productType = productTypeFromName(value);
683
+ if (productType === 0 /* UNSPECIFIED */) {
684
+ throw new HiveNgError("INVALID_ARGUMENT", "productType is required");
685
+ }
686
+ return productType;
687
+ }
688
+ function optionalProductType(value) {
689
+ if (value === void 0 || value.trim() === "") {
690
+ return 0 /* UNSPECIFIED */;
691
+ }
692
+ return requireProductType(value);
693
+ }
694
+ function productTypeFromName(value) {
695
+ const names = {
696
+ one_time: 1 /* ONE_TIME */,
697
+ subscription: 2 /* SUBSCRIPTION */
698
+ };
699
+ return names[value] ?? 0 /* UNSPECIFIED */;
700
+ }
593
701
  function productTypeName(productType) {
594
702
  const names = {
595
703
  [1 /* ONE_TIME */]: "one_time",
@@ -597,6 +705,21 @@ function productTypeName(productType) {
597
705
  };
598
706
  return names[productType] ?? "unspecified";
599
707
  }
708
+ function consumePolicyName(policy) {
709
+ const names = {
710
+ 1: "none",
711
+ 2: "consume_after_grant"
712
+ };
713
+ return names[policy] ?? "unspecified";
714
+ }
715
+ function grantModeName(mode) {
716
+ const names = {
717
+ 1: "webhook_required",
718
+ 2: "no_grant",
719
+ 3: "client_grant"
720
+ };
721
+ return names[mode] ?? "unspecified";
722
+ }
600
723
  function purchaseStatusName(status) {
601
724
  const names = {
602
725
  [1 /* PENDING */]: "pending",
@@ -608,6 +731,13 @@ function purchaseStatusName(status) {
608
731
  };
609
732
  return names[status] ?? "unspecified";
610
733
  }
734
+ function requireValue(value, fieldName) {
735
+ const normalized = value.trim();
736
+ if (!normalized) {
737
+ throw new HiveNgError("INVALID_ARGUMENT", `${fieldName} is required`);
738
+ }
739
+ return normalized;
740
+ }
611
741
  function isGrantFinished(purchase) {
612
742
  return purchase.grantStatus === "delivered" || purchase.grantStatus === "not_required";
613
743
  }