@shware/purchase 2.0.1 → 4.0.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.
Files changed (37) hide show
  1. package/dist/google-play/index.cjs +3 -1
  2. package/dist/google-play/index.d.cts +3 -2
  3. package/dist/google-play/index.d.mts +3 -2
  4. package/dist/google-play/index.mjs +3 -2
  5. package/dist/google-play/mapper.cjs +19 -0
  6. package/dist/google-play/mapper.cjs.map +1 -0
  7. package/dist/google-play/mapper.d.cts +7 -0
  8. package/dist/google-play/mapper.d.cts.map +1 -0
  9. package/dist/google-play/mapper.d.mts +7 -0
  10. package/dist/google-play/mapper.d.mts.map +1 -0
  11. package/dist/google-play/mapper.mjs +18 -0
  12. package/dist/google-play/mapper.mjs.map +1 -0
  13. package/dist/google-play/real-time-developer-notification.cjs +41 -77
  14. package/dist/google-play/real-time-developer-notification.cjs.map +1 -1
  15. package/dist/google-play/real-time-developer-notification.d.cts +76 -72
  16. package/dist/google-play/real-time-developer-notification.d.cts.map +1 -1
  17. package/dist/google-play/real-time-developer-notification.d.mts +76 -72
  18. package/dist/google-play/real-time-developer-notification.d.mts.map +1 -1
  19. package/dist/google-play/real-time-developer-notification.mjs +41 -77
  20. package/dist/google-play/real-time-developer-notification.mjs.map +1 -1
  21. package/dist/index.cjs +3 -5
  22. package/dist/index.d.cts +2 -2
  23. package/dist/index.d.mts +2 -2
  24. package/dist/index.mjs +2 -2
  25. package/dist/stripe/mapper.cjs +0 -1
  26. package/dist/stripe/mapper.cjs.map +1 -1
  27. package/dist/stripe/mapper.mjs +0 -1
  28. package/dist/stripe/mapper.mjs.map +1 -1
  29. package/dist/subscription/index.cjs +11 -151
  30. package/dist/subscription/index.cjs.map +1 -1
  31. package/dist/subscription/index.d.cts +137 -141
  32. package/dist/subscription/index.d.cts.map +1 -1
  33. package/dist/subscription/index.d.mts +137 -141
  34. package/dist/subscription/index.d.mts.map +1 -1
  35. package/dist/subscription/index.mjs +9 -147
  36. package/dist/subscription/index.mjs.map +1 -1
  37. package/package.json +1 -1
