cas-parser-node 1.4.0 → 1.6.2

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 (186) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/LICENSE +1 -1
  3. package/README.md +30 -32
  4. package/client.d.mts +51 -7
  5. package/client.d.mts.map +1 -1
  6. package/client.d.ts +51 -7
  7. package/client.d.ts.map +1 -1
  8. package/client.js +56 -12
  9. package/client.js.map +1 -1
  10. package/client.mjs +56 -12
  11. package/client.mjs.map +1 -1
  12. package/internal/parse.d.mts.map +1 -1
  13. package/internal/parse.d.ts.map +1 -1
  14. package/internal/parse.js +5 -0
  15. package/internal/parse.js.map +1 -1
  16. package/internal/parse.mjs +5 -0
  17. package/internal/parse.mjs.map +1 -1
  18. package/internal/to-file.d.mts +1 -1
  19. package/internal/to-file.d.ts +1 -1
  20. package/internal/to-file.js +1 -1
  21. package/internal/to-file.mjs +1 -1
  22. package/internal/tslib.js +17 -17
  23. package/internal/utils/values.js +3 -3
  24. package/internal/utils/values.js.map +1 -1
  25. package/internal/utils/values.mjs +3 -3
  26. package/internal/utils/values.mjs.map +1 -1
  27. package/package.json +9 -10
  28. package/resources/access-token.d.mts +48 -0
  29. package/resources/access-token.d.mts.map +1 -0
  30. package/resources/access-token.d.ts +48 -0
  31. package/resources/access-token.d.ts.map +1 -0
  32. package/resources/access-token.js +30 -0
  33. package/resources/access-token.js.map +1 -0
  34. package/resources/access-token.mjs +26 -0
  35. package/resources/access-token.mjs.map +1 -0
  36. package/resources/{cas-parser.d.mts → cams-kfintech.d.mts} +282 -105
  37. package/resources/cams-kfintech.d.mts.map +1 -0
  38. package/resources/{cas-parser.d.ts → cams-kfintech.d.ts} +282 -105
  39. package/resources/cams-kfintech.d.ts.map +1 -0
  40. package/resources/cams-kfintech.js +18 -0
  41. package/resources/cams-kfintech.js.map +1 -0
  42. package/resources/cams-kfintech.mjs +14 -0
  43. package/resources/cams-kfintech.mjs.map +1 -0
  44. package/resources/cdsl/cdsl.d.mts +39 -0
  45. package/resources/cdsl/cdsl.d.mts.map +1 -0
  46. package/resources/cdsl/cdsl.d.ts +39 -0
  47. package/resources/cdsl/cdsl.d.ts.map +1 -0
  48. package/resources/cdsl/cdsl.js +31 -0
  49. package/resources/cdsl/cdsl.js.map +1 -0
  50. package/resources/cdsl/cdsl.mjs +26 -0
  51. package/resources/cdsl/cdsl.mjs.map +1 -0
  52. package/resources/cdsl/fetch.d.mts +91 -0
  53. package/resources/cdsl/fetch.d.mts.map +1 -0
  54. package/resources/cdsl/fetch.d.ts +91 -0
  55. package/resources/cdsl/fetch.d.ts.map +1 -0
  56. package/resources/cdsl/fetch.js +50 -0
  57. package/resources/cdsl/fetch.js.map +1 -0
  58. package/resources/cdsl/fetch.mjs +46 -0
  59. package/resources/cdsl/fetch.mjs.map +1 -0
  60. package/resources/cdsl/index.d.mts +3 -0
  61. package/resources/cdsl/index.d.mts.map +1 -0
  62. package/resources/cdsl/index.d.ts +3 -0
  63. package/resources/cdsl/index.d.ts.map +1 -0
  64. package/resources/cdsl/index.js +9 -0
  65. package/resources/cdsl/index.js.map +1 -0
  66. package/resources/cdsl/index.mjs +4 -0
  67. package/resources/cdsl/index.mjs.map +1 -0
  68. package/resources/cdsl.d.mts +2 -0
  69. package/resources/cdsl.d.mts.map +1 -0
  70. package/resources/cdsl.d.ts +2 -0
  71. package/resources/cdsl.d.ts.map +1 -0
  72. package/resources/cdsl.js +6 -0
  73. package/resources/cdsl.js.map +1 -0
  74. package/resources/cdsl.mjs +3 -0
  75. package/resources/cdsl.mjs.map +1 -0
  76. package/resources/contract-note.d.mts +323 -0
  77. package/resources/contract-note.d.mts.map +1 -0
  78. package/resources/contract-note.d.ts +323 -0
  79. package/resources/contract-note.d.ts.map +1 -0
  80. package/resources/contract-note.js +49 -0
  81. package/resources/contract-note.js.map +1 -0
  82. package/resources/contract-note.mjs +45 -0
  83. package/resources/contract-note.mjs.map +1 -0
  84. package/resources/credits.d.mts +47 -0
  85. package/resources/credits.d.mts.map +1 -0
  86. package/resources/credits.d.ts +47 -0
  87. package/resources/credits.d.ts.map +1 -0
  88. package/resources/credits.js +23 -0
  89. package/resources/credits.js.map +1 -0
  90. package/resources/credits.mjs +19 -0
  91. package/resources/credits.mjs.map +1 -0
  92. package/resources/inbox.d.mts +206 -0
  93. package/resources/inbox.d.mts.map +1 -0
  94. package/resources/inbox.d.ts +206 -0
  95. package/resources/inbox.d.ts.map +1 -0
  96. package/resources/inbox.js +109 -0
  97. package/resources/inbox.js.map +1 -0
  98. package/resources/inbox.mjs +105 -0
  99. package/resources/inbox.mjs.map +1 -0
  100. package/resources/index.d.mts +11 -2
  101. package/resources/index.d.mts.map +1 -1
  102. package/resources/index.d.ts +11 -2
  103. package/resources/index.d.ts.map +1 -1
  104. package/resources/index.js +23 -5
  105. package/resources/index.js.map +1 -1
  106. package/resources/index.mjs +11 -2
  107. package/resources/index.mjs.map +1 -1
  108. package/resources/kfintech.d.mts +53 -0
  109. package/resources/kfintech.d.mts.map +1 -0
  110. package/resources/kfintech.d.ts +53 -0
  111. package/resources/kfintech.d.ts.map +1 -0
  112. package/resources/kfintech.js +29 -0
  113. package/resources/kfintech.js.map +1 -0
  114. package/resources/kfintech.mjs +25 -0
  115. package/resources/kfintech.mjs.map +1 -0
  116. package/resources/logs.d.mts +129 -0
  117. package/resources/logs.d.mts.map +1 -0
  118. package/resources/logs.d.ts +129 -0
  119. package/resources/logs.d.ts.map +1 -0
  120. package/resources/logs.js +37 -0
  121. package/resources/logs.js.map +1 -0
  122. package/resources/logs.mjs +33 -0
  123. package/resources/logs.mjs.map +1 -0
  124. package/resources/nsdl.d.mts +30 -0
  125. package/resources/nsdl.d.mts.map +1 -0
  126. package/resources/nsdl.d.ts +30 -0
  127. package/resources/nsdl.d.ts.map +1 -0
  128. package/resources/nsdl.js +18 -0
  129. package/resources/nsdl.js.map +1 -0
  130. package/resources/nsdl.mjs +14 -0
  131. package/resources/nsdl.mjs.map +1 -0
  132. package/resources/smart.d.mts +31 -0
  133. package/resources/smart.d.mts.map +1 -0
  134. package/resources/smart.d.ts +31 -0
  135. package/resources/smart.d.ts.map +1 -0
  136. package/resources/smart.js +19 -0
  137. package/resources/smart.js.map +1 -0
  138. package/resources/smart.mjs +15 -0
  139. package/resources/smart.mjs.map +1 -0
  140. package/resources/verify-token.d.mts +28 -0
  141. package/resources/verify-token.d.mts.map +1 -0
  142. package/resources/verify-token.d.ts +28 -0
  143. package/resources/verify-token.d.ts.map +1 -0
  144. package/resources/verify-token.js +16 -0
  145. package/resources/verify-token.js.map +1 -0
  146. package/resources/verify-token.mjs +12 -0
  147. package/resources/verify-token.mjs.map +1 -0
  148. package/src/client.ts +143 -31
  149. package/src/internal/parse.ts +6 -0
  150. package/src/internal/to-file.ts +1 -1
  151. package/src/internal/utils/values.ts +3 -3
  152. package/src/resources/access-token.ts +63 -0
  153. package/src/resources/{cas-parser.ts → cams-kfintech.ts} +340 -130
  154. package/src/resources/cdsl/cdsl.ts +67 -0
  155. package/src/resources/cdsl/fetch.ts +122 -0
  156. package/src/resources/cdsl/index.ts +10 -0
  157. package/src/resources/cdsl.ts +3 -0
  158. package/src/resources/contract-note.ts +402 -0
  159. package/src/resources/credits.ts +58 -0
  160. package/src/resources/inbox.ts +283 -0
  161. package/src/resources/index.ts +31 -11
  162. package/src/resources/kfintech.ts +71 -0
  163. package/src/resources/logs.ts +170 -0
  164. package/src/resources/nsdl.ts +42 -0
  165. package/src/resources/smart.ts +46 -0
  166. package/src/resources/verify-token.ts +36 -0
  167. package/src/version.ts +1 -1
  168. package/version.d.mts +1 -1
  169. package/version.d.ts +1 -1
  170. package/version.js +1 -1
  171. package/version.mjs +1 -1
  172. package/resources/cas-generator.d.mts +0 -56
  173. package/resources/cas-generator.d.mts.map +0 -1
  174. package/resources/cas-generator.d.ts +0 -56
  175. package/resources/cas-generator.d.ts.map +0 -1
  176. package/resources/cas-generator.js +0 -27
  177. package/resources/cas-generator.js.map +0 -1
  178. package/resources/cas-generator.mjs +0 -23
  179. package/resources/cas-generator.mjs.map +0 -1
  180. package/resources/cas-parser.d.mts.map +0 -1
  181. package/resources/cas-parser.d.ts.map +0 -1
  182. package/resources/cas-parser.js +0 -43
  183. package/resources/cas-parser.js.map +0 -1
  184. package/resources/cas-parser.mjs +0 -39
  185. package/resources/cas-parser.mjs.map +0 -1
  186. package/src/resources/cas-generator.ts +0 -75
