@fencyai/js 0.1.41 → 0.1.43

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 (115) hide show
  1. package/lib/api/createChatCompletion.d.ts +0 -4
  2. package/lib/api/createChatCompletion.js +16 -30
  3. package/lib/api/createStream.d.ts +14 -0
  4. package/lib/api/createStream.js +53 -0
  5. package/lib/api/createUpload.d.ts +16 -0
  6. package/lib/api/createUpload.js +53 -0
  7. package/lib/api/createWebsite.d.ts +16 -0
  8. package/lib/api/createWebsite.js +39 -0
  9. package/lib/index.d.ts +21 -8
  10. package/lib/index.js +10 -4
  11. package/lib/openapi/core/ApiError.d.ts +10 -0
  12. package/lib/openapi/core/ApiError.js +11 -0
  13. package/lib/openapi/core/ApiRequestOptions.d.ts +13 -0
  14. package/lib/openapi/core/ApiRequestOptions.js +1 -0
  15. package/lib/openapi/core/ApiResult.d.ts +7 -0
  16. package/lib/openapi/core/ApiResult.js +1 -0
  17. package/lib/openapi/core/CancelablePromise.d.ts +20 -0
  18. package/lib/openapi/core/CancelablePromise.js +111 -0
  19. package/lib/openapi/core/OpenAPI.d.ts +16 -0
  20. package/lib/openapi/core/OpenAPI.js +11 -0
  21. package/lib/openapi/core/request.d.ts +30 -0
  22. package/lib/openapi/core/request.js +275 -0
  23. package/lib/openapi/index.d.ts +31 -0
  24. package/lib/openapi/index.js +11 -0
  25. package/lib/openapi/models/ApiDtoType.d.ts +6 -0
  26. package/lib/openapi/models/ApiDtoType.js +11 -0
  27. package/lib/openapi/models/ChatCompletionDto.d.ts +10 -0
  28. package/lib/openapi/models/ChatCompletionDto.js +1 -0
  29. package/lib/openapi/models/ChatCompletionStreamCompletedEventDto.d.ts +9 -0
  30. package/lib/openapi/models/ChatCompletionStreamCompletedEventDto.js +1 -0
  31. package/lib/openapi/models/CreateAnthropicChatCompletionDto.d.ts +8 -0
  32. package/lib/openapi/models/CreateAnthropicChatCompletionDto.js +1 -0
  33. package/lib/openapi/models/CreateChatCompletionRequest.d.ts +10 -0
  34. package/lib/openapi/models/CreateChatCompletionRequest.js +1 -0
  35. package/lib/openapi/models/CreateChatCompletionStreamRequest.d.ts +3 -0
  36. package/lib/openapi/models/CreateChatCompletionStreamRequest.js +1 -0
  37. package/lib/openapi/models/CreateGeminiChatCompletionDto.d.ts +8 -0
  38. package/lib/openapi/models/CreateGeminiChatCompletionDto.js +1 -0
  39. package/lib/openapi/models/CreateOpenAiChatCompletionDto.d.ts +8 -0
  40. package/lib/openapi/models/CreateOpenAiChatCompletionDto.js +1 -0
  41. package/lib/openapi/models/CreateOpenAiChatCompletionMessageDto.d.ts +4 -0
  42. package/lib/openapi/models/CreateOpenAiChatCompletionMessageDto.js +1 -0
  43. package/lib/openapi/models/CreateStreamRequest.d.ts +6 -0
  44. package/lib/openapi/models/CreateStreamRequest.js +1 -0
  45. package/lib/openapi/models/CreateWebsiteRequest.d.ts +3 -0
  46. package/lib/openapi/models/CreateWebsiteRequest.js +1 -0
  47. package/lib/openapi/models/FileUploadCompletedEventDto.d.ts +11 -0
  48. package/lib/openapi/models/FileUploadCompletedEventDto.js +1 -0
  49. package/lib/openapi/models/NewChatCompletionStreamChunkEventDto.d.ts +10 -0
  50. package/lib/openapi/models/NewChatCompletionStreamChunkEventDto.js +1 -0
  51. package/lib/openapi/models/PubCreateUploadRequest.d.ts +6 -0
  52. package/lib/openapi/models/PubCreateUploadRequest.js +1 -0
  53. package/lib/openapi/models/PubUploadDto.d.ts +6 -0
  54. package/lib/openapi/models/PubUploadDto.js +1 -0
  55. package/lib/openapi/models/PubWebsiteDto.d.ts +5 -0
  56. package/lib/openapi/models/PubWebsiteDto.js +1 -0
  57. package/lib/openapi/models/S3PostRequestDto.d.ts +10 -0
  58. package/lib/openapi/models/S3PostRequestDto.js +1 -0
  59. package/lib/openapi/models/StoredChatCompletionId.d.ts +3 -0
  60. package/lib/openapi/models/StoredChatCompletionId.js +1 -0
  61. package/lib/openapi/models/StoredFileId.d.ts +3 -0
  62. package/lib/openapi/models/StoredFileId.js +1 -0
  63. package/lib/openapi/models/StoredStreamId.d.ts +3 -0
  64. package/lib/openapi/models/StoredStreamId.js +1 -0
  65. package/lib/openapi/models/StoredUploadId.d.ts +3 -0
  66. package/lib/openapi/models/StoredUploadId.js +1 -0
  67. package/lib/openapi/models/StreamDto.d.ts +6 -0
  68. package/lib/openapi/models/StreamDto.js +1 -0
  69. package/lib/openapi/models/StreamEventType.d.ts +7 -0
  70. package/lib/openapi/models/StreamEventType.js +12 -0
  71. package/lib/openapi/models/StreamNotFoundEventDto.d.ts +7 -0
  72. package/lib/openapi/models/StreamNotFoundEventDto.js +1 -0
  73. package/lib/openapi/models/StreamTimeoutEventDto.d.ts +7 -0
  74. package/lib/openapi/models/StreamTimeoutEventDto.js +1 -0
  75. package/lib/openapi/models/StreamType.d.ts +4 -0
  76. package/lib/openapi/models/StreamType.js +9 -0
  77. package/lib/openapi/services/PubService.d.ts +50 -0
  78. package/lib/openapi/services/PubService.js +71 -0
  79. package/lib/types/ApiError.d.ts +0 -1
  80. package/lib/types/ApiError.js +1 -8
  81. package/lib/types/CreateStreamRequest.d.ts +6 -0
  82. package/lib/types/CreateStreamRequest.js +1 -0
  83. package/lib/types/CreateStreamResponse.d.ts +9 -0
  84. package/lib/types/CreateStreamResponse.js +1 -0
  85. package/lib/types/CreateUploadRequest.d.ts +6 -0
  86. package/lib/types/CreateUploadRequest.js +1 -0
  87. package/lib/types/CreateUploadResponse.d.ts +9 -0
  88. package/lib/types/CreateUploadResponse.js +1 -0
  89. package/lib/types/CreateWebsiteRequest.d.ts +3 -0
  90. package/lib/types/CreateWebsiteRequest.js +1 -0
  91. package/lib/types/CreateWebsiteResponse.d.ts +9 -0
  92. package/lib/types/CreateWebsiteResponse.js +1 -0
  93. package/lib/types/FencyFile.d.ts +8 -0
  94. package/lib/types/FencyFile.js +1 -0
  95. package/lib/types/FencyUpload.d.ts +6 -0
  96. package/lib/types/FencyUpload.js +1 -0
  97. package/lib/types/FencyWebsite.d.ts +5 -0
  98. package/lib/types/FencyWebsite.js +1 -0
  99. package/lib/types/S3PostRequest.d.ts +10 -0
  100. package/lib/types/S3PostRequest.js +1 -0
  101. package/lib/types/Stream.d.ts +5 -0
  102. package/lib/types/{ChatCompletionStream.js → Stream.js} +2 -2
  103. package/lib/types/StreamData.d.ts +31 -0
  104. package/lib/types/StreamData.js +1 -0
  105. package/lib/utils/parseApiError.d.ts +2 -0
  106. package/lib/utils/parseApiError.js +14 -0
  107. package/lib/utils/parseErrorBody.d.ts +1 -0
  108. package/lib/utils/parseErrorBody.js +8 -0
  109. package/lib/utils/parseNonOkResponse.d.ts +2 -0
  110. package/lib/utils/parseNonOkResponse.js +35 -0
  111. package/lib/utils/version.js +1 -1
  112. package/package.json +5 -3
  113. package/lib/api/createChatCompletionStream.d.ts +0 -21
  114. package/lib/api/createChatCompletionStream.js +0 -44
  115. package/lib/types/ChatCompletionStream.d.ts +0 -5
@@ -1,10 +1,6 @@
1
1
  import { ApiError } from '../types/ApiError';
2
2
  import { ChatCompletion } from '../types/ChatCompletion';
3
3
  import { CreateChatCompletionRequest } from '../types/CreateChatCompletionRequest';
4
- export interface CreateChatCompletionOptions {
5
- apiUrl?: string;
6
- request: CreateChatCompletionRequest;
7
- }
8
4
  /**
9
5
  * Creates a chat completion by making a POST request to the Fency API.
10
6
  *
@@ -1,46 +1,32 @@
1
- import { isApiError } from '../types/ApiError';
2
- import { isChatCompletion } from '../types/ChatCompletion';
1
+ import { OpenAPI, PubService } from '../openapi';
3
2
  import { getPackageVersion } from '../utils/version';
4
3
  export async function createChatCompletion(params) {
5
- const apiUrl = `${params.baseUrl}/v1/pub/chat-completions`;
6
- console.log('request', params.request);
7
- const response = await fetch(apiUrl, {
8
- method: 'POST',
9
- headers: {
4
+ try {
5
+ OpenAPI.BASE = params.baseUrl;
6
+ OpenAPI.HEADERS = {
10
7
  'Content-Type': 'application/json',
11
8
  Authorization: `Bearer ${params.pk}`,
12
9
  'X-Fency-Sdk-Version': getPackageVersion(),
13
- },
14
- body: JSON.stringify(params.request),
15
- });
16
- if (!response.ok) {
17
- const error = await response.json();
18
- if (isApiError(error)) {
19
- return {
20
- type: 'error',
21
- error,
22
- };
23
- }
10
+ };
11
+ const response = await PubService.createChatCompletion(params.request);
24
12
  return {
25
- type: 'error',
26
- error: {
27
- code: 'UnknownError',
28
- message: `Unknown error: ${JSON.stringify(error)}`,
13
+ type: 'success',
14
+ completion: {
15
+ id: response.id,
16
+ createdAt: response.createdAt,
17
+ streamId: response.streamId ?? undefined,
18
+ response: response.response ?? undefined,
19
+ responseIsStructured: response.responseIsStructured ?? undefined,
29
20
  },
30
21
  };
31
22
  }
32
- const completion = await response.json();
33
- if (!isChatCompletion(completion)) {
23
+ catch (error) {
34
24
  return {
35
25
  type: 'error',
36
26
  error: {
37
- code: 'InvalidResponse',
38
- message: `Invalid chat completion response: ${JSON.stringify(completion)}`,
27
+ code: 'UnknownError',
28
+ message: `Unknown error!\n${error ? `Error: ${error}\n` : ''}`.trim(),
39
29
  },
40
30
  };
41
31
  }
42
- return {
43
- type: 'success',
44
- completion,
45
- };
46
32
  }
@@ -0,0 +1,14 @@
1
+ import { CreateStreamRequest, CreateStreamResponse } from '..';
2
+ /**
3
+ * Creates a new stream by making a POST request to the Fency API.
4
+ *
5
+ * @param pk - The publishable key (used as Bearer token and default name)
6
+ * @param options - Optional configuration (apiUrl, name)
7
+ * @returns A promise that resolves to a Stream
8
+ * @throws Error if the request fails or the response is invalid
9
+ */
10
+ export declare function createStream(params: {
11
+ pk: string;
12
+ request: CreateStreamRequest;
13
+ baseUrl: string;
14
+ }): Promise<CreateStreamResponse>;
@@ -0,0 +1,53 @@
1
+ import { OpenAPI, PubService, StreamType } from '../openapi';
2
+ import { getPackageVersion } from '../utils/version';
3
+ /**
4
+ * Creates a new stream by making a POST request to the Fency API.
5
+ *
6
+ * @param pk - The publishable key (used as Bearer token and default name)
7
+ * @param options - Optional configuration (apiUrl, name)
8
+ * @returns A promise that resolves to a Stream
9
+ * @throws Error if the request fails or the response is invalid
10
+ */
11
+ export async function createStream(params) {
12
+ try {
13
+ OpenAPI.BASE = params.baseUrl;
14
+ OpenAPI.HEADERS = {
15
+ 'Content-Type': 'application/json',
16
+ Authorization: `Bearer ${params.pk}`,
17
+ 'X-Fency-Sdk-Version': getPackageVersion(),
18
+ };
19
+ const response = await PubService.createStream({
20
+ type: mapTypeToStreamType(params.request.type),
21
+ chatCompletionStream: params.request.type === 'ChatCompletionStream'
22
+ ? {
23
+ clientSecret: params.request.chatCompletionStreamOptions
24
+ ?.sessionClientSecret,
25
+ }
26
+ : undefined,
27
+ });
28
+ return {
29
+ type: 'success',
30
+ stream: {
31
+ id: response.id,
32
+ createdAt: response.createdAt,
33
+ },
34
+ };
35
+ }
36
+ catch (error) {
37
+ return {
38
+ type: 'error',
39
+ error: {
40
+ code: 'UnknownError',
41
+ message: `Unknown error!\n${error ? `Error: ${error}\n` : ''}`.trim(),
42
+ },
43
+ };
44
+ }
45
+ }
46
+ const mapTypeToStreamType = (type) => {
47
+ switch (type) {
48
+ case 'ChatCompletionStream':
49
+ return StreamType.CHAT_COMPLETION_STREAM;
50
+ case 'FileUploadStream':
51
+ return StreamType.FILE_UPLOAD_STREAM;
52
+ }
53
+ };
@@ -0,0 +1,16 @@
1
+ import { CreateUploadRequest } from '../types/CreateUploadRequest';
2
+ import { CreateUploadResponse } from '../types/CreateUploadResponse';
3
+ /**
4
+ * Creates a website by making a POST request to the Fency API.
5
+ *
6
+ * @param pk - The publishable key (used as Bearer token)
7
+ * @param request - The request body
8
+ * @param options - Optional configuration (apiUrl, request overrides)
9
+ * @returns A promise that resolves to a CreateWebsiteResponse
10
+ * @throws Error if the request fails or the response is invalid
11
+ */
12
+ export declare function createUpload(params: {
13
+ pk: string;
14
+ request: CreateUploadRequest;
15
+ baseUrl: string;
16
+ }): Promise<CreateUploadResponse>;
@@ -0,0 +1,53 @@
1
+ import { OpenAPI, PubService } from '../openapi';
2
+ import { getPackageVersion } from '../utils/version';
3
+ /**
4
+ * Creates a website by making a POST request to the Fency API.
5
+ *
6
+ * @param pk - The publishable key (used as Bearer token)
7
+ * @param request - The request body
8
+ * @param options - Optional configuration (apiUrl, request overrides)
9
+ * @returns A promise that resolves to a CreateWebsiteResponse
10
+ * @throws Error if the request fails or the response is invalid
11
+ */
12
+ export async function createUpload(params) {
13
+ try {
14
+ OpenAPI.BASE = params.baseUrl;
15
+ OpenAPI.HEADERS = {
16
+ 'Content-Type': 'application/json',
17
+ Authorization: `Bearer ${params.pk}`,
18
+ 'X-Fency-Sdk-Version': getPackageVersion(),
19
+ };
20
+ const response = await PubService.createUpload({
21
+ streamId: params.request.streamId,
22
+ fileName: params.request.fileName,
23
+ mimeType: params.request.fileType,
24
+ fileSize: params.request.fileSize,
25
+ });
26
+ return {
27
+ type: 'success',
28
+ upload: {
29
+ id: response.id,
30
+ createdAt: response.createdAt,
31
+ s3PostRequest: {
32
+ xAmzDate: response.s3PostRequest.amzDate,
33
+ xAmzSignature: response.s3PostRequest.amzSignature,
34
+ xAmzAlgorithm: response.s3PostRequest.amzAlgorithm,
35
+ xAmzCredential: response.s3PostRequest.amzCredential,
36
+ policy: response.s3PostRequest.policy,
37
+ key: response.s3PostRequest.key,
38
+ uploadUrl: response.s3PostRequest.uploadUrl,
39
+ sessionToken: response.s3PostRequest.sessionToken,
40
+ },
41
+ },
42
+ };
43
+ }
44
+ catch (error) {
45
+ return {
46
+ type: 'error',
47
+ error: {
48
+ code: 'UnknownError',
49
+ message: `Unknown error!\n${error ? `Error: ${error}\n` : ''}`.trim(),
50
+ },
51
+ };
52
+ }
53
+ }
@@ -0,0 +1,16 @@
1
+ import { CreateWebsiteRequest } from '../types/CreateWebsiteRequest';
2
+ import { CreateWebsiteResponse } from '../types/CreateWebsiteResponse';
3
+ /**
4
+ * Creates a website by making a POST request to the Fency API.
5
+ *
6
+ * @param pk - The publishable key (used as Bearer token)
7
+ * @param request - The request body
8
+ * @param options - Optional configuration (apiUrl, request overrides)
9
+ * @returns A promise that resolves to a CreateWebsiteResponse
10
+ * @throws Error if the request fails or the response is invalid
11
+ */
12
+ export declare function createWebsite(params: {
13
+ pk: string;
14
+ request: CreateWebsiteRequest;
15
+ baseUrl: string;
16
+ }): Promise<CreateWebsiteResponse>;
@@ -0,0 +1,39 @@
1
+ import { OpenAPI, PubService } from '../openapi';
2
+ import { getPackageVersion } from '../utils/version';
3
+ /**
4
+ * Creates a website by making a POST request to the Fency API.
5
+ *
6
+ * @param pk - The publishable key (used as Bearer token)
7
+ * @param request - The request body
8
+ * @param options - Optional configuration (apiUrl, request overrides)
9
+ * @returns A promise that resolves to a CreateWebsiteResponse
10
+ * @throws Error if the request fails or the response is invalid
11
+ */
12
+ export async function createWebsite(params) {
13
+ try {
14
+ OpenAPI.BASE = params.baseUrl;
15
+ OpenAPI.HEADERS = {
16
+ 'Content-Type': 'application/json',
17
+ Authorization: `Bearer ${params.pk}`,
18
+ 'X-Fency-Sdk-Version': getPackageVersion(),
19
+ };
20
+ const response = await PubService.createWebsite(params.request);
21
+ return {
22
+ type: 'success',
23
+ website: {
24
+ id: response.id,
25
+ createdAt: response.createdAt,
26
+ content: response.content,
27
+ },
28
+ };
29
+ }
30
+ catch (error) {
31
+ return {
32
+ type: 'error',
33
+ error: {
34
+ code: 'UnknownError',
35
+ message: `Unknown error!\n${error ? `Error: ${error}\n` : ''}`.trim(),
36
+ },
37
+ };
38
+ }
39
+ }
package/lib/index.d.ts CHANGED
@@ -1,24 +1,37 @@
1
1
  import { createChatCompletion } from './api/createChatCompletion';
