musora-content-services 2.161.3 → 2.161.4
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 +2 -0
- package/package.json +1 -1
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/services/search.ts +19 -0
- package/test/unit/search.test.ts +44 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [2.161.4](https://github.com/railroadmedia/musora-content-services/compare/v2.161.3...v2.161.4) (2026-06-02)
|
|
6
|
+
|
|
5
7
|
### [2.161.3](https://github.com/railroadmedia/musora-content-services/compare/v2.161.2...v2.161.3) (2026-06-02)
|
|
6
8
|
|
|
7
9
|
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -362,6 +362,10 @@ import {
|
|
|
362
362
|
jumpToContinueContent
|
|
363
363
|
} from './services/sanity.js';
|
|
364
364
|
|
|
365
|
+
import {
|
|
366
|
+
searchAlgolia
|
|
367
|
+
} from './services/search.ts';
|
|
368
|
+
|
|
365
369
|
import {
|
|
366
370
|
clearState
|
|
367
371
|
} from './services/state.ts';
|
|
@@ -793,6 +797,7 @@ declare module 'musora-content-services' {
|
|
|
793
797
|
restoreUserActivity,
|
|
794
798
|
restoreUserPractice,
|
|
795
799
|
search,
|
|
800
|
+
searchAlgolia,
|
|
796
801
|
sendAccountSetupEmail,
|
|
797
802
|
sendPasswordResetEmail,
|
|
798
803
|
setStudentViewForUser,
|
package/src/index.js
CHANGED
|
@@ -366,6 +366,10 @@ import {
|
|
|
366
366
|
jumpToContinueContent
|
|
367
367
|
} from './services/sanity.js';
|
|
368
368
|
|
|
369
|
+
import {
|
|
370
|
+
searchAlgolia
|
|
371
|
+
} from './services/search.ts';
|
|
372
|
+
|
|
369
373
|
import {
|
|
370
374
|
clearState
|
|
371
375
|
} from './services/state.ts';
|
|
@@ -792,6 +796,7 @@ export {
|
|
|
792
796
|
restoreUserActivity,
|
|
793
797
|
restoreUserPractice,
|
|
794
798
|
search,
|
|
799
|
+
searchAlgolia,
|
|
795
800
|
sendAccountSetupEmail,
|
|
796
801
|
sendPasswordResetEmail,
|
|
797
802
|
setStudentViewForUser,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { POST } from '../infrastructure/http/HttpClient'
|
|
2
|
+
|
|
3
|
+
export interface AlgoliaSearchRequest {
|
|
4
|
+
query?: string
|
|
5
|
+
hitsPerPage?: number
|
|
6
|
+
page?: number
|
|
7
|
+
[key: string]: unknown
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface AlgoliaSearchResponse {
|
|
11
|
+
// Shape varies by index configuration and query — MPB passes Algolia's response through unchanged
|
|
12
|
+
results: unknown[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function searchAlgolia(
|
|
16
|
+
requests: AlgoliaSearchRequest[]
|
|
17
|
+
): Promise<AlgoliaSearchResponse> {
|
|
18
|
+
return POST('/api/content/v1/search', { requests }) as Promise<AlgoliaSearchResponse>
|
|
19
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { searchAlgolia } from '../../src/services/search'
|
|
2
|
+
|
|
3
|
+
const mockPost = jest.fn()
|
|
4
|
+
|
|
5
|
+
jest.mock('../../src/infrastructure/http/HttpClient', () => ({
|
|
6
|
+
POST: (...args: unknown[]) => mockPost(...args),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
describe('searchAlgolia', () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockPost.mockReset()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('posts requests to the correct endpoint', async () => {
|
|
15
|
+
mockPost.mockResolvedValue({ results: [] })
|
|
16
|
+
|
|
17
|
+
await searchAlgolia([{ query: 'drum', hitsPerPage: 5 }])
|
|
18
|
+
|
|
19
|
+
expect(mockPost).toHaveBeenCalledWith('/api/content/v1/search', {
|
|
20
|
+
requests: [{ query: 'drum', hitsPerPage: 5 }],
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('returns the response from the endpoint', async () => {
|
|
25
|
+
const mockResponse = {
|
|
26
|
+
results: [{ hits: [{ objectID: 'abc123' }], nbHits: 1 }],
|
|
27
|
+
}
|
|
28
|
+
mockPost.mockResolvedValue(mockResponse)
|
|
29
|
+
|
|
30
|
+
const result = await searchAlgolia([{ query: 'drum' }])
|
|
31
|
+
|
|
32
|
+
expect(result).toEqual(mockResponse)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('passes multiple requests', async () => {
|
|
36
|
+
mockPost.mockResolvedValue({ results: [] })
|
|
37
|
+
|
|
38
|
+
await searchAlgolia([{ query: 'drum' }, { query: 'piano' }])
|
|
39
|
+
|
|
40
|
+
expect(mockPost).toHaveBeenCalledWith('/api/content/v1/search', {
|
|
41
|
+
requests: [{ query: 'drum' }, { query: 'piano' }],
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
})
|