@vtex/api 7.0.1 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,4 +3,4 @@ import { SchemaDirectiveVisitor } from 'graphql-tools';
3
3
  export declare class Auth extends SchemaDirectiveVisitor {
4
4
  visitFieldDefinition(field: GraphQLField<any, any>): void;
5
5
  }
6
- export declare const authDirectiveTypeDefs = "\ndirective @auth(\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
6
+ export declare const authDirectiveTypeDefs = "\n\nenum IOAuthScope {\n PUBLIC\n PRIVATE\n}\n\ndirective @auth(\n scope: IOAuthScope\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
@@ -50,8 +50,11 @@ async function auth(ctx, authArgs) {
50
50
  }
51
51
  }
52
52
  function parseArgs(authArgs) {
53
+ if (authArgs.scope == 'PUBLIC') {
54
+ return authArgs;
55
+ }
53
56
  if (!authArgs.productCode || !authArgs.resourceCode) {
54
- throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(productCode: String, resourceCode: String).');
57
+ throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(scope: IOAuthScope, productCode: String, resourceCode: String).');
55
58
  }
56
59
  return authArgs;
57
60
  }
@@ -60,14 +63,23 @@ class Auth extends graphql_tools_1.SchemaDirectiveVisitor {
60
63
  const { resolve = graphql_1.defaultFieldResolver } = field;
61
64
  field.resolve = async (root, args, ctx, info) => {
62
65
  const authArgs = parseArgs(this.args);
63
- await auth(ctx, authArgs);
66
+ if (!authArgs.scope || authArgs.scope == 'PRIVATE') {
67
+ await auth(ctx, authArgs);
68
+ }
64
69
  return resolve(root, args, ctx, info);
65
70
  };
66
71
  }
67
72
  }
68
73
  exports.Auth = Auth;
69
74
  exports.authDirectiveTypeDefs = `
75
+
76
+ enum IOAuthScope {
77
+ PUBLIC
78
+ PRIVATE
79
+ }
80
+
70
81
  directive @auth(
82
+ scope: IOAuthScope
71
83
  productCode: String
72
84
  resourceCode: String
73
85
  ) on FIELD_DEFINITION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "7.0.1",
3
+ "version": "7.1.0",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",