2
- import { createChatCompletionStream } from './api/createChatCompletionStream';
2
+ import { createStream } from './api/createStream';
3
3
  import { loadFency } from './loadFency';
4
- export type { FencyInstance, FencyOptions, } from './types';
4
+ export type { FencyInstance, FencyOptions } from './types';
5
+ export type { AnthropicModel } from './types/AnthropicModel';
5
6
  export type { ChatCompletion, isChatCompletion } from './types/ChatCompletion';
6
7
  export type { ChatCompletionMessage } from './types/ChatCompletionMessage';
7
- export type { ChatCompletionStream } from './types/ChatCompletionStream';
8
- export type { CreateChatCompletionRequest } from './types/CreateChatCompletionRequest';
9
8
  export type { CreateAnthropicChatCompletionParams } from './types/CreateAnthropicChatCompletionParams';
9
+ export type { CreateChatCompletionRequest } from './types/CreateChatCompletionRequest';
10
10
  export type { CreateGeminiChatCompletionParams } from './types/CreateGeminiChatCompletionParams';
11
11
  export type { CreateOpenAiChatCompletionParams } from './types/CreateOpenAiChatCompletionParams';
12
- export type { AnthropicModel } from './types/AnthropicModel';
12
+ export type { CreateStreamRequest } from './types/CreateStreamRequest';
13
+ export type { CreateStreamResponse } from './types/CreateStreamResponse';
14
+ export type { CreateWebsiteRequest } from './types/CreateWebsiteRequest';
15
+ export type { FencyUpload } from './types/FencyUpload';
16
+ export type { FencyWebsite } from './types/FencyWebsite';
13
17
  export type { GeminiModel } from './types/GeminiModel';
14
18
  export type { OpenAiModel } from './types/OpenAiModel';
19
+ export type { Stream } from './types/Stream';
15
20
  export { createChatCompletion } from './api/createChatCompletion';
16
- export type { CreateChatCompletionOptions } from './api/createChatCompletion';
17
- export { createChatCompletionStream } from './api/createChatCompletionStream';
21
+ export type { CreateChatCompletionResponse } from './api/createChatCompletion';
22
+ export { createUpload } from './api/createUpload';
23
+ export type { CreateUploadRequest } from './types/CreateUploadRequest';
24
+ export type { CreateUploadResponse } from './types/CreateUploadResponse';
25
+ export type { FencyFile } from './types/FencyFile';
26
+ export { createStream } from './api/createStream';
27
+ export type { ChatCompletionStreamCompleted, FileUploadCompleted, NewChatCompletionStreamChunk, StreamData, StreamNotFound, StreamTimeout, } from './types/StreamData';
28
+ export { createWebsite } from './api/createWebsite';
29
+ export type { CreateWebsiteResponse } from './types/CreateWebsiteResponse';
18
30
  export { loadFency } from './loadFency';
31
+ export type { ApiError } from './types/ApiError';
19
32
  declare const _default: {
20
33
  loadFency: typeof loadFency;
21
34
  createChatCompletion: typeof createChatCompletion;
22
- createChatCompletionStream: typeof createChatCompletionStream;
35
+ createStream: typeof createStream;
23
36
  };
