@qwickapps/server 1.4.0 → 1.5.1

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 (273) hide show
  1. package/CHANGELOG.md +507 -0
  2. package/README.md +9 -0
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +12 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/plugins/bans/bans-plugin.d.ts.map +1 -1
  8. package/dist/plugins/bans/bans-plugin.js +12 -3
  9. package/dist/plugins/bans/bans-plugin.js.map +1 -1
  10. package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts +11 -0
  11. package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts.map +1 -0
  12. package/dist/plugins/devices/__tests__/devices-plugin.test.js +410 -0
  13. package/dist/plugins/devices/__tests__/devices-plugin.test.js.map +1 -0
  14. package/dist/plugins/devices/__tests__/token-utils.test.d.ts +7 -0
  15. package/dist/plugins/devices/__tests__/token-utils.test.d.ts.map +1 -0
  16. package/dist/plugins/devices/__tests__/token-utils.test.js +197 -0
  17. package/dist/plugins/devices/__tests__/token-utils.test.js.map +1 -0
  18. package/dist/plugins/devices/adapters/compute-adapter.d.ts +36 -0
  19. package/dist/plugins/devices/adapters/compute-adapter.d.ts.map +1 -0
  20. package/dist/plugins/devices/adapters/compute-adapter.js +100 -0
  21. package/dist/plugins/devices/adapters/compute-adapter.js.map +1 -0
  22. package/dist/plugins/devices/adapters/index.d.ts +12 -0
  23. package/dist/plugins/devices/adapters/index.d.ts.map +1 -0
  24. package/dist/plugins/devices/adapters/index.js +10 -0
  25. package/dist/plugins/devices/adapters/index.js.map +1 -0
  26. package/dist/plugins/devices/adapters/mobile-adapter.d.ts +41 -0
  27. package/dist/plugins/devices/adapters/mobile-adapter.d.ts.map +1 -0
  28. package/dist/plugins/devices/adapters/mobile-adapter.js +131 -0
  29. package/dist/plugins/devices/adapters/mobile-adapter.js.map +1 -0
  30. package/dist/plugins/devices/devices-plugin.d.ts +70 -0
  31. package/dist/plugins/devices/devices-plugin.d.ts.map +1 -0
  32. package/dist/plugins/devices/devices-plugin.js +453 -0
  33. package/dist/plugins/devices/devices-plugin.js.map +1 -0
  34. package/dist/plugins/devices/index.d.ts +18 -0
  35. package/dist/plugins/devices/index.d.ts.map +1 -0
  36. package/dist/plugins/devices/index.js +18 -0
  37. package/dist/plugins/devices/index.js.map +1 -0
  38. package/dist/plugins/devices/stores/index.d.ts +9 -0
  39. package/dist/plugins/devices/stores/index.d.ts.map +1 -0
  40. package/dist/plugins/devices/stores/index.js +9 -0
  41. package/dist/plugins/devices/stores/index.js.map +1 -0
  42. package/dist/plugins/devices/stores/postgres-store.d.ts +26 -0
  43. package/dist/plugins/devices/stores/postgres-store.d.ts.map +1 -0
  44. package/dist/plugins/devices/stores/postgres-store.js +199 -0
  45. package/dist/plugins/devices/stores/postgres-store.js.map +1 -0
  46. package/dist/plugins/devices/token-utils.d.ts +100 -0
  47. package/dist/plugins/devices/token-utils.d.ts.map +1 -0
  48. package/dist/plugins/devices/token-utils.js +162 -0
  49. package/dist/plugins/devices/token-utils.js.map +1 -0
  50. package/dist/plugins/devices/types.d.ts +307 -0
  51. package/dist/plugins/devices/types.d.ts.map +1 -0
  52. package/dist/plugins/devices/types.js +10 -0
  53. package/dist/plugins/devices/types.js.map +1 -0
  54. package/dist/plugins/index.d.ts +14 -2
  55. package/dist/plugins/index.d.ts.map +1 -1
  56. package/dist/plugins/index.js +13 -1
  57. package/dist/plugins/index.js.map +1 -1
  58. package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts +5 -0
  59. package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts.map +1 -0
  60. package/dist/plugins/notifications/__tests__/notifications-manager.test.js +470 -0
  61. package/dist/plugins/notifications/__tests__/notifications-manager.test.js.map +1 -0
  62. package/dist/plugins/notifications/index.d.ts +71 -0
  63. package/dist/plugins/notifications/index.d.ts.map +1 -0
  64. package/dist/plugins/notifications/index.js +72 -0
  65. package/dist/plugins/notifications/index.js.map +1 -0
  66. package/dist/plugins/notifications/notifications-manager.d.ts +182 -0
  67. package/dist/plugins/notifications/notifications-manager.d.ts.map +1 -0
  68. package/dist/plugins/notifications/notifications-manager.js +610 -0
  69. package/dist/plugins/notifications/notifications-manager.js.map +1 -0
  70. package/dist/plugins/notifications/notifications-plugin.d.ts +83 -0
  71. package/dist/plugins/notifications/notifications-plugin.d.ts.map +1 -0
  72. package/dist/plugins/notifications/notifications-plugin.js +337 -0
  73. package/dist/plugins/notifications/notifications-plugin.js.map +1 -0
  74. package/dist/plugins/notifications/types.d.ts +164 -0
  75. package/dist/plugins/notifications/types.d.ts.map +1 -0
  76. package/dist/plugins/notifications/types.js +9 -0
  77. package/dist/plugins/notifications/types.js.map +1 -0
  78. package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts +12 -0
  79. package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts.map +1 -0
  80. package/dist/plugins/parental/__tests__/parental-plugin.test.js +349 -0
  81. package/dist/plugins/parental/__tests__/parental-plugin.test.js.map +1 -0
  82. package/dist/plugins/parental/adapters/index.d.ts +8 -0
  83. package/dist/plugins/parental/adapters/index.d.ts.map +1 -0
  84. package/dist/plugins/parental/adapters/index.js +7 -0
  85. package/dist/plugins/parental/adapters/index.js.map +1 -0
  86. package/dist/plugins/parental/adapters/kids-adapter.d.ts +24 -0
  87. package/dist/plugins/parental/adapters/kids-adapter.d.ts.map +1 -0
  88. package/dist/plugins/parental/adapters/kids-adapter.js +174 -0
  89. package/dist/plugins/parental/adapters/kids-adapter.js.map +1 -0
  90. package/dist/plugins/parental/index.d.ts +14 -0
  91. package/dist/plugins/parental/index.d.ts.map +1 -0
  92. package/dist/plugins/parental/index.js +15 -0
  93. package/dist/plugins/parental/index.js.map +1 -0
  94. package/dist/plugins/parental/parental-plugin.d.ts +88 -0
  95. package/dist/plugins/parental/parental-plugin.d.ts.map +1 -0
  96. package/dist/plugins/parental/parental-plugin.js +666 -0
  97. package/dist/plugins/parental/parental-plugin.js.map +1 -0
  98. package/dist/plugins/parental/stores/index.d.ts +7 -0
  99. package/dist/plugins/parental/stores/index.d.ts.map +1 -0
  100. package/dist/plugins/parental/stores/index.js +7 -0
  101. package/dist/plugins/parental/stores/index.js.map +1 -0
  102. package/dist/plugins/parental/stores/postgres-store.d.ts +10 -0
  103. package/dist/plugins/parental/stores/postgres-store.d.ts.map +1 -0
  104. package/dist/plugins/parental/stores/postgres-store.js +209 -0
  105. package/dist/plugins/parental/stores/postgres-store.js.map +1 -0
  106. package/dist/plugins/parental/types.d.ts +154 -0
  107. package/dist/plugins/parental/types.d.ts.map +1 -0
  108. package/dist/plugins/parental/types.js +10 -0
  109. package/dist/plugins/parental/types.js.map +1 -0
  110. package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts +11 -0
  111. package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts.map +1 -0
  112. package/dist/plugins/profiles/__tests__/profiles-plugin.test.js +243 -0
  113. package/dist/plugins/profiles/__tests__/profiles-plugin.test.js.map +1 -0
  114. package/dist/plugins/profiles/index.d.ts +12 -0
  115. package/dist/plugins/profiles/index.d.ts.map +1 -0
  116. package/dist/plugins/profiles/index.js +13 -0
  117. package/dist/plugins/profiles/index.js.map +1 -0
  118. package/dist/plugins/profiles/profiles-plugin.d.ts +71 -0
  119. package/dist/plugins/profiles/profiles-plugin.d.ts.map +1 -0
  120. package/dist/plugins/profiles/profiles-plugin.js +481 -0
  121. package/dist/plugins/profiles/profiles-plugin.js.map +1 -0
  122. package/dist/plugins/profiles/stores/index.d.ts +9 -0
  123. package/dist/plugins/profiles/stores/index.d.ts.map +1 -0
  124. package/dist/plugins/profiles/stores/index.js +9 -0
  125. package/dist/plugins/profiles/stores/index.js.map +1 -0
  126. package/dist/plugins/profiles/stores/postgres-store.d.ts +18 -0
  127. package/dist/plugins/profiles/stores/postgres-store.d.ts.map +1 -0
  128. package/dist/plugins/profiles/stores/postgres-store.js +310 -0
  129. package/dist/plugins/profiles/stores/postgres-store.js.map +1 -0
  130. package/dist/plugins/profiles/types.d.ts +289 -0
  131. package/dist/plugins/profiles/types.d.ts.map +1 -0
  132. package/dist/plugins/profiles/types.js +10 -0
  133. package/dist/plugins/profiles/types.js.map +1 -0
  134. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts +11 -0
  135. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts.map +1 -0
  136. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js +305 -0
  137. package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js.map +1 -0
  138. package/dist/plugins/subscriptions/index.d.ts +12 -0
  139. package/dist/plugins/subscriptions/index.d.ts.map +1 -0
  140. package/dist/plugins/subscriptions/index.js +13 -0
  141. package/dist/plugins/subscriptions/index.js.map +1 -0
  142. package/dist/plugins/subscriptions/stores/index.d.ts +9 -0
  143. package/dist/plugins/subscriptions/stores/index.d.ts.map +1 -0
  144. package/dist/plugins/subscriptions/stores/index.js +9 -0
  145. package/dist/plugins/subscriptions/stores/index.js.map +1 -0
  146. package/dist/plugins/subscriptions/stores/postgres-store.d.ts +14 -0
  147. package/dist/plugins/subscriptions/stores/postgres-store.d.ts.map +1 -0
  148. package/dist/plugins/subscriptions/stores/postgres-store.js +359 -0
  149. package/dist/plugins/subscriptions/stores/postgres-store.js.map +1 -0
  150. package/dist/plugins/subscriptions/subscriptions-plugin.d.ts +82 -0
  151. package/dist/plugins/subscriptions/subscriptions-plugin.d.ts.map +1 -0
  152. package/dist/plugins/subscriptions/subscriptions-plugin.js +449 -0
  153. package/dist/plugins/subscriptions/subscriptions-plugin.js.map +1 -0
  154. package/dist/plugins/subscriptions/types.d.ts +308 -0
  155. package/dist/plugins/subscriptions/types.d.ts.map +1 -0
  156. package/dist/plugins/subscriptions/types.js +10 -0
  157. package/dist/plugins/subscriptions/types.js.map +1 -0
  158. package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts +11 -0
  159. package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts.map +1 -0
  160. package/dist/plugins/usage/__tests__/usage-plugin.test.js +218 -0
  161. package/dist/plugins/usage/__tests__/usage-plugin.test.js.map +1 -0
  162. package/dist/plugins/usage/index.d.ts +12 -0
  163. package/dist/plugins/usage/index.d.ts.map +1 -0
  164. package/dist/plugins/usage/index.js +13 -0
  165. package/dist/plugins/usage/index.js.map +1 -0
  166. package/dist/plugins/usage/stores/index.d.ts +9 -0
  167. package/dist/plugins/usage/stores/index.d.ts.map +1 -0
  168. package/dist/plugins/usage/stores/index.js +9 -0
  169. package/dist/plugins/usage/stores/index.js.map +1 -0
  170. package/dist/plugins/usage/stores/postgres-store.d.ts +14 -0
  171. package/dist/plugins/usage/stores/postgres-store.d.ts.map +1 -0
  172. package/dist/plugins/usage/stores/postgres-store.js +146 -0
  173. package/dist/plugins/usage/stores/postgres-store.js.map +1 -0
  174. package/dist/plugins/usage/types.d.ts +195 -0
  175. package/dist/plugins/usage/types.d.ts.map +1 -0
  176. package/dist/plugins/usage/types.js +10 -0
  177. package/dist/plugins/usage/types.js.map +1 -0
  178. package/dist/plugins/usage/usage-plugin.d.ts +51 -0
  179. package/dist/plugins/usage/usage-plugin.d.ts.map +1 -0
  180. package/dist/plugins/usage/usage-plugin.js +412 -0
  181. package/dist/plugins/usage/usage-plugin.js.map +1 -0
  182. package/dist/plugins/users/__tests__/postgres-store.test.d.ts +10 -0
  183. package/dist/plugins/users/__tests__/postgres-store.test.d.ts.map +1 -0
  184. package/dist/plugins/users/__tests__/postgres-store.test.js +229 -0
  185. package/dist/plugins/users/__tests__/postgres-store.test.js.map +1 -0
  186. package/dist/plugins/users/__tests__/users-plugin.test.js +3 -0
  187. package/dist/plugins/users/__tests__/users-plugin.test.js.map +1 -1
  188. package/dist/plugins/users/index.d.ts +2 -2
  189. package/dist/plugins/users/index.d.ts.map +1 -1
  190. package/dist/plugins/users/index.js +1 -1
  191. package/dist/plugins/users/index.js.map +1 -1
  192. package/dist/plugins/users/stores/postgres-store.d.ts.map +1 -1
  193. package/dist/plugins/users/stores/postgres-store.js +76 -0
  194. package/dist/plugins/users/stores/postgres-store.js.map +1 -1
  195. package/dist/plugins/users/types.d.ts +74 -6
  196. package/dist/plugins/users/types.d.ts.map +1 -1
  197. package/dist/plugins/users/users-plugin.d.ts +15 -1
  198. package/dist/plugins/users/users-plugin.d.ts.map +1 -1
  199. package/dist/plugins/users/users-plugin.js +29 -0
  200. package/dist/plugins/users/users-plugin.js.map +1 -1
  201. package/dist-ui/assets/index-CynOqPkb.js +469 -0
  202. package/dist-ui/assets/index-CynOqPkb.js.map +1 -0
  203. package/dist-ui/index.html +1 -1
  204. package/dist-ui-lib/api/controlPanelApi.d.ts +46 -0
  205. package/dist-ui-lib/components/StatCard.d.ts +16 -0
  206. package/dist-ui-lib/dashboard/widgets/NotificationsStatsWidget.d.ts +12 -0
  207. package/dist-ui-lib/dashboard/widgets/index.d.ts +1 -0
  208. package/dist-ui-lib/index.js +1822 -1611
  209. package/dist-ui-lib/index.js.map +1 -1
  210. package/dist-ui-lib/pages/NotificationsPage.d.ts +9 -0
  211. package/dist-ui-lib/utils/formatters.d.ts +19 -0
  212. package/package.json +3 -2
  213. package/src/index.ts +178 -0
  214. package/src/plugins/bans/bans-plugin.ts +15 -3
  215. package/src/plugins/devices/__tests__/devices-plugin.test.ts +551 -0
  216. package/src/plugins/devices/__tests__/token-utils.test.ts +264 -0
  217. package/src/plugins/devices/adapters/compute-adapter.ts +139 -0
  218. package/src/plugins/devices/adapters/index.ts +13 -0
  219. package/src/plugins/devices/adapters/mobile-adapter.ts +179 -0
  220. package/src/plugins/devices/devices-plugin.ts +538 -0
  221. package/src/plugins/devices/index.ts +69 -0
  222. package/src/plugins/devices/stores/index.ts +9 -0
  223. package/src/plugins/devices/stores/postgres-store.ts +304 -0
  224. package/src/plugins/devices/token-utils.ts +213 -0
  225. package/src/plugins/devices/types.ts +351 -0
  226. package/src/plugins/index.ts +218 -0
  227. package/src/plugins/notifications/__tests__/notifications-manager.test.ts +637 -0
  228. package/src/plugins/notifications/index.ts +91 -0
  229. package/src/plugins/notifications/notifications-manager.ts +773 -0
  230. package/src/plugins/notifications/notifications-plugin.ts +398 -0
  231. package/src/plugins/notifications/types.ts +207 -0
  232. package/src/plugins/parental/__tests__/parental-plugin.test.ts +465 -0
  233. package/src/plugins/parental/adapters/index.ts +8 -0
  234. package/src/plugins/parental/adapters/kids-adapter.ts +206 -0
  235. package/src/plugins/parental/index.ts +55 -0
  236. package/src/plugins/parental/parental-plugin.ts +759 -0
  237. package/src/plugins/parental/stores/index.ts +7 -0
  238. package/src/plugins/parental/stores/postgres-store.ts +304 -0
  239. package/src/plugins/parental/types.ts +180 -0
  240. package/src/plugins/profiles/__tests__/profiles-plugin.test.ts +321 -0
  241. package/src/plugins/profiles/index.ts +49 -0
  242. package/src/plugins/profiles/profiles-plugin.ts +546 -0
  243. package/src/plugins/profiles/stores/index.ts +9 -0
  244. package/src/plugins/profiles/stores/postgres-store.ts +439 -0
  245. package/src/plugins/profiles/types.ts +338 -0
  246. package/src/plugins/subscriptions/__tests__/subscriptions-plugin.test.ts +404 -0
  247. package/src/plugins/subscriptions/index.ts +51 -0
  248. package/src/plugins/subscriptions/stores/index.ts +9 -0
  249. package/src/plugins/subscriptions/stores/postgres-store.ts +482 -0
  250. package/src/plugins/subscriptions/subscriptions-plugin.ts +530 -0
  251. package/src/plugins/subscriptions/types.ts +355 -0
  252. package/src/plugins/usage/__tests__/usage-plugin.test.ts +288 -0
  253. package/src/plugins/usage/index.ts +39 -0
  254. package/src/plugins/usage/stores/index.ts +9 -0
  255. package/src/plugins/usage/stores/postgres-store.ts +213 -0
  256. package/src/plugins/usage/types.ts +222 -0
  257. package/src/plugins/usage/usage-plugin.ts +484 -0
  258. package/src/plugins/users/__tests__/postgres-store.test.ts +326 -0
  259. package/src/plugins/users/__tests__/users-plugin.test.ts +3 -0
  260. package/src/plugins/users/index.ts +6 -0
  261. package/src/plugins/users/stores/postgres-store.ts +104 -0
  262. package/src/plugins/users/types.ts +82 -6
  263. package/src/plugins/users/users-plugin.ts +37 -0
  264. package/ui/src/App.tsx +5 -1
  265. package/ui/src/api/controlPanelApi.ts +103 -6
  266. package/ui/src/components/StatCard.tsx +58 -0
  267. package/ui/src/dashboard/builtInWidgets.tsx +3 -1
  268. package/ui/src/dashboard/widgets/NotificationsStatsWidget.tsx +167 -0
  269. package/ui/src/dashboard/widgets/index.ts +1 -0
  270. package/ui/src/pages/NotificationsPage.tsx +417 -0
  271. package/ui/src/utils/formatters.ts +33 -0
  272. package/dist-ui/assets/index-D7DoZ9rL.js +0 -478
  273. package/dist-ui/assets/index-D7DoZ9rL.js.map +0 -1
