Skip to content

Commit

Permalink
pass settings in all HTTP provider invocations
Browse files Browse the repository at this point in the history
The spec says that HTTP providers are invoked with a POST whose body includes the settings (https://openctx.org/docs/protocol). However, this was not happening; only the `params` were being sent. This fix makes it so that the `settings` are also passed.
  • Loading branch information
sqs committed Oct 25, 2024
1 parent 0eb3961 commit 654f92f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 11 additions & 2 deletions lib/client/src/providerClient/transport/createTransport.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { afterEach } from 'node:test'
import type { MetaResult, ResponseMessage } from '@openctx/protocol'
import type { MetaResult, ProviderSettings, ResponseMessage } from '@openctx/protocol'
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'
import createFetchMock from 'vitest-fetch-mock'
import { type ProviderTransport, createTransport } from './createTransport.js'

const SETTINGS_FIXTURE: ProviderSettings = { a: 1 }

async function expectProviderTransport(provider: ProviderTransport) {
expect(await provider.meta({}, {})).toEqual<MetaResult>({
expect(await provider.meta({}, SETTINGS_FIXTURE)).toEqual<MetaResult>({
annotations: { selectors: [{ path: 'foo' }] },
name: 'foo',
})
Expand Down Expand Up @@ -67,6 +69,13 @@ describe('createTransport', () => {
)
const provider = createTransport('https://example.com/openctx', {})
await expectProviderTransport(provider)

const body = await fetchMocker.requests()[0].json()
expect(body).toEqual({
method: 'meta',
params: {},
settings: SETTINGS_FIXTURE,
})
})

describe('errors', () => {
Expand Down
10 changes: 6 additions & 4 deletions lib/client/src/providerClient/transport/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ export function createHttpTransport(
}

return {
meta: async params => send<MetaResult>({ method: 'meta', params }),
mentions: async params => send<MentionsResult>({ method: 'mentions', params }),
items: async params => send<ItemsResult>({ method: 'items', params }),
annotations: async params => send<AnnotationsResult>({ method: 'annotations', params }),
meta: async (params, settings) => send<MetaResult>({ method: 'meta', params, settings }),
mentions: async (params, settings) =>
send<MentionsResult>({ method: 'mentions', params, settings }),
items: async (params, settings) => send<ItemsResult>({ method: 'items', params, settings }),
annotations: async (params, settings) =>
send<AnnotationsResult>({ method: 'annotations', params, settings }),
}
}

0 comments on commit 654f92f

Please sign in to comment.