From 1ff5078d2a7be78f19961b40e76e047585381533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hector=20G=C3=B3mez=20Varela?= Date: Tue, 16 Jul 2024 17:59:48 +0200 Subject: [PATCH 1/7] Add CGW Accounts API specification --- src/types/accounts.ts | 29 +++++++++++ src/types/api.ts | 118 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/types/accounts.ts diff --git a/src/types/accounts.ts b/src/types/accounts.ts new file mode 100644 index 00000000..cdc1a77d --- /dev/null +++ b/src/types/accounts.ts @@ -0,0 +1,29 @@ +export type Account = { + accountId: string + groupId: string | null + address: string +} + +export type AccountDataType = { + id: string + name: string + description: string | null + isActive: boolean +} + +export type AccountDataSetting = { + name: string + description: string | null + enabled: boolean +} + +export type CreateAccountDto = { + address: string +} + +export type UpsertAccountDataSettingsDto = { + accountDataSettings: { + id: string + enabled: boolean + }[] +} diff --git a/src/types/api.ts b/src/types/api.ts index 11129c38..c226251c 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -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 { + Account, + AccountDataSetting, + AccountDataType, + CreateAccountDto, + UpsertAccountDataSettingsDto, +} from './accounts' export type Primitive = string | number | boolean | null @@ -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' + } + } } export interface operations { @@ -1225,4 +1265,82 @@ export interface operations { } } } + create_account: { + parameters: { + body: CreateAccountDto + 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: UpsertAccountDataSettingsDto + } + 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 + } + 403: unknown + } + } } From e74b0321e1713990300889f00bda44959dacf7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hector=20G=C3=B3mez=20Varela?= Date: Wed, 17 Jul 2024 10:26:19 +0200 Subject: [PATCH 2/7] Enforce hexadecimal string for address fields --- src/types/accounts.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/accounts.ts b/src/types/accounts.ts index cdc1a77d..718618fb 100644 --- a/src/types/accounts.ts +++ b/src/types/accounts.ts @@ -1,7 +1,7 @@ export type Account = { accountId: string groupId: string | null - address: string + address: `0x${string}` } export type AccountDataType = { @@ -18,7 +18,7 @@ export type AccountDataSetting = { } export type CreateAccountDto = { - address: string + address: `0x${string}` } export type UpsertAccountDataSettingsDto = { From eaa943b7a8c532b1c194ccb05d9fffb3a9c5dda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hector=20G=C3=B3mez=20Varela?= Date: Wed, 17 Jul 2024 17:34:29 +0200 Subject: [PATCH 3/7] Refactor Account types definitions --- src/types/accounts.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/types/accounts.ts b/src/types/accounts.ts index 718618fb..49a62966 100644 --- a/src/types/accounts.ts +++ b/src/types/accounts.ts @@ -1,5 +1,5 @@ export type Account = { - accountId: string + id: string groupId: string | null address: `0x${string}` } @@ -12,18 +12,14 @@ export type AccountDataType = { } export type AccountDataSetting = { - name: string - description: string | null + dataTypeId: string enabled: boolean } -export type CreateAccountDto = { +export type CreateAccountRequest = { address: `0x${string}` } -export type UpsertAccountDataSettingsDto = { - accountDataSettings: { - id: string - enabled: boolean - }[] +export type UpsertAccountDataSettingsRequest = { + accountDataSettings: AccountDataSetting[] } From 20ad85f9fc777c42fba389e81ecf93957ca5a4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20G=C3=B3mez?= Date: Thu, 18 Jul 2024 14:03:30 +0200 Subject: [PATCH 4/7] Update src/types/api.ts Co-authored-by: Usame Algan <5880855+usame-algan@users.noreply.github.com> --- src/types/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/api.ts b/src/types/api.ts index c226251c..00bd376e 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -1267,7 +1267,7 @@ export interface operations { } create_account: { parameters: { - body: CreateAccountDto + body: CreateAccountRequest credentials: 'include' } responses: { From dc5bf2b74cd06340df73ef3f5e4444a9778d6113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20G=C3=B3mez?= Date: Thu, 18 Jul 2024 14:03:35 +0200 Subject: [PATCH 5/7] Update src/types/api.ts Co-authored-by: Usame Algan <5880855+usame-algan@users.noreply.github.com> --- src/types/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/api.ts b/src/types/api.ts index 00bd376e..834c0b71 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -1306,7 +1306,7 @@ export interface operations { address: string } credentials: 'include' - body: UpsertAccountDataSettingsDto + body: UpsertAccountDataSettingsRequest } responses: { 200: { From 1342978d4739396573ecfe31692969cd92a133bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20G=C3=B3mez?= Date: Thu, 18 Jul 2024 14:05:43 +0200 Subject: [PATCH 6/7] Update src/types/api.ts Co-authored-by: Usame Algan <5880855+usame-algan@users.noreply.github.com> --- src/types/api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types/api.ts b/src/types/api.ts index 834c0b71..0db8ed7d 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -46,12 +46,12 @@ import type { RelayCountResponse, RelayTransactionRequest, RelayTransactionRespo import type { RegisterRecoveryModuleRequestBody } from './recovery' import type { Contract } from './contracts' import type { AuthNonce } from './auth' -import { +import type { Account, AccountDataSetting, AccountDataType, - CreateAccountDto, - UpsertAccountDataSettingsDto, + CreateAccountRequest, + UpsertAccountDataSettingsRequest, } from './accounts' export type Primitive = string | number | boolean | null From fdeb8b1243d35f9f7d76699d688a4e951e445536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hector=20G=C3=B3mez=20Varela?= Date: Thu, 18 Jul 2024 15:57:57 +0200 Subject: [PATCH 7/7] Add Account API functions to index.ts --- src/index.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ src/types/api.ts | 3 +++ 2 files changed, 46 insertions(+) diff --git a/src/index.ts b/src/index.ts index 56ce3ca0..93364a40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 */ diff --git a/src/types/api.ts b/src/types/api.ts index 0db8ed7d..acdb1972 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -1340,6 +1340,9 @@ export interface operations { 204: { schema: void } + 200: { + schema: void + } 403: unknown } }