From 022401b60ef7926c81214c83a4e515d3ddeedd7d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 27 Jun 2022 21:31:54 +0200 Subject: [PATCH] web: manage version via package.json Signed-off-by: Jens Langhammer --- .bumpversion.cfg | 2 +- web/.eslintignore | 2 -- web/.prettierignore | 2 -- web/package.json | 4 +-- web/rollup.config.js | 13 +++++---- web/src/api/Config.ts | 61 ++++++++++++++++++++++++---------------- web/src/api/Plex.ts | 4 +-- web/src/api/Sentry.ts | 34 ++++++++++++++-------- web/src/api/Users.ts | 65 ++++++++++++++++++++++++------------------- web/src/constants.ts | 4 ++- 10 files changed, 111 insertions(+), 80 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 8aef550c4..0a2eb407b 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -17,4 +17,4 @@ tag_name = version/{new_version} [bumpversion:file:internal/constants/constants.go] -[bumpversion:file:web/src/constants.ts] +[bumpversion:file:web/package.json] diff --git a/web/.eslintignore b/web/.eslintignore index 8310f82be..537b7fae4 100644 --- a/web/.eslintignore +++ b/web/.eslintignore @@ -4,5 +4,3 @@ node_modules dist # don't lint nyc coverage output coverage -# don't lint generated code -api/ diff --git a/web/.prettierignore b/web/.prettierignore index eb60f42e2..bbc64fc00 100644 --- a/web/.prettierignore +++ b/web/.prettierignore @@ -4,7 +4,5 @@ node_modules dist # don't lint nyc coverage output coverage -# don't lint generated code -api/ # Import order matters poly.ts diff --git a/web/package.json b/web/package.json index b1382e171..201be35f3 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { - "name": "authentik-web", - "version": "0.0.0", + "name": "@goauthentik/web", + "version": "2022.6.3", "private": true, "license": "GNU GPLv3", "scripts": { diff --git a/web/rollup.config.js b/web/rollup.config.js index 8e4ff033f..970fb0f3e 100644 --- a/web/rollup.config.js +++ b/web/rollup.config.js @@ -7,6 +7,8 @@ import copy from "rollup-plugin-copy"; import cssimport from "rollup-plugin-cssimport"; import { terser } from "rollup-plugin-terser"; +import pkg from "./package.json"; + const extensions = [".js", ".jsx", ".ts", ".tsx"]; export const resources = [ @@ -73,6 +75,12 @@ export const defaultOptions = { plugins: [ cssimport(), markdown(), + replace({ + "process.env.NODE_ENV": JSON.stringify(isProdBuild ? "production" : "development"), + "process.env.AK_API_BASE_PATH": JSON.stringify(apiBasePath), + "process.env.AK_VERSION": JSON.stringify(pkg.version), + "preventAssignment": true, + }), nodeResolve({ extensions, browser: true }), commonjs(), babel({ @@ -80,11 +88,6 @@ export const defaultOptions = { babelHelpers: "runtime", include: ["src/**/*"], }), - replace({ - "process.env.NODE_ENV": JSON.stringify(isProdBuild ? "production" : "development"), - "process.env.AK_API_BASE_PATH": JSON.stringify(apiBasePath), - "preventAssignment": true, - }), isProdBuild && terser(), ].filter((p) => p), watch: { diff --git a/web/src/api/Config.ts b/web/src/api/Config.ts index 06ef8f6fb..7b3f3cb2e 100644 --- a/web/src/api/Config.ts +++ b/web/src/api/Config.ts @@ -1,20 +1,29 @@ -import { Config, Configuration, CoreApi, CurrentTenant, FetchParams, Middleware, RequestContext, ResponseContext, RootApi } from "@goauthentik/api"; -import { getCookie } from "@goauthentik/web/utils"; -import { APIMiddleware } from "@goauthentik/web/elements/notifications/APIDrawer"; -import { MessageMiddleware } from "@goauthentik/web/elements/messages/Middleware"; import { VERSION } from "@goauthentik/web/constants"; +import { MessageMiddleware } from "@goauthentik/web/elements/messages/Middleware"; +import { APIMiddleware } from "@goauthentik/web/elements/notifications/APIDrawer"; +import { getCookie } from "@goauthentik/web/utils"; + +import { + Config, + Configuration, + CoreApi, + CurrentTenant, + FetchParams, + Middleware, + RequestContext, + ResponseContext, + RootApi, +} from "@goauthentik/api"; export class LoggingMiddleware implements Middleware { - post(context: ResponseContext): Promise { - tenant().then(tenant => { + tenant().then((tenant) => { let msg = `authentik/api[${tenant.matchedDomain}]: `; msg += `${context.response.status} ${context.init.method} ${context.url}`; console.debug(msg); }); return Promise.resolve(context.response); } - } let globalConfigPromise: Promise; @@ -28,23 +37,27 @@ export function config(): Promise { let globalTenantPromise: Promise; export function tenant(): Promise { if (!globalTenantPromise) { - globalTenantPromise = new CoreApi(DEFAULT_CONFIG).coreTenantsCurrentRetrieve().then(tenant => { - /** - * - * - */ - const rels = ["icon", "shortcut icon"]; - rels.forEach(rel => { - let relIcon = document.head.querySelector(`link[rel='${rel}']`); - if (!relIcon) { - relIcon = document.createElement('link'); - relIcon.rel = rel; - document.getElementsByTagName('head')[0].appendChild(relIcon); - } - relIcon.href = tenant.brandingFavicon; - }) - return tenant; - }); + globalTenantPromise = new CoreApi(DEFAULT_CONFIG) + .coreTenantsCurrentRetrieve() + .then((tenant) => { + /** + * + * + */ + const rels = ["icon", "shortcut icon"]; + rels.forEach((rel) => { + let relIcon = document.head.querySelector( + `link[rel='${rel}']`, + ); + if (!relIcon) { + relIcon = document.createElement("link"); + relIcon.rel = rel; + document.getElementsByTagName("head")[0].appendChild(relIcon); + } + relIcon.href = tenant.brandingFavicon; + }); + return tenant; + }); } return globalTenantPromise; } diff --git a/web/src/api/Plex.ts b/web/src/api/Plex.ts index 7185a94d2..6295a5fe9 100644 --- a/web/src/api/Plex.ts +++ b/web/src/api/Plex.ts @@ -74,10 +74,10 @@ export class PlexAPIClient { headers: headers, }); if (pinResponse.status > 200) { - throw new SentryIgnoredError("Invalid response code") + throw new SentryIgnoredError("Invalid response code"); } const pin: PlexPinResponse = await pinResponse.json(); - console.debug(`authentik/plex: polling Pin`); + console.debug("authentik/plex: polling Pin"); return pin.authToken; } diff --git a/web/src/api/Sentry.ts b/web/src/api/Sentry.ts index 815a94af9..6c500afbd 100644 --- a/web/src/api/Sentry.ts +++ b/web/src/api/Sentry.ts @@ -1,11 +1,13 @@ +import { SentryIgnoredError } from "@goauthentik/web/common/errors"; +import { VERSION } from "@goauthentik/web/constants"; import * as Sentry from "@sentry/browser"; import { Integrations } from "@sentry/tracing"; -import { VERSION } from "@goauthentik/web/constants"; -import { SentryIgnoredError } from "@goauthentik/web/common/errors"; -import { me } from "./Users"; -import { config } from "./Config"; + import { Config } from "@goauthentik/api"; +import { config } from "./Config"; +import { me } from "./Users"; + export const TAG_SENTRY_COMPONENT = "authentik.component"; export const TAG_SENTRY_CAPABILITIES = "authentik.capabilities"; @@ -15,13 +17,13 @@ export function configureSentry(canDoPpi = false): Promise { Sentry.init({ dsn: "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8", ignoreErrors: [ - /network/ig, - /fetch/ig, + /network/gi, + /fetch/gi, // Error on edge on ios, // https://stackoverflow.com/questions/69261499/what-is-instantsearchsdkjsbridgeclearhighlight - /instantSearchSDKJSBridgeClearHighlight/ig, + /instantSearchSDKJSBridgeClearHighlight/gi, // Seems to be an issue in Safari and Firefox - /MutationObserver.observe/ig, + /MutationObserver.observe/gi, ], release: `authentik@${VERSION}`, tunnel: "/api/v3/sentry/", @@ -32,14 +34,20 @@ export function configureSentry(canDoPpi = false): Promise { ], tracesSampleRate: config.errorReporting.tracesSampleRate, environment: config.errorReporting.environment, - beforeSend: async (event: Sentry.Event, hint: Sentry.EventHint | undefined): Promise => { + beforeSend: async ( + event: Sentry.Event, + hint: Sentry.EventHint | undefined, + ): Promise => { if (!hint) { return event; } if (hint.originalException instanceof SentryIgnoredError) { return null; } - if (hint.originalException instanceof Response || hint.originalException instanceof DOMException) { + if ( + hint.originalException instanceof Response || + hint.originalException instanceof DOMException + ) { return null; } return event; @@ -48,10 +56,12 @@ export function configureSentry(canDoPpi = false): Promise { Sentry.setTag(TAG_SENTRY_CAPABILITIES, config.capabilities.join(",")); if (window.location.pathname.includes("if/")) { Sentry.setTag(TAG_SENTRY_COMPONENT, `web/${currentInterface()}`); - Sentry.configureScope((scope) => scope.setTransactionName(`authentik.web.if.${currentInterface()}`)); + Sentry.configureScope((scope) => + scope.setTransactionName(`authentik.web.if.${currentInterface()}`), + ); } if (config.errorReporting.sendPii && canDoPpi) { - me().then(user => { + me().then((user) => { Sentry.setUser({ email: user.user.email }); console.debug("authentik/config: Sentry with PII enabled."); }); diff --git a/web/src/api/Users.ts b/web/src/api/Users.ts index bfff41a0e..616db9169 100644 --- a/web/src/api/Users.ts +++ b/web/src/api/Users.ts @@ -1,5 +1,7 @@ -import { CoreApi, ResponseError, SessionUser } from "@goauthentik/api"; import { activateLocale } from "@goauthentik/web/interfaces/locale"; + +import { CoreApi, ResponseError, SessionUser } from "@goauthentik/api"; + import { DEFAULT_CONFIG } from "./Config"; let globalMePromise: Promise | undefined; @@ -11,35 +13,40 @@ export function refreshMe(): Promise { export function me(): Promise { if (!globalMePromise) { - globalMePromise = new CoreApi(DEFAULT_CONFIG).coreUsersMeRetrieve().then((user) => { - if (!user.user.settings || !("locale" in user.user.settings)) { - return user; - } - const locale = user.user.settings.locale; - if (locale && locale !== "") { - console.debug(`authentik/locale: Activating user's configured locale '${locale}'`); - activateLocale(locale); - } - return user; - }).catch((ex: ResponseError) => { - const defaultUser: SessionUser = { - user: { - pk: -1, - isSuperuser: false, - isActive: true, - groups: [], - avatar: "", - uid: "", - username: "", - name: "", - settings: {}, + globalMePromise = new CoreApi(DEFAULT_CONFIG) + .coreUsersMeRetrieve() + .then((user) => { + if (!user.user.settings || !("locale" in user.user.settings)) { + return user; } - }; - if (ex.response.status === 401 || ex.response.status === 403) { - window.location.assign("/"); - } - return defaultUser; - }); + const locale = user.user.settings.locale; + if (locale && locale !== "") { + console.debug( + `authentik/locale: Activating user's configured locale '${locale}'`, + ); + activateLocale(locale); + } + return user; + }) + .catch((ex: ResponseError) => { + const defaultUser: SessionUser = { + user: { + pk: -1, + isSuperuser: false, + isActive: true, + groups: [], + avatar: "", + uid: "", + username: "", + name: "", + settings: {}, + }, + }; + if (ex.response.status === 401 || ex.response.status === 403) { + window.location.assign("/"); + } + return defaultUser; + }); } return globalMePromise; } diff --git a/web/src/constants.ts b/web/src/constants.ts index e66700b9c..30a799de2 100644 --- a/web/src/constants.ts +++ b/web/src/constants.ts @@ -1,9 +1,11 @@ +// Placeholder, replaced by rollup; +export const VERSION = process.env.AK_VERSION; + export const SECONDARY_CLASS = "pf-m-secondary"; export const SUCCESS_CLASS = "pf-m-success"; export const ERROR_CLASS = "pf-m-danger"; export const PROGRESS_CLASS = "pf-m-in-progress"; export const CURRENT_CLASS = "pf-m-current"; -export const VERSION = "2022.6.3"; export const TITLE_DEFAULT = "authentik"; export const ROUTE_SEPARATOR = ";";