@sentry/api 0.131.0 → 0.133.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.
@@ -21,24 +21,84 @@ export type UnwrappedResult<TData> = {
21
21
  };
22
22
  export type PaginatedResponse<T> = {
23
23
  data: T;
24
+ /** Cursor for the next page. `undefined` when there are no more pages. */
24
25
  nextCursor?: string;
26
+ /** Cursor for the previous page. `undefined` on the first page. */
27
+ prevCursor?: string;
25
28
  };
26
29
  export type PaginateAllOptions = {
30
+ /** Hard cap on the number of pages fetched. Default: 50. */
27
31
  maxPages?: number;
28
32
  };
33
+ export type PaginateUpToOptions = {
34
+ /** Hard cap on the number of items returned. Required. */
35
+ limit: number;
36
+ /** Safety cap on the number of pages fetched. Default: 50. */
37
+ maxPages?: number;
38
+ /** Resume pagination from this cursor instead of starting from the beginning. */
39
+ startCursor?: string;
40
+ /** Called after each page is fetched. Useful for progress indicators. */
41
+ onPage?: (fetched: number, limit: number) => void;
42
+ /**
43
+ * When true, preserve `nextCursor` even when the last page was trimmed
44
+ * to fit `limit`. Default: false (the safe default — see body comment).
45
+ *
46
+ * Use this only for endpoints that have **no** server-side per-page
47
+ * control (so the trimmed tail items remain reachable via the same
48
+ * cursor on the next call). Sentry's `/issues/{id}/events/` is one
49
+ * such endpoint: it has no `per_page` param, so dropping the cursor
50
+ * on overshoot would orphan the items the helper trimmed.
51
+ *
52
+ * For endpoints that DO support `per_page` / `limit`, leave this
53
+ * `false` — returning a cursor that points past trimmed items would
54
+ * cause callers resuming pagination to skip records.
55
+ */
56
+ keepCursorOnOvershoot?: boolean;
57
+ };
29
58
  export type PageFetcher<TData, TError> = (cursor: string | undefined) => Promise<SdkResult<TData, TError>>;
30
59
  /**
31
- * Parse Sentry's Link header to extract the next page cursor.
60
+ * Parse Sentry's Link header to extract pagination cursors.
32
61
  *
33
62
  * Sentry returns Link headers in the format:
34
- * <url>; rel="previous"; results="false"; cursor="...";,
63
+ * <url>; rel="previous"; results="true"; cursor="abc:0:1";,
35
64
  * <url>; rel="next"; results="true"; cursor="1234:0:0";
36
65
  *
37
- * Returns `{ nextCursor }` if there is a next page, or `{}` if not.
66
+ * Returns `{ nextCursor?, prevCursor? }`:
67
+ * - `nextCursor` set when there is a next page.
68
+ * - `prevCursor` set when there is a previous page.
69
+ *
70
+ * The `results="true"` qualifier is required — Sentry includes a
71
+ * `previous` rel even on the first page, but with `results="false"`.
72
+ * We honor that signal so first-page callers don't see a bogus `prevCursor`.
38
73
  */
39
74
  export declare const parseSentryLinkHeader: (header: string | null) => {
40
75
  nextCursor?: string;
76
+ prevCursor?: string;
41
77
  };
78
+ /**
79
+ * Internal: merge a managed `cursor` into an SDK call's `options.query`
80
+ * and re-shape the result back to the SDK's `Options<TData>` type.
81
+ *
82
+ * Used exclusively by the auto-generated wrappers in `pagination.gen.ts`
83
+ * (one call per wrapper kind, one `_withCursor` invocation per page).
84
+ * Centralizes the cast chain — every wrapper used to inline its own
85
+ * `as unknown as ...` quartet, which meant the same logic was repeated
86
+ * once per generated wrapper (~115 places). This helper makes that
87
+ * exactly one place.
88
+ *
89
+ * Type-erasure rationale: each SDK operation has its own `Options<TData>`
90
+ * shape with operation-specific `query`, `path`, and `body` types. We
91
+ * can't write a generic that's tight enough to satisfy all 200+ SDK
92
+ * functions structurally without committing to a discriminated-union
93
+ * encoding of every operation. The `_` prefix marks this as internal —
94
+ * the typed wrappers in `pagination.gen.ts` are the supported public API.
95
+ *
96
+ * @internal
97
+ */
98
+ export declare const _withCursor: <TOptions>(options: {
99
+ query?: unknown;
100
+ [k: string]: unknown;
101
+ }, cursor: string | undefined) => TOptions;
42
102
  /**
43
103
  * Unwrap an SDK result, throwing on error.
44
104
  *
@@ -47,13 +107,36 @@ export declare const parseSentryLinkHeader: (header: string | null) => {
47
107
  */
48
108
  export declare const unwrapResult: <TData>(result: SdkResult<TData>, context: string) => UnwrappedResult<TData>;
