@shipstatic/types 2.25.0 → 2.26.0-beta.2

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.d.ts CHANGED
@@ -135,7 +135,7 @@ export interface Deployment {
135
135
  readonly created: number;
136
136
  /** Unix timestamp (seconds) when deployment expires, null if never */
137
137
  expires: number | null;
138
- /** Full URL to the deployment screenshot (e.g., 'https://screenshots.shipstatic.com/happy-cat-abc1234/a3f2c1b4d5e6f789') */
138
+ /** Full URL to the deployment screenshot, rendered on the first request for it (e.g., 'https://screenshots.shipstatic.com/happy-cat-abc1234/a3f2c1b4d5e6f789') */
139
139
  readonly screenshot: string;
140
140
  }
141
141
  /**
@@ -1793,6 +1793,38 @@ export declare const MY_API_KEY_URL = "https://my.shipstatic.com/api-key";
1793
1793
  * it is.
1794
1794
  */
1795
1795
  export declare const PUBLIC_DEPLOYMENT_TTL_SECONDS: number;
1796
+ /**
1797
+ * A span of time in words: `"3 days"`, `"5 hours"`, `"45 minutes"`.
1798
+ *
1799
+ * Minutes under two hours, hours under two days, and days beyond, each rounded
1800
+ * to the nearest. The unit changes exactly where the larger one rounds to two,
1801
+ * so the number never jumps as time passes (119 minutes, then 2 hours), and
1802
+ * the two vaguest things a rounded clock can say, "1 hour" and "1 day", are
1803
+ * never said. Rounding rather than truncating is what lets a deployment made a
1804
+ * second ago read the lifetime it was given: "3 days", not "2 days". Days are
1805
+ * the largest unit because nobody counts a deadline in weeks, and a month has
1806
+ * no fixed length.
1807
+ *
1808
+ * A span that rounds to no minutes at all, zero and negative included, reads
1809
+ * "less than a minute".
1810
+ */
1811
+ export declare function formatDuration(seconds: number): string;
1812
+ /**
1813
+ * The time left before a deadline, in words (`"3 days"`), or `null` once it
1814
+ * has passed.
1815
+ *
1816
+ * `expires` is unix SECONDS, the wire's own field, taken as it arrives so that
1817
+ * no caller converts it: the deploy card once read it as a date string and
1818
+ * showed the same three days on every deployment for months. `now` is seconds
1819
+ * too, and defaults to the clock.
1820
+ *
1821
+ * A surface that tells a person how long a deployment has left says it with
1822
+ * this, so one deployment reads the same everywhere, whenever it is looked at.
1823
+ * What a surface says around the words is its own ("Expires in", "It stays
1824
+ * live for"), and so is what it says once the deadline has passed, which is
1825
+ * why that case is `null` rather than a sentence.
1826
+ */
1827
+ export declare function formatTimeRemaining(expires: number, now?: number): string | null;
1796
1828
  /**
1797
1829
  * Universal deploy input — the union of every shape the SDK accepts.
1798
1830
  *
package/dist/index.js CHANGED
@@ -1725,6 +1725,57 @@ export const MY_API_KEY_URL = 'https://my.shipstatic.com/api-key';
1725
1725
  */
1726
1726
  export const PUBLIC_DEPLOYMENT_TTL_SECONDS = 3 * 24 * 60 * 60;
1727
1727
  // =============================================================================
