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 CGW Accounts API specification #190

Merged
merged 7 commits into from
Jul 22, 2024
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
43 changes: 43 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,47 @@ export function verifyAuth(body: operations['verify_auth']['parameters']['body']
})
}

export function createAccount(body: operations['create_account']['parameters']['body']) {
return postEndpoint(baseUrl, '/v1/accounts', {
body,
credentials: 'include',
})
}

export function getAccount(address: string) {
return getEndpoint(baseUrl, '/v1/accounts/{address}', {
path: { address },
credentials: 'include',
})
}

export function deleteAccount(address: string) {
return deleteEndpoint(baseUrl, '/v1/accounts/{address}', {
path: { address },
credentials: 'include',
})
}

export function getAccountDataTypes() {
return getEndpoint(baseUrl, '/v1/accounts/data-types')
}

export function getAccountDataSettings(address: string) {
return getEndpoint(baseUrl, '/v1/accounts/{address}/data-settings', {
path: { address },
credentials: 'include',
})
}

export function putAccountDataSettings(
address: string,
body: operations['put_account_data_settings']['parameters']['body'],
) {
return putEndpoint(baseUrl, '/v1/accounts/{address}/data-settings', {
path: { address },
body,
credentials: 'include',
})
}

/* eslint-enable @typescript-eslint/explicit-module-boundary-types */
25 changes: 25 additions & 0 deletions src/types/accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export type Account = {
id: string
groupId: string | null
address: `0x${string}`
}

export type AccountDataType = {
id: string
name: string
description: string | null
isActive: boolean
}

export type AccountDataSetting = {
dataTypeId: string
enabled: boolean
}

export type CreateAccountRequest = {
address: `0x${string}`
}

export type UpsertAccountDataSettingsRequest = {
accountDataSettings: AccountDataSetting[]
}
121 changes: 121 additions & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ import type { RelayCountResponse, RelayTransactionRequest, RelayTransactionRespo
import type { RegisterRecoveryModuleRequestBody } from './recovery'
import type { Contract } from './contracts'
import type { AuthNonce } from './auth'
import type {
Account,
AccountDataSetting,
AccountDataType,
CreateAccountRequest,
UpsertAccountDataSettingsRequest,
} from './accounts'

export type Primitive = string | number | boolean | null

Expand Down Expand Up @@ -472,6 +479,39 @@ export interface paths extends PathRegistry {
}
}
}
'/v1/accounts': {
post: operations['create_account']
parameters: {
path: null
credentials: 'include'
}
}
'/v1/accounts/{address}': {
get: operations['get_account']
delete: operations['delete_account']
parameters: {
path: {
address: string
}
credentials: 'include'
}
}
'/v1/accounts/data-types': {
get: operations['get_account_data_types']
parameters: {
path: null
}
}
'/v1/accounts/{address}/data-settings': {
get: operations['get_account_data_settings']
put: operations['put_account_data_settings']
parameters: {
path: {
address: string
}
credentials: 'include'
}
}
Comment on lines +505 to +514
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we have to define the body here as well but when calling putAccountDataSettings there is no type checking so I can pass anything I want as the second parameter in putAccountDataSettings(wallet.address, {}) without an error 🤔 @katspaugh do you remember if this is expected?

}

export interface operations {
Expand Down Expand Up @@ -1225,4 +1265,85 @@ export interface operations {
}
}
}
create_account: {
parameters: {
body: CreateAccountRequest
credentials: 'include'
}
responses: {
200: {
schema: Account
}
403: unknown
422: unknown
}
}
get_account_data_types: {
parameters: null
responses: {
200: {
schema: AccountDataType[]
}
}
}
get_account_data_settings: {
parameters: {
path: {
address: string
}
credentials: 'include'
}
responses: {
200: {
schema: AccountDataSetting[]
}
403: unknown
}
}
put_account_data_settings: {
parameters: {
path: {
address: string
}
credentials: 'include'
body: UpsertAccountDataSettingsRequest
}
responses: {
200: {
schema: AccountDataSetting[]
}
403: unknown
}
}
get_account: {
parameters: {
path: {
address: string
}
credentials: 'include'
}
responses: {
200: {
schema: Account
}
403: unknown
}
}
delete_account: {
parameters: {
path: {
address: string
}
credentials: 'include'
}
responses: {
204: {
schema: void
}
200: {
schema: void
}
403: unknown
}
}
}
Loading