From 99bd3175cb5053d640b8f22cfa1ee672ed4dbdc2 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:07:17 +0200 Subject: [PATCH] revamp installer models --- src/Umbraco.Web.UI.Client/schemas/api/api.yml | 76 +++++++++++-------- .../schemas/generated-schema.ts | 73 ++++++++++-------- .../src/core/api/fetcher.ts | 5 +- .../src/core/models/index.ts | 12 ++- .../src/installer/installer-context.ts | 9 ++- .../src/mocks/domains/install.handlers.ts | 6 +- .../temp-schema-generator/installer.ts | 55 ++++++++------ 7 files changed, 134 insertions(+), 102 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/schemas/api/api.yml b/src/Umbraco.Web.UI.Client/schemas/api/api.yml index 4de5ad87c3..9e33e5fdff 100644 --- a/src/Umbraco.Web.UI.Client/schemas/api/api.yml +++ b/src/Umbraco.Web.UI.Client/schemas/api/api.yml @@ -3,24 +3,31 @@ info: title: umbraco-backoffice-api version: 1.0.0 paths: - /install: + /install/settings: get: - operationId: GetInstall + operationId: GetInstallSettings responses: '200': description: 200 response content: application/json: schema: - $ref: '#/components/schemas/UmbracoInstaller' + $ref: '#/components/schemas/InstallSettingsResponse' + default: + description: default response + content: + application/json: + schema: + $ref: '#/components/schemas/ProblemDetails' + /install/setup: post: - operationId: PostInstall + operationId: PostInstallSetup parameters: [] requestBody: content: application/json: schema: - $ref: '#/components/schemas/UmbracoPerformInstallRequest' + $ref: '#/components/schemas/InstallSetupRequest' required: true responses: '201': @@ -31,7 +38,7 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetails' - /install/database/validate: + /install/validateDatabase: post: operationId: PostInstallValidateDatabase parameters: [] @@ -39,7 +46,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/UmbracoPerformInstallDatabaseConfiguration' + $ref: '#/components/schemas/InstallValidateDatabaseRequest' required: true responses: '201': @@ -163,7 +170,7 @@ components: required: - level - description - UmbracoInstallerUserModel: + InstallUserModel: type: object properties: minCharLength: @@ -180,7 +187,7 @@ components: - minCharLength - minNonAlphaNumericLength - consentLevels - UmbracoInstallerDatabaseModel: + InstallDatabaseModel: type: object properties: id: @@ -220,19 +227,38 @@ components: - requiresCredentials - supportsIntegratedAuthentication - requiresConnectionTest - UmbracoInstaller: + InstallSettingsResponse: type: object properties: user: - $ref: '#/components/schemas/UmbracoInstallerUserModel' + $ref: '#/components/schemas/InstallUserModel' databases: type: array items: - $ref: '#/components/schemas/UmbracoInstallerDatabaseModel' + $ref: '#/components/schemas/InstallDatabaseModel' required: - user - databases - UmbracoPerformInstallDatabaseConfiguration: + ProblemDetails: + type: object + properties: + type: + type: string + status: + type: number + format: float + title: + type: string + detail: + type: string + instance: + type: string + errors: + type: object + required: + - type + - status + InstallSetupDatabaseConfiguration: type: object properties: server: @@ -256,7 +282,7 @@ components: connectionString: type: string nullable: true - UmbracoPerformInstallRequest: + InstallSetupRequest: type: object properties: name: @@ -270,7 +296,7 @@ components: telemetryLevel: $ref: '#/components/schemas/ConsentLevel' database: - $ref: '#/components/schemas/UmbracoPerformInstallDatabaseConfiguration' + $ref: '#/components/schemas/InstallSetupDatabaseConfiguration' required: - name - email @@ -278,25 +304,13 @@ components: - subscribeToNewsletter - telemetryLevel - database - ProblemDetails: + InstallValidateDatabaseRequest: type: object properties: - type: - type: string - status: - type: number - format: float - title: - type: string - detail: - type: string - instance: - type: string - errors: - type: object + database: + $ref: '#/components/schemas/InstallSetupDatabaseConfiguration' required: - - type - - status + - database StatusResponse: type: object properties: diff --git a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts index 4805a58150..583b8c8cf8 100644 --- a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts +++ b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts @@ -4,11 +4,13 @@ */ export interface paths { - "/install": { - get: operations["GetInstall"]; - post: operations["PostInstall"]; + "/install/settings": { + get: operations["GetInstallSettings"]; }; - "/install/database/validate": { + "/install/setup": { + post: operations["PostInstallSetup"]; + }; + "/install/validateDatabase": { post: operations["PostInstallValidateDatabase"]; }; "/server/status": { @@ -39,14 +41,14 @@ export interface components { level: components["schemas"]["ConsentLevel"]; description: string; }; - UmbracoInstallerUserModel: { + InstallUserModel: { /** Format: float */ minCharLength: number; /** Format: float */ minNonAlphaNumericLength: number; consentLevels: components["schemas"]["TelemetryModel"][]; }; - UmbracoInstallerDatabaseModel: { + InstallDatabaseModel: { id: string; /** Format: float */ sortOrder: number; @@ -60,26 +62,9 @@ export interface components { supportsIntegratedAuthentication: boolean; requiresConnectionTest: boolean; }; - UmbracoInstaller: { - user: components["schemas"]["UmbracoInstallerUserModel"]; - databases: components["schemas"]["UmbracoInstallerDatabaseModel"][]; - }; - UmbracoPerformInstallDatabaseConfiguration: { - server?: string | null; - password?: string | null; - username?: string | null; - databaseName?: string | null; - databaseType?: string | null; - useIntegratedAuthentication?: boolean | null; - connectionString?: string | null; - }; - UmbracoPerformInstallRequest: { - name: string; - email: string; - password: string; - subscribeToNewsletter: boolean; - telemetryLevel: components["schemas"]["ConsentLevel"]; - database: components["schemas"]["UmbracoPerformInstallDatabaseConfiguration"]; + InstallSettingsResponse: { + user: components["schemas"]["InstallUserModel"]; + databases: components["schemas"]["InstallDatabaseModel"][]; }; ProblemDetails: { type: string; @@ -90,6 +75,26 @@ export interface components { instance?: string; errors?: { [key: string]: unknown }; }; + InstallSetupDatabaseConfiguration: { + server?: string | null; + password?: string | null; + username?: string | null; + databaseName?: string | null; + databaseType?: string | null; + useIntegratedAuthentication?: boolean | null; + connectionString?: string | null; + }; + InstallSetupRequest: { + name: string; + email: string; + password: string; + subscribeToNewsletter: boolean; + telemetryLevel: components["schemas"]["ConsentLevel"]; + database: components["schemas"]["InstallSetupDatabaseConfiguration"]; + }; + InstallValidateDatabaseRequest: { + database: components["schemas"]["InstallSetupDatabaseConfiguration"]; + }; StatusResponse: { installed: boolean; }; @@ -112,17 +117,23 @@ export interface components { } export interface operations { - GetInstall: { + GetInstallSettings: { responses: { /** 200 response */ 200: { content: { - "application/json": components["schemas"]["UmbracoInstaller"]; + "application/json": components["schemas"]["InstallSettingsResponse"]; + }; + }; + /** default response */ + default: { + content: { + "application/json": components["schemas"]["ProblemDetails"]; }; }; }; }; - PostInstall: { + PostInstallSetup: { parameters: {}; responses: { /** 201 response */ @@ -136,7 +147,7 @@ export interface operations { }; requestBody: { content: { - "application/json": components["schemas"]["UmbracoPerformInstallRequest"]; + "application/json": components["schemas"]["InstallSetupRequest"]; }; }; }; @@ -154,7 +165,7 @@ export interface operations { }; requestBody: { content: { - "application/json": components["schemas"]["UmbracoPerformInstallDatabaseConfiguration"]; + "application/json": components["schemas"]["InstallValidateDatabaseRequest"]; }; }; }; diff --git a/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts b/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts index 4721e5a4e6..02aff8e69d 100644 --- a/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts +++ b/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts @@ -14,5 +14,6 @@ export const getUser = fetcher.path('/user').method('get').create(); export const postUserLogin = fetcher.path('/user/login').method('post').create(); export const postUserLogout = fetcher.path('/user/logout').method('post').create(); export const getUserSections = fetcher.path('/user/sections').method('get').create(); -export const getInstall = fetcher.path('/install').method('get').create(); -export const postInstall = fetcher.path('/install').method('post').create(); +export const getInstallSettings = fetcher.path('/install/settings').method('get').create(); +export const postInstallValidateDatabase = fetcher.path('/install/validateDatabase').method('post').create(); +export const postInstallSetup = fetcher.path('/install/setup').method('post').create(); diff --git a/src/Umbraco.Web.UI.Client/src/core/models/index.ts b/src/Umbraco.Web.UI.Client/src/core/models/index.ts index 682be78e8d..0ab6fe2ae3 100644 --- a/src/Umbraco.Web.UI.Client/src/core/models/index.ts +++ b/src/Umbraco.Web.UI.Client/src/core/models/index.ts @@ -1,19 +1,17 @@ import { components } from '../../../schemas/generated-schema'; -export type PostInstallRequest = components['schemas']['UmbracoPerformInstallRequest']; +export type PostInstallRequest = components['schemas']['InstallSetupRequest']; export type StatusResponse = components['schemas']['StatusResponse']; export type VersionResponse = components['schemas']['VersionResponse']; export type ProblemDetails = components['schemas']['ProblemDetails']; export type UserResponse = components['schemas']['UserResponse']; export type AllowedSectionsResponse = components['schemas']['AllowedSectionsResponse']; -export type UmbracoInstaller = components['schemas']['UmbracoInstaller']; -export type UmbracoPerformInstallRequest = components['schemas']['UmbracoPerformInstallRequest']; -export type UmbracoPerformInstallDatabaseConfiguration = - components['schemas']['UmbracoPerformInstallDatabaseConfiguration']; +export type UmbracoInstaller = components['schemas']['InstallSettingsResponse']; // Models -export type UmbracoInstallerDatabaseModel = components['schemas']['UmbracoInstallerDatabaseModel']; -export type UmbracoInstallerUserModel = components['schemas']['UmbracoInstallerUserModel']; +export type UmbracoPerformInstallDatabaseConfiguration = components['schemas']['InstallSetupDatabaseConfiguration']; +export type UmbracoInstallerDatabaseModel = components['schemas']['InstallDatabaseModel']; +export type UmbracoInstallerUserModel = components['schemas']['InstallUserModel']; export type TelemetryModel = components['schemas']['TelemetryModel']; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/Umbraco.Web.UI.Client/src/installer/installer-context.ts b/src/Umbraco.Web.UI.Client/src/installer/installer-context.ts index 73aeee01fd..fa94721ad9 100644 --- a/src/Umbraco.Web.UI.Client/src/installer/installer-context.ts +++ b/src/Umbraco.Web.UI.Client/src/installer/installer-context.ts @@ -1,7 +1,8 @@ -import { getInstall, postInstall } from '../core/api/fetcher'; -import { PostInstallRequest, UmbracoInstaller } from '../core/models'; import { BehaviorSubject, Observable, ReplaySubject, Subject } from 'rxjs'; +import { getInstallSettings, postInstallSetup } from '../core/api/fetcher'; +import { PostInstallRequest, UmbracoInstaller } from '../core/models'; + export class UmbInstallerContext { private _data: BehaviorSubject = new BehaviorSubject({ name: '', @@ -30,14 +31,14 @@ export class UmbInstallerContext { public requestInstall() { return new Promise((resolve, reject) => { - postInstall(this._data.getValue()).then(resolve, ({ data }) => { + postInstallSetup(this._data.getValue()).then(resolve, ({ data }) => { reject(data); }); }); } private loadIntallerSettings() { - getInstall({}).then(({ data }) => { + getInstallSettings({}).then(({ data }) => { this._settings.next(data); }); } diff --git a/src/Umbraco.Web.UI.Client/src/mocks/domains/install.handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/domains/install.handlers.ts index d7da2055f8..2f656c49ae 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/domains/install.handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/domains/install.handlers.ts @@ -1,9 +1,9 @@ import { rest } from 'msw'; -import { ProblemDetails, UmbracoInstaller, UmbracoPerformInstallRequest } from '../../core/models'; +import { PostInstallRequest, ProblemDetails, UmbracoInstaller } from '../../core/models'; export const handlers = [ - rest.get('/umbraco/backoffice/install', (_req, res, ctx) => { + rest.get('/umbraco/backoffice/install/settings', (_req, res, ctx) => { return res( // Respond with a 200 status code ctx.status(200), @@ -72,7 +72,7 @@ export const handlers = [ ); }), - rest.post('/umbraco/backoffice/install', async (req, res, ctx) => { + rest.post('/umbraco/backoffice/install/setup', async (req, res, ctx) => { await new Promise((resolve) => setTimeout(resolve, (Math.random() + 1) * 1000)); // simulate a delay of 1-2 seconds if (req.body.database.databaseName === 'fail') { diff --git a/src/Umbraco.Web.UI.Client/temp-schema-generator/installer.ts b/src/Umbraco.Web.UI.Client/temp-schema-generator/installer.ts index 70bd9747ad..9dead39dc3 100644 --- a/src/Umbraco.Web.UI.Client/temp-schema-generator/installer.ts +++ b/src/Umbraco.Web.UI.Client/temp-schema-generator/installer.ts @@ -1,23 +1,26 @@ -import { body, endpoint, request, response } from '@airtasker/spot'; +import { body, defaultResponse, endpoint, request, response } from '@airtasker/spot'; import { ProblemDetails } from './models'; @endpoint({ method: 'GET', - path: '/install', + path: '/install/settings', }) -export class GetInstall { +export class GetInstallSettings { @response({ status: 200 }) - success(@body body: UmbracoInstaller) {} + success(@body body: InstallSettingsResponse) {} + + @defaultResponse + default(@body body: ProblemDetails) {} } @endpoint({ method: 'POST', - path: '/install', + path: '/install/setup', }) -export class PostInstall { +export class PostInstallSetup { @request - request(@body body: UmbracoPerformInstallRequest) {} + request(@body body: InstallSetupRequest) {} @response({ status: 201 }) success() {} @@ -28,11 +31,11 @@ export class PostInstall { @endpoint({ method: 'POST', - path: '/install/database/validate', + path: '/install/validateDatabase', }) export class PostInstallValidateDatabase { @request - request(@body body: UmbracoPerformInstallDatabaseConfiguration) {} + request(@body body: InstallValidateDatabaseRequest) {} @response({ status: 201 }) success() {} @@ -41,16 +44,31 @@ export class PostInstallValidateDatabase { badRequest(@body body: ProblemDetails) {} } -export interface UmbracoPerformInstallRequest { +export interface InstallSetupRequest { name: string; email: string; password: string; subscribeToNewsletter: boolean; telemetryLevel: ConsentLevel; - database: UmbracoPerformInstallDatabaseConfiguration; + database: InstallSetupDatabaseConfiguration; } -export interface UmbracoPerformInstallDatabaseConfiguration { +export interface InstallValidateDatabaseRequest { + database: InstallSetupDatabaseConfiguration; +} + +export interface InstallSettingsResponse { + user: InstallUserModel; + databases: InstallDatabaseModel[]; +} + +export interface InstallUserModel { + minCharLength: number; + minNonAlphaNumericLength: number; + consentLevels: TelemetryModel[]; +} + +export interface InstallSetupDatabaseConfiguration { server?: string | null; password?: string | null; username?: string | null; @@ -60,23 +78,12 @@ export interface UmbracoPerformInstallDatabaseConfiguration { connectionString?: string | null; } -export interface UmbracoInstaller { - user: UmbracoInstallerUserModel; - databases: UmbracoInstallerDatabaseModel[]; -} - -export interface UmbracoInstallerUserModel { - minCharLength: number; - minNonAlphaNumericLength: number; - consentLevels: TelemetryModel[]; -} - export interface TelemetryModel { level: ConsentLevel; description: string; } -export interface UmbracoInstallerDatabaseModel { +export interface InstallDatabaseModel { id: string; sortOrder: number; displayName: string;