package/src/client.ts CHANGED
@@ -16,19 +16,39 @@ import * as Errors from './core/error';
16
16
  import * as Uploads from './core/uploads';
17
17
  import * as API from './resources/index';
18
18
  import { APIPromise } from './core/api-promise';
19
+ import { AccessToken, AccessTokenCreateParams, AccessTokenCreateResponse } from './resources/access-token';
19
20
  import {
20
- CasGenerator,
21
- CasGeneratorGenerateCasParams,
22
- CasGeneratorGenerateCasResponse,
23
- } from './resources/cas-generator';
24
- import {
25
- CasParserCamsKfintechParams,
26
- CasParserCdslParams,
27
- CasParserNsdlParams,
28
- CasParserResource,
29
- CasParserSmartParseParams,
21
+ CamsKfintech,
22
+ CamsKfintechParseParams,
23
+ LinkedHolder,
24
+ Transaction,
30
25
  UnifiedResponse,
31
- } from './resources/cas-parser';
26
+ } from './resources/cams-kfintech';
27
+ import { ContractNote, ContractNoteParseParams, ContractNoteParseResponse } from './resources/contract-note';
28
+ import { CreditCheckResponse, Credits } from './resources/credits';
29
+ import {
30
+ Inbox,
31
+ InboxCheckConnectionStatusParams,
32
+ InboxCheckConnectionStatusResponse,
33
+ InboxConnectEmailParams,
34
+ InboxConnectEmailResponse,
35
+ InboxDisconnectEmailParams,
36
+ InboxDisconnectEmailResponse,
37
+ InboxListCasFilesParams,
38
+ InboxListCasFilesResponse,
39
+ } from './resources/inbox';
40
+ import { Kfintech, KfintechGenerateCasParams, KfintechGenerateCasResponse } from './resources/kfintech';
41
+ import {
42
+ LogCreateParams,
43
+ LogCreateResponse,
44
+ LogGetSummaryParams,
45
+ LogGetSummaryResponse,
46
+ Logs,
47
+ } from './resources/logs';
48
+ import { Nsdl, NsdlParseParams } from './resources/nsdl';
49
+ import { Smart, SmartParseCasPdfParams } from './resources/smart';
50
+ import { VerifyToken, VerifyTokenVerifyResponse } from './resources/verify-token';
51
+ import { Cdsl, CdslParsePdfParams } from './resources/cdsl/cdsl';
32
52
  import { type Fetch } from './internal/builtin-types';
