@shaxpir/duiduidui-models 1.34.0 → 1.35.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/models/Billing.d.ts +35 -0
- package/dist/models/Billing.js +26 -1
- package/package.json +1 -1
package/dist/models/Billing.d.ts
CHANGED
|
@@ -4,6 +4,31 @@ import { ShareSync } from '../repo';
|
|
|
4
4
|
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
5
5
|
export type SubscriptionStatus = 'active' | 'trialing' | 'grace_period' | 'expired' | 'inactive';
|
|
6
6
|
export type SubscriptionSource = 'app_store' | 'play_store' | 'stripe' | 'promo' | 'lifetime_free';
|
|
7
|
+
export type TransactionType = 'purchase' | 'renewal' | 'refund' | 'revocation' | 'cancellation' | 'grace_period' | 'expiration' | 'promo_grant' | 'admin_grant' | 'price_change';
|
|
8
|
+
export type TransactionSource = 'app_store' | 'play_store' | 'stripe' | 'promo' | 'admin';
|
|
9
|
+
export interface Transaction {
|
|
10
|
+
id: string;
|
|
11
|
+
source: TransactionSource;
|
|
12
|
+
type: TransactionType;
|
|
13
|
+
timestamp: CompactDateTime;
|
|
14
|
+
amount: number | null;
|
|
15
|
+
currency: string | null;
|
|
16
|
+
product_id: string | null;
|
|
17
|
+
app_store_transaction_id: string | null;
|
|
18
|
+
app_store_original_transaction_id: string | null;
|
|
19
|
+
play_store_order_id: string | null;
|
|
20
|
+
play_store_purchase_token: string | null;
|
|
21
|
+
stripe_invoice_id: string | null;
|
|
22
|
+
stripe_payment_intent_id: string | null;
|
|
23
|
+
note: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface FeatureGrant {
|
|
26
|
+
source: 'promo' | 'subscription' | 'admin';
|
|
27
|
+
granted_at: CompactDateTime;
|
|
28
|
+
expires_at: CompactDateTime | null;
|
|
29
|
+
code?: string;
|
|
30
|
+
note?: string;
|
|
31
|
+
}
|
|
7
32
|
export interface BillingPayload {
|
|
8
33
|
subscription_status: SubscriptionStatus;
|
|
9
34
|
subscription_source: SubscriptionSource | null;
|
|
@@ -16,6 +41,9 @@ export interface BillingPayload {
|
|
|
16
41
|
stripe_customer_id: string | null;
|
|
17
42
|
stripe_subscription_id: string | null;
|
|
18
43
|
grant_note: string | null;
|
|
44
|
+
feature_grants: Record<string, FeatureGrant>;
|
|
45
|
+
redeemed_codes: string[];
|
|
46
|
+
transactions: Transaction[];
|
|
19
47
|
}
|
|
20
48
|
export interface BillingBody extends ContentBody {
|
|
21
49
|
meta: ContentMeta;
|
|
@@ -30,7 +58,14 @@ export declare class Billing extends Content {
|
|
|
30
58
|
get subscriptionStatus(): SubscriptionStatus;
|
|
31
59
|
get subscriptionSource(): SubscriptionSource | null;
|
|
32
60
|
get expiresAt(): CompactDateTime | null;
|
|
61
|
+
get featureGrants(): Record<string, FeatureGrant>;
|
|
62
|
+
get redeemedCodes(): string[];
|
|
63
|
+
get transactions(): Transaction[];
|
|
33
64
|
isActive(): boolean;
|
|
34
65
|
isTrialing(): boolean;
|
|
35
66
|
isLifetimeFree(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Check whether the user has an active (non-expired) grant for the given feature flag.
|
|
69
|
+
*/
|
|
70
|
+
hasFeature(flag: string): boolean;
|
|
36
71
|
}
|
package/dist/models/Billing.js
CHANGED
|
@@ -21,7 +21,10 @@ class Billing extends Content_1.Content {
|
|
|
21
21
|
play_store_purchase_token: null,
|
|
22
22
|
stripe_customer_id: null,
|
|
23
23
|
stripe_subscription_id: null,
|
|
24
|
-
grant_note: null
|
|
24
|
+
grant_note: null,
|
|
25
|
+
feature_grants: {},
|
|
26
|
+
redeemed_codes: [],
|
|
27
|
+
transactions: []
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
static create(userId, payload, createdAt) {
|
|
@@ -57,6 +60,15 @@ class Billing extends Content_1.Content {
|
|
|
57
60
|
get expiresAt() {
|
|
58
61
|
return this.payload.expires_at;
|
|
59
62
|
}
|
|
63
|
+
get featureGrants() {
|
|
64
|
+
return this.payload.feature_grants ?? {};
|
|
65
|
+
}
|
|
66
|
+
get redeemedCodes() {
|
|
67
|
+
return this.payload.redeemed_codes ?? [];
|
|
68
|
+
}
|
|
69
|
+
get transactions() {
|
|
70
|
+
return this.payload.transactions ?? [];
|
|
71
|
+
}
|
|
60
72
|
isActive() {
|
|
61
73
|
const status = this.subscriptionStatus;
|
|
62
74
|
return status === 'active' || status === 'trialing' || status === 'grace_period';
|
|
@@ -67,5 +79,18 @@ class Billing extends Content_1.Content {
|
|
|
67
79
|
isLifetimeFree() {
|
|
68
80
|
return this.subscriptionSource === 'lifetime_free';
|
|
69
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Check whether the user has an active (non-expired) grant for the given feature flag.
|
|
84
|
+
*/
|
|
85
|
+
hasFeature(flag) {
|
|
86
|
+
const grant = this.featureGrants[flag];
|
|
87
|
+
if (!grant)
|
|
88
|
+
return false;
|
|
89
|
+
const expiresAt = grant.expires_at;
|
|
90
|
+
if (!expiresAt)
|
|
91
|
+
return true;
|
|
92
|
+
const now = shaxpir_common_1.ClockService.getClock().utc();
|
|
93
|
+
return shaxpir_common_1.Time.isDateTimeAfter(expiresAt, now);
|
|
94
|
+
}
|
|
70
95
|
}
|
|
71
96
|
exports.Billing = Billing;
|