@tbs-fitness/contract 0.5.0 → 0.7.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 +33 -9
- package/dist/cjs/auth/auth.dto.js +5 -0
- package/dist/cjs/enums/index.d.ts +80 -0
- package/dist/cjs/enums/index.js +97 -1
- package/dist/cjs/feature-flags/feature-flag.dto.d.ts +9 -0
- package/dist/cjs/feature-flags/feature-flag.dto.js +9 -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.js +5 -0
- package/dist/esm/enums/index.d.ts +80 -0
- package/dist/esm/enums/index.js +96 -0
- package/dist/esm/feature-flags/feature-flag.dto.d.ts +9 -0
- package/dist/esm/feature-flags/feature-flag.dto.js +8 -0
- 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 +11 -1
package/README.md
CHANGED
|
@@ -6,15 +6,16 @@ It is published as `@tbs-fitness/contract`. The package holds definitions only:
|
|
|
6
6
|
|
|
7
7
|
## What is in it
|
|
8
8
|
|
|
9
|
-
| Import | Contents
|
|
10
|
-
| ------------------------------------- |
|
|
11
|
-
| `@tbs-fitness/contract/enums` | `ROLES`, `ACCOUNT_STATUSES`, `TOKEN_TRANSPORTS`, `AUDIT_OUTCOMES`, `APP_ENVIRONMENTS`, `FEATURE_FLAG_RULE_TYPES` and their types |
|
|
12
|
-
| `@tbs-fitness/contract/common` | Pagination, response envelopes (`{ data }`, `{ data, meta }`, `{ error }`), `emailSchema`, `phoneSchema`, `safeTextSchema`
|
|
13
|
-
| `@tbs-fitness/contract/auth` | Login, sessions, password changes and resets, account administration
|
|
14
|
-
| `@tbs-fitness/contract/client` | Client sign-up, one-time code verification and resend, client sign-in and profile, password recovery
|
|
15
|
-
| `@tbs-fitness/contract/coach` | Coach sign-up, one-time code verification and resend, coach sign-in and profile, password recovery
|
|
16
|
-
| `@tbs-fitness/contract/audit` | The audit log query and response
|
|
17
|
-
| `@tbs-fitness/contract/feature-flags` | Feature flag requests and responses
|
|
9
|
+
| Import | Contents |
|
|
10
|
+
| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `@tbs-fitness/contract/enums` | `ROLES`, `PERMISSIONS`, `CSRF_COOKIE_NAMES`, `CSRF_HEADER`, `ACCOUNT_STATUSES`, `TOKEN_TRANSPORTS`, `AUDIT_OUTCOMES`, `APP_ENVIRONMENTS`, `FEATURE_FLAG_RULE_TYPES` and their types |
|
|
12
|
+
| `@tbs-fitness/contract/common` | Pagination, response envelopes (`{ data }`, `{ data, meta }`, `{ error }`), `emailSchema`, `phoneSchema`, `safeTextSchema` |
|
|
13
|
+
| `@tbs-fitness/contract/auth` | Login, sessions, password changes and resets, account administration |
|
|
14
|
+
| `@tbs-fitness/contract/client` | Client sign-up, one-time code verification and resend, client sign-in and profile, password recovery |
|
|
15
|
+
| `@tbs-fitness/contract/coach` | Coach sign-up, one-time code verification and resend, coach sign-in and profile, password recovery |
|
|
16
|
+
| `@tbs-fitness/contract/audit` | The audit log query and response |
|
|
17
|
+
| `@tbs-fitness/contract/feature-flags` | Feature flag requests and responses |
|
|
18
|
+
| `@tbs-fitness/contract/food` | Food library, metadata, CSV/XLSX import, client food suggestions and their review, and the shared nutrition helpers |
|
|
18
19
|
|
|
19
20
|
Each domain has its own entry point, so names only need to be unique within a domain. `auditLogResponseSchema`, for example, exists in both `/audit` and `/feature-flags`.
|
|
20
21
|
|
|
@@ -42,6 +43,29 @@ const result = createFlagSchema.safeParse(input); // The same rules as the API.
|
|
|
42
43
|
|
|
43
44
|
Requests have two types. Clients use `*Input`, where fields with a default are optional. The backend uses `*Body`, which is the result after validation. List queries come from the URL as strings, so they have no `*Input`: use `Partial<PaginationQuery>` or `Partial<AuditLogQuery>`.
|
|
44
45
|
|
|
46
|
+
## Version 0.7.0
|
|
47
|
+
|
|
48
|
+
Permission names, CSRF names and the client feature-flag response. Additive; consumers install `^0.7.0` explicitly.
|
|
49
|
+
|
|
50
|
+
- `/enums`: `PERMISSIONS` and `Permission`, every permission name the API grants. Which role has which permission stays in the backend.
|
|
51
|
+
- `/enums`: `CSRF_COOKIE_NAMES` (`__Host-tbs_csrf` when Secure, else `tbs_csrf`) and `CSRF_HEADER` (`x-csrf-token`).
|
|
52
|
+
- `/feature-flags`: `evaluatedFlagsResponseSchema` and `EvaluatedFlagsResponse`, the response of `GET /feature-flags/me`: only the flags that are on for the caller.
|
|
53
|
+
- `accountResponseSchema.permissions` stays an array of plain strings, so a client older than a new permission still accepts the sign-in.
|
|
54
|
+
|
|
55
|
+
## Version 0.6.0
|
|
56
|
+
|
|
57
|
+
The food library. Additive; consumers install `^0.6.0` explicitly.
|
|
58
|
+
|
|
59
|
+
- `/enums`: `FOOD_SOURCES`, `SERVING_UNITS` (`g`, `ml`), `PORTION_UNITS`, `NUTRITION_BASES`, `FOOD_SUGGESTION_STATUSES`, `FOOD_SUGGESTION_RESOLUTIONS`, `FOOD_IMPORT_MODES`, `FOOD_IMPORT_STATUSES`, `FOOD_IMPORT_ROW_STATUSES`, `FOOD_IMPORT_FILE_TYPES`, `FOOD_IMPORT_ISSUE_SEVERITIES`, `FOOD_METADATA_SELECTIONS`, `FOOD_SORT_FIELDS` and `SORT_ORDERS`.
|
|
60
|
+
- New `/food`:
|
|
61
|
+
- Library: `createFoodSchema`, `updateFoodSchema` (with `version`), `foodListQuerySchema`, `foodResponseSchema` (values per 100 and per serving, plus `formulaCalories`), `similarFoodResponseSchema`, `foodStatsResponseSchema`.
|
|
62
|
+
- Metadata: `metadataTypeResponseSchema`, `metadataValueResponseSchema`, `createMetadataValueSchema`, `updateMetadataValueSchema`.
|
|
63
|
+
- Import: `foodImportRowSchema` (one spreadsheet row, shared by the API and the preview), `commitFoodImportSchema`, `foodImportBatchResponseSchema`, `foodImportRowResponseSchema`, `FOOD_IMPORT_LIMITS`.
|
|
64
|
+
- Suggestions: `submitFoodSuggestionSchema`, `suggestionPhotoUploadSchema`, `presignedUploadResponseSchema`, `approveFoodSuggestionSchema` (one shape per resolution), `rejectFoodSuggestionSchema`, `foodSuggestionResponseSchema` (coach view), `clientFoodSuggestionResponseSchema` (client view), `FOOD_SUGGESTION_LIMITS`.
|
|
65
|
+
- Client search: `clientFoodSearchQuerySchema`, `clientFoodResponseSchema`.
|
|
66
|
+
- Helpers: `toPer100`, `perServing`, `formulaCalories` (Biki's formula, (protein + carbs) × 4 + fat × 9), `nutritionIssues`, `normalizeFoodName`, `slugifyMetadataKey`, `parseServingLabel`, `roundNutrient`.
|
|
67
|
+
- Library nutrients are per 100 of the serving unit: per 100 g, or per 100 ml for a serving in ml. Values have at most 2 decimals.
|
|
68
|
+
|
|
45
69
|
## Version 0.5.0 (breaking)
|
|
46
70
|
|
|
47
71
|
- `ROLES` is now `ADMIN`, `COACH` and `CLIENT`: `CUSTOMER` is renamed to `CLIENT`. The backend migrates stored roles in step.
|
|
@@ -90,6 +90,11 @@ exports.accountResponseSchema = zod_1.z
|
|
|
90
90
|
role: zod_1.z.enum(index_js_1.ROLES),
|
|
91
91
|
/** @deprecated Always `[role]`. Kept for clients written before `role`. */
|
|
92
92
|
roles: zod_1.z.array(zod_1.z.string()),
|
|
93
|
+
/**
|
|
94
|
+
* Plain strings rather than `PERMISSIONS` values, because clients validate
|
|
95
|
+
* this response. With an enum, a client older than a new permission would
|
|
96
|
+
* reject the sign-in of everyone granted it.
|
|
97
|
+
*/
|
|
93
98
|
permissions: zod_1.z.array(zod_1.z.string()),
|
|
94
99
|
lastLoginAt: date_time_schema_js_1.utcTimestampSchema.nullable(),
|
|
95
100
|
})
|
|
@@ -3,6 +3,37 @@ 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
4
|
export declare const ROLES: readonly ["ADMIN", "COACH", "CLIENT"];
|
|
5
5
|
export type Role = (typeof ROLES)[number];
|
|
6
|
+
/**
|
|
7
|
+
* Every permission name the API grants. Renaming one is a breaking change:
|
|
8
|
+
* clients compare these strings with what the API returns, so one on the old
|
|
9
|
+
* name silently loses whatever it guards. Which role has which permission is a
|
|
10
|
+
* server decision, so that mapping stays in the backend.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PERMISSIONS: {
|
|
13
|
+
readonly accountsManage: "accounts:manage";
|
|
14
|
+
readonly rolesManage: "roles:manage";
|
|
15
|
+
readonly auditRead: "audit:read";
|
|
16
|
+
readonly featureFlagsManage: "feature_flags:manage";
|
|
17
|
+
readonly appSettingsManage: "app_settings:manage";
|
|
18
|
+
readonly communicationTemplatesManage: "communication_templates:manage";
|
|
19
|
+
readonly clientsReadAny: "clients:read:any";
|
|
20
|
+
readonly clientsWriteAny: "clients:write:any";
|
|
21
|
+
readonly clientsReadAssigned: "clients:read:assigned";
|
|
22
|
+
readonly clientsWriteAssigned: "clients:write:assigned";
|
|
23
|
+
readonly clientsReadSelf: "clients:read:self";
|
|
24
|
+
readonly clientsWriteSelf: "clients:write:self";
|
|
25
|
+
readonly foodsRead: "foods:read";
|
|
26
|
+
readonly foodsCreate: "foods:create";
|
|
27
|
+
readonly foodsUpdate: "foods:update";
|
|
28
|
+
readonly foodsDelete: "foods:delete";
|
|
29
|
+
readonly foodsImport: "foods:import";
|
|
30
|
+
readonly foodMetadataManage: "food_metadata:manage";
|
|
31
|
+
readonly foodSuggestionsReview: "food_suggestions:review";
|
|
32
|
+
readonly foodsSearchSelf: "foods:search:self";
|
|
33
|
+
readonly foodSuggestionsSubmitSelf: "food_suggestions:submit:self";
|
|
34
|
+
readonly foodSuggestionsReadSelf: "food_suggestions:read:self";
|
|
35
|
+
};
|
|
36
|
+
export type Permission = (typeof PERMISSIONS)[keyof typeof PERMISSIONS];
|
|
6
37
|
/**
|
|
7
38
|
* `pending_verification` is a self-registered user who has not yet proved they
|
|
8
39
|
* own their email address. Such a user cannot sign in.
|
|
@@ -21,6 +52,17 @@ export declare const TIMEZONE_SOURCES: readonly ["AUTO", "MANUAL"];
|
|
|
21
52
|
export type TimezoneSource = (typeof TIMEZONE_SOURCES)[number];
|
|
22
53
|
export declare const TOKEN_TRANSPORTS: readonly ["body", "cookie"];
|
|
23
54
|
export type TokenTransport = (typeof TOKEN_TRANSPORTS)[number];
|
|
55
|
+
/**
|
|
56
|
+
* The CSRF cookie the API sets, which scripts may read. The `__Host-` name is
|
|
57
|
+
* used when cookies are Secure, because browsers only honour that prefix on
|
|
58
|
+
* Secure cookies.
|
|
59
|
+
*/
|
|
60
|
+
export declare const CSRF_COOKIE_NAMES: {
|
|
61
|
+
readonly secure: "__Host-tbs_csrf";
|
|
62
|
+
readonly insecure: "tbs_csrf";
|
|
63
|
+
};
|
|
64
|
+
/** The header that carries the CSRF token back to the API. */
|
|
65
|
+
export declare const CSRF_HEADER = "x-csrf-token";
|
|
24
66
|
export declare const AUDIT_OUTCOMES: readonly ["success", "failure"];
|
|
25
67
|
export type AuditOutcome = (typeof AUDIT_OUTCOMES)[number];
|
|
26
68
|
export declare const FEATURE_FLAG_RULE_TYPES: readonly ["user", "client", "trainer", "role"];
|
|
@@ -44,3 +86,41 @@ export type DeliveryStatus = (typeof DELIVERY_STATUSES)[number];
|
|
|
44
86
|
/** Only one version of a template per message type and channel is active. */
|
|
45
87
|
export declare const TEMPLATE_STATUSES: readonly ["draft", "active", "archived"];
|
|
46
88
|
export type TemplateStatus = (typeof TEMPLATE_STATUSES)[number];
|
|
89
|
+
/** Who put a food into the library. */
|
|
90
|
+
export declare const FOOD_SOURCES: readonly ["ADMIN", "COACH", "CLIENT_SUGGESTION", "IMPORT"];
|
|
91
|
+
export type FoodSource = (typeof FOOD_SOURCES)[number];
|
|
92
|
+
/**
|
|
93
|
+
* The unit a library serving is measured in. Nutrients are stored per 100 of
|
|
94
|
+
* this unit, so a food in `ml` holds values per 100 ml.
|
|
95
|
+
*/
|
|
96
|
+
export declare const SERVING_UNITS: readonly ["g", "ml"];
|
|
97
|
+
export type ServingUnit = (typeof SERVING_UNITS)[number];
|
|
98
|
+
/** The portion units a client can pick when logging a food. */
|
|
99
|
+
export declare const PORTION_UNITS: readonly ["BOWL", "GRAM", "PIECE", "CUP"];
|
|
100
|
+
export type PortionUnit = (typeof PORTION_UNITS)[number];
|
|
101
|
+
/** Whether submitted nutrient values are per 100 units or per serving. */
|
|
102
|
+
export declare const NUTRITION_BASES: readonly ["PER_100", "PER_SERVING"];
|
|
103
|
+
export type NutritionBasis = (typeof NUTRITION_BASES)[number];
|
|
104
|
+
export declare const FOOD_SUGGESTION_STATUSES: readonly ["pending", "approved", "rejected", "withdrawn"];
|
|
105
|
+
export type FoodSuggestionStatus = (typeof FOOD_SUGGESTION_STATUSES)[number];
|
|
106
|
+
/** How an approved suggestion was resolved. */
|
|
107
|
+
export declare const FOOD_SUGGESTION_RESOLUTIONS: readonly ["ADDED_TO_LIBRARY", "LINKED_TO_EXISTING", "APPROVED_WITHOUT_LIBRARY"];
|
|
108
|
+
export type FoodSuggestionResolution = (typeof FOOD_SUGGESTION_RESOLUTIONS)[number];
|
|
109
|
+
/** What a bulk import does with a row whose food is already in the library. */
|
|
110
|
+
export declare const FOOD_IMPORT_MODES: readonly ["SKIP_DUPLICATES", "UPDATE_EXISTING"];
|
|
111
|
+
export type FoodImportMode = (typeof FOOD_IMPORT_MODES)[number];
|
|
112
|
+
export declare const FOOD_IMPORT_STATUSES: readonly ["previewed", "completed", "expired"];
|
|
113
|
+
export type FoodImportStatus = (typeof FOOD_IMPORT_STATUSES)[number];
|
|
114
|
+
export declare const FOOD_IMPORT_ROW_STATUSES: readonly ["valid", "invalid", "duplicate_in_file", "duplicate_existing"];
|
|
115
|
+
export type FoodImportRowStatus = (typeof FOOD_IMPORT_ROW_STATUSES)[number];
|
|
116
|
+
export declare const FOOD_IMPORT_FILE_TYPES: readonly ["csv", "xlsx"];
|
|
117
|
+
export type FoodImportFileType = (typeof FOOD_IMPORT_FILE_TYPES)[number];
|
|
118
|
+
export declare const FOOD_IMPORT_ISSUE_SEVERITIES: readonly ["error", "warning"];
|
|
119
|
+
export type FoodImportIssueSeverity = (typeof FOOD_IMPORT_ISSUE_SEVERITIES)[number];
|
|
120
|
+
/** Whether a food takes one value of a metadata type or several. */
|
|
121
|
+
export declare const FOOD_METADATA_SELECTIONS: readonly ["single", "multiple"];
|
|
122
|
+
export type FoodMetadataSelection = (typeof FOOD_METADATA_SELECTIONS)[number];
|
|
123
|
+
export declare const FOOD_SORT_FIELDS: readonly ["name", "updatedAt", "calories", "protein"];
|
|
124
|
+
export type FoodSortField = (typeof FOOD_SORT_FIELDS)[number];
|
|
125
|
+
export declare const SORT_ORDERS: readonly ["asc", "desc"];
|
|
126
|
+
export type SortOrder = (typeof SORT_ORDERS)[number];
|
package/dist/cjs/enums/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// These values are stored in the database and sent over the API. Renaming or
|
|
3
3
|
// removing one is a breaking change, so it needs a major version.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.TEMPLATE_STATUSES = exports.DELIVERY_STATUSES = exports.MESSAGE_TYPES = exports.COMMUNICATION_CHANNELS = exports.FEATURE_FLAG_RULE_TYPES = exports.AUDIT_OUTCOMES = exports.TOKEN_TRANSPORTS = exports.TIMEZONE_SOURCES = exports.ADMIN_SETTABLE_ACCOUNT_STATUSES = exports.ACCOUNT_STATUSES = exports.ROLES = exports.APP_ENVIRONMENTS = void 0;
|
|
5
|
+
exports.SORT_ORDERS = exports.FOOD_SORT_FIELDS = exports.FOOD_METADATA_SELECTIONS = exports.FOOD_IMPORT_ISSUE_SEVERITIES = exports.FOOD_IMPORT_FILE_TYPES = exports.FOOD_IMPORT_ROW_STATUSES = exports.FOOD_IMPORT_STATUSES = exports.FOOD_IMPORT_MODES = exports.FOOD_SUGGESTION_RESOLUTIONS = exports.FOOD_SUGGESTION_STATUSES = exports.NUTRITION_BASES = exports.PORTION_UNITS = exports.SERVING_UNITS = exports.FOOD_SOURCES = exports.TEMPLATE_STATUSES = exports.DELIVERY_STATUSES = exports.MESSAGE_TYPES = exports.COMMUNICATION_CHANNELS = exports.FEATURE_FLAG_RULE_TYPES = exports.AUDIT_OUTCOMES = exports.CSRF_HEADER = exports.CSRF_COOKIE_NAMES = exports.TOKEN_TRANSPORTS = exports.TIMEZONE_SOURCES = exports.ADMIN_SETTABLE_ACCOUNT_STATUSES = exports.ACCOUNT_STATUSES = exports.PERMISSIONS = exports.ROLES = exports.APP_ENVIRONMENTS = void 0;
|
|
6
6
|
exports.APP_ENVIRONMENTS = [
|
|
7
7
|
'development',
|
|
8
8
|
'staging',
|
|
@@ -10,6 +10,36 @@ exports.APP_ENVIRONMENTS = [
|
|
|
10
10
|
];
|
|
11
11
|
/** Each user has exactly one role. A new role is added here and nowhere else. */
|
|
12
12
|
exports.ROLES = ['ADMIN', 'COACH', 'CLIENT'];
|
|
13
|
+
/**
|
|
14
|
+
* Every permission name the API grants. Renaming one is a breaking change:
|
|
15
|
+
* clients compare these strings with what the API returns, so one on the old
|
|
16
|
+
* name silently loses whatever it guards. Which role has which permission is a
|
|
17
|
+
* server decision, so that mapping stays in the backend.
|
|
18
|
+
*/
|
|
19
|
+
exports.PERMISSIONS = {
|
|
20
|
+
accountsManage: 'accounts:manage',
|
|
21
|
+
rolesManage: 'roles:manage',
|
|
22
|
+
auditRead: 'audit:read',
|
|
23
|
+
featureFlagsManage: 'feature_flags:manage',
|
|
24
|
+
appSettingsManage: 'app_settings:manage',
|
|
25
|
+
communicationTemplatesManage: 'communication_templates:manage',
|
|
26
|
+
clientsReadAny: 'clients:read:any',
|
|
27
|
+
clientsWriteAny: 'clients:write:any',
|
|
28
|
+
clientsReadAssigned: 'clients:read:assigned',
|
|
29
|
+
clientsWriteAssigned: 'clients:write:assigned',
|
|
30
|
+
clientsReadSelf: 'clients:read:self',
|
|
31
|
+
clientsWriteSelf: 'clients:write:self',
|
|
32
|
+
foodsRead: 'foods:read',
|
|
33
|
+
foodsCreate: 'foods:create',
|
|
34
|
+
foodsUpdate: 'foods:update',
|
|
35
|
+
foodsDelete: 'foods:delete',
|
|
36
|
+
foodsImport: 'foods:import',
|
|
37
|
+
foodMetadataManage: 'food_metadata:manage',
|
|
38
|
+
foodSuggestionsReview: 'food_suggestions:review',
|
|
39
|
+
foodsSearchSelf: 'foods:search:self',
|
|
40
|
+
foodSuggestionsSubmitSelf: 'food_suggestions:submit:self',
|
|
41
|
+
foodSuggestionsReadSelf: 'food_suggestions:read:self',
|
|
42
|
+
};
|
|
13
43
|
/**
|
|
14
44
|
* `pending_verification` is a self-registered user who has not yet proved they
|
|
15
45
|
* own their email address. Such a user cannot sign in.
|
|
@@ -28,6 +58,17 @@ exports.ADMIN_SETTABLE_ACCOUNT_STATUSES = ['active', 'disabled'];
|
|
|
28
58
|
*/
|
|
29
59
|
exports.TIMEZONE_SOURCES = ['AUTO', 'MANUAL'];
|
|
30
60
|
exports.TOKEN_TRANSPORTS = ['body', 'cookie'];
|
|
61
|
+
/**
|
|
62
|
+
* The CSRF cookie the API sets, which scripts may read. The `__Host-` name is
|
|
63
|
+
* used when cookies are Secure, because browsers only honour that prefix on
|
|
64
|
+
* Secure cookies.
|
|
65
|
+
*/
|
|
66
|
+
exports.CSRF_COOKIE_NAMES = {
|
|
67
|
+
secure: '__Host-tbs_csrf',
|
|
68
|
+
insecure: 'tbs_csrf',
|
|
69
|
+
};
|
|
70
|
+
/** The header that carries the CSRF token back to the API. */
|
|
71
|
+
exports.CSRF_HEADER = 'x-csrf-token';
|
|
31
72
|
exports.AUDIT_OUTCOMES = ['success', 'failure'];
|
|
32
73
|
exports.FEATURE_FLAG_RULE_TYPES = [
|
|
33
74
|
'user',
|
|
@@ -60,3 +101,58 @@ exports.DELIVERY_STATUSES = [
|
|
|
60
101
|
];
|
|
61
102
|
/** Only one version of a template per message type and channel is active. */
|
|
62
103
|
exports.TEMPLATE_STATUSES = ['draft', 'active', 'archived'];
|
|
104
|
+
/** Who put a food into the library. */
|
|
105
|
+
exports.FOOD_SOURCES = [
|
|
106
|
+
'ADMIN',
|
|
107
|
+
'COACH',
|
|
108
|
+
'CLIENT_SUGGESTION',
|
|
109
|
+
'IMPORT',
|
|
110
|
+
];
|
|
111
|
+
/**
|
|
112
|
+
* The unit a library serving is measured in. Nutrients are stored per 100 of
|
|
113
|
+
* this unit, so a food in `ml` holds values per 100 ml.
|
|
114
|
+
*/
|
|
115
|
+
exports.SERVING_UNITS = ['g', 'ml'];
|
|
116
|
+
/** The portion units a client can pick when logging a food. */
|
|
117
|
+
exports.PORTION_UNITS = ['BOWL', 'GRAM', 'PIECE', 'CUP'];
|
|
118
|
+
/** Whether submitted nutrient values are per 100 units or per serving. */
|
|
119
|
+
exports.NUTRITION_BASES = ['PER_100', 'PER_SERVING'];
|
|
120
|
+
exports.FOOD_SUGGESTION_STATUSES = [
|
|
121
|
+
'pending',
|
|
122
|
+
'approved',
|
|
123
|
+
'rejected',
|
|
124
|
+
'withdrawn',
|
|
125
|
+
];
|
|
126
|
+
/** How an approved suggestion was resolved. */
|
|
127
|
+
exports.FOOD_SUGGESTION_RESOLUTIONS = [
|
|
128
|
+
'ADDED_TO_LIBRARY',
|
|
129
|
+
'LINKED_TO_EXISTING',
|
|
130
|
+
'APPROVED_WITHOUT_LIBRARY',
|
|
131
|
+
];
|
|
132
|
+
/** What a bulk import does with a row whose food is already in the library. */
|
|
133
|
+
exports.FOOD_IMPORT_MODES = [
|
|
134
|
+
'SKIP_DUPLICATES',
|
|
135
|
+
'UPDATE_EXISTING',
|
|
136
|
+
];
|
|
137
|
+
exports.FOOD_IMPORT_STATUSES = [
|
|
138
|
+
'previewed',
|
|
139
|
+
'completed',
|
|
140
|
+
'expired',
|
|
141
|
+
];
|
|
142
|
+
exports.FOOD_IMPORT_ROW_STATUSES = [
|
|
143
|
+
'valid',
|
|
144
|
+
'invalid',
|
|
145
|
+
'duplicate_in_file',
|
|
146
|
+
'duplicate_existing',
|
|
147
|
+
];
|
|
148
|
+
exports.FOOD_IMPORT_FILE_TYPES = ['csv', 'xlsx'];
|
|
149
|
+
exports.FOOD_IMPORT_ISSUE_SEVERITIES = ['error', 'warning'];
|
|
150
|
+
/** Whether a food takes one value of a metadata type or several. */
|
|
151
|
+
exports.FOOD_METADATA_SELECTIONS = ['single', 'multiple'];
|
|
152
|
+
exports.FOOD_SORT_FIELDS = [
|
|
153
|
+
'name',
|
|
154
|
+
'updatedAt',
|
|
155
|
+
'calories',
|
|
156
|
+
'protein',
|
|
157
|
+
];
|
|
158
|
+
exports.SORT_ORDERS = ['asc', 'desc'];
|
|
@@ -140,3 +140,12 @@ export declare const killSwitchResponseSchema: z.ZodObject<{
|
|
|
140
140
|
updatedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
141
141
|
}, z.core.$strip>;
|
|
142
142
|
export type KillSwitchResponse = z.output<typeof killSwitchResponseSchema>;
|
|
143
|
+
/**
|
|
144
|
+
* What a signed-in user may know about flags: only the keys that are on for
|
|
145
|
+
* them. It never holds rules, targeting values, rollout percentages or who
|
|
146
|
+
* changed what. A missing key means off, so always compare a value with `true`.
|
|
147
|
+
*/
|
|
148
|
+
export declare const evaluatedFlagsResponseSchema: z.ZodObject<{
|
|
149
|
+
flags: z.ZodRecord<z.ZodString, z.ZodBoolean>;
|
|
150
|
+
}, z.core.$strip>;
|
|
151
|
+
export type EvaluatedFlagsResponse = z.output<typeof evaluatedFlagsResponseSchema>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.killSwitchResponseSchema = exports.auditLogResponseSchema = exports.flagResponseSchema = exports.ruleResponseSchema = exports.flagListQuerySchema = exports.setKillSwitchSchema = exports.updateRuleSchema = exports.createRuleSchema = exports.updateFlagSchema = exports.createFlagSchema = exports.flagIdParamSchema = void 0;
|
|
3
|
+
exports.evaluatedFlagsResponseSchema = exports.killSwitchResponseSchema = exports.auditLogResponseSchema = exports.flagResponseSchema = exports.ruleResponseSchema = exports.flagListQuerySchema = exports.setKillSwitchSchema = exports.updateRuleSchema = exports.createRuleSchema = exports.updateFlagSchema = exports.createFlagSchema = exports.flagIdParamSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const date_time_schema_js_1 = require("../common/date-time.schema.js");
|
|
6
6
|
const pagination_schema_js_1 = require("../common/pagination.schema.js");
|
|
@@ -134,3 +134,11 @@ exports.killSwitchResponseSchema = zod_1.z.object({
|
|
|
134
134
|
updatedBy: zod_1.z.uuid().nullable(),
|
|
135
135
|
updatedAt: date_time_schema_js_1.utcTimestampSchema.nullable(),
|
|
136
136
|
});
|
|
137
|
+
/**
|
|
138
|
+
* What a signed-in user may know about flags: only the keys that are on for
|
|
139
|
+
* them. It never holds rules, targeting values, rollout percentages or who
|
|
140
|
+
* changed what. A missing key means off, so always compare a value with `true`.
|
|
141
|
+
*/
|
|
142
|
+
exports.evaluatedFlagsResponseSchema = zod_1.z.object({
|
|
143
|
+
flags: zod_1.z.record(zod_1.z.string(), zod_1.z.boolean()),
|
|
144
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const MIN_CLIENT_FOOD_SEARCH_LENGTH = 2;
|
|
3
|
+
export declare const clientFoodSearchQuerySchema: z.ZodObject<{
|
|
4
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
5
|
+
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
6
|
+
search: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type ClientFoodSearchQuery = z.output<typeof clientFoodSearchQuerySchema>;
|
|
9
|
+
/** A library food as a client sees it: what they need to log it, and nothing about who added it. */
|
|
10
|
+
export declare const clientFoodResponseSchema: z.ZodObject<{
|
|
11
|
+
id: z.ZodUUID;
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
nameHi: z.ZodNullable<z.ZodString>;
|
|
14
|
+
namePa: z.ZodNullable<z.ZodString>;
|
|
15
|
+
englishAlias: z.ZodNullable<z.ZodString>;
|
|
16
|
+
serving: z.ZodObject<{
|
|
17
|
+
label: z.ZodString;
|
|
18
|
+
quantity: z.ZodNumber;
|
|
19
|
+
unit: z.ZodEnum<{
|
|
20
|
+
g: "g";
|
|
21
|
+
ml: "ml";
|
|
22
|
+
}>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
per100: z.ZodObject<{
|
|
25
|
+
calories: z.ZodNumber;
|
|
26
|
+
protein: z.ZodNumber;
|
|
27
|
+
carbs: z.ZodNumber;
|
|
28
|
+
fat: z.ZodNumber;
|
|
29
|
+
sugar: z.ZodNullable<z.ZodNumber>;
|
|
30
|
+
fiber: z.ZodNullable<z.ZodNumber>;
|
|
31
|
+
solubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
32
|
+
insolubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
perServing: z.ZodObject<{
|
|
35
|
+
calories: z.ZodNumber;
|
|
36
|
+
protein: z.ZodNumber;
|
|
37
|
+
carbs: z.ZodNumber;
|
|
38
|
+
fat: z.ZodNumber;
|
|
39
|
+
sugar: z.ZodNullable<z.ZodNumber>;
|
|
40
|
+
fiber: z.ZodNullable<z.ZodNumber>;
|
|
41
|
+
solubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
42
|
+
insolubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
tags: z.ZodArray<z.ZodObject<{
|
|
45
|
+
typeKey: z.ZodString;
|
|
46
|
+
label: z.ZodString;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export type ClientFoodResponse = z.output<typeof clientFoodResponseSchema>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clientFoodResponseSchema = exports.clientFoodSearchQuerySchema = exports.MIN_CLIENT_FOOD_SEARCH_LENGTH = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const pagination_schema_js_1 = require("../common/pagination.schema.js");
|
|
6
|
+
const food_dto_js_1 = require("./food.dto.js");
|
|
7
|
+
exports.MIN_CLIENT_FOOD_SEARCH_LENGTH = 2;
|
|
8
|
+
exports.clientFoodSearchQuerySchema = pagination_schema_js_1.paginationQuerySchema.extend({
|
|
9
|
+
search: zod_1.z
|
|
10
|
+
.string()
|
|
11
|
+
.trim()
|
|
12
|
+
.min(exports.MIN_CLIENT_FOOD_SEARCH_LENGTH)
|
|
13
|
+
.max(food_dto_js_1.MAX_FOOD_SEARCH_LENGTH),
|
|
14
|
+
});
|
|
15
|
+
/** A library food as a client sees it: what they need to log it, and nothing about who added it. */
|
|
16
|
+
exports.clientFoodResponseSchema = zod_1.z.object({
|
|
17
|
+
id: zod_1.z.uuid(),
|
|
18
|
+
name: zod_1.z.string(),
|
|
19
|
+
nameHi: zod_1.z.string().nullable(),
|
|
20
|
+
namePa: zod_1.z.string().nullable(),
|
|
21
|
+
englishAlias: zod_1.z.string().nullable(),
|
|
22
|
+
serving: food_dto_js_1.servingResponseSchema,
|
|
23
|
+
per100: food_dto_js_1.nutrientValuesResponseSchema,
|
|
24
|
+
perServing: food_dto_js_1.nutrientValuesResponseSchema,
|
|
25
|
+
tags: zod_1.z.array(zod_1.z.object({ typeKey: zod_1.z.string(), label: zod_1.z.string() })),
|
|
26
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The file limits the API enforces, shared so the upload screen can say them up front. */
|
|
3
|
+
export declare const FOOD_IMPORT_LIMITS: {
|
|
4
|
+
readonly maxFileBytes: number;
|
|
5
|
+
readonly maxRows: 5000;
|
|
6
|
+
readonly extensions: readonly [".csv", ".xlsx"];
|
|
7
|
+
};
|
|
8
|
+
export declare const importIdParamSchema: z.ZodUUID;
|
|
9
|
+
/**
|
|
10
|
+
* One spreadsheet row after its cells are read. Values per 100 g (or per 100 ml
|
|
11
|
+
* for a serving in ml). Metadata are keys such as `protein` or `high-protein`,
|
|
12
|
+
* matched to the library's values. Has no defaults, so it also serves as the
|
|
13
|
+
* preview response.
|
|
14
|
+
*/
|
|
15
|
+
export declare const foodImportRowSchema: z.ZodObject<{
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
nameHi: z.ZodNullable<z.ZodString>;
|
|
18
|
+
namePa: z.ZodNullable<z.ZodString>;
|
|
19
|
+
englishAlias: z.ZodNullable<z.ZodString>;
|
|
20
|
+
category: z.ZodString;
|
|
21
|
+
subcategory: z.ZodNullable<z.ZodString>;
|
|
22
|
+
servingLabel: z.ZodString;
|
|
23
|
+
servingQuantity: z.ZodNumber;
|
|
24
|
+
servingUnit: z.ZodEnum<{
|
|
25
|
+
g: "g";
|
|
26
|
+
ml: "ml";
|
|
27
|
+
}>;
|
|
28
|
+
calories: z.ZodNumber;
|
|
29
|
+
protein: z.ZodNumber;
|
|
30
|
+
carbs: z.ZodNumber;
|
|
31
|
+
fat: z.ZodNumber;
|
|
32
|
+
sugar: z.ZodNullable<z.ZodNumber>;
|
|
33
|
+
fiber: z.ZodNullable<z.ZodNumber>;
|
|
34
|
+
solubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
35
|
+
insolubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
36
|
+
tags: z.ZodArray<z.ZodString>;
|
|
37
|
+
mealTimings: z.ZodArray<z.ZodString>;
|
|
38
|
+
notes: z.ZodNullable<z.ZodString>;
|
|
39
|
+
}, z.core.$strict>;
|
|
40
|
+
export type FoodImportRow = z.output<typeof foodImportRowSchema>;
|
|
41
|
+
export declare const commitFoodImportSchema: z.ZodObject<{
|
|
42
|
+
mode: z.ZodDefault<z.ZodEnum<{
|
|
43
|
+
SKIP_DUPLICATES: "SKIP_DUPLICATES";
|
|
44
|
+
UPDATE_EXISTING: "UPDATE_EXISTING";
|
|
45
|
+
}>>;
|
|
46
|
+
createMissingMetadata: z.ZodDefault<z.ZodBoolean>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export type CommitFoodImportInput = z.input<typeof commitFoodImportSchema>;
|
|
49
|
+
export type CommitFoodImportBody = z.output<typeof commitFoodImportSchema>;
|
|
50
|
+
export declare const foodImportListQuerySchema: z.ZodObject<{
|
|
51
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
52
|
+
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export declare const foodImportRowsQuerySchema: z.ZodObject<{
|
|
55
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
56
|
+
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
57
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
58
|
+
valid: "valid";
|
|
59
|
+
invalid: "invalid";
|
|
60
|
+
duplicate_in_file: "duplicate_in_file";
|
|
61
|
+
duplicate_existing: "duplicate_existing";
|
|
62
|
+
}>>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export type FoodImportRowsQuery = z.output<typeof foodImportRowsQuerySchema>;
|
|
65
|
+
export declare const foodImportIssueSchema: z.ZodObject<{
|
|
66
|
+
column: z.ZodNullable<z.ZodString>;
|
|
67
|
+
code: z.ZodString;
|
|
68
|
+
message: z.ZodString;
|
|
69
|
+
severity: z.ZodEnum<{
|
|
70
|
+
error: "error";
|
|
71
|
+
warning: "warning";
|
|
72
|
+
}>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
export type FoodImportIssue = z.output<typeof foodImportIssueSchema>;
|
|
75
|
+
export declare const foodImportBatchResponseSchema: z.ZodObject<{
|
|
76
|
+
id: z.ZodUUID;
|
|
77
|
+
fileName: z.ZodString;
|
|
78
|
+
fileType: z.ZodEnum<{
|
|
79
|
+
csv: "csv";
|
|
80
|
+
xlsx: "xlsx";
|
|
81
|
+
}>;
|
|
82
|
+
sheetName: z.ZodNullable<z.ZodString>;
|
|
83
|
+
status: z.ZodEnum<{
|
|
84
|
+
previewed: "previewed";
|
|
85
|
+
completed: "completed";
|
|
86
|
+
expired: "expired";
|
|
87
|
+
}>;
|
|
88
|
+
mode: z.ZodNullable<z.ZodEnum<{
|
|
89
|
+
SKIP_DUPLICATES: "SKIP_DUPLICATES";
|
|
90
|
+
UPDATE_EXISTING: "UPDATE_EXISTING";
|
|
91
|
+
}>>;
|
|
92
|
+
createMissingMetadata: z.ZodBoolean;
|
|
93
|
+
totalRows: z.ZodNumber;
|
|
94
|
+
validRows: z.ZodNumber;
|
|
95
|
+
invalidRows: z.ZodNumber;
|
|
96
|
+
duplicateRows: z.ZodNumber;
|
|
97
|
+
emptyRows: z.ZodNumber;
|
|
98
|
+
createdCount: z.ZodNumber;
|
|
99
|
+
updatedCount: z.ZodNumber;
|
|
100
|
+
skippedCount: z.ZodNumber;
|
|
101
|
+
unknownMetadata: z.ZodArray<z.ZodObject<{
|
|
102
|
+
typeKey: z.ZodString;
|
|
103
|
+
values: z.ZodArray<z.ZodString>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
ignoredColumns: z.ZodArray<z.ZodString>;
|
|
106
|
+
ignoredSheets: z.ZodArray<z.ZodString>;
|
|
107
|
+
uploadedBy: z.ZodUUID;
|
|
108
|
+
expiresAt: z.ZodISODateTime;
|
|
109
|
+
committedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
110
|
+
createdAt: z.ZodISODateTime;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
export type FoodImportBatchResponse = z.output<typeof foodImportBatchResponseSchema>;
|
|
113
|
+
export declare const foodImportRowResponseSchema: z.ZodObject<{
|
|
114
|
+
id: z.ZodUUID;
|
|
115
|
+
rowNumber: z.ZodNumber;
|
|
116
|
+
status: z.ZodEnum<{
|
|
117
|
+
valid: "valid";
|
|
118
|
+
invalid: "invalid";
|
|
119
|
+
duplicate_in_file: "duplicate_in_file";
|
|
120
|
+
duplicate_existing: "duplicate_existing";
|
|
121
|
+
}>;
|
|
122
|
+
raw: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
123
|
+
parsed: z.ZodNullable<z.ZodObject<{
|
|
124
|
+
name: z.ZodString;
|
|
125
|
+
nameHi: z.ZodNullable<z.ZodString>;
|
|
126
|
+
namePa: z.ZodNullable<z.ZodString>;
|
|
127
|
+
englishAlias: z.ZodNullable<z.ZodString>;
|
|
128
|
+
category: z.ZodString;
|
|
129
|
+
subcategory: z.ZodNullable<z.ZodString>;
|
|
130
|
+
servingLabel: z.ZodString;
|
|
131
|
+
servingQuantity: z.ZodNumber;
|
|
132
|
+
servingUnit: z.ZodEnum<{
|
|
133
|
+
g: "g";
|
|
134
|
+
ml: "ml";
|
|
135
|
+
}>;
|
|
136
|
+
calories: z.ZodNumber;
|
|
137
|
+
protein: z.ZodNumber;
|
|
138
|
+
carbs: z.ZodNumber;
|
|
139
|
+
fat: z.ZodNumber;
|
|
140
|
+
sugar: z.ZodNullable<z.ZodNumber>;
|
|
141
|
+
fiber: z.ZodNullable<z.ZodNumber>;
|
|
142
|
+
solubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
143
|
+
insolubleFiber: z.ZodNullable<z.ZodNumber>;
|
|
144
|
+
tags: z.ZodArray<z.ZodString>;
|
|
145
|
+
mealTimings: z.ZodArray<z.ZodString>;
|
|
146
|
+
notes: z.ZodNullable<z.ZodString>;
|
|
147
|
+
}, z.core.$strict>>;
|
|
148
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
149
|
+
column: z.ZodNullable<z.ZodString>;
|
|
150
|
+
code: z.ZodString;
|
|
151
|
+
message: z.ZodString;
|
|
152
|
+
severity: z.ZodEnum<{
|
|
153
|
+
error: "error";
|
|
154
|
+
warning: "warning";
|
|
155
|
+
}>;
|
|
156
|
+
}, z.core.$strip>>;
|
|
157
|
+
matchedFoodId: z.ZodNullable<z.ZodUUID>;
|
|
158
|
+
resultFoodId: z.ZodNullable<z.ZodUUID>;
|
|
159
|
+
}, z.core.$strip>;
|
|
160
|
+
export type FoodImportRowResponse = z.output<typeof foodImportRowResponseSchema>;
|