Skip to content
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

Adjust @configu/ts - ConfiguConfigStore for the Revision Tag feature #349

Merged
merged 6 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ts/packages/ts/src/stores/Configu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,28 @@ describe(`ConfiguConfigStore`, () => {
expect(typeof headers.common.Token).toBe('string');
expect(typeof headers.common.Authorization).toBe('undefined');
});
it(`sets the tag property if provided`, () => {
const store = new ConfiguConfigStore({
credentials: {
org: 'test',
token: 'test-token',
},
source: 'test',
tag: 'test-tag',
});

expect(store['tag']).toBe('test-tag');
});
it(`does not set the tag property if not provided`, () => {
const store = new ConfiguConfigStore({
credentials: {
org: 'test',
token: 'test-token',
},
source: 'test',
});

expect(store['tag']).toBeUndefined();
});
});
});
13 changes: 11 additions & 2 deletions ts/packages/ts/src/stores/Configu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type ConfiguConfigStoreConfiguration = {
credentials: { org: string; token: string };
endpoint?: string;
source?: string;
tag?: string;
};

export class ConfiguConfigStoreApprovalQueueError extends Error {
Expand All @@ -22,7 +23,13 @@ export class ConfiguConfigStoreApprovalQueueError extends Error {

export class ConfiguConfigStore extends ConfigStore {
private client: Axios;
constructor({ credentials, endpoint = `https://api.configu.com`, source = 'sdk' }: ConfiguConfigStoreConfiguration) {
public tag?: string;
constructor({
credentials,
endpoint = `https://api.configu.com`,
source = 'sdk',
tag,
}: ConfiguConfigStoreConfiguration) {
super('configu');

this.client = axios.create({
Expand All @@ -39,10 +46,12 @@ export class ConfiguConfigStore extends ConfigStore {
} else {
this.client.defaults.headers.common.Token = credentials.token;
}

this.tag = tag;
}

async get(queries: ConfigStoreQuery[]): Promise<Config[]> {
const { data } = await this.client.post('/config', { queries });
const { data } = await this.client.post(`/config${this.tag ? `?tag=${this.tag}` : ''}`, { queries });
return data;
}

Expand Down
Loading