@ztimson/momentum 0.53.1 → 0.58.0

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.
Files changed (86) hide show
  1. package/README.md +200 -148
  2. package/bin/build-models.mjs +28 -37
  3. package/dist/actions.d.ts +32 -43
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/ai.d.ts +38 -17
  6. package/dist/ai.d.ts.map +1 -1
  7. package/dist/analytics.d.ts +169 -36
  8. package/dist/analytics.d.ts.map +1 -1
  9. package/dist/api.d.ts +22 -22
  10. package/dist/api.d.ts.map +1 -1
  11. package/dist/asset-controller.d.ts +92 -0
  12. package/dist/asset-controller.d.ts.map +1 -0
  13. package/dist/audit.d.ts +22 -0
  14. package/dist/audit.d.ts.map +1 -0
  15. package/dist/auth.d.ts +39 -92
  16. package/dist/auth.d.ts.map +1 -1
  17. package/dist/call.d.ts +39 -0
  18. package/dist/call.d.ts.map +1 -0
  19. package/dist/captcha.d.ts +14 -0
  20. package/dist/captcha.d.ts.map +1 -0
  21. package/dist/client.d.ts +44 -33
  22. package/dist/client.d.ts.map +1 -1
  23. package/dist/core.d.ts +50 -21
  24. package/dist/core.d.ts.map +1 -1
  25. package/dist/data.d.ts +59 -77
  26. package/dist/data.d.ts.map +1 -1
  27. package/dist/dialog.d.ts +11 -0
  28. package/dist/dialog.d.ts.map +1 -0
  29. package/dist/discounts.d.ts +8 -12
  30. package/dist/discounts.d.ts.map +1 -1
  31. package/dist/email.d.ts +19 -19
  32. package/dist/email.d.ts.map +1 -1
  33. package/dist/forms.d.ts +6 -13
  34. package/dist/forms.d.ts.map +1 -1
  35. package/dist/groups.d.ts +22 -16
  36. package/dist/groups.d.ts.map +1 -1
  37. package/dist/index.d.ts +13 -3
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +4446 -0
  40. package/dist/index.mjs +3422 -1731
  41. package/dist/logger.d.ts +78 -48
  42. package/dist/logger.d.ts.map +1 -1
  43. package/dist/momentum.d.ts +69 -15
  44. package/dist/momentum.d.ts.map +1 -1
  45. package/dist/momentum.worker.d.mts +2 -0
  46. package/dist/momentum.worker.d.mts.map +1 -0
  47. package/dist/momentum.worker.mjs +103 -0
  48. package/dist/notifications.d.ts +39 -0
  49. package/dist/notifications.d.ts.map +1 -0
  50. package/dist/pdf.d.ts +31 -14
  51. package/dist/pdf.d.ts.map +1 -1
  52. package/dist/products.d.ts +47 -0
  53. package/dist/products.d.ts.map +1 -0
  54. package/dist/routes.d.ts +40 -0
  55. package/dist/routes.d.ts.map +1 -0
  56. package/dist/schemas.d.ts +79 -0
  57. package/dist/schemas.d.ts.map +1 -0
  58. package/dist/settings.d.ts +30 -14
  59. package/dist/settings.d.ts.map +1 -1
  60. package/dist/sms.d.ts +14 -0
  61. package/dist/sms.d.ts.map +1 -0
  62. package/dist/sockets.d.ts +21 -10
  63. package/dist/sockets.d.ts.map +1 -1
  64. package/dist/static.d.ts +4 -2
  65. package/dist/static.d.ts.map +1 -1
  66. package/dist/storage.d.ts +103 -24
  67. package/dist/storage.d.ts.map +1 -1
  68. package/dist/templates.d.ts +23 -0
  69. package/dist/templates.d.ts.map +1 -0
  70. package/dist/tokens.d.ts +50 -0
  71. package/dist/tokens.d.ts.map +1 -0
  72. package/dist/totp.d.ts +45 -0
  73. package/dist/totp.d.ts.map +1 -0
  74. package/dist/transactions.d.ts +153 -0
  75. package/dist/transactions.d.ts.map +1 -0
  76. package/dist/users.d.ts +63 -25
  77. package/dist/users.d.ts.map +1 -1
  78. package/dist/webRtc.d.ts +39 -0
  79. package/dist/webRtc.d.ts.map +1 -0
  80. package/package.json +53 -43
  81. package/dist/index.cjs +0 -2755
  82. package/dist/momentum.worker.js +0 -16
  83. package/dist/payments.d.ts +0 -184
  84. package/dist/payments.d.ts.map +0 -1
  85. package/dist/phone.d.ts +0 -19
  86. package/dist/phone.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,148 +1,200 @@
