@bunizao/contracts 0.22.0 → 0.24.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.
@@ -359,3 +359,106 @@ export interface SiteAnalyticsReportResult {
359
359
  }> | null;
360
360
  notices: string[];
361
361
  }
362
+ export declare const SITE_EXPLORE_ENDPOINT: '/api/analytics/explore';
363
+ export declare const SITE_EXPLORE_VIEWS: readonly ['traffic', 'decoy'];
364
+ export type SiteExploreView = typeof SITE_EXPLORE_VIEWS[number];
365
+ export declare const SITE_EXPLORE_RANGES: readonly ['24h', '7d', '30d', '90d'];
366
+ export type SiteExploreRange = typeof SITE_EXPLORE_RANGES[number];
367
+ export declare const SITE_EXPLORE_CLASSES: readonly ['human', 'bot', 'owner', 'all'];
368
+ export type SiteExploreClass = typeof SITE_EXPLORE_CLASSES[number];
369
+ export declare const SITE_EXPLORE_PARTS: readonly ['summary', 'panel', 'clicks', 'log'];
370
+ export type SiteExplorePart = typeof SITE_EXPLORE_PARTS[number];
371
+ export declare const SITE_EXPLORE_DIMS: {
372
+ readonly traffic: readonly ['page', 'section', 'referrer', 'channel', 'utm', 'country', 'city', 'device', 'browser', 'os', 'visitor'];
373
+ readonly decoy: readonly ['client', 'kind', 'reason', 'ua', 'path', 'network', 'country'];
374
+ };
375
+ export type SiteExploreDim<V extends SiteExploreView = SiteExploreView> = typeof SITE_EXPLORE_DIMS[V][number];
376
+ export declare const SITE_EXPLORE_METRICS: {
377
+ readonly traffic: readonly ['visitors', 'views', 'engagement', 'dwell'];
378
+ readonly decoy: readonly ['hits', 'clients', 'networks', 'named'];
379
+ };
380
+ export type SiteExploreMetric<V extends SiteExploreView = SiteExploreView> = typeof SITE_EXPLORE_METRICS[V][number];
381
+ export declare const SITE_EXPLORE_PANEL_LIMIT = 100;
382
+ export declare const SITE_EXPLORE_EMPTY = "(none)";
383
+ export interface SiteExploreSeries {
384
+ totals: Record<string, number>;
385
+ points: Record<string, number[]>;
386
+ }
387
+ export interface SiteExploreSummary {
388
+ view: SiteExploreView;
389
+ range: SiteExploreRange;
390
+ timezone: 'Australia/Melbourne';
391
+ bucket: 'hour' | 'day';
392
+ buckets: string[];
393
+ from: string;
394
+ to: string;
395
+ previousFrom: string | null;
396
+ current: SiteExploreSeries;
397
+ previous: SiteExploreSeries | null;
398
+ notices: Array<'compare_beyond_retention'>;
399
+ }
400
+ export interface SiteExploreRow {
401
+ key: string;
402
+ label: string;
403
+ count: number;
404
+ visitors: number;
405
+ }
406
+ export interface SiteExplorePanel {
407
+ dim: SiteExploreDim;
408
+ rows: SiteExploreRow[];
409
+ more: boolean;
410
+ }
411
+ export interface SiteExploreClickRow {
412
+ name: string;
413
+ label: string;
414
+ href: string;
415
+ clicks: number;
416
+ visitors: number;
417
+ }
418
+ export interface SiteExploreClicks {
419
+ rows: SiteExploreClickRow[];
420
+ more: boolean;
421
+ ignored: SiteExploreDim<'traffic'>[];
422
+ }
423
+ export interface SiteExploreVisit {
424
+ at: string;
425
+ until: string;
426
+ visitor: string;
427
+ session: string;
428
+ class: SiteAnalyticsTrafficClass;
429
+ country: string;
430
+ city: string;
431
+ network: string;
432
+ org: string;
433
+ device: string;
434
+ browser: string;
435
+ os: string;
436
+ entry: string;
437
+ referrer: string;
438
+ channel: string;
439
+ pages: number;
440
+ dwellMs: number;
441
+ interactions: number;
442
+ }
443
+ export interface SiteExploreDecoyHit {
444
+ at: string;
445
+ reason: string;
446
+ kind: string;
447
+ client: string;
448
+ ua: string;
449
+ path: string;
450
+ network: string;
451
+ org: string;
452
+ country: string;
453
+ method: string;
454
+ }
455
+ export type SiteExploreLog = {
456
+ view: 'traffic';
457
+ rows: SiteExploreVisit[];
458
+ more: boolean;
459
+ next: string | null;
460
+ } | {
461
+ view: 'decoy';
462
+ rows: SiteExploreDecoyHit[];
463
+ more: boolean;
464
+ };
package/dist/analytics.js CHANGED
@@ -36,6 +36,21 @@ var SITE_ANALYTICS_SURFACES = [
36
36
  "other"
37
37
  ];
