Skip to content

Commit

Permalink
fix: biome issues + adapt due to axios downgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDecMeetsMore committed Oct 16, 2024
1 parent 52eace9 commit cf04ad2
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 113 deletions.
8 changes: 4 additions & 4 deletions clients/javascript/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
preset: 'ts-jest',
testEnvironment: 'node',
bail: true,
testMatch: ["**/*.spec*"],
};
testMatch: ['**/*.spec*'],
}
8 changes: 4 additions & 4 deletions clients/javascript/lib/accountClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NitteiBaseClient } from './baseClient'
import { AccountResponse } from './gen_types/AccountResponse'
import { AddAccountIntegrationRequestBody } from './gen_types/AddAccountIntegrationRequestBody'
import { CreateAccountRequestBody } from './gen_types/CreateAccountRequestBody'
import { CreateAccountResponseBody } from './gen_types/CreateAccountResponseBody'
import type { AccountResponse } from './gen_types/AccountResponse'
import type { AddAccountIntegrationRequestBody } from './gen_types/AddAccountIntegrationRequestBody'
import type { CreateAccountRequestBody } from './gen_types/CreateAccountRequestBody'
import type { CreateAccountResponseBody } from './gen_types/CreateAccountResponseBody'

/**
* Client for the account endpoints
Expand Down
47 changes: 34 additions & 13 deletions clients/javascript/lib/baseClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios, {
AxiosRequestConfig,
type AxiosRequestConfig,
type AxiosInstance,
type AxiosResponse,
} from 'axios'
import { ICredentials } from './helpers/credentials'
import type { ICredentials } from './helpers/credentials'
import {
BadRequestError,
NotFoundError,
Expand Down Expand Up @@ -98,7 +98,7 @@ export abstract class NitteiBaseClient {
* @returns response's data
*/
protected async deleteWithBody<T>(path: string, data: unknown): Promise<T> {
const res = await this.axiosClient<T>({
const res: AxiosResponse<T> = await this.axiosClient({
method: 'DELETE',
data,
url: path,
Expand All @@ -122,13 +122,14 @@ export abstract class NitteiBaseClient {
if (res.status >= 400) {
if (res.status === 400) {
throw new BadRequestError(res.data)
} else if (res.status === 401 || res.status === 403) {
}
if (res.status === 401 || res.status === 403) {
throw new UnauthorizedError(res.data)
} else if (res.status === 404) {
}
if (res.status === 404) {
throw new NotFoundError(res.data)
} else {
throw new Error(`Request failed with status code ${res.status}`)
}
throw new Error(`Request failed with status code ${res.status}`)
}
}
}
Expand All @@ -153,8 +154,18 @@ export const createAxiosInstanceFrontend = (
baseURL: args.baseUrl,
headers: credentials.createAuthHeaders(),
validateStatus: () => true, // allow all status codes without throwing error
paramsSerializer: {
indexes: null, // Force to stringify arrays like value1,value2 instead of value1[0],value1[1]
paramsSerializer: params => {
if (!params) {
return ''
}
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)
return new URLSearchParams(filteredMap).toString()
},
}

Expand All @@ -180,8 +191,18 @@ export const createAxiosInstanceBackend = async (
baseURL: args.baseUrl,
headers: credentials.createAuthHeaders(),
validateStatus: () => true, // allow all status codes without throwing error
paramsSerializer: {
indexes: null, // Force to stringify arrays like value1,value2 instead of value1[0],value1[1]
paramsSerializer: params => {
if (!params) {
return ''
}
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)
return new URLSearchParams(filteredMap).toString()
},
}

Expand All @@ -190,11 +211,11 @@ export const createAxiosInstanceBackend = async (
if (args.keepAlive && typeof module !== 'undefined' && module.exports) {
if (args.baseUrl.startsWith('https')) {
// This is a dynamic import to avoid loading the https module in the browser
const https = await import('https')
const https = await import('node:https')
config.httpsAgent = new https.Agent({ keepAlive: true })
} else {
// This is a dynamic import to avoid loading the http module in the browser
const http = await import('http')
const http = await import('node:http')
config.httpAgent = new http.Agent({ keepAlive: true })
}
}
Expand Down
28 changes: 14 additions & 14 deletions clients/javascript/lib/calendarClient.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { NitteiBaseClient } from './baseClient'
import type { Timespan } from './eventClient'
import type { AddSyncCalendarPathParams } from './gen_types/AddSyncCalendarPathParams'
import type { AddSyncCalendarRequestBody } from './gen_types/AddSyncCalendarRequestBody'
import type { CalendarDTO } from './gen_types/CalendarDTO'
import type { CalendarResponse } from './gen_types/CalendarResponse'
import type { CreateCalendarRequestBody } from './gen_types/CreateCalendarRequestBody'
import type { GetCalendarEventsAPIResponse } from './gen_types/GetCalendarEventsAPIResponse'
import type { GetCalendarsByUserAPIResponse } from './gen_types/GetCalendarsByUserAPIResponse'
import type { GoogleCalendarAccessRole } from './gen_types/GoogleCalendarAccessRole'
import type { GoogleCalendarListEntry } from './gen_types/GoogleCalendarListEntry'
import type { ID } from './gen_types/ID'
import type { OutlookCalendar } from './gen_types/OutlookCalendar'
import type { OutlookCalendarAccessRole } from './gen_types/OutlookCalendarAccessRole'
import type { RemoveSyncCalendarPathParams } from './gen_types/RemoveSyncCalendarPathParams'
import type { RemoveSyncCalendarRequestBody } from './gen_types/RemoveSyncCalendarRequestBody'
import {
convertEventDates,
convertInstanceDates,
} from './helpers/datesConverters'
import { AddSyncCalendarPathParams } from './gen_types/AddSyncCalendarPathParams'
import { AddSyncCalendarRequestBody } from './gen_types/AddSyncCalendarRequestBody'
import { CalendarDTO } from './gen_types/CalendarDTO'
import { CalendarResponse } from './gen_types/CalendarResponse'
import { CreateCalendarRequestBody } from './gen_types/CreateCalendarRequestBody'
import { GetCalendarEventsAPIResponse } from './gen_types/GetCalendarEventsAPIResponse'
import { GoogleCalendarAccessRole } from './gen_types/GoogleCalendarAccessRole'
import { GoogleCalendarListEntry } from './gen_types/GoogleCalendarListEntry'
import { ID } from './gen_types/ID'
import { OutlookCalendar } from './gen_types/OutlookCalendar'
import { OutlookCalendarAccessRole } from './gen_types/OutlookCalendarAccessRole'
import { RemoveSyncCalendarPathParams } from './gen_types/RemoveSyncCalendarPathParams'
import { RemoveSyncCalendarRequestBody } from './gen_types/RemoveSyncCalendarRequestBody'
import { GetCalendarsByUserAPIResponse } from './gen_types/GetCalendarsByUserAPIResponse'

/**
* Request for updating a calendar
Expand Down
14 changes: 7 additions & 7 deletions clients/javascript/lib/eventClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { NitteiBaseClient } from './baseClient'
import type { CalendarEventDTO } from './gen_types/CalendarEventDTO'
import type { CalendarEventResponse } from './gen_types/CalendarEventResponse'
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 {
convertEventDates,
convertInstanceDates,
} from './helpers/datesConverters'
import { CalendarEventDTO } from './gen_types/CalendarEventDTO'
import { CalendarEventResponse } from './gen_types/CalendarEventResponse'
import { CreateEventRequestBody } from './gen_types/CreateEventRequestBody'
import { GetEventInstancesAPIResponse } from './gen_types/GetEventInstancesAPIResponse'
import { ID } from './gen_types/ID'
import { UpdateEventRequestBody } from './gen_types/UpdateEventRequestBody'

/**
* Timespan for getting event instances
Expand Down Expand Up @@ -60,7 +60,7 @@ export class NitteiEventClient extends NitteiBaseClient {
}

public async getByExternalId(
externalId: String
externalId: string
): Promise<CalendarEventResponse> {
const res = await this.get<CalendarEventResponse>(
`/user/events/external_id/${externalId}`
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/lib/gen_types/CalendarEventDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { CalendarEventReminder } from './CalendarEventReminder'
import type { CalendarEventStatus } from './CalendarEventStatus'
import type { ID } from './ID'
import type { JsonValue } from './serde_json/JsonValue'
import type { RRuleOptions } from './RRuleOptions'
import type { JsonValue } from './serde_json/JsonValue'

/**
* Calendar event object
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/lib/gen_types/CreateEventRequestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { CalendarEventReminder } from './CalendarEventReminder'
import type { CalendarEventStatus } from './CalendarEventStatus'
import type { ID } from './ID'
import type { JsonValue } from './serde_json/JsonValue'
import type { RRuleOptions } from './RRuleOptions'
import type { JsonValue } from './serde_json/JsonValue'

/**
* Request body for creating an event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ServiceMultiPersonOptions } from './ServiceMultiPersonOptions'
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { JsonValue } from './serde_json/JsonValue'
import type { ServiceMultiPersonOptions } from './ServiceMultiPersonOptions'

export type CreateServiceRequestBody = {
metadata?: JsonValue
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/lib/gen_types/ScheduleDTO.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ID } from './ID'
import type { JsonValue } from './serde_json/JsonValue'
import type { ScheduleRule } from './ScheduleRule'
import type { JsonValue } from './serde_json/JsonValue'

/**
* A schedule is a set of rules that define when a service is available
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/lib/gen_types/ServiceWithUsersDTO.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ID } from './ID'
import type { JsonValue } from './serde_json/JsonValue'
import type { ServiceResourceDTO } from './ServiceResourceDTO'
import type { JsonValue } from './serde_json/JsonValue'

export type ServiceWithUsersDTO = {
id: ID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UpdateCalendarSettings } from './UpdateCalendarSettings'
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { JsonValue } from './serde_json/JsonValue'
import type { UpdateCalendarSettings } from './UpdateCalendarSettings'

/**
* Request body for updating a calendar
Expand Down
2 changes: 1 addition & 1 deletion clients/javascript/lib/gen_types/UpdateEventRequestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { CalendarEventReminder } from './CalendarEventReminder'
import type { CalendarEventStatus } from './CalendarEventStatus'
import type { ID } from './ID'
import type { JsonValue } from './serde_json/JsonValue'
import type { RRuleOptions } from './RRuleOptions'
import type { JsonValue } from './serde_json/JsonValue'

/**
* Request body for updating an event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ServiceMultiPersonOptions } from './ServiceMultiPersonOptions'
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { JsonValue } from './serde_json/JsonValue'
import type { ServiceMultiPersonOptions } from './ServiceMultiPersonOptions'

export type UpdateServiceRequestBody = {
metadata?: JsonValue
Expand Down
4 changes: 3 additions & 1 deletion clients/javascript/lib/helpers/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { AxiosRequestHeaders } from 'axios'

/**
* Partial credentials to be used for the client
*/
Expand Down Expand Up @@ -84,5 +86,5 @@ export class EmptyCreds implements ICredentials {
}

export interface ICredentials {
createAuthHeaders(): object
createAuthHeaders(): AxiosRequestHeaders
}
4 changes: 2 additions & 2 deletions clients/javascript/lib/helpers/datesConverters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CalendarEventDTO } from '../gen_types/CalendarEventDTO'
import { EventInstance } from '../gen_types/EventInstance'
import type { CalendarEventDTO } from '../gen_types/CalendarEventDTO'
import type { EventInstance } from '../gen_types/EventInstance'

/**
* Convert the dates inside an event to Date objects
Expand Down
8 changes: 4 additions & 4 deletions clients/javascript/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
} from './calendarClient'
import { NitteiEventClient, NitteiEventUserClient } from './eventClient'
import { NitteiHealthClient } from './healthClient'
import { createCreds, PartialCredentials } from './helpers/credentials'
import { type PartialCredentials, createCreds } from './helpers/credentials'
import {
NitteiScheduleUserClient,
NitteiScheduleClient,
NitteiScheduleUserClient,
} from './scheduleClient'
import { NitteiServiceUserClient, NitteiServiceClient } from './serviceClient'
import { NitteiServiceClient, NitteiServiceUserClient } from './serviceClient'
import {
NitteiUserClient as _NitteiUserClient,
NitteiUserUserClient,
NitteiUserClient as _NitteiUserClient,
} from './userClient'

export interface INitteiUserClient {
Expand Down
6 changes: 3 additions & 3 deletions clients/javascript/lib/scheduleClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NitteiBaseClient } from './baseClient'
import { ID } from './gen_types/ID'
import { ScheduleDTO } from './gen_types/ScheduleDTO'
import { ScheduleRule } from './gen_types/ScheduleRule'
import type { ID } from './gen_types/ID'
import type { ScheduleDTO } from './gen_types/ScheduleDTO'
import type { ScheduleRule } from './gen_types/ScheduleRule'

interface UpdateScheduleRequest {
rules?: ScheduleRule[]
Expand Down
24 changes: 12 additions & 12 deletions clients/javascript/lib/serviceClient.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { NitteiBaseClient } from './baseClient'
import { AddBusyCalendarPathParams } from './gen_types/AddBusyCalendarPathParams'
import { AddBusyCalendarRequestBody } from './gen_types/AddBusyCalendarRequestBody'
import { AddUserToServiceRequestBody } from './gen_types/AddUserToServiceRequestBody'
import { CreateServiceRequestBody } from './gen_types/CreateServiceRequestBody'
import { GetServiceBookingSlotsAPIResponse } from './gen_types/GetServiceBookingSlotsAPIResponse'
import { GetServiceBookingSlotsQueryParams } from './gen_types/GetServiceBookingSlotsQueryParams'
import { ID } from './gen_types/ID'
import { RemoveBusyCalendarPathParams } from './gen_types/RemoveBusyCalendarPathParams'
import { RemoveBusyCalendarRequestBody } from './gen_types/RemoveBusyCalendarRequestBody'
import { ServiceResponse } from './gen_types/ServiceResponse'
import { ServiceWithUsersDTO } from './gen_types/ServiceWithUsersDTO'
import { UpdateServiceRequestBody } from './gen_types/UpdateServiceRequestBody'
import type { AddBusyCalendarPathParams } from './gen_types/AddBusyCalendarPathParams'
import type { AddBusyCalendarRequestBody } from './gen_types/AddBusyCalendarRequestBody'
import type { AddUserToServiceRequestBody } from './gen_types/AddUserToServiceRequestBody'
import type { CreateServiceRequestBody } from './gen_types/CreateServiceRequestBody'
import type { GetServiceBookingSlotsAPIResponse } from './gen_types/GetServiceBookingSlotsAPIResponse'
import type { GetServiceBookingSlotsQueryParams } from './gen_types/GetServiceBookingSlotsQueryParams'
import type { ID } from './gen_types/ID'
import type { RemoveBusyCalendarPathParams } from './gen_types/RemoveBusyCalendarPathParams'
import type { RemoveBusyCalendarRequestBody } from './gen_types/RemoveBusyCalendarRequestBody'
import type { ServiceResponse } from './gen_types/ServiceResponse'
import type { ServiceWithUsersDTO } from './gen_types/ServiceWithUsersDTO'
import type { UpdateServiceRequestBody } from './gen_types/UpdateServiceRequestBody'

/**
* Client for the service endpoints (admin)
Expand Down
24 changes: 12 additions & 12 deletions clients/javascript/lib/userClient.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { NitteiBaseClient } from './baseClient'
import type { CreateUserRequestBody } from './gen_types/CreateUserRequestBody'
import type { GetEventsByCalendarsAPIResponse } from './gen_types/GetEventsByCalendarsAPIResponse'
import type { GetEventsByCalendarsQueryParams } from './gen_types/GetEventsByCalendarsQueryParams'
import type { GetUserFreeBusyAPIResponse } from './gen_types/GetUserFreeBusyAPIResponse'
import type { GetUserFreeBusyQueryParams } from './gen_types/GetUserFreeBusyQueryParams'
import type { ID } from './gen_types/ID'
import type { IntegrationProvider } from './gen_types/IntegrationProvider'
import type { MultipleFreeBusyAPIResponse } from './gen_types/MultipleFreeBusyAPIResponse'
import type { MultipleFreeBusyRequestBody } from './gen_types/MultipleFreeBusyRequestBody'
import type { UpdateUserRequestBody } from './gen_types/UpdateUserRequestBody'
import type { UserDTO } from './gen_types/UserDTO'
import type { UserResponse } from './gen_types/UserResponse'
import {
convertEventDates,
convertInstanceDates,
} from './helpers/datesConverters'
import { CreateUserRequestBody } from './gen_types/CreateUserRequestBody'
import { GetEventsByCalendarsAPIResponse } from './gen_types/GetEventsByCalendarsAPIResponse'
import { GetEventsByCalendarsQueryParams } from './gen_types/GetEventsByCalendarsQueryParams'
import { GetUserFreeBusyAPIResponse } from './gen_types/GetUserFreeBusyAPIResponse'
import { GetUserFreeBusyQueryParams } from './gen_types/GetUserFreeBusyQueryParams'
import { ID } from './gen_types/ID'
import { IntegrationProvider } from './gen_types/IntegrationProvider'
import { MultipleFreeBusyAPIResponse } from './gen_types/MultipleFreeBusyAPIResponse'
import { MultipleFreeBusyRequestBody } from './gen_types/MultipleFreeBusyRequestBody'
import { UpdateUserRequestBody } from './gen_types/UpdateUserRequestBody'
import { UserDTO } from './gen_types/UserDTO'
import { UserResponse } from './gen_types/UserResponse'

/**
* Client for the user endpoints
Expand Down
4 changes: 2 additions & 2 deletions clients/javascript/tests/account.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { INitteiClient, NitteiClient } from '../lib'
import { type INitteiClient, NitteiClient } from '../lib'
import {
CREATE_ACCOUNT_CODE,
setupAccount,
setupUserClientForAccount,
CREATE_ACCOUNT_CODE,
} from './helpers/fixtures'
import { readPrivateKey, readPublicKey } from './helpers/utils'

Expand Down
8 changes: 6 additions & 2 deletions clients/javascript/tests/calendar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { INitteiClient, NitteiClient, type INitteiUserClient } from '../lib'
import { setupUserClient, setupAccount } from './helpers/fixtures'
import {
type INitteiClient,
type INitteiUserClient,
NitteiClient,
} from '../lib'
import { setupAccount, setupUserClient } from './helpers/fixtures'

describe('Calendar API', () => {
let client: INitteiUserClient
Expand Down
Loading

0 comments on commit cf04ad2

Please sign in to comment.