@speechall/sdk 1.0.0 → 2.1.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/.beads/README.md +81 -0
- package/.beads/config.yaml +62 -0
- package/.beads/issues.jsonl +47 -0
- package/.beads/metadata.json +4 -0
- package/.env.example +5 -0
- package/.fernignore +45 -0
- package/.gitattributes +3 -0
- package/.github/copilot-instructions.md +78 -0
- package/.github/workflows/auto-release-simple.yml.deprecated +106 -0
- package/.github/workflows/auto-release.yml +67 -0
- package/.github/workflows/ci.yml +41 -0
- package/.github/workflows/release.yml +57 -0
- package/AGENTS.md +94 -0
- package/CHANGELOG.md +65 -0
- package/CLAUDE.md +129 -0
- package/README.md +294 -155
- package/examples/CLAUDE.md +136 -0
- package/examples/advanced-options.ts +213 -0
- package/examples/basic-transcription.ts +66 -0
- package/examples/error-handling.ts +251 -0
- package/examples/list-models.ts +112 -0
- package/examples/remote-transcription.ts +60 -0
- package/fern/fern.config.json +4 -0
- package/fern/generators.yml +43 -0
- package/jest.config.js +11 -0
- package/package.json +26 -46
- package/regenerate.sh +45 -0
- package/scripts/fix-generated-code.sh +25 -0
- package/src/BaseClient.ts +82 -0
- package/src/Client.ts +30 -0
- package/src/api/errors/BadRequestError.ts +22 -0
- package/src/api/errors/GatewayTimeoutError.ts +22 -0
- package/src/api/errors/InternalServerError.ts +22 -0
- package/src/api/errors/NotFoundError.ts +22 -0
- package/src/api/errors/PaymentRequiredError.ts +22 -0
- package/src/api/errors/ServiceUnavailableError.ts +22 -0
- package/src/api/errors/TooManyRequestsError.ts +22 -0
- package/src/api/errors/UnauthorizedError.ts +22 -0
- package/src/api/errors/index.ts +8 -0
- package/src/api/index.ts +3 -0
- package/src/api/resources/index.ts +5 -0
- package/src/api/resources/replacementRules/client/Client.ts +148 -0
- package/src/api/resources/replacementRules/client/index.ts +1 -0
- package/src/api/resources/replacementRules/client/requests/CreateReplacementRulesetRequest.ts +25 -0
- package/src/api/resources/replacementRules/client/requests/index.ts +1 -0
- package/src/api/resources/replacementRules/index.ts +2 -0
- package/src/api/resources/replacementRules/types/CreateReplacementRulesetResponse.ts +6 -0
- package/src/api/resources/replacementRules/types/index.ts +1 -0
- package/src/api/resources/speechToText/client/Client.ts +275 -0
- package/src/api/resources/speechToText/client/index.ts +1 -0
- package/src/api/resources/speechToText/client/requests/RemoteTranscriptionConfiguration.ts +20 -0
- package/src/api/resources/speechToText/client/requests/TranscribeRequest.ts +26 -0
- package/src/api/resources/speechToText/client/requests/index.ts +2 -0
- package/src/api/resources/speechToText/index.ts +1 -0
- package/src/api/types/BaseTranscriptionConfiguration.ts +29 -0
- package/src/api/types/ErrorResponse.ts +11 -0
- package/src/api/types/ExactRule.ts +13 -0
- package/src/api/types/RegexGroupRule.ts +28 -0
- package/src/api/types/RegexRule.ts +28 -0
- package/src/api/types/ReplacementRule.ts +25 -0
- package/src/api/types/SpeechToTextModel.ts +90 -0
- package/src/api/types/TranscriptLanguageCode.ts +114 -0
- package/src/api/types/TranscriptOutputFormat.ts +18 -0
- package/src/api/types/TranscriptionDetailed.ts +19 -0
- package/src/api/types/TranscriptionModelIdentifier.ts +70 -0
- package/src/api/types/TranscriptionOnlyText.ts +11 -0
- package/src/api/types/TranscriptionProvider.ts +23 -0
- package/src/api/types/TranscriptionResponse.ts +8 -0
- package/src/api/types/TranscriptionSegment.ts +17 -0
- package/src/api/types/TranscriptionWord.ts +17 -0
- package/src/api/types/index.ts +16 -0
- package/src/auth/BearerAuthProvider.ts +37 -0
- package/src/auth/index.ts +1 -0
- package/src/core/auth/AuthProvider.ts +6 -0
- package/src/core/auth/AuthRequest.ts +9 -0
- package/src/core/auth/BasicAuth.ts +32 -0
- package/src/core/auth/BearerToken.ts +20 -0
- package/src/core/auth/NoOpAuthProvider.ts +8 -0
- package/src/core/auth/index.ts +5 -0
- package/src/core/base64.ts +27 -0
- package/src/core/exports.ts +2 -0
- package/src/core/fetcher/APIResponse.ts +23 -0
- package/src/core/fetcher/BinaryResponse.ts +34 -0
- package/src/core/fetcher/EndpointMetadata.ts +13 -0
- package/src/core/fetcher/EndpointSupplier.ts +14 -0
- package/src/core/fetcher/Fetcher.ts +391 -0
- package/src/core/fetcher/Headers.ts +93 -0
- package/src/core/fetcher/HttpResponsePromise.ts +116 -0
- package/src/core/fetcher/RawResponse.ts +61 -0
- package/src/core/fetcher/Supplier.ts +11 -0
- package/src/core/fetcher/createRequestUrl.ts +6 -0
- package/src/core/fetcher/getErrorResponseBody.ts +33 -0
- package/src/core/fetcher/getFetchFn.ts +3 -0
- package/src/core/fetcher/getHeader.ts +8 -0
- package/src/core/fetcher/getRequestBody.ts +20 -0
- package/src/core/fetcher/getResponseBody.ts +58 -0
- package/src/core/fetcher/index.ts +11 -0
- package/src/core/fetcher/makeRequest.ts +42 -0
- package/src/core/fetcher/requestWithRetries.ts +64 -0
- package/src/core/fetcher/signals.ts +26 -0
- package/src/core/file/exports.ts +1 -0
- package/src/core/file/file.ts +217 -0
- package/src/core/file/index.ts +2 -0
- package/src/core/file/types.ts +81 -0
- package/src/core/headers.ts +35 -0
- package/src/core/index.ts +7 -0
- package/src/core/json.ts +27 -0
- package/src/core/logging/exports.ts +19 -0
- package/src/core/logging/index.ts +1 -0
- package/src/core/logging/logger.ts +203 -0
- package/src/core/runtime/index.ts +1 -0
- package/src/core/runtime/runtime.ts +134 -0
- package/src/core/url/encodePathParam.ts +18 -0
- package/src/core/url/index.ts +3 -0
- package/src/core/url/join.ts +79 -0
- package/src/core/url/qs.ts +74 -0
- package/src/environments.ts +7 -0
- package/src/errors/SpeechallError.ts +58 -0
- package/src/errors/SpeechallTimeoutError.ts +13 -0
- package/src/errors/handleNonStatusCodeError.ts +37 -0
- package/src/errors/index.ts +2 -0
- package/src/exports.ts +1 -0
- package/src/index.ts +6 -0
- package/test-import.ts +17 -0
- package/tests/integration/api.test.ts +93 -0
- package/tests/unit/client.test.ts +91 -0
- package/tsconfig.json +20 -0
- package/dist/api.d.ts +0 -501
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -610
- package/dist/base.d.ts +0 -32
- package/dist/base.d.ts.map +0 -1
- package/dist/base.js +0 -35
- package/dist/common.d.ts +0 -14
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -91
- package/dist/configuration.d.ts +0 -23
- package/dist/configuration.d.ts.map +0 -1
- package/dist/configuration.js +0 -25
- package/dist/esm/api.js +0 -592
- package/dist/esm/base.js +0 -27
- package/dist/esm/common.js +0 -79
- package/dist/esm/configuration.js +0 -21
- package/dist/esm/example.js +0 -131
- package/dist/esm/index.js +0 -2
- package/dist/example.d.ts +0 -3
- package/dist/example.d.ts.map +0 -1
- package/dist/example.js +0 -133
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -18
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { SpeechallClient } from '../../src';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
// Skip integration tests if no API token is provided
|
|
6
|
+
const runIntegration = process.env.SPEECHALL_API_TOKEN !== undefined;
|
|
7
|
+
const describeIntegration = runIntegration ? describe : describe.skip;
|
|
8
|
+
|
|
9
|
+
describeIntegration('API Integration Tests', () => {
|
|
10
|
+
let client: SpeechallClient;
|
|
11
|
+
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
client = new SpeechallClient({
|
|
14
|
+
token: process.env.SPEECHALL_API_TOKEN!,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('SpeechToText API', () => {
|
|
19
|
+
it('should transcribe audio file', async () => {
|
|
20
|
+
// This test requires an actual audio file and API token
|
|
21
|
+
// Skip if no audio fixture is available
|
|
22
|
+
const audioPath = path.join(__dirname, '../fixtures/audio-sample.wav');
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(audioPath)) {
|
|
25
|
+
console.log('Skipping: No audio fixture available');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const audioBuffer = fs.readFileSync(audioPath);
|
|
30
|
+
const audioFile = new File([audioBuffer], 'audio-sample.wav', {
|
|
31
|
+
type: 'audio/wav',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const response = await client.speechToText.transcribe(
|
|
35
|
+
audioFile,
|
|
36
|
+
{
|
|
37
|
+
model: 'openai.whisper-1',
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(response).toBeDefined();
|
|
42
|
+
// Add more specific assertions based on your API response structure
|
|
43
|
+
}, 30000); // 30 second timeout for API calls
|
|
44
|
+
|
|
45
|
+
it('should list available speech-to-text models', async () => {
|
|
46
|
+
const models = await client.speechToText.listSpeechToTextModels();
|
|
47
|
+
|
|
48
|
+
expect(models).toBeDefined();
|
|
49
|
+
expect(Array.isArray(models)).toBe(true);
|
|
50
|
+
}, 30000);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('Replacement Rules API', () => {
|
|
54
|
+
it('should create replacement ruleset', async () => {
|
|
55
|
+
const ruleset = await client.replacementRules.createReplacementRuleset({
|
|
56
|
+
name: 'Test Ruleset',
|
|
57
|
+
rules: [
|
|
58
|
+
{
|
|
59
|
+
kind: 'exact',
|
|
60
|
+
search: 'test',
|
|
61
|
+
replacement: 'TEST',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(ruleset).toBeDefined();
|
|
67
|
+
expect(ruleset.id).toBeDefined();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Mock integration tests that always run
|
|
73
|
+
describe('API Integration Tests (Mocked)', () => {
|
|
74
|
+
let client: SpeechallClient;
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
client = new SpeechallClient({
|
|
78
|
+
token: 'mock-api-token',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should have speechToText client available', () => {
|
|
83
|
+
expect(client.speechToText).toBeDefined();
|
|
84
|
+
expect(typeof client.speechToText.transcribe).toBe('function');
|
|
85
|
+
expect(typeof client.speechToText.transcribeRemote).toBe('function');
|
|
86
|
+
expect(typeof client.speechToText.listSpeechToTextModels).toBe('function');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should have replacementRules client available', () => {
|
|
90
|
+
expect(client.replacementRules).toBeDefined();
|
|
91
|
+
expect(typeof client.replacementRules.createReplacementRuleset).toBe('function');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { SpeechallClient, SpeechallError } from '../../src';
|
|
2
|
+
|
|
3
|
+
describe('SpeechallClient', () => {
|
|
4
|
+
describe('initialization', () => {
|
|
5
|
+
it('should initialize with token', () => {
|
|
6
|
+
const client = new SpeechallClient({
|
|
7
|
+
token: 'test-api-token',
|
|
8
|
+
});
|
|
9
|
+
expect(client).toBeDefined();
|
|
10
|
+
expect(client).toBeInstanceOf(SpeechallClient);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should initialize with token as a function', () => {
|
|
14
|
+
const client = new SpeechallClient({
|
|
15
|
+
token: () => 'test-api-token',
|
|
16
|
+
});
|
|
17
|
+
expect(client).toBeDefined();
|
|
18
|
+
expect(client).toBeInstanceOf(SpeechallClient);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should expose speechToText client', () => {
|
|
22
|
+
const client = new SpeechallClient({
|
|
23
|
+
token: 'test-api-token',
|
|
24
|
+
});
|
|
25
|
+
expect(client.speechToText).toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should expose replacementRules client', () => {
|
|
29
|
+
const client = new SpeechallClient({
|
|
30
|
+
token: 'test-api-token',
|
|
31
|
+
});
|
|
32
|
+
expect(client.replacementRules).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('configuration', () => {
|
|
37
|
+
it('should accept custom baseUrl', () => {
|
|
38
|
+
const client = new SpeechallClient({
|
|
39
|
+
token: 'test-api-token',
|
|
40
|
+
baseUrl: 'https://custom-api.example.com',
|
|
41
|
+
});
|
|
42
|
+
expect(client).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should accept custom headers', () => {
|
|
46
|
+
const client = new SpeechallClient({
|
|
47
|
+
token: 'test-api-token',
|
|
48
|
+
headers: {
|
|
49
|
+
'X-Custom-Header': 'custom-value',
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
expect(client).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should accept timeout configuration', () => {
|
|
56
|
+
const client = new SpeechallClient({
|
|
57
|
+
token: 'test-api-token',
|
|
58
|
+
timeoutInSeconds: 30,
|
|
59
|
+
});
|
|
60
|
+
expect(client).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should accept maxRetries configuration', () => {
|
|
64
|
+
const client = new SpeechallClient({
|
|
65
|
+
token: 'test-api-token',
|
|
66
|
+
maxRetries: 5,
|
|
67
|
+
});
|
|
68
|
+
expect(client).toBeDefined();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('lazy initialization', () => {
|
|
73
|
+
it('should lazily initialize speechToText client', () => {
|
|
74
|
+
const client = new SpeechallClient({
|
|
75
|
+
token: 'test-api-token',
|
|
76
|
+
});
|
|
77
|
+
const firstAccess = client.speechToText;
|
|
78
|
+
const secondAccess = client.speechToText;
|
|
79
|
+
expect(firstAccess).toBe(secondAccess);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should lazily initialize replacementRules client', () => {
|
|
83
|
+
const client = new SpeechallClient({
|
|
84
|
+
token: 'test-api-token',
|
|
85
|
+
});
|
|
86
|
+
const firstAccess = client.replacementRules;
|
|
87
|
+
const secondAccess = client.replacementRules;
|
|
88
|
+
expect(firstAccess).toBe(secondAccess);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"rootDir": "./src",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"moduleResolution": "node"
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist", "tests", "examples"]
|
|
20
|
+
}
|