@shware/purchase 1.8.8 → 1.9.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.
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/app-store/config.cjs +98 -128
- package/dist/app-store/config.cjs.map +1 -1
- package/dist/app-store/config.d.cts +31 -31
- package/dist/app-store/config.d.cts.map +1 -0
- package/dist/app-store/config.d.mts +39 -0
- package/dist/app-store/config.d.mts.map +1 -0
- package/dist/app-store/config.mjs +93 -91
- package/dist/app-store/config.mjs.map +1 -1
- package/dist/app-store/index.cjs +3 -31
- package/dist/app-store/index.d.cts +2 -3
- package/dist/app-store/index.d.mts +2 -0
- package/dist/app-store/index.mjs +1 -5
- package/dist/google-play/config.cjs +100 -123
- package/dist/google-play/config.cjs.map +1 -1
- package/dist/google-play/config.d.cts +31 -31
- package/dist/google-play/config.d.cts.map +1 -0
- package/dist/google-play/config.d.mts +39 -0
- package/dist/google-play/config.d.mts.map +1 -0
- package/dist/google-play/config.mjs +95 -86
- package/dist/google-play/config.mjs.map +1 -1
- package/dist/google-play/index.cjs +9 -42
- package/dist/google-play/index.d.cts +3 -4
- package/dist/google-play/index.d.mts +3 -0
- package/dist/google-play/index.mjs +2 -17
- package/dist/google-play/real-time-developer-notification.cjs +122 -81
- package/dist/google-play/real-time-developer-notification.cjs.map +1 -1
- package/dist/google-play/real-time-developer-notification.d.cts +119 -117
- package/dist/google-play/real-time-developer-notification.d.cts.map +1 -0
- package/dist/google-play/real-time-developer-notification.d.mts +150 -0
- package/dist/google-play/real-time-developer-notification.d.mts.map +1 -0
- package/dist/google-play/real-time-developer-notification.mjs +118 -53
- package/dist/google-play/real-time-developer-notification.mjs.map +1 -1
- package/dist/index.cjs +13 -48
- package/dist/index.d.cts +5 -6
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +2 -19
- package/dist/stripe/config.cjs +104 -133
- package/dist/stripe/config.cjs.map +1 -1
- package/dist/stripe/config.d.cts +35 -35
- package/dist/stripe/config.d.cts.map +1 -0
- package/dist/stripe/config.d.mts +43 -0
- package/dist/stripe/config.d.mts.map +1 -0
- package/dist/stripe/config.mjs +99 -96
- package/dist/stripe/config.mjs.map +1 -1
- package/dist/stripe/handler.cjs +25 -53
- package/dist/stripe/handler.cjs.map +1 -1
- package/dist/stripe/handler.d.cts +10 -9
- package/dist/stripe/handler.d.cts.map +1 -0
- package/dist/stripe/handler.d.mts +16 -0
- package/dist/stripe/handler.d.mts.map +1 -0
- package/dist/stripe/handler.mjs +25 -29
- package/dist/stripe/handler.mjs.map +1 -1
- package/dist/stripe/index.cjs +27 -74
- package/dist/stripe/index.d.cts +8 -12
- package/dist/stripe/index.d.mts +8 -0
- package/dist/stripe/index.mjs +5 -44
- package/dist/stripe/mapper.cjs +168 -218
- package/dist/stripe/mapper.cjs.map +1 -1
- package/dist/stripe/mapper.d.cts +115 -114
- package/dist/stripe/mapper.d.cts.map +1 -0
- package/dist/stripe/mapper.d.mts +158 -0
- package/dist/stripe/mapper.d.mts.map +1 -0
- package/dist/stripe/mapper.mjs +155 -181
- package/dist/stripe/mapper.mjs.map +1 -1
- package/dist/stripe/metadata.cjs +11 -35
- package/dist/stripe/metadata.cjs.map +1 -1
- package/dist/stripe/metadata.d.cts +9 -7
- package/dist/stripe/metadata.d.cts.map +1 -0
- package/dist/stripe/metadata.d.mts +12 -0
- package/dist/stripe/metadata.d.mts.map +1 -0
- package/dist/stripe/metadata.mjs +11 -11
- package/dist/stripe/metadata.mjs.map +1 -1
- package/dist/stripe/pending-checkout.cjs +55 -61
- package/dist/stripe/pending-checkout.cjs.map +1 -1
- package/dist/stripe/pending-checkout.d.cts +3 -1
- package/dist/stripe/pending-checkout.d.cts.map +1 -0
- package/dist/stripe/{pending-checkout.d.ts → pending-checkout.d.mts} +3 -1
- package/dist/stripe/pending-checkout.d.mts.map +1 -0
- package/dist/stripe/pending-checkout.mjs +52 -34
- package/dist/stripe/pending-checkout.mjs.map +1 -1
- package/dist/stripe/schema.cjs +30 -55
- package/dist/stripe/schema.cjs.map +1 -1
- package/dist/stripe/schema.d.cts +36 -37
- package/dist/stripe/schema.d.cts.map +1 -0
- package/dist/stripe/schema.d.mts +40 -0
- package/dist/stripe/schema.d.mts.map +1 -0
- package/dist/stripe/schema.mjs +28 -40
- package/dist/stripe/schema.mjs.map +1 -1
- package/dist/subscription/index.cjs +178 -80
- package/dist/subscription/index.cjs.map +1 -1
- package/dist/subscription/index.d.cts +136 -134
- package/dist/subscription/index.d.cts.map +1 -0
- package/dist/subscription/index.d.mts +150 -0
- package/dist/subscription/index.d.mts.map +1 -0
- package/dist/subscription/index.mjs +173 -51
- package/dist/subscription/index.mjs.map +1 -1
- package/dist/types.cjs +0 -19
- package/dist/types.d.cts +7 -6
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +10 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -1
- package/package.json +41 -26
- package/dist/app-store/config.d.ts +0 -39
- package/dist/app-store/index.cjs.map +0 -1
- package/dist/app-store/index.d.ts +0 -3
- package/dist/app-store/index.mjs.map +0 -1
- package/dist/google-play/config.d.ts +0 -39
- package/dist/google-play/index.cjs.map +0 -1
- package/dist/google-play/index.d.ts +0 -4
- package/dist/google-play/index.mjs.map +0 -1
- package/dist/google-play/real-time-developer-notification.d.ts +0 -148
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.mjs.map +0 -1
- package/dist/stripe/config.d.ts +0 -43
- package/dist/stripe/handler.d.ts +0 -15
- package/dist/stripe/index.cjs.map +0 -1
- package/dist/stripe/index.d.ts +0 -12
- package/dist/stripe/index.mjs.map +0 -1
- package/dist/stripe/mapper.d.ts +0 -157
- package/dist/stripe/metadata.d.ts +0 -10
- package/dist/stripe/schema.d.ts +0 -41
- package/dist/subscription/index.d.ts +0 -148
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.ts +0 -9
- package/dist/types.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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":"
|
|
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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,48 +1,13 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
ALL_PLATFORMS: () => import_subscription.ALL_PLATFORMS,
|
|
24
|
-
ALL_SUBSCRIPTION_STATUS: () => import_subscription.ALL_SUBSCRIPTION_STATUS,
|
|
25
|
-
AVAILABLE_STATUS: () => import_subscription.AVAILABLE_STATUS,
|
|
26
|
-
AppStoreConfig: () => import_config.AppStoreConfig,
|
|
27
|
-
GooglePlayConfig: () => import_config2.GooglePlayConfig,
|
|
28
|
-
Platform: () => import_subscription.Platform,
|
|
29
|
-
StripeConfig: () => import_config3.StripeConfig,
|
|
30
|
-
SubscriptionStatus: () => import_subscription.SubscriptionStatus
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(index_exports);
|
|
33
|
-
var import_subscription = require("./subscription/index.cjs");
|
|
34
|
-
var import_config = require("./app-store/config.cjs");
|
|
35
|
-
var import_config2 = require("./google-play/config.cjs");
|
|
36
|
-
var import_config3 = require("./stripe/config.cjs");
|
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
-
0 && (module.exports = {
|
|
39
|
-
ALL_PLATFORMS,
|
|
40
|
-
ALL_SUBSCRIPTION_STATUS,
|
|
41
|
-
AVAILABLE_STATUS,
|
|
42
|
-
AppStoreConfig,
|
|
43
|
-
GooglePlayConfig,
|
|
44
|
-
Platform,
|
|
45
|
-
StripeConfig,
|
|
46
|
-
SubscriptionStatus
|
|
47
|
-
});
|
|
48
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_subscription_index = require("./subscription/index.cjs");
|
|
3
|
+
const require_app_store_config = require("./app-store/config.cjs");
|
|
4
|
+
const require_google_play_config = require("./google-play/config.cjs");
|
|
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;
|
|
9
|
+
exports.AppStoreConfig = require_app_store_config.AppStoreConfig;
|
|
10
|
+
exports.GooglePlayConfig = require_google_play_config.GooglePlayConfig;
|
|
11
|
+
exports.Platform = require_subscription_index.Platform;
|
|
12
|
+
exports.StripeConfig = require_stripe_config.StripeConfig;
|
|
13
|
+
exports.SubscriptionStatus = require_subscription_index.SubscriptionStatus;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import 'ms';
|
|
1
|
+
import { AppStoreConfig } from "./app-store/config.cjs";
|
|
2
|
+
import { GooglePlayConfig } from "./google-play/config.cjs";
|
|
3
|
+
import { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from "./subscription/index.cjs";
|
|
4
|
+
import { StripeConfig } from "./stripe/config.cjs";
|
|
5
|
+
export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, AppStoreConfig, GooglePlayConfig, Platform, StripeConfig, SubscriptionStatus };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AppStoreConfig } from "./app-store/config.mjs";
|
|
2
|
+
import { GooglePlayConfig } from "./google-play/config.mjs";
|
|
3
|
+
import { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from "./subscription/index.mjs";
|
|
4
|
+
import { StripeConfig } from "./stripe/config.mjs";
|
|
5
|
+
export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, AppStoreConfig, GooglePlayConfig, Platform, StripeConfig, SubscriptionStatus };
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
Platform,
|
|
4
|
-
SubscriptionStatus,
|
|
5
|
-
ALL_PLATFORMS,
|
|
6
|
-
AVAILABLE_STATUS,
|
|
7
|
-
ALL_SUBSCRIPTION_STATUS
|
|
8
|
-
} from "./subscription/index.mjs";
|
|
1
|
+
import { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from "./subscription/index.mjs";
|
|
9
2
|
import { AppStoreConfig } from "./app-store/config.mjs";
|
|
10
3
|
import { GooglePlayConfig } from "./google-play/config.mjs";
|
|
11
4
|
import { StripeConfig } from "./stripe/config.mjs";
|
|
12
|
-
export {
|
|
13
|
-
ALL_PLATFORMS,
|
|
14
|
-
ALL_SUBSCRIPTION_STATUS,
|
|
15
|
-
AVAILABLE_STATUS,
|
|
16
|
-
AppStoreConfig,
|
|
17
|
-
GooglePlayConfig,
|
|
18
|
-
Platform,
|
|
19
|
-
StripeConfig,
|
|
20
|
-
SubscriptionStatus
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=index.mjs.map
|
|
5
|
+
export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, AppStoreConfig, GooglePlayConfig, Platform, StripeConfig, SubscriptionStatus };
|
package/dist/stripe/config.cjs
CHANGED
|
@@ -1,137 +1,108 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/stripe/config.ts
|
|
31
|
-
var config_exports = {};
|
|
32
|
-
__export(config_exports, {
|
|
33
|
-
StripeConfig: () => StripeConfig
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(config_exports);
|
|
36
|
-
var import_utils = require("@shware/utils");
|
|
37
|
-
var import_ms = __toESM(require("ms"), 1);
|
|
38
|
-
var addMethod = /* @__PURE__ */ Symbol("addMethod");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
let _shware_utils = require("@shware/utils");
|
|
4
|
+
let ms = require("ms");
|
|
5
|
+
ms = require_runtime.__toESM(ms, 1);
|
|
6
|
+
//#region src/stripe/config.ts
|
|
7
|
+
const addMethod = Symbol("addMethod");
|
|
39
8
|
var Product = class {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
9
|
+
id;
|
|
10
|
+
config;
|
|
11
|
+
plan;
|
|
12
|
+
prices;
|
|
13
|
+
defaultPriceId;
|
|
14
|
+
constructor(config, id, plan = null) {
|
|
15
|
+
this.id = id;
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.plan = plan;
|
|
18
|
+
this.prices = /* @__PURE__ */ new Map();
|
|
19
|
+
this.defaultPriceId = null;
|
|
20
|
+
}
|
|
21
|
+
price = (priceId, metadata = {
|
|
22
|
+
credits: 0,
|
|
23
|
+
expiresIn: "0"
|
|
24
|
+
}) => {
|
|
25
|
+
this.prices.set(priceId, metadata);
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
default = (defaultPriceId) => {
|
|
29
|
+
this.defaultPriceId = defaultPriceId;
|
|
30
|
+
this.config[addMethod](this);
|
|
31
|
+
return this.config;
|
|
32
|
+
};
|
|
61
33
|
};
|
|
62
|
-
var StripeConfig = class
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
34
|
+
var StripeConfig = class StripeConfig {
|
|
35
|
+
products = /* @__PURE__ */ new Map();
|
|
36
|
+
returnUrl;
|
|
37
|
+
cancelUrl;
|
|
38
|
+
successUrl;
|
|
39
|
+
cancellationCouponId;
|
|
40
|
+
allowPromotionCodes;
|
|
41
|
+
get productIds() {
|
|
42
|
+
return Array.from(this.products.keys());
|
|
43
|
+
}
|
|
44
|
+
[addMethod] = (product) => {
|
|
45
|
+
this.products.set(product.id, product);
|
|
46
|
+
return this;
|
|
47
|
+
};
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.returnUrl = options.returnUrl;
|
|
50
|
+
this.cancelUrl = options.cancelUrl;
|
|
51
|
+
this.successUrl = options.successUrl;
|
|
52
|
+
this.cancellationCouponId = options.cancellationCouponId;
|
|
53
|
+
this.allowPromotionCodes = options.allowPromotionCodes;
|
|
54
|
+
}
|
|
55
|
+
static create = (options) => {
|
|
56
|
+
return new StripeConfig(options);
|
|
57
|
+
};
|
|
58
|
+
product = (productId, plan = null) => {
|
|
59
|
+
return new Product(this, productId, plan);
|
|
60
|
+
};
|
|
61
|
+
getPlan = (productId) => {
|
|
62
|
+
const product = this.products.get(productId);
|
|
63
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
64
|
+
(0, _shware_utils.invariant)(product.plan, `Product ${productId} is not a subscription`);
|
|
65
|
+
return product.plan;
|
|
66
|
+
};
|
|
67
|
+
getMode = (productId) => {
|
|
68
|
+
const product = this.products.get(productId);
|
|
69
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
70
|
+
return product.plan === null ? "payment" : "subscription";
|
|
71
|
+
};
|
|
72
|
+
getPriceId = (productId) => {
|
|
73
|
+
const product = this.products.get(productId);
|
|
74
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
75
|
+
(0, _shware_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
|
|
76
|
+
return product.defaultPriceId;
|
|
77
|
+
};
|
|
78
|
+
getCreditAmount = (productId, priceId) => {
|
|
79
|
+
const product = this.products.get(productId);
|
|
80
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
81
|
+
if (priceId) {
|
|
82
|
+
const price = product.prices.get(priceId);
|
|
83
|
+
(0, _shware_utils.invariant)(price, `Price not found for ${priceId}`);
|
|
84
|
+
return price.credits;
|
|
85
|
+
}
|
|
86
|
+
(0, _shware_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
|
|
87
|
+
return product.prices.get(product.defaultPriceId)?.credits ?? 0;
|
|
88
|
+
};
|
|
89
|
+
getCreditExpiresIn = (productId, priceId) => {
|
|
90
|
+
const product = this.products.get(productId);
|
|
91
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
92
|
+
if (priceId) {
|
|
93
|
+
const price = product.prices.get(priceId);
|
|
94
|
+
(0, _shware_utils.invariant)(price, `Price not found for ${priceId}`);
|
|
95
|
+
return (0, ms.default)(price.expiresIn);
|
|
96
|
+
}
|
|
97
|
+
(0, _shware_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
|
|
98
|
+
return (0, ms.default)(product.prices.get(product.defaultPriceId)?.expiresIn ?? "0");
|
|
99
|
+
};
|
|
100
|
+
getCreditExpiresAt = (productId, priceId) => {
|
|
101
|
+
const expiresIn = this.getCreditExpiresIn(productId, priceId);
|
|
102
|
+
return new Date(Date.now() + expiresIn).toISOString();
|
|
103
|
+
};
|
|
132
104
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
105
|
+
//#endregion
|
|
106
|
+
exports.StripeConfig = StripeConfig;
|
|
107
|
+
|
|
137
108
|
//# sourceMappingURL=config.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { Metadata } from '../types';\n\nexport type PriceId = `price_${string}`;\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n I extends PriceId = never,\n> {\n readonly id: string;\n readonly config: StripeConfig<NS, PE, PI>;\n readonly plan: PE | null;\n readonly prices: Map<PriceId, Metadata>;\n\n defaultPriceId: I | null;\n\n constructor(config: StripeConfig<NS, PE, PI>, id: string, plan: PE | null = null) {\n this.id = id;\n this.config = config;\n this.plan = plan;\n this.prices = new Map();\n this.defaultPriceId = null;\n }\n\n price = <K extends PriceId>(\n priceId: K extends I ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Product<NS, PE, PI, I | K> => {\n this.prices.set(priceId, metadata);\n return this as Product<NS, PE, PI, I | K>;\n };\n\n default = (defaultPriceId: I) => {\n this.defaultPriceId = defaultPriceId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n cancellationCouponId: string;\n allowPromotionCodes: boolean;\n};\n\nexport class StripeConfig<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n> {\n private products: Map<string, Product<NS, PE, PI>> = new Map();\n\n public returnUrl: string;\n public cancelUrl: string;\n public successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n public cancellationCouponId: string;\n public allowPromotionCodes: boolean;\n\n get productIds(): string[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (product: Product<NS, PE, PI>) => {\n this.products.set(product.id, product);\n return this;\n };\n\n private constructor(options: Options) {\n this.returnUrl = options.returnUrl;\n this.cancelUrl = options.cancelUrl;\n this.successUrl = options.successUrl;\n this.cancellationCouponId = options.cancellationCouponId;\n this.allowPromotionCodes = options.allowPromotionCodes;\n }\n\n static create = <NS extends Lowercase<string>, PE extends string>(options: Options) => {\n return new StripeConfig<NS, PE>(options);\n };\n\n product = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n plan: PE | null = null\n ) => {\n return new Product<NS, PE, K | PI>(this, productId, plan);\n };\n\n getPlan = (productId: string): PE => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.plan, `Product ${productId} is not a subscription`);\n return product.plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n return product.plan === null ? 'payment' : 'subscription';\n };\n\n getPriceId = (productId: string): PriceId => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.defaultPriceId;\n };\n\n getCreditAmount = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return price.credits;\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.prices.get(product.defaultPriceId)?.credits ?? 0;\n };\n\n private getCreditExpiresIn = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return ms(price.expiresIn);\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? '0');\n };\n\n getCreditExpiresAt = (productId: string, priceId?: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, priceId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.cjs","names":[],"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { Metadata } from '../types';\n\nexport type PriceId = `price_${string}`;\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n I extends PriceId = never,\n> {\n readonly id: string;\n readonly config: StripeConfig<NS, PE, PI>;\n readonly plan: PE | null;\n readonly prices: Map<PriceId, Metadata>;\n\n defaultPriceId: I | null;\n\n constructor(config: StripeConfig<NS, PE, PI>, id: string, plan: PE | null = null) {\n this.id = id;\n this.config = config;\n this.plan = plan;\n this.prices = new Map();\n this.defaultPriceId = null;\n }\n\n price = <K extends PriceId>(\n priceId: K extends I ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Product<NS, PE, PI, I | K> => {\n this.prices.set(priceId, metadata);\n return this as Product<NS, PE, PI, I | K>;\n };\n\n default = (defaultPriceId: I) => {\n this.defaultPriceId = defaultPriceId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n cancellationCouponId: string;\n allowPromotionCodes: boolean;\n};\n\nexport class StripeConfig<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n> {\n private products: Map<string, Product<NS, PE, PI>> = new Map();\n\n public returnUrl: string;\n public cancelUrl: string;\n public successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n public cancellationCouponId: string;\n public allowPromotionCodes: boolean;\n\n get productIds(): string[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (product: Product<NS, PE, PI>) => {\n this.products.set(product.id, product);\n return this;\n };\n\n private constructor(options: Options) {\n this.returnUrl = options.returnUrl;\n this.cancelUrl = options.cancelUrl;\n this.successUrl = options.successUrl;\n this.cancellationCouponId = options.cancellationCouponId;\n this.allowPromotionCodes = options.allowPromotionCodes;\n }\n\n static create = <NS extends Lowercase<string>, PE extends string>(options: Options) => {\n return new StripeConfig<NS, PE>(options);\n };\n\n product = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n plan: PE | null = null\n ) => {\n return new Product<NS, PE, K | PI>(this, productId, plan);\n };\n\n getPlan = (productId: string): PE => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.plan, `Product ${productId} is not a subscription`);\n return product.plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n return product.plan === null ? 'payment' : 'subscription';\n };\n\n getPriceId = (productId: string): PriceId => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.defaultPriceId;\n };\n\n getCreditAmount = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return price.credits;\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.prices.get(product.defaultPriceId)?.credits ?? 0;\n };\n\n private getCreditExpiresIn = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return ms(price.expiresIn);\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? '0');\n };\n\n getCreditExpiresAt = (productId: string, priceId?: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, priceId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":"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"}
|
package/dist/stripe/config.d.cts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { Metadata } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Metadata } from "../types.cjs";
|
|
2
|
+
//#region src/stripe/config.d.ts
|
|
4
3
|
type PriceId = `price_${string}`;
|
|
5
4
|
declare const addMethod: unique symbol;
|
|
6
5
|
declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends PriceId = never> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly config: StripeConfig<NS, PE, PI>;
|
|
8
|
+
readonly plan: PE | null;
|
|
9
|
+
readonly prices: Map<PriceId, Metadata>;
|
|
10
|
+
defaultPriceId: I | null;
|
|
11
|
+
constructor(config: StripeConfig<NS, PE, PI>, id: string, plan?: PE | null);
|
|
12
|
+
price: <K extends PriceId>(priceId: K extends I ? never : K, metadata?: Metadata) => Product<NS, PE, PI, I | K>;
|
|
13
|
+
default: (defaultPriceId: I) => StripeConfig<NS, PE, PI>;
|
|
15
14
|
}
|
|
16
15
|
type Options = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
returnUrl: string;
|
|
17
|
+
cancelUrl: string;
|
|
18
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
19
|
+
cancellationCouponId: string;
|
|
20
|
+
allowPromotionCodes: boolean;
|
|
22
21
|
};
|
|
23
22
|
declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
private products;
|
|
24
|
+
returnUrl: string;
|
|
25
|
+
cancelUrl: string;
|
|
26
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
27
|
+
cancellationCouponId: string;
|
|
28
|
+
allowPromotionCodes: boolean;
|
|
29
|
+
get productIds(): string[];
|
|
30
|
+
[addMethod]: (product: Product<NS, PE, PI>) => this;
|
|
31
|
+
private constructor();
|
|
32
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => StripeConfig<NS_1, PE_1, never>;
|
|
33
|
+
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, plan?: PE | null) => Product<NS, PE, K | PI, never>;
|
|
34
|
+
getPlan: (productId: string) => PE;
|
|
35
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
36
|
+
getPriceId: (productId: string) => PriceId;
|
|
37
|
+
getCreditAmount: (productId: string, priceId?: string) => number;
|
|
38
|
+
private getCreditExpiresIn;
|
|
39
|
+
getCreditExpiresAt: (productId: string, priceId?: string) => string;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
export {
|
|
41
|
+
//#endregion
|
|
42
|
+
export { PriceId, StripeConfig };
|
|
43
|
+
//# sourceMappingURL=config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.cts","names":[],"sources":["../../src/stripe/config.ts"],"mappings":";;KAIY;cAEN;cAEA,QACJ,WAAW,oBAAoB,mBAC/B,4BACA,2BACA,UAAU;WAED;WACA,QAAQ,aAAa,IAAI,IAAI;WAC7B,MAAM;WACN,QAAQ,IAAI,SAAS;EAE9B,gBAAgB;EAEhB,YAAY,QAAQ,aAAa,IAAI,IAAI,KAAK,YAAY,OAAM;EAQhE,QAAS,UAAU,SAAO,SACf,UAAU,YAAY,GAAC,WACtB,aACT,QAAQ,IAAI,IAAI,IAAI,IAAI;EAK3B,UAAO,gBAAoB,MAAC,aAAA,IAAA,IAAA;;KAOzB;EACH;EACA;EACA;EACA;EACA;;cAGW,aACX,WAAW,oBAAoB,mBAC/B,4BACA;UAEQ;EAED;EACA;EACA;EACA;EACA;MAEH;GAIH,aAAU,SAAa,QAAQ,IAAI,IAAI;UAKjC;SAQA,SAAU,aAAW,mBAAmB,qBAAiB,SAAW,YAAO,aAAA,MAAA;EAIlF,UAAW,aAAa,MAAM,qBAAmB,WACpC,UAAU,aAAa,GAAC,OAC7B,cAAS,QAAA,IAAA,IAAA,IAAA;EAKjB,UAAO,sBAAwB;EAO/B,UAAO;EAMP,aAAU,sBAAwB;EAOlC,kBAAe,mBAAqB;UAa5B;EAaR,qBAAkB,mBAAqB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Metadata } from "../types.mjs";
|
|
2
|
+
//#region src/stripe/config.d.ts
|
|
3
|
+
type PriceId = `price_${string}`;
|
|
4
|
+
declare const addMethod: unique symbol;
|
|
5
|
+
declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends PriceId = never> {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly config: StripeConfig<NS, PE, PI>;
|
|
8
|
+
readonly plan: PE | null;
|
|
9
|
+
readonly prices: Map<PriceId, Metadata>;
|
|
10
|
+
defaultPriceId: I | null;
|
|
11
|
+
constructor(config: StripeConfig<NS, PE, PI>, id: string, plan?: PE | null);
|
|
12
|
+
price: <K extends PriceId>(priceId: K extends I ? never : K, metadata?: Metadata) => Product<NS, PE, PI, I | K>;
|
|
13
|
+
default: (defaultPriceId: I) => StripeConfig<NS, PE, PI>;
|
|
14
|
+
}
|
|
15
|
+
type Options = {
|
|
16
|
+
returnUrl: string;
|
|
17
|
+
cancelUrl: string;
|
|
18
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
19
|
+
cancellationCouponId: string;
|
|
20
|
+
allowPromotionCodes: boolean;
|
|
21
|
+
};
|
|
22
|
+
declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
|
|
23
|
+
private products;
|
|
24
|
+
returnUrl: string;
|
|
25
|
+
cancelUrl: string;
|
|
26
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
27
|
+
cancellationCouponId: string;
|
|
28
|
+
allowPromotionCodes: boolean;
|
|
29
|
+
get productIds(): string[];
|
|
30
|
+
[addMethod]: (product: Product<NS, PE, PI>) => this;
|
|
31
|
+
private constructor();
|
|
32
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => StripeConfig<NS_1, PE_1, never>;
|
|
33
|
+
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, plan?: PE | null) => Product<NS, PE, K | PI, never>;
|
|
34
|
+
getPlan: (productId: string) => PE;
|
|
35
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
36
|
+
getPriceId: (productId: string) => PriceId;
|
|
37
|
+
getCreditAmount: (productId: string, priceId?: string) => number;
|
|
38
|
+
private getCreditExpiresIn;
|
|
39
|
+
getCreditExpiresAt: (productId: string, priceId?: string) => string;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { PriceId, StripeConfig };
|
|
43
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../../src/stripe/config.ts"],"mappings":";;KAIY;cAEN;cAEA,QACJ,WAAW,oBAAoB,mBAC/B,4BACA,2BACA,UAAU;WAED;WACA,QAAQ,aAAa,IAAI,IAAI;WAC7B,MAAM;WACN,QAAQ,IAAI,SAAS;EAE9B,gBAAgB;EAEhB,YAAY,QAAQ,aAAa,IAAI,IAAI,KAAK,YAAY,OAAM;EAQhE,QAAS,UAAU,SAAO,SACf,UAAU,YAAY,GAAC,WACtB,aACT,QAAQ,IAAI,IAAI,IAAI,IAAI;EAK3B,UAAO,gBAAoB,MAAC,aAAA,IAAA,IAAA;;KAOzB;EACH;EACA;EACA;EACA;EACA;;cAGW,aACX,WAAW,oBAAoB,mBAC/B,4BACA;UAEQ;EAED;EACA;EACA;EACA;EACA;MAEH;GAIH,aAAU,SAAa,QAAQ,IAAI,IAAI;UAKjC;SAQA,SAAU,aAAW,mBAAmB,qBAAiB,SAAW,YAAO,aAAA,MAAA;EAIlF,UAAW,aAAa,MAAM,qBAAmB,WACpC,UAAU,aAAa,GAAC,OAC7B,cAAS,QAAA,IAAA,IAAA,IAAA;EAKjB,UAAO,sBAAwB;EAO/B,UAAO;EAMP,aAAU,sBAAwB;EAOlC,kBAAe,mBAAqB;UAa5B;EAaR,qBAAkB,mBAAqB"}
|