Skip to content

Commit 78b537c

Browse files
committed
expose analytics API functions
1 parent b7abdaa commit 78b537c

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,40 @@ class SocketSdk {
225225
}
226226
}
227227

228+
/**
229+
* @param {string} time
230+
* @returns {Promise<SocketSdkResultType<'getOrgAnalytics'>>}
231+
*/
232+
async getOrgAnalytics (time) {
233+
const timeParam = encodeURIComponent(time)
234+
235+
try {
236+
const client = await this.#getClient()
237+
const data = await client.get(`analytics/org/${timeParam}`).json()
238+
return { success: true, status: 200, data }
239+
} catch (err) {
240+
return /** @type {SocketSdkErrorType<'getOrgAnalytics'>} */ (this.#handleApiError(err))
241+
}
242+
}
243+
244+
/**
245+
* @param {string} repo
246+
* @param {string} time
247+
* @returns {Promise<SocketSdkResultType<'getRepoAnalytics'>>}
248+
*/
249+
async getRepoAnalytics (repo, time) {
250+
const timeParam = encodeURIComponent(time)
251+
const repoParam = encodeURIComponent(repo)
252+
253+
try {
254+
const client = await this.#getClient()
255+
const data = await client.get(`analytics/repo/${repoParam}/${timeParam}`).json()
256+
return { success: true, status: 200, data }
257+
} catch (err) {
258+
return /** @type {SocketSdkErrorType<'getRepoAnalytics'>} */ (this.#handleApiError(err))
259+
}
260+
}
261+
228262
/**
229263
* @param {Array<{ organization?: string }>} selectors
230264
* @returns {Promise<SocketSdkResultType<'postSettings'>>}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)