Skip to content

Commit

Permalink
feat: adding scope middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Sep 11, 2023
1 parent 6c07fcd commit 46cfb96
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 140 deletions.
18 changes: 3 additions & 15 deletions dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,6 @@ input OnChainPaymentSendAllInput
address: OnChainAddress!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

Expand All @@ -989,15 +988,13 @@ input OnChainPaymentSendInput
amount: SatAmount!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

type OnChainTxFee
@join__type(graph: PUBLIC)
{
amount: SatAmount!
targetConfirmations: TargetConfirmations! @deprecated(reason: "Ignored - will be removed")
}

scalar OnChainTxHash
Expand All @@ -1021,7 +1018,6 @@ input OnChainUsdPaymentSendAsBtcDenominatedInput
amount: SatAmount!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

Expand All @@ -1032,15 +1028,13 @@ input OnChainUsdPaymentSendInput
amount: CentAmount!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

type OnChainUsdTxFee
@join__type(graph: PUBLIC)
{
amount: CentAmount!
targetConfirmations: TargetConfirmations! @deprecated(reason: "Ignored - will be removed")
}

type OneDayAccountLimit implements AccountLimit
Expand Down Expand Up @@ -1232,9 +1226,9 @@ type Query
lnInvoicePaymentStatus(input: LnInvoicePaymentStatusInput!): LnInvoicePaymentStatusPayload!
me: User
mobileVersions: [MobileVersions]
onChainTxFee(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced"), walletId: WalletId!): OnChainTxFee!
onChainUsdTxFee(address: OnChainAddress!, amount: CentAmount!, speed: PayoutSpeed = FAST, targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced"), walletId: WalletId!): OnChainUsdTxFee!
onChainUsdTxFeeAsBtcDenominated(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced"), walletId: WalletId!): OnChainUsdTxFee!
onChainTxFee(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainTxFee!
onChainUsdTxFee(address: OnChainAddress!, amount: CentAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee!
onChainUsdTxFeeAsBtcDenominated(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee!
quizQuestions: [QuizQuestion] @deprecated(reason: "TODO: remove. we don't need a non authenticated version of this query. the users can only do the query while authenticated")

"""Returns 1 Sat and 1 Usd Cent price for the given currency"""
Expand Down Expand Up @@ -1380,12 +1374,6 @@ type SuccessPayload
success: Boolean
}

"""
(Positive) Number of blocks in which the transaction is expected to be confirmed
"""
scalar TargetConfirmations
@join__type(graph: PUBLIC)

"""
Timestamp field, serialized as Unix time (the number of seconds since the Unix epoch)
"""
Expand Down
5 changes: 5 additions & 0 deletions src/domain/authorization/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const ScopesOauth2 = {
TransactionsRead: "transactions:read",
Offline: "offline",
PaymentsSend: "payments:send",
} as const
2 changes: 2 additions & 0 deletions src/domain/authorization/index.types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type ScopesOauth2 =
(typeof import("./index").ScopesOauth2)[keyof typeof import("./index").ScopesOauth2]
6 changes: 3 additions & 3 deletions src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type GTType = {
Boolean: GraphQLScalarType
Float: GraphQLScalarType

Interface<TSource = any, TContext = GraphQLPublicContext>(
Interface<TSource = any, TContext = any>(
config: Readonly<GraphQLInterfaceTypeConfig<TSource, TContext>>,
): GraphQLInterfaceType
Union<TSource = any, TContext = GraphQLPublicContext>(
Union<TSource = any, TContext = any>(
config: Readonly<GraphQLUnionTypeConfig<TSource, TContext>>,
): GraphQLUnionType

Expand All @@ -47,7 +47,7 @@ type GTType = {
): GraphQLScalarType<TInternal, TExternal>
Enum(config: Readonly<GraphQLEnumTypeConfig>): GraphQLEnumType

Object<TSource = any, TContext = GraphQLPublicContext>(
Object<TSource = any, TContext = any>(
arg: GraphQLObjectTypeConfig<TSource, TContext>,
): GraphQLObjectType<TSource, TContext>
Input(arg: Readonly<GraphQLInputObjectTypeConfig>): GraphQLInputObjectType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const IntraLedgerPaymentSendMutation = GT.Field<null, GraphQLPublicContextAuth>(
args: {
input: { type: GT.NonNull(IntraLedgerPaymentSendInput) },
},
resolve: async (_, args, { domainAccount }: GraphQLPublicContextAuth) => {
resolve: async (_, args, { domainAccount }) => {
const { walletId, recipientWalletId, amount, memo } = args.input
for (const input of [walletId, recipientWalletId, amount, memo]) {
if (input instanceof Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const IntraLedgerUsdPaymentSendInput = GT.Input({
}),
})

const IntraLedgerUsdPaymentSendMutation = GT.Field({
const IntraLedgerUsdPaymentSendMutation = GT.Field<null, GraphQLPublicContextAuth>({
extensions: {
complexity: 120,
},
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/public/root/mutation/ln-invoice-fee-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const LnInvoiceFeeProbeInput = GT.Input({

const LnInvoiceFeeProbeMutation = GT.Field<
null,
GraphQLPublicContext,
GraphQLPublicContextAuth,
{
input: {
walletId: WalletId | InputValidationError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const LnUsdInvoiceFeeProbeInput = GT.Input({

const LnUsdInvoiceFeeProbeMutation = GT.Field<
null,
GraphQLPublicContext,
GraphQLPublicContextAuth,
{
input: {
walletId: WalletId | InputValidationError
Expand Down
6 changes: 0 additions & 6 deletions src/graphql/public/root/mutation/onchain-payment-send-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { mapAndParseErrorForGqlResponse } from "@graphql/error-map"
import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address"
import PaymentSendPayload from "@graphql/public/types/payload/payment-send"
import PayoutSpeed from "@graphql/public/types/scalar/payout-speed"
import TargetConfirmations from "@graphql/public/types/scalar/target-confirmations"
import WalletId from "@graphql/shared/types/scalar/wallet-id"

import { Wallets } from "@app"
Expand All @@ -21,11 +20,6 @@ const OnChainPaymentSendAllInput = GT.Input({
defaultValue: DomainPayoutSpeed.Fast,
},
memo: { type: Memo },
targetConfirmations: {
deprecationReason: "Ignored - will be replaced",
type: TargetConfirmations,
defaultValue: 0,
},
}),
})

Expand Down
6 changes: 0 additions & 6 deletions src/graphql/public/root/mutation/onchain-payment-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address"
import PaymentSendPayload from "@graphql/public/types/payload/payment-send"
import PayoutSpeed from "@graphql/public/types/scalar/payout-speed"
import SatAmount from "@graphql/shared/types/scalar/sat-amount"
import TargetConfirmations from "@graphql/public/types/scalar/target-confirmations"
import WalletId from "@graphql/shared/types/scalar/wallet-id"

import { Wallets } from "@app"
Expand All @@ -23,11 +22,6 @@ const OnChainPaymentSendInput = GT.Input({
defaultValue: DomainPayoutSpeed.Fast,
},
memo: { type: Memo },
targetConfirmations: {
deprecationReason: "Ignored - will be replaced",
type: TargetConfirmations,
defaultValue: 0,
},
}),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address"
import PaymentSendPayload from "@graphql/public/types/payload/payment-send"
import PayoutSpeed from "@graphql/public/types/scalar/payout-speed"
import SatsAmount from "@graphql/shared/types/scalar/sat-amount"
import TargetConfirmations from "@graphql/public/types/scalar/target-confirmations"
import WalletId from "@graphql/shared/types/scalar/wallet-id"

import { Wallets } from "@app"
Expand All @@ -23,11 +22,6 @@ const OnChainUsdPaymentSendAsBtcDenominatedInput = GT.Input({
defaultValue: DomainPayoutSpeed.Fast,
},
memo: { type: Memo },
targetConfirmations: {
deprecationReason: "Ignored - will be replaced",
type: TargetConfirmations,
defaultValue: 0,
},
}),
})

Expand Down
6 changes: 0 additions & 6 deletions src/graphql/public/root/mutation/onchain-usd-payment-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import CentAmount from "@graphql/public/types/scalar/cent-amount"
import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address"
import PaymentSendPayload from "@graphql/public/types/payload/payment-send"
import PayoutSpeed from "@graphql/public/types/scalar/payout-speed"
import TargetConfirmations from "@graphql/public/types/scalar/target-confirmations"
import WalletId from "@graphql/shared/types/scalar/wallet-id"

import { Wallets } from "@app"
Expand All @@ -23,11 +22,6 @@ const OnChainUsdPaymentSendInput = GT.Input({
defaultValue: DomainPayoutSpeed.Fast,
},
memo: { type: Memo },
targetConfirmations: {
deprecationReason: "Ignored - will be replaced",
type: TargetConfirmations,
defaultValue: 0,
},
}),
})

Expand Down
2 changes: 1 addition & 1 deletion src/graphql/public/root/mutation/user-logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const UserLogoutInput = GT.Input({

const UserLogoutMutation = GT.Field<
null,
GraphQLPublicContext | GraphQLAdminContext,
GraphQLPublicContext,
{
input: {
authToken: AuthToken | InputValidationError
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/public/root/query/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GT } from "@graphql/index"

import GraphQLUser from "@graphql/public/types/object/user"

const MeQuery = GT.Field<null, GraphQLPublicContext>({
const MeQuery = GT.Field<null, GraphQLPublicContextAuth>({
type: GraphQLUser,
resolve: async (_, __, { user }) => user,
})
Expand Down
7 changes: 0 additions & 7 deletions src/graphql/public/root/query/on-chain-tx-fee-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { mapError } from "@graphql/error-map"
import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address"
import PayoutSpeed from "@graphql/public/types/scalar/payout-speed"
import SatAmount from "@graphql/shared/types/scalar/sat-amount"
import TargetConfirmations from "@graphql/public/types/scalar/target-confirmations"
import WalletId from "@graphql/shared/types/scalar/wallet-id"

import OnChainTxFee from "@graphql/public/types/object/onchain-tx-fee"
Expand All @@ -25,11 +24,6 @@ const OnChainTxFeeQuery = GT.Field<null, GraphQLPublicContextAuth>({
type: PayoutSpeed,
defaultValue: DomainPayoutSpeed.Fast,
},
targetConfirmations: {
deprecationReason: "Ignored - will be replaced",
type: TargetConfirmations,
defaultValue: 0,
},
},
resolve: async (_, args, { domainAccount }) => {
const { walletId, address, amount, speed } = args
Expand All @@ -49,7 +43,6 @@ const OnChainTxFeeQuery = GT.Field<null, GraphQLPublicContextAuth>({

return {
amount: normalizePaymentAmount(fee).amount,
targetConfirmations: 0,
}
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { mapError } from "@graphql/error-map"
import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address"
import PayoutSpeed from "@graphql/public/types/scalar/payout-speed"
import SatAmount from "@graphql/shared/types/scalar/sat-amount"
import TargetConfirmations from "@graphql/public/types/scalar/target-confirmations"
import WalletId from "@graphql/shared/types/scalar/wallet-id"

import OnChainUsdTxFee from "@graphql/public/types/object/onchain-usd-tx-fee"
Expand All @@ -25,11 +24,6 @@ const OnChainUsdTxFeeAsBtcDenominatedQuery = GT.Field<null, GraphQLPublicContext
type: PayoutSpeed,
defaultValue: DomainPayoutSpeed.Fast,
},
targetConfirmations: {
deprecationReason: "Ignored - will be replaced",
type: TargetConfirmations,
defaultValue: 0,
},
},
resolve: async (_, args, { domainAccount }) => {
const { walletId, address, amount, speed } = args
Expand Down
8 changes: 1 addition & 7 deletions src/graphql/public/root/query/on-chain-usd-tx-fee-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import { mapError } from "@graphql/error-map"
import CentAmount from "@graphql/public/types/scalar/cent-amount"
import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address"
import PayoutSpeed from "@graphql/public/types/scalar/payout-speed"
import TargetConfirmations from "@graphql/public/types/scalar/target-confirmations"
import WalletId from "@graphql/shared/types/scalar/wallet-id"

import OnChainUsdTxFee from "@graphql/public/types/object/onchain-usd-tx-fee"

import { normalizePaymentAmount } from "../../../shared/root/mutation"

const OnChainUsdTxFeeQuery = GT.Field<null, GraphQLPublicContext>({
const OnChainUsdTxFeeQuery = GT.Field<null, GraphQLPublicContextAuth>({
type: GT.NonNull(OnChainUsdTxFee),
args: {
walletId: { type: GT.NonNull(WalletId) },
Expand All @@ -25,11 +24,6 @@ const OnChainUsdTxFeeQuery = GT.Field<null, GraphQLPublicContext>({
type: PayoutSpeed,
defaultValue: DomainPayoutSpeed.Fast,
},
targetConfirmations: {
deprecationReason: "Ignored - will be replaced",
type: TargetConfirmations,
defaultValue: 0,
},
},
resolve: async (_, args, { domainAccount }) => {
const { walletId, address, amount, speed } = args
Expand Down
17 changes: 3 additions & 14 deletions src/graphql/public/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@ input OnChainPaymentSendAllInput {
address: OnChainAddress!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

Expand All @@ -778,13 +777,11 @@ input OnChainPaymentSendInput {
amount: SatAmount!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

type OnChainTxFee {
amount: SatAmount!
targetConfirmations: TargetConfirmations! @deprecated(reason: "Ignored - will be removed")
}

scalar OnChainTxHash
Expand All @@ -803,7 +800,6 @@ input OnChainUsdPaymentSendAsBtcDenominatedInput {
amount: SatAmount!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

Expand All @@ -812,13 +808,11 @@ input OnChainUsdPaymentSendInput {
amount: CentAmount!
memo: Memo
speed: PayoutSpeed = FAST
targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced")
walletId: WalletId!
}

type OnChainUsdTxFee {
amount: CentAmount!
targetConfirmations: TargetConfirmations! @deprecated(reason: "Ignored - will be removed")
}

type OneDayAccountLimit implements AccountLimit {
Expand Down Expand Up @@ -969,9 +963,9 @@ type Query {
lnInvoicePaymentStatus(input: LnInvoicePaymentStatusInput!): LnInvoicePaymentStatusPayload!
me: User
mobileVersions: [MobileVersions]
onChainTxFee(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced"), walletId: WalletId!): OnChainTxFee!
onChainUsdTxFee(address: OnChainAddress!, amount: CentAmount!, speed: PayoutSpeed = FAST, targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced"), walletId: WalletId!): OnChainUsdTxFee!
onChainUsdTxFeeAsBtcDenominated(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, targetConfirmations: TargetConfirmations = 0 @deprecated(reason: "Ignored - will be replaced"), walletId: WalletId!): OnChainUsdTxFee!
onChainTxFee(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainTxFee!
onChainUsdTxFee(address: OnChainAddress!, amount: CentAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee!
onChainUsdTxFeeAsBtcDenominated(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee!
quizQuestions: [QuizQuestion] @deprecated(reason: "TODO: remove. we don't need a non authenticated version of this query. the users can only do the query while authenticated")

"""Returns 1 Sat and 1 Usd Cent price for the given currency"""
Expand Down Expand Up @@ -1081,11 +1075,6 @@ type SuccessPayload {
success: Boolean
}

"""
(Positive) Number of blocks in which the transaction is expected to be confirmed
"""
scalar TargetConfirmations

"""
Timestamp field, serialized as Unix time (the number of seconds since the Unix epoch)
"""
Expand Down
Loading

0 comments on commit 46cfb96

Please sign in to comment.