1728
+ // TIME REMAINING
1729
+ // =============================================================================
1730
+ /**
1731
+ * A span of time in words: `"3 days"`, `"5 hours"`, `"45 minutes"`.
1732
+ *
1733
+ * Minutes under two hours, hours under two days, and days beyond, each rounded
1734
+ * to the nearest. The unit changes exactly where the larger one rounds to two,
1735
+ * so the number never jumps as time passes (119 minutes, then 2 hours), and
1736
+ * the two vaguest things a rounded clock can say, "1 hour" and "1 day", are
1737
+ * never said. Rounding rather than truncating is what lets a deployment made a
1738
+ * second ago read the lifetime it was given: "3 days", not "2 days". Days are
1739
+ * the largest unit because nobody counts a deadline in weeks, and a month has
1740
+ * no fixed length.
1741
+ *
1742
+ * A span that rounds to no minutes at all, zero and negative included, reads
1743
+ * "less than a minute".
1744
+ */
1745
+ export function formatDuration(seconds) {
1746
+ const minutes = Math.round(seconds / 60);
1747
+ if (!(minutes >= 1))
1748
+ return 'less than a minute';
1749
+ if (minutes < 120)
1750
+ return countOf(minutes, 'minute');
1751
+ const hours = Math.round(seconds / 3_600);
1752
+ if (hours < 48)
1753
+ return countOf(hours, 'hour');
1754
+ return countOf(Math.round(seconds / 86_400), 'day');
1755
+ }
1756
+ /**
1757
+ * The time left before a deadline, in words (`"3 days"`), or `null` once it
1758
+ * has passed.
1759
+ *
1760
+ * `expires` is unix SECONDS, the wire's own field, taken as it arrives so that
1761
+ * no caller converts it: the deploy card once read it as a date string and
1762
+ * showed the same three days on every deployment for months. `now` is seconds
1763
+ * too, and defaults to the clock.
1764
+ *
1765
+ * A surface that tells a person how long a deployment has left says it with
1766
+ * this, so one deployment reads the same everywhere, whenever it is looked at.
1767
+ * What a surface says around the words is its own ("Expires in", "It stays
1768
+ * live for"), and so is what it says once the deadline has passed, which is
1769
+ * why that case is `null` rather than a sentence.
1770
+ */
1771
+ export function formatTimeRemaining(expires, now = Date.now() / 1_000) {
1772
+ const seconds = expires - now;
1773
+ return seconds > 0 ? formatDuration(seconds) : null;
1774
+ }
1775
+ function countOf(count, unit) {
1776
+ return `${count} ${unit}${count === 1 ? '' : 's'}`;
1777
+ }
1778
+ // =============================================================================
1728
1779
  // FILE UPLOAD TYPES
1729
1780
  // =============================================================================
1730
1781
  /**
package/dist/schemas.js CHANGED
@@ -75,7 +75,7 @@ export const DeploymentSchema = z.object({
75
75
  .describe(`Unix timestamp (seconds) when the deployment expires; null when permanent. Anonymous deployments expire ${PUBLIC_DEPLOYMENT_TTL_SECONDS / 86_400} days after creation unless claimed; an authenticated deployment carries one only when it requested a ttl.`),
76
76
  screenshot: z
77
77
  .url()
78
- .describe('Full URL to the deployment screenshot. Captured asynchronously after deploy; the URL is returned immediately but the image may take a few seconds to become available.'),
78
+ .describe('Full URL to the deployment screenshot. Rendered on the first request for it, so the URL is returned immediately and the first request takes a few seconds; every request after that is served immediately.'),
79
79
  });
80
80
  export const DeploymentCreateResponseSchema = DeploymentSchema.extend({
81
81
  claim: z
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "2.25.0",
3
+ "version": "2.26.0-beta.2",
4
4
  "description": "Shared TypeScript types for the ShipStatic platform.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -144,7 +144,7 @@ export interface Deployment {
144
144
  readonly created: number;
145
145
  /** Unix timestamp (seconds) when deployment expires, null if never */
146
146
  expires: number | null; // Mutable - can be updated
147
- /** Full URL to the deployment screenshot (e.g., 'https://screenshots.shipstatic.com/happy-cat-abc1234/a3f2c1b4d5e6f789') */
147
+ /** Full URL to the deployment screenshot, rendered on the first request for it (e.g., 'https://screenshots.shipstatic.com/happy-cat-abc1234/a3f2c1b4d5e6f789') */
148
148
  readonly screenshot: string;
