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,68 @@
|
|
|
1
|
+
import { Date2 } from '@beseif-solutions/utility-functions/dist/utils/date-utils';
|
|
2
|
+
import APIError, { StatusCodes } from '../../../helpers/api-error';
|
|
3
|
+
import { Policy } from '../../types/admin/policy-types';
|
|
4
|
+
import { PolicyVersion } from '../../types/admin/policy-version-types';
|
|
5
|
+
import { PublicPolicy } from '../../types/policies/public-policy-types';
|
|
6
|
+
import policyController from '../admin/policy-controller';
|
|
7
|
+
import policyVersionController from '../admin/policy-version-controller';
|
|
8
|
+
|
|
9
|
+
class PublicPolicyController {
|
|
10
|
+
|
|
11
|
+
public readonly getLatestVersion = async (id: number): Promise<PolicyVersion> => {
|
|
12
|
+
try {
|
|
13
|
+
const versions = await policyVersionController.list(
|
|
14
|
+
{ policy: id },
|
|
15
|
+
{ order: { by: [`effective_date`], direction: `descendent` } },
|
|
16
|
+
);
|
|
17
|
+
return (versions.filter(v => new Date2(v.effective_date).isPast()))[0];
|
|
18
|
+
} catch (e) { throw e; }
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
public readonly list = async (): Promise<PublicPolicy[]> => {
|
|
22
|
+
try {
|
|
23
|
+
const policies = await policyController.list({});
|
|
24
|
+
return await this.parsePolicies(policies);
|
|
25
|
+
} catch (e) { throw e; }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
public readonly get = async (uuid: string): Promise<PublicPolicy[]> => {
|
|
29
|
+
try {
|
|
30
|
+
const policy = (await policyController.list({ uuid: uuid }))[0];
|
|
31
|
+
if (!policy) {
|
|
32
|
+
throw new APIError({
|
|
33
|
+
code: StatusCodes.NOT_FOUND,
|
|
34
|
+
detail: `Policy ${uuid} not found.`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return await this.parsePolicies([policy]);
|
|
38
|
+
} catch (e) { throw e; }
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
public readonly parsePolicies = async (policies: Policy[]): Promise<PublicPolicy[]> => {
|
|
42
|
+
try {
|
|
43
|
+
const parsed: PublicPolicy[] = [];
|
|
44
|
+
|
|
45
|
+
for (const policy of policies) {
|
|
46
|
+
const currentVersion = await this.getLatestVersion(policy.id);
|
|
47
|
+
const p: PublicPolicy = {
|
|
48
|
+
uuid: policy.uuid,
|
|
49
|
+
name: policy.name,
|
|
50
|
+
current_version: currentVersion ? {
|
|
51
|
+
version: currentVersion.version,
|
|
52
|
+
url: currentVersion.url,
|
|
53
|
+
metadata: currentVersion.metadata,
|
|
54
|
+
created_date: currentVersion.created_date,
|
|
55
|
+
effective_date: currentVersion.effective_date,
|
|
56
|
+
} : null,
|
|
57
|
+
metadata: policy.metadata,
|
|
58
|
+
};
|
|
59
|
+
parsed.push(p);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return parsed;
|
|
63
|
+
} catch (e) { throw e; }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const publicPolicyController = new PublicPolicyController();
|
|
68
|
+
export default publicPolicyController;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Validator } from "@beseif-solutions/utility-functions/dist/utils/validation-utils";
|
|
2
|
+
import APIError, { StatusCodes } from "../../../helpers/api-error";
|
|
3
|
+
import { License, LicenseType } from "../../types/admin/license-types";
|
|
4
|
+
import { Service } from "../../types/admin/service-types";
|
|
5
|
+
import { ListLicenseParams, PublicLicense, PublicService } from "../../types/services/public-service-types";
|
|
6
|
+
import licenseController from "../admin/license-controller";
|
|
7
|
+
import licenseLimitController from "../admin/license-limit-controller";
|
|
8
|
+
import serviceController from "../admin/service-controller";
|
|
9
|
+
import { listLicensesSchema } from "../../schemas/services/public-service-schemas";
|
|
10
|
+
import _ from "lodash";
|
|
11
|
+
|
|
12
|
+
class PublicServiceController {
|
|
13
|
+
|
|
14
|
+
public readonly services = async (): Promise<PublicService[]> => {
|
|
15
|
+
try {
|
|
16
|
+
const services = await serviceController.list({ enabled: true });
|
|
17
|
+
return await this.parseServices(services);
|
|
18
|
+
} catch (e) { throw e; }
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
public readonly licenses = async (serviceUUID: string, params: ListLicenseParams): Promise<PublicLicense[]> => {
|
|
23
|
+
try {
|
|
24
|
+
Validator.validate(listLicensesSchema, params);
|
|
25
|
+
|
|
26
|
+
const service = (await serviceController.list({ uuid: serviceUUID, enabled: true }))[0];
|
|
27
|
+
if (!service) {
|
|
28
|
+
throw new APIError({
|
|
29
|
+
code: StatusCodes.NOT_FOUND,
|
|
30
|
+
detail: `Service ${serviceUUID} not found.`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const licenses = await licenseController.list({
|
|
35
|
+
service: service.id,
|
|
36
|
+
type: LicenseType.Base,
|
|
37
|
+
public: true,
|
|
38
|
+
enabled: true,
|
|
39
|
+
...params,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return await this.parseLicenses(licenses);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.log(e);
|
|
45
|
+
throw e;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
public readonly license = async (serviceUUID: string, licenseUUID: string): Promise<PublicLicense[]> => {
|
|
50
|
+
try {
|
|
51
|
+
const service = (await serviceController.list({ uuid: serviceUUID, enabled: true }))[0];
|
|
52
|
+
if (!service) {
|
|
53
|
+
throw new APIError({
|
|
54
|
+
code: StatusCodes.NOT_FOUND,
|
|
55
|
+
detail: `Service ${serviceUUID} not found.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const licenses = await licenseController.list({
|
|
60
|
+
uuid: licenseUUID,
|
|
61
|
+
service: service.id,
|
|
62
|
+
type: LicenseType.Base,
|
|
63
|
+
enabled: true,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return await this.parseLicenses(licenses);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.log(e);
|
|
69
|
+
throw e;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
public readonly powerUps = async (serviceUUID: string, params: ListLicenseParams): Promise<PublicLicense[]> => {
|
|
74
|
+
try {
|
|
75
|
+
Validator.validate(listLicensesSchema, params);
|
|
76
|
+
|
|
77
|
+
const service = (await serviceController.list({ uuid: serviceUUID, enabled: true }))[0];
|
|
78
|
+
if (!service) {
|
|
79
|
+
throw new APIError({
|
|
80
|
+
code: StatusCodes.NOT_FOUND,
|
|
81
|
+
detail: `Service ${serviceUUID} not found.`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const licenses = await licenseController.list({
|
|
86
|
+
service: service.id,
|
|
87
|
+
type: LicenseType.Variant,
|
|
88
|
+
public: true,
|
|
89
|
+
enabled: true,
|
|
90
|
+
...params,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return await this.parseLicenses(licenses);
|
|
94
|
+
} catch (e) { throw e; }
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
public readonly powerUp = async (serviceUUID: string, licenseUUID: string): Promise<PublicLicense[]> => {
|
|
98
|
+
try {
|
|
99
|
+
const service = (await serviceController.list({ uuid: serviceUUID, enabled: true }))[0];
|
|
100
|
+
if (!service) {
|
|
101
|
+
throw new APIError({
|
|
102
|
+
code: StatusCodes.NOT_FOUND,
|
|
103
|
+
detail: `Service ${serviceUUID} not found.`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const licenses = await licenseController.list({
|
|
108
|
+
uuid: licenseUUID,
|
|
109
|
+
service: service.id,
|
|
110
|
+
type: LicenseType.Variant,
|
|
111
|
+
enabled: true,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return await this.parseLicenses(licenses);
|
|
115
|
+
} catch (e) { throw e; }
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
public readonly parseServices = async (records: Service[]): Promise<PublicService[]> => {
|
|
119
|
+
try {
|
|
120
|
+
const response: PublicService[] = [];
|
|
121
|
+
for (const record of records) {
|
|
122
|
+
response.push({
|
|
123
|
+
uuid: record.uuid,
|
|
124
|
+
properties: record.properties,
|
|
125
|
+
preferences: record.preferences,
|
|
126
|
+
created_date: record.created_date,
|
|
127
|
+
modified_date: record.modified_date,
|
|
128
|
+
metadata: record.metadata,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return response;
|
|
132
|
+
} catch (e) { throw e; }
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
public readonly parseLicenses = async (records: License[]): Promise<PublicLicense[]> => {
|
|
136
|
+
try {
|
|
137
|
+
const [limits, associatedLicenses] = await Promise.all([
|
|
138
|
+
licenseLimitController.list({ license: { in: records.map((l) => l.id) } }),
|
|
139
|
+
licenseController.list({ id: { in: _.compact(records.map((r) => r.associated)) } }),
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
const response: PublicLicense[] = [];
|
|
143
|
+
for (const record of records) {
|
|
144
|
+
const licenseLimits = limits.filter((l) => l.license === record.id);
|
|
145
|
+
response.push({
|
|
146
|
+
uuid: record.uuid,
|
|
147
|
+
type: record.type,
|
|
148
|
+
associated: record.associated ?
|
|
149
|
+
associatedLicenses.find((l) => l.id === record.associated)?.uuid || null
|
|
150
|
+
: null,
|
|
151
|
+
properties: record.properties,
|
|
152
|
+
data: record.data,
|
|
153
|
+
annual_price: record.annual_price,
|
|
154
|
+
monthly_price: record.monthly_price,
|
|
155
|
+
limits: licenseLimits.map((ll) => ({
|
|
156
|
+
name: ll.name,
|
|
157
|
+
limit: ll.limit,
|
|
158
|
+
period: ll.period,
|
|
159
|
+
monthly_price_abs: ll.monthly_price_abs,
|
|
160
|
+
annual_price_abs: ll.annual_price_abs,
|
|
161
|
+
overconsume_monthly_price_per_unit: ll.overconsume_monthly_price_per_unit,
|
|
162
|
+
overconsume_annual_price_per_unit: ll.overconsume_annual_price_per_unit,
|
|
163
|
+
metadata: ll.metadata,
|
|
164
|
+
})),
|
|
165
|
+
created_date: record.created_date,
|
|
166
|
+
modified_date: record.modified_date,
|
|
167
|
+
metadata: record.metadata,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return response;
|
|
171
|
+
} catch (e) { throw e; }
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const publicServiceController = new PublicServiceController();
|
|
177
|
+
export default publicServiceController;
|