@ossy/users 1.5.2 → 1.5.3
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/package.json +2 -2
- package/src/users.startup.js +38 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/users",
|
|
3
3
|
"description": "User domain — aggregate, events, and validators for the Ossy user model",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.js",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"/src",
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "b8cbdc545a659e96af8948aa08a89316a2c2d193"
|
|
29
29
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Aggregate } from '@ossy/event-store'
|
|
2
|
+
import { UsersEvents, User } from './index.js'
|
|
3
|
+
|
|
4
|
+
export const id = 'create-bot-user'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Ensures the system bot user exists in the event store.
|
|
8
|
+
* Reads BOT_USER_EMAIL and BOT_USER_ID from env (with sensible defaults).
|
|
9
|
+
*
|
|
10
|
+
* @param {{ env: NodeJS.ProcessEnv }} options
|
|
11
|
+
*/
|
|
12
|
+
export async function run ({ env }) {
|
|
13
|
+
const botEmail = env.BOT_USER_EMAIL || 'ossybot@ossy.se'
|
|
14
|
+
const botUserId = env.BOT_USER_ID || 'Mil5qAL7jDFCTyuKD_BKb'
|
|
15
|
+
|
|
16
|
+
console.log('[users.startup][create-bot-user] Starting bot user creation script')
|
|
17
|
+
|
|
18
|
+
const existing = await Aggregate.Collection.findOne({
|
|
19
|
+
type: 'User',
|
|
20
|
+
'state.email': botEmail,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
if (existing?.state?.id === botUserId) {
|
|
24
|
+
console.log('[users.startup][create-bot-user] Bot user already exists')
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.log('[users.startup][create-bot-user] No bot user found, creating')
|
|
29
|
+
|
|
30
|
+
const signedUpEvent = UsersEvents.SignedUp({
|
|
31
|
+
type: 'Bot',
|
|
32
|
+
email: botEmail,
|
|
33
|
+
userId: botUserId,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
await Aggregate.Of(User, signedUpEvent)
|
|
37
|
+
console.log('[users.startup][create-bot-user] Bot user created')
|
|
38
|
+
}
|