Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
27 changes: 19 additions & 8 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ jobs:
# If pull request was merged then we should check for a package version update
check-version-update:
runs-on: ubuntu-22.04
outputs:
should-bump: ${{ steps.version-check.outputs.should-bump }}
steps:
# Checkout to target branch
- uses: actions/checkout@v2
- uses: actions/checkout@v5
with:
fetch-depth: 0

Expand All @@ -26,20 +28,29 @@ jobs:
id: packageOld
uses: codex-team/action-nodejs-package-info@v1

# Stop workflow and do not bump version if it was changed already
- name: Stop workflow and do not bump version if it was changed already
uses: andymckay/cancel-action@0.2
if: steps.packageOld.outputs.version != steps.packageNew.outputs.version
# Check if version should be bumped
- name: Check if version should be bumped
id: version-check
run: |
if [ "${{ steps.packageOld.outputs.version }}" == "${{ steps.packageNew.outputs.version }}" ]; then
echo "should-bump=true" >> $GITHUB_OUTPUT
else
echo "should-bump=false" >> $GITHUB_OUTPUT
fi

bump-version:
needs: check-version-update
if: needs.check-version-update.outputs.should-bump == 'true'
runs-on: ubuntu-22.04
steps:
# Checkout to target branch
- uses: actions/checkout@v2
- uses: actions/checkout@v5
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

# Setup node environment
- uses: actions/setup-node@v3
- uses: actions/setup-node@v5
with:
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org/
Expand All @@ -54,7 +65,7 @@ jobs:
uses: codex-team/action-nodejs-package-info@v1

# Commit version upgrade
- uses: EndBug/add-and-commit@v7
- uses: EndBug/add-and-commit@v9
with:
author_name: github-actions
author_email: 41898282+github-actions[bot]@users.noreply.github.com
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.34",
"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 @@ function checkUser(context: ResolverContextBase): void {
}
}

export default function requireAuthDirective(directiveName = 'requireAuth') {
export default function allowAnonDirective(directiveName = 'allowAnon') {
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) =>
mapSchema(schema, {
[MapperKind.OBJECT_FIELD]: (fieldConfig, fieldName) => {
const requireAuthDirective = getDirective(schema, fieldConfig, directiveName)?.[0];
const allowAnonDirective = getDirective(schema, fieldConfig, directiveName)?.[0];

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!
}
`;
14 changes: 7 additions & 7 deletions src/typeDefs/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Release {
"""
Release commits
"""
commits: [Commit!]!
commits: [Commit!]
}

"""
Expand Down 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!
}
`;
Loading
Loading