From 1063a60814d933d7a37595460f6d3836a3639814 Mon Sep 17 00:00:00 2001 From: Ben Ramey Date: Wed, 15 May 2024 19:51:12 -0500 Subject: [PATCH] Commit changes --- .../src/lib/oap/oapApiV1Client.ts | 388 +++++++----------- .../src/lib/oap/oapApiV1ClientTypes.ts | 244 +++++------ 2 files changed, 279 insertions(+), 353 deletions(-) diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1Client.ts b/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1Client.ts index 2333d1f..0e0710b 100644 --- a/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1Client.ts +++ b/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1Client.ts @@ -1,231 +1,157 @@ -// DO NOT EDIT: generated by fsdgenjs - -import { - HttpClientUtility, - type IServiceResult, - type IHttpClientOptions, -} from "facility-core"; -import type { - IOapApiV1Client, - IGetApplicationsRequest, - IGetApplicationsResponse, - ICreateApplicationRequest, - ICreateApplicationResponse, - IGetApplicationRequest, - IGetApplicationResponse, - IUpdateApplicationRequest, - IUpdateApplicationResponse, - IApplication, - IApplicationCreateSet, - IApplicationChangeSet, - IApplicationTermsCreateSet, - IApplicationTerms, - ApplicationStatus, -} from "./oapApiV1ClientTypes"; -export * from "./oapApiV1ClientTypes"; - -/** Provides access to OapApiV1Client over HTTP via fetch. */ -export function createHttpClient({ - fetch, - baseUri, -}: IHttpClientOptions): IOapApiV1Client { - return new OapApiV1ClientHttpClient(fetch, baseUri); -} - -const { fetchResponse, createResponseError, createRequiredRequestFieldError } = - HttpClientUtility; -type IFetch = HttpClientUtility.IFetch; -type IFetchRequest = HttpClientUtility.IFetchRequest; - -class OapApiV1ClientHttpClient implements IOapApiV1Client { - constructor(fetch: IFetch, baseUri?: string) { - if (typeof fetch !== "function") { - throw new TypeError("fetch must be a function."); - } - if (typeof baseUri === "undefined") { - baseUri = "https://oaprotection.org/api/v1"; - } - if (/[^\/]$/.test(baseUri)) { - baseUri += "/"; - } - this._fetch = fetch; - this._baseUri = baseUri; - } - - /** Gets applications for the current user. */ - public getApplications( - request: IGetApplicationsRequest, - context?: unknown - ): Promise> { - let uri = "applications"; - const query: string[] = []; - request.status == null || query.push("status=" + request.status); - request.limit == null || - query.push("limit=" + request.limit.toString()); - request.nextToken == null || - query.push("nextToken=" + encodeURIComponent(request.nextToken)); - if (query.length) { - uri = uri + "?" + query.join("&"); - } - const fetchRequest: IFetchRequest = { - method: "GET", - }; - return fetchResponse( - this._fetch, - this._baseUri + uri, - fetchRequest, - context - ).then((result) => { - const status = result.response.status; - let value: IGetApplicationsResponse | null = null; - if (status === 200) { - if (result.json) { - value = result.json as IGetApplicationsResponse | null; - } - } - if (!value) { - return createResponseError( - status, - result.json - ) as IServiceResult; - } - return { value: value }; - }); - } - - /** Creates a new application for the current user. */ - public createApplication( - request: ICreateApplicationRequest, - context?: unknown - ): Promise> { - const uri = "applications/"; - if (!request.applicationCreateSet) { - return Promise.resolve( - createRequiredRequestFieldError("applicationCreateSet") - ); - } - const fetchRequest: IFetchRequest = { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(request.applicationCreateSet), - }; - return fetchResponse( - this._fetch, - this._baseUri + uri, - fetchRequest, - context - ).then((result) => { - const status = result.response.status; - let value: ICreateApplicationResponse | null = null; - if (status === 200) { - if (result.json) { - value = { - application: result.json, - } as ICreateApplicationResponse; - } - } else if (status === 201) { - value = {}; - } - if (!value) { - return createResponseError( - status, - result.json - ) as IServiceResult; - } - return { value: value }; - }); - } - - /** Gets the specified application for the current user. */ - public getApplication( - request: IGetApplicationRequest, - context?: unknown - ): Promise> { - const uriPartId = request.id != null && encodeURIComponent(request.id); - if (!uriPartId) { - return Promise.resolve(createRequiredRequestFieldError("id")); - } - const uri = `applications/${uriPartId}`; - const fetchRequest: IFetchRequest = { - method: "GET", - }; - return fetchResponse( - this._fetch, - this._baseUri + uri, - fetchRequest, - context - ).then((result) => { - const status = result.response.status; - let value: IGetApplicationResponse | null = null; - if (status === 200) { - if (result.json) { - value = { - application: result.json, - } as IGetApplicationResponse; - } - } else if (status === 304) { - value = { notModified: true }; - } - if (!value) { - return createResponseError( - status, - result.json - ) as IServiceResult; - } - let headerValue: string | null | undefined; - headerValue = result.response.headers.get("eTag"); - if (headerValue != null) { - value.eTag = headerValue; - } - return { value: value }; - }); - } - - /** Updates the application. */ - public updateApplication( - request: IUpdateApplicationRequest, - context?: unknown - ): Promise> { - const uriPartId = request.id != null && encodeURIComponent(request.id); - if (!uriPartId) { - return Promise.resolve(createRequiredRequestFieldError("id")); - } - const uri = `applications/${uriPartId}`; - if (!request.applicationChangeSet) { - return Promise.resolve( - createRequiredRequestFieldError("applicationChangeSet") - ); - } - const fetchRequest: IFetchRequest = { - method: "PATCH", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(request.applicationChangeSet), - }; - return fetchResponse( - this._fetch, - this._baseUri + uri, - fetchRequest, - context - ).then((result) => { - const status = result.response.status; - let value: IUpdateApplicationResponse | null = null; - if (status === 200) { - if (result.json) { - value = { - application: result.json, - } as IUpdateApplicationResponse; - } - } - if (!value) { - return createResponseError( - status, - result.json - ) as IServiceResult; - } - return { value: value }; - }); - } - - private _fetch: IFetch; - private _baseUri: string; -} +// DO NOT EDIT: generated by fsdgenjs + +import { HttpClientUtility, IServiceResult, IHttpClientOptions } from 'facility-core'; +import { IOapApiV1Client, IGetApplicationsRequest, IGetApplicationsResponse, ICreateApplicationRequest, ICreateApplicationResponse, IGetApplicationRequest, IGetApplicationResponse, IUpdateApplicationRequest, IUpdateApplicationResponse, IApplication, IApplicationCreateSet, IApplicationChangeSet, IApplicationTermsCreateSet, IApplicationTerms, ApplicationStatus } from './oapApiV1ClientTypes'; +export * from './oapApiV1ClientTypes'; + +/** Provides access to OapApiV1Client over HTTP via fetch. */ +export function createHttpClient({ fetch, baseUri }: IHttpClientOptions): IOapApiV1Client { + return new OapApiV1ClientHttpClient(fetch, baseUri); +} + +const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility; +type IFetch = HttpClientUtility.IFetch; +type IFetchRequest = HttpClientUtility.IFetchRequest; + +class OapApiV1ClientHttpClient implements IOapApiV1Client { + constructor(fetch: IFetch, baseUri?: string) { + if (typeof fetch !== 'function') { + throw new TypeError('fetch must be a function.'); + } + if (typeof baseUri === 'undefined') { + baseUri = 'https://oaprotection.org/api/v1'; + } + if (/[^\/]$/.test(baseUri)) { + baseUri += '/'; + } + this._fetch = fetch; + this._baseUri = baseUri; + } + + /** Gets applications for the current user. */ + public getApplications(request: IGetApplicationsRequest, context?: unknown): Promise> { + let uri = 'applications'; + const query: string[] = []; + request.status == null || query.push('status=' + request.status); + request.limit == null || query.push('limit=' + request.limit.toString()); + request.nextToken == null || query.push('nextToken=' + encodeURIComponent(request.nextToken)); + if (query.length) { + uri = uri + '?' + query.join('&'); + } + const fetchRequest: IFetchRequest = { + method: 'GET', + }; + return fetchResponse(this._fetch, this._baseUri + uri, fetchRequest, context) + .then(result => { + const status = result.response.status; + let value: IGetApplicationsResponse | null = null; + if (status === 200) { + if (result.json) { + value = result.json as IGetApplicationsResponse | null; + } + } + if (!value) { + return createResponseError(status, result.json) as IServiceResult; + } + return { value: value }; + }); + } + + /** Creates a new application for the current user. */ + public createApplication(request: ICreateApplicationRequest, context?: unknown): Promise> { + const uri = 'applications/'; + if (!request.applicationCreateSet) { + return Promise.resolve(createRequiredRequestFieldError('applicationCreateSet')); + } + const fetchRequest: IFetchRequest = { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(request.applicationCreateSet) + }; + return fetchResponse(this._fetch, this._baseUri + uri, fetchRequest, context) + .then(result => { + const status = result.response.status; + let value: ICreateApplicationResponse | null = null; + if (status === 200) { + if (result.json) { + value = { application: result.json } as ICreateApplicationResponse; + } + } + else if (status === 201) { + value = {}; + } + if (!value) { + return createResponseError(status, result.json) as IServiceResult; + } + return { value: value }; + }); + } + + /** Gets the specified application for the current user. */ + public getApplication(request: IGetApplicationRequest, context?: unknown): Promise> { + const uriPartId = request.id != null && encodeURIComponent(request.id); + if (!uriPartId) { + return Promise.resolve(createRequiredRequestFieldError('id')); + } + const uri = `applications/${uriPartId}`; + const fetchRequest: IFetchRequest = { + method: 'GET', + }; + return fetchResponse(this._fetch, this._baseUri + uri, fetchRequest, context) + .then(result => { + const status = result.response.status; + let value: IGetApplicationResponse | null = null; + if (status === 200) { + if (result.json) { + value = { application: result.json } as IGetApplicationResponse; + } + } + else if (status === 304) { + value = { notModified: true }; + } + if (!value) { + return createResponseError(status, result.json) as IServiceResult; + } + let headerValue: string | null | undefined; + headerValue = result.response.headers.get('eTag'); + if (headerValue != null) { + value.eTag = headerValue; + } + return { value: value }; + }); + } + + /** Updates the application. */ + public updateApplication(request: IUpdateApplicationRequest, context?: unknown): Promise> { + const uriPartId = request.id != null && encodeURIComponent(request.id); + if (!uriPartId) { + return Promise.resolve(createRequiredRequestFieldError('id')); + } + const uri = `applications/${uriPartId}`; + if (!request.applicationChangeSet) { + return Promise.resolve(createRequiredRequestFieldError('applicationChangeSet')); + } + const fetchRequest: IFetchRequest = { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(request.applicationChangeSet) + }; + return fetchResponse(this._fetch, this._baseUri + uri, fetchRequest, context) + .then(result => { + const status = result.response.status; + let value: IUpdateApplicationResponse | null = null; + if (status === 200) { + if (result.json) { + value = { application: result.json } as IUpdateApplicationResponse; + } + } + if (!value) { + return createResponseError(status, result.json) as IServiceResult; + } + return { value: value }; + }); + } + + private _fetch: IFetch; + private _baseUri: string; +} diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1ClientTypes.ts b/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1ClientTypes.ts index b409ed2..cc80376 100644 --- a/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1ClientTypes.ts +++ b/src/OAP/Oap.Theme.Svelte/src/lib/oap/oapApiV1ClientTypes.ts @@ -1,122 +1,122 @@ -// DO NOT EDIT: generated by fsdgenjs - -import { IServiceResult } from 'facility-core'; - -export interface IOapApiV1Client { - /** Gets applications for the current user. */ - getApplications(request: IGetApplicationsRequest, context?: unknown): Promise>; - - /** Creates a new application for the current user. */ - createApplication(request: ICreateApplicationRequest, context?: unknown): Promise>; - - /** Gets the specified application for the current user. */ - getApplication(request: IGetApplicationRequest, context?: unknown): Promise>; - - /** Updates the application. */ - updateApplication(request: IUpdateApplicationRequest, context?: unknown): Promise>; -} - -/** Request for GetApplications. */ -export interface IGetApplicationsRequest { - /** Filter applications by the given status. */ - status?: ApplicationStatus; - - /** The limit of returned results. */ - limit?: number; - - /** The token presenting the next page of applications to get. */ - nextToken?: string; -} - -/** Response for GetApplications. */ -export interface IGetApplicationsResponse { - /** The applications. */ - applications?: IApplication[]; - - /** The total number of applications. */ - total?: number; - - /** The token representing the next page of results. */ - nextToken?: string; - - /** True if this is the last page of results, false otherwise. */ - isLastPage?: boolean; -} - -/** Request for CreateApplication. */ -export interface ICreateApplicationRequest { - /** The application to create. */ - applicationCreateSet?: IApplicationCreateSet; -} - -/** Response for CreateApplication. */ -export interface ICreateApplicationResponse { - /** The created application. */ - application?: IApplication; -} - -/** Request for GetApplication. */ -export interface IGetApplicationRequest { - /** The widget ID. */ - id?: string; -} - -/** Response for GetApplication. */ -export interface IGetApplicationResponse { - /** The requested widget. */ - application?: IApplication; - - eTag?: string; - - notModified?: boolean; -} - -/** Request for UpdateApplication. */ -export interface IUpdateApplicationRequest { - /** The application ID. */ - id?: string; - - /** The application update set. */ - applicationChangeSet?: IApplicationChangeSet; -} - -/** Response for UpdateApplication. */ -export interface IUpdateApplicationResponse { - /** The updated Application. */ - application?: IApplication; -} - -/** An application. */ -export interface IApplication { - /** A unique identifier for the application. */ - id?: string; - - /** The current status of this application. */ - status?: ApplicationStatus; - - /** Terms the user must accept to start, continue an accept an application. */ - terms?: IApplicationTerms; -} - -export interface IApplicationCreateSet { - /** Terms a user must accept to start an application. */ - terms?: IApplicationTermsCreateSet; -} - -export interface IApplicationChangeSet { -} - -export interface IApplicationTermsCreateSet { - hasReadInstructions?: boolean; -} - -export interface IApplicationTerms { - hasReadInstructions?: boolean; -} - -export enum ApplicationStatus { - InProgress = 'InProgress', - - Submitted = 'Submitted', -} - +// DO NOT EDIT: generated by fsdgenjs + +import { IServiceResult } from 'facility-core'; + +export interface IOapApiV1Client { + /** Gets applications for the current user. */ + getApplications(request: IGetApplicationsRequest, context?: unknown): Promise>; + + /** Creates a new application for the current user. */ + createApplication(request: ICreateApplicationRequest, context?: unknown): Promise>; + + /** Gets the specified application for the current user. */ + getApplication(request: IGetApplicationRequest, context?: unknown): Promise>; + + /** Updates the application. */ + updateApplication(request: IUpdateApplicationRequest, context?: unknown): Promise>; +} + +/** Request for GetApplications. */ +export interface IGetApplicationsRequest { + /** Filter applications by the given status. */ + status?: ApplicationStatus; + + /** The limit of returned results. */ + limit?: number; + + /** The token presenting the next page of applications to get. */ + nextToken?: string; +} + +/** Response for GetApplications. */ +export interface IGetApplicationsResponse { + /** The applications. */ + applications?: IApplication[]; + + /** The total number of applications. */ + total?: number; + + /** The token representing the next page of results. */ + nextToken?: string; + + /** True if this is the last page of results, false otherwise. */ + isLastPage?: boolean; +} + +/** Request for CreateApplication. */ +export interface ICreateApplicationRequest { + /** The application to create. */ + applicationCreateSet?: IApplicationCreateSet; +} + +/** Response for CreateApplication. */ +export interface ICreateApplicationResponse { + /** The created application. */ + application?: IApplication; +} + +/** Request for GetApplication. */ +export interface IGetApplicationRequest { + /** The widget ID. */ + id?: string; +} + +/** Response for GetApplication. */ +export interface IGetApplicationResponse { + /** The requested widget. */ + application?: IApplication; + + eTag?: string; + + notModified?: boolean; +} + +/** Request for UpdateApplication. */ +export interface IUpdateApplicationRequest { + /** The application ID. */ + id?: string; + + /** The application update set. */ + applicationChangeSet?: IApplicationChangeSet; +} + +/** Response for UpdateApplication. */ +export interface IUpdateApplicationResponse { + /** The updated Application. */ + application?: IApplication; +} + +/** An application. */ +export interface IApplication { + /** A unique identifier for the application. */ + id?: string; + + /** The current status of this application. */ + status?: ApplicationStatus; + + /** Terms the user must accept to start, continue an accept an application. */ + terms?: IApplicationTerms; +} + +export interface IApplicationCreateSet { + /** Terms a user must accept to start an application. */ + terms?: IApplicationTermsCreateSet; +} + +export interface IApplicationChangeSet { +} + +export interface IApplicationTermsCreateSet { + hasReadInstructions?: boolean; +} + +export interface IApplicationTerms { + hasReadInstructions?: boolean; +} + +export enum ApplicationStatus { + InProgress = 'InProgress', + + Submitted = 'Submitted', +} +