@tbs-fitness/contract 0.2.0 → 0.4.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.
Files changed (48) hide show
  1. package/README.md +21 -0
  2. package/dist/cjs/app-settings/app-settings.dto.d.ts +124 -0
  3. package/dist/cjs/app-settings/app-settings.dto.js +94 -0
  4. package/dist/cjs/app-settings/index.d.ts +1 -0
  5. package/dist/cjs/app-settings/index.js +17 -0
  6. package/dist/cjs/audit/audit-log.dto.js +2 -1
  7. package/dist/cjs/auth/auth.dto.d.ts +36 -0
  8. package/dist/cjs/auth/auth.dto.js +28 -8
  9. package/dist/cjs/coach/coach-auth.dto.d.ts +12 -0
  10. package/dist/cjs/coach/coach-auth.dto.js +18 -6
  11. package/dist/cjs/common/api-response.schema.js +2 -1
  12. package/dist/cjs/common/date-time.schema.d.ts +39 -0
  13. package/dist/cjs/common/date-time.schema.js +112 -0
  14. package/dist/cjs/common/index.d.ts +1 -0
  15. package/dist/cjs/common/index.js +1 -0
  16. package/dist/cjs/communication/index.d.ts +2 -0
  17. package/dist/cjs/communication/index.js +18 -0
  18. package/dist/cjs/communication/message-catalogue.d.ts +26 -0
  19. package/dist/cjs/communication/message-catalogue.js +53 -0
  20. package/dist/cjs/communication/template.dto.d.ts +240 -0
  21. package/dist/cjs/communication/template.dto.js +206 -0
  22. package/dist/cjs/enums/index.d.ts +26 -0
  23. package/dist/cjs/enums/index.js +32 -1
  24. package/dist/cjs/feature-flags/feature-flag.dto.js +10 -9
  25. package/dist/esm/app-settings/app-settings.dto.d.ts +124 -0
  26. package/dist/esm/app-settings/app-settings.dto.js +90 -0
  27. package/dist/esm/app-settings/index.d.ts +1 -0
  28. package/dist/esm/app-settings/index.js +1 -0
  29. package/dist/esm/audit/audit-log.dto.js +2 -1
  30. package/dist/esm/auth/auth.dto.d.ts +36 -0
  31. package/dist/esm/auth/auth.dto.js +28 -8
  32. package/dist/esm/coach/coach-auth.dto.d.ts +12 -0
  33. package/dist/esm/coach/coach-auth.dto.js +19 -7
  34. package/dist/esm/common/api-response.schema.js +2 -1
  35. package/dist/esm/common/date-time.schema.d.ts +39 -0
  36. package/dist/esm/common/date-time.schema.js +107 -0
  37. package/dist/esm/common/index.d.ts +1 -0
  38. package/dist/esm/common/index.js +1 -0
  39. package/dist/esm/communication/index.d.ts +2 -0
  40. package/dist/esm/communication/index.js +2 -0
  41. package/dist/esm/communication/message-catalogue.d.ts +26 -0
  42. package/dist/esm/communication/message-catalogue.js +50 -0
  43. package/dist/esm/communication/template.dto.d.ts +240 -0
  44. package/dist/esm/communication/template.dto.js +200 -0
  45. package/dist/esm/enums/index.d.ts +26 -0
  46. package/dist/esm/enums/index.js +31 -0
  47. package/dist/esm/feature-flags/feature-flag.dto.js +10 -9
  48. package/package.json +21 -1
@@ -12,9 +12,35 @@ export type AccountStatus = (typeof ACCOUNT_STATUSES)[number];
12
12
  /** The statuses an administrator may set. Verification is never set by hand. */
13
13
  export declare const ADMIN_SETTABLE_ACCOUNT_STATUSES: readonly ["active", "disabled"];
14
14
  export type AdminSettableAccountStatus = (typeof ADMIN_SETTABLE_ACCOUNT_STATUSES)[number];
15
+ /**
16
+ * Where a user's time zone came from. `AUTO` was detected from their browser
17
+ * and may be updated when they sign in elsewhere. `MANUAL` was chosen by the
18
+ * user, and only the user changes it.
19
+ */
20
+ export declare const TIMEZONE_SOURCES: readonly ["AUTO", "MANUAL"];
21
+ export type TimezoneSource = (typeof TIMEZONE_SOURCES)[number];
15
22
  export declare const TOKEN_TRANSPORTS: readonly ["body", "cookie"];
16
23
  export type TokenTransport = (typeof TOKEN_TRANSPORTS)[number];
17
24
  export declare const AUDIT_OUTCOMES: readonly ["success", "failure"];
18
25
  export type AuditOutcome = (typeof AUDIT_OUTCOMES)[number];
19
26
  export declare const FEATURE_FLAG_RULE_TYPES: readonly ["user", "customer", "trainer", "role"];
20
27
  export type FeatureFlagRuleType = (typeof FEATURE_FLAG_RULE_TYPES)[number];
28
+ /**
29
+ * The ways a message can reach someone. WhatsApp and push are added here when
30
+ * their channel modules are built.
31
+ */
32
+ export declare const COMMUNICATION_CHANNELS: readonly ["EMAIL", "SMS"];
33
+ export type CommunicationChannel = (typeof COMMUNICATION_CHANNELS)[number];
34
+ /**
35
+ * Every message the platform sends. Each has a catalogue entry in
36
+ * `@tbs-fitness/contract/communication` saying which channels may carry it and
37
+ * which variables its sender supplies.
38
+ */
39
+ export declare const MESSAGE_TYPES: readonly ["auth.otp.signup_verification", "auth.otp.password_reset", "auth.password_reset_link"];
40
+ export type MessageType = (typeof MESSAGE_TYPES)[number];
41
+ /** What happened to one message on one channel. */
42
+ export declare const DELIVERY_STATUSES: readonly ["sent", "skipped_disabled", "skipped_unreachable", "failed", "failed_missing_variables"];
43
+ export type DeliveryStatus = (typeof DELIVERY_STATUSES)[number];
44
+ /** Only one version of a template per message type and channel is active. */
45
+ export declare const TEMPLATE_STATUSES: readonly ["draft", "active", "archived"];
46
+ export type TemplateStatus = (typeof TEMPLATE_STATUSES)[number];
@@ -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.FEATURE_FLAG_RULE_TYPES = exports.AUDIT_OUTCOMES = exports.TOKEN_TRANSPORTS = exports.ADMIN_SETTABLE_ACCOUNT_STATUSES = exports.ACCOUNT_STATUSES = exports.ROLES = exports.APP_ENVIRONMENTS = void 0;
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;
6
6
  exports.APP_ENVIRONMENTS = [
7
7
  'development',
8
8
  'staging',
@@ -21,6 +21,12 @@ exports.ACCOUNT_STATUSES = [
21
21
  ];
22
22
  /** The statuses an administrator may set. Verification is never set by hand. */
23
23
  exports.ADMIN_SETTABLE_ACCOUNT_STATUSES = ['active', 'disabled'];
24
+ /**
25
+ * Where a user's time zone came from. `AUTO` was detected from their browser
26
+ * and may be updated when they sign in elsewhere. `MANUAL` was chosen by the
27
+ * user, and only the user changes it.
28
+ */
29
+ exports.TIMEZONE_SOURCES = ['AUTO', 'MANUAL'];
24
30
  exports.TOKEN_TRANSPORTS = ['body', 'cookie'];
25
31
  exports.AUDIT_OUTCOMES = ['success', 'failure'];
26
32
  exports.FEATURE_FLAG_RULE_TYPES = [
@@ -29,3 +35,28 @@ exports.FEATURE_FLAG_RULE_TYPES = [
29
35
  'trainer',
30
36
  'role',
31
37
  ];
38
+ /**
39
+ * The ways a message can reach someone. WhatsApp and push are added here when
40
+ * their channel modules are built.
41
+ */
42
+ exports.COMMUNICATION_CHANNELS = ['EMAIL', 'SMS'];
43
+ /**
44
+ * Every message the platform sends. Each has a catalogue entry in
45
+ * `@tbs-fitness/contract/communication` saying which channels may carry it and
46
+ * which variables its sender supplies.
47
+ */
48
+ exports.MESSAGE_TYPES = [
49
+ 'auth.otp.signup_verification',
50
+ 'auth.otp.password_reset',
51
+ 'auth.password_reset_link',
52
+ ];
53
+ /** What happened to one message on one channel. */
54
+ exports.DELIVERY_STATUSES = [
55
+ 'sent',
56
+ 'skipped_disabled',
57
+ 'skipped_unreachable',
58
+ 'failed',
59
+ 'failed_missing_variables',
60
+ ];
61
+ /** Only one version of a template per message type and channel is active. */
62
+ exports.TEMPLATE_STATUSES = ['draft', 'active', 'archived'];
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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;
4
4
  const zod_1 = require("zod");
5
+ const date_time_schema_js_1 = require("../common/date-time.schema.js");
5
6
  const pagination_schema_js_1 = require("../common/pagination.schema.js");
6
7
  const safe_text_schema_js_1 = require("../common/safe-text.schema.js");
7
8
  const index_js_1 = require("../enums/index.js");
@@ -17,7 +18,7 @@ const keySchema = zod_1.z
17
18
  const nameSchema = (0, safe_text_schema_js_1.safeTextSchema)(120);
18
19
  const descriptionSchema = (0, safe_text_schema_js_1.safeTextSchema)(500);
19
20
  const percentageSchema = zod_1.z.number().int().min(0).max(100);
20
- const timestampSchema = zod_1.z.iso.datetime({ offset: true });
21
+ const timestampSchema = date_time_schema_js_1.instantInputSchema;
21
22
  /** Lower-cased, so that it matches IDs as they come from the database. */
22
23
  const accountIdSchema = zod_1.z.string().toLowerCase().pipe(zod_1.z.uuid());
23
24
  const scheduleIsOrdered = ({ activationAt, expiresAt, }) => !activationAt || !expiresAt || new Date(activationAt) < new Date(expiresAt);
@@ -95,8 +96,8 @@ exports.ruleResponseSchema = zod_1.z.object({
95
96
  ruleType: zod_1.z.enum(index_js_1.FEATURE_FLAG_RULE_TYPES),
96
97
  ruleValue: zod_1.z.string(),
97
98
  enabled: zod_1.z.boolean(),
98
- createdAt: zod_1.z.iso.datetime(),
99
- updatedAt: zod_1.z.iso.datetime(),
99
+ createdAt: date_time_schema_js_1.utcTimestampSchema,
100
+ updatedAt: date_time_schema_js_1.utcTimestampSchema,
100
101
  });
101
102
  exports.flagResponseSchema = zod_1.z.object({
102
103
  id: zod_1.z.uuid(),
@@ -106,13 +107,13 @@ exports.flagResponseSchema = zod_1.z.object({
106
107
  environment: zod_1.z.enum(index_js_1.APP_ENVIRONMENTS),
107
108
  enabled: zod_1.z.boolean(),
108
109
  rolloutPercentage: zod_1.z.number().int(),
109
- activationAt: zod_1.z.iso.datetime().nullable(),
110
- expiresAt: zod_1.z.iso.datetime().nullable(),
110
+ activationAt: date_time_schema_js_1.utcTimestampSchema.nullable(),
111
+ expiresAt: date_time_schema_js_1.utcTimestampSchema.nullable(),
111
112
  version: zod_1.z.number().int(),
112
113
  createdBy: zod_1.z.uuid(),
113
114
  updatedBy: zod_1.z.uuid(),
114
- createdAt: zod_1.z.iso.datetime(),
115
- updatedAt: zod_1.z.iso.datetime(),
115
+ createdAt: date_time_schema_js_1.utcTimestampSchema,
116
+ updatedAt: date_time_schema_js_1.utcTimestampSchema,
116
117
  rules: zod_1.z.array(exports.ruleResponseSchema),
117
118
  });
118
119
  exports.auditLogResponseSchema = zod_1.z.object({
@@ -124,12 +125,12 @@ exports.auditLogResponseSchema = zod_1.z.object({
124
125
  action: zod_1.z.string(),
125
126
  previousValue: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable(),
126
127
  newValue: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable(),
127
- createdAt: zod_1.z.iso.datetime(),
128
+ createdAt: date_time_schema_js_1.utcTimestampSchema,
128
129
  });
129
130
  exports.killSwitchResponseSchema = zod_1.z.object({
130
131
  environment: zod_1.z.enum(index_js_1.APP_ENVIRONMENTS),
131
132
  engaged: zod_1.z.boolean(),
132
133
  reason: zod_1.z.string().nullable(),
133
134
  updatedBy: zod_1.z.uuid().nullable(),
134
- updatedAt: zod_1.z.iso.datetime().nullable(),
135
+ updatedAt: date_time_schema_js_1.utcTimestampSchema.nullable(),
135
136
  });
@@ -0,0 +1,124 @@
1
+ import { z } from 'zod';
2
+ import { type MessageType } from '../enums/index.js';
3
+ /**
4
+ * Runtime settings an administrator changes without a deploy. Each key has a
5
+ * value schema here, which both the server and the admin screen use. A key
6
+ * with no saved value uses its default.
7
+ */
8
+ export declare const APP_SETTING_KEYS: readonly ["communication.channels", "communication.messages"];
9
+ export type AppSettingKey = (typeof APP_SETTING_KEYS)[number];
10
+ /** A switch per channel. */
11
+ export declare const channelSwitchesSchema: z.ZodObject<{
12
+ EMAIL: z.ZodBoolean;
13
+ SMS: z.ZodBoolean;
14
+ }, z.core.$strict>;
15
+ export type ChannelSwitches = z.output<typeof channelSwitchesSchema>;
16
+ /**
17
+ * Master switches: a channel switched off here sends nothing, whatever the
18
+ * per-message settings say.
19
+ */
20
+ export declare const communicationChannelsSettingSchema: z.ZodObject<{
21
+ EMAIL: z.ZodBoolean;
22
+ SMS: z.ZodBoolean;
23
+ }, z.core.$strict>;
24
+ /**
25
+ * Per message type and channel. A type missing from a saved value uses its
26
+ * catalogue defaults, so a newly added message type needs no data change.
27
+ */
28
+ export declare const communicationMessagesSettingSchema: z.ZodRecord<z.ZodEnum<{
29
+ "auth.otp.signup_verification": "auth.otp.signup_verification";
30
+ "auth.otp.password_reset": "auth.otp.password_reset";
31
+ "auth.password_reset_link": "auth.password_reset_link";
32
+ }> & z.core.$partial, z.ZodObject<{
33
+ EMAIL: z.ZodBoolean;
34
+ SMS: z.ZodBoolean;
35
+ }, z.core.$strict>>;
36
+ export type CommunicationMessagesSetting = z.output<typeof communicationMessagesSettingSchema>;
37
+ export declare const APP_SETTING_VALUE_SCHEMAS: {
38
+ readonly 'communication.channels': z.ZodObject<{
39
+ EMAIL: z.ZodBoolean;
40
+ SMS: z.ZodBoolean;
41
+ }, z.core.$strict>;
42
+ readonly 'communication.messages': z.ZodRecord<z.ZodEnum<{
43
+ "auth.otp.signup_verification": "auth.otp.signup_verification";
44
+ "auth.otp.password_reset": "auth.otp.password_reset";
45
+ "auth.password_reset_link": "auth.password_reset_link";
46
+ }> & z.core.$partial, z.ZodObject<{
47
+ EMAIL: z.ZodBoolean;
48
+ SMS: z.ZodBoolean;
49
+ }, z.core.$strict>>;
50
+ };
51
+ export interface AppSettingValues {
52
+ 'communication.channels': ChannelSwitches;
53
+ 'communication.messages': CommunicationMessagesSetting;
54
+ }
55
+ /** Every message type, with its catalogue defaults: the effective value with nothing saved. */
56
+ export declare function defaultMessageSettings(): Record<MessageType, ChannelSwitches>;
57
+ export declare const APP_SETTING_DEFAULTS: AppSettingValues;
58
+ export declare const appSettingKeyParamSchema: z.ZodEnum<{
59
+ "communication.channels": "communication.channels";
60
+ "communication.messages": "communication.messages";
61
+ }>;
62
+ export declare const appSettingResponseSchema: z.ZodObject<{
63
+ key: z.ZodEnum<{
64
+ "communication.channels": "communication.channels";
65
+ "communication.messages": "communication.messages";
66
+ }>;
67
+ label: z.ZodString;
68
+ description: z.ZodString;
69
+ value: z.ZodUnknown;
70
+ defaultValue: z.ZodUnknown;
71
+ version: z.ZodNumber;
72
+ updatedBy: z.ZodNullable<z.ZodUUID>;
73
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
74
+ }, z.core.$strip>;
75
+ export type AppSettingResponse = z.output<typeof appSettingResponseSchema>;
76
+ export declare const appSettingListResponseSchema: z.ZodArray<z.ZodObject<{
77
+ key: z.ZodEnum<{
78
+ "communication.channels": "communication.channels";
79
+ "communication.messages": "communication.messages";
80
+ }>;
81
+ label: z.ZodString;
82
+ description: z.ZodString;
83
+ value: z.ZodUnknown;
84
+ defaultValue: z.ZodUnknown;
85
+ version: z.ZodNumber;
86
+ updatedBy: z.ZodNullable<z.ZodUUID>;
87
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
88
+ }, z.core.$strip>>;
89
+ /**
90
+ * Replaces a setting's value. `version` must be the one last read, so a
91
+ * change made in between is not silently overwritten. The value is checked
92
+ * against the key's schema on the server.
93
+ */
94
+ export declare const updateAppSettingSchema: z.ZodObject<{
95
+ value: z.ZodUnknown;
96
+ version: z.ZodNumber;
97
+ }, z.core.$strict>;
98
+ export type UpdateAppSettingInput = z.input<typeof updateAppSettingSchema>;
99
+ export type UpdateAppSettingBody = z.output<typeof updateAppSettingSchema>;
100
+ export declare const appSettingHistoryEntrySchema: z.ZodObject<{
101
+ id: z.ZodUUID;
102
+ key: z.ZodEnum<{
103
+ "communication.channels": "communication.channels";
104
+ "communication.messages": "communication.messages";
105
+ }>;
106
+ previousValue: z.ZodUnknown;
107
+ newValue: z.ZodUnknown;
108
+ version: z.ZodNumber;
109
+ actorUserId: z.ZodUUID;
110
+ createdAt: z.ZodISODateTime;
111
+ }, z.core.$strip>;
112
+ export type AppSettingHistoryEntry = z.output<typeof appSettingHistoryEntrySchema>;
113
+ export declare const appSettingHistoryResponseSchema: z.ZodArray<z.ZodObject<{
114
+ id: z.ZodUUID;
115
+ key: z.ZodEnum<{
116
+ "communication.channels": "communication.channels";
117
+ "communication.messages": "communication.messages";
118
+ }>;
119
+ previousValue: z.ZodUnknown;
120
+ newValue: z.ZodUnknown;
121
+ version: z.ZodNumber;
122
+ actorUserId: z.ZodUUID;
123
+ createdAt: z.ZodISODateTime;
124
+ }, z.core.$strip>>;
@@ -0,0 +1,90 @@
1
+ import { z } from 'zod';
2
+ import { utcTimestampSchema } from '../common/date-time.schema.js';
3
+ import { MESSAGE_CATALOGUE } from '../communication/message-catalogue.js';
4
+ import { MESSAGE_TYPES } from '../enums/index.js';
5
+ /**
6
+ * Runtime settings an administrator changes without a deploy. Each key has a
7
+ * value schema here, which both the server and the admin screen use. A key
8
+ * with no saved value uses its default.
9
+ */
10
+ export const APP_SETTING_KEYS = [
11
+ 'communication.channels',
12
+ 'communication.messages',
13
+ ];
14
+ /** A switch per channel. */
15
+ export const channelSwitchesSchema = z.strictObject({
16
+ EMAIL: z.boolean(),
17
+ SMS: z.boolean(),
18
+ });
19
+ /**
20
+ * Master switches: a channel switched off here sends nothing, whatever the
21
+ * per-message settings say.
22
+ */
23
+ export const communicationChannelsSettingSchema = channelSwitchesSchema;
24
+ /**
25
+ * Per message type and channel. A type missing from a saved value uses its
26
+ * catalogue defaults, so a newly added message type needs no data change.
27
+ */
28
+ export const communicationMessagesSettingSchema = z
29
+ .partialRecord(z.enum(MESSAGE_TYPES), channelSwitchesSchema)
30
+ .superRefine((value, ctx) => {
31
+ for (const [type, switches] of Object.entries(value)) {
32
+ const allowed = MESSAGE_CATALOGUE[type].channels;
33
+ for (const [channel, on] of Object.entries(switches ?? {})) {
34
+ if (on && !allowed.includes(channel)) {
35
+ ctx.addIssue({
36
+ code: 'custom',
37
+ path: [type, channel],
38
+ message: `${MESSAGE_CATALOGUE[type].label} cannot be sent by ${channel}`,
39
+ });
40
+ }
41
+ }
42
+ }
43
+ });
44
+ export const APP_SETTING_VALUE_SCHEMAS = {
45
+ 'communication.channels': communicationChannelsSettingSchema,
46
+ 'communication.messages': communicationMessagesSettingSchema,
47
+ };
48
+ /** Every message type, with its catalogue defaults: the effective value with nothing saved. */
49
+ export function defaultMessageSettings() {
50
+ return Object.fromEntries(MESSAGE_TYPES.map((type) => [
51
+ type,
52
+ { ...MESSAGE_CATALOGUE[type].defaultChannels },
53
+ ]));
54
+ }
55
+ export const APP_SETTING_DEFAULTS = {
56
+ 'communication.channels': { EMAIL: true, SMS: true },
57
+ 'communication.messages': defaultMessageSettings(),
58
+ };
59
+ export const appSettingKeyParamSchema = z.enum(APP_SETTING_KEYS);
60
+ export const appSettingResponseSchema = z.object({
61
+ key: z.enum(APP_SETTING_KEYS),
62
+ label: z.string(),
63
+ description: z.string(),
64
+ value: z.unknown(),
65
+ defaultValue: z.unknown(),
66
+ /** 0 until the setting is first saved. Send it back to update. */
67
+ version: z.number().int(),
68
+ updatedBy: z.uuid().nullable(),
69
+ updatedAt: utcTimestampSchema.nullable(),
70
+ });
71
+ export const appSettingListResponseSchema = z.array(appSettingResponseSchema);
72
+ /**
73
+ * Replaces a setting's value. `version` must be the one last read, so a
74
+ * change made in between is not silently overwritten. The value is checked
75
+ * against the key's schema on the server.
76
+ */
77
+ export const updateAppSettingSchema = z.strictObject({
78
+ value: z.unknown(),
79
+ version: z.number().int().min(0),
80
+ });
81
+ export const appSettingHistoryEntrySchema = z.object({
82
+ id: z.uuid(),
83
+ key: z.enum(APP_SETTING_KEYS),
84
+ previousValue: z.unknown(),
85
+ newValue: z.unknown(),
86
+ version: z.number().int(),
87
+ actorUserId: z.uuid(),
88
+ createdAt: utcTimestampSchema,
89
+ });
90
+ export const appSettingHistoryResponseSchema = z.array(appSettingHistoryEntrySchema);
@@ -0,0 +1 @@
1
+ export * from './app-settings.dto.js';
@@ -0,0 +1 @@
1
+ export * from './app-settings.dto.js';
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { utcTimestampSchema } from '../common/date-time.schema.js';
2
3
  import { paginationQuerySchema } from '../common/pagination.schema.js';
3
4
  import { AUDIT_OUTCOMES } from '../enums/index.js';
4
5
  export const auditLogQuerySchema = paginationQuerySchema.extend({
@@ -17,5 +18,5 @@ export const auditLogResponseSchema = z.object({
17
18
  requestId: z.string().nullable(),
18
19
  correlationId: z.string().nullable(),
19
20
  metadata: z.record(z.string(), z.unknown()).nullable(),
20
- createdAt: z.iso.datetime(),
21
+ createdAt: utcTimestampSchema,
21
22
  });
@@ -68,6 +68,32 @@ export declare const tokenResponseSchema: z.ZodObject<{
68
68
  sessionId: z.ZodUUID;
69
69
  }, z.core.$strip>;
70
70
  export type TokenResponse = z.output<typeof tokenResponseSchema>;
71
+ /**
72
+ * A user's time zone preference: an IANA zone, and whether it was detected
73
+ * (`AUTO`) or chosen (`MANUAL`).
74
+ */
75
+ export declare const timezonePreferenceSchema: z.ZodObject<{
76
+ timezone: z.ZodString;
77
+ timezoneSource: z.ZodEnum<{
78
+ AUTO: "AUTO";
79
+ MANUAL: "MANUAL";
80
+ }>;
81
+ }, z.core.$strip>;
82
+ export type TimezonePreference = z.output<typeof timezonePreferenceSchema>;
83
+ /**
84
+ * Sets the signed-in user's own time zone. `MANUAL` (the default) is a choice
85
+ * the user made. `AUTO` records a detected zone that a later sign-in may
86
+ * replace.
87
+ */
88
+ export declare const updateTimezoneSchema: z.ZodObject<{
89
+ timezone: z.ZodPipe<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>, z.ZodTransform<string, string>>;
90
+ source: z.ZodDefault<z.ZodEnum<{
91
+ AUTO: "AUTO";
92
+ MANUAL: "MANUAL";
93
+ }>>;
94
+ }, z.core.$strict>;
95
+ export type UpdateTimezoneInput = z.input<typeof updateTimezoneSchema>;
96
+ export type UpdateTimezoneBody = z.output<typeof updateTimezoneSchema>;
71
97
  export declare const accountResponseSchema: z.ZodObject<{
72
98
  id: z.ZodUUID;
73
99
  email: z.ZodString;
@@ -79,6 +105,11 @@ export declare const accountResponseSchema: z.ZodObject<{
79
105
  roles: z.ZodArray<z.ZodString>;
80
106
  permissions: z.ZodArray<z.ZodString>;
81
107
  lastLoginAt: z.ZodNullable<z.ZodISODateTime>;
108
+ timezone: z.ZodString;
109
+ timezoneSource: z.ZodEnum<{
110
+ AUTO: "AUTO";
111
+ MANUAL: "MANUAL";
112
+ }>;
82
113
  }, z.core.$strip>;
83
114
  export type AccountResponse = z.output<typeof accountResponseSchema>;
84
115
  export declare const loginResponseSchema: z.ZodObject<{
@@ -99,6 +130,11 @@ export declare const loginResponseSchema: z.ZodObject<{
99
130
  roles: z.ZodArray<z.ZodString>;
100
131
  permissions: z.ZodArray<z.ZodString>;
101
132
  lastLoginAt: z.ZodNullable<z.ZodISODateTime>;
133
+ timezone: z.ZodString;
134
+ timezoneSource: z.ZodEnum<{
135
+ AUTO: "AUTO";
136
+ MANUAL: "MANUAL";
137
+ }>;
102
138
  }, z.core.$strip>;
103
139
  }, z.core.$strip>;
104
140
  export type LoginResponse = z.output<typeof loginResponseSchema>;
@@ -1,7 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { emailSchema } from '../common/contact.schema.js';
3
+ import { timezoneSchema, utcTimestampSchema, } from '../common/date-time.schema.js';
3
4
  import { safeTextSchema } from '../common/safe-text.schema.js';
4
- import { ACCOUNT_STATUSES, ADMIN_SETTABLE_ACCOUNT_STATUSES, ROLES, TOKEN_TRANSPORTS, } from '../enums/index.js';
5
+ import { ACCOUNT_STATUSES, ADMIN_SETTABLE_ACCOUNT_STATUSES, ROLES, TIMEZONE_SOURCES, TOKEN_TRANSPORTS, } from '../enums/index.js';
5
6
  // Per OWASP: length is what matters, with no composition rules. The upper limit
6
7
  // stops very long inputs from being used to exhaust the hashing function.
7
8
  export const MIN_PASSWORD_LENGTH = 12;
@@ -62,15 +63,34 @@ export const tokenResponseSchema = z.object({
62
63
  csrfToken: z.string().optional(),
63
64
  sessionId: z.uuid(),
64
65
  });
65
- export const accountResponseSchema = z.object({
66
+ /**
67
+ * A user's time zone preference: an IANA zone, and whether it was detected
68
+ * (`AUTO`) or chosen (`MANUAL`).
69
+ */
70
+ export const timezonePreferenceSchema = z.object({
71
+ timezone: z.string(),
72
+ timezoneSource: z.enum(TIMEZONE_SOURCES),
73
+ });
74
+ /**
75
+ * Sets the signed-in user's own time zone. `MANUAL` (the default) is a choice
76
+ * the user made. `AUTO` records a detected zone that a later sign-in may
77
+ * replace.
78
+ */
79
+ export const updateTimezoneSchema = z.strictObject({
80
+ timezone: timezoneSchema,
81
+ source: z.enum(TIMEZONE_SOURCES).default('MANUAL'),
82
+ });
83
+ export const accountResponseSchema = z
84
+ .object({
66
85
  id: z.uuid(),
67
86
  email: z.string(),
68
87
  role: z.enum(ROLES),
69
88
  /** @deprecated Always `[role]`. Kept for clients written before `role`. */
70
89
  roles: z.array(z.string()),
71
90
  permissions: z.array(z.string()),
72
- lastLoginAt: z.iso.datetime().nullable(),
73
- });
91
+ lastLoginAt: utcTimestampSchema.nullable(),
92
+ })
93
+ .extend(timezonePreferenceSchema.shape);
74
94
  export const loginResponseSchema = tokenResponseSchema.extend({
75
95
  account: accountResponseSchema,
76
96
  });
@@ -78,9 +98,9 @@ export const sessionResponseSchema = z.object({
78
98
  id: z.uuid(),
79
99
  deviceName: z.string().nullable(),
80
100
  userAgent: z.string().nullable(),
81
- createdAt: z.iso.datetime(),
82
- lastUsedAt: z.iso.datetime(),
83
- expiresAt: z.iso.datetime(),
101
+ createdAt: utcTimestampSchema,
102
+ lastUsedAt: utcTimestampSchema,
103
+ expiresAt: utcTimestampSchema,
84
104
  current: z.boolean(),
85
105
  });
86
106
  export const logoutAllResponseSchema = z.object({
@@ -94,7 +114,7 @@ export const adminAccountResponseSchema = z.object({
94
114
  email: z.string(),
95
115
  role: z.enum(ROLES),
96
116
  status: z.enum(ACCOUNT_STATUSES),
97
- lastLoginAt: z.iso.datetime().nullable(),
117
+ lastLoginAt: utcTimestampSchema.nullable(),
98
118
  });
99
119
  export const revokedSessionsResponseSchema = z.object({
100
120
  revokedSessions: z.number().int(),
@@ -4,6 +4,7 @@ export declare const coachSignupSchema: z.ZodObject<{
4
4
  email: z.ZodPipe<z.ZodString, z.ZodEmail>;
5
5
  phone: z.ZodOptional<z.ZodString>;
6
6
  password: z.ZodString;
7
+ timezone: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<string | undefined, unknown>>>;
7
8
  }, z.core.$strict>;
8
9
  export type CoachSignupInput = z.input<typeof coachSignupSchema>;
9
10
  export type CoachSignupBody = z.output<typeof coachSignupSchema>;
@@ -29,6 +30,7 @@ export declare const coachLoginSchema: z.ZodObject<{
29
30
  password: z.ZodString;
30
31
  deviceName: z.ZodOptional<z.ZodString>;
31
32
  rememberMe: z.ZodDefault<z.ZodBoolean>;
33
+ timezone: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<string | undefined, unknown>>>;
32
34
  }, z.core.$strict>;
33
35
  export type CoachLoginInput = z.input<typeof coachLoginSchema>;
34
36
  export type CoachLoginBody = z.output<typeof coachLoginSchema>;
@@ -74,6 +76,11 @@ export declare const coachProfileSchema: z.ZodObject<{
74
76
  emailVerifiedAt: z.ZodNullable<z.ZodISODateTime>;
75
77
  lastLoginAt: z.ZodNullable<z.ZodISODateTime>;
76
78
  createdAt: z.ZodISODateTime;
79
+ timezone: z.ZodString;
80
+ timezoneSource: z.ZodEnum<{
81
+ AUTO: "AUTO";
82
+ MANUAL: "MANUAL";
83
+ }>;
77
84
  }, z.core.$strip>;
78
85
  export type CoachProfile = z.output<typeof coachProfileSchema>;
79
86
  export declare const coachLoginResponseSchema: z.ZodObject<{
@@ -97,6 +104,11 @@ export declare const coachLoginResponseSchema: z.ZodObject<{
97
104
  emailVerifiedAt: z.ZodNullable<z.ZodISODateTime>;
98
105
  lastLoginAt: z.ZodNullable<z.ZodISODateTime>;
99
106
  createdAt: z.ZodISODateTime;
107
+ timezone: z.ZodString;
108
+ timezoneSource: z.ZodEnum<{
109
+ AUTO: "AUTO";
110
+ MANUAL: "MANUAL";
111
+ }>;
100
112
  }, z.core.$strip>;
101
113
  }, z.core.$strip>;
102
114
  export type CoachLoginResponse = z.output<typeof coachLoginResponseSchema>;
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
- import { loginSchema, newPasswordSchema, opaqueTokenSchema, otpCodeSchema, tokenResponseSchema, } from '../auth/auth.dto.js';
2
+ import { loginSchema, newPasswordSchema, opaqueTokenSchema, otpCodeSchema, timezonePreferenceSchema, tokenResponseSchema, } from '../auth/auth.dto.js';
3
3
  import { emailSchema, phoneSchema } from '../common/contact.schema.js';
4
+ import { detectedTimezoneSchema, utcTimestampSchema, } from '../common/date-time.schema.js';
4
5
  import { safeTextSchema } from '../common/safe-text.schema.js';
5
6
  import { ACCOUNT_STATUSES } from '../enums/index.js';
6
7
  export const coachSignupSchema = z.strictObject({
@@ -8,6 +9,8 @@ export const coachSignupSchema = z.strictObject({
8
9
  email: emailSchema,
9
10
  phone: phoneSchema.optional(),
10
11
  password: newPasswordSchema,
12
+ /** The browser's time zone. Missing or unusable becomes UTC on the server. */
13
+ timezone: detectedTimezoneSchema,
11
14
  });
12
15
  /** Used by both resend endpoints and by forgot-password. */
13
16
  export const otpEmailSchema = z.strictObject({ email: emailSchema });
@@ -22,7 +25,14 @@ export const verifyOtpSchema = z.strictObject({
22
25
  */
23
26
  export const coachLoginSchema = loginSchema
24
27
  .omit({ tokenTransport: true })
25
- .extend({ rememberMe: z.boolean().default(true) });
28
+ .extend({
29
+ rememberMe: z.boolean().default(true),
30
+ /**
31
+ * The browser's time zone. It replaces the saved one only while the
32
+ * coach's preference is `AUTO`; a manual choice is never overwritten.
33
+ */
34
+ timezone: detectedTimezoneSchema,
35
+ });
26
36
  export const resetPasswordSchema = z.strictObject({
27
37
  resetToken: opaqueTokenSchema,
28
38
  newPassword: newPasswordSchema,
@@ -46,17 +56,19 @@ export const resetTokenResponseSchema = z.object({
46
56
  resetToken: z.string(),
47
57
  expiresInSeconds: z.number().int(),
48
58
  });
49
- export const coachProfileSchema = z.object({
59
+ export const coachProfileSchema = z
60
+ .object({
50
61
  id: z.uuid(),
51
62
  email: z.string(),
52
63
  fullName: z.string().nullable(),
53
64
  phone: z.string().nullable(),
54
65
  role: z.literal('COACH'),
55
66
  status: z.enum(ACCOUNT_STATUSES),
56
- emailVerifiedAt: z.iso.datetime().nullable(),
57
- lastLoginAt: z.iso.datetime().nullable(),
58
- createdAt: z.iso.datetime(),
59
- });
67
+ emailVerifiedAt: utcTimestampSchema.nullable(),
68
+ lastLoginAt: utcTimestampSchema.nullable(),
69
+ createdAt: utcTimestampSchema,
70
+ })
71
+ .extend(timezonePreferenceSchema.shape);
60
72
  export const coachLoginResponseSchema = tokenResponseSchema.extend({
61
73
  coach: coachProfileSchema,
62
74
  });
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { utcTimestampSchema } from './date-time.schema.js';
2
3
  import { paginationMetaSchema, } from './pagination.schema.js';
3
4
  export const apiErrorResponseSchema = z.object({
4
5
  error: z.object({
@@ -13,7 +14,7 @@ export const apiErrorResponseSchema = z.object({
13
14
  }))
14
15
  .optional(),
15
16
  requestId: z.string(),
16
- timestamp: z.iso.datetime(),
17
+ timestamp: utcTimestampSchema,
17
18
  path: z.string(),
18
19
  }),
19
20
  });
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The platform's date and time rules, shared so the backend and the apps
4
+ * validate them identically:
5
+ *
6
+ * - An instant (something that happened at one moment) travels as ISO 8601.
7
+ * Responses always use UTC with `Z`. Requests may use `Z` or an explicit
8
+ * offset, but never a bare local time, which would be ambiguous.
9
+ * - A date-only value (a birthday, an expiry date) travels as `YYYY-MM-DD` and
10
+ * is never converted between time zones.
11
+ * - A time zone is an IANA identifier such as `Asia/Kolkata`. Abbreviations
12
+ * (`IST`) and fixed offsets (`+05:30`) are refused, because offsets change
13
+ * with daylight saving.
14
+ */
15
+ export declare const DEFAULT_TIMEZONE = "UTC";
16
+ /**
17
+ * True for `UTC` and for an IANA `Area/Location` name the runtime's time zone
18
+ * database knows. Runs anywhere `Intl` does, so the browser and the server
19
+ * agree.
20
+ */
21
+ export declare function isValidTimezone(value: unknown): value is string;
22
+ /** The current IANA name for a zone, such as `Asia/Kolkata` for `Asia/Calcutta`. */
23
+ export declare function canonicalTimezone(value: string): string;
24
+ export declare const timezoneSchema: z.ZodPipe<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>, z.ZodTransform<string, string>>;
25
+ /**
26
+ * A time zone the client detected and suggests, such as at sign-up. A missing
27
+ * or unusable value becomes `undefined` instead of failing the request, and the
28
+ * server then applies its default.
29
+ */
30
+ export declare const detectedTimezoneSchema: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<string | undefined, unknown>>>;
31
+ /** An instant in a response: ISO 8601 in UTC, ending in `Z`. */
32
+ export declare const utcTimestampSchema: z.ZodISODateTime;
33
+ /**
34
+ * An instant in a request: ISO 8601 with `Z` or an explicit offset, such as
35
+ * `2026-11-02T15:00:00+05:30`. A local time without either is refused.
36
+ */
37
+ export declare const instantInputSchema: z.ZodISODateTime;
38
+ /** A calendar date with no time and no zone, such as `2026-11-02`. */
39
+ export declare const dateOnlySchema: z.ZodString;