@vtex/api 6.50.0-beta.2 → 7.0.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 = "\
|
|
6
|
+
export declare const authDirectiveTypeDefs = "\ndirective @auth(\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
|
|
@@ -8,11 +8,6 @@ const apollo_server_errors_1 = require("apollo-server-errors");
|
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const graphql_1 = require("graphql");
|
|
10
10
|
const graphql_tools_1 = require("graphql-tools");
|
|
11
|
-
var Scope;
|
|
12
|
-
(function (Scope) {
|
|
13
|
-
Scope["PUBLIC"] = "PUBLIC";
|
|
14
|
-
Scope["PRIVATE"] = "PRIVATE";
|
|
15
|
-
})(Scope || (Scope = {}));
|
|
16
11
|
async function parseIdToken(authToken, vtexIdToken) {
|
|
17
12
|
const url = `vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=${vtexIdToken}`;
|
|
18
13
|
const req = await axios_1.default.request({
|
|
@@ -56,7 +51,7 @@ async function auth(ctx, authArgs) {
|
|
|
56
51
|
}
|
|
57
52
|
function parseArgs(authArgs) {
|
|
58
53
|
if (!authArgs.productCode || !authArgs.resourceCode) {
|
|
59
|
-
throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(
|
|
54
|
+
throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(productCode: String, resourceCode: String).');
|
|
60
55
|
}
|
|
61
56
|
return authArgs;
|
|
62
57
|
}
|
|
@@ -65,22 +60,14 @@ class Auth extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
|
65
60
|
const { resolve = graphql_1.defaultFieldResolver } = field;
|
|
66
61
|
field.resolve = async (root, args, ctx, info) => {
|
|
67
62
|
const authArgs = parseArgs(this.args);
|
|
68
|
-
|
|
69
|
-
await auth(ctx, authArgs);
|
|
70
|
-
}
|
|
63
|
+
await auth(ctx, authArgs);
|
|
71
64
|
return resolve(root, args, ctx, info);
|
|
72
65
|
};
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
68
|
exports.Auth = Auth;
|
|
76
69
|
exports.authDirectiveTypeDefs = `
|
|
77
|
-
enum Scope {
|
|
78
|
-
PUBLIC
|
|
79
|
-
PRIVATE
|
|
80
|
-
}
|
|
81
|
-
|
|
82
70
|
directive @auth(
|
|
83
|
-
scope: Scope
|
|
84
71
|
productCode: String
|
|
85
72
|
resourceCode: String
|
|
86
73
|
) on FIELD_DEFINITION
|