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

@live-change/user-service

Package Overview
Dependencies
Maintainers
1
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@live-change/user-service - npm Package Compare versions

Comparing version 0.2.25 to 0.2.26

combinations.js

23

index.js

@@ -10,2 +10,4 @@ const app = require("@live-change/framework").app()

require('./sessionOrUserItem.js')
require('./contactOrUserProperty.js')
require('./contactOrUserItem.js')

@@ -48,2 +50,6 @@ const Session = definition.foreignModel('session', 'Session')

if(!userData) throw 'userNotFound'
await service.trigger({
type: 'signedIn',
session, user
})
emit({

@@ -60,2 +66,7 @@ type: "signedIn",

if(!client.user) throw "notSignedIn"
await service.trigger({
type: 'signedOut',
session: client.session,
user: client.user
})
emit({

@@ -84,2 +95,6 @@ type: "signedOut",

}
await service.trigger({
type: 'signedIn',
session, user
})
emit([{

@@ -106,3 +121,11 @@ type: "created",

await service.trigger({
type: 'signedOut',
session: client.session, user: client.user
})
await service.trigger({
type: 'userDeleted',
user: client.user
})
await service.trigger({
type: 'userDeleted',
user

@@ -109,0 +132,0 @@ })

8

package.json
{
"name": "@live-change/user-service",
"version": "0.2.25",
"version": "0.2.26",
"description": "",

@@ -24,7 +24,7 @@ "main": "index.js",

"dependencies": {
"@live-change/framework": "0.5.27",
"@live-change/relations-plugin": "^0.5.20",
"@live-change/framework": "0.6.0",
"@live-change/relations-plugin": "0.6.0",
"pluralize": "8.0.0"
},
"gitHead": "4ccbe06b5a1ad1c46a907ac079e31a6d72a8591e"
"gitHead": "f3d7b9b6c689b9d87df3cb7f64cd75fc72339b7a"
}

@@ -33,2 +33,5 @@ const definition = require("./definition.js")

/// TODO: merge on signedIn trigger
/// TODO: delete on userDeleted trigger
if(config.ownerReadAccess) {

@@ -54,4 +57,3 @@ const viewName = 'my' + pluralize(modelName)

access(params, context) {
if(!context.client.user) return false
return config.userReadAccess ? config.userReadAccess(params, context) : true
return config.ownerReadAccess(params, context)
},

@@ -61,3 +63,3 @@ properties: App.rangeProperties,

const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
return modelRuntime().sortedIndexRangePath('byOwner' + sortFieldUc, owner, range)
return modelRuntime().sortedIndexRangePath('byOwner' + sortFieldUc, owner, App.extractRange(range))
}

@@ -64,0 +66,0 @@ })

@@ -5,3 +5,21 @@ const definition = require("./definition.js")

const { User } = require("./model.js")
const { allCombinations } = require("./combinations.js")
const pluralize = require('pluralize')
function createIdentifiersProperties(keys) {
const identifiers = {}
if(keys) for(const key of keys) {
identifiers[key] = {
type: String,
validation: ['nonEmpty']
}
identifiers[key + 'Type'] = {
type: String,
validation: ['nonEmpty']
}
}
return identifiers
}
definition.processor(function(service, app) {

@@ -13,4 +31,4 @@

if(model.sessionOrUserProperty) {
console.log("MODEL " + modelName + " IS SESSION OR USER PROPERTY, CONFIG:", model.userProperty)
if (model.properties.owner) throw new Error('owner property already exists!!!')
console.log("MODEL " + modelName + " IS SESSION OR USER PROPERTY, CONFIG:", model.sessionOrUserProperty)
if (model.properties.sessionOrUser) throw new Error('sessionOrUser property already exists!!!')

@@ -28,11 +46,25 @@ const originalModelProperties = { ...model.properties }

if(model.propertyOf) throw new Error("model " + modelName + " already have owner")
if(model.propertyOfAny) throw new Error("model " + modelName + " already have owner")
const extendedWith = config.extendedWith
? (Array.isArray(config.extendedWith) ? config.extendedWith : [config.extendedWith])
: []
model.propertyOfAny = {
...config
...config,
to: ['sessionOrUser', ...extendedWith]
}
if(config.ownerReadAccess) {
/// TODO: merge on signedIn trigger
/// TODO: delete on userDeleted trigger
if(config.ownerReadAccess) { // single item view
const viewName = 'my' + modelName
const identifiers = createIdentifiersProperties(extendedWith)
service.views[viewName] = new ViewDefinition({
name: viewName,
properties: {
...identifiers
},
access(params, context) {

@@ -43,2 +75,5 @@ return config.ownerReadAccess ? config.ownerReadAccess(params, context) : true

const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
for(const key of extendedWith) {
owner.push(params[key+'Type'], params[key])
}
const id = owner.map(p => JSON.stringify(p)).join(':')

@@ -50,2 +85,29 @@ return modelRuntime().path(id)

if(config.ownerReadAccess && config.extendedWith) {
const extendedCombinations = [[]].concat(allCombinations(extendedWith).slice(0, -1))
for(const combination of extendedCombinations) {
const propsUpperCase = combination.map(prop => prop[0].toUpperCase() + prop.slice(1))
const indexName = 'by' + (combination).map(prop => prop[0].toUpperCase() + prop.slice(1))
const viewName = 'my' + propsUpperCase.join('And') + pluralize(modelName)
const identifiers = createIdentifiersProperties(combination)
service.views[viewName] = new ViewDefinition({
name: viewName,
properties: {
...identifiers,
...App.rangeProperties,
},
access(params, context) {
return config.ownerReadAccess ? config.ownerReadAccess(params, context) : true
},
daoPath(params, {client, context}) {
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
for (const key of combination) {
owner.push(params[key + 'Type'], params[key])
}
return modelRuntime().indexRangePath(indexName, owner, App.extractRange(params) )
}
})
}
}
if(config.ownerViews) {

@@ -52,0 +114,0 @@ for(const view of config.userViews) {

@@ -33,2 +33,4 @@ const definition = require("./definition.js")

/// TODO: delete on userDeleted trigger
if(config.userReadAccess) {

@@ -35,0 +37,0 @@ const viewName = 'myUser' + pluralize(modelName)

@@ -32,2 +32,4 @@ const definition = require("./definition.js")

/// TODO: delete on userDeleted trigger
if(config.userReadAccess) {

@@ -34,0 +36,0 @@ const viewName = 'myUser' + modelName

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