prow-authority 3.6.3
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/.claude/settings.local.json +11 -0
- package/.dockerignore +11 -0
- package/.github/workflows/_deploy.yml +191 -0
- package/.github/workflows/deploy-dev.yml +30 -0
- package/.github/workflows/deploy-prod.yml +34 -0
- package/CLAUDE.md +114 -0
- package/Dockerfile +61 -0
- package/Dockerfile.dev +24 -0
- package/README.md +1 -0
- package/package.json +61 -0
- package/src/App.ts +40 -0
- package/src/helpers/api-error.ts +21 -0
- package/src/helpers/authority.ts +216 -0
- package/src/helpers/config.ts +4 -0
- package/src/helpers/holded.ts +105 -0
- package/src/helpers/mysql.ts +15 -0
- package/src/helpers/notifications.ts +55 -0
- package/src/helpers/random.ts +18 -0
- package/src/helpers/s3.ts +43 -0
- package/src/helpers/stripe.ts +8 -0
- package/src/index.ts +47 -0
- package/src/v1/common-types.ts +12 -0
- package/src/v1/controllers/admin/accounting-seat-controller.ts +148 -0
- package/src/v1/controllers/admin/billing-cycle-controller.ts +171 -0
- package/src/v1/controllers/admin/invoice-controller.ts +222 -0
- package/src/v1/controllers/admin/license-controller.ts +190 -0
- package/src/v1/controllers/admin/license-limit-controller.ts +160 -0
- package/src/v1/controllers/admin/notification-controller.ts +115 -0
- package/src/v1/controllers/admin/organization-controller.ts +210 -0
- package/src/v1/controllers/admin/organization-license-controller.ts +224 -0
- package/src/v1/controllers/admin/organization-license-limit-controller.ts +196 -0
- package/src/v1/controllers/admin/organization-usage-controller.ts +167 -0
- package/src/v1/controllers/admin/payment-method-controller.ts +173 -0
- package/src/v1/controllers/admin/policy-controller.ts +138 -0
- package/src/v1/controllers/admin/policy-version-controller.ts +143 -0
- package/src/v1/controllers/admin/schedule-controller.ts +181 -0
- package/src/v1/controllers/admin/service-controller.ts +206 -0
- package/src/v1/controllers/admin/service-notification-controller.ts +166 -0
- package/src/v1/controllers/admin/user-controller.ts +282 -0
- package/src/v1/controllers/admin/user-organization-controller.ts +172 -0
- package/src/v1/controllers/admin/user-policy-controller.ts +164 -0
- package/src/v1/controllers/auth/@deprecated oauth-controller.ts +191 -0
- package/src/v1/controllers/auth/identity-token-controller.ts +286 -0
- package/src/v1/controllers/auth/organization-token-controller.ts +277 -0
- package/src/v1/controllers/auth/temp-code-controller.ts +60 -0
- package/src/v1/controllers/billing/billing-controller.ts +805 -0
- package/src/v1/controllers/organizations/public-organization-controller.ts +1796 -0
- package/src/v1/controllers/policies/public-policy-controller.ts +68 -0
- package/src/v1/controllers/services/public-service-controller.ts +177 -0
- package/src/v1/controllers/services/service-controller.ts +474 -0
- package/src/v1/controllers/users/public-user-controller.ts +471 -0
- package/src/v1/daos/@deprecated auth-dao.ts +173 -0
- package/src/v1/daos/accounting-seat-dao.ts +111 -0
- package/src/v1/daos/billing-cycle-dao.ts +107 -0
- package/src/v1/daos/invoice-dao.ts +131 -0
- package/src/v1/daos/license-dao.ts +152 -0
- package/src/v1/daos/license-limit-dao.ts +120 -0
- package/src/v1/daos/organization-dao.ts +109 -0
- package/src/v1/daos/organization-license-dao.ts +117 -0
- package/src/v1/daos/organization-license-limit-dao.ts +157 -0
- package/src/v1/daos/organization-usage-dao.ts +115 -0
- package/src/v1/daos/payment-method-dao.ts +110 -0
- package/src/v1/daos/policy-dao.ts +105 -0
- package/src/v1/daos/policy-version-dao.ts +112 -0
- package/src/v1/daos/redis-dao.ts +38 -0
- package/src/v1/daos/schema.sql +462 -0
- package/src/v1/daos/service-dao.ts +118 -0
- package/src/v1/daos/service-notification-dao.ts +120 -0
- package/src/v1/daos/user-dao.ts +127 -0
- package/src/v1/daos/user-organization-dao.ts +123 -0
- package/src/v1/daos/user-policy-dao.ts +109 -0
- package/src/v1/middlewares/auth/identity-token-middleware.ts +51 -0
- package/src/v1/middlewares/auth/organization-token-middleware.ts +73 -0
- package/src/v1/middlewares/auth/service-token-middleware.ts +167 -0
- package/src/v1/middlewares/authority-middleware.ts +97 -0
- package/src/v1/middlewares/organizations/organization-middleware.ts +94 -0
- package/src/v1/middlewares/static/static-middleware.ts +41 -0
- package/src/v1/middlewares/users/user-middleware.ts +41 -0
- package/src/v1/routes/admin/accounting-seat-router.ts +89 -0
- package/src/v1/routes/admin/admin-router.ts +61 -0
- package/src/v1/routes/admin/billing-cycle-router.ts +89 -0
- package/src/v1/routes/admin/invoice-router.ts +89 -0
- package/src/v1/routes/admin/license-limit-router.ts +89 -0
- package/src/v1/routes/admin/license-router.ts +89 -0
- package/src/v1/routes/admin/notification-router.ts +61 -0
- package/src/v1/routes/admin/organization-license-limit-router.ts +89 -0
- package/src/v1/routes/admin/organization-license-router.ts +89 -0
- package/src/v1/routes/admin/organization-router.ts +89 -0
- package/src/v1/routes/admin/payment-method-router.ts +89 -0
- package/src/v1/routes/admin/policy-router.ts +89 -0
- package/src/v1/routes/admin/policy-version-router.ts +89 -0
- package/src/v1/routes/admin/schedule-router.ts +75 -0
- package/src/v1/routes/admin/service-notification-router.ts +98 -0
- package/src/v1/routes/admin/service-router.ts +89 -0
- package/src/v1/routes/admin/user-organization-router.ts +89 -0
- package/src/v1/routes/admin/user-policy-router.ts +89 -0
- package/src/v1/routes/admin/user-router.ts +89 -0
- package/src/v1/routes/auth/@deprecated auth-router.ts +199 -0
- package/src/v1/routes/auth/identity-token-router.ts +147 -0
- package/src/v1/routes/auth/organization-token-router.ts +70 -0
- package/src/v1/routes/billing/billing-router.ts +227 -0
- package/src/v1/routes/organizations/invoices-router.ts +48 -0
- package/src/v1/routes/organizations/payments-router.ts +104 -0
- package/src/v1/routes/organizations/public-organization-router.ts +319 -0
- package/src/v1/routes/organizations/users-router.ts +139 -0
- package/src/v1/routes/policies/public-policy-router.ts +50 -0
- package/src/v1/routes/services/public-service-router.ts +89 -0
- package/src/v1/routes/services/service-router.ts +197 -0
- package/src/v1/routes/users/public-user-router.ts +230 -0
- package/src/v1/routes/v1-router.ts +50 -0
- package/src/v1/schemas/admin/accounting-seat-schemas.ts +22 -0
- package/src/v1/schemas/admin/billing-cycle-schemas.ts +20 -0
- package/src/v1/schemas/admin/invoice-schemas.ts +41 -0
- package/src/v1/schemas/admin/license-limit-schemas.ts +25 -0
- package/src/v1/schemas/admin/license-schemas.ts +30 -0
- package/src/v1/schemas/admin/organization-license-limit-schemas.ts +29 -0
- package/src/v1/schemas/admin/organization-license-schemas.ts +43 -0
- package/src/v1/schemas/admin/organization-schemas.ts +67 -0
- package/src/v1/schemas/admin/organization-usage-schemas.ts +15 -0
- package/src/v1/schemas/admin/payment-method-schemas.ts +40 -0
- package/src/v1/schemas/admin/policy-schemas.ts +31 -0
- package/src/v1/schemas/admin/service-notification-schemas.ts +23 -0
- package/src/v1/schemas/admin/service-schemas.ts +56 -0
- package/src/v1/schemas/admin/user-organization-schemas.ts +24 -0
- package/src/v1/schemas/admin/user-policy-schemas.ts +17 -0
- package/src/v1/schemas/admin/user-schemas.ts +52 -0
- package/src/v1/schemas/auth/auth-schemas.ts +55 -0
- package/src/v1/schemas/billing/billing-schemas.ts +32 -0
- package/src/v1/schemas/organizations/public-organization-schemas.ts +77 -0
- package/src/v1/schemas/payments/payment-method-schemas.ts +0 -0
- package/src/v1/schemas/services/public-service-schemas.ts +5 -0
- package/src/v1/schemas/services/service-schemas.ts +27 -0
- package/src/v1/schemas/users/public-user-schemas.ts +73 -0
- package/src/v1/types/admin/accounting-seat-types.ts +16 -0
- package/src/v1/types/admin/billing-cycle-types.ts +14 -0
- package/src/v1/types/admin/invoice-types.ts +39 -0
- package/src/v1/types/admin/license-limit-types.ts +16 -0
- package/src/v1/types/admin/license-types.ts +29 -0
- package/src/v1/types/admin/organization-license-limit-types.ts +13 -0
- package/src/v1/types/admin/organization-license-types.ts +21 -0
- package/src/v1/types/admin/organization-types.ts +60 -0
- package/src/v1/types/admin/organization-usage-types.ts +17 -0
- package/src/v1/types/admin/payment-method-types.ts +30 -0
- package/src/v1/types/admin/policy-types.ts +9 -0
- package/src/v1/types/admin/policy-version-types.ts +12 -0
- package/src/v1/types/admin/service-notification-types.ts +20 -0
- package/src/v1/types/admin/service-types.ts +36 -0
- package/src/v1/types/admin/user-organization-types.ts +31 -0
- package/src/v1/types/admin/user-types.ts +44 -0
- package/src/v1/types/auth/@deprecated auth-types.ts +26 -0
- package/src/v1/types/auth/common-types.ts +7 -0
- package/src/v1/types/auth/confirmation-types.ts +5 -0
- package/src/v1/types/auth/identity-token-types.ts +8 -0
- package/src/v1/types/auth/organization-token-types.ts +23 -0
- package/src/v1/types/auth/otp-types.ts +12 -0
- package/src/v1/types/billing/billing-types.ts +37 -0
- package/src/v1/types/billing/ue-types.ts +29 -0
- package/src/v1/types/organizations/public-organization-types.ts +76 -0
- package/src/v1/types/policies/public-policy-types.ts +7 -0
- package/src/v1/types/services/public-service-types.ts +20 -0
- package/src/v1/types/services/service-types.ts +43 -0
- package/src/v1/types/users/public-user-types.ts +15 -0
- package/src/v1/types/users/user-policy-types.ts +11 -0
- package/static/error.html +55 -0
- package/static/grant.html +117 -0
- package/static/login.html +54 -0
- package/static/oauth-client-logo.webp +0 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Where } from '@beseif-solutions/utility-functions/dist/utils/sql-utils';
|
|
2
|
+
import mySql from '../../helpers/mysql';
|
|
3
|
+
import { DBRecord } from '../types/admin/policy-types';
|
|
4
|
+
import { Modifiers } from '../common-types';
|
|
5
|
+
|
|
6
|
+
class PolicyDao {
|
|
7
|
+
public readonly get = async (
|
|
8
|
+
params: Pick<DBRecord, 'id'>
|
|
9
|
+
): Promise<DBRecord[]> => {
|
|
10
|
+
try {
|
|
11
|
+
const { query: q, params: p } = await mySql.queryConstructor<DBRecord>({
|
|
12
|
+
select: `*`,
|
|
13
|
+
from: `policy`,
|
|
14
|
+
where: params,
|
|
15
|
+
});
|
|
16
|
+
const response = await mySql.promiseQuery(q, p);
|
|
17
|
+
return response;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
public readonly list = async (params: Where<DBRecord>, modifiers: Modifiers = {}): Promise<DBRecord[]> => {
|
|
24
|
+
try {
|
|
25
|
+
const { query: q, params: p } = await mySql.queryConstructor<DBRecord>({
|
|
26
|
+
select: `*`,
|
|
27
|
+
from: `policy`,
|
|
28
|
+
where: params,
|
|
29
|
+
...modifiers.order && { order: { by: modifiers.order.by, direction: modifiers.order.direction } },
|
|
30
|
+
...modifiers.limit && {
|
|
31
|
+
limit: {
|
|
32
|
+
count: parseInt(modifiers.limit.count, 10),
|
|
33
|
+
...modifiers.limit.from && { from: parseInt(modifiers.limit.from, 10) },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const response = await mySql.promiseQuery(q, p);
|
|
38
|
+
return response;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
public readonly add = async (
|
|
45
|
+
data: Omit<DBRecord, 'id'>
|
|
46
|
+
): Promise<{ insertId: number }> => {
|
|
47
|
+
try {
|
|
48
|
+
const q = `insert into policy (uuid, name, metadata, internal) values (?,?,?,?)`;
|
|
49
|
+
const p = [
|
|
50
|
+
data.uuid,
|
|
51
|
+
data.name,
|
|
52
|
+
JSON.stringify(data.metadata || {}),
|
|
53
|
+
JSON.stringify(data.internal || {}),
|
|
54
|
+
];
|
|
55
|
+
const response = await mySql.promiseQuery(q, p);
|
|
56
|
+
return response;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
public readonly update = async (
|
|
63
|
+
params: Pick<DBRecord, 'id'>,
|
|
64
|
+
data: Omit<DBRecord, 'id'>
|
|
65
|
+
): Promise<{ affectedRows: number }> => {
|
|
66
|
+
try {
|
|
67
|
+
const q = `update policy set
|
|
68
|
+
uuid = ?,
|
|
69
|
+
name = ?,
|
|
70
|
+
metadata = ?,
|
|
71
|
+
internal = ?
|
|
72
|
+
where id = ?`;
|
|
73
|
+
const p = [
|
|
74
|
+
data.uuid,
|
|
75
|
+
data.name,
|
|
76
|
+
JSON.stringify(data.metadata || {}),
|
|
77
|
+
JSON.stringify(data.internal || {}),
|
|
78
|
+
params.id,
|
|
79
|
+
];
|
|
80
|
+
const response = await mySql.promiseQuery(q, p);
|
|
81
|
+
return response;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
public readonly delete = async (
|
|
88
|
+
params: Pick<DBRecord, 'id'>
|
|
89
|
+
): Promise<{ affectedRows: number }> => {
|
|
90
|
+
try {
|
|
91
|
+
const { query: q, params: p } = await mySql.queryConstructor<DBRecord>({
|
|
92
|
+
delete: null,
|
|
93
|
+
from: `policy`,
|
|
94
|
+
where: params,
|
|
95
|
+
});
|
|
96
|
+
const response = await mySql.promiseQuery(q, p);
|
|
97
|
+
return response;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const policyDao = new PolicyDao();
|
|
105
|
+
export default policyDao;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Where } from '@beseif-solutions/utility-functions/dist/utils/sql-utils';
|
|
2
|
+
import mySql from '../../helpers/mysql';
|
|
3
|
+
import { DBRecord } from '../types/admin/policy-version-types';
|
|
4
|
+
import { Modifiers } from '../common-types';
|
|
5
|
+
|
|
6
|
+
class PolicyVersionDao {
|
|
7
|
+
public readonly get = async (
|
|
8
|
+
params: Pick<DBRecord, 'id'>
|
|
9
|
+
): Promise<DBRecord[]> => {
|
|
10
|
+
try {
|
|
11
|
+
const { query: q, params: p } = await mySql.queryConstructor<DBRecord>({
|
|
12
|
+
select: `*`,
|
|
13
|
+
from: `policy_version`,
|
|
14
|
+
where: params,
|
|
15
|
+
});
|
|
16
|
+
const response = await mySql.promiseQuery(q, p);
|
|
17
|
+
return response;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
public readonly list = async (params: Where<DBRecord>, modifiers: Modifiers = {}): Promise<DBRecord[]> => {
|
|
24
|
+
try {
|
|
25
|
+
const { query: q, params: p } = await mySql.queryConstructor<DBRecord>({
|
|
26
|
+
select: `*`,
|
|
27
|
+
from: `policy_version`,
|
|
28
|
+
where: params,
|
|
29
|
+
...modifiers.order && { order: { by: modifiers.order.by, direction: modifiers.order.direction } },
|
|
30
|
+
...modifiers.limit && {
|
|
31
|
+
limit: {
|
|
32
|
+
count: parseInt(modifiers.limit.count, 10),
|
|
33
|
+
...modifiers.limit.from && { from: parseInt(modifiers.limit.from, 10) },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const response = await mySql.promiseQuery(q, p);
|
|
38
|
+
return response;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
public readonly add = async (
|
|
45
|
+
data: Omit<DBRecord, 'id' | 'created_date'>
|
|
46
|
+
): Promise<{ insertId: number }> => {
|
|
47
|
+
try {
|
|
48
|
+
const q = `insert into policy_version (policy, version, url, metadata, internal, created_date, effective_date) values (?,?,?,?,?,?,?)`;
|
|
49
|
+
const p = [
|
|
50
|
+
data.policy,
|
|
51
|
+
data.version,
|
|
52
|
+
data.url,
|
|
53
|
+
JSON.stringify(data.metadata || {}),
|
|
54
|
+
JSON.stringify(data.internal || {}),
|
|
55
|
+
new Date(),
|
|
56
|
+
data.effective_date ? new Date(data.effective_date) : null,
|
|
57
|
+
];
|
|
58
|
+
const response = await mySql.promiseQuery(q, p);
|
|
59
|
+
return response;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
public readonly update = async (
|
|
66
|
+
params: Pick<DBRecord, 'id'>,
|
|
67
|
+
data: Omit<DBRecord, 'id' | 'created_date'>
|
|
68
|
+
): Promise<{ affectedRows: number }> => {
|
|
69
|
+
try {
|
|
70
|
+
const q = `update policy_version set
|
|
71
|
+
policy = ?,
|
|
72
|
+
version = ?,
|
|
73
|
+
url = ?,
|
|
74
|
+
metadata = ?,
|
|
75
|
+
internal = ?,
|
|
76
|
+
effective_date = ?
|
|
77
|
+
where id = ?`;
|
|
78
|
+
const p = [
|
|
79
|
+
data.policy,
|
|
80
|
+
data.version,
|
|
81
|
+
data.url,
|
|
82
|
+
JSON.stringify(data.metadata || {}),
|
|
83
|
+
JSON.stringify(data.internal || {}),
|
|
84
|
+
data.effective_date ? new Date(data.effective_date) : null,
|
|
85
|
+
params.id,
|
|
86
|
+
];
|
|
87
|
+
const response = await mySql.promiseQuery(q, p);
|
|
88
|
+
return response;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
public readonly delete = async (
|
|
95
|
+
params: Pick<DBRecord, 'id'>
|
|
96
|
+
): Promise<{ affectedRows: number }> => {
|
|
97
|
+
try {
|
|
98
|
+
const { query: q, params: p } = await mySql.queryConstructor<DBRecord>({
|
|
99
|
+
delete: null,
|
|
100
|
+
from: `policy_version`,
|
|
101
|
+
where: params,
|
|
102
|
+
});
|
|
103
|
+
const response = await mySql.promiseQuery(q, p);
|
|
104
|
+
return response;
|
|
105
|
+
} catch (e) {
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const policyVersionDao = new PolicyVersionDao();
|
|
112
|
+
export default policyVersionDao;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import { Redis } from '@beseif-solutions/utility-functions/dist/utils/sql-utils';
|
|
3
|
+
import nconf from '../../helpers/config';
|
|
4
|
+
|
|
5
|
+
class RedisDao<T extends Record<string, any>> {
|
|
6
|
+
|
|
7
|
+
private readonly redis = new Redis({
|
|
8
|
+
url: `redis://${nconf.get(`SERVICES:REDIS:URL`)}:${nconf.get(`SERVICES:REDIS:PORT`)}`,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
public readonly add = async (key: string, value: T, expires?: number): Promise<void> => {
|
|
12
|
+
try {
|
|
13
|
+
await this.redis.set(key, JSON.stringify(value), { EX: expires });
|
|
14
|
+
} catch (e) { throw e; }
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
public readonly get = async (mask: string): Promise<T> => {
|
|
18
|
+
try {
|
|
19
|
+
const response = (await this.redis.getAll(mask))[0];
|
|
20
|
+
return response ? JSON.parse(response) : undefined;
|
|
21
|
+
} catch (e) { throw e; }
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
public readonly list = async (mask: string): Promise<T[]> => {
|
|
25
|
+
try {
|
|
26
|
+
const response = await this.redis.getAll(mask);
|
|
27
|
+
return response.map((r) => JSON.parse(r));
|
|
28
|
+
} catch (e) { throw e; }
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
public readonly delete = async (mask: string): Promise<void> => {
|
|
32
|
+
try {
|
|
33
|
+
await this.redis.deleteAll(mask);
|
|
34
|
+
} catch (e) { throw e; }
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default RedisDao;
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
drop database if exists prow_authority;
|
|
2
|
+
create database prow_authority;
|
|
3
|
+
use prow_authority;
|
|
4
|
+
|
|
5
|
+
-- ACCESS ENTITIES
|
|
6
|
+
|
|
7
|
+
create table `user` (
|
|
8
|
+
id integer not null auto_increment,
|
|
9
|
+
uuid varchar(36) not null,
|
|
10
|
+
email varchar(200) not null,
|
|
11
|
+
password varchar(64),
|
|
12
|
+
omnipotent boolean default false,
|
|
13
|
+
properties JSON not null,
|
|
14
|
+
preferences JSON not null,
|
|
15
|
+
utm JSON not null,
|
|
16
|
+
referrer varchar(200),
|
|
17
|
+
created_date datetime default now(),
|
|
18
|
+
modified_date datetime default now(),
|
|
19
|
+
status varchar(20) not null,
|
|
20
|
+
metadata json not null,
|
|
21
|
+
|
|
22
|
+
constraint user_pk primary key (id),
|
|
23
|
+
constraint user_uniq_uuid unique key (uuid),
|
|
24
|
+
constraint user_uniq_email unique key (email)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
create table organization (
|
|
28
|
+
id integer not null auto_increment,
|
|
29
|
+
uuid varchar(36) not null,
|
|
30
|
+
properties json not null,
|
|
31
|
+
billing json not null,
|
|
32
|
+
preferences json not null,
|
|
33
|
+
created_date datetime default now(),
|
|
34
|
+
modified_date datetime default now(),
|
|
35
|
+
status varchar(20) not null,
|
|
36
|
+
metadata json not null,
|
|
37
|
+
internal json not null,
|
|
38
|
+
|
|
39
|
+
constraint organization_pk primary key (id),
|
|
40
|
+
constraint organization_uniq_uuid unique key (uuid)
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
create table user_organization (
|
|
44
|
+
id integer not null auto_increment,
|
|
45
|
+
user integer not null,
|
|
46
|
+
organization integer not null,
|
|
47
|
+
role varchar(10) not null,
|
|
48
|
+
invite varchar(36),
|
|
49
|
+
invited_by integer,
|
|
50
|
+
created_date datetime default now(),
|
|
51
|
+
modified_date datetime default now(),
|
|
52
|
+
enabled boolean not null,
|
|
53
|
+
preferences json not null,
|
|
54
|
+
metadata JSON not null,
|
|
55
|
+
|
|
56
|
+
constraint user_organization_pk primary key (id),
|
|
57
|
+
constraint user_organization_uniq_user_on_organization unique key (user, organization),
|
|
58
|
+
constraint user_organization_uniq_invite_for_organization unique key (organization, invite),
|
|
59
|
+
constraint user_organization_fk_user foreign key (user)
|
|
60
|
+
references user (id),
|
|
61
|
+
constraint user_organization_fk_invited_by foreign key (invited_by)
|
|
62
|
+
references user (id)
|
|
63
|
+
on delete set null,
|
|
64
|
+
constraint user_organization_fk_organization foreign key (organization)
|
|
65
|
+
references organization (id)
|
|
66
|
+
on delete cascade,
|
|
67
|
+
|
|
68
|
+
index (role),
|
|
69
|
+
index (invite),
|
|
70
|
+
index (enabled)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
-- LICENSE ENTITIES (SYSTEM)
|
|
74
|
+
|
|
75
|
+
create table service (
|
|
76
|
+
id integer not null auto_increment,
|
|
77
|
+
uuid varchar(36) not null,
|
|
78
|
+
token varchar(100) not null,
|
|
79
|
+
properties json not null,
|
|
80
|
+
preferences JSON not null,
|
|
81
|
+
created_date datetime default now(),
|
|
82
|
+
modified_date datetime default now(),
|
|
83
|
+
enabled boolean not null,
|
|
84
|
+
metadata json not null,
|
|
85
|
+
internal json not null,
|
|
86
|
+
|
|
87
|
+
constraint service_pk primary key (id),
|
|
88
|
+
constraint service_uniq_uuid unique key (uuid)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
create table service_notifications (
|
|
92
|
+
id integer not null auto_increment,
|
|
93
|
+
service integer not null,
|
|
94
|
+
event varchar(100) not null,
|
|
95
|
+
template varchar(36) not null,
|
|
96
|
+
scope json not null,
|
|
97
|
+
created_date datetime default now(),
|
|
98
|
+
modified_date datetime default now(),
|
|
99
|
+
`default` boolean not null default false,
|
|
100
|
+
enabled boolean not null,
|
|
101
|
+
metadata json not null,
|
|
102
|
+
|
|
103
|
+
constraint service_notifications_pk primary key (id, service),
|
|
104
|
+
constraint service_notifications_uniq_event_per_service unique key (service, event),
|
|
105
|
+
constraint service_notifications_fk_service foreign key (service)
|
|
106
|
+
references service (id)
|
|
107
|
+
on delete cascade,
|
|
108
|
+
|
|
109
|
+
index (event),
|
|
110
|
+
index (`default`),
|
|
111
|
+
index (enabled)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
create table license (
|
|
115
|
+
id integer not null auto_increment,
|
|
116
|
+
uuid varchar(36) not null,
|
|
117
|
+
service integer not null,
|
|
118
|
+
type varchar(10) not null,
|
|
119
|
+
associated integer,
|
|
120
|
+
properties json not null,
|
|
121
|
+
data json not null,
|
|
122
|
+
created_date datetime default now(),
|
|
123
|
+
modified_date datetime default now(),
|
|
124
|
+
public boolean not null,
|
|
125
|
+
enabled boolean not null,
|
|
126
|
+
metadata json not null,
|
|
127
|
+
|
|
128
|
+
constraint license_pk primary key (id),
|
|
129
|
+
constraint license_uniq_uuid unique key (uuid),
|
|
130
|
+
constraint license_fk_service foreign key (service)
|
|
131
|
+
references service (id)
|
|
132
|
+
on delete cascade,
|
|
133
|
+
constraint license_fk_associated foreign key (associated)
|
|
134
|
+
references license (id)
|
|
135
|
+
on delete cascade,
|
|
136
|
+
|
|
137
|
+
index (type),
|
|
138
|
+
index (public),
|
|
139
|
+
index (enabled)
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
create table license_limit (
|
|
143
|
+
id integer not null auto_increment,
|
|
144
|
+
license integer not null,
|
|
145
|
+
name varchar(100) not null,
|
|
146
|
+
`limit` integer not null,
|
|
147
|
+
period varchar(10),
|
|
148
|
+
monthly_price_abs decimal(10,2) not null,
|
|
149
|
+
annual_price_abs decimal(10,2) not null,
|
|
150
|
+
overconsume_monthly_price_per_unit decimal(64,30),
|
|
151
|
+
overconsume_annual_price_per_unit decimal(64,30),
|
|
152
|
+
metadata json not null,
|
|
153
|
+
|
|
154
|
+
constraint license_limit_pk primary key (id),
|
|
155
|
+
constraint license_limit_fk_license foreign key (license)
|
|
156
|
+
references license (id)
|
|
157
|
+
on delete cascade,
|
|
158
|
+
constraint license_limit_uniq_limit_per_license unique key (license, name),
|
|
159
|
+
|
|
160
|
+
index (name),
|
|
161
|
+
index (period)
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
-- create a view for prices
|
|
165
|
+
-- drop view license_prices;
|
|
166
|
+
create view license_prices as
|
|
167
|
+
select
|
|
168
|
+
l.*,
|
|
169
|
+
sum(ll.annual_price_abs) as annual_price,
|
|
170
|
+
sum(ll.monthly_price_abs) as monthly_price
|
|
171
|
+
from
|
|
172
|
+
license l
|
|
173
|
+
left outer join license_limit ll on ll.license = l.id
|
|
174
|
+
group by l.id;
|
|
175
|
+
|
|
176
|
+
-- LICENSE ENTITIES (ORGANIZATION)
|
|
177
|
+
|
|
178
|
+
create table organization_license (
|
|
179
|
+
id integer not null auto_increment,
|
|
180
|
+
uuid varchar(36) not null,
|
|
181
|
+
organization integer not null,
|
|
182
|
+
service integer not null,
|
|
183
|
+
type varchar(10) not null,
|
|
184
|
+
associated integer,
|
|
185
|
+
original integer,
|
|
186
|
+
billing varchar(10) not null,
|
|
187
|
+
properties json not null,
|
|
188
|
+
data json not null,
|
|
189
|
+
start_date datetime not null,
|
|
190
|
+
end_date datetime,
|
|
191
|
+
metadata json not null,
|
|
192
|
+
internal json not null,
|
|
193
|
+
|
|
194
|
+
constraint organization_license_pk primary key (id),
|
|
195
|
+
constraint organization_license_uniq_uuid unique key (uuid),
|
|
196
|
+
constraint organization_license_fk_organization foreign key (organization)
|
|
197
|
+
references organization (id)
|
|
198
|
+
on delete cascade,
|
|
199
|
+
constraint organization_license_fk_service foreign key (service)
|
|
200
|
+
references service (id)
|
|
201
|
+
on delete cascade,
|
|
202
|
+
constraint organization_license_fk_associated foreign key (associated)
|
|
203
|
+
references organization_license (id)
|
|
204
|
+
on delete cascade,
|
|
205
|
+
constraint organization_license_fk_original foreign key (original)
|
|
206
|
+
references license (id)
|
|
207
|
+
on delete set null,
|
|
208
|
+
|
|
209
|
+
index (type),
|
|
210
|
+
index (billing),
|
|
211
|
+
index (start_date),
|
|
212
|
+
index (end_date),
|
|
213
|
+
index (start_date, end_date)
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
-- create a view to override license end_date with associated license's
|
|
217
|
+
-- drop view organization_license_associated;
|
|
218
|
+
create view organization_license_associated as
|
|
219
|
+
select l.id, l.uuid, l.organization, l.service, l.`type`, l.billing, l.properties, l.data, l.start_date,
|
|
220
|
+
IF(a.end_date is not null, a.end_date, l.end_date) as end_date,
|
|
221
|
+
l.end_date as original_end_date,
|
|
222
|
+
l.metadata, l.internal, l.associated, l.original
|
|
223
|
+
from
|
|
224
|
+
organization_license l
|
|
225
|
+
left outer join organization_license a
|
|
226
|
+
on l.associated = a.id;
|
|
227
|
+
|
|
228
|
+
-- create a view for the enabled status
|
|
229
|
+
-- drop view organization_license_enabled;
|
|
230
|
+
create view organization_license_enabled as
|
|
231
|
+
select
|
|
232
|
+
ola.*,
|
|
233
|
+
sum(oll.annual_price_abs) as annual_price,
|
|
234
|
+
sum(oll.monthly_price_abs) as monthly_price,
|
|
235
|
+
(CONVERT_TZ(now(), 'SYSTEM', 'Europe/Madrid') >= start_date and (end_date is null or CONVERT_TZ(now(), 'SYSTEM', 'Europe/Madrid') < end_date)) as enabled
|
|
236
|
+
from
|
|
237
|
+
organization_license_associated ola
|
|
238
|
+
left outer join organization_license_limit oll on oll.license = ola.id
|
|
239
|
+
group by ola.id;
|
|
240
|
+
|
|
241
|
+
create table organization_license_limit (
|
|
242
|
+
id integer not null auto_increment,
|
|
243
|
+
organization integer not null,
|
|
244
|
+
license integer not null,
|
|
245
|
+
name varchar(100) not null,
|
|
246
|
+
`limit` integer not null,
|
|
247
|
+
period varchar(10),
|
|
248
|
+
monthly_price_abs decimal(10,2) not null,
|
|
249
|
+
annual_price_abs decimal(10,2) not null,
|
|
250
|
+
overconsume boolean not null,
|
|
251
|
+
overconsume_monthly_price_per_unit decimal(64,30),
|
|
252
|
+
overconsume_annual_price_per_unit decimal(64,30),
|
|
253
|
+
metadata json not null,
|
|
254
|
+
|
|
255
|
+
constraint organization_license_limit_pk primary key (id),
|
|
256
|
+
constraint organization_license_limit_fk_organization foreign key (organization)
|
|
257
|
+
references organization (id)
|
|
258
|
+
on delete cascade,
|
|
259
|
+
constraint organization_license_limit_fk_license foreign key (license)
|
|
260
|
+
references organization_license (id)
|
|
261
|
+
on delete cascade,
|
|
262
|
+
constraint organization_license_limit_uniq_limit_per_license unique key (license, name),
|
|
263
|
+
|
|
264
|
+
index (name),
|
|
265
|
+
index (period),
|
|
266
|
+
index (overconsume)
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
-- CONSUMPTION AND QUOTA
|
|
270
|
+
|
|
271
|
+
create table organization_usage (
|
|
272
|
+
id integer not null auto_increment,
|
|
273
|
+
organization integer not null,
|
|
274
|
+
service integer not null,
|
|
275
|
+
name varchar(100) not null,
|
|
276
|
+
count decimal(64,30) not null,
|
|
277
|
+
date datetime default now(),
|
|
278
|
+
|
|
279
|
+
constraint organization_usage_pk primary key (id),
|
|
280
|
+
constraint organization_usage_fk_organization foreign key (organization)
|
|
281
|
+
references organization (id)
|
|
282
|
+
on delete cascade,
|
|
283
|
+
constraint organization_usage_fk_service foreign key (service)
|
|
284
|
+
references service (id)
|
|
285
|
+
on delete cascade,
|
|
286
|
+
|
|
287
|
+
index (name),
|
|
288
|
+
index (date),
|
|
289
|
+
index idx_lookup_optimized (organization, service, name, date)
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
-- PAYMENTS AND BILLING
|
|
293
|
+
|
|
294
|
+
create table billing_cycle (
|
|
295
|
+
id integer not null auto_increment,
|
|
296
|
+
uuid varchar(36) not null,
|
|
297
|
+
organization integer not null,
|
|
298
|
+
trial boolean default false,
|
|
299
|
+
start_date datetime not null,
|
|
300
|
+
end_date datetime not null,
|
|
301
|
+
metadata json not null,
|
|
302
|
+
internal json not null,
|
|
303
|
+
|
|
304
|
+
constraint billing_cycle_pk primary key (id),
|
|
305
|
+
constraint billing_cycle_uniq_uuid_for_organization unique key (organization, uuid),
|
|
306
|
+
constraint billing_cycle_fk_organization foreign key (organization)
|
|
307
|
+
references organization (id)
|
|
308
|
+
on delete cascade,
|
|
309
|
+
|
|
310
|
+
index (uuid),
|
|
311
|
+
index (organization),
|
|
312
|
+
index (start_date),
|
|
313
|
+
index (end_date)
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
create table payment_method (
|
|
317
|
+
id integer not null auto_increment,
|
|
318
|
+
uuid varchar(36) not null,
|
|
319
|
+
organization integer not null,
|
|
320
|
+
type varchar(10) not null,
|
|
321
|
+
properties json not null,
|
|
322
|
+
enabled boolean not null,
|
|
323
|
+
created_date datetime default now(),
|
|
324
|
+
modified_date datetime default now(),
|
|
325
|
+
metadata json not null,
|
|
326
|
+
internal json not null,
|
|
327
|
+
|
|
328
|
+
constraint payment_method_pk primary key (id),
|
|
329
|
+
constraint payment_method_uniq_uuid_for_organization unique key (organization, uuid),
|
|
330
|
+
constraint payment_method_fk_organization foreign key (organization)
|
|
331
|
+
references organization (id)
|
|
332
|
+
on delete cascade,
|
|
333
|
+
|
|
334
|
+
index (uuid),
|
|
335
|
+
index (organization),
|
|
336
|
+
index (type),
|
|
337
|
+
index (enabled)
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
create table invoice (
|
|
341
|
+
id integer not null auto_increment,
|
|
342
|
+
uuid varchar(36) not null,
|
|
343
|
+
organization integer not null,
|
|
344
|
+
date datetime not null,
|
|
345
|
+
amount decimal(64,30) not null,
|
|
346
|
+
tax_code varchar(20) not null,
|
|
347
|
+
tax_percentage decimal(64,30) not null,
|
|
348
|
+
concepts json not null,
|
|
349
|
+
billing json not null,
|
|
350
|
+
status varchar(20) not null,
|
|
351
|
+
invoice varchar(255),
|
|
352
|
+
number varchar(255),
|
|
353
|
+
payment varchar(255),
|
|
354
|
+
method integer,
|
|
355
|
+
metadata json not null,
|
|
356
|
+
internal json not null,
|
|
357
|
+
|
|
358
|
+
constraint invoice_pk primary key (id),
|
|
359
|
+
constraint invoice_uniq_uuid_for_organization unique key (organization, uuid),
|
|
360
|
+
constraint invoice_fk_organization foreign key (organization)
|
|
361
|
+
references organization (id)
|
|
362
|
+
on delete cascade,
|
|
363
|
+
constraint invoice_fk_method foreign key (method)
|
|
364
|
+
references payment_method (id)
|
|
365
|
+
on delete cascade,
|
|
366
|
+
|
|
367
|
+
index (uuid),
|
|
368
|
+
index (organization),
|
|
369
|
+
index (date),
|
|
370
|
+
index (method),
|
|
371
|
+
index (status),
|
|
372
|
+
index (invoice),
|
|
373
|
+
index (number),
|
|
374
|
+
index (payment)
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
create table accounting_seat (
|
|
378
|
+
id integer not null auto_increment,
|
|
379
|
+
uuid varchar(36) not null,
|
|
380
|
+
organization integer not null,
|
|
381
|
+
invoice integer not null,
|
|
382
|
+
date datetime not null,
|
|
383
|
+
amount decimal(64,30) not null,
|
|
384
|
+
done boolean not null,
|
|
385
|
+
metadata json not null,
|
|
386
|
+
internal json not null,
|
|
387
|
+
|
|
388
|
+
constraint accounting_seat_pk primary key (id),
|
|
389
|
+
constraint accounting_seat_uniq_uuid_for_organization unique key (organization, uuid),
|
|
390
|
+
constraint accounting_seat_fk_organization foreign key (organization)
|
|
391
|
+
references organization (id)
|
|
392
|
+
on delete cascade,
|
|
393
|
+
constraint accounting_seat_fk_invoice foreign key (invoice)
|
|
394
|
+
references invoice (id)
|
|
395
|
+
on delete cascade,
|
|
396
|
+
|
|
397
|
+
index (uuid),
|
|
398
|
+
index (organization),
|
|
399
|
+
index (invoice),
|
|
400
|
+
index (date),
|
|
401
|
+
index (done)
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
-- POLICY ENTITIES
|
|
405
|
+
|
|
406
|
+
create table policy (
|
|
407
|
+
id integer not null auto_increment,
|
|
408
|
+
uuid varchar(36) not null,
|
|
409
|
+
name varchar(100) not null,
|
|
410
|
+
metadata json not null,
|
|
411
|
+
internal json not null,
|
|
412
|
+
|
|
413
|
+
constraint policy_pk primary key (id),
|
|
414
|
+
constraint policy_uniq_uuid unique key (uuid),
|
|
415
|
+
constraint policy_uniq_name unique key (name)
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
create table policy_version (
|
|
419
|
+
id integer not null auto_increment,
|
|
420
|
+
policy integer not null,
|
|
421
|
+
version varchar(20) not null,
|
|
422
|
+
url varchar(255) not null,
|
|
423
|
+
metadata json not null,
|
|
424
|
+
internal json not null,
|
|
425
|
+
created_date datetime default now(),
|
|
426
|
+
effective_date datetime default now(),
|
|
427
|
+
|
|
428
|
+
constraint policy_version_pk primary key (id),
|
|
429
|
+
constraint policy_version_uniq_version_for_policy unique key (policy, version),
|
|
430
|
+
constraint policy_version_fk_policy foreign key (policy)
|
|
431
|
+
references policy (id)
|
|
432
|
+
on delete cascade,
|
|
433
|
+
|
|
434
|
+
index (effective_date)
|
|
435
|
+
);
|
|
436
|
+
|
|
437
|
+
create table user_policy (
|
|
438
|
+
id integer not null auto_increment,
|
|
439
|
+
user integer not null,
|
|
440
|
+
policy integer not null,
|
|
441
|
+
version integer not null,
|
|
442
|
+
metadata json not null,
|
|
443
|
+
internal json not null,
|
|
444
|
+
informed_date datetime default now(),
|
|
445
|
+
|
|
446
|
+
constraint user_policy_pk primary key (id),
|
|
447
|
+
constraint user_policy_fk_user foreign key (user)
|
|
448
|
+
references user (id)
|
|
449
|
+
on delete cascade,
|
|
450
|
+
constraint user_policy_fk_policy foreign key (policy)
|
|
451
|
+
references policy (id)
|
|
452
|
+
on delete cascade,
|
|
453
|
+
constraint user_policy_fk_version foreign key (version)
|
|
454
|
+
references policy_version (id)
|
|
455
|
+
on delete cascade,
|
|
456
|
+
constraint user_policy_uniq_user_policy_version unique key (user, policy, version),
|
|
457
|
+
|
|
458
|
+
index (user),
|
|
459
|
+
index (policy),
|
|
460
|
+
index (version),
|
|
461
|
+
index (informed_date)
|
|
462
|
+
);
|