149
149
  }
150
150
 
@@ -2646,6 +2646,61 @@ export const MY_API_KEY_URL = 'https://my.shipstatic.com/api-key';
2646
2646
  */
2647
2647
  export const PUBLIC_DEPLOYMENT_TTL_SECONDS = 3 * 24 * 60 * 60;
2648
2648
 
2649
+ // =============================================================================
2650
+ // TIME REMAINING
2651
+ // =============================================================================
2652
+
2653
+ /**
2654
+ * A span of time in words: `"3 days"`, `"5 hours"`, `"45 minutes"`.
2655
+ *
2656
+ * Minutes under two hours, hours under two days, and days beyond, each rounded
2657
+ * to the nearest. The unit changes exactly where the larger one rounds to two,
2658
+ * so the number never jumps as time passes (119 minutes, then 2 hours), and
2659
+ * the two vaguest things a rounded clock can say, "1 hour" and "1 day", are
2660
+ * never said. Rounding rather than truncating is what lets a deployment made a
2661
+ * second ago read the lifetime it was given: "3 days", not "2 days". Days are
2662
+ * the largest unit because nobody counts a deadline in weeks, and a month has
2663
+ * no fixed length.
2664
+ *
2665
+ * A span that rounds to no minutes at all, zero and negative included, reads
2666
+ * "less than a minute".
2667
+ */
2668
+ export function formatDuration(seconds: number): string {
2669
+ const minutes = Math.round(seconds / 60);
2670
+ if (!(minutes >= 1)) return 'less than a minute';
2671
+ if (minutes < 120) return countOf(minutes, 'minute');
2672
+ const hours = Math.round(seconds / 3_600);
2673
+ if (hours < 48) return countOf(hours, 'hour');
2674
+ return countOf(Math.round(seconds / 86_400), 'day');
2675
+ }
2676
+
2677
+ /**
2678
+ * The time left before a deadline, in words (`"3 days"`), or `null` once it
2679
+ * has passed.
2680
+ *
2681
+ * `expires` is unix SECONDS, the wire's own field, taken as it arrives so that
2682
+ * no caller converts it: the deploy card once read it as a date string and
2683
+ * showed the same three days on every deployment for months. `now` is seconds
2684
+ * too, and defaults to the clock.
2685
+ *
2686
+ * A surface that tells a person how long a deployment has left says it with
2687
+ * this, so one deployment reads the same everywhere, whenever it is looked at.
2688
+ * What a surface says around the words is its own ("Expires in", "It stays
2689
+ * live for"), and so is what it says once the deadline has passed, which is
2690
+ * why that case is `null` rather than a sentence.
2691
+ */
2692
+ export function formatTimeRemaining(
2693
+ expires: number,
2694
+ now: number = Date.now() / 1_000,
2695
+ ): string | null {
2696
+ const seconds = expires - now;
2697
+ return seconds > 0 ? formatDuration(seconds) : null;
2698
+ }
2699
+
2700
+ function countOf(count: number, unit: string): string {
2701
+ return `${count} ${unit}${count === 1 ? '' : 's'}`;
2702
+ }
2703
+
2649
2704
  // =============================================================================
2650
2705
  // RESOURCE INTERFACE CONTRACTS
2651
2706
  // =============================================================================
package/src/schemas.ts CHANGED
@@ -94,7 +94,7 @@ export const DeploymentSchema = z.object({
94
94
  screenshot: z
95
95
  .url()
96
96
  .describe(
97
- 'Full URL to the deployment screenshot. Captured asynchronously after deploy; the URL is returned immediately but the image may take a few seconds to become available.',
97
+ 'Full URL to the deployment screenshot. Rendered on the first request for it, so the URL is returned immediately and the first request takes a few seconds; every request after that is served immediately.',
98
98
  ),
99
99
  });
100
100