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

@next-auth/neo4j-adapter

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@next-auth/neo4j-adapter - npm Package Compare versions

Comparing version 0.1.1-pr.314-9c3d7ae5.299 to 0.1.1-pr.314-f40ff972.300

92

dist/index.js

@@ -8,29 +8,31 @@ "use strict";

function Neo4jAdapter(session) {
const query = (0, utils_1.client)(session);
const { read, write } = (0, utils_1.client)(session);
return {
async createUser(data) {
const user = { id: (0, uuid_1.v4)(), ...data };
await query(`CREATE (u:User $u)`, { u: utils_1.format.to(user) });
await write(`CREATE (u:User $data)`, user);
return user;
},
async getUser(id) {
return await query(`MATCH (u:User { id: $id }) RETURN properties(u)`, { id }, { tx: "read" });
return await read(`MATCH (u:User { id: $id }) RETURN properties(u)`, {
id,
});
},
async getUserByEmail(email) {
return await query(`MATCH (u:User { email: $email }) RETURN properties(u)`, { email }, { tx: "read" });
return await read(`MATCH (u:User { email: $email }) RETURN properties(u)`, { email });
},
async getUserByAccount(provider_providerAccountId) {
return await query(`MATCH (u:User)-[:HAS_ACCOUNT]->(a:Account {
return await read(`MATCH (u:User)-[:HAS_ACCOUNT]->(a:Account {
provider: $provider,
providerAccountId: $providerAccountId
})
RETURN properties(u)`, provider_providerAccountId, { tx: "read" });
RETURN properties(u)`, provider_providerAccountId);
},
async updateUser(user) {
return await query(`MATCH (u:User { id: $u.id })
SET u += $u
RETURN properties(u)`, { u: utils_1.format.to(user) });
async updateUser(data) {
return await write(`MATCH (u:User { id: $data.id })
SET u += $data
RETURN properties(u)`, data);
},
async deleteUser(id) {
return await query(`MATCH (u:User { id: $id })
return await write(`MATCH (u:User { id: $data.id })
WITH u, properties(u) AS properties

@@ -42,16 +44,16 @@ DETACH DELETE u

const account = { id: (0, uuid_1.v4)(), ...data };
await query(`MATCH (u:User { id: $a.userId })
await write(`MATCH (u:User { id: $data.userId })
MERGE (a:Account {
providerAccountId: $a.providerAccountId,
provider: $a.provider
providerAccountId: $data.providerAccountId,
provider: $data.provider
})
ON CREATE SET a.id = $a.id
SET a += $a
MERGE (u)-[:HAS_ACCOUNT]->(a)`, { a: utils_1.format.to(account) });
ON CREATE SET a.id = $data.id
SET a += $data
MERGE (u)-[:HAS_ACCOUNT]->(a)`, account);
return account;
},
async unlinkAccount(provider_providerAccountId) {
return await query(`MATCH (u:User)-[:HAS_ACCOUNT]->(a:Account {
providerAccountId: $providerAccountId,
provider: $provider
return await write(`MATCH (u:User)-[:HAS_ACCOUNT]->(a:Account {
providerAccountId: $data.providerAccountId,
provider: $data.provider
})

@@ -64,45 +66,49 @@ WITH u, a, properties(a) AS properties

const session = { ...data, id: (0, uuid_1.v4)() };
await query(`MATCH (u:User { id: $s.userId })
CREATE (s:Session $s)
CREATE (u)-[:HAS_SESSION]->(s)`, { s: utils_1.format.to(session) });
await write(`MATCH (u:User { id: $data.userId })
CREATE (s:Session $data)
CREATE (u)-[:HAS_SESSION]->(s)`, session);
return session;
},
async getSessionAndUser(sessionToken) {
const result = await query(`OPTIONAL MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $sessionToken })
WHERE s.expires <= datetime($now)
const result = await write(`OPTIONAL MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $data.sessionToken })
WHERE s.expires <= datetime($data.now)
DETACH DELETE s
WITH count(s) AS c
MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $sessionToken })
RETURN s { .*, userId: u.id } AS session, properties(u) AS user`, { sessionToken, now: new Date().toISOString() }, { returnFormat: ["session", "user"] });
MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $data.sessionToken })
RETURN s { .*, userId: u.id } AS session, properties(u) AS user`, { sessionToken, now: new Date().toISOString() });
if (!(result === null || result === void 0 ? void 0 : result.session) || !(result === null || result === void 0 ? void 0 : result.user))
return null;
return result;
return {
session: utils_1.format.from(result.session),
user: utils_1.format.from(result.user),
};
},
async updateSession(data) {
return await query(`MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $s.sessionToken })
SET s += $s
RETURN s { .*, userId: u.id }`, { s: utils_1.format.to(data) });
return await write(`MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $data.sessionToken })
SET s += $data
RETURN s { .*, userId: u.id }`, data);
},
async deleteSession(sessionToken) {
return await query(` MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $sessionToken })
WITH u, s, properties(s) AS properties
DETACH DELETE s
RETURN properties { .*, userId: u.id }`, { sessionToken });
return await write(`MATCH (u:User)-[:HAS_SESSION]->(s:Session { sessionToken: $data.sessionToken })
WITH u, s, properties(s) AS properties
DETACH DELETE s
RETURN properties { .*, userId: u.id }`, { sessionToken });
},
async createVerificationToken(data) {
await query(`MERGE (v:VerificationToken {
identifier: $v.identifier,
token: $v.token
await write(`MERGE (v:VerificationToken {
identifier: $data.identifier,
token: $data.token
})
SET v += $v`, { v: utils_1.format.to(data) });
SET v += $data`, data);
return data;
},
async useVerificationToken(data) {
return await query(`MATCH (v:VerificationToken {
identifier: $identifier,
token: $token
const r = await write(`MATCH (v:VerificationToken {
identifier: $data.identifier,
token: $data.token
})
WITH v, properties(v) AS properties
WITH v, properties(v) as properties
DETACH DELETE v
RETURN properties`, data);
return utils_1.format.from(r === null || r === void 0 ? void 0 : r.properties);
},

@@ -109,0 +115,0 @@ };

@@ -8,2 +8,10 @@ import type { Session } from "neo4j-driver";

};
export declare function client(session: Session): (statement: string, values?: any, options?: any) => Promise<any>;
export declare function client(session: Session): {
/** Reads values from the database */
read<T>(statement: string, values?: any): Promise<T | null>;
/**
* Reads/writes values from/to the database.
* Properties are available under `$data`
*/
write<T_1>(statement: string, values: T_1): Promise<any>;
};

@@ -47,34 +47,20 @@ "use strict";

function client(session) {
return async function query(statement, values, options) {
var _a;
let result;
// Database read or write transaction.
if ((options === null || options === void 0 ? void 0 : options.tx) === "read") {
result = await session.readTransaction((tx) => tx.run(statement, values));
}
else {
result = await session.writeTransaction((tx) => tx.run(statement, exports.format.to(values)));
}
// Following are different ways to return the data.
// 1️⃣ Return the single value or object from the database response.
if (!(options === null || options === void 0 ? void 0 : options.returnFormat)) {
return exports.format.from((_a = result === null || result === void 0 ? void 0 : result.records[0]) === null || _a === void 0 ? void 0 : _a.get(0)) || null;
}
// 2️⃣ Return multiple values or objects from the database response.
if (Array.isArray(options === null || options === void 0 ? void 0 : options.returnFormat)) {
const returnObject = {};
options === null || options === void 0 ? void 0 : options.returnFormat.forEach((returnKey) => {
var _a;
returnObject[returnKey] =
exports.format.from((_a = result === null || result === void 0 ? void 0 : result.records[0]) === null || _a === void 0 ? void 0 : _a.get(returnKey)) || null;
});
return returnObject;
}
// 3️⃣ Return the database data without any transforms.
if ((options === null || options === void 0 ? void 0 : options.returnFormat) === "raw") {
return result;
}
return null;
return {
/** Reads values from the database */
async read(statement, values) {
var _a, _b;
const result = await session.readTransaction((tx) => tx.run(statement, values));
return (_b = exports.format.from((_a = result === null || result === void 0 ? void 0 : result.records[0]) === null || _a === void 0 ? void 0 : _a.get(0))) !== null && _b !== void 0 ? _b : null;
},
/**
* Reads/writes values from/to the database.
* Properties are available under `$data`
*/
async write(statement, values) {
var _a;
const result = await session.writeTransaction((tx) => tx.run(statement, { data: exports.format.to(values) }));
return exports.format.from((_a = result === null || result === void 0 ? void 0 : result.records[0]) === null || _a === void 0 ? void 0 : _a.toObject());
},
};
}
exports.client = client;
{
"name": "@next-auth/neo4j-adapter",
"version": "0.1.1-pr.314-9c3d7ae5.299+9c3d7ae",
"version": "0.1.1-pr.314-f40ff972.300+f40ff97",
"description": "neo4j adapter for next-auth.",

@@ -46,3 +46,3 @@ "homepage": "https://next-auth.js.org",

},
"gitHead": "9c3d7ae57aa0e355b357fd65df31f28c4dab9931"
"gitHead": "f40ff9728e1d3c48ea59ca2695189f01d56b8068"
}
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