@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.
Files changed (239) hide show
  1. package/AIChatInterface.d.ts +7 -43
  2. package/AIChatInterface.js +8 -6
  3. package/AIChatInterface.js.map +1 -1
  4. package/AIController.js +44 -49
  5. package/AIController.js.map +1 -1
  6. package/AIOpenAIRealtimeInterface.d.ts +1 -1
  7. package/AnthropicAIChatInterface.js +4 -4
  8. package/AnthropicAIChatInterface.js.map +1 -1
  9. package/AuthController.d.ts +78 -10
  10. package/AuthController.js +230 -166
  11. package/AuthController.js.map +1 -1
  12. package/AuthStore.d.ts +317 -4
  13. package/BigIntPatch.d.ts +1 -0
  14. package/BigIntPatch.js +24 -0
  15. package/BigIntPatch.js.map +1 -0
  16. package/BlockadeLabsGenerateSkyboxInterface.js +4 -4
  17. package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
  18. package/CachingConfigStore.d.ts +8 -1
  19. package/CachingConfigStore.js +50 -0
  20. package/CachingConfigStore.js.map +1 -1
  21. package/ComIdConfig.d.ts +132 -86
  22. package/ComIdConfig.js +5 -5
  23. package/ComIdConfig.js.map +1 -1
  24. package/ConfigurationStore.d.ts +1393 -3
  25. package/ConfigurationStore.js +49 -0
  26. package/ConfigurationStore.js.map +1 -1
  27. package/DataRecordsController.js +28 -28
  28. package/DataRecordsController.js.map +1 -1
  29. package/EventRecordsController.js +9 -9
  30. package/EventRecordsController.js.map +1 -1
  31. package/FileRecordsController.js +18 -17
  32. package/FileRecordsController.js.map +1 -1
  33. package/GoogleAIChatInterface.js +4 -4
  34. package/GoogleAIChatInterface.js.map +1 -1
  35. package/HttpTestUtils.d.ts +48 -0
  36. package/HttpTestUtils.js +256 -0
  37. package/HttpTestUtils.js.map +1 -0
  38. package/LivekitController.js +2 -2
  39. package/LivekitController.js.map +1 -1
  40. package/LoomController.js +3 -4
  41. package/LoomController.js.map +1 -1
  42. package/MemoryStore.d.ts +60 -7
  43. package/MemoryStore.js +427 -59
  44. package/MemoryStore.js.map +1 -1
  45. package/MetricsStore.d.ts +11 -0
  46. package/ModerationConfiguration.d.ts +11 -85
  47. package/ModerationConfiguration.js +17 -17
  48. package/ModerationConfiguration.js.map +1 -1
  49. package/ModerationController.js +9 -11
  50. package/ModerationController.js.map +1 -1
  51. package/OpenAIChatInterface.js +8 -13
  52. package/OpenAIChatInterface.js.map +1 -1
  53. package/OpenAIImageInterface.js +4 -5
  54. package/OpenAIImageInterface.js.map +1 -1
  55. package/PolicyController.js +66 -73
  56. package/PolicyController.js.map +1 -1
  57. package/PolicyStore.d.ts +59 -33
  58. package/PolicyStore.js +35 -1
  59. package/PolicyStore.js.map +1 -1
  60. package/PrivoClient.d.ts +3 -1
  61. package/PrivoClient.js +2 -4
  62. package/PrivoClient.js.map +1 -1
  63. package/PrivoConfiguration.d.ts +6 -72
  64. package/PrivoConfiguration.js +30 -31
  65. package/PrivoConfiguration.js.map +1 -1
  66. package/README.md +276 -2
  67. package/RateLimitController.js +2 -2
  68. package/RateLimitController.js.map +1 -1
  69. package/RecordsClient.d.ts +3 -1
  70. package/RecordsClient.js +6 -6
  71. package/RecordsClient.js.map +1 -1
  72. package/RecordsController.d.ts +145 -3
  73. package/RecordsController.js +399 -61
  74. package/RecordsController.js.map +1 -1
  75. package/RecordsServer.d.ts +1932 -1109
  76. package/RecordsStore.d.ts +99 -14
  77. package/RecordsStore.js +8 -10
  78. package/RecordsStore.js.map +1 -1
  79. package/ServerConfig.d.ts +698 -9867
  80. package/ServerConfig.js +457 -377
  81. package/ServerConfig.js.map +1 -1
  82. package/SloydInterface.js +1 -1
  83. package/SloydInterface.js.map +1 -1
  84. package/StabilityAIImageInterface.js +6 -9
  85. package/StabilityAIImageInterface.js.map +1 -1
  86. package/StripeInterface.d.ts +431 -287
  87. package/StripeInterface.js +21 -1
  88. package/StripeInterface.js.map +1 -1
  89. package/SubscriptionConfigBuilder.d.ts +10 -1
  90. package/SubscriptionConfigBuilder.js +72 -41
  91. package/SubscriptionConfigBuilder.js.map +1 -1
  92. package/SubscriptionConfiguration.d.ts +606 -6334
  93. package/SubscriptionConfiguration.js +460 -277
  94. package/SubscriptionConfiguration.js.map +1 -1
  95. package/SubscriptionController.d.ts +677 -4
  96. package/SubscriptionController.js +2986 -186
  97. package/SubscriptionController.js.map +1 -1
  98. package/SystemNotificationMessenger.d.ts +14 -70
  99. package/SystemNotificationMessenger.js +17 -20
  100. package/SystemNotificationMessenger.js.map +1 -1
  101. package/TestUtils.d.ts +18 -3
  102. package/TestUtils.js +84 -8
  103. package/TestUtils.js.map +1 -1
  104. package/TypeUtils.d.ts +991 -0
  105. package/TypeUtils.js +2 -0
  106. package/TypeUtils.js.map +1 -0
  107. package/Utils.d.ts +59 -0
  108. package/Utils.js +507 -3
  109. package/Utils.js.map +1 -1
  110. package/Validations.d.ts +24 -108
  111. package/Validations.js +62 -45
  112. package/Validations.js.map +1 -1
  113. package/ViewTemplateRenderer.d.ts +39 -0
  114. package/ViewTemplateRenderer.js +19 -0
  115. package/ViewTemplateRenderer.js.map +1 -0
  116. package/contracts/ContractRecordsController.d.ts +58 -0
  117. package/contracts/ContractRecordsController.js +144 -0
  118. package/contracts/ContractRecordsController.js.map +1 -0
  119. package/contracts/ContractRecordsStore.d.ts +285 -0
  120. package/contracts/ContractRecordsStore.js +19 -0
  121. package/contracts/ContractRecordsStore.js.map +1 -0
  122. package/contracts/MemoryContractRecordsStore.d.ts +27 -0
  123. package/contracts/MemoryContractRecordsStore.js +124 -0
  124. package/contracts/MemoryContractRecordsStore.js.map +1 -0
  125. package/contracts/index.d.ts +4 -0
  126. package/contracts/index.js +21 -0
  127. package/contracts/index.js.map +1 -0
  128. package/crud/CrudHelpers.d.ts +25 -26
  129. package/crud/CrudHelpers.js +1 -1
  130. package/crud/CrudHelpers.js.map +1 -1
  131. package/crud/CrudRecordsController.js +13 -16
  132. package/crud/CrudRecordsController.js.map +1 -1
  133. package/crud/CrudRecordsControllerTests.d.ts +2 -2
  134. package/crud/CrudRecordsControllerTests.js +605 -580
  135. package/crud/CrudRecordsControllerTests.js.map +1 -1
  136. package/crud/MemoryCrudRecordsStore.js +1 -2
  137. package/crud/MemoryCrudRecordsStore.js.map +1 -1
  138. package/crud/sub/MemorySubCrudRecordsStore.js +4 -6
  139. package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -1
  140. package/crud/sub/SubCrudRecordsController.js +8 -8
  141. package/crud/sub/SubCrudRecordsController.js.map +1 -1
  142. package/database/DatabaseRecordsController.js +1 -2
  143. package/database/DatabaseRecordsController.js.map +1 -1
  144. package/database/SqliteDatabaseInterface.js +1 -2
  145. package/database/SqliteDatabaseInterface.js.map +1 -1
  146. package/dns/DNSDomainNameValidator.d.ts +11 -0
  147. package/dns/DNSDomainNameValidator.js +59 -0
  148. package/dns/DNSDomainNameValidator.js.map +1 -0
  149. package/dns/DomainNameValidator.d.ts +36 -0
  150. package/dns/DomainNameValidator.js +19 -0
  151. package/dns/DomainNameValidator.js.map +1 -0
  152. package/dns/index.d.ts +3 -0
  153. package/dns/index.js +20 -0
  154. package/dns/index.js.map +1 -0
  155. package/financial/FinancialController.d.ts +272 -0
  156. package/financial/FinancialController.js +762 -0
  157. package/financial/FinancialController.js.map +1 -0
  158. package/financial/FinancialInterface.d.ts +352 -0
  159. package/financial/FinancialInterface.js +642 -0
  160. package/financial/FinancialInterface.js.map +1 -0
  161. package/financial/FinancialStore.d.ts +186 -0
  162. package/financial/FinancialStore.js +19 -0
  163. package/financial/FinancialStore.js.map +1 -0
  164. package/financial/MemoryFinancialInterface.d.ts +23 -0
  165. package/financial/MemoryFinancialInterface.js +592 -0
  166. package/financial/MemoryFinancialInterface.js.map +1 -0
  167. package/financial/TigerBeetleFinancialInterface.d.ts +46 -0
  168. package/financial/TigerBeetleFinancialInterface.js +109 -0
  169. package/financial/TigerBeetleFinancialInterface.js.map +1 -0
  170. package/financial/TigerBeetleTestUtils.d.ts +40 -0
  171. package/financial/TigerBeetleTestUtils.js +185 -0
  172. package/financial/TigerBeetleTestUtils.js.map +1 -0
  173. package/financial/Types.d.ts +1 -0
  174. package/financial/Types.js +801 -0
  175. package/financial/Types.js.map +1 -0
  176. package/financial/index.d.ts +6 -0
  177. package/financial/index.js +24 -0
  178. package/financial/index.js.map +1 -0
  179. package/index.d.ts +4 -0
  180. package/index.js +3 -0
  181. package/index.js.map +1 -1
  182. package/notifications/NotificationRecordsController.js +14 -14
  183. package/notifications/NotificationRecordsController.js.map +1 -1
  184. package/notifications/WebPushInterface.d.ts +24 -155
  185. package/notifications/WebPushInterface.js +2 -2
  186. package/notifications/WebPushInterface.js.map +1 -1
  187. package/package.json +72 -70
  188. package/packages/version/MemoryPackageVersionRecordsStore.js +12 -15
  189. package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -1
  190. package/packages/version/PackageVersionRecordsController.d.ts +19 -0
  191. package/packages/version/PackageVersionRecordsController.js +102 -22
  192. package/packages/version/PackageVersionRecordsController.js.map +1 -1
  193. package/packages/version/PackageVersionRecordsStore.js +6 -8
  194. package/packages/version/PackageVersionRecordsStore.js.map +1 -1
  195. package/purchasable-items/MemoryPurchasableItemRecordsStore.d.ts +7 -0
  196. package/purchasable-items/MemoryPurchasableItemRecordsStore.js +33 -0
  197. package/purchasable-items/MemoryPurchasableItemRecordsStore.js.map +1 -0
  198. package/purchasable-items/PurchasableItemRecordsController.d.ts +16 -0
  199. package/purchasable-items/PurchasableItemRecordsController.js +72 -0
  200. package/purchasable-items/PurchasableItemRecordsController.js.map +1 -0
  201. package/purchasable-items/PurchasableItemRecordsStore.d.ts +66 -0
  202. package/purchasable-items/PurchasableItemRecordsStore.js +2 -0
  203. package/purchasable-items/PurchasableItemRecordsStore.js.map +1 -0
  204. package/purchasable-items/index.d.ts +4 -0
  205. package/purchasable-items/index.js +21 -0
  206. package/purchasable-items/index.js.map +1 -0
  207. package/queue/MemoryQueue.js +1 -1
  208. package/queue/MemoryQueue.js.map +1 -1
  209. package/search/MemorySearchInterface.js +1 -2
  210. package/search/MemorySearchInterface.js.map +1 -1
  211. package/search/SearchRecordsController.d.ts +66 -244
  212. package/search/SearchRecordsController.js +35 -36
  213. package/search/SearchRecordsController.js.map +1 -1
  214. package/search/SearchSyncProcessor.d.ts +7 -83
  215. package/search/TypesenseSearchInterface.js +8 -11
  216. package/search/TypesenseSearchInterface.js.map +1 -1
  217. package/tracing/TracingDecorators.js +5 -8
  218. package/tracing/TracingDecorators.js.map +1 -1
  219. package/webhooks/WebhookEnvironment.d.ts +36 -560
  220. package/webhooks/WebhookEnvironment.js +1 -1
  221. package/webhooks/WebhookEnvironment.js.map +1 -1
  222. package/webhooks/WebhookRecordsController.js +14 -16
  223. package/webhooks/WebhookRecordsController.js.map +1 -1
  224. package/websockets/MemoryLockStore.d.ts +18 -0
  225. package/websockets/MemoryLockStore.js +2 -0
  226. package/websockets/MemoryLockStore.js.map +1 -0
  227. package/websockets/MemoryTempInstRecordsStore.js +15 -27
  228. package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
  229. package/websockets/MemoryWebsocketConnectionStore.js +6 -8
  230. package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
  231. package/websockets/MemoryWebsocketMessenger.js +1 -2
  232. package/websockets/MemoryWebsocketMessenger.js.map +1 -1
  233. package/websockets/SplitInstRecordsStore.js +2 -2
  234. package/websockets/SplitInstRecordsStore.js.map +1 -1
  235. package/websockets/WebsocketController.d.ts +5 -0
  236. package/websockets/WebsocketController.js +122 -83
  237. package/websockets/WebsocketController.js.map +1 -1
  238. package/RecordsServer.js +0 -6435
  239. package/RecordsServer.js.map +0 -1
@@ -23,67 +23,169 @@ export const webhookFeaturesSchema = z
23
23
  .boolean()
24
24
  .describe('Whether webhook features are granted for the subscription.'),
25
25
  maxItems: z
26
- .number()
27
- .describe('The maximum number of webhook items that are allowed for the subscription. If not specified, then there is no limit.')
28
26
  .int()
29
- .optional(),
27
+ .optional()
28
+ .describe('The maximum number of webhook items that are allowed for the subscription. If not specified, then there is no limit.'),
30
29
  tokenLifetimeMs: z
31
- .number()
32
- .describe('The lifetime of session tokens that are issued to the webhook in miliseconds. Defaults to 5 minutes.')
33
30
  .int()
34
31
  .positive()
35
32
  .optional()
36
33
  .nullable()
37
- .default(5 * 60 * 1000),
34
+ .prefault(5 * 60 * 1000)
35
+ .describe('The lifetime of session tokens that are issued to the webhook in miliseconds. Defaults to 5 minutes.'),
38
36
  initTimeoutMs: z
39
- .number()
40
- .describe('The maximum number of miliseconds that the webhook has to initialize. Defaults to 5000ms.')
41
37
  .int()
42
38
  .positive()
43
39
  .optional()
44
40
  .nullable()
45
- .default(5000),
41
+ .prefault(5000)
42
+ .describe('The maximum number of miliseconds that the webhook has to initialize. Defaults to 5000ms.'),
46
43
  requestTimeoutMs: z
47
- .number()
48
- .describe('The maximum number of miliseconds that the webhook has to respond to a request after being initialized. Defaults to 5000ms')
49
44
  .int()
50
45
  .positive()
51
46
  .optional()
52
47
  .nullable()
53
- .default(5000),
48
+ .prefault(5000)
49
+ .describe('The maximum number of miliseconds that the webhook has to respond to a request after being initialized. Defaults to 5000ms'),
54
50
  fetchTimeoutMs: z
55
- .number()
56
- .describe('The maximum number of miliseconds that the system will take to fetch the AUX state for the webhook. Defaults to 5000ms.')
57
51
  .int()
58
52
  .positive()
59
53
  .optional()
60
54
  .nullable()
61
- .default(5000),
55
+ .prefault(5000)
56
+ .describe('The maximum number of miliseconds that the system will take to fetch the AUX state for the webhook. Defaults to 5000ms.'),
62
57
  addStateTimeoutMs: z
