@ztimson/momentum 0.27.2 → 0.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +3 -3
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +16 -13
- package/dist/api.d.ts +8 -8
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +3 -2
- package/dist/auth.d.ts +4 -4
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +17 -15
- package/dist/data.js +6 -6
- package/dist/email.d.ts +1 -1
- package/dist/email.js +1 -1
- package/dist/groups.d.ts +1 -1
- package/dist/groups.d.ts.map +1 -1
- package/dist/groups.js +8 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -1
- package/dist/logger.d.ts +7 -7
- package/dist/logger.js +7 -7
- package/dist/momentum.d.ts +5 -2
- package/dist/momentum.d.ts.map +1 -1
- package/dist/momentum.js +6 -0
- package/dist/payments.d.ts +15 -0
- package/dist/payments.d.ts.map +1 -0
- package/dist/payments.js +51 -0
- package/dist/pdf.d.ts +3 -3
- package/dist/settings.js +11 -11
- package/dist/static.js +4 -4
- package/dist/storage.d.ts +3 -3
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +26 -59
- package/dist/users.d.ts +4 -3
- package/dist/users.d.ts.map +1 -1
- package/dist/users.js +22 -18
- package/package.json +2 -2
package/dist/actions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Api } from './api';
|
|
2
|
-
import {
|
|
2
|
+
import { HttpRequestOptions, TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
3
3
|
import { BehaviorSubject } from 'rxjs';
|
|
4
4
|
import { Meta } from './core';
|
|
5
5
|
export type Action = Meta & {
|
|
@@ -45,8 +45,8 @@ export declare class Actions extends TypedEmitter<ActionEvents> {
|
|
|
45
45
|
delete(id: string): Promise<void>;
|
|
46
46
|
list(): Promise<Action[]>;
|
|
47
47
|
read(id: string, reload?: boolean): Promise<Action | null>;
|
|
48
|
-
run<T>(path: string, opts?:
|
|
49
|
-
runById(action: string | Action, opts?:
|
|
48
|
+
run<T>(path: string, opts?: HttpRequestOptions): import("@ztimson/utils").PromiseProgress<any>;
|
|
49
|
+
runById(action: string | Action, opts?: HttpRequestOptions): import("@ztimson/utils").PromiseProgress<any>;
|
|
50
50
|
update(action: Action): Promise<Action>;
|
|
51
51
|
}
|
|
52
52
|
//# sourceMappingURL=actions.d.ts.map
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -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,
|
|
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,kBAAkB,EAAE,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAClF,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,CAAC,EAAE,OAAO,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,E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AAM,EAAE,IAAI,GAAE,kBAAuB;IAM9D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAWvC"}
|
package/dist/actions.js
CHANGED
|
@@ -31,9 +31,10 @@ class Actions extends utils_1.TypedEmitter {
|
|
|
31
31
|
}
|
|
32
32
|
list() {
|
|
33
33
|
return this.api.request({ url: `/api/actions` }).then(resp => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
if (resp.data)
|
|
35
|
+
this.cache = resp.data;
|
|
36
|
+
this.emit('LIST', resp.data || []);
|
|
37
|
+
return resp.data;
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
read(id, reload = false) {
|
|
@@ -41,18 +42,20 @@ class Actions extends utils_1.TypedEmitter {
|
|
|
41
42
|
if (!reload && cached)
|
|
42
43
|
return Promise.resolve(cached);
|
|
43
44
|
return this.api.request({ url: `/api/actions/${id}` }).then(action => {
|
|
44
|
-
if (action)
|
|
45
|
-
this.cache = this.cache.filter(a => a._id != id).concat([action]);
|
|
46
|
-
this.emit('READ', action);
|
|
47
|
-
return action;
|
|
45
|
+
if (action.data)
|
|
46
|
+
this.cache = this.cache.filter(a => a._id != id).concat([action.data]);
|
|
47
|
+
this.emit('READ', action.data);
|
|
48
|
+
return action.data;
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
run(path, opts = {}) {
|
|
51
|
-
return this.api.request({ url: (`/api/actions/run/` + path).replaceAll('//', '/'), ...opts })
|
|
52
|
+
return this.api.request({ url: (`/api/actions/run/` + path).replaceAll('//', '/'), ...opts })
|
|
53
|
+
.then(resp => resp.data);
|
|
52
54
|
}
|
|
53
55
|
runById(action, opts = {}) {
|
|
54
56
|
const id = typeof action == 'string' ? action : action._id;
|
|
55
|
-
return this.api.request({ url: '/api/actions/run-by-id/' + id, method: 'POST', ...opts })
|
|
57
|
+
return this.api.request({ url: '/api/actions/run-by-id/' + id, method: 'POST', ...opts })
|
|
58
|
+
.then(resp => resp.data);
|
|
56
59
|
}
|
|
57
60
|
update(action) {
|
|
58
61
|
return this.api.request({
|
|
@@ -60,10 +63,10 @@ class Actions extends utils_1.TypedEmitter {
|
|
|
60
63
|
method: 'POST',
|
|
61
64
|
body: action
|
|
62
65
|
}).then(action => {
|
|
63
|
-
if (action)
|
|
64
|
-
this.cache = this.cache.filter(a => a._id != action._id).concat([action]);
|
|
65
|
-
this.emit('UPDATE', action);
|
|
66
|
-
return action;
|
|
66
|
+
if (action.data)
|
|
67
|
+
this.cache = this.cache.filter(a => a._id != action.data?._id).concat([action.data]);
|
|
68
|
+
this.emit('UPDATE', action.data);
|
|
69
|
+
return action.data;
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
}
|
package/dist/api.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DecodedResponse, Http, HttpDefaults, HttpRequestOptions, PromiseProgress, type TypedEvents } from '@ztimson/utils';
|
|
2
2
|
export type ApiEvents = TypedEvents & {
|
|
3
|
-
REQUEST: (request: Promise<any>, options:
|
|
4
|
-
RESPONSE: (response: any, options:
|
|
5
|
-
REJECTED: (response: Error, options:
|
|
3
|
+
REQUEST: (request: Promise<any>, options: HttpRequestOptions) => any;
|
|
4
|
+
RESPONSE: (response: any, options: HttpRequestOptions) => any;
|
|
5
|
+
REJECTED: (response: Error, options: HttpRequestOptions) => any;
|
|
6
6
|
TOKEN: (token: string | null) => any;
|
|
7
7
|
};
|
|
8
|
-
export declare class Api extends
|
|
8
|
+
export declare class Api extends Http {
|
|
9
9
|
readonly url: string;
|
|
10
|
-
readonly opts:
|
|
10
|
+
readonly opts: HttpDefaults;
|
|
11
11
|
private emitter;
|
|
12
12
|
private _token;
|
|
13
13
|
get token(): string | null;
|
|
14
14
|
set token(token: string | null);
|
|
15
|
-
constructor(url?: string, opts?:
|
|
15
|
+
constructor(url?: string, opts?: HttpDefaults);
|
|
16
16
|
emit: <K extends string | symbol>(event: K, ...args: Parameters<ApiEvents[K]>) => void;
|
|
17
17
|
off: <K extends string | symbol = string>(event: K, listener: ApiEvents[K]) => void;
|
|
18
18
|
on: <K extends string | symbol = string>(event: K, listener: ApiEvents[K]) => () => void;
|
|
19
19
|
once: <K extends string | symbol = string>(event: K, listener?: ApiEvents[K] | undefined) => Promise<any>;
|
|
20
|
-
request<T>(options:
|
|
20
|
+
request<T>(options: HttpRequestOptions): PromiseProgress<DecodedResponse<T>>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,IAAI,EAAE,YAAY,EAClB,kBAAkB,EAClB,eAAe,EAEf,KAAK,WAAW,EAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IACrC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IACrE,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IAC9D,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IAChE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,GAAG,CAAA;CACpC,CAAA;AAED,qBAAa,GAAI,SAAQ,IAAI;aAYA,GAAG,EAAE,MAAM;aAAoC,IAAI,EAAE,YAAY;IAX7F,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,YAAiB;IAKlG,IAAI,mFAAwC;IAC5C,GAAG,iFAAuC;IAC1C,EAAE,uFAAsC;IACxC,IAAI,sGAAwC;IAE5C,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;CAY5E"}
|
package/dist/api.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Api = void 0;
|
|
4
4
|
const utils_1 = require("@ztimson/utils");
|
|
5
|
-
class Api extends utils_1.
|
|
5
|
+
class Api extends utils_1.Http {
|
|
6
6
|
url;
|
|
7
7
|
opts;
|
|
8
8
|
emitter = new utils_1.TypedEmitter();
|
|
@@ -26,7 +26,8 @@ class Api extends utils_1.XHR {
|
|
|
26
26
|
on = this.emitter.on.bind(this.emitter);
|
|
27
27
|
once = this.emitter.once.bind(this.emitter);
|
|
28
28
|
request(options) {
|
|
29
|
-
const req = super.request(options)
|
|
29
|
+
const req = super.request(options)
|
|
30
|
+
.then(resp => {
|
|
30
31
|
this.emit('RESPONSE', resp, options);
|
|
31
32
|
return resp;
|
|
32
33
|
}).catch(err => {
|
package/dist/auth.d.ts
CHANGED
|
@@ -16,10 +16,10 @@ export type AuthOptions = {
|
|
|
16
16
|
export declare class Totp {
|
|
17
17
|
private api;
|
|
18
18
|
constructor(api: Api);
|
|
19
|
-
disable(username: string):
|
|
20
|
-
enable: (username: string) =>
|
|
21
|
-
reset(username: string):
|
|
22
|
-
setup(username: string, method?: string, totp?: string):
|
|
19
|
+
disable(username: string): import("@ztimson/utils").PromiseProgress<import("@ztimson/utils").DecodedResponse<void>>;
|
|
20
|
+
enable: (username: string) => import("@ztimson/utils").PromiseProgress<import("@ztimson/utils").DecodedResponse<void>>;
|
|
21
|
+
reset(username: string): import("@ztimson/utils").PromiseProgress<import("@ztimson/utils").DecodedResponse<void>>;
|
|
22
|
+
setup(username: string, method?: string, totp?: string): import("@ztimson/utils").PromiseProgress<import("@ztimson/utils").DecodedResponse<void>>;
|
|
23
23
|
}
|
|
24
24
|
export declare class Auth extends TypedEmitter<AuthEvents> {
|
|
25
25
|
private readonly opts?;
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +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,EAAiB,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAElC,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,eAAe,EAAE,MAAM,GAAG,CAAC;CAC3B,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAA;AAED,qBAAa,IAAI;IACJ,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,GAAG;IAE5B,OAAO,CAAC,QAAQ,EAAE,MAAM;IAIxB,MAAM,aAEU,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.d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
|
|
|
82
82
|
knownHost(host = location.origin) {
|
|
83
83
|
if (host.startsWith('/'))
|
|
84
84
|
return Promise.resolve();
|
|
85
|
-
return this.api.request({ url: `/api/auth/known-host?host=${encodeURI(new URL(host).origin)}` })
|
|
85
|
+
return this.api.request({ url: `/api/auth/known-host?host=${encodeURI(new URL(host).origin)}` })
|
|
86
|
+
.then(() => { });
|
|
86
87
|
}
|
|
87
88
|
login(username, password, totp) {
|
|
88
89
|
return this.api.request({
|
|
89
90
|
url: '/api/auth/login',
|
|
90
91
|
headers: { Authorization: undefined },
|
|
92
|
+
method: 'POST',
|
|
91
93
|
body: {
|
|
92
94
|
username: username.trim(),
|
|
93
95
|
password: password.trim(),
|
|
94
96
|
totp,
|
|
95
97
|
}
|
|
96
98
|
}).then(async (resp) => {
|
|
97
|
-
this.api.token = resp.token;
|
|
99
|
+
this.api.token = resp.data?.token || null;
|
|
98
100
|
return await this.once('USER');
|
|
99
101
|
});
|
|
100
102
|
}
|
|
@@ -118,8 +120,8 @@ class Auth extends utils_1.TypedEmitter {
|
|
|
118
120
|
this.emit('LOGOUT');
|
|
119
121
|
}
|
|
120
122
|
async register(u) {
|
|
121
|
-
const user = await this.api.request({ url: '/api/auth/register', body: { ...u } });
|
|
122
|
-
if (user
|
|
123
|
+
const user = (await this.api.request({ url: '/api/auth/register', body: { ...u } }))?.data;
|
|
124
|
+
if (user?.image?.startsWith('/'))
|
|
123
125
|
user.image = `${this.api.url}${user.image}?token=${this.api.token}`;
|
|
124
126
|
this.emit('REGISTER', user);
|
|
125
127
|
return user;
|
|
@@ -132,32 +134,32 @@ class Auth extends utils_1.TypedEmitter {
|
|
|
132
134
|
email: token ? undefined : emailOrPass,
|
|
133
135
|
password: token ? emailOrPass : undefined,
|
|
134
136
|
}
|
|
135
|
-
});
|
|
137
|
+
}).then(() => { });
|
|
136
138
|
}
|
|
137
139
|
async session(token, set = false) {
|
|
138
140
|
if (!token)
|
|
139
141
|
token = this.api.token;
|
|
140
|
-
const
|
|
142
|
+
const session = (await this.api.request({
|
|
141
143
|
url: '/api/auth/session',
|
|
142
144
|
headers: token ? { 'Authorization': `Bearer ${token}` } : undefined
|
|
143
|
-
});
|
|
145
|
+
}))?.data;
|
|
144
146
|
if (set) {
|
|
145
147
|
this.api.token = token;
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
this.user =
|
|
149
|
-
if (
|
|
150
|
-
this.emit('LOGIN',
|
|
148
|
+
if (session?.user)
|
|
149
|
+
session.user.image = `${this.api.url}${session.user.image}?token=${this.api.token}`;
|
|
150
|
+
this.user = session?.user || null;
|
|
151
|
+
if (session)
|
|
152
|
+
this.emit('LOGIN', session.user);
|
|
151
153
|
}
|
|
152
|
-
return
|
|
154
|
+
return session;
|
|
153
155
|
}
|
|
154
156
|
async updatePassword(username, password, oldPassword) {
|
|
155
157
|
return this.api.request({
|
|
156
158
|
url: '/api/auth/password',
|
|
157
159
|
body: { username, password, oldPassword }
|
|
158
160
|
}).then(resp => {
|
|
159
|
-
if (resp?.token)
|
|
160
|
-
this.api.token = resp.token;
|
|
161
|
+
if (resp?.data?.token)
|
|
162
|
+
this.api.token = resp.data.token;
|
|
161
163
|
});
|
|
162
164
|
}
|
|
163
165
|
}
|
package/dist/data.js
CHANGED
|
@@ -17,8 +17,8 @@ class Data extends utils_1.TypedEmitter {
|
|
|
17
17
|
}
|
|
18
18
|
get(collection, document) {
|
|
19
19
|
return this.api.request({ url: `/api/data/${collection}${document ? `/${document}` : ''}` }).then(resp => {
|
|
20
|
-
this.emit('GET', collection, resp);
|
|
21
|
-
return resp;
|
|
20
|
+
this.emit('GET', collection, resp.data);
|
|
21
|
+
return resp.data;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
raw(collection, operand, query, options) {
|
|
@@ -30,8 +30,8 @@ class Data extends utils_1.TypedEmitter {
|
|
|
30
30
|
options,
|
|
31
31
|
}
|
|
32
32
|
}).then(resp => {
|
|
33
|
-
this.emit('RAW', collection, resp);
|
|
34
|
-
return resp;
|
|
33
|
+
this.emit('RAW', collection, resp.data);
|
|
34
|
+
return resp.data;
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
set(collection, document, append = false) {
|
|
@@ -40,8 +40,8 @@ class Data extends utils_1.TypedEmitter {
|
|
|
40
40
|
method: append ? 'PATCH' : 'POST',
|
|
41
41
|
body: document
|
|
42
42
|
}).then(resp => {
|
|
43
|
-
this.emit('SET', collection,
|
|
44
|
-
return resp;
|
|
43
|
+
this.emit('SET', collection, resp.data);
|
|
44
|
+
return resp.data;
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
package/dist/email.d.ts
CHANGED
|
@@ -17,6 +17,6 @@ export type EmailEvents = TypedEvents & {
|
|
|
17
17
|
export declare class Email extends TypedEmitter<EmailEvents> {
|
|
18
18
|
private readonly api;
|
|
19
19
|
constructor(api: Api | string);
|
|
20
|
-
send(email: Mail):
|
|
20
|
+
send(email: Mail): import("@ztimson/utils").PromiseProgress<any>;
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=email.d.ts.map
|
package/dist/email.js
CHANGED
package/dist/groups.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type Group = Meta & {
|
|
|
12
12
|
export type GroupEvents = TypedEvents & {
|
|
13
13
|
LIST: (users: Group[]) => any;
|
|
14
14
|
CREATE: (user: Group) => any;
|
|
15
|
-
READ: (user: Group) => any;
|
|
15
|
+
READ: (user: Group | null) => any;
|
|
16
16
|
UPDATE: (user: Group) => any;
|
|
17
17
|
DELETE: (name: string) => any;
|
|
18
18
|
};
|
package/dist/groups.d.ts.map
CHANGED
|
@@ -1 +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,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EA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EAAE,KAAK,GAAG,IAAI,KAAK,GAAG,CAAC;IAClC,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/groups.js
CHANGED
|
@@ -15,20 +15,20 @@ class Groups extends utils_1.TypedEmitter {
|
|
|
15
15
|
method: 'POST',
|
|
16
16
|
body: group
|
|
17
17
|
}).then(resp => {
|
|
18
|
-
this.emit('CREATE', resp);
|
|
19
|
-
return resp;
|
|
18
|
+
this.emit('CREATE', resp.data);
|
|
19
|
+
return resp.data;
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
list() {
|
|
23
23
|
return this.api.request({ url: `/api/groups` }).then(resp => {
|
|
24
|
-
this.emit('LIST', resp);
|
|
25
|
-
return resp;
|
|
24
|
+
this.emit('LIST', resp.data || []);
|
|
25
|
+
return resp.data;
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
read(name) {
|
|
29
29
|
return this.api.request({ url: `/api/groups/${name}` }).then(resp => {
|
|
30
|
-
this.emit('READ', resp);
|
|
31
|
-
return resp;
|
|
30
|
+
this.emit('READ', resp.data);
|
|
31
|
+
return resp.data;
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
update(group) {
|
|
@@ -37,8 +37,8 @@ class Groups extends utils_1.TypedEmitter {
|
|
|
37
37
|
method: 'PATCH',
|
|
38
38
|
body: group
|
|
39
39
|
}).then(resp => {
|
|
40
|
-
this.emit('UPDATE', resp);
|
|
41
|
-
return resp;
|
|
40
|
+
this.emit('UPDATE', resp.data);
|
|
41
|
+
return resp.data;
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
delete(name) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
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,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./email"), exports);
|
|
|
23
23
|
__exportStar(require("./groups"), exports);
|
|
24
24
|
__exportStar(require("./logger"), exports);
|
|
25
25
|
__exportStar(require("./momentum"), exports);
|
|
26
|
+
__exportStar(require("./payments"), exports);
|
|
26
27
|
__exportStar(require("./pdf"), exports);
|
|
27
28
|
__exportStar(require("./settings"), exports);
|
|
28
29
|
__exportStar(require("./sockets"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var B=function(t,i=!1){if(t==null)throw new Error("Cannot clean a NULL value");return Array.isArray(t)?t=t.filter((e)=>e!=null):Object.entries(t).forEach(([e,n])=>{(i&&n===void 0||!i&&n==null)&&delete t[e]}),t};var Q=function(t,i){const e=typeof t,n=typeof i;return e!="object"||t==null||n!="object"||i==null?e=="function"&&n=="function"?t.toString()==i.toString():t===i:Object.keys(t).length!=Object.keys(i).length?!1:Object.keys(t).every((s)=>Q(t[s],i[s]))};var x=function(t,i){const e=document.createElement("a");e.href=t,e.download=i,document.body.appendChild(e),e.click(),document.body.removeChild(e)};var St=Object.defineProperty,Mt=(t,i,e)=>(i in t)?St(t,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[i]=e,r=(t,i,e)=>(Mt(t,typeof i!="symbol"?i+"":i,e),e);class a{constructor(){r(this,"listeners",{})}static emit(t,...i){(this.listeners["*"]||[]).forEach((e)=>e(t,...i)),(this.listeners[t.toString()]||[]).forEach((e)=>e(...i))}static off(t,i){const e=t.toString();this.listeners[e]=(this.listeners[e]||[]).filter((n)=>n===i)}static on(t,i){var e;const n=t.toString();return this.listeners[n]||(this.listeners[n]=[]),(e=this.listeners[n])==null||e.push(i),()=>this.off(t,i)}static once(t,i){return new Promise((e)=>{const n=this.on(t,(...s)=>{e(s.length==1?s[0]:s),i&&i(...s),n()})})}emit(t,...i){(this.listeners["*"]||[]).forEach((e)=>e(t,...i)),(this.listeners[t]||[]).forEach((e)=>e(...i))}off(t,i){this.listeners[t]=(this.listeners[t]||[]).filter((e)=>e===i)}on(t,i){var e;return this.listeners[t]||(this.listeners[t]=[]),(e=this.listeners[t])==null||e.push(i),()=>this.off(t,i)}once(t,i){return new Promise((e)=>{const n=this.on(t,(...s)=>{e(s.length==1?s[0]:s),i&&i(...s),n()})})}}r(a,"listeners",{});class w extends Error{constructor(t,i){super(t);r(this,"_code"),i!=null&&(this._code=i)}get code(){return this._code||this.constructor.code}set code(t){this._code=t}static from(t){const i=Number(t.statusCode)??Number(t.code),e=new this(t.message||t.toString());return Object.assign(e,{stack:t.stack,...t,code:i??void 0})}static instanceof(t){return t.constructor.code!=null}toString(){return this.message||super.toString()}}r(w,"code",500);class yt extends w{constructor(t="Bad Request"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(yt,"code",400);class mt extends w{constructor(t="Unauthorized"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(mt,"code",401);class ct extends w{constructor(t="Forbidden"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(ct,"code",403);class dt extends w{constructor(t="Not Found"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(dt,"code",404);class gt extends w{constructor(t="Internal Server Error"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(gt,"code",500);var U={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},k={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 P=((t)=>(t[t.ERROR=0]="ERROR",t[t.WARN=1]="WARN",t[t.INFO=2]="INFO",t[t.LOG=3]="LOG",t[t.DEBUG=4]="DEBUG",t))(P||{}),kt=class t extends a{constructor(i){super(),this.namespace=i}pad(i,e,n,s=!1){const o=i.toString(),u=e-o.length;if(u<=0)return o;const h=Array(~~(u/n.length)).fill(n).join("");return s?o+h:h+o}format(...i){const e=new Date;return`${`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()} ${this.pad(e.getHours().toString(),2,"0")}:${this.pad(e.getMinutes().toString(),2,"0")}:${this.pad(e.getSeconds().toString(),2,"0")}.${this.pad(e.getMilliseconds().toString(),3,"0",!0)}`}${this.namespace?` [${this.namespace}]`:""} ${i.join(" ")}`}debug(...i){if(t.LOG_LEVEL<4)return;const e=this.format(...i);t.emit(4,e),console.debug(k.LIGHT_GREY+e+U.CLEAR)}log(...i){if(t.LOG_LEVEL<3)return;const e=this.format(...i);t.emit(3,e),console.log(U.CLEAR+e)}info(...i){if(t.LOG_LEVEL<2)return;const e=this.format(...i);t.emit(2,e),console.info(k.BLUE+e+U.CLEAR)}warn(...i){if(t.LOG_LEVEL<1)return;const e=this.format(...i);t.emit(1,e),console.warn(k.YELLOW+e+U.CLEAR)}error(...i){if(t.LOG_LEVEL<0)return;const e=this.format(...i);t.emit(0,e),console.error(k.RED+e+U.CLEAR)}};r(kt,"LOG_LEVEL",4);var xt="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Wt="0123456789",Ht="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",Ct=xt+Wt+Ht;class J extends Promise{constructor(t){super((i,e)=>t((n)=>i(n),(n)=>e(n),(n)=>this.progress=n));r(this,"listeners",[]),r(this,"_progress",0)}get progress(){return this._progress}set progress(t){t!=this._progress&&(this._progress=t,this.listeners.forEach((i)=>i(t)))}onProgress(t){return this.listeners.push(t),this}}var X=class t{constructor(i={}){r(this,"interceptors",{}),r(this,"headers",{}),this.opts=i,this.headers=i.headers||{},i.interceptors&&i.interceptors.forEach((e)=>t.addInterceptor(e))}static addInterceptor(i){const e=Object.keys(t.interceptors).length.toString();return t.interceptors[e]=i,()=>{t.interceptors[e]=null}}addInterceptor(i){const e=Object.keys(this.interceptors).length.toString();return this.interceptors[e]=i,()=>{this.interceptors[e]=null}}async request(i={}){var e,n;if(!this.opts.url&&!i.url)throw new Error("URL needs to be set");let s=((e=i.url)!=null&&e.startsWith("http")?i.url:(this.opts.url||"")+(i.url||"")).replace(/([^:]\/)\/+/g,"$1");if(i.fragment&&(s.includes("#")?s.replace(/#.*(\?|\n)/g,(u,h)=>`#${i.fragment}${h}`):s+="#"+i.fragment),i.query){const u=Array.isArray(i.query)?i.query:Object.keys(i.query).map((h)=>({key:h,value:i.query[h]}));s+=(s.includes("?")?"&":"?")+u.map((h)=>`${h.key}=${h.value}`).join("&")}const o=B({"Content-Type":i.body&&!(i.body instanceof FormData)?"application/json":void 0,...t.headers,...this.headers,...i.headers});return fetch(s,{headers:o,method:i.method||(i.body?"POST":"GET"),body:(n=o["Content-Type"])!=null&&n.startsWith("application/json")&&i.body?JSON.stringify(i.body):i.body}).then(async(u)=>{for(let l of[...Object.values(t.interceptors),...Object.values(this.interceptors)])await new Promise((m)=>l(u,()=>m()));const h=await(async()=>{var l,m;return!i.skipConverting&&((l=u.headers.get("Content-Type"))!=null&&l.startsWith("application/json"))?await u.json():!i.skipConverting&&((m=u.headers.get("Content-Type"))!=null&&m.startsWith("text/plain"))?await u.text():u})();if(u.ok)return h;throw Object.assign(new Error(typeof h=="string"?h:u.statusText),typeof h=="object"?h:{})})}};r(X,"interceptors",{}),r(X,"headers",{});var Et=X;class p extends Et{t;i;emitter=new a;_token=null;get token(){return this._token}set token(t){if(t==this._token)return;this._token=t,this.headers.Authorization=t?`Bearer ${t}`:void 0,this.emit("TOKEN",t)}constructor(t=location.origin,i={}){i.url=t;super(i);this.url=t;this.opts=i}emit=this.emitter.emit.bind(this.emitter);off=this.emitter.off.bind(this.emitter);on=this.emitter.on.bind(this.emitter);once=this.emitter.once.bind(this.emitter);request(t){const i=super.request(t).then((e)=>{return this.emit("RESPONSE",e,t),e}).catch((e)=>{throw this.emit("REJECTED",e,t),e});return this.emit("REQUEST",i,t),i}}function T(t,i){if(typeof i!=="function"&&i!==null)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");C(t,i);function e(){this.constructor=t}t.prototype=i===null?Object.create(i):(e.prototype=i.prototype,new e)}function S(t){var i=typeof Symbol==="function"&&Symbol.iterator,e=i&&t[i],n=0;if(e)return e.call(t);if(t&&typeof t.length==="number")return{next:function(){if(t&&n>=t.length)t=void 0;return{value:t&&t[n++],done:!t}}};throw new TypeError(i?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(t,i){var e=typeof Symbol==="function"&&t[Symbol.iterator];if(!e)return t;var n=e.call(t),s,o=[],u;try{while((i===void 0||i-- >0)&&!(s=n.next()).done)o.push(s.value)}catch(h){u={error:h}}finally{try{if(s&&!s.done&&(e=n.return))e.call(n)}finally{if(u)throw u.error}}return o}function R(t,i,e){if(e||arguments.length===2){for(var n=0,s=i.length,o;n<s;n++)if(o||!(n in i)){if(!o)o=Array.prototype.slice.call(i,0,n);o[n]=i[n]}}return t.concat(o||Array.prototype.slice.call(i))}var C=function(t,i){return C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var s in n)if(Object.prototype.hasOwnProperty.call(n,s))e[s]=n[s]},C(t,i)};function y(t){return typeof t==="function"}function W(t){var i=function(n){Error.call(n),n.stack=new Error().stack},e=t(i);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var H=W(function(t){return function i(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map(function(n,s){return s+1+") "+n.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}});function M(t,i){if(t){var e=t.indexOf(i);0<=e&&t.splice(e,1)}}function F(t){return t instanceof $||t&&"closed"in t&&y(t.remove)&&y(t.add)&&y(t.unsubscribe)}var Tt=function(t){if(y(t))t();else t.unsubscribe()},$=function(){function t(i){this.initialTeardown=i,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var i,e,n,s,o;if(!this.closed){this.closed=!0;var u=this._parentage;if(u)if(this._parentage=null,Array.isArray(u))try{for(var h=S(u),l=h.next();!l.done;l=h.next()){var m=l.value;m.remove(this)}}catch(f){i={error:f}}finally{try{if(l&&!l.done&&(e=h.return))e.call(h)}finally{if(i)throw i.error}}else u.remove(this);var I=this.initialTeardown;if(y(I))try{I()}catch(f){o=f instanceof H?f.errors:[f]}var G=this._finalizers;if(G){this._finalizers=null;try{for(var A=S(G),g=A.next();!g.done;g=A.next()){var E=g.value;try{Tt(E)}catch(f){if(o=o!==null&&o!==void 0?o:[],f instanceof H)o=R(R([],L(o)),L(f.errors));else o.push(f)}}}catch(f){n={error:f}}finally{try{if(g&&!g.done&&(s=A.return))s.call(A)}finally{if(n)throw n.error}}}if(o)throw new H(o)}},t.prototype.add=function(i){var e;if(i&&i!==this)if(this.closed)Tt(i);else{if(i instanceof t){if(i.closed||i._hasParent(this))return;i._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(i)}},t.prototype._hasParent=function(i){var e=this._parentage;return e===i||Array.isArray(e)&&e.includes(i)},t.prototype._addParent=function(i){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(i),e):e?[e,i]:i},t.prototype._removeParent=function(i){var e=this._parentage;if(e===i)this._parentage=null;else if(Array.isArray(e))M(e,i)},t.prototype.remove=function(i){var e=this._finalizers;if(e&&M(e,i),i instanceof t)i._removeParent(this)},t.EMPTY=function(){var i=new t;return i.closed=!0,i}(),t}();var Z=$.EMPTY;var c={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var O={setTimeout:function(t,i){var e=[];for(var n=2;n<arguments.length;n++)e[n-2]=arguments[n];var s=O.delegate;if(s===null||s===void 0?void 0:s.setTimeout)return s.setTimeout.apply(s,R([t,i],L(e)));return setTimeout.apply(void 0,R([t,i],L(e)))},clearTimeout:function(t){var i=O.delegate;return((i===null||i===void 0?void 0:i.clearTimeout)||clearTimeout)(t)},delegate:void 0};function At(t){O.setTimeout(function(){var i=c.onUnhandledError;if(i)i(t);else throw t})}function Y(){}function Pt(t){return v("E",void 0,t)}function Dt(t){return v("N",t,void 0)}function v(t,i,e){return{kind:t,value:i,error:e}}var wt=function(){return v("C",void 0,void 0)}();function q(t){if(c.useDeprecatedSynchronousErrorHandling){var i=!D;if(i)D={errorThrown:!1,error:null};if(t(),i){var e=D,n=e.errorThrown,s=e.error;if(D=null,n)throw s}}else t()}function Lt(t){if(c.useDeprecatedSynchronousErrorHandling&&D)D.errorThrown=!0,D.error=t}var D=null;var j=function(t,i){return Ft.call(t,i)},K=function(t){if(c.useDeprecatedSynchronousErrorHandling)Lt(t);else At(t)},Nt=function(t){throw t},z=function(t,i){var e=c.onStoppedNotification;e&&O.setTimeout(function(){return e(t,i)})},b=function(t){T(i,t);function i(e){var n=t.call(this)||this;if(n.isStopped=!1,e){if(n.destination=e,F(e))e.add(n)}else n.destination=Vt;return n}return i.create=function(e,n,s){return new N(e,n,s)},i.prototype.next=function(e){if(this.isStopped)z(Dt(e),this);else this._next(e)},i.prototype.error=function(e){if(this.isStopped)z(Pt(e),this);else this.isStopped=!0,this._error(e)},i.prototype.complete=function(){if(this.isStopped)z(wt,this);else this.isStopped=!0,this._complete()},i.prototype.unsubscribe=function(){if(!this.closed)this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null},i.prototype._next=function(e){this.destination.next(e)},i.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},i.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},i}($);var Ft=Function.prototype.bind,Kt=function(){function t(i){this.partialObserver=i}return t.prototype.next=function(i){var e=this.partialObserver;if(e.next)try{e.next(i)}catch(n){K(n)}},t.prototype.error=function(i){var e=this.partialObserver;if(e.error)try{e.error(i)}catch(n){K(n)}else K(i)},t.prototype.complete=function(){var i=this.partialObserver;if(i.complete)try{i.complete()}catch(e){K(e)}},t}(),N=function(t){T(i,t);function i(e,n,s){var o=t.call(this)||this,u;if(y(e)||!e)u={next:e!==null&&e!==void 0?e:void 0,error:n!==null&&n!==void 0?n:void 0,complete:s!==null&&s!==void 0?s:void 0};else{var h;if(o&&c.useDeprecatedNextContext)h=Object.create(e),h.unsubscribe=function(){return o.unsubscribe()},u={next:e.next&&j(e.next,h),error:e.error&&j(e.error,h),complete:e.complete&&j(e.complete,h)};else u=e}return o.destination=new Kt(u),o}return i}(b);var Vt={closed:!0,next:Y,error:Nt,complete:Y};var Rt=function(){return typeof Symbol==="function"&&Symbol.observable||"@@observable"}();function $t(t){return t}function Ot(t){if(t.length===0)return $t;if(t.length===1)return t[0];return function i(e){return t.reduce(function(n,s){return s(n)},e)}}var qt=function(t){var i;return(i=t!==null&&t!==void 0?t:c.Promise)!==null&&i!==void 0?i:Promise},Xt=function(t){return t&&y(t.next)&&y(t.error)&&y(t.complete)},Bt=function(t){return t&&t instanceof b||Xt(t)&&F(t)},_=function(){function t(i){if(i)this._subscribe=i}return t.prototype.lift=function(i){var e=new t;return e.source=this,e.operator=i,e},t.prototype.subscribe=function(i,e,n){var s=this,o=Bt(i)?i:new N(i,e,n);return q(function(){var u=s,h=u.operator,l=u.source;o.add(h?h.call(o,l):l?s._subscribe(o):s._trySubscribe(o))}),o},t.prototype._trySubscribe=function(i){try{return this._subscribe(i)}catch(e){i.error(e)}},t.prototype.forEach=function(i,e){var n=this;return e=qt(e),new e(function(s,o){var u=new N({next:function(h){try{i(h)}catch(l){o(l),u.unsubscribe()}},error:o,complete:s});n.subscribe(u)})},t.prototype._subscribe=function(i){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(i)},t.prototype[Rt]=function(){return this},t.prototype.pipe=function(){var i=[];for(var e=0;e<arguments.length;e++)i[e]=arguments[e];return Ot(i)(this)},t.prototype.toPromise=function(i){var e=this;return i=qt(i),new i(function(n,s){var o;e.subscribe(function(u){return o=u},function(u){return s(u)},function(){return n(o)})})},t.create=function(i){return new t(i)},t}();var It=W(function(t){return function i(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var tt=function(t){T(i,t);function i(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return i.prototype.lift=function(e){var n=new Gt(this,this);return n.operator=e,n},i.prototype._throwIfClosed=function(){if(this.closed)throw new It},i.prototype.next=function(e){var n=this;q(function(){var s,o;if(n._throwIfClosed(),!n.isStopped){if(!n.currentObservers)n.currentObservers=Array.from(n.observers);try{for(var u=S(n.currentObservers),h=u.next();!h.done;h=u.next()){var l=h.value;l.next(e)}}catch(m){s={error:m}}finally{try{if(h&&!h.done&&(o=u.return))o.call(u)}finally{if(s)throw s.error}}}})},i.prototype.error=function(e){var n=this;q(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;var s=n.observers;while(s.length)s.shift().error(e)}})},i.prototype.complete=function(){var e=this;q(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;var n=e.observers;while(n.length)n.shift().complete()}})},i.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(i.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),i.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},i.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},i.prototype._innerSubscribe=function(e){var n=this,s=this,o=s.hasError,u=s.isStopped,h=s.observers;if(o||u)return Z;return this.currentObservers=null,h.push(e),new $(function(){n.currentObservers=null,M(h,e)})},i.prototype._checkFinalizedStatuses=function(e){var n=this,s=n.hasError,o=n.thrownError,u=n.isStopped;if(s)e.error(o);else if(u)e.complete()},i.prototype.asObservable=function(){var e=new _;return e.source=this,e},i.create=function(e,n){return new Gt(e,n)},i}(_);var Gt=function(t){T(i,t);function i(e,n){var s=t.call(this)||this;return s.destination=e,s.source=n,s}return i.prototype.next=function(e){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,e)},i.prototype.error=function(e){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,e)},i.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},i.prototype._subscribe=function(e){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&s!==void 0?s:Z},i}(tt);var d=function(t){T(i,t);function i(e){var n=t.call(this)||this;return n._value=e,n}return Object.defineProperty(i.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),i.prototype._subscribe=function(e){var n=t.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},i.prototype.getValue=function(){var e=this,n=e.hasError,s=e.thrownError,o=e._value;if(n)throw s;return this._throwIfClosed(),o},i.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},i}(tt);var Qt;((h)=>{h[h.CRON=0]="CRON";h[h.EVENT=1]="EVENT";h[h.DELETE=2]="DELETE";h[h.GET=3]="GET";h[h.PATCH=4]="PATCH";h[h.POST=5]="POST";h[h.PUT=6]="PUT"})(Qt||={});class it extends a{api;$cache=new d([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new p(t):t}delete(t){return this.api.request({url:`/api/actions/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((i)=>i._id!=t),this.emit("DELETE",t)})}list(){return this.api.request({url:"/api/actions"}).then((t)=>{return this.cache=t,this.emit("LIST",t),t})}read(t,i=!1){const e=this.cache.find((n)=>n._id==t);if(!i&&e)return Promise.resolve(e);return this.api.request({url:`/api/actions/${t}`}).then((n)=>{if(n)this.cache=this.cache.filter((s)=>s._id!=t).concat([n]);return this.emit("READ",n),n})}run(t,i={}){return this.api.request({url:("/api/actions/run/"+t).replaceAll("//","/"),...i})}runById(t,i={}){const e=typeof t=="string"?t:t._id;return this.api.request({url:"/api/actions/run-by-id/"+e,method:"POST",...i})}update(t){return this.api.request({url:`/api/actions${t._id?`/${t._id}`:""}`,method:"POST",body:t}).then((i)=>{if(i)this.cache=this.cache.filter((e)=>e._id!=i._id).concat([i]);return this.emit("UPDATE",i),i})}}class Ut{t;constructor(t){this.api=t}disable(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"DELETE"})}enable=this.reset;reset(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"POST"})}setup(t,i="app",e){return this.api.request({url:`/api/auth/totp/${t}`,body:B({method:i,totp:e})})}}class et extends a{i;api;storageKey;totp;$user=new d(void 0);get user(){return this.$user.value}set user(t){if(!Q(this.user,t)){const i=t?t:null;this.$user.next(i),this.emit("USER",i)}}constructor(t,i){super();this.opts=i;if(this.api=typeof t=="string"?new p(t):t,this.totp=new Ut(this.api),!this.opts?.loginUi)this.opts={...this.opts,loginUi:this.api.url+"/ui/login"};if(this.storageKey=`momentum:${new URL(this.api.url).host}`,this.api.addInterceptor((e,n)=>{const s=["/api/auth/login","/api/auth/password","/api/auth/totp"];if(e.status==401&&!s.find((o)=>e.url.includes(o)))this.emit("SESSION_EXPIRED");n()}),this.api.on("TOKEN",(e)=>{if(this.opts?.persist)if(e)localStorage.setItem(this.storageKey,e);else localStorage.removeItem(this.storageKey);if(e)this.session(e,!0).catch(()=>{});else this.user=null}),i?.persist){const e=localStorage.getItem(this.storageKey);if(e)this.api.token=e;else this.user=null}else this.user=null}knownHost(t=location.origin){if(t.startsWith("/"))return Promise.resolve();return this.api.request({url:`/api/auth/known-host?host=${encodeURI(new URL(t).origin)}`})}login(t,i,e){return this.api.request({url:"/api/auth/login",headers:{Authorization:void 0},body:{username:t.trim(),password:i.trim(),totp:e}}).then(async(n)=>{return this.api.token=n.token,await this.once("USER")})}loginRedirect(t=location.origin){return new Promise((i,e)=>{const n=window.open(encodeURI(`${this.opts?.loginUi}?redirect=postmessage&host=${t}`),"_blank");if(!n)return e("Unable to open login");n.addEventListener("message",(s)=>{if(!s?.data?.token)return e("Unknown response from login");this.api.token=s.data.token,i(s.data.token),n.close()})})}logout(){this.api.token=null,this.user=null,this.emit("LOGOUT")}async register(t){const i=await this.api.request({url:"/api/auth/register",body:{...t}});if(i.image.startsWith("/"))i.image=`${this.api.url}${i.image}?token=${this.api.token}`;return this.emit("REGISTER",i),i}reset(t,i){return this.api.request({url:"/api/auth/reset",headers:{Authorization:i?`Bearer ${i}`:void 0},body:{email:i?void 0:t,password:i?t:void 0}})}async session(t,i=!1){if(!t)t=this.api.token;const e=await this.api.request({url:"/api/auth/session",headers:t?{Authorization:`Bearer ${t}`}:void 0});if(i){if(this.api.token=t,e?.user)e.user.image=`${this.api.url}${e.user.image}?token=${this.api.token}`;if(this.user=e?.user||null,e)this.emit("LOGIN",e.user)}return e}async updatePassword(t,i,e){return this.api.request({url:"/api/auth/password",body:{username:t,password:i,oldPassword:e}}).then((n)=>{if(n?.token)this.api.token=n.token})}}class nt extends a{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}delete(t,i){return this.api.request({url:`/api/data/${t}/${i}`,method:"DELETE"}).then(()=>this.emit("DELETE",t,i))}get(t,i){return this.api.request({url:`/api/data/${t}${i?`/${i}`:""}`}).then((e)=>{return this.emit("GET",t,e),e})}raw(t,i,e,n){return this.api.request({url:`/api/data/${t}`,body:{operand:i,query:e,options:n}}).then((s)=>{return this.emit("RAW",t,s),s})}set(t,i,e=!1){return this.api.request({url:`/api/data/${t}/${i._id||""}`,method:e?"PATCH":"POST",body:i}).then((n)=>{return this.emit("SET",t,i),n})}}class st extends a{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}send(t){let i="/api/email";if(typeof t.body=="object")i+=`/${t.body.template}`;return this.api.request({url:i,body:t}).then((e)=>{return this.emit("SENT",t),e})}}class ot extends a{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}create(t){return this.api.request({url:`/api/groups/${t.name}`,method:"POST",body:t}).then((i)=>{return this.emit("CREATE",i),i})}list(){return this.api.request({url:"/api/groups"}).then((t)=>{return this.emit("LIST",t),t})}read(t){return this.api.request({url:`/api/groups/${t}`}).then((i)=>{return this.emit("READ",i),i})}update(t){return this.api.request({url:`/api/groups/${t.name}`,method:"PATCH",body:t}).then((i)=>{return this.emit("UPDATE",i),i})}delete(t){return this.api.request({url:`/api/groups/${t}`,method:"DELETE"}).then(()=>this.emit("DELETE",t))}}class ut{api;constructor(t,i){if(this.api=typeof t=="string"?new p(t):t,i!=null&&i!="NONE")window.addEventListener("error",(e)=>this.error(e.error.stack)),window.addEventListener("unhandledrejection",async(e)=>this.error(e.reason.stack))}buildLog(t,i){return{time:(new Date()).getTime(),level:t,log:i,ctx:{cores:navigator.hardwareConcurrency,mem:navigator?.deviceMemory,res:[window.innerWidth,window.innerHeight],url:location.href}}}clearClientLogs(){return this.api.request({url:"/api/logs/client",method:"DELETE"})}clearServerLogs(){return this.api.request({url:"/api/logs/server",method:"DELETE"})}clientLogs(t,i){const e=[t?`length=${t}`:void 0,i?`page=${i}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/client${e?`?${e}`:""}`})}serverLogs(t,i){const e=[t?`length=${t}`:void 0,i?`page=${i}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/server${e?`?${e}`:""}`})}debug(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.DEBUG,t)}).catch(()=>{})}log(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.LOG,t)}).catch(()=>{})}info(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.INFO,t)}).catch(()=>{})}warn(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.WARN,t)}).catch(()=>{})}error(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.ERROR,t)}).catch(()=>{})}}class ht extends a{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}async handleResponse(t,i){const e=await t.blob();if(i){const n=URL.createObjectURL(e);x(n,i.endsWith(".pdf")?i:i+".pdf"),URL.revokeObjectURL(n)}return this.emit("CREATE",e),e}fromHtml(t,i={}){return this.api.request({url:"/api/pdf",body:{html:t}}).then((e)=>this.handleResponse(e,i.download?i.fileName||(new Date()).toISOString():void 0))}fromTemplate(t,i,e={}){return this.api.request({url:`/api/pdf${t}`,body:i}).then((n)=>this.handleResponse(n,e.download?e.fileName||(new Date()).toISOString():void 0))}fromUrl(t,i={}){return this.api.request({url:`/api/pdf?url=${t}`}).then((e)=>this.handleResponse(e,i.download?i.fileName||(new Date()).toISOString():void 0))}}class V{static timeout=1e4;api;url;connection;open=!1;constructor(t){if(this.api=typeof t=="string"?new p(t):t,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(t=3){if(this.connection?.readyState<2)this.connection.close();this.connection=new WebSocket(this.url+(this.api.token?`?token=${this.api.token}`:""));const i=setTimeout(()=>{if(this.open)return;if(this.connection.close(),console.error("Momentum connection timeout"),t>0)this.connect(t-1)},V.timeout);this.connection.onclose=()=>this.open=!1,this.connection.onmessage=this.handle,this.connection.onopen=()=>{this.open=!0,clearTimeout(i),console.debug("Connected to Momentum")}}handle(...t){console.log(t)}send(t,i){this.connection.send(JSON.stringify({token:this.api.token,channel:t,payload:i}))}}class at extends a{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}delete(t){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:i,method:"DELETE"}).then(()=>{this.emit("DELETE",i)})}list(t){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:i+"?list"}).then((e)=>{return this.emit("LIST",t,e),e})}open(t,i="_blank"){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/"),n=`${this.api.url}${e}${this.api.token?`?token=${this.api.token}`:""}`;if(!i)return n;return this.emit("OPEN",t),window.open(n,i)}mkdir(t){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/");return this.api.request({url:i+"?directory",method:"POST"})}download(t,i={}){return new J((e,n,s)=>{const o=("/api/storage/"+t).replaceAll("//","/");this.api.request({...i,url:o,skipConverting:!0}).then((u)=>{if(!u.ok)return n(u.statusText);const h=u.headers.get("Content-Length"),l=h?parseInt(h,10):0;let m=[],I=0;const G=u.body?.getReader(),A=(g)=>{if(g.done){s(1);const E=new Blob(m),f=i.downloadAs||new URL(u.url).pathname.split("/").pop(),ft=URL.createObjectURL(E);x(ft,f.includes(".")?f:f+".zip"),URL.revokeObjectURL(ft),this.emit("DOWNLOAD",t,E),e(E)}else{const E=g.value;m.push(E),I+=E.length,s(I/l),G.read().then(A)}};G?.read().then(A)})})}async upload(t,i=""){const e=()=>{return new Promise((o)=>{const u=document.createElement("input");u.type="file",u.accept=i?.accept||"*",u.style.display="none",u.multiple=!!i?.multiple,u.onblur=u.onchange=async()=>{o(Array.from(u.files)),u.remove()},document.body.appendChild(u),u.click()})};if(!t)t=await e();if(!t||Array.isArray(t)&&!t.length)return[];const n=new FormData,s=("/api/storage/"+(typeof i=="string"?i:i?.path)).replaceAll("//","/");return(Array.isArray(t)?t:[t]).forEach((o)=>n.append("file",o)),this.api.request({url:s,body:n}).then((o)=>{return this.emit("UPLOAD",o),o})}}class pt extends a{api;listed=!1;$cache=new d([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new p(t):t}delete(t){return this.api.request({url:`/api/users/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((i)=>i.username!=t),this.emit("DELETE",t)})}list(t=!1){if(!t&&this.listed)return Promise.resolve(this.cache);return this.api.request({url:"/api/users"}).then((i)=>{return i.map((e)=>{return e.image=this.api.url+e.image+`?token=${this.api.token}`,e}),this.cache=i,this.listed=!0,this.emit("LIST",i),i})}read(t,i=!1){if(!i){const e=this.cache.find((n)=>n.username==t);if(e)return Promise.resolve(e)}return this.api.request({url:`/api/users/${t}`}).then((e)=>{if(e.image=this.api.url+e.image+`?token=${this.api.token}`,e)this.cache=[...this.cache.filter((n)=>n.username!=t),e];return this.emit("READ",e),e})}update(t){return this.api.request({url:`/api/users/${t.username}`,method:"PATCH",body:t}).then((i)=>{if(i.image=this.api.url+i.image+`?token=${this.api.token}`,i)this.cache=this.cache.filter((e)=>e.username!=t.username).concat([i]);return this.emit("UPDATE",i),i})}uploadImage(t,i){const e=new FormData;return e.append("file",i),this.api.request({url:`/api/users/${t}/image`,body:e}).then((n)=>{return this.emit("UPLOAD_IMAGE",i),n})}}class lt extends a{api;$cache=new d({});get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new p(t):t}list(t=!1){return this.api.request({url:"/api/settings"+(t?"?detailed":"")}).then((i)=>{return this.cache=!t?i:Object.values(i).reduce((e,n)=>({...e,[n.key]:n.value}),{}),this.emit("LIST",i),i})}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,i=!1){if(!i&&this.cache[t])return Promise.resolve(this.cache[t]);return this.api.request({url:`/api/settings/${t}`}).then((e)=>{if(e)this.cache={...this.cache,[e.key]:e};return this.emit("READ",e),e})}update(t){return this.api.request({url:`/api/settings/${t.key}`,body:t}).then((i)=>{if(i)this.cache={...this.cache,[i.key]:i.value};return this.emit("UPDATE",i),i})}}class rt extends a{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}delete(t){return this.api.request({url:`/api/static/${t}`,method:"DELETE"}).then(()=>{this.emit("DELETE",t)})}list(t){const i=("/api/static/"+t).replaceAll("//","/");return this.api.request({url:i}).then((e)=>{return this.emit("LIST",t,e),e})}upload(t,i="/"){const e=new FormData;return(Array.isArray(t)?t:[t]).forEach((n)=>e.append("file",n)),this.api.request({url:"/api/static"+i,body:e}).then((n)=>{return this.emit("UPLOAD",n),n})}}class Jt extends a{api;actions;auth;data;email;groups;logger;pdf;settings;socket;static;storage;users;constructor(t,i){super();if(this.api=new p(t,i?.api),this.actions=new it(this.api),this.auth=new et(this.api,{persist:i?.persist??!0,loginUi:i?.loginUi}),this.data=new nt(this.api),this.email=new st(this.api),this.groups=new ot(this.api),this.logger=new ut(this.api,i?.logLevel),this.pdf=new ht(this.api),this.settings=new lt(this.api),this.static=new rt(this.api),this.storage=new at(this.api),this.users=new pt(this.api),i?.socket)this.socket=new V(this.api);this.api.on("*",(e,...n)=>this.emit(`API::${e}`,...n)),this.actions.on("*",(e,...n)=>this.emit(`ACTIONS::${e}`,...n)),this.auth.on("*",(e,...n)=>this.emit(`AUTH::${e}`,...n)),this.data.on("*",(e,...n)=>this.emit(`DATA::${e}`,...n)),this.email.on("*",(e,...n)=>this.emit(`EMAIL::${e}`,...n)),this.groups.on("*",(e,...n)=>this.emit(`GROUPS::${e}`,...n)),this.pdf.on("*",(e,...n)=>this.emit(`PDF::${e}`,...n)),this.settings.on("*",(e,...n)=>this.emit(`SETTINGS::${e}`,...n)),this.static.on("*",(e,...n)=>this.emit(`STATIC::${e}`,...n)),this.storage.on("*",(e,...n)=>this.emit(`STORAGE::${e}`,...n)),this.users.on("*",(e,...n)=>this.emit(`USERS::${e}`,...n)),this.users.on("*",(e,...n)=>{if(Array.isArray(n[0])){const s=n[0].find((o)=>o._id==this.auth.user?._id);if(s)this.auth.user=s}else if(n[0]._id==this.auth.user?._id)this.auth.user=n[0]})}}export{pt as Users,Ut as Totp,at as Storage,rt as Static,V as Socket,lt as Settings,ht as Pdf,Jt as Momentum,ut as Logger,ot as Groups,st as Email,nt as Data,et as Auth,p as Api,it as Actions,Qt as ActionType};
|
|
1
|
+
var v=function(t,e=!1){if(t==null)throw new Error("Cannot clean a NULL value");return Array.isArray(t)?t=t.filter((i)=>i!=null):Object.entries(t).forEach(([i,n])=>{(e&&n===void 0||!e&&n==null)&&delete t[i]}),t};var j=function(t,e){const i=typeof t,n=typeof e;return i!="object"||t==null||n!="object"||e==null?i=="function"&&n=="function"?t.toString()==e.toString():t===e:Object.keys(t).length!=Object.keys(e).length?!1:Object.keys(t).every((s)=>j(t[s],e[s]))};var z=function(t,e){const i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i)},Tt=function(t,e){const i=URL.createObjectURL(t);z(i,e),URL.revokeObjectURL(i)},At=function(t={}){return new Promise((e)=>{const i=document.createElement("input");i.type="file",i.accept=t.accept||"*",i.style.display="none",i.multiple=!!t.multiple,i.onblur=i.onchange=async()=>{e(Array.from(i.files)),i.remove()},document.body.appendChild(i),i.click()})},V=function(t){return new E((e,i,n)=>{const s=new XMLHttpRequest,a=new FormData;t.files.forEach((o)=>a.append("file",o)),s.withCredentials=!!t.withCredentials,s.upload.addEventListener("progress",(o)=>o.lengthComputable?n(o.loaded/o.total):null),s.upload.addEventListener("load",(o)=>e(o)),s.upload.addEventListener("error",(o)=>i(o)),s.open("POST",t.url),Object.entries(t.headers||{}).forEach(([o,p])=>s.setRequestHeader(o,p)),s.send(a)})};var Nt=Object.defineProperty,Vt=(t,e,i)=>(e in t)?Nt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,l=(t,e,i)=>(Vt(t,typeof e!="symbol"?e+"":e,i),i);class E extends Promise{constructor(t){super((e,i)=>t((n)=>e(n),(n)=>i(n),(n)=>this.progress=n));l(this,"listeners",[]),l(this,"_progress",0)}get progress(){return this._progress}set progress(t){t!=this._progress&&(this._progress=t,this.listeners.forEach((e)=>e(t)))}static from(t){return t instanceof E?t:new E((e,i)=>t.then((...n)=>e(...n)).catch((...n)=>i(...n)))}from(t){const e=E.from(t);return this.onProgress((i)=>e.progress=i),e}onProgress(t){return this.listeners.push(t),this}then(t,e){const i=super.then(t,e);return this.from(i)}catch(t){return this.from(super.catch(t))}finally(t){return this.from(super.finally(t))}}class h{constructor(){l(this,"listeners",{})}static emit(t,...e){(this.listeners["*"]||[]).forEach((i)=>i(t,...e)),(this.listeners[t.toString()]||[]).forEach((i)=>i(...e))}static off(t,e){const i=t.toString();this.listeners[i]=(this.listeners[i]||[]).filter((n)=>n===e)}static on(t,e){var i;const n=t.toString();return this.listeners[n]||(this.listeners[n]=[]),(i=this.listeners[n])==null||i.push(e),()=>this.off(t,e)}static once(t,e){return new Promise((i)=>{const n=this.on(t,(...s)=>{i(s.length==1?s[0]:s),e&&e(...s),n()})})}emit(t,...e){(this.listeners["*"]||[]).forEach((i)=>i(t,...e)),(this.listeners[t]||[]).forEach((i)=>i(...e))}off(t,e){this.listeners[t]=(this.listeners[t]||[]).filter((i)=>i===e)}on(t,e){var i;return this.listeners[t]||(this.listeners[t]=[]),(i=this.listeners[t])==null||i.push(e),()=>this.off(t,e)}once(t,e){return new Promise((i)=>{const n=this.on(t,(...s)=>{i(s.length==1?s[0]:s),e&&e(...s),n()})})}}l(h,"listeners",{});class A extends Error{constructor(t,e){super(t);l(this,"_code"),e!=null&&(this._code=e)}get code(){return this._code||this.constructor.code}set code(t){this._code=t}static from(t){const e=Number(t.statusCode)??Number(t.code),i=new this(t.message||t.toString());return Object.assign(i,{stack:t.stack,...t,code:e??void 0})}static instanceof(t){return t.constructor.code!=null}toString(){return this.message||super.toString()}}l(A,"code",500);class wt extends A{constructor(t="Bad Request"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(wt,"code",400);class Pt extends A{constructor(t="Unauthorized"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Pt,"code",401);class Dt extends A{constructor(t="Forbidden"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Dt,"code",403);class Lt extends A{constructor(t="Not Found"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Lt,"code",404);class Rt extends A{constructor(t="Internal Server Error"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Rt,"code",500);var Y=class t{constructor(e={}){l(this,"interceptors",{}),l(this,"headers",{}),l(this,"url"),this.url=e.url??null,this.headers=e.headers||{},e.interceptors&&e.interceptors.forEach((i)=>t.addInterceptor(i))}static addInterceptor(e){const i=Object.keys(t.interceptors).length.toString();return t.interceptors[i]=e,()=>{t.interceptors[i]=null}}addInterceptor(e){const i=Object.keys(this.interceptors).length.toString();return this.interceptors[i]=e,()=>{this.interceptors[i]=null}}request(e={}){var i;if(!this.url&&!e.url)throw new Error("URL needs to be set");let n=((i=e.url)!=null&&i.startsWith("http")?e.url:(this.url||"")+(e.url||"")).replace(/([^:]\/)\/+/g,"$1");if(e.fragment&&(n.includes("#")?n.replace(/#.*(\?|\n)/g,(a,o)=>`#${e.fragment}${o}`):n+="#"+e.fragment),e.query){const a=Array.isArray(e.query)?e.query:Object.keys(e.query).map((o)=>({key:o,value:e.query[o]}));n+=(n.includes("?")?"&":"?")+a.map((o)=>`${o.key}=${o.value}`).join("&")}const s=v({"Content-Type":e.body?e.body instanceof FormData?"multipart/form-data":"application/json":void 0,...t.headers,...this.headers,...e.headers});return typeof e.body=="object"&&e.body!=null&&s["Content-Type"]=="application/json"&&(e.body=JSON.stringify(e.body)),new E((a,o,p)=>{fetch(n,{headers:s,method:e.method||(e.body?"POST":"GET"),body:e.body}).then(async(u)=>{var D,S;for(let U of[...Object.values(t.interceptors),...Object.values(this.interceptors)])await new Promise((K)=>U(u,()=>K()));const G=u.headers.get("Content-Length"),L=G?parseInt(G,10):0;let g=0;const W=(D=u.body)==null?void 0:D.getReader(),y=new ReadableStream({start(U){function K(){W==null||W.read().then((H)=>{if(H.done)return U.close();g+=H.value.byteLength,p(g/L),U.enqueue(H.value),K()}).catch((H)=>U.error(H))}K()}}),F=new Response(y),c=(S=u.headers.get("Content-Type"))==null?void 0:S.toLowerCase();c!=null&&c.includes("json")?u.data=await F.json():c!=null&&c.includes("text")?u.data=await F.text():c!=null&&c.includes("form")?u.data=await F.formData():c!=null&&c.includes("application")?u.data=await F.blob():u.data=null,u.ok?a(u):o(u)})})}};l(Y,"interceptors",{}),l(Y,"headers",{});var $t=Y,M={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},N={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 w=((t)=>(t[t.ERROR=0]="ERROR",t[t.WARN=1]="WARN",t[t.INFO=2]="INFO",t[t.LOG=3]="LOG",t[t.DEBUG=4]="DEBUG",t))(w||{}),Ct=class t extends h{constructor(e){super(),this.namespace=e}pad(e,i,n,s=!1){const a=e.toString(),o=i-a.length;if(o<=0)return a;const p=Array(~~(o/n.length)).fill(n).join("");return s?a+p:p+a}format(...e){const i=new Date;return`${`${i.getFullYear()}-${i.getMonth()+1}-${i.getDate()} ${this.pad(i.getHours().toString(),2,"0")}:${this.pad(i.getMinutes().toString(),2,"0")}:${this.pad(i.getSeconds().toString(),2,"0")}.${this.pad(i.getMilliseconds().toString(),3,"0",!0)}`}${this.namespace?` [${this.namespace}]`:""} ${e.join(" ")}`}debug(...e){if(t.LOG_LEVEL<4)return;const i=this.format(...e);t.emit(4,i),console.debug(N.LIGHT_GREY+i+M.CLEAR)}log(...e){if(t.LOG_LEVEL<3)return;const i=this.format(...e);t.emit(3,i),console.log(M.CLEAR+i)}info(...e){if(t.LOG_LEVEL<2)return;const i=this.format(...e);t.emit(2,i),console.info(N.BLUE+i+M.CLEAR)}warn(...e){if(t.LOG_LEVEL<1)return;const i=this.format(...e);t.emit(1,i),console.warn(N.YELLOW+i+M.CLEAR)}error(...e){if(t.LOG_LEVEL<0)return;const i=this.format(...e);t.emit(0,i),console.error(N.RED+i+M.CLEAR)}};l(Ct,"LOG_LEVEL",4);var Bt="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Jt="0123456789",Xt="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",ti=Bt+Jt+Xt;class r extends $t{t;e;emitter=new h;_token=null;get token(){return this._token}set token(t){if(t==this._token)return;this._token=t,this.headers.Authorization=t?`Bearer ${t}`:void 0,this.emit("TOKEN",t)}constructor(t=location.origin,e={}){e.url=t;super(e);this.url=t;this.opts=e}emit=this.emitter.emit.bind(this.emitter);off=this.emitter.off.bind(this.emitter);on=this.emitter.on.bind(this.emitter);once=this.emitter.once.bind(this.emitter);request(t){const e=super.request(t).then((i)=>{return this.emit("RESPONSE",i,t),i}).catch((i)=>{throw this.emit("REJECTED",i,t),i});return this.emit("REQUEST",e,t),e}}function T(t,e){if(typeof e!=="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");b(t,e);function i(){this.constructor=t}t.prototype=e===null?Object.create(e):(i.prototype=e.prototype,new i)}function x(t){var e=typeof Symbol==="function"&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&typeof t.length==="number")return{next:function(){if(t&&n>=t.length)t=void 0;return{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(t,e){var i=typeof Symbol==="function"&&t[Symbol.iterator];if(!i)return t;var n=i.call(t),s,a=[],o;try{while((e===void 0||e-- >0)&&!(s=n.next()).done)a.push(s.value)}catch(p){o={error:p}}finally{try{if(s&&!s.done&&(i=n.return))i.call(n)}finally{if(o)throw o.error}}return a}function $(t,e,i){if(i||arguments.length===2){for(var n=0,s=e.length,a;n<s;n++)if(a||!(n in e)){if(!a)a=Array.prototype.slice.call(e,0,n);a[n]=e[n]}}return t.concat(a||Array.prototype.slice.call(e))}var b=function(t,e){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,n){i.__proto__=n}||function(i,n){for(var s in n)if(Object.prototype.hasOwnProperty.call(n,s))i[s]=n[s]},b(t,e)};function d(t){return typeof t==="function"}function C(t){var e=function(n){Error.call(n),n.stack=new Error().stack},i=t(e);return i.prototype=Object.create(Error.prototype),i.prototype.constructor=i,i}var B=C(function(t){return function e(i){t(this),this.message=i?i.length+" errors occurred during unsubscription:\n"+i.map(function(n,s){return s+1+") "+n.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=i}});function k(t,e){if(t){var i=t.indexOf(e);0<=i&&t.splice(i,1)}}function J(t){return t instanceof O||t&&"closed"in t&&d(t.remove)&&d(t.add)&&d(t.unsubscribe)}var Ot=function(t){if(d(t))t();else t.unsubscribe()},O=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,i,n,s,a;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var p=x(o),u=p.next();!u.done;u=p.next()){var D=u.value;D.remove(this)}}catch(y){e={error:y}}finally{try{if(u&&!u.done&&(i=p.return))i.call(p)}finally{if(e)throw e.error}}else o.remove(this);var S=this.initialTeardown;if(d(S))try{S()}catch(y){a=y instanceof B?y.errors:[y]}var G=this._finalizers;if(G){this._finalizers=null;try{for(var L=x(G),g=L.next();!g.done;g=L.next()){var W=g.value;try{Ot(W)}catch(y){if(a=a!==null&&a!==void 0?a:[],y instanceof B)a=$($([],R(a)),R(y.errors));else a.push(y)}}}catch(y){n={error:y}}finally{try{if(g&&!g.done&&(s=L.return))s.call(L)}finally{if(n)throw n.error}}}if(a)throw new B(a)}},t.prototype.add=function(e){var i;if(e&&e!==this)if(this.closed)Ot(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(i=this._finalizers)!==null&&i!==void 0?i:[]).push(e)}},t.prototype._hasParent=function(e){var i=this._parentage;return i===e||Array.isArray(i)&&i.includes(e)},t.prototype._addParent=function(e){var i=this._parentage;this._parentage=Array.isArray(i)?(i.push(e),i):i?[i,e]:e},t.prototype._removeParent=function(e){var i=this._parentage;if(i===e)this._parentage=null;else if(Array.isArray(i))k(i,e)},t.prototype.remove=function(e){var i=this._finalizers;if(i&&k(i,e),e instanceof t)e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}();var _=O.EMPTY;var f={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var q={setTimeout:function(t,e){var i=[];for(var n=2;n<arguments.length;n++)i[n-2]=arguments[n];var s=q.delegate;if(s===null||s===void 0?void 0:s.setTimeout)return s.setTimeout.apply(s,$([t,e],R(i)));return setTimeout.apply(void 0,$([t,e],R(i)))},clearTimeout:function(t){var e=q.delegate;return((e===null||e===void 0?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function qt(t){q.setTimeout(function(){var e=f.onUnhandledError;if(e)e(t);else throw t})}function tt(){}function St(t){return it("E",void 0,t)}function Gt(t){return it("N",t,void 0)}function it(t,e,i){return{kind:t,value:e,error:i}}var It=function(){return it("C",void 0,void 0)}();function I(t){if(f.useDeprecatedSynchronousErrorHandling){var e=!P;if(e)P={errorThrown:!1,error:null};if(t(),e){var i=P,n=i.errorThrown,s=i.error;if(P=null,n)throw s}}else t()}function Ut(t){if(f.useDeprecatedSynchronousErrorHandling&&P)P.errorThrown=!0,P.error=t}var P=null;var et=function(t,e){return Qt.call(t,e)},X=function(t){if(f.useDeprecatedSynchronousErrorHandling)Ut(t);else qt(t)},Yt=function(t){throw t},nt=function(t,e){var i=f.onStoppedNotification;i&&q.setTimeout(function(){return i(t,e)})},st=function(t){T(e,t);function e(i){var n=t.call(this)||this;if(n.isStopped=!1,i){if(n.destination=i,J(i))i.add(n)}else n.destination=vt;return n}return e.create=function(i,n,s){return new Q(i,n,s)},e.prototype.next=function(i){if(this.isStopped)nt(Gt(i),this);else this._next(i)},e.prototype.error=function(i){if(this.isStopped)nt(St(i),this);else this.isStopped=!0,this._error(i)},e.prototype.complete=function(){if(this.isStopped)nt(It,this);else this.isStopped=!0,this._complete()},e.prototype.unsubscribe=function(){if(!this.closed)this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null},e.prototype._next=function(i){this.destination.next(i)},e.prototype._error=function(i){try{this.destination.error(i)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(O);var Qt=Function.prototype.bind,Zt=function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var i=this.partialObserver;if(i.next)try{i.next(e)}catch(n){X(n)}},t.prototype.error=function(e){var i=this.partialObserver;if(i.error)try{i.error(e)}catch(n){X(n)}else X(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(i){X(i)}},t}(),Q=function(t){T(e,t);function e(i,n,s){var a=t.call(this)||this,o;if(d(i)||!i)o={next:i!==null&&i!==void 0?i:void 0,error:n!==null&&n!==void 0?n:void 0,complete:s!==null&&s!==void 0?s:void 0};else{var p;if(a&&f.useDeprecatedNextContext)p=Object.create(i),p.unsubscribe=function(){return a.unsubscribe()},o={next:i.next&&et(i.next,p),error:i.error&&et(i.error,p),complete:i.complete&&et(i.complete,p)};else o=i}return a.destination=new Zt(o),a}return e}(st);var vt={closed:!0,next:tt,error:Yt,complete:tt};var Ht=function(){return typeof Symbol==="function"&&Symbol.observable||"@@observable"}();function Mt(t){return t}function xt(t){if(t.length===0)return Mt;if(t.length===1)return t[0];return function e(i){return t.reduce(function(n,s){return s(n)},i)}}var kt=function(t){var e;return(e=t!==null&&t!==void 0?t:f.Promise)!==null&&e!==void 0?e:Promise},jt=function(t){return t&&d(t.next)&&d(t.error)&&d(t.complete)},zt=function(t){return t&&t instanceof st||jt(t)&&J(t)},at=function(){function t(e){if(e)this._subscribe=e}return t.prototype.lift=function(e){var i=new t;return i.source=this,i.operator=e,i},t.prototype.subscribe=function(e,i,n){var s=this,a=zt(e)?e:new Q(e,i,n);return I(function(){var o=s,p=o.operator,u=o.source;a.add(p?p.call(a,u):u?s._subscribe(a):s._trySubscribe(a))}),a},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(i){e.error(i)}},t.prototype.forEach=function(e,i){var n=this;return i=kt(i),new i(function(s,a){var o=new Q({next:function(p){try{e(p)}catch(u){a(u),o.unsubscribe()}},error:a,complete:s});n.subscribe(o)})},t.prototype._subscribe=function(e){var i;return(i=this.source)===null||i===void 0?void 0:i.subscribe(e)},t.prototype[Ht]=function(){return this},t.prototype.pipe=function(){var e=[];for(var i=0;i<arguments.length;i++)e[i]=arguments[i];return xt(e)(this)},t.prototype.toPromise=function(e){var i=this;return e=kt(e),new e(function(n,s){var a;i.subscribe(function(o){return a=o},function(o){return s(o)},function(){return n(a)})})},t.create=function(e){return new t(e)},t}();var Wt=C(function(t){return function e(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var ot=function(t){T(e,t);function e(){var i=t.call(this)||this;return i.closed=!1,i.currentObservers=null,i.observers=[],i.isStopped=!1,i.hasError=!1,i.thrownError=null,i}return e.prototype.lift=function(i){var n=new Ft(this,this);return n.operator=i,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new Wt},e.prototype.next=function(i){var n=this;I(function(){var s,a;if(n._throwIfClosed(),!n.isStopped){if(!n.currentObservers)n.currentObservers=Array.from(n.observers);try{for(var o=x(n.currentObservers),p=o.next();!p.done;p=o.next()){var u=p.value;u.next(i)}}catch(D){s={error:D}}finally{try{if(p&&!p.done&&(a=o.return))a.call(o)}finally{if(s)throw s.error}}}})},e.prototype.error=function(i){var n=this;I(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=i;var s=n.observers;while(s.length)s.shift().error(i)}})},e.prototype.complete=function(){var i=this;I(function(){if(i._throwIfClosed(),!i.isStopped){i.isStopped=!0;var n=i.observers;while(n.length)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var i;return((i=this.observers)===null||i===void 0?void 0:i.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(i){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,i)},e.prototype._subscribe=function(i){return this._throwIfClosed(),this._checkFinalizedStatuses(i),this._innerSubscribe(i)},e.prototype._innerSubscribe=function(i){var n=this,s=this,a=s.hasError,o=s.isStopped,p=s.observers;if(a||o)return _;return this.currentObservers=null,p.push(i),new O(function(){n.currentObservers=null,k(p,i)})},e.prototype._checkFinalizedStatuses=function(i){var n=this,s=n.hasError,a=n.thrownError,o=n.isStopped;if(s)i.error(a);else if(o)i.complete()},e.prototype.asObservable=function(){var i=new at;return i.source=this,i},e.create=function(i,n){return new Ft(i,n)},e}(at);var Ft=function(t){T(e,t);function e(i,n){var s=t.call(this)||this;return s.destination=i,s.source=n,s}return e.prototype.next=function(i){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,i)},e.prototype.error=function(i){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,i)},e.prototype.complete=function(){var i,n;(n=(i=this.destination)===null||i===void 0?void 0:i.complete)===null||n===void 0||n.call(i)},e.prototype._subscribe=function(i){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(i))!==null&&s!==void 0?s:_},e}(ot);var m=function(t){T(e,t);function e(i){var n=t.call(this)||this;return n._value=i,n}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(i){var n=t.prototype._subscribe.call(this,i);return!n.closed&&i.next(this._value),n},e.prototype.getValue=function(){var i=this,n=i.hasError,s=i.thrownError,a=i._value;if(n)throw s;return this._throwIfClosed(),a},e.prototype.next=function(i){t.prototype.next.call(this,this._value=i)},e}(ot);var bt;((p)=>{p[p.CRON=0]="CRON";p[p.EVENT=1]="EVENT";p[p.DELETE=2]="DELETE";p[p.GET=3]="GET";p[p.PATCH=4]="PATCH";p[p.POST=5]="POST";p[p.PUT=6]="PUT"})(bt||={});class pt extends h{api;$cache=new m([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/actions/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((e)=>e._id!=t),this.emit("DELETE",t)})}list(){return this.api.request({url:"/api/actions"}).then((t)=>{if(t.data)this.cache=t.data;return this.emit("LIST",t.data||[]),t.data})}read(t,e=!1){const i=this.cache.find((n)=>n._id==t);if(!e&&i)return Promise.resolve(i);return this.api.request({url:`/api/actions/${t}`}).then((n)=>{if(n.data)this.cache=this.cache.filter((s)=>s._id!=t).concat([n.data]);return this.emit("READ",n.data),n.data})}run(t,e={}){return this.api.request({url:("/api/actions/run/"+t).replaceAll("//","/"),...e}).then((i)=>i.data)}runById(t,e={}){const i=typeof t=="string"?t:t._id;return this.api.request({url:"/api/actions/run-by-id/"+i,method:"POST",...e}).then((n)=>n.data)}update(t){return this.api.request({url:`/api/actions${t._id?`/${t._id}`:""}`,method:"POST",body:t}).then((e)=>{if(e.data)this.cache=this.cache.filter((i)=>i._id!=e.data?._id).concat([e.data]);return this.emit("UPDATE",e.data),e.data})}}class Kt{t;constructor(t){this.api=t}disable(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"DELETE"})}enable=this.reset;reset(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"POST"})}setup(t,e="app",i){return this.api.request({url:`/api/auth/totp/${t}`,body:v({method:e,totp:i})})}}class ht extends h{e;api;storageKey;totp;$user=new m(void 0);get user(){return this.$user.value}set user(t){if(!j(this.user,t)){const e=t?t:null;this.$user.next(e),this.emit("USER",e)}}constructor(t,e){super();this.opts=e;if(this.api=typeof t=="string"?new r(t):t,this.totp=new Kt(this.api),!this.opts?.loginUi)this.opts={...this.opts,loginUi:this.api.url+"/ui/login"};if(this.storageKey=`momentum:${new URL(this.api.url).host}`,this.api.addInterceptor((i,n)=>{const s=["/api/auth/login","/api/auth/password","/api/auth/totp"];if(i.status==401&&!s.find((a)=>i.url.includes(a)))this.emit("SESSION_EXPIRED");n()}),this.api.on("TOKEN",(i)=>{if(this.opts?.persist)if(i)localStorage.setItem(this.storageKey,i);else localStorage.removeItem(this.storageKey);if(i)this.session(i,!0).catch(()=>{});else this.user=null}),e?.persist){const i=localStorage.getItem(this.storageKey);if(i)this.api.token=i;else this.user=null}else this.user=null}knownHost(t=location.origin){if(t.startsWith("/"))return Promise.resolve();return this.api.request({url:`/api/auth/known-host?host=${encodeURI(new URL(t).origin)}`}).then(()=>{})}login(t,e,i){return this.api.request({url:"/api/auth/login",headers:{Authorization:void 0},method:"POST",body:{username:t.trim(),password:e.trim(),totp:i}}).then(async(n)=>{return this.api.token=n.data?.token||null,await this.once("USER")})}loginRedirect(t=location.origin){return new Promise((e,i)=>{const n=window.open(encodeURI(`${this.opts?.loginUi}?redirect=postmessage&host=${t}`),"_blank");if(!n)return i("Unable to open login");n.addEventListener("message",(s)=>{if(!s?.data?.token)return i("Unknown response from login");this.api.token=s.data.token,e(s.data.token),n.close()})})}logout(){this.api.token=null,this.user=null,this.emit("LOGOUT")}async register(t){const e=(await this.api.request({url:"/api/auth/register",body:{...t}}))?.data;if(e?.image?.startsWith("/"))e.image=`${this.api.url}${e.image}?token=${this.api.token}`;return this.emit("REGISTER",e),e}reset(t,e){return this.api.request({url:"/api/auth/reset",headers:{Authorization:e?`Bearer ${e}`:void 0},body:{email:e?void 0:t,password:e?t:void 0}}).then(()=>{})}async session(t,e=!1){if(!t)t=this.api.token;const i=(await this.api.request({url:"/api/auth/session",headers:t?{Authorization:`Bearer ${t}`}:void 0}))?.data;if(e){if(this.api.token=t,i?.user)i.user.image=`${this.api.url}${i.user.image}?token=${this.api.token}`;if(this.user=i?.user||null,i)this.emit("LOGIN",i.user)}return i}async updatePassword(t,e,i){return this.api.request({url:"/api/auth/password",body:{username:t,password:e,oldPassword:i}}).then((n)=>{if(n?.data?.token)this.api.token=n.data.token})}}class rt extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t,e){return this.api.request({url:`/api/data/${t}/${e}`,method:"DELETE"}).then(()=>this.emit("DELETE",t,e))}get(t,e){return this.api.request({url:`/api/data/${t}${e?`/${e}`:""}`}).then((i)=>{return this.emit("GET",t,i.data),i.data})}raw(t,e,i,n){return this.api.request({url:`/api/data/${t}`,body:{operand:e,query:i,options:n}}).then((s)=>{return this.emit("RAW",t,s.data),s.data})}set(t,e,i=!1){return this.api.request({url:`/api/data/${t}/${e._id||""}`,method:i?"PATCH":"POST",body:e}).then((n)=>{return this.emit("SET",t,n.data),n.data})}}class ut extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}send(t){let e="/api/email";if(typeof t.body=="object")e+=`/${t.body.template}`;return this.api.request({url:e,body:t}).then((i)=>{return this.emit("SENT",t),i.data})}}class lt extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}create(t){return this.api.request({url:`/api/groups/${t.name}`,method:"POST",body:t}).then((e)=>{return this.emit("CREATE",e.data),e.data})}list(){return this.api.request({url:"/api/groups"}).then((t)=>{return this.emit("LIST",t.data||[]),t.data})}read(t){return this.api.request({url:`/api/groups/${t}`}).then((e)=>{return this.emit("READ",e.data),e.data})}update(t){return this.api.request({url:`/api/groups/${t.name}`,method:"PATCH",body:t}).then((e)=>{return this.emit("UPDATE",e.data),e.data})}delete(t){return this.api.request({url:`/api/groups/${t}`,method:"DELETE"}).then(()=>this.emit("DELETE",t))}}class yt{api;constructor(t,e){if(this.api=typeof t=="string"?new r(t):t,e!=null&&e!="NONE")window.addEventListener("error",(i)=>this.error(i.error.stack)),window.addEventListener("unhandledrejection",async(i)=>this.error(i.reason.stack))}buildLog(t,e){return{time:(new Date()).getTime(),level:t,log:e,ctx:{cores:navigator.hardwareConcurrency,mem:navigator?.deviceMemory,res:[window.innerWidth,window.innerHeight],url:location.href}}}clearClientLogs(){return this.api.request({url:"/api/logs/client",method:"DELETE"})}clearServerLogs(){return this.api.request({url:"/api/logs/server",method:"DELETE"})}clientLogs(t,e){const i=[t?`length=${t}`:void 0,e?`page=${e}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/client${i?`?${i}`:""}`}).then((n)=>n.data)}serverLogs(t,e){const i=[t?`length=${t}`:void 0,e?`page=${e}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/server${i?`?${i}`:""}`}).then((n)=>n.data)}debug(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.DEBUG,t)}).then(()=>{}).catch(()=>{})}log(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.LOG,t)}).then(()=>{}).catch(()=>{})}info(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.INFO,t)}).then(()=>{}).catch(()=>{})}warn(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.WARN,t)}).then(()=>{}).catch(()=>{})}error(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.ERROR,t)}).then(()=>{}).catch(()=>{})}}class dt extends h{api;stripe;constructor(t,e){super();this.api=typeof t=="string"?new r(t):t;const i=(n=1)=>{try{if(!Stripe)throw new Error("Stripe not added");this.stripe=Stripe(e)}catch(s){if(n>0)setTimeout(()=>i(n--),250);else console.warn("Stripe failed, did you add the library & setup your API key?",s)}};i()}async charge(t,e={}){return this.emit("CHECKOUT",t,e),(await this.api.request({url:"/api/payments",body:{amount:t,custom:e}})).data.clientSecret}async createForm(t,e,i){const n=await this.charge(e,i),s=this.stripe.elements({clientSecret:n});return s.create("payment").mount(t),()=>this.stripe.confirmPayment({elements:s,redirect:"if_required",confirmParams:{return_url:location.origin}})}async history(t){const e=await this.api.request({url:`/api/payments${t?`/${t}`:""}`});return this.emit("LIST",t||null,e.data),e.data}}class ft extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}async handleResponse(t,e){const i=await t.blob();if(e){const n=URL.createObjectURL(i);z(n,e.endsWith(".pdf")?e:e+".pdf"),URL.revokeObjectURL(n)}return this.emit("CREATE",i),i}fromHtml(t,e={}){return this.api.request({url:"/api/pdf",body:{html:t}}).then((i)=>this.handleResponse(i,e.download?e.fileName||(new Date()).toISOString():void 0))}fromTemplate(t,e,i={}){return this.api.request({url:`/api/pdf${t}`,body:e}).then((n)=>this.handleResponse(n,i.download?i.fileName||(new Date()).toISOString():void 0))}fromUrl(t,e={}){return this.api.request({url:`/api/pdf?url=${t}`}).then((i)=>this.handleResponse(i,e.download?e.fileName||(new Date()).toISOString():void 0))}}class Z{static timeout=1e4;api;url;connection;open=!1;constructor(t){if(this.api=typeof t=="string"?new r(t):t,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(t=3){if(this.connection?.readyState<2)this.connection.close();this.connection=new WebSocket(this.url+(this.api.token?`?token=${this.api.token}`:""));const e=setTimeout(()=>{if(this.open)return;if(this.connection.close(),console.error("Momentum connection timeout"),t>0)this.connect(t-1)},Z.timeout);this.connection.onclose=()=>this.open=!1,this.connection.onmessage=this.handle,this.connection.onopen=()=>{this.open=!0,clearTimeout(e),console.debug("Connected to Momentum")}}handle(...t){console.log(t)}send(t,e){this.connection.send(JSON.stringify({token:this.api.token,channel:t,payload:e}))}}class mt extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:e,method:"DELETE"}).then(()=>{this.emit("DELETE",e)})}list(t){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:e+"?list"}).then((i)=>{return this.emit("LIST",t,i.data),i.data})}open(t,e="_blank"){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/"),n=`${this.api.url}${i}${this.api.token?`?token=${this.api.token}`:""}`;if(!e)return n;return this.emit("OPEN",t),window.open(n,e)}mkdir(t){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/");return this.api.request({url:e+"?directory",method:"POST"}).then((i)=>i.data)}download(t,e={}){const i=("/api/storage/"+t).replaceAll("//","/");return this.api.request({...e,url:i,skipConverting:!0}).then((n)=>{const s=e.downloadAs||new URL(n.url).pathname.split("/").pop();return this.emit("DOWNLOAD",t,n.data),Tt(n.data,s),n.data})}upload(t,e=""){return new E(async(i,n,s)=>{if(!t)t=await At();if(!t||Array.isArray(t)&&!t.length)return[];const a=this.api.url+("/api/storage/"+(typeof e=="string"?e:e?.path)).replaceAll("//","/");return V({url:a,files:Array.isArray(t)?t:[t],headers:this.api.headers}).onProgress((o)=>{s(o)}).then((o)=>{this.emit("UPLOAD",o),i(o)}).catch((o)=>n(o))})}}class gt extends h{api;listed=!1;$cache=new m([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/users/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((e)=>e.username!=t),this.emit("DELETE",t)})}list(t=!1){if(!t&&this.listed)return Promise.resolve(this.cache);return this.api.request({url:"/api/users"}).then((e)=>{return e.data?.map((i)=>{return i.image=this.api.url+i.image+`?token=${this.api.token}`,i}),this.cache=e.data||[],this.listed=!0,this.emit("LIST",e.data||[]),e.data})}read(t,e=!1){if(!e){const i=this.cache.find((n)=>n.username==t);if(i)return Promise.resolve(i)}return this.api.request({url:`/api/users/${t}`}).then((i)=>{if(i.data)i.data.image=this.api.url+i.data.image+`?token=${this.api.token}`,this.cache=[...this.cache.filter((n)=>n.username!=t),i.data];return this.emit("READ",i.data),i.data})}update(t){return this.api.request({url:`/api/users/${t.username}`,method:"PATCH",body:t}).then((e)=>{if(e.data)e.data.image=this.api.url+e.data.image+`?token=${this.api.token}`,this.cache=this.cache.filter((i)=>i.username!=t.username).concat([e.data]);return this.emit(t._id?"UPDATE":"CREATE",e.data),e.data})}uploadImage(t,e){return V({url:this.api.url+`/api/users/${t}/image`,files:[e],headers:this.api.headers}).then((i)=>{return this.emit("UPLOAD_IMAGE",t,e),i})}}class ct extends h{api;$cache=new m({});get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}list(t=!1){return this.api.request({url:"/api/settings"+(t?"?detailed":"")}).then((e)=>{return this.cache=!t?e.data:Object.values(e.data||{}).reduce((i,n)=>({...i,[n.key]:n.value}),{}),this.emit("LIST",e.data||[]),e.data})}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,e=!1){if(!e&&this.cache[t])return Promise.resolve(this.cache[t]);return this.api.request({url:`/api/settings/${t}`}).then((i)=>{if(i.data)this.cache={...this.cache,[i.data.key]:i};return this.emit("READ",i.data),i.data})}update(t){return this.api.request({url:`/api/settings/${t.key}`,body:t}).then((e)=>{if(e.data)this.cache={...this.cache,[e.data.key]:e.data.value};return this.emit("UPDATE",e.data),e.data})}}class Et extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/static/${t}`,method:"DELETE"}).then(()=>{this.emit("DELETE",t)})}list(t){const e=("/api/static/"+t).replaceAll("//","/");return this.api.request({url:e}).then((i)=>{return this.emit("LIST",t,i.data||[]),i.data})}upload(t,e="/"){const i=new FormData;return(Array.isArray(t)?t:[t]).forEach((n)=>i.append("file",n)),this.api.request({url:"/api/static"+e,body:i}).then((n)=>{return this.emit("UPLOAD",n.data||[]),n.data})}}class _t extends h{api;actions;auth;data;email;groups;logger;payments;pdf;settings;socket;static;storage;users;constructor(t,e){super();if(this.api=new r(t,e?.api),this.actions=new pt(this.api),this.auth=new ht(this.api,{persist:e?.persist??!0,loginUi:e?.loginUi}),this.data=new rt(this.api),this.email=new ut(this.api),this.groups=new lt(this.api),this.logger=new yt(this.api,e?.logLevel),e?.stripeSecret)this.payments=new dt(this.api,e.stripeSecret);if(this.pdf=new ft(this.api),this.settings=new ct(this.api),this.static=new Et(this.api),this.storage=new mt(this.api),this.users=new gt(this.api),e?.socket)this.socket=new Z(this.api);if(this.api.on("*",(i,...n)=>this.emit(`API::${i}`,...n)),this.actions.on("*",(i,...n)=>this.emit(`ACTIONS::${i}`,...n)),this.auth.on("*",(i,...n)=>this.emit(`AUTH::${i}`,...n)),this.data.on("*",(i,...n)=>this.emit(`DATA::${i}`,...n)),this.email.on("*",(i,...n)=>this.emit(`EMAIL::${i}`,...n)),this.groups.on("*",(i,...n)=>this.emit(`GROUPS::${i}`,...n)),this.payments)this.payments.on("*",(i,...n)=>this.emit(`PAYMENT::${i}`,...n));this.pdf.on("*",(i,...n)=>this.emit(`PDF::${i}`,...n)),this.settings.on("*",(i,...n)=>this.emit(`SETTINGS::${i}`,...n)),this.static.on("*",(i,...n)=>this.emit(`STATIC::${i}`,...n)),this.storage.on("*",(i,...n)=>this.emit(`STORAGE::${i}`,...n)),this.users.on("*",(i,...n)=>this.emit(`USERS::${i}`,...n)),this.users.on("*",(i,...n)=>{if(Array.isArray(n[0])){const s=n[0].find((a)=>a._id==this.auth.user?._id);if(s)this.auth.user=s}else if(n[0]._id==this.auth.user?._id)this.auth.user=n[0]})}}export{gt as Users,Kt as Totp,mt as Storage,Et as Static,Z as Socket,ct as Settings,ft as Pdf,dt as Payments,_t as Momentum,yt as Logger,lt as Groups,ut as Email,rt as Data,ht as Auth,r as Api,pt as Actions,bt as ActionType};
|
package/dist/logger.d.ts
CHANGED
|
@@ -42,14 +42,14 @@ export declare class Logger {
|
|
|
42
42
|
private readonly api;
|
|
43
43
|
constructor(api: Api | string, logLevel?: LogLevel | null);
|
|
44
44
|
private buildLog;
|
|
45
|
-
clearClientLogs():
|
|
46
|
-
clearServerLogs():
|
|
45
|
+
clearClientLogs(): import("@ztimson/utils").PromiseProgress<import("@ztimson/utils").DecodedResponse<ClientLog[]>>;
|
|
46
|
+
clearServerLogs(): import("@ztimson/utils").PromiseProgress<import("@ztimson/utils").DecodedResponse<ClientLog[]>>;
|
|
47
47
|
clientLogs(length?: number, page?: number): Promise<ClientLog[]>;
|
|
48
48
|
serverLogs(length?: number, page?: number): Promise<Log<any>[]>;
|
|
49
|
-
debug(...logs: any[]):
|
|
50
|
-
log(...logs: any[]):
|
|
51
|
-
info(...logs: any[]):
|
|
52
|
-
warn(...logs: any[]):
|
|
53
|
-
error(...logs: any[]):
|
|
49
|
+
debug(...logs: any[]): import("@ztimson/utils").PromiseProgress<any>;
|
|
50
|
+
log(...logs: any[]): import("@ztimson/utils").PromiseProgress<any>;
|
|
51
|
+
info(...logs: any[]): import("@ztimson/utils").PromiseProgress<any>;
|
|
52
|
+
warn(...logs: any[]): import("@ztimson/utils").PromiseProgress<any>;
|
|
53
|
+
error(...logs: any[]): import("@ztimson/utils").PromiseProgress<any>;
|
|
54
54
|
}
|
|
55
55
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.js
CHANGED
|
@@ -34,26 +34,26 @@ class Logger {
|
|
|
34
34
|
}
|
|
35
35
|
clientLogs(length, page) {
|
|
36
36
|
const query = [length ? `length=${length}` : undefined, page ? `page=${page}` : undefined,].filter(v => !!v).join('&');
|
|
37
|
-
return this.api.request({ url: `/api/logs/client${query ? `?${query}` : ''}` });
|
|
37
|
+
return this.api.request({ url: `/api/logs/client${query ? `?${query}` : ''}` }).then(resp => resp.data);
|
|
38
38
|
}
|
|
39
39
|
serverLogs(length, page) {
|
|
40
40
|
const query = [length ? `length=${length}` : undefined, page ? `page=${page}` : undefined,].filter(v => !!v).join('&');
|
|
41
|
-
return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ''}` });
|
|
41
|
+
return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ''}` }).then(resp => resp.data);
|
|
42
42
|
}
|
|
43
43
|
debug(...logs) {
|
|
44
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.DEBUG, logs) }).catch(() => { });
|
|
44
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.DEBUG, logs) }).then(() => { }).catch(() => { });
|
|
45
45
|
}
|
|
46
46
|
log(...logs) {
|
|
47
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.LOG, logs) }).catch(() => { });
|
|
47
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.LOG, logs) }).then(() => { }).catch(() => { });
|
|
48
48
|
}
|
|
49
49
|
info(...logs) {
|
|
50
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.INFO, logs) }).catch(() => { });
|
|
50
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.INFO, logs) }).then(() => { }).catch(() => { });
|
|
51
51
|
}
|
|
52
52
|
warn(...logs) {
|
|
53
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.WARN, logs) }).catch(() => { });
|
|
53
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.WARN, logs) }).then(() => { }).catch(() => { });
|
|
54
54
|
}
|
|
55
55
|
error(...logs) {
|
|
56
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.ERROR, logs) }).catch(() => { });
|
|
56
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.ERROR, logs) }).then(() => { }).catch(() => { });
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
exports.Logger = Logger;
|
package/dist/momentum.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { Auth, type AuthEvents, AuthOptions } from './auth';
|
|
|
4
4
|
import { Data, type DataEvents } from './data';
|
|
5
5
|
import { Email, type EmailEvents } from './email';
|
|
6
6
|
import { Groups } from './groups';
|
|
7
|
-
import { TypedEmitter, type TypedEvents, type
|
|
7
|
+
import { TypedEmitter, type TypedEvents, type HttpRequestOptions } from '@ztimson/utils';
|
|
8
8
|
import { Logger, LogLevel } from './logger';
|
|
9
|
+
import { Payments } from './payments';
|
|
9
10
|
import { Pdf, type PdfEvents } from './pdf';
|
|
10
11
|
import { Socket } from './sockets';
|
|
11
12
|
import { Storage, type StorageEvents } from './storage';
|
|
@@ -16,7 +17,8 @@ export type MomentumEvents = TypedEvents & ApiEvents & AuthEvents & DataEvents &
|
|
|
16
17
|
export type MomentumOptions = AuthOptions & {
|
|
17
18
|
logLevel?: LogLevel;
|
|
18
19
|
socket?: boolean;
|
|
19
|
-
|
|
20
|
+
stripeSecret?: string;
|
|
21
|
+
api?: HttpRequestOptions;
|
|
20
22
|
};
|
|
21
23
|
export declare class Momentum extends TypedEmitter<MomentumEvents> {
|
|
22
24
|
api: Api;
|
|
@@ -26,6 +28,7 @@ export declare class Momentum extends TypedEmitter<MomentumEvents> {
|
|
|
26
28
|
email: Email;
|
|
27
29
|
groups: Groups;
|
|
28
30
|
logger: Logger;
|
|
31
|
+
payments: Payments;
|
|
29
32
|
pdf: Pdf;
|
|
30
33
|
settings: Settings;
|
|
31
34
|
socket?: Socket;
|
package/dist/momentum.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"momentum.d.ts","sour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groups_1 = require("./groups");
|
|
10
10
|
const utils_1 = require("@ztimson/utils");
|
|
11
11
|
const logger_1 = require("./logger");
|
|
12
|
+
const payments_1 = require("./payments");
|
|
12
13
|
const pdf_1 = require("./pdf");
|
|
13
14
|
const sockets_1 = require("./sockets");
|
|
14
15
|
const storage_1 = require("./storage");
|
|
@@ -23,6 +24,7 @@ class Momentum extends utils_1.TypedEmitter {
|
|
|
23
24
|
email;
|
|
24
25
|
groups;
|
|
25
26
|
logger;
|
|
27
|
+
payments;
|
|
26
28
|
pdf;
|
|
27
29
|
settings;
|
|
28
30
|
socket;
|
|
@@ -41,6 +43,8 @@ class Momentum extends utils_1.TypedEmitter {
|
|
|
41
43
|
this.email = new email_1.Email(this.api);
|
|
42
44
|
this.groups = new groups_1.Groups(this.api);
|
|
43
45
|
this.logger = new logger_1.Logger(this.api, opts?.logLevel);
|
|
46
|
+
if (opts?.stripeSecret)
|
|
47
|
+
this.payments = new payments_1.Payments(this.api, opts.stripeSecret);
|
|
44
48
|
this.pdf = new pdf_1.Pdf(this.api);
|
|
45
49
|
this.settings = new settings_1.Settings(this.api);
|
|
46
50
|
this.static = new static_1.Static(this.api);
|
|
@@ -54,6 +58,8 @@ class Momentum extends utils_1.TypedEmitter {
|
|
|
54
58
|
this.data.on('*', (event, ...args) => this.emit(`DATA::${event}`, ...args));
|
|
55
59
|
this.email.on('*', (event, ...args) => this.emit(`EMAIL::${event}`, ...args));
|
|
56
60
|
this.groups.on('*', (event, ...args) => this.emit(`GROUPS::${event}`, ...args));
|
|
61
|
+
if (this.payments)
|
|
62
|
+
this.payments.on('*', (event, ...args) => this.emit(`PAYMENT::${event}`, ...args));
|
|
57
63
|
this.pdf.on('*', (event, ...args) => this.emit(`PDF::${event}`, ...args));
|
|
58
64
|
this.settings.on('*', (event, ...args) => this.emit(`SETTINGS::${event}`, ...args));
|
|
59
65
|
this.static.on('*', (event, ...args) => this.emit(`STATIC::${event}`, ...args));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
2
|
+
import { Api } from './api';
|
|
3
|
+
export type PaymentEvents = TypedEvents & {
|
|
4
|
+
'CHECKOUT': (amount: number, custom: any) => any;
|
|
5
|
+
'LIST': (username: string | null, history: any[]) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare class Payments extends TypedEmitter<PaymentEvents> {
|
|
8
|
+
private readonly api;
|
|
9
|
+
stripe: any;
|
|
10
|
+
constructor(api: Api | string, secret: string);
|
|
11
|
+
private charge;
|
|
12
|
+
createForm(element: string, amount: number, custom?: any): Promise<() => Promise<any>>;
|
|
13
|
+
history(username?: string): Promise<any[] | null>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACzC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IACjD,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF,qBAAa,QAAS,SAAQ,YAAY,CAAC,aAAa,CAAC;IACxD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;IAE3B,MAAM,EAAG,GAAG,CAAC;gBAED,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM;YAgB/B,MAAM;IASd,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IAWtF,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;CAK/B"}
|
package/dist/payments.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Payments = void 0;
|
|
4
|
+
const utils_1 = require("@ztimson/utils");
|
|
5
|
+
const api_1 = require("./api");
|
|
6
|
+
class Payments extends utils_1.TypedEmitter {
|
|
7
|
+
api;
|
|
8
|
+
stripe;
|
|
9
|
+
constructor(api, secret) {
|
|
10
|
+
super();
|
|
11
|
+
this.api = typeof api == 'string' ? new api_1.Api(api) : api;
|
|
12
|
+
const setup = (retry = 1) => {
|
|
13
|
+
try {
|
|
14
|
+
if (!Stripe)
|
|
15
|
+
throw new Error('Stripe not added');
|
|
16
|
+
this.stripe = Stripe(secret);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (retry > 0)
|
|
20
|
+
setTimeout(() => setup(retry--), 250);
|
|
21
|
+
else
|
|
22
|
+
console.warn('Stripe failed, did you add the library & setup your API key?', err);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
setup();
|
|
26
|
+
}
|
|
27
|
+
async charge(amount, custom = {}) {
|
|
28
|
+
this.emit('CHECKOUT', amount, custom);
|
|
29
|
+
const request = await this.api.request({ url: '/api/payments', body: {
|
|
30
|
+
amount,
|
|
31
|
+
custom,
|
|
32
|
+
} });
|
|
33
|
+
return request.data.clientSecret;
|
|
34
|
+
}
|
|
35
|
+
async createForm(element, amount, custom) {
|
|
36
|
+
const token = await this.charge(amount, custom);
|
|
37
|
+
const form = this.stripe.elements({ clientSecret: token });
|
|
38
|
+
form.create('payment').mount(element);
|
|
39
|
+
return () => this.stripe.confirmPayment({
|
|
40
|
+
elements: form,
|
|
41
|
+
redirect: "if_required",
|
|
42
|
+
confirmParams: { return_url: location.origin }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async history(username) {
|
|
46
|
+
const history = await this.api.request({ url: `/api/payments${username ? `/${username}` : ''}` });
|
|
47
|
+
this.emit('LIST', username || null, history.data);
|
|
48
|
+
return history.data;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Payments = Payments;
|
package/dist/pdf.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare class Pdf extends TypedEmitter<PdfEvents> {
|
|
|
11
11
|
private readonly api;
|
|
12
12
|
constructor(api: Api | string);
|
|
13
13
|
private handleResponse;
|
|
14
|
-
fromHtml(content: string, opts?: PdfOptions):
|
|
15
|
-
fromTemplate(template: string, data: object, opts?: PdfOptions):
|
|
16
|
-
fromUrl(url: string, opts?: PdfOptions):
|
|
14
|
+
fromHtml(content: string, opts?: PdfOptions): import("@ztimson/utils").PromiseProgress<any>;
|
|
15
|
+
fromTemplate(template: string, data: object, opts?: PdfOptions): import("@ztimson/utils").PromiseProgress<any>;
|
|
16
|
+
fromUrl(url: string, opts?: PdfOptions): import("@ztimson/utils").PromiseProgress<any>;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=pdf.d.ts.map
|
package/dist/settings.js
CHANGED
|
@@ -15,9 +15,9 @@ class Settings extends utils_1.TypedEmitter {
|
|
|
15
15
|
}
|
|
16
16
|
list(detailed = false) {
|
|
17
17
|
return this.api.request({ url: `/api/settings` + (detailed ? '?detailed' : '') }).then(resp => {
|
|
18
|
-
this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v) => ({ ...acc, [v.key]: v.value }), {});
|
|
19
|
-
this.emit('LIST', resp);
|
|
20
|
-
return resp;
|
|
18
|
+
this.cache = !detailed ? resp.data : Object.values(resp.data || {}).reduce((acc, v) => ({ ...acc, [v.key]: v.value }), {});
|
|
19
|
+
this.emit('LIST', resp.data || []);
|
|
20
|
+
return resp.data;
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
delete(key) {
|
|
@@ -30,18 +30,18 @@ class Settings extends utils_1.TypedEmitter {
|
|
|
30
30
|
if (!reload && this.cache[key])
|
|
31
31
|
return Promise.resolve(this.cache[key]);
|
|
32
32
|
return this.api.request({ url: `/api/settings/${key}` }).then(variable => {
|
|
33
|
-
if (variable)
|
|
34
|
-
this.cache = { ...this.cache, [variable.key]: variable };
|
|
35
|
-
this.emit('READ', variable);
|
|
36
|
-
return variable;
|
|
33
|
+
if (variable.data)
|
|
34
|
+
this.cache = { ...this.cache, [variable.data.key]: variable };
|
|
35
|
+
this.emit('READ', variable.data);
|
|
36
|
+
return variable.data;
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
update(variable) {
|
|
40
40
|
return this.api.request({ url: `/api/settings/${variable.key}`, body: variable }).then(variable => {
|
|
41
|
-
if (variable)
|
|
42
|
-
this.cache = { ...this.cache, [variable.key]: variable.value };
|
|
43
|
-
this.emit('UPDATE', variable);
|
|
44
|
-
return variable;
|
|
41
|
+
if (variable.data)
|
|
42
|
+
this.cache = { ...this.cache, [variable.data.key]: variable.data.value };
|
|
43
|
+
this.emit('UPDATE', variable.data);
|
|
44
|
+
return variable.data;
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
package/dist/static.js
CHANGED
|
@@ -17,16 +17,16 @@ class Static extends utils_1.TypedEmitter {
|
|
|
17
17
|
list(path) {
|
|
18
18
|
const url = ('/api/static/' + path).replaceAll('//', '/');
|
|
19
19
|
return this.api.request({ url }).then(resp => {
|
|
20
|
-
this.emit('LIST', path, resp);
|
|
21
|
-
return resp;
|
|
20
|
+
this.emit('LIST', path, resp.data || []);
|
|
21
|
+
return resp.data;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
upload(files, path = '/') {
|
|
25
25
|
const data = new FormData();
|
|
26
26
|
(Array.isArray(files) ? files : [files]).forEach(f => data.append('file', f));
|
|
27
27
|
return this.api.request({ url: '/api/static' + path, body: data }).then(resp => {
|
|
28
|
-
this.emit('UPLOAD', resp);
|
|
29
|
-
return resp;
|
|
28
|
+
this.emit('UPLOAD', resp.data || []);
|
|
29
|
+
return resp.data;
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Api } from './api';
|
|
2
2
|
import { type Meta } from './core';
|
|
3
|
-
import { PromiseProgress,
|
|
3
|
+
import { PromiseProgress, TypedEmitter, type TypedEvents, HttpRequestOptions } from '@ztimson/utils';
|
|
4
4
|
export type DirMeta = {
|
|
5
5
|
children: (DirMeta | FileMeta)[];
|
|
6
6
|
path: string;
|
|
@@ -29,13 +29,13 @@ export declare class Storage extends TypedEmitter<StorageEvents> {
|
|
|
29
29
|
open(path: string, target: false): string;
|
|
30
30
|
open(path: string, target?: '_blank' | '_self'): Window | null;
|
|
31
31
|
mkdir(path: string): Promise<DirMeta>;
|
|
32
|
-
download(path: string, opts?:
|
|
32
|
+
download(path: string, opts?: HttpRequestOptions & {
|
|
33
33
|
'downloadAs'?: string;
|
|
34
34
|
}): PromiseProgress<Blob>;
|
|
35
35
|
upload(files?: File | File[] | null, opts?: string | {
|
|
36
36
|
path?: string;
|
|
37
37
|
accept?: string;
|
|
38
38
|
multiple?: boolean;
|
|
39
|
-
}):
|
|
39
|
+
}): PromiseProgress<FileMeta[]>;
|
|
40
40
|
}
|
|
41
41
|
//# sourceMappingURL=storage.d.ts.map
|
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;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AAG,QAAQ,CAAC;IAQ/C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM;IACzC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI;IAS9D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKrC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,kBAAkB,GAAG;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAM,GAAG,eAAe,CAAC,IAAI,CAAC;IAUtG,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,GAAE,MAAM,GAAG;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,eAAe,CAAC,QAAQ,EAAE,CAAC;CAkB3I"}
|
package/dist/storage.js
CHANGED
|
@@ -18,8 +18,8 @@ class Storage extends utils_1.TypedEmitter {
|
|
|
18
18
|
list(path) {
|
|
19
19
|
const url = (path.startsWith('/api/storage/') ? path : '/api/storage/' + path).replaceAll('//', '/');
|
|
20
20
|
return this.api.request({ url: url + '?list' }).then(resp => {
|
|
21
|
-
this.emit('LIST', path, resp);
|
|
22
|
-
return resp;
|
|
21
|
+
this.emit('LIST', path, resp.data);
|
|
22
|
+
return resp.data;
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
open(path, target = '_blank') {
|
|
@@ -32,67 +32,34 @@ class Storage extends utils_1.TypedEmitter {
|
|
|
32
32
|
}
|
|
33
33
|
mkdir(path) {
|
|
34
34
|
const p = (path.startsWith('/api/storage/') ? path : '/api/storage/' + path).replaceAll(/\/{2,}/g, '/');
|
|
35
|
-
return this.api.request({ url: p + '?directory', method: 'POST' });
|
|
35
|
+
return this.api.request({ url: p + '?directory', method: 'POST' }).then(resp => resp.data);
|
|
36
36
|
}
|
|
37
37
|
download(path, opts = {}) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const total = contentLength ? parseInt(contentLength, 10) : 0;
|
|
45
|
-
let chunks = [], loaded = 0;
|
|
46
|
-
const reader = response.body?.getReader();
|
|
47
|
-
const process = (result) => {
|
|
48
|
-
if (result.done) {
|
|
49
|
-
progress(1);
|
|
50
|
-
const blob = new Blob(chunks);
|
|
51
|
-
const name = opts.downloadAs || new URL(response.url).pathname.split('/').pop();
|
|
52
|
-
const url = URL.createObjectURL(blob);
|
|
53
|
-
(0, utils_1.download)(url, name.includes('.') ? name : name + '.zip');
|
|
54
|
-
URL.revokeObjectURL(url);
|
|
55
|
-
this.emit('DOWNLOAD', path, blob);
|
|
56
|
-
res(blob);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const chunk = result.value;
|
|
60
|
-
chunks.push(chunk);
|
|
61
|
-
loaded += chunk.length;
|
|
62
|
-
progress(loaded / total);
|
|
63
|
-
reader.read().then(process);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
reader?.read().then(process);
|
|
67
|
-
});
|
|
38
|
+
const p = ('/api/storage/' + path).replaceAll('//', '/');
|
|
39
|
+
return this.api.request({ ...opts, url: p, skipConverting: true }).then((response) => {
|
|
40
|
+
const name = opts.downloadAs || new URL(response.url).pathname.split('/').pop();
|
|
41
|
+
this.emit('DOWNLOAD', path, response.data);
|
|
42
|
+
(0, utils_1.downloadBlob)(response.data, name);
|
|
43
|
+
return response.data;
|
|
68
44
|
});
|
|
69
45
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
files = await fileBrowser();
|
|
88
|
-
if (!files || Array.isArray(files) && !files.length)
|
|
89
|
-
return [];
|
|
90
|
-
const data = new FormData();
|
|
91
|
-
const p = ('/api/storage/' + (typeof opts == 'string' ? opts : opts?.path)).replaceAll('//', '/');
|
|
92
|
-
(Array.isArray(files) ? files : [files]).forEach(f => data.append('file', f));
|
|
93
|
-
return this.api.request({ url: p, body: data }).then(resp => {
|
|
94
|
-
this.emit('UPLOAD', resp);
|
|
95
|
-
return resp;
|
|
46
|
+
upload(files, opts = '') {
|
|
47
|
+
return new utils_1.PromiseProgress(async (res, rej, prog) => {
|
|
48
|
+
if (!files)
|
|
49
|
+
files = await (0, utils_1.fileBrowser)();
|
|
50
|
+
if (!files || Array.isArray(files) && !files.length)
|
|
51
|
+
return [];
|
|
52
|
+
const url = this.api.url + ('/api/storage/' + (typeof opts == 'string' ? opts : opts?.path)).replaceAll('//', '/');
|
|
53
|
+
return (0, utils_1.uploadWithProgress)({
|
|
54
|
+
url,
|
|
55
|
+
files: Array.isArray(files) ? files : [files],
|
|
56
|
+
headers: this.api.headers
|
|
57
|
+
}).onProgress(p => {
|
|
58
|
+
prog(p);
|
|
59
|
+
}).then(resp => {
|
|
60
|
+
this.emit('UPLOAD', resp);
|
|
61
|
+
res(resp);
|
|
62
|
+
}).catch(err => rej(err));
|
|
96
63
|
});
|
|
97
64
|
}
|
|
98
65
|
}
|
package/dist/users.d.ts
CHANGED
|
@@ -17,10 +17,11 @@ export type User = Meta & {
|
|
|
17
17
|
};
|
|
18
18
|
export type UserEvents = TypedEvents & {
|
|
19
19
|
LIST: (users: User[]) => any;
|
|
20
|
-
|
|
20
|
+
CREATE: (user: User) => any;
|
|
21
|
+
READ: (user: User | null) => any;
|
|
21
22
|
UPDATE: (user: User) => any;
|
|
22
23
|
DELETE: (username: string) => any;
|
|
23
|
-
UPLOAD_IMAGE: (file: File) => any;
|
|
24
|
+
UPLOAD_IMAGE: (username: string, file: File) => any;
|
|
24
25
|
};
|
|
25
26
|
export declare class Users extends TypedEmitter<UserEvents> {
|
|
26
27
|
private readonly api;
|
|
@@ -33,6 +34,6 @@ export declare class Users extends TypedEmitter<UserEvents> {
|
|
|
33
34
|
list(reload?: boolean): Promise<User[]>;
|
|
34
35
|
read(username: string, reload?: boolean): Promise<User>;
|
|
35
36
|
update(user: User): Promise<User>;
|
|
36
|
-
uploadImage(username: string, file: File):
|
|
37
|
+
uploadImage(username: string, file: File): import("@ztimson/utils").PromiseProgress<any>;
|
|
37
38
|
}
|
|
38
39
|
//# sourceMappingURL=users.d.ts.map
|
package/dist/users.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../src/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../src/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAC,eAAe,EAAC,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAEjC,MAAM,MAAM,IAAI,GAAG,IAAI,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,C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|
package/dist/users.js
CHANGED
|
@@ -27,14 +27,14 @@ class Users extends utils_1.TypedEmitter {
|
|
|
27
27
|
if (!reload && this.listed)
|
|
28
28
|
return Promise.resolve(this.cache);
|
|
29
29
|
return this.api.request({ url: `/api/users` }).then(resp => {
|
|
30
|
-
resp.map(r => {
|
|
30
|
+
resp.data?.map(r => {
|
|
31
31
|
r.image = this.api.url + r.image + `?token=${this.api.token}`;
|
|
32
32
|
return r;
|
|
33
33
|
});
|
|
34
|
-
this.cache = resp;
|
|
34
|
+
this.cache = resp.data || [];
|
|
35
35
|
this.listed = true;
|
|
36
|
-
this.emit('LIST', resp);
|
|
37
|
-
return resp;
|
|
36
|
+
this.emit('LIST', resp.data || []);
|
|
37
|
+
return resp.data;
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
read(username, reload = false) {
|
|
@@ -44,11 +44,12 @@ class Users extends utils_1.TypedEmitter {
|
|
|
44
44
|
return Promise.resolve(cached);
|
|
45
45
|
}
|
|
46
46
|
return this.api.request({ url: `/api/users/${username}` }).then(resp => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.cache = [...this.cache.filter(u => u.username != username), resp];
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
if (resp.data) {
|
|
48
|
+
resp.data.image = this.api.url + resp.data.image + `?token=${this.api.token}`;
|
|
49
|
+
this.cache = [...this.cache.filter(u => u.username != username), resp.data];
|
|
50
|
+
}
|
|
51
|
+
this.emit('READ', resp.data);
|
|
52
|
+
return resp.data;
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
55
|
update(user) {
|
|
@@ -57,18 +58,21 @@ class Users extends utils_1.TypedEmitter {
|
|
|
57
58
|
method: 'PATCH',
|
|
58
59
|
body: user
|
|
59
60
|
}).then(resp => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.cache = this.cache.filter(u => u.username != user.username).concat([resp]);
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (resp.data) {
|
|
62
|
+
resp.data.image = this.api.url + resp.data.image + `?token=${this.api.token}`;
|
|
63
|
+
this.cache = this.cache.filter(u => u.username != user.username).concat([resp.data]);
|
|
64
|
+
}
|
|
65
|
+
this.emit(user._id ? 'UPDATE' : 'CREATE', resp.data);
|
|
66
|
+
return resp.data;
|
|
65
67
|
});
|
|
66
68
|
}
|
|
67
69
|
uploadImage(username, file) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.
|
|
70
|
+
return (0, utils_1.uploadWithProgress)({
|
|
71
|
+
url: this.api.url + `/api/users/${username}/image`,
|
|
72
|
+
files: [file],
|
|
73
|
+
headers: this.api.headers,
|
|
74
|
+
}).then(resp => {
|
|
75
|
+
this.emit('UPLOAD_IMAGE', username, file);
|
|
72
76
|
return resp;
|
|
73
77
|
});
|
|
74
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ztimson/momentum",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.3",
|
|
4
4
|
"description": "Client library for momentum",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Momentum"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"watch": "tsc -w & bun build --watch --target browser --outfile dist/index.mjs --minify src/index.ts"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ztimson/utils": "^0.
|
|
29
|
+
"@ztimson/utils": "^0.14.5",
|
|
30
30
|
"rxjs": "^7.8.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|