@accounts/graphql-api
Advanced tools
Comparing version 0.30.0 to 0.31.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./modules"), exports); | ||
@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./utils"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AccountsPasswordModule = void 0; | ||
var tslib_1 = require("tslib"); | ||
var core_1 = require("@graphql-modules/core"); | ||
var password_1 = require("@accounts/password"); | ||
var server_1 = require("@accounts/server"); | ||
var types_1 = tslib_1.__importDefault(require("./schema/types")); | ||
var query_1 = tslib_1.__importDefault(require("./schema/query")); | ||
var mutation_1 = tslib_1.__importDefault(require("./schema/mutation")); | ||
var query_2 = require("./resolvers/query"); | ||
var mutation_2 = require("./resolvers/mutation"); | ||
var utils_1 = require("../../utils"); | ||
var core_2 = require("../core"); | ||
const tslib_1 = require("tslib"); | ||
const core_1 = require("@graphql-modules/core"); | ||
const password_1 = require("@accounts/password"); | ||
const server_1 = require("@accounts/server"); | ||
const types_1 = tslib_1.__importDefault(require("./schema/types")); | ||
const query_1 = tslib_1.__importDefault(require("./schema/query")); | ||
const mutation_1 = tslib_1.__importDefault(require("./schema/mutation")); | ||
const query_2 = require("./resolvers/query"); | ||
const mutation_2 = require("./resolvers/mutation"); | ||
const utils_1 = require("../../utils"); | ||
const core_2 = require("../core"); | ||
exports.AccountsPasswordModule = new core_1.GraphQLModule({ | ||
name: 'accounts-password', | ||
typeDefs: function (_a) { | ||
var config = _a.config; | ||
return [types_1.default, query_1.default(config), mutation_1.default(config)]; | ||
}, | ||
resolvers: function (_a) { | ||
var _b; | ||
var config = _a.config; | ||
return (_b = {}, | ||
_b[config.rootQueryName || 'Query'] = query_2.Query, | ||
_b[config.rootMutationName || 'Mutation'] = mutation_2.Mutation, | ||
_b); | ||
}, | ||
imports: function (_a) { | ||
var config = _a.config; | ||
return [ | ||
core_2.CoreAccountsModule.forRoot({ | ||
userAsInterface: config.userAsInterface, | ||
}), | ||
]; | ||
}, | ||
providers: function (_a) { | ||
var config = _a.config; | ||
return [ | ||
{ | ||
provide: server_1.AccountsServer, | ||
useValue: config.accountsServer, | ||
}, | ||
{ | ||
provide: password_1.AccountsPassword, | ||
useValue: config.accountsPassword, | ||
}, | ||
]; | ||
}, | ||
typeDefs: ({ config }) => [types_1.default, query_1.default(config), mutation_1.default(config)], | ||
resolvers: ({ config }) => ({ | ||
[config.rootQueryName || 'Query']: query_2.Query, | ||
[config.rootMutationName || 'Mutation']: mutation_2.Mutation, | ||
}), | ||
imports: ({ config }) => [ | ||
core_2.CoreAccountsModule.forRoot({ | ||
userAsInterface: config.userAsInterface, | ||
}), | ||
], | ||
providers: ({ config }) => [ | ||
{ | ||
provide: server_1.AccountsServer, | ||
useValue: config.accountsServer, | ||
}, | ||
{ | ||
provide: password_1.AccountsPassword, | ||
useValue: config.accountsPassword, | ||
}, | ||
], | ||
context: utils_1.context('accounts-password'), | ||
@@ -51,0 +38,0 @@ configRequired: true, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Mutation = void 0; | ||
var tslib_1 = require("tslib"); | ||
var password_1 = require("@accounts/password"); | ||
var server_1 = require("@accounts/server"); | ||
const password_1 = require("@accounts/password"); | ||
const server_1 = require("@accounts/server"); | ||
exports.Mutation = { | ||
addEmail: function (_, _a, _b) { | ||
var newEmail = _a.newEmail; | ||
var user = _b.user, injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var userId; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
userId = user.id; | ||
return [4 /*yield*/, injector.get(password_1.AccountsPassword).addEmail(userId, newEmail)]; | ||
case 1: | ||
_c.sent(); | ||
return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); | ||
addEmail: async (_, { newEmail }, { user, injector }) => { | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
const userId = user.id; | ||
await injector.get(password_1.AccountsPassword).addEmail(userId, newEmail); | ||
return null; | ||
}, | ||
changePassword: function (_, _a, _b) { | ||
var oldPassword = _a.oldPassword, newPassword = _a.newPassword; | ||
var user = _b.user, injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var userId; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
userId = user.id; | ||
return [4 /*yield*/, injector.get(password_1.AccountsPassword).changePassword(userId, oldPassword, newPassword)]; | ||
case 1: | ||
_c.sent(); | ||
return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); | ||
changePassword: async (_, { oldPassword, newPassword }, { user, injector }) => { | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
const userId = user.id; | ||
await injector.get(password_1.AccountsPassword).changePassword(userId, oldPassword, newPassword); | ||
return null; | ||
}, | ||
createUser: function (_, _a, ctx) { | ||
var user = _a.user; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var injector, infos, accountsServer, accountsPassword, userId, error_1, createdUser, loginResult; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
injector = ctx.injector, infos = ctx.infos; | ||
accountsServer = injector.get(server_1.AccountsServer); | ||
accountsPassword = injector.get(password_1.AccountsPassword); | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, accountsPassword.createUser(user)]; | ||
case 2: | ||
userId = _b.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _b.sent(); | ||
// If ambiguousErrorMessages is true we obfuscate the email or username already exist error | ||
// to prevent user enumeration during user creation | ||
if (accountsServer.options.ambiguousErrorMessages && | ||
error_1 instanceof server_1.AccountsJsError && | ||
(error_1.code === password_1.CreateUserErrors.EmailAlreadyExists || | ||
error_1.code === password_1.CreateUserErrors.UsernameAlreadyExists)) { | ||
return [2 /*return*/, {}]; | ||
} | ||
throw error_1; | ||
case 4: | ||
if (!accountsServer.options.enableAutologin) { | ||
return [2 /*return*/, { | ||
userId: accountsServer.options.ambiguousErrorMessages ? null : userId, | ||
}]; | ||
} | ||
return [4 /*yield*/, accountsServer.findUserById(userId)]; | ||
case 5: | ||
createdUser = _b.sent(); | ||
return [4 /*yield*/, accountsServer.loginWithUser(createdUser, infos)]; | ||
case 6: | ||
loginResult = _b.sent(); | ||
return [2 /*return*/, { | ||
userId: userId, | ||
loginResult: loginResult, | ||
}]; | ||
} | ||
}); | ||
}); | ||
createUser: async (_, { user }, ctx) => { | ||
const { injector, infos } = ctx; | ||
const accountsServer = injector.get(server_1.AccountsServer); | ||
const accountsPassword = injector.get(password_1.AccountsPassword); | ||
let userId; | ||
try { | ||
userId = await accountsPassword.createUser(user); | ||
} | ||
catch (error) { | ||
// If ambiguousErrorMessages is true we obfuscate the email or username already exist error | ||
// to prevent user enumeration during user creation | ||
if (accountsServer.options.ambiguousErrorMessages && | ||
error instanceof server_1.AccountsJsError && | ||
(error.code === password_1.CreateUserErrors.EmailAlreadyExists || | ||
error.code === password_1.CreateUserErrors.UsernameAlreadyExists)) { | ||
return {}; | ||
} | ||
throw error; | ||
} | ||
if (!accountsServer.options.enableAutologin) { | ||
return { | ||
userId: accountsServer.options.ambiguousErrorMessages ? null : userId, | ||
}; | ||
} | ||
// When initializing AccountsServer we check that enableAutologin and ambiguousErrorMessages options | ||
// are not enabled at the same time | ||
const createdUser = await accountsServer.findUserById(userId); | ||
// If we are here - user must be created successfully | ||
// Explicitly saying this to Typescript compiler | ||
const loginResult = await accountsServer.loginWithUser(createdUser, infos); | ||
return { | ||
userId, | ||
loginResult, | ||
}; | ||
}, | ||
twoFactorSet: function (_, _a, _b) { | ||
var code = _a.code, secret = _a.secret; | ||
var user = _b.user, injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var userId; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
// Make sure user is logged in | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
userId = user.id; | ||
return [4 /*yield*/, injector.get(password_1.AccountsPassword).twoFactor.set(userId, secret, code)]; | ||
case 1: | ||
_c.sent(); | ||
return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); | ||
twoFactorSet: async (_, { code, secret }, { user, injector }) => { | ||
// Make sure user is logged in | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
const userId = user.id; | ||
await injector.get(password_1.AccountsPassword).twoFactor.set(userId, secret, code); | ||
return null; | ||
}, | ||
twoFactorUnset: function (_, _a, _b) { | ||
var code = _a.code; | ||
var user = _b.user, injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var userId; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
// Make sure user is logged in | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
userId = user.id; | ||
return [4 /*yield*/, injector.get(password_1.AccountsPassword).twoFactor.unset(userId, code)]; | ||
case 1: | ||
_c.sent(); | ||
return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); | ||
twoFactorUnset: async (_, { code }, { user, injector }) => { | ||
// Make sure user is logged in | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
const userId = user.id; | ||
await injector.get(password_1.AccountsPassword).twoFactor.unset(userId, code); | ||
return null; | ||
}, | ||
resetPassword: function (_, _a, _b) { | ||
var token = _a.token, newPassword = _a.newPassword; | ||
var injector = _b.injector, infos = _b.infos; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_c) { | ||
return [2 /*return*/, injector.get(password_1.AccountsPassword).resetPassword(token, newPassword, infos)]; | ||
}); | ||
}); | ||
resetPassword: async (_, { token, newPassword }, { injector, infos }) => { | ||
return injector.get(password_1.AccountsPassword).resetPassword(token, newPassword, infos); | ||
}, | ||
sendResetPasswordEmail: function (_, _a, _b) { | ||
var email = _a.email; | ||
var injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var accountsServer, accountsPassword, error_2; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
accountsServer = injector.get(server_1.AccountsServer); | ||
accountsPassword = injector.get(password_1.AccountsPassword); | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, accountsPassword.sendResetPasswordEmail(email)]; | ||
case 2: | ||
_c.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_2 = _c.sent(); | ||
// If ambiguousErrorMessages is true, | ||
// to prevent user enumeration we fail silently in case there is no user attached to this email | ||
if (accountsServer.options.ambiguousErrorMessages && | ||
error_2 instanceof server_1.AccountsJsError && | ||
error_2.code === password_1.SendResetPasswordEmailErrors.UserNotFound) { | ||
return [2 /*return*/, null]; | ||
} | ||
throw error_2; | ||
case 4: return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); | ||
sendResetPasswordEmail: async (_, { email }, { injector }) => { | ||
const accountsServer = injector.get(server_1.AccountsServer); | ||
const accountsPassword = injector.get(password_1.AccountsPassword); | ||
try { | ||
await accountsPassword.sendResetPasswordEmail(email); | ||
} | ||
catch (error) { | ||
// If ambiguousErrorMessages is true, | ||
// to prevent user enumeration we fail silently in case there is no user attached to this email | ||
if (accountsServer.options.ambiguousErrorMessages && | ||
error instanceof server_1.AccountsJsError && | ||
error.code === password_1.SendResetPasswordEmailErrors.UserNotFound) { | ||
return null; | ||
} | ||
throw error; | ||
} | ||
return null; | ||
}, | ||
verifyEmail: function (_, _a, _b) { | ||
var token = _a.token; | ||
var injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, injector.get(password_1.AccountsPassword).verifyEmail(token)]; | ||
case 1: | ||
_c.sent(); | ||
return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); | ||
verifyEmail: async (_, { token }, { injector }) => { | ||
await injector.get(password_1.AccountsPassword).verifyEmail(token); | ||
return null; | ||
}, | ||
sendVerificationEmail: function (_, _a, _b) { | ||
var email = _a.email; | ||
var injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var accountsServer, accountsPassword, error_3; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
accountsServer = injector.get(server_1.AccountsServer); | ||
accountsPassword = injector.get(password_1.AccountsPassword); | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, accountsPassword.sendVerificationEmail(email)]; | ||
case 2: | ||
_c.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_3 = _c.sent(); | ||
// If ambiguousErrorMessages is true, | ||
// to prevent user enumeration we fail silently in case there is no user attached to this email | ||
if (accountsServer.options.ambiguousErrorMessages && | ||
error_3 instanceof server_1.AccountsJsError && | ||
error_3.code === password_1.SendVerificationEmailErrors.UserNotFound) { | ||
return [2 /*return*/, null]; | ||
} | ||
throw error_3; | ||
case 4: return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); | ||
sendVerificationEmail: async (_, { email }, { injector }) => { | ||
const accountsServer = injector.get(server_1.AccountsServer); | ||
const accountsPassword = injector.get(password_1.AccountsPassword); | ||
try { | ||
await accountsPassword.sendVerificationEmail(email); | ||
} | ||
catch (error) { | ||
// If ambiguousErrorMessages is true, | ||
// to prevent user enumeration we fail silently in case there is no user attached to this email | ||
if (accountsServer.options.ambiguousErrorMessages && | ||
error instanceof server_1.AccountsJsError && | ||
error.code === password_1.SendVerificationEmailErrors.UserNotFound) { | ||
return null; | ||
} | ||
throw error; | ||
} | ||
return null; | ||
}, | ||
}; | ||
//# sourceMappingURL=mutation.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Query = void 0; | ||
var tslib_1 = require("tslib"); | ||
var password_1 = require("@accounts/password"); | ||
const password_1 = require("@accounts/password"); | ||
exports.Query = { | ||
twoFactorSecret: function (_, args, ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var user, injector, secret; | ||
return tslib_1.__generator(this, function (_a) { | ||
user = ctx.user, injector = ctx.injector; | ||
// Make sure user is logged in | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
secret = injector.get(password_1.AccountsPassword).twoFactor.getNewAuthSecret(); | ||
return [2 /*return*/, secret]; | ||
}); | ||
}); }, | ||
twoFactorSecret: async (_, args, ctx) => { | ||
const { user, injector } = ctx; | ||
// Make sure user is logged in | ||
if (!(user && user.id)) { | ||
throw new Error('Unauthorized'); | ||
} | ||
// https://github.com/speakeasyjs/speakeasy/blob/master/index.js#L517 | ||
const secret = injector.get(password_1.AccountsPassword).twoFactor.getNewAuthSecret(); | ||
return secret; | ||
}, | ||
}; | ||
//# sourceMappingURL=query.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (function (config) { return graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n ", " type ", " {\n # Creates a user with a password, returns the id corresponding db ids, such as number IDs, ObjectIDs or UUIDs\n createUser(user: CreateUserInput!): CreateUserResult\n verifyEmail(token: String!): Boolean\n resetPassword(token: String!, newPassword: String!): LoginResult\n sendVerificationEmail(email: String!): Boolean\n sendResetPasswordEmail(email: String!): Boolean\n addEmail(newEmail: String!): Boolean\n changePassword(oldPassword: String!, newPassword: String!): Boolean\n twoFactorSet(secret: TwoFactorSecretKeyInput!, code: String!): Boolean\n twoFactorUnset(code: String!): Boolean\n }\n"], ["\n ", " type ", " {\n # Creates a user with a password, returns the id corresponding db ids, such as number IDs, ObjectIDs or UUIDs\n createUser(user: CreateUserInput!): CreateUserResult\n verifyEmail(token: String!): Boolean\n resetPassword(token: String!, newPassword: String!): LoginResult\n sendVerificationEmail(email: String!): Boolean\n sendResetPasswordEmail(email: String!): Boolean\n addEmail(newEmail: String!): Boolean\n changePassword(oldPassword: String!, newPassword: String!): Boolean\n twoFactorSet(secret: TwoFactorSecretKeyInput!, code: String!): Boolean\n twoFactorUnset(code: String!): Boolean\n }\n"])), config.extendTypeDefs ? 'extend' : '', config.rootMutationName || 'Mutation'); }); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (config) => graphql_tag_1.default ` | ||
${config.extendTypeDefs ? 'extend' : ''} type ${config.rootMutationName || 'Mutation'} { | ||
# Creates a user with a password, returns the id corresponding db ids, such as number IDs, ObjectIDs or UUIDs | ||
createUser(user: CreateUserInput!): CreateUserResult | ||
verifyEmail(token: String!): Boolean | ||
resetPassword(token: String!, newPassword: String!): LoginResult | ||
sendVerificationEmail(email: String!): Boolean | ||
sendResetPasswordEmail(email: String!): Boolean | ||
addEmail(newEmail: String!): Boolean | ||
changePassword(oldPassword: String!, newPassword: String!): Boolean | ||
twoFactorSet(secret: TwoFactorSecretKeyInput!, code: String!): Boolean | ||
twoFactorUnset(code: String!): Boolean | ||
} | ||
`; | ||
//# sourceMappingURL=mutation.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (function (config) { return graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n ", " type ", " {\n twoFactorSecret: TwoFactorSecretKey\n }\n"], ["\n ", " type ", " {\n twoFactorSecret: TwoFactorSecretKey\n }\n"])), config.extendTypeDefs ? 'extend' : '', config.rootQueryName || 'Query'); }); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (config) => graphql_tag_1.default ` | ||
${config.extendTypeDefs ? 'extend' : ''} type ${config.rootQueryName || 'Query'} { | ||
twoFactorSecret: TwoFactorSecretKey | ||
} | ||
`; | ||
//# sourceMappingURL=query.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n type Tokens {\n refreshToken: String\n accessToken: String\n }\n\n type LoginResult {\n sessionId: String\n tokens: Tokens\n user: User\n }\n\n type CreateUserResult {\n # Will be returned only if ambiguousErrorMessages is set to false.\n userId: ID\n # Will be returned only if enableAutologin is set to true.\n loginResult: LoginResult\n }\n\n type TwoFactorSecretKey {\n ascii: String\n base32: String\n hex: String\n qr_code_ascii: String\n qr_code_hex: String\n qr_code_base32: String\n google_auth_qr: String\n otpauth_url: String\n }\n\n input TwoFactorSecretKeyInput {\n ascii: String\n base32: String\n hex: String\n qr_code_ascii: String\n qr_code_hex: String\n qr_code_base32: String\n google_auth_qr: String\n otpauth_url: String\n }\n\n input CreateUserInput {\n username: String\n email: String\n password: String\n }\n"], ["\n type Tokens {\n refreshToken: String\n accessToken: String\n }\n\n type LoginResult {\n sessionId: String\n tokens: Tokens\n user: User\n }\n\n type CreateUserResult {\n # Will be returned only if ambiguousErrorMessages is set to false.\n userId: ID\n # Will be returned only if enableAutologin is set to true.\n loginResult: LoginResult\n }\n\n type TwoFactorSecretKey {\n ascii: String\n base32: String\n hex: String\n qr_code_ascii: String\n qr_code_hex: String\n qr_code_base32: String\n google_auth_qr: String\n otpauth_url: String\n }\n\n input TwoFactorSecretKeyInput {\n ascii: String\n base32: String\n hex: String\n qr_code_ascii: String\n qr_code_hex: String\n qr_code_base32: String\n google_auth_qr: String\n otpauth_url: String\n }\n\n input CreateUserInput {\n username: String\n email: String\n password: String\n }\n"]))); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = graphql_tag_1.default ` | ||
type Tokens { | ||
refreshToken: String | ||
accessToken: String | ||
} | ||
type LoginResult { | ||
sessionId: String | ||
tokens: Tokens | ||
user: User | ||
} | ||
type CreateUserResult { | ||
# Will be returned only if ambiguousErrorMessages is set to false. | ||
userId: ID | ||
# Will be returned only if enableAutologin is set to true. | ||
loginResult: LoginResult | ||
} | ||
type TwoFactorSecretKey { | ||
ascii: String | ||
base32: String | ||
hex: String | ||
qr_code_ascii: String | ||
qr_code_hex: String | ||
qr_code_base32: String | ||
google_auth_qr: String | ||
otpauth_url: String | ||
} | ||
input TwoFactorSecretKeyInput { | ||
ascii: String | ||
base32: String | ||
hex: String | ||
qr_code_ascii: String | ||
qr_code_hex: String | ||
qr_code_base32: String | ||
google_auth_qr: String | ||
otpauth_url: String | ||
} | ||
input CreateUserInput { | ||
username: String | ||
email: String | ||
password: String | ||
} | ||
`; | ||
//# sourceMappingURL=types.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AccountsModule = void 0; | ||
var tslib_1 = require("tslib"); | ||
var core_1 = require("@graphql-modules/core"); | ||
var merge_1 = require("@graphql-tools/merge"); | ||
var server_1 = require("@accounts/server"); | ||
var types_1 = tslib_1.__importDefault(require("./schema/types")); | ||
var query_1 = tslib_1.__importDefault(require("./schema/query")); | ||
var mutation_1 = tslib_1.__importDefault(require("./schema/mutation")); | ||
var schema_def_1 = tslib_1.__importDefault(require("./schema/schema-def")); | ||
var query_2 = require("./resolvers/query"); | ||
var mutation_2 = require("./resolvers/mutation"); | ||
var user_1 = require("./resolvers/user"); | ||
var accounts_password_1 = require("../accounts-password"); | ||
var authenticated_directive_1 = require("../../utils/authenticated-directive"); | ||
var utils_1 = require("../../utils"); | ||
var core_2 = require("../core"); | ||
const tslib_1 = require("tslib"); | ||
const core_1 = require("@graphql-modules/core"); | ||
const merge_1 = require("@graphql-tools/merge"); | ||
const server_1 = require("@accounts/server"); | ||
const types_1 = tslib_1.__importDefault(require("./schema/types")); | ||
const query_1 = tslib_1.__importDefault(require("./schema/query")); | ||
const mutation_1 = tslib_1.__importDefault(require("./schema/mutation")); | ||
const schema_def_1 = tslib_1.__importDefault(require("./schema/schema-def")); | ||
const query_2 = require("./resolvers/query"); | ||
const mutation_2 = require("./resolvers/mutation"); | ||
const user_1 = require("./resolvers/user"); | ||
const accounts_password_1 = require("../accounts-password"); | ||
const authenticated_directive_1 = require("../../utils/authenticated-directive"); | ||
const utils_1 = require("../../utils"); | ||
const core_2 = require("../core"); | ||
// You can see the below. It is really easy to create a reusable GraphQL-Module with different configurations | ||
exports.AccountsModule = new core_1.GraphQLModule({ | ||
name: 'accounts', | ||
typeDefs: function (_a) { | ||
var config = _a.config; | ||
return merge_1.mergeTypeDefs(tslib_1.__spreadArrays([ | ||
types_1.default, | ||
query_1.default(config), | ||
mutation_1.default(config) | ||
], schema_def_1.default(config)), { | ||
useSchemaDefinition: config.withSchemaDefinition, | ||
}); | ||
}, | ||
resolvers: function (_a) { | ||
var _b; | ||
var config = _a.config; | ||
return (_b = {}, | ||
_b[config.rootQueryName || 'Query'] = query_2.Query, | ||
_b[config.rootMutationName || 'Mutation'] = mutation_2.Mutation, | ||
_b.User = user_1.User, | ||
_b); | ||
}, | ||
typeDefs: ({ config }) => merge_1.mergeTypeDefs([ | ||
types_1.default, | ||
query_1.default(config), | ||
mutation_1.default(config), | ||
...schema_def_1.default(config), | ||
], { | ||
useSchemaDefinition: config.withSchemaDefinition, | ||
}), | ||
resolvers: ({ config }) => ({ | ||
[config.rootQueryName || 'Query']: query_2.Query, | ||
[config.rootMutationName || 'Mutation']: mutation_2.Mutation, | ||
User: user_1.User, | ||
}), | ||
// If necessary, import AccountsPasswordModule together with this module | ||
imports: function (_a) { | ||
var config = _a.config; | ||
return tslib_1.__spreadArrays([ | ||
core_2.CoreAccountsModule.forRoot({ | ||
userAsInterface: config.userAsInterface, | ||
}) | ||
], (config.accountsServer.getServices().password | ||
imports: ({ config }) => [ | ||
core_2.CoreAccountsModule.forRoot({ | ||
userAsInterface: config.userAsInterface, | ||
}), | ||
...(config.accountsServer.getServices().password | ||
? [ | ||
accounts_password_1.AccountsPasswordModule.forRoot(tslib_1.__assign({ accountsPassword: config.accountsServer.getServices().password }, config)), | ||
accounts_password_1.AccountsPasswordModule.forRoot({ | ||
accountsPassword: config.accountsServer.getServices().password, | ||
...config, | ||
}), | ||
] | ||
: [])); | ||
}, | ||
providers: function (_a) { | ||
var config = _a.config; | ||
return [ | ||
{ | ||
provide: server_1.AccountsServer, | ||
useValue: config.accountsServer, | ||
}, | ||
]; | ||
}, | ||
: []), | ||
], | ||
providers: ({ config }) => [ | ||
{ | ||
provide: server_1.AccountsServer, | ||
useValue: config.accountsServer, | ||
}, | ||
], | ||
context: utils_1.context('accounts'), | ||
@@ -64,0 +56,0 @@ schemaDirectives: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Mutation = void 0; | ||
var tslib_1 = require("tslib"); | ||
var server_1 = require("@accounts/server"); | ||
const server_1 = require("@accounts/server"); | ||
exports.Mutation = { | ||
authenticate: function (_, args, ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var serviceName, params, injector, infos, authenticated; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
serviceName = args.serviceName, params = args.params; | ||
injector = ctx.injector, infos = ctx.infos; | ||
return [4 /*yield*/, injector | ||
.get(server_1.AccountsServer) | ||
.loginWithService(serviceName, params, infos)]; | ||
case 1: | ||
authenticated = _a.sent(); | ||
return [2 /*return*/, authenticated]; | ||
} | ||
}); | ||
}); }, | ||
verifyAuthentication: function (_, args, ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var serviceName, params, injector, infos, authenticated; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
serviceName = args.serviceName, params = args.params; | ||
injector = ctx.injector, infos = ctx.infos; | ||
return [4 /*yield*/, injector | ||
.get(server_1.AccountsServer) | ||
.authenticateWithService(serviceName, params, infos)]; | ||
case 1: | ||
authenticated = _a.sent(); | ||
return [2 /*return*/, authenticated]; | ||
} | ||
}); | ||
}); }, | ||
impersonate: function (_, args, ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var accessToken, impersonated, injector, infos, impersonateRes; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
accessToken = args.accessToken, impersonated = args.impersonated; | ||
injector = ctx.injector, infos = ctx.infos; | ||
return [4 /*yield*/, injector.get(server_1.AccountsServer).impersonate(accessToken, { | ||
userId: impersonated.userId, | ||
username: impersonated.username, | ||
email: impersonated.email, | ||
}, infos)]; | ||
case 1: | ||
impersonateRes = _a.sent(); | ||
// So ctx.user can be used in subsequent queries / mutations | ||
if (impersonateRes && impersonateRes.user && impersonateRes.tokens) { | ||
ctx.user = impersonateRes.user; | ||
ctx.authToken = impersonateRes.tokens.accessToken; | ||
} | ||
return [2 /*return*/, impersonateRes]; | ||
} | ||
}); | ||
}); }, | ||
logout: function (_, __, context) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var authToken, injector; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
authToken = context.authToken, injector = context.injector; | ||
if (!authToken) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, injector.get(server_1.AccountsServer).logout(authToken)]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, null]; | ||
} | ||
}); | ||
}); }, | ||
refreshTokens: function (_, args, ctx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var accessToken, refreshToken, injector, infos, refreshedSession; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
accessToken = args.accessToken, refreshToken = args.refreshToken; | ||
injector = ctx.injector, infos = ctx.infos; | ||
return [4 /*yield*/, injector | ||
.get(server_1.AccountsServer) | ||
.refreshTokens(accessToken, refreshToken, infos)]; | ||
case 1: | ||
refreshedSession = _a.sent(); | ||
return [2 /*return*/, refreshedSession]; | ||
} | ||
}); | ||
}); }, | ||
authenticate: async (_, args, ctx) => { | ||
const { serviceName, params } = args; | ||
const { injector, infos } = ctx; | ||
const authenticated = await injector | ||
.get(server_1.AccountsServer) | ||
.loginWithService(serviceName, params, infos); | ||
return authenticated; | ||
}, | ||
verifyAuthentication: async (_, args, ctx) => { | ||
const { serviceName, params } = args; | ||
const { injector, infos } = ctx; | ||
const authenticated = await injector | ||
.get(server_1.AccountsServer) | ||
.authenticateWithService(serviceName, params, infos); | ||
return authenticated; | ||
}, | ||
impersonate: async (_, args, ctx) => { | ||
const { accessToken, impersonated } = args; | ||
const { injector, infos } = ctx; | ||
const impersonateRes = await injector.get(server_1.AccountsServer).impersonate(accessToken, { | ||
userId: impersonated.userId, | ||
username: impersonated.username, | ||
email: impersonated.email, | ||
}, infos); | ||
// So ctx.user can be used in subsequent queries / mutations | ||
if (impersonateRes && impersonateRes.user && impersonateRes.tokens) { | ||
ctx.user = impersonateRes.user; | ||
ctx.authToken = impersonateRes.tokens.accessToken; | ||
} | ||
return impersonateRes; | ||
}, | ||
logout: async (_, __, context) => { | ||
const { authToken, injector } = context; | ||
if (authToken) { | ||
await injector.get(server_1.AccountsServer).logout(authToken); | ||
} | ||
return null; | ||
}, | ||
refreshTokens: async (_, args, ctx) => { | ||
const { accessToken, refreshToken } = args; | ||
const { injector, infos } = ctx; | ||
const refreshedSession = await injector | ||
.get(server_1.AccountsServer) | ||
.refreshTokens(accessToken, refreshToken, infos); | ||
return refreshedSession; | ||
}, | ||
}; | ||
//# sourceMappingURL=mutation.js.map |
@@ -5,4 +5,4 @@ "use strict"; | ||
exports.Query = { | ||
getUser: function (_, __, context) { return context.user || null; }, | ||
getUser: (_, __, context) => context.user || null, | ||
}; | ||
//# sourceMappingURL=query.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (function (config) { return graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n ", " type ", " {\n impersonate(accessToken: String!, impersonated: ImpersonationUserIdentityInput!): ImpersonateReturn\n refreshTokens(accessToken: String!, refreshToken: String!): LoginResult\n logout: Boolean\n\n # Example: Login with password\n # authenticate(serviceName: \"password\", params: {password: \"<pw>\", user: {email: \"<email>\"}})\n authenticate(serviceName: String!, params: AuthenticateParamsInput!): LoginResult\n verifyAuthentication(serviceName: String!, params: AuthenticateParamsInput!): Boolean\n }\n"], ["\n ", " type ", " {\n impersonate(accessToken: String!, impersonated: ImpersonationUserIdentityInput!): ImpersonateReturn\n refreshTokens(accessToken: String!, refreshToken: String!): LoginResult\n logout: Boolean\n\n # Example: Login with password\n # authenticate(serviceName: \"password\", params: {password: \"<pw>\", user: {email: \"<email>\"}})\n authenticate(serviceName: String!, params: AuthenticateParamsInput!): LoginResult\n verifyAuthentication(serviceName: String!, params: AuthenticateParamsInput!): Boolean\n }\n"])), config.extendTypeDefs ? 'extend' : '', config.rootMutationName || 'Mutation'); }); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (config) => graphql_tag_1.default ` | ||
${config.extendTypeDefs ? 'extend' : ''} type ${config.rootMutationName || 'Mutation'} { | ||
impersonate(accessToken: String!, impersonated: ImpersonationUserIdentityInput!): ImpersonateReturn | ||
refreshTokens(accessToken: String!, refreshToken: String!): LoginResult | ||
logout: Boolean | ||
# Example: Login with password | ||
# authenticate(serviceName: "password", params: {password: "<pw>", user: {email: "<email>"}}) | ||
authenticate(serviceName: String!, params: AuthenticateParamsInput!): LoginResult | ||
verifyAuthentication(serviceName: String!, params: AuthenticateParamsInput!): Boolean | ||
} | ||
`; | ||
//# sourceMappingURL=mutation.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (function (config) { return graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n ", " type ", " {\n getUser: User\n }\n"], ["\n ", " type ", " {\n getUser: User\n }\n"])), config.extendTypeDefs ? 'extend' : '', config.rootQueryName || 'Query'); }); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (config) => graphql_tag_1.default ` | ||
${config.extendTypeDefs ? 'extend' : ''} type ${config.rootQueryName || 'Query'} { | ||
getUser: User | ||
} | ||
`; | ||
//# sourceMappingURL=query.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (function (config) { | ||
return config.withSchemaDefinition | ||
? [ | ||
graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n schema {\n query: ", "\n mutation: ", "\n }\n"], ["\n schema {\n query: ", "\n mutation: ", "\n }\n"])), config.rootMutationName || 'Query', config.rootQueryName || 'Mutation'), | ||
] | ||
: []; | ||
}); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (config) => config.withSchemaDefinition | ||
? [ | ||
graphql_tag_1.default ` | ||
schema { | ||
query: ${config.rootMutationName || 'Query'} | ||
mutation: ${config.rootQueryName || 'Mutation'} | ||
} | ||
`, | ||
] | ||
: []; | ||
//# sourceMappingURL=schema-def.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n directive @auth on FIELD_DEFINITION | OBJECT\n\n type ImpersonateReturn {\n authorized: Boolean\n tokens: Tokens\n user: User\n }\n\n input UserInput {\n id: ID\n email: String\n username: String\n }\n\n input AuthenticateParamsInput {\n # Twitter, Instagram\n access_token: String\n # Twitter\n access_token_secret: String\n # OAuth\n provider: String\n # Password\n password: String\n # Password\n user: UserInput\n # Two factor\n code: String\n }\n\n input ImpersonationUserIdentityInput {\n userId: String\n username: String\n email: String\n }\n"], ["\n directive @auth on FIELD_DEFINITION | OBJECT\n\n type ImpersonateReturn {\n authorized: Boolean\n tokens: Tokens\n user: User\n }\n\n input UserInput {\n id: ID\n email: String\n username: String\n }\n\n input AuthenticateParamsInput {\n # Twitter, Instagram\n access_token: String\n # Twitter\n access_token_secret: String\n # OAuth\n provider: String\n # Password\n password: String\n # Password\n user: UserInput\n # Two factor\n code: String\n }\n\n input ImpersonationUserIdentityInput {\n userId: String\n username: String\n email: String\n }\n"]))); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = graphql_tag_1.default ` | ||
directive @auth on FIELD_DEFINITION | OBJECT | ||
type ImpersonateReturn { | ||
authorized: Boolean | ||
tokens: Tokens | ||
user: User | ||
} | ||
input UserInput { | ||
id: ID | ||
email: String | ||
username: String | ||
} | ||
input AuthenticateParamsInput { | ||
# Twitter, Instagram | ||
access_token: String | ||
access_token_secret: String | ||
# OAuth | ||
provider: String | ||
# Password | ||
password: String | ||
# Password | ||
user: UserInput | ||
# Two factor | ||
code: String | ||
} | ||
input ImpersonationUserIdentityInput { | ||
userId: String | ||
username: String | ||
email: String | ||
} | ||
`; | ||
//# sourceMappingURL=types.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreAccountsModule = void 0; | ||
var tslib_1 = require("tslib"); | ||
var core_1 = require("@graphql-modules/core"); | ||
var schema_1 = tslib_1.__importDefault(require("./schema")); | ||
const tslib_1 = require("tslib"); | ||
const core_1 = require("@graphql-modules/core"); | ||
const schema_1 = tslib_1.__importDefault(require("./schema")); | ||
exports.CoreAccountsModule = new core_1.GraphQLModule({ | ||
typeDefs: function (_a) { | ||
var config = _a.config; | ||
return schema_1.default(config); | ||
}, | ||
typeDefs: ({ config }) => schema_1.default(config), | ||
resolvers: {}, | ||
@@ -13,0 +10,0 @@ imports: [], |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = (function (_a) { | ||
var userAsInterface = _a.userAsInterface; | ||
return graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n ", " User {\n id: ID!\n emails: [EmailRecord!]\n username: String\n }\n\n type EmailRecord {\n address: String\n verified: Boolean\n }\n \n type Tokens {\n refreshToken: String\n accessToken: String\n }\n\n type LoginResult {\n sessionId: String\n tokens: Tokens\n user: User\n }\n"], ["\n ", " User {\n id: ID!\n emails: [EmailRecord!]\n username: String\n }\n\n type EmailRecord {\n address: String\n verified: Boolean\n }\n \n type Tokens {\n refreshToken: String\n accessToken: String\n }\n\n type LoginResult {\n sessionId: String\n tokens: Tokens\n user: User\n }\n"])), userAsInterface ? 'interface' : 'type'); | ||
}); | ||
var templateObject_1; | ||
const tslib_1 = require("tslib"); | ||
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); | ||
exports.default = ({ userAsInterface }) => graphql_tag_1.default ` | ||
${userAsInterface ? 'interface' : 'type'} User { | ||
id: ID! | ||
emails: [EmailRecord!] | ||
username: String | ||
} | ||
type EmailRecord { | ||
address: String | ||
verified: Boolean | ||
} | ||
type Tokens { | ||
refreshToken: String | ||
accessToken: String | ||
} | ||
type LoginResult { | ||
sessionId: String | ||
tokens: Tokens | ||
user: User | ||
} | ||
`; | ||
//# sourceMappingURL=schema.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./accounts"), exports); | ||
tslib_1.__exportStar(require("./accounts-password"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var modules_1 = require("./modules"); | ||
const modules_1 = require("./modules"); | ||
exports.default = modules_1.AccountsModule.forRoot({ | ||
accountsServer: { | ||
getServices: function () { return ({ | ||
getServices: () => ({ | ||
password: {}, | ||
}); }, | ||
}), | ||
}, | ||
}).typeDefs; | ||
//# sourceMappingURL=schema.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AuthenticatedDirective = void 0; | ||
var tslib_1 = require("tslib"); | ||
var authenticated_resolver_1 = require("./authenticated-resolver"); | ||
var utils_1 = require("@graphql-tools/utils"); | ||
var AuthenticatedDirective = /** @class */ (function (_super) { | ||
tslib_1.__extends(AuthenticatedDirective, _super); | ||
function AuthenticatedDirective() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const authenticated_resolver_1 = require("./authenticated-resolver"); | ||
const utils_1 = require("@graphql-tools/utils"); | ||
class AuthenticatedDirective extends utils_1.SchemaDirectiveVisitor { | ||
visitFieldDefinition(field) { | ||
field.resolve = authenticated_resolver_1.authenticated(field.resolve); | ||
} | ||
AuthenticatedDirective.prototype.visitFieldDefinition = function (field) { | ||
field.resolve = authenticated_resolver_1.authenticated(field.resolve); | ||
}; | ||
AuthenticatedDirective.prototype.visitObject = function (object) { | ||
var fields = object.getFields(); | ||
Object.keys(fields).forEach(function (fieldName) { | ||
var field = fields[fieldName]; | ||
visitObject(object) { | ||
const fields = object.getFields(); | ||
Object.keys(fields).forEach((fieldName) => { | ||
const field = fields[fieldName]; | ||
if ('resolve' in field) { | ||
@@ -23,6 +18,5 @@ field.resolve = authenticated_resolver_1.authenticated(field.resolve); | ||
}); | ||
}; | ||
return AuthenticatedDirective; | ||
}(utils_1.SchemaDirectiveVisitor)); | ||
} | ||
} | ||
exports.AuthenticatedDirective = AuthenticatedDirective; | ||
//# sourceMappingURL=authenticated-directive.js.map |
@@ -1,1 +0,5 @@ | ||
export declare const authenticated: (func: any) => (root: any, args: any, context: any, info: any) => Promise<any>; | ||
export declare const authenticated: <CustomRoot, CustomArgs, CustomContext extends { | ||
skipJSAccountsVerification?: Boolean | undefined; | ||
userId?: any; | ||
user?: any; | ||
}, Info, ReturnType_1>(func: (root: CustomRoot, args: CustomArgs, context: CustomContext, info: Info) => ReturnType_1 | Promise<ReturnType_1>) => (root: CustomRoot, args: CustomArgs, context: CustomContext, info: Info) => Promise<ReturnType_1>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.authenticated = void 0; | ||
var tslib_1 = require("tslib"); | ||
exports.authenticated = function (func) { return function (root, args, context, info) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
if (context && context.skipJSAccountsVerification === true) { | ||
return [2 /*return*/, func(root, args, context, info)]; | ||
} | ||
if (!context.userId && !context.user) { | ||
throw new Error('Unauthorized'); | ||
} | ||
return [2 /*return*/, func(root, args, context, info)]; | ||
}); | ||
}); }; }; | ||
exports.authenticated = (func) => async (root, args, context, info) => { | ||
if (context && context.skipJSAccountsVerification === true) { | ||
return func(root, args, context, info); | ||
} | ||
if (!context.userId && !context.user) { | ||
throw new Error('Unauthorized'); | ||
} | ||
return func(root, args, context, info); | ||
}; | ||
//# sourceMappingURL=authenticated-resolver.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.context = void 0; | ||
var tslib_1 = require("tslib"); | ||
var core_1 = require("@graphql-modules/core"); | ||
var request_ip_1 = require("request-ip"); | ||
exports.context = function (moduleName) { return function (_a, _, _b) { | ||
var req = _a.req; | ||
var injector = _b.injector; | ||
return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var config, headerName, authToken, user, error_1, ip, userAgent; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!req) { | ||
return [2 /*return*/, { | ||
ip: '', | ||
userAgent: '', | ||
infos: { | ||
ip: '', | ||
userAgent: '', | ||
}, | ||
}]; | ||
} | ||
config = injector.get(core_1.ModuleConfig(moduleName)); | ||
headerName = config.headerName || 'Authorization'; | ||
authToken = (req.headers[headerName] || req.headers[headerName.toLowerCase()]); | ||
authToken = authToken && authToken.replace('Bearer ', ''); | ||
if (!(authToken && !config.excludeAddUserInContext)) return [3 /*break*/, 4]; | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, config.accountsServer.resumeSession(authToken)]; | ||
case 2: | ||
user = _c.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _c.sent(); | ||
return [3 /*break*/, 4]; | ||
case 4: | ||
ip = request_ip_1.getClientIp(req); | ||
userAgent = req.headers['user-agent'] || ''; | ||
if (req.headers['x-ucbrowser-ua']) { | ||
// special case of UC Browser | ||
userAgent = req.headers['x-ucbrowser-ua']; | ||
} | ||
return [2 /*return*/, { | ||
authToken: authToken, | ||
user: user, | ||
userId: user && user.id, | ||
userAgent: userAgent, | ||
ip: ip, | ||
infos: { | ||
userAgent: userAgent, | ||
ip: ip, | ||
}, | ||
}]; | ||
} | ||
}); | ||
}); | ||
}; }; | ||
const core_1 = require("@graphql-modules/core"); | ||
const request_ip_1 = require("request-ip"); | ||
exports.context = (moduleName) => async ({ req }, _, { injector }) => { | ||
if (!req) { | ||
return { | ||
ip: '', | ||
userAgent: '', | ||
infos: { | ||
ip: '', | ||
userAgent: '', | ||
}, | ||
}; | ||
} | ||
const config = injector.get(core_1.ModuleConfig(moduleName)); | ||
const headerName = config.headerName || 'Authorization'; | ||
let authToken = (req.headers[headerName] || req.headers[headerName.toLowerCase()]); | ||
authToken = authToken && authToken.replace('Bearer ', ''); | ||
let user; | ||
if (authToken && !config.excludeAddUserInContext) { | ||
try { | ||
user = await config.accountsServer.resumeSession(authToken); | ||
} | ||
catch (error) { | ||
// Empty catch | ||
} | ||
} | ||
const ip = request_ip_1.getClientIp(req); | ||
let userAgent = req.headers['user-agent'] || ''; | ||
if (req.headers['x-ucbrowser-ua']) { | ||
// special case of UC Browser | ||
userAgent = req.headers['x-ucbrowser-ua']; | ||
} | ||
return { | ||
authToken, | ||
user, | ||
userId: user && user.id, | ||
userAgent, | ||
ip, | ||
infos: { | ||
userAgent, | ||
ip, | ||
}, | ||
}; | ||
}; | ||
//# sourceMappingURL=context-builder.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./authenticated-directive"), exports); | ||
@@ -5,0 +5,0 @@ tslib_1.__exportStar(require("./authenticated-resolver"), exports); |
{ | ||
"name": "@accounts/graphql-api", | ||
"version": "0.30.0", | ||
"version": "0.31.0", | ||
"description": "Server side GraphQL transport for accounts", | ||
@@ -36,6 +36,7 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"@accounts/password": "^0.28.0", | ||
"@accounts/server": "^0.28.0", | ||
"@accounts/types": "^0.28.0", | ||
"@accounts/password": "^0.30.0", | ||
"@accounts/server": "^0.30.0", | ||
"@accounts/types": "^0.30.0", | ||
"@graphql-modules/core": "0.7.17", | ||
"graphql": "^14.6.0 || ^15.0.0", | ||
"graphql-tag": "^2.10.0" | ||
@@ -50,5 +51,5 @@ }, | ||
"devDependencies": { | ||
"@accounts/password": "^0.30.0", | ||
"@accounts/server": "^0.30.0", | ||
"@accounts/types": "^0.30.0", | ||
"@accounts/password": "^0.31.0", | ||
"@accounts/server": "^0.31.0", | ||
"@accounts/types": "^0.31.0", | ||
"@graphql-codegen/add": "1.17.4", | ||
@@ -70,3 +71,3 @@ "@graphql-codegen/cli": "1.17.4", | ||
}, | ||
"gitHead": "a883d3b90c481e9c73a7655ef2aadac092fc6b0e" | ||
"gitHead": "8938531dd59f40e14e029c8785433acb455bd58c" | ||
} |
@@ -1,7 +0,15 @@ | ||
export const authenticated = (func: any) => async ( | ||
root: any, | ||
args: any, | ||
context: any, | ||
info: any | ||
) => { | ||
export const authenticated = < | ||
CustomRoot, | ||
CustomArgs, | ||
CustomContext extends { skipJSAccountsVerification?: Boolean; userId?: any; user?: any }, | ||
Info, | ||
ReturnType | ||
>( | ||
func: ( | ||
root: CustomRoot, | ||
args: CustomArgs, | ||
context: CustomContext, | ||
info: Info | ||
) => ReturnType | Promise<ReturnType> | ||
) => async (root: CustomRoot, args: CustomArgs, context: CustomContext, info: Info) => { | ||
if (context && context.skipJSAccountsVerification === true) { | ||
@@ -8,0 +16,0 @@ return func(root, args, context, info); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 4 instances in 1 package
2
104775
10
1985