@@ -19,80 +19,84 @@ interface DeveloperNotification {
19
19
  /**
20
20
  * [Real-time developer notifications reference guide](https://developer.android.com/google/play/billing/rtdn-reference)
21
21
  * */
22
- declare enum SubscriptionNotificationType {
22
+ declare const SubscriptionNotificationType: {
23
23
  /** A subscription was recovered from account hold. */
24
- SUBSCRIPTION_RECOVERED = 1,
24
+ readonly SUBSCRIPTION_RECOVERED: 1;
25
25
  /** An active subscription was renewed. */
26
- SUBSCRIPTION_RENEWED = 2,
26
+ readonly SUBSCRIPTION_RENEWED: 2;
27
27
  /**
28
28
  * A subscription was either voluntarily or involuntarily cancelled. For voluntary cancellation,
29
29
  * sent when the user cancels.
30
30
  */
31
- SUBSCRIPTION_CANCELED = 3,
31
+ readonly SUBSCRIPTION_CANCELED: 3;
32
32
  /** A new subscription was purchased. */
33
- SUBSCRIPTION_PURCHASED = 4,
33
+ readonly SUBSCRIPTION_PURCHASED: 4;
34
34
  /** A subscription has entered account hold (if enabled). */
35
- SUBSCRIPTION_ON_HOLD = 5,
35
+ readonly SUBSCRIPTION_ON_HOLD: 5;
36
36
  /** A subscription has entered grace period (if enabled). */
37
- SUBSCRIPTION_IN_GRACE_PERIOD = 6,
37
+ readonly SUBSCRIPTION_IN_GRACE_PERIOD: 6;
38
38
  /**
39
39
  * User has restored their subscription from Play > Account > Subscriptions. The subscription was
40
40
  * canceled but had not expired yet when the user restores. For more information, see Restorations.
41
41
  */
42
- SUBSCRIPTION_RESTARTED = 7,
42
+ readonly SUBSCRIPTION_RESTARTED: 7;
43
43
  /** (DEPRECATED) A subscription price change has successfully been confirmed by the user. */
44
- SUBSCRIPTION_PRICE_CHANGE_CONFIRMED = 8,
44
+ readonly SUBSCRIPTION_PRICE_CHANGE_CONFIRMED: 8;
45
45
  /** A subscription's recurrence time has been extended. */
46
- SUBSCRIPTION_DEFERRED = 9,
46
+ readonly SUBSCRIPTION_DEFERRED: 9;
47
47
  /** A subscription has been paused. */
48
- SUBSCRIPTION_PAUSED = 10,
48
+ readonly SUBSCRIPTION_PAUSED: 10;
49
49
  /** A subscription pause schedule has been changed. */
50
- SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED = 11,
50
+ readonly SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED: 11;
51
51
  /** A subscription has been revoked from the user before the expiration time. */
52
- SUBSCRIPTION_REVOKED = 12,
52
+ readonly SUBSCRIPTION_REVOKED: 12;
53
53
  /** A subscription has expired. */
54
- SUBSCRIPTION_EXPIRED = 13,
54
+ readonly SUBSCRIPTION_EXPIRED: 13;
55
55
  /** A subscription item's price change details are updated. */
56
- SUBSCRIPTION_PRICE_CHANGE_UPDATED = 19,
56
+ readonly SUBSCRIPTION_PRICE_CHANGE_UPDATED: 19;
57
57
  /** A pending transaction of a subscription has been canceled. */
58
- SUBSCRIPTION_PENDING_PURCHASE_CANCELED = 20
59
- }
58
+ readonly SUBSCRIPTION_PENDING_PURCHASE_CANCELED: 20;
59
+ };
60
+ type SubscriptionNotificationType = (typeof SubscriptionNotificationType)[keyof typeof SubscriptionNotificationType];
60
61
  interface SubscriptionNotification {
61
62
  version: string;
62
63
  purchaseToken: string;
63
64
  notificationType: SubscriptionNotificationType;
64
65
  }
65
- declare enum OneTimeProductNotificationType {
66
+ declare const OneTimeProductNotificationType: {
66
67
  /** A one-time product was successfully purchased by a user. */
67
- ONE_TIME_PRODUCT_PURCHASED = 1,
68
+ readonly ONE_TIME_PRODUCT_PURCHASED: 1;
68
69
  /** A pending one-time product purchase has been canceled by the user. */
69
- ONE_TIME_PRODUCT_CANCELED = 2
70
- }
70
+ readonly ONE_TIME_PRODUCT_CANCELED: 2;
71
+ };
72
+ type OneTimeProductNotificationType = (typeof OneTimeProductNotificationType)[keyof typeof OneTimeProductNotificationType];
71
73
  interface OneTimeProductNotification {
72
74
  version: string;
73
75
  sku: string;
74
76
  purchaseToken: string;
75
77
  notificationType: OneTimeProductNotificationType;
76
78
  }
77
- declare enum VoidedPurchaseProductType {
79
+ declare const VoidedPurchaseProductType: {
78
80
  /** A subscription purchase has been voided. */
79
- PRODUCT_TYPE_SUBSCRIPTION = 1,
81
+ readonly PRODUCT_TYPE_SUBSCRIPTION: 1;
80
82
  /** A one-time purchase has been voided. */
81
- PRODUCT_TYPE_ONE_TIME = 2
82
- }
83
+ readonly PRODUCT_TYPE_ONE_TIME: 2;
84
+ };
85
+ type VoidedPurchaseProductType = (typeof VoidedPurchaseProductType)[keyof typeof VoidedPurchaseProductType];
83
86
  /**
84
87
  * Note when the remaining total quantity of a multi-quantity purchase is refunded, the refundType
85
88
  * will be REFUND_TYPE_FULL_REFUND.
86
89
  */
87
- declare enum VoidedPurchaseRefundType {
90
+ declare const VoidedPurchaseRefundType: {
88
91
  /** The purchase has been fully voided. */
89
- REFUND_TYPE_FULL_REFUND = 1,
92
+ readonly REFUND_TYPE_FULL_REFUND: 1;
90
93
  /**
91
94
  * The purchase has been partially voided by a quantity-based partial refund, applicable only to
92
95
  * multi-quantity purchases. A purchase can be partially voided multiple times.
93
96
  */
94
- REFUND_TYPE_QUANTITY_BASED_PARTIAL_REFUND = 2
95
- }
97
+ readonly REFUND_TYPE_QUANTITY_BASED_PARTIAL_REFUND: 2;
98
+ };
99
+ type VoidedPurchaseRefundType = (typeof VoidedPurchaseRefundType)[keyof typeof VoidedPurchaseRefundType];
96
100
  interface VoidedPurchaseNotification {
97
101
  purchaseToken: string;
98
102
  orderId: string;
@@ -103,48 +107,48 @@ interface TestNotification {
103
107
  version: string;
104
108
  }
105
109
  /** ref: https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#SubscriptionState */
106
- declare enum GooglePlaySubscriptionState {
107
- /** Unspecified subscription state. */
108
- SUBSCRIPTION_STATE_UNSPECIFIED = "SUBSCRIPTION_STATE_UNSPECIFIED",
109
- /**
110
- * Subscription was created but awaiting payment during signup. In this state, all items are
111
- * awaiting payment.
112
- */
113
- SUBSCRIPTION_STATE_PENDING = "SUBSCRIPTION_STATE_PENDING",
114
- /**
115
- * Subscription is active.
116
- * (1) If the subscription is an auto renewing plan, at least one item is autoRenewEnabled and not expired.
117
- * (2) If the subscription is a prepaid plan, at least one item is not expired.
118
- */
119
- SUBSCRIPTION_STATE_ACTIVE = "SUBSCRIPTION_STATE_ACTIVE",
120
- /**
121
- * Subscription is paused. The state is only available when the subscription is an auto renewing
122
- * plan. In this state, all items are in paused state.
123
- */
124
- SUBSCRIPTION_STATE_PAUSED = "SUBSCRIPTION_STATE_PAUSED",
125
- /**
126
- * Subscription is in grace period. The state is only available when the subscription is an auto
127
- * renewing plan. In this state, all items are in grace period.
128
- */
129
- SUBSCRIPTION_STATE_IN_GRACE_PERIOD = "SUBSCRIPTION_STATE_IN_GRACE_PERIOD",
130
- /**
131
- * Subscription is on hold (suspended). The state is only available when the subscription is an
132
- * auto renewing plan. In this state, all items are on hold.
133
- */
134
- SUBSCRIPTION_STATE_ON_HOLD = "SUBSCRIPTION_STATE_ON_HOLD",
135
- /**
136
- * Subscription is canceled but not expired yet. The state is only available when the subscription
137
- * is an auto renewing plan. All items have autoRenewEnabled set to false.
138
- */
139
- SUBSCRIPTION_STATE_CANCELED = "SUBSCRIPTION_STATE_CANCELED",
140
- /** Subscription is expired. All items have expiryTime in the past. */
141
- SUBSCRIPTION_STATE_EXPIRED = "SUBSCRIPTION_STATE_EXPIRED",
142
- /**
143
- * Pending transaction for subscription is canceled. If this pending purchase was for an existing
144
- * subscription, use linkedPurchaseToken to get the current state of that subscription.
145
- */
146
- SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED = "SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED"
147
- }
110
+ declare const GOOGLE_PLAY_SUBSCRIPTION_STATES: readonly [
111
+ /** Unspecified subscription state. */
112
+ 'SUBSCRIPTION_STATE_UNSPECIFIED',
113
+ /**
114
+ * Subscription was created but awaiting payment during signup. In this state, all items are
115
+ * awaiting payment.
116
+ */
117
+ 'SUBSCRIPTION_STATE_PENDING',
118
+ /**
119
+ * Subscription is active.
120
+ * (1) If the subscription is an auto renewing plan, at least one item is autoRenewEnabled and not expired.
121
+ * (2) If the subscription is a prepaid plan, at least one item is not expired.
122
+ */
123
+ 'SUBSCRIPTION_STATE_ACTIVE',
124
+ /**
125
+ * Subscription is paused. The state is only available when the subscription is an auto renewing
126
+ * plan. In this state, all items are in paused state.
127
+ */
128
+ 'SUBSCRIPTION_STATE_PAUSED',
129
+ /**
130
+ * Subscription is in grace period. The state is only available when the subscription is an auto
131
+ * renewing plan. In this state, all items are in grace period.
132
+ */
133
+ 'SUBSCRIPTION_STATE_IN_GRACE_PERIOD',
134
+ /**
135
+ * Subscription is on hold (suspended). The state is only available when the subscription is an
136
+ * auto renewing plan. In this state, all items are on hold.
137
+ */
138
+ 'SUBSCRIPTION_STATE_ON_HOLD',
139
+ /**
140
+ * Subscription is canceled but not expired yet. The state is only available when the subscription
141
+ * is an auto renewing plan. All items have autoRenewEnabled set to false.
142
+ */
143
+ 'SUBSCRIPTION_STATE_CANCELED',
144
+ /** Subscription is expired. All items have expiryTime in the past. */
145
+ 'SUBSCRIPTION_STATE_EXPIRED',
146
+ /**
147
+ * Pending transaction for subscription is canceled. If this pending purchase was for an existing
148
+ * subscription, use linkedPurchaseToken to get the current state of that subscription.
149
+ */
150
+ 'SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED'];
151
+ type GooglePlaySubscriptionState = (typeof GOOGLE_PLAY_SUBSCRIPTION_STATES)[number];
148
152
  //#endregion
149
- export { DeveloperNotification, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType };
153
+ export { DeveloperNotification, GOOGLE_PLAY_SUBSCRIPTION_STATES, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType };
150
154
  //# sourceMappingURL=real-time-developer-notification.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"real-time-developer-notification.d.mts","names":[],"sources":["../../src/google-play/real-time-developer-notification.ts"],"mappings":";KACY;EACV;EACA,YAAY;EACZ;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA,0BAA0B;EAC1B,4BAA4B;EAC5B,4BAA4B;EAC5B,kBAAkB;;;;;aAMR;;EAEV;;EAGA;;;;;EAMA;;EAGA;;EAGA;;EAGA;;;;;EAMA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;UAGe;EACf;EACA;EACA,kBAAkB;;aAGR;;EAEV;;EAGA;;UAGe;EACf;EACA;EACA;EACA,kBAAkB;;aAGR;;EAEV;;EAGA;;;;;;aAOU;;EAEV;;;;;EAMA;;UAGe;EACf;EACA;EACA,aAAa;EACb,YAAY;;UAGG;EACf;;;aAIU;;EAEV;;;;;EAMA;;;;;;EAOA;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;EAMA;;EAGA;;;;;EAMA"}
1
+ {"version":3,"file":"real-time-developer-notification.d.mts","names":[],"sources":["../../src/google-play/real-time-developer-notification.ts"],"mappings":";KACY;EACV;EACA,YAAY;EACZ;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA,0BAA0B;EAC1B,4BAA4B;EAC5B,4BAA4B;EAC5B,kBAAkB;;;;;cAMP;;WAEX;;WAGA;;;;;WAMA;;WAGA;;WAGA;;WAGA;;;;;WAMA;;WAGA;;WAGA;;WAGA;;WAGA;;WAGA;;WAGA;;WAGA;;WAGA;;KAGU,uCACF,2CAA2C;UAEpC;EACf;EACA;EACA,kBAAkB;;cAGP;;WAEX;;WAGA;;KAGU,yCACF,6CAA6C;UAEtC;EACf;EACA;EACA;EACA,kBAAkB;;cAGP;;WAEX;;WAGA;;KAGU,oCACF,wCAAwC;;;;;cAMrC;;WAEX;;;;;WAMA;;KAGU,mCACF,uCAAuC;UAEhC;EACf;EACA;EACA,aAAa;EACb,YAAY;;UAGG;EACf;;;cAIW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmDD,sCAAsC"}
@@ -2,118 +2,82 @@
2
2
  /**
3
3
  * [Real-time developer notifications reference guide](https://developer.android.com/google/play/billing/rtdn-reference)
4
4
  * */
5
- let SubscriptionNotificationType = /* @__PURE__ */ function(SubscriptionNotificationType) {
5
+ const SubscriptionNotificationType = {
6
6
  /** A subscription was recovered from account hold. */
7
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_RECOVERED"] = 1] = "SUBSCRIPTION_RECOVERED";
7
+ SUBSCRIPTION_RECOVERED: 1,
8
8
  /** An active subscription was renewed. */
9
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_RENEWED"] = 2] = "SUBSCRIPTION_RENEWED";
9
+ SUBSCRIPTION_RENEWED: 2,
10
10
  /**
11
11
  * A subscription was either voluntarily or involuntarily cancelled. For voluntary cancellation,
12
12
  * sent when the user cancels.
13
13
  */
14
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_CANCELED"] = 3] = "SUBSCRIPTION_CANCELED";
14
+ SUBSCRIPTION_CANCELED: 3,
15
15
  /** A new subscription was purchased. */
16
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_PURCHASED"] = 4] = "SUBSCRIPTION_PURCHASED";
16
+ SUBSCRIPTION_PURCHASED: 4,
17
17
  /** A subscription has entered account hold (if enabled). */
18
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_ON_HOLD"] = 5] = "SUBSCRIPTION_ON_HOLD";
18
+ SUBSCRIPTION_ON_HOLD: 5,
19
19
  /** A subscription has entered grace period (if enabled). */
20
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_IN_GRACE_PERIOD"] = 6] = "SUBSCRIPTION_IN_GRACE_PERIOD";
20
+ SUBSCRIPTION_IN_GRACE_PERIOD: 6,
21
21
  /**
22
22
  * User has restored their subscription from Play > Account > Subscriptions. The subscription was
23
23
  * canceled but had not expired yet when the user restores. For more information, see Restorations.
24
24
  */
25
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_RESTARTED"] = 7] = "SUBSCRIPTION_RESTARTED";
25
+ SUBSCRIPTION_RESTARTED: 7,
26
26
  /** (DEPRECATED) A subscription price change has successfully been confirmed by the user. */
27
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_PRICE_CHANGE_CONFIRMED"] = 8] = "SUBSCRIPTION_PRICE_CHANGE_CONFIRMED";
27
+ SUBSCRIPTION_PRICE_CHANGE_CONFIRMED: 8,
28
28
  /** A subscription's recurrence time has been extended. */
29
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_DEFERRED"] = 9] = "SUBSCRIPTION_DEFERRED";
29
+ SUBSCRIPTION_DEFERRED: 9,
30
30
  /** A subscription has been paused. */
31
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_PAUSED"] = 10] = "SUBSCRIPTION_PAUSED";
31
+ SUBSCRIPTION_PAUSED: 10,
32
32
  /** A subscription pause schedule has been changed. */
33
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED"] = 11] = "SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED";
33
+ SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED: 11,
34
34
  /** A subscription has been revoked from the user before the expiration time. */
35
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_REVOKED"] = 12] = "SUBSCRIPTION_REVOKED";
35
+ SUBSCRIPTION_REVOKED: 12,
36
36
  /** A subscription has expired. */
37
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_EXPIRED"] = 13] = "SUBSCRIPTION_EXPIRED";
37
+ SUBSCRIPTION_EXPIRED: 13,
38
38
  /** A subscription item's price change details are updated. */
39
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_PRICE_CHANGE_UPDATED"] = 19] = "SUBSCRIPTION_PRICE_CHANGE_UPDATED";
39
+ SUBSCRIPTION_PRICE_CHANGE_UPDATED: 19,
40
40
  /** A pending transaction of a subscription has been canceled. */
41
- SubscriptionNotificationType[SubscriptionNotificationType["SUBSCRIPTION_PENDING_PURCHASE_CANCELED"] = 20] = "SUBSCRIPTION_PENDING_PURCHASE_CANCELED";
42
- return SubscriptionNotificationType;
43
- }({});
44
- let OneTimeProductNotificationType = /* @__PURE__ */ function(OneTimeProductNotificationType) {
41
+ SUBSCRIPTION_PENDING_PURCHASE_CANCELED: 20
42
+ };
43
+ const OneTimeProductNotificationType = {
45
44
  /** A one-time product was successfully purchased by a user. */
46
- OneTimeProductNotificationType[OneTimeProductNotificationType["ONE_TIME_PRODUCT_PURCHASED"] = 1] = "ONE_TIME_PRODUCT_PURCHASED";
45
+ ONE_TIME_PRODUCT_PURCHASED: 1,
47
46
  /** A pending one-time product purchase has been canceled by the user. */
48
- OneTimeProductNotificationType[OneTimeProductNotificationType["ONE_TIME_PRODUCT_CANCELED"] = 2] = "ONE_TIME_PRODUCT_CANCELED";
49
- return OneTimeProductNotificationType;
50
- }({});
51
- let VoidedPurchaseProductType = /* @__PURE__ */ function(VoidedPurchaseProductType) {
47
+ ONE_TIME_PRODUCT_CANCELED: 2
48
+ };
49
+ const VoidedPurchaseProductType = {
52
50
  /** A subscription purchase has been voided. */
53
- VoidedPurchaseProductType[VoidedPurchaseProductType["PRODUCT_TYPE_SUBSCRIPTION"] = 1] = "PRODUCT_TYPE_SUBSCRIPTION";
51
+ PRODUCT_TYPE_SUBSCRIPTION: 1,
54
52
  /** A one-time purchase has been voided. */
55
- VoidedPurchaseProductType[VoidedPurchaseProductType["PRODUCT_TYPE_ONE_TIME"] = 2] = "PRODUCT_TYPE_ONE_TIME";
56
- return VoidedPurchaseProductType;
57
- }({});
53
+ PRODUCT_TYPE_ONE_TIME: 2
54
+ };
58
55
  /**
59
56
  * Note when the remaining total quantity of a multi-quantity purchase is refunded, the refundType
60
57
  * will be REFUND_TYPE_FULL_REFUND.
61
58
  */
62
- let VoidedPurchaseRefundType = /* @__PURE__ */ function(VoidedPurchaseRefundType) {
59
+ const VoidedPurchaseRefundType = {
63
60
  /** The purchase has been fully voided. */
64
- VoidedPurchaseRefundType[VoidedPurchaseRefundType["REFUND_TYPE_FULL_REFUND"] = 1] = "REFUND_TYPE_FULL_REFUND";
61
+ REFUND_TYPE_FULL_REFUND: 1,
65
62
  /**
66
63
  * The purchase has been partially voided by a quantity-based partial refund, applicable only to
67
64
  * multi-quantity purchases. A purchase can be partially voided multiple times.
68
65
  */
69
- VoidedPurchaseRefundType[VoidedPurchaseRefundType["REFUND_TYPE_QUANTITY_BASED_PARTIAL_REFUND"] = 2] = "REFUND_TYPE_QUANTITY_BASED_PARTIAL_REFUND";
70
- return VoidedPurchaseRefundType;
71
- }({});
66
+ REFUND_TYPE_QUANTITY_BASED_PARTIAL_REFUND: 2
67
+ };
72
68
  /** ref: https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#SubscriptionState */
73
- let GooglePlaySubscriptionState = /* @__PURE__ */ function(GooglePlaySubscriptionState) {
74
- /** Unspecified subscription state. */
75
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_UNSPECIFIED"] = "SUBSCRIPTION_STATE_UNSPECIFIED";
76
- /**
77
- * Subscription was created but awaiting payment during signup. In this state, all items are
78
- * awaiting payment.
79
- */
80
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_PENDING"] = "SUBSCRIPTION_STATE_PENDING";
81
- /**
82
- * Subscription is active.
83
- * (1) If the subscription is an auto renewing plan, at least one item is autoRenewEnabled and not expired.
84
- * (2) If the subscription is a prepaid plan, at least one item is not expired.
85
- */
86
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_ACTIVE"] = "SUBSCRIPTION_STATE_ACTIVE";
87
- /**
88
- * Subscription is paused. The state is only available when the subscription is an auto renewing
89
- * plan. In this state, all items are in paused state.
90
- */
91
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_PAUSED"] = "SUBSCRIPTION_STATE_PAUSED";
92
- /**
93
- * Subscription is in grace period. The state is only available when the subscription is an auto
94
- * renewing plan. In this state, all items are in grace period.
95
- */
96
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_IN_GRACE_PERIOD"] = "SUBSCRIPTION_STATE_IN_GRACE_PERIOD";
97
- /**
98
- * Subscription is on hold (suspended). The state is only available when the subscription is an
99
- * auto renewing plan. In this state, all items are on hold.
100
- */
101
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_ON_HOLD"] = "SUBSCRIPTION_STATE_ON_HOLD";
102
- /**
103
- * Subscription is canceled but not expired yet. The state is only available when the subscription
104
- * is an auto renewing plan. All items have autoRenewEnabled set to false.
105
- */
106
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_CANCELED"] = "SUBSCRIPTION_STATE_CANCELED";
107
- /** Subscription is expired. All items have expiryTime in the past. */
108
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_EXPIRED"] = "SUBSCRIPTION_STATE_EXPIRED";
109
- /**
110
- * Pending transaction for subscription is canceled. If this pending purchase was for an existing
111
- * subscription, use linkedPurchaseToken to get the current state of that subscription.
112
- */
113
- GooglePlaySubscriptionState["SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED"] = "SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED";
114
- return GooglePlaySubscriptionState;
115
- }({});
69
+ const GOOGLE_PLAY_SUBSCRIPTION_STATES = [
70
+ "SUBSCRIPTION_STATE_UNSPECIFIED",
71
+ "SUBSCRIPTION_STATE_PENDING",
72
+ "SUBSCRIPTION_STATE_ACTIVE",
73
+ "SUBSCRIPTION_STATE_PAUSED",
74
+ "SUBSCRIPTION_STATE_IN_GRACE_PERIOD",
75
+ "SUBSCRIPTION_STATE_ON_HOLD",
76
+ "SUBSCRIPTION_STATE_CANCELED",
77
+ "SUBSCRIPTION_STATE_EXPIRED",
78
+ "SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED"
79
+ ];
116
80
  //#endregion
117
- export { GooglePlaySubscriptionState, OneTimeProductNotificationType, SubscriptionNotificationType, VoidedPurchaseProductType, VoidedPurchaseRefundType };
81
+ export { GOOGLE_PLAY_SUBSCRIPTION_STATES, OneTimeProductNotificationType, SubscriptionNotificationType, VoidedPurchaseProductType, VoidedPurchaseRefundType };
118
82
 
119
83
  //# sourceMappingURL=real-time-developer-notification.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"real-time-developer-notification.mjs","names":[],"sources":["../../src/google-play/real-time-developer-notification.ts"],"sourcesContent":["// ref: https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage\nexport type PubsubMessage = {\n data: string;\n attributes: Record<string, string>;\n messageId: string;\n publishTime: string;\n orderingKey: string;\n};\n\n/** https://developer.android.com/google/play/billing/rtdn-reference */\nexport interface DeveloperNotification {\n version: string;\n packageName: string;\n eventTimeMillis: number;\n subscriptionNotification: SubscriptionNotification;\n oneTimeProductNotification: OneTimeProductNotification;\n voidedPurchaseNotification: VoidedPurchaseNotification;\n testNotification: TestNotification;\n}\n\n/**\n * [Real-time developer notifications reference guide](https://developer.android.com/google/play/billing/rtdn-reference)\n * */\nexport enum SubscriptionNotificationType {\n /** A subscription was recovered from account hold. */\n SUBSCRIPTION_RECOVERED = 1,\n\n /** An active subscription was renewed. */\n SUBSCRIPTION_RENEWED = 2,\n\n /**\n * A subscription was either voluntarily or involuntarily cancelled. For voluntary cancellation,\n * sent when the user cancels.\n */\n SUBSCRIPTION_CANCELED = 3,\n\n /** A new subscription was purchased. */\n SUBSCRIPTION_PURCHASED = 4,\n\n /** A subscription has entered account hold (if enabled). */\n SUBSCRIPTION_ON_HOLD = 5,\n\n /** A subscription has entered grace period (if enabled). */\n SUBSCRIPTION_IN_GRACE_PERIOD = 6,\n\n /**\n * User has restored their subscription from Play > Account > Subscriptions. The subscription was\n * canceled but had not expired yet when the user restores. For more information, see Restorations.\n */\n SUBSCRIPTION_RESTARTED = 7,\n\n /** (DEPRECATED) A subscription price change has successfully been confirmed by the user. */\n SUBSCRIPTION_PRICE_CHANGE_CONFIRMED = 8,\n\n /** A subscription's recurrence time has been extended. */\n SUBSCRIPTION_DEFERRED = 9,\n\n /** A subscription has been paused. */\n SUBSCRIPTION_PAUSED = 10,\n\n /** A subscription pause schedule has been changed. */\n SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED = 11,\n\n /** A subscription has been revoked from the user before the expiration time. */\n SUBSCRIPTION_REVOKED = 12,\n\n /** A subscription has expired. */\n SUBSCRIPTION_EXPIRED = 13,\n\n /** A subscription item's price change details are updated. */\n SUBSCRIPTION_PRICE_CHANGE_UPDATED = 19,\n\n /** A pending transaction of a subscription has been canceled. */\n SUBSCRIPTION_PENDING_PURCHASE_CANCELED = 20,\n}\n\nexport interface SubscriptionNotification {\n version: string;\n purchaseToken: string;\n notificationType: SubscriptionNotificationType;\n}\n\nexport enum OneTimeProductNotificationType {\n /** A one-time product was successfully purchased by a user. */\n ONE_TIME_PRODUCT_PURCHASED = 1,\n\n /** A pending one-time product purchase has been canceled by the user. */\n ONE_TIME_PRODUCT_CANCELED = 2,\n}\n\nexport interface OneTimeProductNotification {\n version: string;\n sku: string;\n purchaseToken: string;\n notificationType: OneTimeProductNotificationType;\n}\n\nexport enum VoidedPurchaseProductType {\n /** A subscription purchase has been voided. */\n PRODUCT_TYPE_SUBSCRIPTION = 1,\n\n /** A one-time purchase has been voided. */\n PRODUCT_TYPE_ONE_TIME = 2,\n}\n\n/**\n * Note when the remaining total quantity of a multi-quantity purchase is refunded, the refundType\n * will be REFUND_TYPE_FULL_REFUND.\n */\nexport enum VoidedPurchaseRefundType {\n /** The purchase has been fully voided. */\n REFUND_TYPE_FULL_REFUND = 1,\n\n /**\n * The purchase has been partially voided by a quantity-based partial refund, applicable only to\n * multi-quantity purchases. A purchase can be partially voided multiple times.\n */\n REFUND_TYPE_QUANTITY_BASED_PARTIAL_REFUND = 2,\n}\n\nexport interface VoidedPurchaseNotification {\n purchaseToken: string;\n orderId: string;\n productType: VoidedPurchaseProductType;\n refundType: VoidedPurchaseRefundType;\n}\n\nexport interface TestNotification {\n version: string;\n}\n\n/** ref: https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#SubscriptionState */\nexport enum GooglePlaySubscriptionState {\n /** Unspecified subscription state. */\n SUBSCRIPTION_STATE_UNSPECIFIED = 'SUBSCRIPTION_STATE_UNSPECIFIED',\n\n /**\n * Subscription was created but awaiting payment during signup. In this state, all items are\n * awaiting payment.\n */\n SUBSCRIPTION_STATE_PENDING = 'SUBSCRIPTION_STATE_PENDING',\n\n /**\n * Subscription is active.\n * (1) If the subscription is an auto renewing plan, at least one item is autoRenewEnabled and not expired.\n * (2) If the subscription is a prepaid plan, at least one item is not expired.\n */\n SUBSCRIPTION_STATE_ACTIVE = 'SUBSCRIPTION_STATE_ACTIVE',\n\n /**\n * Subscription is paused. The state is only available when the subscription is an auto renewing\n * plan. In this state, all items are in paused state.\n */\n SUBSCRIPTION_STATE_PAUSED = 'SUBSCRIPTION_STATE_PAUSED',\n\n /**\n * Subscription is in grace period. The state is only available when the subscription is an auto\n * renewing plan. In this state, all items are in grace period.\n */\n SUBSCRIPTION_STATE_IN_GRACE_PERIOD = 'SUBSCRIPTION_STATE_IN_GRACE_PERIOD',\n\n /**\n * Subscription is on hold (suspended). The state is only available when the subscription is an\n * auto renewing plan. In this state, all items are on hold.\n */\n SUBSCRIPTION_STATE_ON_HOLD = 'SUBSCRIPTION_STATE_ON_HOLD',\n\n /**\n * Subscription is canceled but not expired yet. The state is only available when the subscription\n * is an auto renewing plan. All items have autoRenewEnabled set to false.\n */\n SUBSCRIPTION_STATE_CANCELED = 'SUBSCRIPTION_STATE_CANCELED',\n\n /** Subscription is expired. All items have expiryTime in the past. */\n SUBSCRIPTION_STATE_EXPIRED = 'SUBSCRIPTION_STATE_EXPIRED',\n\n /**\n * Pending transaction for subscription is canceled. If this pending purchase was for an existing\n * subscription, use linkedPurchaseToken to get the current state of that subscription.\n */\n SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED = 'SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED',\n}\n"],"mappings":";;;;AAuBA,IAAY,+BAAL,yBAAA,8BAAA;;CAEL,6BAAA,6BAAA,4BAAA,KAAA;;CAGA,6BAAA,6BAAA,0BAAA,KAAA;;;;;CAMA,6BAAA,6BAAA,2BAAA,KAAA;;CAGA,6BAAA,6BAAA,4BAAA,KAAA;;CAGA,6BAAA,6BAAA,0BAAA,KAAA;;CAGA,6BAAA,6BAAA,kCAAA,KAAA;;;;;CAMA,6BAAA,6BAAA,4BAAA,KAAA;;CAGA,6BAAA,6BAAA,yCAAA,KAAA;;CAGA,6BAAA,6BAAA,2BAAA,KAAA;;CAGA,6BAAA,6BAAA,yBAAA,MAAA;;CAGA,6BAAA,6BAAA,yCAAA,MAAA;;CAGA,6BAAA,6BAAA,0BAAA,MAAA;;CAGA,6BAAA,6BAAA,0BAAA,MAAA;;CAGA,6BAAA,6BAAA,uCAAA,MAAA;;CAGA,6BAAA,6BAAA,4CAAA,MAAA;;AACF,EAAA,CAAA,CAAA;AAQA,IAAY,iCAAL,yBAAA,gCAAA;;CAEL,+BAAA,+BAAA,gCAAA,KAAA;;CAGA,+BAAA,+BAAA,+BAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AASA,IAAY,4BAAL,yBAAA,2BAAA;;CAEL,0BAAA,0BAAA,+BAAA,KAAA;;CAGA,0BAAA,0BAAA,2BAAA,KAAA;;AACF,EAAA,CAAA,CAAA;;;;;AAMA,IAAY,2BAAL,yBAAA,0BAAA;;CAEL,yBAAA,yBAAA,6BAAA,KAAA;;;;;CAMA,yBAAA,yBAAA,+CAAA,KAAA;;AACF,EAAA,CAAA,CAAA;;AAcA,IAAY,8BAAL,yBAAA,6BAAA;;CAEL,4BAAA,oCAAA;;;;;CAMA,4BAAA,gCAAA;;;;;;CAOA,4BAAA,+BAAA;;;;;CAMA,4BAAA,+BAAA;;;;;CAMA,4BAAA,wCAAA;;;;;CAMA,4BAAA,gCAAA;;;;;CAMA,4BAAA,iCAAA;;CAGA,4BAAA,gCAAA;;;;;CAMA,4BAAA,kDAAA;;AACF,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"real-time-developer-notification.mjs","names":[],"sources":["../../src/google-play/real-time-developer-notification.ts"],"sourcesContent":["// ref: https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage\nexport type PubsubMessage = {\n data: string;\n attributes: Record<string, string>;\n messageId: string;\n publishTime: string;\n orderingKey: string;\n};\n\n/** https://developer.android.com/google/play/billing/rtdn-reference */\nexport interface DeveloperNotification {\n version: string;\n packageName: string;\n eventTimeMillis: number;\n subscriptionNotification: SubscriptionNotification;\n oneTimeProductNotification: OneTimeProductNotification;\n voidedPurchaseNotification: VoidedPurchaseNotification;\n testNotification: TestNotification;\n}\n\n/**\n * [Real-time developer notifications reference guide](https://developer.android.com/google/play/billing/rtdn-reference)\n * */\nexport const SubscriptionNotificationType = {\n /** A subscription was recovered from account hold. */\n SUBSCRIPTION_RECOVERED: 1,\n\n /** An active subscription was renewed. */\n SUBSCRIPTION_RENEWED: 2,\n\n /**\n * A subscription was either voluntarily or involuntarily cancelled. For voluntary cancellation,\n * sent when the user cancels.\n */\n SUBSCRIPTION_CANCELED: 3,\n\n /** A new subscription was purchased. */\n SUBSCRIPTION_PURCHASED: 4,\n\n /** A subscription has entered account hold (if enabled). */\n SUBSCRIPTION_ON_HOLD: 5,\n\n /** A subscription has entered grace period (if enabled). */\n SUBSCRIPTION_IN_GRACE_PERIOD: 6,\n\n /**\n * User has restored their subscription from Play > Account > Subscriptions. The subscription was\n * canceled but had not expired yet when the user restores. For more information, see Restorations.\n */\n SUBSCRIPTION_RESTARTED: 7,\n\n /** (DEPRECATED) A subscription price change has successfully been confirmed by the user. */\n SUBSCRIPTION_PRICE_CHANGE_CONFIRMED: 8,\n\n /** A subscription's recurrence time has been extended. */\n SUBSCRIPTION_DEFERRED: 9,\n\n /** A subscription has been paused. */\n SUBSCRIPTION_PAUSED: 10,\n\n /** A subscription pause schedule has been changed. */\n SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED: 11,\n\n /** A subscription has been revoked from the user before the expiration time. */\n SUBSCRIPTION_REVOKED: 12,\n\n /** A subscription has expired. */\n SUBSCRIPTION_EXPIRED: 13,\n\n /** A subscription item's price change details are updated. */\n SUBSCRIPTION_PRICE_CHANGE_UPDATED: 19,\n\n /** A pending transaction of a subscription has been canceled. */\n SUBSCRIPTION_PENDING_PURCHASE_CANCELED: 20,\n} as const;\n\nexport type SubscriptionNotificationType =\n (typeof SubscriptionNotificationType)[keyof typeof SubscriptionNotificationType];\n\nexport interface SubscriptionNotification {\n version: string;\n purchaseToken: string;\n notificationType: SubscriptionNotificationType;\n}\n\nexport const OneTimeProductNotificationType = {\n /** A one-time product was successfully purchased by a user. */\n ONE_TIME_PRODUCT_PURCHASED: 1,\n\n /** A pending one-time product purchase has been canceled by the user. */\n ONE_TIME_PRODUCT_CANCELED: 2,\n} as const;\n\nexport type OneTimeProductNotificationType =\n (typeof OneTimeProductNotificationType)[keyof typeof OneTimeProductNotificationType];\n\nexport interface OneTimeProductNotification {\n version: string;\n sku: string;\n purchaseToken: string;\n notificationType: OneTimeProductNotificationType;\n}\n\nexport const VoidedPurchaseProductType = {\n /** A subscription purchase has been voided. */\n PRODUCT_TYPE_SUBSCRIPTION: 1,\n\n /** A one-time purchase has been voided. */\n PRODUCT_TYPE_ONE_TIME: 2,\n} as const;\n\nexport type VoidedPurchaseProductType =\n (typeof VoidedPurchaseProductType)[keyof typeof VoidedPurchaseProductType];\n\n/**\n * Note when the remaining total quantity of a multi-quantity purchase is refunded, the refundType\n * will be REFUND_TYPE_FULL_REFUND.\n */\nexport const VoidedPurchaseRefundType = {\n /** The purchase has been fully voided. */\n REFUND_TYPE_FULL_REFUND: 1,\n\n /**\n * The purchase has been partially voided by a quantity-based partial refund, applicable only to\n * multi-quantity purchases. A purchase can be partially voided multiple times.\n */\n REFUND_TYPE_QUANTITY_BASED_PARTIAL_REFUND: 2,\n} as const;\n\nexport type VoidedPurchaseRefundType =\n (typeof VoidedPurchaseRefundType)[keyof typeof VoidedPurchaseRefundType];\n\nexport interface VoidedPurchaseNotification {\n purchaseToken: string;\n orderId: string;\n productType: VoidedPurchaseProductType;\n refundType: VoidedPurchaseRefundType;\n}\n\nexport interface TestNotification {\n version: string;\n}\n\n/** ref: https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#SubscriptionState */\nexport const GOOGLE_PLAY_SUBSCRIPTION_STATES = [\n /** Unspecified subscription state. */\n 'SUBSCRIPTION_STATE_UNSPECIFIED',\n\n /**\n * Subscription was created but awaiting payment during signup. In this state, all items are\n * awaiting payment.\n */\n 'SUBSCRIPTION_STATE_PENDING',\n\n /**\n * Subscription is active.\n * (1) If the subscription is an auto renewing plan, at least one item is autoRenewEnabled and not expired.\n * (2) If the subscription is a prepaid plan, at least one item is not expired.\n */\n 'SUBSCRIPTION_STATE_ACTIVE',\n\n /**\n * Subscription is paused. The state is only available when the subscription is an auto renewing\n * plan. In this state, all items are in paused state.\n */\n 'SUBSCRIPTION_STATE_PAUSED',\n\n /**\n * Subscription is in grace period. The state is only available when the subscription is an auto\n * renewing plan. In this state, all items are in grace period.\n */\n 'SUBSCRIPTION_STATE_IN_GRACE_PERIOD',\n\n /**\n * Subscription is on hold (suspended). The state is only available when the subscription is an\n * auto renewing plan. In this state, all items are on hold.\n */\n 'SUBSCRIPTION_STATE_ON_HOLD',\n\n /**\n * Subscription is canceled but not expired yet. The state is only available when the subscription\n * is an auto renewing plan. All items have autoRenewEnabled set to false.\n */\n 'SUBSCRIPTION_STATE_CANCELED',\n\n /** Subscription is expired. All items have expiryTime in the past. */\n 'SUBSCRIPTION_STATE_EXPIRED',\n\n /**\n * Pending transaction for subscription is canceled. If this pending purchase was for an existing\n * subscription, use linkedPurchaseToken to get the current state of that subscription.\n */\n 'SUBSCRIPTION_STATE_PENDING_PURCHASE_CANCELED',\n] as const;\n\nexport type GooglePlaySubscriptionState = (typeof GOOGLE_PLAY_SUBSCRIPTION_STATES)[number];\n"],"mappings":";;;;AAuBA,MAAa,+BAA+B;;CAE1C,wBAAwB;;CAGxB,sBAAsB;;;;;CAMtB,uBAAuB;;CAGvB,wBAAwB;;CAGxB,sBAAsB;;CAGtB,8BAA8B;;;;;CAM9B,wBAAwB;;CAGxB,qCAAqC;;CAGrC,uBAAuB;;CAGvB,qBAAqB;;CAGrB,qCAAqC;;CAGrC,sBAAsB;;CAGtB,sBAAsB;;CAGtB,mCAAmC;;CAGnC,wCAAwC;AAC1C;AAWA,MAAa,iCAAiC;;CAE5C,4BAA4B;;CAG5B,2BAA2B;AAC7B;AAYA,MAAa,4BAA4B;;CAEvC,2BAA2B;;CAG3B,uBAAuB;AACzB;;;;;AASA,MAAa,2BAA2B;;CAEtC,yBAAyB;;;;;CAMzB,2CAA2C;AAC7C;;AAiBA,MAAa,kCAAkC;CAE7C;CAMA;CAOA;CAMA;CAMA;CAMA;CAMA;CAGA;CAMA;AACF"}
package/dist/index.cjs CHANGED
@@ -3,11 +3,9 @@ const require_subscription_index = require("./subscription/index.cjs");
3
3
  const require_app_store_config = require("./app-store/config.cjs");
4
4
  const require_google_play_config = require("./google-play/config.cjs");
5
5
  const require_stripe_config = require("./stripe/config.cjs");
6
- exports.ALL_PLATFORMS = require_subscription_index.ALL_PLATFORMS;
7
- exports.ALL_SUBSCRIPTION_STATUS = require_subscription_index.ALL_SUBSCRIPTION_STATUS;
8
- exports.AVAILABLE_STATUS = require_subscription_index.AVAILABLE_STATUS;
6
+ exports.AVAILABLE_STATUSES = require_subscription_index.AVAILABLE_STATUSES;
9
7
  exports.AppStoreConfig = require_app_store_config.AppStoreConfig;
10
8
  exports.GooglePlayConfig = require_google_play_config.GooglePlayConfig;
11
- exports.Platform = require_subscription_index.Platform;
9
+ exports.PLATFORMS = require_subscription_index.PLATFORMS;
10
+ exports.SUBSCRIPTION_STATUSES = require_subscription_index.SUBSCRIPTION_STATUSES;
12
11
  exports.StripeConfig = require_stripe_config.StripeConfig;
13
- exports.SubscriptionStatus = require_subscription_index.SubscriptionStatus;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AppStoreConfig } from "./app-store/config.cjs";
2
2
  import { GooglePlayConfig } from "./google-play/config.cjs";
3
- import { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from "./subscription/index.cjs";
3
+ import { AVAILABLE_STATUSES, PLATFORMS, Platform, SUBSCRIPTION_STATUSES, SubscriptionStatus } from "./subscription/index.cjs";
4
4
  import { StripeConfig } from "./stripe/config.cjs";
5
- export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, AppStoreConfig, GooglePlayConfig, Platform, StripeConfig, SubscriptionStatus };
5
+ export { AVAILABLE_STATUSES, AppStoreConfig, GooglePlayConfig, PLATFORMS, type Platform, SUBSCRIPTION_STATUSES, StripeConfig, type SubscriptionStatus };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AppStoreConfig } from "./app-store/config.mjs";
2
2
  import { GooglePlayConfig } from "./google-play/config.mjs";
