diff --git a/core/api/src/domain/users/index.ts b/core/api/src/domain/users/index.ts index 17d88617414..1c6fb89e899 100644 --- a/core/api/src/domain/users/index.ts +++ b/core/api/src/domain/users/index.ts @@ -19,7 +19,7 @@ const PhoneNumberRegex = /^\+\d{7,14}$/i // FIXME {7,14} to be refined const EmailAddressRegex = /^[\w-.+]+@([\w-]+\.)+[\w-]{2,4}$/i -const IdRegex = +const UuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i export const checkedToPhoneNumber = ( @@ -74,7 +74,7 @@ export const checkedToDeviceId = ( export const checkedToIdentityUsername = ( username: string, ): IdentityUsername | ValidationError => { - if (!username.match(IdRegex)) { + if (!username.match(UuidRegex)) { return new InvalidIdentityUsername(username) } return username as IdentityUsername @@ -83,7 +83,7 @@ export const checkedToIdentityUsername = ( export const checkedToIdentityPassword = ( password: string, ): IdentityPassword | ValidationError => { - if (!password.match(IdRegex)) { + if (!password.match(UuidRegex)) { return new InvalidIdentityPassword(password) } return password as IdentityPassword diff --git a/core/api/src/domain/wallets/validation.ts b/core/api/src/domain/wallets/validation.ts index 7fe9a106ba3..1841a5b42a4 100644 --- a/core/api/src/domain/wallets/validation.ts +++ b/core/api/src/domain/wallets/validation.ts @@ -1,9 +1,9 @@ import { InvalidWalletId } from "@/domain/errors" -const IdRegex = +const UuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i -export const WalletIdRegex = IdRegex +export const WalletIdRegex = UuidRegex export const checkedToWalletId = (walletId: string): WalletId | ValidationError => { if (!walletId.match(WalletIdRegex)) { diff --git a/core/api/src/graphql/admin/root/mutation/account-update-level.ts b/core/api/src/graphql/admin/root/mutation/account-update-level.ts index 048e08e3086..240accd9f7d 100644 --- a/core/api/src/graphql/admin/root/mutation/account-update-level.ts +++ b/core/api/src/graphql/admin/root/mutation/account-update-level.ts @@ -3,13 +3,13 @@ import AccountDetailPayload from "@/graphql/admin/types/payload/account-detail" import AccountLevel from "@/graphql/shared/types/scalar/account-level" import { mapAndParseErrorForGqlResponse } from "@/graphql/error-map" import { GT } from "@/graphql/index" -import AccountId from "@/graphql/shared/types/scalar/account-id" const AccountUpdateLevelInput = GT.Input({ name: "AccountUpdateLevelInput", fields: () => ({ - accountId: { - type: GT.NonNull(AccountId), + // FIXME: should be account id + uid: { + type: GT.NonNullID, }, level: { type: GT.NonNull(AccountLevel), @@ -22,7 +22,7 @@ const AccountUpdateLevelMutation = GT.Field< GraphQLAdminContext, { input: { - accountId: AccountId | Error + uid: string | Error level: AccountLevel | Error } } @@ -35,12 +35,12 @@ const AccountUpdateLevelMutation = GT.Field< input: { type: GT.NonNull(AccountUpdateLevelInput) }, }, resolve: async (_, args) => { - const { accountId, level } = args.input + const { uid, level } = args.input if (level instanceof Error) return { errors: [{ message: level.message }] } - if (accountId instanceof Error) return { errors: [{ message: accountId.message }] } + if (uid instanceof Error) return { errors: [{ message: uid.message }] } - const account = await Accounts.updateAccountLevel({ accountId, level }) + const account = await Accounts.updateAccountLevel({ accountId: uid, level }) if (account instanceof Error) { return { errors: [mapAndParseErrorForGqlResponse(account)] } diff --git a/core/api/src/graphql/admin/schema.graphql b/core/api/src/graphql/admin/schema.graphql index a19396d241f..362ca702439 100644 --- a/core/api/src/graphql/admin/schema.graphql +++ b/core/api/src/graphql/admin/schema.graphql @@ -3,9 +3,6 @@ type AccountDetailPayload { errors: [Error!]! } -"""Unique identifier of an account""" -scalar AccountId - enum AccountLevel { ONE TWO @@ -21,8 +18,8 @@ enum AccountStatus { } input AccountUpdateLevelInput { - accountId: AccountId! level: AccountLevel! + uid: ID! } input AccountUpdateStatusInput { diff --git a/core/api/src/migrations/20221010162913-add-self-trade-type.ts b/core/api/src/migrations/20221010162913-add-self-trade-type.ts index 2e59d3a2d56..fb5144c67a9 100644 --- a/core/api/src/migrations/20221010162913-add-self-trade-type.ts +++ b/core/api/src/migrations/20221010162913-add-self-trade-type.ts @@ -42,6 +42,8 @@ const getNonUserWalletIds = async ({ usersCollection, walletsCollection }) => { } module.exports = { + /* eslint @typescript-eslint/ban-ts-comment: "off" */ + // @ts-ignore-next-line no-implicit-any error async up(db) { const usersCollection = db.collection("users") const walletsCollection = db.collection("wallets") @@ -96,7 +98,7 @@ module.exports = { if (txns[0].currency === txns[1].currency) return false // Compare accountIds to see if self-trade - const accountIdsSet = new Set(txns.map((txn) => txn.AccountId)) + const accountIdsSet = new Set(txns.map((txn) => txn.accountId)) if (accountIdsSet.size > 1) return false // RETURN SELF-TRADE TYPE diff --git a/core/api/src/migrations/20230807205306-add-uuid-to-accounts.ts b/core/api/src/migrations/20230807205306-add-uuid-to-accounts.ts index 59d1e37635d..a3ad9bd5c98 100644 --- a/core/api/src/migrations/20230807205306-add-uuid-to-accounts.ts +++ b/core/api/src/migrations/20230807205306-add-uuid-to-accounts.ts @@ -1,7 +1,7 @@ /* eslint @typescript-eslint/ban-ts-comment: "off" */ // @ts-nocheck /* eslint @typescript-eslint/no-var-requires: "off" */ -const getUuidByString = require("id-by-string") +const getUuidByString = require("uuid-by-string") async function migrateAccounts(db, batchSize = 100) { const cursor = db.collection("accounts").find() @@ -11,11 +11,11 @@ async function migrateAccounts(db, batchSize = 100) { const batchUpdates = [] for (let i = 0; i < batchSize && (await cursor.hasNext()); i++) { const account = await cursor.next() - const id = account.id || getUuidByString(account._id.toString()) + const id = account.uuid || getUuidByString(account._id.toString()) batchUpdates.push({ updateOne: { filter: { _id: account._id }, - update: { $set: { id }, $unset: { id: 1 } }, + update: { $set: { id }, $unset: { uuid: 1 } }, }, }) } @@ -32,6 +32,8 @@ async function migrateAccounts(db, batchSize = 100) { } module.exports = { + /* eslint @typescript-eslint/ban-ts-comment: "off" */ + // @ts-ignore-next-line no-implicit-any error async up(db) { console.log("Begin migration to add UUIDs to Accounts Schema") await migrateAccounts(db) @@ -39,6 +41,6 @@ module.exports = { }, async down() { - console.log(`Rollback of add id to Account Schema migration not needed`) + console.log(`Rollback of add uuid to Account Schema migration not needed`) }, } diff --git a/core/api/src/servers/graphql-admin-server.ts b/core/api/src/servers/graphql-admin-server.ts index 1bbd7753905..240e4f178d0 100644 --- a/core/api/src/servers/graphql-admin-server.ts +++ b/core/api/src/servers/graphql-admin-server.ts @@ -83,7 +83,7 @@ const setGqlAdminContext = async ( } // can be anon. - // TODO: refactor to remove auth endpoint and make context always carry a id v4 .sub/UserId + // TODO: refactor to remove auth endpoint and make context always carry a uuid v4 .sub/UserId const auditorId = tokenPayload.sub as UserId let isEditor = false diff --git a/core/api/src/servers/middlewares/idempotency.ts b/core/api/src/servers/middlewares/idempotency.ts index f2941350130..f2af482d4dc 100644 --- a/core/api/src/servers/middlewares/idempotency.ts +++ b/core/api/src/servers/middlewares/idempotency.ts @@ -10,11 +10,11 @@ import { addAttributesToCurrentSpan } from "@/services/tracing" // Create lock service instance const lockService = LockService() -const IdRegex = +const UuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i const checkedToIdempotencyKey = (input: string) => { - if (!input.match(IdRegex)) { + if (!input.match(UuidRegex)) { return new InvalidIdempotencyKeyError(input) } return input as IdempotencyKey diff --git a/core/api/src/services/kratos/index.ts b/core/api/src/services/kratos/index.ts index e49103bc6bf..2523e151a27 100644 --- a/core/api/src/services/kratos/index.ts +++ b/core/api/src/services/kratos/index.ts @@ -12,13 +12,13 @@ export * from "./identity" export * from "./totp" export * from "./schema" -export const IdRegex = +export const UuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i export const checkedToEmailRegistrationId = ( flow: string, ): EmailRegistrationId | ValidationError => { - if (!flow.match(IdRegex)) { + if (!flow.match(UuidRegex)) { return new InvalidFlowId(flow) } return flow as EmailRegistrationId @@ -27,14 +27,14 @@ export const checkedToEmailRegistrationId = ( export const checkedToTotpRegistrationId = ( flow: string, ): TotpRegistrationId | ValidationError => { - if (!flow.match(IdRegex)) { + if (!flow.match(UuidRegex)) { return new InvalidFlowId(flow) } return flow as TotpRegistrationId } export const checkedToEmailLoginId = (flow: string): EmailLoginId | ValidationError => { - if (!flow.match(IdRegex)) { + if (!flow.match(UuidRegex)) { return new InvalidFlowId(flow) } return flow as EmailLoginId diff --git a/core/api/src/services/mongoose/schema.ts b/core/api/src/services/mongoose/schema.ts index 11052bf7ad6..95baa428467 100644 --- a/core/api/src/services/mongoose/schema.ts +++ b/core/api/src/services/mongoose/schema.ts @@ -330,7 +330,7 @@ const AccountIpsSchema = new Schema({ export const AccountIps = mongoose.model("AccountIp", AccountIpsSchema) AccountIpsSchema.index({ - _AccountId: 1, + accountId: 1, ip: 1, }) diff --git a/core/api/src/services/svix/index.ts b/core/api/src/services/svix/index.ts index 1306eb8feb6..842c66cf320 100644 --- a/core/api/src/services/svix/index.ts +++ b/core/api/src/services/svix/index.ts @@ -85,7 +85,7 @@ export const CallbackService = (config: SvixConfig) => { const prefixedPayload = prefixObjectKeys(payload, "callback.payload.") addAttributesToCurrentSpan({ ...prefixedPayload, - ["callback.AccountId"]: accountId, + ["callback.accountId"]: accountId, ["callback.eventType"]: eventType, }) baseLogger.info({ res }, `message sent successfully to ${accountCallbackId}`) diff --git a/core/api/test/bats/admin-gql/account-details-by-account-id.gql b/core/api/test/bats/admin-gql/account-details-by-account-id.gql index a05d9a34937..f65559d233b 100644 --- a/core/api/test/bats/admin-gql/account-details-by-account-id.gql +++ b/core/api/test/bats/admin-gql/account-details-by-account-id.gql @@ -1,6 +1,5 @@ query accountDetailsByAccountId($accountId: ID!) { accountDetailsByAccountId(accountId: $accountId) { id - uuid } } diff --git a/core/api/test/bats/admin-gql/account-details-by-user-phone.gql b/core/api/test/bats/admin-gql/account-details-by-user-phone.gql index e6a632e1af2..e040c44f646 100644 --- a/core/api/test/bats/admin-gql/account-details-by-user-phone.gql +++ b/core/api/test/bats/admin-gql/account-details-by-user-phone.gql @@ -1,6 +1,5 @@ query accountDetailsByUserPhone($phone: Phone!) { accountDetailsByUserPhone(phone: $phone) { id - uuid } } diff --git a/core/api/test/bats/admin.bats b/core/api/test/bats/admin.bats index 3726f894929..b1856de3cba 100644 --- a/core/api/test/bats/admin.bats +++ b/core/api/test/bats/admin.bats @@ -86,18 +86,15 @@ gql_admin_file() { exec_admin_graphql $admin_token 'account-details-by-user-phone' "$variables" id="$(graphql_output '.data.accountDetailsByUserPhone.id')" [[ "$id" != "null" && "$id" != "" ]] || exit 1 - id="$(graphql_output '.data.accountDetailsByUserPhone.id')" - [[ "$id" != "null" && "$id" != "" ]] || exit 1 - echo "id: $id" echo "id: $id" new_phone="$(random_phone)" variables=$( jq -n \ --arg phone "$new_phone" \ - --arg AccountId "$id" \ - '{input: {phone: $phone, accountId:$AccountId}}' + --arg accountId "$id" \ + '{input: {phone: $phone, accountId:$accountId}}' ) exec_admin_graphql $admin_token 'user-update-phone' "$variables" diff --git a/core/api/test/bats/device-account.bats b/core/api/test/bats/device-account.bats index d3347fb4125..c0eb752b29f 100644 --- a/core/api/test/bats/device-account.bats +++ b/core/api/test/bats/device-account.bats @@ -19,8 +19,8 @@ jwt="eyJhbGciOiJSUzI1NiIsImtpZCI6IjFiOTdiMjIxLWNhMDgtNGViMi05ZDA5LWE1NzcwZmNjZWI @test "device-account: create" { token_name="$DEVICE_NAME" - username="$(random_id)" - password="$(random_id)" + username="$(random_uuid)" + password="$(random_uuid)" if [[ "$(uname)" == "Linux" ]]; then basic_token="$(echo -n $username:$password | base64 -w 0)" diff --git a/core/api/test/bats/helpers/_common.bash b/core/api/test/bats/helpers/_common.bash index 9b9ad7b1718..b7e96892fe1 100644 --- a/core/api/test/bats/helpers/_common.bash +++ b/core/api/test/bats/helpers/_common.bash @@ -111,7 +111,7 @@ gql_file() { } new_idempotency_key() { - random_id + random_uuid } exec_graphql() { @@ -150,11 +150,11 @@ graphql_output() { echo $output | jq -r "$@" } -random_id() { - if [[ -e /proc/sys/kernel/random/id ]]; then - cat /proc/sys/kernel/random/id +random_uuid() { + if [[ -e /proc/sys/kernel/random/uuid ]]; then + cat /proc/sys/kernel/random/uuid else - idgen + uuidgen fi } diff --git a/core/api/test/bats/oathkeeper.bats b/core/api/test/bats/oathkeeper.bats index 84dbf1334b9..54ecfab0d9f 100644 --- a/core/api/test/bats/oathkeeper.bats +++ b/core/api/test/bats/oathkeeper.bats @@ -12,11 +12,11 @@ teardown_file() { OATHKEEPER_ENDPOINT=${OATHKEEPER_ENDPOINT:-"http://127.0.0.1:4456/decisions/"} -check_is_id() { - id_string=$1 +check_is_uuid() { + uuid_string=$1 - id_regex='^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$' - echo $id_string | grep -Eq "$id_regex" + uuid_regex='^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$' + echo $uuid_string | grep -Eq "$uuid_regex" } decode_jwt() { @@ -116,5 +116,5 @@ oathkeeper_jwt() { cache_value 'alice.oath' $jwt subject=$(decode_jwt "$jwt" 'payload' | jq -r '.sub') - check_is_id "$subject" || exit 1 + check_is_uuid "$subject" || exit 1 } diff --git a/core/api/test/bats/public-ln-receive.bats b/core/api/test/bats/public-ln-receive.bats index b67b1edbf4d..9818d2d72f2 100644 --- a/core/api/test/bats/public-ln-receive.bats +++ b/core/api/test/bats/public-ln-receive.bats @@ -275,7 +275,7 @@ usd_amount=50 } @test "public-ln-receive: fail to create invoice - nonexistent wallet-id" { - non_existent_wallet_id="$(random_id)" + non_existent_wallet_id="$(random_uuid)" variables=$( jq -n \