1
- <!-- Header -->
2
- <div id="top" align="center">
3
- <br />
4
-
5
- <!-- Logo -->
6
- <img src="server/public/favicon.png" alt="Logo" width="200" height="200">
7
-
8
- <!-- Title -->
9
- ### Momentum
10
-
11
- <!-- Description -->
12
- Enterprise Record Management
13
-
14
- <!-- Repo badges -->
15
- [![Version](https://img.shields.io/badge/dynamic/json.svg?label=Version&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/momentum/tags%3Ftoken%3D35a3bf73a216782a7435f86117412bcb9784b716&query=$[0].name)](https://git.zakscode.com/ztimson/momentum/tags)
16
- [![Pull Requests](https://img.shields.io/badge/dynamic/json.svg?label=Pull%20Requests&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/momentum%3Ftoken%3D35a3bf73a216782a7435f86117412bcb9784b716&query=open_pr_counter)](https://git.zakscode.com/ztimson/momentum/pulls)
17
- [![Issues](https://img.shields.io/badge/dynamic/json.svg?label=Issues&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/momentum%3Ftoken%3D35a3bf73a216782a7435f86117412bcb9784b716&query=open_issues_count)](https://git.zakscode.com/ztimson/momentum/issues)
18
-
19
- <!-- Links -->
20
-
21
- ---
22
- <div>
23
- <a href="https://git.zakscode.com/ztimson/momentum/wiki" target="_blank">Documentation</a>
24
- • <a href="https://git.zakscode.com/ztimson/momentum/releases" target="_blank">Release Notes</a>
25
- • <a href="https://git.zakscode.com/ztimson/momentum/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
26
- • <a href="https://git.zakscode.com/ztimson/momentum/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
27
- </div>
28
-
29
- ---
30
- </div>
31
-
32
- ## Table of Contents
33
- - [Momentum](#top)
34
- - [About](#about)
35
- - [Built With](#built-with)
36
- - [Setup](#setup)
37
- - [Production](#production)
38
- - [Development](#development)
39
- - [License](#license)
40
-
41
- ## About
42
-
43
- Momentum is a self-hosted enterprise resource planning tool. What does that mean? Think something similar to [Firebase](https://firebase.google.com) but you are in full control of your data & services.
44
-
45
- It was developed as a generic backend to add functionality to single page applications such as angular, react, svelte or vue. Momentum comes with a client library to make integration extremely easy.
46
-
47
- Momentum also comes with a management interface to allow easy administration of momentum without having to build anything.
48
-
49
- Features include:
50
- - Actions
51
- - Write server side code to create custom functionality
52
- - Writen with javascript & the momentum client library to minimize the learning curve
53
- - Custom library and can be installed & accessed from actions using Docker & NPM
54
- - Trigger actions including CRONs, RESTFUL requests & system events
55
- - Extremely fast
56
- - Authentication
57
- - Manage users with custom values
58
- - Manage groups with cascading permissions & custom values
59
- - Token management for 3rd party applications
60
- - Full permission system which supports custom values
61
- - Account validation & reset emails
62
- - Optional public registration form
63
- - OAuth support for custom applications
64
- - Custom password strength rules
65
- - Two-Factor Authentication
66
- - Data
67
- - Edit database like an Excel table
68
- - Create custom forms & reports to interact with data
69
- - Interact with data through the REST API
70
- - Granular collection & document level permissions
71
- - Automatic metadata tracking
72
- - Easy import/export to CSV, Excel & JSON
73
- - Logs
74
- - Save & view server logs through the UI for easy debugging
75
- - Submit client logs to momentum to aid in remote debugging
76
- - Client logs come with device information such as user agent & screen size
77
- - Storage
78
- - Storage anything with momentum storage
79
- - Built in filebrowser
80
- - Upload & download files with the API
81
- - Full file permissions
82
- - Automatic metadata tracking
83
- - Static File Server
84
- - Host your single page application using Momentum for easy hosting
85
- - Configurable routing
86
- - Settings
87
- - Full theming & white label support
88
- - Manage the server through variables which can be changed at runtime
89
- - Create & use custom variables for your application
90
- - Miscellaneous
91
- - Automatically turn website into Progressive Web App
92
- - Caching & offline support built into the client library
93
- - Socket support to keep all clients in sync automatically
94
- - Generate PDFs from templates, HTML or links
95
- - SMTP support to send emails from templates
96
- - Twilio support to manage texts & calls
97
- - Stripe support to handle payments & subscriptions
98
-
99
- ### Built With
100
- [![Docker](https://img.shields.io/badge/Docker-384d54?style=for-the-badge&logo=docker)](https://docker.com/)
101
- [![MongoDB](https://img.shields.io/badge/mongodb-000000?style=for-the-badge&logo=mongodb)](https://www.mongodb.com/)
102
- [![Node](https://img.shields.io/badge/Node.js-000000?style=for-the-badge&logo=nodedotjs)](https://nodejs.org/)
103
- [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white)](https://typescriptlang.org/)
104
-
105
- ## Setup
106
-
107
- <details>
108
- <summary>
109
- <h3 id="production" style="display: inline">Production</h3>
110
- </summary>
111
-
112
- #### Prerequisites
113
- - [Docker](https://docs.docker.com/install/)
114
-
115
- #### Instructions
116
- 1. _Optional: Use momentum to host your [static site](https://git.zakscode.com/ztimson/momentum/wiki/Static)_
117
- 2. Download the [docker-compose](https://git.zakscode.com/ztimson/momentum/src/branch/develop/docker-compose.yml) file: `curl -o momentum.yaml https://git.zakscode.com/ztimson/momentum/raw/branch/develop/docker-compose.yml`
118
- 3. Configure the [Environment Variables](https://git.zakscode.com/ztimson/momentum/wiki/Environment-Variables) inside the docker-compose
119
- 4. Start the server with: `docker-compose up -f momentum.yaml`
120
- 5. Open http://localhost:80
121
- - Default login: `admin/admin`
122
- - Configure [System Variables](https://git.zakscode.com/ztimson/momentum/wiki/System-Variables)
123
-
124
- </details>
125
-
126
- <details>
127
- <summary>
128
- <h3 id="development" style="display: inline">Development</h3>
129
- </summary>
130
-
131
- #### Prerequisites
132
- - [Docker](https://docs.docker.com/install/)
133
- - [Node.js](https://nodejs.org/en/download)
134
-
135
- #### Instructions
136
- 1. Install the dependencies: `npm install`
137
- 2. Start MongoDB: `docker-compose up db`
138
- 3. Start the dev server: `npm run start`
139
- 4. Open http://localhost:3000
140
- - Default login: `admin/admin`
141
- - Configure [System Variables](https://git.zakscode.com/ztimson/momentum/wiki/System-Variables)
142
-
143
- </details>
144
-
145
- ## License
146
- Copyright © 2024 Zakary Timson | All Rights Reserved
147
-
148
- See the [license](./LICENSE) for more information.
1
+ <!-- Header -->
2
+ <div id="top" align="center">
3
+ <br />
4
+
5
+ <!-- Logo -->
6
+ <img src="https://momentum.zakscode.com/favicon.png" alt="Logo" width="200" height="200">
7
+
8
+ <!-- Title -->
9
+ ### Momentum
10
+
11
+ <!-- Description -->
12
+ Enterprise Record Management
13
+
14
+ <!-- Repo badges -->
15
+ [![Version](https://img.shields.io/badge/dynamic/json.svg?label=Version&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/momentum/momentum/tags%3Ftoken%3D35a3bf73a216782a7435f86117412bcb9784b716&query=$[0].name)](https://git.zakscode.com/momentum/momentum/tags)
16
+ [![Pull Requests](https://img.shields.io/badge/dynamic/json.svg?label=Pull%20Requests&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/momentum/momentum%3Ftoken%3D35a3bf73a216782a7435f86117412bcb9784b716&query=open_pr_counter)](https://git.zakscode.com/momentum/momentum/pulls)
17
+ [![Issues](https://img.shields.io/badge/dynamic/json.svg?label=Issues&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/momentum/momentum%3Ftoken%3D35a3bf73a216782a7435f86117412bcb9784b716&query=open_issues_count)](https://git.zakscode.com/momentum/momentum/issues)
18
+
19
+ <!-- Links -->
20
+
21
+ ---
22
+ <div>
23
+ <a href="https://git.zakscode.com/momentum/momentum/wiki" target="_blank">Documentation</a>
24
+ • <a href="https://git.zakscode.com/momentum/momentum/releases" target="_blank">Release Notes</a>
25
+ • <a href="https://git.zakscode.com/momentum/momentum/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
26
+ • <a href="https://git.zakscode.com/momentum/momentum/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
27
+ </div>
28
+
29
+ ---
30
+ </div>
31
+
32
+ ## Table of Contents
33
+ - [Momentum](#top)
34
+ - [About](#about)
35
+ - [Built With](#built-with)
36
+ - [Setup](#setup)
37
+ - [Production](#production)
38
+ - [Development](#development)
39
+ - [License](#license)
40
+
41
+ ## About
42
+
43
+ https://momentum.zakscode.com
44
+
45
+ Momentum is a self-hosted _Enterprise Resource Planning_ (ERP) tool. What does that mean? We can help you run your businesses day-to-day operations by storing, automating & coordinating your data & information; from any location or server.
46
+
47
+ While several businesses might deliver the same final product as your business, what sets you apart is your institutional knowledge and unique execution. However, most of this is
48
+ lost when businesses are forced to conform to software and not the other way around. This is where Momentum is different.
49
+
50
+ Momentum delivers several feature-packed modules to cover every software need and an intuitive _Content Management System_ (CMS) to connect features as needed.
51
+ And with the built-in AI or a programmer you can build & integrate custom apps and websites in seconds.
52
+
53
+ Here at ZaksCode we believe the current standard software is held to is pitiful. We aim to keep your business by being the best, not vendor lock-in practices.
54
+ Not only do we offer the most features and the best experience, but we do so while being the smallest, fastest, most efficient & secure ERP system out there.
55
+
56
+ Features include:
57
+ - Actions
58
+ - Write server side code to "mod" Momentum & create custom functionality
59
+ - Writen with javascript & the momentum client library to minimize the learning curve
60
+ - Custom library and can be installed & accessed from actions using Docker & NPM
61
+ - Trigger actions via events, CRONs or REST requests
62
+ - Kept in memory for high performance and 0 cold start time
63
+ - AI
64
+ - Ask the assistant questions about your records
65
+ - Automate your workflow and use AI to process data & files automatically
66
+ - Use the AI to build actions, apps & websites with momentum integration
67
+ - Local / Offline ASR & OCR models to extract text from most file types (text, image, pdf, audio, video)
68
+ - Local or remote LLM models
69
+ - Analytics
70
+ - Track device specs & performance
71
+ - Track IP addresses and trace on demand (not stored)
72
+ - Track a user journey (which pages are visited for how long)
73
+ - Track referrers & ad campaigns
74
+ - Track conversion rates & custom metrics tracking
75
+ - UI for viewing all data & running custom reports
76
+ - Authentication
77
+ - Manage users with custom values
78
+ - Manage groups with cascading permissions & custom values
79
+ - Token management for 3rd party applications
80
+ - Full permission system with custom permissions support
81
+ - Account validation & reset emails
82
+ - Optional public registration form
83
+ - Host OAuth portal for custom application login
84
+ - Custom password strength & rotation settings
85
+ - Two-Factor Authentication
86
+ - OAuth & LDAP support
87
+ - Data
88
+ - Advanced search
89
+ - Edit database like an Excel spreadsheet
90
+ - Conditional styling
91
+ - Calculate columns with excel formulas or javascript
92
+ - Granular collection & record level permissions
93
+ - Automatic metadata & history tracking
94
+ - Easy import/export to CSV, Excel & JSON
95
+ - Forms
96
+ - Create forms that integrate with database
97
+ - Create custom reports with graphs, maps & more
98
+ - Granular permissions
99
+ - Logs
100
+ - Save & view server logs for easy debugging
101
+ - Submit logs to track remote environments
102
+ - Capture remote device specs for debugging
103
+ - Unlimited remote logging channels
104
+ - Local logs for debugging mobile devices
105
+ - All changes are recorded and can be reverted
106
+ - Messaging
107
+ - Send emails with SMTP
108
+ - Send notifications to apps
109
+ - Phone call & SMS integration with Twilio
110
+ - Supports WebRTC with built-in STUN/TURN server for video/voice calls
111
+ - Payments
112
+ - Stripe support to handle payments & subscriptions
113
+ - Manage products through spreadsheets
114
+ - Easy form & report integration
115
+ - Create custom discount codes
116
+ - Automatic taxes
117
+ - Storage
118
+ - Store files
119
+ - Share files with any user/group
120
+ - Built-in filebrowser with drag & drop
121
+ - Automatic metadata tracking
122
+ - Full file/folder permissions
123
+ - Static File Server
124
+ - Host your web applications with the API
125
+ - Built-in filebrowser with drag & drop
126
+ - Automatic metadata tracking
127
+ - Configurable routing
128
+ - Settings
129
+ - Full theming & white label support
130
+ - Manage the server through variables which can be changed at runtime
131
+ - Create & use custom variables for your application
132
+ - Miscellaneous
133
+ - CCPA / GDPR / PIPEDA compliant
134
+ - Configurable Terms of Service & Privacy Policy
135
+ - Automatic notifications/SMS/call/email alerts
136
+ - Generate PDFs from templates, forms, pages or HTML
137
+ - Turn any website into an offline mobile/desktop app
138
+ - Caching & offline support built in
139
+ - Live collaborative editing
140
+ - All features support REST for easy integration with websites & apps
141
+ - Writen documentation & OpenApi docs
142
+ - Extremely light weight & small
143
+ - Configurable endpoint protection with rate limiting & CAPTCHA bot detection
144
+ - Handles thousands of requests per second per instance while losing < 1GB of RAM
145
+ - Prometheus metrics
146
+
147
+ ### Built With
148
+ [![Docker](https://img.shields.io/badge/Docker-384d54?style=for-the-badge&logo=docker)](https://docker.com/)
149
+ [![MongoDB](https://img.shields.io/badge/mongodb-000000?style=for-the-badge&logo=mongodb)](https://www.mongodb.com/)
150
+ [![Node](https://img.shields.io/badge/Node.js-000000?style=for-the-badge&logo=nodedotjs)](https://nodejs.org/)
151
+ [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white)](https://typescriptlang.org/)
152
+
153
+ ## Setup
154
+
155
+ <details>
156
+ <summary>
157
+ <h3 id="production" style="display: inline">Production</h3>
158
+ </summary>
159
+
160
+ #### Prerequisites
161
+ - [Docker](https://docs.docker.com/install/)
162
+
163
+ #### Instructions
164
+ 1. _Optional: Use momentum to host your [static site](https://git.zakscode.com/momentum/momentum/wiki/Static)_
165
+ 2. Download the [docker-compose](https://git.zakscode.com/momentum/momentum/src/branch/develop/docker-compose.yml) file: `curl -o momentum.yaml https://git.zakscode.com/momentum/momentum/raw/branch/develop/docker-compose.yml`
166
+ 3. Configure the [Environment Variables](https://git.zakscode.com/momentum/momentum/wiki/Environment-Variables) inside the docker-compose
167
+ 4. Start the server with: `docker-compose up -f momentum.yaml`
168
+ 5. Open http://localhost:80
169
+ - Default login: `admin/admin`
170
+ - Configure [System Variables](https://git.zakscode.com/ztimson/momentum/wiki/System-Variables)
171
+
172
+ </details>
173
+
174
+ <details>
175
+ <summary>
176
+ <h3 id="development" style="display: inline">Development</h3>
177
+ </summary>
178
+
179
+ #### Prerequisites
180
+ - [Docker](https://docs.docker.com/install/)
181
+ - [Node.js](https://nodejs.org/en/download)
182
+
183
+ ##### Optional
184
+ - _[ffmpeg](https://ffmpeg.org/download.html) (Video utilities)_
185
+ - _[Whisper](https://github.com/ggml-org/whisper.cpp/releases/tag/v1.7.6) (Audio -> Text)_
186
+
187
+ #### Instructions
188
+ 1. Install the dependencies: `npm install`
189
+ 2. Start MongoDB: `docker-compose up db`
190
+ 3. Start the dev server: `npm run start`
191
+ 4. Open http://localhost:3000
192
+ - Default login: `admin/admin`
193
+ - Configure [System Variables](https://git.zakscode.com/momentum/momentum/wiki/System-Variables)
194
+
195
+ </details>
196
+
197
+ ## License
198
+ Copyright © 2024 Zakary Timson | All Rights Reserved
199
+
200
+ See the [license](./LICENSE) for more information.
@@ -3,14 +3,18 @@
3
3
  import fs from 'fs';
4
4
  import {join} from 'path';
5
5
  import {Momentum} from '../dist/index.mjs';
6
- import * as readline from 'node:readline';
7
- import {camelCase, formatDate} from '@ztimson/utils';
6
+ import {formatDate, kebabCase, pascalCase} from '@ztimson/utils';
7
+ import readline from 'readline';
8
+ import packageFile from '../package.json' with {type: 'json'};
8
9
 
9
- export function ask(prompt, hide = false) {
10
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });
10
+ function ask(prompt, hide = false) {
11
+ const rl = readline.createInterface({input: process.stdin, output: process.stdout, terminal: true});
11
12
  return new Promise((resolve) => {
12
13
  if (!hide) {
13
- rl.question(prompt, (answer) => (rl.close(), resolve(answer)));
14
+ rl.question(prompt, (answer) => {
15
+ resolve(answer);
16
+ rl.close();
17
+ });
14
18
  } else {
15
19
  let input = '';
16
20
  const onKeyPress = (char, key) => {
@@ -38,70 +42,57 @@ export function ask(prompt, hide = false) {
38
42
  });
39
43
  }
40
44
 
41
- function createProp(column) {
42
- let prop = column.prop;
43
- if(column.type == 'formula' || column.type == 'javascript') prop = `readonly ${prop}`;
44
- prop += column.required ? ': ' : '?: ';
45
- if(column.type == 'formula' || column.type == 'javascript') prop += 'any';
46
- else if(column.type == 'link') prop += 'string';
47
- else if(column.type == 'timestamp') prop += 'Date';
48
- else prop += `${column.type}`;
49
- return prop;
50
- }
51
-
52
45
  // Main loop
53
46
  (async () => {
54
47
  try {
55
48
  // Arguments
56
- let [,, destination, url, username, password] = process.argv;
57
- const packageFile = await import('../package.json', {with: { type: 'json' }});
49
+ let [, , destination, url, username, password] = process.argv;
58
50
  console.log(`Momentum v${packageFile.default.version}`);
59
51
  let momentum;
60
52
 
61
53
  // Login
62
54
  do {
63
- while(!url) url = await ask('URL: ');
64
- while(!username) username = await ask('Username: ');
65
- while(!password) password = await ask('Password: ', true);
55
+ while (!url) url = await ask('URL: ');
56
+ while (!username) username = await ask('Username: ');
57
+ while (!password) password = await ask('Password: ', true);
66
58
 
67
- if(!url.startsWith('http')) url = 'http://' + url;
59
+ if (!url.startsWith('http')) url = 'http://' + url;
68
60
  momentum = new Momentum(url);
69
61
  await momentum.auth.login(username, password)
70
62
  .catch(err => {
71
63
  url = username = password = '';
72
64
  console.log('Failed to authenticate');
73
65
  });
74
- } while(!momentum?.auth.user);
66
+ } while (!momentum?.auth.user);
75
67
  console.log('Login Succeeded!\n');
76
68
 
77
- if(!destination) destination = await ask('Destination (src/models): ');
78
- if(!destination) destination = 'src/models';
69
+ if (!destination) destination = await ask('Destination (src/models): ');
70
+ if (!destination) destination = 'src/models';
79
71
  let path = join(process.cwd(), destination);
80
- if(!fs.existsSync(path)) fs.mkdirSync(path);
72
+ if (!fs.existsSync(path)) fs.mkdirSync(path);
81
73
 
82
74
  console.log('\nCollecting Schemas...');
83
- const schemas = await momentum.data.schema.read();
75
+ const schemas = await momentum.schemas.read();
84
76
  schemas.forEach(schema => {
85
- const fileName = camelCase(schema.path) + '.ts';
77
+ const fileName = kebabCase(schema.path) + '.ts';
86
78
  console.log(`Creating Model: ${schema.path} -> ${fileName}`);
87
79
  const path = join(process.cwd(), destination, fileName);
88
- fs.writeFileSync(path, `import {Meta} from '@ztimson/momentum';
80
+ fs.writeFileSync(path, `import {Formula, Link, Meta} from '@ztimson/momentum';
89
81
 
90
82
  /**
91
- * ${schema.path}
92
- *
93
- * ${schema.description}
94
- *
95
- * Generated by Momentum v${packageFile.default.version} - ${formatDate('YYYY-MM-DD')}
83
+ * Generated by Momentum v${packageFile.default.version}
84
+ * Date: ${formatDate('YYYY-MM-DD')}
85
+ * Schema: ${schema.path}
86
+ * Description: ${schema.description}
96
87
  */
97
- export interface ${camelCase(schema.path)} extends Meta${schema.columns.length ? '' : ', Record<string, any>'} {
98
- ${schema.columns.map(column => `\t${createProp(column)};`).join('\n')}
88
+ export interface ${pascalCase(schema.path)} extends Meta${schema.columns.length ? '' : ', Record<string, any>'} {
89
+ ${schema.columns.map(column => `\t${column.readonly ? 'readonly ' : ''}${column.prop}${column.required ? ':' : '?:'} ${column.type};`).join('\n')}
99
90
  }
100
91
  `);
101
92
  });
102
93
  console.log('Done!');
103
94
  process.exit();
104
- } catch(err) {
95
+ } catch (err) {
105
96
  console.error(`\n${err.stack || err.stackTrace || err.message || err.toString()}`);
106
97
  process.exit(1);
107
98
  }
package/dist/actions.d.ts CHANGED
@@ -1,63 +1,71 @@
1
- import { Api } from './api';
2
- import { Cache, HttpRequestOptions, PathEventEmitter } from '@ztimson/utils';
1
+ import { HttpRequestOptions } from '@ztimson/utils';
2
+ import { AssetController } from './asset-controller';
3
3
  import { Meta } from './core';
4
+ import { Momentum } from './momentum';
4
5
  /** Action model */
5
6
  export type Action = Meta & {
6
7
  /** Action name */
7
8
  name: string;
9
+ /** Disable action */
10
+ disabled?: boolean;
8
11
  /** Trigger with CRON, CRUD or Event */
9
12
  trigger: {
10
13
  type: ActionType;
11
14
  value: string;
12
15
  };
13
16
  /** Run as system or with triggering user permissions */
14
- system?: boolean;
17
+ system?: boolean | null;
15
18
  /** Action code */
16
19
  fn: string;
17
20
  /** User nodes */
18
- notes?: string;
21
+ notes?: string | null;
19
22
  /** Last execution timestamp */
20
- lastRun?: Date;
23
+ readonly lastRun?: null | Date;
21
24
  /** Last execution duration */
22
- lastRunLength?: number;
25
+ readonly lastRunDuration?: number | null;
23
26
  /** Next scheduled run time (CRON only) */
24
- nextRun?: Date;
27
+ readonly nextRun?: null | Date;
25
28
  /** Last execution results */
26
- response?: ActionResult;
29
+ readonly response?: ActionResult | null;
27
30
  };
28
31
  /** Action execution result */
29
32
  export type ActionResult = {
30
33
  /** ID of associated action */
31
- action: string;
34
+ readonly action: string;
35
+ /** Runtime */
36
+ readonly duration: number;
37
+ /** Start timestamp */
38
+ readonly start: Date;
32
39
  /** Console output */
33
- stdout: any[];
40
+ readonly stdout: any[];
34
41
  /** Console errors */
35
- stderr: any[];
42
+ readonly stderr: any[];
36
43
  /** HTTP Response */
37
- response?: any;
44
+ readonly response?: any;
38
45
  /** Action return value */
39
- return?: any;
46
+ readonly return?: any;
40
47
  };
48
+ /** Action triggers */
41
49
  export declare enum ActionType {
50
+ /** CRON Job */
42
51
  'CRON' = 0,
52
+ /** Internal Event */
43
53
  'EVENT' = 1,
54
+ /** HTTP DELETE request */
44
55
  'DELETE' = 2,
56
+ /** HTTP GET request */
45
57
  'GET' = 3,
58
+ /** HTTP PATCH request */
46
59
  'PATCH' = 4,
60
+ /** HTTP POST request */
47
61
  'POST' = 5,
62
+ /** HTTP PUT request */
48
63
  'PUT' = 6
49
64
  }
50
- /** Execute custom Javascript on trigger event */
51
- export declare class Actions extends PathEventEmitter {
52
- private readonly api;
53
- cache: Cache<string, Action>;
54
- constructor(api: Api | string);
55
- /**
56
- * All saved actions
57
- * @param {boolean} reload Will use cached response if false
58
- * @return {Promise<Action[]>} List of saved actions
59
- */
60
- all(reload?: boolean): Promise<Action[]>;
65
+ /** Run cloud functions & custom code */
66
+ export declare class Actions extends AssetController<Action> {
67
+ protected momentum: Momentum;
68
+ constructor(momentum: Momentum);
61
69
  /**
62
70
  * Manually trigger an actions execution
63
71
  * @param {string} id Action ID
@@ -65,19 +73,6 @@ export declare class Actions extends PathEventEmitter {
65
73
  * @return {Promise<ActionResult>} All action output including console logs & return
66
74
  */
67
75
  debug(id: string, opts?: HttpRequestOptions): Promise<ActionResult>;
68
- /**
69
- * Delete an existing action
70
- * @param {string} id Action ID
71
- * @return {Promise<void>} Delete complete
72
- */
73
- delete(id: string): Promise<void>;
74
- /**
75
- * Fetch action info
76
- * @param {string} id Action ID
77
- * @param {boolean} reload Will use cached response if false
78
- * @return {Promise<Action | null>} Requested action
79
- */
80
- read(id: string, reload?: boolean): Promise<Action | null>;
81
76
  /**
82
77
  * Run an HTTP action
83
78
  * @param {string} path HTTP path excluding `/api/actions/run`
@@ -85,11 +80,5 @@ export declare class Actions extends PathEventEmitter {
85
80
  * @return {Promise<T>} HTTP response
86
81
  */
87
82
  run<T>(path: string, opts?: HttpRequestOptions): Promise<T>;
88
- /**
89
- * Update an action
90
- * @param {Action} action The new action
91
- * @return {Promise<Action>} Saved action
92
- */
93
- update(action: Action): Promise<Action>;
94
83
  }
95
84
  //# sourceMappingURL=actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAM,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAE5B,mBAAmB;AACnB,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG;IAC3B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,OAAO,EAAE;QAAC,IAAI,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;IAC3C,wDAAwD;IACxD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kBAAkB;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,8BAA8B;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,YAAY,CAAA;CACvB,CAAA;AAED,8BAA8B;AAC9B,MAAM,MAAM,YAAY,GAAG;IAC1B,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,qBAAqB;IACrB,MAAM,EAAE,GAAG,EAAE,CAAC;IACd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