38
38
  var SITE_ANALYTICS_REPORTS = ["overview", "pages", "clicks", "sources", "audience", "quality", "log", "visitor"];
39
+ var SITE_EXPLORE_ENDPOINT = "/api/analytics/explore";
40
+ var SITE_EXPLORE_VIEWS = ["traffic", "decoy"];
41
+ var SITE_EXPLORE_RANGES = ["24h", "7d", "30d", "90d"];
42
+ var SITE_EXPLORE_CLASSES = ["human", "bot", "owner", "all"];
43
+ var SITE_EXPLORE_PARTS = ["summary", "panel", "clicks", "log"];
44
+ var SITE_EXPLORE_DIMS = {
45
+ traffic: ["page", "section", "referrer", "channel", "utm", "country", "city", "device", "browser", "os", "visitor"],
46
+ decoy: ["client", "kind", "reason", "ua", "path", "network", "country"]
47
+ };
48
+ var SITE_EXPLORE_METRICS = {
49
+ traffic: ["visitors", "views", "engagement", "dwell"],
50
+ decoy: ["hits", "clients", "networks", "named"]
51
+ };
52
+ var SITE_EXPLORE_PANEL_LIMIT = 100;
53
+ var SITE_EXPLORE_EMPTY = "(none)";
39
54
  export {
40
55
  BLOG_ANALYTICS_ARTICLE_ENDPOINT,
41
56
  BLOG_ANALYTICS_COMPLETION_SCROLL_DEPTH,
@@ -53,5 +68,14 @@ export {
53
68
  SITE_ANALYTICS_REPORTS,
54
69
  SITE_ANALYTICS_REPORT_ENDPOINT,
55
70
  SITE_ANALYTICS_SESSION_IDLE_MS,
56
- SITE_ANALYTICS_SURFACES
71
+ SITE_ANALYTICS_SURFACES,
72
+ SITE_EXPLORE_CLASSES,
73
+ SITE_EXPLORE_DIMS,
74
+ SITE_EXPLORE_EMPTY,
75
+ SITE_EXPLORE_ENDPOINT,
76
+ SITE_EXPLORE_METRICS,
77
+ SITE_EXPLORE_PANEL_LIMIT,
78
+ SITE_EXPLORE_PARTS,
79
+ SITE_EXPLORE_RANGES,
80
+ SITE_EXPLORE_VIEWS
57
81
  };
package/dist/desk.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ /** Mac power state as the reporter sees it. */
2
+ export declare const DESK_MAC_STATES: readonly ['on', 'locked', 'sleeping', 'paused'];
3
+ export type DeskMacState = (typeof DESK_MAC_STATES)[number];
4
+ /**
5
+ * An app on the desk. `label` is at most 24 letters, digits, spaces and dots;
6
+ * site-api turns anything else into "something else". `icon` is the
7
+ * lowercase hex sha256 of a PNG (at most 128 px a side) already uploaded to
8
+ * deskIconPath(icon), or null.
9
+ */
10
+ export interface DeskApp {
11
+ label: string;
12
+ icon: string | null;
13
+ }
14
+ /** Report body version the reporter sends; site-api rejects any other. */
15
+ export declare const DESK_REPORT_VERSION = 1;
16
+ /**
17
+ * Body of the owner-only, HMAC-signed POST to DESK_REPORT_PATH. The server
18
+ * ignores a report whose sentAt is not newer than the stored one, and
19
+ * computes expiry from its own clock plus ttl.
20
+ */
21
+ export interface DeskReport {
22
+ v: typeof DESK_REPORT_VERSION;
23
+ /** Reporter clock, epoch milliseconds. Only used for ordering. */
24
+ sentAt: number;
25
+ mac: DeskMacState;
26
+ /** Seconds since the last keyboard or pointer input. */
27
+ idleSeconds: number;
28
+ /** True while an app holds a display-sleep assertion (video, a call). */
29
+ screenHeld: boolean;
30
+ /** Apps in use, most active first; `other` for an unlisted one. Never window titles or bundle ids. */
31
+ apps: DeskApp[];
32
+ /** IANA zone of the Mac, e.g. Australia/Melbourne. */
33
+ timeZone: string;
34
+ /** Seconds this report stays valid without a successor. */
35
+ ttl: number;
36
+ }
37
+ export declare const DESK_PRESENCE_STATES: readonly ['awake', 'idle', 'asleep', 'offline'];
38
+ export type DeskPresenceState = (typeof DESK_PRESENCE_STATES)[number];
39
+ export declare const DESK_SKIES: readonly ['clear', 'cloudy', 'fog', 'drizzle', 'rain', 'snow', 'storm'];
40
+ export type Sky = (typeof DESK_SKIES)[number];
41
+ export interface DeskPresence {
42
+ state: DeskPresenceState;
43
+ /** Empty unless awake or idle; an unlisted app reads "something else" with no icon. */
44
+ apps: DeskApp[];
45
+ /** Seconds of lease left when computed; null when offline or asleep. */
46
+ validFor: number | null;
47
+ }
48
+ export interface DeskPlace {
49
+ /** IANA zone the clock shows; the last pushed zone, or the default. */
50
+ timeZone: string;
51
+ /** City named by the zone; null when the zone names none (e.g. UTC). */
52
+ city: string | null;
53
+ }
54
+ export interface DeskWeather {
55
+ /** Degrees Celsius, rounded. */
56
+ temperature: number;
57
+ sky: Sky;
58
+ /** Daylight at the place right now. */
59
+ day: boolean;
60
+ }
61
+ /** Response of GET DESK_PATH. Fields are only ever added. */
62
+ export interface DeskNow {
63
+ presence: DeskPresence;
64
+ place: DeskPlace;
65
+ /** Null when the weather source is unavailable. */
66
+ weather: DeskWeather | null;
67
+ }
68
+ /** Close code the live socket uses when it is full; poll instead. */
69
+ export declare const DESK_LIVE_FULL_CLOSE_CODE = 1013;
70
+ /**
71
+ * Message the live socket at DESK_LIVE_PATH sends on connect and whenever
72
+ * presence or place changes. Weather is not pushed; read it from DESK_PATH.
73
+ * The socket answers the text `ping` with `pong`. Fields are only ever added.
74
+ */
75
+ export interface DeskLive {
76
+ presence: DeskPresence;
77
+ place: DeskPlace;
78
+ }
package/dist/desk.js ADDED
@@ -0,0 +1,13 @@
1
+ // src/desk.ts
2
+ var DESK_MAC_STATES = ["on", "locked", "sleeping", "paused"];
3
+ var DESK_REPORT_VERSION = 1;
4
+ var DESK_PRESENCE_STATES = ["awake", "idle", "asleep", "offline"];
5
+ var DESK_SKIES = ["clear", "cloudy", "fog", "drizzle", "rain", "snow", "storm"];
6
+ var DESK_LIVE_FULL_CLOSE_CODE = 1013;
7
+ export {
8
+ DESK_LIVE_FULL_CLOSE_CODE,
9
+ DESK_MAC_STATES,
10
+ DESK_PRESENCE_STATES,
11
+ DESK_REPORT_VERSION,
12
+ DESK_SKIES
13
+ };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './analytics';
2
2
  export * from './admin';
3
3
  export * from './comments';
4
4
  export * from './content';
5
+ export * from './desk';
5
6
  export * from './instagram';
6
7
  export * from './listening';
7
8
  export * from './messages';
package/dist/index.js CHANGED
@@ -36,6 +36,21 @@ var SITE_ANALYTICS_SURFACES = [
36
36
  "other"
37
37
  ];
38
38
  var SITE_ANALYTICS_REPORTS = ["overview", "pages", "clicks", "sources", "audience", "quality", "log", "visitor"];
39
+ var SITE_EXPLORE_ENDPOINT = "/api/analytics/explore";
40
+ var SITE_EXPLORE_VIEWS = ["traffic", "decoy"];
41
+ var SITE_EXPLORE_RANGES = ["24h", "7d", "30d", "90d"];
42
+ var SITE_EXPLORE_CLASSES = ["human", "bot", "owner", "all"];
43
+ var SITE_EXPLORE_PARTS = ["summary", "panel", "clicks", "log"];
44
+ var SITE_EXPLORE_DIMS = {
45
+ traffic: ["page", "section", "referrer", "channel", "utm", "country", "city", "device", "browser", "os", "visitor"],
46
+ decoy: ["client", "kind", "reason", "ua", "path", "network", "country"]
47
+ };
48
+ var SITE_EXPLORE_METRICS = {
49
+ traffic: ["visitors", "views", "engagement", "dwell"],
50
+ decoy: ["hits", "clients", "networks", "named"]
51
+ };
52
+ var SITE_EXPLORE_PANEL_LIMIT = 100;
53
+ var SITE_EXPLORE_EMPTY = "(none)";
39
54
  // src/admin.ts
40
55
  var ADMIN_COMMENT_REJECT_REASONS = ["spam", "promotional", "abuse", "off_topic", "personal_info"];
41
56
  var ADMIN_ACTIVITY_EVENTS = [
@@ -145,6 +160,12 @@ function parsePostLocaleTag(tagName) {
145
160
  }
146
161
  return canonicalSlug ? { locale, canonicalSlug } : { locale };
147
162
  }
163
+ // src/desk.ts
164
+ var DESK_MAC_STATES = ["on", "locked", "sleeping", "paused"];
165
+ var DESK_REPORT_VERSION = 1;
166
+ var DESK_PRESENCE_STATES = ["awake", "idle", "asleep", "offline"];
167
+ var DESK_SKIES = ["clear", "cloudy", "fog", "drizzle", "rain", "snow", "storm"];
168
+ var DESK_LIVE_FULL_CLOSE_CODE = 1013;
148
169
  // src/messages.ts
149
170
  var MESSAGE_LOCALES = ["zh", "en"];
150
171
  var MESSAGE_MIN_BODY_LENGTH = 2;
@@ -205,6 +226,13 @@ var MOOD_SEARCH_PATH = "/v2/mood/search";
205
226
  var MOOD_IMAGE_PROXY_BASE_PATH = "/v2/images";
206
227
  var MOOD_MEDIA_PROXY_BASE_PATH = "/v2/media";
207
228
  var LISTENING_PATH = "/v2/listening";
229
+ var DESK_PATH = "/v2/desk";
230
+ var DESK_LIVE_PATH = "/v2/desk/live";
231
+ var DESK_REPORT_PATH = "/v2/desk/report";
232
+ var DESK_ICONS_PATH = "/v2/desk/icons";
233
+ function deskIconPath(hash) {
234
+ return `${DESK_ICONS_PATH}/${hash}`;
235
+ }
208
236
  var INSTAGRAM_PROFILE_PATH = "/v2/instagram";
209
237
  var INSTAGRAM_AVATAR_PATH = "/v2/instagram/avatar";
210
238
  var COMMENTS_PATH = "/v2/comments";
@@ -317,6 +345,15 @@ export {
317
345
  CONTENT_DOCUMENT_SOURCES,
318
346
  DEFAULT_COMMENT_POLICY,
319
347
  DEFAULT_REACTION_EMOJI,
348
+ DESK_ICONS_PATH,
349
+ DESK_LIVE_FULL_CLOSE_CODE,
350
+ DESK_LIVE_PATH,
351
+ DESK_MAC_STATES,
352
+ DESK_PATH,
353
+ DESK_PRESENCE_STATES,
354
+ DESK_REPORT_PATH,
355
+ DESK_REPORT_VERSION,
356
+ DESK_SKIES,
320
357
  EVENT_STATUSES,
321
358
  GHOST_WEBHOOK_PATH,
322
359
  HEALTH_PATH,
@@ -386,6 +423,15 @@ export {
386
423
  SITE_ANALYTICS_REPORT_ENDPOINT,
387
424
  SITE_ANALYTICS_SESSION_IDLE_MS,
388
425
  SITE_ANALYTICS_SURFACES,
426
+ SITE_EXPLORE_CLASSES,
427
+ SITE_EXPLORE_DIMS,
428
+ SITE_EXPLORE_EMPTY,
429
+ SITE_EXPLORE_ENDPOINT,
430
+ SITE_EXPLORE_METRICS,
431
+ SITE_EXPLORE_PANEL_LIMIT,
432
+ SITE_EXPLORE_PARTS,
433
+ SITE_EXPLORE_RANGES,
434
+ SITE_EXPLORE_VIEWS,
389
435
  SUBSCRIPTION_SOURCES,
390
436
  TELEGRAM_OPS_BASE_PATH,
391
437
  TELEGRAM_OPS_BROADCASTS_PATH,
@@ -407,6 +453,7 @@ export {
407
453
  avatarClass,
408
454
  commentAnchorToken,
409
455
  commentPolicyFromTags,
456
+ deskIconPath,
410
457
  isAvatarSeed,
411
458
  parsePostLocaleTag,
412
459
  seedInClass,
package/dist/routes.d.ts CHANGED
@@ -12,6 +12,13 @@ export declare const MOOD_SEARCH_PATH: '/v2/mood/search';
12
12
  export declare const MOOD_IMAGE_PROXY_BASE_PATH: '/v2/images';
13
13
  export declare const MOOD_MEDIA_PROXY_BASE_PATH: '/v2/media';
14
14
  export declare const LISTENING_PATH: '/v2/listening';
15
+ export declare const DESK_PATH: '/v2/desk';
16
+ /** WebSocket upgrade; the server pushes DeskLive messages. */
17
+ export declare const DESK_LIVE_PATH: '/v2/desk/live';
18
+ export declare const DESK_REPORT_PATH: '/v2/desk/report';
19
+ /** PUT (owner-signed) and GET an app icon PNG by its sha256: `${DESK_ICONS_PATH}/<hash>`. */
20
+ export declare const DESK_ICONS_PATH: '/v2/desk/icons';
21
+ export declare function deskIconPath(hash: string): string;
15
22
  export declare const INSTAGRAM_PROFILE_PATH: '/v2/instagram';
16
23
  export declare const INSTAGRAM_AVATAR_PATH: '/v2/instagram/avatar';
17
24
  export declare const COMMENTS_PATH: '/v2/comments';
package/dist/routes.js CHANGED
@@ -13,6 +13,13 @@ var MOOD_SEARCH_PATH = "/v2/mood/search";
13
13
  var MOOD_IMAGE_PROXY_BASE_PATH = "/v2/images";
14
14
  var MOOD_MEDIA_PROXY_BASE_PATH = "/v2/media";
15
15
  var LISTENING_PATH = "/v2/listening";
16
+ var DESK_PATH = "/v2/desk";
17
+ var DESK_LIVE_PATH = "/v2/desk/live";
18
+ var DESK_REPORT_PATH = "/v2/desk/report";
19
+ var DESK_ICONS_PATH = "/v2/desk/icons";
20
+ function deskIconPath(hash) {
21
+ return `${DESK_ICONS_PATH}/${hash}`;
22
+ }
16
23
  var INSTAGRAM_PROFILE_PATH = "/v2/instagram";
17
24
  var INSTAGRAM_AVATAR_PATH = "/v2/instagram/avatar";
18
25
  var COMMENTS_PATH = "/v2/comments";
@@ -45,6 +52,10 @@ export {
45
52
  API_PREFIX,
46
53
  COMMENTS_PATH,
47
54
  COMMENT_PATH_PREFIX,
55
+ DESK_ICONS_PATH,
56
+ DESK_LIVE_PATH,
57
+ DESK_PATH,
58
+ DESK_REPORT_PATH,
48
59
  GHOST_WEBHOOK_PATH,
49
60
  HEALTH_PATH,
50
61
  INSTAGRAM_AVATAR_PATH,
@@ -81,5 +92,6 @@ export {
81
92
  READER_PREFERENCES_PATH,
82
93
  READER_RESEND_PATH,
83
94
  READER_VERIFY_PATH,
84
- TELEGRAM_WEBHOOK_PATH
95
+ TELEGRAM_WEBHOOK_PATH,
96
+ deskIconPath
85
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunizao/contracts",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Shared TypeScript contracts for buxx.me services and clients.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -48,6 +48,11 @@
48
48
  "import": "./dist/content.js",
49
49
  "default": "./dist/content.js"
50
50
  },
51
+ "./desk": {
52
+ "types": "./dist/desk.d.ts",
53
+ "import": "./dist/desk.js",
54
+ "default": "./dist/desk.js"
55
+ },
51
56
  "./instagram": {
52
57
  "types": "./dist/instagram.d.ts",
53
58
  "import": "./dist/instagram.js",