@fabriktor/fx 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/src/billable/billable.d.ts +12 -10
  2. package/dist/src/billable/billable.js +1 -2
  3. package/dist/src/calls/calls.d.ts +5 -5
  4. package/dist/src/calls/calls.js +10 -4
  5. package/dist/src/chat/chat.d.ts +90 -0
  6. package/dist/src/chat/chat.js +194 -0
  7. package/dist/src/contacts/contacts.d.ts +67 -0
  8. package/dist/src/contacts/contacts.js +179 -0
  9. package/dist/src/core/err.d.ts +0 -10
  10. package/dist/src/core/err.js +0 -38
  11. package/dist/src/core/pull.d.ts +39 -0
  12. package/dist/src/core/pull.js +101 -0
  13. package/dist/src/feed/feed.d.ts +167 -0
  14. package/dist/src/feed/feed.js +642 -0
  15. package/dist/src/fx.d.ts +62 -8
  16. package/dist/src/fx.js +137 -9
  17. package/dist/src/index.d.ts +13 -0
  18. package/dist/src/index.js +13 -0
  19. package/dist/src/jobs/jobs.d.ts +74 -0
  20. package/dist/src/jobs/jobs.js +375 -0
  21. package/dist/src/marketplace/marketplace.d.ts +35 -0
  22. package/dist/src/marketplace/marketplace.js +159 -0
  23. package/dist/src/notifications/notifications.d.ts +20 -0
  24. package/dist/src/notifications/notifications.js +45 -0
  25. package/dist/src/payments/payments.d.ts +59 -0
  26. package/dist/src/payments/payments.js +266 -0
  27. package/dist/src/payrolls/payrolls.d.ts +52 -0
  28. package/dist/src/payrolls/payrolls.js +54 -0
  29. package/dist/src/privacy/privacy.d.ts +21 -0
  30. package/dist/src/privacy/privacy.js +78 -0
  31. package/dist/src/routes/routes.d.ts +22 -0
  32. package/dist/src/routes/routes.js +134 -0
  33. package/dist/src/session/session.d.ts +29 -13
  34. package/dist/src/session/session.js +21 -14
  35. package/dist/src/storage/storage.d.ts +79 -0
  36. package/dist/src/storage/storage.js +240 -0
  37. package/dist/src/timesheets/timesheets.d.ts +91 -0
  38. package/dist/src/timesheets/timesheets.js +407 -0
  39. package/dist/src/users/users.d.ts +15 -11
  40. package/dist/src/users/users.js +33 -7
  41. package/package.json +3 -3
@@ -4,12 +4,6 @@
4
4
  // not use this file except in compliance with the License. You may obtain
5
5
  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  const msgUnknownFXErr = "Unknown FX error.";
7
- const msgUnableToResolveUsername = "Unable to resolve username.";
8
- const msgUnableToMintVideoToken = "Unable to mint video token.";
9
- const msgPhoneRequired = "Phone number is required.";
10
- const msgPhoneCodeRequired = "Verification code is required.";
11
- const resourceUsername = "username";
12
- const resourceVideoToken = "video_token";
13
7
  export const FXErrKind = {
14
8
  Required: "required",
15
9
  Validation: "validation",
@@ -64,38 +58,6 @@ export function errResolveFailed(opts) {
64
58
  cause: opts.cause,
65
59
  });
66
60
  }
