@joystick.js/node-canary 0.0.0-canary.437 → 0.0.0-canary.439
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import i from"../databases/queries/accounts.js";import m from"../../lib/camel_pascal_to_snake.js";import u from"../databases/postgresql/accounts/create_accounts_metadata_table_columns.js";import l from"../databases/database_type_map.js";import f from"./generate_account_session.js";import w from"../api/get_output.js";import
|
|
1
|
+
import i from"../databases/queries/accounts.js";import m from"../../lib/camel_pascal_to_snake.js";import u from"../databases/postgresql/accounts/create_accounts_metadata_table_columns.js";import l from"../databases/database_type_map.js";import f from"./generate_account_session.js";import w from"../api/get_output.js";import y from"../databases/get_target_database_connection.js";import g from"../../lib/hash_string.js";import p from"./roles/index.js";import n from"../../lib/types.js";const b=(e=null,s=null)=>i("add_session",{user_id:e,session:s}),h=(e="")=>i("user",{_id:e}),x=async(e={})=>i("create_user",e),_=(e={})=>Object.entries(e||{}).reduce((s={},[r,a])=>(s[m(r)]=a,s),{}),E=async(e={})=>{const s=y("users"),r=l[s?.provider];let a={password:g(e.password)};if((e?.email_address||e?.emailAddress)&&(a.emailAddress=e?.email_address||e.emailAddress),e?.username&&(a.username=e?.username),e?.metadata&&n.is_object(e.metadata)&&r==="sql"){const t=_(e.metadata);await u(s,t);const d={...e?.metadata||{}};d?.roles&&delete d.roles,a={..._(d),...a}}if(e?.metadata&&n.is_object(e.metadata)&&r==="nosql"){let t={...e?.metadata||{}};t?.roles&&delete t.roles,a={...t||{},...a}}return a},j=(e="",s="")=>i("existing_user",{email_address:e,username:s}),v=async(e={})=>{if(!e.email_address&&!e.emailAddress)throw new Error("Email address is required.");if(!e.password)throw new Error("Password is required.");const s=await j(e.email_address||e.emailAddress,e?.username);if(s&&process.env.NODE_ENV!=="test")throw new Error(`A user with the ${s.existing_username?"username":"email address"} ${s.existing_username||s.existing_email_address} already exists.`);let r,a=s?._id||s?.user_id;s||(r=await E(e),a=await x(r));const t=await h(a),d=f();if(a&&await b(a,d),e?.metadata?.roles?.length>0&&process.env.NODE_ENV==="test")for(let o=0;o<e?.metadata?.roles?.length;o+=1){const c=e?.metadata?.roles[o];p.grant(t?.user_id,c)}return(n.is_function(process.joystick?.app_options?.accounts?.events?.onSignup)||n.is_function(process.joystick?.app_options?.accounts?.events?.on_signup))&&(process.joystick?.app_options?.accounts?.events?.onSignup||process.joystick?.app_options?.accounts?.events?.on_signup)({...d,user_id:a,userId:a,user:t}),{...d,userId:a,user_id:a,user:w(t,e?.output)}};var z=v;export{z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import r from"cluster";import n from"os";const p=(c=null)=>{const t=n.cpus().length;if(r.isPrimary){for(let s=0;s<t;s++){const e=r.fork();e.process.joystick_process=s+1,e.on("message",o=>{process.send&&process.send(o)}),process.on("message",o=>{e.send(o)})}r.on("exit",s=>{console.warn(`Worker ${s.process.pid} died.`)})}else c()};var d=p;export{d as default};
|
package/package.json
CHANGED
|
@@ -36,7 +36,7 @@ const get_user_to_create = async (options = {}) => {
|
|
|
36
36
|
password: hash_string(options.password),
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
if (options?.email_address) {
|
|
39
|
+
if (options?.email_address || options?.emailAddress) {
|
|
40
40
|
user.emailAddress = options?.email_address || options.emailAddress;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -88,7 +88,7 @@ const get_existing_user = (email_address = "", username = "") => {
|
|
|
88
88
|
return accounts_query("existing_user", { email_address, username });
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
const signup = async (signup_options) => {
|
|
91
|
+
const signup = async (signup_options = {}) => {
|
|
92
92
|
if (!signup_options.email_address && !signup_options.emailAddress) {
|
|
93
93
|
throw new Error("Email address is required.");
|
|
94
94
|
}
|
|
@@ -8,6 +8,11 @@ const start_node_as_cluster = (callback = null) => {
|
|
|
8
8
|
for (let i = 0; i < cpus; i++) {
|
|
9
9
|
const worker = cluster.fork();
|
|
10
10
|
|
|
11
|
+
// NOTE: Intentionally track the worker index on its process so we can
|
|
12
|
+
// check for a primary in our code (e.g., when running cluster of an app that
|
|
13
|
+
// has code we only want to run on 1/X workers, not all workers).
|
|
14
|
+
worker.process.joystick_process= i +1;
|
|
15
|
+
|
|
11
16
|
worker.on("message", (message) => {
|
|
12
17
|
if (process.send) {
|
|
13
18
|
process.send(message);
|