Skip to content

Commit

Permalink
Adjust @configu/ts - ConfiguConfigStore for the Approval Queue fe…
Browse files Browse the repository at this point in the history
…ature (#344)
  • Loading branch information
RichardAkman committed Feb 5, 2024
1 parent 33be024 commit 01c06f6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ts/packages/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export { NoopConfigStore, InMemoryConfigStore, ConfiguConfigStore } from '@configu/ts';
export {
NoopConfigStore,
InMemoryConfigStore,
ConfiguConfigStore,
ConfiguConfigStoreApprovalQueueError,
} from '@configu/ts';

export * from './stores/LocalForage';

Expand Down
7 changes: 6 additions & 1 deletion ts/packages/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export { NoopConfigStore, InMemoryConfigStore, ConfiguConfigStore } from '@configu/ts';
export {
NoopConfigStore,
InMemoryConfigStore,
ConfiguConfigStore,
ConfiguConfigStoreApprovalQueueError,
} from '@configu/ts';

export * from './stores/JsonFile';
export * from './stores/IniFile';
Expand Down
18 changes: 17 additions & 1 deletion ts/packages/ts/src/stores/Configu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ export type ConfiguConfigStoreConfiguration = {
source?: string;
};

export class ConfiguConfigStoreApprovalQueueError extends Error {
readonly queueUrl: string;
constructor(protectedSet: string, queueUrl: string) {
super(
`Your recent upsert to the ${protectedSet} ConfigSet is currently pending in its approval queue, as ${protectedSet} is a "protected set". To proceed with these changes, please review and approve them at ${queueUrl}. If you lack the necessary permissions, reach out to an authorized org member.`,
);
this.queueUrl = queueUrl;
this.name = 'ConfiguConfigStoreApprovalQueueError';
}
}

export class ConfiguConfigStore extends ConfigStore {
private client: Axios;
constructor({ credentials, endpoint = `https://api.configu.com`, source = 'sdk' }: ConfiguConfigStoreConfiguration) {
Expand Down Expand Up @@ -36,6 +47,11 @@ export class ConfiguConfigStore extends ConfigStore {
}

async set(configs: Config[]): Promise<void> {
await this.client.put('/config', { configs });
const response = await this.client.put('/config', { configs });
if (response.status === 202) {
const protectedSet = response.data.diff.pending[0].set;
const queueUrl = `${response.data.queueUrl}?set=${protectedSet}`;
throw new ConfiguConfigStoreApprovalQueueError(protectedSet, queueUrl);
}
}
}

0 comments on commit 01c06f6

Please sign in to comment.