@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.
- package/CHANGELOG.md +507 -0
- package/README.md +9 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/plugins/bans/bans-plugin.d.ts.map +1 -1
- package/dist/plugins/bans/bans-plugin.js +12 -3
- package/dist/plugins/bans/bans-plugin.js.map +1 -1
- package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts +11 -0
- package/dist/plugins/devices/__tests__/devices-plugin.test.d.ts.map +1 -0
- package/dist/plugins/devices/__tests__/devices-plugin.test.js +410 -0
- package/dist/plugins/devices/__tests__/devices-plugin.test.js.map +1 -0
- package/dist/plugins/devices/__tests__/token-utils.test.d.ts +7 -0
- package/dist/plugins/devices/__tests__/token-utils.test.d.ts.map +1 -0
- package/dist/plugins/devices/__tests__/token-utils.test.js +197 -0
- package/dist/plugins/devices/__tests__/token-utils.test.js.map +1 -0
- package/dist/plugins/devices/adapters/compute-adapter.d.ts +36 -0
- package/dist/plugins/devices/adapters/compute-adapter.d.ts.map +1 -0
- package/dist/plugins/devices/adapters/compute-adapter.js +100 -0
- package/dist/plugins/devices/adapters/compute-adapter.js.map +1 -0
- package/dist/plugins/devices/adapters/index.d.ts +12 -0
- package/dist/plugins/devices/adapters/index.d.ts.map +1 -0
- package/dist/plugins/devices/adapters/index.js +10 -0
- package/dist/plugins/devices/adapters/index.js.map +1 -0
- package/dist/plugins/devices/adapters/mobile-adapter.d.ts +41 -0
- package/dist/plugins/devices/adapters/mobile-adapter.d.ts.map +1 -0
- package/dist/plugins/devices/adapters/mobile-adapter.js +131 -0
- package/dist/plugins/devices/adapters/mobile-adapter.js.map +1 -0
- package/dist/plugins/devices/devices-plugin.d.ts +70 -0
- package/dist/plugins/devices/devices-plugin.d.ts.map +1 -0
- package/dist/plugins/devices/devices-plugin.js +453 -0
- package/dist/plugins/devices/devices-plugin.js.map +1 -0
- package/dist/plugins/devices/index.d.ts +18 -0
- package/dist/plugins/devices/index.d.ts.map +1 -0
- package/dist/plugins/devices/index.js +18 -0
- package/dist/plugins/devices/index.js.map +1 -0
- package/dist/plugins/devices/stores/index.d.ts +9 -0
- package/dist/plugins/devices/stores/index.d.ts.map +1 -0
- package/dist/plugins/devices/stores/index.js +9 -0
- package/dist/plugins/devices/stores/index.js.map +1 -0
- package/dist/plugins/devices/stores/postgres-store.d.ts +26 -0
- package/dist/plugins/devices/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/devices/stores/postgres-store.js +199 -0
- package/dist/plugins/devices/stores/postgres-store.js.map +1 -0
- package/dist/plugins/devices/token-utils.d.ts +100 -0
- package/dist/plugins/devices/token-utils.d.ts.map +1 -0
- package/dist/plugins/devices/token-utils.js +162 -0
- package/dist/plugins/devices/token-utils.js.map +1 -0
- package/dist/plugins/devices/types.d.ts +307 -0
- package/dist/plugins/devices/types.d.ts.map +1 -0
- package/dist/plugins/devices/types.js +10 -0
- package/dist/plugins/devices/types.js.map +1 -0
- package/dist/plugins/index.d.ts +14 -2
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +13 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts +5 -0
- package/dist/plugins/notifications/__tests__/notifications-manager.test.d.ts.map +1 -0
- package/dist/plugins/notifications/__tests__/notifications-manager.test.js +470 -0
- package/dist/plugins/notifications/__tests__/notifications-manager.test.js.map +1 -0
- package/dist/plugins/notifications/index.d.ts +71 -0
- package/dist/plugins/notifications/index.d.ts.map +1 -0
- package/dist/plugins/notifications/index.js +72 -0
- package/dist/plugins/notifications/index.js.map +1 -0
- package/dist/plugins/notifications/notifications-manager.d.ts +182 -0
- package/dist/plugins/notifications/notifications-manager.d.ts.map +1 -0
- package/dist/plugins/notifications/notifications-manager.js +610 -0
- package/dist/plugins/notifications/notifications-manager.js.map +1 -0
- package/dist/plugins/notifications/notifications-plugin.d.ts +83 -0
- package/dist/plugins/notifications/notifications-plugin.d.ts.map +1 -0
- package/dist/plugins/notifications/notifications-plugin.js +337 -0
- package/dist/plugins/notifications/notifications-plugin.js.map +1 -0
- package/dist/plugins/notifications/types.d.ts +164 -0
- package/dist/plugins/notifications/types.d.ts.map +1 -0
- package/dist/plugins/notifications/types.js +9 -0
- package/dist/plugins/notifications/types.js.map +1 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts +12 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.d.ts.map +1 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.js +349 -0
- package/dist/plugins/parental/__tests__/parental-plugin.test.js.map +1 -0
- package/dist/plugins/parental/adapters/index.d.ts +8 -0
- package/dist/plugins/parental/adapters/index.d.ts.map +1 -0
- package/dist/plugins/parental/adapters/index.js +7 -0
- package/dist/plugins/parental/adapters/index.js.map +1 -0
- package/dist/plugins/parental/adapters/kids-adapter.d.ts +24 -0
- package/dist/plugins/parental/adapters/kids-adapter.d.ts.map +1 -0
- package/dist/plugins/parental/adapters/kids-adapter.js +174 -0
- package/dist/plugins/parental/adapters/kids-adapter.js.map +1 -0
- package/dist/plugins/parental/index.d.ts +14 -0
- package/dist/plugins/parental/index.d.ts.map +1 -0
- package/dist/plugins/parental/index.js +15 -0
- package/dist/plugins/parental/index.js.map +1 -0
- package/dist/plugins/parental/parental-plugin.d.ts +88 -0
- package/dist/plugins/parental/parental-plugin.d.ts.map +1 -0
- package/dist/plugins/parental/parental-plugin.js +666 -0
- package/dist/plugins/parental/parental-plugin.js.map +1 -0
- package/dist/plugins/parental/stores/index.d.ts +7 -0
- package/dist/plugins/parental/stores/index.d.ts.map +1 -0
- package/dist/plugins/parental/stores/index.js +7 -0
- package/dist/plugins/parental/stores/index.js.map +1 -0
- package/dist/plugins/parental/stores/postgres-store.d.ts +10 -0
- package/dist/plugins/parental/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/parental/stores/postgres-store.js +209 -0
- package/dist/plugins/parental/stores/postgres-store.js.map +1 -0
- package/dist/plugins/parental/types.d.ts +154 -0
- package/dist/plugins/parental/types.d.ts.map +1 -0
- package/dist/plugins/parental/types.js +10 -0
- package/dist/plugins/parental/types.js.map +1 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts +11 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.d.ts.map +1 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.js +243 -0
- package/dist/plugins/profiles/__tests__/profiles-plugin.test.js.map +1 -0
- package/dist/plugins/profiles/index.d.ts +12 -0
- package/dist/plugins/profiles/index.d.ts.map +1 -0
- package/dist/plugins/profiles/index.js +13 -0
- package/dist/plugins/profiles/index.js.map +1 -0
- package/dist/plugins/profiles/profiles-plugin.d.ts +71 -0
- package/dist/plugins/profiles/profiles-plugin.d.ts.map +1 -0
- package/dist/plugins/profiles/profiles-plugin.js +481 -0
- package/dist/plugins/profiles/profiles-plugin.js.map +1 -0
- package/dist/plugins/profiles/stores/index.d.ts +9 -0
- package/dist/plugins/profiles/stores/index.d.ts.map +1 -0
- package/dist/plugins/profiles/stores/index.js +9 -0
- package/dist/plugins/profiles/stores/index.js.map +1 -0
- package/dist/plugins/profiles/stores/postgres-store.d.ts +18 -0
- package/dist/plugins/profiles/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/profiles/stores/postgres-store.js +310 -0
- package/dist/plugins/profiles/stores/postgres-store.js.map +1 -0
- package/dist/plugins/profiles/types.d.ts +289 -0
- package/dist/plugins/profiles/types.d.ts.map +1 -0
- package/dist/plugins/profiles/types.js +10 -0
- package/dist/plugins/profiles/types.js.map +1 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts +11 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.d.ts.map +1 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js +305 -0
- package/dist/plugins/subscriptions/__tests__/subscriptions-plugin.test.js.map +1 -0
- package/dist/plugins/subscriptions/index.d.ts +12 -0
- package/dist/plugins/subscriptions/index.d.ts.map +1 -0
- package/dist/plugins/subscriptions/index.js +13 -0
- package/dist/plugins/subscriptions/index.js.map +1 -0
- package/dist/plugins/subscriptions/stores/index.d.ts +9 -0
- package/dist/plugins/subscriptions/stores/index.d.ts.map +1 -0
- package/dist/plugins/subscriptions/stores/index.js +9 -0
- package/dist/plugins/subscriptions/stores/index.js.map +1 -0
- package/dist/plugins/subscriptions/stores/postgres-store.d.ts +14 -0
- package/dist/plugins/subscriptions/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/subscriptions/stores/postgres-store.js +359 -0
- package/dist/plugins/subscriptions/stores/postgres-store.js.map +1 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.d.ts +82 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.d.ts.map +1 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.js +449 -0
- package/dist/plugins/subscriptions/subscriptions-plugin.js.map +1 -0
- package/dist/plugins/subscriptions/types.d.ts +308 -0
- package/dist/plugins/subscriptions/types.d.ts.map +1 -0
- package/dist/plugins/subscriptions/types.js +10 -0
- package/dist/plugins/subscriptions/types.js.map +1 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts +11 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.d.ts.map +1 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.js +218 -0
- package/dist/plugins/usage/__tests__/usage-plugin.test.js.map +1 -0
- package/dist/plugins/usage/index.d.ts +12 -0
- package/dist/plugins/usage/index.d.ts.map +1 -0
- package/dist/plugins/usage/index.js +13 -0
- package/dist/plugins/usage/index.js.map +1 -0
- package/dist/plugins/usage/stores/index.d.ts +9 -0
- package/dist/plugins/usage/stores/index.d.ts.map +1 -0
- package/dist/plugins/usage/stores/index.js +9 -0
- package/dist/plugins/usage/stores/index.js.map +1 -0
- package/dist/plugins/usage/stores/postgres-store.d.ts +14 -0
- package/dist/plugins/usage/stores/postgres-store.d.ts.map +1 -0
- package/dist/plugins/usage/stores/postgres-store.js +146 -0
- package/dist/plugins/usage/stores/postgres-store.js.map +1 -0
- package/dist/plugins/usage/types.d.ts +195 -0
- package/dist/plugins/usage/types.d.ts.map +1 -0
- package/dist/plugins/usage/types.js +10 -0
- package/dist/plugins/usage/types.js.map +1 -0
- package/dist/plugins/usage/usage-plugin.d.ts +51 -0
- package/dist/plugins/usage/usage-plugin.d.ts.map +1 -0
- package/dist/plugins/usage/usage-plugin.js +412 -0
- package/dist/plugins/usage/usage-plugin.js.map +1 -0
- package/dist/plugins/users/__tests__/postgres-store.test.d.ts +10 -0
- package/dist/plugins/users/__tests__/postgres-store.test.d.ts.map +1 -0
- package/dist/plugins/users/__tests__/postgres-store.test.js +229 -0
- package/dist/plugins/users/__tests__/postgres-store.test.js.map +1 -0
- package/dist/plugins/users/__tests__/users-plugin.test.js +3 -0
- package/dist/plugins/users/__tests__/users-plugin.test.js.map +1 -1
- package/dist/plugins/users/index.d.ts +2 -2
- package/dist/plugins/users/index.d.ts.map +1 -1
- package/dist/plugins/users/index.js +1 -1
- package/dist/plugins/users/index.js.map +1 -1
- package/dist/plugins/users/stores/postgres-store.d.ts.map +1 -1
- package/dist/plugins/users/stores/postgres-store.js +76 -0
- package/dist/plugins/users/stores/postgres-store.js.map +1 -1
- package/dist/plugins/users/types.d.ts +74 -6
- package/dist/plugins/users/types.d.ts.map +1 -1
- package/dist/plugins/users/users-plugin.d.ts +15 -1
- package/dist/plugins/users/users-plugin.d.ts.map +1 -1
- package/dist/plugins/users/users-plugin.js +29 -0
- package/dist/plugins/users/users-plugin.js.map +1 -1
- package/dist-ui/assets/index-CynOqPkb.js +469 -0
- package/dist-ui/assets/index-CynOqPkb.js.map +1 -0
- package/dist-ui/index.html +1 -1
- package/dist-ui-lib/api/controlPanelApi.d.ts +46 -0
- package/dist-ui-lib/components/StatCard.d.ts +16 -0
- package/dist-ui-lib/dashboard/widgets/NotificationsStatsWidget.d.ts +12 -0
- package/dist-ui-lib/dashboard/widgets/index.d.ts +1 -0
- package/dist-ui-lib/index.js +1822 -1611
- package/dist-ui-lib/index.js.map +1 -1
- package/dist-ui-lib/pages/NotificationsPage.d.ts +9 -0
- package/dist-ui-lib/utils/formatters.d.ts +19 -0
- package/package.json +3 -2
- package/src/index.ts +178 -0
- package/src/plugins/bans/bans-plugin.ts +15 -3
- package/src/plugins/devices/__tests__/devices-plugin.test.ts +551 -0
- package/src/plugins/devices/__tests__/token-utils.test.ts +264 -0
- package/src/plugins/devices/adapters/compute-adapter.ts +139 -0
- package/src/plugins/devices/adapters/index.ts +13 -0
- package/src/plugins/devices/adapters/mobile-adapter.ts +179 -0
- package/src/plugins/devices/devices-plugin.ts +538 -0
- package/src/plugins/devices/index.ts +69 -0
- package/src/plugins/devices/stores/index.ts +9 -0
- package/src/plugins/devices/stores/postgres-store.ts +304 -0
- package/src/plugins/devices/token-utils.ts +213 -0
- package/src/plugins/devices/types.ts +351 -0
- package/src/plugins/index.ts +218 -0
- package/src/plugins/notifications/__tests__/notifications-manager.test.ts +637 -0
- package/src/plugins/notifications/index.ts +91 -0
- package/src/plugins/notifications/notifications-manager.ts +773 -0
- package/src/plugins/notifications/notifications-plugin.ts +398 -0
- package/src/plugins/notifications/types.ts +207 -0
- package/src/plugins/parental/__tests__/parental-plugin.test.ts +465 -0
- package/src/plugins/parental/adapters/index.ts +8 -0
- package/src/plugins/parental/adapters/kids-adapter.ts +206 -0
- package/src/plugins/parental/index.ts +55 -0
- package/src/plugins/parental/parental-plugin.ts +759 -0
- package/src/plugins/parental/stores/index.ts +7 -0
- package/src/plugins/parental/stores/postgres-store.ts +304 -0
- package/src/plugins/parental/types.ts +180 -0
- package/src/plugins/profiles/__tests__/profiles-plugin.test.ts +321 -0
- package/src/plugins/profiles/index.ts +49 -0
- package/src/plugins/profiles/profiles-plugin.ts +546 -0
- package/src/plugins/profiles/stores/index.ts +9 -0
- package/src/plugins/profiles/stores/postgres-store.ts +439 -0
- package/src/plugins/profiles/types.ts +338 -0
- package/src/plugins/subscriptions/__tests__/subscriptions-plugin.test.ts +404 -0
- package/src/plugins/subscriptions/index.ts +51 -0
- package/src/plugins/subscriptions/stores/index.ts +9 -0
- package/src/plugins/subscriptions/stores/postgres-store.ts +482 -0
- package/src/plugins/subscriptions/subscriptions-plugin.ts +530 -0
- package/src/plugins/subscriptions/types.ts +355 -0
- package/src/plugins/usage/__tests__/usage-plugin.test.ts +288 -0
- package/src/plugins/usage/index.ts +39 -0
- package/src/plugins/usage/stores/index.ts +9 -0
- package/src/plugins/usage/stores/postgres-store.ts +213 -0
- package/src/plugins/usage/types.ts +222 -0
- package/src/plugins/usage/usage-plugin.ts +484 -0
- package/src/plugins/users/__tests__/postgres-store.test.ts +326 -0
- package/src/plugins/users/__tests__/users-plugin.test.ts +3 -0
- package/src/plugins/users/index.ts +6 -0
- package/src/plugins/users/stores/postgres-store.ts +104 -0
- package/src/plugins/users/types.ts +82 -6
- package/src/plugins/users/users-plugin.ts +37 -0
- package/ui/src/App.tsx +5 -1
- package/ui/src/api/controlPanelApi.ts +103 -6
- package/ui/src/components/StatCard.tsx +58 -0
- package/ui/src/dashboard/builtInWidgets.tsx +3 -1
- package/ui/src/dashboard/widgets/NotificationsStatsWidget.tsx +167 -0
- package/ui/src/dashboard/widgets/index.ts +1 -0
- package/ui/src/pages/NotificationsPage.tsx +417 -0
- package/ui/src/utils/formatters.ts +33 -0
- package/dist-ui/assets/index-D7DoZ9rL.js +0 -478
- package/dist-ui/assets/index-D7DoZ9rL.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-store.d.ts","sourceRoot":"","sources":["../../../../src/plugins/usage/stores/postgres-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,UAAU,EAGV,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAsBrB;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,UAAU,CA6K/E"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL Usage Store
|
|
3
|
+
*
|
|
4
|
+
* Usage tracking storage implementation using PostgreSQL.
|
|
5
|
+
* Tracks daily and monthly usage counters.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Get current date in YYYY-MM-DD format
|
|
11
|
+
*/
|
|
12
|
+
function getCurrentDate() {
|
|
13
|
+
return new Date().toISOString().split('T')[0];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get current year-month in YYYY-MM format
|
|
17
|
+
*/
|
|
18
|
+
function getCurrentYearMonth() {
|
|
19
|
+
const now = new Date();
|
|
20
|
+
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a PostgreSQL usage store
|
|
24
|
+
*/
|
|
25
|
+
export function postgresUsageStore(config) {
|
|
26
|
+
const { pool: poolOrFn, dailyTable = 'usage_daily', monthlyTable = 'usage_monthly', schema = 'public', autoCreateTables = true, } = config;
|
|
27
|
+
// Helper to get pool (supports lazy initialization via function)
|
|
28
|
+
const getPool = () => {
|
|
29
|
+
const pool = typeof poolOrFn === 'function' ? poolOrFn() : poolOrFn;
|
|
30
|
+
return pool;
|
|
31
|
+
};
|
|
32
|
+
const dailyTableFull = `"${schema}"."${dailyTable}"`;
|
|
33
|
+
const monthlyTableFull = `"${schema}"."${monthlyTable}"`;
|
|
34
|
+
return {
|
|
35
|
+
name: 'postgres',
|
|
36
|
+
async initialize() {
|
|
37
|
+
if (!autoCreateTables)
|
|
38
|
+
return;
|
|
39
|
+
// Create usage_daily table
|
|
40
|
+
await getPool().query(`
|
|
41
|
+
CREATE TABLE IF NOT EXISTS ${dailyTableFull} (
|
|
42
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
43
|
+
user_id UUID NOT NULL,
|
|
44
|
+
feature_code VARCHAR(100) NOT NULL,
|
|
45
|
+
date DATE NOT NULL DEFAULT CURRENT_DATE,
|
|
46
|
+
count INTEGER DEFAULT 0,
|
|
47
|
+
metadata JSONB DEFAULT '{}',
|
|
48
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
49
|
+
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
50
|
+
UNIQUE(user_id, feature_code, date)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_${dailyTable}_user_date ON ${dailyTableFull}(user_id, date);
|
|
54
|
+
CREATE INDEX IF NOT EXISTS idx_${dailyTable}_feature ON ${dailyTableFull}(feature_code);
|
|
55
|
+
CREATE INDEX IF NOT EXISTS idx_${dailyTable}_date ON ${dailyTableFull}(date);
|
|
56
|
+
`);
|
|
57
|
+
// Create usage_monthly table
|
|
58
|
+
await getPool().query(`
|
|
59
|
+
CREATE TABLE IF NOT EXISTS ${monthlyTableFull} (
|
|
60
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
61
|
+
user_id UUID NOT NULL,
|
|
62
|
+
feature_code VARCHAR(100) NOT NULL,
|
|
63
|
+
year_month VARCHAR(7) NOT NULL,
|
|
64
|
+
count INTEGER DEFAULT 0,
|
|
65
|
+
metadata JSONB DEFAULT '{}',
|
|
66
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
67
|
+
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
68
|
+
UNIQUE(user_id, feature_code, year_month)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
CREATE INDEX IF NOT EXISTS idx_${monthlyTable}_user ON ${monthlyTableFull}(user_id, year_month);
|
|
72
|
+
CREATE INDEX IF NOT EXISTS idx_${monthlyTable}_feature ON ${monthlyTableFull}(feature_code);
|
|
73
|
+
`);
|
|
74
|
+
},
|
|
75
|
+
async getDailyUsage(userId, featureCode, date) {
|
|
76
|
+
const targetDate = date || getCurrentDate();
|
|
77
|
+
const result = await getPool().query(`SELECT * FROM ${dailyTableFull}
|
|
78
|
+
WHERE user_id = $1 AND feature_code = $2 AND date = $3`, [userId, featureCode, targetDate]);
|
|
79
|
+
return result.rows[0] || null;
|
|
80
|
+
},
|
|
81
|
+
async getMonthlyUsage(userId, featureCode, yearMonth) {
|
|
82
|
+
const targetMonth = yearMonth || getCurrentYearMonth();
|
|
83
|
+
const result = await getPool().query(`SELECT * FROM ${monthlyTableFull}
|
|
84
|
+
WHERE user_id = $1 AND feature_code = $2 AND year_month = $3`, [userId, featureCode, targetMonth]);
|
|
85
|
+
return result.rows[0] || null;
|
|
86
|
+
},
|
|
87
|
+
async incrementDaily(userId, featureCode, amount = 1, date) {
|
|
88
|
+
const targetDate = date || getCurrentDate();
|
|
89
|
+
const yearMonth = targetDate.substring(0, 7); // Extract YYYY-MM from YYYY-MM-DD
|
|
90
|
+
// Increment daily usage (upsert)
|
|
91
|
+
const dailyResult = await getPool().query(`INSERT INTO ${dailyTableFull} (user_id, feature_code, date, count)
|
|
92
|
+
VALUES ($1, $2, $3, $4)
|
|
93
|
+
ON CONFLICT (user_id, feature_code, date)
|
|
94
|
+
DO UPDATE SET count = ${dailyTableFull}.count + $4, updated_at = NOW()
|
|
95
|
+
RETURNING count`, [userId, featureCode, targetDate, amount]);
|
|
96
|
+
const newCount = dailyResult.rows[0].count;
|
|
97
|
+
// Also increment monthly usage
|
|
98
|
+
await getPool().query(`INSERT INTO ${monthlyTableFull} (user_id, feature_code, year_month, count)
|
|
99
|
+
VALUES ($1, $2, $3, $4)
|
|
100
|
+
ON CONFLICT (user_id, feature_code, year_month)
|
|
101
|
+
DO UPDATE SET count = ${monthlyTableFull}.count + $4, updated_at = NOW()`, [userId, featureCode, yearMonth, amount]);
|
|
102
|
+
return newCount;
|
|
103
|
+
},
|
|
104
|
+
async getAllDailyUsage(userId, date) {
|
|
105
|
+
const targetDate = date || getCurrentDate();
|
|
106
|
+
const result = await getPool().query(`SELECT * FROM ${dailyTableFull}
|
|
107
|
+
WHERE user_id = $1 AND date = $2
|
|
108
|
+
ORDER BY feature_code`, [userId, targetDate]);
|
|
109
|
+
return result.rows;
|
|
110
|
+
},
|
|
111
|
+
async getAllMonthlyUsage(userId, yearMonth) {
|
|
112
|
+
const targetMonth = yearMonth || getCurrentYearMonth();
|
|
113
|
+
const result = await getPool().query(`SELECT * FROM ${monthlyTableFull}
|
|
114
|
+
WHERE user_id = $1 AND year_month = $2
|
|
115
|
+
ORDER BY feature_code`, [userId, targetMonth]);
|
|
116
|
+
return result.rows;
|
|
117
|
+
},
|
|
118
|
+
async resetDailyUsage(userId, featureCode, date) {
|
|
119
|
+
const targetDate = date || getCurrentDate();
|
|
120
|
+
await getPool().query(`UPDATE ${dailyTableFull}
|
|
121
|
+
SET count = 0, updated_at = NOW()
|
|
122
|
+
WHERE user_id = $1 AND feature_code = $2 AND date = $3`, [userId, featureCode, targetDate]);
|
|
123
|
+
},
|
|
124
|
+
async cleanupOldDaily(daysToKeep) {
|
|
125
|
+
// Calculate cutoff date to avoid SQL interpolation
|
|
126
|
+
const cutoffDate = new Date();
|
|
127
|
+
cutoffDate.setDate(cutoffDate.getDate() - daysToKeep);
|
|
128
|
+
const cutoffDateStr = cutoffDate.toISOString().split('T')[0];
|
|
129
|
+
const result = await getPool().query(`DELETE FROM ${dailyTableFull} WHERE date < $1`, [cutoffDateStr]);
|
|
130
|
+
return result.rowCount ?? 0;
|
|
131
|
+
},
|
|
132
|
+
async cleanupOldMonthly(monthsToKeep) {
|
|
133
|
+
// Calculate the cutoff year-month
|
|
134
|
+
const now = new Date();
|
|
135
|
+
now.setMonth(now.getMonth() - monthsToKeep);
|
|
136
|
+
const cutoffMonth = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
|
137
|
+
const result = await getPool().query(`DELETE FROM ${monthlyTableFull}
|
|
138
|
+
WHERE year_month < $1`, [cutoffMonth]);
|
|
139
|
+
return result.rowCount ?? 0;
|
|
140
|
+
},
|
|
141
|
+
async shutdown() {
|
|
142
|
+
// Pool is managed externally, nothing to do here
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=postgres-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-store.js","sourceRoot":"","sources":["../../../../src/plugins/usage/stores/postgres-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH;;GAEG;AACH,SAAS,cAAc;IACrB,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB;IAC1B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,GAAG,GAAG,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAgC;IACjE,MAAM,EACJ,IAAI,EAAE,QAAQ,EACd,UAAU,GAAG,aAAa,EAC1B,YAAY,GAAG,eAAe,EAC9B,MAAM,GAAG,QAAQ,EACjB,gBAAgB,GAAG,IAAI,GACxB,GAAG,MAAM,CAAC;IAEX,iEAAiE;IACjE,MAAM,OAAO,GAAG,GAAW,EAAE;QAC3B,MAAM,IAAI,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACpE,OAAO,IAAc,CAAC;IACxB,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,IAAI,MAAM,MAAM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CAAC,QAAQ,IAAI,CAAC,CAAC;QAC9B,CAAC;QAED,KAAK,CAAC,QAAQ;YACZ,iDAAiD;QACnD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage Plugin Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for usage tracking with daily/monthly counters.
|
|
5
|
+
* Integrates with subscriptions-plugin for limit enforcement.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Daily usage record
|
|
11
|
+
*/
|
|
12
|
+
export interface DailyUsage {
|
|
13
|
+
/** Primary key - UUID */
|
|
14
|
+
id: string;
|
|
15
|
+
/** User ID */
|
|
16
|
+
user_id: string;
|
|
17
|
+
/** Feature code (e.g., 'ai_messages', 'vision_calls') */
|
|
18
|
+
feature_code: string;
|
|
19
|
+
/** Date (YYYY-MM-DD) */
|
|
20
|
+
date: string;
|
|
21
|
+
/** Usage count */
|
|
22
|
+
count: number;
|
|
23
|
+
/** Additional metadata */
|
|
24
|
+
metadata: Record<string, unknown>;
|
|
25
|
+
/** When the record was created */
|
|
26
|
+
created_at: Date;
|
|
27
|
+
/** When the record was last updated */
|
|
28
|
+
updated_at: Date;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Monthly usage record
|
|
32
|
+
*/
|
|
33
|
+
export interface MonthlyUsage {
|
|
34
|
+
/** Primary key - UUID */
|
|
35
|
+
id: string;
|
|
36
|
+
/** User ID */
|
|
37
|
+
user_id: string;
|
|
38
|
+
/** Feature code */
|
|
39
|
+
feature_code: string;
|
|
40
|
+
/** Year-month (YYYY-MM) */
|
|
41
|
+
year_month: string;
|
|
42
|
+
/** Usage count */
|
|
43
|
+
count: number;
|
|
44
|
+
/** Additional metadata */
|
|
45
|
+
metadata: Record<string, unknown>;
|
|
46
|
+
/** When the record was created */
|
|
47
|
+
created_at: Date;
|
|
48
|
+
/** When the record was last updated */
|
|
49
|
+
updated_at: Date;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Usage increment result
|
|
53
|
+
*/
|
|
54
|
+
export interface UsageIncrementResult {
|
|
55
|
+
/** Whether the increment was allowed */
|
|
56
|
+
allowed: boolean;
|
|
57
|
+
/** Current count after increment (if allowed) */
|
|
58
|
+
current_count: number;
|
|
59
|
+
/** Limit value (-1 = unlimited) */
|
|
60
|
+
limit: number | null;
|
|
61
|
+
/** Remaining quota */
|
|
62
|
+
remaining: number | null;
|
|
63
|
+
/** When the counter resets */
|
|
64
|
+
resets_at?: Date;
|
|
65
|
+
/** Reason if not allowed */
|
|
66
|
+
reason?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Usage status for a feature
|
|
70
|
+
*/
|
|
71
|
+
export interface UsageStatus {
|
|
72
|
+
/** Feature code */
|
|
73
|
+
feature_code: string;
|
|
74
|
+
/** Current usage count */
|
|
75
|
+
current: number;
|
|
76
|
+
/** Limit value (-1 = unlimited, null = no subscription) */
|
|
77
|
+
limit: number | null;
|
|
78
|
+
/** Remaining quota (-1 = unlimited) */
|
|
79
|
+
remaining: number | null;
|
|
80
|
+
/** When the counter resets */
|
|
81
|
+
resets_at: Date;
|
|
82
|
+
/** Percentage used (0-100, null if unlimited) */
|
|
83
|
+
percentage_used: number | null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Usage summary for a user
|
|
87
|
+
*/
|
|
88
|
+
export interface UsageSummary {
|
|
89
|
+
/** User ID */
|
|
90
|
+
user_id: string;
|
|
91
|
+
/** Period (daily or monthly) */
|
|
92
|
+
period: 'daily' | 'monthly';
|
|
93
|
+
/** Period date/month */
|
|
94
|
+
period_value: string;
|
|
95
|
+
/** Usage by feature */
|
|
96
|
+
features: UsageStatus[];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Usage store interface
|
|
100
|
+
*/
|
|
101
|
+
export interface UsageStore {
|
|
102
|
+
/** Store name (e.g., 'postgres') */
|
|
103
|
+
name: string;
|
|
104
|
+
/**
|
|
105
|
+
* Initialize the store (create tables, etc.)
|
|
106
|
+
*/
|
|
107
|
+
initialize(): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Get daily usage for a user and feature
|
|
110
|
+
*/
|
|
111
|
+
getDailyUsage(userId: string, featureCode: string, date?: string): Promise<DailyUsage | null>;
|
|
112
|
+
/**
|
|
113
|
+
* Get monthly usage for a user and feature
|
|
114
|
+
*/
|
|
115
|
+
getMonthlyUsage(userId: string, featureCode: string, yearMonth?: string): Promise<MonthlyUsage | null>;
|
|
116
|
+
/**
|
|
117
|
+
* Increment daily usage (also updates monthly)
|
|
118
|
+
*/
|
|
119
|
+
incrementDaily(userId: string, featureCode: string, amount?: number, date?: string): Promise<number>;
|
|
120
|
+
/**
|
|
121
|
+
* Get all daily usage for a user on a date
|
|
122
|
+
*/
|
|
123
|
+
getAllDailyUsage(userId: string, date?: string): Promise<DailyUsage[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Get all monthly usage for a user
|
|
126
|
+
*/
|
|
127
|
+
getAllMonthlyUsage(userId: string, yearMonth?: string): Promise<MonthlyUsage[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Reset daily usage for a user and feature
|
|
130
|
+
*/
|
|
131
|
+
resetDailyUsage(userId: string, featureCode: string, date?: string): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Cleanup old daily records
|
|
134
|
+
*/
|
|
135
|
+
cleanupOldDaily(daysToKeep: number): Promise<number>;
|
|
136
|
+
/**
|
|
137
|
+
* Cleanup old monthly records
|
|
138
|
+
*/
|
|
139
|
+
cleanupOldMonthly(monthsToKeep: number): Promise<number>;
|
|
140
|
+
/**
|
|
141
|
+
* Shutdown the store
|
|
142
|
+
*/
|
|
143
|
+
shutdown(): Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* PostgreSQL usage store configuration
|
|
147
|
+
*/
|
|
148
|
+
export interface PostgresUsageStoreConfig {
|
|
149
|
+
/** PostgreSQL pool instance or a function that returns one */
|
|
150
|
+
pool: unknown | (() => unknown);
|
|
151
|
+
/** Daily usage table name (default: 'usage_daily') */
|
|
152
|
+
dailyTable?: string;
|
|
153
|
+
/** Monthly usage table name (default: 'usage_monthly') */
|
|
154
|
+
monthlyTable?: string;
|
|
155
|
+
/** Schema name (default: 'public') */
|
|
156
|
+
schema?: string;
|
|
157
|
+
/** Auto-create tables on init (default: true) */
|
|
158
|
+
autoCreateTables?: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* API configuration
|
|
162
|
+
*/
|
|
163
|
+
export interface UsageApiConfig {
|
|
164
|
+
/** API route prefix (default: '/usage') */
|
|
165
|
+
prefix?: string;
|
|
166
|
+
/** Enable usage endpoints */
|
|
167
|
+
enabled?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Cleanup configuration
|
|
171
|
+
*/
|
|
172
|
+
export interface UsageCleanupConfig {
|
|
173
|
+
/** Days to keep daily records (default: 90) */
|
|
174
|
+
dailyRetentionDays?: number;
|
|
175
|
+
/** Months to keep monthly records (default: 24) */
|
|
176
|
+
monthlyRetentionMonths?: number;
|
|
177
|
+
/** Run cleanup on startup */
|
|
178
|
+
runOnStartup?: boolean;
|
|
179
|
+
/** Cleanup interval in hours (0 = disabled) */
|
|
180
|
+
cleanupIntervalHours?: number;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Usage plugin configuration
|
|
184
|
+
*/
|
|
185
|
+
export interface UsagePluginConfig {
|
|
186
|
+
/** Usage storage backend */
|
|
187
|
+
store: UsageStore;
|
|
188
|
+
/** API configuration */
|
|
189
|
+
api?: UsageApiConfig;
|
|
190
|
+
/** Cleanup configuration */
|
|
191
|
+
cleanup?: UsageCleanupConfig;
|
|
192
|
+
/** Enable debug logging */
|
|
193
|
+
debug?: boolean;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/usage/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,kCAAkC;IAClC,UAAU,EAAE,IAAI,CAAC;IACjB,uCAAuC;IACvC,UAAU,EAAE,IAAI,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,kCAAkC;IAClC,UAAU,EAAE,IAAI,CAAC;IACjB,uCAAuC;IACvC,UAAU,EAAE,IAAI,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,aAAa,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,sBAAsB;IACtB,SAAS,EAAE,MAA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kB;IACjC,+CAA+C;IAC/C,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mDAAmD;IACnD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,6BAA6B;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,+CAA+C;IAC/C,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,wBAAwB;IACxB,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage Plugin Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for usage tracking with daily/monthly counters.
|
|
5
|
+
* Integrates with subscriptions-plugin for limit enforcement.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plugins/usage/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage Plugin
|
|
3
|
+
*
|
|
4
|
+
* Usage tracking plugin for @qwickapps/server.
|
|
5
|
+
* Tracks daily/monthly feature usage and enforces limits.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
8
|
+
*/
|
|
9
|
+
import type { Plugin } from '../../core/plugin-registry.js';
|
|
10
|
+
import type { UsagePluginConfig, UsageStore, UsageIncrementResult, UsageStatus, UsageSummary } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Create the Usage plugin
|
|
13
|
+
*/
|
|
14
|
+
export declare function createUsagePlugin(config: UsagePluginConfig): Plugin;
|
|
15
|
+
/**
|
|
16
|
+
* Get the current usage store instance
|
|
17
|
+
*/
|
|
18
|
+
export declare function getUsageStore(): UsageStore | null;
|
|
19
|
+
/**
|
|
20
|
+
* Get current daily usage for a feature
|
|
21
|
+
*/
|
|
22
|
+
export declare function getDailyUsage(userId: string, featureCode: string): Promise<number>;
|
|
23
|
+
/**
|
|
24
|
+
* Increment usage and check limit
|
|
25
|
+
*/
|
|
26
|
+
export declare function incrementUsage(userId: string, featureCode: string, amount?: number): Promise<UsageIncrementResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Check if usage is within limit (without incrementing)
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkUsageLimit(userId: string, featureCode: string, amount?: number): Promise<UsageIncrementResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Get usage status for a specific feature
|
|
33
|
+
*/
|
|
34
|
+
export declare function getFeatureUsageStatus(userId: string, featureCode: string): Promise<UsageStatus>;
|
|
35
|
+
/**
|
|
36
|
+
* Get daily usage summary for all features
|
|
37
|
+
*/
|
|
38
|
+
export declare function getDailyUsageSummary(userId: string, date?: string): Promise<UsageSummary>;
|
|
39
|
+
/**
|
|
40
|
+
* Reset usage for a feature (admin function)
|
|
41
|
+
*/
|
|
42
|
+
export declare function resetUsage(userId: string, featureCode: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get remaining quota for a feature
|
|
45
|
+
*/
|
|
46
|
+
export declare function getRemainingQuota(userId: string, featureCode: string): Promise<number | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Check if user can use a feature (has remaining quota)
|
|
49
|
+
*/
|
|
50
|
+
export declare function canUseFeature(userId: string, featureCode: string, amount?: number): Promise<boolean>;
|
|
51
|
+
//# sourceMappingURL=usage-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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