63
- .number()
64
- .describe('The maximum number of miliseconds that the system will take to add the AUX state to the webhook simulation. Defaults to 1000ms.')
65
58
  .int()
66
59
  .positive()
67
60
  .optional()
68
61
  .nullable()
69
- .default(1000),
62
+ .prefault(1000)
63
+ .describe('The maximum number of miliseconds that the system will take to add the AUX state to the webhook simulation. Defaults to 1000ms.'),
70
64
  maxRunsPerPeriod: z
71
- .number()
72
- .describe('The maximum number of webhook runs allowed per subscription period. If not specified, then there is no limit.')
73
65
  .int()
74
66
  .positive()
75
- .optional(),
67
+ .optional()
68
+ .describe('The maximum number of webhook runs allowed per subscription period. If not specified, then there is no limit.'),
76
69
  maxRunsPerHour: z
77
- .number()
78
- .describe('The maximum number of webhook runs allowed per hour for the subscription. If not specified, then there is no limit.')
79
70
  .int()
80
71
  .positive()
81
- .optional(),
72
+ .optional()
73
+ .describe('The maximum number of webhook runs allowed per hour for the subscription. If not specified, then there is no limit.'),
74
+ })
75
+ .optional()
76
+ .prefault({
77
+ allowed: false,
78
+ })
79
+ .describe('The configuration for webhook features. Defaults to not allowed.');
80
+ const currencyLimitsSchema = z
81
+ .object({})
82
+ .catchall(z.object({
83
+ maxCost: z
84
+ .int()
85
+ .positive()
86
+ .describe('The maximum cost that items can have in this currency.'),
87
+ minCost: z
88
+ .int()
89
+ .positive()
90
+ .describe("The minimum cost that items can have in this currency. Note that this doesn't prevent free items, it only sets the minimum cost for a non-free item."),
91
+ fee: z
92
+ .discriminatedUnion('type', [
93
+ z.object({
94
+ type: z.literal('percent'),
95
+ percent: z
96
+ .int()
97
+ .min(0)
98
+ .max(100)
99
+ .describe('The integer percentage of the cost that should be charged as a fee. Must be between 0 and 100'),
100
+ }),
101
+ z.object({
102
+ type: z.literal('fixed'),
103
+ amount: z
104
+ .int()
105
+ .positive()
106
+ .describe('The fixed amount in cents that should be charged as a fee. Must be a positive integer.'),
107
+ }),
108
+ ])
109
+ .optional()
110
+ .nullable()
111
+ .describe('The fee that should be charged for purchases in this currency. If omitted, then there is no fee.'),
112
+ }))
113
+ .optional()
114
+ .prefault({
115
+ usd: {
116
+ maxCost: 100 * 1000, /// $1,000 US Dollars (USD)
117
+ minCost: 50, // $0.50 US Dollars (USD)
118
+ },
119
+ })
120
+ .describe('The limits for each currency that can be used for purchasable items. If a currency is not specified, then it is not allowed');
121
+ export const storeFeaturesSchema = z
122
+ .object({
123
+ allowed: z
124
+ .boolean()
125
+ .describe('Whether purchasable items features are granted to the studio.'),
126
+ maxItems: z
127
+ .int()
128
+ .positive()
129
+ .optional()
130
+ .describe('The maximum number of purchasable items that can be created. If omitted, then there is no limit.'),
131
+ currencyLimits: currencyLimitsSchema,
132
+ })
133
+ .optional()
134
+ .prefault({
135
+ allowed: false,
136
+ })
137
+ .describe('The configuration for purchasable items features for studios. Defaults to not allowed.');
138
+ export const contractFeaturesSchema = z
139
+ .object({
140
+ allowed: z
141
+ .boolean()
142
+ .describe('Whether contract features are granted to the user/studio.'),
143
+ maxItems: z
144
+ .int()
145
+ .positive()
146
+ .optional()
147
+ .describe('The maximum number of contracts that can be created. If omitted, then there is no limit.'),
148
+ currencyLimits: currencyLimitsSchema,
82
149
  })
83
- .describe('The configuration for webhook features. Defaults to not allowed.')
84
150
  .optional()