33
53
  import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
34
54
  import { FinalRequestOptions, RequestOptions } from './internal/request-options';
@@ -42,6 +62,13 @@ import {
42
62
  } from './internal/utils/log';
43
63
  import { isEmptyObj } from './internal/utils/values';
44
64
 
65
+ const environments = {
66
+ production: 'https://portfolio-parser.api.casparser.in',
67
+ environment_1: 'https://client-apis.casparser.in',
68
+ environment_2: 'http://localhost:5000',
69
+ };
70
+ type Environment = keyof typeof environments;
71
+
45
72
  export interface ClientOptions {
46
73
  /**
47
74
  * Your API key for authentication.
@@ -50,6 +77,16 @@ export interface ClientOptions {
50
77
  */
51
78
  apiKey?: string | undefined;
52
79
 
80
+ /**
81
+ * Specifies the environment to use for the API.
82
+ *
83
+ * Each environment maps to a different base URL:
84
+ * - `production` corresponds to `https://portfolio-parser.api.casparser.in`
85
+ * - `environment_1` corresponds to `https://client-apis.casparser.in`
86
+ * - `environment_2` corresponds to `http://localhost:5000`
87
+ */
88
+ environment?: Environment | undefined;
89
+
53
90
  /**
54
91
  * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
55
92
  *
@@ -128,7 +165,7 @@ export class CasParser {
128
165
  baseURL: string;
129
166
  maxRetries: number;
130
167
  timeout: number;
131
- logger: Logger | undefined;
168
+ logger: Logger;
132
169
  logLevel: LogLevel | undefined;
133
170
  fetchOptions: MergedRequestInit | undefined;
134
171
 
@@ -141,6 +178,7 @@ export class CasParser {
141
178
  * API Client for interfacing with the Cas Parser API.
142
179
  *
143
180
  * @param {string | undefined} [opts.apiKey=process.env['CAS_PARSER_API_KEY'] ?? undefined]
181
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
144
182
  * @param {string} [opts.baseURL=process.env['CAS_PARSER_BASE_URL'] ?? https://portfolio-parser.api.casparser.in] - Override the default base URL for the API.
145
183
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
146
184
  * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
@@ -163,10 +201,17 @@ export class CasParser {
163
201
  const options: ClientOptions = {
164
202
  apiKey,
165
203
  ...opts,
166
- baseURL: baseURL || `https://portfolio-parser.api.casparser.in`,
204
+ baseURL,
205
+ environment: opts.environment ?? 'production',
167
206
  };
168
207
 
169
- this.baseURL = options.baseURL!;
208
+ if (baseURL && opts.environment) {
209
+ throw new Errors.CasParserError(
210
+ 'Ambiguous URL; The `baseURL` option (or CAS_PARSER_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
211
+ );
212
+ }
213
+
214
+ this.baseURL = options.baseURL || environments[options.environment || 'production'];
170
215
  this.timeout = options.timeout ?? CasParser.DEFAULT_TIMEOUT /* 1 minute */;
171
216
  this.logger = options.logger ?? console;
172
217
  const defaultLogLevel = 'warn';
@@ -192,7 +237,8 @@ export class CasParser {
192
237
  withOptions(options: Partial<ClientOptions>): this {
193
238
  const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
194
239
  ...this._options,
195
- baseURL: this.baseURL,
240
+ environment: options.environment ? options.environment : undefined,
241
+ baseURL: options.environment ? undefined : this.baseURL,
196
242
  maxRetries: this.maxRetries,
197
243
  timeout: this.timeout,
198
244
  logger: this.logger,
@@ -209,7 +255,7 @@ export class CasParser {
209
255
  * Check whether the base URL is set to its default.
210
256
  */
211
257
  #baseURLOverridden(): boolean {
212
- return this.baseURL !== 'https://portfolio-parser.api.casparser.in';
258
+ return this.baseURL !== environments[this._options.environment || 'production'];
213
259
  }
214
260
 
215
261
  protected defaultQuery(): Record<string, string | undefined> | undefined {
@@ -462,7 +508,7 @@ export class CasParser {
462
508
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
463
509
 
464
510
  const errText = await response.text().catch((err: any) => castToError(err).message);
465
- const errJSON = safeJSON(errText);
511
+ const errJSON = safeJSON(errText) as any;
466
512
  const errMessage = errJSON ? undefined : errText;
467
513
 
468
514
  loggerFor(this).debug(
@@ -503,9 +549,10 @@ export class CasParser {
503
549
  controller: AbortController,
504
550
  ): Promise<Response> {
505
551
  const { signal, method, ...options } = init || {};
506
- if (signal) signal.addEventListener('abort', () => controller.abort());
552
+ const abort = this._makeAbort(controller);
553
+ if (signal) signal.addEventListener('abort', abort, { once: true });
507
554
 
508
- const timeout = setTimeout(() => controller.abort(), ms);
555
+ const timeout = setTimeout(abort, ms);
509
556
 
510
557
  const isReadableBody =
511
558
  ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
@@ -672,6 +719,12 @@ export class CasParser {
672
719
  return headers.values;
673
720
  }
674
721
 
722
+ private _makeAbort(controller: AbortController) {
723
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
724
+ // would capture all request options, and cause a memory leak.
725
+ return () => controller.abort();
726
+ }
727
+
675
728
  private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
676
729
  bodyHeaders: HeadersLike;
677
730
  body: BodyInit | undefined;
@@ -728,28 +781,87 @@ export class CasParser {
728
781
 
729
782
  static toFile = Uploads.toFile;
730
783
 
731
- casParser: API.CasParserResource = new API.CasParserResource(this);
732
- casGenerator: API.CasGenerator = new API.CasGenerator(this);
784
+ credits: API.Credits = new API.Credits(this);
785
+ logs: API.Logs = new API.Logs(this);
786
+ accessToken: API.AccessToken = new API.AccessToken(this);
787
+ verifyToken: API.VerifyToken = new API.VerifyToken(this);
788
+ camsKfintech: API.CamsKfintech = new API.CamsKfintech(this);
789
+ cdsl: API.Cdsl = new API.Cdsl(this);
790
+ contractNote: API.ContractNote = new API.ContractNote(this);
791
+ inbox: API.Inbox = new API.Inbox(this);
792
+ kfintech: API.Kfintech = new API.Kfintech(this);
793
+ nsdl: API.Nsdl = new API.Nsdl(this);
794
+ smart: API.Smart = new API.Smart(this);
733
795
  }
734
796
 
735
- CasParser.CasParserResource = CasParserResource;
736
- CasParser.CasGenerator = CasGenerator;
797
+ CasParser.Credits = Credits;
798
+ CasParser.Logs = Logs;
799
+ CasParser.AccessToken = AccessToken;
800
+ CasParser.VerifyToken = VerifyToken;
801
+ CasParser.CamsKfintech = CamsKfintech;
802
+ CasParser.Cdsl = Cdsl;
803
+ CasParser.ContractNote = ContractNote;
804
+ CasParser.Inbox = Inbox;
805
+ CasParser.Kfintech = Kfintech;
806
+ CasParser.Nsdl = Nsdl;
807
+ CasParser.Smart = Smart;
737
808
 
738
809
  export declare namespace CasParser {
739
810
  export type RequestOptions = Opts.RequestOptions;
740
811
 
812
+ export { Credits as Credits, type CreditCheckResponse as CreditCheckResponse };
813
+
741
814
  export {
742
- CasParserResource as CasParserResource,
815
+ Logs as Logs,
816
+ type LogCreateResponse as LogCreateResponse,
817
+ type LogGetSummaryResponse as LogGetSummaryResponse,
818
+ type LogCreateParams as LogCreateParams,
819
+ type LogGetSummaryParams as LogGetSummaryParams,
820
+ };
821
+
822
+ export {
823
+ AccessToken as AccessToken,
824
+ type AccessTokenCreateResponse as AccessTokenCreateResponse,
825
+ type AccessTokenCreateParams as AccessTokenCreateParams,
826
+ };
827
+
828
+ export { VerifyToken as VerifyToken, type VerifyTokenVerifyResponse as VerifyTokenVerifyResponse };
829
+
830
+ export {
831
+ CamsKfintech as CamsKfintech,
832
+ type LinkedHolder as LinkedHolder,
833
+ type Transaction as Transaction,
743
834
  type UnifiedResponse as UnifiedResponse,
744
- type CasParserCamsKfintechParams as CasParserCamsKfintechParams,
745
- type CasParserCdslParams as CasParserCdslParams,
746
- type CasParserNsdlParams as CasParserNsdlParams,
747
- type CasParserSmartParseParams as CasParserSmartParseParams,
835
+ type CamsKfintechParseParams as CamsKfintechParseParams,
748
836
  };
749
837
 
838
+ export { Cdsl as Cdsl, type CdslParsePdfParams as CdslParsePdfParams };
839
+
750
840
  export {
751
- CasGenerator as CasGenerator,
752
- type CasGeneratorGenerateCasResponse as CasGeneratorGenerateCasResponse,
753
- type CasGeneratorGenerateCasParams as CasGeneratorGenerateCasParams,
841
+ ContractNote as ContractNote,
842
+ type ContractNoteParseResponse as ContractNoteParseResponse,
843
+ type ContractNoteParseParams as ContractNoteParseParams,
754
844
  };
845
+
846
+ export {
847
+ Inbox as Inbox,
848
+ type InboxCheckConnectionStatusResponse as InboxCheckConnectionStatusResponse,
849
+ type InboxConnectEmailResponse as InboxConnectEmailResponse,
850
+ type InboxDisconnectEmailResponse as InboxDisconnectEmailResponse,
851
+ type InboxListCasFilesResponse as InboxListCasFilesResponse,
852
+ type InboxCheckConnectionStatusParams as InboxCheckConnectionStatusParams,
853
+ type InboxConnectEmailParams as InboxConnectEmailParams,
854
+ type InboxDisconnectEmailParams as InboxDisconnectEmailParams,
855
+ type InboxListCasFilesParams as InboxListCasFilesParams,
856
+ };
857
+
858
+ export {
859
+ Kfintech as Kfintech,
860
+ type KfintechGenerateCasResponse as KfintechGenerateCasResponse,
861
+ type KfintechGenerateCasParams as KfintechGenerateCasParams,
862
+ };
863
+
864
+ export { Nsdl as Nsdl, type NsdlParseParams as NsdlParseParams };
865
+
866
+ export { Smart as Smart, type SmartParseCasPdfParams as SmartParseCasPdfParams };
755
867
  }
@@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: CasParser, props: APIRespo
29
29
  const mediaType = contentType?.split(';')[0]?.trim();
30
30
  const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
31
31
  if (isJSON) {
32
+ const contentLength = response.headers.get('content-length');
33
+ if (contentLength === '0') {
34
+ // if there is no content we can't do anything
35
+ return undefined as T;
36
+ }
37
+
32
38
  const json = await response.json();
33
39
  return json as T;
34
40
  }
@@ -73,7 +73,7 @@ export type ToFileInput =
73
73
 
74
74
  /**
75
75
  * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
76
- * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
76
+ * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
77
77
  * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
78
78
  * @param {Object=} options additional properties
79
79
  * @param {string=} options.type the MIME type of the content
@@ -76,21 +76,21 @@ export const coerceBoolean = (value: unknown): boolean => {
76
76
  };
77
77
 
78
78
  export const maybeCoerceInteger = (value: unknown): number | undefined => {
79
- if (value === undefined) {
79
+ if (value == null) {
80
80
  return undefined;
81
81
  }
82
82
  return coerceInteger(value);
83
83
  };
84
84
 
85
85
  export const maybeCoerceFloat = (value: unknown): number | undefined => {
86
- if (value === undefined) {
86
+ if (value == null) {
87
87
  return undefined;
88
88
  }
89
89
  return coerceFloat(value);
90
90
  };
91
91
 
92
92
  export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
93
- if (value === undefined) {
93
+ if (value == null) {
94
94
  return undefined;
95
95
  }
96
96
  return coerceBoolean(value);
@@ -0,0 +1,63 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import { APIPromise } from '../core/api-promise';
5
+ import { RequestOptions } from '../internal/request-options';
6
+
7
+ export class AccessToken extends APIResource {
8
+ /**
9
+ * Generate a short-lived access token from your API key.
10
+ *
11
+ * **Use this endpoint from your backend** to create tokens that can be safely
12
+ * passed to frontend/SDK.
13
+ *
14
+ * Access tokens:
15
+ *
16
+ * - Are prefixed with `at_` for easy identification
17
+ * - Valid for up to 60 minutes
18
+ * - Can be used in place of API keys on all v4 endpoints
19
+ * - Cannot be used to generate other access tokens
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const accessToken = await client.accessToken.create();
24
+ * ```
25
+ */
26
+ create(
27
+ body: AccessTokenCreateParams | null | undefined = {},
28
+ options?: RequestOptions,
29
+ ): APIPromise<AccessTokenCreateResponse> {
30
+ return this._client.post('/v1/access-token', { body, ...options });
31
+ }
32
+ }
33
+
34
+ export interface AccessTokenCreateResponse {
35
+ /**
36
+ * The at\_ prefixed access token
37
+ */
38
+ access_token?: string;
39
+
40
+ /**
41
+ * Token validity in seconds
42
+ */
43
+ expires_in?: number;
44
+
45
+ /**
46
+ * Always "api_key" - token is a drop-in replacement for x-api-key header
47
+ */
48
+ token_type?: string;
49
+ }
50
+
51
+ export interface AccessTokenCreateParams {
52
+ /**
53
+ * Token validity in minutes (max 60)
54
+ */
55
+ expiry_minutes?: number;
56
+ }
57
+
58
+ export declare namespace AccessToken {
59
+ export {
60
+ type AccessTokenCreateResponse as AccessTokenCreateResponse,
61
+ type AccessTokenCreateParams as AccessTokenCreateParams,
62
+ };
63
+ }