67
- export function errUsernameResolveFailed(field) {
68
- return errResolveFailed({
69
- resource: resourceUsername,
70
- field,
71
- msg: msgUnableToResolveUsername,
72
- });
73
- }
74
- export function errVideoTokenMintFailed() {
75
- return errResolveFailed({
76
- resource: resourceVideoToken,
77
- msg: msgUnableToMintVideoToken,
78
- });
79
- }
80
- export function errUsernameInvalid(opts) {
81
- return errValidation({
82
- field: opts.field,
83
- msg: opts.msg,
84
- cause: opts.cause,
85
- });
86
- }
87
- export function errPhoneRequired(field) {
88
- return errRequired({
89
- field,
90
- msg: msgPhoneRequired,
91
- });
92
- }
93
- export function errPhoneCodeRequired(field) {
94
- return errRequired({
95
- field,
96
- msg: msgPhoneCodeRequired,
97
- });
98
- }
99
61
  export function errUnknown(cause) {
100
62
  if (isFXErr(cause)) {
101
63
  return cause;
@@ -0,0 +1,39 @@
1
+ export type PullSessionErrorHandler = (err: unknown) => void;
2
+ export interface PullSession<TResult> {
3
+ readonly initial: TResult;
4
+ readonly sessionToken: string;
5
+ pullNext(): Promise<TResult>;
6
+ close(): void;
7
+ }
8
+ export type PullSessionOptions<TResult> = {
9
+ initial: TResult;
10
+ session_token: string;
11
+ keep_alive_interval_ms: number;
12
+ pull_next: (session_token: string) => Promise<TResult>;
13
+ keep_alive: (session_token: string) => Promise<TResult>;
14
+ resolve_session_token: (out: TResult) => string;
15
+ closed_error: () => Error;
16
+ pull_in_progress_error: () => Error;
17
+ on_error?: PullSessionErrorHandler;
18
+ };
19
+ export declare class DefaultPullSession<TResult> implements PullSession<TResult> {
20
+ readonly initial: TResult;
21
+ private token;
22
+ private closed;
23
+ private pulling;
24
+ private timer;
25
+ private keepAliveTask?;
26
+ private pullNextFn;
27
+ private keepAliveFn;
28
+ private resolveSessionToken;
29
+ private closedError;
30
+ private pullInProgressError;
31
+ private onError?;
32
+ constructor(opts: PullSessionOptions<TResult>);
33
+ get sessionToken(): string;
34
+ pullNext(): Promise<TResult>;
35
+ close(): void;
36
+ private keepAlive;
37
+ private runKeepAlive;
38
+ }
39
+ export declare function newPullSession<TResult>(opts: PullSessionOptions<TResult>): DefaultPullSession<TResult>;
@@ -0,0 +1,101 @@
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
+ export class DefaultPullSession {
7
+ initial;
8
+ token;
9
+ closed;
10
+ pulling;
11
+ timer;
12
+ keepAliveTask;
13
+ pullNextFn;
14
+ keepAliveFn;
15
+ resolveSessionToken;
16
+ closedError;
17
+ pullInProgressError;
18
+ onError;
19
+ constructor(opts) {
20
+ this.initial = opts.initial;
21
+ this.token = opts.session_token;
22
+ this.closed = false;
23
+ this.pulling = false;
24
+ this.pullNextFn = opts.pull_next;
25
+ this.keepAliveFn = opts.keep_alive;
26
+ this.resolveSessionToken = opts.resolve_session_token;
27
+ this.closedError = opts.closed_error;
28
+ this.pullInProgressError = opts.pull_in_progress_error;
29
+ this.onError = opts.on_error;
30
+ this.timer = globalThis.setInterval(() => {
31
+ void this.keepAlive();
32
+ }, opts.keep_alive_interval_ms);
33
+ }
34
+ get sessionToken() {
35
+ return this.token;
36
+ }
37
+ async pullNext() {
38
+ if (this.closed) {
39
+ throw this.closedError();
40
+ }
41
+ if (this.pulling) {
42
+ throw this.pullInProgressError();
43
+ }
44
+ this.pulling = true;
45
+ try {
46
+ const keepAliveTask = this.keepAliveTask;
47
+ if (keepAliveTask !== undefined) {
48
+ await keepAliveTask;
49
+ }
50
+ if (this.closed) {
51
+ throw this.closedError();
52
+ }
53
+ const out = await this.pullNextFn(this.token);
54
+ if (!this.closed) {
55
+ this.token = this.resolveSessionToken(out);
56
+ }
57
+ return out;
58
+ }
59
+ finally {
60
+ this.pulling = false;
61
+ }
62
+ }
63
+ close() {
64
+ if (this.closed) {
65
+ return;
66
+ }
67
+ this.closed = true;
68
+ globalThis.clearInterval(this.timer);
69
+ }
70
+ async keepAlive() {
71
+ if (this.closed || this.pulling || this.keepAliveTask !== undefined) {
72
+ return;
73
+ }
74
+ const task = this.runKeepAlive();
75
+ this.keepAliveTask = task;
76
+ try {
77
+ await task;
78
+ }
79
+ finally {
80
+ if (this.keepAliveTask === task) {
81
+ this.keepAliveTask = undefined;
82
+ }
83
+ }
84
+ }
85
+ async runKeepAlive() {
86
+ try {
87
+ const out = await this.keepAliveFn(this.token);
88
+ if (!this.closed) {
89
+ this.token = this.resolveSessionToken(out);
90
+ }
91
+ }
92
+ catch (err) {
93
+ if (!this.closed) {
94
+ this.onError?.(err);
95
+ }
96
+ }
97
+ }
98
+ }
99
+ export function newPullSession(opts) {
100
+ return new DefaultPullSession(opts);
101
+ }
@@ -0,0 +1,167 @@
1
+ import { type FeedObject, type FeedPost, type OperationResult, type RPFeedPull } from "@fabriktor/schema";
2
+ import type { FeedOperator, OperationResultOf, StorageUploadFile } from "@fabriktor/client";
3
+ import { type PullSession, type PullSessionErrorHandler } from "../core/pull.js";
4
+ import { type StorageFXOperator, type StoragePersonalBoxUploadResult } from "../storage/storage.js";
5
+ type FeedPullOptions = Parameters<FeedOperator["pull"]>[0];
6
+ type FeedPostInsert = Parameters<FeedOperator["insertOneFeedPost"]>[0]["in"];
7
+ type FeedReactionInsert = Parameters<FeedOperator["insertOneFeedReaction"]>[0]["in"];
8
+ export declare const FeedAction: {
9
+ readonly Reaction: "reaction";
10
+ readonly Favorite: "favorite";
11
+ readonly Reply: "reply";
12
+ readonly Reference: "reference";
13
+ };
14
+ export type FeedAction = (typeof FeedAction)[keyof typeof FeedAction];
15
+ export declare const FeedMediaPostStatus: {
16
+ readonly Complete: "complete";
17
+ readonly CreateUnresolved: "create_unresolved";
18
+ readonly UploadFailed: "upload_failed";
19
+ readonly AllForbidden: "all_forbidden";
20
+ readonly DownloadFailed: "download_failed";
21
+ readonly ResolveFailed: "resolve_failed";
22
+ readonly PatchFailed: "patch_failed";
23
+ };
24
+ export type FeedMediaPostStatus = (typeof FeedMediaPostStatus)[keyof typeof FeedMediaPostStatus];
25
+ export type FeedReactionType = FeedReactionInsert["reaction_type"];
26
+ export type FeedPullContext = Pick<FeedPullOptions, "contact_ids" | "pull_type" | "entity_id" | "research">;
27
+ export type FeedTextPostContent = Pick<FeedPostInsert, "text">;
28
+ export type FeedMediaPostInput = Pick<FeedPostInsert, "text" | "visibility">;
29
+ export type FeedPullResult = OperationResultOf<RPFeedPull>;
30
+ export type FeedSession = PullSession<FeedPullResult>;
31
+ export type FeedSessionErrorHandler = PullSessionErrorHandler;
32
+ export type FeedFXOptions = {
33
+ feed: FeedOperator;
34
+ storage_fx: StorageFXOperator;
35
+ keep_alive_interval_ms: number;
36
+ };
37
+ export type StartFeedSessionOptions = FeedPullContext & {
38
+ on_error?: FeedSessionErrorHandler;
39
+ };
40
+ export type AddFeedReactionOptions = {
41
+ post: FeedPost;
42
+ reaction_type: FeedReactionType;
43
+ };
44
+ export type RemoveFeedReactionOptions = {
45
+ post: FeedPost;
46
+ };
47
+ export type AddFeedFavoriteOptions = {
48
+ post: FeedPost;
49
+ };
50
+ export type RemoveFeedFavoriteOptions = {
51
+ post: FeedPost;
52
+ };
53
+ export type CreateFeedReplyOptions = {
54
+ post: FeedPost;
55
+ in: FeedTextPostContent;
56
+ };
57
+ export type RemoveFeedReplyOptions = {
58
+ post: FeedPost;
59
+ };
60
+ export type CreateFeedReferenceOptions = {
61
+ post: FeedPost;
62
+ in: FeedTextPostContent;
63
+ };
64
+ export type RemoveFeedReferenceOptions = {
65
+ post: FeedPost;
66
+ };
67
+ export type FeedMediaUploadOptions = {
68
+ user_id?: string;
69
+ uploader_id?: string;
70
+ full_quality?: boolean;
71
+ files: StorageUploadFile[];
72
+ save_to_personal_box?: boolean;
73
+ };
74
+ export type CreateFeedPostWithMediaOptions = FeedMediaUploadOptions & {
75
+ in: FeedMediaPostInput;
76
+ };
77
+ export type CreateFeedReplyWithMediaOptions = FeedMediaUploadOptions & {
78
+ post: FeedPost;
79
+ in: FeedTextPostContent;
80
+ };
81
+ export type CreateFeedReferenceWithMediaOptions = FeedMediaUploadOptions & {
82
+ post: FeedPost;
83
+ in: FeedTextPostContent;
84
+ };
85
+ export type CreateFeedPostWithMediaResult = {
86
+ status: typeof FeedMediaPostStatus.Complete;
87
+ post_id: string;
88
+ upload: StoragePersonalBoxUploadResult;
89
+ objects: FeedObject[];
90
+ } | {
91
+ status: typeof FeedMediaPostStatus.CreateUnresolved;
92
+ create: OperationResult;
93
+ error: unknown;
94
+ } | {
95
+ status: typeof FeedMediaPostStatus.UploadFailed;
96
+ post_id: string;
97
+ error: unknown;
98
+ } | {
99
+ status: typeof FeedMediaPostStatus.AllForbidden;
100
+ post_id: string;
101
+ upload: StoragePersonalBoxUploadResult;
102
+ } | {
103
+ status: typeof FeedMediaPostStatus.DownloadFailed;
104
+ post_id: string;
105
+ upload: StoragePersonalBoxUploadResult;
106
+ error: unknown;
107
+ } | {
108
+ status: typeof FeedMediaPostStatus.ResolveFailed;
109
+ post_id: string;
110
+ upload: StoragePersonalBoxUploadResult;
111
+ error: unknown;
112
+ } | {
113
+ status: typeof FeedMediaPostStatus.PatchFailed;
114
+ post_id: string;
115
+ upload: StoragePersonalBoxUploadResult;
116
+ objects: FeedObject[];
117
+ error: unknown;
118
+ };
119
+ export interface FeedFXOperator {
120
+ startSession(opts: StartFeedSessionOptions): Promise<FeedSession>;
121
+ addReaction(opts: AddFeedReactionOptions): Promise<OperationResult>;
122
+ removeReaction(opts: RemoveFeedReactionOptions): Promise<OperationResult>;
123
+ addFavorite(opts: AddFeedFavoriteOptions): Promise<OperationResult>;
124
+ removeFavorite(opts: RemoveFeedFavoriteOptions): Promise<OperationResult>;
125
+ createReply(opts: CreateFeedReplyOptions): Promise<OperationResult>;
126
+ removeReply(opts: RemoveFeedReplyOptions): Promise<OperationResult>;
127
+ createReference(opts: CreateFeedReferenceOptions): Promise<OperationResult>;
128
+ removeReference(opts: RemoveFeedReferenceOptions): Promise<OperationResult>;
129
+ createPostWithMedia(opts: CreateFeedPostWithMediaOptions): Promise<CreateFeedPostWithMediaResult>;
130
+ createReplyWithMedia(opts: CreateFeedReplyWithMediaOptions): Promise<CreateFeedPostWithMediaResult>;
131
+ createReferenceWithMedia(opts: CreateFeedReferenceWithMediaOptions): Promise<CreateFeedPostWithMediaResult>;
132
+ }
133
+ export declare class FeedFX implements FeedFXOperator {
134
+ private feed;
135
+ private storage_fx;
136
+ private keep_alive_interval_ms;
137
+ private running_actions;
138
+ private completed_actions;
139
+ private removed_actions;
140
+ private action_ids;
141
+ constructor(opts: FeedFXOptions);
142
+ startSession(opts: StartFeedSessionOptions): Promise<FeedSession>;
143
+ addReaction(opts: AddFeedReactionOptions): Promise<OperationResult>;
144
+ removeReaction(opts: RemoveFeedReactionOptions): Promise<OperationResult>;
145
+ addFavorite(opts: AddFeedFavoriteOptions): Promise<OperationResult>;
146
+ removeFavorite(opts: RemoveFeedFavoriteOptions): Promise<OperationResult>;
147
+ createReply(opts: CreateFeedReplyOptions): Promise<OperationResult>;
148
+ removeReply(opts: RemoveFeedReplyOptions): Promise<OperationResult>;
149
+ createReference(opts: CreateFeedReferenceOptions): Promise<OperationResult>;
150
+ removeReference(opts: RemoveFeedReferenceOptions): Promise<OperationResult>;
151
+ createPostWithMedia(opts: CreateFeedPostWithMediaOptions): Promise<CreateFeedPostWithMediaResult>;
152
+ createReplyWithMedia(opts: CreateFeedReplyWithMediaOptions): Promise<CreateFeedPostWithMediaResult>;
153
+ createReferenceWithMedia(opts: CreateFeedReferenceWithMediaOptions): Promise<CreateFeedPostWithMediaResult>;
154
+ private createMediaPost;
155
+ private runAction;
156
+ private hasAction;
157
+ private actionID;
158
+ private markAction;
159
+ private markActionRemoved;
160
+ private clearActionRemoved;
161
+ private isActionCompleted;
162
+ private isActionRemoved;
163
+ private isActionRunning;
164
+ private setActionRunning;
165
+ }
166
+ export declare function newFeedFX(opts: FeedFXOptions): FeedFX;
167
+ export {};