@codegouvfr/sill
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -8,2 +8,2 @@ import { UserApi } from "../ports/UserApi"; | ||
}; | ||
export declare function createKeycloakUserApi(params: KeycloakUserApiParams): Promise<UserApi>; | ||
export declare function createKeycloakUserApi(params: KeycloakUserApiParams): UserApi; |
@@ -33,3 +33,4 @@ "use strict"; | ||
const memoizee_1 = __importDefault(require("memoizee")); | ||
async function createKeycloakUserApi(params) { | ||
const maxAge = 5 * 60 * 1000; | ||
function createKeycloakUserApi(params) { | ||
const { url, adminPassword, realm, organizationUserProfileAttributeName } = params; | ||
@@ -64,3 +65,3 @@ const keycloakAdminApiClient = (0, keycloakAdminApiClient_1.createKeycloakAdminApiClient)({ | ||
"promise": true, | ||
"maxAge": 5 * 60 * 1000, | ||
maxAge, | ||
"preFetch": true | ||
@@ -97,3 +98,3 @@ }), | ||
"promise": true, | ||
"maxAge": 60 * 60 * 1000, | ||
maxAge, | ||
"preFetch": true | ||
@@ -120,8 +121,11 @@ }), | ||
"promise": true, | ||
"maxAge": 60 * 60 * 1000, | ||
maxAge, | ||
"preFetch": true | ||
}) | ||
}; | ||
//NOTE: Preload data | ||
await Promise.all([userApi.getUserCount(), userApi.getAllOrganizations(), userApi.getAllowedEmailRegexp()]); | ||
["getUserCount", "getAllOrganizations", "getAllowedEmailRegexp"].map(function callee(methodName) { | ||
const f = userApi[methodName]; | ||
f(); | ||
setInterval(f, maxAge - 10000); | ||
}); | ||
return userApi; | ||
@@ -128,0 +132,0 @@ } |
{ | ||
"name": "@codegouvfr/sill", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "The backend of sill.etalab.gouv.fr", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -250,12 +250,18 @@ "use strict"; | ||
.query((() => { | ||
const maxAge = (1000 * 3600) / 2; | ||
const memoizedFetch = (0, memoizee_1.default)(async (url) => (0, node_fetch_1.default)(url).then(res => res.text()), { | ||
"promise": true, | ||
"maxAge": (1000 * 3600) / 2, | ||
maxAge, | ||
"preFetch": true | ||
}); | ||
const allowedUrls = GetWikidataSoftware_1.languages | ||
// prettier-ignore | ||
GetWikidataSoftware_1.languages | ||
.map(lang => (0, LocalizedString_1.createResolveLocalizedString)({ "currentLanguage": lang, "fallbackLanguage": "en" })) | ||
.map(({ resolveLocalizedString }) => [termsOfServiceUrl, readmeUrl].map(resolveLocalizedString)) | ||
.flat(); | ||
allowedUrls.forEach(memoizedFetch); | ||
.flat() | ||
.forEach(async function callee(url) { | ||
memoizedFetch(url); | ||
await new Promise(resolve => setTimeout(resolve, maxAge - 10000)); | ||
callee(url); | ||
}); | ||
return async ({ input }) => { | ||
@@ -262,0 +268,0 @@ const { language, name } = input; |
@@ -13,3 +13,5 @@ import { createKeycloakAdminApiClient } from "../../tools/keycloakAdminApiClient"; | ||
export async function createKeycloakUserApi(params: KeycloakUserApiParams): Promise<UserApi> { | ||
const maxAge = 5 * 60 * 1000; | ||
export function createKeycloakUserApi(params: KeycloakUserApiParams): UserApi { | ||
const { url, adminPassword, realm, organizationUserProfileAttributeName } = params; | ||
@@ -55,3 +57,3 @@ | ||
"promise": true, | ||
"maxAge": 5 * 60 * 1000, | ||
maxAge, | ||
"preFetch": true | ||
@@ -100,3 +102,3 @@ } | ||
"promise": true, | ||
"maxAge": 60 * 60 * 1000, | ||
maxAge, | ||
"preFetch": true | ||
@@ -133,3 +135,3 @@ } | ||
"promise": true, | ||
"maxAge": 60 * 60 * 1000, | ||
maxAge, | ||
"preFetch": true | ||
@@ -140,6 +142,11 @@ } | ||
//NOTE: Preload data | ||
await Promise.all([userApi.getUserCount(), userApi.getAllOrganizations(), userApi.getAllowedEmailRegexp()]); | ||
(["getUserCount", "getAllOrganizations", "getAllowedEmailRegexp"] as const).map(function callee(methodName) { | ||
const f = userApi[methodName]; | ||
f(); | ||
setInterval(f, maxAge - 10_000); | ||
}); | ||
return userApi; | ||
} |
@@ -306,17 +306,25 @@ import type { ReturnType } from "tsafe"; | ||
(() => { | ||
const maxAge = (1000 * 3600) / 2; | ||
const memoizedFetch = memoize(async (url: string) => fetch(url).then(res => res.text()), { | ||
"promise": true, | ||
"maxAge": (1000 * 3600) / 2, | ||
maxAge, | ||
"preFetch": true | ||
}); | ||
const allowedUrls = languages | ||
.map(lang => | ||
createResolveLocalizedString({ "currentLanguage": lang, "fallbackLanguage": "en" }) | ||
) | ||
// prettier-ignore | ||
languages | ||
.map(lang => createResolveLocalizedString({ "currentLanguage": lang, "fallbackLanguage": "en" })) | ||
.map(({ resolveLocalizedString }) => [termsOfServiceUrl, readmeUrl].map(resolveLocalizedString)) | ||
.flat(); | ||
.flat() | ||
.forEach(async function callee(url) { | ||
allowedUrls.forEach(memoizedFetch); | ||
memoizedFetch(url); | ||
await new Promise(resolve => setTimeout(resolve, maxAge - 10_000)); | ||
callee(url); | ||
}); | ||
return async ({ input }) => { | ||
@@ -323,0 +331,0 @@ const { language, name } = input; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
615849
11701