@fabriktor/fx 0.0.176 → 0.0.178
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/chat/chat.d.ts +1 -1
- package/dist/src/chat/chat.js +3 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/payments/payments.d.ts +3 -1
- package/dist/src/payments/payments.js +23 -2
- package/dist/src/users/picture.d.ts +8 -0
- package/dist/src/users/picture.js +29 -0
- package/dist/src/users/users.d.ts +8 -0
- package/dist/src/users/users.js +20 -0
- package/package.json +3 -3
package/dist/src/chat/chat.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export type MyChatRoomMembersOptions = {
|
|
|
67
67
|
export type ChatRoomParticipantsOptions = {
|
|
68
68
|
chat_room_ids: string[];
|
|
69
69
|
};
|
|
70
|
-
export type ChatRoomParticipant = Pick<User, "id" | "full_name" | "username" | "account_identity">;
|
|
70
|
+
export type ChatRoomParticipant = Pick<User, "id" | "full_name" | "username" | "account_identity" | "picture_id" | "picture_preview" | "picture_url">;
|
|
71
71
|
export type ChatRoomParticipants = {
|
|
72
72
|
members: ChatRoomMember[];
|
|
73
73
|
users: ChatRoomParticipant[];
|
package/dist/src/chat/chat.js
CHANGED
|
@@ -480,6 +480,9 @@ export class ChatFX {
|
|
|
480
480
|
full_name: user.full_name,
|
|
481
481
|
username: user.username,
|
|
482
482
|
account_identity: user.account_identity,
|
|
483
|
+
picture_id: user.picture_id,
|
|
484
|
+
picture_preview: user.picture_preview,
|
|
485
|
+
picture_url: user.picture_url,
|
|
483
486
|
};
|
|
484
487
|
}
|
|
485
488
|
async findChat(id, signal) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -58,5 +58,6 @@ export * from "./timesheets/timesheets.js";
|
|
|
58
58
|
export * from "./timesheets/workspace.js";
|
|
59
59
|
export * from "./users/email.js";
|
|
60
60
|
export * from "./users/phone.js";
|
|
61
|
+
export * from "./users/picture.js";
|
|
61
62
|
export * from "./users/username.js";
|
|
62
63
|
export * from "./users/users.js";
|
package/dist/src/index.js
CHANGED
|
@@ -58,5 +58,6 @@ export * from "./timesheets/timesheets.js";
|
|
|
58
58
|
export * from "./timesheets/workspace.js";
|
|
59
59
|
export * from "./users/email.js";
|
|
60
60
|
export * from "./users/phone.js";
|
|
61
|
+
export * from "./users/picture.js";
|
|
61
62
|
export * from "./users/username.js";
|
|
62
63
|
export * from "./users/users.js";
|
|
@@ -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,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type InUser, type User } from "@fabriktor/schema";
|
|
2
|
+
export type UserAvatarProfile = Pick<User, "id" | "full_name" | "username" | "picture_id" | "picture_preview" | "picture_url">;
|
|
3
|
+
export type UserPictureInput = Pick<InUser, "picture_id" | "picture_preview">;
|
|
4
|
+
export declare const userPictureMaxBytes: number;
|
|
5
|
+
export declare const userPictureMaxSize = 128;
|
|
6
|
+
export declare function hasUserPicture(user: Pick<User, "picture_id"> | null | undefined): boolean;
|
|
7
|
+
export declare function userPicturePreview(user: Pick<User, "picture_id" | "picture_preview"> | null | undefined): string;
|
|
8
|
+
export declare function validUserPicturePreview(value: string): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MimeJPEG, MimePNG } from "@fabriktor/schema";
|
|
2
|
+
import { resolvedID } from "../core/id.js";
|
|
3
|
+
export const userPictureMaxBytes = 16 * 1024;
|
|
4
|
+
export const userPictureMaxSize = 128;
|
|
5
|
+
const previewTypes = [MimeJPEG, MimePNG];
|
|
6
|
+
export function hasUserPicture(user) {
|
|
7
|
+
return !!resolvedID(user?.picture_id);
|
|
8
|
+
}
|
|
9
|
+
// Avatars never fall back to the original URL: the preview travels with the user.
|
|
10
|
+
export function userPicturePreview(user) {
|
|
11
|
+
if (!hasUserPicture(user))
|
|
12
|
+
return "";
|
|
13
|
+
const value = user?.picture_preview ?? "";
|
|
14
|
+
return validUserPicturePreview(value) ? value : "";
|
|
15
|
+
}
|
|
16
|
+
export function validUserPicturePreview(value) {
|
|
17
|
+
const comma = value.indexOf(",");
|
|
18
|
+
if (comma < 0 ||
|
|
19
|
+
!previewTypes.some((mime) => value.slice(0, comma) === `data:${mime};base64`))
|
|
20
|
+
return false;
|
|
21
|
+
const data = value.slice(comma + 1);
|
|
22
|
+
if (!data ||
|
|
23
|
+
data.length > Math.ceil(userPictureMaxBytes / 3) * 4 ||
|
|
24
|
+
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data))
|
|
25
|
+
return false;
|
|
26
|
+
const bytes = (data.length / 4) * 3 -
|
|
27
|
+
(data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0);
|
|
28
|
+
return bytes > 0 && bytes <= userPictureMaxBytes;
|
|
29
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type GetByUIDOptions, type OperationResultOf, type TmpPhonesOperator, type TmpUsernamesOperator, type UsernameVerification, type UsersOperator } from "@fabriktor/client";
|
|
2
2
|
import { UserTypeEmployee, UserTypeEmployer, type InAddress, type InUser, type User } from "@fabriktor/schema";
|
|
3
3
|
import { type RunSearchOptions, type SearchPage } from "../core/search.js";
|
|
4
|
+
import { type UserPictureInput } from "./picture.js";
|
|
4
5
|
export type ResolveUsernameOptions = Parameters<UsersOperator["resolveUsername"]>[0];
|
|
5
6
|
export type VerifyUsernameOptions = Parameters<TmpUsernamesOperator["verify"]>[0];
|
|
6
7
|
export type GenerateUsernamesOptions = VerifyUsernameOptions;
|
|
@@ -30,6 +31,11 @@ export type UpdateUserProfileOptions = GetByUIDOptions & {
|
|
|
30
31
|
id: string;
|
|
31
32
|
in: UserProfileInput;
|
|
32
33
|
};
|
|
34
|
+
export type UpdateUserPictureOptions = GetByUIDOptions & {
|
|
35
|
+
id: string;
|
|
36
|
+
in: UserPictureInput;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
};
|
|
33
39
|
export type UpdateUserPhoneOptions = GetByUIDOptions & {
|
|
34
40
|
id: string;
|
|
35
41
|
phone: string;
|
|
@@ -60,6 +66,7 @@ export interface UsersFXOperator {
|
|
|
60
66
|
updateExternalUser(opts: UpdateExternalUserOptions): Promise<User>;
|
|
61
67
|
searchExternalUsers(opts: SearchExternalUsersOptions): Promise<SearchExternalUsersPage>;
|
|
62
68
|
updateUserProfile(opts: UpdateUserProfileOptions): Promise<User>;
|
|
69
|
+
updateUserPicture(opts: UpdateUserPictureOptions): Promise<User>;
|
|
63
70
|
updateUserPhone(opts: UpdateUserPhoneOptions): Promise<User>;
|
|
64
71
|
switchActiveMode(opts: SwitchActiveModeOptions): Promise<User>;
|
|
65
72
|
establishWorkIdentity(opts: EstablishWorkIdentityOptions): Promise<User>;
|
|
@@ -80,6 +87,7 @@ export declare class UsersFX implements UsersFXOperator {
|
|
|
80
87
|
updateExternalUser(opts: UpdateExternalUserOptions): Promise<User>;
|
|
81
88
|
searchExternalUsers(opts: SearchExternalUsersOptions): Promise<SearchExternalUsersPage>;
|
|
82
89
|
updateUserProfile(opts: UpdateUserProfileOptions): Promise<User>;
|
|
90
|
+
updateUserPicture(opts: UpdateUserPictureOptions): Promise<User>;
|
|
83
91
|
updateUserPhone(opts: UpdateUserPhoneOptions): Promise<User>;
|
|
84
92
|
switchActiveMode(opts: SwitchActiveModeOptions): Promise<User>;
|
|
85
93
|
establishWorkIdentity(opts: EstablishWorkIdentityOptions): Promise<User>;
|
package/dist/src/users/users.js
CHANGED
|
@@ -5,7 +5,9 @@ import { normalizeIDs, requiredOperationID, resolvedID } from "../core/id.js";
|
|
|
5
5
|
import { runSearch, } from "../core/search.js";
|
|
6
6
|
import { normalizePhone, normalizePhoneCode, validatePhone, validatePhoneCode, } from "./phone.js";
|
|
7
7
|
import { normalizeEmail, isValidEmail } from "./email.js";
|
|
8
|
+
import { validUserPicturePreview } from "./picture.js";
|
|
8
9
|
import { normalizeUsername, validateUsernameFormat } from "./username.js";
|
|
10
|
+
const msgPictureRequired = "A valid account and profile preview are required.";
|
|
9
11
|
const msgUnableToResolveUsername = "Unable to resolve username.";
|
|
10
12
|
const msgPhoneRequired = "Phone number is required.";
|
|
11
13
|
const msgPhoneCodeRequired = "Verification code is required.";
|
|
@@ -154,6 +156,24 @@ export class UsersFX {
|
|
|
154
156
|
});
|
|
155
157
|
return await this.updatedUser(opts.uid);
|
|
156
158
|
}
|
|
159
|
+
async updateUserPicture(opts) {
|
|
160
|
+
opts.signal?.throwIfAborted();
|
|
161
|
+
const id = resolvedID(opts.id);
|
|
162
|
+
const picture_id = resolvedID(opts.in.picture_id) ?? "";
|
|
163
|
+
const picture_preview = picture_id ? opts.in.picture_preview : "";
|
|
164
|
+
if (!id ||
|
|
165
|
+
!opts.uid.trim() ||
|
|
166
|
+
(picture_id && !validUserPicturePreview(picture_preview))) {
|
|
167
|
+
throw errValidation({ msg: msgPictureRequired });
|
|
168
|
+
}
|
|
169
|
+
await this.users.replaceOneUser({
|
|
170
|
+
id,
|
|
171
|
+
in: { picture_id, picture_preview },
|
|
172
|
+
signal: opts.signal,
|
|
173
|
+
});
|
|
174
|
+
opts.signal?.throwIfAborted();
|
|
175
|
+
return await this.updatedUser(opts.uid);
|
|
176
|
+
}
|
|
157
177
|
async updateUserPhone(opts) {
|
|
158
178
|
const phone = normalizePhone(opts.phone);
|
|
159
179
|
const code = normalizePhoneCode(opts.code);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/fx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.178",
|
|
4
4
|
"description": "",
|
|
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.
|
|
20
|
+
"@fabriktor/client": "0.0.109",
|
|
21
21
|
"@fabriktor/fx": "0.0.94",
|
|
22
|
-
"@fabriktor/schema": "0.0.
|
|
22
|
+
"@fabriktor/schema": "0.0.81",
|
|
23
23
|
"convert": "8.0.2"
|
|
24
24
|
}
|
|
25
25
|
}
|