@casual-simulation/aux-records 3.8.1 → 3.10.2
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 +7 -43
- package/AIChatInterface.js +8 -6
- package/AIChatInterface.js.map +1 -1
- package/AIController.js +44 -49
- package/AIController.js.map +1 -1
- package/AIOpenAIRealtimeInterface.d.ts +1 -1
- package/AnthropicAIChatInterface.js +4 -4
- package/AnthropicAIChatInterface.js.map +1 -1
- package/AuthController.d.ts +78 -10
- package/AuthController.js +230 -166
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +317 -4
- package/BigIntPatch.d.ts +1 -0
- package/BigIntPatch.js +24 -0
- package/BigIntPatch.js.map +1 -0
- package/BlockadeLabsGenerateSkyboxInterface.js +4 -4
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
- package/CachingConfigStore.d.ts +8 -1
- package/CachingConfigStore.js +50 -0
- package/CachingConfigStore.js.map +1 -1
- package/ComIdConfig.d.ts +132 -86
- package/ComIdConfig.js +5 -5
- package/ComIdConfig.js.map +1 -1
- package/ConfigurationStore.d.ts +1393 -3
- package/ConfigurationStore.js +49 -0
- package/ConfigurationStore.js.map +1 -1
- package/DataRecordsController.js +28 -28
- package/DataRecordsController.js.map +1 -1
- package/EventRecordsController.js +9 -9
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.js +18 -17
- package/FileRecordsController.js.map +1 -1
- package/GoogleAIChatInterface.js +4 -4
- package/GoogleAIChatInterface.js.map +1 -1
- package/HttpTestUtils.d.ts +48 -0
- package/HttpTestUtils.js +256 -0
- package/HttpTestUtils.js.map +1 -0
- package/LivekitController.js +2 -2
- package/LivekitController.js.map +1 -1
- package/LoomController.js +3 -4
- package/LoomController.js.map +1 -1
- package/MemoryStore.d.ts +60 -7
- package/MemoryStore.js +427 -59
- package/MemoryStore.js.map +1 -1
- package/MetricsStore.d.ts +11 -0
- package/ModerationConfiguration.d.ts +11 -85
- package/ModerationConfiguration.js +17 -17
- package/ModerationConfiguration.js.map +1 -1
- package/ModerationController.js +9 -11
- package/ModerationController.js.map +1 -1
- package/OpenAIChatInterface.js +8 -13
- package/OpenAIChatInterface.js.map +1 -1
- package/OpenAIImageInterface.js +4 -5
- package/OpenAIImageInterface.js.map +1 -1
- package/PolicyController.js +66 -73
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +59 -33
- package/PolicyStore.js +35 -1
- package/PolicyStore.js.map +1 -1
- package/PrivoClient.d.ts +3 -1
- package/PrivoClient.js +2 -4
- package/PrivoClient.js.map +1 -1
- package/PrivoConfiguration.d.ts +6 -72
- package/PrivoConfiguration.js +30 -31
- package/PrivoConfiguration.js.map +1 -1
- package/README.md +276 -2
- package/RateLimitController.js +2 -2
- package/RateLimitController.js.map +1 -1
- package/RecordsClient.d.ts +3 -1
- package/RecordsClient.js +6 -6
- package/RecordsClient.js.map +1 -1
- package/RecordsController.d.ts +145 -3
- package/RecordsController.js +399 -61
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +1932 -1109
- package/RecordsStore.d.ts +99 -14
- package/RecordsStore.js +8 -10
- package/RecordsStore.js.map +1 -1
- package/ServerConfig.d.ts +698 -9867
- package/ServerConfig.js +457 -377
- package/ServerConfig.js.map +1 -1
- package/SloydInterface.js +1 -1
- package/SloydInterface.js.map +1 -1
- package/StabilityAIImageInterface.js +6 -9
- package/StabilityAIImageInterface.js.map +1 -1
- package/StripeInterface.d.ts +431 -287
- package/StripeInterface.js +21 -1
- package/StripeInterface.js.map +1 -1
- package/SubscriptionConfigBuilder.d.ts +10 -1
- package/SubscriptionConfigBuilder.js +72 -41
- package/SubscriptionConfigBuilder.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +606 -6334
- package/SubscriptionConfiguration.js +460 -277
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +677 -4
- package/SubscriptionController.js +2986 -186
- package/SubscriptionController.js.map +1 -1
- package/SystemNotificationMessenger.d.ts +14 -70
- package/SystemNotificationMessenger.js +17 -20
- package/SystemNotificationMessenger.js.map +1 -1
- package/TestUtils.d.ts +18 -3
- package/TestUtils.js +84 -8
- package/TestUtils.js.map +1 -1
- package/TypeUtils.d.ts +991 -0
- package/TypeUtils.js +2 -0
- package/TypeUtils.js.map +1 -0
- package/Utils.d.ts +59 -0
- package/Utils.js +507 -3
- package/Utils.js.map +1 -1
- package/Validations.d.ts +24 -108
- package/Validations.js +62 -45
- package/Validations.js.map +1 -1
- package/ViewTemplateRenderer.d.ts +39 -0
- package/ViewTemplateRenderer.js +19 -0
- package/ViewTemplateRenderer.js.map +1 -0
- package/contracts/ContractRecordsController.d.ts +58 -0
- package/contracts/ContractRecordsController.js +144 -0
- package/contracts/ContractRecordsController.js.map +1 -0
- package/contracts/ContractRecordsStore.d.ts +285 -0
- package/contracts/ContractRecordsStore.js +19 -0
- package/contracts/ContractRecordsStore.js.map +1 -0
- package/contracts/MemoryContractRecordsStore.d.ts +27 -0
- package/contracts/MemoryContractRecordsStore.js +124 -0
- package/contracts/MemoryContractRecordsStore.js.map +1 -0
- package/contracts/index.d.ts +4 -0
- package/contracts/index.js +21 -0
- package/contracts/index.js.map +1 -0
- package/crud/CrudHelpers.d.ts +25 -26
- package/crud/CrudHelpers.js +1 -1
- package/crud/CrudHelpers.js.map +1 -1
- package/crud/CrudRecordsController.js +13 -16
- package/crud/CrudRecordsController.js.map +1 -1
- package/crud/CrudRecordsControllerTests.d.ts +2 -2
- package/crud/CrudRecordsControllerTests.js +605 -580
- package/crud/CrudRecordsControllerTests.js.map +1 -1
- package/crud/MemoryCrudRecordsStore.js +1 -2
- package/crud/MemoryCrudRecordsStore.js.map +1 -1
- package/crud/sub/MemorySubCrudRecordsStore.js +4 -6
- package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -1
- package/crud/sub/SubCrudRecordsController.js +8 -8
- package/crud/sub/SubCrudRecordsController.js.map +1 -1
- package/database/DatabaseRecordsController.js +1 -2
- package/database/DatabaseRecordsController.js.map +1 -1
- package/database/SqliteDatabaseInterface.js +1 -2
- package/database/SqliteDatabaseInterface.js.map +1 -1
- package/dns/DNSDomainNameValidator.d.ts +11 -0
- package/dns/DNSDomainNameValidator.js +59 -0
- package/dns/DNSDomainNameValidator.js.map +1 -0
- package/dns/DomainNameValidator.d.ts +36 -0
- package/dns/DomainNameValidator.js +19 -0
- package/dns/DomainNameValidator.js.map +1 -0
- package/dns/index.d.ts +3 -0
- package/dns/index.js +20 -0
- package/dns/index.js.map +1 -0
- package/financial/FinancialController.d.ts +272 -0
- package/financial/FinancialController.js +762 -0
- package/financial/FinancialController.js.map +1 -0
- package/financial/FinancialInterface.d.ts +352 -0
- package/financial/FinancialInterface.js +642 -0
- package/financial/FinancialInterface.js.map +1 -0
- package/financial/FinancialStore.d.ts +186 -0
- package/financial/FinancialStore.js +19 -0
- package/financial/FinancialStore.js.map +1 -0
- package/financial/MemoryFinancialInterface.d.ts +23 -0
- package/financial/MemoryFinancialInterface.js +592 -0
- package/financial/MemoryFinancialInterface.js.map +1 -0
- package/financial/TigerBeetleFinancialInterface.d.ts +46 -0
- package/financial/TigerBeetleFinancialInterface.js +109 -0
- package/financial/TigerBeetleFinancialInterface.js.map +1 -0
- package/financial/TigerBeetleTestUtils.d.ts +40 -0
- package/financial/TigerBeetleTestUtils.js +185 -0
- package/financial/TigerBeetleTestUtils.js.map +1 -0
- package/financial/Types.d.ts +1 -0
- package/financial/Types.js +801 -0
- package/financial/Types.js.map +1 -0
- package/financial/index.d.ts +6 -0
- package/financial/index.js +24 -0
- package/financial/index.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +3 -0
- package/index.js.map +1 -1
- package/notifications/NotificationRecordsController.js +14 -14
- package/notifications/NotificationRecordsController.js.map +1 -1
- package/notifications/WebPushInterface.d.ts +24 -155
- package/notifications/WebPushInterface.js +2 -2
- package/notifications/WebPushInterface.js.map +1 -1
- package/package.json +72 -70
- package/packages/version/MemoryPackageVersionRecordsStore.js +12 -15
- package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -1
- package/packages/version/PackageVersionRecordsController.d.ts +19 -0
- package/packages/version/PackageVersionRecordsController.js +102 -22
- package/packages/version/PackageVersionRecordsController.js.map +1 -1
- package/packages/version/PackageVersionRecordsStore.js +6 -8
- package/packages/version/PackageVersionRecordsStore.js.map +1 -1
- package/purchasable-items/MemoryPurchasableItemRecordsStore.d.ts +7 -0
- package/purchasable-items/MemoryPurchasableItemRecordsStore.js +33 -0
- package/purchasable-items/MemoryPurchasableItemRecordsStore.js.map +1 -0
- package/purchasable-items/PurchasableItemRecordsController.d.ts +16 -0
- package/purchasable-items/PurchasableItemRecordsController.js +72 -0
- package/purchasable-items/PurchasableItemRecordsController.js.map +1 -0
- package/purchasable-items/PurchasableItemRecordsStore.d.ts +66 -0
- package/purchasable-items/PurchasableItemRecordsStore.js +2 -0
- package/purchasable-items/PurchasableItemRecordsStore.js.map +1 -0
- package/purchasable-items/index.d.ts +4 -0
- package/purchasable-items/index.js +21 -0
- package/purchasable-items/index.js.map +1 -0
- package/queue/MemoryQueue.js +1 -1
- package/queue/MemoryQueue.js.map +1 -1
- package/search/MemorySearchInterface.js +1 -2
- package/search/MemorySearchInterface.js.map +1 -1
- package/search/SearchRecordsController.d.ts +66 -244
- package/search/SearchRecordsController.js +35 -36
- package/search/SearchRecordsController.js.map +1 -1
- package/search/SearchSyncProcessor.d.ts +7 -83
- package/search/TypesenseSearchInterface.js +8 -11
- package/search/TypesenseSearchInterface.js.map +1 -1
- package/tracing/TracingDecorators.js +5 -8
- package/tracing/TracingDecorators.js.map +1 -1
- package/webhooks/WebhookEnvironment.d.ts +36 -560
- package/webhooks/WebhookEnvironment.js +1 -1
- package/webhooks/WebhookEnvironment.js.map +1 -1
- package/webhooks/WebhookRecordsController.js +14 -16
- package/webhooks/WebhookRecordsController.js.map +1 -1
- package/websockets/MemoryLockStore.d.ts +18 -0
- package/websockets/MemoryLockStore.js +2 -0
- package/websockets/MemoryLockStore.js.map +1 -0
- package/websockets/MemoryTempInstRecordsStore.js +15 -27
- package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
- package/websockets/MemoryWebsocketConnectionStore.js +6 -8
- package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
- package/websockets/MemoryWebsocketMessenger.js +1 -2
- package/websockets/MemoryWebsocketMessenger.js.map +1 -1
- package/websockets/SplitInstRecordsStore.js +2 -2
- package/websockets/SplitInstRecordsStore.js.map +1 -1
- package/websockets/WebsocketController.d.ts +5 -0
- package/websockets/WebsocketController.js +122 -83
- package/websockets/WebsocketController.js.map +1 -1
- package/RecordsServer.js +0 -6435
- package/RecordsServer.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* CasualOS is a set of web-based tools designed to facilitate the creation of real-time, multi-user, context-aware interactive experiences.
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2019-2025 Casual Simulation, Inc.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
* License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { failure, success, } from '@casual-simulation/aux-common';
|
|
19
|
+
import { CrudRecordsController } from '../crud';
|
|
20
|
+
import { getContractFeatures } from '../SubscriptionConfiguration';
|
|
21
|
+
import { v7 as uuid } from 'uuid';
|
|
22
|
+
/**
|
|
23
|
+
* Defines a controller that can be used to interact with NotificationRecords.
|
|
24
|
+
*/
|
|
25
|
+
export class ContractRecordsController extends CrudRecordsController {
|
|
26
|
+
constructor(config) {
|
|
27
|
+
super({
|
|
28
|
+
...config,
|
|
29
|
+
name: 'ContractRecordsController',
|
|
30
|
+
resourceKind: 'contract',
|
|
31
|
+
});
|
|
32
|
+
this._authStore = config.authStore;
|
|
33
|
+
this._privo = config.privo;
|
|
34
|
+
}
|
|
35
|
+
// TODO: decide how to prevent users from deleting/updating contracts
|
|
36
|
+
// eraseItem(request: CrudEraseItemRequest): Promise<CrudEraseItemResult> {
|
|
37
|
+
// return {
|
|
38
|
+
// success: false,
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
41
|
+
async _transformInputItem(item, existingItem, action, context, authorization) {
|
|
42
|
+
if (action === 'create') {
|
|
43
|
+
let user = (await this._authStore.findUser(item.holdingUser)) ??
|
|
44
|
+
(await this._authStore.findUserByAddress(item.holdingUser, 'email')) ??
|
|
45
|
+
(await this._authStore.findUserByAddress(item.holdingUser, 'phone'));
|
|
46
|
+
if (!user && this._privo) {
|
|
47
|
+
const serviceId = (await this._privo.lookupServiceId({
|
|
48
|
+
email: item.holdingUser,
|
|
49
|
+
})) ??
|
|
50
|
+
(await this._privo.lookupServiceId({
|
|
51
|
+
displayName: item.holdingUser,
|
|
52
|
+
})) ??
|
|
53
|
+
(await this._privo.lookupServiceId({
|
|
54
|
+
phoneNumber: item.holdingUser,
|
|
55
|
+
}));
|
|
56
|
+
if (serviceId) {
|
|
57
|
+
user = await this._authStore.findUserByPrivoServiceId(serviceId);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!user) {
|
|
61
|
+
return failure({
|
|
62
|
+
success: false,
|
|
63
|
+
errorCode: 'user_not_found',
|
|
64
|
+
errorMessage: `The holding user (${item.holdingUser}) was not found.`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return success({
|
|
68
|
+
id: uuid(),
|
|
69
|
+
address: item.address,
|
|
70
|
+
markers: item.markers,
|
|
71
|
+
initialValue: item.initialValue,
|
|
72
|
+
rate: item.rate,
|
|
73
|
+
description: item.description,
|
|
74
|
+
issuedAtMs: Date.now(),
|
|
75
|
+
status: 'pending',
|
|
76
|
+
issuingUserId: context.userId,
|
|
77
|
+
holdingUserId: user.id,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return failure({
|
|
81
|
+
errorCode: 'not_supported',
|
|
82
|
+
errorMessage: 'Updating contracts is not supported.',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async _checkSubscriptionMetrics(action, context, authorization, item) {
|
|
86
|
+
const config = await this.config.getSubscriptionConfiguration();
|
|
87
|
+
const metrics = await this.store.getSubscriptionMetrics({
|
|
88
|
+
ownerId: context.recordOwnerId,
|
|
89
|
+
studioId: context.recordStudioId,
|
|
90
|
+
});
|
|
91
|
+
const features = getContractFeatures(config, metrics.subscriptionStatus, metrics.subscriptionId, metrics.subscriptionType, metrics.currentPeriodStartMs, metrics.currentPeriodEndMs);
|
|
92
|
+
if (!features.allowed) {
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
errorCode: 'not_authorized',
|
|
96
|
+
errorMessage: 'Contracts are not allowed for this subscription.',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (action === 'delete') {
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
errorCode: 'not_supported',
|
|
103
|
+
errorMessage: 'Deleting contracts is not supported.',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (action === 'create') {
|
|
107
|
+
if (typeof features.maxItems === 'number' &&
|
|
108
|
+
metrics.totalItems >= features.maxItems) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
errorCode: 'subscription_limit_reached',
|
|
112
|
+
errorMessage: 'The maximum number of contract items has been reached for your subscription.',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// TODO: Support checking the holding user's subscription
|
|
116
|
+
// const holdingUserMetrics = await this.store.getSubscriptionMetrics({
|
|
117
|
+
// ownerId: item.holdingUserId,
|
|
118
|
+
// });
|
|
119
|
+
// const holdingUserFeatures = getContractFeatures(
|
|
120
|
+
// config,
|
|
121
|
+
// holdingUserMetrics.subscriptionStatus,
|
|
122
|
+
// holdingUserMetrics.subscriptionId,
|
|
123
|
+
// holdingUserMetrics.subscriptionType,
|
|
124
|
+
// holdingUserMetrics.currentPeriodStartMs,
|
|
125
|
+
// holdingUserMetrics.currentPeriodEndMs
|
|
126
|
+
// );
|
|
127
|
+
// if (!holdingUserFeatures.allowed) {
|
|
128
|
+
// return {
|
|
129
|
+
// success: false,
|
|
130
|
+
// errorCode: 'invalid_user',
|
|
131
|
+
// errorMessage:
|
|
132
|
+
// 'The holding user does not have access to contracting features.',
|
|
133
|
+
// };
|
|
134
|
+
// }
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
success: true,
|
|
138
|
+
config,
|
|
139
|
+
metrics,
|
|
140
|
+
features,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=ContractRecordsController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContractRecordsController.js","sourceRoot":"","sources":["ContractRecordsController.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACH,OAAO,EACP,OAAO,GAIV,MAAM,+BAA+B,CAAC;AAYvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAUhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAiDlC;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,qBAI9C;IAIG,YAAY,MAAoC;QAC5C,KAAK,CAAC;YACF,GAAG,MAAM;YACT,IAAI,EAAE,2BAA2B;YACjC,YAAY,EAAE,UAAU;SAC3B,CAAC,C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AAE,CAAC;YACpB,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,gBAAgB;gBAC3B,YAAY,EACR,kDAAkD;aACzD,CAAC;QACN,CAAC;QAED,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YACtB,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,eAAe;gBAC1B,YAAY,EAAE,sCAAsC;aACvD,CAAC;QACN,CAAC;QAED,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YACtB,IACI,OAAO,QAAQ,CAAC,QAAQ,KAAK,QAAQ;gBACrC,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC,QAAQ,EACzC,CAAC;gBACC,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,4BAA4B;oBACvC,YAAY,EACR,8EAA8E;iBACrF,CAAC;YACN,CAAC;YAED,yDAAyD;YACzD,uEAAuE;YACvE,mCAAmC;YACnC,MAAM;YAEN,mDAAmD;YACnD,cAAc;YACd,6CAA6C;YAC7C,yCAAyC;YACzC,2CAA2C;YAC3C,+CAA+C;YAC/C,4CAA4C;YAC5C,KAAK;YAEL,sCAAsC;YACtC,eAAe;YACf,0BAA0B;YAC1B,qCAAqC;YACrC,wBAAwB;YACxB,gFAAgF;YAChF,SAAS;YACT,IAAI;QACR,CAAC;QAED,OAAO;YACH,OAAO,EAAE,IAAI;YACb,MAAM;YACN,OAAO;YACP,QAAQ;SACX,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import type { CrudRecord, CrudRecordsStore, CrudSubscriptionMetrics, PartialExcept } from '../crud';
|
|
2
|
+
import type { SubscriptionFilter } from '../MetricsStore';
|
|
3
|
+
/**
|
|
4
|
+
* Defines a store that contains notification records.
|
|
5
|
+
*/
|
|
6
|
+
export interface ContractRecordsStore extends CrudRecordsStore<ContractRecord> {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the item metrics for the subscription of the given user or studio.
|
|
9
|
+
* @param filter The filter to use.
|
|
10
|
+
*/
|
|
11
|
+
getSubscriptionMetrics(filter: SubscriptionFilter): Promise<ContractSubscriptionMetrics>;
|
|
12
|
+
/**
|
|
13
|
+
* Marks the given pending contract as open.
|
|
14
|
+
* @param recordName The name of the record.
|
|
15
|
+
* @param address The address of the contract.
|
|
16
|
+
*/
|
|
17
|
+
markPendingContractAsOpen(recordName: string, address: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Marks the given contract as closed and also voids any open invoices.
|
|
20
|
+
* @param recordName The name of the record.
|
|
21
|
+
* @param address The address of the contract.
|
|
22
|
+
*/
|
|
23
|
+
markContractAsClosed(recordName: string, address: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Getes the contract record with the given ID.
|
|
26
|
+
* @param id The ID of the contract to get.
|
|
27
|
+
*/
|
|
28
|
+
getItemById(id: string): Promise<{
|
|
29
|
+
recordName: string;
|
|
30
|
+
contract: ContractRecord;
|
|
31
|
+
} | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new invoice.
|
|
34
|
+
* @param invoice The invoice to create.
|
|
35
|
+
*/
|
|
36
|
+
createInvoice(invoice: ContractInvoice): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the invoice with the given ID.
|
|
39
|
+
* @param id The ID of the invoice to get.
|
|
40
|
+
*/
|
|
41
|
+
getInvoiceById(id: string): Promise<{
|
|
42
|
+
invoice: ContractInvoice;
|
|
43
|
+
contract: ContractRecord;
|
|
44
|
+
} | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Updates the given invoice.
|
|
47
|
+
* @param invoice The invoice to update.
|
|
48
|
+
*/
|
|
49
|
+
updateInvoice(invoice: PartialExcept<ContractInvoice, 'id'>): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Deletes the invoice with the given ID.
|
|
52
|
+
* @param id The ID of the invoice to delete.
|
|
53
|
+
*/
|
|
54
|
+
deleteInvoice(id: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the list of invoices for the given contract.
|
|
57
|
+
* @param contractId The ID of the contract to get invoices for.
|
|
58
|
+
*/
|
|
59
|
+
listInvoicesForContract(contractId: string): Promise<ContractInvoice[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Marks the open invoice with the given ID as paid or void.
|
|
62
|
+
* @param invoiceId The ID of the invoice to update.
|
|
63
|
+
* @param status The status to mark the invoice as. Must be either "paid" or "void".
|
|
64
|
+
*/
|
|
65
|
+
markOpenInvoiceAs(invoiceId: string, status: 'paid' | 'void'): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Defines a record that represents a notification.
|
|
69
|
+
* That is, a way for users to be notified of something.
|
|
70
|
+
*
|
|
71
|
+
* @dochash types/records/packages
|
|
72
|
+
* @docName ContractRecord
|
|
73
|
+
*/
|
|
74
|
+
export interface ContractRecord extends CrudRecord {
|
|
75
|
+
/**
|
|
76
|
+
* The ID of the contract.
|
|
77
|
+
*/
|
|
78
|
+
id: string;
|
|
79
|
+
/**
|
|
80
|
+
* The ID of the user that issued the contract.
|
|
81
|
+
* That is, the user who created the contract in the record.
|
|
82
|
+
* (Similar to subjectId in other record types)
|
|
83
|
+
*/
|
|
84
|
+
issuingUserId: string;
|
|
85
|
+
/**
|
|
86
|
+
* The ID of the user that is holding the contract.
|
|
87
|
+
* That is, the user who is currently responsible for fulfilling the contract.
|
|
88
|
+
*/
|
|
89
|
+
holdingUserId: string;
|
|
90
|
+
/**
|
|
91
|
+
* The current status of the contract.
|
|
92
|
+
*/
|
|
93
|
+
status: ContractStatus;
|
|
94
|
+
/**
|
|
95
|
+
* The unix time in miliseconds when the contract was initially issued.
|
|
96
|
+
*/
|
|
97
|
+
issuedAtMs: number;
|
|
98
|
+
/**
|
|
99
|
+
* The unix time in miliseconds when the contract was closed.
|
|
100
|
+
*/
|
|
101
|
+
closedAtMs?: number | null;
|
|
102
|
+
/**
|
|
103
|
+
* The rate at which the contract is paid.
|
|
104
|
+
* This is the amount of money that each gig is worth.
|
|
105
|
+
*/
|
|
106
|
+
rate: number;
|
|
107
|
+
/**
|
|
108
|
+
* The initial value of the contract.
|
|
109
|
+
* This is the total value of what the contract was worth when it was created.
|
|
110
|
+
*/
|
|
111
|
+
initialValue: number;
|
|
112
|
+
/**
|
|
113
|
+
* The description of the contract.
|
|
114
|
+
*/
|
|
115
|
+
description?: string | null;
|
|
116
|
+
/**
|
|
117
|
+
* The ID of the checkout session that was created to pay for the contract, if applicable.
|
|
118
|
+
*/
|
|
119
|
+
stripeCheckoutSessionId?: string | null;
|
|
120
|
+
/**
|
|
121
|
+
* The ID of the payment intent that was created to pay for the contract, if applicable.
|
|
122
|
+
*/
|
|
123
|
+
stripePaymentIntentId?: string | null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The status of a contract.
|
|
127
|
+
* - "pending" means the contract is awaiting purchase.
|
|
128
|
+
* - "open" means the contract is active and can be invoiced.
|
|
129
|
+
* - "closed" means the contract is no longer active and cannot be invoiced.
|
|
130
|
+
*/
|
|
131
|
+
export type ContractStatus = 'pending' | 'open' | 'closed';
|
|
132
|
+
/**
|
|
133
|
+
* Represents an invoice against a contract.
|
|
134
|
+
*/
|
|
135
|
+
export interface ContractInvoice {
|
|
136
|
+
/**
|
|
137
|
+
* The ID of the invoice.
|
|
138
|
+
*/
|
|
139
|
+
id: string;
|
|
140
|
+
/**
|
|
141
|
+
* The ID of the contract that this invoice is for.
|
|
142
|
+
*/
|
|
143
|
+
contractId: string;
|
|
144
|
+
/**
|
|
145
|
+
* The amount charged in the invoice.
|
|
146
|
+
*/
|
|
147
|
+
amount: number;
|
|
148
|
+
/**
|
|
149
|
+
* The current status of the invoice.
|
|
150
|
+
*/
|
|
151
|
+
status: InvoiceStatus;
|
|
152
|
+
/**
|
|
153
|
+
* The unix time in milliseconds when the invoice was opened.
|
|
154
|
+
*/
|
|
155
|
+
openedAtMs: number;
|
|
156
|
+
/**
|
|
157
|
+
* The unix time in miliseconds when the invoice was paid, if applicable.
|
|
158
|
+
*/
|
|
159
|
+
paidAtMs?: number | null;
|
|
160
|
+
/**
|
|
161
|
+
* The unix time in milliseconds when the invoice was voided, if applicable.
|
|
162
|
+
*/
|
|
163
|
+
voidedAtMs?: number | null;
|
|
164
|
+
/**
|
|
165
|
+
* The destination for the payout of the invoice.
|
|
166
|
+
*/
|
|
167
|
+
payoutDestination: InvoicePayoutDestination;
|
|
168
|
+
/**
|
|
169
|
+
* The ID of the external transfer that was created to payout the invoice, if applicable.
|
|
170
|
+
* Null if the invoice is not paid or the payout destination is "account".
|
|
171
|
+
*/
|
|
172
|
+
destinationTransferId?: string | null;
|
|
173
|
+
/**
|
|
174
|
+
* The reason why the invoice was voided, if applicable.
|
|
175
|
+
*/
|
|
176
|
+
voidReason?: InvoiceVoidReason | null;
|
|
177
|
+
/**
|
|
178
|
+
* The ID of the transaction that paid the invoice, if applicable.
|
|
179
|
+
*/
|
|
180
|
+
transactionId?: string | null;
|
|
181
|
+
/**
|
|
182
|
+
* The ID of the external payout that was created as part of the invoice payment process, if applicatble.
|
|
183
|
+
* Null if the invoice is not paid or the payout destination is "account".
|
|
184
|
+
*/
|
|
185
|
+
externalPayoutId?: string | null;
|
|
186
|
+
/**
|
|
187
|
+
* An additional note about the invoice.
|
|
188
|
+
*/
|
|
189
|
+
note?: string | null;
|
|
190
|
+
/**
|
|
191
|
+
* The unix time in milliseconds when the invoice was created.
|
|
192
|
+
*/
|
|
193
|
+
createdAtMs: number;
|
|
194
|
+
/**
|
|
195
|
+
* The unix time in milliseconds when the invoice was last updated.
|
|
196
|
+
*/
|
|
197
|
+
updatedAtMs: number;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Represents the process of transferring funds from a user's account to an external destination.
|
|
201
|
+
*/
|
|
202
|
+
export interface ExternalPayout {
|
|
203
|
+
/**
|
|
204
|
+
* The ID of the payout.
|
|
205
|
+
*/
|
|
206
|
+
id: string;
|
|
207
|
+
/**
|
|
208
|
+
* The ID of the user that this payout is for.
|
|
209
|
+
*/
|
|
210
|
+
userId: string;
|
|
211
|
+
/**
|
|
212
|
+
* The ID of the invoice that this payout is assocated with, if applicable.
|
|
213
|
+
*/
|
|
214
|
+
invoiceId?: string | null;
|
|
215
|
+
/**
|
|
216
|
+
* The ID of the transfer in the financial system that represents the payout.
|
|
217
|
+
*/
|
|
218
|
+
transferId: string;
|
|
219
|
+
/**
|
|
220
|
+
* The ID of the transaction that was created to transfer the funds.
|
|
221
|
+
*/
|
|
222
|
+
transactionId: string;
|
|
223
|
+
/**
|
|
224
|
+
* The external destination for the transfer.
|
|
225
|
+
*/
|
|
226
|
+
externalDestination: 'stripe';
|
|
227
|
+
/**
|
|
228
|
+
* The ID of the stripe transfer that was created to transfer the funds.
|
|
229
|
+
*/
|
|
230
|
+
stripeTransferId: string | null;
|
|
231
|
+
/**
|
|
232
|
+
* The stripe account ID that the payout is being sent to.
|
|
233
|
+
*/
|
|
234
|
+
destinationStripeAccountId: string | null;
|
|
235
|
+
/**
|
|
236
|
+
* The amount of the transfer.
|
|
237
|
+
*/
|
|
238
|
+
amount: number;
|
|
239
|
+
/**
|
|
240
|
+
* The ID of the transfer that posted the original transfer.
|
|
241
|
+
*/
|
|
242
|
+
postedTransferId?: string | null;
|
|
243
|
+
/**
|
|
244
|
+
* The ID of the transfer that voided the original transfer, if applicable.
|
|
245
|
+
*/
|
|
246
|
+
voidedTransferId?: string | null;
|
|
247
|
+
/**
|
|
248
|
+
* The unix time in milliseconds when the payout was initiated.
|
|
249
|
+
*/
|
|
250
|
+
initatedAtMs?: number | null;
|
|
251
|
+
/**
|
|
252
|
+
* The unix time in milliseconds when the payout was posted.
|
|
253
|
+
*/
|
|
254
|
+
postedAtMs?: number | null;
|
|
255
|
+
/**
|
|
256
|
+
* The unix time in miliseconds when the payout was voided, if applicable.
|
|
257
|
+
*/
|
|
258
|
+
voidedAtMs?: number | null;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The status of an invoice.
|
|
262
|
+
* - "open" means the invoice is pending payment.
|
|
263
|
+
* - "paid" means the invoice has been paid.
|
|
264
|
+
* - "void" means the invoice has been voided and is no longer valid.
|
|
265
|
+
*/
|
|
266
|
+
export type InvoiceStatus = 'open' | 'paid' | 'void';
|
|
267
|
+
/**
|
|
268
|
+
* The destination for the payout of an invoice.
|
|
269
|
+
* - "stripe" means that the invoiced amount will be transfered to the users Stripe account once paid.
|
|
270
|
+
* - "account" means that the invoiced amount will remain in thier CasualOS account.
|
|
271
|
+
*/
|
|
272
|
+
export type InvoicePayoutDestination = 'stripe' | 'account';
|
|
273
|
+
/**
|
|
274
|
+
* The reason why an invoice was voided.
|
|
275
|
+
* - "rejected" means the invoice was rejected by the contract issuer, the system, or an admin.
|
|
276
|
+
* - "cancelled" means the invoice was cancelled by the user, the system, or an admin.
|
|
277
|
+
*/
|
|
278
|
+
export type InvoiceVoidReason = 'rejected' | 'cancelled';
|
|
279
|
+
export interface ContractSubscriptionMetrics extends CrudSubscriptionMetrics {
|
|
280
|
+
/**
|
|
281
|
+
* The total number of packages stored in the subscription.
|
|
282
|
+
*/
|
|
283
|
+
totalItems: number;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=ContractRecordsStore.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* CasualOS is a set of web-based tools designed to facilitate the creation of real-time, multi-user, context-aware interactive experiences.
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2019-2025 Casual Simulation, Inc.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
* License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=ContractRecordsStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContractRecordsStore.js","sourceRoot":"","sources":["ContractRecordsStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MemoryCrudRecordsStore } from '../crud/MemoryCrudRecordsStore';
|
|
2
|
+
import type { ContractRecordsStore, ContractRecord, ContractSubscriptionMetrics, ContractInvoice } from './ContractRecordsStore';
|
|
3
|
+
import type { SubscriptionFilter } from '../MetricsStore';
|
|
4
|
+
import type { PartialExcept } from '../crud';
|
|
5
|
+
/**
|
|
6
|
+
* A Memory-based implementation of the ContractRecordsStore.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MemoryContractRecordsStore extends MemoryCrudRecordsStore<ContractRecord> implements ContractRecordsStore {
|
|
9
|
+
private _invoices;
|
|
10
|
+
createInvoice(invoice: ContractInvoice): Promise<void>;
|
|
11
|
+
getInvoiceById(id: string): Promise<{
|
|
12
|
+
invoice: ContractInvoice;
|
|
13
|
+
contract: ContractRecord;
|
|
14
|
+
} | null>;
|
|
15
|
+
updateInvoice(invoice: PartialExcept<ContractInvoice, 'id'>): Promise<void>;
|
|
16
|
+
deleteInvoice(id: string): Promise<void>;
|
|
17
|
+
listInvoicesForContract(contractId: string): Promise<ContractInvoice[]>;
|
|
18
|
+
markOpenInvoiceAs(invoiceId: string, status: 'paid' | 'void'): Promise<void>;
|
|
19
|
+
getItemById(id: string): Promise<{
|
|
20
|
+
recordName: string;
|
|
21
|
+
contract: ContractRecord;
|
|
22
|
+
} | null>;
|
|
23
|
+
markPendingContractAsOpen(recordName: string, address: string): Promise<void>;
|
|
24
|
+
markContractAsClosed(recordName: string, address: string): Promise<void>;
|
|
25
|
+
getSubscriptionMetrics(filter: SubscriptionFilter): Promise<ContractSubscriptionMetrics>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=MemoryContractRecordsStore.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* CasualOS is a set of web-based tools designed to facilitate the creation of real-time, multi-user, context-aware interactive experiences.
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2019-2025 Casual Simulation, Inc.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
* License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { MemoryCrudRecordsStore } from '../crud/MemoryCrudRecordsStore';
|
|
19
|
+
/**
|
|
20
|
+
* A Memory-based implementation of the ContractRecordsStore.
|
|
21
|
+
*/
|
|
22
|
+
export class MemoryContractRecordsStore extends MemoryCrudRecordsStore {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this._invoices = new Map();
|
|
26
|
+
}
|
|
27
|
+
async createInvoice(invoice) {
|
|
28
|
+
this._invoices.set(invoice.id, { ...invoice });
|
|
29
|
+
}
|
|
30
|
+
async getInvoiceById(id) {
|
|
31
|
+
const invoice = this._invoices.get(id) || null;
|
|
32
|
+
if (!invoice) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const contract = await this.getItemById(invoice.contractId);
|
|
36
|
+
if (!contract) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
invoice,
|
|
41
|
+
contract: contract.contract,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async updateInvoice(invoice) {
|
|
45
|
+
let existing = this._invoices.get(invoice.id);
|
|
46
|
+
if (!existing) {
|
|
47
|
+
throw new Error('Invoice not found: ' + invoice.id);
|
|
48
|
+
}
|
|
49
|
+
this._invoices.set(invoice.id, {
|
|
50
|
+
...existing,
|
|
51
|
+
...invoice,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async deleteInvoice(id) {
|
|
55
|
+
this._invoices.delete(id);
|
|
56
|
+
}
|
|
57
|
+
async listInvoicesForContract(contractId) {
|
|
58
|
+
return Array.from(this._invoices.values()).filter((i) => i.contractId === contractId);
|
|
59
|
+
}
|
|
60
|
+
async markOpenInvoiceAs(invoiceId, status) {
|
|
61
|
+
const invoice = this._invoices.get(invoiceId);
|
|
62
|
+
if (invoice && invoice.status === 'open') {
|
|
63
|
+
this._invoices.set(invoiceId, {
|
|
64
|
+
...invoice,
|
|
65
|
+
status,
|
|
66
|
+
voidedAtMs: status === 'void' ? Date.now() : invoice.voidedAtMs,
|
|
67
|
+
paidAtMs: status === 'paid' ? Date.now() : invoice.paidAtMs,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getItemById(id) {
|
|
72
|
+
const records = this.getItemRecords();
|
|
73
|
+
for (let [recordName, items] of records) {
|
|
74
|
+
for (let item of items.values()) {
|
|
75
|
+
if (item.id === id) {
|
|
76
|
+
return { recordName, contract: item };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
async markPendingContractAsOpen(recordName, address) {
|
|
83
|
+
const record = this.getItemRecord(recordName);
|
|
84
|
+
const item = record.get(address);
|
|
85
|
+
if (item && item.status === 'pending') {
|
|
86
|
+
record.set(address, {
|
|
87
|
+
...item,
|
|
88
|
+
status: 'open',
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async markContractAsClosed(recordName, address) {
|
|
93
|
+
const record = this.getItemRecord(recordName);
|
|
94
|
+
const item = record.get(address);
|
|
95
|
+
if (item && item.status !== 'closed') {
|
|
96
|
+
record.set(address, {
|
|
97
|
+
...item,
|
|
98
|
+
status: 'closed',
|
|
99
|
+
closedAtMs: Date.now(),
|
|
100
|
+
});
|
|
101
|
+
const invoices = await this.listInvoicesForContract(item.id);
|
|
102
|
+
for (let invoice of invoices) {
|
|
103
|
+
if (invoice.status === 'open') {
|
|
104
|
+
await this.markOpenInvoiceAs(invoice.id, 'void');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async getSubscriptionMetrics(filter) {
|
|
110
|
+
const info = await super.getSubscriptionMetrics(filter);
|
|
111
|
+
let totalItems = 0;
|
|
112
|
+
const records = filter.ownerId
|
|
113
|
+
? await this.store.listRecordsByOwnerId(filter.ownerId)
|
|
114
|
+
: await this.store.listRecordsByStudioId(filter.studioId);
|
|
115
|
+
for (let record of records) {
|
|
116
|
+
totalItems += this.getItemRecord(record.name).size;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
...info,
|
|
120
|
+
totalItems,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=MemoryContractRecordsStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryContractRecordsStore.js","sourceRoot":"","sources":["MemoryContractRecordsStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAUxE;;GAEG;A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MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC;YACvD,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC,QAAS,CAAC,CAAC;QAC/D,KAAK,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;YACzB,UAAU,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;QACvD,CAAC;QAED,OAAO;YACH,GAAG,IAAI;YACP,UAAU;SACb,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* CasualOS is a set of web-based tools designed to facilitate the creation of real-time, multi-user, context-aware interactive experiences.
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2019-2025 Casual Simulation, Inc.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as
|
|
7
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
* License, or (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
export * from './ContractRecordsStore';
|
|
19
|
+
export * from './ContractRecordsController';
|
|
20
|
+
export * from './MemoryContractRecordsStore';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC"}
|