Skip to content

Commit a93cebd

Browse files
authored
Merge pull request #954 from duffelhq/client-keys
Introduces component client keys
2 parents 4aa7d0e + 39a8a53 commit a93cebd

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import nock from 'nock'
2+
import { Client } from '../../../Client'
3+
import { ComponentClientKeys } from './ComponentClientKeys'
4+
import { mockComponentClientKey } from './mockComponentClientKey'
5+
6+
describe('component client keys', () => {
7+
afterEach(() => {
8+
nock.cleanAll()
9+
})
10+
11+
test('creates a component client key', async () => {
12+
nock(/(.*)/)
13+
.post(`/identity/component_client_keys/`)
14+
.reply(200, { data: mockComponentClientKey })
15+
16+
const response = await new ComponentClientKeys(
17+
new Client({ token: 'mockToken' }),
18+
).create()
19+
20+
const regex_to_match_jwt = new RegExp(
21+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.[a-zA-Z0-9_-]*.[a-zA-Z0-9_-]*',
22+
)
23+
expect(response.data.component_client_key).toMatch(regex_to_match_jwt)
24+
})
25+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Resource } from '../../../Resource'
2+
import { type DuffelResponse } from '../../../types/ClientType'
3+
import { type ComponentClientKey } from './types'
4+
/**
5+
* A component client key is a unique identifier that allows you to authenticate with the Duffel API.
6+
*/
7+
export class ComponentClientKeys extends Resource {
8+
/**
9+
* Endpoint path
10+
*/
11+
path: string
12+
13+
constructor(args: any) {
14+
super(args)
15+
this.path = 'identity/component_client_keys/'
16+
}
17+
18+
/**
19+
* A component client key is a unique identifier that allows you to authenticate with the Duffel API.
20+
* @param data A JSON object containing the data to create a new component client key
21+
*/
22+
public create = async (
23+
data: Record<string, string> = {},
24+
): Promise<DuffelResponse<ComponentClientKey>> =>
25+
this.request({ method: 'POST', path: `${this.path}`, data })
26+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { type ComponentClientKey } from './types'
2+
3+
export const mockComponentClientKey: ComponentClientKey = {
4+
component_client_key:
5+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiaWN1XzAwMDBBZ1ppdHBPblF0ZDNOUXhqd08iLCJvcmRlcl9pZCI6Im9yZF8wMDAwQUJkWm5nZ1NjdDdCb3JhVTFvIiwiaWF0IjoxNTE2MjM5MDIyfQ.GtJDKrfum7aLlNaXmUj-RtQIbx0-Opwjdid0fiJk6DE',
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface ComponentClientKey {
2+
/**
3+
* The client key used to authenticate Duffel UI components to our API.
4+
*/
5+
component_client_key: string
6+
}

0 commit comments

Comments
 (0)