@volley/recognition-client-sdk 0.1.211 → 0.1.255
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/README.md +83 -7
- package/dist/{browser-C4ZssGoU.d.ts → browser-BZs4BL_w.d.ts} +84 -6
- package/dist/index.d.ts +630 -16
- package/dist/index.js +284 -44
- package/dist/index.js.map +1 -1
- package/dist/recog-client-sdk.browser.d.ts +1 -1
- package/dist/recog-client-sdk.browser.js +203 -42
- package/dist/recog-client-sdk.browser.js.map +1 -1
- package/package.json +3 -3
- package/src/config-builder.ts +21 -3
- package/src/errors.ts +84 -0
- package/src/index.ts +34 -1
- package/src/recognition-client.spec.ts +39 -0
- package/src/recognition-client.ts +157 -41
- package/src/recognition-client.types.ts +58 -6
- package/src/simplified-vgf-recognition-client.ts +9 -0
- package/src/utils/url-builder.spec.ts +53 -6
- package/src/utils/url-builder.ts +19 -4
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { buildWebSocketUrl, UrlBuilderConfig } from './url-builder.js';
|
|
6
|
-
import { RecognitionContextTypeV1 } from '@recog/shared-types';
|
|
6
|
+
import { RecognitionContextTypeV1, STAGES } from '@recog/shared-types';
|
|
7
7
|
|
|
8
8
|
// Mock the shared-config module
|
|
9
|
+
const mockGetRecognitionServiceBase = jest.fn();
|
|
9
10
|
jest.mock('@recog/shared-config', () => ({
|
|
10
|
-
getRecognitionServiceBase:
|
|
11
|
-
wsBase: 'wss://recognition.volley.com'
|
|
12
|
-
})
|
|
11
|
+
getRecognitionServiceBase: mockGetRecognitionServiceBase
|
|
13
12
|
}));
|
|
14
13
|
|
|
15
14
|
describe('buildWebSocketUrl', () => {
|
|
@@ -17,23 +16,71 @@ describe('buildWebSocketUrl', () => {
|
|
|
17
16
|
audioUtteranceId: 'test-utterance-123'
|
|
18
17
|
};
|
|
19
18
|
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
// Reset mock before each test
|
|
21
|
+
mockGetRecognitionServiceBase.mockReturnValue({
|
|
22
|
+
wsBase: 'wss://recognition.volley.com'
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
20
26
|
it('should build URL with only audioUtteranceId', () => {
|
|
21
27
|
const url = buildWebSocketUrl(baseConfig);
|
|
22
28
|
expect(url).toContain('audioUtteranceId=test-utterance-123');
|
|
23
29
|
});
|
|
24
30
|
|
|
25
|
-
it('should use default URL if
|
|
31
|
+
it('should use default production URL if neither url nor stage provided', () => {
|
|
26
32
|
const url = buildWebSocketUrl(baseConfig);
|
|
27
33
|
expect(url).toContain('wss://recognition.volley.com/ws/v1/recognize');
|
|
34
|
+
expect(mockGetRecognitionServiceBase).toHaveBeenCalledWith('production');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should use stage parameter to build URL', () => {
|
|
38
|
+
mockGetRecognitionServiceBase.mockReturnValue({
|
|
39
|
+
wsBase: 'wss://recognition-staging.volley.com'
|
|
40
|
+
});
|
|
41
|
+
const config = {
|
|
42
|
+
...baseConfig,
|
|
43
|
+
stage: 'staging'
|
|
44
|
+
};
|
|
45
|
+
const url = buildWebSocketUrl(config);
|
|
46
|
+
expect(url).toContain('wss://recognition-staging.volley.com/ws/v1/recognize');
|
|
47
|
+
expect(mockGetRecognitionServiceBase).toHaveBeenCalledWith('staging');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should accept Stage enum as stage parameter', () => {
|
|
51
|
+
mockGetRecognitionServiceBase.mockReturnValue({
|
|
52
|
+
wsBase: 'wss://recognition-dev.volley.com'
|
|
53
|
+
});
|
|
54
|
+
const config = {
|
|
55
|
+
...baseConfig,
|
|
56
|
+
stage: STAGES.DEV
|
|
57
|
+
};
|
|
58
|
+
const url = buildWebSocketUrl(config);
|
|
59
|
+
expect(url).toContain('wss://recognition-dev.volley.com/ws/v1/recognize');
|
|
60
|
+
expect(mockGetRecognitionServiceBase).toHaveBeenCalledWith(STAGES.DEV);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should prioritize url over stage when both provided', () => {
|
|
64
|
+
const config = {
|
|
65
|
+
...baseConfig,
|
|
66
|
+
url: 'ws://localhost:3101/ws/v1/recognize',
|
|
67
|
+
stage: 'staging'
|
|
68
|
+
};
|
|
69
|
+
const url = buildWebSocketUrl(config);
|
|
70
|
+
expect(url).toContain('ws://localhost:3101/ws/v1/recognize');
|
|
71
|
+
// Mock should not be called when explicit URL is provided
|
|
72
|
+
expect(mockGetRecognitionServiceBase).not.toHaveBeenCalled();
|
|
28
73
|
});
|
|
29
74
|
|
|
30
|
-
it('should use custom URL if provided', () => {
|
|
75
|
+
it('should use custom URL if provided (backward compatibility)', () => {
|
|
31
76
|
const config = {
|
|
32
77
|
...baseConfig,
|
|
33
78
|
url: 'ws://localhost:3101/ws/v1/recognize'
|
|
34
79
|
};
|
|
35
80
|
const url = buildWebSocketUrl(config);
|
|
36
81
|
expect(url).toContain('ws://localhost:3101/ws/v1/recognize');
|
|
82
|
+
// Mock should not be called when explicit URL is provided
|
|
83
|
+
expect(mockGetRecognitionServiceBase).not.toHaveBeenCalled();
|
|
37
84
|
});
|
|
38
85
|
|
|
39
86
|
it('should add userId to query parameters', () => {
|
package/src/utils/url-builder.ts
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { getRecognitionServiceBase } from '@recog/shared-config';
|
|
7
|
-
import type { GameContextV1 } from '@recog/shared-types';
|
|
7
|
+
import type { GameContextV1, Stage } from '@recog/shared-types';
|
|
8
8
|
import type { RecognitionCallbackUrl } from '../recognition-client.types.js';
|
|
9
9
|
|
|
10
10
|
export interface UrlBuilderConfig {
|
|
11
11
|
url?: string;
|
|
12
|
+
stage?: Stage | string;
|
|
12
13
|
audioUtteranceId: string;
|
|
13
14
|
callbackUrls?: RecognitionCallbackUrl[];
|
|
14
15
|
userId?: string;
|
|
@@ -22,11 +23,25 @@ export interface UrlBuilderConfig {
|
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Build WebSocket URL with all query parameters
|
|
26
|
+
* Either `url` or `stage` must be provided (or defaults to production if neither provided)
|
|
27
|
+
* If both are provided, `url` takes precedence over `stage`
|
|
25
28
|
*/
|
|
26
29
|
export function buildWebSocketUrl(config: UrlBuilderConfig): string {
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
// Determine base URL based on precedence: url > stage > default production
|
|
31
|
+
let baseUrl: string;
|
|
32
|
+
|
|
33
|
+
if (config.url) {
|
|
34
|
+
// Explicit URL takes precedence
|
|
35
|
+
baseUrl = config.url;
|
|
36
|
+
} else if (config.stage) {
|
|
37
|
+
// Use stage to build URL
|
|
38
|
+
const stageBase = getRecognitionServiceBase(config.stage);
|
|
39
|
+
baseUrl = `${stageBase.wsBase}/ws/v1/recognize`;
|
|
40
|
+
} else {
|
|
41
|
+
// Default to production if neither provided
|
|
42
|
+
const defaultBase = getRecognitionServiceBase('production');
|
|
43
|
+
baseUrl = `${defaultBase.wsBase}/ws/v1/recognize`;
|
|
44
|
+
}
|
|
30
45
|
|
|
31
46
|
// Build URL - add all optional identification parameters
|
|
32
47
|
const url = new URL(baseUrl);
|