@shware/purchase 2.0.1 → 3.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.
@@ -1,11 +1,5 @@
1
1
  //#region src/subscription/index.ts
2
- let Platform = /* @__PURE__ */ function(Platform) {
3
- Platform["APPLE"] = "APPLE";
4
- Platform["GOOGLE"] = "GOOGLE";
5
- Platform["STRIPE"] = "STRIPE";
6
- return Platform;
7
- }({});
8
- const ALL_PLATFORMS = [
2
+ const PLATFORMS = [
9
3
  "APPLE",
10
4
  "GOOGLE",
11
5
  "STRIPE"
@@ -16,145 +10,7 @@ const ALL_PLATFORMS = [
16
10
  *
17
11
  * provision product for customer when Status = TRIALING, ACTIVE, IN_GRACE_PERIOD
18
12
  */
19
- let SubscriptionStatus = /* @__PURE__ */ function(SubscriptionStatus) {
20
- /**
21
- * The subscription is currently in a trial period and it’s safe to provision your product for
22
- * your customer. The subscription transitions automatically to active when the first payment
23
- * is made.
24
- *
25
- * Google: play(LineItems[0].OfferDetails.OfferId == 'xx')
26
- *
27
- * Platform: Apple, Google, Stripe
28
- * */
29
- SubscriptionStatus["TRIALING"] = "TRIALING";
30
- /**
31
- * The subscription is in good standing and the most recent payment is successful. It’s safe to
32
- * provision your product for your customer.
33
- *
34
- * Platform: Apple, Google, Stripe
35
- * */
36
- SubscriptionStatus["ACTIVE"] = "ACTIVE";
37
- /**
38
- * Apple: The subscription enters the billing retry period. If the subtype is GRACE_PERIOD,
39
- * continue to provide service through the grace period. If the subtype is empty, the
40
- * subscription isn’t in a grace period and you can stop providing the subscription service.
41
- *
42
- * Google: Subscription is in grace period. The state is only available when the subscription
43
- * is an auto renewing plan. In this state, all items are in grace period.
44
- *
45
- * Platform: Apple, Google
46
- * */
47
- SubscriptionStatus["IN_GRACE_PERIOD"] = "IN_GRACE_PERIOD";
48
- /**
49
- * A successful payment needs to be made within 23 hours to activate the subscription. Or the
50
- * payment requires action, like customer authentication. Subscriptions can also be incomplete
51
- * if there’s a pending payment and the PaymentIntent status would be processing.
52
- *
53
- * Platform: Stripe
54
- * */
55
- SubscriptionStatus["INCOMPLETE"] = "INCOMPLETE";
56
- /**
57
- * The initial payment on the subscription failed and no successful payment was made within 23
58
- * hours of creating the subscription. These subscriptions don’t bill customers. This status
59
- * exists so you can track customers that failed to activate their subscriptions.
60
- *
61
- * Platform: Stripe
62
- * */
63
- SubscriptionStatus["INCOMPLETE_EXPIRED"] = "INCOMPLETE_EXPIRED";
64
- /**
65
- * Subscription was created but awaiting payment during signup. In this state, all items are
66
- * awaiting payment.
67
- *
68
- * Platform: Google
69
- * */
70
- SubscriptionStatus["PENDING"] = "PENDING";
71
- /**
72
- * Pending transaction for subscription is canceled. If this pending purchase was for an
73
- * existing subscription, use linkedPurchaseToken to get the current state of that subscription.
74
- *
75
- * Platform: Google
76
- * */
77
- SubscriptionStatus["PENDING_PURCHASE_CANCELED"] = "PENDING_PURCHASE_CANCELED";
78
- /**
79
- * Payment on the latest finalized invoice either failed or wasn’t attempted. The subscription
80
- * continues to create invoices. Your subscription settings determine the subscription’s next
81
- * state. If the invoice is still unpaid after all Smart Retries have been attempted, you can
82
- * configure the subscription to move to canceled, unpaid, or leave it as past_due. To move the
83
- * subscription to active, pay the most recent invoice before its due date.
84
- *
85
- * Platform: Stripe
86
- * */
87
- SubscriptionStatus["PAST_DUE"] = "PAST_DUE";
88
- /**
89
- * Subscription is on hold (suspended). The state is only available when the subscription is an
90
- * auto renewing plan. In this state, all items are on hold. Grace period ends or Active period
91
- * ends but not grace period
92
- *
93
- * Platform: Google
94
- * */
95
- SubscriptionStatus["ON_HOLD"] = "ON_HOLD";
96
- /**
97
- * The subscription has been canceled. During cancellation, automatic collection for all unpaid
98
- * invoices is disabled (auto_advance=false). This is a terminal state that can’t be updated.
99
- *
100
- * Platform: Apple, Google, Stripe
101
- * */
102
- SubscriptionStatus["CANCELED"] = "CANCELED";
103
- /**
104
- * The latest invoice hasn’t been paid but the subscription remains in place. The latest invoice
105
- * remains open and invoices continue to be generated but payments aren’t attempted. You should
106
- * revoke access to your product when the subscription is unpaid since payments were already
107
- * attempted and retried when it was past_due. To move the subscription to active, pay the most
108
- * recent invoice before its due date.
109
- *
110
- * Platform: Stripe
111
- * */
112
- SubscriptionStatus["UNPAID"] = "UNPAID";
113
- /**
114
- * Google: Subscription is paused. The state is only available when the subscription is an auto
115
- * renewing plan. In this state, all items are in paused state.
116
- *
117
- * Stripe: The subscription has ended its trial period without a default payment method and the
118
- * trial_settings.end_behavior.missing_payment_method is set to pause. Invoices will no longer
119
- * be created for the subscription. After a default payment method has been attached to the
120
- * customer, you can resume the subscription.
121
- *
122
- * Platform: Google, Stripe
123
- * */
124
- SubscriptionStatus["PAUSED"] = "PAUSED";
125
- /**
126
- * For example, a user buys a subscription and receives a purchase token A. The
127
- * linkedPurchaseToken field will not be set in the API response because the purchase token
128
- * belongs to a brand new subscription.
129
- *
130
- * If the user upgrades their subscription, a new purchase token B will be generated. Since the
131
- * upgrade is replacing the subscription from purchase token A, the linkedPurchaseToken field
132
- * for token B will be set to point to token A. Notice it points backwards in time to the
133
- * original purchase token.
134
- *
135
- * +---------------------------+ +------------------------+ +------------------------+
136
- * | Step 1 first purchase | | Step 2 upgrades | | Step 3 downgrades |
137
- * | purchaseToken: A |->| purchaseToken: B |->| purchaseToken: C |
138
- * | linkedPurchaseToken: null | | linkedPurchaseToken: A | | linkedPurchaseToken: B |
139
- * +---------------------------+ +------------------------+ +------------------------+
140
- *
141
- * Platform: Google
142
- * */
143
- SubscriptionStatus["REPLACED"] = "REPLACED";
144
- /**
145
- * Google: Subscription is expired. All items have expiryTime in the past.
146
- *
147
- * Platform: Apple, Google
148
- * */
149
- SubscriptionStatus["EXPIRED"] = "EXPIRED";
150
- return SubscriptionStatus;
151
- }({});
152
- const AVAILABLE_STATUS = [
153
- "ACTIVE",
154
- "TRIALING",
155
- "IN_GRACE_PERIOD"
156
- ];
157
- const ALL_SUBSCRIPTION_STATUS = [
13
+ const SUBSCRIPTION_STATUSES = [
158
14
  "TRIALING",
159
15
  "ACTIVE",
160
16
  "IN_GRACE_PERIOD",
@@ -170,7 +26,13 @@ const ALL_SUBSCRIPTION_STATUS = [
170
26
  "REPLACED",
171
27
  "EXPIRED"
172
28
  ];
29
+ /** statuses where it is safe to provision your product for the customer */
30
+ const AVAILABLE_STATUSES = [
31
+ "ACTIVE",
32
+ "TRIALING",
33
+ "IN_GRACE_PERIOD"
34
+ ];
173
35
  //#endregion
174
- export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus };
36
+ export { AVAILABLE_STATUSES, PLATFORMS, SUBSCRIPTION_STATUSES };
175
37
 
176
38
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/subscription/index.ts"],"sourcesContent":["export enum Platform {\n APPLE = 'APPLE',\n GOOGLE = 'GOOGLE',\n STRIPE = 'STRIPE',\n}\n\nexport const ALL_PLATFORMS = [Platform.APPLE, Platform.GOOGLE, Platform.STRIPE] as const;\n\n/**\n * [Stripe Subscription Status](https://stripe.com/docs/api/subscriptions/object#subscription_object-status)\n * [Stripe Subscription Lifecycle](https://docs.stripe.com/billing/subscriptions/overview)\n *\n * provision product for customer when Status = TRIALING, ACTIVE, IN_GRACE_PERIOD\n */\nexport enum SubscriptionStatus {\n /**\n * The subscription is currently in a trial period and it’s safe to provision your product for\n * your customer. The subscription transitions automatically to active when the first payment\n * is made.\n *\n * Google: play(LineItems[0].OfferDetails.OfferId == 'xx')\n *\n * Platform: Apple, Google, Stripe\n * */\n TRIALING = 'TRIALING',\n\n /**\n * The subscription is in good standing and the most recent payment is successful. It’s safe to\n * provision your product for your customer.\n *\n * Platform: Apple, Google, Stripe\n * */\n ACTIVE = 'ACTIVE',\n\n /**\n * Apple: The subscription enters the billing retry period. If the subtype is GRACE_PERIOD,\n * continue to provide service through the grace period. If the subtype is empty, the\n * subscription isn’t in a grace period and you can stop providing the subscription service.\n *\n * Google: Subscription is in grace period. The state is only available when the subscription\n * is an auto renewing plan. In this state, all items are in grace period.\n *\n * Platform: Apple, Google\n * */\n IN_GRACE_PERIOD = 'IN_GRACE_PERIOD',\n\n /**\n * A successful payment needs to be made within 23 hours to activate the subscription. Or the\n * payment requires action, like customer authentication. Subscriptions can also be incomplete\n * if there’s a pending payment and the PaymentIntent status would be processing.\n *\n * Platform: Stripe\n * */\n INCOMPLETE = 'INCOMPLETE',\n\n /**\n * The initial payment on the subscription failed and no successful payment was made within 23\n * hours of creating the subscription. These subscriptions don’t bill customers. This status\n * exists so you can track customers that failed to activate their subscriptions.\n *\n * Platform: Stripe\n * */\n INCOMPLETE_EXPIRED = 'INCOMPLETE_EXPIRED',\n\n /**\n * Subscription was created but awaiting payment during signup. In this state, all items are\n * awaiting payment.\n *\n * Platform: Google\n * */\n PENDING = 'PENDING',\n\n /**\n * Pending transaction for subscription is canceled. If this pending purchase was for an\n * existing subscription, use linkedPurchaseToken to get the current state of that subscription.\n *\n * Platform: Google\n * */\n PENDING_PURCHASE_CANCELED = 'PENDING_PURCHASE_CANCELED',\n\n /**\n * Payment on the latest finalized invoice either failed or wasn’t attempted. The subscription\n * continues to create invoices. Your subscription settings determine the subscription’s next\n * state. If the invoice is still unpaid after all Smart Retries have been attempted, you can\n * configure the subscription to move to canceled, unpaid, or leave it as past_due. To move the\n * subscription to active, pay the most recent invoice before its due date.\n *\n * Platform: Stripe\n * */\n PAST_DUE = 'PAST_DUE',\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. Grace period ends or Active period\n * ends but not grace period\n *\n * Platform: Google\n * */\n ON_HOLD = 'ON_HOLD',\n\n /**\n * The subscription has been canceled. During cancellation, automatic collection for all unpaid\n * invoices is disabled (auto_advance=false). This is a terminal state that can’t be updated.\n *\n * Platform: Apple, Google, Stripe\n * */\n CANCELED = 'CANCELED',\n\n /**\n * The latest invoice hasn’t been paid but the subscription remains in place. The latest invoice\n * remains open and invoices continue to be generated but payments aren’t attempted. You should\n * revoke access to your product when the subscription is unpaid since payments were already\n * attempted and retried when it was past_due. To move the subscription to active, pay the most\n * recent invoice before its due date.\n *\n * Platform: Stripe\n * */\n UNPAID = 'UNPAID',\n\n /**\n * Google: Subscription is paused. The state is only available when the subscription is an auto\n * renewing plan. In this state, all items are in paused state.\n *\n * Stripe: The subscription has ended its trial period without a default payment method and the\n * trial_settings.end_behavior.missing_payment_method is set to pause. Invoices will no longer\n * be created for the subscription. After a default payment method has been attached to the\n * customer, you can resume the subscription.\n *\n * Platform: Google, Stripe\n * */\n PAUSED = 'PAUSED',\n\n /**\n * For example, a user buys a subscription and receives a purchase token A. The\n * linkedPurchaseToken field will not be set in the API response because the purchase token\n * belongs to a brand new subscription.\n *\n * If the user upgrades their subscription, a new purchase token B will be generated. Since the\n * upgrade is replacing the subscription from purchase token A, the linkedPurchaseToken field\n * for token B will be set to point to token A. Notice it points backwards in time to the\n * original purchase token.\n *\n * +---------------------------+ +------------------------+ +------------------------+\n * | Step 1 first purchase | | Step 2 upgrades | | Step 3 downgrades |\n * | purchaseToken: A |->| purchaseToken: B |->| purchaseToken: C |\n * | linkedPurchaseToken: null | | linkedPurchaseToken: A | | linkedPurchaseToken: B |\n * +---------------------------+ +------------------------+ +------------------------+\n *\n * Platform: Google\n * */\n REPLACED = 'REPLACED',\n\n /**\n * Google: \tSubscription is expired. All items have expiryTime in the past.\n *\n * Platform: Apple, Google\n * */\n EXPIRED = 'EXPIRED',\n}\n\nexport const AVAILABLE_STATUS = [\n SubscriptionStatus.ACTIVE,\n SubscriptionStatus.TRIALING,\n SubscriptionStatus.IN_GRACE_PERIOD,\n];\n\nexport const ALL_SUBSCRIPTION_STATUS = [\n SubscriptionStatus.TRIALING,\n SubscriptionStatus.ACTIVE,\n SubscriptionStatus.IN_GRACE_PERIOD,\n SubscriptionStatus.INCOMPLETE,\n SubscriptionStatus.INCOMPLETE_EXPIRED,\n SubscriptionStatus.PENDING,\n SubscriptionStatus.PENDING_PURCHASE_CANCELED,\n SubscriptionStatus.PAST_DUE,\n SubscriptionStatus.ON_HOLD,\n SubscriptionStatus.CANCELED,\n SubscriptionStatus.UNPAID,\n SubscriptionStatus.PAUSED,\n SubscriptionStatus.REPLACED,\n SubscriptionStatus.EXPIRED,\n] as const;\n"],"mappings":";AAAA,IAAY,WAAL,yBAAA,UAAA;CACL,SAAA,WAAA;CACA,SAAA,YAAA;CACA,SAAA,YAAA;;AACF,EAAA,CAAA,CAAA;AAEA,MAAa,gBAAgB;;;;AAAiD;;;;;;;AAQ9E,IAAY,qBAAL,yBAAA,oBAAA;;;;;;;;;;CAUL,mBAAA,cAAA;;;;;;;CAQA,mBAAA,YAAA;;;;;;;;;;;CAYA,mBAAA,qBAAA;;;;;;;;CASA,mBAAA,gBAAA;;;;;;;;CASA,mBAAA,wBAAA;;;;;;;CAQA,mBAAA,aAAA;;;;;;;CAQA,mBAAA,+BAAA;;;;;;;;;;CAWA,mBAAA,cAAA;;;;;;;;CASA,mBAAA,aAAA;;;;;;;CAQA,mBAAA,cAAA;;;;;;;;;;CAWA,mBAAA,YAAA;;;;;;;;;;;;CAaA,mBAAA,YAAA;;;;;;;;;;;;;;;;;;;CAoBA,mBAAA,cAAA;;;;;;CAOA,mBAAA,aAAA;;AACF,EAAA,CAAA,CAAA;AAEA,MAAa,mBAAmB;;;;AAIhC;AAEA,MAAa,0BAA0B;;;;;;;;;;;;;;;AAevC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/subscription/index.ts"],"sourcesContent":["export const PLATFORMS = ['APPLE', 'GOOGLE', 'STRIPE'] as const;\n\nexport type Platform = (typeof PLATFORMS)[number];\n\n/**\n * [Stripe Subscription Status](https://stripe.com/docs/api/subscriptions/object#subscription_object-status)\n * [Stripe Subscription Lifecycle](https://docs.stripe.com/billing/subscriptions/overview)\n *\n * provision product for customer when Status = TRIALING, ACTIVE, IN_GRACE_PERIOD\n */\nexport const SUBSCRIPTION_STATUSES = [\n /**\n * The subscription is currently in a trial period and it’s safe to provision your product for\n * your customer. The subscription transitions automatically to active when the first payment\n * is made.\n *\n * Google: play(LineItems[0].OfferDetails.OfferId == 'xx')\n *\n * Platform: Apple, Google, Stripe\n * */\n 'TRIALING',\n\n /**\n * The subscription is in good standing and the most recent payment is successful. It’s safe to\n * provision your product for your customer.\n *\n * Platform: Apple, Google, Stripe\n * */\n 'ACTIVE',\n\n /**\n * Apple: The subscription enters the billing retry period. If the subtype is GRACE_PERIOD,\n * continue to provide service through the grace period. If the subtype is empty, the\n * subscription isn’t in a grace period and you can stop providing the subscription service.\n *\n * Google: Subscription is in grace period. The state is only available when the subscription\n * is an auto renewing plan. In this state, all items are in grace period.\n *\n * Platform: Apple, Google\n * */\n 'IN_GRACE_PERIOD',\n\n /**\n * A successful payment needs to be made within 23 hours to activate the subscription. Or the\n * payment requires action, like customer authentication. Subscriptions can also be incomplete\n * if there’s a pending payment and the PaymentIntent status would be processing.\n *\n * Platform: Stripe\n * */\n 'INCOMPLETE',\n\n /**\n * The initial payment on the subscription failed and no successful payment was made within 23\n * hours of creating the subscription. These subscriptions don’t bill customers. This status\n * exists so you can track customers that failed to activate their subscriptions.\n *\n * Platform: Stripe\n * */\n 'INCOMPLETE_EXPIRED',\n\n /**\n * Subscription was created but awaiting payment during signup. In this state, all items are\n * awaiting payment.\n *\n * Platform: Google\n * */\n 'PENDING',\n\n /**\n * Pending transaction for subscription is canceled. If this pending purchase was for an\n * existing subscription, use linkedPurchaseToken to get the current state of that subscription.\n *\n * Platform: Google\n * */\n 'PENDING_PURCHASE_CANCELED',\n\n /**\n * Payment on the latest finalized invoice either failed or wasn’t attempted. The subscription\n * continues to create invoices. Your subscription settings determine the subscription’s next\n * state. If the invoice is still unpaid after all Smart Retries have been attempted, you can\n * configure the subscription to move to canceled, unpaid, or leave it as past_due. To move the\n * subscription to active, pay the most recent invoice before its due date.\n *\n * Platform: Stripe\n * */\n 'PAST_DUE',\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. Grace period ends or Active period\n * ends but not grace period\n *\n * Platform: Google\n * */\n 'ON_HOLD',\n\n /**\n * The subscription has been canceled. During cancellation, automatic collection for all unpaid\n * invoices is disabled (auto_advance=false). This is a terminal state that can’t be updated.\n *\n * Platform: Apple, Google, Stripe\n * */\n 'CANCELED',\n\n /**\n * The latest invoice hasn’t been paid but the subscription remains in place. The latest invoice\n * remains open and invoices continue to be generated but payments aren’t attempted. You should\n * revoke access to your product when the subscription is unpaid since payments were already\n * attempted and retried when it was past_due. To move the subscription to active, pay the most\n * recent invoice before its due date.\n *\n * Platform: Stripe\n * */\n 'UNPAID',\n\n /**\n * Google: Subscription is paused. The state is only available when the subscription is an auto\n * renewing plan. In this state, all items are in paused state.\n *\n * Stripe: The subscription has ended its trial period without a default payment method and the\n * trial_settings.end_behavior.missing_payment_method is set to pause. Invoices will no longer\n * be created for the subscription. After a default payment method has been attached to the\n * customer, you can resume the subscription.\n *\n * Platform: Google, Stripe\n * */\n 'PAUSED',\n\n /**\n * For example, a user buys a subscription and receives a purchase token A. The\n * linkedPurchaseToken field will not be set in the API response because the purchase token\n * belongs to a brand new subscription.\n *\n * If the user upgrades their subscription, a new purchase token B will be generated. Since the\n * upgrade is replacing the subscription from purchase token A, the linkedPurchaseToken field\n * for token B will be set to point to token A. Notice it points backwards in time to the\n * original purchase token.\n *\n * +---------------------------+ +------------------------+ +------------------------+\n * | Step 1 first purchase | | Step 2 upgrades | | Step 3 downgrades |\n * | purchaseToken: A |->| purchaseToken: B |->| purchaseToken: C |\n * | linkedPurchaseToken: null | | linkedPurchaseToken: A | | linkedPurchaseToken: B |\n * +---------------------------+ +------------------------+ +------------------------+\n *\n * Platform: Google\n * */\n 'REPLACED',\n\n /**\n * Google: Subscription is expired. All items have expiryTime in the past.\n *\n * Platform: Apple, Google\n * */\n 'EXPIRED',\n] as const;\n\nexport type SubscriptionStatus = (typeof SUBSCRIPTION_STATUSES)[number];\n\n/** statuses where it is safe to provision your product for the customer */\nexport const AVAILABLE_STATUSES = [\n 'ACTIVE',\n 'TRIALING',\n 'IN_GRACE_PERIOD',\n] as const satisfies readonly SubscriptionStatus[];\n"],"mappings":";AAAA,MAAa,YAAY;CAAC;CAAS;CAAU;AAAQ;;;;;;;AAUrD,MAAa,wBAAwB;CAUnC;CAQA;CAYA;CASA;CASA;CAQA;CAQA;CAWA;CASA;CAQA;CAWA;CAaA;CAoBA;CAOA;AACF;;AAKA,MAAa,qBAAqB;CAChC;CACA;CACA;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/purchase",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",