Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1# Server Scripts
2
3This directory contains utility scripts for managing the Coop server.
4
5## get-invite-token.ts
6
7Retrieves the signup invite link for a user that was invited from the UI.
8
9### Usage
10
11From the `server` directory, run:
12
13```bash
14npm run get-invite -- --email "user@example.com"
15```
16
17### Parameters
18
19- `--email`: Email address of the invited user (required)
20
21### Output
22
23The script will display:
24- Invite details (email, role, org ID, created date)
25- **Signup URL** - The full URL to complete signup
26
27### Example Output
28
29```
30✅ Invite Token Found!
31
32════════════════════════════════════════════════════════════
33Invite Details:
34════════════════════════════════════════════════════════════
35Email: user@example.com
36Role: MODERATOR
37Organization: abc123xyz
38Created At: 2025-12-10T20:15:30.000Z
39
40════════════════════════════════════════════════════════════
41🔗 Signup URL:
42════════════════════════════════════════════════════════════
43
44http://localhost:3000/signup/a1b2c3d4e5f6...
45
46Copy this URL and paste it in your browser to sign up.
47════════════════════════════════════════════════════════════
48```
49
50### Notes
51
52- Invite tokens are stored in the `public.invite_user_tokens` table.
53- Emails are normally sent to new users, but require SENDGRID token for this.
54- The script shows the most recent invite for the given email.
55
56---
57
58## create-org-and-user.ts
59
60Creates a new organization with an admin user and generates an API key.
61
62### Usage
63
64From the `server` directory, run:
65
66```bash
67npm run create-org -- \
68 --name "My Organization" \
69 --email "admin@example.com" \
70 --website "https://example.com" \
71 --firstName "John" \
72 --lastName "Doe" \
73 --password "testpassword123"
74```
75
76### Parameters
77
78All parameters are required:
79
80- `--name`: Organization name (must be unique)
81- `--email`: Admin user email (must be unique)
82- `--website`: Organization website URL (must be a valid URL)
83- `--firstName`: Admin user's first name
84- `--lastName`: Admin user's last name
85- `--password`: Admin user's password (minimum 8 characters recommended)
86
87### Output
88
89The script will output:
90- Organization ID
91- Organization details (name, email, website)
92- Admin user ID and details
93- **API Key** - This is only shown once! Copy and store it securely.
94
95### Example Output
96
97```
98✅ Organization and admin user created successfully!
99
100════════════════════════════════════════════════════════════
101Organization Details:
102════════════════════════════════════════════════════════════
103Organization ID: abc123xyz
104Organization Name: My Organization
105Organization Email: admin@example.com
106Website URL: https://example.com
107
108════════════════════════════════════════════════════════════
109Admin User Details:
110════════════════════════════════════════════════════════════
111User ID: user456def
112Name: John Doe
113Email: admin@example.com
114Role: ADMIN
115
116════════════════════════════════════════════════════════════
117🔑 API KEY (STORE THIS SECURELY!)
118════════════════════════════════════════════════════════════
119
120New API key generated successfully! Please copy and store it securely.
121
122API Key: ABC123-XYZ789-DEF456-GHI012
123
124⚠️ This API key will not be shown again. Save it now!
125════════════════════════════════════════════════════════════
126```
127
128### What Gets Created
129
130The script performs the following actions:
131
1321. **Creates an Organization** with the provided details
1332. **Generates an API Key** for the organization
1343. **Creates Signing Keys** for JWT token verification
1354. **Initializes Organization Settings**:
136 - Default user type for moderation
137 - Default user interface settings
138 - Default organization settings
139 - Default manual review tool settings
1405. **Creates an Admin User** with:
141 - Password login method enabled
142 - Admin role permissions
143 - Approved status
144
145### Notes
146
147- The API key is only displayed once. Make sure to copy and store it securely.
148- The organization name and email must be unique in the database.
149- The password should be strong and at least 8 characters long.
150- All database connections are properly closed after the script completes.
151
152### Troubleshooting
153
154If the script fails:
155- Check that your database connection is configured correctly in `.env`
156- Verify that the organization name and email don't already exist
157- Ensure the website URL is valid (must start with `http://` or `https://`)
158- Check the console output for specific error messages
159