@casual-simulation/aux-records 3.2.3 → 3.2.4-alpha.5940763320
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/AIChatInterface.d.ts +8 -0
- package/AIChatInterface.js.map +1 -1
- package/AIController.d.ts +10 -4
- package/AIController.js +112 -3
- package/AIController.js.map +1 -1
- package/AuthController.d.ts +4 -8
- package/AuthController.js +39 -45
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +236 -4
- package/ConfigurationStore.d.ts +12 -0
- package/ConfigurationStore.js +2 -0
- package/ConfigurationStore.js.map +1 -0
- package/DataRecordsController.d.ts +18 -6
- package/DataRecordsController.js +31 -5
- package/DataRecordsController.js.map +1 -1
- package/Errors.d.ts +4 -0
- package/EventRecordsController.d.ts +12 -3
- package/EventRecordsController.js +27 -5
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.d.ts +13 -3
- package/FileRecordsController.js +46 -9
- package/FileRecordsController.js.map +1 -1
- package/MemoryFileRecordsLookup.d.ts +11 -0
- package/MemoryFileRecordsLookup.js +128 -0
- package/MemoryFileRecordsLookup.js.map +1 -0
- package/MemoryStore.d.ts +191 -0
- package/MemoryStore.js +1381 -0
- package/MemoryStore.js.map +1 -0
- package/MetricsStore.d.ts +186 -0
- package/MetricsStore.js +2 -0
- package/MetricsStore.js.map +1 -0
- package/OpenAIChatInterface.js +1 -0
- package/OpenAIChatInterface.js.map +1 -1
- package/PolicyController.d.ts +7 -4
- package/PolicyController.js +33 -8
- package/PolicyController.js.map +1 -1
- package/RecordsController.d.ts +185 -7
- package/RecordsController.js +588 -70
- package/RecordsController.js.map +1 -1
- package/RecordsHttpServer.d.ts +8 -0
- package/RecordsHttpServer.js +450 -8
- package/RecordsHttpServer.js.map +1 -1
- package/RecordsStore.d.ts +263 -5
- package/StripeInterface.d.ts +331 -0
- package/StripeInterface.js +37 -1
- package/StripeInterface.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +2523 -33
- package/SubscriptionConfiguration.js +130 -1
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +23 -6
- package/SubscriptionController.js +344 -69
- package/SubscriptionController.js.map +1 -1
- package/TestUtils.d.ts +7 -6
- package/TestUtils.js +28 -14
- package/TestUtils.js.map +1 -1
- package/Utils.js +9 -0
- package/Utils.js.map +1 -1
- package/index.d.ts +5 -4
- package/index.js +5 -4
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/MemoryAuthStore.d.ts +0 -33
- package/MemoryAuthStore.js +0 -186
- package/MemoryAuthStore.js.map +0 -1
- package/MemoryDataRecordsStore.d.ts +0 -10
- package/MemoryDataRecordsStore.js +0 -98
- package/MemoryDataRecordsStore.js.map +0 -1
- package/MemoryEventRecordsStore.d.ts +0 -10
- package/MemoryEventRecordsStore.js +0 -89
- package/MemoryEventRecordsStore.js.map +0 -1
- package/MemoryFileRecordsStore.d.ts +0 -25
- package/MemoryFileRecordsStore.js +0 -310
- package/MemoryFileRecordsStore.js.map +0 -1
- package/MemoryPolicyStore.d.ts +0 -43
- package/MemoryPolicyStore.js +0 -255
- package/MemoryPolicyStore.js.map +0 -1
- package/MemoryRecordsStore.d.ts +0 -13
- package/MemoryRecordsStore.js +0 -67
- package/MemoryRecordsStore.js.map +0 -1
package/AuthStore.d.ts
CHANGED
|
@@ -100,6 +100,60 @@ export interface AuthStore {
|
|
|
100
100
|
* Gets the list of SMS rules.
|
|
101
101
|
*/
|
|
102
102
|
listSmsRules(): Promise<RegexRule[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Creates or updates the given subscription.
|
|
105
|
+
* @param subscription The subscription to save.
|
|
106
|
+
*/
|
|
107
|
+
saveSubscription(subscription: AuthSubscription): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Gets the subscription with the given ID.
|
|
110
|
+
* @param id The ID of the subscription.
|
|
111
|
+
*/
|
|
112
|
+
getSubscriptionById(id: string): Promise<AuthSubscription | null>;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the subscription with the given stripe subscription ID.
|
|
115
|
+
* @param id The ID of the stripe subscription.
|
|
116
|
+
*/
|
|
117
|
+
getSubscriptionByStripeSubscriptionId(id: string): Promise<AuthSubscription | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Creates or updates the given subscription period.
|
|
120
|
+
* @param period The subscription period.
|
|
121
|
+
*/
|
|
122
|
+
saveSubscriptionPeriod(period: AuthSubscriptionPeriod): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Gets the subscription period with the given ID.
|
|
125
|
+
* @param id The ID of the subscription period.
|
|
126
|
+
*/
|
|
127
|
+
getSubscriptionPeriodById(id: string): Promise<AuthSubscriptionPeriod | null>;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the subscription periods that belong to the given subscription.
|
|
130
|
+
* @param subscriptionId The ID of the subscription.
|
|
131
|
+
*/
|
|
132
|
+
listSubscriptionPeriodsBySubscriptionId(subscriptionId: string): Promise<AuthSubscriptionPeriod[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Creates or updates the given invoice.
|
|
135
|
+
* @param invoice The invoice that should be saved.
|
|
136
|
+
*/
|
|
137
|
+
saveInvoice(invoice: AuthInvoice): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Gets the invoice with the given ID.
|
|
140
|
+
* @param id The ID of the invoice.
|
|
141
|
+
*/
|
|
142
|
+
getInvoiceById(id: string): Promise<AuthInvoice | null>;
|
|
143
|
+
/**
|
|
144
|
+
* Updates the subscription info for a user/studio.
|
|
145
|
+
*
|
|
146
|
+
* This will create/update a subscription object, update the info on the user/studio and subscription, and optionally update the period of the subscription.
|
|
147
|
+
* @param request The request.
|
|
148
|
+
*/
|
|
149
|
+
updateSubscriptionInfo(request: UpdateSubscriptionInfoRequest): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Updates the subscription period for a user/studio.
|
|
152
|
+
*
|
|
153
|
+
* This will update the period of the subscription, and optionally create subscription objects for the user/studio if neccesary.
|
|
154
|
+
* @param request The request.
|
|
155
|
+
*/
|
|
156
|
+
updateSubscriptionPeriod(request: UpdateSubscriptionPeriodRequest): Promise<void>;
|
|
103
157
|
}
|
|
104
158
|
export type AddressType = 'email' | 'phone';
|
|
105
159
|
export interface AuthUser {
|
|
@@ -109,10 +163,6 @@ export interface AuthUser {
|
|
|
109
163
|
phoneNumber: string | null;
|
|
110
164
|
avatarUrl?: string | null;
|
|
111
165
|
avatarPortraitUrl?: string | null;
|
|
112
|
-
/**
|
|
113
|
-
* The OpenAI API Key that the user has configured in their account.
|
|
114
|
-
*/
|
|
115
|
-
openAiKey?: string | null;
|
|
116
166
|
/**
|
|
117
167
|
* The ID of the stripe customer that is associated with this user.
|
|
118
168
|
*/
|
|
@@ -126,6 +176,18 @@ export interface AuthUser {
|
|
|
126
176
|
* Note that this is the ID of the subscription in the config, not the ID of the stripe subscription.
|
|
127
177
|
*/
|
|
128
178
|
subscriptionId?: string;
|
|
179
|
+
/**
|
|
180
|
+
* The ID of the subscription that this user record references.
|
|
181
|
+
*/
|
|
182
|
+
subscriptionInfoId?: string;
|
|
183
|
+
/**
|
|
184
|
+
* The unix time in miliseconds that the user's current subscription period started at.
|
|
185
|
+
*/
|
|
186
|
+
subscriptionPeriodStartMs?: number | null;
|
|
187
|
+
/**
|
|
188
|
+
* The unix time in miliseconds that the user's current subscription period ends at.
|
|
189
|
+
*/
|
|
190
|
+
subscriptionPeriodEndMs?: number | null;
|
|
129
191
|
/**
|
|
130
192
|
* The last Unix time that all the sessions were revoked at.
|
|
131
193
|
*/
|
|
@@ -239,6 +301,104 @@ export interface AuthSession {
|
|
|
239
301
|
*/
|
|
240
302
|
ipAddress: string;
|
|
241
303
|
}
|
|
304
|
+
export interface AuthSubscription {
|
|
305
|
+
id: string;
|
|
306
|
+
stripeSubscriptionId: string;
|
|
307
|
+
userId: string;
|
|
308
|
+
studioId: string;
|
|
309
|
+
/**
|
|
310
|
+
* The ID of the stripe customer that is associated with this subscription.
|
|
311
|
+
*/
|
|
312
|
+
stripeCustomerId: string | null;
|
|
313
|
+
/**
|
|
314
|
+
* The current status of the subscription.
|
|
315
|
+
*/
|
|
316
|
+
subscriptionStatus: string | null;
|
|
317
|
+
/**
|
|
318
|
+
* The ID of the purchasable subscription that the user has.
|
|
319
|
+
* Note that this is the ID of the subscription in the config, not the ID of the stripe subscription.
|
|
320
|
+
*/
|
|
321
|
+
subscriptionId: string;
|
|
322
|
+
/**
|
|
323
|
+
* The unix time in miliseconds that the current subscription period started at.
|
|
324
|
+
*/
|
|
325
|
+
currentPeriodStartMs: number | null;
|
|
326
|
+
/**
|
|
327
|
+
* The unix time in miliseconds that the current subscription period ends at.
|
|
328
|
+
*/
|
|
329
|
+
currentPeriodEndMs: number | null;
|
|
330
|
+
}
|
|
331
|
+
export interface AuthSubscriptionPeriod {
|
|
332
|
+
id: string;
|
|
333
|
+
/**
|
|
334
|
+
* The ID of the subscription that this period is for.
|
|
335
|
+
*/
|
|
336
|
+
subscriptionId: string;
|
|
337
|
+
/**
|
|
338
|
+
* The ID of the invoice for this period.
|
|
339
|
+
*/
|
|
340
|
+
invoiceId: string;
|
|
341
|
+
/**
|
|
342
|
+
* The unix time in miliseconds that the subscription period started at.
|
|
343
|
+
*/
|
|
344
|
+
periodStartMs: number;
|
|
345
|
+
/**
|
|
346
|
+
* The unix time in miliseconds that the subscription period ends at.
|
|
347
|
+
*/
|
|
348
|
+
periodEndMs: number;
|
|
349
|
+
}
|
|
350
|
+
export interface AuthInvoice {
|
|
351
|
+
id: string;
|
|
352
|
+
/**
|
|
353
|
+
* The ID of the stripe invoice that is associated with this invoice.
|
|
354
|
+
*/
|
|
355
|
+
stripeInvoiceId: string;
|
|
356
|
+
/**
|
|
357
|
+
* The ID of the subscription that this invoice is for.
|
|
358
|
+
*/
|
|
359
|
+
subscriptionId: string;
|
|
360
|
+
/**
|
|
361
|
+
* The ID of the subscription period that this invoice is for.
|
|
362
|
+
*/
|
|
363
|
+
periodId: string;
|
|
364
|
+
/**
|
|
365
|
+
* The description of the invoice.
|
|
366
|
+
*/
|
|
367
|
+
description: string;
|
|
368
|
+
/**
|
|
369
|
+
* The status of the invoice.
|
|
370
|
+
*/
|
|
371
|
+
status: string;
|
|
372
|
+
/**
|
|
373
|
+
* Whether the invoice is paid.
|
|
374
|
+
*/
|
|
375
|
+
paid: boolean;
|
|
376
|
+
/**
|
|
377
|
+
* The three-letter ISO code for the currency that the invoice is in.
|
|
378
|
+
*/
|
|
379
|
+
currency: string;
|
|
380
|
+
/**
|
|
381
|
+
* The amount of the invoice in the smallest unit of the currency.
|
|
382
|
+
*/
|
|
383
|
+
total: number;
|
|
384
|
+
/**
|
|
385
|
+
* The subtotal of the invoice.
|
|
386
|
+
*/
|
|
387
|
+
subtotal: number;
|
|
388
|
+
/**
|
|
389
|
+
* The amount of tax collected.
|
|
390
|
+
*/
|
|
391
|
+
tax: number;
|
|
392
|
+
/**
|
|
393
|
+
* The URL of the stripe hosted invoice.
|
|
394
|
+
* Users can use this to pay and see the invoice.
|
|
395
|
+
*/
|
|
396
|
+
stripeHostedInvoiceUrl: string;
|
|
397
|
+
/**
|
|
398
|
+
* The URL of the stripe hosted invoice PDF.
|
|
399
|
+
*/
|
|
400
|
+
stripeInvoicePdfUrl: string;
|
|
401
|
+
}
|
|
242
402
|
export type SaveNewUserResult = SaveNewUserSuccess | SaveNewUserFailure;
|
|
243
403
|
export interface SaveNewUserSuccess {
|
|
244
404
|
success: true;
|
|
@@ -258,4 +418,76 @@ export interface ListSessionsDataFailure {
|
|
|
258
418
|
errorCode: ServerError;
|
|
259
419
|
errorMessage: string;
|
|
260
420
|
}
|
|
421
|
+
export interface UpdateSubscriptionInfoRequest {
|
|
422
|
+
/**
|
|
423
|
+
* The ID of the user that the subscription info should be updated for.
|
|
424
|
+
*/
|
|
425
|
+
userId?: string;
|
|
426
|
+
/**
|
|
427
|
+
* The ID of the studio that the subscription info should be updated for.
|
|
428
|
+
*/
|
|
429
|
+
studioId?: string;
|
|
430
|
+
/**
|
|
431
|
+
* The current status of the subscription.
|
|
432
|
+
*/
|
|
433
|
+
subscriptionStatus: string;
|
|
434
|
+
/**
|
|
435
|
+
* The ID of the purchasable subscription that the user has.
|
|
436
|
+
*/
|
|
437
|
+
subscriptionId: string;
|
|
438
|
+
/**
|
|
439
|
+
* The ID of the subscription in Stripe's database.
|
|
440
|
+
*/
|
|
441
|
+
stripeSubscriptionId: string;
|
|
442
|
+
/**
|
|
443
|
+
* The ID of the stripe customer.
|
|
444
|
+
*/
|
|
445
|
+
stripeCustomerId: string;
|
|
446
|
+
/**
|
|
447
|
+
* The unix time in miliseconds that the current subscription period started at.
|
|
448
|
+
*/
|
|
449
|
+
currentPeriodStartMs: number;
|
|
450
|
+
/**
|
|
451
|
+
* The unix time in miliseconds that the current subscription period ends at.
|
|
452
|
+
*/
|
|
453
|
+
currentPeriodEndMs: number;
|
|
454
|
+
}
|
|
455
|
+
export interface UpdateSubscriptionPeriodRequest {
|
|
456
|
+
/**
|
|
457
|
+
* The ID of the user that the subscription info should be updated for.
|
|
458
|
+
*/
|
|
459
|
+
userId?: string;
|
|
460
|
+
/**
|
|
461
|
+
* The ID of the studio that the subscription info should be updated for.
|
|
462
|
+
*/
|
|
463
|
+
studioId?: string;
|
|
464
|
+
/**
|
|
465
|
+
* The current status of the subscription.
|
|
466
|
+
*/
|
|
467
|
+
subscriptionStatus: string;
|
|
468
|
+
/**
|
|
469
|
+
* The ID of the purchasable subscription that the user has.
|
|
470
|
+
*/
|
|
471
|
+
subscriptionId: string;
|
|
472
|
+
/**
|
|
473
|
+
* The ID of the subscription in Stripe's database.
|
|
474
|
+
*/
|
|
475
|
+
stripeSubscriptionId: string;
|
|
476
|
+
/**
|
|
477
|
+
* The ID of the stripe customer.
|
|
478
|
+
*/
|
|
479
|
+
stripeCustomerId: string;
|
|
480
|
+
/**
|
|
481
|
+
* The unix time in miliseconds that the current subscription period started at.
|
|
482
|
+
*/
|
|
483
|
+
currentPeriodStartMs: number;
|
|
484
|
+
/**
|
|
485
|
+
* The unix time in miliseconds that the current subscription period ends at.
|
|
486
|
+
*/
|
|
487
|
+
currentPeriodEndMs: number;
|
|
488
|
+
/**
|
|
489
|
+
* The invoice that should be created.
|
|
490
|
+
*/
|
|
491
|
+
invoice: Omit<AuthInvoice, 'id' | 'subscriptionId' | 'periodId'>;
|
|
492
|
+
}
|
|
261
493
|
//# sourceMappingURL=AuthStore.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SubscriptionConfiguration } from './SubscriptionConfiguration';
|
|
2
|
+
export declare const SUBSCRIPTIONS_CONFIG_KEY = "subscriptions";
|
|
3
|
+
/**
|
|
4
|
+
* Defines an interface that is used for storing configuration data.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConfigurationStore {
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the subscription configuration from the store.
|
|
9
|
+
*/
|
|
10
|
+
getSubscriptionConfiguration(): Promise<SubscriptionConfiguration | null>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ConfigurationStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigurationStore.js","sourceRoot":"","sources":["ConfigurationStore.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,wBAAwB,GAAG,eAAe,CAAC"}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import { NotAuthorizedError, NotLoggedInError, ServerError } from './Errors';
|
|
1
|
+
import { NotAuthorizedError, NotLoggedInError, ServerError, SubscriptionLimitReached } from './Errors';
|
|
2
2
|
import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, SetDataResult, UserPolicy, ListDataStoreFailure } from './DataRecordsStore';
|
|
3
3
|
import { ValidatePublicRecordKeyFailure } from './RecordsController';
|
|
4
4
|
import { AuthorizeDenied, PolicyController } from './PolicyController';
|
|
5
|
+
import { MetricsStore } from './MetricsStore';
|
|
6
|
+
import { ConfigurationStore } from './ConfigurationStore';
|
|
7
|
+
export interface DataRecordsConfiguration {
|
|
8
|
+
store: DataRecordsStore;
|
|
9
|
+
policies: PolicyController;
|
|
10
|
+
metrics: MetricsStore;
|
|
11
|
+
config: ConfigurationStore;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Defines a class that is able to manage data (key/value) records.
|
|
7
15
|
*/
|
|
8
16
|
export declare class DataRecordsController {
|
|
9
|
-
private _manager;
|
|
10
17
|
private _store;
|
|
11
18
|
private _policies;
|
|
19
|
+
private _metrics;
|
|
20
|
+
private _config;
|
|
12
21
|
/**
|
|
13
22
|
* Creates a DataRecordsController.
|
|
14
|
-
* @param
|
|
15
|
-
* @param store The store that should be used to save data.
|
|
23
|
+
* @param config The configuration that should be used for the data records controller.
|
|
16
24
|
*/
|
|
17
|
-
constructor(
|
|
25
|
+
constructor(config: DataRecordsConfiguration);
|
|
18
26
|
/**
|
|
19
27
|
* Records the given data in the given record and address.
|
|
20
28
|
* Uses the given record key to access the record and the given subject ID to store which user the data came from.
|
|
@@ -98,11 +106,15 @@ export interface RecordDataFailure {
|
|
|
98
106
|
/**
|
|
99
107
|
* The error code for the failure.
|
|
100
108
|
*/
|
|
101
|
-
errorCode: ServerError | NotLoggedInError | NotAuthorizedError | ValidatePublicRecordKeyFailure['errorCode'] | SetDataResult['errorCode'] | 'unacceptable_request' | 'not_supported' | 'invalid_update_policy' | 'invalid_delete_policy';
|
|
109
|
+
errorCode: ServerError | NotLoggedInError | NotAuthorizedError | ValidatePublicRecordKeyFailure['errorCode'] | SetDataResult['errorCode'] | SubscriptionLimitReached | 'unacceptable_request' | 'not_supported' | 'invalid_update_policy' | 'invalid_delete_policy';
|
|
102
110
|
/**
|
|
103
111
|
* The error message for the failure.
|
|
104
112
|
*/
|
|
105
113
|
errorMessage: string;
|
|
114
|
+
/**
|
|
115
|
+
* The reason for the error.
|
|
116
|
+
*/
|
|
117
|
+
errorReason?: 'data_not_allowed' | 'too_many_items';
|
|
106
118
|
}
|
|
107
119
|
/**
|
|
108
120
|
* The possible results of a get data request.
|
package/DataRecordsController.js
CHANGED
|
@@ -11,18 +11,20 @@ import { doesSubjectMatchPolicy, isValidUserPolicy, } from './DataRecordsStore';
|
|
|
11
11
|
import { returnAuthorizationResult, } from './PolicyController';
|
|
12
12
|
import { PUBLIC_READ_MARKER } from './PolicyPermissions';
|
|
13
13
|
import { without } from 'lodash';
|
|
14
|
+
import { getSubscriptionFeatures } from './SubscriptionConfiguration';
|
|
14
15
|
/**
|
|
15
16
|
* Defines a class that is able to manage data (key/value) records.
|
|
16
17
|
*/
|
|
17
18
|
export class DataRecordsController {
|
|
18
19
|
/**
|
|
19
20
|
* Creates a DataRecordsController.
|
|
20
|
-
* @param
|
|
21
|
-
* @param store The store that should be used to save data.
|
|
21
|
+
* @param config The configuration that should be used for the data records controller.
|
|
22
22
|
*/
|
|
23
|
-
constructor(
|
|
24
|
-
this._store = store;
|
|
25
|
-
this._policies = policies;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this._store = config.store;
|
|
25
|
+
this._policies = config.policies;
|
|
26
|
+
this._metrics = config.metrics;
|
|
27
|
+
this._config = config.config;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Records the given data in the given record and address.
|
|
@@ -140,6 +142,30 @@ export class DataRecordsController {
|
|
|
140
142
|
if (authorization.allowed === false) {
|
|
141
143
|
return returnAuthorizationResult(authorization);
|
|
142
144
|
}
|
|
145
|
+
const metricsResult = yield this._metrics.getSubscriptionDataMetricsByRecordName(recordName);
|
|
146
|
+
const config = yield this._config.getSubscriptionConfiguration();
|
|
147
|
+
const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
|
|
148
|
+
if (!features.data.allowed) {
|
|
149
|
+
return {
|
|
150
|
+
success: false,
|
|
151
|
+
errorCode: 'not_authorized',
|
|
152
|
+
errorMessage: 'The subscription does not permit the recording of data.',
|
|
153
|
+
errorReason: 'data_not_allowed',
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (request.action === 'data.create') {
|
|
157
|
+
// Check metrics
|
|
158
|
+
if (features.data.maxItems > 0) {
|
|
159
|
+
if (metricsResult.totalItems >= features.data.maxItems) {
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
errorCode: 'subscription_limit_reached',
|
|
163
|
+
errorMessage: 'The maximum number of items has been reached for your subscription.',
|
|
164
|
+
errorReason: 'too_many_items',
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
143
169
|
const result2 = yield this._store.setData(recordName, address, data, authorization.authorizerId, subjectId, updatePolicy, deletePolicy, resourceMarkers);
|
|
144
170
|
if (result2.success === false) {
|
|
145
171
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataRecordsController.js","sourceRoot":"","sources":["DataRecordsController.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"DataRecordsController.js","sourceRoot":"","sources":["DataRecordsController.ts"],"names":[],"mappings":";;;;;;;;;AAMA,OAAO,EAOH,sBAAsB,EACtB,iBAAiB,GAEpB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAQH,yBAAyB,GAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAStE;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAM9B;;;OAGG;IACH,YAAY,MAAgC;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,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,KAAK,EAAE;oBAC3B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;qBACrC,CAAC;iBACL;gBAED,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,UAAU;oBACV,OAAO;iBACV,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;;KACJ;CACJ"}
|
package/Errors.d.ts
CHANGED
|
@@ -22,4 +22,8 @@ export type NotSubscribedError = 'not_subscribed';
|
|
|
22
22
|
* Defines an error that occurrs when the user tries to perform an action that requires a subscription tier that .
|
|
23
23
|
*/
|
|
24
24
|
export type InvalidSubscriptionTierError = 'invalid_subscription_tier';
|
|
25
|
+
/**
|
|
26
|
+
* Defines an error that occurs when the user tries to perform an action that would exceed their subscription limit.
|
|
27
|
+
*/
|
|
28
|
+
export type SubscriptionLimitReached = 'subscription_limit_reached';
|
|
25
29
|
//# sourceMappingURL=Errors.d.ts.map
|
|
@@ -2,18 +2,27 @@ import { AuthorizeDenied, PolicyController } from './PolicyController';
|
|
|
2
2
|
import { NotLoggedInError, NotSupportedError, ServerError } from './Errors';
|
|
3
3
|
import { EventRecordsStore, AddEventCountStoreFailure, GetEventCountStoreFailure } from './EventRecordsStore';
|
|
4
4
|
import { ValidatePublicRecordKeyFailure } from './RecordsController';
|
|
5
|
+
import { MetricsStore } from './MetricsStore';
|
|
6
|
+
import { ConfigurationStore } from './ConfigurationStore';
|
|
7
|
+
export interface EventRecordsConfiguration {
|
|
8
|
+
policies: PolicyController;
|
|
9
|
+
store: EventRecordsStore;
|
|
10
|
+
metrics: MetricsStore;
|
|
11
|
+
config: ConfigurationStore;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Defines a class that is able to manage event (count) records.
|
|
7
15
|
*/
|
|
8
16
|
export declare class EventRecordsController {
|
|
9
17
|
private _policies;
|
|
10
18
|
private _store;
|
|
19
|
+
private _metrics;
|
|
20
|
+
private _config;
|
|
11
21
|
/**
|
|
12
22
|
* Creates a DataRecordsController.
|
|
13
|
-
* @param
|
|
14
|
-
* @param store The store that should be used to save data.
|
|
23
|
+
* @param config The configuration to use.
|
|
15
24
|
*/
|
|
16
|
-
constructor(
|
|
25
|
+
constructor(config: EventRecordsConfiguration);
|
|
17
26
|
/**
|
|
18
27
|
* Adds the given count of events to the total count of events with the given name.
|
|
19
28
|
* @param recordKeyOrRecordName The record key or the name of the record that should be used to add the events.
|
|
@@ -11,18 +11,20 @@ import { returnAuthorizationResult, } from './PolicyController';
|
|
|
11
11
|
import { cleanupObject, getMarkersOrDefault } from './Utils';
|
|
12
12
|
import { without } from 'lodash';
|
|
13
13
|
import { PUBLIC_READ_MARKER } from './PolicyPermissions';
|
|
14
|
+
import { getSubscriptionFeatures } from './SubscriptionConfiguration';
|
|
14
15
|
/**
|
|
15
16
|
* Defines a class that is able to manage event (count) records.
|
|
16
17
|
*/
|
|
17
18
|
export class EventRecordsController {
|
|
18
19
|
/**
|
|
19
20
|
* Creates a DataRecordsController.
|
|
20
|
-
* @param
|
|
21
|
-
* @param store The store that should be used to save data.
|
|
21
|
+
* @param config The configuration to use.
|
|
22
22
|
*/
|
|
23
|
-
constructor(
|
|
24
|
-
this._policies = policies;
|
|
25
|
-
this._store = store;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this._policies = config.policies;
|
|
25
|
+
this._store = config.store;
|
|
26
|
+
this._metrics = config.metrics;
|
|
27
|
+
this._config = config.config;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Adds the given count of events to the total count of events with the given name.
|
|
@@ -62,6 +64,16 @@ export class EventRecordsController {
|
|
|
62
64
|
errorMessage: 'The user must be logged in in order to record events.',
|
|
63
65
|
};
|
|
64
66
|
}
|
|
67
|
+
const metricsResult = yield this._metrics.getSubscriptionEventMetricsByRecordName(recordName);
|
|
68
|
+
const config = yield this._config.getSubscriptionConfiguration();
|
|
69
|
+
const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
|
|
70
|
+
if (!features.events.allowed) {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
errorCode: 'not_authorized',
|
|
74
|
+
errorMessage: 'The subscription does not permit the recording of events.',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
65
77
|
const result2 = yield this._store.addEventCount(recordName, eventName, count);
|
|
66
78
|
if (result2.success === true) {
|
|
67
79
|
return {
|
|
@@ -168,6 +180,16 @@ export class EventRecordsController {
|
|
|
168
180
|
if (authorizeResult.allowed === false) {
|
|
169
181
|
return returnAuthorizationResult(authorizeResult);
|
|
170
182
|
}
|
|
183
|
+
const metricsResult = yield this._metrics.getSubscriptionEventMetricsByRecordName(recordName);
|
|
184
|
+
const config = yield this._config.getSubscriptionConfiguration();
|
|
185
|
+
const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
|
|
186
|
+
if (!features.events.allowed) {
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
errorCode: 'not_authorized',
|
|
190
|
+
errorMessage: 'The subscription does not permit the recording of events.',
|
|
191
|
+
};
|
|
192
|
+
}
|
|
171
193
|
const update = yield this._store.updateEvent(recordName, eventName, cleanupObject({
|
|
172
194
|
count: request.count,
|
|
173
195
|
markers: markers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventRecordsController.js","sourceRoot":"","sources":["EventRecordsController.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAGH,yBAAyB,GAC5B,MAAM,oBAAoB,CAAC;AAa5B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO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AK,KAAK,EAAE;oBAC1B,OAAO,MAAM,CAAC;iBACjB;gBAED,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,gBAAgB,+BACzD,MAAM,EAAE,YAAY,IACjB,WAAW,KACd,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;wBAAC,OAAA,CAAC;4BAClC,SAAS,EAAE,CAAC,CAAC,SAAS;4BACtB,OAAO,EAAE,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,kBAAkB,CAAC;4BAC1C,KAAK,EAAE,CAAC,CAAC,KAAK;yBACjB,CAAC,CAAA;qBAAA,CAAC,IACL,CAAC;gBAEH,IAAI,eAAe,CAAC,OAAO,KAAK,KAAK,EAAE;oBACnC,OAAO,yBAAyB,CAAC,eAAe,CAAC,CAAC;iBACrD;gBAED,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,MAAM,EAAE,eAAe,CAAC,iBAAkC;iBAC7D,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO,CAAC,KAAK,CACT,iDAAiD,EACjD,GAAG,CACN,CAAC;gBACF,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,0BAA0B;iBAC3C,CAAC;aACL;QACL,CAAC;KAAA;CACJ"}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { FileRecordsStore, AddFileFailure, MarkFileRecordAsUploadedFailure, EraseFileStoreResult, GetFileNameFromUrlResult, PresignFileReadFailure, GetFileRecordFailure } from './FileRecordsStore';
|
|
2
|
-
import { NotLoggedInError, NotSupportedError, ServerError } from './Errors';
|
|
2
|
+
import { NotLoggedInError, NotSupportedError, ServerError, SubscriptionLimitReached } from './Errors';
|
|
3
3
|
import { ValidatePublicRecordKeyFailure } from './RecordsController';
|
|
4
4
|
import { AuthorizeDenied, PolicyController } from './PolicyController';
|
|
5
|
+
import { MetricsStore } from './MetricsStore';
|
|
6
|
+
import { ConfigurationStore } from './ConfigurationStore';
|
|
7
|
+
export interface FileRecordsConfiguration {
|
|
8
|
+
policies: PolicyController;
|
|
9
|
+
store: FileRecordsStore;
|
|
10
|
+
metrics: MetricsStore;
|
|
11
|
+
config: ConfigurationStore;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Defines a class that can manage file records.
|
|
7
15
|
*/
|
|
8
16
|
export declare class FileRecordsController {
|
|
9
17
|
private _policies;
|
|
10
18
|
private _store;
|
|
11
|
-
|
|
19
|
+
private _metrics;
|
|
20
|
+
private _config;
|
|
21
|
+
constructor(config: FileRecordsConfiguration);
|
|
12
22
|
/**
|
|
13
23
|
* Attempts to record a file.
|
|
14
24
|
* @param recordNameOrKey The name of the record or the record key of the record.
|
|
@@ -129,7 +139,7 @@ export interface RecordFileFailure {
|
|
|
129
139
|
/**
|
|
130
140
|
* The error code that indicates why the request failed.
|
|
131
141
|
*/
|
|
132
|
-
errorCode: ServerError | NotLoggedInError | ValidatePublicRecordKeyFailure['errorCode'] | AddFileFailure['errorCode'] | AuthorizeDenied['errorCode'] | 'invalid_file_data' | 'not_supported';
|
|
142
|
+
errorCode: ServerError | NotLoggedInError | ValidatePublicRecordKeyFailure['errorCode'] | AddFileFailure['errorCode'] | AuthorizeDenied['errorCode'] | SubscriptionLimitReached | 'invalid_file_data' | 'not_supported';
|
|
133
143
|
/**
|
|
134
144
|
* The error message that indicates why the request failed.
|
|
135
145
|
*/
|