@fabriktor/fx 0.0.189 → 0.0.191

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.
@@ -39,15 +39,12 @@ export class ChatFX {
39
39
  return new ChatSendQueue({ ...opts, chat: this.chat });
40
40
  }
41
41
  async chatMessage(opts) {
42
- const out = await this.chat.queryChats({
43
- query: queryParams({
44
- id: opts.id,
45
- chat_room_id: opts.chat_room_id,
46
- }),
42
+ const out = await this.chat.findOneChat({
43
+ id: opts.id,
47
44
  signal: opts.signal,
48
45
  });
49
- const chat = out.value?.find((entry) => entry.id === opts.id && entry.chat_room_id === opts.chat_room_id);
50
- if (!chat)
46
+ const chat = out.value;
47
+ if (!chat || chat.id !== opts.id || chat.chat_room_id !== opts.chat_room_id)
51
48
  throw errResolveFailed({ resource: resourceChat, msg: msgChatMissing });
52
49
  return chat;
53
50
  }
@@ -57,3 +57,4 @@ export declare class TalkieSession {
57
57
  private resolve;
58
58
  private patch;
59
59
  }
60
+ export declare function isTalkieUnavailable(error: unknown): boolean;
@@ -2,7 +2,8 @@ import { ColStorageChat, MimePrefixAudio, NotifKChatChatsTalkieReceived, NotifCh
2
2
  import { newChatInput } from "./optimistic.js";
3
3
  import { notifyObserver } from "../core/events.js";
4
4
  import { resolvedID } from "../core/id.js";
5
- import { errResolveFailed } from "../core/err.js";
5
+ import { isNotFoundClientErr } from "@fabriktor/client";
6
+ import { errResolveFailed, isFXErr, FXErrKind } from "../core/err.js";
6
7
  export function notificationTalkie(item) {
7
8
  if (item.notif_k !== NotifKChatChatsTalkieReceived)
8
9
  return;
@@ -203,3 +204,9 @@ function unavailable() {
203
204
  msg: "This voice message or conversation is no longer available.",
204
205
  });
205
206
  }
207
+ export function isTalkieUnavailable(error) {
208
+ return (isNotFoundClientErr(error) ||
209
+ (isFXErr(error) &&
210
+ error.kind === FXErrKind.ResolveFailed &&
211
+ (error.resource === "talkie" || error.resource === "chat")));
212
+ }
@@ -11,8 +11,9 @@ export declare const bannerMaxZoom = 4;
11
11
  export declare function userDisplayName(user: UserCardIdentity): string;
12
12
  export declare function userCardInput(user?: Partial<User> | null): UserCardInput;
13
13
  export declare function normalizeUserCardInput(value: UserCardInput): UserCardInput;
14
+ export declare function normalizeUserProfileURL(value: string): string;
15
+ export declare function validUserProfileURL(value: string): boolean;
14
16
  export declare function validateUserCardInput(input: UserCardInput): void;
15
- export declare function userBannerPreview(user: Partial<User> | null | undefined): string;
16
17
  export declare function bannerCrop(width: number, height: number, frame: BannerFrame): {
17
18
  x: number;
18
19
  y: number;
@@ -1,4 +1,4 @@
1
- import { ZeroID, UserBioMaxLength, UserURLsMaxCount, UserURLMaxLength, UserBannerMaxBytes, UserBannerWidth, UserBannerHeight, } from "@fabriktor/schema";
1
+ import { ZeroID, HTTPSScheme, UserURLHostPattern, UserBioMaxLength, UserURLsMaxCount, UserURLMaxLength, UserBannerMaxBytes, UserBannerWidth, UserBannerHeight, } from "@fabriktor/schema";
2
2
  import { errValidation } from "../core/err.js";
3
3
  import { publicLinkURL } from "../core/links.js";
4
4
  import { resolvedID } from "../core/id.js";
@@ -29,17 +29,38 @@ export function userCardInput(user) {
29
29
  export function normalizeUserCardInput(value) {
30
30
  const input = userCardInput(value);
31
31
  input.bio = input.bio.trim();
32
- input.urls = input.urls.map((url) => url.trim()).filter(Boolean);
32
+ input.urls = input.urls
33
+ .map((url) => normalizeUserProfileURL(url))
34
+ .filter(Boolean);
33
35
  if (!resolvedID(input.banner_id))
34
36
  input.banner_preview = "";
35
37
  return input;
36
38
  }
39
+ export function normalizeUserProfileURL(value) {
40
+ const url = value.trim();
41
+ if (!url)
42
+ return url;
43
+ const normalized = url.includes("://")
44
+ ? url
45
+ : `${HTTPSScheme}://${url.replace(/^\/\//, "")}`;
46
+ return /\s|\\/.test(normalized)
47
+ ? normalized
48
+ : publicLinkURL(normalized) || normalized;
49
+ }
50
+ export function validUserProfileURL(value) {
51
+ const normalized = normalizeUserProfileURL(value);
52
+ const url = publicLinkURL(normalized);
53
+ return (!!url &&
54
+ !/\s|\\/.test(normalized) &&
55
+ new TextEncoder().encode(normalized).length <= UserURLMaxLength &&
56
+ new RegExp(UserURLHostPattern).test(new URL(url).hostname));
57
+ }
37
58
  export function validateUserCardInput(input) {
38
59
  if ([...input.bio].length > UserBioMaxLength)
39
60
  throw errValidation({ field: "bio", msg: msgBioLength });
40
61
  if (input.urls.length > UserURLsMaxCount ||
41
62
  input.urls.some((url) => new TextEncoder().encode(url).length > UserURLMaxLength ||
42
- !publicLinkURL(url)))
63
+ !validUserProfileURL(url)))
43
64
  throw errValidation({
44
65
  field: "urls",
45
66
  msg: msgPublicLinks,
@@ -51,13 +72,6 @@ export function validateUserCardInput(input) {
51
72
  msg: msgBannerRequired,
52
73
  });
53
74
  }
54
- export function userBannerPreview(user) {
55
- const preview = user?.banner_preview ?? "";
56
- return resolvedID(user?.banner_id) &&
57
- validImagePreview(preview, UserBannerMaxBytes)
58
- ? preview
59
- : "";
60
- }
61
75
  // Position is relative to available travel, so the same crop works at every viewport size.
62
76
  export function bannerCrop(width, height, frame) {
63
77
  const clamp = (value, min, max) => Math.min(max, Math.max(min, Number.isFinite(value) ? value : min));
@@ -75,10 +89,13 @@ export function bannerCrop(width, height, frame) {
75
89
  export function moveBannerFrame(width, height, frame, dx, dy, viewportWidth) {
76
90
  const crop = bannerCrop(width, height, frame);
77
91
  const scale = crop.width / Math.max(1, viewportWidth);
92
+ const travelX = width - crop.width;
93
+ const travelY = height - crop.height;
78
94
  const clamp = (value) => Math.min(1, Math.max(0, value));
95
+ // A fitted axis (including subpixel overflow) has no visible travel.
79
96
  return {
80
97
  ...frame,
81
- x: clamp(frame.x - (dx * scale) / Math.max(1, width - crop.width)),
82
- y: clamp(frame.y - (dy * scale) / Math.max(1, height - crop.height)),
98
+ x: travelX > scale ? clamp(frame.x - (dx * scale) / travelX) : frame.x,
99
+ y: travelY > scale ? clamp(frame.y - (dy * scale) / travelY) : frame.y,
83
100
  };
84
101
  }
@@ -8,9 +8,9 @@ import { normalizeEmail, isValidEmail } from "./email.js";
8
8
  import { validUserPicturePreview } from "./picture.js";
9
9
  import { normalizeUsername, validateUsernameFormat } from "./username.js";
10
10
  import { userCardInput, normalizeUserCardInput, validateUserCardInput, } from "./profile.js";
11
- const msgProfileRequired = "A valid account is required to update the public profile.";
11
+ const msgProfileRequired = "A valid account is required to update the public card.";
12
12
  const msgPublicUserRequired = "A valid user is required.";
13
- const msgPublicUserMissing = "Public profile could not be resolved.";
13
+ const msgPublicUserMissing = "Public card could not be resolved.";
14
14
  const msgPictureRequired = "A valid account and profile preview are required.";
15
15
  const msgUnableToResolveUsername = "Unable to resolve username.";
16
16
  const msgPhoneRequired = "Phone number is required.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.189",
3
+ "version": "0.0.191",
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.116",
20
+ "@fabriktor/client": "0.0.117",
21
21
  "@fabriktor/fx": "0.0.94",
22
- "@fabriktor/schema": "0.0.87",
22
+ "@fabriktor/schema": "0.0.88",
23
23
  "convert": "8.0.2"
24
24
  }
25
25
  }