4
4
* See License-AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { v4 as uuidv4 } from ' uuid' ;
8
- import { User } from ' ./protocol' ;
9
- import { oneMonthLater } from ' ./util/timeutil' ;
7
+ import { v4 as uuidv4 } from " uuid" ;
8
+ import { User } from " ./protocol" ;
9
+ import { oneMonthLater } from " ./util/timeutil" ;
10
10
11
11
/*
12
12
* Subscription and acocunting data
@@ -33,7 +33,7 @@ export interface AccountEntry {
33
33
/**
34
34
* credit: end of validity
35
35
*/
36
- expiryDate ?: string ; // exclusive
36
+ expiryDate ?: string ; // exclusive
37
37
38
38
kind : AccountEntryKind ;
39
39
@@ -46,26 +46,26 @@ export interface AccountEntry {
46
46
description ?: object ;
47
47
}
48
48
export namespace AccountEntry {
49
- export function create < T extends AccountEntry > ( entry : Omit < T , ' uid' > ) : T {
49
+ export function create < T extends AccountEntry > ( entry : Omit < T , " uid" > ) : T {
50
50
const result = entry as T ;
51
51
result . uid = uuidv4 ( ) ;
52
52
return result ;
53
- } ;
53
+ }
54
54
}
55
55
56
- export type DebitAccountEntryKind = ' session' | ' expiry' | ' loss' ;
57
- export type AccountEntryKind = ' credit' | DebitAccountEntryKind | ' carry' | ' open' ;
56
+ export type DebitAccountEntryKind = " session" | " expiry" | " loss" ;
57
+ export type AccountEntryKind = " credit" | DebitAccountEntryKind | " carry" | " open" ;
58
58
59
59
export interface Credit extends AccountEntry {
60
- kind : ' credit' ;
60
+ kind : " credit" ;
61
61
expiryDate : string ;
62
62
}
63
63
export type Debit = LossDebit | ExpiryDebit | SessionDebit ;
64
64
export interface LossDebit extends AccountEntry {
65
- kind : ' loss' ;
65
+ kind : " loss" ;
66
66
}
67
67
export interface ExpiryDebit extends AccountEntry {
68
- kind : ' expiry' ;
68
+ kind : " expiry" ;
69
69
creditId : undefined ;
70
70
}
71
71
export interface SessionDebit extends AccountEntry {
@@ -80,9 +80,7 @@ export interface CreditDescription {
80
80
}
81
81
export namespace CreditDescription {
82
82
export function is ( obj : any ) : obj is CreditDescription {
83
- return ! ! obj
84
- && obj . hasOwnProperty ( 'subscriptionId' )
85
- && obj . hasOwnProperty ( 'planId' ) ;
83
+ return ! ! obj && obj . hasOwnProperty ( "subscriptionId" ) && obj . hasOwnProperty ( "planId" ) ;
86
84
}
87
85
}
88
86
export interface SessionDescription {
@@ -93,11 +91,13 @@ export interface SessionDescription {
93
91
}
94
92
export namespace SessionDescription {
95
93
export function is ( obj : any ) : obj is SessionDescription {
96
- return ! ! obj
97
- && obj . hasOwnProperty ( 'contextTitle' )
98
- && obj . hasOwnProperty ( 'contextUrl' )
99
- && obj . hasOwnProperty ( 'workspaceId' )
100
- && obj . hasOwnProperty ( 'workspaceInstanceId' )
94
+ return (
95
+ ! ! obj &&
96
+ obj . hasOwnProperty ( "contextTitle" ) &&
97
+ obj . hasOwnProperty ( "contextUrl" ) &&
98
+ obj . hasOwnProperty ( "workspaceId" ) &&
99
+ obj . hasOwnProperty ( "workspaceInstanceId" )
100
+ ) ;
101
101
}
102
102
}
103
103
@@ -111,11 +111,11 @@ export namespace SessionDescription {
111
111
export interface Subscription {
112
112
uid : string ;
113
113
userId : string ;
114
- startDate : string ; // inclusive
114
+ startDate : string ; // inclusive
115
115
/** When the subscription will end (must be >= cancellationDate!) */
116
- endDate ?: string ; // exclusive
116
+ endDate ?: string ; // exclusive
117
117
/** When the subscription was cancelled */
118
- cancellationDate ?: string ; // exclusive
118
+ cancellationDate ?: string ; // exclusive
119
119
/** Number of granted hours */
120
120
amount : number ;
121
121
/** Number of granted hours for the first month: If this is set, use this value for the first month */
@@ -145,8 +145,7 @@ export interface UserPaidSubscription extends Subscription {
145
145
}
146
146
export namespace UserPaidSubscription {
147
147
export function is ( data : any ) : data is UserPaidSubscription {
148
- return ! ! data
149
- && data . hasOwnProperty ( 'paymentReference' ) ;
148
+ return ! ! data && data . hasOwnProperty ( "paymentReference" ) ;
150
149
}
151
150
}
152
151
@@ -155,61 +154,64 @@ export interface AssignedTeamSubscription extends Subscription {
155
154
}
156
155
export namespace AssignedTeamSubscription {
157
156
export function is ( data : any ) : data is AssignedTeamSubscription {
158
- return ! ! data
159
- && data . hasOwnProperty ( 'teamSubscriptionSlotId' ) ;
157
+ return ! ! data && data . hasOwnProperty ( "teamSubscriptionSlotId" ) ;
160
158
}
161
159
}
162
160
163
161
export namespace Subscription {
164
- export function create ( newSubscription : Omit < Subscription , ' uid' > ) {
162
+ export function create ( newSubscription : Omit < Subscription , " uid" > ) {
165
163
const subscription = newSubscription as Subscription ;
166
164
subscription . uid = uuidv4 ( ) ;
167
165
return subscription ;
168
- } ;
166
+ }
169
167
export function cancelSubscription ( s : Subscription , cancellationDate : string , endDate ?: string ) {
170
168
s . endDate = endDate || cancellationDate ;
171
169
s . cancellationDate = cancellationDate ;
172
- } ;
170
+ }
173
171
export function isSame ( s1 : Subscription | undefined , s2 : Subscription | undefined ) : boolean {
174
- return ! ! s1 && ! ! s2
175
- && s1 . userId === s2 . userId
176
- && s1 . planId === s2 . planId
177
- && s1 . startDate === s2 . startDate
178
- && s1 . endDate === s2 . endDate
179
- && s1 . amount === s2 . amount
180
- && s1 . cancellationDate === s2 . cancellationDate
181
- && s1 . deleted === s2 . deleted
182
- && ( ( s1 . paymentData === undefined && s2 . paymentData === undefined )
183
- || ( ! ! s1 . paymentData && ! ! s2 . paymentData
184
- && s1 . paymentData . downgradeDate === s2 . paymentData . downgradeDate
185
- && s1 . paymentData . newPlan === s2 . paymentData . newPlan ) ) ;
186
- } ;
172
+ return (
173
+ ! ! s1 &&
174
+ ! ! s2 &&
175
+ s1 . userId === s2 . userId &&
176
+ s1 . planId === s2 . planId &&
177
+ s1 . startDate === s2 . startDate &&
178
+ s1 . endDate === s2 . endDate &&
179
+ s1 . amount === s2 . amount &&
180
+ s1 . cancellationDate === s2 . cancellationDate &&
181
+ s1 . deleted === s2 . deleted &&
182
+ ( ( s1 . paymentData === undefined && s2 . paymentData === undefined ) ||
183
+ ( ! ! s1 . paymentData &&
184
+ ! ! s2 . paymentData &&
185
+ s1 . paymentData . downgradeDate === s2 . paymentData . downgradeDate &&
186
+ s1 . paymentData . newPlan === s2 . paymentData . newPlan ) )
187
+ ) ;
188
+ }
187
189
export function isActive ( s : Subscription , date : string ) : boolean {
188
190
return s . startDate <= date && ( s . endDate === undefined || date < s . endDate ) ;
189
- } ;
191
+ }
190
192
export function isDowngraded ( s : Subscription ) {
191
193
return s . paymentData && s . paymentData . downgradeDate ;
192
- } ;
194
+ }
193
195
export function calculateCurrentPeriod ( startDate : string , now : Date ) {
194
196
let nextStartDate = startDate ;
195
197
do {
196
198
startDate = nextStartDate ;
197
199
nextStartDate = oneMonthLater ( startDate , new Date ( startDate ) . getDate ( ) ) ;
198
200
} while ( nextStartDate < now . toISOString ( ) ) ;
199
201
return { startDate, endDate : nextStartDate } ;
200
- } ;
202
+ }
201
203
}
202
204
203
205
export type MaybeSubscription = Subscription | undefined ;
204
206
205
207
export interface Period {
206
- startDate : string ; // inclusive
207
- endDate : string ; // exclusive
208
+ startDate : string ; // inclusive
209
+ endDate : string ; // exclusive
208
210
}
209
211
210
212
export type MaybePeriod = Period | undefined ;
211
213
212
- export type AccountEntryFixedPeriod = Omit < AccountEntry , ' uid' > & { expiryDate : string } ;
214
+ export type AccountEntryFixedPeriod = Omit < AccountEntry , " uid" > & { expiryDate : string } ;
213
215
export interface AccountStatement extends Period {
214
216
userId : string ;
215
217
/**
@@ -221,9 +223,9 @@ export interface AccountStatement extends Period {
221
223
/** Remaining valid hours (accumulated from credits) */
222
224
remainingHours : RemainingHours ;
223
225
}
224
- export type RemainingHours = number | ' unlimited' ;
226
+ export type RemainingHours = number | " unlimited" ;
225
227
226
228
export interface CreditAlert {
227
- userId : string ,
228
- remainingUsageHours : number
229
+ userId : string ;
230
+ remainingUsageHours : number ;
229
231
}
0 commit comments