@payez/next-mvp 4.4.6 → 4.4.8
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/api-handlers/account/change-password.js +28 -6
- package/dist/auth/better-auth.d.ts +62 -15
- package/dist/auth/better-auth.js +180 -19
- package/dist/client/better-auth-client.d.ts +101 -956
- package/dist/config/env.d.ts +0 -2
- package/dist/config/env.js +0 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -1
- package/dist/lib/idp-client-config.js +8 -1
- package/dist/lib/never-in-response.d.ts +30 -0
- package/dist/lib/never-in-response.js +71 -0
- package/dist/lib/nextauth-secret.d.ts +51 -0
- package/dist/lib/nextauth-secret.js +141 -0
- package/dist/lib/safe-error-response.d.ts +6 -6
- package/dist/lib/safe-error-response.js +6 -6
- package/dist/lib/two-factor-verify-failure.d.ts +36 -3
- package/dist/lib/two-factor-verify-failure.js +79 -2
- package/dist/middleware/create-middleware.d.ts +2 -0
- package/dist/middleware/create-middleware.js +36 -0
- package/dist/pages/login/page.js +5 -0
- package/dist/pages/verify-code/page.js +4 -2
- package/dist/routes/auth/settings.js +4 -1
- package/dist/server/auth.d.ts +36 -294
- package/dist/server/auth.js +22 -25
- package/dist/vibe/client.d.ts +132 -16
- package/dist/vibe/client.js +288 -82
- package/dist/vibe/document-unwrap.d.ts +50 -0
- package/dist/vibe/document-unwrap.js +78 -0
- package/dist/vibe/errors.d.ts +17 -0
- package/dist/vibe/errors.js +21 -1
- package/dist/vibe/generic.d.ts +2 -49
- package/dist/vibe/generic.js +17 -78
- package/dist/vibe/index.d.ts +1 -1
- package/dist/vibe/index.js +2 -1
- package/package.json +17 -2
- package/src/api-handlers/account/change-password.ts +31 -6
- package/src/auth/better-auth.ts +188 -21
- package/src/config/env.ts +0 -2
- package/src/index.ts +4 -0
- package/src/lib/idp-client-config.ts +8 -1
- package/src/lib/never-in-response.ts +64 -0
- package/src/lib/nextauth-secret.ts +168 -0
- package/src/lib/safe-error-response.ts +6 -6
- package/src/lib/two-factor-verify-failure.ts +86 -5
- package/src/middleware/create-middleware.ts +42 -0
- package/src/pages/login/page.tsx +4 -0
- package/src/pages/verify-code/page.tsx +4 -2
- package/src/routes/auth/settings.ts +5 -1
- package/src/server/auth.ts +23 -29
- package/src/vibe/client.ts +378 -91
- package/src/vibe/document-unwrap.ts +103 -0
- package/src/vibe/errors.ts +24 -0
- package/src/vibe/generic.ts +8 -100
- package/src/vibe/index.ts +1 -0
package/dist/vibe/client.d.ts
CHANGED
|
@@ -49,7 +49,13 @@ export interface VibeRetryConfig {
|
|
|
49
49
|
retryOnRateLimit?: boolean;
|
|
50
50
|
}
|
|
51
51
|
export interface VibeClientConfig {
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Base URL for the Vibe API (defaults to VIBE_API_URL env var).
|
|
54
|
+
*
|
|
55
|
+
* PAY-1767: proxy mode does NOT need this. Every request is sent to the IDP proxy as an endpoint
|
|
56
|
+
* PATH (`/v1/collections/...`), which is what the proxy validates and signs - it never builds a
|
|
57
|
+
* Vibe URL from this value. It is retained only for compatibility with consumers that still read it.
|
|
58
|
+
*/
|
|
53
59
|
baseUrl?: string;
|
|
54
60
|
/** Vibe Client ID (defaults to VIBE_CLIENT_ID env var) */
|
|
55
61
|
clientId?: string;
|
|
@@ -64,6 +70,15 @@ export interface VibeClientConfig {
|
|
|
64
70
|
* When set, requests are routed through the IDP proxy instead of directly to Vibe.
|
|
65
71
|
*/
|
|
66
72
|
appSigningKey?: string;
|
|
73
|
+
/**
|
|
74
|
+
* PAY-1767: which COLLECTION the table delegates address (defaults to VIBE_COLLECTION, then 'vibe_app').
|
|
75
|
+
*
|
|
76
|
+
* The Vibe API route is `/v1/collections/{collection}/tables/{table}`. This client used to hardcode
|
|
77
|
+
* `/api/v1/vibe_app/{table}` - a collection baked into the path with no route behind it. Pin the
|
|
78
|
+
* collection explicitly at the call site when your tables do not live in `vibe_app` (the UMI
|
|
79
|
+
* VIBE_COLLECTION-double-duty lesson, POST-INSTALL.md item 16).
|
|
80
|
+
*/
|
|
81
|
+
collection?: string;
|
|
67
82
|
/** Custom fetch function (for testing or custom auth) */
|
|
68
83
|
fetch?: typeof fetch;
|
|
69
84
|
/** Retry configuration for transient errors */
|
|
@@ -92,7 +107,13 @@ export interface FindManyOptions<T> {
|
|
|
92
107
|
take?: number;
|
|
93
108
|
skip?: number;
|
|
94
109
|
}
|
|
95
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Options for findUnique.
|
|
112
|
+
*
|
|
113
|
+
* PAY-1767 (NightHawk 64534 MUST 2): `where.id` is the DOCUMENT id - the storage-layer primary key the
|
|
114
|
+
* route constrains (`{id:int}`), NOT a row's own `id` column. The unwrapped row exposes it as
|
|
115
|
+
* `_vibe_doc_id`; use THAT value for a subsequent update/delete.
|
|
116
|
+
*/
|
|
96
117
|
export interface FindUniqueOptions {
|
|
97
118
|
where: {
|
|
98
119
|
id: number;
|
|
@@ -102,14 +123,16 @@ export interface FindUniqueOptions {
|
|
|
102
123
|
export interface CreateOptions<T> {
|
|
103
124
|
data: Omit<T, 'id' | 'created_at' | 'updated_at'>;
|
|
104
125
|
}
|
|
105
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Options for update. `where.id` is the DOCUMENT id (see FindUniqueOptions), not a row's own id column.
|
|
128
|
+
*/
|
|
106
129
|
export interface UpdateOptions<T> {
|
|
107
130
|
where: {
|
|
108
131
|
id: number;
|
|
109
132
|
};
|
|
110
133
|
data: Partial<Omit<T, 'id' | 'created_at' | 'updated_at'>>;
|
|
111
134
|
}
|
|
112
|
-
/** Options for delete */
|
|
135
|
+
/** Options for delete. `where.id` is the DOCUMENT id (see FindUniqueOptions). */
|
|
113
136
|
export interface DeleteOptions {
|
|
114
137
|
where: {
|
|
115
138
|
id: number;
|
|
@@ -122,8 +145,36 @@ export interface CountOptions<T> {
|
|
|
122
145
|
/** Result of findMany with metadata */
|
|
123
146
|
export interface FindManyResult<T> {
|
|
124
147
|
data: T[];
|
|
148
|
+
/**
|
|
149
|
+
* PAY-1767 (NightHawk 64552 item B): true when `data` is a PAGE of a larger population. Read from Core's
|
|
150
|
+
* `pagination.totalCount`; a caller must not treat `data.length` as the table's size.
|
|
151
|
+
*/
|
|
152
|
+
hasMore?: boolean;
|
|
125
153
|
meta: VibeMeta;
|
|
126
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* PAY-1767: the most records `createMany` will create in one call. It is per-record and NOT atomic, so a
|
|
157
|
+
* ceiling bounds the blast radius of a partial failure. 50 is the house's only batch ceiling (Vibe's own
|
|
158
|
+
* DecryptController BATCH_TOO_LARGE = 50).
|
|
159
|
+
*/
|
|
160
|
+
export declare const MAX_BATCH_CREATE_ROWS = 50;
|
|
161
|
+
/**
|
|
162
|
+
* PAY-1767: the default page size findMany asks the query route for. Core clamps pageSize/limit to 100
|
|
163
|
+
* (DocumentsController.Query), so this is the most one call returns.
|
|
164
|
+
*/
|
|
165
|
+
export declare const MAX_FIND_MANY_PAGE_SIZE = 100;
|
|
166
|
+
/**
|
|
167
|
+
* PAY-1767: map a Prisma-style `where` to Core's VibeFilterNode OBJECT.
|
|
168
|
+
*
|
|
169
|
+
* { status: 'active' } -> { 'status': { eq: 'active' } }
|
|
170
|
+
* { score: { gt: 5 } } -> { 'score': { gt: 5 } }
|
|
171
|
+
* { status: 'a', tier: { in: [] } } -> { AND: [ {status:{eq:'a'}}, {tier:{in:[]}} ] }
|
|
172
|
+
*
|
|
173
|
+
* A field name is used as-is: a top-level document column (document_id, created_at...) or a JSONB path
|
|
174
|
+
* (Core treats an unknown name as data->>'name'; a nested path like 'data.x' is honoured explicitly).
|
|
175
|
+
* An unknown OPERATOR throws - dropping an operator would widen the result silently.
|
|
176
|
+
*/
|
|
177
|
+
export declare function buildVibeFilter(where: Record<string, unknown>, table: string): Record<string, unknown>;
|
|
127
178
|
/**
|
|
128
179
|
* Delegate class for table operations.
|
|
129
180
|
* Provides Prisma-style methods for a specific table.
|
|
@@ -133,9 +184,33 @@ export declare class VibeTableDelegate<T extends VibeTableName> {
|
|
|
133
184
|
private client;
|
|
134
185
|
constructor(tableName: T, client: VibeClient);
|
|
135
186
|
/**
|
|
136
|
-
*
|
|
187
|
+
* PAY-1767: the Vibe API route for this table's document collection.
|
|
188
|
+
* `/v1/collections/{collection}/tables/{table}` (Core DocumentsController.cs:15) - the same shape
|
|
189
|
+
* generic.ts and sessions.ts already use. The OLD `/api/v1/vibe_app/{table}` had no route behind it.
|
|
190
|
+
*/
|
|
191
|
+
private tableEndpoint;
|
|
192
|
+
/**
|
|
193
|
+
* Find multiple records, WITH filtering, sorting and paging honoured.
|
|
194
|
+
*
|
|
195
|
+
* PAY-1767 (NightHawk 64534 MUST 1, QAPert 64530, BAPert 64535). The GET list route
|
|
196
|
+
* (`GET /v1/collections/{c}/tables/{t}`, Core DocumentsController.List :44-48) binds ONLY `page` and
|
|
197
|
+
* `pageSize` - it reads no filter, sort or offset, so sending where/orderBy/take/skip there DROPPED them
|
|
198
|
+
* silently. Through the proxy that is worse than loud: a proxied MVP service account is ADMIN mode
|
|
199
|
+
* (HasValidContext), so the ownership filter is bypassed and an unfiltered page is 20 ARBITRARY rows of
|
|
200
|
+
* the tenant - caller code doing `rows[0]` gets the WRONG record with no error.
|
|
201
|
+
*
|
|
202
|
+
* So this now goes to `POST .../tables/{t}/query`, which binds QueryRequest (Filter / OrderBy / Page /
|
|
203
|
+
* PageSize / Limit). The FILTER is a VibeFilterNode OBJECT - `{ "<field>": { "<op>": value } }` - NOT the
|
|
204
|
+
* filter ARRAY that sessions.ts sends: QueryRequest.Filter is typed VibeFilterNode, which has no array
|
|
205
|
+
* form (measured at Core origin/master; CliInitProjectService.cs:197 builds the same object shape). An
|
|
206
|
+
* unmappable option THROWS rather than being dropped.
|
|
137
207
|
*/
|
|
138
208
|
findMany(options?: FindManyOptions<VibeTableType<T>>): Promise<FindManyResult<VibeTableType<T>>>;
|
|
209
|
+
/**
|
|
210
|
+
* PAY-1767: map the Prisma-style findMany options onto Core's QueryRequest body. THROWS on anything the
|
|
211
|
+
* query endpoint cannot express, so nothing is silently dropped.
|
|
212
|
+
*/
|
|
213
|
+
private buildQueryBody;
|
|
139
214
|
/**
|
|
140
215
|
* Find a single record by ID.
|
|
141
216
|
* Throws VibeNotFoundError if not found.
|
|
@@ -147,8 +222,12 @@ export declare class VibeTableDelegate<T extends VibeTableName> {
|
|
|
147
222
|
*/
|
|
148
223
|
findUniqueOrNull(options: FindUniqueOptions): Promise<VibeTableType<T> | null>;
|
|
149
224
|
/**
|
|
150
|
-
* Find the first record
|
|
225
|
+
* Find the first record.
|
|
151
226
|
* Returns null if none found.
|
|
227
|
+
*
|
|
228
|
+
* PAY-1767: takes the first row of the (caller-owned, created_at-ordered) list. Any where/orderBy in
|
|
229
|
+
* `options` is passed through to findMany, which REFUSES them on this route rather than dropping them,
|
|
230
|
+
* so this cannot pretend to filter.
|
|
152
231
|
*/
|
|
153
232
|
findFirst(options?: FindManyOptions<VibeTableType<T>>): Promise<VibeTableType<T> | null>;
|
|
154
233
|
/**
|
|
@@ -163,19 +242,45 @@ export declare class VibeTableDelegate<T extends VibeTableName> {
|
|
|
163
242
|
/**
|
|
164
243
|
* Delete a record by ID (soft delete).
|
|
165
244
|
* Throws VibeNotFoundError if not found.
|
|
245
|
+
*
|
|
246
|
+
* PAY-1767 (NightHawk 64578 item 2): Core answers DELETE with **204 No Content** (DocumentsController
|
|
247
|
+
* Delete returns NoContent()), so a SUCCESSFUL delete carries NO document - and there is none to unwrap.
|
|
248
|
+
* This must therefore NOT go through requireRow (that is the create/update rule: "a success WITH no
|
|
249
|
+
* document throws"). A 2xx with no body is the success here; the request layer already resolves it to an
|
|
250
|
+
* empty success. Returns null when the server sent no document.
|
|
166
251
|
*/
|
|
167
|
-
delete(options: DeleteOptions): Promise<VibeTableType<T
|
|
252
|
+
delete(options: DeleteOptions): Promise<VibeTableType<T> | null>;
|
|
253
|
+
/** Unwrap a single-document response, or THROW - never return an empty object typed as a row. */
|
|
254
|
+
private requireRow;
|
|
168
255
|
/**
|
|
169
256
|
* Count records matching the filter.
|
|
257
|
+
*
|
|
258
|
+
* PAY-1767 (NightHawk 64534): goes to POST /query with limit:0, which is Core's COUNT-ONLY mode
|
|
259
|
+
* (DocumentsController.Query returns an empty Data array plus Pagination.TotalCount). So this is the
|
|
260
|
+
* true population of the filter, not the first page's size.
|
|
170
261
|
*/
|
|
171
262
|
count(options?: CountOptions<VibeTableType<T>>): Promise<number>;
|
|
172
263
|
/**
|
|
173
|
-
* Create multiple records
|
|
264
|
+
* Create multiple records.
|
|
265
|
+
*
|
|
266
|
+
* PAY-1767: the old path `/api/v1/vibe_app/batch` has no route (there is no documents batch endpoint in
|
|
267
|
+
* Core's Vibe Public API), so this CANNOT be atomic here. Until a Core batch route exists, this creates
|
|
268
|
+
* each record against the REAL table endpoint in turn.
|
|
269
|
+
*
|
|
270
|
+
* BOUNDED ON PURPOSE (BAPert 64527). Non-atomic is tolerable only while the blast radius is small, so a
|
|
271
|
+
* request above MAX_BATCH_CREATE_ROWS is REFUSED before anything is sent. 50 matches the house's only
|
|
272
|
+
* batch ceiling (Vibe's DecryptController BATCH_TOO_LARGE).
|
|
273
|
+
*
|
|
274
|
+
* PARTIAL FAILURE IS REPORTED, NOT SWALLOWED (NightHawk 64534 condition (a)). A failure at item k throws
|
|
275
|
+
* a VibeBatchCreateError that CARRIES the count and the document ids already created - a cap cannot fix
|
|
276
|
+
* partial failure, only reporting it can. The created rows are unwrapped (MUST 2) so their own fields are
|
|
277
|
+
* present, not the wrapper's.
|
|
174
278
|
*/
|
|
175
279
|
createMany(options: {
|
|
176
280
|
data: CreateOptions<VibeTableType<T>>['data'][];
|
|
177
281
|
}): Promise<{
|
|
178
282
|
count: number;
|
|
283
|
+
ids: Array<number | string>;
|
|
179
284
|
}>;
|
|
180
285
|
}
|
|
181
286
|
/**
|
|
@@ -205,9 +310,19 @@ export declare class VibeClient {
|
|
|
205
310
|
* Message format: {timestamp}|{method}|{endpoint}
|
|
206
311
|
*/
|
|
207
312
|
private generateProxySignature;
|
|
313
|
+
/**
|
|
314
|
+
* PAY-1767: the Vibe API endpoint PATH for a table in this client's collection.
|
|
315
|
+
* `/v1/collections/{collection}/tables/{table}[/{id}]` - what the IDP proxy validates, signs and forwards.
|
|
316
|
+
* Returned as a PATH, not a URL: proxy mode needs no VIBE_API_URL (the proxy owns the base).
|
|
317
|
+
*/
|
|
318
|
+
tableEndpoint(table: string, id?: number | string): string;
|
|
208
319
|
/**
|
|
209
320
|
* Make a request through the IDP Vibe proxy.
|
|
210
321
|
* The proxy handles credential injection securely.
|
|
322
|
+
*
|
|
323
|
+
* PAY-1767: `endpoint` is the RAW path (+query) to forward. It is what gets signed and sent, so this
|
|
324
|
+
* takes a path directly rather than parsing one out of a URL - proxy mode is complete without a Vibe
|
|
325
|
+
* base URL, which is exactly what an endpoint-path call needs.
|
|
211
326
|
*/
|
|
212
327
|
private requestViaProxy;
|
|
213
328
|
/**
|
|
@@ -220,27 +335,28 @@ export declare class VibeClient {
|
|
|
220
335
|
* Routing:
|
|
221
336
|
* - All requests route through the IDP proxy (requires VIBE_HMAC_KEY + IDP_URL)
|
|
222
337
|
*
|
|
338
|
+
* PAY-1767: `urlOrPath` is EITHER a full URL or a bare Vibe path ('/v1/collections/...'). Proxy mode
|
|
339
|
+
* signs and forwards the PATH either way, so a caller with only a path (the table delegates) needs no
|
|
340
|
+
* Vibe base URL - VIBE_API_URL is not required to make a proxied call.
|
|
341
|
+
*
|
|
223
342
|
* Retry behavior:
|
|
224
343
|
* - 5xx errors: Retry up to maxRetries times with exponential backoff
|
|
225
344
|
* - 429 errors: Retry once after Retry-After delay (if retryOnRateLimit enabled)
|
|
226
345
|
* - 401/403 errors: No retry (auth errors)
|
|
227
346
|
* - Network errors: Retry with backoff
|
|
228
347
|
*/
|
|
229
|
-
request<T>(
|
|
348
|
+
request<T>(urlOrPath: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE', body?: unknown, authToken?: string): Promise<VibeResponse<T>>;
|
|
230
349
|
/**
|
|
231
350
|
* Parse error response body, handling non-JSON responses gracefully.
|
|
232
351
|
*/
|
|
233
352
|
private parseErrorResponse;
|
|
234
353
|
/**
|
|
235
354
|
* Fetch the schema for type generation.
|
|
355
|
+
*
|
|
356
|
+
* PAY-1767: the old path `/api/v1/vibe_app/schema` has no route. The real per-collection schema route is
|
|
357
|
+
* `/v1/mvp/schemas/{collection}` (Core MvpSchemaController.cs:65). Returns the collection schema DTO.
|
|
236
358
|
*/
|
|
237
|
-
getSchema(): Promise<Record<string,
|
|
238
|
-
columns: Array<{
|
|
239
|
-
name: string;
|
|
240
|
-
type: string;
|
|
241
|
-
nullable: boolean;
|
|
242
|
-
}>;
|
|
243
|
-
}>>;
|
|
359
|
+
getSchema(): Promise<Record<string, unknown>>;
|
|
244
360
|
}
|
|
245
361
|
/**
|
|
246
362
|
* Default Vibe client instance.
|