@authhero/adapter-interfaces 4.5.0 → 4.6.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.
@@ -1,4 +1,4 @@
1
- import { AnalyticsQueryParams, AnalyticsQueryResponse, AnalyticsResource } from "../types/Analytics";
1
+ import { AnalyticsQueryParams, AnalyticsQueryResponse, AnalyticsResource, SessionRetentionParams, SessionRetentionResponse } from "../types/Analytics";
2
2
  export interface AnalyticsAdapter {
3
3
  /**
4
4
  * Run an analytics query for a tenant. The adapter is responsible for
@@ -6,4 +6,11 @@ export interface AnalyticsAdapter {
6
6
  * tenant value from a client-controlled source.
7
7
  */
8
8
  query(tenantId: string, resource: AnalyticsResource, params: AnalyticsQueryParams): Promise<AnalyticsQueryResponse>;
9
+ /**
10
+ * Weekly session cohort retention, computed from the sessions table
11
+ * (created_at_ts × used_at_ts) rather than logs. Optional: adapters that
12
+ * only see log events (e.g. Analytics Engine) cannot implement it, and the
13
+ * route responds 501 when it is absent.
14
+ */
15
+ sessionRetention?(tenantId: string, params: SessionRetentionParams): Promise<SessionRetentionResponse>;
9
16
  }
@@ -72,6 +72,45 @@ export interface AnalyticsQueryResponse {
72
72
  bytes_read?: number;
73
73
  };
74
74
  }
