-
Notifications
You must be signed in to change notification settings - Fork 8
feat(mgmt): add outbound SCIM configuration management wrapper #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dorsha
wants to merge
9
commits into
main
Choose a base branch
from
dorsha/outbound-scim-mgmt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ac78fbf
feat(mgmt): add outbound SCIM configuration management wrapper
dorsha fd383ad
style(mgmt): prettier-format outbound SCIM files
dorsha a91cf13
Merge branch 'main' into dorsha/outbound-scim-mgmt
dorsha 4d804d8
refactor(mgmt): drop loadAllConfigurations from outboundSCIM
dorsha 4055ea8
Merge branch 'main' into dorsha/outbound-scim-mgmt
dorsha e9cc315
refactor(mgmt-scim): appId-centric OutboundSCIM surface
dorsha 0b1e9ff
Merge branch 'main' into dorsha/outbound-scim-mgmt
dorsha 6be692e
style: prettier format outboundscim.ts
dorsha 0d8dcff
feat(mgmt-scim): concrete OutboundSCIMConfigurationData type
dorsha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,197 @@ | ||
| import { SdkResponse } from '@descope/core-js-sdk'; | ||
| import withManagement from '.'; | ||
| import apiPaths from './paths'; | ||
| import { OutboundSCIMConfiguration } from './types'; | ||
| import { mockHttpClient, resetMockHttpClient } from './testutils'; | ||
|
|
||
| const management = withManagement(mockHttpClient); | ||
|
|
||
| const mockOutboundSCIMConfig: OutboundSCIMConfiguration = { | ||
| appId: 'app1', | ||
| configuration: { baseUrl: 'https://scim.example.com', token: 'shh' }, | ||
| enabled: true, | ||
| lastExportTime: 1_700_000_000, | ||
| lastProcessingTime: 1_700_000_100, | ||
| failures: 0, | ||
| version: 3, | ||
| }; | ||
|
|
||
| const mockOutboundSCIMConfigResponse = { | ||
| configuration: mockOutboundSCIMConfig, | ||
| }; | ||
|
|
||
| describe('Management OutboundSCIM', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| resetMockHttpClient(); | ||
| }); | ||
|
|
||
| describe('createConfiguration', () => { | ||
| it('should send the correct request and receive correct response', async () => { | ||
| const httpResponse = { | ||
| ok: true, | ||
| json: () => mockOutboundSCIMConfigResponse, | ||
| clone: () => ({ | ||
| json: () => Promise.resolve(mockOutboundSCIMConfigResponse), | ||
| }), | ||
| status: 200, | ||
| }; | ||
| mockHttpClient.post.mockResolvedValue(httpResponse); | ||
|
|
||
| const resp: SdkResponse<OutboundSCIMConfiguration> = | ||
| await management.outboundSCIM.createConfiguration({ | ||
| appId: 'app1', | ||
| configuration: { baseUrl: 'https://scim.example.com', token: 'shh' }, | ||
| }); | ||
|
|
||
| expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.outboundSCIM.create, { | ||
| appId: 'app1', | ||
| configuration: { baseUrl: 'https://scim.example.com', token: 'shh' }, | ||
| }); | ||
|
|
||
| expect(resp).toEqual({ | ||
| code: 200, | ||
| data: mockOutboundSCIMConfig, | ||
| ok: true, | ||
| response: httpResponse, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('updateConfiguration', () => { | ||
| it('should send the correct request and receive correct response', async () => { | ||
| const httpResponse = { | ||
| ok: true, | ||
| json: () => mockOutboundSCIMConfigResponse, | ||
| clone: () => ({ | ||
| json: () => Promise.resolve(mockOutboundSCIMConfigResponse), | ||
| }), | ||
| status: 200, | ||
| }; | ||
| mockHttpClient.post.mockResolvedValue(httpResponse); | ||
|
|
||
| const resp: SdkResponse<OutboundSCIMConfiguration> = | ||
| await management.outboundSCIM.updateConfiguration({ | ||
| appId: 'app1', | ||
| configuration: { baseUrl: 'https://scim2.example.com', token: 'shh2' }, | ||
| version: 3, | ||
| }); | ||
|
|
||
| expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.outboundSCIM.update, { | ||
| appId: 'app1', | ||
| configuration: { baseUrl: 'https://scim2.example.com', token: 'shh2' }, | ||
| version: 3, | ||
| }); | ||
|
|
||
| expect(resp).toEqual({ | ||
| code: 200, | ||
| data: mockOutboundSCIMConfig, | ||
| ok: true, | ||
| response: httpResponse, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('deleteConfiguration', () => { | ||
| it('should send the correct request and receive correct response', async () => { | ||
| const httpResponse = { | ||
| ok: true, | ||
| json: () => {}, | ||
| clone: () => ({ | ||
| json: () => Promise.resolve({}), | ||
| }), | ||
| status: 200, | ||
| }; | ||
| mockHttpClient.post.mockResolvedValue(httpResponse); | ||
|
|
||
| const resp = await management.outboundSCIM.deleteConfiguration('app1'); | ||
|
|
||
| expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.outboundSCIM.delete, { | ||
| appId: 'app1', | ||
| }); | ||
|
|
||
| expect(resp).toEqual({ | ||
| code: 200, | ||
| data: {}, | ||
| ok: true, | ||
| response: httpResponse, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('loadConfiguration', () => { | ||
| it('should send the correct request and receive correct response', async () => { | ||
| const httpResponse = { | ||
| ok: true, | ||
| json: () => mockOutboundSCIMConfigResponse, | ||
| clone: () => ({ | ||
| json: () => Promise.resolve(mockOutboundSCIMConfigResponse), | ||
| }), | ||
| status: 200, | ||
| }; | ||
| mockHttpClient.get.mockResolvedValue(httpResponse); | ||
|
|
||
| const resp: SdkResponse<OutboundSCIMConfiguration> = | ||
| await management.outboundSCIM.loadConfiguration('app1'); | ||
|
|
||
| expect(mockHttpClient.get).toHaveBeenCalledWith(`${apiPaths.outboundSCIM.load}/app1`); | ||
|
|
||
| expect(resp).toEqual({ | ||
| code: 200, | ||
| data: mockOutboundSCIMConfig, | ||
| ok: true, | ||
| response: httpResponse, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('setEnabled', () => { | ||
| it('should send the correct request when enabling', async () => { | ||
| const httpResponse = { | ||
| ok: true, | ||
| json: () => mockOutboundSCIMConfigResponse, | ||
| clone: () => ({ | ||
| json: () => Promise.resolve(mockOutboundSCIMConfigResponse), | ||
| }), | ||
| status: 200, | ||
| }; | ||
| mockHttpClient.post.mockResolvedValue(httpResponse); | ||
|
|
||
| const resp: SdkResponse<OutboundSCIMConfiguration> = await management.outboundSCIM.setEnabled( | ||
| 'app1', | ||
| true, | ||
| ); | ||
|
|
||
| expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.outboundSCIM.setEnabled, { | ||
| appId: 'app1', | ||
| enabled: true, | ||
| }); | ||
|
|
||
| expect(resp).toEqual({ | ||
| code: 200, | ||
| data: mockOutboundSCIMConfig, | ||
| ok: true, | ||
| response: httpResponse, | ||
| }); | ||
| }); | ||
|
|
||
| it('should send the correct request when disabling', async () => { | ||
| const httpResponse = { | ||
| ok: true, | ||
| json: () => mockOutboundSCIMConfigResponse, | ||
| clone: () => ({ | ||
| json: () => Promise.resolve(mockOutboundSCIMConfigResponse), | ||
| }), | ||
| status: 200, | ||
| }; | ||
| mockHttpClient.post.mockResolvedValue(httpResponse); | ||
|
|
||
| await management.outboundSCIM.setEnabled('app1', false); | ||
|
|
||
| expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.outboundSCIM.setEnabled, { | ||
| appId: 'app1', | ||
| enabled: false, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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,50 @@ | ||
| import { SdkResponse, transformResponse, HttpClient } from '@descope/core-js-sdk'; | ||
| import apiPaths from './paths'; | ||
| import { | ||
| OutboundSCIMConfiguration, | ||
| CreateOutboundSCIMConfigurationRequest, | ||
| UpdateOutboundSCIMConfigurationRequest, | ||
| } from './types'; | ||
|
|
||
| type OutboundSCIMConfigurationResponse = { | ||
| configuration: OutboundSCIMConfiguration; | ||
| }; | ||
|
|
||
| const withOutboundSCIM = (httpClient: HttpClient) => ({ | ||
| /** Create a new outbound SCIM configuration on the federated SSO application identified by `appId`. */ | ||
| createConfiguration: ( | ||
| request: CreateOutboundSCIMConfigurationRequest, | ||
| ): Promise<SdkResponse<OutboundSCIMConfiguration>> => | ||
| transformResponse<OutboundSCIMConfigurationResponse, OutboundSCIMConfiguration>( | ||
| httpClient.post(apiPaths.outboundSCIM.create, { ...request }), | ||
| (data) => data.configuration, | ||
| ), | ||
| /** | ||
| * Update the outbound SCIM configuration attached to the given federated SSO app. `version` | ||
| * must match the currently stored version — a mismatch fails the update (optimistic concurrency). | ||
| */ | ||
| updateConfiguration: ( | ||
| request: UpdateOutboundSCIMConfigurationRequest, | ||
| ): Promise<SdkResponse<OutboundSCIMConfiguration>> => | ||
| transformResponse<OutboundSCIMConfigurationResponse, OutboundSCIMConfiguration>( | ||
| httpClient.post(apiPaths.outboundSCIM.update, { ...request }), | ||
| (data) => data.configuration, | ||
| ), | ||
| /** Delete the outbound SCIM configuration attached to the given federated SSO app. */ | ||
| deleteConfiguration: (appId: string): Promise<SdkResponse<never>> => | ||
| transformResponse(httpClient.post(apiPaths.outboundSCIM.delete, { appId })), | ||
| /** Load the outbound SCIM configuration attached to the given federated SSO app. */ | ||
| loadConfiguration: (appId: string): Promise<SdkResponse<OutboundSCIMConfiguration>> => | ||
| transformResponse<OutboundSCIMConfigurationResponse, OutboundSCIMConfiguration>( | ||
| httpClient.get(`${apiPaths.outboundSCIM.load}/${appId}`), | ||
| (data) => data.configuration, | ||
| ), | ||
| /** Enable or disable the outbound SCIM configuration attached to the given federated SSO app. */ | ||
| setEnabled: (appId: string, enabled: boolean): Promise<SdkResponse<OutboundSCIMConfiguration>> => | ||
| transformResponse<OutboundSCIMConfigurationResponse, OutboundSCIMConfiguration>( | ||
| httpClient.post(apiPaths.outboundSCIM.setEnabled, { appId, enabled }), | ||
| (data) => data.configuration, | ||
| ), | ||
| }); | ||
|
|
||
| export default withOutboundSCIM; |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.