@ztimson/momentum 0.0.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.
- package/README.md +135 -0
- package/dist/actions.d.ts +52 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/api.d.ts +22 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/auth.d.ts +61 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/core.d.ts +8 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/data.d.ts +21 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/email.d.ts +22 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/groups.d.ts +20 -0
- package/dist/groups.d.ts.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/logger.d.ts +53 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/momentum.cjs +4 -0
- package/dist/momentum.cjs.map +1 -0
- package/dist/momentum.d.ts +35 -0
- package/dist/momentum.d.ts.map +1 -0
- package/dist/momentum.mjs +1287 -0
- package/dist/momentum.mjs.map +1 -0
- package/dist/settings.d.ts +44 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/sockets.d.ts +14 -0
- package/dist/sockets.d.ts.map +1 -0
- package/dist/static.d.ts +16 -0
- package/dist/static.d.ts.map +1 -0
- package/dist/storage.d.ts +39 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/users.d.ts +23 -0
- package/dist/users.d.ts.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<!-- Header -->
|
|
2
|
+
<div id="top" align="center">
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<!-- Logo -->
|
|
6
|
+
<img src="public/favicon.svg" alt="Logo" width="200" height="200">
|
|
7
|
+
|
|
8
|
+
<!-- Title -->
|
|
9
|
+
### Momentum
|
|
10
|
+
|
|
11
|
+
<!-- Description -->
|
|
12
|
+
Server Development Platform
|
|
13
|
+
|
|
14
|
+
<!-- Repo badges -->
|
|
15
|
+
[](https://git.zakscode.com/ztimson/momentum/tags)
|
|
16
|
+
[](https://git.zakscode.com/ztimson/momentum/pulls)
|
|
17
|
+
[](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 server development platform. 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 server backend for single page applications such as angular, react, svelte or vue. This enables rapid development of the client front-end application or website.
|
|
46
|
+
|
|
47
|
+
Features include:
|
|
48
|
+
- WIP: Admin Panel
|
|
49
|
+
- Use the web UI to manage server features while you build your front end
|
|
50
|
+
- White labeled so it can use it as a content management system
|
|
51
|
+
- View the source code for real examples of how to use the server API
|
|
52
|
+
- [Client Library](https://git.zakscode.com/ztimson/momentum/wiki/Client)
|
|
53
|
+
- TypeScript, ESM & UMD compatible client library for native JavaScript environments
|
|
54
|
+
- Authentication
|
|
55
|
+
- Manage users & save user data
|
|
56
|
+
- Custom password strength rules
|
|
57
|
+
- Account validation & reset emails
|
|
58
|
+
- User groups
|
|
59
|
+
- Permissions for all modules
|
|
60
|
+
- Custom permissions
|
|
61
|
+
- Optionally allow public registration
|
|
62
|
+
- Data
|
|
63
|
+
- Generic collection/do`cument database accessible via REST
|
|
64
|
+
- Granular collection & document level permissions
|
|
65
|
+
- Metadata such as created & modified by is tracked
|
|
66
|
+
- Uses MongoDB
|
|
67
|
+
- Email
|
|
68
|
+
- Supports SMTP
|
|
69
|
+
- HTML email templates
|
|
70
|
+
- Send emails using post requests
|
|
71
|
+
- WIP: Handle newsletter subscriptions
|
|
72
|
+
- WIP: Send newsletters via post request
|
|
73
|
+
- [File Storage](https://git.zakscode.com/ztimson/momentum/wiki/Storage)
|
|
74
|
+
- Upload files using file input field
|
|
75
|
+
- Navigate storage via API
|
|
76
|
+
- Automatically track metadata
|
|
77
|
+
- Granular, file level, permissions
|
|
78
|
+
- [Static File Server](https://git.zakscode.com/ztimson/momentum/wiki/Static)
|
|
79
|
+
- Host your single page application using Momentum for easy hosting
|
|
80
|
+
- Volumize or extend the momentum docker image to include your static website in `/app/public`
|
|
81
|
+
- Enable the single page application redirects with the environment variable: `NOT_FOUND_REDIRECT=TRUE`
|
|
82
|
+
- [Variables](https://git.zakscode.com/ztimson/momentum/wiki/Variables)
|
|
83
|
+
- Manage the server through variables which can be changed at runtime
|
|
84
|
+
- Create & use custom variables for your application
|
|
85
|
+
- Granular, variable level, permissions
|
|
86
|
+
|
|
87
|
+
### Built With
|
|
88
|
+
[](https://docker.com/)
|
|
89
|
+
[](https://www.mongodb.com/)
|
|
90
|
+
[](https://nodejs.org/)
|
|
91
|
+
[](https://typescriptlang.org/)
|
|
92
|
+
|
|
93
|
+
## Setup
|
|
94
|
+
|
|
95
|
+
<details>
|
|
96
|
+
<summary>
|
|
97
|
+
<h3 id="production" style="display: inline">Production</h3>
|
|
98
|
+
</summary>
|
|
99
|
+
|
|
100
|
+
#### Prerequisites
|
|
101
|
+
- [Docker](https://docs.docker.com/install/)
|
|
102
|
+
|
|
103
|
+
#### Instructions
|
|
104
|
+
1. _Optional: Use momentum to host your [static site](https://git.zakscode.com/ztimson/momentum/wiki/Static)_
|
|
105
|
+
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`
|
|
106
|
+
3. Configure the [Environment Variables](https://git.zakscode.com/ztimson/momentum/wiki/Environment-Variables) inside the docker-compose
|
|
107
|
+
4. Start the server with: `docker-compose up -f momentum.yaml`
|
|
108
|
+
5. Open http://localhost:80
|
|
109
|
+
- Default login: `admin/admin`
|
|
110
|
+
- Configure [System Variables](https://git.zakscode.com/ztimson/momentum/wiki/System-Variables)
|
|
111
|
+
|
|
112
|
+
</details>
|
|
113
|
+
|
|
114
|
+
<details>
|
|
115
|
+
<summary>
|
|
116
|
+
<h3 id="development" style="display: inline">Development</h3>
|
|
117
|
+
</summary>
|
|
118
|
+
|
|
119
|
+
#### Prerequisites
|
|
120
|
+
- [Node.js](https://nodejs.org/en/download)
|
|
121
|
+
|
|
122
|
+
#### Instructions
|
|
123
|
+
1. Install the dependencies: `npm install`
|
|
124
|
+
2. Start MongoDB: `docker-compose up db`
|
|
125
|
+
3. Start the dev server: `npm run start`
|
|
126
|
+
4. Open http://localhost:3000
|
|
127
|
+
- Default login: `admin/admin`
|
|
128
|
+
- Configure [System Variables](https://git.zakscode.com/ztimson/momentum/wiki/System-Variables)
|
|
129
|
+
|
|
130
|
+
</details>
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
Copyright © 2023 Zakary Timson | Available under MIT Licensing
|
|
134
|
+
|
|
135
|
+
See the [license](./LICENSE) for more information.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Api } from './api';
|
|
2
|
+
import { TypedEmitter, XhrOptions, type TypedEvents } from '@ztimson/utils';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
import { Meta } from './core';
|
|
5
|
+
export type Action = Meta & {
|
|
6
|
+
name: string;
|
|
7
|
+
trigger: {
|
|
8
|
+
type: ActionType;
|
|
9
|
+
value: string;
|
|
10
|
+
};
|
|
11
|
+
system: boolean;
|
|
12
|
+
fn: string;
|
|
13
|
+
notes: string;
|
|
14
|
+
lastRun: number;
|
|
15
|
+
};
|
|
16
|
+
export type ActionResponse = {
|
|
17
|
+
action: string;
|
|
18
|
+
stdout: any[];
|
|
19
|
+
stderr: any[];
|
|
20
|
+
return?: any;
|
|
21
|
+
};
|
|
22
|
+
export declare enum ActionType {
|
|
23
|
+
'DISABLED' = 0,
|
|
24
|
+
'CRON' = 1,
|
|
25
|
+
'EVENT' = 2,
|
|
26
|
+
'GET' = 3,
|
|
27
|
+
'POST' = 4,
|
|
28
|
+
'PATCH' = 5,
|
|
29
|
+
'PUT' = 6,
|
|
30
|
+
'DELETE' = 7
|
|
31
|
+
}
|
|
32
|
+
export type ActionEvents = TypedEvents & {
|
|
33
|
+
LIST: (actions: Action[]) => any;
|
|
34
|
+
DELETE: (id: string) => any;
|
|
35
|
+
READ: (action: Action | null) => any;
|
|
36
|
+
UPDATE: (action: Action) => any;
|
|
37
|
+
EXECUTE: (action: Action, resp: any) => any;
|
|
38
|
+
};
|
|
39
|
+
export declare class Actions extends TypedEmitter<ActionEvents> {
|
|
40
|
+
private readonly api;
|
|
41
|
+
$cache: BehaviorSubject<Action[]>;
|
|
42
|
+
get cache(): Action[];
|
|
43
|
+
set cache(val: Action[]);
|
|
44
|
+
constructor(api: Api | string);
|
|
45
|
+
delete(id: string): Promise<void>;
|
|
46
|
+
list(): Promise<Action[]>;
|
|
47
|
+
read(id: string, reload?: boolean): Promise<Action | null>;
|
|
48
|
+
run<T>(path: string, opts?: XhrOptions): Promise<T>;
|
|
49
|
+
runById(action: string | Action, opts?: XhrOptions): Promise<ActionResponse>;
|
|
50
|
+
update(action: Action): Promise<Action>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +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,YAAY,EAAE,UAAU,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAC,eAAe,EAAC,MAAM,MAAM,CAAC;AACrC,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAE5B,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAC,IAAI,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;IAC3C,MAAM,EAAE,OAAO,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,MAAM,CAAC,EAAE,GAAG,CAAC;CACb,CAAA;AAED,oBAAY,UAAU;IACrB,UAAU,IAAA;IACV,MAAM,IAAA;IACN,OAAO,IAAA;IACP,KAAK,IAAA;IACL,MAAM,IAAA;IACN,OAAO,IAAA;IACP,KAAK,IAAA;IACL,QAAQ,IAAA;CACR;AAED,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACxC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC;IACjC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,GAAG,CAAC;IAC5B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,GAAG,CAAC;IACrC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,CAAC;IAChC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC;CAC5C,CAAA;AAED,qBAAa,OAAQ,SAAQ,YAAY,CAAC,YAAY,CAAC;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;IAE3B,MAAM,4BAAqC;IAC3C,IAAI,KAAK,aAAgC;IACzC,IAAI,KAAK,CAAC,GAAG,UAAA,EAA4B;gBAE7B,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjC,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAQzB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,UAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUtD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe;IAI1C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,GAAE,UAAe;IAKtD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAWvC"}
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type TypedEvents, type RequestOptions, XHR, type XhrOptions } from '@ztimson/utils';
|
|
2
|
+
export type ApiEvents = TypedEvents & {
|
|
3
|
+
REQUEST: (request: Promise<any>, options: RequestOptions) => any;
|
|
4
|
+
RESPONSE: (response: any, options: RequestOptions) => any;
|
|
5
|
+
REJECTED: (response: Error, options: RequestOptions) => any;
|
|
6
|
+
TOKEN: (token: string | null) => any;
|
|
7
|
+
};
|
|
8
|
+
export declare class Api extends XHR {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
readonly opts: XhrOptions;
|
|
11
|
+
private emitter;
|
|
12
|
+
private _token;
|
|
13
|
+
get token(): string | null;
|
|
14
|
+
set token(token: string | null);
|
|
15
|
+
constructor(url?: string, opts?: XhrOptions);
|
|
16
|
+
emit: <K extends string | symbol>(event: K, ...args: Parameters<ApiEvents[K]>) => void;
|
|
17
|
+
off: <K extends string | symbol = string>(event: K, listener: ApiEvents[K]) => void;
|
|
18
|
+
on: <K extends string | symbol = string>(event: K, listener: ApiEvents[K]) => () => void;
|
|
19
|
+
once: <K extends string | symbol = string>(event: K, listener?: ApiEvents[K] | undefined) => Promise<any>;
|
|
20
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,GAAG,EACH,KAAK,UAAU,EACf,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IACrC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,cAAc,KAAK,GAAG,CAAC;IACjE,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,KAAK,GAAG,CAAC;IAC1D,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,KAAK,GAAG,CAAC;IAC5D,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,GAAG,CAAA;CACpC,CAAA;AAED,qBAAa,GAAI,SAAQ,GAAG;aAYC,GAAG,EAAE,MAAM;aAAoC,IAAI,EAAE,UAAU;IAX3F,OAAO,CAAC,OAAO,CAAiC;IAEhD,OAAO,CAAC,MAAM,CAAuB;IACrC,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAAwB;IAClD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAK7B;gBAE2B,GAAG,GAAE,MAAwB,EAAkB,IAAI,GAAE,UAAe;IAKhG,IAAI,mFAAwC;IAC5C,GAAG,iFAAuC;IAC1C,EAAE,uFAAsC;IACxC,IAAI,sGAAwC;IAE5C,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;CAW/C"}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import { Api } from './api';
|
|
3
|
+
import { type Meta } from './core';
|
|
4
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
5
|
+
export type Group = Meta & {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
notes?: string;
|
|
9
|
+
users: string[];
|
|
10
|
+
permissions: string[];
|
|
11
|
+
extra: any;
|
|
12
|
+
};
|
|
13
|
+
export type User = Meta & {
|
|
14
|
+
username: string;
|
|
15
|
+
name: string;
|
|
16
|
+
email: string;
|
|
17
|
+
image?: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
groups?: string[];
|
|
20
|
+
permissions?: string[];
|
|
21
|
+
notes?: string;
|
|
22
|
+
extra: any;
|
|
23
|
+
lastLogin?: number | null;
|
|
24
|
+
};
|
|
25
|
+
export type AuthEvents = TypedEvents & {
|
|
26
|
+
USER: (user: User | null) => any;
|
|
27
|
+
LOGIN: (user: User) => any;
|
|
28
|
+
LOGOUT: () => any;
|
|
29
|
+
REGISTER: (user: Partial<User>) => any;
|
|
30
|
+
RESET_REQUEST: (email: string) => any;
|
|
31
|
+
RESET_COMPLETE: (token: string) => any;
|
|
32
|
+
};
|
|
33
|
+
export type AuthOptions = {
|
|
34
|
+
loginUi?: string;
|
|
35
|
+
persist?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare class Auth extends TypedEmitter<AuthEvents> {
|
|
38
|
+
private readonly opts?;
|
|
39
|
+
private readonly api;
|
|
40
|
+
private readonly storageKey;
|
|
41
|
+
$user: BehaviorSubject<User | null | undefined>;
|
|
42
|
+
get user(): User | null | undefined;
|
|
43
|
+
set user(user: User | null | undefined);
|
|
44
|
+
constructor(api: Api | string, opts?: AuthOptions | undefined);
|
|
45
|
+
knownHost(host?: string): Promise<void>;
|
|
46
|
+
login(username: string, password: string): Promise<User | null>;
|
|
47
|
+
loginRedirect(host?: string): Promise<string>;
|
|
48
|
+
logout(): void;
|
|
49
|
+
register(user: Partial<User> & {
|
|
50
|
+
username: string;
|
|
51
|
+
password: string;
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
reset(password: string, token?: string): Promise<void>;
|
|
54
|
+
reset(email: string): Promise<void>;
|
|
55
|
+
whoAmI(token?: string, set?: boolean): Promise<{
|
|
56
|
+
token: string;
|
|
57
|
+
user: User;
|
|
58
|
+
permissions: string[];
|
|
59
|
+
} | null>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,MAAM,CAAC;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAU,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAEvE,MAAM,MAAM,KAAK,GAAG,IAAI,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,GAAG,CAAC;CACX,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,IAAI,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG;IACtC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,GAAG,CAAC;IACjC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,CAAC;IAClB,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC;IACvC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;IACtC,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;CACvC,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAA;AAED,qBAAa,IAAK,SAAQ,YAAY,CAAC,UAAU,CAAC;IAclB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAbrD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IAErC,KAAK,2CAA0D;IAC/D,IAAI,IAAI,IAAI,IAAI,GAAG,IAAI,GAAG,SAAS,CAA6B;IAChE,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAMrC;gBAEW,GAAG,EAAE,GAAG,GAAG,MAAM,EAAmB,IAAI,CAAC,yBAAa;IAwBlE,SAAS,CAAC,IAAI,GAAE,MAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxD,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAc/D,aAAa,CAAC,IAAI,GAAE,MAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;IAa9D,MAAM,IAAI,IAAI;IAMR,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzF,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IACtD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa7B,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,UAAQ,GAAG,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAC,GAAG,IAAI,CAAC;CAa7G"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG;IAClB,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACrB,CAAA"}
|
package/dist/data.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Api } from './api';
|
|
2
|
+
import { type Meta } from './core';
|
|
3
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
4
|
+
export type DataEvents = TypedEvents & {
|
|
5
|
+
DELETE: (collection: string, document: string) => any;
|
|
6
|
+
GET: (collection: string, documents: any) => any;
|
|
7
|
+
RAW: (collection: string, response: any) => any;
|
|
8
|
+
SET: (collection: string, document: any) => any;
|
|
9
|
+
};
|
|
10
|
+
export declare class Data extends TypedEmitter<DataEvents> {
|
|
11
|
+
private readonly api;
|
|
12
|
+
constructor(api: Api | string);
|
|
13
|
+
delete(collection: string, document: string): Promise<void>;
|
|
14
|
+
get<T extends Meta>(collection: string): Promise<T[]>;
|
|
15
|
+
get<T extends Meta>(collection: string, document: string): Promise<T>;
|
|
16
|
+
raw<T>(collection: string, operand: string, query: any, options: any): Promise<T>;
|
|
17
|
+
set<T extends Meta>(collection: string, document: Partial<T> & {
|
|
18
|
+
_id?: string;
|
|
19
|
+
}, append?: boolean): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE9D,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG;IACtC,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC;IACtD,GAAG,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,GAAG,CAAC;IACjD,GAAG,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,GAAG,CAAC;IAChD,GAAG,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,GAAG,CAAC;CAChD,CAAC;AAEF,qBAAa,IAAK,SAAQ,YAAY,CAAC,UAAU,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3D,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IACrD,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAQrE,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAcjF,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAC,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;CAU1G"}
|
package/dist/email.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Api } from './api';
|
|
2
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
3
|
+
export type MailTemplate = {
|
|
4
|
+
template: string;
|
|
5
|
+
data?: any;
|
|
6
|
+
};
|
|
7
|
+
export type Mail = {
|
|
8
|
+
to: string | string[];
|
|
9
|
+
cc?: string[];
|
|
10
|
+
bcc?: string[];
|
|
11
|
+
subject?: string;
|
|
12
|
+
body: string | MailTemplate;
|
|
13
|
+
};
|
|
14
|
+
export type EmailEvents = TypedEvents & {
|
|
15
|
+
SENT: (email: Mail) => any;
|
|
16
|
+
};
|
|
17
|
+
export declare class Email extends TypedEmitter<EmailEvents> {
|
|
18
|
+
private readonly api;
|
|
19
|
+
constructor(api: Api | string);
|
|
20
|
+
send(email: Mail): Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=email.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAC,CAAC;AAC1D,MAAM,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CAC5B,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACvC,IAAI,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,GAAG,CAAA;CAC1B,CAAA;AAED,qBAAa,KAAM,SAAQ,YAAY,CAAC,WAAW,CAAC;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,IAAI,CAAC,KAAK,EAAE,IAAI;CAQhB"}
|
package/dist/groups.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Api } from './api';
|
|
2
|
+
import { type Group } from './auth';
|
|
3
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
4
|
+
export type GroupEvents = TypedEvents & {
|
|
5
|
+
LIST: (users: Group[]) => any;
|
|
6
|
+
CREATE: (user: Group) => any;
|
|
7
|
+
READ: (user: Group) => any;
|
|
8
|
+
UPDATE: (user: Group) => any;
|
|
9
|
+
DELETE: (name: string) => any;
|
|
10
|
+
};
|
|
11
|
+
export declare class Groups extends TypedEmitter<GroupEvents> {
|
|
12
|
+
private readonly api;
|
|
13
|
+
constructor(api: Api | string);
|
|
14
|
+
create(group: Group): Promise<Group>;
|
|
15
|
+
list(): Promise<Group[]>;
|
|
16
|
+
read(name: string): Promise<Group>;
|
|
17
|
+
update(group: Group): Promise<Group>;
|
|
18
|
+
delete(name: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=groups.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../src/groups.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,KAAK,EAAC,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACvC,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC;IAC9B,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,GAAG,CAAC;IAC7B,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,GAAG,CAAC;IAC3B,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,GAAG,CAAC;IAC7B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;CAC9B,CAAC;AAEF,qBAAa,MAAO,SAAQ,YAAY,CAAC,WAAW,CAAC;IACpD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAWpC,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAOxB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAOlC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAWpC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAMnC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './actions';
|
|
2
|
+
export * from './api';
|
|
3
|
+
export * from './auth';
|
|
4
|
+
export * from './core';
|
|
5
|
+
export * from './data';
|
|
6
|
+
export * from './email';
|
|
7
|
+
export * from './groups';
|
|
8
|
+
export * from './logger';
|
|
9
|
+
export * from './momentum';
|
|
10
|
+
export * from './settings';
|
|
11
|
+
export * from './sockets';
|
|
12
|
+
export * from './static';
|
|
13
|
+
export * from './storage';
|
|
14
|
+
export * from './users';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Api } from './api';
|
|
2
|
+
import { LOG_LEVEL } from '@ztimson/utils';
|
|
3
|
+
export type LogLevel = 'ERROR' | 'WARN' | 'INFO' | 'LOG' | 'DEBUG' | 'NONE';
|
|
4
|
+
export type Log<T> = {
|
|
5
|
+
time: number;
|
|
6
|
+
level: LOG_LEVEL;
|
|
7
|
+
log: any[];
|
|
8
|
+
ctx?: T;
|
|
9
|
+
};
|
|
10
|
+
export type ClientLog = Log<{
|
|
11
|
+
url: string;
|
|
12
|
+
user: string;
|
|
13
|
+
ip: string;
|
|
14
|
+
res: [number, number];
|
|
15
|
+
ua: string | {
|
|
16
|
+
ua: string;
|
|
17
|
+
browser: {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
major: string;
|
|
21
|
+
};
|
|
22
|
+
cpu: {
|
|
23
|
+
architecture: string;
|
|
24
|
+
};
|
|
25
|
+
device: {
|
|
26
|
+
mode?: string;
|
|
27
|
+
type?: string;
|
|
28
|
+
};
|
|
29
|
+
engine: {
|
|
30
|
+
name: string;
|
|
31
|
+
version: string;
|
|
32
|
+
};
|
|
33
|
+
os: {
|
|
34
|
+
name: string;
|
|
35
|
+
version: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
export declare class Logger {
|
|
40
|
+
private readonly api;
|
|
41
|
+
constructor(api: Api | string, logLevel?: LogLevel | null);
|
|
42
|
+
private buildLog;
|
|
43
|
+
clearClientLogs(): Promise<ClientLog[]>;
|
|
44
|
+
clearServerLogs(): Promise<ClientLog[]>;
|
|
45
|
+
clientLogs(length?: number, page?: number): Promise<ClientLog[]>;
|
|
46
|
+
serverLogs(length?: number, page?: number): Promise<Log<any>[]>;
|
|
47
|
+
debug(...logs: any[]): Promise<unknown>;
|
|
48
|
+
log(...logs: any[]): Promise<unknown>;
|
|
49
|
+
info(...logs: any[]): Promise<unknown>;
|
|
50
|
+
warn(...logs: any[]): Promise<unknown>;
|
|
51
|
+
error(...logs: any[]): Promise<unknown>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAEzC,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAE5E,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;IACjB,GAAG,EAAE,GAAG,EAAE,CAAC;IACX,GAAG,CAAC,EAAE,CAAC,CAAA;CACP,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtB,EAAE,EAAE,MAAM,GAAG;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAC,CAAC;QACxD,GAAG,EAAE;YAAC,YAAY,EAAE,MAAM,CAAA;SAAC,CAAC;QAC5B,MAAM,EAAE;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAC,CAAC;QACvC,MAAM,EAAE;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAC,CAAC;QACxC,EAAE,EAAE;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAC,CAAC;KACpC,CAAA;CACD,CAAC,CAAC;AAEH,qBAAa,MAAM;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI;IASzD,OAAO,CAAC,QAAQ;IAYhB,eAAe;IAIf,eAAe;IAIf,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAKhE,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;IAK/D,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAIpB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAIlB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAInB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAInB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAGpB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
(function(h,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(h=typeof globalThis<"u"?globalThis:h||self,p(h.utils={}))})(this,function(h){"use strict";var Nt=Object.defineProperty;var Ht=(h,p,v)=>p in h?Nt(h,p,{enumerable:!0,configurable:!0,writable:!0,value:v}):h[p]=v;var a=(h,p,v)=>(Ht(h,typeof p!="symbol"?p+"":p,v),v);var p=Object.defineProperty,v=(i,e,t)=>e in i?p(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,l=(i,e,t)=>(v(i,typeof e!="symbol"?e+"":e,t),t);function At(i,e=!1){if(i==null)throw new Error("Cannot clean a NULL value");return Array.isArray(i)?i=i.filter(t=>t!=null):Object.entries(i).forEach(([t,r])=>{(e&&r===void 0||!e&&r==null)&&delete i[t]}),i}function K(i,e){const t=typeof i,r=typeof e;return t!="object"||i==null||r!="object"||e==null?t=="function"&&r=="function"?i.toString()==e.toString():i===e:Object.keys(i).length!=Object.keys(e).length?!1:Object.keys(i).every(s=>K(i[s],e[s]))}function _t(i,e){const t=document.createElement("a");t.href=i,t.download=e,document.body.appendChild(t),t.click(),document.body.removeChild(t)}class f{constructor(){l(this,"listeners",{})}static emit(e,...t){(this.listeners["*"]||[]).forEach(r=>r(e,...t)),(this.listeners[e.toString()]||[]).forEach(r=>r(...t))}static off(e,t){const r=e.toString();this.listeners[r]=(this.listeners[r]||[]).filter(s=>s===t)}static on(e,t){var r;const s=e.toString();return this.listeners[s]||(this.listeners[s]=[]),(r=this.listeners[s])==null||r.push(t),()=>this.off(e,t)}static once(e,t){return new Promise(r=>{const s=this.on(e,(...n)=>{r(n.length==1?n[0]:n),t&&t(...n),s()})})}emit(e,...t){(this.listeners["*"]||[]).forEach(r=>r(e,...t)),(this.listeners[e]||[]).forEach(r=>r(...t))}off(e,t){this.listeners[e]=(this.listeners[e]||[]).filter(r=>r===t)}on(e,t){var r;return this.listeners[e]||(this.listeners[e]=[]),(r=this.listeners[e])==null||r.push(t),()=>this.off(e,t)}once(e,t){return new Promise(r=>{const s=this.on(e,(...n)=>{r(n.length==1?n[0]:n),t&&t(...n),s()})})}}l(f,"listeners",{});const j=class L{constructor(e={}){l(this,"interceptors",{}),l(this,"headers",{}),this.opts=e,this.headers=e.headers||{},e.interceptors&&e.interceptors.forEach(t=>L.addInterceptor(t))}static addInterceptor(e){const t=Object.keys(L.interceptors).length.toString();return L.interceptors[t]=e,()=>{L.interceptors[t]=null}}addInterceptor(e){const t=Object.keys(this.interceptors).length.toString();return this.interceptors[t]=e,()=>{this.interceptors[t]=null}}async request(e={}){var t,r;if(!this.opts.url&&!e.url)throw new Error("URL needs to be set");const s=((t=e.url)!=null&&t.startsWith("http")?e.url:(this.opts.url||"")+(e.url||"")).replace(/([^:]\/)\/+/g,"$1"),n=At({"Content-Type":e.body&&!(e.body instanceof FormData)?"application/json":void 0,...L.headers,...this.headers,...e.headers});return fetch(s,{headers:n,method:e.method||(e.body?"POST":"GET"),body:(r=n["Content-Type"])!=null&&r.startsWith("application/json")&&e.body?JSON.stringify(e.body):e.body}).then(async o=>{var u,c;for(let E of[...Object.values(L.interceptors),...Object.values(this.interceptors)])await new Promise(O=>E(o,()=>O()));if(!o.ok)throw new Error(o.statusText);return!e.skipConverting&&(u=o.headers.get("Content-Type"))!=null&&u.startsWith("application/json")?await o.json():!e.skipConverting&&(c=o.headers.get("Content-Type"))!=null&&c.startsWith("text/plain")?await o.text():o})}};l(j,"interceptors",{}),l(j,"headers",{});let z=j;z.addInterceptor((i,e)=>{if(i.status==200)return e();throw i.status==400?new J(i.statusText):i.status==401?new Q(i.statusText):i.status==403?new X(i.statusText):i.status==404?new Z(i.statusText):i.status==500?new tt(i.statusText):new w(i.statusText,i.status)});class w extends Error{constructor(e,t){super(e),l(this,"_code"),t!=null&&(this._code=t)}get code(){return this._code||this.constructor.code}set code(e){this._code=e}static from(e){const t=Number(e.statusCode)??Number(e.code),r=new this(e.message||e.toString());return Object.assign(r,{stack:e.stack,...e,code:t??void 0})}static instanceof(e){return e.constructor.code!=null}toString(){return this.message||super.toString()}}l(w,"code",500);class J extends w{constructor(e="Bad Request"){super(e)}static instanceof(e){return e.constructor.code==this.code}}l(J,"code",400);class Q extends w{constructor(e="Unauthorized"){super(e)}static instanceof(e){return e.constructor.code==this.code}}l(Q,"code",401);class X extends w{constructor(e="Forbidden"){super(e)}static instanceof(e){return e.constructor.code==this.code}}l(X,"code",403);class Z extends w{constructor(e="Not Found"){super(e)}static instanceof(e){return e.constructor.code==this.code}}l(Z,"code",404);class tt extends w{constructor(e="Internal Server Error"){super(e)}static instanceof(e){return e.constructor.code==this.code}}l(tt,"code",500);const _={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},x={BLACK:"\x1B[30m",RED:"\x1B[31m",GREEN:"\x1B[32m",YELLOW:"\x1B[33m",BLUE:"\x1B[34m",MAGENTA:"\x1B[35m",CYAN:"\x1B[36m",LIGHT_GREY:"\x1B[37m",GREY:"\x1B[90m",LIGHT_RED:"\x1B[91m",LIGHT_GREEN:"\x1B[92m",LIGHT_YELLOW:"\x1B[93m",LIGHT_BLUE:"\x1B[94m",LIGHT_MAGENTA:"\x1B[95m",LIGHT_CYAN:"\x1B[96m",WHITE:"\x1B[97m"};var T=(i=>(i[i.ERROR=0]="ERROR",i[i.WARN=1]="WARN",i[i.INFO=2]="INFO",i[i.LOG=3]="LOG",i[i.DEBUG=4]="DEBUG",i))(T||{});l(class y extends f{constructor(e){super(),this.namespace=e}pad(e,t,r,s=!1){const n=e.toString(),o=t-n.length;if(o<=0)return n;const u=Array(~~(o/r.length)).fill(r).join("");return s?n+u:u+n}format(...e){const t=new Date;return`${`${t.getFullYear()}-${t.getMonth()+1}-${t.getDate()} ${this.pad(t.getHours().toString(),2,"0")}:${this.pad(t.getMinutes().toString(),2,"0")}:${this.pad(t.getSeconds().toString(),2,"0")}.${this.pad(t.getMilliseconds().toString(),3,"0",!0)}`}${this.namespace?` [${this.namespace}]`:""} ${e.join(" ")}`}debug(...e){if(y.LOG_LEVEL<4)return;const t=this.format(...e);y.emit(4,t),console.debug(x.LIGHT_GREY+t+_.CLEAR)}log(...e){if(y.LOG_LEVEL<3)return;const t=this.format(...e);y.emit(3,t),console.log(_.CLEAR+t)}info(...e){if(y.LOG_LEVEL<2)return;const t=this.format(...e);y.emit(2,t),console.info(x.BLUE+t+_.CLEAR)}warn(...e){if(y.LOG_LEVEL<1)return;const t=this.format(...e);y.emit(1,t),console.warn(x.YELLOW+t+_.CLEAR)}error(...e){if(y.LOG_LEVEL<0)return;const t=this.format(...e);y.emit(0,t),console.error(x.RED+t+_.CLEAR)}},"LOG_LEVEL",4);class $t extends Promise{constructor(e){super((t,r)=>e(s=>t(s),s=>r(s),s=>this.progress=s)),l(this,"listeners",[]),l(this,"_progress",0)}get progress(){return this._progress}set progress(e){e!=this._progress&&(this._progress=e,this.listeners.forEach(t=>t(e)))}onProgress(e){return this.listeners.push(e),this}}class m extends z{constructor(t=location.origin,r={}){r.url=t;super(r);a(this,"emitter",new f);a(this,"_token",null);a(this,"emit",this.emitter.emit.bind(this.emitter));a(this,"off",this.emitter.off.bind(this.emitter));a(this,"on",this.emitter.on.bind(this.emitter));a(this,"once",this.emitter.once.bind(this.emitter));this.url=t,this.opts=r}get token(){return this._token}set token(t){t!=this._token&&(this._token=t,this.headers.Authorization=`Bearer ${t}`,this.emit("TOKEN",t))}request(t){const r=super.request(t).then(s=>(this.emit("RESPONSE",s,t),s)).catch(s=>{throw this.emit("REJECTED",s,t),s});return this.emit("REQUEST",r,t),r}}var k=function(i,e){return k=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])},k(i,e)};function $(i,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");k(i,e);function t(){this.constructor=i}i.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function G(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],r=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&r>=i.length&&(i=void 0),{value:i&&i[r++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function N(i,e){var t=typeof Symbol=="function"&&i[Symbol.iterator];if(!t)return i;var r=t.call(i),s,n=[],o;try{for(;(e===void 0||e-- >0)&&!(s=r.next()).done;)n.push(s.value)}catch(u){o={error:u}}finally{try{s&&!s.done&&(t=r.return)&&t.call(r)}finally{if(o)throw o.error}}return n}function H(i,e,t){if(t||arguments.length===2)for(var r=0,s=e.length,n;r<s;r++)(n||!(r in e))&&(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return i.concat(n||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;function b(i){return typeof i=="function"}function et(i){var e=function(r){Error.call(r),r.stack=new Error().stack},t=i(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var W=et(function(i){return function(t){i(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
2
|
+
`+t.map(function(r,s){return s+1+") "+r.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=t}});function M(i,e){if(i){var t=i.indexOf(e);0<=t&&i.splice(t,1)}}var D=function(){function i(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return i.prototype.unsubscribe=function(){var e,t,r,s,n;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var u=G(o),c=u.next();!c.done;c=u.next()){var E=c.value;E.remove(this)}}catch(d){e={error:d}}finally{try{c&&!c.done&&(t=u.return)&&t.call(u)}finally{if(e)throw e.error}}else o.remove(this);var O=this.initialTeardown;if(b(O))try{O()}catch(d){n=d instanceof W?d.errors:[d]}var R=this._finalizers;if(R){this._finalizers=null;try{for(var S=G(R),g=S.next();!g.done;g=S.next()){var C=g.value;try{st(C)}catch(d){n=n??[],d instanceof W?n=H(H([],N(n)),N(d.errors)):n.push(d)}}}catch(d){r={error:d}}finally{try{g&&!g.done&&(s=S.return)&&s.call(S)}finally{if(r)throw r.error}}}if(n)throw new W(n)}},i.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)st(e);else{if(e instanceof i){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},i.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},i.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},i.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&M(t,e)},i.prototype.remove=function(e){var t=this._finalizers;t&&M(t,e),e instanceof i&&e._removeParent(this)},i.EMPTY=function(){var e=new i;return e.closed=!0,e}(),i}(),rt=D.EMPTY;function it(i){return i instanceof D||i&&"closed"in i&&b(i.remove)&&b(i.add)&&b(i.unsubscribe)}function st(i){b(i)?i():i.unsubscribe()}var nt={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ot={setTimeout:function(i,e){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];return setTimeout.apply(void 0,H([i,e],N(t)))},clearTimeout:function(i){var e=ot.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(i)},delegate:void 0};function Rt(i){ot.setTimeout(function(){throw i})}function ut(){}function P(i){i()}var at=function(i){$(e,i);function e(t){var r=i.call(this)||this;return r.isStopped=!1,t?(r.destination=t,it(t)&&t.add(r)):r.destination=It,r}return e.create=function(t,r,s){return new Y(t,r,s)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,i.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(D),xt=Function.prototype.bind;function F(i,e){return xt.call(i,e)}var Dt=function(){function i(e){this.partialObserver=e}return i.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(r){I(r)}},i.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(r){I(r)}else I(e)},i.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){I(t)}},i}(),Y=function(i){$(e,i);function e(t,r,s){var n=i.call(this)||this,o;if(b(t)||!t)o={next:t??void 0,error:r??void 0,complete:s??void 0};else{var u;n&&nt.useDeprecatedNextContext?(u=Object.create(t),u.unsubscribe=function(){return n.unsubscribe()},o={next:t.next&&F(t.next,u),error:t.error&&F(t.error,u),complete:t.complete&&F(t.complete,u)}):o=t}return n.destination=new Dt(o),n}return e}(at);function I(i){Rt(i)}function Pt(i){throw i}var It={closed:!0,next:ut,error:Pt,complete:ut},Ut=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function qt(i){return i}function Bt(i){return i.length===0?qt:i.length===1?i[0]:function(t){return i.reduce(function(r,s){return s(r)},t)}}var ct=function(){function i(e){e&&(this._subscribe=e)}return i.prototype.lift=function(e){var t=new i;return t.source=this,t.operator=e,t},i.prototype.subscribe=function(e,t,r){var s=this,n=jt(e)?e:new Y(e,t,r);return P(function(){var o=s,u=o.operator,c=o.source;n.add(u?u.call(n,c):c?s._subscribe(n):s._trySubscribe(n))}),n},i.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},i.prototype.forEach=function(e,t){var r=this;return t=ht(t),new t(function(s,n){var o=new Y({next:function(u){try{e(u)}catch(c){n(c),o.unsubscribe()}},error:n,complete:s});r.subscribe(o)})},i.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},i.prototype[Ut]=function(){return this},i.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Bt(e)(this)},i.prototype.toPromise=function(e){var t=this;return e=ht(e),new e(function(r,s){var n;t.subscribe(function(o){return n=o},function(o){return s(o)},function(){return r(n)})})},i.create=function(e){return new i(e)},i}();function ht(i){var e;return(e=i??nt.Promise)!==null&&e!==void 0?e:Promise}function Ct(i){return i&&b(i.next)&&b(i.error)&&b(i.complete)}function jt(i){return i&&i instanceof at||Ct(i)&&it(i)}var kt=et(function(i){return function(){i(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),lt=function(i){$(e,i);function e(){var t=i.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var r=new dt(this,this);return r.operator=t,r},e.prototype._throwIfClosed=function(){if(this.closed)throw new kt},e.prototype.next=function(t){var r=this;P(function(){var s,n;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=G(r.currentObservers),u=o.next();!u.done;u=o.next()){var c=u.value;c.next(t)}}catch(E){s={error:E}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(s)throw s.error}}}})},e.prototype.error=function(t){var r=this;P(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=t;for(var s=r.observers;s.length;)s.shift().error(t)}})},e.prototype.complete=function(){var t=this;P(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var r=t.observers;r.length;)r.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),i.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var r=this,s=this,n=s.hasError,o=s.isStopped,u=s.observers;return n||o?rt:(this.currentObservers=null,u.push(t),new D(function(){r.currentObservers=null,M(u,t)}))},e.prototype._checkFinalizedStatuses=function(t){var r=this,s=r.hasError,n=r.thrownError,o=r.isStopped;s?t.error(n):o&&t.complete()},e.prototype.asObservable=function(){var t=new ct;return t.source=this,t},e.create=function(t,r){return new dt(t,r)},e}(ct),dt=function(i){$(e,i);function e(t,r){var s=i.call(this)||this;return s.destination=t,s.source=r,s}return e.prototype.next=function(t){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,t)},e.prototype.error=function(t){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,t)},e.prototype.complete=function(){var t,r;(r=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||r===void 0||r.call(t)},e.prototype._subscribe=function(t){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(t))!==null&&s!==void 0?s:rt},e}(lt),U=function(i){$(e,i);function e(t){var r=i.call(this)||this;return r._value=t,r}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(t){var r=i.prototype._subscribe.call(this,t);return!r.closed&&t.next(this._value),r},e.prototype.getValue=function(){var t=this,r=t.hasError,s=t.thrownError,n=t._value;if(r)throw s;return this._throwIfClosed(),n},e.prototype.next=function(t){i.prototype.next.call(this,this._value=t)},e}(lt),pt=(i=>(i[i.DISABLED=0]="DISABLED",i[i.CRON=1]="CRON",i[i.EVENT=2]="EVENT",i[i.GET=3]="GET",i[i.POST=4]="POST",i[i.PATCH=5]="PATCH",i[i.PUT=6]="PUT",i[i.DELETE=7]="DELETE",i))(pt||{});class ft extends f{constructor(t){super();a(this,"api");a(this,"$cache",new U([]));this.api=typeof t=="string"?new m(t):t}get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}delete(t){return this.api.request({url:`/api/actions/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter(r=>r._id!=t),this.emit("DELETE",t)})}list(){return this.api.request({url:"/api/actions"}).then(t=>(this.cache=t,this.emit("LIST",t),t))}read(t,r=!1){const s=this.cache.find(n=>n._id==t);return!r&&s?Promise.resolve(s):this.api.request({url:`/api/actions/${t}`}).then(n=>(n&&(this.cache=this.cache.filter(o=>o._id!=t).concat([n])),this.emit("READ",n),n))}run(t,r={}){return this.api.request({url:("/api/actions/run/"+t).replaceAll("//","/"),...r})}runById(t,r={}){const s=typeof t=="string"?t:t._id;return this.api.request({url:"/api/actions/run-by-id/"+s,...r})}update(t){return this.api.request({url:`/api/actions${t._id?`/${t._id}`:""}`,method:"POST",body:t}).then(r=>(r&&(this.cache=this.cache.filter(s=>s._id!=r._id).concat([r])),this.emit("UPDATE",r),r))}}class mt extends f{constructor(t,r){var s;super();a(this,"api");a(this,"storageKey");a(this,"$user",new U(void 0));if(this.opts=r,this.api=typeof t=="string"?new m(t):t,(s=this.opts)!=null&&s.loginUi||(this.opts={...this.opts,loginUi:this.api.url+"/ui/login"}),this.storageKey=`momentum:${new URL(this.api.url).host}`,this.api.on("TOKEN",n=>{var o;(o=this.opts)!=null&&o.persist&&(n?localStorage.setItem(this.storageKey,n):localStorage.removeItem(this.storageKey)),n?this.whoAmI(n,!0):this.user=null}),r!=null&&r.persist){const n=localStorage.getItem(this.storageKey);n?this.api.token=n:this.user=null}else this.user=null}get user(){return this.$user.value}set user(t){if(!K(this.user,t)){const r=t||null;this.$user.next(r),this.emit("USER",r)}}knownHost(t=location.origin){return t.startsWith("/")?Promise.resolve():this.api.request({url:`/api/auth/known-host?host=${encodeURI(new URL(t).origin)}`})}login(t,r){return this.api.request({url:"/api/auth/login",headers:{Authorization:void 0},body:{username:t,password:r}}).then(async s=>(this.api.token=s.token,await this.once("USER")))}loginRedirect(t=location.origin){return new Promise((r,s)=>{var o;const n=window.open(encodeURI(`${(o=this.opts)==null?void 0:o.loginUi}?redirect=postmessage&host=${t}`),"_blank");if(!n)return s("Unable to open login");n.addEventListener("message",u=>{var c;if(!((c=u==null?void 0:u.data)!=null&&c.token))return s("Unknown response from login");this.api.token=u.data.token,r(u.data.token),n.close()})})}logout(){this.api.token=null,this.user=null,this.emit("LOGOUT")}async register(t){const r=await this.api.request({url:"/api/auth/register",body:{...t}});return this.emit("REGISTER",t),r}async reset(t,r){await this.api.request({url:"/api/auth/reset",headers:{Authorization:r?`Bearer ${r}`:void 0},body:{email:r?void 0:t,password:r?t:void 0}}),this.emit(r?"RESET_COMPLETE":"RESET_REQUEST",r||t)}async whoAmI(t,r=!1){t||(t=this.api.token);const s=await this.api.request({url:"/api/auth/whoami",headers:t?{Authorization:`Bearer ${t}`}:void 0});return r&&(this.api.token=t,this.user=(s==null?void 0:s.user)||null,s&&this.emit("LOGIN",s.user)),s}}class Et extends f{constructor(t){super();a(this,"api");this.api=typeof t=="string"?new m(t):t}delete(t,r){return this.api.request({url:`/api/data/${t}/${r}`,method:"DELETE"}).then(()=>this.emit("DELETE",t,r))}get(t,r){return this.api.request({url:`/api/data/${t}${r?`/${r}`:""}`}).then(s=>(this.emit("GET",t,s),s))}raw(t,r,s,n){return this.api.request({url:`/api/data/${t}`,body:{operand:r,query:s,options:n}}).then(o=>(this.emit("RAW",t,o),o))}set(t,r,s=!1){return this.api.request({url:`/api/data/${t}/${r._id||""}`,method:s?"PATCH":"POST",body:r}).then(n=>(this.emit("SET",t,r),n))}}class yt extends f{constructor(t){super();a(this,"api");this.api=typeof t=="string"?new m(t):t}send(t){let r="/api/email/send";return typeof t.body=="object"&&(r+=`/${t.body.template}`),this.api.request({url:r,body:t}).then(s=>(this.emit("SENT",t),s))}}class gt extends f{constructor(t){super();a(this,"api");this.api=typeof t=="string"?new m(t):t}create(t){return this.api.request({url:`/api/groups/${t.name}`,method:"POST",body:t}).then(r=>(this.emit("CREATE",r),r))}list(){return this.api.request({url:"/api/groups"}).then(t=>(this.emit("LIST",t),t))}read(t){return this.api.request({url:`/api/groups/${t}`}).then(r=>(this.emit("READ",r),r))}update(t){return this.api.request({url:`/api/groups/${t.name}`,method:"PATCH",body:t}).then(r=>(this.emit("UPDATE",r),r))}delete(t){return this.api.request({url:`/api/groups/${t}`,method:"DELETE"}).then(()=>this.emit("DELETE",t))}}class bt{constructor(e,t){a(this,"api");this.api=typeof e=="string"?new m(e):e,t!=null&&t!="NONE"&&(window.addEventListener("error",r=>this.error(r.error.stack)),window.addEventListener("unhandledrejection",async r=>this.error(r.reason.stack)))}buildLog(e,t){return{time:new Date().getTime(),level:e,log:t,ctx:{url:location.href,res:[window.innerWidth,window.innerHeight]}}}clearClientLogs(){return this.api.request({url:"/api/logs/client",method:"DELETE"})}clearServerLogs(){return this.api.request({url:"/api/logs/server",method:"DELETE"})}clientLogs(e,t){const r=[e?`length=${e}`:void 0,t?`page=${t}`:void 0].filter(s=>!!s).join("&");return this.api.request({url:`/api/logs/client${r?`?${r}`:""}`})}serverLogs(e,t){const r=[e?`length=${e}`:void 0,t?`page=${t}`:void 0].filter(s=>!!s).join("&");return this.api.request({url:`/api/logs/server${r?`?${r}`:""}`})}debug(...e){return this.api.request({url:"/api/logs/client",body:this.buildLog(T.DEBUG,e)}).catch(()=>{})}log(...e){return this.api.request({url:"/api/logs/client",body:this.buildLog(T.LOG,e)}).catch(()=>{})}info(...e){return this.api.request({url:"/api/logs/client",body:this.buildLog(T.INFO,e)}).catch(()=>{})}warn(...e){return this.api.request({url:"/api/logs/client",body:this.buildLog(T.WARN,e)}).catch(()=>{})}error(...e){return this.api.request({url:"/api/logs/client",body:this.buildLog(T.ERROR,e)}).catch(()=>{})}}const B=class B{constructor(e){a(this,"api");a(this,"url");a(this,"connection");a(this,"open",!1);this.api=typeof e=="string"?new m(e):e,this.url=this.api.url.replace("http","ws"),this.api.on("TOKEN",()=>this.connect()),this.api.token||this.connect()}close(){console.debug("Disconnected from Momentum"),this.open=!1,this.connection.close()}connect(e=3){var r;((r=this.connection)==null?void 0:r.readyState)<2&&this.connection.close(),this.connection=new WebSocket(this.url+(this.api.token?`?token=${this.api.token}`:""));const t=setTimeout(()=>{this.open||(this.connection.close(),console.error("Momentum connection timeout"),e>0&&this.connect(e-1))},B.timeout);this.connection.onclose=()=>this.open=!1,this.connection.onmessage=this.handle,this.connection.onopen=()=>{this.open=!0,clearTimeout(t),console.debug("Connected to Momentum")}}handle(...e){console.log(e)}send(e,t){this.connection.send(JSON.stringify({token:this.api.token,channel:e,payload:t}))}};a(B,"timeout",1e4);let q=B;class vt extends f{constructor(t){super();a(this,"api");this.api=typeof t=="string"?new m(t):t}delete(t){const r=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:r,method:"DELETE"}).then(()=>{this.emit("DELETE",r)})}list(t){const r=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:r+"?list"}).then(s=>(this.emit("LIST",t,s),s))}open(t,r="_blank"){const s=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/"),n=`${this.api.url}${s}${this.api.token?`?token=${this.api.token}`:""}`;return r?(this.emit("OPEN",t),window.open(n,r)):n}mkdir(t){const r=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/");return this.api.request({url:r+"?directory",method:"POST"})}download(t,r={}){return new $t((s,n,o)=>{const u=("/api/storage/"+t).replaceAll("//","/");this.api.request({...r,url:u,skipConverting:!0}).then(c=>{var d;if(!c.ok)return n(c.statusText);const E=c.headers.get("Content-Length"),O=E?parseInt(E,10):0;let R=[],S=0;const g=(d=c.body)==null?void 0:d.getReader(),C=Tt=>{if(Tt.done){o(1);const A=new Blob(R),V=r.downloadName||new URL(c.url).pathname.split("/").pop(),Ot=URL.createObjectURL(A);_t(Ot,V.includes(".")?V:V+".zip"),URL.revokeObjectURL(Ot),this.emit("DOWNLOAD",t,A),s(A)}else{const A=Tt.value;R.push(A),S+=A.length,o(S/O),g.read().then(C)}};g==null||g.read().then(C)})})}async upload(t,r=""){if(t||(t=await new Promise(u=>{const c=document.createElement("input");c.type="file",c.accept=(r==null?void 0:r.accept)||"*",c.style.display="none",c.multiple=!!(r!=null&&r.multiple),c.onblur=c.onchange=async()=>{u(Array.from(c.files)),c.remove()},document.body.appendChild(c),c.click()})),!t||Array.isArray(t)&&!t.length)return[];const n=new FormData,o=("/api/storage/"+(typeof r=="string"?r:r==null?void 0:r.path)).replaceAll("//","/");return(Array.isArray(t)?t:[t]).forEach(u=>n.append("file",u)),this.api.request({url:o,body:n}).then(u=>(this.emit("UPLOAD",u),u))}}class wt extends f{constructor(t){super();a(this,"api");a(this,"listed",!1);a(this,"$cache",new U([]));this.api=typeof t=="string"?new m(t):t}get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}delete(t){return this.api.request({url:`/api/users/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter(r=>r.username!=t),this.emit("DELETE",t)})}list(t=!1){return!t&&this.listed?Promise.resolve(this.cache):this.api.request({url:"/api/users"}).then(r=>(this.cache=r,this.listed=!0,this.emit("LIST",r),r))}read(t,r=!1){if(!r){const s=this.cache.find(n=>n.username==t);if(s)return Promise.resolve(s)}return this.api.request({url:`/api/users/${t}`}).then(s=>(s&&(this.cache={...this.cache,[s.username]:s}),this.emit("READ",s),s))}update(t){return this.api.request({url:`/api/users/${t.username}`,method:"PATCH",body:t}).then(r=>(r&&(this.cache=this.cache.filter(s=>s.username!=t.username).concat([r])),this.emit("UPDATE",r),r))}}class St extends f{constructor(t){super();a(this,"api");a(this,"$cache",new U({}));this.api=typeof t=="string"?new m(t):t}get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}list(t=!1){return this.api.request({url:"/api/settings"+(t?"?detailed":"")}).then(r=>(this.cache=t?Object.values(r).reduce((s,n)=>({...s,[n.key]:n.value}),{}):r,this.emit("LIST",r),r))}delete(t){return this.api.request({url:`/api/settings/${t}`,method:"DELETE"}).then(()=>{this.cache={...this.cache,[t]:void 0},this.emit("DELETE",t)})}read(t,r=!1){return!r&&this.cache[t]?Promise.resolve(this.cache[t]):this.api.request({url:`/api/settings/${t}`}).then(s=>(s&&(this.cache={...this.cache,[s.key]:s}),this.emit("READ",s),s))}update(t){return this.api.request({url:`/api/settings/${t.key}`,body:t}).then(r=>(r&&(this.cache={...this.cache,[r.key]:r.value}),this.emit("UPDATE",r),r))}}class Lt extends f{constructor(t){super();a(this,"api");this.api=typeof t=="string"?new m(t):t}delete(t){return this.api.request({url:`/api/static/${t}`,method:"DELETE"}).then(()=>{this.emit("DELETE",t)})}list(t){const r=("/api/static/"+t).replaceAll("//","/");return this.api.request({url:r}).then(s=>(this.emit("LIST",t,s),s))}upload(t,r="/"){const s=new FormData;return(Array.isArray(t)?t:[t]).forEach(n=>s.append("file",n)),this.api.request({url:"/api/static"+r,body:s}).then(n=>(this.emit("UPLOAD",n),n))}}class Gt extends f{constructor(t,r){super();a(this,"api");a(this,"actions");a(this,"auth");a(this,"data");a(this,"email");a(this,"groups");a(this,"logger");a(this,"settings");a(this,"socket");a(this,"static");a(this,"storage");a(this,"users");this.api=new m(t,r==null?void 0:r.api),this.actions=new ft(this.api),this.auth=new mt(this.api,{persist:(r==null?void 0:r.persist)??!0,loginUi:r==null?void 0:r.loginUi}),this.data=new Et(this.api),this.email=new yt(this.api),this.groups=new gt(this.api),this.logger=new bt(this.api,r==null?void 0:r.logLevel),this.settings=new St(this.api),this.static=new Lt(this.api),this.storage=new vt(this.api),this.users=new wt(this.api),r!=null&&r.socket&&(this.socket=new q(this.api)),this.api.on("*",(s,...n)=>this.emit(`API::${s}`,...n)),this.actions.on("*",(s,...n)=>this.emit(`ACTIONS::${s}`,...n)),this.auth.on("*",(s,...n)=>this.emit(`AUTH::${s}`,...n)),this.data.on("*",(s,...n)=>this.emit(`DATA::${s}`,...n)),this.email.on("*",(s,...n)=>this.emit(`EMAIL::${s}`,...n)),this.groups.on("*",(s,...n)=>this.emit(`GROUPS::${s}`,...n)),this.settings.on("*",(s,...n)=>this.emit(`SETTINGS::${s}`,...n)),this.static.on("*",(s,...n)=>this.emit(`STATIC::${s}`,...n)),this.storage.on("*",(s,...n)=>this.emit(`STORAGE::${s}`,...n)),this.users.on("*",(s,...n)=>this.emit(`USERS::${s}`,...n)),this.users.on("*",(s,...n)=>{var o;if(Array.isArray(n[0])){const u=n[0].find(c=>{var E;return c._id==((E=this.auth.user)==null?void 0:E._id)});u&&(this.auth.user=u)}else n[0]._id==((o=this.auth.user)==null?void 0:o._id)&&(this.auth.user=n[0])})}}h.ActionType=pt,h.Actions=ft,h.Api=m,h.Auth=mt,h.Data=Et,h.Email=yt,h.Groups=gt,h.Logger=bt,h.Momentum=Gt,h.Settings=St,h.Socket=q,h.Static=Lt,h.Storage=vt,h.Users=wt,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
4
|
+
//# sourceMappingURL=momentum.cjs.map
|