@tbs-fitness/contract 0.4.0 → 0.6.0
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/README.md +25 -0
- package/dist/cjs/auth/auth.dto.d.ts +4 -4
- package/dist/cjs/auth/index.d.ts +1 -0
- package/dist/cjs/auth/index.js +1 -0
- package/dist/cjs/auth/otp.dto.d.ts +45 -0
- package/dist/cjs/auth/otp.dto.js +39 -0
- package/dist/cjs/client/client-auth.dto.d.ts +81 -0
- package/dist/cjs/client/client-auth.dto.js +49 -0
- package/dist/cjs/client/index.d.ts +2 -0
- package/dist/cjs/client/index.js +18 -0
- package/dist/cjs/coach/coach-auth.dto.d.ts +0 -40
- package/dist/cjs/coach/coach-auth.dto.js +1 -30
- package/dist/cjs/coach/index.d.ts +1 -0
- package/dist/cjs/coach/index.js +1 -0
- package/dist/cjs/enums/index.d.ts +40 -2
- package/dist/cjs/enums/index.js +58 -3
- package/dist/cjs/feature-flags/feature-flag.dto.d.ts +4 -4
- package/dist/cjs/feature-flags/feature-flag.dto.js +1 -1
- package/dist/cjs/food/client-food.dto.d.ts +49 -0
- package/dist/cjs/food/client-food.dto.js +26 -0
- package/dist/cjs/food/food-import.dto.d.ts +160 -0
- package/dist/cjs/food/food-import.dto.js +110 -0
- package/dist/cjs/food/food-suggestion.dto.d.ts +374 -0
- package/dist/cjs/food/food-suggestion.dto.js +170 -0
- package/dist/cjs/food/food.dto.d.ts +339 -0
- package/dist/cjs/food/food.dto.js +256 -0
- package/dist/cjs/food/index.d.ts +5 -0
- package/dist/cjs/food/index.js +21 -0
- package/dist/cjs/food/nutrition.d.ts +75 -0
- package/dist/cjs/food/nutrition.js +158 -0
- package/dist/esm/auth/auth.dto.d.ts +4 -4
- package/dist/esm/auth/index.d.ts +1 -0
- package/dist/esm/auth/index.js +1 -0
- package/dist/esm/auth/otp.dto.d.ts +45 -0
- package/dist/esm/auth/otp.dto.js +36 -0
- package/dist/esm/client/client-auth.dto.d.ts +81 -0
- package/dist/esm/client/client-auth.dto.js +46 -0
- package/dist/esm/client/index.d.ts +2 -0
- package/dist/esm/client/index.js +2 -0
- package/dist/esm/coach/coach-auth.dto.d.ts +0 -40
- package/dist/esm/coach/coach-auth.dto.js +1 -30
- package/dist/esm/coach/index.d.ts +1 -0
- package/dist/esm/coach/index.js +1 -0
- package/dist/esm/enums/index.d.ts +40 -2
- package/dist/esm/enums/index.js +57 -2
- package/dist/esm/feature-flags/feature-flag.dto.d.ts +4 -4
- package/dist/esm/feature-flags/feature-flag.dto.js +1 -1
- package/dist/esm/food/client-food.dto.d.ts +49 -0
- package/dist/esm/food/client-food.dto.js +23 -0
- package/dist/esm/food/food-import.dto.d.ts +160 -0
- package/dist/esm/food/food-import.dto.js +107 -0
- package/dist/esm/food/food-suggestion.dto.d.ts +374 -0
- package/dist/esm/food/food-suggestion.dto.js +167 -0
- package/dist/esm/food/food.dto.d.ts +339 -0
- package/dist/esm/food/food.dto.js +253 -0
- package/dist/esm/food/index.d.ts +5 -0
- package/dist/esm/food/index.js +5 -0
- package/dist/esm/food/nutrition.d.ts +75 -0
- package/dist/esm/food/nutrition.js +144 -0
- package/package.json +21 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type ServingUnit } from '../enums/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Nutrition rules shared by the backend and the apps, so a value the web form
|
|
5
|
+
* accepts is a value the API accepts, and both calculate derived values the
|
|
6
|
+
* same way.
|
|
7
|
+
*
|
|
8
|
+
* Library nutrients are stored per 100 of the serving unit (per 100 g, or per
|
|
9
|
+
* 100 ml for a serving measured in ml). Per-serving values are always derived.
|
|
10
|
+
*/
|
|
11
|
+
/** The largest nutrient amount per 100 units. Pure fat is 100 g; pure fat calories are 900. */
|
|
12
|
+
export declare const MAX_NUTRIENT_PER_100 = 9999.99;
|
|
13
|
+
export declare const MAX_SERVING_QUANTITY = 10000;
|
|
14
|
+
export declare const NUTRIENT_DECIMALS = 2;
|
|
15
|
+
/** Rounds to two decimals, the precision every nutrient is stored at. */
|
|
16
|
+
export declare function roundNutrient(value: number): number;
|
|
17
|
+
export declare function hasAtMostTwoDecimals(value: number): boolean;
|
|
18
|
+
/** A non-negative amount with at most two decimals. */
|
|
19
|
+
export declare const nutrientAmountSchema: (max?: number) => z.ZodNumber;
|
|
20
|
+
/** A positive quantity with at most two decimals, such as 200 (g) or 1.5 (bowls). */
|
|
21
|
+
export declare const quantitySchema: (max?: number) => z.ZodNumber;
|
|
22
|
+
/** The nutrients a library food records. Calories and the three macros are required. */
|
|
23
|
+
export interface NutrientValues {
|
|
24
|
+
calories: number;
|
|
25
|
+
protein: number;
|
|
26
|
+
carbs: number;
|
|
27
|
+
fat: number;
|
|
28
|
+
sugar?: number | null;
|
|
29
|
+
fiber?: number | null;
|
|
30
|
+
solubleFiber?: number | null;
|
|
31
|
+
insolubleFiber?: number | null;
|
|
32
|
+
}
|
|
33
|
+
/** The same values with every optional nutrient present, `null` when unknown. */
|
|
34
|
+
export interface CompleteNutrientValues {
|
|
35
|
+
calories: number;
|
|
36
|
+
protein: number;
|
|
37
|
+
carbs: number;
|
|
38
|
+
fat: number;
|
|
39
|
+
sugar: number | null;
|
|
40
|
+
fiber: number | null;
|
|
41
|
+
solubleFiber: number | null;
|
|
42
|
+
insolubleFiber: number | null;
|
|
43
|
+
}
|
|
44
|
+
/** Converts values for one serving of `servingQuantity` units into values per 100 units. */
|
|
45
|
+
export declare function toPer100(perServing: NutrientValues, servingQuantity: number): CompleteNutrientValues;
|
|
46
|
+
/** Converts values per 100 units into values for one serving of `servingQuantity` units. */
|
|
47
|
+
export declare function perServing(per100: NutrientValues, servingQuantity: number): CompleteNutrientValues;
|
|
48
|
+
/** Calories from the macros, using Biki's formula: (protein + carbs) × 4 + fat × 9. */
|
|
49
|
+
export declare function formulaCalories(protein: number, carbs: number, fat: number): number;
|
|
50
|
+
export interface NutritionIssue {
|
|
51
|
+
path: string;
|
|
52
|
+
message: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The checks that hold for any food's values per 100 units: the macros cannot
|
|
56
|
+
* weigh more than the food, and sugar, fibre and its parts cannot exceed what
|
|
57
|
+
* contains them. The database enforces the same rules.
|
|
58
|
+
*/
|
|
59
|
+
export declare function nutritionIssues(per100: NutrientValues): NutritionIssue[];
|
|
60
|
+
/**
|
|
61
|
+
* The form of a food name used to find duplicates: case, accents of width,
|
|
62
|
+
* punctuation and spacing are ignored, so "Paneer (Full-Fat)" and
|
|
63
|
+
* "paneer full fat" match. Letters in any script are kept.
|
|
64
|
+
*/
|
|
65
|
+
export declare function normalizeFoodName(name: string): string;
|
|
66
|
+
/** The stable key for a metadata value label: "High Protein" becomes "high-protein". */
|
|
67
|
+
export declare function slugifyMetadataKey(label: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Reads the weight or volume from a serving label such as "1 cup (200g)" or
|
|
70
|
+
* "1 glass (250ml)". Returns null when the label states neither.
|
|
71
|
+
*/
|
|
72
|
+
export declare function parseServingLabel(label: string): {
|
|
73
|
+
quantity: number;
|
|
74
|
+
unit: ServingUnit;
|
|
75
|
+
} | null;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quantitySchema = exports.nutrientAmountSchema = exports.NUTRIENT_DECIMALS = exports.MAX_SERVING_QUANTITY = exports.MAX_NUTRIENT_PER_100 = void 0;
|
|
4
|
+
exports.roundNutrient = roundNutrient;
|
|
5
|
+
exports.hasAtMostTwoDecimals = hasAtMostTwoDecimals;
|
|
6
|
+
exports.toPer100 = toPer100;
|
|
7
|
+
exports.perServing = perServing;
|
|
8
|
+
exports.formulaCalories = formulaCalories;
|
|
9
|
+
exports.nutritionIssues = nutritionIssues;
|
|
10
|
+
exports.normalizeFoodName = normalizeFoodName;
|
|
11
|
+
exports.slugifyMetadataKey = slugifyMetadataKey;
|
|
12
|
+
exports.parseServingLabel = parseServingLabel;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const index_js_1 = require("../enums/index.js");
|
|
15
|
+
/**
|
|
16
|
+
* Nutrition rules shared by the backend and the apps, so a value the web form
|
|
17
|
+
* accepts is a value the API accepts, and both calculate derived values the
|
|
18
|
+
* same way.
|
|
19
|
+
*
|
|
20
|
+
* Library nutrients are stored per 100 of the serving unit (per 100 g, or per
|
|
21
|
+
* 100 ml for a serving measured in ml). Per-serving values are always derived.
|
|
22
|
+
*/
|
|
23
|
+
/** The largest nutrient amount per 100 units. Pure fat is 100 g; pure fat calories are 900. */
|
|
24
|
+
exports.MAX_NUTRIENT_PER_100 = 9999.99;
|
|
25
|
+
exports.MAX_SERVING_QUANTITY = 10000;
|
|
26
|
+
exports.NUTRIENT_DECIMALS = 2;
|
|
27
|
+
const SCALE = 10 ** exports.NUTRIENT_DECIMALS;
|
|
28
|
+
const DECIMAL_TOLERANCE = 1e-6;
|
|
29
|
+
/** Rounds to two decimals, the precision every nutrient is stored at. */
|
|
30
|
+
function roundNutrient(value) {
|
|
31
|
+
return Math.round((value + Number.EPSILON) * SCALE) / SCALE;
|
|
32
|
+
}
|
|
33
|
+
function hasAtMostTwoDecimals(value) {
|
|
34
|
+
const scaled = value * SCALE;
|
|
35
|
+
return Math.abs(scaled - Math.round(scaled)) < DECIMAL_TOLERANCE;
|
|
36
|
+
}
|
|
37
|
+
const TWO_DECIMALS_ERROR = { error: 'Use at most 2 decimal places' };
|
|
38
|
+
/** A non-negative amount with at most two decimals. */
|
|
39
|
+
const nutrientAmountSchema = (max = exports.MAX_NUTRIENT_PER_100) => zod_1.z.number().min(0).max(max).refine(hasAtMostTwoDecimals, TWO_DECIMALS_ERROR);
|
|
40
|
+
exports.nutrientAmountSchema = nutrientAmountSchema;
|
|
41
|
+
/** A positive quantity with at most two decimals, such as 200 (g) or 1.5 (bowls). */
|
|
42
|
+
const quantitySchema = (max = exports.MAX_SERVING_QUANTITY) => zod_1.z.number().gt(0).max(max).refine(hasAtMostTwoDecimals, TWO_DECIMALS_ERROR);
|
|
43
|
+
exports.quantitySchema = quantitySchema;
|
|
44
|
+
function scale(values, factor) {
|
|
45
|
+
const optional = (value) => value === null || value === undefined
|
|
46
|
+
? null
|
|
47
|
+
: roundNutrient(value * factor);
|
|
48
|
+
return {
|
|
49
|
+
calories: roundNutrient(values.calories * factor),
|
|
50
|
+
protein: roundNutrient(values.protein * factor),
|
|
51
|
+
carbs: roundNutrient(values.carbs * factor),
|
|
52
|
+
fat: roundNutrient(values.fat * factor),
|
|
53
|
+
sugar: optional(values.sugar),
|
|
54
|
+
fiber: optional(values.fiber),
|
|
55
|
+
solubleFiber: optional(values.solubleFiber),
|
|
56
|
+
insolubleFiber: optional(values.insolubleFiber),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Converts values for one serving of `servingQuantity` units into values per 100 units. */
|
|
60
|
+
function toPer100(perServing, servingQuantity) {
|
|
61
|
+
return scale(perServing, 100 / servingQuantity);
|
|
62
|
+
}
|
|
63
|
+
/** Converts values per 100 units into values for one serving of `servingQuantity` units. */
|
|
64
|
+
function perServing(per100, servingQuantity) {
|
|
65
|
+
return scale(per100, servingQuantity / 100);
|
|
66
|
+
}
|
|
67
|
+
/** Calories from the macros, using Biki's formula: (protein + carbs) × 4 + fat × 9. */
|
|
68
|
+
function formulaCalories(protein, carbs, fat) {
|
|
69
|
+
return roundNutrient((protein + carbs) * 4 + fat * 9);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The checks that hold for any food's values per 100 units: the macros cannot
|
|
73
|
+
* weigh more than the food, and sugar, fibre and its parts cannot exceed what
|
|
74
|
+
* contains them. The database enforces the same rules.
|
|
75
|
+
*/
|
|
76
|
+
function nutritionIssues(per100) {
|
|
77
|
+
const issues = [];
|
|
78
|
+
if (per100.protein + per100.carbs + per100.fat > 100 + DECIMAL_TOLERANCE) {
|
|
79
|
+
issues.push({
|
|
80
|
+
path: 'fat',
|
|
81
|
+
message: 'Protein, carbs and fat together cannot exceed 100 per 100',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if ((per100.sugar ?? 0) > per100.carbs + DECIMAL_TOLERANCE) {
|
|
85
|
+
issues.push({ path: 'sugar', message: 'Sugar cannot exceed carbs' });
|
|
86
|
+
}
|
|
87
|
+
if ((per100.fiber ?? 0) > per100.carbs + DECIMAL_TOLERANCE) {
|
|
88
|
+
issues.push({ path: 'fiber', message: 'Fibre cannot exceed carbs' });
|
|
89
|
+
}
|
|
90
|
+
const fiberParts = (per100.solubleFiber ?? 0) + (per100.insolubleFiber ?? 0);
|
|
91
|
+
const hasParts = isPresent(per100.solubleFiber) || isPresent(per100.insolubleFiber);
|
|
92
|
+
if (hasParts && !isPresent(per100.fiber)) {
|
|
93
|
+
issues.push({
|
|
94
|
+
path: 'fiber',
|
|
95
|
+
message: 'Enter total fibre when entering soluble or insoluble fibre',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else if (fiberParts > (per100.fiber ?? 0) + DECIMAL_TOLERANCE) {
|
|
99
|
+
issues.push({
|
|
100
|
+
path: 'insolubleFiber',
|
|
101
|
+
message: 'Soluble and insoluble fibre together cannot exceed total fibre',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return issues;
|
|
105
|
+
}
|
|
106
|
+
function isPresent(value) {
|
|
107
|
+
return value !== null && value !== undefined;
|
|
108
|
+
}
|
|
109
|
+
const NON_NAME_CHARACTERS = /[^\p{L}\p{M}\p{N}]+/gu;
|
|
110
|
+
/**
|
|
111
|
+
* The form of a food name used to find duplicates: case, accents of width,
|
|
112
|
+
* punctuation and spacing are ignored, so "Paneer (Full-Fat)" and
|
|
113
|
+
* "paneer full fat" match. Letters in any script are kept.
|
|
114
|
+
*/
|
|
115
|
+
function normalizeFoodName(name) {
|
|
116
|
+
return name
|
|
117
|
+
.normalize('NFKC')
|
|
118
|
+
.toLowerCase()
|
|
119
|
+
.replace(NON_NAME_CHARACTERS, ' ')
|
|
120
|
+
.trim();
|
|
121
|
+
}
|
|
122
|
+
const METADATA_KEY_CHARACTERS = /[^a-z0-9]+/g;
|
|
123
|
+
const EDGE_HYPHENS = /^-+|-+$/g;
|
|
124
|
+
/** The stable key for a metadata value label: "High Protein" becomes "high-protein". */
|
|
125
|
+
function slugifyMetadataKey(label) {
|
|
126
|
+
return label
|
|
127
|
+
.normalize('NFKD')
|
|
128
|
+
.toLowerCase()
|
|
129
|
+
.replace(METADATA_KEY_CHARACTERS, '-')
|
|
130
|
+
.replace(EDGE_HYPHENS, '');
|
|
131
|
+
}
|
|
132
|
+
// A serving label usually puts the weight in brackets after a household
|
|
133
|
+
// measure, "1 cup sliced (100g)", and may mention other amounts outside them,
|
|
134
|
+
// "1 scoop (33g) in 200ml water". An amount in brackets wins; otherwise the
|
|
135
|
+
// first amount in the label.
|
|
136
|
+
const SERVING_AMOUNT = /(\d+(?:[.,]\d+)?)\s*(g|ml)\b/i;
|
|
137
|
+
const BRACKETED = /\(([^)]*)\)/g;
|
|
138
|
+
/**
|
|
139
|
+
* Reads the weight or volume from a serving label such as "1 cup (200g)" or
|
|
140
|
+
* "1 glass (250ml)". Returns null when the label states neither.
|
|
141
|
+
*/
|
|
142
|
+
function parseServingLabel(label) {
|
|
143
|
+
const bracketed = [...label.matchAll(BRACKETED)]
|
|
144
|
+
.map((group) => SERVING_AMOUNT.exec(group[1] ?? ''))
|
|
145
|
+
.find((match) => match !== null);
|
|
146
|
+
const [, amount, unitText] = bracketed ?? SERVING_AMOUNT.exec(label) ?? [];
|
|
147
|
+
if (amount === undefined || unitText === undefined) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
const quantity = Number(amount.replace(',', '.'));
|
|
151
|
+
const unit = unitText.toLowerCase();
|
|
152
|
+
if (!Number.isFinite(quantity) ||
|
|
153
|
+
quantity <= 0 ||
|
|
154
|
+
!index_js_1.SERVING_UNITS.includes(unit)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return { quantity: roundNutrient(quantity), unit };
|
|
158
|
+
}
|
|
@@ -45,7 +45,7 @@ export declare const setRoleSchema: z.ZodObject<{
|
|
|
45
45
|
role: z.ZodEnum<{
|
|
46
46
|
ADMIN: "ADMIN";
|
|
47
47
|
COACH: "COACH";
|
|
48
|
-
|
|
48
|
+
CLIENT: "CLIENT";
|
|
49
49
|
}>;
|
|
50
50
|
}, z.core.$strict>;
|
|
51
51
|
export type SetRoleInput = z.input<typeof setRoleSchema>;
|
|
@@ -100,7 +100,7 @@ export declare const accountResponseSchema: z.ZodObject<{
|
|
|
100
100
|
role: z.ZodEnum<{
|
|
101
101
|
ADMIN: "ADMIN";
|
|
102
102
|
COACH: "COACH";
|
|
103
|
-
|
|
103
|
+
CLIENT: "CLIENT";
|
|
104
104
|
}>;
|
|
105
105
|
roles: z.ZodArray<z.ZodString>;
|
|
106
106
|
permissions: z.ZodArray<z.ZodString>;
|
|
@@ -125,7 +125,7 @@ export declare const loginResponseSchema: z.ZodObject<{
|
|
|
125
125
|
role: z.ZodEnum<{
|
|
126
126
|
ADMIN: "ADMIN";
|
|
127
127
|
COACH: "COACH";
|
|
128
|
-
|
|
128
|
+
CLIENT: "CLIENT";
|
|
129
129
|
}>;
|
|
130
130
|
roles: z.ZodArray<z.ZodString>;
|
|
131
131
|
permissions: z.ZodArray<z.ZodString>;
|
|
@@ -162,7 +162,7 @@ export declare const adminAccountResponseSchema: z.ZodObject<{
|
|
|
162
162
|
role: z.ZodEnum<{
|
|
163
163
|
ADMIN: "ADMIN";
|
|
164
164
|
COACH: "COACH";
|
|
165
|
-
|
|
165
|
+
CLIENT: "CLIENT";
|
|
166
166
|
}>;
|
|
167
167
|
status: z.ZodEnum<{
|
|
168
168
|
pending_verification: "pending_verification";
|
package/dist/esm/auth/index.d.ts
CHANGED
package/dist/esm/auth/index.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* One-time code and password recovery shapes shared by every role's sign-up
|
|
4
|
+
* and recovery routes. `/coach` and `/client` re-export them.
|
|
5
|
+
*/
|
|
6
|
+
/** Used by both resend endpoints and by forgot-password. */
|
|
7
|
+
export declare const otpEmailSchema: z.ZodObject<{
|
|
8
|
+
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export type OtpEmailInput = z.input<typeof otpEmailSchema>;
|
|
11
|
+
export type OtpEmailBody = z.output<typeof otpEmailSchema>;
|
|
12
|
+
export declare const verifyOtpSchema: z.ZodObject<{
|
|
13
|
+
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
14
|
+
code: z.ZodString;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
export type VerifyOtpInput = z.input<typeof verifyOtpSchema>;
|
|
17
|
+
export type VerifyOtpBody = z.output<typeof verifyOtpSchema>;
|
|
18
|
+
export declare const resetPasswordSchema: z.ZodObject<{
|
|
19
|
+
resetToken: z.ZodString;
|
|
20
|
+
newPassword: z.ZodString;
|
|
21
|
+
}, z.core.$strict>;
|
|
22
|
+
export type ResetPasswordInput = z.input<typeof resetPasswordSchema>;
|
|
23
|
+
export type ResetPasswordBody = z.output<typeof resetPasswordSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* Says what the client needs to drive the code screen, and nothing about
|
|
26
|
+
* whether the email belongs to an account: the same values are returned either
|
|
27
|
+
* way.
|
|
28
|
+
*/
|
|
29
|
+
export declare const otpDispatchResponseSchema: z.ZodObject<{
|
|
30
|
+
message: z.ZodString;
|
|
31
|
+
otpLength: z.ZodNumber;
|
|
32
|
+
expiresInSeconds: z.ZodNumber;
|
|
33
|
+
resendAvailableInSeconds: z.ZodNumber;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
export type OtpDispatchResponse = z.output<typeof otpDispatchResponseSchema>;
|
|
36
|
+
export declare const signupVerifiedResponseSchema: z.ZodObject<{
|
|
37
|
+
message: z.ZodString;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export type SignupVerifiedResponse = z.output<typeof signupVerifiedResponseSchema>;
|
|
40
|
+
/** Issued only after a recovery code is verified. It can reset a password once. */
|
|
41
|
+
export declare const resetTokenResponseSchema: z.ZodObject<{
|
|
42
|
+
resetToken: z.ZodString;
|
|
43
|
+
expiresInSeconds: z.ZodNumber;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
export type ResetTokenResponse = z.output<typeof resetTokenResponseSchema>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { emailSchema } from '../common/contact.schema.js';
|
|
3
|
+
import { newPasswordSchema, opaqueTokenSchema, otpCodeSchema, } from './auth.dto.js';
|
|
4
|
+
/**
|
|
5
|
+
* One-time code and password recovery shapes shared by every role's sign-up
|
|
6
|
+
* and recovery routes. `/coach` and `/client` re-export them.
|
|
7
|
+
*/
|
|
8
|
+
/** Used by both resend endpoints and by forgot-password. */
|
|
9
|
+
export const otpEmailSchema = z.strictObject({ email: emailSchema });
|
|
10
|
+
export const verifyOtpSchema = z.strictObject({
|
|
11
|
+
email: emailSchema,
|
|
12
|
+
code: otpCodeSchema,
|
|
13
|
+
});
|
|
14
|
+
export const resetPasswordSchema = z.strictObject({
|
|
15
|
+
resetToken: opaqueTokenSchema,
|
|
16
|
+
newPassword: newPasswordSchema,
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Says what the client needs to drive the code screen, and nothing about
|
|
20
|
+
* whether the email belongs to an account: the same values are returned either
|
|
21
|
+
* way.
|
|
22
|
+
*/
|
|
23
|
+
export const otpDispatchResponseSchema = z.object({
|
|
24
|
+
message: z.string(),
|
|
25
|
+
otpLength: z.number().int(),
|
|
26
|
+
expiresInSeconds: z.number().int(),
|
|
27
|
+
resendAvailableInSeconds: z.number().int(),
|
|
28
|
+
});
|
|
29
|
+
export const signupVerifiedResponseSchema = z.object({
|
|
30
|
+
message: z.string(),
|
|
31
|
+
});
|
|
32
|
+
/** Issued only after a recovery code is verified. It can reset a password once. */
|
|
33
|
+
export const resetTokenResponseSchema = z.object({
|
|
34
|
+
resetToken: z.string(),
|
|
35
|
+
expiresInSeconds: z.number().int(),
|
|
36
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Client self sign-up: a name, an email address and a password. The account
|
|
4
|
+
* cannot sign in until the emailed code is verified.
|
|
5
|
+
*/
|
|
6
|
+
export declare const clientSignupSchema: z.ZodObject<{
|
|
7
|
+
fullName: z.ZodPipe<z.ZodString, z.ZodString>;
|
|
8
|
+
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
9
|
+
password: z.ZodString;
|
|
10
|
+
timezone: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<string | undefined, unknown>>>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type ClientSignupInput = z.input<typeof clientSignupSchema>;
|
|
13
|
+
export type ClientSignupBody = z.output<typeof clientSignupSchema>;
|
|
14
|
+
/**
|
|
15
|
+
* Clients sign in from the mobile app, so the refresh token comes back in the
|
|
16
|
+
* body by default. A browser sends `tokenTransport: "cookie"` instead, and
|
|
17
|
+
* `rememberMe: false` then makes the cookie end with the browser session.
|
|
18
|
+
*/
|
|
19
|
+
export declare const clientLoginSchema: z.ZodObject<{
|
|
20
|
+
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
21
|
+
password: z.ZodString;
|
|
22
|
+
deviceName: z.ZodOptional<z.ZodString>;
|
|
23
|
+
tokenTransport: z.ZodDefault<z.ZodEnum<{
|
|
24
|
+
body: "body";
|
|
25
|
+
cookie: "cookie";
|
|
26
|
+
}>>;
|
|
27
|
+
rememberMe: z.ZodDefault<z.ZodBoolean>;
|
|
28
|
+
timezone: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<string | undefined, unknown>>>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
export type ClientLoginInput = z.input<typeof clientLoginSchema>;
|
|
31
|
+
export type ClientLoginBody = z.output<typeof clientLoginSchema>;
|
|
32
|
+
export declare const clientProfileSchema: z.ZodObject<{
|
|
33
|
+
id: z.ZodUUID;
|
|
34
|
+
email: z.ZodString;
|
|
35
|
+
fullName: z.ZodNullable<z.ZodString>;
|
|
36
|
+
phone: z.ZodNullable<z.ZodString>;
|
|
37
|
+
role: z.ZodLiteral<"CLIENT">;
|
|
38
|
+
status: z.ZodEnum<{
|
|
39
|
+
pending_verification: "pending_verification";
|
|
40
|
+
active: "active";
|
|
41
|
+
disabled: "disabled";
|
|
42
|
+
}>;
|
|
43
|
+
emailVerifiedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
44
|
+
lastLoginAt: z.ZodNullable<z.ZodISODateTime>;
|
|
45
|
+
createdAt: z.ZodISODateTime;
|
|
46
|
+
timezone: z.ZodString;
|
|
47
|
+
timezoneSource: z.ZodEnum<{
|
|
48
|
+
AUTO: "AUTO";
|
|
49
|
+
MANUAL: "MANUAL";
|
|
50
|
+
}>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
export type ClientProfile = z.output<typeof clientProfileSchema>;
|
|
53
|
+
export declare const clientLoginResponseSchema: z.ZodObject<{
|
|
54
|
+
accessToken: z.ZodString;
|
|
55
|
+
tokenType: z.ZodLiteral<"Bearer">;
|
|
56
|
+
expiresInSeconds: z.ZodNumber;
|
|
57
|
+
refreshToken: z.ZodOptional<z.ZodString>;
|
|
58
|
+
csrfToken: z.ZodOptional<z.ZodString>;
|
|
59
|
+
sessionId: z.ZodUUID;
|
|
60
|
+
client: z.ZodObject<{
|
|
61
|
+
id: z.ZodUUID;
|
|
62
|
+
email: z.ZodString;
|
|
63
|
+
fullName: z.ZodNullable<z.ZodString>;
|
|
64
|
+
phone: z.ZodNullable<z.ZodString>;
|
|
65
|
+
role: z.ZodLiteral<"CLIENT">;
|
|
66
|
+
status: z.ZodEnum<{
|
|
67
|
+
pending_verification: "pending_verification";
|
|
68
|
+
active: "active";
|
|
69
|
+
disabled: "disabled";
|
|
70
|
+
}>;
|
|
71
|
+
emailVerifiedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
72
|
+
lastLoginAt: z.ZodNullable<z.ZodISODateTime>;
|
|
73
|
+
createdAt: z.ZodISODateTime;
|
|
74
|
+
timezone: z.ZodString;
|
|
75
|
+
timezoneSource: z.ZodEnum<{
|
|
76
|
+
AUTO: "AUTO";
|
|
77
|
+
MANUAL: "MANUAL";
|
|
78
|
+
}>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
export type ClientLoginResponse = z.output<typeof clientLoginResponseSchema>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { loginSchema, newPasswordSchema, timezonePreferenceSchema, tokenResponseSchema, } from '../auth/auth.dto.js';
|
|
3
|
+
import { emailSchema } from '../common/contact.schema.js';
|
|
4
|
+
import { detectedTimezoneSchema, utcTimestampSchema, } from '../common/date-time.schema.js';
|
|
5
|
+
import { safeTextSchema } from '../common/safe-text.schema.js';
|
|
6
|
+
import { ACCOUNT_STATUSES } from '../enums/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Client self sign-up: a name, an email address and a password. The account
|
|
9
|
+
* cannot sign in until the emailed code is verified.
|
|
10
|
+
*/
|
|
11
|
+
export const clientSignupSchema = z.strictObject({
|
|
12
|
+
fullName: safeTextSchema(100).pipe(z.string().min(2, { error: 'Enter your full name' })),
|
|
13
|
+
email: emailSchema,
|
|
14
|
+
password: newPasswordSchema,
|
|
15
|
+
/** The device's time zone. Missing or unusable becomes UTC on the server. */
|
|
16
|
+
timezone: detectedTimezoneSchema,
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Clients sign in from the mobile app, so the refresh token comes back in the
|
|
20
|
+
* body by default. A browser sends `tokenTransport: "cookie"` instead, and
|
|
21
|
+
* `rememberMe: false` then makes the cookie end with the browser session.
|
|
22
|
+
*/
|
|
23
|
+
export const clientLoginSchema = loginSchema.extend({
|
|
24
|
+
rememberMe: z.boolean().default(true),
|
|
25
|
+
/**
|
|
26
|
+
* The device's time zone. It replaces the saved one only while the client's
|
|
27
|
+
* preference is `AUTO`; a manual choice is never overwritten.
|
|
28
|
+
*/
|
|
29
|
+
timezone: detectedTimezoneSchema,
|
|
30
|
+
});
|
|
31
|
+
export const clientProfileSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
id: z.uuid(),
|
|
34
|
+
email: z.string(),
|
|
35
|
+
fullName: z.string().nullable(),
|
|
36
|
+
phone: z.string().nullable(),
|
|
37
|
+
role: z.literal('CLIENT'),
|
|
38
|
+
status: z.enum(ACCOUNT_STATUSES),
|
|
39
|
+
emailVerifiedAt: utcTimestampSchema.nullable(),
|
|
40
|
+
lastLoginAt: utcTimestampSchema.nullable(),
|
|
41
|
+
createdAt: utcTimestampSchema,
|
|
42
|
+
})
|
|
43
|
+
.extend(timezonePreferenceSchema.shape);
|
|
44
|
+
export const clientLoginResponseSchema = tokenResponseSchema.extend({
|
|
45
|
+
client: clientProfileSchema,
|
|
46
|
+
});
|
|
@@ -8,18 +8,6 @@ export declare const coachSignupSchema: z.ZodObject<{
|
|
|
8
8
|
}, z.core.$strict>;
|
|
9
9
|
export type CoachSignupInput = z.input<typeof coachSignupSchema>;
|
|
10
10
|
export type CoachSignupBody = z.output<typeof coachSignupSchema>;
|
|
11
|
-
/** Used by both resend endpoints and by forgot-password. */
|
|
12
|
-
export declare const otpEmailSchema: z.ZodObject<{
|
|
13
|
-
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
14
|
-
}, z.core.$strict>;
|
|
15
|
-
export type OtpEmailInput = z.input<typeof otpEmailSchema>;
|
|
16
|
-
export type OtpEmailBody = z.output<typeof otpEmailSchema>;
|
|
17
|
-
export declare const verifyOtpSchema: z.ZodObject<{
|
|
18
|
-
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
19
|
-
code: z.ZodString;
|
|
20
|
-
}, z.core.$strict>;
|
|
21
|
-
export type VerifyOtpInput = z.input<typeof verifyOtpSchema>;
|
|
22
|
-
export type VerifyOtpBody = z.output<typeof verifyOtpSchema>;
|
|
23
11
|
/**
|
|
24
12
|
* Coaches sign in from the browser, so the refresh token always travels in an
|
|
25
13
|
* HttpOnly cookie. `rememberMe: false` makes that cookie end with the browser
|
|
@@ -34,34 +22,6 @@ export declare const coachLoginSchema: z.ZodObject<{
|
|
|
34
22
|
}, z.core.$strict>;
|
|
35
23
|
export type CoachLoginInput = z.input<typeof coachLoginSchema>;
|
|
36
24
|
export type CoachLoginBody = z.output<typeof coachLoginSchema>;
|
|
37
|
-
export declare const resetPasswordSchema: z.ZodObject<{
|
|
38
|
-
resetToken: z.ZodString;
|
|
39
|
-
newPassword: z.ZodString;
|
|
40
|
-
}, z.core.$strict>;
|
|
41
|
-
export type ResetPasswordInput = z.input<typeof resetPasswordSchema>;
|
|
42
|
-
export type ResetPasswordBody = z.output<typeof resetPasswordSchema>;
|
|
43
|
-
/**
|
|
44
|
-
* Says what the client needs to drive the code screen, and nothing about
|
|
45
|
-
* whether the email belongs to an account: the same values are returned either
|
|
46
|
-
* way.
|
|
47
|
-
*/
|
|
48
|
-
export declare const otpDispatchResponseSchema: z.ZodObject<{
|
|
49
|
-
message: z.ZodString;
|
|
50
|
-
otpLength: z.ZodNumber;
|
|
51
|
-
expiresInSeconds: z.ZodNumber;
|
|
52
|
-
resendAvailableInSeconds: z.ZodNumber;
|
|
53
|
-
}, z.core.$strip>;
|
|
54
|
-
export type OtpDispatchResponse = z.output<typeof otpDispatchResponseSchema>;
|
|
55
|
-
export declare const signupVerifiedResponseSchema: z.ZodObject<{
|
|
56
|
-
message: z.ZodString;
|
|
57
|
-
}, z.core.$strip>;
|
|
58
|
-
export type SignupVerifiedResponse = z.output<typeof signupVerifiedResponseSchema>;
|
|
59
|
-
/** Issued only after a recovery code is verified. It can reset a password once. */
|
|
60
|
-
export declare const resetTokenResponseSchema: z.ZodObject<{
|
|
61
|
-
resetToken: z.ZodString;
|
|
62
|
-
expiresInSeconds: z.ZodNumber;
|
|
63
|
-
}, z.core.$strip>;
|
|
64
|
-
export type ResetTokenResponse = z.output<typeof resetTokenResponseSchema>;
|
|
65
25
|
export declare const coachProfileSchema: z.ZodObject<{
|
|
66
26
|
id: z.ZodUUID;
|
|
67
27
|
email: z.ZodString;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { loginSchema, newPasswordSchema,
|
|
2
|
+
import { loginSchema, newPasswordSchema, timezonePreferenceSchema, tokenResponseSchema, } from '../auth/auth.dto.js';
|
|
3
3
|
import { emailSchema, phoneSchema } from '../common/contact.schema.js';
|
|
4
4
|
import { detectedTimezoneSchema, utcTimestampSchema, } from '../common/date-time.schema.js';
|
|
5
5
|
import { safeTextSchema } from '../common/safe-text.schema.js';
|
|
@@ -12,12 +12,6 @@ export const coachSignupSchema = z.strictObject({
|
|
|
12
12
|
/** The browser's time zone. Missing or unusable becomes UTC on the server. */
|
|
13
13
|
timezone: detectedTimezoneSchema,
|
|
14
14
|
});
|
|
15
|
-
/** Used by both resend endpoints and by forgot-password. */
|
|
16
|
-
export const otpEmailSchema = z.strictObject({ email: emailSchema });
|
|
17
|
-
export const verifyOtpSchema = z.strictObject({
|
|
18
|
-
email: emailSchema,
|
|
19
|
-
code: otpCodeSchema,
|
|
20
|
-
});
|
|
21
15
|
/**
|
|
22
16
|
* Coaches sign in from the browser, so the refresh token always travels in an
|
|
23
17
|
* HttpOnly cookie. `rememberMe: false` makes that cookie end with the browser
|
|
@@ -33,29 +27,6 @@ export const coachLoginSchema = loginSchema
|
|
|
33
27
|
*/
|
|
34
28
|
timezone: detectedTimezoneSchema,
|
|
35
29
|
});
|
|
36
|
-
export const resetPasswordSchema = z.strictObject({
|
|
37
|
-
resetToken: opaqueTokenSchema,
|
|
38
|
-
newPassword: newPasswordSchema,
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* Says what the client needs to drive the code screen, and nothing about
|
|
42
|
-
* whether the email belongs to an account: the same values are returned either
|
|
43
|
-
* way.
|
|
44
|
-
*/
|
|
45
|
-
export const otpDispatchResponseSchema = z.object({
|
|
46
|
-
message: z.string(),
|
|
47
|
-
otpLength: z.number().int(),
|
|
48
|
-
expiresInSeconds: z.number().int(),
|
|
49
|
-
resendAvailableInSeconds: z.number().int(),
|
|
50
|
-
});
|
|
51
|
-
export const signupVerifiedResponseSchema = z.object({
|
|
52
|
-
message: z.string(),
|
|
53
|
-
});
|
|
54
|
-
/** Issued only after a recovery code is verified. It can reset a password once. */
|
|
55
|
-
export const resetTokenResponseSchema = z.object({
|
|
56
|
-
resetToken: z.string(),
|
|
57
|
-
expiresInSeconds: z.number().int(),
|
|
58
|
-
});
|
|
59
30
|
export const coachProfileSchema = z
|
|
60
31
|
.object({
|
|
61
32
|
id: z.uuid(),
|
package/dist/esm/coach/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const APP_ENVIRONMENTS: readonly ["development", "staging", "production"];
|
|
2
2
|
export type AppEnvironment = (typeof APP_ENVIRONMENTS)[number];
|
|
3
3
|
/** Each user has exactly one role. A new role is added here and nowhere else. */
|
|
4
|
-
export declare const ROLES: readonly ["ADMIN", "COACH", "
|
|
4
|
+
export declare const ROLES: readonly ["ADMIN", "COACH", "CLIENT"];
|
|
5
5
|
export type Role = (typeof ROLES)[number];
|
|
6
6
|
/**
|
|
7
7
|
* `pending_verification` is a self-registered user who has not yet proved they
|
|
@@ -23,7 +23,7 @@ export declare const TOKEN_TRANSPORTS: readonly ["body", "cookie"];
|
|
|
23
23
|
export type TokenTransport = (typeof TOKEN_TRANSPORTS)[number];
|
|
24
24
|
export declare const AUDIT_OUTCOMES: readonly ["success", "failure"];
|
|
25
25
|
export type AuditOutcome = (typeof AUDIT_OUTCOMES)[number];
|
|
26
|
-
export declare const FEATURE_FLAG_RULE_TYPES: readonly ["user", "
|
|
26
|
+
export declare const FEATURE_FLAG_RULE_TYPES: readonly ["user", "client", "trainer", "role"];
|
|
27
27
|
export type FeatureFlagRuleType = (typeof FEATURE_FLAG_RULE_TYPES)[number];
|
|
28
28
|
/**
|
|
29
29
|
* The ways a message can reach someone. WhatsApp and push are added here when
|
|
@@ -44,3 +44,41 @@ export type DeliveryStatus = (typeof DELIVERY_STATUSES)[number];
|
|
|
44
44
|
/** Only one version of a template per message type and channel is active. */
|
|
45
45
|
export declare const TEMPLATE_STATUSES: readonly ["draft", "active", "archived"];
|
|
46
46
|
export type TemplateStatus = (typeof TEMPLATE_STATUSES)[number];
|
|
47
|
+
/** Who put a food into the library. */
|
|
48
|
+
export declare const FOOD_SOURCES: readonly ["ADMIN", "COACH", "CLIENT_SUGGESTION", "IMPORT"];
|
|
49
|
+
export type FoodSource = (typeof FOOD_SOURCES)[number];
|
|
50
|
+
/**
|
|
51
|
+
* The unit a library serving is measured in. Nutrients are stored per 100 of
|
|
52
|
+
* this unit, so a food in `ml` holds values per 100 ml.
|
|
53
|
+
*/
|
|
54
|
+
export declare const SERVING_UNITS: readonly ["g", "ml"];
|
|
55
|
+
export type ServingUnit = (typeof SERVING_UNITS)[number];
|
|
56
|
+
/** The portion units a client can pick when logging a food. */
|
|
57
|
+
export declare const PORTION_UNITS: readonly ["BOWL", "GRAM", "PIECE", "CUP"];
|
|
58
|
+
export type PortionUnit = (typeof PORTION_UNITS)[number];
|
|
59
|
+
/** Whether submitted nutrient values are per 100 units or per serving. */
|
|
60
|
+
export declare const NUTRITION_BASES: readonly ["PER_100", "PER_SERVING"];
|
|
61
|
+
export type NutritionBasis = (typeof NUTRITION_BASES)[number];
|
|
62
|
+
export declare const FOOD_SUGGESTION_STATUSES: readonly ["pending", "approved", "rejected", "withdrawn"];
|
|
63
|
+
export type FoodSuggestionStatus = (typeof FOOD_SUGGESTION_STATUSES)[number];
|
|
64
|
+
/** How an approved suggestion was resolved. */
|
|
65
|
+
export declare const FOOD_SUGGESTION_RESOLUTIONS: readonly ["ADDED_TO_LIBRARY", "LINKED_TO_EXISTING", "APPROVED_WITHOUT_LIBRARY"];
|
|
66
|
+
export type FoodSuggestionResolution = (typeof FOOD_SUGGESTION_RESOLUTIONS)[number];
|
|
67
|
+
/** What a bulk import does with a row whose food is already in the library. */
|
|
68
|
+
export declare const FOOD_IMPORT_MODES: readonly ["SKIP_DUPLICATES", "UPDATE_EXISTING"];
|
|
69
|
+
export type FoodImportMode = (typeof FOOD_IMPORT_MODES)[number];
|
|
70
|
+
export declare const FOOD_IMPORT_STATUSES: readonly ["previewed", "completed", "expired"];
|
|
71
|
+
export type FoodImportStatus = (typeof FOOD_IMPORT_STATUSES)[number];
|
|
72
|
+
export declare const FOOD_IMPORT_ROW_STATUSES: readonly ["valid", "invalid", "duplicate_in_file", "duplicate_existing"];
|
|
73
|
+
export type FoodImportRowStatus = (typeof FOOD_IMPORT_ROW_STATUSES)[number];
|
|
74
|
+
export declare const FOOD_IMPORT_FILE_TYPES: readonly ["csv", "xlsx"];
|
|
75
|
+
export type FoodImportFileType = (typeof FOOD_IMPORT_FILE_TYPES)[number];
|
|
76
|
+
export declare const FOOD_IMPORT_ISSUE_SEVERITIES: readonly ["error", "warning"];
|
|
77
|
+
export type FoodImportIssueSeverity = (typeof FOOD_IMPORT_ISSUE_SEVERITIES)[number];
|
|
78
|
+
/** Whether a food takes one value of a metadata type or several. */
|
|
79
|
+
export declare const FOOD_METADATA_SELECTIONS: readonly ["single", "multiple"];
|
|
80
|
+
export type FoodMetadataSelection = (typeof FOOD_METADATA_SELECTIONS)[number];
|
|
81
|
+
export declare const FOOD_SORT_FIELDS: readonly ["name", "updatedAt", "calories", "protein"];
|
|
82
|
+
export type FoodSortField = (typeof FOOD_SORT_FIELDS)[number];
|
|
83
|
+
export declare const SORT_ORDERS: readonly ["asc", "desc"];
|
|
84
|
+
export type SortOrder = (typeof SORT_ORDERS)[number];
|