spitch 1.47.0 → 1.49.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.
- package/CHANGELOG.md +67 -0
- package/README.md +12 -18
- package/client.d.mts +5 -4
- package/client.d.mts.map +1 -1
- package/client.d.ts +5 -4
- package/client.d.ts.map +1 -1
- package/client.js +39 -23
- package/client.js.map +1 -1
- package/client.mjs +39 -23
- package/client.mjs.map +1 -1
- package/internal/types.d.mts +6 -6
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +6 -6
- package/internal/types.d.ts.map +1 -1
- package/internal/utils/env.js +2 -2
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs +2 -2
- package/internal/utils/env.mjs.map +1 -1
- package/internal/utils/query.d.mts +5 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +5 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +23 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +20 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils.d.mts +1 -0
- package/internal/utils.d.ts +1 -0
- package/internal/utils.js +1 -0
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +1 -0
- package/package.json +12 -1
- package/resources/files.d.mts +4 -0
- package/resources/files.d.mts.map +1 -1
- package/resources/files.d.ts +4 -0
- package/resources/files.d.ts.map +1 -1
- package/resources/files.js +6 -0
- package/resources/files.js.map +1 -1
- package/resources/files.mjs +6 -0
- package/resources/files.mjs.map +1 -1
- package/resources/speech.d.mts +37 -22
- package/resources/speech.d.mts.map +1 -1
- package/resources/speech.d.ts +37 -22
- package/resources/speech.d.ts.map +1 -1
- package/resources/speech.js +1 -2
- package/resources/speech.js.map +1 -1
- package/resources/speech.mjs +1 -2
- package/resources/speech.mjs.map +1 -1
- package/resources/text.d.mts +24 -4
- package/resources/text.d.mts.map +1 -1
- package/resources/text.d.ts +24 -4
- package/resources/text.d.ts.map +1 -1
- package/resources/text.js +1 -1
- package/resources/text.mjs +1 -1
- package/src/client.ts +50 -30
- package/src/internal/types.ts +6 -8
- package/src/internal/utils/env.ts +2 -2
- package/src/internal/utils/query.ts +23 -0
- package/src/internal/utils.ts +1 -0
- package/src/resources/files.ts +7 -0
- package/src/resources/speech.ts +45 -26
- package/src/resources/text.ts +27 -5
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/resources/files.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.mjs","sourceRoot":"","sources":["../src/resources/files.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAEf,EAAE,WAAW,EAAuC;OAGpD,EAAE,2BAA2B,EAAE;OAC/B,EAAE,IAAI,EAAE;AAEf,MAAM,OAAO,KAAM,SAAQ,WAAW;IACpC;;OAEG;IACH,IAAI,CACF,QAA2C,EAAE,EAC7C,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,CAAA,WAAqB,CAAA,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAc,EAAE,OAAwB;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAA,aAAa,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,QAAQ,CACN,MAAc,EACd,QAA+C,EAAE,EACjD,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAA,aAAa,MAAM,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAChF,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAsB,EAAE,OAAwB;QACrD,OAAO,IAAI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CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAsB,EAAE,OAAwB;QACrD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,2BAA2B,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACzG,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAwB;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACF"}
|
package/resources/speech.d.mts
CHANGED
|
@@ -7,8 +7,7 @@ import { RequestOptions } from "../internal/request-options.mjs";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class Speech extends APIResource {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* format. Audio is retured in chunks.
|
|
10
|
+
* Generate audio
|
|
12
11
|
*/
|
|
13
12
|
generate(body: SpeechGenerateParams, options?: RequestOptions): APIPromise<Response>;
|
|
14
13
|
/**
|
|
@@ -42,39 +41,55 @@ export interface Transcription {
|
|
|
42
41
|
/**
|
|
43
42
|
* for audit purposes.
|
|
44
43
|
*/
|
|
45
|
-
request_id
|
|
46
|
-
text: string;
|
|
47
|
-
/**
|
|
48
|
-
* sentence-level or word-level groupings of your transcript. Each sentence (or
|
|
49
|
-
* word) will fall within a time range.
|
|
50
|
-
*/
|
|
51
|
-
segments?: Array<Segment> | null;
|
|
44
|
+
request_id?: string;
|
|
52
45
|
/**
|
|
53
|
-
*
|
|
46
|
+
* Either `sentence-level` or `word-level` groupings of your transcript. Each
|
|
54
47
|
* sentence (or word) will fall within a time range.
|
|
55
48
|
*/
|
|
56
|
-
|
|
49
|
+
segments?: Array<Segment> | null;
|
|
50
|
+
text?: string;
|
|
57
51
|
}
|
|
58
52
|
export interface SpeechGenerateParams {
|
|
59
|
-
|
|
53
|
+
/**
|
|
54
|
+
* The text for which you want to generate audio.
|
|
55
|
+
*/
|
|
60
56
|
text: string;
|
|
61
|
-
voice: 'sade' | 'segun' | 'femi' | 'funmi' | 'amina' | 'aliyu' | 'hasan' | 'zainab' | 'john' | 'jude' | 'lina' | 'lucy' | 'henry' | 'kani' | 'ngozi' | 'amara' | 'obinna' | 'ebuka' | 'hana' | 'selam' | 'tena' | 'tesfaye';
|
|
62
57
|
/**
|
|
63
|
-
*
|
|
58
|
+
* The voice you want to be used for audio generation.
|
|
59
|
+
*/
|
|
60
|
+
voice: 'sade' | 'segun' | 'femi' | 'funmi' | 'amina' | 'aliyu' | 'hasan' | 'zainab' | 'john' | 'jude' | 'lina' | 'lucy' | 'henry' | 'kani' | 'remi' | 'kingsley' | 'ngozi' | 'amara' | 'obinna' | 'ebuka' | 'hana' | 'haile' | 'tena' | 'tesfaye' | 'ufoma' | 'tega' | 'justice' | 'boma';
|
|
61
|
+
/**
|
|
62
|
+
* The audio format for the returned audio data, defaults to `wav`.
|
|
64
63
|
*/
|
|
65
64
|
format?: 'mp3' | 'wav' | 'ogg_opus' | 'webm_opus' | 'mulaw' | 'alaw' | 'flac' | 'pcm_s16le';
|
|
66
|
-
|
|
65
|
+
/**
|
|
66
|
+
* This is optional; an ISO 639 language code to be used for the generation.
|
|
67
|
+
*/
|
|
68
|
+
language?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The speed of the voice, defaults to `1.0`
|
|
71
|
+
*/
|
|
72
|
+
speed?: number;
|
|
67
73
|
}
|
|
68
74
|
export interface SpeechTranscribeParams {
|
|
69
|
-
language: 'yo' | 'en' | 'ha' | 'ig' | 'am' | 'pcm';
|
|
70
|
-
content?: Uploadable | string | null;
|
|
71
|
-
model?: 'mansa_v1' | 'legacy' | null;
|
|
72
|
-
special_words?: string | null;
|
|
73
|
-
timestamp?: 'sentence' | 'word' | 'none' | null;
|
|
74
75
|
/**
|
|
75
|
-
*
|
|
76
|
+
* The audio file or content that you want to transcribe. This could be;
|
|
77
|
+
* `file bytes`, a `url to an audio file` (ensure the link does not require
|
|
78
|
+
* authentication to access the file) or a `file UUID`.
|
|
79
|
+
*/
|
|
80
|
+
content: Uploadable | string;
|
|
81
|
+
/**
|
|
82
|
+
* This is optional, an ISO-639 language code that corresponds to the language in
|
|
83
|
+
* the `content`.
|
|
84
|
+
*/
|
|
85
|
+
language?: string | null;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Select the model to be used to perform the transcription, this param
|
|
88
|
+
* has been deprecated.
|
|
76
89
|
*/
|
|
77
|
-
|
|
90
|
+
model?: 'mansa_v1' | 'legacy' | null;
|
|
91
|
+
special_words?: string | null;
|
|
92
|
+
timestamp?: 'sentence' | 'word' | null;
|
|
78
93
|
}
|
|
79
94
|
export declare namespace Speech {
|
|
80
95
|
export { type Segment as Segment, type Transcription as Transcription, type SpeechGenerateParams as SpeechGenerateParams, type SpeechTranscribeParams as SpeechTranscribeParams, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech.d.mts","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,KAAK,UAAU,EAAE;OAEnB,EAAE,cAAc,EAAE;AAGzB;;GAEG;AACH,qBAAa,MAAO,SAAQ,WAAW;IACrC
|
|
1
|
+
{"version":3,"file":"speech.d.mts","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,KAAK,UAAU,EAAE;OAEnB,EAAE,cAAc,EAAE;AAGzB;;GAEG;AACH,qBAAa,MAAO,SAAQ,WAAW;IACrC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC;IASpF;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,U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AAU,GAAG,QAAQ,GAAG,IAAI,CAAC;IAErC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B,SAAS,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,OAAO,EACL,KAAK,OAAO,IAAI,OAAO,EACvB,KAAK,aAAa,IAAI,aAAa,EACnC,KAAK,oBAAoB,IAAI,oBAAoB,EACjD,KAAK,sBAAsB,IAAI,sBAAsB,GACtD,CAAC;CACH"}
|
package/resources/speech.d.ts
CHANGED
|
@@ -7,8 +7,7 @@ import { RequestOptions } from "../internal/request-options.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class Speech extends APIResource {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* format. Audio is retured in chunks.
|
|
10
|
+
* Generate audio
|
|
12
11
|
*/
|
|
13
12
|
generate(body: SpeechGenerateParams, options?: RequestOptions): APIPromise<Response>;
|
|
14
13
|
/**
|
|
@@ -42,39 +41,55 @@ export interface Transcription {
|
|
|
42
41
|
/**
|
|
43
42
|
* for audit purposes.
|
|
44
43
|
*/
|
|
45
|
-
request_id
|
|
46
|
-
text: string;
|
|
47
|
-
/**
|
|
48
|
-
* sentence-level or word-level groupings of your transcript. Each sentence (or
|
|
49
|
-
* word) will fall within a time range.
|
|
50
|
-
*/
|
|
51
|
-
segments?: Array<Segment> | null;
|
|
44
|
+
request_id?: string;
|
|
52
45
|
/**
|
|
53
|
-
*
|
|
46
|
+
* Either `sentence-level` or `word-level` groupings of your transcript. Each
|
|
54
47
|
* sentence (or word) will fall within a time range.
|
|
55
48
|
*/
|
|
56
|
-
|
|
49
|
+
segments?: Array<Segment> | null;
|
|
50
|
+
text?: string;
|
|
57
51
|
}
|
|
58
52
|
export interface SpeechGenerateParams {
|
|
59
|
-
|
|
53
|
+
/**
|
|
54
|
+
* The text for which you want to generate audio.
|
|
55
|
+
*/
|
|
60
56
|
text: string;
|
|
61
|
-
voice: 'sade' | 'segun' | 'femi' | 'funmi' | 'amina' | 'aliyu' | 'hasan' | 'zainab' | 'john' | 'jude' | 'lina' | 'lucy' | 'henry' | 'kani' | 'ngozi' | 'amara' | 'obinna' | 'ebuka' | 'hana' | 'selam' | 'tena' | 'tesfaye';
|
|
62
57
|
/**
|
|
63
|
-
*
|
|
58
|
+
* The voice you want to be used for audio generation.
|
|
59
|
+
*/
|
|
60
|
+
voice: 'sade' | 'segun' | 'femi' | 'funmi' | 'amina' | 'aliyu' | 'hasan' | 'zainab' | 'john' | 'jude' | 'lina' | 'lucy' | 'henry' | 'kani' | 'remi' | 'kingsley' | 'ngozi' | 'amara' | 'obinna' | 'ebuka' | 'hana' | 'haile' | 'tena' | 'tesfaye' | 'ufoma' | 'tega' | 'justice' | 'boma';
|
|
61
|
+
/**
|
|
62
|
+
* The audio format for the returned audio data, defaults to `wav`.
|
|
64
63
|
*/
|
|
65
64
|
format?: 'mp3' | 'wav' | 'ogg_opus' | 'webm_opus' | 'mulaw' | 'alaw' | 'flac' | 'pcm_s16le';
|
|
66
|
-
|
|
65
|
+
/**
|
|
66
|
+
* This is optional; an ISO 639 language code to be used for the generation.
|
|
67
|
+
*/
|
|
68
|
+
language?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The speed of the voice, defaults to `1.0`
|
|
71
|
+
*/
|
|
72
|
+
speed?: number;
|
|
67
73
|
}
|
|
68
74
|
export interface SpeechTranscribeParams {
|
|
69
|
-
language: 'yo' | 'en' | 'ha' | 'ig' | 'am' | 'pcm';
|
|
70
|
-
content?: Uploadable | string | null;
|
|
71
|
-
model?: 'mansa_v1' | 'legacy' | null;
|
|
72
|
-
special_words?: string | null;
|
|
73
|
-
timestamp?: 'sentence' | 'word' | 'none' | null;
|
|
74
75
|
/**
|
|
75
|
-
*
|
|
76
|
+
* The audio file or content that you want to transcribe. This could be;
|
|
77
|
+
* `file bytes`, a `url to an audio file` (ensure the link does not require
|
|
78
|
+
* authentication to access the file) or a `file UUID`.
|
|
79
|
+
*/
|
|
80
|
+
content: Uploadable | string;
|
|
81
|
+
/**
|
|
82
|
+
* This is optional, an ISO-639 language code that corresponds to the language in
|
|
83
|
+
* the `content`.
|
|
84
|
+
*/
|
|
85
|
+
language?: string | null;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Select the model to be used to perform the transcription, this param
|
|
88
|
+
* has been deprecated.
|
|
76
89
|
*/
|
|
77
|
-
|
|
90
|
+
model?: 'mansa_v1' | 'legacy' | null;
|
|
91
|
+
special_words?: string | null;
|
|
92
|
+
timestamp?: 'sentence' | 'word' | null;
|
|
78
93
|
}
|
|
79
94
|
export declare namespace Speech {
|
|
80
95
|
export { type Segment as Segment, type Transcription as Transcription, type SpeechGenerateParams as SpeechGenerateParams, type SpeechTranscribeParams as SpeechTranscribeParams, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech.d.ts","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,KAAK,UAAU,EAAE;OAEnB,EAAE,cAAc,EAAE;AAGzB;;GAEG;AACH,qBAAa,MAAO,SAAQ,WAAW;IACrC
|
|
1
|
+
{"version":3,"file":"speech.d.ts","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,KAAK,UAAU,EAAE;OAEnB,EAAE,cAAc,EAAE;AAGzB;;GAEG;AACH,qBAAa,MAAO,SAAQ,WAAW;IACrC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC;IASpF;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,aAAa,CAAC;CA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AAI,CAAC;IAErC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B,SAAS,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,OAAO,EACL,KAAK,OAAO,IAAI,OAAO,EACvB,KAAK,aAAa,IAAI,aAAa,EACnC,KAAK,oBAAoB,IAAI,oBAAoB,EACjD,KAAK,sBAAsB,IAAI,sBAAsB,GACtD,CAAC;CACH"}
|
package/resources/speech.js
CHANGED
|
@@ -10,8 +10,7 @@ const uploads_1 = require("../internal/uploads.js");
|
|
|
10
10
|
*/
|
|
11
11
|
class Speech extends resource_1.APIResource {
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* format. Audio is retured in chunks.
|
|
13
|
+
* Generate audio
|
|
15
14
|
*/
|
|
16
15
|
generate(body, options) {
|
|
17
16
|
return this._client.post('/v1/speech', {
|
package/resources/speech.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech.js","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kDAA+C;AAG/C,oDAAmD;AAEnD,oDAAkE;AAElE;;GAEG;AACH,MAAa,MAAO,SAAQ,sBAAW;IACrC
|
|
1
|
+
{"version":3,"file":"speech.js","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kDAA+C;AAG/C,oDAAmD;AAEnD,oDAAkE;AAElE;;GAEG;AACH,MAAa,MAAO,SAAQ,sBAAW;IACrC;;OAEG;IACH,QAAQ,CAAC,IAA0B,EAAE,OAAwB;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE;YACrC,IAAI;YACJ,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAClE,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,IAA4B,EAAE,OAAwB;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CACtB,oBAAoB,EACpB,IAAA,qCAA2B,EAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAChE,CAAC;IACJ,CAAC;CACF;AAvBD,wBAuBC"}
|
package/resources/speech.mjs
CHANGED
|
@@ -7,8 +7,7 @@ import { multipartFormRequestOptions } from "../internal/uploads.mjs";
|
|
|
7
7
|
*/
|
|
8
8
|
export class Speech extends APIResource {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* format. Audio is retured in chunks.
|
|
10
|
+
* Generate audio
|
|
12
11
|
*/
|
|
13
12
|
generate(body, options) {
|
|
14
13
|
return this._client.post('/v1/speech', {
|
package/resources/speech.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech.mjs","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAGf,EAAE,YAAY,EAAE;OAEhB,EAAE,2BAA2B,EAAE;AAEtC;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,WAAW;IACrC
|
|
1
|
+
{"version":3,"file":"speech.mjs","sourceRoot":"","sources":["../src/resources/speech.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAGf,EAAE,YAAY,EAAE;OAEhB,EAAE,2BAA2B,EAAE;AAEtC;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,WAAW;IACrC;;OAEG;IACH,QAAQ,CAAC,IAA0B,EAAE,OAAwB;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE;YACrC,IAAI;YACJ,GAAG,OAAO;YACV,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAClE,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,IAA4B,EAAE,OAAwB;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CACtB,oBAAoB,EACpB,2BAA2B,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAChE,CAAC;IACJ,CAAC;CACF"}
|
package/resources/text.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { APIPromise } from "../core/api-promise.mjs";
|
|
|
3
3
|
import { RequestOptions } from "../internal/request-options.mjs";
|
|
4
4
|
export declare class Text extends APIResource {
|
|
5
5
|
/**
|
|
6
|
-
* Add
|
|
6
|
+
* Add appropriate tone marks to text.
|
|
7
7
|
*/
|
|
8
8
|
toneMark(body: TextToneMarkParams, options?: RequestOptions): APIPromise<Diacritics>;
|
|
9
9
|
/**
|
|
@@ -21,13 +21,33 @@ export interface Translation {
|
|
|
21
21
|
text: string;
|
|
22
22
|
}
|
|
23
23
|
export interface TextToneMarkParams {
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Only Yoruba is supported at the moment.
|
|
26
|
+
*/
|
|
27
|
+
language: string;
|
|
25
28
|
text: string;
|
|
26
29
|
}
|
|
27
30
|
export interface TextTranslateParams {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* An ISO 639 code of the language you want to translate to.
|
|
33
|
+
*/
|
|
34
|
+
target: string;
|
|
35
|
+
/**
|
|
36
|
+
* The text to be translated.
|
|
37
|
+
*/
|
|
30
38
|
text: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to be `formal` or `casual`.
|
|
41
|
+
*/
|
|
42
|
+
formality?: 'casual' | 'formal';
|
|
43
|
+
/**
|
|
44
|
+
* An ISO 639 code of the language you're translating from
|
|
45
|
+
*/
|
|
46
|
+
source?: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* The tone of the translated text.
|
|
49
|
+
*/
|
|
50
|
+
tone?: 'neutral' | 'warm' | 'professional' | 'narration';
|
|
31
51
|
}
|
|
32
52
|
export declare namespace Text {
|
|
33
53
|
export { type Diacritics as Diacritics, type Translation as Translation, type TextToneMarkParams as TextToneMarkParams, type TextTranslateParams as TextTranslateParams, };
|
package/resources/text.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.mts","sourceRoot":"","sources":["../src/resources/text.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,cAAc,EAAE;AAEzB,qBAAa,IAAK,SAAQ,WAAW;IACnC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC;IAIpF;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,WAAW,CAAC;CAGxF;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"text.d.mts","sourceRoot":"","sources":["../src/resources/text.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,cAAc,EAAE;AAEzB,qBAAa,IAAK,SAAQ,WAAW;IACnC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC;IAIpF;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,WAAW,CAAC;CAGxF;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAEhC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,WAAW,CAAC;CAC1D;AAED,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B,OAAO,EACL,KAAK,UAAU,IAAI,UAAU,EAC7B,KAAK,WAAW,IAAI,WAAW,EAC/B,KAAK,kBAAkB,IAAI,kBAAkB,EAC7C,KAAK,mBAAmB,IAAI,mBAAmB,GAChD,CAAC;CACH"}
|
package/resources/text.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { APIPromise } from "../core/api-promise.js";
|
|
|
3
3
|
import { RequestOptions } from "../internal/request-options.js";
|
|
4
4
|
export declare class Text extends APIResource {
|
|
5
5
|
/**
|
|
6
|
-
* Add
|
|
6
|
+
* Add appropriate tone marks to text.
|
|
7
7
|
*/
|
|
8
8
|
toneMark(body: TextToneMarkParams, options?: RequestOptions): APIPromise<Diacritics>;
|
|
9
9
|
/**
|
|
@@ -21,13 +21,33 @@ export interface Translation {
|
|
|
21
21
|
text: string;
|
|
22
22
|
}
|
|
23
23
|
export interface TextToneMarkParams {
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Only Yoruba is supported at the moment.
|
|
26
|
+
*/
|
|
27
|
+
language: string;
|
|
25
28
|
text: string;
|
|
26
29
|
}
|
|
27
30
|
export interface TextTranslateParams {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* An ISO 639 code of the language you want to translate to.
|
|
33
|
+
*/
|
|
34
|
+
target: string;
|
|
35
|
+
/**
|
|
36
|
+
* The text to be translated.
|
|
37
|
+
*/
|
|
30
38
|
text: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to be `formal` or `casual`.
|
|
41
|
+
*/
|
|
42
|
+
formality?: 'casual' | 'formal';
|
|
43
|
+
/**
|
|
44
|
+
* An ISO 639 code of the language you're translating from
|
|
45
|
+
*/
|
|
46
|
+
source?: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* The tone of the translated text.
|
|
49
|
+
*/
|
|
50
|
+
tone?: 'neutral' | 'warm' | 'professional' | 'narration';
|
|
31
51
|
}
|
|
32
52
|
export declare namespace Text {
|
|
33
53
|
export { type Diacritics as Diacritics, type Translation as Translation, type TextToneMarkParams as TextToneMarkParams, type TextTranslateParams as TextTranslateParams, };
|
package/resources/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/resources/text.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,EAAE,UAAU,EAAE;OACd,EAAE,cAAc,EAAE;AAEzB,qBAAa,IAAK,SAAQ,WAAW;IACnC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,UAAU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G;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,WAAW,CAAC;CAC1D;AAED,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B,OAAO,EACL,KAAK,UAAU,IAAI,UAAU,EAC7B,KAAK,WAAW,IAAI,WAAW,EAC/B,KAAK,kBAAkB,IAAI,kBAAkB,EAC7C,KAAK,mBAAmB,IAAI,mBAAmB,GAChD,CAAC;CACH"}
|
package/resources/text.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.Text = void 0;
|
|
|
5
5
|
const resource_1 = require("../core/resource.js");
|
|
6
6
|
class Text extends resource_1.APIResource {
|
|
7
7
|
/**
|
|
8
|
-
* Add
|
|
8
|
+
* Add appropriate tone marks to text.
|
|
9
9
|
*/
|
|
10
10
|
toneMark(body, options) {
|
|
11
11
|
return this._client.post('/v1/diacritics', { body, ...options });
|
package/resources/text.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { APIResource } from "../core/resource.mjs";
|
|
3
3
|
export class Text extends APIResource {
|
|
4
4
|
/**
|
|
5
|
-
* Add
|
|
5
|
+
* Add appropriate tone marks to text.
|
|
6
6
|
*/
|
|
7
7
|
toneMark(body, options) {
|
|
8
8
|
return this._client.post('/v1/diacritics', { body, ...options });
|
package/src/client.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { APIResponseProps } from './internal/parse';
|
|
|
11
11
|
import { getPlatformHeaders } from './internal/detect-platform';
|
|
12
12
|
import * as Shims from './internal/shims';
|
|
13
13
|
import * as Opts from './internal/request-options';
|
|
14
|
+
import { stringifyQuery } from './internal/utils/query';
|
|
14
15
|
import { VERSION } from './version';
|
|
15
16
|
import * as Errors from './core/error';
|
|
16
17
|
import * as Pagination from './core/pagination';
|
|
@@ -151,7 +152,7 @@ export class Spitch {
|
|
|
151
152
|
*
|
|
152
153
|
* @param {string | undefined} [opts.apiKey=process.env['SPITCH_API_KEY'] ?? undefined]
|
|
153
154
|
* @param {boolean | null | undefined} [opts.dataRetention=true]
|
|
154
|
-
* @param {string} [opts.baseURL=process.env['SPITCH_BASE_URL'] ?? https://api.
|
|
155
|
+
* @param {string} [opts.baseURL=process.env['SPITCH_BASE_URL'] ?? https://api.spitch.app] - Override the default base URL for the API.
|
|
155
156
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
156
157
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
157
158
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -175,7 +176,7 @@ export class Spitch {
|
|
|
175
176
|
apiKey,
|
|
176
177
|
dataRetention,
|
|
177
178
|
...opts,
|
|
178
|
-
baseURL: baseURL || `https://api.
|
|
179
|
+
baseURL: baseURL || `https://api.spitch.app`,
|
|
179
180
|
};
|
|
180
181
|
|
|
181
182
|
this.baseURL = options.baseURL!;
|
|
@@ -193,6 +194,18 @@ export class Spitch {
|
|
|
193
194
|
this.fetch = options.fetch ?? Shims.getDefaultFetch();
|
|
194
195
|
this.#encoder = Opts.FallbackEncoder;
|
|
195
196
|
|
|
197
|
+
const customHeadersEnv = readEnv('SPITCH_CUSTOM_HEADERS');
|
|
198
|
+
if (customHeadersEnv) {
|
|
199
|
+
const parsed: Record<string, string> = {};
|
|
200
|
+
for (const line of customHeadersEnv.split('\n')) {
|
|
201
|
+
const colon = line.indexOf(':');
|
|
202
|
+
if (colon >= 0) {
|
|
203
|
+
parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
|
|
207
|
+
}
|
|
208
|
+
|
|
196
209
|
this._options = options;
|
|
197
210
|
|
|
198
211
|
this.apiKey = apiKey;
|
|
@@ -223,7 +236,7 @@ export class Spitch {
|
|
|
223
236
|
* Check whether the base URL is set to its default.
|
|
224
237
|
*/
|
|
225
238
|
#baseURLOverridden(): boolean {
|
|
226
|
-
return this.baseURL !== 'https://api.
|
|
239
|
+
return this.baseURL !== 'https://api.spitch.app';
|
|
227
240
|
}
|
|
228
241
|
|
|
229
242
|
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
@@ -241,21 +254,8 @@ export class Spitch {
|
|
|
241
254
|
/**
|
|
242
255
|
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
243
256
|
*/
|
|
244
|
-
protected stringifyQuery(query: Record<string, unknown>): string {
|
|
245
|
-
return
|
|
246
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
247
|
-
.map(([key, value]) => {
|
|
248
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
249
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
250
|
-
}
|
|
251
|
-
if (value === null) {
|
|
252
|
-
return `${encodeURIComponent(key)}=`;
|
|
253
|
-
}
|
|
254
|
-
throw new Errors.SpitchError(
|
|
255
|
-
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
256
|
-
);
|
|
257
|
-
})
|
|
258
|
-
.join('&');
|
|
257
|
+
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
258
|
+
return stringifyQuery(query);
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
private getUserAgent(): string {
|
|
@@ -287,12 +287,13 @@ export class Spitch {
|
|
|
287
287
|
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
288
288
|
|
|
289
289
|
const defaultQuery = this.defaultQuery();
|
|
290
|
-
|
|
291
|
-
|
|
290
|
+
const pathQuery = Object.fromEntries(url.searchParams);
|
|
291
|
+
if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
292
|
+
query = { ...pathQuery, ...defaultQuery, ...query };
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
295
|
-
url.search = this.stringifyQuery(query
|
|
296
|
+
url.search = this.stringifyQuery(query);
|
|
296
297
|
}
|
|
297
298
|
|
|
298
299
|
return url.toString();
|
|
@@ -476,7 +477,7 @@ export class Spitch {
|
|
|
476
477
|
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
477
478
|
|
|
478
479
|
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
479
|
-
const errJSON = safeJSON(errText);
|
|
480
|
+
const errJSON = safeJSON(errText) as any;
|
|
480
481
|
const errMessage = errJSON ? undefined : errText;
|
|
481
482
|
|
|
482
483
|
loggerFor(this).debug(
|
|
@@ -513,9 +514,14 @@ export class Spitch {
|
|
|
513
514
|
getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
|
|
514
515
|
path: string,
|
|
515
516
|
Page: new (...args: any[]) => PageClass,
|
|
516
|
-
opts?: RequestOptions
|
|
517
|
+
opts?: PromiseOrValue<RequestOptions>,
|
|
517
518
|
): Pagination.PagePromise<PageClass, Item> {
|
|
518
|
-
return this.requestAPIList(
|
|
519
|
+
return this.requestAPIList(
|
|
520
|
+
Page,
|
|
521
|
+
opts && 'then' in opts ?
|
|
522
|
+
opts.then((opts) => ({ method: 'get', path, ...opts }))
|
|
523
|
+
: { method: 'get', path, ...opts },
|
|
524
|
+
);
|
|
519
525
|
}
|
|
520
526
|
|
|
521
527
|
requestAPIList<
|
|
@@ -523,7 +529,7 @@ export class Spitch {
|
|
|
523
529
|
PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
|
|
524
530
|
>(
|
|
525
531
|
Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
|
|
526
|
-
options: FinalRequestOptions
|
|
532
|
+
options: PromiseOrValue<FinalRequestOptions>,
|
|
527
533
|
): Pagination.PagePromise<PageClass, Item> {
|
|
528
534
|
const request = this.makeRequest(options, null, undefined);
|
|
529
535
|
return new Pagination.PagePromise<PageClass, Item>(this as any as Spitch, request, Page);
|
|
@@ -536,7 +542,7 @@ export class Spitch {
|
|
|
536
542
|
controller: AbortController,
|
|
537
543
|
): Promise<Response> {
|
|
538
544
|
const { signal, method, ...options } = init || {};
|
|
539
|
-
const abort =
|
|
545
|
+
const abort = this._makeAbort(controller);
|
|
540
546
|
if (signal) signal.addEventListener('abort', abort, { once: true });
|
|
541
547
|
|
|
542
548
|
const timeout = setTimeout(abort, ms);
|
|
@@ -616,9 +622,9 @@ export class Spitch {
|
|
|
616
622
|
}
|
|
617
623
|
}
|
|
618
624
|
|
|
619
|
-
// If the API asks us to wait a certain amount of time
|
|
620
|
-
//
|
|
621
|
-
if (
|
|
625
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
626
|
+
// says, but otherwise calculate a default
|
|
627
|
+
if (timeoutMillis === undefined) {
|
|
622
628
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
623
629
|
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
624
630
|
}
|
|
@@ -628,7 +634,7 @@ export class Spitch {
|
|
|
628
634
|
}
|
|
629
635
|
|
|
630
636
|
private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {
|
|
631
|
-
const initialRetryDelay = 0.
|
|
637
|
+
const initialRetryDelay = 0.35;
|
|
632
638
|
const maxRetryDelay = 10.0;
|
|
633
639
|
|
|
634
640
|
const numRetries = maxRetries - retriesRemaining;
|
|
@@ -707,6 +713,12 @@ export class Spitch {
|
|
|
707
713
|
return headers.values;
|
|
708
714
|
}
|
|
709
715
|
|
|
716
|
+
private _makeAbort(controller: AbortController) {
|
|
717
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
718
|
+
// would capture all request options, and cause a memory leak.
|
|
719
|
+
return () => controller.abort();
|
|
720
|
+
}
|
|
721
|
+
|
|
710
722
|
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
|
|
711
723
|
bodyHeaders: HeadersLike;
|
|
712
724
|
body: BodyInit | undefined;
|
|
@@ -739,6 +751,14 @@ export class Spitch {
|
|
|
739
751
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
|
|
740
752
|
) {
|
|
741
753
|
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
|
|
754
|
+
} else if (
|
|
755
|
+
typeof body === 'object' &&
|
|
756
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
|
|
757
|
+
) {
|
|
758
|
+
return {
|
|
759
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
760
|
+
body: this.stringifyQuery(body),
|
|
761
|
+
};
|
|
742
762
|
} else {
|
|
743
763
|
return this.#encoder({ body, headers });
|
|
744
764
|
}
|
package/src/internal/types.ts
CHANGED
|
@@ -40,7 +40,6 @@ type OverloadedParameters<T> =
|
|
|
40
40
|
: T extends (...args: infer A) => unknown ? A
|
|
41
41
|
: never;
|
|
42
42
|
|
|
43
|
-
/* eslint-disable */
|
|
44
43
|
/**
|
|
45
44
|
* These imports attempt to get types from a parent package's dependencies.
|
|
46
45
|
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
|
@@ -63,19 +62,18 @@ type OverloadedParameters<T> =
|
|
|
63
62
|
*
|
|
64
63
|
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
|
65
64
|
*/
|
|
66
|
-
/** @ts-ignore For users with \@types/node */
|
|
65
|
+
/** @ts-ignore For users with \@types/node */ /* prettier-ignore */
|
|
67
66
|
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit>;
|
|
68
|
-
/** @ts-ignore For users with undici */
|
|
67
|
+
/** @ts-ignore For users with undici */ /* prettier-ignore */
|
|
69
68
|
type UndiciRequestInit = NotAny<import('../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici/index.d.ts').RequestInit>;
|
|
70
|
-
/** @ts-ignore For users with \@types/bun */
|
|
69
|
+
/** @ts-ignore For users with \@types/bun */ /* prettier-ignore */
|
|
71
70
|
type BunRequestInit = globalThis.FetchRequestInit;
|
|
72
|
-
/** @ts-ignore For users with node-fetch@2 */
|
|
71
|
+
/** @ts-ignore For users with node-fetch@2 */ /* prettier-ignore */
|
|
73
72
|
type NodeFetch2RequestInit = NotAny<import('../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit>;
|
|
74
|
-
/** @ts-ignore For users with node-fetch@3, doesn't need file extension because types are at ./@types/index.d.ts */
|
|
73
|
+
/** @ts-ignore For users with node-fetch@3, doesn't need file extension because types are at ./@types/index.d.ts */ /* prettier-ignore */
|
|
75
74
|
type NodeFetch3RequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
|
|
76
|
-
/** @ts-ignore For users who use Deno */
|
|
75
|
+
/** @ts-ignore For users who use Deno */ /* prettier-ignore */
|
|
77
76
|
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
|
78
|
-
/* eslint-enable */
|
|
79
77
|
|
|
80
78
|
type RequestInits =
|
|
81
79
|
| NotAny<UndiciTypesRequestInit>
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export const readEnv = (env: string): string | undefined => {
|
|
11
11
|
if (typeof (globalThis as any).process !== 'undefined') {
|
|
12
|
-
return (globalThis as any).process.env?.[env]?.trim()
|
|
12
|
+
return (globalThis as any).process.env?.[env]?.trim() || undefined;
|
|
13
13
|
}
|
|
14
14
|
if (typeof (globalThis as any).Deno !== 'undefined') {
|
|
15
|
-
return (globalThis as any).Deno.env?.get?.(env)?.trim();
|
|
15
|
+
return (globalThis as any).Deno.env?.get?.(env)?.trim() || undefined;
|
|
16
16
|
}
|
|
17
17
|
return undefined;
|
|
18
18
|
};
|