Skip to content

Commit

Permalink
Merge pull request #954 from duffelhq/client-keys
Browse files Browse the repository at this point in the history
Introduces component client keys
  • Loading branch information
igorp1 authored Sep 13, 2024
2 parents 4aa7d0e + 39a8a53 commit a93cebd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import nock from 'nock'
import { Client } from '../../../Client'
import { ComponentClientKeys } from './ComponentClientKeys'
import { mockComponentClientKey } from './mockComponentClientKey'

describe('component client keys', () => {
afterEach(() => {
nock.cleanAll()
})

test('creates a component client key', async () => {
nock(/(.*)/)
.post(`/identity/component_client_keys/`)
.reply(200, { data: mockComponentClientKey })

const response = await new ComponentClientKeys(
new Client({ token: 'mockToken' }),
).create()

const regex_to_match_jwt = new RegExp(
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.[a-zA-Z0-9_-]*.[a-zA-Z0-9_-]*',
)
expect(response.data.component_client_key).toMatch(regex_to_match_jwt)
})
})
26 changes: 26 additions & 0 deletions src/booking/Identity/ComponentClientKey/ComponentClientKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Resource } from '../../../Resource'
import { type DuffelResponse } from '../../../types/ClientType'
import { type ComponentClientKey } from './types'
/**
* A component client key is a unique identifier that allows you to authenticate with the Duffel API.
*/
export class ComponentClientKeys extends Resource {
/**
* Endpoint path
*/
path: string

constructor(args: any) {
super(args)
this.path = 'identity/component_client_keys/'
}

/**
* A component client key is a unique identifier that allows you to authenticate with the Duffel API.
* @param data A JSON object containing the data to create a new component client key
*/
public create = async (
data: Record<string, string> = {},
): Promise<DuffelResponse<ComponentClientKey>> =>
this.request({ method: 'POST', path: `${this.path}`, data })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type ComponentClientKey } from './types'

export const mockComponentClientKey: ComponentClientKey = {
component_client_key:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiaWN1XzAwMDBBZ1ppdHBPblF0ZDNOUXhqd08iLCJvcmRlcl9pZCI6Im9yZF8wMDAwQUJkWm5nZ1NjdDdCb3JhVTFvIiwiaWF0IjoxNTE2MjM5MDIyfQ.GtJDKrfum7aLlNaXmUj-RtQIbx0-Opwjdid0fiJk6DE',
}
6 changes: 6 additions & 0 deletions src/booking/Identity/ComponentClientKey/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface ComponentClientKey {
/**
* The client key used to authenticate Duffel UI components to our API.
*/
component_client_key: string
}

0 comments on commit a93cebd

Please sign in to comment.