@fabriktor/fx 0.0.205 → 0.0.208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,15 +14,6 @@
14
14
  This package is designed exclusively for Fabriktor's frontend operational needs and is
15
15
  not intended for public usage.
16
16
 
17
- The Timesheets workspace restores open punches across employers and payroll
18
- periods before consulting current preferences. It follows the stored start for
19
- work and transport, confirms the actual returned punch, and requires an explicit
20
- time when continuing a shift from an earlier day. Manual day replacement is one
21
- request. Civil time input resolves to UTC with an explicit choice for repeated
22
- daylight-saving times; the backend remains authoritative for duration, overlap
23
- and persistence rules. Route arrival cues follow the stored active transport
24
- across midnight; unresolved multiple open punches still require recovery first.
25
-
26
17
  ---
27
18
 
28
19
  ## License
@@ -13,6 +13,9 @@ export declare const FeedEvents: {
13
13
  post_id: string;
14
14
  deleted?: boolean;
15
15
  }>;
16
+ Created: import("../index.js").EventKey<{
17
+ post: FeedPost;
18
+ }>;
16
19
  };
17
20
  export type FeedReadOptions = {
18
21
  id: string;
@@ -13,6 +13,7 @@ export * from "./media.js";
13
13
  import { saveFeedPost, newFeedPostSaveState, } from "./media.js";
14
14
  export const FeedEvents = {
15
15
  Changed: createEvent(),
16
+ Created: createEvent(),
16
17
  };
17
18
  const newFeedSessionToken = "";
18
19
  const resourceFeedSessionToken = "feed_session_token";
@@ -137,6 +138,7 @@ export class FeedFX {
137
138
  signal.throwIfAborted();
138
139
  const post = await this.requireFeedPost(id, signal);
139
140
  this.changed(post.id);
141
+ this.events.publish(FeedEvents.Created, { post });
140
142
  if (resolvedID(post.reply_to_post_id))
141
143
  this.changed(post.reply_to_post_id);
142
144
  if (resolvedID(post.referenced_post_id))
@@ -59,6 +59,7 @@ export * from "./routes/tracking.js";
59
59
  export * from "./routes/validation.js";
60
60
  export * from "./routes/workspace.js";
61
61
  export * from "./session/session.js";
62
+ export * from "./session/signup.js";
62
63
  export * from "./storage/capture.js";
63
64
  export * from "./storage/storage.js";
64
65
  export * from "./timesheets/access.js";
package/dist/src/index.js CHANGED
@@ -59,6 +59,7 @@ export * from "./routes/tracking.js";
59
59
  export * from "./routes/validation.js";
60
60
  export * from "./routes/workspace.js";
61
61
  export * from "./session/session.js";
62
+ export * from "./session/signup.js";
62
63
  export * from "./storage/capture.js";
63
64
  export * from "./storage/storage.js";
64
65
  export * from "./timesheets/access.js";
@@ -1,5 +1,5 @@
1
1
  import { PaymentEntityTypeBill, PaymentEntityTypePayroll, type Bill, type Payroll, PSPPaymentStatusPending, PSPPaymentStatusPartial, PSPPaymentStatusFull, type CreditLedgerEntry, type CreditGrant, type Payment, type PmtAccount, type PmtBankAccount, type PmtCard, type PmtCustomer, type PmtPublicSession, type PmtRefund, type SortStripeBalanceResult } from "@fabriktor/schema";
2
- import { type PaymentsOperator, type BillableOperator, type PayrollsOperator } from "@fabriktor/client";
2
+ import { type PaymentsOperator, type BillableOperator, type PayrollsOperator, type RequestOptions } from "@fabriktor/client";
3
3
  import { PreActionBlocked } from "../core/pre-action.js";
4
4
  import { type SearchOptions, type OwnerSearchOptions, type SearchPage } from "../core/search.js";
5
5
  import { EventBus } from "../core/events.js";
@@ -234,7 +234,7 @@ export interface PaymentsFXOperator {
234
234
  createCreditLedgerEntry(opts: CreateCreditLedgerEntryOptions): Promise<CreditLedgerEntry>;
235
235
  replaceCreditLedgerEntry(opts: ReplaceCreditLedgerEntryOptions): Promise<CreditLedgerEntry>;
236
236
  searchCreditLedger(opts: SearchCreditLedgerOptions): Promise<SearchCreditLedgerPage>;
237
- claimSignupCredits(): Promise<CreditGrant | undefined>;
237
+ claimSignupCredits(opts?: RequestOptions): Promise<CreditGrant | undefined>;
238
238
  purchaseAppleCredits(opts: PurchaseAppleCreditsOptions): Promise<void>;
239
239
  purchaseGoogleCredits(opts: PurchaseGoogleCreditsOptions): Promise<void>;
240
240
  prepareStripeCreditPurchase(opts: PrepareStripeCreditPurchaseOptions): Promise<PrepareStripeCreditPurchaseResult>;
@@ -286,7 +286,7 @@ export declare class PaymentsFX implements PaymentsFXOperator {
286
286
  createCreditLedgerEntry(opts: CreateCreditLedgerEntryOptions): Promise<CreditLedgerEntry>;
287
287
  replaceCreditLedgerEntry(opts: ReplaceCreditLedgerEntryOptions): Promise<CreditLedgerEntry>;
288
288
  searchCreditLedger(opts: SearchCreditLedgerOptions): Promise<SearchCreditLedgerPage>;
289
- claimSignupCredits(): Promise<CreditGrant | undefined>;
289
+ claimSignupCredits(opts?: RequestOptions): Promise<CreditGrant | undefined>;
290
290
  purchaseAppleCredits(opts: PurchaseAppleCreditsOptions): Promise<void>;
291
291
  purchaseGoogleCredits(opts: PurchaseGoogleCreditsOptions): Promise<void>;
292
292
  prepareStripeCreditPurchase(opts: PrepareStripeCreditPurchaseOptions): Promise<PrepareStripeCreditPurchaseResult>;
@@ -690,9 +690,10 @@ export class PaymentsFX {
690
690
  search: (searchOpts) => this.payments.searchManyCreditLedger(searchOpts),
691
691
  });
692
692
  }
693
- async claimSignupCredits() {
693
+ async claimSignupCredits(opts = {}) {
694
694
  try {
695
695
  const out = await this.payments.claimCredits({
696
+ ...opts,
696
697
  type: CreditGrantTypeSignup,
697
698
  });
698
699
  if (!out.value) {
@@ -1,5 +1,5 @@
1
1
  import type { PreferencesOperator } from "@fabriktor/client";
2
- import { type InPrefApp, type PrefApp, type InPrefClient, type InPrefCompany, type InPrefEmployee, type OperationResult, type PrefPayment, type PrefClient, type PrefEmployee, type PrefCompany, type PrefVisibility, type PrefLanguage, type PrefNotif, type PrefEmail, type PrefTutorial } from "@fabriktor/schema";
2
+ import { type InPrefApp, type PrefApp, type InPrefClient, type InPrefCompany, type InPrefEmployee, type OperationResult, type PrefPayment, type PrefClient, type PrefEmployee, type PrefCompany, type PrefVisibility, type PrefLanguage, type PrefNotif, type PrefEmail } from "@fabriktor/schema";
3
3
  import { EventBus } from "../core/events.js";
4
4
  export type GetPrefAppOptions = {
5
5
  owner_id: string;
@@ -27,8 +27,6 @@ type PrefNotifInsertOptions = Parameters<PreferencesOperator["insertOnePrefNotif
27
27
  type PrefNotifReplaceOptions = Parameters<PreferencesOperator["replaceOnePrefNotif"]>[0];
28
28
  type PrefEmailInsertOptions = Parameters<PreferencesOperator["insertOnePrefEmail"]>[0];
29
29
  type PrefEmailReplaceOptions = Parameters<PreferencesOperator["replaceOnePrefEmail"]>[0];
30
- type PrefTutorialInsertOptions = Parameters<PreferencesOperator["insertOnePrefTutorial"]>[0];
31
- type PrefTutorialReplaceOptions = Parameters<PreferencesOperator["replaceOnePrefTutorial"]>[0];
32
30
  export type CreatePrefPaymentOptions = PrefPaymentInsertOptions;
33
31
  export type ReplacePrefPaymentOptions = PrefPaymentReplaceOptions;
34
32
  export type CreatePrefClientOptions = PrefClientInsertOptions;
@@ -45,8 +43,6 @@ export type CreatePrefNotifOptions = PrefNotifInsertOptions;
45
43
  export type ReplacePrefNotifOptions = PrefNotifReplaceOptions;
46
44
  export type CreatePrefEmailOptions = PrefEmailInsertOptions;
47
45
  export type ReplacePrefEmailOptions = PrefEmailReplaceOptions;
48
- export type CreatePrefTutorialOptions = PrefTutorialInsertOptions;
49
- export type ReplacePrefTutorialOptions = PrefTutorialReplaceOptions;
50
46
  export type GetPrefClientOptions = {
51
47
  owner_id: string;
52
48
  };
@@ -119,8 +115,6 @@ export interface PreferencesFXOperator {
119
115
  replacePrefNotif(opts: ReplacePrefNotifOptions): Promise<PrefNotif>;
120
116
  createPrefEmail(opts: CreatePrefEmailOptions): Promise<PrefEmail>;
121
117
  replacePrefEmail(opts: ReplacePrefEmailOptions): Promise<PrefEmail>;
122
- createPrefTutorial(opts: CreatePrefTutorialOptions): Promise<PrefTutorial>;
123
- replacePrefTutorial(opts: ReplacePrefTutorialOptions): Promise<PrefTutorial>;
124
118
  ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
125
119
  }
126
120
  export type PreferencesFXOptions = {
@@ -158,8 +152,6 @@ export declare class PreferencesFX implements PreferencesFXOperator {
158
152
  replacePrefNotif(opts: ReplacePrefNotifOptions): Promise<PrefNotif>;
159
153
  createPrefEmail(opts: CreatePrefEmailOptions): Promise<PrefEmail>;
160
154
  replacePrefEmail(opts: ReplacePrefEmailOptions): Promise<PrefEmail>;
161
- createPrefTutorial(opts: CreatePrefTutorialOptions): Promise<PrefTutorial>;
162
- replacePrefTutorial(opts: ReplacePrefTutorialOptions): Promise<PrefTutorial>;
163
155
  ensurePrefLanguage(opts: EnsurePrefLanguageOptions): Promise<OperationResult>;
164
156
  private queryPrefClient;
165
157
  private queryPrefEmployee;
@@ -173,7 +165,6 @@ export declare class PreferencesFX implements PreferencesFXOperator {
173
165
  private findPrefLanguage;
174
166
  private findPrefNotif;
175
167
  private findPrefEmail;
176
- private findPrefTutorial;
177
168
  }
178
169
  export declare function newPreferencesFX(opts: PreferencesFXOptions): PreferencesFX;
179
170
  export {};
@@ -31,9 +31,6 @@ const msgPrefNotifMissing = "Notification preference could not be resolved after
31
31
  const resourcePrefEmail = "pref_email";
32
32
  const msgCreatedPrefEmailIDMissing = "Created email preference response did not contain an ID.";
33
33
  const msgPrefEmailMissing = "Email preference could not be resolved after the mutation.";
34
- const resourcePrefTutorial = "pref_tutorial";
35
- const msgCreatedPrefTutorialIDMissing = "Created tutorial preference response did not contain an ID.";
36
- const msgPrefTutorialMissing = "Tutorial preference could not be resolved after the mutation.";
37
34
  export const PrefCompanyDocumentNote = {
38
35
  Invoice: "invoice",
39
36
  Estimate: "estimate",
@@ -308,15 +305,6 @@ export class PreferencesFX {
308
305
  await this.preferences.replaceOnePrefEmail(opts);
309
306
  return await this.findPrefEmail(opts.id);
310
307
  }
311
- async createPrefTutorial(opts) {
312
- const out = await this.preferences.insertOnePrefTutorial(opts);
313
- const id = requiredOperationID(out, msgCreatedPrefTutorialIDMissing);
314
- return await this.findPrefTutorial(id);
315
- }
316
- async replacePrefTutorial(opts) {
317
- await this.preferences.replaceOnePrefTutorial(opts);
318
- return await this.findPrefTutorial(opts.id);
319
- }
320
308
  async ensurePrefLanguage(opts) {
321
309
  const pref = await this.getPrefLanguage({ owner_id: opts.owner_id });
322
310
  const input = {
@@ -472,19 +460,6 @@ export class PreferencesFX {
472
460
  }
473
461
  return pref_email;
474
462
  }
475
- async findPrefTutorial(id) {
476
- const out = await this.preferences.findOnePrefTutorial({
477
- id,
478
- });
479
- const pref_tutorial = out.value;
480
- if (pref_tutorial === undefined) {
481
- throw errResolveFailed({
482
- resource: resourcePrefTutorial,
483
- msg: msgPrefTutorialMissing,
484
- });
485
- }
486
- return pref_tutorial;
487
- }
488
463
  }
489
464
  function prefCompanyInput(pref) {
490
465
  return {
@@ -0,0 +1,36 @@
1
+ import { type InFeedPost, type InMarketplacePost } from "@fabriktor/schema";
2
+ import type { FeedFXOperator } from "../feed/feed.js";
3
+ import type { MarketplaceFXOperator } from "../marketplace/marketplace.js";
4
+ export type SignupIntroduction = {
5
+ text: string;
6
+ hiring: boolean;
7
+ };
8
+ export type SignupPostsInput = {
9
+ welcome: string;
10
+ user_type: string;
11
+ country: string;
12
+ state: string;
13
+ city: string;
14
+ introduction?: SignupIntroduction;
15
+ };
16
+ export type SignupPostTask = {
17
+ idempotency_key: string;
18
+ attempted: boolean;
19
+ created_id?: string;
20
+ status: "pending" | "done" | "rejected" | "unconfirmed";
21
+ } & ({
22
+ kind: "feed";
23
+ input: InFeedPost;
24
+ } | {
25
+ kind: "marketplace";
26
+ input: InMarketplacePost;
27
+ });
28
+ export declare function newSignupPosts(opts: SignupPostsInput): SignupPostTask[];
29
+ export type CreateSignupPostsOptions = {
30
+ posts: SignupPostTask[];
31
+ feed: Pick<FeedFXOperator, "createFeedPost">;
32
+ marketplace: Pick<MarketplaceFXOperator, "createMarketplacePost">;
33
+ signal: AbortSignal;
34
+ on_change: () => void;
35
+ };
36
+ export declare function createSignupPosts(opts: CreateSignupPostsOptions): Promise<PromiseSettledResult<void>[]>;
@@ -0,0 +1,104 @@
1
+ import { PostTypeEmployment, Private, UserTypeEmployer, ZeroID, } from "@fabriktor/schema";
2
+ import { errUnconfirmedMutation } from "../core/err.js";
3
+ import { resolvedID } from "../core/id.js";
4
+ import { marketplacePostTypes } from "../marketplace/validation.js";
5
+ export function newSignupPosts(opts) {
6
+ const checkpoint = () => ({
7
+ idempotency_key: crypto.randomUUID(),
8
+ attempted: false,
9
+ status: "pending",
10
+ });
11
+ const posts = [
12
+ {
13
+ ...checkpoint(),
14
+ kind: "feed",
15
+ input: {
16
+ text: { text: opts.welcome, file: "", file_url: "", mime: "" },
17
+ objects: [],
18
+ is_uploading: false,
19
+ has_media: false,
20
+ visibility: Private,
21
+ referenced_post_id: ZeroID,
22
+ reply_to_post_id: ZeroID,
23
+ },
24
+ },
25
+ ];
26
+ const text = opts.introduction?.text.trim();
27
+ if (!text)
28
+ return posts;
29
+ for (const post_type of marketplacePostTypes(opts.user_type)) {
30
+ if (opts.user_type === UserTypeEmployer &&
31
+ post_type === PostTypeEmployment &&
32
+ !opts.introduction?.hiring)
33
+ continue;
34
+ posts.push({
35
+ ...checkpoint(),
36
+ kind: "marketplace",
37
+ input: {
38
+ text: { text, file: "", file_url: "", mime: "" },
39
+ post_type,
40
+ user_type: opts.user_type,
41
+ country: opts.country,
42
+ state: opts.state,
43
+ city: opts.city,
44
+ },
45
+ });
46
+ }
47
+ return posts;
48
+ }
49
+ export async function createSignupPosts(opts) {
50
+ return await Promise.allSettled(opts.posts.map(async (post) => {
51
+ if (post.status !== "pending")
52
+ return;
53
+ opts.signal.throwIfAborted();
54
+ if (post.attempted && !resolvedID(post.created_id)) {
55
+ post.status = "unconfirmed";
56
+ opts.on_change();
57
+ throw errUnconfirmedMutation();
58
+ }
59
+ const checkpoint = {
60
+ attempted: post.attempted,
61
+ created_id: post.created_id,
62
+ before_request: () => {
63
+ opts.signal.throwIfAborted();
64
+ post.attempted = true;
65
+ opts.on_change();
66
+ },
67
+ on_created: (id) => {
68
+ post.created_id = id;
69
+ opts.on_change();
70
+ },
71
+ on_rejected: () => {
72
+ post.attempted = false;
73
+ post.status = "rejected";
74
+ opts.on_change();
75
+ },
76
+ };
77
+ const request = {
78
+ ...checkpoint,
79
+ idempotency_key: post.idempotency_key,
80
+ signal: opts.signal,
81
+ };
82
+ try {
83
+ if (post.kind === "feed")
84
+ await opts.feed.createFeedPost({ ...request, in: post.input });
85
+ else
86
+ await opts.marketplace.createMarketplacePost({
87
+ ...request,
88
+ in: post.input,
89
+ });
90
+ post.status = "done";
91
+ opts.on_change();
92
+ }
93
+ catch (error) {
94
+ // A transport failure or 409 is not evidence that a post was committed.
95
+ if (post.status === "pending" &&
96
+ post.attempted &&
97
+ !resolvedID(post.created_id)) {
98
+ post.status = "unconfirmed";
99
+ opts.on_change();
100
+ }
101
+ throw error;
102
+ }
103
+ }));
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.205",
3
+ "version": "0.0.208",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,9 +17,9 @@
17
17
  "typescript": "^6.0.3"
18
18
  },
19
19
  "dependencies": {
20
- "@fabriktor/client": "0.0.124",
20
+ "@fabriktor/client": "0.0.126",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.94",
22
+ "@fabriktor/schema": "0.0.95",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }