go-code-challenge-sdk 0.0.0-dev.c6fa67a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/Api.ts +434 -0
  2. package/package.json +9 -0
package/Api.ts ADDED
@@ -0,0 +1,434 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ // @ts-nocheck
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
12
+
13
+ export interface ErrorDetail {
14
+ /** Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id' */
15
+ location?: string;
16
+ /** Error message text */
17
+ message?: string;
18
+ /** The value at the given location */
19
+ value?: any;
20
+ }
21
+
22
+ export interface ErrorModel {
23
+ /**
24
+ * A URL to the JSON Schema for this object.
25
+ * @format uri
26
+ */
27
+ $schema?: string;
28
+ /** A human-readable explanation specific to this occurrence of the problem. */
29
+ detail?: string;
30
+ /** Optional list of individual error details */
31
+ errors?: any[] | null;
32
+ /**
33
+ * A URI reference that identifies the specific occurrence of the problem.
34
+ * @format uri
35
+ */
36
+ instance?: string;
37
+ /**
38
+ * HTTP status code
39
+ * @format int64
40
+ */
41
+ status?: number;
42
+ /** A short, human-readable summary of the problem type. This value should not change between occurrences of the error. */
43
+ title?: string;
44
+ /**
45
+ * A URI reference to human-readable documentation for the error.
46
+ * @format uri
47
+ * @default "about:blank"
48
+ */
49
+ type?: string;
50
+ }
51
+
52
+ export interface RegisterInputBody {
53
+ /**
54
+ * A URL to the JSON Schema for this object.
55
+ * @format uri
56
+ */
57
+ $schema?: string;
58
+ /**
59
+ * User email address
60
+ * @format email
61
+ */
62
+ email: string;
63
+ }
64
+
65
+ export interface Registration {
66
+ /**
67
+ * Registration timestamp
68
+ * @format date-time
69
+ */
70
+ created_at: string;
71
+ /** Registered email address */
72
+ email: string;
73
+ /** Registration ID */
74
+ id: string;
75
+ /** The invitation code used */
76
+ invitation_code: string;
77
+ }
78
+
79
+ export interface RegistrationResponse {
80
+ /**
81
+ * A URL to the JSON Schema for this object.
82
+ * @format uri
83
+ */
84
+ $schema?: string;
85
+ /** Registration details */
86
+ registration: Registration;
87
+ }
88
+
89
+ export interface VersionOutputBody {
90
+ /**
91
+ * A URL to the JSON Schema for this object.
92
+ * @format uri
93
+ */
94
+ $schema?: string;
95
+ build_date: string;
96
+ commit: string;
97
+ version: string;
98
+ }
99
+
100
+ export type QueryParamsType = Record<string | number, any>;
101
+ export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
102
+
103
+ export interface FullRequestParams extends Omit<RequestInit, "body"> {
104
+ /** set parameter to `true` for call `securityWorker` for this request */
105
+ secure?: boolean;
106
+ /** request path */
107
+ path: string;
108
+ /** content type of request body */
109
+ type?: ContentType;
110
+ /** query params */
111
+ query?: QueryParamsType;
112
+ /** format of response (i.e. response.json() -> format: "json") */
113
+ format?: ResponseFormat;
114
+ /** request body */
115
+ body?: unknown;
116
+ /** base url */
117
+ baseUrl?: string;
118
+ /** request cancellation token */
119
+ cancelToken?: CancelToken;
120
+ }
121
+
122
+ export type RequestParams = Omit<
123
+ FullRequestParams,
124
+ "body" | "method" | "query" | "path"
125
+ >;
126
+
127
+ export interface ApiConfig<SecurityDataType = unknown> {
128
+ baseUrl?: string;
129
+ baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
130
+ securityWorker?: (
131
+ securityData: SecurityDataType | null,
132
+ ) => Promise<RequestParams | void> | RequestParams | void;
133
+ customFetch?: typeof fetch;
134
+ }
135
+
136
+ export interface HttpResponse<D extends unknown, E extends unknown = unknown>
137
+ extends Response {
138
+ data: D;
139
+ error: E;
140
+ }
141
+
142
+ type CancelToken = Symbol | string | number;
143
+
144
+ export enum ContentType {
145
+ Json = "application/json",
146
+ JsonApi = "application/vnd.api+json",
147
+ FormData = "multipart/form-data",
148
+ UrlEncoded = "application/x-www-form-urlencoded",
149
+ Text = "text/plain",
150
+ }
151
+
152
+ export class HttpClient<SecurityDataType = unknown> {
153
+ public baseUrl: string = "";
154
+ private securityData: SecurityDataType | null = null;
155
+ private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
156
+ private abortControllers = new Map<CancelToken, AbortController>();
157
+ private customFetch = (...fetchParams: Parameters<typeof fetch>) =>
158
+ fetch(...fetchParams);
159
+
160
+ private baseApiParams: RequestParams = {
161
+ credentials: "same-origin",
162
+ headers: {},
163
+ redirect: "follow",
164
+ referrerPolicy: "no-referrer",
165
+ };
166
+
167
+ constructor(apiConfig: ApiConfig<SecurityDataType> = {}) {
168
+ Object.assign(this, apiConfig);
169
+ }
170
+
171
+ public setSecurityData = (data: SecurityDataType | null) => {
172
+ this.securityData = data;
173
+ };
174
+
175
+ protected encodeQueryParam(key: string, value: any) {
176
+ const encodedKey = encodeURIComponent(key);
177
+ return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
178
+ }
179
+
180
+ protected addQueryParam(query: QueryParamsType, key: string) {
181
+ return this.encodeQueryParam(key, query[key]);
182
+ }
183
+
184
+ protected addArrayQueryParam(query: QueryParamsType, key: string) {
185
+ const value = query[key];
186
+ return value.map((v: any) => this.encodeQueryParam(key, v)).join("&");
187
+ }
188
+
189
+ protected toQueryString(rawQuery?: QueryParamsType): string {
190
+ const query = rawQuery || {};
191
+ const keys = Object.keys(query).filter(
192
+ (key) => "undefined" !== typeof query[key],
193
+ );
194
+ return keys
195
+ .map((key) =>
196
+ Array.isArray(query[key])
197
+ ? this.addArrayQueryParam(query, key)
198
+ : this.addQueryParam(query, key),
199
+ )
200
+ .join("&");
201
+ }
202
+
203
+ protected addQueryParams(rawQuery?: QueryParamsType): string {
204
+ const queryString = this.toQueryString(rawQuery);
205
+ return queryString ? `?${queryString}` : "";
206
+ }
207
+
208
+ private contentFormatters: Record<ContentType, (input: any) => any> = {
209
+ [ContentType.Json]: (input: any) =>
210
+ input !== null && (typeof input === "object" || typeof input === "string")
211
+ ? JSON.stringify(input)
212
+ : input,
213
+ [ContentType.JsonApi]: (input: any) =>
214
+ input !== null && (typeof input === "object" || typeof input === "string")
215
+ ? JSON.stringify(input)
216
+ : input,
217
+ [ContentType.Text]: (input: any) =>
218
+ input !== null && typeof input !== "string"
219
+ ? JSON.stringify(input)
220
+ : input,
221
+ [ContentType.FormData]: (input: any) => {
222
+ if (input instanceof FormData) {
223
+ return input;
224
+ }
225
+
226
+ return Object.keys(input || {}).reduce((formData, key) => {
227
+ const property = input[key];
228
+ formData.append(
229
+ key,
230
+ property instanceof Blob
231
+ ? property
232
+ : typeof property === "object" && property !== null
233
+ ? JSON.stringify(property)
234
+ : `${property}`,
235
+ );
236
+ return formData;
237
+ }, new FormData());
238
+ },
239
+ [ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
240
+ };
241
+
242
+ protected mergeRequestParams(
243
+ params1: RequestParams,
244
+ params2?: RequestParams,
245
+ ): RequestParams {
246
+ return {
247
+ ...this.baseApiParams,
248
+ ...params1,
249
+ ...(params2 || {}),
250
+ headers: {
251
+ ...(this.baseApiParams.headers || {}),
252
+ ...(params1.headers || {}),
253
+ ...((params2 && params2.headers) || {}),
254
+ },
255
+ };
256
+ }
257
+
258
+ protected createAbortSignal = (
259
+ cancelToken: CancelToken,
260
+ ): AbortSignal | undefined => {
261
+ if (this.abortControllers.has(cancelToken)) {
262
+ const abortController = this.abortControllers.get(cancelToken);
263
+ if (abortController) {
264
+ return abortController.signal;
265
+ }
266
+ return void 0;
267
+ }
268
+
269
+ const abortController = new AbortController();
270
+ this.abortControllers.set(cancelToken, abortController);
271
+ return abortController.signal;
272
+ };
273
+
274
+ public abortRequest = (cancelToken: CancelToken) => {
275
+ const abortController = this.abortControllers.get(cancelToken);
276
+
277
+ if (abortController) {
278
+ abortController.abort();
279
+ this.abortControllers.delete(cancelToken);
280
+ }
281
+ };
282
+
283
+ public request = async <T = any, E = any>({
284
+ body,
285
+ secure,
286
+ path,
287
+ type,
288
+ query,
289
+ format,
290
+ baseUrl,
291
+ cancelToken,
292
+ ...params
293
+ }: FullRequestParams): Promise<HttpResponse<T, E>> => {
294
+ const secureParams =
295
+ ((typeof secure === "boolean" ? secure : this.baseApiParams.secure) &&
296
+ this.securityWorker &&
297
+ (await this.securityWorker(this.securityData))) ||
298
+ {};
299
+ const requestParams = this.mergeRequestParams(params, secureParams);
300
+ const queryString = query && this.toQueryString(query);
301
+ const payloadFormatter = this.contentFormatters[type || ContentType.Json];
302
+ const responseFormat = format || requestParams.format;
303
+
304
+ return this.customFetch(
305
+ `${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`,
306
+ {
307
+ ...requestParams,
308
+ headers: {
309
+ ...(requestParams.headers || {}),
310
+ ...(type && type !== ContentType.FormData
311
+ ? { "Content-Type": type }
312
+ : {}),
313
+ },
314
+ signal:
315
+ (cancelToken
316
+ ? this.createAbortSignal(cancelToken)
317
+ : requestParams.signal) || null,
318
+ body:
319
+ typeof body === "undefined" || body === null
320
+ ? null
321
+ : payloadFormatter(body),
322
+ },
323
+ ).then(async (response) => {
324
+ const r = response as HttpResponse<T, E>;
325
+ r.data = null as unknown as T;
326
+ r.error = null as unknown as E;
327
+
328
+ const responseToParse = responseFormat ? response.clone() : response;
329
+ const data = !responseFormat
330
+ ? r
331
+ : await responseToParse[responseFormat]()
332
+ .then((data) => {
333
+ if (r.ok) {
334
+ r.data = data;
335
+ } else {
336
+ r.error = data;
337
+ }
338
+ return r;
339
+ })
340
+ .catch((e) => {
341
+ r.error = e;
342
+ return r;
343
+ });
344
+
345
+ if (cancelToken) {
346
+ this.abortControllers.delete(cancelToken);
347
+ }
348
+
349
+ if (!response.ok) throw data;
350
+ return data;
351
+ });
352
+ };
353
+ }
354
+
355
+ /**
356
+ * @title Invitation API
357
+ * @version 1.0.0
358
+ */
359
+ export class Api<
360
+ SecurityDataType extends unknown,
361
+ > extends HttpClient<SecurityDataType> {
362
+ v1 = {
363
+ /**
364
+ * @description Submit email to register using an invitation code
365
+ *
366
+ * @tags Invitations
367
+ * @name RegisterByInvitation
368
+ * @summary Register by invitation code
369
+ * @request POST:/api/v1/invitations/{code}
370
+ */
371
+ registerByInvitation: (
372
+ code: string,
373
+ data: RegisterInputBody,
374
+ params: RequestParams = {},
375
+ ) =>
376
+ this.request<RegistrationResponse, ErrorModel>({
377
+ path: `/api/v1/invitations/${code}`,
378
+ method: "POST",
379
+ body: data,
380
+ type: ContentType.Json,
381
+ format: "json",
382
+ ...params,
383
+ }),
384
+ };
385
+ live = {
386
+ /**
387
+ * No description
388
+ *
389
+ * @tags Health
390
+ * @name Liveness
391
+ * @summary Liveness probe
392
+ * @request GET:/health/live
393
+ */
394
+ liveness: (params: RequestParams = {}) =>
395
+ this.request<void, ErrorModel>({
396
+ path: `/health/live`,
397
+ method: "GET",
398
+ ...params,
399
+ }),
400
+ };
401
+ ready = {
402
+ /**
403
+ * No description
404
+ *
405
+ * @tags Health
406
+ * @name Readiness
407
+ * @summary Readiness probe
408
+ * @request GET:/health/ready
409
+ */
410
+ readiness: (params: RequestParams = {}) =>
411
+ this.request<void, ErrorModel>({
412
+ path: `/health/ready`,
413
+ method: "GET",
414
+ ...params,
415
+ }),
416
+ };
417
+ version = {
418
+ /**
419
+ * No description
420
+ *
421
+ * @tags Health
422
+ * @name Version
423
+ * @summary Application version
424
+ * @request GET:/health/version
425
+ */
426
+ version: (params: RequestParams = {}) =>
427
+ this.request<VersionOutputBody, ErrorModel>({
428
+ path: `/health/version`,
429
+ method: "GET",
430
+ format: "json",
431
+ ...params,
432
+ }),
433
+ };
434
+ }
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "go-code-challenge-sdk",
3
+ "version": "0.0.0-dev.c6fa67a",
4
+ "description": "TypeScript SDK for Go Code Challenge API (auto-generated from OpenAPI spec)",
5
+ "main": "Api.ts",
6
+ "types": "Api.ts",
7
+ "files": ["*.ts"],
8
+ "license": "MIT"
9
+ }