Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and push docker image
on:
push:
branches:
- '*'
- '**'
tags:
- 'v*'

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.1.36",
"version": "1.1.38",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand Down
35 changes: 24 additions & 11 deletions src/directives/requireAuth.ts → src/directives/allowAnon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,50 @@
}
}

export default function requireAuthDirective(directiveName = 'requireAuth') {
export default function allowAnonDirective(directiveName = 'allowAnon') {

Check warning on line 23 in src/directives/allowAnon.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc comment

Check warning on line 23 in src/directives/allowAnon.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing return type on function
return {
requireAuthDirectiveTypeDefs: `
allowAnonDirectiveTypeDefs: `
"""
Access to the field only to authorized users
Allow access to the field to anonymous users
"""
directive @${directiveName} on FIELD_DEFINITION
`,
requireAuthDirectiveTransformer: (schema: GraphQLSchema) =>
allowAnonDirectiveTransformer: (schema: GraphQLSchema) =>

Check warning on line 31 in src/directives/allowAnon.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing return type on function
mapSchema(schema, {
[MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName) => {
const requireAuthDirective = getDirective(schema, fieldConfig, directiveName)?.[0];
const allowAnonDirective = getDirective(schema, fieldConfig, directiveName)?.[0];

Check warning on line 34 in src/directives/allowAnon.ts

View workflow job for this annotation

GitHub Actions / ESlint

'allowAnonDirective' is already declared in the upper scope

if (requireAuthDirective) {
if (allowAnonDirective) {
/** Append flag isAnonAllowed to request context */
const {
resolve = defaultFieldResolver,
} = fieldConfig;

/**
* New field resolver
* @param resolverArgs - default GraphQL resolver args
*/
fieldConfig.resolve = async function (...resolverArgs): UnknownGraphQLResolverResult {
const [, , context] = resolverArgs;

checkUser(context);
context.isAnonAllowed = true;

return resolve.apply(this, resolverArgs);
};

return fieldConfig;
}

const {
resolve = defaultFieldResolver,
} = fieldConfig;

fieldConfig.resolve = async function (...resolverArgs): UnknownGraphQLResolverResult {
const [, , context] = resolverArgs;

if (!context.isAnonAllowed) {
checkUser(context);
}

return resolve.apply(this, resolverArgs);
};

return fieldConfig;
},
}),
Expand Down
8 changes: 4 additions & 4 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { mergeTypeDefs } from '@graphql-tools/merge';
import defaultValueDirective from './directives/defaultValue';
import validateDirective from './directives/validate';
import uploadImageDirective from './directives/uploadImageDirective';
import requireAuthDirective from './directives/requireAuth';
import allowAnonDirective from './directives/allowAnon';
import requireAdminDirective from './directives/requireAdmin';
import requireUserInWorkspaceDirective from './directives/requireUserInWorkspace';

const { renameFromDirectiveTypeDefs, renameFromDirectiveTransformer } = renameFromDirective();
const { defaultValueDirectiveTypeDefs, defaultValueDirectiveTransformer } = defaultValueDirective();
const { validateDirectiveTypeDefs, validateDirectiveTransformer } = validateDirective();
const { uploadImageDirectiveTypeDefs, uploadImageDirectiveTransformer } = uploadImageDirective();
const { requireAuthDirectiveTypeDefs, requireAuthDirectiveTransformer } = requireAuthDirective();
const { allowAnonDirectiveTypeDefs, allowAnonDirectiveTransformer } = allowAnonDirective();
const { requireAdminDirectiveTypeDefs, requireAdminDirectiveTransformer } = requireAdminDirective();
const { requireUserInWorkspaceDirectiveTypeDefs, requireUserInWorkspaceDirectiveTransformer } = requireUserInWorkspaceDirective();

Expand All @@ -24,7 +24,7 @@ let schema = makeExecutableSchema({
defaultValueDirectiveTypeDefs,
validateDirectiveTypeDefs,
uploadImageDirectiveTypeDefs,
requireAuthDirectiveTypeDefs,
allowAnonDirectiveTypeDefs,
requireAdminDirectiveTypeDefs,
requireUserInWorkspaceDirectiveTypeDefs,
...typeDefs,
Expand All @@ -36,8 +36,8 @@ schema = renameFromDirectiveTransformer(schema);
schema = defaultValueDirectiveTransformer(schema);
schema = validateDirectiveTransformer(schema);
schema = uploadImageDirectiveTransformer(schema);
schema = requireAuthDirectiveTransformer(schema);
schema = requireAdminDirectiveTransformer(schema);
schema = allowAnonDirectiveTransformer(schema);
schema = requireUserInWorkspaceDirectiveTransformer(schema);

export default schema;
10 changes: 5 additions & 5 deletions src/typeDefs/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ extend type Query {
"""
Get workspace billing history
"""
businessOperations("Workspaces IDs" ids: [ID!] = []): [BusinessOperation!]! @requireAuth @requireAdmin
businessOperations("Workspaces IDs" ids: [ID!] = []): [BusinessOperation!]! @requireAdmin

"""
Prepare payment data before charge (GraphQL version of composePayment)
"""
composePayment(input: ComposePaymentInput!): ComposePaymentResponse! @requireAuth
composePayment(input: ComposePaymentInput!): ComposePaymentResponse!
}

"""
Expand Down Expand Up @@ -324,18 +324,18 @@ extend type Mutation {
"""
Remove card
"""
removeCard(cardNumber: String!): Boolean! @requireAuth
removeCard(cardNumber: String!): Boolean!

"""
Mutation for processing payment with saved card
"""
payWithCard(
input: PayWithCardInput!
): PayWithCardResponse! @requireAuth
): PayWithCardResponse!

"""
Returns JSON data with payment link and initiate card attach procedure
"""
attachCard(language: String): BillingSession! @requireAuth
attachCard(language: String): BillingSession!
}
`;
12 changes: 6 additions & 6 deletions src/typeDefs/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ type Event {
User's local timezone offset in minutes
"""
timezoneOffset: Int! = 0
): [ChartDataItem!]! @requireAuth
): [ChartDataItem!]!
}

"""
Expand Down Expand Up @@ -332,7 +332,7 @@ type Subscription {
"""
Sends new events from all user projects
"""
eventOccurred: Event! @requireAuth
eventOccurred: Event!
}

"""
Expand Down Expand Up @@ -404,14 +404,14 @@ type EventsMutations {
"""
updateAssignee(
input: UpdateAssigneeInput!
): UpdateAssigneeResponse! @requireAuth @requireUserInWorkspace
): UpdateAssigneeResponse! @requireUserInWorkspace

"""
Remove an assignee from the selected event
"""
removeAssignee(
input: RemoveAssigneeInput!
): RemoveAssigneeResponse! @requireAuth @requireUserInWorkspace
): RemoveAssigneeResponse! @requireUserInWorkspace
}

extend type Mutation {
Expand All @@ -428,7 +428,7 @@ extend type Mutation {
ID of the event to visit
"""
eventId: ID!
): Boolean! @requireAuth
): Boolean!

"""
Mutation sets or unsets passed mark to event
Expand All @@ -448,7 +448,7 @@ extend type Mutation {
Mark to set
"""
mark: EventMark!
): Boolean! @requireAuth
): Boolean!

"""
Namespace that contains only mutations related to the events
Expand Down
14 changes: 7 additions & 7 deletions src/typeDefs/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default gql`
"""
Returns authenticated user data
"""
me: User @requireAuth
me: User
}

extend type Mutation {
Expand All @@ -107,7 +107,7 @@ export default gql`
UTM parameters
"""
utm: UtmInput
): ${isE2E ? 'String!' : 'Boolean!'}
): ${isE2E ? 'String!' : 'Boolean!'} @allowAnon

"""
Login user with provided email and password
Expand All @@ -122,7 +122,7 @@ export default gql`
User password
"""
password: String! @validate(notEmpty: true)
): Tokens!
): Tokens! @allowAnon

"""
Update user's tokens pair
Expand All @@ -132,7 +132,7 @@ export default gql`
Refresh token for getting new token pair
"""
refreshToken: String!
): Tokens!
): Tokens! @allowAnon

"""
Reset user's password
Expand All @@ -142,7 +142,7 @@ export default gql`
User email
"""
email: String! @validate(isEmail: true)
): Boolean!
): Boolean! @allowAnon

"""
Update user's profile
Expand All @@ -162,7 +162,7 @@ export default gql`
User image file
"""
image: Upload @uploadImage
): Boolean! @requireAuth
): Boolean!

"""
Change user password
Expand All @@ -177,6 +177,6 @@ export default gql`
New user password
"""
newPassword: String! @validate(notEmpty: true)
): Boolean! @requireAuth
): Boolean!
}
`;
4 changes: 2 additions & 2 deletions src/typeDefs/userNotificationsMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default gql`
Channel data to update
"""
input: NotificationsChannelsInput!
): changeUserNotificationsChannelResponse! @requireAuth
): changeUserNotificationsChannelResponse!

"""
Toggle user notifications receive type active status
Expand All @@ -42,6 +42,6 @@ export default gql`
Receive type with its new is-enabled value
"""
input: ChangeUserNotificationsReceiveTypeInput!
): changeUserNotificationsReceiveTypeResponse! @requireAuth
): changeUserNotificationsReceiveTypeResponse!
}
`;
14 changes: 7 additions & 7 deletions src/typeDefs/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ export default gql`
Project(s) id(s)
"""
ids: [ID!] = []
): [Project!] @requireAuth
): [Project!]
}

extend type Query {
"""
Returns workspace(s) info
If ids = [] returns all user's workspaces
"""
workspaces("Workspace(s) id(s)" ids: [ID] = []): [Workspace] @requireAuth
workspaces("Workspace(s) id(s)" ids: [ID] = []): [Workspace]
}

extend type Mutation {
Expand All @@ -160,7 +160,7 @@ export default gql`
New workspace image
"""
image: Upload @uploadImage
): Workspace! @requireAuth
): Workspace!

"""
Invite user to workspace
Expand All @@ -176,7 +176,7 @@ export default gql`
id of the workspace to which the user is invited
"""
workspaceId: ID!
): Boolean! @requireAuth
): Boolean!

"""
Update workspace settings
Expand Down Expand Up @@ -211,7 +211,7 @@ export default gql`
Workspace invite hash from link
"""
inviteHash: String!
): UpdateWorkspaceResponse! @requireAuth
): UpdateWorkspaceResponse!

"""
Confirm invitation to workspace
Expand All @@ -227,7 +227,7 @@ export default gql`
Id of the workspace to which the user was invited
"""
workspaceId: ID!
): UpdateWorkspaceResponse! @requireAuth
): UpdateWorkspaceResponse!

"""
Grant admin permissions
Expand Down Expand Up @@ -280,6 +280,6 @@ export default gql`
Workspace ID
"""
workspaceId: ID!
): Boolean! @requireAuth
): Boolean!
}
`;
Loading