@@ -0,0 +1,449 @@
1
+ /**
2
+ * Subscriptions Plugin
3
+ *
4
+ * Subscription tier and entitlement management plugin for @qwickapps/server.
5
+ * Supports Stripe integration for paid subscriptions.
6
+ *
7
+ * Copyright (c) 2025 QwickApps.com. All rights reserved.
8
+ */
9
+ // Store instance for helper access
10
+ let currentStore = null;
11
+ let currentConfig = null;
12
+ /**
13
+ * Create the Subscriptions plugin
14
+ */
15
+ export function createSubscriptionsPlugin(config) {
16
+ const debug = config.debug || false;
17
+ const defaultTierSlug = config.defaultTierSlug || 'free';
18
+ const apiPrefix = config.api?.prefix || '/subscriptions';
19
+ function log(message, data) {
20
+ if (debug) {
21
+ console.log(`[SubscriptionsPlugin] ${message}`, data || '');
22
+ }
23
+ }
24
+ return {
25
+ id: 'subscriptions',
26
+ name: 'Subscriptions',
27
+ version: '1.0.0',
28
+ async onStart(_pluginConfig, registry) {
29
+ log('Starting subscriptions plugin');
30
+ // Initialize the store (creates tables if needed)
31
+ await config.store.initialize();
32
+ log('Subscriptions plugin migrations complete');
33
+ // Store references for helper access
34
+ currentStore = config.store;
35
+ currentConfig = config;
36
+ // Register health check
37
+ registry.registerHealthCheck({
38
+ name: 'subscriptions-store',
39
+ type: 'custom',
40
+ check: async () => {
41
+ try {
42
+ const tiers = await config.store.listTiers(true);
43
+ return {
44
+ healthy: true,
45
+ details: {
46
+ tiersCount: tiers.length,
47
+ defaultTier: defaultTierSlug,
48
+ },
49
+ };
50
+ }
51
+ catch {
52
+ return { healthy: false };
53
+ }
54
+ },
55
+ });
56
+ // Add tier management routes
57
+ if (config.api?.tierManagement !== false) {
58
+ // List tiers
59
+ registry.addRoute({
60
+ method: 'get',
61
+ path: `${apiPrefix}/tiers`,
62
+ pluginId: 'subscriptions',
63
+ handler: async (req, res) => {
64
+ try {
65
+ const activeOnly = req.query.active !== 'false';
66
+ const tiers = await config.store.listTiers(activeOnly);
67
+ // Include entitlements if requested
68
+ if (req.query.include === 'entitlements') {
69
+ const tiersWithEntitlements = await Promise.all(tiers.map(async (tier) => ({
70
+ ...tier,
71
+ entitlements: await config.store.getEntitlementsByTier(tier.id),
72
+ })));
73
+ return res.json({ tiers: tiersWithEntitlements });
74
+ }
75
+ res.json({ tiers });
76
+ }
77
+ catch (error) {
78
+ console.error('[SubscriptionsPlugin] List tiers error:', error);
79
+ res.status(500).json({ error: 'Failed to list tiers' });
80
+ }
81
+ },
82
+ });
83
+ // Get tier by ID or slug
84
+ registry.addRoute({
85
+ method: 'get',
86
+ path: `${apiPrefix}/tiers/:idOrSlug`,
87
+ pluginId: 'subscriptions',
88
+ handler: async (req, res) => {
89
+ try {
90
+ const { idOrSlug } = req.params;
91
+ // Try by ID first, then by slug
92
+ let tier = await config.store.getTierById(idOrSlug);
93
+ if (!tier) {
94
+ tier = await config.store.getTierBySlug(idOrSlug);
95
+ }
96
+ if (!tier) {
97
+ return res.status(404).json({ error: 'Tier not found' });
98
+ }
99
+ const entitlements = await config.store.getEntitlementsByTier(tier.id);
100
+ res.json({ ...tier, entitlements });
101
+ }
102
+ catch (error) {
103
+ console.error('[SubscriptionsPlugin] Get tier error:', error);
104
+ res.status(500).json({ error: 'Failed to get tier' });
105
+ }
106
+ },
107
+ });
108
+ // Create tier (admin only)
109
+ registry.addRoute({
110
+ method: 'post',
111
+ path: `${apiPrefix}/tiers`,
112
+ pluginId: 'subscriptions',
113
+ handler: async (req, res) => {
114
+ try {
115
+ const input = req.body;
116
+ if (!input.slug || !input.name) {
117
+ return res.status(400).json({ error: 'slug and name are required' });
118
+ }
119
+ // Check for duplicate slug
120
+ const existing = await config.store.getTierBySlug(input.slug);
121
+ if (existing) {
122
+ return res.status(409).json({ error: 'Tier with this slug already exists' });
123
+ }
124
+ const tier = await config.store.createTier(input);
125
+ res.status(201).json(tier);
126
+ }
127
+ catch (error) {
128
+ console.error('[SubscriptionsPlugin] Create tier error:', error);
129
+ res.status(500).json({ error: 'Failed to create tier' });
130
+ }
131
+ },
132
+ });
133
+ // Update tier (admin only)
134
+ registry.addRoute({
135
+ method: 'put',
136
+ path: `${apiPrefix}/tiers/:id`,
137
+ pluginId: 'subscriptions',
138
+ handler: async (req, res) => {
139
+ try {
140
+ const input = req.body;
141
+ const tier = await config.store.updateTier(req.params.id, input);
142
+ if (!tier) {
143
+ return res.status(404).json({ error: 'Tier not found' });
144
+ }
145
+ res.json(tier);
146
+ }
147
+ catch (error) {
148
+ console.error('[SubscriptionsPlugin] Update tier error:', error);
149
+ res.status(500).json({ error: 'Failed to update tier' });
150
+ }
151
+ },
152
+ });
153
+ // Set tier entitlements (admin only)
154
+ registry.addRoute({
155
+ method: 'put',
156
+ path: `${apiPrefix}/tiers/:id/entitlements`,
157
+ pluginId: 'subscriptions',
158
+ handler: async (req, res) => {
159
+ try {
160
+ const { entitlements } = req.body;
161
+ if (!Array.isArray(entitlements)) {
162
+ return res.status(400).json({ error: 'entitlements array is required' });
163
+ }
164
+ await config.store.setTierEntitlements(req.params.id, entitlements);
165
+ const updatedEntitlements = await config.store.getEntitlementsByTier(req.params.id);
166
+ res.json({ entitlements: updatedEntitlements });
167
+ }
168
+ catch (error) {
169
+ console.error('[SubscriptionsPlugin] Set entitlements error:', error);
170
+ res.status(500).json({ error: 'Failed to set entitlements' });
171
+ }
172
+ },
173
+ });
174
+ }
175
+ // Add user subscription routes
176
+ if (config.api?.userSubscriptions !== false) {
177
+ // Get user's active subscription
178
+ registry.addRoute({
179
+ method: 'get',
180
+ path: `${apiPrefix}/user/:userId`,
181
+ pluginId: 'subscriptions',
182
+ handler: async (req, res) => {
183
+ try {
184
+ const subscription = await config.store.getActiveSubscription(req.params.userId);
185
+ if (!subscription) {
186
+ return res.status(404).json({ error: 'No active subscription found' });
187
+ }
188
+ // Get entitlements for the tier
189
+ const entitlements = await config.store.getEntitlementsByTier(subscription.tier_id);
190
+ res.json({
191
+ subscription,
192
+ entitlements,
193
+ });
194
+ }
195
+ catch (error) {
196
+ console.error('[SubscriptionsPlugin] Get user subscription error:', error);
197
+ res.status(500).json({ error: 'Failed to get subscription' });
198
+ }
199
+ },
200
+ });
201
+ // Create/update user subscription
202
+ registry.addRoute({
203
+ method: 'post',
204
+ path: `${apiPrefix}/user/:userId`,
205
+ pluginId: 'subscriptions',
206
+ handler: async (req, res) => {
207
+ try {
208
+ const input = {
209
+ user_id: req.params.userId,
210
+ ...req.body,
211
+ };
212
+ if (!input.tier_id) {
213
+ // Use default tier if not specified
214
+ const defaultTier = await config.store.getTierBySlug(defaultTierSlug);
215
+ if (!defaultTier) {
216
+ return res.status(400).json({ error: 'tier_id is required (no default tier found)' });
217
+ }
218
+ input.tier_id = defaultTier.id;
219
+ }
220
+ const subscription = await config.store.createUserSubscription(input);
221
+ res.status(201).json(subscription);
222
+ }
223
+ catch (error) {
224
+ console.error('[SubscriptionsPlugin] Create subscription error:', error);
225
+ res.status(500).json({ error: 'Failed to create subscription' });
226
+ }
227
+ },
228
+ });
229
+ // Check feature limit
230
+ registry.addRoute({
231
+ method: 'get',
232
+ path: `${apiPrefix}/user/:userId/features/:featureCode`,
233
+ pluginId: 'subscriptions',
234
+ handler: async (req, res) => {
235
+ try {
236
+ const { userId, featureCode } = req.params;
237
+ const result = await checkFeatureLimit(userId, featureCode);
238
+ res.json(result);
239
+ }
240
+ catch (error) {
241
+ console.error('[SubscriptionsPlugin] Check feature error:', error);
242
+ res.status(500).json({ error: 'Failed to check feature' });
243
+ }
244
+ },
245
+ });
246
+ // Cancel subscription
247
+ registry.addRoute({
248
+ method: 'post',
249
+ path: `${apiPrefix}/:id/cancel`,
250
+ pluginId: 'subscriptions',
251
+ handler: async (req, res) => {
252
+ try {
253
+ const success = await config.store.cancelSubscription(req.params.id);
254
+ if (!success) {
255
+ return res.status(404).json({ error: 'Subscription not found' });
256
+ }
257
+ const subscription = await config.store.getUserSubscriptionById(req.params.id);
258
+ res.json(subscription);
259
+ }
260
+ catch (error) {
261
+ console.error('[SubscriptionsPlugin] Cancel subscription error:', error);
262
+ res.status(500).json({ error: 'Failed to cancel subscription' });
263
+ }
264
+ },
265
+ });
266
+ }
267
+ log('Subscriptions plugin started');
268
+ },
269
+ async onStop() {
270
+ log('Stopping subscriptions plugin');
271
+ await config.store.shutdown();
272
+ currentStore = null;
273
+ currentConfig = null;
274
+ log('Subscriptions plugin stopped');
275
+ },
276
+ };
277
+ }
278
+ // ═══════════════════════════════════════════════════════════════════════════
279
+ // Helper Functions
280
+ // ═══════════════════════════════════════════════════════════════════════════
281
+ /**
282
+ * Get the current subscriptions store instance
283
+ */
284
+ export function getSubscriptionsStore() {
285
+ return currentStore;
286
+ }
287
+ /**
288
+ * Create a subscription tier
289
+ */
290
+ export async function createTier(input) {
291
+ if (!currentStore) {
292
+ throw new Error('Subscriptions plugin not initialized');
293
+ }
294
+ return currentStore.createTier(input);
295
+ }
296
+ /**
297
+ * Get tier by slug
298
+ */
299
+ export async function getTierBySlug(slug) {
300
+ if (!currentStore) {
301
+ throw new Error('Subscriptions plugin not initialized');
302
+ }
303
+ return currentStore.getTierBySlug(slug);
304
+ }
305
+ /**
306
+ * Get tier by ID
307
+ */
308
+ export async function getTierById(id) {
309
+ if (!currentStore) {
310
+ throw new Error('Subscriptions plugin not initialized');
311
+ }
312
+ return currentStore.getTierById(id);
313
+ }
314
+ /**
315
+ * List all tiers
316
+ */
317
+ export async function listTiers(activeOnly = true) {
318
+ if (!currentStore) {
319
+ throw new Error('Subscriptions plugin not initialized');
320
+ }
321
+ return currentStore.listTiers(activeOnly);
322
+ }
323
+ /**
324
+ * Get entitlements for a tier
325
+ */
326
+ export async function getTierEntitlements(tierId) {
327
+ if (!currentStore) {
328
+ throw new Error('Subscriptions plugin not initialized');
329
+ }
330
+ return currentStore.getEntitlementsByTier(tierId);
331
+ }
332
+ /**
333
+ * Set entitlements for a tier
334
+ */
335
+ export async function setTierEntitlements(tierId, entitlements) {
336
+ if (!currentStore) {
337
+ throw new Error('Subscriptions plugin not initialized');
338
+ }
339
+ return currentStore.setTierEntitlements(tierId, entitlements);
340
+ }
341
+ /**
342
+ * Get user's active subscription
343
+ */
344
+ export async function getUserSubscription(userId) {
345
+ if (!currentStore) {
346
+ throw new Error('Subscriptions plugin not initialized');
347
+ }
348
+ return currentStore.getActiveSubscription(userId);
349
+ }
350
+ /**
351
+ * Create a user subscription
352
+ */
353
+ export async function createUserSubscription(input) {
354
+ if (!currentStore) {
355
+ throw new Error('Subscriptions plugin not initialized');
356
+ }
357
+ return currentStore.createUserSubscription(input);
358
+ }
359
+ /**
360
+ * Update a user subscription
361
+ */
362
+ export async function updateUserSubscription(id, input) {
363
+ if (!currentStore) {
364
+ throw new Error('Subscriptions plugin not initialized');
365
+ }
366
+ return currentStore.updateUserSubscription(id, input);
367
+ }
368
+ /**
369
+ * Cancel a subscription
370
+ */
371
+ export async function cancelSubscription(id) {
372
+ if (!currentStore) {
373
+ throw new Error('Subscriptions plugin not initialized');
374
+ }
375
+ return currentStore.cancelSubscription(id);
376
+ }
377
+ /**
378
+ * Get user's tier slug
379
+ */
380
+ export async function getUserTierSlug(userId) {
381
+ const subscription = await getUserSubscription(userId);
382
+ return subscription?.tier.slug || null;
383
+ }
384
+ /**
385
+ * Get feature limit for a user
386
+ */
387
+ export async function getFeatureLimit(userId, featureCode) {
388
+ if (!currentStore) {
389
+ throw new Error('Subscriptions plugin not initialized');
390
+ }
391
+ return currentStore.getFeatureLimit(userId, featureCode);
392
+ }
393
+ /**
394
+ * Check if user has a feature
395
+ */
396
+ export async function hasFeature(userId, featureCode) {
397
+ if (!currentStore) {
398
+ throw new Error('Subscriptions plugin not initialized');
399
+ }
400
+ return currentStore.hasFeature(userId, featureCode);
401
+ }
402
+ /**
403
+ * Check feature limit and availability
404
+ */
405
+ export async function checkFeatureLimit(userId, featureCode) {
406
+ if (!currentStore) {
407
+ throw new Error('Subscriptions plugin not initialized');
408
+ }
409
+ const limit = await currentStore.getFeatureLimit(userId, featureCode);
410
+ if (limit === null) {
411
+ return { available: false };
412
+ }
413
+ if (limit === 0) {
414
+ return { available: false, limit: 0 };
415
+ }
416
+ // -1 means unlimited
417
+ if (limit === -1) {
418
+ return { available: true, limit: -1 };
419
+ }
420
+ // Note: Current usage would need to come from usage-plugin
421
+ return { available: true, limit };
422
+ }
423
+ /**
424
+ * Ensure user has a subscription (create default if not)
425
+ */
426
+ export async function ensureUserSubscription(userId) {
427
+ if (!currentStore || !currentConfig) {
428
+ throw new Error('Subscriptions plugin not initialized');
429
+ }
430
+ let subscription = await currentStore.getActiveSubscription(userId);
431
+ if (!subscription) {
432
+ // Create default subscription
433
+ const defaultTierSlug = currentConfig.defaultTierSlug || 'free';
434
+ const defaultTier = await currentStore.getTierBySlug(defaultTierSlug);
435
+ if (!defaultTier) {
436
+ throw new Error(`Default tier '${defaultTierSlug}' not found`);
437
+ }
438
+ await currentStore.createUserSubscription({
439
+ user_id: userId,
440
+ tier_id: defaultTier.id,
441
+ });
442
+ subscription = await currentStore.getActiveSubscription(userId);
443
+ if (!subscription) {
444
+ throw new Error('Failed to create subscription');
445
+ }
446
+ }
447
+ return subscription;
448
+ }
449
+ //# sourceMappingURL=subscriptions-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions-plugin.js","sourceRoot":"","sources":["../../../src/plugins/subscriptions/subscriptions-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG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