@live-change/user-service 0.2.27 → 0.2.30

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.
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2019-2020 Michał Łaszczewski
1
+ Copyright 2019-2022 Michał Łaszczewski
2
2
 
3
3
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
@@ -39,6 +39,9 @@ definition.processor(function(service, app) {
39
39
  to: ['contactOrUser', ...extendedWith]
40
40
  }
41
41
 
42
+ const transferEventName = ['contactOrUser', ...(extendedWith.map(e => e[0].toUpperCase() + e.slice(1)))]
43
+ .join('And') + 'Owned' + modelName + 'Transferred'
44
+
42
45
  service.trigger({
43
46
  name: 'contactConnected',
44
47
  properties: {
@@ -58,8 +61,14 @@ definition.processor(function(service, app) {
58
61
  async execute({ contactType, contact, user }, { service }, emit) {
59
62
  const contactPath = [contactType, contact]
60
63
  const contactPropertyId = contactPath.map(p => JSON.stringify(p)).join(':')
61
- const contactProperty = await modelRuntime().get(contactPropertyId)
62
- if(contactProperty) {
64
+ const range = {
65
+ gte: contactPropertyId + '', // '' because it can be not-extended
66
+ lte: contactPropertyId + ':\xFF'
67
+ }
68
+ const contactProperties = await modelRuntime().rangeGet(range)
69
+ /// TODO: list based merge method
70
+ for(const contactProperty of contactProperties) {
71
+ console.log("CONTACT PROPERTY FOUND!", contactProperty, "MERGE =", config.merge)
63
72
  const userPath = ['user_User', user]
64
73
  const userPropertyId = userPath.map(p => JSON.stringify(p)).join(':')
65
74
  const userProperty = await modelRuntime().get(userPropertyId)
@@ -69,8 +78,8 @@ definition.processor(function(service, app) {
69
78
  emit({
70
79
  type: 'contactOrUserOwned' + modelName + 'Updated',
71
80
  identifiers: {
72
- ownerType: 'user_User',
73
- owner: user
81
+ contactOrUserType: 'user_User',
82
+ contactOrUser: user
74
83
  },
75
84
  data: mergeResult
76
85
  })
@@ -78,8 +87,8 @@ definition.processor(function(service, app) {
78
87
  emit({
79
88
  type: 'contactOrUserOwned' + modelName + 'Set',
80
89
  identifiers: {
81
- ownerType: 'user_User',
82
- owner: user
90
+ contactOrUserType: 'user_User',
91
+ contactOrUser: user
83
92
  },
84
93
  data: mergeResult
85
94
  })
@@ -87,21 +96,28 @@ definition.processor(function(service, app) {
87
96
  emit({
88
97
  type: 'contactOrUserOwned' + modelName + 'Reset',
89
98
  identifiers: {
90
- ownerType: contactType,
91
- owner: contact
99
+ contactOrUserType: contactType,
100
+ contactOrUser: contact
92
101
  }
93
102
  })
94
103
  } else {
95
104
  if(!userProperty) {
105
+ const extendedIdentifiers = {}
106
+ for(const key of extendedWith) {
107
+ extendedIdentifiers[key+'Type'] = contactProperty[key+'Type']
108
+ extendedIdentifiers[key] = contactProperty[key]
109
+ }
96
110
  emit({
97
- type: 'contactOrUserOwned' + modelName + 'Transferred',
111
+ type: transferEventName,
98
112
  from: {
99
- ownerType: contactType,
100
- owner: contact
113
+ contactOrUserType: contactType,
114
+ contactOrUser: contact,
115
+ ...extendedIdentifiers
101
116
  },
102
117
  to: {
103
- ownerType: 'user_User',
104
- owner: user
118
+ contactOrUserType: 'user_User',
119
+ contactOrUser: user,
120
+ ...extendedIdentifiers
105
121
  }
106
122
  })
107
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/user-service",
3
- "version": "0.2.27",
3
+ "version": "0.2.30",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,9 +21,9 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "0.6.0",
25
- "@live-change/relations-plugin": "0.6.0",
24
+ "@live-change/framework": "0.6.4",
25
+ "@live-change/relations-plugin": "0.6.3",
26
26
  "pluralize": "8.0.0"
27
27
  },
28
- "gitHead": "9a82ff0e7a7003d5b4e34ef9aef1ad4d7d8605dd"
28
+ "gitHead": "0a3acfcbb3a720c3e2f20bb3c9dc80a0a1aaceaa"
29
29
  }
package/README.md DELETED
@@ -1 +0,0 @@
1
- # user-service