75
+ export interface SessionRetentionParams {
76
+ /** Number of weekly cohorts to include, counting back from the current week */
77
+ weeks: number;
78
+ }
79
+ export interface SessionRetentionCohort {
80
+ /** ISO date (UTC Monday) the cohort week starts on */
81
+ cohort: string;
82
+ /** Sessions created during the cohort week */
83
+ sessions: number;
84
+ /**
85
+ * active[k] = sessions still active k weeks after the cohort week, i.e.
86
+ * last used during week k or later. active[0] === sessions. The array is
87
+ * truncated at the current week, so recent cohorts have fewer entries.
88
+ */
89
+ active: number[];
90
+ }
91
+ export interface SessionRetentionResponse {
92
+ interval: "week";
93
+ /** Inclusive lower bound of the first cohort week */
94
+ from: string;
95
+ /** Timestamp the query ran at; the last cohort week is still in progress */
96
+ to: string;
97
+ cohorts: SessionRetentionCohort[];
98
+ }
99
+ export declare const sessionRetentionCohortSchema: z.ZodObject<{
100
+ cohort: z.ZodString;
101
+ sessions: z.ZodNumber;
102
+ active: z.ZodArray<z.ZodNumber>;
103
+ }, z.core.$strip>;
104
+ export declare const sessionRetentionResponseSchema: z.ZodObject<{
105
+ interval: z.ZodLiteral<"week">;
106
+ from: z.ZodString;
107
+ to: z.ZodString;
108
+ cohorts: z.ZodArray<z.ZodObject<{
109
+ cohort: z.ZodString;
110
+ sessions: z.ZodNumber;
111
+ active: z.ZodArray<z.ZodNumber>;
112
+ }, z.core.$strip>>;
113
+ }, z.core.$strip>;
75
114
  export declare const analyticsColumnMetaSchema: z.ZodObject<{
76
115
  name: z.ZodString;
77
116
  type: z.ZodString;
@@ -1,4 +1,14 @@
1
1
  import { z } from "@hono/zod-openapi";
2
+ /**
3
+ * Built-in universal-login pages a page hook can interrupt the login with.
4
+ * The runtime redirects to `/u/{page_id}` (or `/u2/{page_id}`), so this enum
5
+ * is the allowlist of interstitial screens — a free-form string would let a
6
+ * misconfigured hook bounce logins to an arbitrary universal-login path.
7
+ */
8
+ export declare const hookPageId: z.ZodEnum<{
9
+ impersonate: "impersonate";
10
+ }>;
11
+ export type HookPageId = z.infer<typeof hookPageId>;
2
12
  export declare const hookTemplateId: z.ZodEnum<{
3
13
  "ensure-username": "ensure-username";
4
14
  "set-preferred-username": "set-preferred-username";
@@ -77,6 +87,19 @@ export declare const hookInsertSchema: z.ZodUnion<readonly [z.ZodObject<{
77
87
  priority: z.ZodOptional<z.ZodNumber>;
78
88
  hook_id: z.ZodOptional<z.ZodString>;
79
89
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
90
+ }, z.core.$strip>, z.ZodObject<{
91
+ trigger_id: z.ZodEnum<{
92
+ "post-user-login": "post-user-login";
93
+ }>;
94
+ page_id: z.ZodEnum<{
95
+ impersonate: "impersonate";
96
+ }>;
97
+ permission_required: z.ZodOptional<z.ZodString>;
98
+ enabled: z.ZodDefault<z.ZodBoolean>;
99
+ synchronous: z.ZodDefault<z.ZodBoolean>;
100
+ priority: z.ZodOptional<z.ZodNumber>;
101
+ hook_id: z.ZodOptional<z.ZodString>;
102
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
80
103
  }, z.core.$strip>]>;
81
104
  export type HookInsert = z.infer<typeof hookInsertSchema>;
82
105
  export declare const hookSchema: z.ZodUnion<readonly [z.ZodObject<{
@@ -148,5 +171,20 @@ export declare const hookSchema: z.ZodUnion<readonly [z.ZodObject<{
148
171
  updated_at: z.ZodString;
149
172
  hook_id: z.ZodString;
150
173
  code_id: z.ZodString;
174
+ }, z.core.$strip>, z.ZodObject<{
175
+ trigger_id: z.ZodEnum<{
176
+ "post-user-login": "post-user-login";
177
+ }>;
178
+ enabled: z.ZodDefault<z.ZodBoolean>;
179
+ synchronous: z.ZodDefault<z.ZodBoolean>;
180
+ priority: z.ZodOptional<z.ZodNumber>;
181
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
182
+ created_at: z.ZodString;
183
+ updated_at: z.ZodString;
184
+ hook_id: z.ZodString;
185
+ page_id: z.ZodEnum<{
186
+ impersonate: "impersonate";
187
+ }>;
188
+ permission_required: z.ZodOptional<z.ZodString>;
151
189
  }, z.core.$strip>]>;
152
190
  export type Hook = z.infer<typeof hookSchema>;
@@ -8,3 +8,4 @@ export * from "./base32";
8
8
  export * from "./hex";
9
9
  export * from "./cursor";
10
10
  export * from "./lucene";
11
+ export * from "./session-retention";
@@ -0,0 +1,32 @@
1
+ import { SessionRetentionResponse } from "../types/Analytics";
2
+ export declare const WEEK_MS: number;
3
+ /**
4
+ * The Unix epoch (1970-01-01) was a Thursday; adding 3 days before dividing
5
+ * by a week aligns bucket boundaries to Monday 00:00 UTC.
6
+ */
7
+ export declare const MONDAY_EPOCH_SHIFT_MS: number;
8
+ /** Monday-aligned week index for an epoch-ms timestamp. */
9
+ export declare function weekIndex(epochMs: number): number;
10
+ /** Epoch ms of the UTC Monday a week index starts on. */
11
+ export declare function weekStartMs(week: number): number;
12
+ export interface SessionRetentionWindow {
13
+ currentWeek: number;
14
+ firstWeek: number;
15
+ /** Epoch ms lower bound for created_at_ts — the start of the first cohort week */
16
+ sinceMs: number;
17
+ }
18
+ export declare function sessionRetentionWindow(weeks: number, now?: number): SessionRetentionWindow;
19
+ export interface SessionRetentionRawRow {
20
+ /** Monday-aligned week index the session was created in */
21
+ created_week: number;
22
+ /** Monday-aligned week index the session was last used in */
23
+ used_week: number;
24
+ count: number;
25
+ }
26
+ /**
27
+ * Fold raw (created-week × last-used-week) counts into per-cohort retention.
28
+ * A session counts as active k weeks after its cohort week when it was last
29
+ * used during that week or any later one, so a single last-used timestamp is
30
+ * enough to reconstruct the whole retention triangle.
31
+ */
32
+ export declare function buildSessionRetention(rows: SessionRetentionRawRow[], weeks: number, now?: number): SessionRetentionResponse;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/markusahlstrand/authhero"
13
13
  },
14
- "version": "4.5.0",
14
+ "version": "4.6.0",
15
15
  "files": [
16
16
  "dist"
17
17
  ],