Skip to content

Commit e3ea58e

Browse files
committed
[wip] Add audit log and repos features
1 parent 04cad6c commit e3ea58e

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

index.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,112 @@ class SocketSdk {
385385
}
386386
}
387387

388+
/**
389+
* @param {string} orgSlug
390+
* @param {{[key: string]: any }} queryParams
391+
* @returns {Promise<SocketSdkResultType<'getAuditLogEvents'>>}
392+
*/
393+
async getAuditLogEvents (orgSlug, queryParams) {
394+
const orgSlugParam = encodeURIComponent(orgSlug)
395+
const formattedQueryParam = new URLSearchParams(queryParams)
396+
397+
try {
398+
const client = await this.#getClient()
399+
const data = await client.get(`orgs/${orgSlugParam}/audit-log?${formattedQueryParam}`).json()
400+
return { success: true, status: 200, data }
401+
} catch (err) {
402+
return /** @type {SocketSdkErrorType<'getAuditLogEvents'>} */ (this.#handleApiError(err))
403+
}
404+
}
405+
406+
/**
407+
* @param {string} orgSlug
408+
* @param {string} repoSlug
409+
* @returns {Promise<SocketSdkResultType<'getAuditLogEvents'>>}
410+
*/
411+
async getOrgRepo (orgSlug, repoSlug) {
412+
const orgSlugParam = encodeURIComponent(orgSlug)
413+
const repoSlugParam = encodeURIComponent(repoSlug)
414+
415+
try {
416+
const client = await this.#getClient()
417+
const data = await client.get(`orgs/${orgSlugParam}/repos/${repoSlugParam}`).json()
418+
return { success: true, status: 200, data }
419+
} catch (err) {
420+
return /** @type {SocketSdkErrorType<'getAuditLogEvents'>} */ (this.#handleApiError(err))
421+
}
422+
}
423+
424+
/**
425+
* @param {string} orgSlug
426+
* @param {string} repoSlug
427+
* @returns {Promise<SocketSdkResultType<'getAuditLogEvents'>>}
428+
*/
429+
async deleteOrgRepo (orgSlug, repoSlug) {
430+
const orgSlugParam = encodeURIComponent(orgSlug)
431+
const repoSlugParam = encodeURIComponent(repoSlug)
432+
433+
try {
434+
const client = await this.#getClient()
435+
const data = await client.delete(`orgs/${orgSlugParam}/repos/${repoSlugParam}`).json()
436+
return { success: true, status: 200, data }
437+
} catch (err) {
438+
return /** @type {SocketSdkErrorType<'getAuditLogEvents'>} */ (this.#handleApiError(err))
439+
}
440+
}
441+
442+
/**
443+
* @param {string} orgSlug
444+
* @param {{[key: string]: any }} queryParams
445+
* @returns {Promise<SocketSdkResultType<'getAuditLogEvents'>>}
446+
*/
447+
async getOrgRepoList (orgSlug, queryParams) {
448+
const orgSlugParam = encodeURIComponent(orgSlug)
449+
const formattedQueryParam = new URLSearchParams(queryParams)
450+
451+
try {
452+
const client = await this.#getClient()
453+
const data = await client.get(`orgs/${orgSlugParam}/repos?${formattedQueryParam}`).json()
454+
return { success: true, status: 200, data }
455+
} catch (err) {
456+
return /** @type {SocketSdkErrorType<'getAuditLogEvents'>} */ (this.#handleApiError(err))
457+
}
458+
}
459+
460+
/**
461+
* @param {string} orgSlug
462+
* @param {string} params
463+
* @returns {Promise<SocketSdkResultType<'getAuditLogEvents'>>}
464+
*/
465+
async createOrgRepo (orgSlug, params) {
466+
const orgSlugParam = encodeURIComponent(orgSlug)
467+
468+
try {
469+
const client = await this.#getClient()
470+
const data = await client.post(`orgs/${orgSlugParam}/repos`, { body: params }).json()
471+
return { success: true, status: 200, data }
472+
} catch (err) {
473+
return /** @type {SocketSdkErrorType<'getAuditLogEvents'>} */ (this.#handleApiError(err))
474+
}
475+
}
476+
477+
/**
478+
* @param {string} orgSlug
479+
* @param {string} repoSlug
480+
* @returns {Promise<SocketSdkResultType<'getAuditLogEvents'>>}
481+
*/
482+
async updateOrgRepo (orgSlug, repoSlug) {
483+
const orgSlugParam = encodeURIComponent(orgSlug)
484+
485+
try {
486+
const client = await this.#getClient()
487+
const data = await client.post(`orgs/${orgSlugParam}/repos/${repoSlug}`).json()
488+
return { success: true, status: 200, data }
489+
} catch (err) {
490+
return /** @type {SocketSdkErrorType<'getAuditLogEvents'>} */ (this.#handleApiError(err))
491+
}
492+
}
493+
388494
/**
389495
* @param {Array<{ organization?: string }>} selectors
390496
* @returns {Promise<SocketSdkResultType<'postSettings'>>}

0 commit comments

Comments
 (0)