@shaxpir/duiduidui-models 1.12.0 → 1.13.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 +20 -3
- package/dist/models/Billing.js +33 -1
- package/dist/models/Term.d.ts +1 -1
- package/dist/models/Term.js +6 -5
- package/package.json +1 -1
package/dist/models/Billing.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
2
|
-
import { MultiTime } from '@shaxpir/shaxpir-common';
|
|
2
|
+
import { CompactDateTime, MultiTime } from '@shaxpir/shaxpir-common';
|
|
3
3
|
import { ShareSync } from '../repo';
|
|
4
4
|
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
5
|
+
export type SubscriptionStatus = 'active' | 'trialing' | 'grace_period' | 'expired' | 'inactive';
|
|
6
|
+
export type SubscriptionSource = 'app_store' | 'stripe' | 'promo' | 'lifetime_free';
|
|
5
7
|
export interface BillingPayload {
|
|
6
|
-
|
|
8
|
+
subscription_status: SubscriptionStatus;
|
|
9
|
+
subscription_source: SubscriptionSource | null;
|
|
10
|
+
expires_at: CompactDateTime | null;
|
|
11
|
+
renewed_at: CompactDateTime | null;
|
|
12
|
+
app_store_product_id: string | null;
|
|
13
|
+
app_store_original_transaction_id: string | null;
|
|
14
|
+
stripe_customer_id: string | null;
|
|
15
|
+
stripe_subscription_id: string | null;
|
|
16
|
+
grant_note: string | null;
|
|
7
17
|
}
|
|
8
18
|
export interface BillingBody extends ContentBody {
|
|
9
19
|
meta: ContentMeta;
|
|
@@ -11,7 +21,14 @@ export interface BillingBody extends ContentBody {
|
|
|
11
21
|
}
|
|
12
22
|
export declare class Billing extends Content {
|
|
13
23
|
static makeBillingId(userId: ContentId): ContentId;
|
|
14
|
-
static
|
|
24
|
+
static createDefaultPayload(): BillingPayload;
|
|
25
|
+
static create(userId: ContentId, payload?: BillingPayload, createdAt?: MultiTime): Billing;
|
|
15
26
|
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
16
27
|
get payload(): BillingPayload;
|
|
28
|
+
get subscriptionStatus(): SubscriptionStatus;
|
|
29
|
+
get subscriptionSource(): SubscriptionSource | null;
|
|
30
|
+
get expiresAt(): CompactDateTime | null;
|
|
31
|
+
isActive(): boolean;
|
|
32
|
+
isTrialing(): boolean;
|
|
33
|
+
isLifetimeFree(): boolean;
|
|
17
34
|
}
|
package/dist/models/Billing.js
CHANGED
|
@@ -9,10 +9,23 @@ class Billing extends Content_1.Content {
|
|
|
9
9
|
static makeBillingId(userId) {
|
|
10
10
|
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.BILLING);
|
|
11
11
|
}
|
|
12
|
+
static createDefaultPayload() {
|
|
13
|
+
return {
|
|
14
|
+
subscription_status: 'inactive',
|
|
15
|
+
subscription_source: null,
|
|
16
|
+
expires_at: null,
|
|
17
|
+
renewed_at: null,
|
|
18
|
+
app_store_product_id: null,
|
|
19
|
+
app_store_original_transaction_id: null,
|
|
20
|
+
stripe_customer_id: null,
|
|
21
|
+
stripe_subscription_id: null,
|
|
22
|
+
grant_note: null
|
|
23
|
+
};
|
|
24
|
+
}
|
|
12
25
|
static create(userId, payload, createdAt) {
|
|
13
26
|
const now = shaxpir_common_1.ClockService.getClock().now();
|
|
14
|
-
// If the createdAt time is not provided, use the current time
|
|
15
27
|
createdAt ??= now;
|
|
28
|
+
payload ??= Billing.createDefaultPayload();
|
|
16
29
|
const billingId = Billing.makeBillingId(userId);
|
|
17
30
|
return repo_1.ShareSyncFactory.get().createContent({
|
|
18
31
|
meta: {
|
|
@@ -33,5 +46,24 @@ class Billing extends Content_1.Content {
|
|
|
33
46
|
this.checkDisposed("Billing.payload");
|
|
34
47
|
return this.doc.data.payload;
|
|
35
48
|
}
|
|
49
|
+
get subscriptionStatus() {
|
|
50
|
+
return this.payload.subscription_status;
|
|
51
|
+
}
|
|
52
|
+
get subscriptionSource() {
|
|
53
|
+
return this.payload.subscription_source;
|
|
54
|
+
}
|
|
55
|
+
get expiresAt() {
|
|
56
|
+
return this.payload.expires_at;
|
|
57
|
+
}
|
|
58
|
+
isActive() {
|
|
59
|
+
const status = this.subscriptionStatus;
|
|
60
|
+
return status === 'active' || status === 'trialing' || status === 'grace_period';
|
|
61
|
+
}
|
|
62
|
+
isTrialing() {
|
|
63
|
+
return this.subscriptionStatus === 'trialing';
|
|
64
|
+
}
|
|
65
|
+
isLifetimeFree() {
|
|
66
|
+
return this.subscriptionSource === 'lifetime_free';
|
|
67
|
+
}
|
|
36
68
|
}
|
|
37
69
|
exports.Billing = Billing;
|
package/dist/models/Term.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export interface TermBody extends ContentBody {
|
|
|
55
55
|
payload: TermPayload;
|
|
56
56
|
}
|
|
57
57
|
export declare class Term extends Content {
|
|
58
|
-
static makeTermId(userId: ContentId, text: string, senseRank: number): ContentId;
|
|
58
|
+
static makeTermId(userId: ContentId, type: RecordType, text: string, senseRank: number): ContentId;
|
|
59
59
|
private _reviewsView;
|
|
60
60
|
private _impliedReviewsView;
|
|
61
61
|
private _userTagsView;
|
package/dist/models/Term.js
CHANGED
|
@@ -10,8 +10,8 @@ const ContentKind_1 = require("./ContentKind");
|
|
|
10
10
|
const Operation_1 = require("./Operation");
|
|
11
11
|
const RecordType_1 = require("./RecordType");
|
|
12
12
|
class Term extends Content_1.Content {
|
|
13
|
-
static makeTermId(userId, text, senseRank) {
|
|
14
|
-
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(`${ContentKind_1.ContentKind.TERM}-${userId}-${text}-${senseRank}`);
|
|
13
|
+
static makeTermId(userId, type, text, senseRank) {
|
|
14
|
+
return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(`${ContentKind_1.ContentKind.TERM}-${userId}-${type}-${text}-${senseRank}`);
|
|
15
15
|
}
|
|
16
16
|
constructor(doc, shouldAcquire, shareSync) {
|
|
17
17
|
super(doc, shouldAcquire, shareSync);
|
|
@@ -53,7 +53,7 @@ class Term extends Content_1.Content {
|
|
|
53
53
|
recordType = senseRankOrType;
|
|
54
54
|
resolvedPhraseId = undefined;
|
|
55
55
|
}
|
|
56
|
-
const termId = Term.makeTermId(userId, phrase.text, phrase.sense_rank);
|
|
56
|
+
const termId = Term.makeTermId(userId, recordType, phrase.text, phrase.sense_rank);
|
|
57
57
|
return repo_1.ShareSyncFactory.get().createContent({
|
|
58
58
|
meta: {
|
|
59
59
|
ref: termId,
|
|
@@ -94,7 +94,8 @@ class Term extends Content_1.Content {
|
|
|
94
94
|
}
|
|
95
95
|
static forBuiltinPhrase(userId, phrase) {
|
|
96
96
|
const now = shaxpir_common_1.ClockService.getClock().now();
|
|
97
|
-
const
|
|
97
|
+
const resolvedType = phrase.type ?? (0, RecordType_1.getRecordTypeFromId)(phrase.id);
|
|
98
|
+
const termId = Term.makeTermId(userId, resolvedType, phrase.text, phrase.sense_rank);
|
|
98
99
|
return repo_1.ShareSyncFactory.get().createContent({
|
|
99
100
|
meta: {
|
|
100
101
|
ref: termId,
|
|
@@ -109,7 +110,7 @@ class Term extends Content_1.Content {
|
|
|
109
110
|
sense_rank: phrase.sense_rank,
|
|
110
111
|
// difficulty intentionally omitted for built-in phrases - always read from database
|
|
111
112
|
phrase_id: phrase.id,
|
|
112
|
-
type:
|
|
113
|
+
type: resolvedType,
|
|
113
114
|
starred_at: null,
|
|
114
115
|
user_tags: [],
|
|
115
116
|
user_tag_count: 0,
|