Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@accounts/magic-link

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accounts/magic-link - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0-alpha-20231022085748-0910b9e1

lib/types/AccountsMagicLinkConfig.symbol.d.ts

7

lib/accounts-magic-link.d.ts

@@ -1,2 +0,2 @@

import { User, DatabaseInterface, AuthenticationService, LoginUserMagicLinkService, TokenRecord } from '@accounts/types';
import { User, DatabaseInterface, AuthenticationService, LoginUserMagicLinkService, TokenRecord, DatabaseInterfaceUser } from '@accounts/types';
import { AccountsServer } from '@accounts/server';

@@ -20,4 +20,5 @@ import { ErrorMessages } from './types';

private db;
constructor(options?: AccountsMagicLinkOptions);
setStore(store: DatabaseInterface<CustomUser>): void;
constructor(options?: AccountsMagicLinkOptions, server?: AccountsServer, db?: DatabaseInterface<CustomUser> | DatabaseInterfaceUser<CustomUser>);
setUserStore(store: DatabaseInterfaceUser<CustomUser>): void;
setSessionsStore(): void;
requestMagicLinkEmail(email: string): Promise<void>;

@@ -24,0 +25,0 @@ authenticate(params: LoginUserMagicLinkService): Promise<CustomUser>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const server_1 = require("@accounts/server");
const types_1 = require("./types");
const errors_1 = require("./errors");

@@ -8,2 +10,3 @@ const validation_1 = require("./utils/validation");

const user_1 = require("./utils/user");
const graphql_modules_1 = require("graphql-modules");
const defaultOptions = {

@@ -14,12 +17,21 @@ errors: errors_1.errors,

};
class AccountsMagicLink {
constructor(options = {}) {
let AccountsMagicLink = class AccountsMagicLink {
constructor(options = {}, server, db) {
this.serviceName = 'magicLink';
this.options = { ...defaultOptions, ...options };
if (db) {
this.db = db;
}
if (server) {
this.server = server;
}
}
setStore(store) {
setUserStore(store) {
this.db = store;
}
setSessionsStore() {
// Empty
}
async requestMagicLinkEmail(email) {
if (!email || !validation_1.isString(email)) {
if (!email || !(0, validation_1.isString)(email)) {
throw new server_1.AccountsJsError(this.options.errors.invalidEmail, errors_2.RequestMagicLinkEmailErrors.InvalidEmail);

@@ -33,3 +45,3 @@ }

await this.db.removeAllLoginTokens(user.id);
const token = server_1.generateRandomToken();
const token = (0, server_1.generateRandomToken)();
await this.db.addLoginToken(user.id, email, token);

@@ -44,3 +56,3 @@ const requestMagicLinkMail = this.server.prepareMail(email, token, this.server.sanitizeUser(user), 'magiclink', this.server.options.emailTemplates.magicLink, this.server.options.emailTemplates.from);

}
if (!validation_1.isString(token)) {
if (!(0, validation_1.isString)(token)) {
throw new server_1.AccountsJsError(this.options.errors.matchFailed, errors_1.AuthenticateErrors.MatchFailed);

@@ -61,3 +73,3 @@ }

}
const loginTokens = user_1.getUserLoginTokens(foundUser);
const loginTokens = (0, user_1.getUserLoginTokens)(foundUser);
const tokenRecord = loginTokens.find((t) => t.token === token);

@@ -69,4 +81,12 @@ if (!tokenRecord || this.isTokenExpired(tokenRecord, this.options.loginTokenExpiration)) {

}
}
};
AccountsMagicLink = tslib_1.__decorate([
(0, graphql_modules_1.Injectable)({
global: true,
}),
tslib_1.__param(0, (0, graphql_modules_1.Inject)(types_1.AccountsMagicLinkConfigToken)),
tslib_1.__param(2, (0, graphql_modules_1.Inject)(server_1.DatabaseInterfaceUserToken)),
tslib_1.__metadata("design:paramtypes", [Object, server_1.AccountsServer, Object])
], AccountsMagicLink);
exports.default = AccountsMagicLink;
//# sourceMappingURL=accounts-magic-link.js.map

@@ -14,3 +14,3 @@ "use strict";

MagicLinkAuthenticatorErrors["LoginTokenExpired"] = "LoginTokenExpired";
})(MagicLinkAuthenticatorErrors = exports.MagicLinkAuthenticatorErrors || (exports.MagicLinkAuthenticatorErrors = {}));
})(MagicLinkAuthenticatorErrors || (exports.MagicLinkAuthenticatorErrors = MagicLinkAuthenticatorErrors = {}));
var AuthenticateErrors;

@@ -20,3 +20,3 @@ (function (AuthenticateErrors) {

AuthenticateErrors["MatchFailed"] = "MatchFailed";
})(AuthenticateErrors = exports.AuthenticateErrors || (exports.AuthenticateErrors = {}));
})(AuthenticateErrors || (exports.AuthenticateErrors = AuthenticateErrors = {}));
var RequestMagicLinkEmailErrors;

@@ -26,3 +26,3 @@ (function (RequestMagicLinkEmailErrors) {

RequestMagicLinkEmailErrors["UserNotFound"] = "UserNotFound";
})(RequestMagicLinkEmailErrors = exports.RequestMagicLinkEmailErrors || (exports.RequestMagicLinkEmailErrors = {}));
})(RequestMagicLinkEmailErrors || (exports.RequestMagicLinkEmailErrors = RequestMagicLinkEmailErrors = {}));
//# sourceMappingURL=errors.js.map

