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

feat: add optional owner param to syncer methods #58

Closed
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
16 changes: 8 additions & 8 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,24 +328,24 @@ export class SDK {
return await this.sessionSDK.deleteSession(session)
}

public async getSyncers() {
return await this.syncerSDK.getSyncers()
public async getSyncers(owner?: string) {
return await this.syncerSDK.getSyncers(owner)
}

public async getSyncer(id: string) {
return await this.syncerSDK.getSyncer(id)
}

public async addSyncer(syncer: Syncer) {
return await this.syncerSDK.addSyncer(syncer)
public async addSyncer(syncer: Syncer, owner?: string) {
return await this.syncerSDK.addSyncer(syncer, owner)
}

public async updateSyncer(syncer: Syncer) {
return await this.syncerSDK.updateSyncer(syncer)
public async updateSyncer(syncer: Syncer, owner?: string) {
return await this.syncerSDK.updateSyncer(syncer, owner)
}

public async deleteSyncer(syncer: Syncer) {
return await this.syncerSDK.deleteSyncer(syncer)
public async deleteSyncer(syncer: Syncer, owner?: string) {
return await this.syncerSDK.deleteSyncer(syncer, owner)
}

public async getPermissions() {
Expand Down
24 changes: 14 additions & 10 deletions src/syncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export class SyncerSDK {
this.request = request
}

public async getSyncers() {
public async getSyncers(owner = this.config.orgName) {
if (!this.request) {
throw new Error('request init failed')
}

return (await this.request.get('/get-syncers', {
params: {
owner: this.config.orgName,
owner,
},
})) as unknown as Promise<AxiosResponse<{ data: Syncer[] }>>
}
Expand All @@ -85,29 +85,33 @@ export class SyncerSDK {
})) as unknown as Promise<AxiosResponse<{ data: Syncer }>>
}

public async modifySyncer(method: string, syncer: Syncer) {
public async modifySyncer(
method: string,
syncer: Syncer,
owner = this.config.orgName,
) {
if (!this.request) {
throw new Error('request init failed')
}

const url = `/${method}`
syncer.owner = this.config.orgName
syncer.owner = owner
return (await this.request.post(url, syncer, {
params: {
id: `${syncer.owner}/${syncer.name}`,
},
})) as unknown as Promise<AxiosResponse<Record<string, unknown>>>
}

public async addSyncer(syncer: Syncer) {
return this.modifySyncer('add-syncer', syncer)
public async addSyncer(syncer: Syncer, owner?: string) {
return this.modifySyncer('add-syncer', syncer, owner)
}

public async updateSyncer(syncer: Syncer) {
return this.modifySyncer('update-syncer', syncer)
public async updateSyncer(syncer: Syncer, owner?: string) {
return this.modifySyncer('update-syncer', syncer, owner)
}

public async deleteSyncer(syncer: Syncer) {
return this.modifySyncer('delete-syncer', syncer)
public async deleteSyncer(syncer: Syncer, owner?: string) {
return this.modifySyncer('delete-syncer', syncer, owner)
}
}
10 changes: 9 additions & 1 deletion test/syncer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('TestSyncer', async () => {
// Get all objects and check if our added object is in the list
const {
data: { data: syncers },
} = await sdk.getSyncers()
} = await sdk.getSyncers(syncer.owner)
const found = syncers.some((item) => item.name === name)
if (!found) {
throw new Error('Added object not found in list')
Expand All @@ -70,6 +70,14 @@ test('TestSyncer', async () => {
)
}

// Get the objects
const {
data: { data: retrievedSyncers },
} = await sdk.getSyncers(syncer.owner)
if (retrievedSyncers.length !== 1 || retrievedSyncers[0].name !== name) {
throw new Error('Failed to get objects')
}

// Update the object
const updatedHost = 'Updated Host'
retrievedSyncer.host = updatedHost
Expand Down
Loading