hevy-shared 1.0.962 → 1.0.963

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.
Files changed (88) hide show
  1. package/README.md +17 -2
  2. package/built/API/APIClient.d.ts +157 -0
  3. package/built/API/APIClient.js +381 -0
  4. package/built/API/index.d.ts +2 -0
  5. package/built/API/index.js +18 -0
  6. package/built/API/types.d.ts +38 -0
  7. package/built/API/types.js +18 -0
  8. package/built/adjustEventTokens.d.ts +16 -0
  9. package/built/adjustEventTokens.js +18 -0
  10. package/built/adminPermissions.d.ts +4 -0
  11. package/built/adminPermissions.js +22 -0
  12. package/built/async.d.ts +50 -0
  13. package/built/async.js +170 -0
  14. package/built/chat.d.ts +25 -23
  15. package/built/coachPlans.d.ts +2 -1
  16. package/built/coachPlans.js +2 -2
  17. package/built/cue.d.ts +12 -0
  18. package/built/cue.js +22 -0
  19. package/built/exerciseLocaleUtils.d.ts +17 -0
  20. package/built/exerciseLocaleUtils.js +62 -0
  21. package/built/filterExercises.d.ts +19 -3
  22. package/built/filterExercises.js +72 -60
  23. package/built/hevyTrainer.d.ts +250 -0
  24. package/built/hevyTrainer.js +676 -0
  25. package/built/index.d.ts +1140 -304
  26. package/built/index.js +269 -75
  27. package/built/muscleHeatmaps.d.ts +31 -0
  28. package/built/muscleHeatmaps.js +68 -0
  29. package/built/muscleSplits.d.ts +36 -0
  30. package/built/muscleSplits.js +100 -0
  31. package/built/normalizedWorkoutUtils.d.ts +88 -0
  32. package/built/normalizedWorkoutUtils.js +112 -0
  33. package/built/notifications.d.ts +215 -0
  34. package/built/notifications.js +9 -0
  35. package/built/routineUtils.d.ts +14 -0
  36. package/built/routineUtils.js +186 -0
  37. package/built/schemas.d.ts +14 -0
  38. package/built/schemas.js +9 -0
  39. package/built/setIndicatorUtils.d.ts +4 -3
  40. package/built/setIndicatorUtils.js +15 -1
  41. package/built/tests/async.test.d.ts +1 -0
  42. package/built/tests/async.test.js +49 -0
  43. package/built/tests/hevyTrainer.test.d.ts +1 -0
  44. package/built/tests/hevyTrainer.test.js +1199 -0
  45. package/built/tests/muscleSplit.test.d.ts +1 -0
  46. package/built/tests/muscleSplit.test.js +153 -0
  47. package/built/tests/routineUtils.test.d.ts +1 -0
  48. package/built/tests/routineUtils.test.js +745 -0
  49. package/built/tests/testUtils.d.ts +85 -0
  50. package/built/tests/testUtils.js +319 -0
  51. package/built/tests/utils.test.js +748 -0
  52. package/built/tests/workoutVolume.test.js +165 -49
  53. package/built/translations/index.d.ts +2 -0
  54. package/built/translations/index.js +18 -0
  55. package/built/translations/translationUtils.d.ts +2 -0
  56. package/built/translations/translationUtils.js +61 -0
  57. package/built/translations/types.d.ts +8 -0
  58. package/built/translations/types.js +20 -0
  59. package/built/typeUtils.d.ts +70 -0
  60. package/built/typeUtils.js +55 -0
  61. package/built/units.d.ts +14 -7
  62. package/built/units.js +24 -14
  63. package/built/utils.d.ts +192 -5
  64. package/built/utils.js +598 -85
  65. package/built/websocket.d.ts +14 -2
  66. package/built/workoutVolume.d.ts +24 -5
  67. package/built/workoutVolume.js +25 -34
  68. package/package.json +32 -10
  69. package/.eslintignore +0 -2
  70. package/.eslintrc +0 -21
  71. package/.github/workflows/ci.yml +0 -15
  72. package/.github/workflows/npm-publish.yml +0 -59
  73. package/.github/workflows/pr-auto-assign.yml +0 -15
  74. package/.prettierrc.js +0 -5
  75. package/jest.config.js +0 -4
  76. package/src/chat.ts +0 -130
  77. package/src/coachPlans.ts +0 -57
  78. package/src/constants.ts +0 -14
  79. package/src/filterExercises.ts +0 -222
  80. package/src/index.ts +0 -1576
  81. package/src/setIndicatorUtils.ts +0 -137
  82. package/src/tests/utils.test.ts +0 -156
  83. package/src/tests/workoutVolume.test.ts +0 -93
  84. package/src/units.ts +0 -41
  85. package/src/utils.ts +0 -516
  86. package/src/websocket.ts +0 -36
  87. package/src/workoutVolume.ts +0 -175
  88. package/tsconfig.json +0 -70
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ADJUST_EVENT_TOKENS = void 0;
4
+ /**
5
+ * Manage adjust events at https://suite.adjust.com/apps/na3q7q6avq4g/events
6
+ */
7
+ exports.ADJUST_EVENT_TOKENS = {
8
+ logWorkout: 'e3xe9l',
9
+ purchase: 'qf1l8r',
10
+ signupComplete: 'n46d1z',
11
+ renewal: 'i5pcdz',
12
+ updateSexMale: 'kbdp5b',
13
+ updateSexFemale: 'jkkjka',
14
+ updateSexOther: 'z4awr3',
15
+ updateAge18Through28: 'o5f1gc',
16
+ updateAge29Through44: 'vvhb17',
17
+ updateAge45AndUp: '3meyo6',
18
+ };
@@ -0,0 +1,4 @@
1
+ import { Lookup } from './typeUtils';
2
+ export declare const AdminPermissions: readonly ["become_user", "blacklists", "featured_users", "feature_flags", "hevy_trainer", "user_account_management", "import_strong_csv", "community_management", "user_app_logs", "backend_maintenance"];
3
+ export type AdminPermission = Lookup<typeof AdminPermissions>;
4
+ export declare const isAdminPermission: (permission?: any) => permission is AdminPermission;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAdminPermission = exports.AdminPermissions = void 0;
4
+ exports.AdminPermissions = [
5
+ 'become_user',
6
+ 'blacklists',
7
+ 'featured_users',
8
+ 'feature_flags',
9
+ 'hevy_trainer',
10
+ 'user_account_management',
11
+ 'import_strong_csv',
12
+ 'community_management',
13
+ 'user_app_logs',
14
+ 'backend_maintenance',
15
+ ];
16
+ const isAdminPermission = (permission) => {
17
+ if (!permission || typeof permission !== 'string') {
18
+ return false;
19
+ }
20
+ return exports.AdminPermissions.includes(permission);
21
+ };
22
+ exports.isAdminPermission = isAdminPermission;
@@ -0,0 +1,50 @@
1
+ export type Result<T, E = unknown> = {
2
+ isSuccess: true;
3
+ value: T;
4
+ } | {
5
+ isSuccess: false;
6
+ error: E;
7
+ };
8
+ /**
9
+ * The difference between this and `Promise.all` is that `Promise.all` rejects
10
+ * when any promise rejects, and this resolves when all promises resolve _or_
11
+ * reject.
12
+ *
13
+ * This function returns an array of results, each of which is either a success
14
+ * result containing the resolved promise, or an error result containing the
15
+ * value that was passed to `reject()`.
16
+ *
17
+ * This function itself never throws or rejects.
18
+ */
19
+ export declare const allToResolveOrReject: <T>(promises: Promise<T>[]) => Promise<Result<T>[]>;
20
+ /**
21
+ * Attach a dummy rejection handler to a promise and return the original
22
+ * promise. Used to prevent unhandled rejections in the background.
23
+ *
24
+ * To use this, wrap any `async` or `Promise`-returning function with this
25
+ * function and use it as you otherwise would.
26
+ *
27
+ * Calling this multiple times for the same promise should have no ill effect.
28
+ *
29
+ * @example
30
+ * // Before
31
+ * await fetch('https://hevy.com/blabla');
32
+ *
33
+ * // After
34
+ * await handleRejection(fetch('https://hevy.com/blabla'));
35
+ */
36
+ export declare const handleRejection: <T>(p: Promise<T>) => Promise<T>;
37
+ type Stage3MethodDecorator<T> = (value: (...args: any[]) => T, context: ClassMemberDecoratorContext) => (...args: any[]) => T;
38
+ export declare function _synchronized_3(queue: boolean): Stage3MethodDecorator<Promise<any>>;
39
+ export declare function _synchronized_3(queue: boolean, id: any): Stage3MethodDecorator<Promise<any>>;
40
+ export declare function _synchronized_3(value: (...args: any[]) => any, context: ClassMemberDecoratorContext): void;
41
+ type LegacyMethodDecorator<T> = (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => T>) => void;
42
+ export declare function synchronized(queue: boolean): LegacyMethodDecorator<Promise<any>>;
43
+ export declare function synchronized(queue: boolean, id: any): LegacyMethodDecorator<Promise<any>>;
44
+ export declare function synchronized(target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>): void;
45
+ export declare abstract class LockError extends Error {
46
+ abstract readonly propertyKey: string | symbol;
47
+ abstract readonly lockId: unknown;
48
+ protected constructor(...args: any);
49
+ }
50
+ export {};
package/built/async.js ADDED
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LockError = exports.handleRejection = exports.allToResolveOrReject = void 0;
13
+ exports._synchronized_3 = _synchronized_3;
14
+ exports.synchronized = synchronized;
15
+ /**
16
+ * The difference between this and `Promise.all` is that `Promise.all` rejects
17
+ * when any promise rejects, and this resolves when all promises resolve _or_
18
+ * reject.
19
+ *
20
+ * This function returns an array of results, each of which is either a success
21
+ * result containing the resolved promise, or an error result containing the
22
+ * value that was passed to `reject()`.
23
+ *
24
+ * This function itself never throws or rejects.
25
+ */
26
+ const allToResolveOrReject = (promises) => __awaiter(void 0, void 0, void 0, function* () {
27
+ // Attach a dummy rejection handler to each promise as soon as possible, to
28
+ // try to prevent them from rejecting in the background without a handler, as
29
+ // that can cause issues, depending on the runtime environment.
30
+ //
31
+ promises.forEach(exports.handleRejection); // try to comment this out & run the tests
32
+ const results = [];
33
+ for (const promise of promises) {
34
+ try {
35
+ const value = yield promise;
36
+ results.push({ isSuccess: true, value });
37
+ }
38
+ catch (error) {
39
+ results.push({ isSuccess: false, error });
40
+ }
41
+ }
42
+ return results;
43
+ });
44
+ exports.allToResolveOrReject = allToResolveOrReject;
45
+ /**
46
+ * Attach a dummy rejection handler to a promise and return the original
47
+ * promise. Used to prevent unhandled rejections in the background.
48
+ *
49
+ * To use this, wrap any `async` or `Promise`-returning function with this
50
+ * function and use it as you otherwise would.
51
+ *
52
+ * Calling this multiple times for the same promise should have no ill effect.
53
+ *
54
+ * @example
55
+ * // Before
56
+ * await fetch('https://hevy.com/blabla');
57
+ *
58
+ * // After
59
+ * await handleRejection(fetch('https://hevy.com/blabla'));
60
+ */
61
+ const handleRejection = (p) => (p.catch(() => { }), p);
62
+ exports.handleRejection = handleRejection;
63
+ /**
64
+ * Do not use this directly. Use the alias provided by the parent project.
65
+ */
66
+ function _synchronized_3(arg0, arg1) {
67
+ if (typeof arg1 === 'object' &&
68
+ arg1 !== null &&
69
+ 'name' in arg1 &&
70
+ 'access' in arg1) {
71
+ return synchronizedStage3DecoratorFactory(arg0, arg1, true);
72
+ }
73
+ else {
74
+ return function (value, context) {
75
+ return synchronizedStage3DecoratorFactory(value, context, arg0, arg1);
76
+ };
77
+ }
78
+ }
79
+ function synchronized(arg0, arg1, arg2) {
80
+ if (arguments.length === 1) {
81
+ return function (target, propertyKey, descriptor) {
82
+ return synchronizedLegacyDecoratorFactory(target, propertyKey, descriptor, arg0);
83
+ };
84
+ }
85
+ else if (arguments.length === 2) {
86
+ return function (target, propertyKey, descriptor) {
87
+ return synchronizedLegacyDecoratorFactory(target, propertyKey, descriptor, arg0, arg1);
88
+ };
89
+ }
90
+ else {
91
+ return synchronizedLegacyDecoratorFactory(arg0, arg1, arg2, true);
92
+ }
93
+ }
94
+ const $queue = Symbol();
95
+ class LockError extends Error {
96
+ constructor(...args) {
97
+ super(...args);
98
+ }
99
+ }
100
+ exports.LockError = LockError;
101
+ class $LockError extends LockError {
102
+ constructor({ message: baseMessage, propertyKey, lockId, }) {
103
+ const formattedLockId = lockId !== undefined ? `"${String(lockId)}"` : '(anonymous)';
104
+ const message = `Cannot invoke "${String(propertyKey)}" (locked by ${formattedLockId}): ${baseMessage}`;
105
+ super(message);
106
+ this.name = 'LockError';
107
+ this.message = message;
108
+ this.propertyKey = propertyKey;
109
+ this.lockId = lockId;
110
+ }
111
+ }
112
+ function synchronizedStage3DecoratorFactory(origFn, context, wait, id) {
113
+ const lockId = arguments.length === 4 ? id : Symbol();
114
+ const propertyKey = context.name;
115
+ return synchronizedDecoratorFactory({
116
+ id,
117
+ lockId,
118
+ origFn,
119
+ propertyKey,
120
+ wait,
121
+ });
122
+ }
123
+ function synchronizedLegacyDecoratorFactory(_target, propertyKey, descriptor, wait, id) {
124
+ const origFn = descriptor.value;
125
+ const lockId = arguments.length === 5 ? id : Symbol();
126
+ descriptor.value = synchronizedDecoratorFactory({
127
+ id,
128
+ lockId,
129
+ origFn,
130
+ propertyKey,
131
+ wait,
132
+ });
133
+ }
134
+ function synchronizedDecoratorFactory({ id, lockId, origFn, propertyKey, wait, }) {
135
+ return function (...args) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ var _a, _b;
138
+ var _c;
139
+ const queue = ((_b = (_c = ((_a = this[$queue]) !== null && _a !== void 0 ? _a : (this[$queue] = {})))[lockId]) !== null && _b !== void 0 ? _b : (_c[lockId] = []));
140
+ if (queue.length > 0 && !wait) {
141
+ throw new $LockError({
142
+ message: 'Operation is already in progress',
143
+ propertyKey,
144
+ lockId: id,
145
+ });
146
+ }
147
+ let done;
148
+ const thisCall = new Promise((resolve) => {
149
+ done = resolve;
150
+ });
151
+ const waiting = [...queue];
152
+ queue.push(thisCall);
153
+ yield (0, exports.allToResolveOrReject)(waiting);
154
+ try {
155
+ return yield origFn.apply(this, args);
156
+ }
157
+ finally {
158
+ done();
159
+ if (queue.shift() !== thisCall) {
160
+ // eslint-disable-next-line no-unsafe-finally
161
+ throw new $LockError({
162
+ message: 'Assertion failed: @synchronized queue is mangled',
163
+ propertyKey,
164
+ lockId: id,
165
+ });
166
+ }
167
+ }
168
+ });
169
+ };
170
+ }
package/built/chat.d.ts CHANGED
@@ -6,7 +6,15 @@ export interface PostCreateConversationResponse {
6
6
  }
