@fabriktor/fx 0.0.33 → 0.0.35
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/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/memos/memos.d.ts +31 -0
- package/dist/src/memos/memos.js +91 -0
- package/dist/src/session/session.d.ts +5 -20
- package/dist/src/session/session.js +1 -24
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./feed/feed.js";
|
|
|
9
9
|
export * from "./fx.js";
|
|
10
10
|
export * from "./jobs/jobs.js";
|
|
11
11
|
export * from "./marketplace/marketplace.js";
|
|
12
|
+
export * from "./memos/memos.js";
|
|
12
13
|
export * from "./notifications/notifications.js";
|
|
13
14
|
export * from "./payments/payments.js";
|
|
14
15
|
export * from "./payrolls/payrolls.js";
|
package/dist/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./feed/feed.js";
|
|
|
9
9
|
export * from "./fx.js";
|
|
10
10
|
export * from "./jobs/jobs.js";
|
|
11
11
|
export * from "./marketplace/marketplace.js";
|
|
12
|
+
export * from "./memos/memos.js";
|
|
12
13
|
export * from "./notifications/notifications.js";
|
|
13
14
|
export * from "./payments/payments.js";
|
|
14
15
|
export * from "./payrolls/payrolls.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MemosOperator } from "@fabriktor/client";
|
|
2
|
+
import { type Memo, type MemoFolder } from "@fabriktor/schema";
|
|
3
|
+
type MemoInsertOptions = Parameters<MemosOperator["insertOneMemo"]>[0];
|
|
4
|
+
type MemoReplaceOptions = Parameters<MemosOperator["replaceOneMemo"]>[0];
|
|
5
|
+
type MemoFolderInsertOptions = Parameters<MemosOperator["insertOneMemoFolder"]>[0];
|
|
6
|
+
type MemoFolderReplaceOptions = Parameters<MemosOperator["replaceOneMemoFolder"]>[0];
|
|
7
|
+
export type CreateMemoOptions = MemoInsertOptions;
|
|
8
|
+
export type ReplaceMemoOptions = MemoReplaceOptions;
|
|
9
|
+
export type CreateMemoFolderOptions = MemoFolderInsertOptions;
|
|
10
|
+
export type ReplaceMemoFolderOptions = MemoFolderReplaceOptions;
|
|
11
|
+
export interface MemosFXOperator {
|
|
12
|
+
createMemo(opts: CreateMemoOptions): Promise<Memo>;
|
|
13
|
+
replaceMemo(opts: ReplaceMemoOptions): Promise<Memo>;
|
|
14
|
+
createMemoFolder(opts: CreateMemoFolderOptions): Promise<MemoFolder>;
|
|
15
|
+
replaceMemoFolder(opts: ReplaceMemoFolderOptions): Promise<MemoFolder>;
|
|
16
|
+
}
|
|
17
|
+
export type MemosFXOptions = {
|
|
18
|
+
memos: MemosOperator;
|
|
19
|
+
};
|
|
20
|
+
export declare class MemosFX implements MemosFXOperator {
|
|
21
|
+
private memos;
|
|
22
|
+
constructor(opts: MemosFXOptions);
|
|
23
|
+
createMemo(opts: CreateMemoOptions): Promise<Memo>;
|
|
24
|
+
replaceMemo(opts: ReplaceMemoOptions): Promise<Memo>;
|
|
25
|
+
createMemoFolder(opts: CreateMemoFolderOptions): Promise<MemoFolder>;
|
|
26
|
+
replaceMemoFolder(opts: ReplaceMemoFolderOptions): Promise<MemoFolder>;
|
|
27
|
+
private findMemo;
|
|
28
|
+
private findMemoFolder;
|
|
29
|
+
}
|
|
30
|
+
export declare function newMemosFX(opts: MemosFXOptions): MemosFX;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright (C) Fabriktor, Inc. 2025-present.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
4
|
+
// not use this file except in compliance with the License. You may obtain
|
|
5
|
+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
import { ZeroID, } from "@fabriktor/schema";
|
|
7
|
+
import { errResolveFailed } from "../core/err.js";
|
|
8
|
+
const resourceMemoID = "memo_id";
|
|
9
|
+
const resourceMemo = "memo";
|
|
10
|
+
const resourceMemoFolderID = "memo_folder_id";
|
|
11
|
+
const resourceMemoFolder = "memo_folder";
|
|
12
|
+
const msgCreatedMemoIDMissing = "Created memo response did not contain an ID.";
|
|
13
|
+
const msgMemoMissing = "Memo could not be resolved after the mutation.";
|
|
14
|
+
const msgCreatedMemoFolderIDMissing = "Created memo folder response did not contain an ID.";
|
|
15
|
+
const msgMemoFolderMissing = "Memo folder could not be resolved after the mutation.";
|
|
16
|
+
export class MemosFX {
|
|
17
|
+
memos;
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
this.memos = opts.memos;
|
|
20
|
+
}
|
|
21
|
+
async createMemo(opts) {
|
|
22
|
+
const out = await this.memos.insertOneMemo(opts);
|
|
23
|
+
const id = requiredOperationID(out, {
|
|
24
|
+
resource: resourceMemoID,
|
|
25
|
+
msg: msgCreatedMemoIDMissing,
|
|
26
|
+
});
|
|
27
|
+
return await this.findMemo(id);
|
|
28
|
+
}
|
|
29
|
+
async replaceMemo(opts) {
|
|
30
|
+
await this.memos.replaceOneMemo(opts);
|
|
31
|
+
return await this.findMemo(opts.id);
|
|
32
|
+
}
|
|
33
|
+
async createMemoFolder(opts) {
|
|
34
|
+
const out = await this.memos.insertOneMemoFolder(opts);
|
|
35
|
+
const id = requiredOperationID(out, {
|
|
36
|
+
resource: resourceMemoFolderID,
|
|
37
|
+
msg: msgCreatedMemoFolderIDMissing,
|
|
38
|
+
});
|
|
39
|
+
return await this.findMemoFolder(id);
|
|
40
|
+
}
|
|
41
|
+
async replaceMemoFolder(opts) {
|
|
42
|
+
await this.memos.replaceOneMemoFolder(opts);
|
|
43
|
+
return await this.findMemoFolder(opts.id);
|
|
44
|
+
}
|
|
45
|
+
async findMemo(id) {
|
|
46
|
+
const out = await this.memos.findOneMemo({
|
|
47
|
+
id,
|
|
48
|
+
});
|
|
49
|
+
const memo = out.value;
|
|
50
|
+
if (memo === undefined) {
|
|
51
|
+
throw errResolveFailed({
|
|
52
|
+
resource: resourceMemo,
|
|
53
|
+
msg: msgMemoMissing,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return memo;
|
|
57
|
+
}
|
|
58
|
+
async findMemoFolder(id) {
|
|
59
|
+
const out = await this.memos.findOneMemoFolder({
|
|
60
|
+
id,
|
|
61
|
+
});
|
|
62
|
+
const folder = out.value;
|
|
63
|
+
if (folder === undefined) {
|
|
64
|
+
throw errResolveFailed({
|
|
65
|
+
resource: resourceMemoFolder,
|
|
66
|
+
msg: msgMemoFolderMissing,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return folder;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function newMemosFX(opts) {
|
|
73
|
+
return new MemosFX(opts);
|
|
74
|
+
}
|
|
75
|
+
function requiredOperationID(out, opts) {
|
|
76
|
+
const id = resolvedID(out.id);
|
|
77
|
+
if (id === undefined) {
|
|
78
|
+
throw errResolveFailed({
|
|
79
|
+
resource: opts.resource,
|
|
80
|
+
msg: opts.msg,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return id;
|
|
84
|
+
}
|
|
85
|
+
function resolvedID(value) {
|
|
86
|
+
const id = value?.trim();
|
|
87
|
+
if (id === undefined || id === "" || id === ZeroID) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
return id;
|
|
91
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BootstrapOptions, ConnectionsOperator, OperationResultOf, UsersOperator } from "@fabriktor/client";
|
|
1
|
+
import type { ConnectionsOperator, UsersOperator } from "@fabriktor/client";
|
|
3
2
|
import type { AuthEmailOptions, AuthOperator } from "../auth/auth.js";
|
|
4
3
|
import type { UsersFXOperator } from "../users/users.js";
|
|
5
4
|
type ConnectionInsert = Parameters<ConnectionsOperator["insertOneConnection"]>[0]["in"];
|
|
6
|
-
type BootstrapInput =
|
|
5
|
+
type BootstrapInput = Parameters<UsersOperator["bootstrap"]>[0]["in"];
|
|
6
|
+
type BootstrapResult = Awaited<ReturnType<UsersOperator["bootstrap"]>>;
|
|
7
7
|
export declare const SignInMode: {
|
|
8
8
|
readonly Email: "email";
|
|
9
9
|
readonly Username: "username";
|
|
@@ -21,9 +21,6 @@ export type SignInWithEmailOptions = AuthEmailOptions & {
|
|
|
21
21
|
export type SignUpAndBootstrapOptions = AuthEmailOptions & {
|
|
22
22
|
in: BootstrapInput;
|
|
23
23
|
};
|
|
24
|
-
export type ForgotPasswordOptions = Parameters<UsersOperator["forgotPassword"]>[0];
|
|
25
|
-
export type SendSignInLinkOptions = Parameters<UsersOperator["sendSignInLink"]>[0];
|
|
26
|
-
export type SendEmailVerificationOptions = Parameters<UsersOperator["sendEmailVerification"]>[0];
|
|
27
24
|
export type SessionFXOptions = {
|
|
28
25
|
auth: AuthOperator;
|
|
29
26
|
connections: ConnectionsOperator;
|
|
@@ -31,15 +28,9 @@ export type SessionFXOptions = {
|
|
|
31
28
|
users_fx: UsersFXOperator;
|
|
32
29
|
};
|
|
33
30
|
export interface SessionFXOperator {
|
|
34
|
-
|
|
35
|
-
finishSignUp(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
36
|
-
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
31
|
+
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<BootstrapResult>;
|
|
37
32
|
signIn(opts: SignInOptions): Promise<void>;
|
|
38
33
|
signInWithEmail(opts: SignInWithEmailOptions): Promise<void>;
|
|
39
|
-
signOut(): Promise<void>;
|
|
40
|
-
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
41
|
-
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
42
|
-
sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
|
|
43
34
|
checkEmailVerification(): Promise<boolean>;
|
|
44
35
|
}
|
|
45
36
|
export declare class SessionFX implements SessionFXOperator {
|
|
@@ -48,15 +39,9 @@ export declare class SessionFX implements SessionFXOperator {
|
|
|
48
39
|
private users;
|
|
49
40
|
private usersFX;
|
|
50
41
|
constructor(opts: SessionFXOptions);
|
|
51
|
-
|
|
52
|
-
finishSignUp(opts: BootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
53
|
-
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<OperationResultOf<UpsertResult>>;
|
|
42
|
+
signUpAndBootstrap(opts: SignUpAndBootstrapOptions): Promise<BootstrapResult>;
|
|
54
43
|
signIn(opts: SignInOptions): Promise<void>;
|
|
55
44
|
signInWithEmail(opts: SignInWithEmailOptions): Promise<void>;
|
|
56
|
-
signOut(): Promise<void>;
|
|
57
|
-
forgotPassword(opts: ForgotPasswordOptions): Promise<void>;
|
|
58
|
-
sendSignInLink(opts: SendSignInLinkOptions): Promise<void>;
|
|
59
|
-
sendEmailVerification(opts: SendEmailVerificationOptions): Promise<void>;
|
|
60
45
|
checkEmailVerification(): Promise<boolean>;
|
|
61
46
|
}
|
|
62
47
|
export declare function newSessionFX(opts: SessionFXOptions): SessionFX;
|
|
@@ -18,26 +18,15 @@ export class SessionFX {
|
|
|
18
18
|
this.users = opts.users;
|
|
19
19
|
this.usersFX = opts.users_fx;
|
|
20
20
|
}
|
|
21
|
-
async
|
|
21
|
+
async signUpAndBootstrap(opts) {
|
|
22
22
|
await this.auth.signUp({
|
|
23
23
|
email: opts.email,
|
|
24
24
|
password: opts.password,
|
|
25
25
|
});
|
|
26
|
-
}
|
|
27
|
-
async finishSignUp(opts) {
|
|
28
26
|
return await this.users.bootstrap({
|
|
29
27
|
in: opts.in,
|
|
30
28
|
});
|
|
31
29
|
}
|
|
32
|
-
async signUpAndBootstrap(opts) {
|
|
33
|
-
await this.startSignUp({
|
|
34
|
-
email: opts.email,
|
|
35
|
-
password: opts.password,
|
|
36
|
-
});
|
|
37
|
-
return await this.finishSignUp({
|
|
38
|
-
in: opts.in,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
30
|
async signIn(opts) {
|
|
42
31
|
const email = opts.mode === SignInMode.Email
|
|
43
32
|
? opts.identifier
|
|
@@ -60,18 +49,6 @@ export class SessionFX {
|
|
|
60
49
|
});
|
|
61
50
|
await this.users.sync();
|
|
62
51
|
}
|
|
63
|
-
async signOut() {
|
|
64
|
-
await this.auth.signOut();
|
|
65
|
-
}
|
|
66
|
-
async forgotPassword(opts) {
|
|
67
|
-
await this.users.forgotPassword(opts);
|
|
68
|
-
}
|
|
69
|
-
async sendSignInLink(opts) {
|
|
70
|
-
await this.users.sendSignInLink(opts);
|
|
71
|
-
}
|
|
72
|
-
async sendEmailVerification(opts) {
|
|
73
|
-
await this.users.sendEmailVerification(opts);
|
|
74
|
-
}
|
|
75
52
|
async checkEmailVerification() {
|
|
76
53
|
await this.auth.reloadUser();
|
|
77
54
|
if (!this.auth.emailVerified()) {
|