-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #954 from duffelhq/client-keys
Introduces component client keys
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/booking/Identity/ComponentClientKey/ComponentClientKeys.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
src/booking/Identity/ComponentClientKey/ComponentClientKeys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
} |
6 changes: 6 additions & 0 deletions
6
src/booking/Identity/ComponentClientKey/mockComponentClientKey.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |