Skip to content
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
111 changes: 106 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 37 additions & 15 deletions clients/javascript/lib/baseClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import axios, {
type AxiosRequestConfig,
AxiosError,
type AxiosInstance,
type AxiosRequestConfig,
type AxiosResponse,
AxiosError,
} from 'axios'
import axiosRetry, { isNetworkOrIdempotentRequestError } from 'axios-retry'
import type { ICredentials } from './helpers/credentials'
import {
BadRequestError,
Expand All @@ -12,7 +13,6 @@ import {
UnauthorizedError,
UnprocessableEntityError,
} from './helpers/errors'
import axiosRetry, { isNetworkOrIdempotentRequestError } from 'axios-retry'

/**
* Configuration for the keep alive feature
Expand Down Expand Up @@ -113,12 +113,12 @@ export abstract class NitteiBaseClient {
data,
params,
}: {
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
path: string
data?: unknown
params?: Record<string, unknown>
}): Promise<AxiosResponse<T>> {
let res: AxiosResponse<T> | undefined = undefined
let res: AxiosResponse<T> | undefined
try {
res = await this.axiosClient({ method, url: path, data, params })
} catch (error) {
Expand Down Expand Up @@ -201,6 +201,24 @@ export abstract class NitteiBaseClient {
return res.data
}

/**
* Make a PATCH request to the API
* @private
* @param path - path to the endpoint
* @param data - data to send to the server
* @throws Error if the status code is 400 or higher
* @returns response's data
*/
protected async patch<T>(path: string, data: unknown): Promise<T> {
const res = await this.callApi<T>({
method: 'PATCH',
path,
data,
})

return res.data
}

/**
* Make a DELETE request to the API
* Note: this one doesn't have a body
Expand Down Expand Up @@ -301,11 +319,13 @@ export const createAxiosInstanceFrontend = (
}
const filteredMap = Object.entries(params)
.filter(([, value]) => value !== undefined)
.reduce((acc, [key, value]) => {
acc[key] = value
return acc
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
}, {} as any)
.reduce(
(acc, [key, value]) => {
acc[key] = value
return acc
},
{} as Record<string, string>
)
return new URLSearchParams(filteredMap).toString()
},
}
Expand Down Expand Up @@ -352,11 +372,13 @@ export const createAxiosInstanceBackend = async (
}
const filteredMap = Object.entries(params)
.filter(([, value]) => value !== undefined)
.reduce((acc, [key, value]) => {
acc[key] = value
return acc
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
}, {} as any)
.reduce(
(acc, [key, value]) => {
acc[key] = value
return acc
},
{} as Record<string, string>
)
return new URLSearchParams(filteredMap).toString()
},
}
Expand Down
53 changes: 53 additions & 0 deletions clients/javascript/lib/eventClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { CreateEventRequestBody } from './gen_types/CreateEventRequestBody'
import type { GetEventInstancesAPIResponse } from './gen_types/GetEventInstancesAPIResponse'
import type { ID } from './gen_types/ID'
import type { UpdateEventRequestBody } from './gen_types/UpdateEventRequestBody'
import type { UpdateEventRequestBodyV2 } from './gen_types/UpdateEventRequestBodyV2'
import {
convertEventDates,
convertInstanceDates,
Expand All @@ -33,6 +34,12 @@ export type Timespan = {
* This is an admin client (usually backend)
*/
export class NitteiEventClient extends NitteiBaseClient {
/**
* Update an event
* @param eventId - id of the event
* @param data - data of the event
* @returns - the updated event
*/
public async update(
eventId: ID,
data: UpdateEventRequestBody
Expand All @@ -47,6 +54,26 @@ export class NitteiEventClient extends NitteiBaseClient {
}
}

/**
* Update an event (V2)
* @param eventId - id of the event
* @param data - data of the event
* @returns - the updated event
*/
public async updateV2(
eventId: ID,
data: UpdateEventRequestBodyV2
): Promise<CalendarEventResponse> {
const res = await this.patch<CalendarEventResponse>(
`/user/events_v2/${eventId}`,
data
)

return {
event: convertEventDates(res.event),
}
}

/**
* Create a new calendar event
* @param userId - id of the user
Expand Down Expand Up @@ -219,6 +246,12 @@ export class NitteiEventClient extends NitteiBaseClient {
* This is an end user client (usually frontend)
*/
export class NitteiEventUserClient extends NitteiBaseClient {
/**
* Update an event
* @param eventId - id of the event
* @param data - data of the event
* @returns - the updated event
*/
public async update(
eventId: ID,
data: UpdateEventRequestBody
Expand All @@ -233,6 +266,26 @@ export class NitteiEventUserClient extends NitteiBaseClient {
}
}

/**
* Update an event (V2)
* @param eventId - id of the event
* @param data - data of the event
* @returns - the updated event
*/
public async updateV2(
eventId: ID,
data: UpdateEventRequestBodyV2
): Promise<CalendarEventResponse> {
const res = await this.put<CalendarEventResponse>(
`/events_v2/${eventId}`,
data
)

return {
event: convertEventDates(res.event),
}
}

public async create(
data: CreateEventRequestBody
): Promise<CalendarEventResponse> {
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/lib/gen_types/CalendarEventReminder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type CalendarEventReminder = { delta: bigint; identifier: string }
export type CalendarEventReminder = { delta: number; identifier: string }
Loading