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(backend): tenant support for wallet address (#3114) #3152

Merged
merged 77 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
2f74c4e
feat(backend): tenant service
njlie Nov 27, 2024
61d45f7
fix: integration tests
njlie Nov 27, 2024
d57bcc6
feat: use soft delete
njlie Nov 27, 2024
57a663d
refactor: compare whole object in test
njlie Nov 27, 2024
fb3d702
fix: better gql errors in tests
njlie Dec 2, 2024
e5cc2b5
feat: add idp columns to tenant model
njlie Dec 3, 2024
c824c56
feat: pagination tests, push deletedAt to auth api call
njlie Dec 3, 2024
9211ca3
feat: add cache
njlie Dec 3, 2024
e2bbc79
fix: update localenv environment variables
njlie Dec 3, 2024
fda0653
Merge branch 'refs/heads/nl/3123/backend-tenant-service' into 3114/te…
koekiebox Dec 4, 2024
151c3aa
Merge branch 'refs/heads/main' into 3114/tenanted-wallet-addresses
koekiebox Dec 4, 2024
d6257fe
feat(3114): add tenant to wallet address.
koekiebox Dec 5, 2024
86d9a39
feat(3114): test fixes.
koekiebox Dec 5, 2024
3625938
feat: make some tenants fields optional, small refactors
njlie Dec 6, 2024
6f16eaa
Merge branch 'nl/3123/backend-tenant-service' into 3114/tenanted-wall…
koekiebox Dec 9, 2024
490f748
feat(auth): tenants table v1
njlie Nov 25, 2024
10bc6ab
feat(backend): tenant service
njlie Nov 27, 2024
d5cc314
feat: use soft delete
njlie Nov 27, 2024
fc01ef7
feat: add idp columns to tenant model
njlie Dec 3, 2024
87213de
feat: pagination tests, push deletedAt to auth api call
njlie Dec 3, 2024
0a37b3c
feat: add cache
njlie Dec 3, 2024
3805b10
feat(backend): tenant signature validation for admin api
njlie Dec 6, 2024
92fc1ac
fix: rebase errors
njlie Dec 9, 2024
0ad7ccc
Merge branch '2893/multi-tenancy-v1' into 3114/tenanted-wallet-addresses
koekiebox Dec 10, 2024
645e181
feat(3114): update seed.ts
koekiebox Dec 10, 2024
cdc2bda
fix: remove admin api secret check from app
njlie Dec 10, 2024
c44cd03
fix: always expect tenant id in request
njlie Dec 10, 2024
4e17260
chore: remove some logs
njlie Dec 10, 2024
a9f0fff
Merge branch '2893/multi-tenancy-v1' into 3114/tenanted-wallet-addresses
koekiebox Dec 11, 2024
7d562b5
feat(3114): update for auth and resource server.
koekiebox Dec 11, 2024
b5a1667
feat(3114): fix asset service.test.ts
koekiebox Dec 11, 2024
f29862a
feat(3114): fix tests.
koekiebox Dec 11, 2024
868221c
Merge branch 'nl/2928/multi-tenancy-signatures' into 3114/tenanted-wa…
koekiebox Dec 12, 2024
c650b59
Merge branch '2893/multi-tenancy-v1' into 3114/tenanted-wallet-addresses
koekiebox Jan 6, 2025
5477b5a
feat(3114): merged with latest tenant changes.
koekiebox Jan 6, 2025
47d08f1
feat(3114): extract tenant id from tenant context instead of admin in…
koekiebox Jan 7, 2025
ab17c20
feat(3114): test case updates, obtain tenant from header.
koekiebox Jan 7, 2025
aef9471
feat(3114): fix test cases for wallet address.
koekiebox Jan 7, 2025
6510bed
feat(3114): address review comments.
koekiebox Jan 8, 2025
2558836
feat(3114): rework tenantId to not be mandatory for wallet address se…
koekiebox Jan 11, 2025
86f86e6
feat(3114): rework tenantId to not be mandatory for wallet address se…
koekiebox Jan 11, 2025
78bd769
feat(3114): rework tenantId to not be mandatory for wallet address se…
koekiebox Jan 11, 2025
6defb40
feat(3114): fix tenant service test case.
koekiebox Jan 13, 2025
cede83c
feat(3114): fix tenant service test case.
koekiebox Jan 13, 2025
c2caf65
feat(3114): fix tenant service test case.
koekiebox Jan 14, 2025
ecb6639
Merge branch '2893/multi-tenancy-v1' into 3114/tenanted-wallet-addresses
koekiebox Jan 15, 2025
8dfa1fb
feat(3114): fix tenant service test case.
koekiebox Jan 15, 2025
562d7e3
feat(3114): fix tenant service test case.
koekiebox Jan 15, 2025
c1254f4
feat(3114): force 'forTenantId'.
koekiebox Jan 15, 2025
e4dfa65
Merge branch '2893/multi-tenancy-v1' into 3114/tenanted-wallet-addresses
koekiebox Jan 16, 2025
d4d4899
feat(3114): force 'forTenantId'.
koekiebox Jan 17, 2025
60672ba
feat(3114): force 'forTenantId'.
koekiebox Jan 17, 2025
094271f
feat(3114): enhancements for 'forTenantId'.
koekiebox Jan 17, 2025
6707b04
feat(3114): test case fixes.
koekiebox Jan 17, 2025
f824b26
feat(3114): internal server error
koekiebox Jan 17, 2025
f041d80
Merge branch '2893/multi-tenancy-v1' into 3114/tenanted-wallet-addresses
koekiebox Jan 17, 2025
a3af5ea
feat(3114): test case.
koekiebox Jan 20, 2025
c799815
feat(3114): test case.
koekiebox Jan 20, 2025
aaf06b6
feat(3114): review feedback.
koekiebox Jan 20, 2025
87f9ae6
feat(3114): review feedback.
koekiebox Jan 20, 2025
b028de7
feat(3114): remove tenant on quote.
koekiebox Jan 20, 2025
27c4352
feat(3114): default operator tenant.
koekiebox Jan 20, 2025
a3fda78
feat(3114): review feedback.
koekiebox Jan 20, 2025
5e2d5ed
feat(3114): review feedback from Max.
koekiebox Jan 21, 2025
eb87954
feat(3114): review feedback from Max.
koekiebox Jan 21, 2025
951a4c7
feat(3114): fixed.
koekiebox Jan 21, 2025
4c60f7b
feat(3114): review feedback.
koekiebox Jan 22, 2025
3278c87
feat(3114): review feedback.
koekiebox Jan 22, 2025
4d13e0f
feat(3114): review feedback. do not force error on graphql middleware.
koekiebox Jan 22, 2025
b29636a
feat(3114): fix the integration test.
koekiebox Jan 23, 2025
e16cb65
feat(3114): further review comments.
koekiebox Jan 23, 2025
e6b44d7
feat(3114): further review comments.
koekiebox Jan 24, 2025
961c249
feat(3114): final round with Max.
koekiebox Jan 24, 2025
fa19198
feat(3114): revert.
koekiebox Jan 24, 2025
ae157bd
feat(3114): remove unused.
koekiebox Jan 24, 2025
e8bc63c
feat(3114): set the correct operator id.
koekiebox Jan 26, 2025
b1abe92
Merge branch '2893/multi-tenancy-v1' into 3114/tenanted-wallet-addresses
koekiebox Jan 26, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export const CONFIG: Config = {
testnetAutoPeerUrl: process.env.TESTNET_AUTOPEER_URL ?? '',
authServerDomain: process.env.AUTH_SERVER_DOMAIN || 'http://localhost:3006',
graphqlUrl: process.env.GRAPHQL_URL,
idpSecret: process.env.IDP_SECRET
idpSecret: process.env.IDP_SECRET,
operatorTenantId:
process.env.OPERATOR_TENANT_ID || '438fa74a-fa7d-4317-9ced-dde32ece1787'
koekiebox marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
koekiebox marked this conversation as resolved.
Show resolved Hide resolved
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return Promise.all([
knex.schema.alterTable('walletAddresses', function (table) {
table.uuid('tenantId').index().notNullable()
//table.foreign(['tenantId']).references('tenants.id')
})
])
koekiebox marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return Promise.all([
knex.schema.alterTable('walletAddresses', function (table) {
table.dropIndex('tenantId')
table.dropColumn('tenantId')
})
])
}
17 changes: 16 additions & 1 deletion packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import {
getTenantFromApiSignature,
TenantApiSignatureResult
} from './shared/utils'
import { faker } from '@faker-js/faker'
export interface AppContextData {
logger: Logger
container: AppContainer
Expand Down Expand Up @@ -393,7 +394,21 @@ export class App {
)

let tenantApiSignatureResult: TenantApiSignatureResult
if (this.config.env !== 'test') {
if (this.config.env === 'test') {
const tenantService = await this.container.use('tenantService')
koekiebox marked this conversation as resolved.
Show resolved Hide resolved
let tenant = await tenantService.get(this.config.operatorTenantId)
if (!tenant) {
tenant = await Tenant.query().insertAndFetch({
koekiebox marked this conversation as resolved.
Show resolved Hide resolved
id: this.config.operatorTenantId,
email: faker.internet.email(),
publicName: faker.company.name(),
apiSecret: 'test-api-secret',
idpConsentUrl: faker.internet.url(),
idpSecret: 'test-idp-secret'
})
}
tenantApiSignatureResult = { tenant, isOperator: true }
} else {
koa.use(async (ctx, next: Koa.Next): Promise<void> => {
const result = await getTenantFromApiSignature(ctx, this.config)
if (!result) {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/asset/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ describe('Asset Service', (): void => {
// make sure there is at least 1 wallet address using asset
const walletAddress = walletAddressService.create({
url: 'https://alice.me/.well-known/pay',
tenantId: Config.operatorTenantId,
assetId: newAssetId
})
assert.ok(!isWalletAddressError(walletAddress))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('Payment', (): void => {

test('Can get payments', async (): Promise<void> => {
const { id: outWalletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})

Expand All @@ -68,6 +69,7 @@ describe('Payment', (): void => {
})

const { id: inWalletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const incomingPayment = await createIncomingPayment(deps, {
Expand Down Expand Up @@ -146,6 +148,7 @@ describe('Payment', (): void => {

test('Can filter payments by type and wallet address', async (): Promise<void> => {
const { id: outWalletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})

Expand All @@ -168,6 +171,7 @@ describe('Payment', (): void => {
})

const { id: outWalletAddressId2 } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
await createOutgoingPayment(deps, {
Expand Down
11 changes: 9 additions & 2 deletions packages/backend/src/graphql/resolvers/incoming_payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ describe('Incoming Payment Resolver', (): void => {

describe('Wallet address incoming payments', (): void => {
beforeEach(async (): Promise<void> => {
walletAddressId = (await createWalletAddress(deps, { assetId: asset.id }))
.id
walletAddressId = (
await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
).id
})

getPageTests({
Expand Down Expand Up @@ -106,6 +110,7 @@ describe('Incoming Payment Resolver', (): void => {
async ({ metadata, expiresAt, withAmount }): Promise<void> => {
const incomingAmount = withAmount ? amount : undefined
const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const payment = await createIncomingPayment(deps, {
Expand Down Expand Up @@ -305,6 +310,7 @@ describe('Incoming Payment Resolver', (): void => {
}
beforeEach(async (): Promise<void> => {
const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
payment = await createPayment({ walletAddressId, metadata })
Expand Down Expand Up @@ -462,6 +468,7 @@ describe('Incoming Payment Resolver', (): void => {
async ({ metadata }): Promise<void> => {
const incomingAmount = amount ? amount : undefined
const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const payment = await createIncomingPayment(deps, {
Expand Down
9 changes: 7 additions & 2 deletions packages/backend/src/graphql/resolvers/liquidity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ describe('Liquidity Resolvers', (): void => {

beforeEach(async (): Promise<void> => {
walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
createLiquidityAccount: true
})

Expand Down Expand Up @@ -1747,7 +1748,9 @@ describe('Liquidity Resolvers', (): void => {
let payment: OutgoingPayment

beforeEach(async (): Promise<void> => {
walletAddress = await createWalletAddress(deps)
walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId
})
const walletAddressId = walletAddress.id
incomingPayment = await createIncomingPayment(deps, {
walletAddressId,
Expand Down Expand Up @@ -2157,7 +2160,9 @@ describe('Liquidity Resolvers', (): void => {
let outgoingPayment: OutgoingPayment

beforeEach(async (): Promise<void> => {
walletAddress = await createWalletAddress(deps)
walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId
})
const walletAddressId = walletAddress.id
incomingPayment = await createIncomingPayment(deps, {
walletAddressId,
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/graphql/resolvers/outgoing_payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('OutgoingPayment Resolvers', (): void => {
beforeEach(async (): Promise<void> => {
walletAddressId = (
await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
).id
Expand Down Expand Up @@ -135,13 +136,16 @@ describe('OutgoingPayment Resolvers', (): void => {

beforeEach(async (): Promise<void> => {
const firstReceiverWalletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const secondWalletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})

const secondReceiverWalletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})

Expand Down Expand Up @@ -326,6 +330,7 @@ describe('OutgoingPayment Resolvers', (): void => {
const grantId = uuid()

const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})

Expand Down Expand Up @@ -365,6 +370,7 @@ describe('OutgoingPayment Resolvers', (): void => {

beforeEach(async (): Promise<void> => {
const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
payment = await createPayment({ walletAddressId, metadata })
Expand Down Expand Up @@ -553,6 +559,7 @@ describe('OutgoingPayment Resolvers', (): void => {

test('success (metadata)', async (): Promise<void> => {
const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const payment = await createPayment({ walletAddressId, metadata })
Expand Down Expand Up @@ -689,6 +696,7 @@ describe('OutgoingPayment Resolvers', (): void => {

test('create', async (): Promise<void> => {
const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const payment = await createPayment({ walletAddressId: walletAddress.id })
Expand Down Expand Up @@ -840,6 +848,7 @@ describe('OutgoingPayment Resolvers', (): void => {
let payment: OutgoingPaymentModel
beforeEach(async () => {
const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})

Expand Down Expand Up @@ -956,6 +965,7 @@ describe('OutgoingPayment Resolvers', (): void => {
beforeEach(async (): Promise<void> => {
walletAddressId = (
await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
).id
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/graphql/resolvers/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('Quote Resolvers', (): void => {
describe('Query.quote', (): void => {
test('success', async (): Promise<void> => {
const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const quote = await createWalletAddressQuote(walletAddressId)
Expand Down Expand Up @@ -189,6 +190,7 @@ describe('Quote Resolvers', (): void => {
`('$type', async ({ withAmount, receiveAmount }): Promise<void> => {
const amount = withAmount ? debitAmount : undefined
const { id: walletAddressId } = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
const input = {
Expand Down Expand Up @@ -300,6 +302,7 @@ describe('Quote Resolvers', (): void => {
beforeEach(async (): Promise<void> => {
walletAddressId = (
await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
assetId: asset.id
})
).id
Expand Down
16 changes: 12 additions & 4 deletions packages/backend/src/graphql/resolvers/walletAddressKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe('Wallet Address Key Resolvers', (): void => {

describe('Create Wallet Address Keys', (): void => {
test('Can create wallet address key', async (): Promise<void> => {
const walletAddress = await createWalletAddress(deps)
const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId
})

const input: CreateWalletAddressKeyInput = {
walletAddressId: walletAddress.id,
Expand Down Expand Up @@ -106,7 +108,9 @@ describe('Wallet Address Key Resolvers', (): void => {
throw new Error('unexpected')
})

const walletAddress = await createWalletAddress(deps)
const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId
})

const input = {
walletAddressId: walletAddress.id,
Expand Down Expand Up @@ -164,7 +168,9 @@ describe('Wallet Address Key Resolvers', (): void => {

describe('Revoke key', (): void => {
test('Can revoke a key', async (): Promise<void> => {
const walletAddress = await createWalletAddress(deps)
const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId
})

const key = await walletAddressKeyService.create({
walletAddressId: walletAddress.id,
Expand Down Expand Up @@ -267,7 +273,9 @@ describe('Wallet Address Key Resolvers', (): void => {
describe('List Wallet Address Keys', (): void => {
let walletAddressId: string
beforeEach(async (): Promise<void> => {
walletAddressId = (await createWalletAddress(deps)).id
walletAddressId = (
await createWalletAddress(deps, { tenantId: Config.operatorTenantId })
).id
})
getPageTests({
getClient: () => appContainer.apolloClient,
Expand Down
18 changes: 14 additions & 4 deletions packages/backend/src/graphql/resolvers/wallet_address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Wallet Address Resolvers', (): void => {
let walletAddressService: WalletAddressService

beforeAll(async (): Promise<void> => {
deps = await initIocContainer({
deps = initIocContainer({
...Config,
localCacheDuration: 0
})
Expand Down Expand Up @@ -312,7 +312,9 @@ describe('Wallet Address Resolvers', (): void => {
let walletAddress: WalletAddressModel

beforeEach(async (): Promise<void> => {
walletAddress = await createWalletAddress(deps)
walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId
})
})

test('Can update a wallet address', async (): Promise<void> => {
Expand Down Expand Up @@ -426,6 +428,7 @@ describe('Wallet Address Resolvers', (): void => {
})
test('New additional properties override previous additional properties', async (): Promise<void> => {
const createOptions = {
tenantId: Config.operatorTenantId,
additionalProperties: [
{
fieldKey: 'existingKey',
Expand Down Expand Up @@ -492,6 +495,7 @@ describe('Wallet Address Resolvers', (): void => {
})
test('Updating with empty additional properties deletes existing', async (): Promise<void> => {
const createOptions = {
tenantId: Config.operatorTenantId,
additionalProperties: [
{
fieldKey: 'existingKey',
Expand Down Expand Up @@ -655,6 +659,7 @@ describe('Wallet Address Resolvers', (): void => {
const additionalProperties = [walletProp01, walletProp02]

const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
publicName,
createLiquidityAccount: true,
additionalProperties
Expand Down Expand Up @@ -729,6 +734,7 @@ describe('Wallet Address Resolvers', (): void => {
'Can get a wallet address by its url (publicName: $publicName)',
async ({ publicName }): Promise<void> => {
const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
publicName,
createLiquidityAccount: true
})
Expand Down Expand Up @@ -818,14 +824,17 @@ describe('Wallet Address Resolvers', (): void => {

getPageTests({
getClient: () => appContainer.apolloClient,
createModel: () => createWalletAddress(deps),
createModel: () =>
createWalletAddress(deps, { tenantId: Config.operatorTenantId }),
pagedQuery: 'walletAddresses'
})

test('Can get page of wallet addresses', async (): Promise<void> => {
const walletAddresses: WalletAddressModel[] = []
for (let i = 0; i < 2; i++) {
walletAddresses.push(await createWalletAddress(deps))
walletAddresses.push(
await createWalletAddress(deps, { tenantId: Config.operatorTenantId })
)
}
walletAddresses.reverse() // Calling the default getPage will result in descending order
const query = await appContainer.apolloClient
Expand Down Expand Up @@ -889,6 +898,7 @@ describe('Wallet Address Resolvers', (): void => {
const withdrawalAmount = BigInt(10)
for (let i = 0; i < 3; i++) {
const walletAddress = await createWalletAddress(deps, {
tenantId: Config.operatorTenantId,
createLiquidityAccount: true
})
if (i) {
Expand Down
Loading
Loading