@fabriktor/fx 0.0.177 → 0.0.179

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.
@@ -36,6 +36,7 @@ export * from "./marketplace/marketplace.js";
36
36
  export * from "./marketplace/validation.js";
37
37
  export * from "./memos/memos.js";
38
38
  export * from "./notifications/notifications.js";
39
+ export * from "./notifications/route.js";
39
40
  export * from "./payments/payments.js";
40
41
  export * from "./payrolls/payrolls.js";
41
42
  export * from "./payrolls/workspace.js";
package/dist/src/index.js CHANGED
@@ -36,6 +36,7 @@ export * from "./marketplace/marketplace.js";
36
36
  export * from "./marketplace/validation.js";
37
37
  export * from "./memos/memos.js";
38
38
  export * from "./notifications/notifications.js";
39
+ export * from "./notifications/route.js";
39
40
  export * from "./payments/payments.js";
40
41
  export * from "./payrolls/payrolls.js";
41
42
  export * from "./payrolls/workspace.js";
@@ -0,0 +1,2 @@
1
+ export type NotificationRoute = Record<string, string>;
2
+ export declare function notificationRoute(link: string): NotificationRoute | null;
@@ -0,0 +1,50 @@
1
+ import { ColChatChatRooms, DeepLinkScheme, DeepLinkViewKey, DeepLinkRecordKey, DeepLinkToolChat, DeepLinkViewChatAll, DeepLinkToolPreferences, DeepLinkViewPreferencesProfile, IDKey, } from "@fabriktor/schema";
2
+ import { resolvedID } from "../core/id.js";
3
+ export function notificationRoute(link) {
4
+ try {
5
+ const url = new URL(link);
6
+ if (url.protocol !== `${DeepLinkScheme}:` ||
7
+ !url.hostname ||
8
+ url.username ||
9
+ url.password ||
10
+ url.port ||
11
+ url.hash)
12
+ return null;
13
+ const parts = url.pathname
14
+ .split("/")
15
+ .filter(Boolean)
16
+ .map(decodeURIComponent);
17
+ const tool = url.hostname;
18
+ if (parts.length > 0 && (tool !== DeepLinkToolChat || parts.length !== 1))
19
+ return null;
20
+ const id = resolvedID(parts[0] ?? url.searchParams.get(IDKey));
21
+ const record = url.searchParams.get(DeepLinkRecordKey);
22
+ const view = url.searchParams.get(DeepLinkViewKey);
23
+ if (tool === DeepLinkToolChat &&
24
+ (parts.length === 1 || record === ColChatChatRooms))
25
+ return id
26
+ ? {
27
+ tool,
28
+ view: DeepLinkViewChatAll,
29
+ scope_type: ColChatChatRooms,
30
+ scope_id: id,
31
+ }
32
+ : null;
33
+ const out = { tool };
34
+ if (view)
35
+ out.view = view;
36
+ if (tool === DeepLinkToolPreferences &&
37
+ view === DeepLinkViewPreferencesProfile)
38
+ return out;
39
+ if (record) {
40
+ if (!id)
41
+ return null;
42
+ out.record = record;
43
+ out.id = id;
44
+ }
45
+ return out;
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ }
@@ -1,4 +1,4 @@
1
- import { PaymentEntityTypeBill, PaymentEntityTypePayroll, type Bill, type Payroll, PSPPaymentStatusPending, PSPPaymentStatusPartial, PSPPaymentStatusFull, type CreditLedgerEntry, type Payment, type PmtAccount, type PmtBankAccount, type PmtCard, type PmtCustomer, type PmtPublicSession, type PmtRefund, type SortStripeBalanceResult } from "@fabriktor/schema";
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
2
  import { type PaymentsOperator, type BillableOperator, type PayrollsOperator } 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";
@@ -234,6 +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
238
  purchaseAppleCredits(opts: PurchaseAppleCreditsOptions): Promise<void>;
238
239
  purchaseGoogleCredits(opts: PurchaseGoogleCreditsOptions): Promise<void>;
239
240
  prepareStripeCreditPurchase(opts: PrepareStripeCreditPurchaseOptions): Promise<PrepareStripeCreditPurchaseResult>;
@@ -285,6 +286,7 @@ export declare class PaymentsFX implements PaymentsFXOperator {
285
286
  createCreditLedgerEntry(opts: CreateCreditLedgerEntryOptions): Promise<CreditLedgerEntry>;
286
287
  replaceCreditLedgerEntry(opts: ReplaceCreditLedgerEntryOptions): Promise<CreditLedgerEntry>;
287
288
  searchCreditLedger(opts: SearchCreditLedgerOptions): Promise<SearchCreditLedgerPage>;
289
+ claimSignupCredits(): Promise<CreditGrant | undefined>;
288
290
  purchaseAppleCredits(opts: PurchaseAppleCreditsOptions): Promise<void>;
289
291
  purchaseGoogleCredits(opts: PurchaseGoogleCreditsOptions): Promise<void>;
290
292
  prepareStripeCreditPurchase(opts: PrepareStripeCreditPurchaseOptions): Promise<PrepareStripeCreditPurchaseResult>;
@@ -1,5 +1,5 @@
1
- import { CreditLedgerSourceAndroidIAP, CreditLedgerSourceAppleIAP, CreditLedgerSourceStripe, ZeroID, PaymentKindMain, PaymentEntityTypeBill, PaymentEntityTypePayroll, PSPActionableStatusSucceeded, PSPActionableStatusFailed, PSPActionableStatusCanceled, PSPPaymentStatusPending, PSPPaymentStatusPartial, PSPPaymentStatusFull, } from "@fabriktor/schema";
2
- import { queryParams, } from "@fabriktor/client";
1
+ import { CreditGrantTypeSignup, CreditLedgerSourceAndroidIAP, CreditLedgerSourceAppleIAP, CreditLedgerSourceStripe, ZeroID, PaymentKindMain, PaymentEntityTypeBill, PaymentEntityTypePayroll, PSPActionableStatusSucceeded, PSPActionableStatusFailed, PSPActionableStatusCanceled, PSPPaymentStatusPending, PSPPaymentStatusPartial, PSPPaymentStatusFull, } from "@fabriktor/schema";
2
+ import { isHTTPClientErr, queryParams, } from "@fabriktor/client";
3
3
  import { PreActionBlocked, isPreActionBlocked, runPreActionCheck, } from "../core/pre-action.js";
4
4
  import { errResolveFailed, errValidation } from "../core/err.js";
5
5
  import { normalizeIDs, requiredOperationID, resolvedID } from "../core/id.js";
@@ -27,9 +27,11 @@ const resourcePmtRefund = "pmt_refund";
27
27
  const resourcePmtCustomer = "pmt_customer";
28
28
  const resourcePmtPublicSession = "pmt_public_session";
29
29
  const resourceCreditLedgerEntry = "credit_ledger_entry";
30
+ const resourceCreditGrant = "credit_grant";
30
31
  const resourceStripeCreditPayment = "stripe credit payment";
31
32
  const resourcePublicPaymentSession = "public payment session";
32
33
  const msgPayableSourceMissing = "Payable entity source is unavailable.";
34
+ const msgCreditGrantMissing = "Credit grant response is incomplete.";
33
35
  const msgPayableBalanceChanged = "Payment balance changed or a payment is still pending. Refresh before paying.";
34
36
  const msgPaymentMethodRequired = "A payment method is required.";
35
37
  const msgPayableUnavailable = "This entity is not available for payment.";
@@ -688,6 +690,25 @@ export class PaymentsFX {
688
690
  search: (searchOpts) => this.payments.searchManyCreditLedger(searchOpts),
689
691
  });
690
692
  }
693
+ async claimSignupCredits() {
694
+ try {
695
+ const out = await this.payments.claimCredits({
696
+ type: CreditGrantTypeSignup,
697
+ });
698
+ if (!out.value) {
699
+ throw errResolveFailed({
700
+ resource: resourceCreditGrant,
701
+ msg: msgCreditGrantMissing,
702
+ });
703
+ }
704
+ return out.value;
705
+ }
706
+ catch (err) {
707
+ if (isHTTPClientErr(err) && err.status === 409)
708
+ return;
709
+ throw err;
710
+ }
711
+ }
691
712
  async purchaseAppleCredits(opts) {
692
713
  await this.payments.purchaseCredits({
693
714
  src: CreditLedgerSourceAppleIAP,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.177",
3
+ "version": "0.0.179",
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.108",
20
+ "@fabriktor/client": "0.0.111",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.80",
22
+ "@fabriktor/schema": "0.0.83",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }