From 2aca269b8be85e62827d732f021927c4e1b36592 Mon Sep 17 00:00:00 2001 From: Romain Le Cellier Date: Tue, 7 Feb 2023 16:41:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F(chore):=20generate=20joan?= =?UTF-8?q?ie=20api=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/index.ts | 27 ++ .../js/api/joanie/gen/ApiClientJoanie.ts | 58 ++++ .../js/api/joanie/gen/core/ApiError.ts | 24 ++ .../api/joanie/gen/core/ApiRequestOptions.ts | 16 + .../js/api/joanie/gen/core/ApiResult.ts | 10 + .../js/api/joanie/gen/core/BaseHttpRequest.ts | 13 + .../api/joanie/gen/core/CancelablePromise.ts | 128 +++++++ .../api/joanie/gen/core/FetchHttpRequest.ts | 25 ++ .../js/api/joanie/gen/core/OpenAPI.ts | 31 ++ .../js/api/joanie/gen/core/request.ts | 315 ++++++++++++++++++ src/frontend/js/api/joanie/gen/index.ts | 30 ++ .../js/api/joanie/gen/models/Address.ts | 273 +++++++++++++++ .../js/api/joanie/gen/models/Certificate.ts | 8 + .../gen/models/CertificationDefinition.ts | 10 + .../js/api/joanie/gen/models/Course.ts | 9 + .../js/api/joanie/gen/models/CourseRun.ts | 21 ++ .../js/api/joanie/gen/models/CreditCard.ts | 14 + .../js/api/joanie/gen/models/Enrollment.ts | 31 ++ .../js/api/joanie/gen/models/Order.ts | 35 ++ .../js/api/joanie/gen/models/Product.ts | 29 ++ .../joanie/gen/services/AddressesService.ts | 286 ++++++++++++++++ .../gen/services/CertificatesService.ts | 75 +++++ .../joanie/gen/services/CourseRunsService.ts | 35 ++ .../gen/services/CourseRunsSyncService.ts | 34 ++ .../joanie/gen/services/CreditCardsService.ts | 157 +++++++++ .../joanie/gen/services/EnrollmentsService.ts | 126 +++++++ .../api/joanie/gen/services/OrdersService.ts | 143 ++++++++ .../joanie/gen/services/PaymentsService.ts | 24 ++ .../joanie/gen/services/ProductsService.ts | 35 ++ src/frontend/js/api/joanie/index.ts | 29 ++ 30 files changed, 2051 insertions(+) create mode 100644 src/frontend/index.ts create mode 100644 src/frontend/js/api/joanie/gen/ApiClientJoanie.ts create mode 100644 src/frontend/js/api/joanie/gen/core/ApiError.ts create mode 100644 src/frontend/js/api/joanie/gen/core/ApiRequestOptions.ts create mode 100644 src/frontend/js/api/joanie/gen/core/ApiResult.ts create mode 100644 src/frontend/js/api/joanie/gen/core/BaseHttpRequest.ts create mode 100644 src/frontend/js/api/joanie/gen/core/CancelablePromise.ts create mode 100644 src/frontend/js/api/joanie/gen/core/FetchHttpRequest.ts create mode 100644 src/frontend/js/api/joanie/gen/core/OpenAPI.ts create mode 100644 src/frontend/js/api/joanie/gen/core/request.ts create mode 100644 src/frontend/js/api/joanie/gen/index.ts create mode 100644 src/frontend/js/api/joanie/gen/models/Address.ts create mode 100644 src/frontend/js/api/joanie/gen/models/Certificate.ts create mode 100644 src/frontend/js/api/joanie/gen/models/CertificationDefinition.ts create mode 100644 src/frontend/js/api/joanie/gen/models/Course.ts create mode 100644 src/frontend/js/api/joanie/gen/models/CourseRun.ts create mode 100644 src/frontend/js/api/joanie/gen/models/CreditCard.ts create mode 100644 src/frontend/js/api/joanie/gen/models/Enrollment.ts create mode 100644 src/frontend/js/api/joanie/gen/models/Order.ts create mode 100644 src/frontend/js/api/joanie/gen/models/Product.ts create mode 100644 src/frontend/js/api/joanie/gen/services/AddressesService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/CertificatesService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/CourseRunsService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/CourseRunsSyncService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/CreditCardsService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/EnrollmentsService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/OrdersService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/PaymentsService.ts create mode 100644 src/frontend/js/api/joanie/gen/services/ProductsService.ts create mode 100644 src/frontend/js/api/joanie/index.ts diff --git a/src/frontend/index.ts b/src/frontend/index.ts new file mode 100644 index 0000000000..b0c2152236 --- /dev/null +++ b/src/frontend/index.ts @@ -0,0 +1,27 @@ +import context from 'utils/context'; +import { AppClient, OpenAPIConfig } from './v1' +import { JOANIE_API_VERSION } from 'settings'; + +/** + * Build Joanie API Routes interface. + */ +const getAPIEndpoint = () => { + const endpoint = context?.joanie_backend?.endpoint; + const version = JOANIE_API_VERSION; + + if (!endpoint) { + throw new Error('[JOANIE] - Joanie API endpoint is not defined.'); + } + + return `${endpoint}/api/${version}`; + }; + + +const config: OpenAPIConfig = { + BASE: getAPIEndpoint(), + VERSION: '1', + WITH_CREDENTIALS: true, + CREDENTIALS: 'include', +} + +export const api = new AppClient(config).default \ No newline at end of file diff --git a/src/frontend/js/api/joanie/gen/ApiClientJoanie.ts b/src/frontend/js/api/joanie/gen/ApiClientJoanie.ts new file mode 100644 index 0000000000..d9a5a693ab --- /dev/null +++ b/src/frontend/js/api/joanie/gen/ApiClientJoanie.ts @@ -0,0 +1,58 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { BaseHttpRequest } from './core/BaseHttpRequest'; +import type { OpenAPIConfig } from './core/OpenAPI'; +import { FetchHttpRequest } from './core/FetchHttpRequest'; + +import { AddressesService } from './services/AddressesService'; +import { CertificatesService } from './services/CertificatesService'; +import { CourseRunsService } from './services/CourseRunsService'; +import { CourseRunsSyncService } from './services/CourseRunsSyncService'; +import { CreditCardsService } from './services/CreditCardsService'; +import { EnrollmentsService } from './services/EnrollmentsService'; +import { OrdersService } from './services/OrdersService'; +import { PaymentsService } from './services/PaymentsService'; +import { ProductsService } from './services/ProductsService'; + +type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest; + +export class ApiClientJoanie { + + public readonly addresses: AddressesService; + public readonly certificates: CertificatesService; + public readonly courseRuns: CourseRunsService; + public readonly courseRunsSync: CourseRunsSyncService; + public readonly creditCards: CreditCardsService; + public readonly enrollments: EnrollmentsService; + public readonly orders: OrdersService; + public readonly payments: PaymentsService; + public readonly products: ProductsService; + + public readonly request: BaseHttpRequest; + + constructor(config?: Partial, HttpRequest: HttpRequestConstructor = FetchHttpRequest) { + this.request = new HttpRequest({ + BASE: config?.BASE ?? 'http://localhost:8071/api/v1.0', + VERSION: config?.VERSION ?? '1.0', + WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false, + CREDENTIALS: config?.CREDENTIALS ?? 'include', + TOKEN: config?.TOKEN, + USERNAME: config?.USERNAME, + PASSWORD: config?.PASSWORD, + HEADERS: config?.HEADERS, + ENCODE_PATH: config?.ENCODE_PATH, + }); + + this.addresses = new AddressesService(this.request); + this.certificates = new CertificatesService(this.request); + this.courseRuns = new CourseRunsService(this.request); + this.courseRunsSync = new CourseRunsSyncService(this.request); + this.creditCards = new CreditCardsService(this.request); + this.enrollments = new EnrollmentsService(this.request); + this.orders = new OrdersService(this.request); + this.payments = new PaymentsService(this.request); + this.products = new ProductsService(this.request); + } +} + diff --git a/src/frontend/js/api/joanie/gen/core/ApiError.ts b/src/frontend/js/api/joanie/gen/core/ApiError.ts new file mode 100644 index 0000000000..41a9605a3a --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/ApiError.ts @@ -0,0 +1,24 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; + +export class ApiError extends Error { + public readonly url: string; + public readonly status: number; + public readonly statusText: string; + public readonly body: any; + public readonly request: ApiRequestOptions; + + constructor(request: ApiRequestOptions, response: ApiResult, message: string) { + super(message); + + this.name = 'ApiError'; + this.url = response.url; + this.status = response.status; + this.statusText = response.statusText; + this.body = response.body; + this.request = request; + } +} diff --git a/src/frontend/js/api/joanie/gen/core/ApiRequestOptions.ts b/src/frontend/js/api/joanie/gen/core/ApiRequestOptions.ts new file mode 100644 index 0000000000..c9350406a1 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/ApiRequestOptions.ts @@ -0,0 +1,16 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ApiRequestOptions = { + readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; + readonly url: string; + readonly path?: Record; + readonly cookies?: Record; + readonly headers?: Record; + readonly query?: Record; + readonly formData?: Record; + readonly body?: any; + readonly mediaType?: string; + readonly responseHeader?: string; + readonly errors?: Record; +}; diff --git a/src/frontend/js/api/joanie/gen/core/ApiResult.ts b/src/frontend/js/api/joanie/gen/core/ApiResult.ts new file mode 100644 index 0000000000..91f60ae082 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/ApiResult.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ApiResult = { + readonly url: string; + readonly ok: boolean; + readonly status: number; + readonly statusText: string; + readonly body: any; +}; diff --git a/src/frontend/js/api/joanie/gen/core/BaseHttpRequest.ts b/src/frontend/js/api/joanie/gen/core/BaseHttpRequest.ts new file mode 100644 index 0000000000..489f1d10bf --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/BaseHttpRequest.ts @@ -0,0 +1,13 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { CancelablePromise } from './CancelablePromise'; +import type { OpenAPIConfig } from './OpenAPI'; + +export abstract class BaseHttpRequest { + + constructor(public readonly config: OpenAPIConfig) {} + + public abstract request(options: ApiRequestOptions): CancelablePromise; +} diff --git a/src/frontend/js/api/joanie/gen/core/CancelablePromise.ts b/src/frontend/js/api/joanie/gen/core/CancelablePromise.ts new file mode 100644 index 0000000000..b923479fea --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/CancelablePromise.ts @@ -0,0 +1,128 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export class CancelError extends Error { + + constructor(message: string) { + super(message); + this.name = 'CancelError'; + } + + public get isCancelled(): boolean { + return true; + } +} + +export interface OnCancel { + readonly isResolved: boolean; + readonly isRejected: boolean; + readonly isCancelled: boolean; + + (cancelHandler: () => void): void; +} + +export class CancelablePromise implements Promise { + readonly [Symbol.toStringTag]!: string; + + private _isResolved: boolean; + private _isRejected: boolean; + private _isCancelled: boolean; + private readonly _cancelHandlers: (() => void)[]; + private readonly _promise: Promise; + private _resolve?: (value: T | PromiseLike) => void; + private _reject?: (reason?: any) => void; + + constructor( + executor: ( + resolve: (value: T | PromiseLike) => void, + reject: (reason?: any) => void, + onCancel: OnCancel + ) => void + ) { + this._isResolved = false; + this._isRejected = false; + this._isCancelled = false; + this._cancelHandlers = []; + this._promise = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + + const onResolve = (value: T | PromiseLike): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isResolved = true; + this._resolve?.(value); + }; + + const onReject = (reason?: any): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isRejected = true; + this._reject?.(reason); + }; + + const onCancel = (cancelHandler: () => void): void => { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._cancelHandlers.push(cancelHandler); + }; + + Object.defineProperty(onCancel, 'isResolved', { + get: (): boolean => this._isResolved, + }); + + Object.defineProperty(onCancel, 'isRejected', { + get: (): boolean => this._isRejected, + }); + + Object.defineProperty(onCancel, 'isCancelled', { + get: (): boolean => this._isCancelled, + }); + + return executor(onResolve, onReject, onCancel as OnCancel); + }); + } + + public then( + onFulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onRejected?: ((reason: any) => TResult2 | PromiseLike) | null + ): Promise { + return this._promise.then(onFulfilled, onRejected); + } + + public catch( + onRejected?: ((reason: any) => TResult | PromiseLike) | null + ): Promise { + return this._promise.catch(onRejected); + } + + public finally(onFinally?: (() => void) | null): Promise { + return this._promise.finally(onFinally); + } + + public cancel(): void { + if (this._isResolved || this._isRejected || this._isCancelled) { + return; + } + this._isCancelled = true; + if (this._cancelHandlers.length) { + try { + for (const cancelHandler of this._cancelHandlers) { + cancelHandler(); + } + } catch (error) { + console.warn('Cancellation threw an error', error); + return; + } + } + this._cancelHandlers.length = 0; + this._reject?.(new CancelError('Request aborted')); + } + + public get isCancelled(): boolean { + return this._isCancelled; + } +} diff --git a/src/frontend/js/api/joanie/gen/core/FetchHttpRequest.ts b/src/frontend/js/api/joanie/gen/core/FetchHttpRequest.ts new file mode 100644 index 0000000000..9444c54b8c --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/FetchHttpRequest.ts @@ -0,0 +1,25 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; +import { BaseHttpRequest } from './BaseHttpRequest'; +import type { CancelablePromise } from './CancelablePromise'; +import type { OpenAPIConfig } from './OpenAPI'; +import { request as __request } from './request'; + +export class FetchHttpRequest extends BaseHttpRequest { + + constructor(config: OpenAPIConfig) { + super(config); + } + + /** + * Request method + * @param options The request options from the service + * @returns CancelablePromise + * @throws ApiError + */ + public override request(options: ApiRequestOptions): CancelablePromise { + return __request(this.config, options); + } +} diff --git a/src/frontend/js/api/joanie/gen/core/OpenAPI.ts b/src/frontend/js/api/joanie/gen/core/OpenAPI.ts new file mode 100644 index 0000000000..b4b0bfbb3e --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/OpenAPI.ts @@ -0,0 +1,31 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { ApiRequestOptions } from './ApiRequestOptions'; + +type Resolver = (options: ApiRequestOptions) => Promise; +type Headers = Record; + +export type OpenAPIConfig = { + BASE: string; + VERSION: string; + WITH_CREDENTIALS: boolean; + CREDENTIALS: 'include' | 'omit' | 'same-origin'; + TOKEN?: string | Resolver; + USERNAME?: string | Resolver; + PASSWORD?: string | Resolver; + HEADERS?: Headers | Resolver; + ENCODE_PATH?: (path: string) => string; +}; + +export const OpenAPI: OpenAPIConfig = { + BASE: 'http://localhost:8071/api/v1.0', + VERSION: '1.0', + WITH_CREDENTIALS: false, + CREDENTIALS: 'include', + TOKEN: undefined, + USERNAME: undefined, + PASSWORD: undefined, + HEADERS: undefined, + ENCODE_PATH: undefined, +}; diff --git a/src/frontend/js/api/joanie/gen/core/request.ts b/src/frontend/js/api/joanie/gen/core/request.ts new file mode 100644 index 0000000000..d1a71aab06 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/core/request.ts @@ -0,0 +1,315 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import { ApiError } from './ApiError'; +import type { ApiRequestOptions } from './ApiRequestOptions'; +import type { ApiResult } from './ApiResult'; +import { CancelablePromise } from './CancelablePromise'; +import type { OnCancel } from './CancelablePromise'; +import type { OpenAPIConfig } from './OpenAPI'; + +const isDefined = (value: T | null | undefined): value is Exclude => { + return value !== undefined && value !== null; +}; + +const isString = (value: any): value is string => { + return typeof value === 'string'; +}; + +const isStringWithValue = (value: any): value is string => { + return isString(value) && value !== ''; +}; + +const isBlob = (value: any): value is Blob => { + return ( + typeof value === 'object' && + typeof value.type === 'string' && + typeof value.stream === 'function' && + typeof value.arrayBuffer === 'function' && + typeof value.constructor === 'function' && + typeof value.constructor.name === 'string' && + /^(Blob|File)$/.test(value.constructor.name) && + /^(Blob|File)$/.test(value[Symbol.toStringTag]) + ); +}; + +const isFormData = (value: any): value is FormData => { + return value instanceof FormData; +}; + +const base64 = (str: string): string => { + try { + return btoa(str); + } catch (err) { + // @ts-ignore + return Buffer.from(str).toString('base64'); + } +}; + +const getQueryString = (params: Record): string => { + const qs: string[] = []; + + const append = (key: string, value: any) => { + qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); + }; + + const process = (key: string, value: any) => { + if (isDefined(value)) { + if (Array.isArray(value)) { + value.forEach(v => { + process(key, v); + }); + } else if (typeof value === 'object') { + Object.entries(value).forEach(([k, v]) => { + process(`${key}[${k}]`, v); + }); + } else { + append(key, value); + } + } + }; + + Object.entries(params).forEach(([key, value]) => { + process(key, value); + }); + + if (qs.length > 0) { + return `?${qs.join('&')}`; + } + + return ''; +}; + +const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { + const encoder = config.ENCODE_PATH || encodeURI; + + const path = options.url + .replace('{api-version}', config.VERSION) + .replace(/{(.*?)}/g, (substring: string, group: string) => { + if (options.path?.hasOwnProperty(group)) { + return encoder(String(options.path[group])); + } + return substring; + }); + + const url = `${config.BASE}${path}`; + if (options.query) { + return `${url}${getQueryString(options.query)}`; + } + return url; +}; + +const getFormData = (options: ApiRequestOptions): FormData | undefined => { + if (options.formData) { + const formData = new FormData(); + + const process = (key: string, value: any) => { + if (isString(value) || isBlob(value)) { + formData.append(key, value); + } else { + formData.append(key, JSON.stringify(value)); + } + }; + + Object.entries(options.formData) + .filter(([_, value]) => isDefined(value)) + .forEach(([key, value]) => { + if (Array.isArray(value)) { + value.forEach(v => process(key, v)); + } else { + process(key, value); + } + }); + + return formData; + } + return undefined; +}; + +type Resolver = (options: ApiRequestOptions) => Promise; + +const resolve = async (options: ApiRequestOptions, resolver?: T | Resolver): Promise => { + if (typeof resolver === 'function') { + return (resolver as Resolver)(options); + } + return resolver; +}; + +const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise => { + const token = await resolve(options, config.TOKEN); + const username = await resolve(options, config.USERNAME); + const password = await resolve(options, config.PASSWORD); + const additionalHeaders = await resolve(options, config.HEADERS); + + const headers = Object.entries({ + Accept: 'application/json', + ...additionalHeaders, + ...options.headers, + }) + .filter(([_, value]) => isDefined(value)) + .reduce((headers, [key, value]) => ({ + ...headers, + [key]: String(value), + }), {} as Record); + + if (isStringWithValue(token)) { + headers['Authorization'] = `Bearer ${token}`; + } + + if (isStringWithValue(username) && isStringWithValue(password)) { + const credentials = base64(`${username}:${password}`); + headers['Authorization'] = `Basic ${credentials}`; + } + + if (options.body) { + if (options.mediaType) { + headers['Content-Type'] = options.mediaType; + } else if (isBlob(options.body)) { + headers['Content-Type'] = options.body.type || 'application/octet-stream'; + } else if (isString(options.body)) { + headers['Content-Type'] = 'text/plain'; + } else if (!isFormData(options.body)) { + headers['Content-Type'] = 'application/json'; + } + } + + return new Headers(headers); +}; + +const getRequestBody = (options: ApiRequestOptions): any => { + if (options.body) { + if (options.mediaType?.includes('/json')) { + return JSON.stringify(options.body) + } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { + return options.body; + } else { + return JSON.stringify(options.body); + } + } + return undefined; +}; + +export const sendRequest = async ( + config: OpenAPIConfig, + options: ApiRequestOptions, + url: string, + body: any, + formData: FormData | undefined, + headers: Headers, + onCancel: OnCancel +): Promise => { + const controller = new AbortController(); + + const request: RequestInit = { + headers, + body: body ?? formData, + method: options.method, + signal: controller.signal, + }; + + if (config.WITH_CREDENTIALS) { + request.credentials = config.CREDENTIALS; + } + + onCancel(() => controller.abort()); + console.log('joanie.gen.sendRequest::await fetch', await fetch(url, request)) + return await fetch(url, request); +}; + +const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { + if (responseHeader) { + const content = response.headers.get(responseHeader); + if (isString(content)) { + return content; + } + } + return undefined; +}; + +const getResponseBody = async (response: Response): Promise => { + console.log('joanie.gen.getResponseBody::response.status', response.status) + console.log('joanie.gen.getResponseBody::response', response) + if (response.status !== 204) { + try { + const contentType = response.headers.get('Content-Type'); + if (contentType) { + const isJSON = contentType.toLowerCase().startsWith('application/json'); + if (isJSON) { + return await response.json(); + } else { + return await response.text(); + } + } + } catch (error) { + console.error(error); + } + } + return undefined; +}; + +const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { + const errors: Record = { + 400: 'Bad Request', + 401: 'Unauthorized', + 403: 'Forbidden', + 404: 'Not Found', + 500: 'Internal Server Error', + 502: 'Bad Gateway', + 503: 'Service Unavailable', + ...options.errors, + } + + const error = errors[result.status]; + console.log('api.joanie.gen.request.catchErrorCodes::options', options) + console.log('api.joanie.gen.request.catchErrorCodes::result', result) + console.log('api.joanie.gen.request.catchErrorCodes::error', error) + if (error) { + throw new ApiError(options, result, error); + } + + if (!result.ok) { + throw new ApiError(options, result, 'Generic Error'); + } +}; + +/** + * Request method + * @param config The OpenAPI configuration object + * @param options The request options from the service + * @returns CancelablePromise + * @throws ApiError + */ +export const request = (config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise => { + return new CancelablePromise(async (resolve, reject, onCancel) => { + try { + console.log('api.joanie.gen.request') + const url = getUrl(config, options); + const formData = getFormData(options); + const body = getRequestBody(options); + const headers = await getHeaders(config, options); + + if (!onCancel.isCancelled) { + const response = await sendRequest(config, options, url, body, formData, headers, onCancel); + const responseBody = await getResponseBody(response); + const responseHeader = getResponseHeader(response, options.responseHeader); + + console.log('api.joanie.gen.request::response', response) + + const result: ApiResult = { + url, + ok: response.ok, + status: response.status, + statusText: response.statusText, + body: responseHeader ?? responseBody, + }; + + catchErrorCodes(options, result); + + resolve(result.body); + } + } catch (error) { + console.log('api.joanie.gen.throw', error) + reject(error); + } + }); +}; diff --git a/src/frontend/js/api/joanie/gen/index.ts b/src/frontend/js/api/joanie/gen/index.ts new file mode 100644 index 0000000000..3c1be5461a --- /dev/null +++ b/src/frontend/js/api/joanie/gen/index.ts @@ -0,0 +1,30 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export { ApiClientJoanie } from './ApiClientJoanie'; + +export { ApiError } from './core/ApiError'; +export { BaseHttpRequest } from './core/BaseHttpRequest'; +export { CancelablePromise, CancelError } from './core/CancelablePromise'; +export { OpenAPI } from './core/OpenAPI'; +export type { OpenAPIConfig } from './core/OpenAPI'; + +export { Address } from './models/Address'; +export type { Certificate } from './models/Certificate'; +export type { CertificationDefinition } from './models/CertificationDefinition'; +export type { Course } from './models/Course'; +export type { CourseRun } from './models/CourseRun'; +export type { CreditCard } from './models/CreditCard'; +export { Enrollment } from './models/Enrollment'; +export { Order } from './models/Order'; +export { Product } from './models/Product'; + +export { AddressesService } from './services/AddressesService'; +export { CertificatesService } from './services/CertificatesService'; +export { CourseRunsService } from './services/CourseRunsService'; +export { CourseRunsSyncService } from './services/CourseRunsSyncService'; +export { CreditCardsService } from './services/CreditCardsService'; +export { EnrollmentsService } from './services/EnrollmentsService'; +export { OrdersService } from './services/OrdersService'; +export { PaymentsService } from './services/PaymentsService'; +export { ProductsService } from './services/ProductsService'; diff --git a/src/frontend/js/api/joanie/gen/models/Address.ts b/src/frontend/js/api/joanie/gen/models/Address.ts new file mode 100644 index 0000000000..8de84c97cb --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/Address.ts @@ -0,0 +1,273 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Address = { + address: string; + city: string; + country: Address.country; + first_name: string; + last_name: string; + readonly id?: string; + is_main?: boolean; + postcode: string; + title: string; +}; + +export namespace Address { + + export enum country { + AF = 'AF', + AX = 'AX', + AL = 'AL', + DZ = 'DZ', + AS = 'AS', + AD = 'AD', + AO = 'AO', + AI = 'AI', + AQ = 'AQ', + AG = 'AG', + AR = 'AR', + AM = 'AM', + AW = 'AW', + AU = 'AU', + AT = 'AT', + AZ = 'AZ', + BS = 'BS', + BH = 'BH', + BD = 'BD', + BB = 'BB', + BY = 'BY', + BE = 'BE', + BZ = 'BZ', + BJ = 'BJ', + BM = 'BM', + BT = 'BT', + BO = 'BO', + BQ = 'BQ', + BA = 'BA', + BW = 'BW', + BV = 'BV', + BR = 'BR', + IO = 'IO', + BN = 'BN', + BG = 'BG', + BF = 'BF', + BI = 'BI', + CV = 'CV', + KH = 'KH', + CM = 'CM', + CA = 'CA', + KY = 'KY', + CF = 'CF', + TD = 'TD', + CL = 'CL', + CN = 'CN', + CX = 'CX', + CC = 'CC', + CO = 'CO', + KM = 'KM', + CG = 'CG', + CD = 'CD', + CK = 'CK', + CR = 'CR', + CI = 'CI', + HR = 'HR', + CU = 'CU', + CW = 'CW', + CY = 'CY', + CZ = 'CZ', + DK = 'DK', + DJ = 'DJ', + DM = 'DM', + DO = 'DO', + EC = 'EC', + EG = 'EG', + SV = 'SV', + GQ = 'GQ', + ER = 'ER', + EE = 'EE', + SZ = 'SZ', + ET = 'ET', + FK = 'FK', + FO = 'FO', + FJ = 'FJ', + FI = 'FI', + FR = 'FR', + GF = 'GF', + PF = 'PF', + TF = 'TF', + GA = 'GA', + GM = 'GM', + GE = 'GE', + DE = 'DE', + GH = 'GH', + GI = 'GI', + GR = 'GR', + GL = 'GL', + GD = 'GD', + GP = 'GP', + GU = 'GU', + GT = 'GT', + GG = 'GG', + GN = 'GN', + GW = 'GW', + GY = 'GY', + HT = 'HT', + HM = 'HM', + VA = 'VA', + HN = 'HN', + HK = 'HK', + HU = 'HU', + IS = 'IS', + IN = 'IN', + ID = 'ID', + IR = 'IR', + IQ = 'IQ', + IE = 'IE', + IM = 'IM', + IL = 'IL', + IT = 'IT', + JM = 'JM', + JP = 'JP', + JE = 'JE', + JO = 'JO', + KZ = 'KZ', + KE = 'KE', + KI = 'KI', + KW = 'KW', + KG = 'KG', + LA = 'LA', + LV = 'LV', + LB = 'LB', + LS = 'LS', + LR = 'LR', + LY = 'LY', + LI = 'LI', + LT = 'LT', + LU = 'LU', + MO = 'MO', + MG = 'MG', + MW = 'MW', + MY = 'MY', + MV = 'MV', + ML = 'ML', + MT = 'MT', + MH = 'MH', + MQ = 'MQ', + MR = 'MR', + MU = 'MU', + YT = 'YT', + MX = 'MX', + FM = 'FM', + MD = 'MD', + MC = 'MC', + MN = 'MN', + ME = 'ME', + MS = 'MS', + MA = 'MA', + MZ = 'MZ', + MM = 'MM', + NA = 'NA', + NR = 'NR', + NP = 'NP', + NL = 'NL', + NC = 'NC', + NZ = 'NZ', + NI = 'NI', + NE = 'NE', + NG = 'NG', + NU = 'NU', + NF = 'NF', + KP = 'KP', + MK = 'MK', + MP = 'MP', + NO = 'NO', + OM = 'OM', + PK = 'PK', + PW = 'PW', + PS = 'PS', + PA = 'PA', + PG = 'PG', + PY = 'PY', + PE = 'PE', + PH = 'PH', + PN = 'PN', + PL = 'PL', + PT = 'PT', + PR = 'PR', + QA = 'QA', + RE = 'RE', + RO = 'RO', + RU = 'RU', + RW = 'RW', + BL = 'BL', + SH = 'SH', + KN = 'KN', + LC = 'LC', + MF = 'MF', + PM = 'PM', + VC = 'VC', + WS = 'WS', + SM = 'SM', + ST = 'ST', + SA = 'SA', + SN = 'SN', + RS = 'RS', + SC = 'SC', + SL = 'SL', + SG = 'SG', + SX = 'SX', + SK = 'SK', + SI = 'SI', + SB = 'SB', + SO = 'SO', + ZA = 'ZA', + GS = 'GS', + KR = 'KR', + SS = 'SS', + ES = 'ES', + LK = 'LK', + SD = 'SD', + SR = 'SR', + SJ = 'SJ', + SE = 'SE', + CH = 'CH', + SY = 'SY', + TW = 'TW', + TJ = 'TJ', + TZ = 'TZ', + TH = 'TH', + TL = 'TL', + TG = 'TG', + TK = 'TK', + TO = 'TO', + TT = 'TT', + TN = 'TN', + TR = 'TR', + TM = 'TM', + TC = 'TC', + TV = 'TV', + UG = 'UG', + UA = 'UA', + AE = 'AE', + GB = 'GB', + UM = 'UM', + US = 'US', + UY = 'UY', + UZ = 'UZ', + VU = 'VU', + VE = 'VE', + VN = 'VN', + VG = 'VG', + VI = 'VI', + WF = 'WF', + EH = 'EH', + YE = 'YE', + ZM = 'ZM', + ZW = 'ZW', + } + + +} + diff --git a/src/frontend/js/api/joanie/gen/models/Certificate.ts b/src/frontend/js/api/joanie/gen/models/Certificate.ts new file mode 100644 index 0000000000..3494a95f1c --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/Certificate.ts @@ -0,0 +1,8 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Certificate = { + readonly id?: string; +}; + diff --git a/src/frontend/js/api/joanie/gen/models/CertificationDefinition.ts b/src/frontend/js/api/joanie/gen/models/CertificationDefinition.ts new file mode 100644 index 0000000000..8b83993a5d --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/CertificationDefinition.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type CertificationDefinition = { + readonly description?: string; + readonly name?: string; + readonly title?: string; +}; + diff --git a/src/frontend/js/api/joanie/gen/models/Course.ts b/src/frontend/js/api/joanie/gen/models/Course.ts new file mode 100644 index 0000000000..bf6cb79896 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/Course.ts @@ -0,0 +1,9 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Course = { + readonly code?: string; + readonly title?: string; +}; + diff --git a/src/frontend/js/api/joanie/gen/models/CourseRun.ts b/src/frontend/js/api/joanie/gen/models/CourseRun.ts new file mode 100644 index 0000000000..ccc6ebf780 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/CourseRun.ts @@ -0,0 +1,21 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { Course } from './Course'; + +export type CourseRun = { + course?: Course; + readonly end?: string | null; + readonly enrollment_end?: string | null; + readonly enrollment_start?: string | null; + /** + * primary key for the record as UUID + */ + readonly id?: string; + readonly resource_link?: string; + readonly start?: string | null; + readonly title?: string; + readonly state?: string; +}; + diff --git a/src/frontend/js/api/joanie/gen/models/CreditCard.ts b/src/frontend/js/api/joanie/gen/models/CreditCard.ts new file mode 100644 index 0000000000..a1fe0894c9 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/CreditCard.ts @@ -0,0 +1,14 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type CreditCard = { + readonly id?: string; + title?: string | null; + readonly brand?: string | null; + readonly expiration_month?: number; + readonly expiration_year?: number; + readonly last_numbers?: string; + is_main?: boolean; +}; + diff --git a/src/frontend/js/api/joanie/gen/models/Enrollment.ts b/src/frontend/js/api/joanie/gen/models/Enrollment.ts new file mode 100644 index 0000000000..c3fd388787 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/Enrollment.ts @@ -0,0 +1,31 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { CourseRun } from './CourseRun'; + +export type Enrollment = { + readonly id?: string; + course_run?: CourseRun; + /** + * date and time at which a record was created + */ + readonly created_on?: string; + /** + * Ticked if the user is enrolled to the course run. + */ + is_active: boolean; + readonly state?: Enrollment.state; + was_created_by_order: boolean; +}; + +export namespace Enrollment { + + export enum state { + SET = 'set', + FAILED = 'failed', + } + + +} + diff --git a/src/frontend/js/api/joanie/gen/models/Order.ts b/src/frontend/js/api/joanie/gen/models/Order.ts new file mode 100644 index 0000000000..972500d6d7 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/Order.ts @@ -0,0 +1,35 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Order = { + course: string; + /** + * date and time at which a record was created + */ + readonly created_on?: string; + readonly certificate?: string; + readonly enrollments?: string; + readonly id?: string; + readonly main_invoice?: string; + organization?: string; + readonly owner?: string; + readonly total?: number; + readonly total_currency?: string; + product: string; + readonly state?: Order.state; + readonly target_courses?: string; +}; + +export namespace Order { + + export enum state { + PENDING = 'pending', + CANCELED = 'canceled', + FAILED = 'failed', + VALIDATED = 'validated', + } + + +} + diff --git a/src/frontend/js/api/joanie/gen/models/Product.ts b/src/frontend/js/api/joanie/gen/models/Product.ts new file mode 100644 index 0000000000..d421627871 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/models/Product.ts @@ -0,0 +1,29 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { CertificationDefinition } from './CertificationDefinition'; + +export type Product = { + readonly call_to_action?: string; + certificate?: CertificationDefinition; + readonly id?: string; + readonly organizations?: string; + readonly price?: number; + readonly price_currency?: string; + readonly target_courses?: string; + readonly title?: string; + readonly type?: Product.type; +}; + +export namespace Product { + + export enum type { + CREDENTIAL = 'credential', + ENROLLMENT = 'enrollment', + CERTIFICATE = 'certificate', + } + + +} + diff --git a/src/frontend/js/api/joanie/gen/services/AddressesService.ts b/src/frontend/js/api/joanie/gen/services/AddressesService.ts new file mode 100644 index 0000000000..489848704a --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/AddressesService.ts @@ -0,0 +1,286 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Address } from '../models/Address'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class AddressesService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * API view allows to get all addresses or create or update a new one for a user. + * GET /api/addresses/ + * Return list of all addresses for a user + * + * POST /api/addresses/ with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return new address just created + * + * PUT /api/addresses// with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return address just updated + * + * DELETE /api/addresses// + * Delete selected address + * @returns Address + * @throws ApiError + */ + public addressesList(): CancelablePromise> { + return this.httpRequest.request({ + method: 'GET', + url: '/addresses/', + }); + } + + /** + * API view allows to get all addresses or create or update a new one for a user. + * GET /api/addresses/ + * Return list of all addresses for a user + * + * POST /api/addresses/ with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return new address just created + * + * PUT /api/addresses// with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return address just updated + * + * DELETE /api/addresses// + * Delete selected address + * @returns Address + * @throws ApiError + */ + public addressesCreate({ + data, + }: { + data: Address, + }): CancelablePromise
{ + return this.httpRequest.request({ + method: 'POST', + url: '/addresses/', + body: data, + }); + } + + /** + * API view allows to get all addresses or create or update a new one for a user. + * GET /api/addresses/ + * Return list of all addresses for a user + * + * POST /api/addresses/ with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return new address just created + * + * PUT /api/addresses// with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return address just updated + * + * DELETE /api/addresses// + * Delete selected address + * @returns Address + * @throws ApiError + */ + public addressesRead({ + id, + }: { + id: string, + }): CancelablePromise
{ + return this.httpRequest.request({ + method: 'GET', + url: '/addresses/{id}/', + path: { + 'id': id, + }, + }); + } + + /** + * API view allows to get all addresses or create or update a new one for a user. + * GET /api/addresses/ + * Return list of all addresses for a user + * + * POST /api/addresses/ with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return new address just created + * + * PUT /api/addresses// with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return address just updated + * + * DELETE /api/addresses// + * Delete selected address + * @returns Address + * @throws ApiError + */ + public addressesUpdate({ + id, + data, + }: { + id: string, + data: Address, + }): CancelablePromise
{ + return this.httpRequest.request({ + method: 'PUT', + url: '/addresses/{id}/', + path: { + 'id': id, + }, + body: data, + }); + } + + /** + * API view allows to get all addresses or create or update a new one for a user. + * GET /api/addresses/ + * Return list of all addresses for a user + * + * POST /api/addresses/ with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return new address just created + * + * PUT /api/addresses// with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return address just updated + * + * DELETE /api/addresses// + * Delete selected address + * @returns Address + * @throws ApiError + */ + public addressesPartialUpdate({ + id, + data, + }: { + id: string, + data: Address, + }): CancelablePromise
{ + return this.httpRequest.request({ + method: 'PATCH', + url: '/addresses/{id}/', + path: { + 'id': id, + }, + body: data, + }); + } + + /** + * API view allows to get all addresses or create or update a new one for a user. + * GET /api/addresses/ + * Return list of all addresses for a user + * + * POST /api/addresses/ with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return new address just created + * + * PUT /api/addresses// with expected data: + * - address: str + * - city: str + * - country: str, country code + * - first_name: str, recipient first name + * - last_name: str, recipient last name + * - is_main?: bool, if True set address as main + * - postcode: str + * - title: str, address title + * Return address just updated + * + * DELETE /api/addresses// + * Delete selected address + * @returns void + * @throws ApiError + */ + public addressesDelete({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/addresses/{id}/', + path: { + 'id': id, + }, + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/CertificatesService.ts b/src/frontend/js/api/joanie/gen/services/CertificatesService.ts new file mode 100644 index 0000000000..bb54212cdb --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/CertificatesService.ts @@ -0,0 +1,75 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Certificate } from '../models/Certificate'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class CertificatesService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * API views to get all certificates for a user + * GET /api/certificates/:certificate_id + * Return list of all certificates for a user or one certificate if an id is + * provided. + * + * GET /api/certificates/:certificate_id/download + * Return the certificate document in PDF format. + * @returns Certificate + * @throws ApiError + */ + public certificatesList(): CancelablePromise> { + return this.httpRequest.request({ + method: 'GET', + url: '/certificates/', + }); + } + + /** + * API views to get all certificates for a user + * GET /api/certificates/:certificate_id + * Return list of all certificates for a user or one certificate if an id is + * provided. + * + * GET /api/certificates/:certificate_id/download + * Return the certificate document in PDF format. + * @returns Certificate + * @throws ApiError + */ + public certificatesRead({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/certificates/{id}/', + path: { + 'id': id, + }, + }); + } + + /** + * Retrieve a certificate through its id if it is owned by the authenticated user. + * @returns Certificate + * @throws ApiError + */ + public certificatesDownload({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/certificates/{id}/download/', + path: { + 'id': id, + }, + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/CourseRunsService.ts b/src/frontend/js/api/joanie/gen/services/CourseRunsService.ts new file mode 100644 index 0000000000..e932db00f5 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/CourseRunsService.ts @@ -0,0 +1,35 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { CourseRun } from '../models/CourseRun'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class CourseRunsService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * API ViewSet for all interactions with course runs. + * @returns CourseRun + * @throws ApiError + */ + public courseRunsRead({ + id, + }: { + /** + * primary key for the record as UUID + */ + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/course-runs/{id}/', + path: { + 'id': id, + }, + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/CourseRunsSyncService.ts b/src/frontend/js/api/joanie/gen/services/CourseRunsSyncService.ts new file mode 100644 index 0000000000..6439b290e9 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/CourseRunsSyncService.ts @@ -0,0 +1,34 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class CourseRunsSyncService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * View for the web hook to create or update course runs based on their resource link. + * - A new course run is created or the existing course run is updated + * + * Parameters + * ---------- + * request : Type[django.http.request.HttpRequest] + * The request on the API endpoint, it should contain a payload with course run fields. + * + * Returns + * ------- + * Type[rest_framework.response.Response] + * HttpResponse acknowledging the success or failure of the synchronization operation. + * @returns any + * @throws ApiError + */ + public courseRunsSyncCreate(): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/course-runs-sync/', + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/CreditCardsService.ts b/src/frontend/js/api/joanie/gen/services/CreditCardsService.ts new file mode 100644 index 0000000000..a9e4de2033 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/CreditCardsService.ts @@ -0,0 +1,157 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { CreditCard } from '../models/CreditCard'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class CreditCardsService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * API views allows to get all credit cards, update or delete one + * for the authenticated user. + * GET /api/credit-cards/ + * Return the list of all credit cards owned by the authenticated user + * + * PUT /api/credit-cards/ with expected data: + * - title: str + * - is_main?: bool + * + * DELETE /api/credit-cards/ + * Delete the selected credit card + * @returns CreditCard + * @throws ApiError + */ + public creditCardsList(): CancelablePromise> { + return this.httpRequest.request({ + method: 'GET', + url: '/credit-cards/', + }); + } + + /** + * API views allows to get all credit cards, update or delete one + * for the authenticated user. + * GET /api/credit-cards/ + * Return the list of all credit cards owned by the authenticated user + * + * PUT /api/credit-cards/ with expected data: + * - title: str + * - is_main?: bool + * + * DELETE /api/credit-cards/ + * Delete the selected credit card + * @returns CreditCard + * @throws ApiError + */ + public creditCardsRead({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/credit-cards/{id}/', + path: { + 'id': id, + }, + }); + } + + /** + * API views allows to get all credit cards, update or delete one + * for the authenticated user. + * GET /api/credit-cards/ + * Return the list of all credit cards owned by the authenticated user + * + * PUT /api/credit-cards/ with expected data: + * - title: str + * - is_main?: bool + * + * DELETE /api/credit-cards/ + * Delete the selected credit card + * @returns CreditCard + * @throws ApiError + */ + public creditCardsUpdate({ + id, + data, + }: { + id: string, + data: CreditCard, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'PUT', + url: '/credit-cards/{id}/', + path: { + 'id': id, + }, + body: data, + }); + } + + /** + * API views allows to get all credit cards, update or delete one + * for the authenticated user. + * GET /api/credit-cards/ + * Return the list of all credit cards owned by the authenticated user + * + * PUT /api/credit-cards/ with expected data: + * - title: str + * - is_main?: bool + * + * DELETE /api/credit-cards/ + * Delete the selected credit card + * @returns CreditCard + * @throws ApiError + */ + public creditCardsPartialUpdate({ + id, + data, + }: { + id: string, + data: CreditCard, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'PATCH', + url: '/credit-cards/{id}/', + path: { + 'id': id, + }, + body: data, + }); + } + + /** + * API views allows to get all credit cards, update or delete one + * for the authenticated user. + * GET /api/credit-cards/ + * Return the list of all credit cards owned by the authenticated user + * + * PUT /api/credit-cards/ with expected data: + * - title: str + * - is_main?: bool + * + * DELETE /api/credit-cards/ + * Delete the selected credit card + * @returns void + * @throws ApiError + */ + public creditCardsDelete({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/credit-cards/{id}/', + path: { + 'id': id, + }, + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/EnrollmentsService.ts b/src/frontend/js/api/joanie/gen/services/EnrollmentsService.ts new file mode 100644 index 0000000000..5bb7b3d20f --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/EnrollmentsService.ts @@ -0,0 +1,126 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Enrollment } from '../models/Enrollment'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class EnrollmentsService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * API ViewSet for all interactions with enrollments. + * @returns any + * @throws ApiError + */ + public enrollmentsList({ + courseRun, + wasCreatedByOrder, + page, + }: { + courseRun?: string, + wasCreatedByOrder?: string, + /** + * A page number within the paginated result set. + */ + page?: number, + }): CancelablePromise<{ + count: number; + next?: string | null; + previous?: string | null; + results: Array; + }> { + return this.httpRequest.request({ + method: 'GET', + url: '/enrollments/', + query: { + 'course_run': courseRun, + 'was_created_by_order': wasCreatedByOrder, + 'page': page, + }, + }); + } + + /** + * API ViewSet for all interactions with enrollments. + * @returns Enrollment + * @throws ApiError + */ + public enrollmentsCreate({ + data, + }: { + data: Enrollment, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/enrollments/', + body: data, + }); + } + + /** + * API ViewSet for all interactions with enrollments. + * @returns Enrollment + * @throws ApiError + */ + public enrollmentsRead({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/enrollments/{id}/', + path: { + 'id': id, + }, + }); + } + + /** + * API ViewSet for all interactions with enrollments. + * @returns Enrollment + * @throws ApiError + */ + public enrollmentsUpdate({ + id, + data, + }: { + id: string, + data: Enrollment, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'PUT', + url: '/enrollments/{id}/', + path: { + 'id': id, + }, + body: data, + }); + } + + /** + * API ViewSet for all interactions with enrollments. + * @returns Enrollment + * @throws ApiError + */ + public enrollmentsPartialUpdate({ + id, + data, + }: { + id: string, + data: Enrollment, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'PATCH', + url: '/enrollments/{id}/', + path: { + 'id': id, + }, + body: data, + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/OrdersService.ts b/src/frontend/js/api/joanie/gen/services/OrdersService.ts new file mode 100644 index 0000000000..ee783d1819 --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/OrdersService.ts @@ -0,0 +1,143 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Order } from '../models/Order'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class OrdersService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * API view for a user to consult the orders he/she owns or create a new one. + * GET /api/orders/ + * Return list of all orders for a user with pagination + * + * POST /api/orders/ with expected data: + * - course: course code + * - product: product id (product must be associated to the course. Otherwise, + * a 400 error is returned) + * Return new order just created + * @returns any + * @throws ApiError + */ + public ordersList({ + product, + course, + state, + page, + }: { + product?: string, + course?: string, + state?: string, + /** + * A page number within the paginated result set. + */ + page?: number, + }): CancelablePromise<{ + count: number; + next?: string | null; + previous?: string | null; + results: Array; + }> { + return this.httpRequest.request({ + method: 'GET', + url: '/orders/', + query: { + 'product': product, + 'course': course, + 'state': state, + 'page': page, + }, + }); + } + + /** + * Try to create an order and a related payment if the payment is fee. + * @returns Order + * @throws ApiError + */ + public ordersCreate({ + data, + }: { + data: Order, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/orders/', + body: data, + }); + } + + /** + * API view for a user to consult the orders he/she owns or create a new one. + * GET /api/orders/ + * Return list of all orders for a user with pagination + * + * POST /api/orders/ with expected data: + * - course: course code + * - product: product id (product must be associated to the course. Otherwise, + * a 400 error is returned) + * Return new order just created + * @returns Order + * @throws ApiError + */ + public ordersRead({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/orders/{id}/', + path: { + 'id': id, + }, + }); + } + + /** + * Abort a pending order and the related payment if there is one. + * @returns Order + * @throws ApiError + */ + public ordersAbort({ + id, + data, + }: { + id: string, + data: Order, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/orders/{id}/abort/', + path: { + 'id': id, + }, + body: data, + }); + } + + /** + * Retrieve an invoice through its reference if it is related to + * the order instance and owned by the authenticated user. + * @returns Order + * @throws ApiError + */ + public ordersInvoice({ + id, + }: { + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/orders/{id}/invoice/', + path: { + 'id': id, + }, + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/PaymentsService.ts b/src/frontend/js/api/joanie/gen/services/PaymentsService.ts new file mode 100644 index 0000000000..f41431163c --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/PaymentsService.ts @@ -0,0 +1,24 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class PaymentsService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * The webhook called by payment provider + * when a payment has been created/updated/refunded... + * @returns any + * @throws ApiError + */ + public paymentsNotificationsCreate(): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/payments/notifications/', + }); + } + +} diff --git a/src/frontend/js/api/joanie/gen/services/ProductsService.ts b/src/frontend/js/api/joanie/gen/services/ProductsService.ts new file mode 100644 index 0000000000..374f6dde4f --- /dev/null +++ b/src/frontend/js/api/joanie/gen/services/ProductsService.ts @@ -0,0 +1,35 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Product } from '../models/Product'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class ProductsService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * API ViewSet for all interactions with products. + * @returns Product + * @throws ApiError + */ + public productsRead({ + id, + }: { + /** + * primary key for the record as UUID + */ + id: string, + }): CancelablePromise { + return this.httpRequest.request({ + method: 'GET', + url: '/products/{id}/', + path: { + 'id': id, + }, + }); + } + +} diff --git a/src/frontend/js/api/joanie/index.ts b/src/frontend/js/api/joanie/index.ts new file mode 100644 index 0000000000..5e1a84898c --- /dev/null +++ b/src/frontend/js/api/joanie/index.ts @@ -0,0 +1,29 @@ +import context from 'utils/context'; +import { JOANIE_API_VERSION } from 'settings'; +import { ApiClientJoanie, OpenAPIConfig } from './gen'; + +/** + * Build Joanie API Routes interface. + */ +const getAPIEndpoint = () => { + const endpoint = context?.joanie_backend?.endpoint; + const version = JOANIE_API_VERSION; + + if (!endpoint) { + throw new Error('[JOANIE] - Joanie API endpoint is not defined.'); + } + + return `${endpoint}/api/${version}`; +}; + +// TODO add auth with jwt +const config: OpenAPIConfig = { + BASE: getAPIEndpoint(), + VERSION: '1', + WITH_CREDENTIALS: true, + CREDENTIALS: 'include', + // TOKEN: +}; + +export const joanieApi = new ApiClientJoanie(config); +export * from './hooks';