@authhero/aws-adapter 1.1.4 → 1.1.7

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.
@@ -0,0 +1,39 @@
1
+ /** A DynamoDB `LastEvaluatedKey` / `ExclusiveStartKey`. */
2
+ export type DynamoKey = Record<string, string>;
3
+ /**
4
+ * The query a cursor must belong to. Every tenant-scoped entity shares the
5
+ * partition key `TENANT#{id}` and is separated only by its sort-key prefix, so
6
+ * the prefix is part of a cursor's identity, not a detail.
7
+ */
8
+ export interface CursorQuery {
9
+ /** Partition key value the query filters on. */
10
+ pk: string;
11
+ /** GSI being queried, if any. Its keys are named `{indexName}PK`/`SK`. */
12
+ indexName?: string;
13
+ /** `begins_with` prefix applied to the sort key, if any. */
14
+ skPrefix?: string;
15
+ }
16
+ /**
17
+ * Encode a `LastEvaluatedKey` into an opaque cursor token suitable for
18
+ * returning as `next` and accepting back as `from`.
19
+ */
20
+ export declare function encodeDynamoCursor(key: Record<string, unknown>): string;
21
+ /**
22
+ * Decode an opaque cursor token into an `ExclusiveStartKey`, verifying it was
23
+ * minted by the same query that is now presenting it.
24
+ *
25
+ * Returns `null` for anything unusable so a client-supplied `from` degrades to
26
+ * "start from the beginning" rather than throwing — matching `decodeCursor()`
27
+ * in adapter-interfaces.
28
+ *
29
+ * The query check is not decoration. DynamoDB rejects a key that disagrees with
30
+ * the query's key conditions ("The provided starting key does not match the
31
+ * range key predicate", "...is invalid"), so without this an attacker-supplied
32
+ * or merely stale `from` turns into an unhandled ValidationException — a 500
33
+ * driven by a query parameter. Note that this validation is a robustness
34
+ * measure, not a tenant boundary: DynamoDB already refuses a cursor whose
35
+ * partition key differs from the one being queried, so a foreign cursor could
36
+ * never read another tenant's rows. It fails cleanly here instead of loudly
37
+ * there.
38
+ */
39
+ export declare function decodeDynamoCursor(token: string, query: CursorQuery): DynamoKey | null;
@@ -41,8 +41,21 @@ export declare function queryItems<T>(ctx: DynamoDBContext, pk: string, options?
41
41
  items: T[];
42
42
  lastKey?: Record<string, unknown>;
43
43
  }>;
44
+ /** True when the caller asked for keyset (checkpoint) pagination. */
45
+ export declare function isKeysetRequest(params?: ListParams): boolean;
44
46
  /**
45
- * Query with pagination support
47
+ * Query with pagination support.
48
+ *
49
+ * Two modes, picked by which parameters the caller supplied:
50
+ *
51
+ * - **Keyset (checkpoint)** — `from`/`take`. `from` is an OPAQUE cursor (see
52
+ * `encodeDynamoCursor`) wrapping DynamoDB's own `LastEvaluatedKey`, so a page
53
+ * resumes natively via `ExclusiveStartKey` with no scanning of skipped rows.
54
+ * Returns `next` when a further page may exist, and no `total` — matching
55
+ * Auth0's checkpoint responses and the SQL adapters.
56
+ * - **Offset** — `page`/`per_page`. Unchanged, including the read-and-discard
57
+ * loop DynamoDB forces on us (it has no native offset). The admin UI uses
58
+ * this, and it is what `include_totals` is for.
46
59
  */
47
60
  export declare function queryWithPagination<T>(ctx: DynamoDBContext, pk: string, params?: ListParams, options?: {
48
61
  skPrefix?: string;
@@ -54,6 +67,8 @@ export declare function queryWithPagination<T>(ctx: DynamoDBContext, pk: string,
54
67
  limit: number;
55
68
  length: number;
56
69
  total?: number;
70
+ /** Opaque cursor for the next page; keyset mode only, absent on the last. */
71
+ next?: string;
57
72
  }>;
58
73
  /**
59
74
  * Generic update operation for DynamoDB
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/markusahlstrand/authhero"
13
13
  },
14
- "version": "1.1.4",
14
+ "version": "1.1.7",
15
15
  "files": [
16
16
  "dist"
17
17
  ],
@@ -44,8 +44,8 @@
44
44
  "@aws-sdk/client-dynamodb": "^3.1085.0",
45
45
  "@aws-sdk/lib-dynamodb": "^3.1085.0",
46
46
  "nanoid": "^5.1.11",
47
- "@authhero/adapter-interfaces": "4.8.0",
48
- "@authhero/proxy": "0.10.5"
47
+ "@authhero/adapter-interfaces": "4.8.1",
48
+ "@authhero/proxy": "0.10.7"
49
49
  },
50
50
  "license": "AGPL-3.0-only",
51
51
  "scripts": {