@fabriktor/fx 0.0.175 → 0.0.177

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.
@@ -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[];
@@ -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) {
@@ -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";
@@ -29,12 +29,12 @@ export type ArchiveLocationOptions = {
29
29
  type LocationSearchFields = Partial<Pick<Location, "is_archived">>;
30
30
  type JobSearchFields = Partial<Pick<Job, "location_id" | "status">>;
31
31
  export type SearchLocationsOptions = OwnerSearchOptions & LocationSearchFields;
32
- export type SearchAccessibleLocationsOptions = SearchOptions & LocationSearchFields;
32
+ export type SearchAccessibleLocationsOptions = SearchOptions & LocationSearchFields & Partial<Pick<Location, "owner_id">>;
33
33
  export type SearchJobProgramsOptions = OwnerSearchOptions & Partial<Pick<JobProgram, "finished">> & {
34
34
  location_id?: JobProgram["job_location_id"];
35
35
  };
36
36
  export type SearchJobsOptions = OwnerSearchOptions & JobSearchFields;
37
- export type SearchAccessibleJobsOptions = SearchOptions & JobSearchFields;
37
+ export type SearchAccessibleJobsOptions = SearchOptions & JobSearchFields & Partial<Pick<Job, "owner_id">>;
38
38
  export type SearchLocationsPage = SearchPage<Location>;
39
39
  export type SearchJobProgramsPage = SearchPage<JobProgram>;
40
40
  export type SearchJobsPage = SearchPage<Job>;
@@ -110,12 +110,10 @@ export class JobsFX {
110
110
  });
111
111
  }
112
112
  async searchAccessibleLocations(opts = {}) {
113
- const { is_archived, ...searchOpts } = opts;
113
+ const { owner_id, is_archived, ...searchOpts } = opts;
114
114
  return await runSearch({
115
115
  ...searchOpts,
116
- query: is_archived === undefined
117
- ? undefined
118
- : queryParams({ is_archived }),
116
+ query: queryParams({ owner_id: resolvedID(owner_id), is_archived }),
119
117
  search: (opts) => this.jobs.searchMineLocations(opts),
120
118
  });
121
119
  }
@@ -230,10 +228,13 @@ export class JobsFX {
230
228
  });
231
229
  }
232
230
  async searchAccessibleJobs(opts = {}) {
233
- const { location_id, status, ...searchOpts } = opts;
231
+ const { owner_id, location_id, status, ...searchOpts } = opts;
234
232
  return await runSearch({
235
233
  ...searchOpts,
236
- query: jobSearchQuery({ location_id, status }),
234
+ query: {
235
+ ...jobSearchQuery({ location_id, status }),
236
+ ...queryParams({ owner_id: resolvedID(owner_id) }),
237
+ },
237
238
  search: (opts) => this.jobs.searchMineJobs(opts),
238
239
  });
239
240
  }
@@ -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>;
@@ -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.175",
3
+ "version": "0.0.177",
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.107",
20
+ "@fabriktor/client": "0.0.108",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.78",
22
+ "@fabriktor/schema": "0.0.80",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }