@teemill/gfn-catalog 1.4.0 → 2.0.0

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 (164) hide show
  1. package/.openapi-generator/FILES +7 -28
  2. package/README.md +3 -3
  3. package/api.ts +1646 -0
  4. package/base.ts +86 -0
  5. package/common.ts +150 -0
  6. package/configuration.ts +110 -0
  7. package/dist/api.d.ts +1074 -0
  8. package/dist/api.js +1014 -0
  9. package/dist/base.d.ts +66 -0
  10. package/dist/base.js +65 -0
  11. package/dist/common.d.ts +65 -0
  12. package/dist/common.js +161 -0
  13. package/dist/configuration.d.ts +91 -0
  14. package/dist/configuration.js +43 -0
  15. package/dist/esm/api.d.ts +1074 -0
  16. package/dist/esm/api.js +995 -0
  17. package/dist/esm/base.d.ts +66 -0
  18. package/dist/esm/{models/AttributeThumbnail.js → base.js} +38 -26
  19. package/dist/esm/common.d.ts +65 -0
  20. package/dist/esm/common.js +149 -0
  21. package/dist/esm/configuration.d.ts +91 -0
  22. package/dist/esm/configuration.js +39 -0
  23. package/dist/esm/index.d.ts +13 -3
  24. package/dist/esm/index.js +13 -3
  25. package/dist/index.d.ts +13 -3
  26. package/dist/index.js +15 -5
  27. package/git_push.sh +57 -0
  28. package/{dist/models/Stock.d.ts → index.ts} +8 -21
  29. package/package.json +14 -2
  30. package/tsconfig.json +4 -6
  31. package/dist/apis/ProductsApi.d.ts +0 -35
  32. package/dist/apis/ProductsApi.js +0 -85
  33. package/dist/apis/StatementsApi.d.ts +0 -48
  34. package/dist/apis/StatementsApi.js +0 -127
  35. package/dist/apis/TransactionsApi.d.ts +0 -48
  36. package/dist/apis/TransactionsApi.js +0 -129
  37. package/dist/apis/VariantsApi.d.ts +0 -82
  38. package/dist/apis/VariantsApi.js +0 -229
  39. package/dist/apis/index.d.ts +0 -4
  40. package/dist/apis/index.js +0 -22
  41. package/dist/esm/apis/ProductsApi.d.ts +0 -35
  42. package/dist/esm/apis/ProductsApi.js +0 -81
  43. package/dist/esm/apis/StatementsApi.d.ts +0 -48
  44. package/dist/esm/apis/StatementsApi.js +0 -123
  45. package/dist/esm/apis/TransactionsApi.d.ts +0 -48
  46. package/dist/esm/apis/TransactionsApi.js +0 -125
  47. package/dist/esm/apis/VariantsApi.d.ts +0 -82
  48. package/dist/esm/apis/VariantsApi.js +0 -225
  49. package/dist/esm/apis/index.d.ts +0 -4
  50. package/dist/esm/apis/index.js +0 -6
  51. package/dist/esm/models/ApiError.d.ts +0 -37
  52. package/dist/esm/models/ApiError.js +0 -42
  53. package/dist/esm/models/ApiValidationError.d.ts +0 -39
  54. package/dist/esm/models/ApiValidationError.js +0 -44
  55. package/dist/esm/models/Attribute.d.ts +0 -50
  56. package/dist/esm/models/Attribute.js +0 -49
  57. package/dist/esm/models/AttributeThumbnail.d.ts +0 -46
  58. package/dist/esm/models/ExportTransactionsRequest.d.ts +0 -43
  59. package/dist/esm/models/ExportTransactionsRequest.js +0 -42
  60. package/dist/esm/models/Image.d.ts +0 -67
  61. package/dist/esm/models/Image.js +0 -50
  62. package/dist/esm/models/ListStatements200Response.d.ts +0 -38
  63. package/dist/esm/models/ListStatements200Response.js +0 -41
  64. package/dist/esm/models/ListTransactions200Response.d.ts +0 -38
  65. package/dist/esm/models/ListTransactions200Response.js +0 -41
  66. package/dist/esm/models/Product.d.ts +0 -67
  67. package/dist/esm/models/Product.js +0 -52
  68. package/dist/esm/models/ProductsResponse.d.ts +0 -38
  69. package/dist/esm/models/ProductsResponse.js +0 -41
  70. package/dist/esm/models/Statement.d.ts +0 -61
  71. package/dist/esm/models/Statement.js +0 -60
  72. package/dist/esm/models/Stock.d.ts +0 -31
  73. package/dist/esm/models/Stock.js +0 -38
  74. package/dist/esm/models/StockResponse.d.ts +0 -38
  75. package/dist/esm/models/StockResponse.js +0 -41
  76. package/dist/esm/models/Transaction.d.ts +0 -68
  77. package/dist/esm/models/Transaction.js +0 -61
  78. package/dist/esm/models/TransactionOrder.d.ts +0 -37
  79. package/dist/esm/models/TransactionOrder.js +0 -44
  80. package/dist/esm/models/Variant.d.ts +0 -78
  81. package/dist/esm/models/Variant.js +0 -61
  82. package/dist/esm/models/VariantManufacturerOrigin.d.ts +0 -37
  83. package/dist/esm/models/VariantManufacturerOrigin.js +0 -40
  84. package/dist/esm/models/VariantProduct.d.ts +0 -37
  85. package/dist/esm/models/VariantProduct.js +0 -40
  86. package/dist/esm/models/VariantStock.d.ts +0 -50
  87. package/dist/esm/models/VariantStock.js +0 -45
  88. package/dist/esm/models/VariantsResponse.d.ts +0 -38
  89. package/dist/esm/models/VariantsResponse.js +0 -41
  90. package/dist/esm/models/index.d.ts +0 -20
  91. package/dist/esm/models/index.js +0 -22
  92. package/dist/esm/runtime.d.ts +0 -187
  93. package/dist/esm/runtime.js +0 -333
  94. package/dist/models/ApiError.d.ts +0 -37
  95. package/dist/models/ApiError.js +0 -49
  96. package/dist/models/ApiValidationError.d.ts +0 -39
  97. package/dist/models/ApiValidationError.js +0 -51
  98. package/dist/models/Attribute.d.ts +0 -50
  99. package/dist/models/Attribute.js +0 -56
  100. package/dist/models/AttributeThumbnail.d.ts +0 -46
  101. package/dist/models/AttributeThumbnail.js +0 -55
  102. package/dist/models/ExportTransactionsRequest.d.ts +0 -43
  103. package/dist/models/ExportTransactionsRequest.js +0 -49
  104. package/dist/models/Image.d.ts +0 -67
  105. package/dist/models/Image.js +0 -57
  106. package/dist/models/ListStatements200Response.d.ts +0 -38
  107. package/dist/models/ListStatements200Response.js +0 -48
  108. package/dist/models/ListTransactions200Response.d.ts +0 -38
  109. package/dist/models/ListTransactions200Response.js +0 -48
  110. package/dist/models/Product.d.ts +0 -67
  111. package/dist/models/Product.js +0 -59
  112. package/dist/models/ProductsResponse.d.ts +0 -38
  113. package/dist/models/ProductsResponse.js +0 -48
  114. package/dist/models/Statement.d.ts +0 -61
  115. package/dist/models/Statement.js +0 -67
  116. package/dist/models/Stock.js +0 -45
  117. package/dist/models/StockResponse.d.ts +0 -38
  118. package/dist/models/StockResponse.js +0 -48
  119. package/dist/models/Transaction.d.ts +0 -68
  120. package/dist/models/Transaction.js +0 -68
  121. package/dist/models/TransactionOrder.d.ts +0 -37
  122. package/dist/models/TransactionOrder.js +0 -51
  123. package/dist/models/Variant.d.ts +0 -78
  124. package/dist/models/Variant.js +0 -68
  125. package/dist/models/VariantManufacturerOrigin.d.ts +0 -37
  126. package/dist/models/VariantManufacturerOrigin.js +0 -47
  127. package/dist/models/VariantProduct.d.ts +0 -37
  128. package/dist/models/VariantProduct.js +0 -47
  129. package/dist/models/VariantStock.d.ts +0 -50
  130. package/dist/models/VariantStock.js +0 -52
  131. package/dist/models/VariantsResponse.d.ts +0 -38
  132. package/dist/models/VariantsResponse.js +0 -48
  133. package/dist/models/index.d.ts +0 -20
  134. package/dist/models/index.js +0 -38
  135. package/dist/runtime.d.ts +0 -187
  136. package/dist/runtime.js +0 -349
  137. package/src/apis/ProductsApi.ts +0 -116
  138. package/src/apis/StatementsApi.ts +0 -177
  139. package/src/apis/TransactionsApi.ts +0 -180
  140. package/src/apis/VariantsApi.ts +0 -345
  141. package/src/apis/index.ts +0 -6
  142. package/src/index.ts +0 -5
  143. package/src/models/ApiError.ts +0 -69
  144. package/src/models/ApiValidationError.ts +0 -70
  145. package/src/models/Attribute.ts +0 -93
  146. package/src/models/AttributeThumbnail.ts +0 -80
  147. package/src/models/ExportTransactionsRequest.ts +0 -76
  148. package/src/models/Image.ts +0 -108
  149. package/src/models/ListStatements200Response.ts +0 -75
  150. package/src/models/ListTransactions200Response.ts +0 -75
  151. package/src/models/Product.ts +0 -109
  152. package/src/models/ProductsResponse.ts +0 -75
  153. package/src/models/Statement.ts +0 -106
  154. package/src/models/Stock.ts +0 -60
  155. package/src/models/StockResponse.ts +0 -75
  156. package/src/models/Transaction.ts +0 -120
  157. package/src/models/TransactionOrder.ts +0 -70
  158. package/src/models/Variant.ts +0 -149
  159. package/src/models/VariantManufacturerOrigin.ts +0 -68
  160. package/src/models/VariantProduct.ts +0 -68
  161. package/src/models/VariantStock.ts +0 -91
  162. package/src/models/VariantsResponse.ts +0 -75
  163. package/src/models/index.ts +0 -22
  164. package/src/runtime.ts +0 -441
