@ramme-io/shared 3.3.1 → 3.5.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
@@ -118,7 +118,12 @@ __export(index_exports, {
118
118
  EntitySchema: () => EntitySchema,
119
119
  EventBucketSizeSchema: () => EventBucketSizeSchema,
120
120
  EventSourceSchema: () => EventSourceSchema,
121
+ FIRMWARE_UPDATE_ATTEMPTS: () => FIRMWARE_UPDATE_ATTEMPTS,
122
+ FIRMWARE_UPDATE_PREFIX: () => FIRMWARE_UPDATE_PREFIX,
123
+ FULL_COLOUR_FRAME_MAX: () => FULL_COLOUR_FRAME_MAX,
124
+ FULL_RENDITION: () => FULL_RENDITION,
121
125
  FieldSchema: () => FieldSchema,
126
+ FirmwareUpdateSchema: () => FirmwareUpdateSchema,
122
127
  FloraTelemetrySchema: () => FloraTelemetrySchema,
123
128
  GENESIS_LIBRARY_CONTEXT: () => GENESIS_LIBRARY_CONTEXT,
124
129
  GENESIS_VALID_COMPONENTS: () => GENESIS_VALID_COMPONENTS,
@@ -141,6 +146,8 @@ __export(index_exports, {
141
146
  PageSectionSchema: () => PageSectionSchema,
142
147
  PaginatedEntityEventsSchema: () => PaginatedEntityEventsSchema,
143
148
  PairCodeSchema: () => PairCodeSchema,
149
+ PhotoCropSchema: () => PhotoCropSchema,
150
+ PhotoFullSchema: () => PhotoFullSchema,
144
151
  PhotoSummarySchema: () => PhotoSummarySchema,
145
152
  PhotoUploadSchema: () => PhotoUploadSchema,
146
153
  ProvisioningStateSchema: () => ProvisioningStateSchema,
@@ -750,6 +757,7 @@ var AssetHashSchema = import_zod6.z.string().regex(/^[0-9a-f]{64}$/, "a lowercas
750
757
  var IMAGE_MAX_DRAWN = { width: 304, height: 224 };
751
758
  var IMAGE_MAX_SCALE = 8;
752
759
  var RETRO_RENDITION = { width: 76, height: 56, scale: 4, colors: 16 };
760
+ var FULL_RENDITION = { width: 304, height: 224, quality: 0.82, maxBytes: 48e3 };
753
761
  var SPR_FORMAT = {
754
762
  /** "RSPR". */
755
763
  magic: [82, 83, 80, 82],
@@ -768,6 +776,12 @@ var AppImageSchema = import_zod6.z.object({
768
776
  width: import_zod6.z.number().int().min(1).max(IMAGE_MAX_DRAWN.width),
769
777
  height: import_zod6.z.number().int().min(1).max(IMAGE_MAX_DRAWN.height),
770
778
  scale: import_zod6.z.number().int().min(1).max(IMAGE_MAX_SCALE).default(1),
779
+ /**
780
+ * What kind of file `asset` names: `spr`, the palette file the retro look
781
+ * uses, or `jpeg`, the full-colour rendition (drawn at scale 1). Absent means
782
+ * `spr`, which is every image block written before full colour existed.
783
+ */
784
+ format: import_zod6.z.enum(["spr", "jpeg"]).default("spr"),
771
785
  align: AppAlignSchema.default("start"),
772
786
  /** Drawn only when this is false, or absent. */
773
787
  hideWhen: AppConditionSchema.optional()
@@ -823,6 +837,14 @@ var AppDocumentSchema = import_zod6.z.object({
823
837
  const b = block;
824
838
  if (b?.type !== "image" || !b.width || !b.height) return;
825
839
  const scale = b.scale ?? 1;
840
+ if (b.format === "jpeg" && scale !== 1) {
841
+ ctx.addIssue({
842
+ code: import_zod6.z.ZodIssueCode.custom,
843
+ path: [...path, "scale"],
844
+ message: "A jpeg image is drawn at scale 1; make the file the size it should appear."
845
+ });
846
+ return;
847
+ }
826
848
  const w = b.width * scale;
827
849
  const h = b.height * scale;
828
850
  if (w <= IMAGE_MAX_DRAWN.width && h <= IMAGE_MAX_DRAWN.height) return;
@@ -851,10 +873,22 @@ var ORIGINAL_MAX_SIDE = 3072;
851
873
  var ORIGINAL_MAX_BYTES = 3e6;
852
874
  var PHOTOS_PER_ACCOUNT = 50;
853
875
  var PHOTO_UPLOADS_PER_HOUR = 30;
876
+ var PhotoCropSchema = import_zod7.z.object({
877
+ x: import_zod7.z.number().min(0).max(1),
878
+ y: import_zod7.z.number().min(0).max(1),
879
+ w: import_zod7.z.number().gt(0).max(1),
880
+ h: import_zod7.z.number().gt(0).max(1),
881
+ mirror: import_zod7.z.boolean().default(false)
882
+ });
854
883
  var PhotoUploadSchema = import_zod7.z.object({
855
884
  rendition: import_zod7.z.string().min(4),
856
- original: import_zod7.z.string().min(4)
885
+ original: import_zod7.z.string().min(4),
886
+ /** The full-colour rendition (FULL_RENDITION), base64 JPEG. Optional for older clients. */
887
+ full: import_zod7.z.string().min(4).optional(),
888
+ crop: PhotoCropSchema.optional()
857
889
  });
890
+ var PhotoFullSchema = import_zod7.z.object({ full: import_zod7.z.string().min(4) });
891
+ var FULL_COLOUR_FRAME_MAX = 4;
858
892
  var PhotoSummarySchema = import_zod7.z.object({
859
893
  hash: AssetHashSchema,
860
894
  /** The rendition's own pixels. */
@@ -864,7 +898,10 @@ var PhotoSummarySchema = import_zod7.z.object({
864
898
  originalWidth: import_zod7.z.number().int().positive(),
865
899
  originalHeight: import_zod7.z.number().int().positive(),
866
900
  originalBytes: import_zod7.z.number().int().positive(),
867
- uploadedAt: import_zod7.z.number().int()
901
+ uploadedAt: import_zod7.z.number().int(),
902
+ /** The full-colour rendition, when one has been made. Its own hash names it. */
903
+ full: import_zod7.z.object({ hash: AssetHashSchema, bytes: import_zod7.z.number().int().positive() }).optional(),
904
+ crop: PhotoCropSchema.optional()
868
905
  });
869
906
 
870
907
  // src/apps/delivery.ts
@@ -913,6 +950,15 @@ var DeviceRecordSchema = import_zod8.z.object({
913
950
  var DEVICE_LABEL_MAX = 48;
914
951
  var DEVICE_TTL_SECONDS = 60 * 60 * 24 * 30;
915
952
  var CLAIMED_DEVICE_TTL_SECONDS = 60 * 60 * 24 * 400;
953
+ var FirmwareUpdateSchema = import_zod8.z.object({
954
+ version: import_zod8.z.string().min(1).max(40),
955
+ url: import_zod8.z.string().url().max(200),
956
+ sha256: import_zod8.z.string().regex(/^[0-9a-f]{64}$/),
957
+ bytes: import_zod8.z.number().int().positive(),
958
+ requestedAt: import_zod8.z.number().int().nonnegative()
959
+ });
960
+ var FIRMWARE_UPDATE_PREFIX = "https://www.ramme.io/firmware/weather-display/";
961
+ var FIRMWARE_UPDATE_ATTEMPTS = 3;
916
962
 
917
963
  // src/apps/vitals.ts
918
964
  var import_zod9 = require("zod");
@@ -952,7 +998,19 @@ var DeviceSeenSchema = import_zod9.z.object({
952
998
  /** When the board last asked for its app. The freshest signal this system has. */
953
999
  lastPollAt: import_zod9.z.number().int().nonnegative(),
954
1000
  /** The revision it reported drawing at that moment. */
955
- drewRevision: import_zod9.z.number().int().nonnegative().optional()
1001
+ drewRevision: import_zod9.z.number().int().nonnegative().optional(),
1002
+ /**
1003
+ * The firmware it is running, sent on every poll by builds that can update
1004
+ * remotely — so its presence is also the answer to "can this board be
1005
+ * updated from its page?". Registration reports the version too, but only
1006
+ * every six hours; after a remote update this is what shows it took.
1007
+ */
1008
+ firmware: import_zod9.z.string().max(40).optional(),
1009
+ /** Photos its app names, and how many of those it holds in flash. */
1010
+ photosWanted: import_zod9.z.number().int().nonnegative().optional(),
1011
+ photosHeld: import_zod9.z.number().int().nonnegative().optional(),
1012
+ /** What happened to the last firmware update it tried, in a few words. */
1013
+ updateResult: import_zod9.z.string().max(80).optional()
956
1014
  });
957
1015
  var DEVICE_VITALS_FIELDS = [
958
1016
  {
@@ -1980,7 +2038,12 @@ var EXCLUDED_SOURCES = {
1980
2038
  EntitySchema,
1981
2039
  EventBucketSizeSchema,
1982
2040
  EventSourceSchema,
2041
+ FIRMWARE_UPDATE_ATTEMPTS,
2042
+ FIRMWARE_UPDATE_PREFIX,
2043
+ FULL_COLOUR_FRAME_MAX,
2044
+ FULL_RENDITION,
1983
2045
  FieldSchema,
2046
+ FirmwareUpdateSchema,
1984
2047
  FloraTelemetrySchema,
1985
2048
  GENESIS_LIBRARY_CONTEXT,
1986
2049
  GENESIS_VALID_COMPONENTS,
@@ -2003,6 +2066,8 @@ var EXCLUDED_SOURCES = {
2003
2066
  PageSectionSchema,
2004
2067
  PaginatedEntityEventsSchema,
2005
2068
  PairCodeSchema,
2069
+ PhotoCropSchema,
2070
+ PhotoFullSchema,
2006
2071
  PhotoSummarySchema,
2007
2072
  PhotoUploadSchema,
2008
2073
  ProvisioningStateSchema,