serene-core-server 0.1.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/dist/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
- package/dist/apollo/resolvers/mutations/mailing-lists.js +30 -0
- package/dist/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
- package/dist/apollo/resolvers/mutations/user-preferences.js +31 -0
- package/dist/apollo/resolvers/mutations/users.d.ts +28 -0
- package/dist/apollo/resolvers/mutations/users.js +44 -0
- package/dist/apollo/resolvers/queries/access.d.ts +11 -0
- package/dist/apollo/resolvers/queries/access.js +25 -0
- package/dist/apollo/resolvers/queries/profile.d.ts +11 -0
- package/dist/apollo/resolvers/queries/profile.js +25 -0
- package/dist/apollo/resolvers/queries/quotas.d.ts +21 -0
- package/dist/apollo/resolvers/queries/quotas.js +25 -0
- package/dist/apollo/resolvers/queries/tech.d.ts +5 -0
- package/dist/apollo/resolvers/queries/tech.js +35 -0
- package/dist/apollo/resolvers/queries/user-preferences.d.ts +5 -0
- package/dist/apollo/resolvers/queries/user-preferences.js +33 -0
- package/dist/apollo/resolvers/queries/users.d.ts +15 -0
- package/dist/apollo/resolvers/queries/users.js +28 -0
- package/dist/apollo/resolvers/resolvers.d.ts +20 -0
- package/dist/apollo/resolvers/resolvers.js +38 -0
- package/dist/apollo/typedefs/typedefs.d.ts +1 -0
- package/dist/apollo/typedefs/typedefs.js +142 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +68 -0
- package/dist/models/chat/chat-message-created-model.d.ts +17 -0
- package/dist/models/chat/chat-message-created-model.js +113 -0
- package/dist/models/chat/chat-message-model.d.ts +44 -0
- package/dist/models/chat/chat-message-model.js +523 -0
- package/dist/models/chat/chat-participant-model.d.ts +39 -0
- package/dist/models/chat/chat-participant-model.js +211 -0
- package/dist/models/chat/chat-session-model.d.ts +92 -0
- package/dist/models/chat/chat-session-model.js +301 -0
- package/dist/models/chat/chat-settings-model.d.ts +87 -0
- package/dist/models/chat/chat-settings-model.js +261 -0
- package/dist/models/feature-flags/feature-flag-model.d.ts +40 -0
- package/dist/models/feature-flags/feature-flag-model.js +164 -0
- package/dist/models/instances/instance-model.d.ts +93 -0
- package/dist/models/instances/instance-model.js +432 -0
- package/dist/models/instances/instance-setting-model.d.ts +39 -0
- package/dist/models/instances/instance-setting-model.js +193 -0
- package/dist/models/mailing-lists/mailing-list-model.d.ts +34 -0
- package/dist/models/mailing-lists/mailing-list-model.js +154 -0
- package/dist/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
- package/dist/models/mailing-lists/mailing-list-subscriber-model.js +152 -0
- package/dist/models/quotas/resource-quota-total-model.d.ts +46 -0
- package/dist/models/quotas/resource-quota-total-model.js +200 -0
- package/dist/models/quotas/resource-quota-usage-model.d.ts +51 -0
- package/dist/models/quotas/resource-quota-usage-model.js +181 -0
- package/dist/models/tech/rate-limited-api-event-model.d.ts +25 -0
- package/dist/models/tech/rate-limited-api-event-model.js +161 -0
- package/dist/models/tech/rate-limited-api-model.d.ts +21 -0
- package/dist/models/tech/rate-limited-api-model.js +141 -0
- package/dist/models/tech/tech-model.d.ts +44 -0
- package/dist/models/tech/tech-model.js +268 -0
- package/dist/models/tech/tech-provider-api-key-model.d.ts +43 -0
- package/dist/models/tech/tech-provider-api-key-model.js +224 -0
- package/dist/models/tech/tech-provider-model.d.ts +28 -0
- package/dist/models/tech/tech-provider-model.js +197 -0
- package/dist/models/users/external-user-integration-model.d.ts +36 -0
- package/dist/models/users/external-user-integration-model.js +196 -0
- package/dist/models/users/user-error-model.d.ts +54 -0
- package/dist/models/users/user-error-model.js +173 -0
- package/dist/models/users/user-error-summary-model.d.ts +45 -0
- package/dist/models/users/user-error-summary-model.js +172 -0
- package/dist/models/users/user-group-member-model.d.ts +41 -0
- package/dist/models/users/user-group-member-model.js +193 -0
- package/dist/models/users/user-group-model.d.ts +27 -0
- package/dist/models/users/user-group-model.js +146 -0
- package/dist/models/users/user-model.d.ts +46 -0
- package/dist/models/users/user-model.js +153 -0
- package/dist/models/users/user-preference-model.d.ts +60 -0
- package/dist/models/users/user-preference-model.js +228 -0
- package/dist/models/users/user-profile-model.d.ts +58 -0
- package/dist/models/users/user-profile-model.js +173 -0
- package/dist/prisma.config.d.ts +3 -0
- package/dist/prisma.config.js +13 -0
- package/dist/services/access/access-service.d.ts +12 -0
- package/dist/services/access/access-service.js +44 -0
- package/dist/services/access/encrypt-service.d.ts +13 -0
- package/dist/services/access/encrypt-service.js +84 -0
- package/dist/services/api-usage/api-usage-base-service.d.ts +15 -0
- package/dist/services/api-usage/api-usage-base-service.js +75 -0
- package/dist/services/console/service.d.ts +7 -0
- package/dist/services/console/service.js +70 -0
- package/dist/services/db/pg/pg-estimate-size-service.d.ts +16 -0
- package/dist/services/db/pg/pg-estimate-size-service.js +90 -0
- package/dist/services/files/types.d.ts +6 -0
- package/dist/services/files/types.js +2 -0
- package/dist/services/files/walk-dir-service.d.ts +8 -0
- package/dist/services/files/walk-dir-service.js +94 -0
- package/dist/services/locale/countries.d.ts +6 -0
- package/dist/services/locale/countries.js +484 -0
- package/dist/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
- package/dist/services/mailing-lists/mailing-list-subscriber-service.js +45 -0
- package/dist/services/process/sleep.d.ts +2 -0
- package/dist/services/process/sleep.js +10 -0
- package/dist/services/quotas/mutate-service.d.ts +5 -0
- package/dist/services/quotas/mutate-service.js +54 -0
- package/dist/services/quotas/query-service.d.ts +27 -0
- package/dist/services/quotas/query-service.js +137 -0
- package/dist/services/quotas/utils-service.d.ts +4 -0
- package/dist/services/quotas/utils-service.js +28 -0
- package/dist/services/tech/tech-provider-mutate-service.d.ts +7 -0
- package/dist/services/tech/tech-provider-mutate-service.js +142 -0
- package/dist/services/tech/tech-query-service.d.ts +9 -0
- package/dist/services/tech/tech-query-service.js +77 -0
- package/dist/services/user-preference/service.d.ts +10 -0
- package/dist/services/user-preference/service.js +70 -0
- package/dist/services/users/external-user-integration-service.d.ts +9 -0
- package/dist/services/users/external-user-integration-service.js +42 -0
- package/dist/services/users/profile-service.d.ts +40 -0
- package/dist/services/users/profile-service.js +408 -0
- package/dist/services/users/service.d.ts +64 -0
- package/dist/services/users/service.js +187 -0
- package/dist/services/users/user-error-service.d.ts +4 -0
- package/dist/services/users/user-error-service.js +42 -0
- package/dist/services/users/users-group-service.d.ts +16 -0
- package/dist/services/users/users-group-service.js +68 -0
- package/dist/services/utils/string-utils-service.d.ts +5 -0
- package/dist/services/utils/string-utils-service.js +41 -0
- package/dist/src/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
- package/dist/src/apollo/resolvers/mutations/mailing-lists.js +19 -0
- package/dist/src/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
- package/dist/src/apollo/resolvers/mutations/user-preferences.js +20 -0
- package/dist/src/apollo/resolvers/mutations/users.d.ts +28 -0
- package/dist/src/apollo/resolvers/mutations/users.js +33 -0
- package/dist/src/apollo/resolvers/queries/access.d.ts +11 -0
- package/dist/src/apollo/resolvers/queries/access.js +14 -0
- package/dist/src/apollo/resolvers/queries/profile.d.ts +11 -0
- package/dist/src/apollo/resolvers/queries/profile.js +14 -0
- package/dist/src/apollo/resolvers/queries/quotas.d.ts +21 -0
- package/dist/src/apollo/resolvers/queries/quotas.js +14 -0
- package/dist/src/apollo/resolvers/queries/tech.d.ts +5 -0
- package/dist/src/apollo/resolvers/queries/tech.js +24 -0
- package/dist/src/apollo/resolvers/queries/user-preferences.d.ts +5 -0
- package/dist/src/apollo/resolvers/queries/user-preferences.js +22 -0
- package/dist/src/apollo/resolvers/queries/users.d.ts +15 -0
- package/dist/src/apollo/resolvers/queries/users.js +17 -0
- package/dist/src/apollo/typedefs/typedefs.d.ts +1 -0
- package/dist/src/apollo/typedefs/typedefs.js +139 -0
- package/dist/src/db.d.ts +3 -0
- package/dist/src/db.js +11 -0
- package/dist/src/index.d.ts +52 -0
- package/dist/src/index.js +52 -0
- package/dist/src/models/chat/chat-message-created-model.d.ts +17 -0
- package/dist/src/models/chat/chat-message-created-model.js +92 -0
- package/dist/src/models/chat/chat-message-model.d.ts +44 -0
- package/dist/src/models/chat/chat-message-model.js +484 -0
- package/dist/src/models/chat/chat-participant-model.d.ts +39 -0
- package/dist/src/models/chat/chat-participant-model.js +178 -0
- package/dist/src/models/chat/chat-session-model.d.ts +92 -0
- package/dist/src/models/chat/chat-session-model.js +266 -0
- package/dist/src/models/chat/chat-settings-model.d.ts +87 -0
- package/dist/src/models/chat/chat-settings-model.js +230 -0
- package/dist/src/models/feature-flags/feature-flag-model.d.ts +40 -0
- package/dist/src/models/feature-flags/feature-flag-model.js +137 -0
- package/dist/src/models/instances/instance-model.d.ts +100 -0
- package/dist/src/models/instances/instance-model.js +466 -0
- package/dist/src/models/instances/instance-setting-model.d.ts +39 -0
- package/dist/src/models/instances/instance-setting-model.js +164 -0
- package/dist/src/models/mailing-lists/mailing-list-model.d.ts +34 -0
- package/dist/src/models/mailing-lists/mailing-list-model.js +127 -0
- package/dist/src/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
- package/dist/src/models/mailing-lists/mailing-list-subscriber-model.js +127 -0
- package/dist/src/models/quotas/resource-quota-total-model.d.ts +46 -0
- package/dist/src/models/quotas/resource-quota-total-model.js +170 -0
- package/dist/src/models/quotas/resource-quota-usage-model.d.ts +51 -0
- package/dist/src/models/quotas/resource-quota-usage-model.js +151 -0
- package/dist/src/models/tech/rate-limited-api-event-model.d.ts +25 -0
- package/dist/src/models/tech/rate-limited-api-event-model.js +134 -0
- package/dist/src/models/tech/rate-limited-api-model.d.ts +21 -0
- package/dist/src/models/tech/rate-limited-api-model.js +116 -0
- package/dist/src/models/tech/tech-model.d.ts +44 -0
- package/dist/src/models/tech/tech-model.js +239 -0
- package/dist/src/models/tech/tech-provider-api-key-model.d.ts +43 -0
- package/dist/src/models/tech/tech-provider-api-key-model.js +195 -0
- package/dist/src/models/tech/tech-provider-model.d.ts +28 -0
- package/dist/src/models/tech/tech-provider-model.js +170 -0
- package/dist/src/models/users/external-user-integration-model.d.ts +36 -0
- package/dist/src/models/users/external-user-integration-model.js +167 -0
- package/dist/src/models/users/user-error-model.d.ts +54 -0
- package/dist/src/models/users/user-error-model.js +146 -0
- package/dist/src/models/users/user-error-summary-model.d.ts +45 -0
- package/dist/src/models/users/user-error-summary-model.js +145 -0
- package/dist/src/models/users/user-group-member-model.d.ts +41 -0
- package/dist/src/models/users/user-group-member-model.js +164 -0
- package/dist/src/models/users/user-group-model.d.ts +27 -0
- package/dist/src/models/users/user-group-model.js +121 -0
- package/dist/src/models/users/user-model.d.ts +46 -0
- package/dist/src/models/users/user-model.js +126 -0
- package/dist/src/models/users/user-preference-model.d.ts +60 -0
- package/dist/src/models/users/user-preference-model.js +197 -0
- package/dist/src/models/users/user-profile-model.d.ts +58 -0
- package/dist/src/models/users/user-profile-model.js +146 -0
- package/dist/src/services/access/access-service.d.ts +12 -0
- package/dist/src/services/access/access-service.js +27 -0
- package/dist/src/services/access/encrypt-service.d.ts +13 -0
- package/dist/src/services/access/encrypt-service.js +79 -0
- package/dist/src/services/api-usage/api-usage-base-service.d.ts +15 -0
- package/dist/src/services/api-usage/api-usage-base-service.js +58 -0
- package/dist/src/services/console/service.d.ts +7 -0
- package/dist/src/services/console/service.js +18 -0
- package/dist/src/services/db/pg/pg-estimate-size-service.d.ts +16 -0
- package/dist/src/services/db/pg/pg-estimate-size-service.js +83 -0
- package/dist/src/services/files/types.d.ts +6 -0
- package/dist/src/services/files/types.js +1 -0
- package/dist/src/services/files/walk-dir-service.d.ts +8 -0
- package/dist/src/services/files/walk-dir-service.js +77 -0
- package/dist/src/services/locale/countries.d.ts +6 -0
- package/dist/src/services/locale/countries.js +481 -0
- package/dist/src/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
- package/dist/src/services/mailing-lists/mailing-list-subscriber-service.js +28 -0
- package/dist/src/services/process/sleep.d.ts +2 -0
- package/dist/src/services/process/sleep.js +6 -0
- package/dist/src/services/quotas/mutate-service.d.ts +5 -0
- package/dist/src/services/quotas/mutate-service.js +37 -0
- package/dist/src/services/quotas/query-service.d.ts +27 -0
- package/dist/src/services/quotas/query-service.js +116 -0
- package/dist/src/services/quotas/utils-service.d.ts +4 -0
- package/dist/src/services/quotas/utils-service.js +22 -0
- package/dist/src/services/tech/tech-provider-mutate-service.d.ts +7 -0
- package/dist/src/services/tech/tech-provider-mutate-service.js +85 -0
- package/dist/src/services/tech/tech-query-service.d.ts +9 -0
- package/dist/src/services/tech/tech-query-service.js +58 -0
- package/dist/src/services/user-preference/service.d.ts +10 -0
- package/dist/src/services/user-preference/service.js +49 -0
- package/dist/src/services/users/external-user-integration-service.d.ts +9 -0
- package/dist/src/services/users/external-user-integration-service.js +25 -0
- package/dist/src/services/users/profile-service.d.ts +40 -0
- package/dist/src/services/users/profile-service.js +385 -0
- package/dist/src/services/users/service.d.ts +64 -0
- package/dist/src/services/users/service.js +152 -0
- package/dist/src/services/users/user-error-service.d.ts +4 -0
- package/dist/src/services/users/user-error-service.js +27 -0
- package/dist/src/services/users/users-group-service.d.ts +16 -0
- package/dist/src/services/users/users-group-service.js +51 -0
- package/dist/src/services/utils/field-naming-service.d.ts +20 -0
- package/dist/src/services/utils/field-naming-service.js +59 -0
- package/dist/src/services/utils/string-utils-service.d.ts +5 -0
- package/dist/src/services/utils/string-utils-service.js +37 -0
- package/dist/src/types/errors.d.ts +9 -0
- package/dist/src/types/errors.js +15 -0
- package/dist/src/types/user-types.d.ts +11 -0
- package/dist/src/types/user-types.js +14 -0
- package/dist/types/errors.d.ts +9 -0
- package/dist/types/errors.js +20 -0
- package/dist/types/user-types.d.ts +11 -0
- package/dist/types/user-types.js +19 -0
- package/package.json +21 -0
- package/prisma/schema.prisma +572 -0
- package/prisma.config.ts +14 -0
- package/src/apollo/README.md +4 -0
- package/src/apollo/resolvers/mutations/mailing-lists.ts +30 -0
- package/src/apollo/resolvers/mutations/user-preferences.ts +33 -0
- package/src/apollo/resolvers/mutations/users.ts +61 -0
- package/src/apollo/resolvers/queries/access.ts +23 -0
- package/src/apollo/resolvers/queries/profile.ts +24 -0
- package/src/apollo/resolvers/queries/quotas.ts +25 -0
- package/src/apollo/resolvers/queries/tech.ts +42 -0
- package/src/apollo/resolvers/queries/user-preferences.ts +34 -0
- package/src/apollo/resolvers/queries/users.ts +33 -0
- package/src/apollo/typedefs/typedefs.ts +139 -0
- package/src/db.ts +19 -0
- package/src/index.ts +52 -0
- package/src/models/chat/chat-message-created-model.ts +126 -0
- package/src/models/chat/chat-message-model.ts +678 -0
- package/src/models/chat/chat-participant-model.ts +248 -0
- package/src/models/chat/chat-session-model.ts +397 -0
- package/src/models/chat/chat-settings-model.ts +336 -0
- package/src/models/feature-flags/feature-flag-model.ts +198 -0
- package/src/models/instances/instance-model.ts +673 -0
- package/src/models/instances/instance-setting-model.ts +235 -0
- package/src/models/mailing-lists/mailing-list-model.ts +177 -0
- package/src/models/mailing-lists/mailing-list-subscriber-model.ts +194 -0
- package/src/models/quotas/resource-quota-total-model.ts +243 -0
- package/src/models/quotas/resource-quota-usage-model.ts +219 -0
- package/src/models/tech/rate-limited-api-event-model.ts +190 -0
- package/src/models/tech/rate-limited-api-model.ts +171 -0
- package/src/models/tech/tech-model.ts +360 -0
- package/src/models/tech/tech-provider-api-key-model.ts +289 -0
- package/src/models/tech/tech-provider-model.ts +247 -0
- package/src/models/users/external-user-integration-model.ts +236 -0
- package/src/models/users/user-error-model.ts +219 -0
- package/src/models/users/user-error-summary-model.ts +216 -0
- package/src/models/users/user-group-member-model.ts +233 -0
- package/src/models/users/user-group-model.ts +174 -0
- package/src/models/users/user-model.ts +172 -0
- package/src/models/users/user-preference-model.ts +285 -0
- package/src/models/users/user-profile-model.ts +207 -0
- package/src/services/access/access-service.ts +36 -0
- package/src/services/access/encrypt-service.ts +122 -0
- package/src/services/api-usage/api-usage-base-service.ts +95 -0
- package/src/services/console/service.ts +24 -0
- package/src/services/db/pg/pg-estimate-size-service.ts +119 -0
- package/src/services/files/types.ts +7 -0
- package/src/services/files/walk-dir-service.ts +135 -0
- package/src/services/locale/countries.ts +483 -0
- package/src/services/mailing-lists/mailing-list-subscriber-service.ts +54 -0
- package/src/services/process/sleep.ts +7 -0
- package/src/services/quotas/mutate-service.ts +66 -0
- package/src/services/quotas/query-service.ts +197 -0
- package/src/services/quotas/utils-service.ts +29 -0
- package/src/services/tech/tech-provider-mutate-service.ts +136 -0
- package/src/services/tech/tech-query-service.ts +93 -0
- package/src/services/user-preference/service.ts +110 -0
- package/src/services/users/external-user-integration-service.ts +51 -0
- package/src/services/users/profile-service.ts +513 -0
- package/src/services/users/service.ts +293 -0
- package/src/services/users/user-error-service.ts +74 -0
- package/src/services/users/users-group-service.ts +85 -0
- package/src/services/utils/field-naming-service.ts +78 -0
- package/src/services/utils/string-utils-service.ts +48 -0
- package/src/types/errors.ts +18 -0
- package/src/types/user-types.ts +19 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
export class UserPreferenceModel {
|
|
2
|
+
// Consts
|
|
3
|
+
clName = 'UserPreferenceModel';
|
|
4
|
+
// Code
|
|
5
|
+
async create(prisma, userProfileId, category, key, value, values) {
|
|
6
|
+
// Debug
|
|
7
|
+
const fnName = `${this.clName}.create()`;
|
|
8
|
+
// Values can't be null
|
|
9
|
+
if (values == null) {
|
|
10
|
+
values = [];
|
|
11
|
+
}
|
|
12
|
+
// Create record
|
|
13
|
+
try {
|
|
14
|
+
return await prisma.userPreference.create({
|
|
15
|
+
data: {
|
|
16
|
+
userProfileId: userProfileId,
|
|
17
|
+
category: category,
|
|
18
|
+
key: key,
|
|
19
|
+
value: value,
|
|
20
|
+
values: values
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error(`${fnName}: error: ${error}`);
|
|
26
|
+
throw 'Prisma error';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async deleteById(prisma, id) {
|
|
30
|
+
// Debug
|
|
31
|
+
const fnName = `${this.clName}.deleteById()`;
|
|
32
|
+
// Delete
|
|
33
|
+
try {
|
|
34
|
+
return await prisma.userPreference.delete({
|
|
35
|
+
where: {
|
|
36
|
+
id: id
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (!(error instanceof error.NotFound)) {
|
|
42
|
+
console.error(`${fnName}: error: ${error}`);
|
|
43
|
+
throw 'Prisma error';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async filter(prisma, userProfileId, category, key) {
|
|
48
|
+
// Debug
|
|
49
|
+
const fnName = `${this.clName}.filter()`;
|
|
50
|
+
// Query
|
|
51
|
+
try {
|
|
52
|
+
return await prisma.userPreference.findMany({
|
|
53
|
+
where: {
|
|
54
|
+
userProfileId: userProfileId,
|
|
55
|
+
category: category,
|
|
56
|
+
key: key
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error(`${fnName}: error: ${error}`);
|
|
62
|
+
throw 'Prisma error';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async filterManyKeys(prisma, userProfileId, keys) {
|
|
66
|
+
// Debug
|
|
67
|
+
const fnName = `${this.clName}.filter()`;
|
|
68
|
+
// Query
|
|
69
|
+
try {
|
|
70
|
+
return await prisma.userPreference.findMany({
|
|
71
|
+
where: {
|
|
72
|
+
userProfileId: userProfileId,
|
|
73
|
+
key: {
|
|
74
|
+
in: keys
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error(`${fnName}: error: ${error}`);
|
|
81
|
+
throw 'Prisma error';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async getById(prisma, id) {
|
|
85
|
+
// Debug
|
|
86
|
+
const fnName = `${this.clName}.getById()`;
|
|
87
|
+
// Query
|
|
88
|
+
var userpreference = null;
|
|
89
|
+
try {
|
|
90
|
+
userpreference = await prisma.userPreference.findUnique({
|
|
91
|
+
where: {
|
|
92
|
+
id: id
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (!(error instanceof error.NotFound)) {
|
|
98
|
+
console.error(`${fnName}: error: ${error}`);
|
|
99
|
+
throw 'Prisma error';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Return
|
|
103
|
+
return userpreference;
|
|
104
|
+
}
|
|
105
|
+
async getByUniqueKey(prisma, userProfileId, key) {
|
|
106
|
+
// Debug
|
|
107
|
+
const fnName = `${this.clName}.getByUniqueKey()`;
|
|
108
|
+
// Query
|
|
109
|
+
var userpreference = null;
|
|
110
|
+
try {
|
|
111
|
+
userpreference = await prisma.userPreference.findFirst({
|
|
112
|
+
where: {
|
|
113
|
+
userProfileId: userProfileId,
|
|
114
|
+
key: key
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (!(error instanceof error.NotFound)) {
|
|
120
|
+
console.error(`${fnName}: error: ${error}`);
|
|
121
|
+
throw 'Prisma error';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Return
|
|
125
|
+
return userpreference;
|
|
126
|
+
}
|
|
127
|
+
async update(prisma, id, userProfileId, category, key, value, values) {
|
|
128
|
+
// Debug
|
|
129
|
+
const fnName = `${this.clName}.update()`;
|
|
130
|
+
// Values can't be null
|
|
131
|
+
if (values == null) {
|
|
132
|
+
values = [];
|
|
133
|
+
}
|
|
134
|
+
// Update record
|
|
135
|
+
try {
|
|
136
|
+
return await prisma.userPreference.update({
|
|
137
|
+
data: {
|
|
138
|
+
userProfileId: userProfileId,
|
|
139
|
+
category: category,
|
|
140
|
+
key: key,
|
|
141
|
+
value: value,
|
|
142
|
+
values: values
|
|
143
|
+
},
|
|
144
|
+
where: {
|
|
145
|
+
id: id
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error(`${fnName}: error: ${error}`);
|
|
151
|
+
throw 'Prisma error';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async upsert(prisma, id, userProfileId, category, key, value, values) {
|
|
155
|
+
// Debug
|
|
156
|
+
const fnName = `${this.clName}.upsert()`;
|
|
157
|
+
// If id isn't specified, but the unique keys are, try to get the record
|
|
158
|
+
if (id == null &&
|
|
159
|
+
userProfileId != null &&
|
|
160
|
+
key != null) {
|
|
161
|
+
const userPreference = await this.getByUniqueKey(prisma, userProfileId, key);
|
|
162
|
+
if (userPreference != null) {
|
|
163
|
+
id = userPreference.id;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Upsert
|
|
167
|
+
if (id == null) {
|
|
168
|
+
// Validate for create (mainly for type validation of the create call)
|
|
169
|
+
if (userProfileId == null) {
|
|
170
|
+
console.error(`${fnName}: id is null and userProfileId is null`);
|
|
171
|
+
throw 'Prisma error';
|
|
172
|
+
}
|
|
173
|
+
if (category == null) {
|
|
174
|
+
console.error(`${fnName}: id is null and category is null`);
|
|
175
|
+
throw 'Prisma error';
|
|
176
|
+
}
|
|
177
|
+
if (key == null) {
|
|
178
|
+
console.error(`${fnName}: id is null and key is null`);
|
|
179
|
+
throw 'Prisma error';
|
|
180
|
+
}
|
|
181
|
+
if (value === undefined) {
|
|
182
|
+
console.error(`${fnName}: id is null and value is undefined`);
|
|
183
|
+
throw 'Prisma error';
|
|
184
|
+
}
|
|
185
|
+
if (values === undefined) {
|
|
186
|
+
console.error(`${fnName}: id is null and values is undefined`);
|
|
187
|
+
throw 'Prisma error';
|
|
188
|
+
}
|
|
189
|
+
// Create
|
|
190
|
+
return await this.create(prisma, userProfileId, category, key, value, values);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Update
|
|
194
|
+
return await this.update(prisma, id, userProfileId, category, key, value, values);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PrismaClient } from '@/prisma/client';
|
|
2
|
+
export declare class UserProfileModel {
|
|
3
|
+
clName: string;
|
|
4
|
+
create(prisma: PrismaClient, userId: string | null, isAdmin: boolean, deletePending: Date | null): Promise<{
|
|
5
|
+
id: string;
|
|
6
|
+
userId: string | null;
|
|
7
|
+
created: Date;
|
|
8
|
+
updated: Date;
|
|
9
|
+
isAdmin: boolean;
|
|
10
|
+
ownerType: string | null;
|
|
11
|
+
roles: string[];
|
|
12
|
+
deletePending: Date | null;
|
|
13
|
+
}>;
|
|
14
|
+
getById(prisma: PrismaClient, id: string): Promise<{
|
|
15
|
+
id: string;
|
|
16
|
+
userId: string | null;
|
|
17
|
+
created: Date;
|
|
18
|
+
updated: Date;
|
|
19
|
+
isAdmin: boolean;
|
|
20
|
+
ownerType: string | null;
|
|
21
|
+
roles: string[];
|
|
22
|
+
deletePending: Date | null;
|
|
23
|
+
} | null | undefined>;
|
|
24
|
+
getByUserId(prisma: PrismaClient, userId: string): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
userId: string | null;
|
|
27
|
+
created: Date;
|
|
28
|
+
updated: Date;
|
|
29
|
+
isAdmin: boolean;
|
|
30
|
+
ownerType: string | null;
|
|
31
|
+
roles: string[];
|
|
32
|
+
deletePending: Date | null;
|
|
33
|
+
} | null | undefined>;
|
|
34
|
+
setOwnerType(prisma: PrismaClient, userProfile: any): Promise<{
|
|
35
|
+
status: boolean;
|
|
36
|
+
userProfile: any;
|
|
37
|
+
}>;
|
|
38
|
+
update(prisma: PrismaClient, id: string, userId: string | null | undefined, isAdmin: boolean | undefined, deletePending: Date | null | undefined): Promise<{
|
|
39
|
+
id: string;
|
|
40
|
+
userId: string | null;
|
|
41
|
+
created: Date;
|
|
42
|
+
updated: Date;
|
|
43
|
+
isAdmin: boolean;
|
|
44
|
+
ownerType: string | null;
|
|
45
|
+
roles: string[];
|
|
46
|
+
deletePending: Date | null;
|
|
47
|
+
}>;
|
|
48
|
+
upsert(prisma: PrismaClient, id: string | undefined, userId: string | null | undefined, isAdmin: boolean | undefined, deletePending: Date | null | undefined): Promise<{
|
|
49
|
+
id: string;
|
|
50
|
+
userId: string | null;
|
|
51
|
+
created: Date;
|
|
52
|
+
updated: Date;
|
|
53
|
+
isAdmin: boolean;
|
|
54
|
+
ownerType: string | null;
|
|
55
|
+
roles: string[];
|
|
56
|
+
deletePending: Date | null;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { UserTypes } from '../../types/user-types';
|
|
2
|
+
export class UserProfileModel {
|
|
3
|
+
// Consts
|
|
4
|
+
clName = 'UserProfileModel';
|
|
5
|
+
// Code
|
|
6
|
+
async create(prisma, userId, isAdmin, deletePending) {
|
|
7
|
+
// Debug
|
|
8
|
+
const fnName = `${this.clName}.create()`;
|
|
9
|
+
// Create record
|
|
10
|
+
try {
|
|
11
|
+
return await prisma.userProfile.create({
|
|
12
|
+
data: {
|
|
13
|
+
userId: userId,
|
|
14
|
+
isAdmin: isAdmin,
|
|
15
|
+
deletePending: deletePending
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error(`${fnName}: error: ${error}`);
|
|
21
|
+
throw 'Prisma error';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async getById(prisma, id) {
|
|
25
|
+
// Debug
|
|
26
|
+
const fnName = `${this.clName}.getById()`;
|
|
27
|
+
// Get record
|
|
28
|
+
try {
|
|
29
|
+
return await prisma.userProfile.findUnique({
|
|
30
|
+
where: {
|
|
31
|
+
id: id
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (!(error instanceof error.NotFound)) {
|
|
37
|
+
console.error(`${fnName}: error: ${error}`);
|
|
38
|
+
throw 'Prisma error';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async getByUserId(prisma, userId) {
|
|
43
|
+
// Debug
|
|
44
|
+
const fnName = `${this.clName}.getByUserId()`;
|
|
45
|
+
// Get record
|
|
46
|
+
try {
|
|
47
|
+
return await prisma.userProfile.findFirst({
|
|
48
|
+
where: {
|
|
49
|
+
userId: userId
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (!(error instanceof error.NotFound)) {
|
|
55
|
+
console.error(`${fnName}: error: ${error}`);
|
|
56
|
+
throw 'Prisma error';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async setOwnerType(prisma, userProfile) {
|
|
61
|
+
// Debug
|
|
62
|
+
const fnName = `${this.clName}.setOwnerType()`;
|
|
63
|
+
console.log(`${fnName}: starting with userProfile: ` +
|
|
64
|
+
JSON.stringify(userProfile));
|
|
65
|
+
// Return immediately if ownerType is set
|
|
66
|
+
if (userProfile.ownerType != null) {
|
|
67
|
+
return {
|
|
68
|
+
status: true,
|
|
69
|
+
userProfile: userProfile
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Set to human ownerType if the userId field is set
|
|
73
|
+
var ownerType = '';
|
|
74
|
+
if (userProfile.ownerType == null) {
|
|
75
|
+
ownerType = UserTypes.humanRoleOwnerType;
|
|
76
|
+
}
|
|
77
|
+
// Update record
|
|
78
|
+
userProfile = await prisma.userProfile.update({
|
|
79
|
+
data: {
|
|
80
|
+
ownerType: ownerType
|
|
81
|
+
},
|
|
82
|
+
where: {
|
|
83
|
+
id: userProfile.id
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Return
|
|
87
|
+
return {
|
|
88
|
+
status: true,
|
|
89
|
+
userProfile: userProfile
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async update(prisma, id, userId, isAdmin, deletePending) {
|
|
93
|
+
// Debug
|
|
94
|
+
const fnName = `${this.clName}.update()`;
|
|
95
|
+
// Create record
|
|
96
|
+
try {
|
|
97
|
+
return await prisma.userProfile.update({
|
|
98
|
+
data: {
|
|
99
|
+
userId: userId,
|
|
100
|
+
isAdmin: isAdmin
|
|
101
|
+
},
|
|
102
|
+
where: {
|
|
103
|
+
id: id
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error(`${fnName}: error: ${error}`);
|
|
109
|
+
throw 'Prisma error';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async upsert(prisma, id, userId, isAdmin, deletePending) {
|
|
113
|
+
// Debug
|
|
114
|
+
const fnName = `${this.clName}.upsert()`;
|
|
115
|
+
// If id isn't specified, but the unique keys are, try to get the record
|
|
116
|
+
if (id == null &&
|
|
117
|
+
userId != null) {
|
|
118
|
+
const userProfile = await this.getByUserId(prisma, userId);
|
|
119
|
+
if (userProfile != null) {
|
|
120
|
+
id = userProfile.id;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Upsert
|
|
124
|
+
if (id == null) {
|
|
125
|
+
// Validate for create (mainly for type validation of the create call)
|
|
126
|
+
if (userId === undefined) {
|
|
127
|
+
console.error(`${fnName}: id is null and userId is undefined`);
|
|
128
|
+
throw 'Prisma error';
|
|
129
|
+
}
|
|
130
|
+
if (isAdmin == null) {
|
|
131
|
+
console.error(`${fnName}: id is null and isAdmin is null`);
|
|
132
|
+
throw 'Prisma error';
|
|
133
|
+
}
|
|
134
|
+
if (deletePending === undefined) {
|
|
135
|
+
console.error(`${fnName}: id is null and deletePending is undefined`);
|
|
136
|
+
throw 'Prisma error';
|
|
137
|
+
}
|
|
138
|
+
// Create
|
|
139
|
+
return await this.create(prisma, userId, isAdmin, deletePending);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Update
|
|
143
|
+
return await this.update(prisma, id, userId, isAdmin, deletePending);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrismaClient } from '@/prisma/client';
|
|
2
|
+
import { UsersService } from '../users/service';
|
|
3
|
+
export declare class AccessService {
|
|
4
|
+
usersService: UsersService;
|
|
5
|
+
isAdminUser(prisma: PrismaClient, userProfileId: string): Promise<{
|
|
6
|
+
status: boolean;
|
|
7
|
+
message: string;
|
|
8
|
+
} | {
|
|
9
|
+
status: any;
|
|
10
|
+
message: null;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { UsersService } from '../users/service';
|
|
2
|
+
export class AccessService {
|
|
3
|
+
usersService = new UsersService();
|
|
4
|
+
async isAdminUser(prisma, userProfileId) {
|
|
5
|
+
// Get UserProfile record
|
|
6
|
+
var userProfile = null;
|
|
7
|
+
try {
|
|
8
|
+
userProfile = await prisma.userProfile.findUnique({
|
|
9
|
+
where: {
|
|
10
|
+
id: userProfileId
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
catch (NotFound) { }
|
|
15
|
+
if (userProfile == null) {
|
|
16
|
+
return {
|
|
17
|
+
status: false,
|
|
18
|
+
message: 'User not found'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// Return isAdmin value
|
|
22
|
+
return {
|
|
23
|
+
status: userProfile.isAdmin,
|
|
24
|
+
message: null
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CipherGCMTypes } from 'crypto';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
export declare class Encrypter {
|
|
4
|
+
clName: string;
|
|
5
|
+
header: string;
|
|
6
|
+
algorithm: CipherGCMTypes;
|
|
7
|
+
key: Buffer;
|
|
8
|
+
constructor(encryptionKey: string | undefined);
|
|
9
|
+
encrypt(clearText: string): string;
|
|
10
|
+
encryptAes256Gcm(clearText: string): string;
|
|
11
|
+
decrypt(encryptedText: string): string;
|
|
12
|
+
decryptAes256Gcm(encryptedText: string): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Source: https://stackoverflow.com/a/66476430
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
export class Encrypter {
|
|
5
|
+
// Consts
|
|
6
|
+
clName = 'Encrypter';
|
|
7
|
+
header = '!enc%';
|
|
8
|
+
algorithm = 'aes-256-gcm';
|
|
9
|
+
// Vars
|
|
10
|
+
key;
|
|
11
|
+
// Code
|
|
12
|
+
constructor(encryptionKey) {
|
|
13
|
+
// Debug
|
|
14
|
+
const fnName = `${this.clName}.constructor()`;
|
|
15
|
+
// Validate
|
|
16
|
+
if (encryptionKey == null) {
|
|
17
|
+
throw new Error(`${fnName}: encryptionKey == null`);
|
|
18
|
+
}
|
|
19
|
+
// Set key
|
|
20
|
+
this.key = crypto.scryptSync(encryptionKey, 'salt', 32);
|
|
21
|
+
}
|
|
22
|
+
encrypt(clearText) {
|
|
23
|
+
return this.encryptAes256Gcm(clearText);
|
|
24
|
+
}
|
|
25
|
+
encryptAes256Gcm(clearText) {
|
|
26
|
+
// Get IV
|
|
27
|
+
const iv = crypto.randomBytes(16);
|
|
28
|
+
// Get cipher
|
|
29
|
+
const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);
|
|
30
|
+
// Encrypt string
|
|
31
|
+
const encrypted = cipher.update(clearText, 'utf8', 'hex') + cipher.final('hex');
|
|
32
|
+
// Get the authTag
|
|
33
|
+
const authTag = cipher.getAuthTag().toString('hex');
|
|
34
|
+
// Return final string with metadata
|
|
35
|
+
return [
|
|
36
|
+
this.header,
|
|
37
|
+
this.algorithm,
|
|
38
|
+
encrypted,
|
|
39
|
+
iv.toString('hex'),
|
|
40
|
+
authTag
|
|
41
|
+
].join('|');
|
|
42
|
+
}
|
|
43
|
+
decrypt(encryptedText) {
|
|
44
|
+
return this.decryptAes256Gcm(encryptedText);
|
|
45
|
+
}
|
|
46
|
+
decryptAes256Gcm(encryptedText) {
|
|
47
|
+
// Debug
|
|
48
|
+
const fnName = `${this.clName}.decryptAes256Gcm()`;
|
|
49
|
+
// console.log(`${fnName}: starting with encryptedText: ${encryptedText}`)
|
|
50
|
+
// Split string with metadata into separate vars
|
|
51
|
+
const [header, algorithm, encrypted, iv, authTag] = encryptedText.split('|');
|
|
52
|
+
// Validate
|
|
53
|
+
if (header !== this.header) {
|
|
54
|
+
throw new Error('Unexpected header, string is likely not encrypted');
|
|
55
|
+
}
|
|
56
|
+
if (algorithm !== this.algorithm) {
|
|
57
|
+
throw new Error('Unexpected/invalid encryption algorithm');
|
|
58
|
+
}
|
|
59
|
+
if (!iv) {
|
|
60
|
+
throw new Error('IV not found');
|
|
61
|
+
}
|
|
62
|
+
if (!authTag) {
|
|
63
|
+
throw new Error('authTag not found');
|
|
64
|
+
}
|
|
65
|
+
// Debug
|
|
66
|
+
// console.log(`${fnName}: decipher encrypted text..`)
|
|
67
|
+
// Decipher encrypted string
|
|
68
|
+
const decipher = crypto.createDecipheriv(this.algorithm, this.key, Buffer.from(iv, 'hex'));
|
|
69
|
+
decipher.setAuthTag(new Uint8Array(Buffer.from(authTag, 'hex')));
|
|
70
|
+
// Debug
|
|
71
|
+
// console.log(`${fnName}: decipher: ` + JSON.stringify(decipher))
|
|
72
|
+
// Get the final decrypted string
|
|
73
|
+
const decryptedText = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
|
|
74
|
+
// Debug
|
|
75
|
+
// console.log(`${fnName}: returning decrypted text..`)
|
|
76
|
+
// Return final decrypted string
|
|
77
|
+
return decryptedText;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PrismaClient } from '@/prisma/client';
|
|
2
|
+
import { TechModel } from '../../models/tech/tech-model';
|
|
3
|
+
import { RateLimitedApiModel } from '../../models/tech/rate-limited-api-model';
|
|
4
|
+
import { RateLimitedApiEventModel } from '../../models/tech/rate-limited-api-event-model';
|
|
5
|
+
export declare class ApiUsageBaseService {
|
|
6
|
+
clName: string;
|
|
7
|
+
rateLimitedApiEventModel: RateLimitedApiEventModel;
|
|
8
|
+
rateLimitedApiModel: RateLimitedApiModel;
|
|
9
|
+
techModel: TechModel;
|
|
10
|
+
isRateLimited(prisma: PrismaClient, variantName?: string | undefined, techId?: string | undefined): Promise<{
|
|
11
|
+
isRateLimited: boolean;
|
|
12
|
+
waitSeconds: number | null;
|
|
13
|
+
rateLimitedApiId: any;
|
|
14
|
+
} | null>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CustomError } from '../../types/errors';
|
|
2
|
+
import { TechModel } from '../../models/tech/tech-model';
|
|
3
|
+
import { RateLimitedApiModel } from '../../models/tech/rate-limited-api-model';
|
|
4
|
+
import { RateLimitedApiEventModel } from '../../models/tech/rate-limited-api-event-model';
|
|
5
|
+
export class ApiUsageBaseService {
|
|
6
|
+
// Consts
|
|
7
|
+
clName = 'ApiUsageBaseService';
|
|
8
|
+
// Models
|
|
9
|
+
rateLimitedApiEventModel = new RateLimitedApiEventModel();
|
|
10
|
+
rateLimitedApiModel = new RateLimitedApiModel();
|
|
11
|
+
techModel = new TechModel();
|
|
12
|
+
// Code
|
|
13
|
+
async isRateLimited(prisma, variantName = undefined, techId = undefined) {
|
|
14
|
+
// Debug
|
|
15
|
+
const fnName = `${this.clName}.isRateLimited()`;
|
|
16
|
+
// Validate
|
|
17
|
+
if (techId == null &&
|
|
18
|
+
variantName == null) {
|
|
19
|
+
throw new CustomError(`Either a techId or variantName must be specified`);
|
|
20
|
+
}
|
|
21
|
+
// Get the techId for the Apollo.io API
|
|
22
|
+
if (techId == null &&
|
|
23
|
+
variantName != null) {
|
|
24
|
+
const tech = await this.techModel.getByVariantName(prisma, variantName);
|
|
25
|
+
techId = tech.id;
|
|
26
|
+
}
|
|
27
|
+
if (techId == null) {
|
|
28
|
+
throw new CustomError(`techId not found`);
|
|
29
|
+
}
|
|
30
|
+
// Get API rate limiting data
|
|
31
|
+
const rateLimitedApi = await this.rateLimitedApiModel.getByTechId(prisma, techId);
|
|
32
|
+
// Return null if not a rate-limited tech
|
|
33
|
+
if (rateLimitedApi == null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
// Determine if rate-limited
|
|
37
|
+
const eventCount = await this.rateLimitedApiEventModel.getUserSentForLastSpecifiedMinutes(prisma, 1); // For the last minute
|
|
38
|
+
// console.log(`${fnName}: is eventCount: ${eventCount} >= ` +
|
|
39
|
+
// `rateLimitedApi.ratePerMinute: ${rateLimitedApi.ratePerMinute}`)
|
|
40
|
+
// Is the API currently rate limited?
|
|
41
|
+
var isRateLimited = false;
|
|
42
|
+
var waitSeconds = 0;
|
|
43
|
+
if (eventCount >= rateLimitedApi.ratePerMinute) {
|
|
44
|
+
isRateLimited = true;
|
|
45
|
+
// Get last record within the window
|
|
46
|
+
waitSeconds = await this.rateLimitedApiEventModel.getWaitSecondsSinceLastSpecifiedMinutes(prisma, 1); // For the last minute
|
|
47
|
+
if (waitSeconds == null ||
|
|
48
|
+
waitSeconds === 0) {
|
|
49
|
+
isRateLimited = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
isRateLimited: isRateLimited,
|
|
54
|
+
waitSeconds: waitSeconds,
|
|
55
|
+
rateLimitedApiId: rateLimitedApi.id
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import * as readline from 'node:readline/promises';
|
|
3
|
+
import { stdin as input, stdout } from 'node:process';
|
|
4
|
+
// Note: this class's console services can clash with other CLI libraries.
|
|
5
|
+
class ConsoleService {
|
|
6
|
+
rl = readline.createInterface({ input });
|
|
7
|
+
async askQuestion(query) {
|
|
8
|
+
// Reuse the class-level interface
|
|
9
|
+
stdout.write(chalk.bold.cyan(query));
|
|
10
|
+
const answer = await this.rl.question('');
|
|
11
|
+
return answer;
|
|
12
|
+
}
|
|
13
|
+
close() {
|
|
14
|
+
this.rl.close();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// Export a single instance so that the interface is only created once
|
|
18
|
+
export const consoleService = new ConsoleService();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type PgRecordEstimateInput = {
|
|
2
|
+
numberFields?: number[];
|
|
3
|
+
booleanFields?: boolean[];
|
|
4
|
+
stringFields?: string[];
|
|
5
|
+
jsonFields?: any[];
|
|
6
|
+
bigStringValues?: any[];
|
|
7
|
+
bigJsonValues?: any[];
|
|
8
|
+
};
|
|
9
|
+
export declare class PgEstimateSizeService {
|
|
10
|
+
clName: string;
|
|
11
|
+
estimateRecordSize(records: PgRecordEstimateInput[]): {
|
|
12
|
+
totalInline: number;
|
|
13
|
+
totalToast: number;
|
|
14
|
+
total: number;
|
|
15
|
+
};
|
|
16
|
+
}
|