7
7
  export interface PostMessageRequest {
8
8
  conversation_id: string;
9
- data: CreateTextMessageData | CreateNewWorkoutMessageData | CreateNewBodyMeasurementMesageData;
9
+ data: CreateTextMessageData | CreateVideoMessageData | CreateImageMessageData;
10
+ }
11
+ export interface PostGetDeletedMessagesRequest {
12
+ messages_deleted_since_time?: string;
13
+ conversation_id: string;
14
+ }
15
+ export interface PostDeletedMessagesResponse {
16
+ deleted_message_ids: string[];
17
+ checked_at_time: string;
10
18
  }
11
19
  export interface PostMessageResponse {
12
20
  message_id: string;
@@ -15,13 +23,13 @@ export interface CreateTextMessageData {
15
23
  type: 'text';
16
24
  text: string;
17
25
  }
18
- export interface CreateNewWorkoutMessageData {
19
- type: 'new-workout';
20
- workout_id: string;
26
+ export interface CreateVideoMessageData {
27
+ type: 'video';
28
+ video_url: string;
21
29
  }
22
- export interface CreateNewBodyMeasurementMesageData {
23
- type: 'new-body-measurement';
24
- measurement_id: number;
30
+ export interface CreateImageMessageData {
31
+ type: 'image';
32
+ image_url: string;
25
33
  }
26
34
  export interface GetLatestMessageFromAllClientsResponse {
27
35
  conversations: {
@@ -48,7 +56,7 @@ export interface Conversation {
48
56
  conversation_id: string;
49
57
  user_ids: string[];
50
58
  }
51
- export type MessageType = 'text' | 'new-workout' | 'new-body-measurement';
59
+ export type MessageType = 'text' | 'video' | 'image';
52
60
  export interface MessageBase {
53
61
  id: string;
54
62
  sender_user_id: string;
@@ -60,21 +68,15 @@ export interface TextMessage extends MessageBase {
60
68
  type: 'text';
61
69
  text: string;
62
70
  }
63
- export interface NewWorkoutMessageData {
64
- workout_id: string;
65
- }
66
- export interface NewWorkoutMessage extends MessageBase {
67
- type: 'new-workout';
68
- data: NewWorkoutMessageData;
69
- }
70
- export interface NewBodyMeasurementMessageData {
71
- measurement_id: number;
71
+ export interface VideoMessage extends MessageBase {
72
+ type: 'video';
73
+ video_url: string;
72
74
  }
73
- export interface NewBodyMeasurementMessage extends MessageBase {
74
- type: 'new-body-measurement';
75
- data: NewBodyMeasurementMessageData;
75
+ export interface ImageMessage extends MessageBase {
76
+ type: 'image';
77
+ image_url: string;
76
78
  }
77
- export type Message = TextMessage | NewWorkoutMessage | NewBodyMeasurementMessage;
79
+ export type Message = TextMessage | VideoMessage | ImageMessage;
78
80
  export declare const isMessage: (message?: any) => message is Message;
79
81
  export interface NewMessageChatUpdate {
80
82
  type: 'new-message';
@@ -89,5 +91,5 @@ export interface NewConversationChatUpdate {
89
91
  conversation_id: string;
90
92
  conversation_users: string[];
91
93
  }
92
- export type HevyChatUpdatePush = NewMessageChatUpdate | MessageDeletedChatUpdate | NewConversationChatUpdate;
93
- export declare const isHevyChatUpdatePush: (message?: any) => message is HevyChatUpdatePush;
94
+ export type HevyChatUpdateMobilePushData = NewMessageChatUpdate | MessageDeletedChatUpdate | NewConversationChatUpdate;
95
+ export declare const isHevyChatUpdatePush: (message?: any) => message is HevyChatUpdateMobilePushData;
@@ -1,10 +1,11 @@
1
1
  export declare const HevyCoachDefaultPlan: Plan;
2
- export type PlanType = 'default' | 'paid_paddle' | 'trial' | 'beta';
2
+ export type PlanType = 'none' | 'paid_paddle' | 'trial' | 'beta';
3
3
  export interface Plan {
4
4
  title: string;
5
5
  maximum_clients: number;
6
6
  id: string;
7
7
  paddle_update_payment_url?: string;
8
+ paddle_subscription_id?: number;
8
9
  renewal_period: 'monthly' | 'lifetime';
9
10
  renewal_price?: string;
10
11
  renewal_currency?: string;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HevyCoachDefaultPlan = void 0;
4
4
  exports.HevyCoachDefaultPlan = {
5
- maximum_clients: 3,
5
+ maximum_clients: 0,
6
6
  id: 'hevy_coach_free',
7
7
  title: 'Free',
8
8
  renewal_period: 'lifetime',
9
- type: 'default',
9
+ type: 'none',
10
10
  };
package/built/cue.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A = control group
3
+ *
4
+ * B = test group
5
+ */
6
+ export type CueGroup = 'a' | 'b';
7
+ /**
8
+ * A = control group
9
+ *
10
+ * B = test group
11
+ */
12
+ export declare const generateCueGroup: (userId: string) => CueGroup | undefined;
package/built/cue.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCueGroup = void 0;
4
+ /**
5
+ * A = control group
6
+ *
7
+ * B = test group
8
+ */
9
+ const generateCueGroup = (userId) => {
10
+ if (typeof userId !== 'string') {
11
+ return undefined;
12
+ }
13
+ const firstCharacter = userId.charAt(0);
14
+ if (['0', '1', '2', '3', '4', '5', '6', '7'].includes(firstCharacter)) {
15
+ return 'a';
16
+ }
17
+ if (['8', '9', 'a', 'b', 'c', 'd', 'e', 'f'].includes(firstCharacter)) {
18
+ return 'b';
19
+ }
20
+ return undefined;
21
+ };
22
+ exports.generateCueGroup = generateCueGroup;
@@ -0,0 +1,17 @@
1
+ import { LibraryExercise, Lookup } from '.';
2
+ import { Language } from './translations';
3
+ /** Keeping exercise instruction/title localization utils here instead of translations
4
+ * so I don't need to import exercise types from here in translations (translations was
5
+ * created so that hevy-web can import utils from shared without importing something from
6
+ * that isn't allowed in Edge Runtime)
7
+ */
8
+ export declare const supportedInstructionsLanguages: readonly ["en", "it", "de", "es", "fr", "pt"];
9
+ export type InstructionsLanguage = Lookup<typeof supportedInstructionsLanguages>;
10
+ export declare const isSupportedInstructionsLanguage: (lang: string) => lang is InstructionsLanguage;
11
+ type LocalizableExerciseTemplate = Pick<LibraryExercise, 'title' | 'es_title' | 'de_title' | 'fr_title' | 'it_title' | 'ja_title' | 'ko_title' | 'pt_title' | 'ru_title' | 'tr_title' | 'zh_cn_title' | 'zh_tw_title' | 'localised_instructions' | 'is_custom'>;
12
+ export declare const localisedExerciseTitle: (locale: Language, template: LocalizableExerciseTemplate) => string;
13
+ export declare const localisedExerciseInstructions: (locale: Language, exerciseTemplate: LocalizableExerciseTemplate) => string;
14
+ export declare const localeSelect: <T>(locale: Language, options: {
15
+ en: T;
16
+ } & { [language in Exclude<Language, "en">]?: T | null; }) => T;
17
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.localeSelect = exports.localisedExerciseInstructions = exports.localisedExerciseTitle = exports.isSupportedInstructionsLanguage = exports.supportedInstructionsLanguages = void 0;
4
+ const _1 = require(".");
5
+ /** Keeping exercise instruction/title localization utils here instead of translations
6
+ * so I don't need to import exercise types from here in translations (translations was
7
+ * created so that hevy-web can import utils from shared without importing something from
8
+ * that isn't allowed in Edge Runtime)
9
+ */
10
+ exports.supportedInstructionsLanguages = [
11
+ 'en',
12
+ 'it',
13
+ 'de',
14
+ 'es',
15
+ 'fr',
16
+ 'pt',
17
+ ];
18
+ const isSupportedInstructionsLanguage = (lang) => {
19
+ return (0, _1.isInArray)(lang, exports.supportedInstructionsLanguages);
20
+ };
21
+ exports.isSupportedInstructionsLanguage = isSupportedInstructionsLanguage;
22
+ const localisedExerciseTitle = (locale, template) => {
23
+ var _a;
24
+ if (template.is_custom) {
25
+ return template.title;
26
+ }
27
+ return ((_a = (0, exports.localeSelect)(locale, {
28
+ en: template.title,
29
+ es: template.es_title,
30
+ de: template.de_title,
31
+ fr: template.fr_title,
32
+ it: template.it_title,
33
+ pt: template.pt_title,
34
+ tr: template.tr_title,
35
+ zh_CN: template.zh_cn_title,
36
+ zh_TW: template.zh_tw_title,
37
+ ru: template.ru_title,
38
+ ja: template.ja_title,
39
+ ko: template.ko_title,
40
+ })) !== null && _a !== void 0 ? _a : template.title);
41
+ };
42
+ exports.localisedExerciseTitle = localisedExerciseTitle;
43
+ const localisedExerciseInstructions = (locale, exerciseTemplate) => {
44
+ var _a, _b, _c, _d, _e, _f, _g;
45
+ if (exerciseTemplate.is_custom) {
46
+ return '';
47
+ }
48
+ return (0, exports.localeSelect)(locale, {
49
+ en: (_b = (_a = exerciseTemplate === null || exerciseTemplate === void 0 ? void 0 : exerciseTemplate.localised_instructions) === null || _a === void 0 ? void 0 : _a.en) !== null && _b !== void 0 ? _b : '',
50
+ pt: (_c = exerciseTemplate === null || exerciseTemplate === void 0 ? void 0 : exerciseTemplate.localised_instructions) === null || _c === void 0 ? void 0 : _c.pt,
51
+ de: (_d = exerciseTemplate === null || exerciseTemplate === void 0 ? void 0 : exerciseTemplate.localised_instructions) === null || _d === void 0 ? void 0 : _d.de,
52
+ es: (_e = exerciseTemplate === null || exerciseTemplate === void 0 ? void 0 : exerciseTemplate.localised_instructions) === null || _e === void 0 ? void 0 : _e.es,
53
+ it: (_f = exerciseTemplate === null || exerciseTemplate === void 0 ? void 0 : exerciseTemplate.localised_instructions) === null || _f === void 0 ? void 0 : _f.it,
54
+ fr: (_g = exerciseTemplate === null || exerciseTemplate === void 0 ? void 0 : exerciseTemplate.localised_instructions) === null || _g === void 0 ? void 0 : _g.fr,
55
+ });
56
+ };
57
+ exports.localisedExerciseInstructions = localisedExerciseInstructions;
58
+ const localeSelect = (locale, options) => {
59
+ var _a;
60
+ return (_a = options[locale]) !== null && _a !== void 0 ? _a : options.en;
61
+ };
62
+ exports.localeSelect = localeSelect;
@@ -1,7 +1,19 @@
1
- import { EquipmentFilter, ExerciseTemplate, Language, MuscleGroupFilter } from './index';
2
- export interface SearchableExerciseTemplate extends ExerciseTemplate {
1
+ import { EquipmentFilter, LibraryExercise, MuscleGroupFilter, CustomExercise } from './index';
2
+ import { Language } from './translations';
3
+ export interface SearchableLibraryExercise extends LibraryExercise {
3
4
  localized_muscle_group_name: string;
4
5
  }
6
+ export interface SearchableCustomExercise extends CustomExercise {
7
+ localized_muscle_group_name: string;
8
+ }
9
+ export type SearchableExerciseTemplate = SearchableLibraryExercise | SearchableCustomExercise;
10
+ export interface SearchableLibraryExerciseWithStringScore<T = number> extends SearchableLibraryExercise {
11
+ searchStringScore?: T;
12
+ }
13
+ export interface SearchableCustomExerciseWithStringScore<T = number> extends SearchableCustomExercise {
14
+ searchStringScore?: T;
15
+ }
16
+ export type SearchableExerciseTemplateWithStringScore<T = number> = SearchableLibraryExerciseWithStringScore<T> | SearchableCustomExerciseWithStringScore<T>;
5
17
  interface FilterExercisesProps {
6
18
  exercises: SearchableExerciseTemplate[];
7
19
  muscleGroupFilter: MuscleGroupFilter;
@@ -9,7 +21,11 @@ interface FilterExercisesProps {
9
21
  searchText: string;
10
22
  language: Language;
11
23
  }
12
- export declare const filterExercises: ({ exercises, muscleGroupFilter, equipmentType, searchText, language, }: FilterExercisesProps) => ExerciseTemplate[];
24
+ export declare const getExerciseMatches: ({ exercises, muscleGroupFilter, equipmentType, searchText, language, }: FilterExercisesProps) => ExerciseSearchMatch<SearchableExerciseTemplate>[];
25
+ export type ExerciseSearchMatch<T> = {
26
+ exercise: T;
27
+ matchType: 'title' | 'muscle_group' | 'other' | 'custom';
28
+ };
13
29
  /**
14
30
  * Exercise templates that are shown at the top of the Exercise Library to
15
31
  * users who don't have any workouts logged.