3
- import { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from "./subscription/index.mjs";
3
+ import { AVAILABLE_STATUSES, PLATFORMS, Platform, SUBSCRIPTION_STATUSES, SubscriptionStatus } from "./subscription/index.mjs";
4
4
  import { StripeConfig } from "./stripe/config.mjs";
5
- export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, AppStoreConfig, GooglePlayConfig, Platform, StripeConfig, SubscriptionStatus };
5
+ export { AVAILABLE_STATUSES, AppStoreConfig, GooglePlayConfig, PLATFORMS, type Platform, SUBSCRIPTION_STATUSES, StripeConfig, type SubscriptionStatus };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from "./subscription/index.mjs";
1
+ import { AVAILABLE_STATUSES, PLATFORMS, SUBSCRIPTION_STATUSES } from "./subscription/index.mjs";
2
2
  import { AppStoreConfig } from "./app-store/config.mjs";
3
3
  import { GooglePlayConfig } from "./google-play/config.mjs";
4
4
  import { StripeConfig } from "./stripe/config.mjs";
5
- export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, AppStoreConfig, GooglePlayConfig, Platform, StripeConfig, SubscriptionStatus };
5
+ export { AVAILABLE_STATUSES, AppStoreConfig, GooglePlayConfig, PLATFORMS, SUBSCRIPTION_STATUSES, StripeConfig };
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("../subscription/index.cjs");
3
2
  //#region src/stripe/mapper.ts
4
3
  function mapTime(stripeTimestampSeconds) {
5
4
  if (!stripeTimestampSeconds) return null;
@@ -1 +1 @@
1
- {"version":3,"file":"mapper.cjs","names":[],"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport type Price = {\n id: string;\n type: Stripe.Price.Type;\n active: boolean;\n billing_scheme: Stripe.Price.BillingScheme;\n currency: Stripe.Price['currency'];\n unit_amount: number | null;\n unit_amount_decimal: string | null;\n recurring: Stripe.Price.Recurring | null;\n};\n\nexport function mapPrice(price: Stripe.Price): Price {\n return {\n id: price.id,\n type: price.type,\n active: price.active,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n unit_amount: price.unit_amount,\n unit_amount_decimal: price.unit_amount_decimal?.toString() ?? null,\n recurring: price.recurring,\n };\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? mapPrice(item.price) : null,\n };\n}\n\nexport type PaymentStatus = 'no_payment_required' | 'paid' | 'unpaid';\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n // The variable annotation makes the emitted .d.ts reference the local\n // PaymentStatus alias instead of stripe's internal module path (TS2883)\n const payment_status: PaymentStatus = session.payment_status;\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${String(status)}`);\n throw new Error(`Invalid stripe status: ${String(status)}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";;;AAGA,SAAgB,QACd,wBACkC;CAClC,IAAI,CAAC,wBAAwB,OAAO;CACpC,wBAAO,IAAI,KAAK,yBAAyB,GAAI,EAAA,CA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S,SAAS,YAAY,CAAC,IAAI,IAAI;AACxE;AAEA,SAAgB,MAAM,OAAe,UAAkB;CACrD,OAAO,QAAQ,WAAW,QAAQ;AACpC;AAwCA,SAAgB,sBAAsB,SAA8C;CAClF,IAAI;CACJ,IAAI;CACJ,IAAI,CAAC,QAAQ,gBAAgB,CAAC,QAAQ,UAAU;EAC9C,QAAQ,QAAQ,YAAY,QAAQ,KAAK,SAAS,OAAO,KAAK,gBAAgB,IAAI,CAAC,KAAK;EACxF,WAAW,QAAQ,aAAa,EAAE,EAAE,YAAY;CAClD,OAAO;EACL,QAAQ,QAAQ;EAChB,WAAW,QAAQ;CACrB;CAEA,OAAO;EACL,gBAAgB,QAAQ;EACxB,OAAO,MAAM,OAAO,QAAQ;EAC5B,UAAU,SAAS,YAAY;EAC/B,QAAQ,QAAQ;EAChB,OAAO,QAAQ,YAAY,KAAK,MAAM,WAAW;GAC/C;GACA,SAAS,KAAK;GACd,WAAW,KAAK,eAAe;GAC/B,OAAO,MAAM,KAAK,cAAc,KAAK,QAAQ;GAC7C,UAAU,KAAK,YAAY;GAC3B,UAAU,MAAM,KAAK,iBAAiB,KAAK,QAAQ;EACrD,EAAE;CACJ;AACF;AAEA,SAAgB,2BAA2B,GAA0C;CACnF,OAAO;EACL,UAAU,EAAE,SAAS,YAAY;EACjC,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;EACtC,OAAO,CACL;GACE,SAAS,EAAE,QAAQ;GACnB,WAAW,EAAE,QAAQ;GACrB,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;EACxC,CACF;CACF;AACF"}
1
+ {"version":3,"file":"mapper.cjs","names":[],"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\nimport type { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport type Price = {\n id: string;\n type: Stripe.Price.Type;\n active: boolean;\n billing_scheme: Stripe.Price.BillingScheme;\n currency: Stripe.Price['currency'];\n unit_amount: number | null;\n unit_amount_decimal: string | null;\n recurring: Stripe.Price.Recurring | null;\n};\n\nexport function mapPrice(price: Stripe.Price): Price {\n return {\n id: price.id,\n type: price.type,\n active: price.active,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n unit_amount: price.unit_amount,\n unit_amount_decimal: price.unit_amount_decimal?.toString() ?? null,\n recurring: price.recurring,\n };\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? mapPrice(item.price) : null,\n };\n}\n\nexport type PaymentStatus = 'no_payment_required' | 'paid' | 'unpaid';\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n // The variable annotation makes the emitted .d.ts reference the local\n // PaymentStatus alias instead of stripe's internal module path (TS2883)\n const payment_status: PaymentStatus = session.payment_status;\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return 'ACTIVE';\n case 'canceled':\n return 'CANCELED';\n case 'incomplete':\n return 'INCOMPLETE';\n case 'incomplete_expired':\n return 'INCOMPLETE_EXPIRED';\n case 'past_due':\n return 'PAST_DUE';\n case 'paused':\n return 'PAUSED';\n case 'trialing':\n return 'TRIALING';\n case 'unpaid':\n return 'UNPAID';\n default: {\n console.error(`Invalid stripe status: ${String(status)}`);\n throw new Error(`Invalid stripe status: ${String(status)}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.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TimestampSeconds) {
4
3
  if (!stripeTimestampSeconds) return null;
@@ -1 +1 @@
1
- {"version":3,"file":"mapper.mjs","names":[],"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\nimport { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport type Price = {\n id: string;\n type: Stripe.Price.Type;\n active: boolean;\n billing_scheme: Stripe.Price.BillingScheme;\n currency: Stripe.Price['currency'];\n unit_amount: number | null;\n unit_amount_decimal: string | null;\n recurring: Stripe.Price.Recurring | null;\n};\n\nexport function mapPrice(price: Stripe.Price): Price {\n return {\n id: price.id,\n type: price.type,\n active: price.active,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n unit_amount: price.unit_amount,\n unit_amount_decimal: price.unit_amount_decimal?.toString() ?? null,\n recurring: price.recurring,\n };\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? mapPrice(item.price) : null,\n };\n}\n\nexport type PaymentStatus = 'no_payment_required' | 'paid' | 'unpaid';\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n // The variable annotation makes the emitted .d.ts reference the local\n // PaymentStatus alias instead of stripe's internal module path (TS2883)\n const payment_status: PaymentStatus = session.payment_status;\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return SubscriptionStatus.ACTIVE;\n case 'canceled':\n return SubscriptionStatus.CANCELED;\n case 'incomplete':\n return SubscriptionStatus.INCOMPLETE;\n case 'incomplete_expired':\n return SubscriptionStatus.INCOMPLETE_EXPIRED;\n case 'past_due':\n return SubscriptionStatus.PAST_DUE;\n case 'paused':\n return SubscriptionStatus.PAUSED;\n case 'trialing':\n return SubscriptionStatus.TRIALING;\n case 'unpaid':\n return SubscriptionStatus.UNPAID;\n default: {\n console.error(`Invalid stripe status: ${String(status)}`);\n throw new Error(`Invalid stripe status: ${String(status)}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";;AAGA,SAAgB,QACd,wBACkC;CAClC,IAAI,CAAC,wBAAwB,OAAO;CACpC,wBAAO,IAAI,KAAK,yBAAyB,GAAI,EAAA,CAAE,YAAY;AAC7D;AAaA,SAAgB,SAAS,OAA4B;CACnD,OAAO;EACL,IAAI,MAAM;EACV,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,gBAAgB,MAAM;EACtB,UAAU,MAAM;EAChB,aAAa,MAAM;EACnB,qBAAqB,MAAM,qBAAqB,SAAS,KAAK;EAC9D,WAAW,MAAM;CACnB;AACF;AAEA,SAAgB,YAAY,MAAuB;CACjD,OAAO;EACL,IAAI,KAAK,QACL,OAAO,KAAK,MAAM,YAAY,WAC5B,KAAK,MAAM,UACX,KAAK,MAAM,QAAQ,KACrB,KAAK;EACT,UAAU,KAAK;EACf,UAAU,KAAK;EACf,aAAa,KAAK;EAClB,YAAY,KAAK;EACjB,cAAc,KAAK;EACnB,iBAAiB,KAAK;EACtB,iBAAiB,KAAK;EACtB,OAAO,KAAK,QAAQ,SAAS,KAAK,KAAK,IAAI;CAC7C;AACF;AAIA,SAAgB,mBAAmB,SAAkC;CACnE,IAAI,SAA6B,KAAA;CACjC,IAAI,MAAM,QAAQ,QAAQ,SAAS,KAAK,QAAQ,UAAU,WAAW,GAAG;EACtE,M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AK,iBAAiB,KAAK,QAAQ;EACrD,EAAE;CACJ;AACF;AAEA,SAAgB,2BAA2B,GAA0C;CACnF,OAAO;EACL,UAAU,EAAE,SAAS,YAAY;EACjC,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;EACtC,OAAO,CACL;GACE,SAAS,EAAE,QAAQ;GACnB,WAAW,EAAE,QAAQ;GACrB,OAAO,MAAM,EAAE,aAAa,EAAE,QAAQ;EACxC,CACF;CACF;AACF"}
1
+ {"version":3,"file":"mapper.mjs","names":[],"sources":["../../src/stripe/mapper.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\nimport type { SubscriptionStatus } from '../subscription/index';\n\nexport function mapTime<T extends number | null>(\n stripeTimestampSeconds: T\n): T extends number ? string : null {\n if (!stripeTimestampSeconds) return null as T extends number ? string : null;\n return new Date(stripeTimestampSeconds * 1000).toISOString() as T extends number ? string : null;\n}\n\nexport type Price = {\n id: string;\n type: Stripe.Price.Type;\n active: boolean;\n billing_scheme: Stripe.Price.BillingScheme;\n currency: Stripe.Price['currency'];\n unit_amount: number | null;\n unit_amount_decimal: string | null;\n recurring: Stripe.Price.Recurring | null;\n};\n\nexport function mapPrice(price: Stripe.Price): Price {\n return {\n id: price.id,\n type: price.type,\n active: price.active,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n unit_amount: price.unit_amount,\n unit_amount_decimal: price.unit_amount_decimal?.toString() ?? null,\n recurring: price.recurring,\n };\n}\n\nexport function mapLineItem(item: Stripe.LineItem) {\n return {\n id: item.price\n ? typeof item.price.product === 'string'\n ? item.price.product\n : item.price.product.id\n : item.id,\n currency: item.currency,\n quantity: item.quantity,\n description: item.description,\n amount_tax: item.amount_tax,\n amount_total: item.amount_total,\n amount_subtotal: item.amount_subtotal,\n amount_discount: item.amount_discount,\n price: item.price ? mapPrice(item.price) : null,\n };\n}\n\nexport type PaymentStatus = 'no_payment_required' | 'paid' | 'unpaid';\n\nexport function mapCheckoutSession(session: Stripe.Checkout.Session) {\n let coupon: string | undefined = undefined;\n if (Array.isArray(session.discounts) && session.discounts.length !== 0) {\n const discount = session.discounts[0];\n if (discount.coupon && typeof discount.coupon === 'object') {\n coupon = discount.coupon.id;\n } else if (typeof discount.coupon === 'string') {\n coupon = discount.coupon;\n } else {\n coupon = undefined;\n }\n }\n\n // The variable annotation makes the emitted .d.ts reference the local\n // PaymentStatus alias instead of stripe's internal module path (TS2883)\n const payment_status: PaymentStatus = session.payment_status;\n\n return {\n id: session.id,\n url: session.url,\n coupon,\n livemode: session.livemode,\n expires_at: session.expires_at,\n payment_status,\n currency: session.currency,\n amount_total: session.amount_total,\n line_items: session.line_items?.data.map(mapLineItem),\n };\n}\n\nexport function mapInvoice(i: Stripe.Invoice) {\n return {\n id: i.id,\n number: i.number,\n total: i.total,\n subtotal: i.subtotal,\n amount_due: i.amount_due,\n amount_paid: i.amount_paid,\n amount_remaining: i.amount_remaining,\n currency: i.currency,\n billing_reason: i.billing_reason,\n hosted_invoice_url: i.hosted_invoice_url,\n invoice_pdf: i.invoice_pdf,\n receipt_number: i.receipt_number,\n status: i.status,\n created: i.created,\n period_start: i.period_start,\n period_end: i.period_end,\n };\n}\n\nexport function mapPaymentIntent(intent: Stripe.PaymentIntent) {\n return {\n id: intent.id,\n amount: intent.amount,\n amount_capturable: intent.amount_capturable,\n amount_received: intent.amount_received,\n currency: intent.currency,\n client_secret: intent.client_secret,\n description: intent.description,\n status: intent.status,\n created: intent.created,\n };\n}\n\nexport function mapCharge(charge: Stripe.Charge) {\n return {\n id: charge.id,\n description: charge.description,\n currency: charge.currency,\n amount: charge.amount,\n amount_captured: charge.amount_captured,\n amount_refunded: charge.amount_refunded,\n receipt_email: charge.receipt_email,\n receipt_number: charge.receipt_number,\n receipt_url: charge.receipt_url,\n status: charge.status,\n created: charge.created,\n payment_intent:\n charge.payment_intent && typeof charge.payment_intent === 'object'\n ? mapPaymentIntent(charge.payment_intent)\n : undefined,\n };\n}\n\nexport type CheckoutSession = ReturnType<typeof mapCheckoutSession>;\nexport type ProductPrice = {\n id: string;\n type: Stripe.Price.Type;\n unit_amount: number;\n currency: Stripe.Price['currency'];\n product: {\n id: Stripe.Product['id'];\n name: Stripe.Product['name'];\n description: Stripe.Product['description'];\n livemode: Stripe.Product['livemode'];\n };\n};\n\nexport function mapSubscriptionStatus(status: Stripe.Subscription.Status): SubscriptionStatus {\n switch (status) {\n case 'active':\n return 'ACTIVE';\n case 'canceled':\n return 'CANCELED';\n case 'incomplete':\n return 'INCOMPLETE';\n case 'incomplete_expired':\n return 'INCOMPLETE_EXPIRED';\n case 'past_due':\n return 'PAST_DUE';\n case 'paused':\n return 'PAUSED';\n case 'trialing':\n return 'TRIALING';\n case 'unpaid':\n return 'UNPAID';\n default: {\n console.error(`Invalid stripe status: ${String(status)}`);\n throw new Error(`Invalid stripe status: ${String(status)}`);\n }\n }\n}\n\nexport const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\nexport function minorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n\nexport function price(value: number, currency: string) {\n return value / minorUnits(currency);\n}\n\nexport interface Item {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n}\n\nexport interface PurchaseProperties {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n}\n\nexport interface BeginCheckoutProperties {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n}\n\nexport function getPurchaseProperties(session: CheckoutSession): PurchaseProperties {\n let value: number;\n let currency: string;\n if (!session.amount_total || !session.currency) {\n value = session.line_items?.reduce((acc, item) => acc + (item.amount_total ?? 0), 0) ?? 0;\n currency = session.line_items?.[0]?.currency ?? 'usd';\n } else {\n value = session.amount_total;\n currency = session.currency;\n }\n\n return {\n transaction_id: session.id,\n value: price(value, currency),\n currency: currency.toUpperCase(),\n coupon: session.coupon,\n items: session.line_items?.map((item, index) => ({\n index,\n item_id: item.id,\n item_name: item.description ?? '',\n price: price(item.amount_total, item.currency),\n quantity: item.quantity ?? 1,\n discount: price(item.amount_discount, item.currency),\n })),\n };\n}\n\nexport function getBeginCheckoutProperties(p: ProductPrice): BeginCheckoutProperties {\n return {\n currency: p.currency.toUpperCase(),\n value: price(p.unit_amount, p.currency),\n items: [\n {\n item_id: p.product.id,\n item_name: p.product.name,\n price: price(p.unit_amount, p.currency),\n },\n ],\n };\n}\n"],"mappings":";AAGA,SAAgB,QACd,wBACkC;CAClC,IAAI,CAAC,wBAAwB,OAAO;CACpC,wBAAO,IAAI,KAAK,yBAAyB,GAAI,EAAA,CAAE,YAAY;AAC7D;AAaA,SAAgB,SAAS,OAA4B;CACnD,OAAO;EACL,IAAI,MAAM;EACV,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,gBAAgB,MAAM;EACtB,UAAU,MAAM;EAChB,aAAa,MAAM;EACnB,qBAAqB,MAAM,qBAAqB,SAAS,KAAK;EAC9D,WAAW,MAAM;CACnB;AACF;AAEA,SAAgB,YAAY,MAAuB;CACjD,OAAO;EACL,IAAI,KAAK,QACL,OAAO,KAAK,MAAM,YAAY,WAC5B,KAAK,MAAM,UACX,KAAK,MAAM,QAAQ,KACrB,KAAK;EACT,UAAU,KAAK;EACf,UAAU,KAAK;EACf,aAAa,KAAK;EAClB,YAAY,KAAK;EACjB,cAAc,KAAK;EACnB,iBAAiB,KAAK;EACtB,iBAAiB,KAAK;EACtB,OAAO,KAAK,QAAQ,SAAS,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