@sunsteel/contracts 0.27.0 → 0.29.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/dist/index.cjs CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ ACHIEVEMENT_CATEGORIES: () => ACHIEVEMENT_CATEGORIES,
24
+ ACHIEVEMENT_DEFINITIONS: () => ACHIEVEMENT_DEFINITIONS,
23
25
  EXERCISE_EQUIPMENT: () => EXERCISE_EQUIPMENT,
24
26
  EXERCISE_MECHANICS: () => EXERCISE_MECHANICS,
25
27
  FOLLOW_SUGGESTIONS_DEFAULT_LIMIT: () => FOLLOW_SUGGESTIONS_DEFAULT_LIMIT,
@@ -237,6 +239,62 @@ var MEASURABLE_GOAL_TYPES = [
237
239
  var MEASURABLE_GOAL_DIRECTIONS = ["AT_LEAST", "AT_MOST"];
238
240
  var MEASURABLE_GOALS_MAX = 8;
239
241
 
242
+ // src/achievements.ts
243
+ var ACHIEVEMENT_CATEGORIES = [
244
+ "SESSIONS",
245
+ "SETS",
246
+ "VOLUME_KG",
247
+ "RECORDS",
248
+ "STREAK_DAYS"
249
+ ];
250
+ var formatCount = (value) => value.toLocaleString("en-US");
251
+ function titleFor(category, threshold) {
252
+ const count = formatCount(threshold);
253
+ switch (category) {
254
+ case "SESSIONS":
255
+ return threshold === 1 ? "First Session" : `${count} Sessions`;
256
+ case "SETS":
257
+ return `${count} Sets Completed`;
258
+ case "VOLUME_KG":
259
+ return `${count} kg Moved`;
260
+ case "RECORDS":
261
+ return threshold === 1 ? "First Record" : `${count} Records`;
262
+ case "STREAK_DAYS":
263
+ return `${count}-Day Streak`;
264
+ }
265
+ }
266
+ function descriptionFor(category, threshold) {
267
+ const count = formatCount(threshold);
268
+ switch (category) {
269
+ case "SESSIONS":
270
+ return `Complete ${count} ${threshold === 1 ? "training session" : "training sessions"}.`;
271
+ case "SETS":
272
+ return `Complete ${count} logged sets.`;
273
+ case "VOLUME_KG":
274
+ return `Accumulate ${count} kg of external-load volume.`;
275
+ case "RECORDS":
276
+ return `Establish records for ${count} ${threshold === 1 ? "exercise" : "exercises"}.`;
277
+ case "STREAK_DAYS":
278
+ return `Build a ${count}-day training streak.`;
279
+ }
280
+ }
281
+ var THRESHOLDS = {
282
+ SESSIONS: [1, 10, 25, 50, 100],
283
+ SETS: [10, 100, 250, 500, 1e3],
284
+ VOLUME_KG: [1e3, 1e4, 5e4, 1e5, 25e4],
285
+ RECORDS: [1, 5, 10, 25, 50],
286
+ STREAK_DAYS: [2, 3, 5, 10, 20]
287
+ };
288
+ var ACHIEVEMENT_DEFINITIONS = ACHIEVEMENT_CATEGORIES.flatMap(
289
+ (category) => THRESHOLDS[category].map((threshold) => ({
290
+ id: `${category.toLowerCase()}:${threshold}`,
291
+ category,
292
+ threshold,
293
+ title: titleFor(category, threshold),
294
+ description: descriptionFor(category, threshold)
295
+ }))
296
+ );
297
+
240
298
  // src/workout.ts
241
299
  var SESSION_SHARE_FIELDS = [
242
300
  "duration",
@@ -258,7 +316,9 @@ var SESSION_SHARE_MAX_ACTIVE_LINKS = 10;
258
316
  var TRAINING_EVENT_TYPES = [
259
317
  "SESSION_COMPLETED",
260
318
  "PERSONAL_RECORD",
261
- "PROGRESSION_CHANGED"
319
+ "PROGRESSION_CHANGED",
320
+ "STREAK_MILESTONE",
321
+ "ACHIEVEMENT_UNLOCKED"
262
322
  ];
263
323
  var PROGRESS_TIMELINE_EVENT_TYPES = [
264
324
  "PERSONAL_RECORD",
@@ -266,6 +326,8 @@ var PROGRESS_TIMELINE_EVENT_TYPES = [
266
326
  ];
267
327
  // Annotate the CommonJS export names for ESM import in node:
268
328
  0 && (module.exports = {
329
+ ACHIEVEMENT_CATEGORIES,
330
+ ACHIEVEMENT_DEFINITIONS,
269
331
  EXERCISE_EQUIPMENT,
270
332
  EXERCISE_MECHANICS,
271
333
  FOLLOW_SUGGESTIONS_DEFAULT_LIMIT,
package/dist/index.d.cts CHANGED
@@ -50,6 +50,12 @@ interface WorkoutSession {
50
50
  notes?: string | null;
51
51
  lastActivityAt?: IsoDateString | null;
52
52
  setLogs?: SetLog[];
53
+ /**
54
+ * LIVE-11: slots performed with a different exercise in this session. The
55
+ * routine day (snapshot) keeps the original prescription; set logs for a
56
+ * substituted slot carry the substitute's `exerciseId`.
57
+ */
58
+ exerciseSubstitutions?: SessionExerciseSubstitution[];
53
59
  reused?: boolean;
54
60
  routine?: {
55
61
  id: string;
@@ -154,6 +160,38 @@ interface UpsertSetLogRequest {
154
160
  rpe?: number;
155
161
  isCompleted?: boolean;
156
162
  }
163
+ /**
164
+ * LIVE-11: an exercise performed in place of one routine slot for a single
165
+ * session. The substitute's muscles are captured when the swap is made, so
166
+ * later catalog changes cannot rewrite what the session trained.
167
+ */
168
+ interface SessionExerciseSubstitution {
169
+ /** The replaced slot, as in `routineDay.exercises[].id`. */
170
+ routineExerciseId: string;
171
+ exercise: {
172
+ id: string;
173
+ name: string;
174
+ primaryMuscles: MuscleGroup[];
175
+ secondaryMuscles: MuscleGroup[];
176
+ };
177
+ substitutedAt: IsoDateString;
178
+ }
179
+ /** Body of PUT /workouts/sessions/:id/exercises/:routineExerciseId/substitution. */
180
+ interface SubstituteSessionExerciseRequest {
181
+ exerciseId: string;
182
+ /** Also use this exercise in the routine from the next session on. */
183
+ applyToRoutine?: boolean;
184
+ }
185
+ /**
186
+ * Stable successful response of the substitution PUT and DELETE. A swap is
187
+ * refused once the slot has a completed set; incomplete drafts for the slot
188
+ * are cleared because their values belonged to the other exercise.
189
+ */
190
+ interface SubstituteSessionExerciseResponse {
191
+ session: WorkoutSession;
192
+ /** True only when `applyToRoutine` was asked for and the routine still has the slot. */
193
+ routineUpdated: boolean;
194
+ }
157
195
  type PersonalRecordKind = 'WEIGHT' | 'REPS' | 'VOLUME' | 'ESTIMATED_1RM';
158
196
  /** A record frontier crossed by the set mutation that produced this response. */
159
197
  interface EarnedPersonalRecord {
@@ -288,7 +326,7 @@ interface WorkoutStatsResponse {
288
326
  activeDaysThisWeek: number;
289
327
  }
290
328
 
291
- declare const TRAINING_EVENT_TYPES: readonly ["SESSION_COMPLETED", "PERSONAL_RECORD", "PROGRESSION_CHANGED"];
329
+ declare const TRAINING_EVENT_TYPES: readonly ["SESSION_COMPLETED", "PERSONAL_RECORD", "PROGRESSION_CHANGED", "STREAK_MILESTONE", "ACHIEVEMENT_UNLOCKED"];
292
330
  type TrainingEventType = (typeof TRAINING_EVENT_TYPES)[number];
293
331
  /** Stable successful response of GET /workouts/progress. */
294
332
  interface WorkoutProgressQuery {
@@ -883,6 +921,42 @@ interface PersonalGoalsResponse {
883
921
  goals: PersonalGoalProgress[];
884
922
  }
885
923
 
924
+ declare const ACHIEVEMENT_CATEGORIES: readonly ["SESSIONS", "SETS", "VOLUME_KG", "RECORDS", "STREAK_DAYS"];
925
+ type AchievementCategory = (typeof ACHIEVEMENT_CATEGORIES)[number];
926
+ interface AchievementDefinition {
927
+ id: string;
928
+ category: AchievementCategory;
929
+ threshold: number;
930
+ title: string;
931
+ description: string;
932
+ }
933
+ /** Stable milestone catalog shared by the writer and every presentation. */
934
+ declare const ACHIEVEMENT_DEFINITIONS: readonly AchievementDefinition[];
935
+ interface AchievementUnlockedEventPayload extends AchievementDefinition {
936
+ schemaVersion: 1;
937
+ backfilled: boolean;
938
+ }
939
+ interface StreakMilestoneEventPayload {
940
+ schemaVersion: 1;
941
+ achievementId: string;
942
+ streakDays: number;
943
+ backfilled: boolean;
944
+ }
945
+ interface EarnedAchievement extends AchievementDefinition {
946
+ eventId: string;
947
+ unlockedAt: IsoDateString;
948
+ sourceSessionId: string | null;
949
+ /** True when existing verified history was recognized after ACH-01 shipped. */
950
+ backfilled: boolean;
951
+ }
952
+ /** Stable successful response of GET /achievements. */
953
+ interface AchievementsResponse {
954
+ analyticsReady: boolean;
955
+ earnedCount: number;
956
+ availableCount: number;
957
+ achievements: EarnedAchievement[];
958
+ }
959
+
886
960
  interface RoutineSet {
887
961
  setNumber: number;
888
962
  repType: RepType;
@@ -947,4 +1021,4 @@ interface CreateRoutineRequest {
947
1021
  }
948
1022
  type UpdateRoutineRequest = Partial<CreateRoutineRequest>;
949
1023
 
950
- export { type Brand, type CreateRoutineDayInput, type CreateRoutineExerciseInput, type CreateRoutineRequest, type CreateSessionShareRequest, EXERCISE_EQUIPMENT, EXERCISE_MECHANICS, type EarnedPersonalRecord, type Exercise, type ExerciseEquipment, type ExerciseId, type ExerciseMechanic, type ExercisePerformanceHistoryQuery, type ExercisePerformanceHistoryResponse, type ExercisePerformancePrescription, type ExercisePerformancePrescriptionSet, type ExercisePerformanceSession, type ExercisePerformanceSet, type ExercisePerformanceSummary, type ExerciseStrengthSummary, type ExerciseStrengthTrendPoint, type ExerciseStrengthTrendQuery, type ExerciseStrengthTrendResponse, FOLLOW_SUGGESTIONS_DEFAULT_LIMIT, FOLLOW_SUGGESTIONS_MAX_LIMIT, FOLLOW_SUGGESTION_REASONS, type FinishStatus, type FinishWorkoutRequest, type FinishWorkoutResponse, type FollowSuggestion, type FollowSuggestionReason, type FollowSuggestionsResponse, type IsoDateString, type ListSessionsParams, MEASURABLE_GOALS_MAX, MEASURABLE_GOAL_DIRECTIONS, MEASURABLE_GOAL_TYPES, MOVEMENT_PATTERNS, MUSCLE_GROUPS, type MeasurableGoal, type MeasurableGoalDirection, type MeasurableGoalExercise, type MeasurableGoalInput, type MeasurableGoalType, type MovementPattern, type MuscleGroup, type MuscleGroupHeatmapQuery, type MuscleGroupHeatmapResponse, type MuscleGroupHeatmapValue, type MuscleGroupHeatmapWeek, type MuscleVolumeTrendSeries, PREFERRED_TRAINING_STYLE_VALUES, PROFILE_BIO_MAX_LENGTH, PROFILE_FAVORITE_EXERCISES_MAX, PROFILE_LOCATION_MAX_LENGTH, PROFILE_TRAINING_DISCIPLINES_MAX, PROFILE_TRAINING_GOALS_MAX, PROFILE_VISIBILITY_VALUES, PROGRESSION_SCHEMES, PROGRESS_TIMELINE_EVENT_TYPES, type PaginatedResponse, type PersonalGoalProgress, type PersonalGoalsResponse, type PersonalRecordEntry, type PersonalRecordKind, type PlatePairInventory, type PreferredTrainingStyle, type PreviousPerformanceResponse, type PreviousSessionRecap, type PreviousSetPerformance, type ProfileDiscoverySettings, type ProfileFavoriteExercise, type ProfilePrivacySettings, type ProfileViewerAccess, type ProfileVisibility, type ProgressTimelineEventType, type ProgressTimelineItem, type ProgressTimelinePersonalRecordItem, type ProgressTimelineProgressionItem, type ProgressTimelineQuery, type ProgressTimelineRecordPerformance, type ProgressTimelineRecordReason, type ProgressTimelineResponse, type ProgressTimelineSessionContext, type ProgressionChange, type ProgressionRule, type ProgressionScheme, type ProgressionSetChange, type PublicBodyMetrics, type PublicTrainingSummary, type PublicUserProfile, RELATIONSHIP_LIST_DEFAULT_LIMIT, RELATIONSHIP_LIST_KINDS, RELATIONSHIP_LIST_MAX_LIMIT, REP_TYPES, RESERVED_USERNAMES, type RecentActivityEntry, type RelationshipListKind, type RelationshipListQuery, type RelationshipListResponse, type RelationshipMember, type RepType, type ReplaceMeasurableGoalsRequest, type ReplaceTrainingLocationsRequest, type Routine, type RoutineDay, type RoutineDayId, type RoutineExercise, type RoutineId, type RoutineSet, SESSION_SHARE_DEFAULT_FIELDS, SESSION_SHARE_FIELDS, SESSION_SHARE_MAX_ACTIVE_LINKS, SEXES, type SessionComparisonExercise, type SessionComparisonQuery, type SessionComparisonResponse, type SessionComparisonRoutineDay, type SessionComparisonSession, type SessionComparisonSet, type SessionRecapRecord, type SessionShare, type SessionShareField, type SessionShareListResponse, type SetAccountTimeZoneRequest, type SetLog, type Sex, type SharedSessionOwner, type SharedSessionRecap, type StartWorkoutRequest, type StartWorkoutResponse, type SupabaseAuthResponse, type SupabaseAuthUser, type SupabaseMigrationResponse, TRAINING_DISCIPLINE_VALUES, TRAINING_EVENT_TYPES, TRAINING_EXPERIENCE_LEVEL_VALUES, TRAINING_GOAL_VALUES, type TrainingDiscipline, type TrainingEventType, type TrainingExperienceLevel, type TrainingGoal, type TrainingIdentity, type TrainingLocationPreference, type TrainingLocationPreferenceInput, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH, USERNAME_PATTERN_SOURCE, type UpdateProfileDiscoveryRequest, type UpdateProfilePrivacyRequest, type UpdateProfileRequest, type UpdateRoutineRequest, type UpsertSetLogRequest, type UpsertSetLogResponse, type UserId, type UserProfile, type UserSearchResponse, type VolumeTrendPoint, type VolumeTrendQuery, type VolumeTrendResponse, type VolumeTrendSeries, WEIGHT_UNITS, WORKOUT_SESSION_STATUSES, type WeightUnit, type WorkoutAnalyticsStatus, type WorkoutProgressQuery, type WorkoutProgressResponse, type WorkoutSession, type WorkoutSessionId, type WorkoutSessionListResponse, type WorkoutSessionRecap, type WorkoutSessionSnapshotV1, type WorkoutSessionStatus, type WorkoutSessionSummary, type WorkoutStatsQuery, type WorkoutStatsResponse };
1024
+ export { ACHIEVEMENT_CATEGORIES, ACHIEVEMENT_DEFINITIONS, type AchievementCategory, type AchievementDefinition, type AchievementUnlockedEventPayload, type AchievementsResponse, type Brand, type CreateRoutineDayInput, type CreateRoutineExerciseInput, type CreateRoutineRequest, type CreateSessionShareRequest, EXERCISE_EQUIPMENT, EXERCISE_MECHANICS, type EarnedAchievement, type EarnedPersonalRecord, type Exercise, type ExerciseEquipment, type ExerciseId, type ExerciseMechanic, type ExercisePerformanceHistoryQuery, type ExercisePerformanceHistoryResponse, type ExercisePerformancePrescription, type ExercisePerformancePrescriptionSet, type ExercisePerformanceSession, type ExercisePerformanceSet, type ExercisePerformanceSummary, type ExerciseStrengthSummary, type ExerciseStrengthTrendPoint, type ExerciseStrengthTrendQuery, type ExerciseStrengthTrendResponse, FOLLOW_SUGGESTIONS_DEFAULT_LIMIT, FOLLOW_SUGGESTIONS_MAX_LIMIT, FOLLOW_SUGGESTION_REASONS, type FinishStatus, type FinishWorkoutRequest, type FinishWorkoutResponse, type FollowSuggestion, type FollowSuggestionReason, type FollowSuggestionsResponse, type IsoDateString, type ListSessionsParams, MEASURABLE_GOALS_MAX, MEASURABLE_GOAL_DIRECTIONS, MEASURABLE_GOAL_TYPES, MOVEMENT_PATTERNS, MUSCLE_GROUPS, type MeasurableGoal, type MeasurableGoalDirection, type MeasurableGoalExercise, type MeasurableGoalInput, type MeasurableGoalType, type MovementPattern, type MuscleGroup, type MuscleGroupHeatmapQuery, type MuscleGroupHeatmapResponse, type MuscleGroupHeatmapValue, type MuscleGroupHeatmapWeek, type MuscleVolumeTrendSeries, PREFERRED_TRAINING_STYLE_VALUES, PROFILE_BIO_MAX_LENGTH, PROFILE_FAVORITE_EXERCISES_MAX, PROFILE_LOCATION_MAX_LENGTH, PROFILE_TRAINING_DISCIPLINES_MAX, PROFILE_TRAINING_GOALS_MAX, PROFILE_VISIBILITY_VALUES, PROGRESSION_SCHEMES, PROGRESS_TIMELINE_EVENT_TYPES, type PaginatedResponse, type PersonalGoalProgress, type PersonalGoalsResponse, type PersonalRecordEntry, type PersonalRecordKind, type PlatePairInventory, type PreferredTrainingStyle, type PreviousPerformanceResponse, type PreviousSessionRecap, type PreviousSetPerformance, type ProfileDiscoverySettings, type ProfileFavoriteExercise, type ProfilePrivacySettings, type ProfileViewerAccess, type ProfileVisibility, type ProgressTimelineEventType, type ProgressTimelineItem, type ProgressTimelinePersonalRecordItem, type ProgressTimelineProgressionItem, type ProgressTimelineQuery, type ProgressTimelineRecordPerformance, type ProgressTimelineRecordReason, type ProgressTimelineResponse, type ProgressTimelineSessionContext, type ProgressionChange, type ProgressionRule, type ProgressionScheme, type ProgressionSetChange, type PublicBodyMetrics, type PublicTrainingSummary, type PublicUserProfile, RELATIONSHIP_LIST_DEFAULT_LIMIT, RELATIONSHIP_LIST_KINDS, RELATIONSHIP_LIST_MAX_LIMIT, REP_TYPES, RESERVED_USERNAMES, type RecentActivityEntry, type RelationshipListKind, type RelationshipListQuery, type RelationshipListResponse, type RelationshipMember, type RepType, type ReplaceMeasurableGoalsRequest, type ReplaceTrainingLocationsRequest, type Routine, type RoutineDay, type RoutineDayId, type RoutineExercise, type RoutineId, type RoutineSet, SESSION_SHARE_DEFAULT_FIELDS, SESSION_SHARE_FIELDS, SESSION_SHARE_MAX_ACTIVE_LINKS, SEXES, type SessionComparisonExercise, type SessionComparisonQuery, type SessionComparisonResponse, type SessionComparisonRoutineDay, type SessionComparisonSession, type SessionComparisonSet, type SessionExerciseSubstitution, type SessionRecapRecord, type SessionShare, type SessionShareField, type SessionShareListResponse, type SetAccountTimeZoneRequest, type SetLog, type Sex, type SharedSessionOwner, type SharedSessionRecap, type StartWorkoutRequest, type StartWorkoutResponse, type StreakMilestoneEventPayload, type SubstituteSessionExerciseRequest, type SubstituteSessionExerciseResponse, type SupabaseAuthResponse, type SupabaseAuthUser, type SupabaseMigrationResponse, TRAINING_DISCIPLINE_VALUES, TRAINING_EVENT_TYPES, TRAINING_EXPERIENCE_LEVEL_VALUES, TRAINING_GOAL_VALUES, type TrainingDiscipline, type TrainingEventType, type TrainingExperienceLevel, type TrainingGoal, type TrainingIdentity, type TrainingLocationPreference, type TrainingLocationPreferenceInput, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH, USERNAME_PATTERN_SOURCE, type UpdateProfileDiscoveryRequest, type UpdateProfilePrivacyRequest, type UpdateProfileRequest, type UpdateRoutineRequest, type UpsertSetLogRequest, type UpsertSetLogResponse, type UserId, type UserProfile, type UserSearchResponse, type VolumeTrendPoint, type VolumeTrendQuery, type VolumeTrendResponse, type VolumeTrendSeries, WEIGHT_UNITS, WORKOUT_SESSION_STATUSES, type WeightUnit, type WorkoutAnalyticsStatus, type WorkoutProgressQuery, type WorkoutProgressResponse, type WorkoutSession, type WorkoutSessionId, type WorkoutSessionListResponse, type WorkoutSessionRecap, type WorkoutSessionSnapshotV1, type WorkoutSessionStatus, type WorkoutSessionSummary, type WorkoutStatsQuery, type WorkoutStatsResponse };
package/dist/index.d.ts CHANGED
@@ -50,6 +50,12 @@ interface WorkoutSession {
50
50
  notes?: string | null;
51
51
  lastActivityAt?: IsoDateString | null;
52
52
  setLogs?: SetLog[];
53
+ /**
54
+ * LIVE-11: slots performed with a different exercise in this session. The
55
+ * routine day (snapshot) keeps the original prescription; set logs for a
56
+ * substituted slot carry the substitute's `exerciseId`.
57
+ */
58
+ exerciseSubstitutions?: SessionExerciseSubstitution[];
53
59
  reused?: boolean;
54
60
  routine?: {
55
61
  id: string;
@@ -154,6 +160,38 @@ interface UpsertSetLogRequest {
154
160
  rpe?: number;
155
161
  isCompleted?: boolean;
156
162
  }
163
+ /**
164
+ * LIVE-11: an exercise performed in place of one routine slot for a single
165
+ * session. The substitute's muscles are captured when the swap is made, so
166
+ * later catalog changes cannot rewrite what the session trained.
167
+ */
168
+ interface SessionExerciseSubstitution {
169
+ /** The replaced slot, as in `routineDay.exercises[].id`. */
170
+ routineExerciseId: string;
171
+ exercise: {
172
+ id: string;
173
+ name: string;
174
+ primaryMuscles: MuscleGroup[];
175
+ secondaryMuscles: MuscleGroup[];
176
+ };
177
+ substitutedAt: IsoDateString;
178
+ }
179
+ /** Body of PUT /workouts/sessions/:id/exercises/:routineExerciseId/substitution. */
180
+ interface SubstituteSessionExerciseRequest {
181
+ exerciseId: string;
182
+ /** Also use this exercise in the routine from the next session on. */
183
+ applyToRoutine?: boolean;
184
+ }
185
+ /**
186
+ * Stable successful response of the substitution PUT and DELETE. A swap is
187
+ * refused once the slot has a completed set; incomplete drafts for the slot
188
+ * are cleared because their values belonged to the other exercise.
189
+ */
190
+ interface SubstituteSessionExerciseResponse {
191
+ session: WorkoutSession;
192
+ /** True only when `applyToRoutine` was asked for and the routine still has the slot. */
193
+ routineUpdated: boolean;
194
+ }
157
195
  type PersonalRecordKind = 'WEIGHT' | 'REPS' | 'VOLUME' | 'ESTIMATED_1RM';
158
196
  /** A record frontier crossed by the set mutation that produced this response. */
159
197
  interface EarnedPersonalRecord {
@@ -288,7 +326,7 @@ interface WorkoutStatsResponse {
288
326
  activeDaysThisWeek: number;
289
327
  }
290
328
 
291
- declare const TRAINING_EVENT_TYPES: readonly ["SESSION_COMPLETED", "PERSONAL_RECORD", "PROGRESSION_CHANGED"];
329
+ declare const TRAINING_EVENT_TYPES: readonly ["SESSION_COMPLETED", "PERSONAL_RECORD", "PROGRESSION_CHANGED", "STREAK_MILESTONE", "ACHIEVEMENT_UNLOCKED"];
292
330
  type TrainingEventType = (typeof TRAINING_EVENT_TYPES)[number];
293
331
  /** Stable successful response of GET /workouts/progress. */
294
332
  interface WorkoutProgressQuery {
@@ -883,6 +921,42 @@ interface PersonalGoalsResponse {
883
921
  goals: PersonalGoalProgress[];
884
922
  }
885
923
 
924
+ declare const ACHIEVEMENT_CATEGORIES: readonly ["SESSIONS", "SETS", "VOLUME_KG", "RECORDS", "STREAK_DAYS"];
925
+ type AchievementCategory = (typeof ACHIEVEMENT_CATEGORIES)[number];
926
+ interface AchievementDefinition {
927
+ id: string;
928
+ category: AchievementCategory;
929
+ threshold: number;
930
+ title: string;
931
+ description: string;
932
+ }
933
+ /** Stable milestone catalog shared by the writer and every presentation. */
934
+ declare const ACHIEVEMENT_DEFINITIONS: readonly AchievementDefinition[];
935
+ interface AchievementUnlockedEventPayload extends AchievementDefinition {
936
+ schemaVersion: 1;
937
+ backfilled: boolean;
938
+ }
939
+ interface StreakMilestoneEventPayload {
940
+ schemaVersion: 1;
941
+ achievementId: string;
942
+ streakDays: number;
943
+ backfilled: boolean;
944
+ }
945
+ interface EarnedAchievement extends AchievementDefinition {
946
+ eventId: string;
947
+ unlockedAt: IsoDateString;
948
+ sourceSessionId: string | null;
949
+ /** True when existing verified history was recognized after ACH-01 shipped. */
950
+ backfilled: boolean;
951
+ }
952
+ /** Stable successful response of GET /achievements. */
953
+ interface AchievementsResponse {
954
+ analyticsReady: boolean;
955
+ earnedCount: number;
956
+ availableCount: number;
957
+ achievements: EarnedAchievement[];
958
+ }
959
+
886
960
  interface RoutineSet {
887
961
  setNumber: number;
888
962
  repType: RepType;
@@ -947,4 +1021,4 @@ interface CreateRoutineRequest {
947
1021
  }
948
1022
  type UpdateRoutineRequest = Partial<CreateRoutineRequest>;
949
1023
 
950
- export { type Brand, type CreateRoutineDayInput, type CreateRoutineExerciseInput, type CreateRoutineRequest, type CreateSessionShareRequest, EXERCISE_EQUIPMENT, EXERCISE_MECHANICS, type EarnedPersonalRecord, type Exercise, type ExerciseEquipment, type ExerciseId, type ExerciseMechanic, type ExercisePerformanceHistoryQuery, type ExercisePerformanceHistoryResponse, type ExercisePerformancePrescription, type ExercisePerformancePrescriptionSet, type ExercisePerformanceSession, type ExercisePerformanceSet, type ExercisePerformanceSummary, type ExerciseStrengthSummary, type ExerciseStrengthTrendPoint, type ExerciseStrengthTrendQuery, type ExerciseStrengthTrendResponse, FOLLOW_SUGGESTIONS_DEFAULT_LIMIT, FOLLOW_SUGGESTIONS_MAX_LIMIT, FOLLOW_SUGGESTION_REASONS, type FinishStatus, type FinishWorkoutRequest, type FinishWorkoutResponse, type FollowSuggestion, type FollowSuggestionReason, type FollowSuggestionsResponse, type IsoDateString, type ListSessionsParams, MEASURABLE_GOALS_MAX, MEASURABLE_GOAL_DIRECTIONS, MEASURABLE_GOAL_TYPES, MOVEMENT_PATTERNS, MUSCLE_GROUPS, type MeasurableGoal, type MeasurableGoalDirection, type MeasurableGoalExercise, type MeasurableGoalInput, type MeasurableGoalType, type MovementPattern, type MuscleGroup, type MuscleGroupHeatmapQuery, type MuscleGroupHeatmapResponse, type MuscleGroupHeatmapValue, type MuscleGroupHeatmapWeek, type MuscleVolumeTrendSeries, PREFERRED_TRAINING_STYLE_VALUES, PROFILE_BIO_MAX_LENGTH, PROFILE_FAVORITE_EXERCISES_MAX, PROFILE_LOCATION_MAX_LENGTH, PROFILE_TRAINING_DISCIPLINES_MAX, PROFILE_TRAINING_GOALS_MAX, PROFILE_VISIBILITY_VALUES, PROGRESSION_SCHEMES, PROGRESS_TIMELINE_EVENT_TYPES, type PaginatedResponse, type PersonalGoalProgress, type PersonalGoalsResponse, type PersonalRecordEntry, type PersonalRecordKind, type PlatePairInventory, type PreferredTrainingStyle, type PreviousPerformanceResponse, type PreviousSessionRecap, type PreviousSetPerformance, type ProfileDiscoverySettings, type ProfileFavoriteExercise, type ProfilePrivacySettings, type ProfileViewerAccess, type ProfileVisibility, type ProgressTimelineEventType, type ProgressTimelineItem, type ProgressTimelinePersonalRecordItem, type ProgressTimelineProgressionItem, type ProgressTimelineQuery, type ProgressTimelineRecordPerformance, type ProgressTimelineRecordReason, type ProgressTimelineResponse, type ProgressTimelineSessionContext, type ProgressionChange, type ProgressionRule, type ProgressionScheme, type ProgressionSetChange, type PublicBodyMetrics, type PublicTrainingSummary, type PublicUserProfile, RELATIONSHIP_LIST_DEFAULT_LIMIT, RELATIONSHIP_LIST_KINDS, RELATIONSHIP_LIST_MAX_LIMIT, REP_TYPES, RESERVED_USERNAMES, type RecentActivityEntry, type RelationshipListKind, type RelationshipListQuery, type RelationshipListResponse, type RelationshipMember, type RepType, type ReplaceMeasurableGoalsRequest, type ReplaceTrainingLocationsRequest, type Routine, type RoutineDay, type RoutineDayId, type RoutineExercise, type RoutineId, type RoutineSet, SESSION_SHARE_DEFAULT_FIELDS, SESSION_SHARE_FIELDS, SESSION_SHARE_MAX_ACTIVE_LINKS, SEXES, type SessionComparisonExercise, type SessionComparisonQuery, type SessionComparisonResponse, type SessionComparisonRoutineDay, type SessionComparisonSession, type SessionComparisonSet, type SessionRecapRecord, type SessionShare, type SessionShareField, type SessionShareListResponse, type SetAccountTimeZoneRequest, type SetLog, type Sex, type SharedSessionOwner, type SharedSessionRecap, type StartWorkoutRequest, type StartWorkoutResponse, type SupabaseAuthResponse, type SupabaseAuthUser, type SupabaseMigrationResponse, TRAINING_DISCIPLINE_VALUES, TRAINING_EVENT_TYPES, TRAINING_EXPERIENCE_LEVEL_VALUES, TRAINING_GOAL_VALUES, type TrainingDiscipline, type TrainingEventType, type TrainingExperienceLevel, type TrainingGoal, type TrainingIdentity, type TrainingLocationPreference, type TrainingLocationPreferenceInput, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH, USERNAME_PATTERN_SOURCE, type UpdateProfileDiscoveryRequest, type UpdateProfilePrivacyRequest, type UpdateProfileRequest, type UpdateRoutineRequest, type UpsertSetLogRequest, type UpsertSetLogResponse, type UserId, type UserProfile, type UserSearchResponse, type VolumeTrendPoint, type VolumeTrendQuery, type VolumeTrendResponse, type VolumeTrendSeries, WEIGHT_UNITS, WORKOUT_SESSION_STATUSES, type WeightUnit, type WorkoutAnalyticsStatus, type WorkoutProgressQuery, type WorkoutProgressResponse, type WorkoutSession, type WorkoutSessionId, type WorkoutSessionListResponse, type WorkoutSessionRecap, type WorkoutSessionSnapshotV1, type WorkoutSessionStatus, type WorkoutSessionSummary, type WorkoutStatsQuery, type WorkoutStatsResponse };
1024
+ export { ACHIEVEMENT_CATEGORIES, ACHIEVEMENT_DEFINITIONS, type AchievementCategory, type AchievementDefinition, type AchievementUnlockedEventPayload, type AchievementsResponse, type Brand, type CreateRoutineDayInput, type CreateRoutineExerciseInput, type CreateRoutineRequest, type CreateSessionShareRequest, EXERCISE_EQUIPMENT, EXERCISE_MECHANICS, type EarnedAchievement, type EarnedPersonalRecord, type Exercise, type ExerciseEquipment, type ExerciseId, type ExerciseMechanic, type ExercisePerformanceHistoryQuery, type ExercisePerformanceHistoryResponse, type ExercisePerformancePrescription, type ExercisePerformancePrescriptionSet, type ExercisePerformanceSession, type ExercisePerformanceSet, type ExercisePerformanceSummary, type ExerciseStrengthSummary, type ExerciseStrengthTrendPoint, type ExerciseStrengthTrendQuery, type ExerciseStrengthTrendResponse, FOLLOW_SUGGESTIONS_DEFAULT_LIMIT, FOLLOW_SUGGESTIONS_MAX_LIMIT, FOLLOW_SUGGESTION_REASONS, type FinishStatus, type FinishWorkoutRequest, type FinishWorkoutResponse, type FollowSuggestion, type FollowSuggestionReason, type FollowSuggestionsResponse, type IsoDateString, type ListSessionsParams, MEASURABLE_GOALS_MAX, MEASURABLE_GOAL_DIRECTIONS, MEASURABLE_GOAL_TYPES, MOVEMENT_PATTERNS, MUSCLE_GROUPS, type MeasurableGoal, type MeasurableGoalDirection, type MeasurableGoalExercise, type MeasurableGoalInput, type MeasurableGoalType, type MovementPattern, type MuscleGroup, type MuscleGroupHeatmapQuery, type MuscleGroupHeatmapResponse, type MuscleGroupHeatmapValue, type MuscleGroupHeatmapWeek, type MuscleVolumeTrendSeries, PREFERRED_TRAINING_STYLE_VALUES, PROFILE_BIO_MAX_LENGTH, PROFILE_FAVORITE_EXERCISES_MAX, PROFILE_LOCATION_MAX_LENGTH, PROFILE_TRAINING_DISCIPLINES_MAX, PROFILE_TRAINING_GOALS_MAX, PROFILE_VISIBILITY_VALUES, PROGRESSION_SCHEMES, PROGRESS_TIMELINE_EVENT_TYPES, type PaginatedResponse, type PersonalGoalProgress, type PersonalGoalsResponse, type PersonalRecordEntry, type PersonalRecordKind, type PlatePairInventory, type PreferredTrainingStyle, type PreviousPerformanceResponse, type PreviousSessionRecap, type PreviousSetPerformance, type ProfileDiscoverySettings, type ProfileFavoriteExercise, type ProfilePrivacySettings, type ProfileViewerAccess, type ProfileVisibility, type ProgressTimelineEventType, type ProgressTimelineItem, type ProgressTimelinePersonalRecordItem, type ProgressTimelineProgressionItem, type ProgressTimelineQuery, type ProgressTimelineRecordPerformance, type ProgressTimelineRecordReason, type ProgressTimelineResponse, type ProgressTimelineSessionContext, type ProgressionChange, type ProgressionRule, type ProgressionScheme, type ProgressionSetChange, type PublicBodyMetrics, type PublicTrainingSummary, type PublicUserProfile, RELATIONSHIP_LIST_DEFAULT_LIMIT, RELATIONSHIP_LIST_KINDS, RELATIONSHIP_LIST_MAX_LIMIT, REP_TYPES, RESERVED_USERNAMES, type RecentActivityEntry, type RelationshipListKind, type RelationshipListQuery, type RelationshipListResponse, type RelationshipMember, type RepType, type ReplaceMeasurableGoalsRequest, type ReplaceTrainingLocationsRequest, type Routine, type RoutineDay, type RoutineDayId, type RoutineExercise, type RoutineId, type RoutineSet, SESSION_SHARE_DEFAULT_FIELDS, SESSION_SHARE_FIELDS, SESSION_SHARE_MAX_ACTIVE_LINKS, SEXES, type SessionComparisonExercise, type SessionComparisonQuery, type SessionComparisonResponse, type SessionComparisonRoutineDay, type SessionComparisonSession, type SessionComparisonSet, type SessionExerciseSubstitution, type SessionRecapRecord, type SessionShare, type SessionShareField, type SessionShareListResponse, type SetAccountTimeZoneRequest, type SetLog, type Sex, type SharedSessionOwner, type SharedSessionRecap, type StartWorkoutRequest, type StartWorkoutResponse, type StreakMilestoneEventPayload, type SubstituteSessionExerciseRequest, type SubstituteSessionExerciseResponse, type SupabaseAuthResponse, type SupabaseAuthUser, type SupabaseMigrationResponse, TRAINING_DISCIPLINE_VALUES, TRAINING_EVENT_TYPES, TRAINING_EXPERIENCE_LEVEL_VALUES, TRAINING_GOAL_VALUES, type TrainingDiscipline, type TrainingEventType, type TrainingExperienceLevel, type TrainingGoal, type TrainingIdentity, type TrainingLocationPreference, type TrainingLocationPreferenceInput, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH, USERNAME_PATTERN_SOURCE, type UpdateProfileDiscoveryRequest, type UpdateProfilePrivacyRequest, type UpdateProfileRequest, type UpdateRoutineRequest, type UpsertSetLogRequest, type UpsertSetLogResponse, type UserId, type UserProfile, type UserSearchResponse, type VolumeTrendPoint, type VolumeTrendQuery, type VolumeTrendResponse, type VolumeTrendSeries, WEIGHT_UNITS, WORKOUT_SESSION_STATUSES, type WeightUnit, type WorkoutAnalyticsStatus, type WorkoutProgressQuery, type WorkoutProgressResponse, type WorkoutSession, type WorkoutSessionId, type WorkoutSessionListResponse, type WorkoutSessionRecap, type WorkoutSessionSnapshotV1, type WorkoutSessionStatus, type WorkoutSessionSummary, type WorkoutStatsQuery, type WorkoutStatsResponse };
package/dist/index.js CHANGED
@@ -175,6 +175,62 @@ var MEASURABLE_GOAL_TYPES = [
175
175
  var MEASURABLE_GOAL_DIRECTIONS = ["AT_LEAST", "AT_MOST"];
176
176
  var MEASURABLE_GOALS_MAX = 8;
177
177
 
178
+ // src/achievements.ts
179
+ var ACHIEVEMENT_CATEGORIES = [
180
+ "SESSIONS",
181
+ "SETS",
182
+ "VOLUME_KG",
183
+ "RECORDS",
184
+ "STREAK_DAYS"
185
+ ];
186
+ var formatCount = (value) => value.toLocaleString("en-US");
187
+ function titleFor(category, threshold) {
188
+ const count = formatCount(threshold);
189
+ switch (category) {
190
+ case "SESSIONS":
191
+ return threshold === 1 ? "First Session" : `${count} Sessions`;
192
+ case "SETS":
193
+ return `${count} Sets Completed`;
194
+ case "VOLUME_KG":
195
+ return `${count} kg Moved`;
196
+ case "RECORDS":
197
+ return threshold === 1 ? "First Record" : `${count} Records`;
198
+ case "STREAK_DAYS":
199
+ return `${count}-Day Streak`;
200
+ }
201
+ }
202
+ function descriptionFor(category, threshold) {
203
+ const count = formatCount(threshold);
204
+ switch (category) {
205
+ case "SESSIONS":
206
+ return `Complete ${count} ${threshold === 1 ? "training session" : "training sessions"}.`;
207
+ case "SETS":
208
+ return `Complete ${count} logged sets.`;
209
+ case "VOLUME_KG":
210
+ return `Accumulate ${count} kg of external-load volume.`;
211
+ case "RECORDS":
212
+ return `Establish records for ${count} ${threshold === 1 ? "exercise" : "exercises"}.`;
213
+ case "STREAK_DAYS":
214
+ return `Build a ${count}-day training streak.`;
215
+ }
216
+ }
217
+ var THRESHOLDS = {
218
+ SESSIONS: [1, 10, 25, 50, 100],
219
+ SETS: [10, 100, 250, 500, 1e3],
220
+ VOLUME_KG: [1e3, 1e4, 5e4, 1e5, 25e4],
221
+ RECORDS: [1, 5, 10, 25, 50],
222
+ STREAK_DAYS: [2, 3, 5, 10, 20]
223
+ };
224
+ var ACHIEVEMENT_DEFINITIONS = ACHIEVEMENT_CATEGORIES.flatMap(
225
+ (category) => THRESHOLDS[category].map((threshold) => ({
226
+ id: `${category.toLowerCase()}:${threshold}`,
227
+ category,
228
+ threshold,
229
+ title: titleFor(category, threshold),
230
+ description: descriptionFor(category, threshold)
231
+ }))
232
+ );
233
+
178
234
  // src/workout.ts
179
235
  var SESSION_SHARE_FIELDS = [
180
236
  "duration",
@@ -196,13 +252,17 @@ var SESSION_SHARE_MAX_ACTIVE_LINKS = 10;
196
252
  var TRAINING_EVENT_TYPES = [
197
253
  "SESSION_COMPLETED",
198
254
  "PERSONAL_RECORD",
199
- "PROGRESSION_CHANGED"
255
+ "PROGRESSION_CHANGED",
256
+ "STREAK_MILESTONE",
257
+ "ACHIEVEMENT_UNLOCKED"
200
258
  ];
201
259
  var PROGRESS_TIMELINE_EVENT_TYPES = [
202
260
  "PERSONAL_RECORD",
203
261
  "PROGRESSION_CHANGED"
204
262
  ];
205
263
  export {
264
+ ACHIEVEMENT_CATEGORIES,
265
+ ACHIEVEMENT_DEFINITIONS,
206
266
  EXERCISE_EQUIPMENT,
207
267
  EXERCISE_MECHANICS,
208
268
  FOLLOW_SUGGESTIONS_DEFAULT_LIMIT,
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "@sunsteel/contracts",
3
- "version": "0.27.0",
4
- "repository": {
5
- "type": "git",
6
- "url": "git+https://github.com/ezee969/sunsteel-contracts.git"
7
- },
8
- "private": false,
9
- "engines": {
10
- "node": ">=20.11"
11
- },
12
- "type": "module",
13
- "sideEffects": false,
14
- "main": "./dist/index.cjs",
15
- "module": "./dist/index.js",
16
- "types": "./dist/index.d.ts",
17
- "exports": {
18
- ".": {
19
- "types": "./dist/index.d.ts",
20
- "import": "./dist/index.js",
21
- "require": "./dist/index.cjs"
22
- }
23
- },
24
- "files": [
25
- "dist"
26
- ],
27
- "scripts": {
28
- "build": "tsup src/index.ts --format esm,cjs --dts --clean",
29
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
30
- "typecheck": "tsc --noEmit",
31
- "lint": "npm run typecheck",
32
- "verify": "npm run typecheck && npm run build",
33
- "verify:security": "npm audit",
34
- "prepublishOnly": "npm run build"
35
- },
36
- "devDependencies": {
37
- "tsup": "^8.3.5",
38
- "typescript": "^5.7.3"
39
- }
40
- }
1
+ {
2
+ "name": "@sunsteel/contracts",
3
+ "version": "0.29.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/ezee969/sunsteel-contracts.git"
7
+ },
8
+ "private": false,
9
+ "engines": {
10
+ "node": ">=20.11"
11
+ },
12
+ "type": "module",
13
+ "sideEffects": false,
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
29
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
30
+ "typecheck": "tsc --noEmit",
31
+ "lint": "npm run typecheck",
32
+ "verify": "npm run typecheck && npm run build",
33
+ "verify:security": "npm audit",
34
+ "prepublishOnly": "npm run build"
35
+ },
36
+ "devDependencies": {
37
+ "tsup": "^8.3.5",
38
+ "typescript": "^5.7.3"
39
+ }
40
+ }