85
- .default({
151
+ .prefault({
86
152
  allowed: false,
153
+ })
154
+ .describe('The configuration for contract features. Defaults to not allowed');
155
+ export const dataFeaturesSchema = z.object({
156
+ allowed: z
157
+ .boolean()
158
+ .describe('Whether data resources are allowed for the subscription. If false, then every request to create or update a data resource will be rejected.'),
159
+ maxItems: z
160
+ .int()
161
+ .positive()
162
+ .optional()
163
+ .describe('The maximum number of data resource items allowed for the subscription. If omitted, then there is no limit.'),
164
+ maxReadsPerPeriod: z
165
+ .int()
166
+ .positive()
167
+ .optional()
168
+ .describe('The maximum number of data item reads allowed per subscription period. If omitted, then there is no limit.'),
169
+ maxWritesPerPeriod: z
170
+ .int()
171
+ .positive()
172
+ .optional()
173
+ .describe('The maximum number of data item writes allowed per subscription period. If omitted, then there is no limit.'),
174
+ maxItemSizeInBytes: z
175
+ .int()
176
+ .positive()
177
+ .nullable()
178
+ .optional()
179
+ .prefault(500000)
180
+ .describe('The maximum number of bytes that can be stored in a single data item. If set to null, then there is no limit. If omitted, then the limit is 500,000 bytes (500KB)'),
181
+ creditFeePerRead: z
182
+ .int()
183
+ .optional()
184
+ .describe('The number of credits that are charged for each read operation. If not specified, then there is no fee.'),
185
+ creditFeePerWrite: z
186
+ .int()
187
+ .optional()
188
+ .describe('The number of credits that are charged for each write operation. If not specified, then there is no fee.'),
87
189
  });
88
190
  export const subscriptionFeaturesSchema = z.object({
89
191
  records: z
@@ -92,95 +194,66 @@ export const subscriptionFeaturesSchema = z.object({
92
194
  .boolean()
93
195
  .describe('Whether records are allowed for the subscription. If false, then every request to create or update a record will be rejected.'),
94
196
  maxRecords: z
95
- .number()
96
- .describe('The maximum number of records allowed for the subscription.')
97
197
  .int()
98
198
  .positive()
99
- .optional(),
100
- })
101
- .describe('The configuration for record features.')
102
- .optional(),
103
- data: z.object({
104
- allowed: z
105
- .boolean()
106
- .describe('Whether data resources are allowed for the subscription. If false, then every request to create or update a data resource will be rejected.'),
107
- maxItems: z
108
- .number({})
109
- .describe('The maximum number of data resource items allowed for the subscription. If omitted, then there is no limit.')
110
- .int()
111
- .positive()
112
- .optional(),
113
- maxReadsPerPeriod: z
114
- .number()
115
- .describe('The maximum number of data item reads allowed per subscription period. If omitted, then there is no limit.')
116
- .int()
117
- .positive()
118
- .optional(),
119
- maxWritesPerPeriod: z
120
- .number()
121
- .describe('The maximum number of data item writes allowed per subscription period. If omitted, then there is no limit.')
122
- .int()
123
- .positive()
124
- .optional(),
125
- maxItemSizeInBytes: z
126
- .number()
127
- .describe('The maximum number of bytes that can be stored in a single data item. If set to null, then there is no limit. If omitted, then the limit is 500,000 bytes (500KB)')
128
- .int()
129
- .positive()
130
- .nullable()
131
199
  .optional()
132
- .default(500000),
133
- }),
200
+ .describe('The maximum number of records allowed for the subscription.'),
201
+ })
202
+ .optional()
203
+ .describe('The configuration for record features.'),
204
+ data: dataFeaturesSchema,
134
205
  files: z.object({
135
206
  allowed: z
136
207
  .boolean()
137
208
  .describe('Whether file resources are allowed for the subscription. If false, then every request to create or update a file resource will be rejected.'),
138
209
  maxFiles: z
139
- .number()
140
- .describe('The maximum number of files allowed for the subscription. If omitted, then there is no limit.')
141
210
  .int()
142
211
  .positive()
143
- .optional(),
212
+ .optional()
213
+ .describe('The maximum number of files allowed for the subscription. If omitted, then there is no limit.'),
144
214
  maxBytesPerFile: z
145
- .number()
146
- .describe('The maximum number of bytes per file allowed for the subscription. If omitted, then there is no limit.')
147
215
  .int()
148
216
  .positive()
149
- .optional(),
217
+ .optional()
218
+ .describe('The maximum number of bytes per file allowed for the subscription. If omitted, then there is no limit.'),
150
219
  maxBytesTotal: z
151
- .number()
152
- .describe('The maximum number of file bytes that can be stored for the subscription. If omitted, then there is no limit.')
153
220
  .int()
154
221
  .positive()
155
- .optional(),
222
+ .optional()
223
+ .describe('The maximum number of file bytes that can be stored for the subscription. If omitted, then there is no limit.'),
224
+ creditFeePerBytePerPeriod: z
225
+ .int()
226
+ .optional()
227
+ .describe('The number of credits that are charged for each byte stored in files per subscription period. If not specified, then there is no fee.'),
228
+ creditFeePerFilePerPeriod: z
229
+ .int()
230
+ .optional()
231
+ .describe('The number of credits that are charged for each file per subscription period. If not specified, then there is no fee.'),
156
232
  }),
157
233
  events: z.object({
158
234
  allowed: z
159
235
  .boolean()
160
236
  .describe('Whether event resources are allowed for the subscription. If false, then every request to increment or count events will be rejected.'),
161
237
  maxEvents: z
162
- .number()
163
- .describe('The maximum number of distinct event names that are allowed for the subscription. If omitted, then there is no limit.')
164
238
  .int()
165
239
  .positive()
166
- .optional(),
240
+ .optional()
241
+ .describe('The maximum number of distinct event names that are allowed for the subscription. If omitted, then there is no limit.'),
167
242
  maxUpdatesPerPeriod: z
168
- .number()
169
- .describe('Not currently implemented.')
170
243
  .int()
171
244
  .positive()
172
- .optional(),
245
+ .optional()
246
+ .describe('Not currently implemented.'),
173
247
  }),
174
248
  policies: z.object({
175
249
  allowed: z
176
250
  .boolean()
177
251
  .describe('Whether policy resources are allowed for the subscription. If false, then every request to create or update a policy will be rejected.'),
178
252
  maxPolicies: z
179
- .number()
180
- .describe('Not currently implemented.')
181
253
  .int()
182
254
  .positive()
183
- .optional(),
255
+ .optional()
256
+ .describe('Not currently implemented.'),
184
257
  }),
185
258
  ai: z.object({
186
259
  chat: z.object({
@@ -188,37 +261,46 @@ export const subscriptionFeaturesSchema = z.object({
188
261
  .boolean()
189
262
  .describe('Whether AI chat requests are allowed for the subscription. If false, then every request to generate AI chat will be rejected.'),
190
263
  maxTokensPerPeriod: z
191
- .number()
192
- .describe('The maximum number of AI chat tokens allowed per subscription period. If omitted, then there is no limit.')
193
264
  .int()
194
265
  .positive()
195
- .optional(),
266
+ .optional()
267
+ .describe('The maximum number of AI chat tokens allowed per subscription period. If omitted, then there is no limit.'),
196
268
  allowedModels: z
197
269
  .array(z.string())
198
- .describe('The list of model IDs that are allowed for the subscription. If omitted, then all models are allowed.')
199
- .optional(),
270
+ .optional()
271
+ .describe('The list of model IDs that are allowed for the subscription. If omitted, then all models are allowed.'),
272
+ creditFeePerToken: z
273
+ .int()
274
+ .optional()
275
+ .describe('The number of credits that are charged for each token that is generated. If not specified, then there is no fee.'),
200
276
  }),
201
277
  images: z.object({
202
278
  allowed: z
203
279
  .boolean()
204
280
  .describe('Whether AI image requests are allowed for the subscription. If false, then every request to generate AI images will be rejected.'),
205
281
  maxSquarePixelsPerPeriod: z
206
- .number()
207
- .describe('The maximum number of square pixels (pixels squared) that are allowed to be generated per subscription period. If omitted, then there is no limit.')
208
282
  .int()
209
283
  .positive()
210
- .optional(),
284
+ .optional()
285
+ .describe('The maximum number of square pixels (pixels squared) that are allowed to be generated per subscription period. If omitted, then there is no limit.'),
286
+ creditFeePerSquarePixel: z
287
+ .int()
288
+ .optional()
289
+ .describe('The number of credits that are charged for each square pixel that is generated. If not specified, then there is no fee.'),
211
290
  }),
212
291
  skyboxes: z.object({
213
292
  allowed: z
214
293
  .boolean()
215
294
  .describe('Whether AI Skybox requests are allowed for the subscription. If false, then every request to generate AI skyboxes will be rejected.'),
216
295
  maxSkyboxesPerPeriod: z
217
- .number()
218
- .describe('The maximum number of skyboxes that are allowed to be generated per subscription period. If omitted, then there is no limit.')
219
296
  .int()
220
297
  .positive()
221
- .optional(),
298
+ .optional()
299
+ .describe('The maximum number of skyboxes that are allowed to be generated per subscription period. If omitted, then there is no limit.'),
300
+ creditFeePerSkybox: z
301
+ .int()
302
+ .optional()
303
+ .describe('The number of credits that are charged for each skybox that is generated. If not specified, then there is no fee.'),
222
304
  }),
223
305
  hume: z
224
306
  .object({
@@ -226,28 +308,27 @@ export const subscriptionFeaturesSchema = z.object({
226
308
  .boolean()
227
309
  .describe('Whether Hume AI features are allowed for the subscription. If false, then every request to generate Hume AI will be rejected.'),
228
310
  })
229
- .describe('The configuration for Hume AI features for the subscription. Defaults to not allowed if omitted.')
230
311
  .optional()
231
- .default({
312
+ .prefault({
232
313
  allowed: false,
233
- }),
314
+ })
315
+ .describe('The configuration for Hume AI features for the subscription. Defaults to not allowed if omitted.'),
234
316
  sloyd: z
235
317
  .object({
236
318
  allowed: z
237
319
  .boolean()
238
320
  .describe('Whether Sloyd AI features are allowed for the subscription. If false, then every request to generate Sloyd AI will be rejected.'),
239
321
  maxModelsPerPeriod: z
240
- .number()
241
- .describe('The maximum number of models that can be generated per subscription period. If omitted, then there is no limit.')
242
- .positive()
243
322
  .int()
244
- .optional(),
323
+ .positive()
324
+ .optional()
325
+ .describe('The maximum number of models that can be generated per subscription period. If omitted, then there is no limit.'),
245
326
  })
246
- .describe('The configuration for Sloyd AI features for the subscription. Defaults to not allowed if omitted.')
247
327
  .optional()
248
- .default({
328
+ .prefault({
249
329
  allowed: false,
250
- }),
330
+ })
331
+ .describe('The configuration for Sloyd AI features for the subscription. Defaults to not allowed if omitted.'),
251
332
  openai: z
252
333
  .object({
253
334
  realtime: z
@@ -256,89 +337,94 @@ export const subscriptionFeaturesSchema = z.object({
256
337
  .boolean()
257
338
  .describe('Whether OpenAI realtime API features are allowed.'),
258
339
  maxSessionsPerPeriod: z
259
- .number()
260
- .describe('The maximum number of realtime sessions that can be initiated per subscription period. If omitted, then there is no limit.')
261
340
  .int()
262
341
  .positive()
263
- .optional(),
342
+ .optional()
343
+ .describe('The maximum number of realtime sessions that can be initiated per subscription period. If omitted, then there is no limit.'),
264
344
  maxResponseOutputTokens: z
265
- .number()
266
- .describe('The maximum number of output tokens that can be generated per response per session. If omitted, then there is no limit.')
267
345
  .int()
268
346
  .positive()
269
- .optional(),
347
+ .optional()
348
+ .describe('The maximum number of output tokens that can be generated per response per session. If omitted, then there is no limit.'),
270
349
  allowedModels: z
271
350
  .array(z.string())
272
- .describe('The list of models that are allowed to be used with the realtime API. If ommited, then all models are allowed.')
273
- .optional(),
351
+ .optional()
352
+ .describe('The list of models that are allowed to be used with the realtime API. If ommited, then all models are allowed.'),
353
+ creditFeePerRealtimeSession: z
354
+ .int()
355
+ .optional()
356
+ .describe('The number of credits that are charged for each realtime session that is initiated. If not specified, then there is no fee.'),
274
357
  })
275
- .describe('The configuration for OpenAI realtime API features.')
276
358
  .optional()
277
- .default({
359
+ .prefault({
278
360
  allowed: false,
279
- }),
361
+ })
362
+ .describe('The configuration for OpenAI realtime API features.'),
280
363
  })
281
- .describe('The configuration for Open AI-specific features for the subscription. Defaults to not allowed if omitted.')
282
364
  .optional()
283
- .default({}),
365
+ .prefault({})
366
+ .describe('The configuration for Open AI-specific features for the subscription. Defaults to not allowed if omitted.'),
284
367
  }),
285
368
  insts: z.object({
286
369
  allowed: z
287
370
  .boolean()
288
371
  .describe('Whether insts are allowed for the subscription. If false, then every request to create or update an inst will be rejected.'),
289
372
  maxInsts: z
290
- .number()
291
- .describe('The maximum number of private insts that are allowed for the subscription. If omitted, then there is no limit.')
292
373
  .int()
293
374
  .positive()
294
- .optional(),
375
+ .optional()
376
+ .describe('The maximum number of private insts that are allowed for the subscription. If omitted, then there is no limit.'),
295
377
  maxBytesPerInst: z
296
- .number()
297
- .describe('The maximum number of bytes that can be stored in an inst. If omitted, then there is no limit.')
298
378
  .int()
299
379
  .positive()
300
- .optional(),
380
+ .optional()
381
+ .describe('The maximum number of bytes that can be stored in an inst. If omitted, then there is no limit.'),
301
382
  maxActiveConnectionsPerInst: z
302
- .number()
303
- .describe('The maximum number of active websocket connections that an inst can have. If omitted, then there is no limit.')
304
383
  .int()
305
384
  .positive()
306
- .optional(),
385
+ .optional()
386
+ .describe('The maximum number of active websocket connections that an inst can have. If omitted, then there is no limit.'),
387
+ creditFeePerInstPerPeriod: z
388
+ .int()
389
+ .optional()
390
+ .describe('The number of credits that are charged for each inst per subscription period. If not specified, then there is no fee.'),
391
+ creditFeePerBytePerPeriod: z
392
+ .int()
393
+ .optional()
394
+ .describe('The number of credits that are charged for each byte stored in an inst per subscription period. If not specified, then there is no fee.'),
307
395
  }),
308
396
  comId: z
309
397
  .object({
310
398
  allowed: z
311
399
  .boolean()
312
400
  .describe('Whether comId features are granted to the studio.'),
313
- // allowCustomComId: z
314
- // .boolean()
315
- // .describe(
316
- // 'Whether the studio is allowed to set their own comId. If false, then the user will be able to request changes to their comId, but they will not automatically apply.'
317
- // ),
318
401
  maxStudios: z
319
- .number()
320
- .describe('The maximum number of studios that can be created in this comId. If omitted, then there is no limit.')
402
+ .int()
321
403
  .positive()
404
+ .optional()
405
+ .describe('The maximum number of studios that can be created in this comId. If omitted, then there is no limit.'),
406
+ maxDomains: z
322
407
  .int()
323
- .optional(),
408
+ .positive()
409
+ .optional()
410
+ .describe('The maximum number of custom domains that can be used with this comId. If omitted, then there is no limit.'),
324
411
  })
325
- .describe('The configuration for comId features for studios. Defaults to not allowed.')
326
412
  .optional()
327
- .default({
413
+ .prefault({
328
414
  allowed: false,
329
- // allowCustomComId: false,
330
- }),
415
+ })
416
+ .describe('The configuration for comId features for studios. Defaults to not allowed.'),
331
417
  loom: z
332
418
  .object({
333
419
  allowed: z
334
420
  .boolean()
335
421
  .describe('Whether loom features are granted to the studio.'),
336
422
  })
337
- .describe('The configuration for loom features for studios. Defaults to not allowed.')
338
423
  .optional()
339
- .default({
424
+ .prefault({
340
425
  allowed: false,
341
- }),
426
+ })
427
+ .describe('The configuration for loom features for studios. Defaults to not allowed.'),
342
428
  webhooks: webhookFeaturesSchema,
343
429
  notifications: z
344
430
  .object({
@@ -346,239 +432,246 @@ export const subscriptionFeaturesSchema = z.object({
346
432
  .boolean()
347
433
  .describe('Whether notifications are allowed for the subscription.'),
348
434
  maxItems: z
349
- .number()
350
- .describe('The maximum number of notification items that are allowed for the subscription. If not specified, then there is no limit.')
351
435
  .int()
352
436
  .positive()
353
- .optional(),
437
+ .optional()
438
+ .describe('The maximum number of notification items that are allowed for the subscription. If not specified, then there is no limit.'),
354
439
  maxSubscribersPerItem: z
355
- .number()
356
- .describe('The maximum number of subscribers that a notification can have in the subscription. If not specified, then there is no limit.')
357
440
  .int()
358
441
  .positive()
359
- .optional(),
442
+ .optional()
443
+ .describe('The maximum number of subscribers that a notification can have in the subscription. If not specified, then there is no limit.'),
360
444
  maxSentNotificationsPerPeriod: z
361
- .number()
362
- .describe('The maximum number of notifications that can be sent per subscription period. This tracks the number of times the "sendNotification" operation was called. If not specified, then there is no limit.')
363
445
  .int()
364
446
  .positive()
365
- .optional(),
447
+ .optional()
448
+ .describe('The maximum number of notifications that can be sent per subscription period. This tracks the number of times the "sendNotification" operation was called. If not specified, then there is no limit.'),
366
449
  maxSentPushNotificationsPerPeriod: z
367
- .number()
368
- .describe('The maximum number of push notifications that can be sent per subscription period. This tracks the actual number of push notifications that were sent to users. If not specified, then there is no limit.')
369
450
  .int()
370
451
  .positive()
371
- .optional(),
452
+ .optional()
453
+ .describe('The maximum number of push notifications that can be sent per subscription period. This tracks the actual number of push notifications that were sent to users. If not specified, then there is no limit.'),
454
+ creditFeePerNotificationSent: z
455
+ .int()
456
+ .optional()
457
+ .describe('The number of credits that it costs to send a notification. If not specified, then sending notifications is free.'),
458
+ creditFeePerPushNotificationSent: z
459
+ .int()
460
+ .optional()
461
+ .describe('The number of credits that it costs to send a push notification. If not specified, then sending push notifications is free.'),
462
+ creditFeePerSubscriberPerPeriod: z
463
+ .int()
464
+ .optional()
465
+ .describe('The number of credits that are charged for each subscriber per subscription period. If not specified, then there is no fee.'),
372
466
  })
373
- .describe('The configuration for notification features. Defaults to not allowed.')
374
467
  .optional()
375
- .default({
468
+ .prefault({
376
469
  allowed: false,
377
- }),
470
+ })
471
+ .describe('The configuration for notification features. Defaults to not allowed.'),
378
472
  packages: z
379
473
  .object({
380
474
  allowed: z
381
475
  .boolean()
382
476
  .describe('Whether packages are allowed for the subscription.'),
383
477
  maxItems: z
384
- .number()
385
- .describe('The maximum number of packages that are allowed for the subscription. If not specified, then there is no limit.')
386
478
  .int()
387
479
  .positive()
388
- .optional(),
480
+ .optional()
481
+ .describe('The maximum number of packages that are allowed for the subscription. If not specified, then there is no limit.'),
389
482
  maxPackageVersions: z
390
- .number()
391
- .describe('The maximum number of package versions that are allowed for the subscription. If not specified, then there is no limit.')
392
483
  .int()
393
484
  .positive()
394
- .optional(),
485
+ .optional()
486
+ .describe('The maximum number of package versions that are allowed for the subscription. If not specified, then there is no limit.'),
395
487
  maxPackageVersionSizeInBytes: z
396
- .number()
397
- .describe('The maximum number of bytes that a single package version can be. If not specified, then there is no limit.')
398
488
  .int()
399
489
  .positive()
400
- .optional(),
490
+ .optional()
491
+ .describe('The maximum number of bytes that a single package version can be. If not specified, then there is no limit.'),
401
492
  maxPackageBytesTotal: z
402
- .number()
403
- .describe('The maximum number of bytes that all package versions in the subscription can be. If not specified, then there is no limit.')
404
493
  .int()
405
494
  .positive()
406
- .optional(),
495
+ .optional()
496
+ .describe('The maximum number of bytes that all package versions in the subscription can be. If not specified, then there is no limit.'),
407
497
  })
408
- .describe('The configuration for package features. Defaults to allowed.')
409
498
  .optional()
410
- .default({
499
+ .prefault({
411
500
  allowed: true,
412
- }),
501
+ })
502
+ .describe('The configuration for package features. Defaults to allowed.'),
413
503
  search: z
414
504
  .object({
415
505
  allowed: z
416
506
  .boolean()
417
507
  .describe('Whether search records are allowed for the subscription.'),
418
508
  maxItems: z
419
- .number()
420
- .describe('The maximum number of search records that can be created for the subscription. If not specified, then there is no limit.')
421
509
  .int()
422
510
  .positive()
423
- .optional(),
511
+ .optional()
512
+ .describe('The maximum number of search records that can be created for the subscription. If not specified, then there is no limit.'),
424
513
  })
425
- .describe('The configuration for search records features. Defaults to allowed.')
426
514
  .optional()
427
- .default({
515
+ .prefault({
428
516
  allowed: true,
429
- }),
517
+ })
518
+ .describe('The configuration for search records features. Defaults to allowed.'),
430
519
  databases: z
431
520
  .object({
432
521
  allowed: z
433
522
  .boolean()
434
523
  .describe('Whether database records are allowed for the subscription.'),
435
524
  maxItems: z
436
- .number()
437
- .describe('The maximum number of database records that can be created for the subscription. If not specified, then there is no limit.')
438
525
  .int()
439
526
  .positive()
440
- .optional(),
527
+ .optional()
528
+ .describe('The maximum number of database records that can be created for the subscription. If not specified, then there is no limit.'),
441
529
  maxBytesPerDatabase: z
442
- .number()
443
- .describe('The maximum size of the database in bytes. If not specified, then there is no limit.')
444
530
  .int()
445
531
  .positive()
446
- .optional(),
532
+ .optional()
533
+ .describe('The maximum size of the database in bytes. If not specified, then there is no limit.'),
447
534
  })
448
- .describe('The configuration for database records features. Defaults to allowed.')
449
535
  .optional()
450
- .default({
536
+ .prefault({
451
537
  allowed: true,
452
- }),
538
+ })
539
+ .describe('The configuration for database records features. Defaults to allowed.'),
540
+ store: storeFeaturesSchema,
541
+ contracts: contractFeaturesSchema,
453
542
  });
454
543
  export const subscriptionConfigSchema = z.object({
455
544
  webhookSecret: z
456
545
  .string()
457
- .describe('The Stripe Webhook secret. Used to validate that webhooks are actually coming from Stripe.')
458
- .nonempty(),
546
+ .nonempty()
547
+ .describe('The Stripe Webhook secret. Used to validate that webhooks are actually coming from Stripe.'),
459
548
  successUrl: z
460
549
  .string()
461
- .describe('The URL that successful Stripe checkout sessions should be redirected to.')
462
- .nonempty(),
550
+ .nonempty()
551
+ .describe('The URL that successful Stripe checkout sessions should be redirected to.'),
463
552
  cancelUrl: z
464
553
  .string()
465
- .describe('The URL that canceled Stripe checkout sessions should be redirected to.')
466
- .nonempty(),
554
+ .nonempty()
555
+ .describe('The URL that canceled Stripe checkout sessions should be redirected to.'),
467
556
  returnUrl: z
468
557
  .string()
469
- .describe('The URL that users should be redirected to when exiting the Stripe subscription management customer portal.')
470
- .nonempty(),
558
+ .nonempty()
559
+ .describe('The URL that users should be redirected to when exiting the Stripe subscription management customer portal.'),
471
560
  portalConfig: z
472
- .object({})
473
- .describe('Additional options that should be passed to stripe.billingPortal.sessions.create().')
474
- .passthrough()
561
+ .looseObject({})
475
562
  .optional()
476
- .nullable(),
563
+ .nullable()
564
+ .describe('Additional options that should be passed to stripe.billingPortal.sessions.create().'),
477
565
  checkoutConfig: z
478
- .object({})
479
- .describe('Additional options that should be passed to stripe.checkout.sessions.create().')
480
- .passthrough()
566
+ .looseObject({})
481
567
  .optional()
482
- .nullable(),
568
+ .nullable()
569
+ .describe('Additional options that should be passed to stripe.checkout.sessions.create().'),
483
570
  subscriptions: z
484
571
  .array(z.object({
485
572
  id: z
486
573
  .string()
487
- .describe('The ID of the subscription. Can be anything, but it must be unique to each subscription and never change.')
488
- .nonempty(),
574
+ .describe('The ID of the subscription. Can be anything, but it must be unique to each subscription and never change.'),
489
575
  product: z
490
576
  .string()
491
- .describe('The ID of the Stripe product that is being offered by this subscription. If omitted, then this subscription will be shown but not able to be purchased.')
492
- .nonempty()
493
- .optional(),
577
+ .optional()
578
+ .describe('The ID of the Stripe product that is being offered by this subscription. If omitted, then this subscription will be shown but not able to be purchased.'),
494
579
  featureList: z
495
- .array(z.string().nonempty())
580
+ .array(z.string())
496
581
  .describe('The list of features that should be shown for this subscription tier.'),
497
582
  eligibleProducts: z
498
- .array(z.string().nonempty())
499
- .describe('The list of Stripe product IDs that count as eligible for this subscription. Useful if you want to change the product of this subscription, but grandfather in existing users.')
500
- .optional(),
583
+ .array(z.string())
584
+ .optional()
585
+ .describe('The list of Stripe product IDs that count as eligible for this subscription. Useful if you want to change the product of this subscription, but grandfather in existing users.'),
501
586
  defaultSubscription: z
502
587
  .boolean()
503
- .describe("Whether this subscription should be granted to users if they don't already have a subscription. The first in the list of subscriptions that is marked as the default will be used. Defaults to false")
504
- .optional(),
588
+ .optional()
589
+ .describe("Whether this subscription should be granted to users if they don't already have a subscription. The first in the list of subscriptions that is marked as the default will be used. Defaults to false"),
505
590
  purchasable: z
506
591
  .boolean()
507
- .describe('Whether this subscription is purchasable and should be offered to users who do not already have a subscription. If false, then this subscription will not be shown to users unless they already have an active subscription for it. Defaults to true.')
508
- .optional(),
592
+ .optional()
593
+ .describe('Whether this subscription is purchasable and should be offered to users who do not already have a subscription. If false, then this subscription will not be shown to users unless they already have an active subscription for it. Defaults to true.'),
509
594
  name: z
510
595
  .string()
511
- .describe('The name of the subscription. Ignored if a Stripe product is specified.')
512
- .nonempty()
513
- .optional(),
596
+ .optional()
597
+ .describe('The name of the subscription. Ignored if a Stripe product is specified.'),
514
598
  description: z
515
599
  .string()
516
- .describe('The description of the subscription. Ignored if a Stripe product is specified.')
517
- .nonempty()
518
- .optional(),
600
+ .optional()
601
+ .describe('The description of the subscription. Ignored if a Stripe product is specified.'),
519
602
  tier: z
520
603
  .string()
521
- .describe('The tier of this subscription. Useful for grouping multiple subscriptions into the same set of features. Defaults to "beta"')
522
- .nonempty()
523
- .optional(),
604
+ .optional()
605
+ .describe('The tier of this subscription. Useful for grouping multiple subscriptions into the same set of features. Defaults to "beta"'),
524
606
  userOnly: z
525
607
  .boolean()
526
- .describe('Whether this subscription can only be purchased by individual users. Defaults to false.')
527
- .optional(),
608
+ .optional()
609
+ .describe('Whether this subscription can only be purchased by individual users. Defaults to false.'),
528
610
  studioOnly: z
529
611
  .boolean()
530
- .describe('Whether this subscription can only be purchased by studios. Defaults to false.')
531
- .optional(),
612
+ .optional()
613
+ .describe('Whether this subscription can only be purchased by studios. Defaults to false.'),
614
+ creditGrant: z
615
+ .union([
616
+ z
617
+ .int()
618
+ .positive()
619
+ .describe('The number of credits that should be granted to the user/studio upon purchasing (and renewal) of this subscription.'),
620
+ z.enum([
621
+ 'match-invoice', // Grants credits equal to the total of the invoice that pays for the subscription.
622
+ ]),
623
+ ])
624
+ .optional()
625
+ .nullable()
626
+ .describe('The number of credits that should be granted to the user/studio upon purchasing (and renewal) of this subscription. Defaults to 0.'),
532
627
  }))
533
628
  .describe('The list of subscriptions that are in use.'),
534
629
  tiers: z
535
630
  .object({})
536
- .describe('The configuration for the subscription tiers. Each key should be a tier.')
537
631
  .catchall(z
538
632
  .object({
539
633
  features: subscriptionFeaturesSchema.optional(),
540
634
  })
541
635
  .describe('The configuration for an individual tier.'))
542
- .optional(),
636
+ .optional()
637
+ .describe('The configuration for the subscription tiers. Each key should be a tier.'),
543
638
  defaultFeatures: z
544
639
  .object({
545
640
  user: subscriptionFeaturesSchema
546
- .describe('The features that are available for users who either dont have a subscription for have a subscription for a tier that is not listed in the tiers configuration. Defaults to an object that allows all features.')
547
- .optional(),
641
+ .optional()
642
+ .describe('The features that are available for users who either dont have a subscription for have a subscription for a tier that is not listed in the tiers configuration. Defaults to an object that allows all features.'),
548
643
  studio: subscriptionFeaturesSchema
549
- .describe('The features that are available for studios who either dont have a subscription for have a subscription for a tier that is not listed in the tiers configuration. Defaults to an object that allows all features.')
550
- .optional(),
644
+ .optional()
645
+ .describe('The features that are available for studios who either dont have a subscription for have a subscription for a tier that is not listed in the tiers configuration. Defaults to an object that allows all features.'),
551
646
  defaultPeriodLength: z
552
647
  .object({
553
- days: z.number().int().nonnegative().optional(),
554
- months: z.number().int().nonnegative().optional(),
648
+ days: z.int().nonnegative().optional(),
649
+ months: z.int().nonnegative().optional(),
555
650
  })
556
- .describe('The length of the period for users that do not have a subscription. Defaults to 1 month and 0 days.')
557
651
  .optional()
558
- .default({
652
+ .prefault({
559
653
  days: 0,
560
654
  months: 1,
561
- }),
655
+ })
656
+ .describe('The length of the period for users that do not have a subscription. Defaults to 1 month and 0 days.'),
562
657
  publicInsts: z
563
658
  .object({
564
659
  allowed: z
565
660
  .boolean()
566
661
  .describe('Whether public (temp) insts are allowed. If false, then every request to create or update a public inst will be rejected.'),
567
662
  maxBytesPerInst: z
568
- .number()
569
- .describe('The maximum number of bytes that can be stored for a public inst. If omitted, then there is no limit.')
570
663
  .int()
571
664
  .positive()
572
- .optional(),
665
+ .optional()
666
+ .describe('The maximum number of bytes that can be stored for a public inst. If omitted, then there is no limit.'),
573
667
  maxActiveConnectionsPerInst: z
574
- .number()
575
- .describe('The maximum number of active connections that are allowed for a public inst. If omitted, then there is no limit.')
576
668
  .int()
577
669
  .positive()
578
- .optional(),
670
+ .optional()
671
+ .describe('The maximum number of active connections that are allowed for a public inst. If omitted, then there is no limit.'),
579
672
  })
580
- .describe('The feature limits for public insts (insts that do not belong to a record and will expire after a preset time). Defaults to an object that allows all features.')
581
- .optional(),
673
+ .optional()
674
+ .describe('The feature limits for public insts (insts that do not belong to a record and will expire after a preset time). Defaults to an object that allows all features.'),
582
675
  })
583
676
  .optional(),
584
677
  });
@@ -595,7 +688,75 @@ export function parseSubscriptionConfig(config, defaultConfig) {
595
688
  return defaultConfig;
596
689
  }
597
690
  export function allowAllFeatures() {
598
- return {
691
+ return subscriptionFeaturesSchema.parse({
692
+ records: {
693
+ allowed: true,
694
+ },
695
+ ai: {
696
+ chat: {
697
+ allowed: true,
698
+ },
699
+ images: {
700
+ allowed: true,
701
+ },
702
+ skyboxes: {
703
+ allowed: true,
704
+ },
705
+ hume: {
706
+ allowed: true,
707
+ },
708
+ sloyd: {
709
+ allowed: true,
710
+ },
711
+ openai: {
712
+ realtime: {
713
+ allowed: true,
714
+ },
715
+ },
716
+ },
717
+ data: {
718
+ allowed: true,
719
+ },
720
+ events: {
721
+ allowed: true,
722
+ },
723
+ files: {
724
+ allowed: true,
725
+ },
726
+ policies: {
727
+ allowed: true,
728
+ },
729
+ insts: {
730
+ allowed: true,
731
+ },
732
+ notifications: {
733
+ allowed: true,
734
+ },
735
+ packages: {
736
+ allowed: true,
737
+ },
738
+ search: {
739
+ allowed: true,
740
+ },
741
+ databases: {
742
+ allowed: true,
743
+ },
744
+ contracts: {
745
+ allowed: true,
746
+ },
747
+ loom: {
748
+ allowed: true,
749
+ },
750
+ webhooks: {
751
+ allowed: true,
752
+ },
753
+ store: {
754
+ allowed: true,
755
+ },
756
+ });
757
+ }
758
+ export function allowAllDefaultFeatures() {
759
+ return subscriptionFeaturesSchema.parse({
599
760
  records: {
600
761
  allowed: true,
601
762
  },
@@ -630,6 +791,9 @@ export function allowAllFeatures() {
630
791
  files: {
631
792
  allowed: true,
632
793
  },
794
+ policies: {
795
+ allowed: true,
796
+ },
633
797
  insts: {
634
798
  allowed: true,
635
799
  },
@@ -645,10 +809,10 @@ export function allowAllFeatures() {
645
809
  databases: {
646
810
  allowed: true,
647
811
  },
648
- };
812
+ });
649
813
  }
650
814
  export function denyAllFeatures() {
651
- return {
815
+ return subscriptionFeaturesSchema.parse({
652
816
  records: {
653
817
  allowed: false,
654
818
  },
@@ -683,6 +847,9 @@ export function denyAllFeatures() {
683
847
  files: {
684
848
  allowed: false,
685
849
  },
850
+ policies: {
851
+ allowed: false,
852
+ },
686
853
  insts: {
687
854
  allowed: false,
688
855
  },
@@ -698,7 +865,22 @@ export function denyAllFeatures() {
698
865
  databases: {
699
866
  allowed: false,
700
867
  },
701
- };
868
+ contracts: {
869
+ allowed: false,
870
+ },
871
+ });
872
+ }
873
+ /**
874
+ * Gets the contract features that are available for the given subscription.
875
+ * @param config The configuration. If null, then all default features are allowed.
876
+ * @param subscriptionStatus The status of the subscription.
877
+ * @param subscriptionId The ID of the subscription.
878
+ * @param type The type of the user.
879
+ */
880
+ export function getContractFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
881
+ const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
882
+ return (features.contracts ??
883
+ contractFeaturesSchema.parse({ allowed: false }));
702
884
  }
703
885
  /**
704
886
  * Gets the database features that are available for the given subscription.
@@ -708,9 +890,8 @@ export function denyAllFeatures() {
708
890
  * @param type The type of the user.
709
891
  */
710
892
  export function getDatabaseFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
711
- var _a;
712
893
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
713
- return (_a = features.databases) !== null && _a !== void 0 ? _a : { allowed: true };
894
+ return features.databases ?? { allowed: true };
714
895
  }
715
896
  /**
716
897
  * Gets the search features that are available for the given subscription.
@@ -720,9 +901,8 @@ export function getDatabaseFeatures(config, subscriptionStatus, subscriptionId,
720
901
  * @param type The type of the user.
721
902
  */
722
903
  export function getSearchFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
723
- var _a;
724
904
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
725
- return (_a = features.search) !== null && _a !== void 0 ? _a : { allowed: true };
905
+ return features.search ?? { allowed: true };
726
906
  }
727
907
  /**
728
908
  * Gets the package features that are available for the given subscription.
@@ -732,9 +912,8 @@ export function getSearchFeatures(config, subscriptionStatus, subscriptionId, ty
732
912
  * @param type The type of the user.
733
913
  */
734
914
  export function getPackageFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
735
- var _a;
736
915
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
737
- return (_a = features.packages) !== null && _a !== void 0 ? _a : { allowed: true };
916
+ return features.packages ?? { allowed: true };
738
917
  }
739
918
  /**
740
919
  * Gets the notification features that are available for the given subscription.
@@ -744,9 +923,8 @@ export function getPackageFeatures(config, subscriptionStatus, subscriptionId, t
744
923
  * @param type The type of the user.
745
924
  */
746
925
  export function getNotificationFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
747
- var _a;
748
926
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
749
- return (_a = features.notifications) !== null && _a !== void 0 ? _a : { allowed: false };
927
+ return features.notifications ?? { allowed: false };
750
928
  }
751
929
  /**
752
930
  * Gets the webhook features that are available for the given subscription.
@@ -756,9 +934,8 @@ export function getNotificationFeatures(config, subscriptionStatus, subscription
756
934
  * @param type The type of the user.
757
935
  */
758
936
  export function getWebhookFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
759
- var _a;
760
937
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
761
- return (_a = features.webhooks) !== null && _a !== void 0 ? _a : webhookFeaturesSchema.parse({ allowed: false });
938
+ return features.webhooks ?? webhookFeaturesSchema.parse({ allowed: false });
762
939
  }
763
940
  /**
764
941
  * Gets the comId features that are available for the given subscription.
@@ -767,13 +944,26 @@ export function getWebhookFeatures(config, subscriptionStatus, subscriptionId, t
767
944
  * @param subscriptionId The ID of the subscription.
768
945
  */
769
946
  export function getComIdFeatures(config, subscriptionStatus, subscriptionId, periodStartMs, periodEndMs, nowMs = Date.now()) {
770
- var _a;
771
947
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, 'studio', periodStartMs, periodEndMs, nowMs);
772
- return ((_a = features.comId) !== null && _a !== void 0 ? _a : {
948
+ return (features.comId ?? {
773
949
  allowed: false,
774
950
  // allowCustomComId: false,
775
951
  });
776
952
  }
953
+ /**
954
+ * Gets the purchasableItems features that are available for the given subscription.
955
+ * Gets the comId features that are available for the given subscription.
956
+ * @param config The configuration. If null, then all default features are allowed.
957
+ * @param subscriptionStatus The status of the subscription.
958
+ * @param subscriptionId The ID of the subscription.
959
+ */
960
+ export function getPurchasableItemsFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
961
+ const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
962
+ return (features.store ??
963
+ storeFeaturesSchema.parse({
964
+ allowed: false,
965
+ }));
966
+ }
777
967
  /**
778
968
  * Gets the loom features that are available for the given subscription.
779
969
  * @param config The configuration. If null, then all default features are allowed.
@@ -781,9 +971,8 @@ export function getComIdFeatures(config, subscriptionStatus, subscriptionId, per
781
971
  * @param subscriptionId The ID of the subscription.
782
972
  */
783
973
  export function getLoomFeatures(config, subscriptionStatus, subscriptionId, periodStartMs, periodEndMs, nowMs = Date.now()) {
784
- var _a;
785
974
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, 'studio', periodStartMs, periodEndMs, nowMs);
786
- return (_a = features.loom) !== null && _a !== void 0 ? _a : { allowed: false };
975
+ return features.loom ?? { allowed: false };
787
976
  }
788
977
  /**
789
978
  * Gets the Hume AI features that are allowed for the given subscription.
@@ -794,9 +983,8 @@ export function getLoomFeatures(config, subscriptionStatus, subscriptionId, peri
794
983
  * @param type The type of the user.
795
984
  */
796
985
  export function getHumeAiFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
797
- var _a;
798
986
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
799
- return (_a = features.ai.hume) !== null && _a !== void 0 ? _a : { allowed: false };
987
+ return features.ai.hume ?? { allowed: false };
800
988
  }
801
989
  /**
802
990
  * Gets the Sloyd AI features that are allowed for the given subscription.
@@ -807,9 +995,8 @@ export function getHumeAiFeatures(config, subscriptionStatus, subscriptionId, ty
807
995
  * @param type The type of the user.
808
996
  */
809
997
  export function getSloydAiFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
810
- var _a;
811
998
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
812
- return (_a = features.ai.sloyd) !== null && _a !== void 0 ? _a : { allowed: false };
999
+ return features.ai.sloyd ?? { allowed: false };
813
1000
  }
814
1001
  /**
815
1002
  * Gets the OpenAI-specific features that are allowed for the given subscription.
@@ -820,9 +1007,8 @@ export function getSloydAiFeatures(config, subscriptionStatus, subscriptionId, t
820
1007
  * @param type The type of the user.
821
1008
  */
822
1009
  export function getOpenAiFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
823
- var _a;
824
1010
  const features = getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
825
- return ((_a = features.ai.openai) !== null && _a !== void 0 ? _a : {
1011
+ return (features.ai.openai ?? {
826
1012
  realtime: {
827
1013
  allowed: false,
828
1014
  },
@@ -840,19 +1026,18 @@ export function getOpenAiFeatures(config, subscriptionStatus, subscriptionId, ty
840
1026
  * @param nowMs The current time in milliseconds.
841
1027
  */
842
1028
  export function getSubscriptionFeatures(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs = Date.now()) {
843
- var _a, _b, _c, _d;
844
1029
  const sub = getSubscription(config, subscriptionStatus, subscriptionId, type, periodStartMs, periodEndMs, nowMs);
845
1030
  if (typeof sub === 'undefined') {
846
1031
  return allowAllFeatures();
847
1032
  }
848
1033
  else if (sub) {
849
- const tier = sub === null || sub === void 0 ? void 0 : sub.tier;
850
- const features = tier ? (_b = (_a = config === null || config === void 0 ? void 0 : config.tiers) === null || _a === void 0 ? void 0 : _a[tier]) === null || _b === void 0 ? void 0 : _b.features : null;
1034
+ const tier = sub?.tier;
1035
+ const features = tier ? config?.tiers?.[tier]?.features : null;
851
1036
  if (features) {
852
1037
  return features;
853
1038
  }
854
1039
  }
855
- return (_d = (_c = config.defaultFeatures) === null || _c === void 0 ? void 0 : _c[type]) !== null && _d !== void 0 ? _d : allowAllFeatures();
1040
+ return config.defaultFeatures?.[type] ?? allowAllFeatures();
856
1041
  }
857
1042
  /**
858
1043
  * Gets the subscription for the given configuration, subscription status, subscription ID, user type and period.
@@ -888,12 +1073,11 @@ export function getSubscription(config, subscriptionStatus, subscriptionId, type
888
1073
  return null;
889
1074
  }
890
1075
  export function getSubscriptionTier(config, subscriptionStatus, subId, type) {
891
- var _a;
892
1076
  const sub = getSubscription(config, subscriptionStatus, subId, type);
893
1077
  if (!sub) {
894
1078
  return null;
895
1079
  }
896
- return (_a = sub === null || sub === void 0 ? void 0 : sub.tier) !== null && _a !== void 0 ? _a : null;
1080
+ return sub?.tier ?? null;
897
1081
  }
898
1082
  /**
899
1083
  * Determines if the subscription is allowed to be used for the given role.
@@ -901,9 +1085,8 @@ export function getSubscriptionTier(config, subscriptionStatus, subId, type) {
901
1085
  * @param role The role.
902
1086
  */
903
1087
  export function subscriptionMatchesRole(subscription, role) {
904
- var _a, _b;
905
- const isUserOnly = (_a = subscription.userOnly) !== null && _a !== void 0 ? _a : false;
906
- const isStudioOnly = (_b = subscription.studioOnly) !== null && _b !== void 0 ? _b : false;
1088
+ const isUserOnly = subscription.userOnly ?? false;
1089
+ const isStudioOnly = subscription.studioOnly ?? false;
907
1090
  const matchesRole = (isUserOnly && role === 'user') ||
908
1091
  (isStudioOnly && role === 'studio') ||
909
1092
  (!isUserOnly && !isStudioOnly);