@@ -1,68 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * GFN Catalog API
5
- * Use this API to access the Global Fulfilment Network, which contains all the warehouse products and variants available to a given project. Warehouse products represent the base products that can be printed on. Products are the top level items, and variants are the different options available for each product. For example, a product might be a T-shirt, and each variant represents a different size and colour combination of that T-shirt. Use references to these warehouse products to create new product listings on your project via the Product Catalog API. Use the variant information to decide which options you would like to offer on each product listing.
6
- *
7
- * The version of the OpenAPI document: 1.4.0
8
- * Contact: hello@teemill.com
9
- *
10
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
- * https://openapi-generator.tech
12
- * Do not edit the class manually.
13
- */
14
-
15
- import { mapValues } from '../runtime';
16
- /**
17
- *
18
- * @export
19
- * @interface VariantProduct
20
- */
21
- export interface VariantProduct {
22
- /**
23
- * Unique object identifier
24
- * @type {string}
25
- * @memberof VariantProduct
26
- */
27
- id?: string;
28
- /**
29
- * A reference to the resource location
30
- * @type {string}
31
- * @memberof VariantProduct
32
- */
33
- ref?: string;
34
- }
35
-
36
- /**
37
- * Check if a given object implements the VariantProduct interface.
38
- */
39
- export function instanceOfVariantProduct(value: object): value is VariantProduct {
40
- return true;
41
- }
42
-
43
- export function VariantProductFromJSON(json: any): VariantProduct {
44
- return VariantProductFromJSONTyped(json, false);
45
- }
46
-
47
- export function VariantProductFromJSONTyped(json: any, ignoreDiscriminator: boolean): VariantProduct {
48
- if (json == null) {
49
- return json;
50
- }
51
- return {
52
-
53
- 'id': json['id'] == null ? undefined : json['id'],
54
- 'ref': json['ref'] == null ? undefined : json['ref'],
55
- };
56
- }
57
-
58
- export function VariantProductToJSON(value?: VariantProduct | null): any {
59
- if (value == null) {
60
- return value;
61
- }
62
- return {
63
-
64
- 'id': value['id'],
65
- 'ref': value['ref'],
66
- };
67
- }
68
-
@@ -1,91 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * GFN Catalog API
5
- * Use this API to access the Global Fulfilment Network, which contains all the warehouse products and variants available to a given project. Warehouse products represent the base products that can be printed on. Products are the top level items, and variants are the different options available for each product. For example, a product might be a T-shirt, and each variant represents a different size and colour combination of that T-shirt. Use references to these warehouse products to create new product listings on your project via the Product Catalog API. Use the variant information to decide which options you would like to offer on each product listing.
6
- *
7
- * The version of the OpenAPI document: 1.4.0
8
- * Contact: hello@teemill.com
9
- *
10
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
- * https://openapi-generator.tech
12
- * Do not edit the class manually.
13
- */
14
-
15
- import { mapValues } from '../runtime';
16
- import type { Stock } from './Stock';
17
- import {
18
- StockFromJSON,
19
- StockFromJSONTyped,
20
- StockToJSON,
21
- } from './Stock';
22
-
23
- /**
24
- *
25
- * @export
26
- * @interface VariantStock
27
- */
28
- export interface VariantStock {
29
- /**
30
- * Unique object identifier
31
- * @type {string}
32
- * @memberof VariantStock
33
- */
34
- id?: string;
35
- /**
36
- * A reference to the resource location
37
- * @type {string}
38
- * @memberof VariantStock
39
- */
40
- ref?: string;
41
- /**
42
- * A reference to the resource location
43
- * @type {string}
44
- * @memberof VariantStock
45
- */
46
- productRef?: string;
47
- /**
48
- *
49
- * @type {Stock}
50
- * @memberof VariantStock
51
- */
52
- stock?: Stock;
53
- }
54
-
55
- /**
56
- * Check if a given object implements the VariantStock interface.
57
- */
58
- export function instanceOfVariantStock(value: object): value is VariantStock {
59
- return true;
60
- }
61
-
62
- export function VariantStockFromJSON(json: any): VariantStock {
63
- return VariantStockFromJSONTyped(json, false);
64
- }
65
-
66
- export function VariantStockFromJSONTyped(json: any, ignoreDiscriminator: boolean): VariantStock {
67
- if (json == null) {
68
- return json;
69
- }
70
- return {
71
-
72
- 'id': json['id'] == null ? undefined : json['id'],
73
- 'ref': json['ref'] == null ? undefined : json['ref'],
74
- 'productRef': json['productRef'] == null ? undefined : json['productRef'],
75
- 'stock': json['stock'] == null ? undefined : StockFromJSON(json['stock']),
76
- };
77
- }
78
-
79
- export function VariantStockToJSON(value?: VariantStock | null): any {
80
- if (value == null) {
81
- return value;
82
- }
83
- return {
84
-
85
- 'id': value['id'],
86
- 'ref': value['ref'],
87
- 'productRef': value['productRef'],
88
- 'stock': StockToJSON(value['stock']),
89
- };
90
- }
91
-
@@ -1,75 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * GFN Catalog API
5
- * Use this API to access the Global Fulfilment Network, which contains all the warehouse products and variants available to a given project. Warehouse products represent the base products that can be printed on. Products are the top level items, and variants are the different options available for each product. For example, a product might be a T-shirt, and each variant represents a different size and colour combination of that T-shirt. Use references to these warehouse products to create new product listings on your project via the Product Catalog API. Use the variant information to decide which options you would like to offer on each product listing.
6
- *
7
- * The version of the OpenAPI document: 1.4.0
8
- * Contact: hello@teemill.com
9
- *
10
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
- * https://openapi-generator.tech
12
- * Do not edit the class manually.
13
- */
14
-
15
- import { mapValues } from '../runtime';
16
- import type { Variant } from './Variant';
17
- import {
18
- VariantFromJSON,
19
- VariantFromJSONTyped,
20
- VariantToJSON,
21
- } from './Variant';
22
-
23
- /**
24
- *
25
- * @export
26
- * @interface VariantsResponse
27
- */
28
- export interface VariantsResponse {
29
- /**
30
- *
31
- * @type {Array<Variant>}
32
- * @memberof VariantsResponse
33
- */
34
- variants?: Array<Variant>;
35
- /**
36
- *
37
- * @type {number}
38
- * @memberof VariantsResponse
39
- */
40
- nextPageToken?: number;
41
- }
42
-
43
- /**
44
- * Check if a given object implements the VariantsResponse interface.
45
- */
46
- export function instanceOfVariantsResponse(value: object): value is VariantsResponse {
47
- return true;
48
- }
49
-
50
- export function VariantsResponseFromJSON(json: any): VariantsResponse {
51
- return VariantsResponseFromJSONTyped(json, false);
52
- }
53
-
54
- export function VariantsResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): VariantsResponse {
55
- if (json == null) {
56
- return json;
57
- }
58
- return {
59
-
60
- 'variants': json['variants'] == null ? undefined : ((json['variants'] as Array<any>).map(VariantFromJSON)),
61
- 'nextPageToken': json['nextPageToken'] == null ? undefined : json['nextPageToken'],
62
- };
63
- }
64
-
65
- export function VariantsResponseToJSON(value?: VariantsResponse | null): any {
66
- if (value == null) {
67
- return value;
68
- }
69
- return {
70
-
71
- 'variants': value['variants'] == null ? undefined : ((value['variants'] as Array<any>).map(VariantToJSON)),
72
- 'nextPageToken': value['nextPageToken'],
73
- };
74
- }
75
-
@@ -1,22 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- export * from './ApiError';
4
- export * from './ApiValidationError';
5
- export * from './Attribute';
6
- export * from './AttributeThumbnail';
7
- export * from './ExportTransactionsRequest';
8
- export * from './Image';
9
- export * from './ListStatements200Response';
10
- export * from './ListTransactions200Response';
11
- export * from './Product';
12
- export * from './ProductsResponse';
13
- export * from './Statement';
14
- export * from './Stock';
15
- export * from './StockResponse';
16
- export * from './Transaction';
17
- export * from './TransactionOrder';
18
- export * from './Variant';
19
- export * from './VariantManufacturerOrigin';
20
- export * from './VariantProduct';
21
- export * from './VariantStock';
22
- export * from './VariantsResponse';
package/src/runtime.ts DELETED
@@ -1,441 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * GFN Catalog API
5
- * Use this API to access the Global Fulfilment Network, which contains all the warehouse products and variants available to a given project. Warehouse products represent the base products that can be printed on. Products are the top level items, and variants are the different options available for each product. For example, a product might be a T-shirt, and each variant represents a different size and colour combination of that T-shirt. Use references to these warehouse products to create new product listings on your project via the Product Catalog API. Use the variant information to decide which options you would like to offer on each product listing.
6
- *
7
- * The version of the OpenAPI document: 1.4.0
8
- * Contact: hello@teemill.com
9
- *
10
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
- * https://openapi-generator.tech
12
- * Do not edit the class manually.
13
- */
14
-
15
-
16
- export type OptionalProperties<T> = {
17
- [K in keyof T]-?: undefined extends T[K] ? K : never
18
- }[keyof T];
19
-
20
- export type OptionalOnly<T> = Partial<Pick<T, OptionalProperties<T>>>;
21
-
22
- export const BASE_PATH = "https://api.teemill.com".replace(/\/+$/, "");
23
-
24
- export interface ConfigurationParameters {
25
- basePath?: string; // override base path
26
- fetchApi?: FetchAPI; // override for fetch implementation
27
- middleware?: Middleware[]; // middleware to apply before/after fetch requests
28
- queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
29
- username?: string; // parameter for basic security
30
- password?: string; // parameter for basic security
31
- apiKey?: string | ((name: string) => string); // parameter for apiKey security
32
- accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
33
- headers?: HTTPHeaders; //header params we want to use on every request
34
- credentials?: RequestCredentials; //value for the credentials param we want to use on each request
35
- }
36
-
37
- export class Configuration {
38
- constructor(private configuration: ConfigurationParameters = {}) {}
39
-
40
- set config(configuration: Configuration) {
41
- this.configuration = configuration;
42
- }
43
-
44
- get basePath(): string {
45
- return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
46
- }
47
-
48
- get fetchApi(): FetchAPI | undefined {
49
- return this.configuration.fetchApi;
50
- }
51
-
52
- get middleware(): Middleware[] {
53
- return this.configuration.middleware || [];
54
- }
55
-
56
- get queryParamsStringify(): (params: HTTPQuery) => string {
57
- return this.configuration.queryParamsStringify || querystring;
58
- }
59
-
60
- get username(): string | undefined {
61
- return this.configuration.username;
62
- }
63
-
64
- get password(): string | undefined {
65
- return this.configuration.password;
66
- }
67
-
68
- get apiKey(): ((name: string) => string) | undefined {
69
- const apiKey = this.configuration.apiKey;
70
- if (apiKey) {
71
- return typeof apiKey === 'function' ? apiKey : () => apiKey;
72
- }
73
- return undefined;
74
- }
75
-
76
- get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
77
- const accessToken = this.configuration.accessToken;
78
- if (accessToken) {
79
- return typeof accessToken === 'function' ? accessToken : async () => accessToken;
80
- }
81
- return undefined;
82
- }
83
-
84
- get headers(): HTTPHeaders | undefined {
85
- return this.configuration.headers;
86
- }
87
-
88
- get credentials(): RequestCredentials | undefined {
89
- return this.configuration.credentials;
90
- }
91
- }
92
-
93
- export const DefaultConfig = new Configuration();
94
-
95
- /**
96
- * This is the base class for all generated API classes.
97
- */
98
- export class BaseAPI {
99
-
100
- private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i');
101
- private middleware: Middleware[];
102
-
103
- constructor(protected configuration = DefaultConfig) {
104
- this.middleware = configuration.middleware;
105
- }
106
-
107
- isResponseError(error: any): error is ResponseError {
108
- return error instanceof Error && error.name === 'ResponseError';
109
- }
110
-
111
- withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
112
- const next = this.clone<T>();
113
- next.middleware = next.middleware.concat(...middlewares);
114
- return next;
115
- }
116
-
117
- withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
118
- const middlewares = preMiddlewares.map((pre) => ({ pre }));
119
- return this.withMiddleware<T>(...middlewares);
120
- }
121
-
122
- withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
123
- const middlewares = postMiddlewares.map((post) => ({ post }));
124
- return this.withMiddleware<T>(...middlewares);
125
- }
126
-
127
- /**
128
- * Check if the given MIME is a JSON MIME.
129
- * JSON MIME examples:
130
- * application/json
131
- * application/json; charset=UTF8
132
- * APPLICATION/JSON
133
- * application/vnd.company+json
134
- * @param mime - MIME (Multipurpose Internet Mail Extensions)
135
- * @return True if the given MIME is JSON, false otherwise.
136
- */
137
- protected isJsonMime(mime: string | null | undefined): boolean {
138
- if (!mime) {
139
- return false;
140
- }
141
- return BaseAPI.jsonRegex.test(mime);
142
- }
143
-
144
- protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response> {
145
- const { url, init } = await this.createFetchParams(context, initOverrides);
146
- const response = await this.fetchApi(url, init);
147
- if (response && (response.status >= 200 && response.status < 300)) {
148
- return response;
149
- }
150
- throw new ResponseError(response, 'Response returned an error code');
151
- }
152
-
153
- private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) {
154
- let url = this.configuration.basePath + context.path;
155
- if (context.query !== undefined && Object.keys(context.query).length !== 0) {
156
- // only add the querystring to the URL if there are query parameters.
157
- // this is done to avoid urls ending with a "?" character which buggy webservers
158
- // do not handle correctly sometimes.
159
- url += '?' + this.configuration.queryParamsStringify(context.query);
160
- }
161
-
162
- const headers = Object.assign({}, this.configuration.headers, context.headers);
163
- Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
164
-
165
- const initOverrideFn =
166
- typeof initOverrides === "function"
167
- ? initOverrides
168
- : async () => initOverrides;
169
-
170
- const initParams = {
171
- method: context.method,
172
- headers,
173
- body: context.body,
174
- credentials: this.configuration.credentials,
175
- };
176
-
177
- const overriddenInit: RequestInit = {
178
- ...initParams,
179
- ...(await initOverrideFn({
180
- init: initParams,
181
- context,
182
- }))
183
- };
184
-
185
- let body: any;
186
- if (isFormData(overriddenInit.body)
187
- || (overriddenInit.body instanceof URLSearchParams)
188
- || isBlob(overriddenInit.body)) {
189
- body = overriddenInit.body;
190
- } else if (this.isJsonMime(headers['Content-Type'])) {
191
- body = JSON.stringify(overriddenInit.body);
192
- } else {
193
- body = overriddenInit.body;
194
- }
195
-
196
- const init: RequestInit = {
197
- ...overriddenInit,
198
- body
199
- };
200
-
201
- return { url, init };
202
- }
203
-
204
- private fetchApi = async (url: string, init: RequestInit) => {
205
- let fetchParams = { url, init };
206
- for (const middleware of this.middleware) {
207
- if (middleware.pre) {
208
- fetchParams = await middleware.pre({
209
- fetch: this.fetchApi,
210
- ...fetchParams,
211
- }) || fetchParams;
212
- }
213
- }
214
- let response: Response | undefined = undefined;
215
- try {
216
- response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
217
- } catch (e) {
218
- for (const middleware of this.middleware) {
219
- if (middleware.onError) {
220
- response = await middleware.onError({
221
- fetch: this.fetchApi,
222
- url: fetchParams.url,
223
- init: fetchParams.init,
224
- error: e,
225
- response: response ? response.clone() : undefined,
226
- }) || response;
227
- }
228
- }
229
- if (response === undefined) {
230
- if (e instanceof Error) {
231
- throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
232
- } else {
233
- throw e;
234
- }
235
- }
236
- }
237
- for (const middleware of this.middleware) {
238
- if (middleware.post) {
239
- response = await middleware.post({
240
- fetch: this.fetchApi,
241
- url: fetchParams.url,
242
- init: fetchParams.init,
243
- response: response.clone(),
244
- }) || response;
245
- }
246
- }
247
- return response;
248
- }
249
-
250
- /**
251
- * Create a shallow clone of `this` by constructing a new instance
252
- * and then shallow cloning data members.
253
- */
254
- private clone<T extends BaseAPI>(this: T): T {
255
- const constructor = this.constructor as any;
256
- const next = new constructor(this.configuration);
257
- next.middleware = this.middleware.slice();
258
- return next;
259
- }
260
- };
261
-
262
- function isBlob(value: any): value is Blob {
263
- return typeof Blob !== 'undefined' && value instanceof Blob;
264
- }
265
-
266
- function isFormData(value: any): value is FormData {
267
- return typeof FormData !== "undefined" && value instanceof FormData;
268
- }
269
-
270
- export class ResponseError extends Error {
271
- override name: "ResponseError" = "ResponseError";
272
- constructor(public response: Response, msg?: string) {
273
- super(msg);
274
- }
275
- }
276
-
277
- export class FetchError extends Error {
278
- override name: "FetchError" = "FetchError";
279
- constructor(public cause: Error, msg?: string) {
280
- super(msg);
281
- }
282
- }
283
-
284
- export class RequiredError extends Error {
285
- override name: "RequiredError" = "RequiredError";
286
- constructor(public field: string, msg?: string) {
287
- super(msg);
288
- }
289
- }
290
-
291
- export const COLLECTION_FORMATS = {
292
- csv: ",",
293
- ssv: " ",
294
- tsv: "\t",
295
- pipes: "|",
296
- };
297
-
298
- export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
299
-
300
- export type Json = any;
301
- export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
302
- export type HTTPHeaders = { [key: string]: string };
303
- export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
304
- export type HTTPBody = Json | FormData | URLSearchParams;
305
- export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
306
- export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
307
-
308
- export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
309
-
310
- export interface FetchParams {
311
- url: string;
312
- init: RequestInit;
313
- }
314
-
315
- export interface RequestOpts {
316
- path: string;
317
- method: HTTPMethod;
318
- headers: HTTPHeaders;
319
- query?: HTTPQuery;
320
- body?: HTTPBody;
321
- }
322
-
323
- export function exists(json: any, key: string) {
324
- const value = json[key];
325
- return value !== null && value !== undefined;
326
- }
327
-
328
- export function querystring(params: HTTPQuery, prefix: string = ''): string {
329
- return Object.keys(params)
330
- .map(key => querystringSingleKey(key, params[key], prefix))
331
- .filter(part => part.length > 0)
332
- .join('&');
333
- }
334
-
335
- function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery, keyPrefix: string = ''): string {
336
- const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
337
- if (value instanceof Array) {
338
- const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
339
- .join(`&${encodeURIComponent(fullKey)}[]=`);
340
- return `${encodeURIComponent(fullKey)}[]=${multiValue}`;
341
- }
342
- if (value instanceof Set) {
343
- const valueAsArray = Array.from(value);
344
- return querystringSingleKey(key, valueAsArray, keyPrefix);
345
- }
346
- if (value instanceof Date) {
347
- return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
348
- }
349
- if (value instanceof Object) {
350
- return querystring(value as HTTPQuery, fullKey);
351
- }
352
- return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
353
- }
354
-
355
- export function mapValues(data: any, fn: (item: any) => any) {
356
- return Object.keys(data).reduce(
357
- (acc, key) => ({ ...acc, [key]: fn(data[key]) }),
358
- {}
359
- );
360
- }
361
-
362
- export function canConsumeForm(consumes: Consume[]): boolean {
363
- for (const consume of consumes) {
364
- if ('multipart/form-data' === consume.contentType) {
365
- return true;
366
- }
367
- }
368
- return false;
369
- }
370
-
371
- export interface Consume {
372
- contentType: string;
373
- }
374
-
375
- export interface RequestContext {
376
- fetch: FetchAPI;
377
- url: string;
378
- init: RequestInit;
379
- }
380
-
381
- export interface ResponseContext {
382
- fetch: FetchAPI;
383
- url: string;
384
- init: RequestInit;
385
- response: Response;
386
- }
387
-
388
- export interface ErrorContext {
389
- fetch: FetchAPI;
390
- url: string;
391
- init: RequestInit;
392
- error: unknown;
393
- response?: Response;
394
- }
395
-
396
- export interface Middleware {
397
- pre?(context: RequestContext): Promise<FetchParams | void>;
398
- post?(context: ResponseContext): Promise<Response | void>;
399
- onError?(context: ErrorContext): Promise<Response | void>;
400
- }
401
-
402
- export interface ApiResponse<T> {
403
- raw: Response;
404
- value(): Promise<T>;
405
- }
406
-
407
- export interface ResponseTransformer<T> {
408
- (json: any): T;
409
- }
410
-
411
- export class JSONApiResponse<T> {
412
- constructor(public raw: Response, private transformer: ResponseTransformer<T> = (jsonValue: any) => jsonValue) {}
413
-
414
- async value(): Promise<T> {
415
- return this.transformer(await this.raw.json());
416
- }
417
- }
418
-
419
- export class VoidApiResponse {
420
- constructor(public raw: Response) {}
421
-
422
- async value(): Promise<void> {
423
- return undefined;
424
- }
425
- }
426
-
427
- export class BlobApiResponse {
428
- constructor(public raw: Response) {}
429
-
430
- async value(): Promise<Blob> {
431
- return await this.raw.blob();
432
- };
433
- }
434
-
435
- export class TextApiResponse {
436
- constructor(public raw: Response) {}
437
-
438
- async value(): Promise<string> {
439
- return await this.raw.text();
440
- };
441
- }