New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@live-change/user-service

Package Overview
Dependencies
Maintainers
1
Versions
274
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.26 to 0.2.27

utils.js

69

contactOrUserProperty.js

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

const { User } = require("./model.js")
const { allCombinations } = require("./combinations.js")
const { createIdentifiersProperties } = require('./utils.js')
const pluralize = require('pluralize')
definition.processor(function(service, app) {

@@ -14,3 +18,3 @@

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

@@ -28,5 +32,12 @@ 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: ['contactOrUser', ...extendedWith]
}

@@ -62,3 +73,3 @@

emit({
type: 'ownerOwned' + modelName + 'Updated',
type: 'contactOrUserOwned' + modelName + 'Updated',
identifiers: {

@@ -72,3 +83,3 @@ ownerType: 'user_User',

emit({
type: 'ownerOwned' + modelName + 'Set',
type: 'contactOrUserOwned' + modelName + 'Set',
identifiers: {

@@ -82,3 +93,3 @@ ownerType: 'user_User',

emit({
type: 'ownerOwned' + modelName + 'Reset',
type: 'contactOrUserOwned' + modelName + 'Reset',
identifiers: {

@@ -92,3 +103,3 @@ ownerType: contactType,

emit({
type: 'ownerOwned' + modelName + 'Transferred',
type: 'contactOrUserOwned' + modelName + 'Transferred',
from: {

@@ -109,6 +120,10 @@ ownerType: contactType,

if(config.ownerReadAccess) {
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) {

@@ -119,2 +134,5 @@ return context.client.user && (config.ownerReadAccess ? config.ownerReadAccess(params, context) : true)

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

@@ -126,2 +144,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 context.client.user && (config.ownerReadAccess ? config.ownerReadAccess(params, context) : true)
},
daoPath(params, { client, context }) {
const owner = ['user_User', client.user]
for (const key of combination) {
owner.push(params[key + 'Type'], params[key])
}
return modelRuntime().indexRangePath(indexName, owner, App.extractRange(params) )
}
})
}
}
if(config.ownerViews) {

@@ -146,4 +191,8 @@ for(const view of config.userViews) {

const eventPrefix = ['contactOrUser',
...(extendedWith.map(p => p[0].toUpperCase()+p.slice(1)))
].join('And') +'Owned'
if(config.ownerSetAccess || config.ownerWriteAccess) {
const eventName = 'ownerOwned' + modelName + 'Set'
const eventName = eventPrefix + modelName + 'Set'
const actionName = 'setMy' + modelName

@@ -185,3 +234,3 @@ service.actions[actionName] = new ActionDefinition({

if(config.ownerUpdateAccess || config.ownerWriteAccess) {
const eventName = 'ownerOwned' + modelName + 'Updated'
const eventName = eventPrefix + modelName + 'Updated'
const actionName = 'updateMy' + modelName

@@ -227,3 +276,3 @@ service.actions[actionName] = new ActionDefinition({

if(config.ownerResetAccess || config.ownerWriteAccess) {
const eventName = 'ownerOwned' + modelName + 'Reset'
const eventName = eventPrefix + modelName + 'Reset'
const actionName = 'resetMy' + modelName

@@ -230,0 +279,0 @@ service.actions[actionName] = new ActionDefinition({

4

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

@@ -28,3 +28,3 @@ "main": "index.js",

},
"gitHead": "f3d7b9b6c689b9d87df3cb7f64cd75fc72339b7a"
"gitHead": "9a82ff0e7a7003d5b4e34ef9aef1ad4d7d8605dd"
}

@@ -6,19 +6,6 @@ const definition = require("./definition.js")

const { allCombinations } = require("./combinations.js")
const { createIdentifiersProperties } = require('./utils.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
}

@@ -98,3 +85,3 @@ definition.processor(function(service, app) {

},
daoPath(params, {client, context}) {
daoPath(params, { client, context }) {
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]

@@ -129,4 +116,8 @@ for (const key of combination) {

const eventPrefix = ['sessionOrUser',
...(extendedWith.map(p => p[0].toUpperCase()+p.slice(1)))
].join('And') +'Owned'
if(config.ownerSetAccess || config.ownerWriteAccess) {
const eventName = 'ownerOwned' + modelName + 'Set'
const eventName = eventPrefix + modelName + 'Set'
const actionName = 'setMy' + modelName

@@ -170,3 +161,3 @@ service.actions[actionName] = new ActionDefinition({

if(config.ownerUpdateAccess || config.ownerWriteAccess) {
const eventName = 'ownerOwned' + modelName + 'Updated'
const eventName = eventPrefix + modelName + 'Updated'
const actionName = 'updateMy' + modelName

@@ -214,3 +205,3 @@ service.actions[actionName] = new ActionDefinition({

if(config.ownerResetAccess || config.ownerWriteAccess) {
const eventName = 'ownerOwned' + modelName + 'Reset'
const eventName = eventPrefix + modelName + 'Reset'
const actionName = 'resetMy' + modelName

@@ -217,0 +208,0 @@ service.actions[actionName] = new ActionDefinition({

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