24
37
  export default _default;
package/lib/index.js CHANGED
@@ -2,15 +2,21 @@
2
2
  // This is the base library that provides the loadFency method
3
3
  // Import main functions
4
4
  import { createChatCompletion } from './api/createChatCompletion';
5
- import { createChatCompletionStream } from './api/createChatCompletionStream';
5
+ import { createStream } from './api/createStream';
6
6
  import { loadFency } from './loadFency';
7
- // Re-export main functions
7
+ // create chat completion
8
8
  export { createChatCompletion } from './api/createChatCompletion';
9
- export { createChatCompletionStream } from './api/createChatCompletionStream';
9
+ // uploads
10
+ export { createUpload } from './api/createUpload';
11
+ // create chat completion stream
12
+ export { createStream } from './api/createStream';
13
+ // create website
14
+ export { createWebsite } from './api/createWebsite';
15
+ // load fency
10
16
  export { loadFency } from './loadFency';
11
17
  // Default export for convenience
12
18
  export default {
13
19
  loadFency,
14
20
  createChatCompletion,
15
- createChatCompletionStream,
21
+ createStream,
16
22
  };
@@ -0,0 +1,10 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ import type { ApiResult } from './ApiResult';
3
+ export declare class ApiError extends Error {
4
+ readonly url: string;
5
+ readonly status: number;
6
+ readonly statusText: string;
7
+ readonly body: any;
8
+ readonly request: ApiRequestOptions;
9
+ constructor(request: ApiRequestOptions, response: ApiResult, message: string);
10
+ }
@@ -0,0 +1,11 @@
1
+ export class ApiError extends Error {
2
+ constructor(request, response, message) {
3
+ super(message);
4
+ this.name = 'ApiError';
5
+ this.url = response.url;
6
+ this.status = response.status;
7
+ this.statusText = response.statusText;
8
+ this.body = response.body;
9
+ this.request = request;
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ export type ApiRequestOptions = {
2
+ readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
3
+ readonly url: string;
4
+ readonly path?: Record<string, any>;
5
+ readonly cookies?: Record<string, any>;
6
+ readonly headers?: Record<string, any>;
7
+ readonly query?: Record<string, any>;
8
+ readonly formData?: Record<string, any>;
9
+ readonly body?: any;
10
+ readonly mediaType?: string;
11
+ readonly responseHeader?: string;
12
+ readonly errors?: Record<number, string>;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export type ApiResult = {
2
+ readonly url: string;
3
+ readonly ok: boolean;
4
+ readonly status: number;
5
+ readonly statusText: string;
6
+ readonly body: any;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ export declare class CancelError extends Error {
2
+ constructor(message: string);
3
+ get isCancelled(): boolean;
4
+ }
5
+ export interface OnCancel {
6
+ readonly isResolved: boolean;
7
+ readonly isRejected: boolean;
8
+ readonly isCancelled: boolean;
9
+ (cancelHandler: () => void): void;
10
+ }
11
+ export declare class CancelablePromise<T> implements Promise<T> {
12
+ #private;
13
+ constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: OnCancel) => void);
14
+ get [Symbol.toStringTag](): string;
15
+ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
16
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
17
+ finally(onFinally?: (() => void) | null): Promise<T>;
18
+ cancel(): void;
19
+ get isCancelled(): boolean;
20
+ }
@@ -0,0 +1,111 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _CancelablePromise_isResolved, _CancelablePromise_isRejected, _CancelablePromise_isCancelled, _CancelablePromise_cancelHandlers, _CancelablePromise_promise, _CancelablePromise_resolve, _CancelablePromise_reject;
13
+ /* generated using openapi-typescript-codegen -- do not edit */
14
+ /* istanbul ignore file */
15
+ /* tslint:disable */
16
+ /* eslint-disable */
17
+ export class CancelError extends Error {
18
+ constructor(message) {
19
+ super(message);
20
+ this.name = 'CancelError';
21
+ }
22
+ get isCancelled() {
23
+ return true;
24
+ }
25
+ }
26
+ export class CancelablePromise {
27
+ constructor(executor) {
28
+ _CancelablePromise_isResolved.set(this, void 0);
29
+ _CancelablePromise_isRejected.set(this, void 0);
30
+ _CancelablePromise_isCancelled.set(this, void 0);
31
+ _CancelablePromise_cancelHandlers.set(this, void 0);
32
+ _CancelablePromise_promise.set(this, void 0);
33
+ _CancelablePromise_resolve.set(this, void 0);
34
+ _CancelablePromise_reject.set(this, void 0);
35
+ __classPrivateFieldSet(this, _CancelablePromise_isResolved, false, "f");
36
+ __classPrivateFieldSet(this, _CancelablePromise_isRejected, false, "f");
37
+ __classPrivateFieldSet(this, _CancelablePromise_isCancelled, false, "f");
38
+ __classPrivateFieldSet(this, _CancelablePromise_cancelHandlers, [], "f");
39
+ __classPrivateFieldSet(this, _CancelablePromise_promise, new Promise((resolve, reject) => {
40
+ __classPrivateFieldSet(this, _CancelablePromise_resolve, resolve, "f");
41
+ __classPrivateFieldSet(this, _CancelablePromise_reject, reject, "f");
42
+ const onResolve = (value) => {
43
+ if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
44
+ return;
45
+ }
46
+ __classPrivateFieldSet(this, _CancelablePromise_isResolved, true, "f");
47
+ if (__classPrivateFieldGet(this, _CancelablePromise_resolve, "f"))
48
+ __classPrivateFieldGet(this, _CancelablePromise_resolve, "f").call(this, value);
49
+ };
50
+ const onReject = (reason) => {
51
+ if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
52
+ return;
53
+ }
54
+ __classPrivateFieldSet(this, _CancelablePromise_isRejected, true, "f");
55
+ if (__classPrivateFieldGet(this, _CancelablePromise_reject, "f"))
56
+ __classPrivateFieldGet(this, _CancelablePromise_reject, "f").call(this, reason);
57
+ };
58
+ const onCancel = (cancelHandler) => {
59
+ if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
60
+ return;
61
+ }
62
+ __classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f").push(cancelHandler);
63
+ };
64
+ Object.defineProperty(onCancel, 'isResolved', {
65
+ get: () => __classPrivateFieldGet(this, _CancelablePromise_isResolved, "f"),
66
+ });
67
+ Object.defineProperty(onCancel, 'isRejected', {
68
+ get: () => __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f"),
69
+ });
70
+ Object.defineProperty(onCancel, 'isCancelled', {
71
+ get: () => __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f"),
72
+ });
73
+ return executor(onResolve, onReject, onCancel);
74
+ }), "f");
75
+ }
76
+ get [(_CancelablePromise_isResolved = new WeakMap(), _CancelablePromise_isRejected = new WeakMap(), _CancelablePromise_isCancelled = new WeakMap(), _CancelablePromise_cancelHandlers = new WeakMap(), _CancelablePromise_promise = new WeakMap(), _CancelablePromise_resolve = new WeakMap(), _CancelablePromise_reject = new WeakMap(), Symbol.toStringTag)]() {
77
+ return "Cancellable Promise";
78
+ }
79
+ then(onFulfilled, onRejected) {
80
+ return __classPrivateFieldGet(this, _CancelablePromise_promise, "f").then(onFulfilled, onRejected);
81
+ }
82
+ catch(onRejected) {
83
+ return __classPrivateFieldGet(this, _CancelablePromise_promise, "f").catch(onRejected);
84
+ }
85
+ finally(onFinally) {
86
+ return __classPrivateFieldGet(this, _CancelablePromise_promise, "f").finally(onFinally);
87
+ }
88
+ cancel() {
89
+ if (__classPrivateFieldGet(this, _CancelablePromise_isResolved, "f") || __classPrivateFieldGet(this, _CancelablePromise_isRejected, "f") || __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f")) {
90
+ return;
91
+ }
92
+ __classPrivateFieldSet(this, _CancelablePromise_isCancelled, true, "f");
93
+ if (__classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f").length) {
94
+ try {
95
+ for (const cancelHandler of __classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f")) {
96
+ cancelHandler();
97
+ }
98
+ }
99
+ catch (error) {
100
+ console.warn('Cancellation threw an error', error);
101
+ return;
102
+ }
103
+ }
104
+ __classPrivateFieldGet(this, _CancelablePromise_cancelHandlers, "f").length = 0;
105
+ if (__classPrivateFieldGet(this, _CancelablePromise_reject, "f"))
106
+ __classPrivateFieldGet(this, _CancelablePromise_reject, "f").call(this, new CancelError('Request aborted'));
107
+ }
108
+ get isCancelled() {
109
+ return __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f");
110
+ }
111
+ }
@@ -0,0 +1,16 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
3
+ type Headers = Record<string, string>;
4
+ export type OpenAPIConfig = {
5
+ BASE: string;
6
+ VERSION: string;
7
+ WITH_CREDENTIALS: boolean;
8
+ CREDENTIALS: 'include' | 'omit' | 'same-origin';
9
+ TOKEN?: string | Resolver<string> | undefined;
10
+ USERNAME?: string | Resolver<string> | undefined;
11
+ PASSWORD?: string | Resolver<string> | undefined;
12
+ HEADERS?: Headers | Resolver<Headers> | undefined;
13
+ ENCODE_PATH?: ((path: string) => string) | undefined;
14
+ };
15
+ export declare const OpenAPI: OpenAPIConfig;
16
+ export {};
@@ -0,0 +1,11 @@
1
+ export const OpenAPI = {
2
+ BASE: '',
3
+ VERSION: '1.0',
4
+ WITH_CREDENTIALS: false,
5
+ CREDENTIALS: 'include',
6
+ TOKEN: undefined,
7
+ USERNAME: undefined,
8
+ PASSWORD: undefined,
9
+ HEADERS: undefined,
10
+ ENCODE_PATH: undefined,
11
+ };
@@ -0,0 +1,30 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ import type { ApiResult } from './ApiResult';
3
+ import { CancelablePromise } from './CancelablePromise';
4
+ import type { OnCancel } from './CancelablePromise';
5
+ import type { OpenAPIConfig } from './OpenAPI';
6
+ export declare const isDefined: <T>(value: T | null | undefined) => value is Exclude<T, null | undefined>;
7
+ export declare const isString: (value: any) => value is string;
8
+ export declare const isStringWithValue: (value: any) => value is string;
9
+ export declare const isBlob: (value: any) => value is Blob;
10
+ export declare const isFormData: (value: any) => value is FormData;
11
+ export declare const base64: (str: string) => string;
12
+ export declare const getQueryString: (params: Record<string, any>) => string;
13
+ export declare const getFormData: (options: ApiRequestOptions) => FormData | undefined;
14
+ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
15
+ export declare const resolve: <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>) => Promise<T | undefined>;
16
+ export declare const getHeaders: (config: OpenAPIConfig, options: ApiRequestOptions) => Promise<Headers>;
17
+ export declare const getRequestBody: (options: ApiRequestOptions) => any;
18
+ export declare const sendRequest: (config: OpenAPIConfig, options: ApiRequestOptions, url: string, body: any, formData: FormData | undefined, headers: Headers, onCancel: OnCancel) => Promise<Response>;
19
+ export declare const getResponseHeader: (response: Response, responseHeader?: string) => string | undefined;
20
+ export declare const getResponseBody: (response: Response) => Promise<any>;
21
+ export declare const catchErrorCodes: (options: ApiRequestOptions, result: ApiResult) => void;
22
+ /**
23
+ * Request method
24
+ * @param config The OpenAPI configuration object
25
+ * @param options The request options from the service
26
+ * @returns CancelablePromise<T>
27
+ * @throws ApiError
28
+ */
29
+ export declare const request: <T>(config: OpenAPIConfig, options: ApiRequestOptions) => CancelablePromise<T>;
30
+ export {};