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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [6.50.0] - 2025-09-02
### Fixed
- Add new scope argument into auth directive

## [6.49.7] - 2025-08-13
### Fixed
- Version of Axios that is incompatible with Asset Builder
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": "@vtex/api",
"version": "6.49.7",
"version": "6.50.0",
"description": "VTEX I/O API client",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
18 changes: 16 additions & 2 deletions src/service/worker/runtime/graphql/schema/schemaDirectives/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ServiceContext } from '../../../typings'
interface AuthDirectiveArgs {
readonly productCode: string
readonly resourceCode: string
readonly scope: 'PRIVATE' | 'PUBLIC'
}

interface VtexIdParsedToken {
Expand Down Expand Up @@ -68,8 +69,12 @@ async function auth (ctx: ServiceContext, authArgs: AuthDirectiveArgs): Promise<
}

function parseArgs (authArgs: AuthDirectiveArgs): AuthDirectiveArgs {
if (authArgs.scope == 'PUBLIC') {
return authArgs
}

if (!authArgs.productCode || !authArgs.resourceCode) {
throw new UserInputError('Invalid auth schema directive args. Usage: @auth(productCode: String, resourceCode: String).')
throw new UserInputError('Invalid auth schema directive args. Usage: @auth(scope: IOAuthScope, productCode: String, resourceCode: String).')
}
return authArgs
}
Expand All @@ -79,14 +84,23 @@ export class Auth extends SchemaDirectiveVisitor {
const {resolve = defaultFieldResolver} = field
field.resolve = async (root, args, ctx, info) => {
const authArgs = parseArgs(this.args as AuthDirectiveArgs)
await auth(ctx, authArgs)
if (!authArgs.scope || authArgs.scope == 'PRIVATE') {
await auth(ctx, authArgs)
}
return resolve(root, args, ctx, info)
}
}
}

export const authDirectiveTypeDefs = `

enum IOAuthScope {
PUBLIC
PRIVATE
}

directive @auth(
scope: IOAuthScope
productCode: String
resourceCode: String
) on FIELD_DEFINITION
Expand Down
Loading