49
109
  /**
50
- * Unwrap an SDK result and extract the next-page cursor from the
110
+ * Unwrap an SDK result and extract pagination cursors from the
51
111
  * Link header. Throws on error.
52
112
  *
53
- * Returns `{ data, nextCursor? }` if `nextCursor` is undefined,
54
- * there are no more pages.
113
+ * Returns `{ data, nextCursor?, prevCursor? }`. Each cursor is
114
+ * `undefined` when the corresponding rel does not exist or has
115
+ * `results="false"`.
55
116
  */
56
117
  export declare const unwrapPaginatedResult: <TData>(result: SdkResult<TData>, context: string) => PaginatedResponse<TData>;
118
+ /**
119
+ * Fetch a single page from a Sentry list endpoint and return both
120
+ * the data and the pagination cursors.
121
+ *
122
+ * Thin wrapper over an SDK function call: invokes the fetcher with
123
+ * an optional cursor, unwraps the result, and parses the Link header.
124
+ *
125
+ * Useful when you want manual control over pagination (e.g. exposing
126
+ * a "next page" button in a UI) instead of fetching all pages eagerly.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const { data, nextCursor } = await fetchPage(
131
+ * (cursor) => listAnOrganization_sRepositories({
132
+ * path: { organization_id_or_slug: 'my-org' },
133
+ * query: { cursor },
134
+ * }),
135
+ * 'listRepos',
136
+ * );
137
+ * ```
138
+ */
139
+ export declare const fetchPage: <TData, TError = unknown>(fetcher: PageFetcher<TData, TError>, context: string, cursor?: string) => Promise<PaginatedResponse<TData>>;
57
140
  /**
58
141
  * Automatically paginate through all pages of a Sentry list endpoint.
59
142
  *
@@ -72,4 +155,31 @@ export declare const unwrapPaginatedResult: <TData>(result: SdkResult<TData>, co
72
155
  * ```
73
156
  */
74
157
  export declare const paginateAll: <TItem, TError = unknown>(fetcher: PageFetcher<Array<TItem>, TError>, context: string, options?: PaginateAllOptions) => Promise<Array<TItem>>;
158
+ /**
159
+ * Paginate up to a hard limit of items, suppressing the next-cursor
160
+ * if the last fetched page had to be trimmed to fit.
161
+ *
162
+ * The trim-and-suppress behavior is intentional: returning a cursor
163
+ * that points past the trimmed items would cause callers resuming
164
+ * pagination to skip records. When the requested limit is reached
165
+ * mid-page, no `nextCursor` is returned and the caller should treat
166
+ * the result as the final page they're going to fetch.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * // Fetch up to 250 issues, in pages of 100 (Sentry's API max)
171
+ * const { data, nextCursor } = await paginateUpTo(
172
+ * (cursor) => listAnOrganization_sIssues({
173
+ * path: { organization_id_or_slug: 'my-org' },
174
+ * query: { cursor, limit: 100 },
175
+ * }),
176
+ * { limit: 250 },
177
+ * 'listIssues',
178
+ * );
179
+ * ```
180
+ */
181
+ export declare const paginateUpTo: <TItem, TError = unknown>(fetcher: PageFetcher<Array<TItem>, TError>, options: PaginateUpToOptions, context: string) => Promise<{
182
+ data: Array<TItem>;
183
+ nextCursor?: string;
184
+ }>;
75
185
  export {};
@@ -9494,7 +9494,6 @@ export type ListYourOrganizationsData = {
9494
9494
  * - `slug`: The organization slug
9495
9495
  * - `status`: The organization's current status (one of `active`, `pending_deletion`, or `deletion_in_progress`)
9496
9496
  * - `email` or `member_id`: Filter your organizations by the emails or [organization member IDs](/api/organizations/list-an-organizations-members/) of specific members included
9497
- * - `platform`: Filter your organizations to those with at least one project using this platform
9498
9497
  * - `query`: Filter your organizations by name, slug, and members that contain this substring
9499
9498
  *
9500
9499
  * Example: `query=(slug:foo AND status:active) OR (email:[thing-one@example.com,thing-two@example.com] AND query:bar)`
@@ -9506,7 +9505,6 @@ export type ListYourOrganizationsData = {
9506
9505
  *
9507
9506
  * Valid fields include:
9508
9507
  * - `members`: By number of members
9509
- * - `projects`: By number of projects
9510
9508
  * - `events`: By number of events in the past 24 hours
9511
9509
  *
9512
9510
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/api",
3
- "version": "0.131.0",
3
+ "version": "0.133.0",
4
4
  "description": "Official auto-generated TypeScript client for the Sentry public REST API",
5
5
  "keywords": [
6
6
  "sentry",
@@ -17,7 +17,9 @@
17
17
  "dist"
18
18
  ],
19
19
  "scripts": {
20
- "build": "node build.mjs"
20
+ "build": "node build.mjs",
21
+ "test": "bun test",
22
+ "typecheck": "tsc -p tsconfig.test.json"
21
23
  },
22
24
  "exports": {
23
25
  "import": "./dist/index.js",
@@ -36,6 +38,7 @@
36
38
  },
37
39
  "devDependencies": {
38
40
  "@hey-api/openapi-ts": "0.91.1",
41
+ "@types/bun": "^1.3.13",
39
42
  "@types/node": "^22",
40
43
  "typescript": "^5.9.3"
41
44
  },