@@ -1,5 +0,5 @@

import AccountsMagicLink from './accounts-magic-link';
import AccountsMagicLink, { AccountsMagicLinkOptions } from './accounts-magic-link';
export * from './types';
export { errors, AuthenticateErrors, MagicLinkAuthenticatorErrors, RequestMagicLinkEmailErrors, } from './errors';
export default AccountsMagicLink;
export { AccountsMagicLink };
export { AccountsMagicLink, AccountsMagicLinkOptions };
export { ErrorMessages } from './error-messages';
export * from './AccountsMagicLinkConfig.symbol';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./AccountsMagicLinkConfig.symbol"), exports);
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

export declare const isEmail: (email?: string | undefined) => boolean;
export declare const isEmail: (email?: string) => boolean;
{
"name": "@accounts/magic-link",
"version": "0.1.1",
"version": "1.0.0-alpha-20231022085748-0910b9e1",
"license": "MIT",

@@ -10,2 +10,11 @@ "main": "lib/index.js",

},
"scripts": {
"clean": "yarn run -T rimraf lib",
"start": "yarn run -T tsc --watch",
"precompile": "yarn run clean",
"compile": "yarn run -T tsc",
"prepublishOnly": "yarn run compile",
"testonly": "yarn run -T jest --coverage",
"coverage": "yarn run -T jest --coverage"
},
"files": [

@@ -20,28 +29,19 @@ "src",

"dependencies": {
"bcryptjs": "^2.4.3",
"tslib": "2.3.0"
"bcryptjs": "2.4.3",
"tslib": "2.6.2"
},
"devDependencies": {
"@accounts/server": "^0.33.1",
"@accounts/types": "^0.33.1",
"@types/bcryptjs": "2.4.2",
"@types/jest": "26.0.24",
"@types/lodash.set": "4.3.6",
"@types/node": "16.4.13",
"jest": "27.0.6",
"@accounts/server": "1.0.0-alpha-20231022085748-0910b9e1",
"@accounts/types": "1.0.0-alpha-20231022085748-0910b9e1",
"@types/bcryptjs": "2.4.5",
"@types/lodash.set": "4.3.8",
"graphql": "16.8.1",
"graphql-modules": "3.0.0-alpha-20231018163544-36199b68",
"lodash.set": "4.3.2",
"rimraf": "3.0.2",
"ts-jest": "27.0.4"
"reflect-metadata": "0.1.13"
},
"peerDependencies": {
"@accounts/server": "^0.32.0 || ^0.33.0"
},
"scripts": {
"clean": "rimraf lib",
"start": "tsc --watch",
"precompile": "pnpm run clean",
"compile": "tsc",
"testonly": "jest --coverage",
"coverage": "jest --coverage"
"@accounts/server": "1.0.0-alpha-20231022085748-0910b9e1",
"graphql-modules": "^3.0.0"
}
}
}

@@ -7,5 +7,11 @@ import {

TokenRecord,
DatabaseInterfaceUser,
} from '@accounts/types';
import { AccountsServer, AccountsJsError, generateRandomToken } from '@accounts/server';
import { ErrorMessages } from './types';
import {
AccountsServer,
AccountsJsError,
generateRandomToken,
DatabaseInterfaceUserToken,
} from '@accounts/server';
import { AccountsMagicLinkConfigToken, ErrorMessages } from './types';
import { errors, AuthenticateErrors, MagicLinkAuthenticatorErrors } from './errors';

@@ -15,2 +21,3 @@ import { isString } from './utils/validation';

import { getUserLoginTokens } from './utils/user';
import { Injectable, Inject } from 'graphql-modules';

@@ -35,2 +42,5 @@ export interface AccountsMagicLinkOptions {

@Injectable({
global: true,
})
export default class AccountsMagicLink<CustomUser extends User = User>

@@ -42,12 +52,27 @@ implements AuthenticationService

private options: AccountsMagicLinkOptions & typeof defaultOptions;
private db!: DatabaseInterface<CustomUser>;
private db!: DatabaseInterfaceUser<CustomUser>;
constructor(options: AccountsMagicLinkOptions = {}) {
constructor(
@Inject(AccountsMagicLinkConfigToken) options: AccountsMagicLinkOptions = {},
server?: AccountsServer,
@Inject(DatabaseInterfaceUserToken)
db?: DatabaseInterface<CustomUser> | DatabaseInterfaceUser<CustomUser>
) {
this.options = { ...defaultOptions, ...options };
if (db) {
this.db = db;
}
if (server) {
this.server = server;
}
}
public setStore(store: DatabaseInterface<CustomUser>) {
public setUserStore(store: DatabaseInterfaceUser<CustomUser>) {
this.db = store;
}
public setSessionsStore() {
// Empty
}
public async requestMagicLinkEmail(email: string): Promise<void> {

@@ -54,0 +79,0 @@ if (!email || !isString(email)) {

@@ -1,2 +0,2 @@

import AccountsMagicLink from './accounts-magic-link';
import AccountsMagicLink, { AccountsMagicLinkOptions } from './accounts-magic-link';
export * from './types';

@@ -11,2 +11,2 @@ export {

export default AccountsMagicLink;
export { AccountsMagicLink };
export { AccountsMagicLink, AccountsMagicLinkOptions };
export { ErrorMessages } from './error-messages';
export * from './AccountsMagicLinkConfig.symbol';

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc