@kalutskii/foundation 0.4.5 → 0.5.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.
- package/dist/index.d.ts +30 -6
- package/dist/index.js +4 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -191,21 +191,42 @@ declare const log: {
|
|
|
191
191
|
error: (message: string, service?: string, stack?: string) => void;
|
|
192
192
|
};
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Utility type that simplifies a given type T by flattening its structure.
|
|
196
|
+
* This is particularly useful for improving the readability of complex types.
|
|
197
|
+
*/
|
|
198
|
+
type Simplify<T> = {
|
|
199
|
+
[K in keyof T]: T[K];
|
|
200
|
+
} & {};
|
|
194
201
|
/**
|
|
195
202
|
* A utility type that represents a value that can be of type T or null.
|
|
196
203
|
* Commonly used for optional fields in data models or function return types.
|
|
197
204
|
*
|
|
198
|
-
* ```
|
|
205
|
+
* ```ts
|
|
199
206
|
* export type ObjectSelect = XOR<
|
|
200
207
|
* Pick<Object, 'id'>,
|
|
201
208
|
* Pick<Object, 'anotherUniqueField'>
|
|
202
209
|
* >;
|
|
203
210
|
*/
|
|
204
|
-
type XOR<T, U> =
|
|
211
|
+
type XOR<T, U> = Simplify<T & {
|
|
205
212
|
[K in keyof U]?: never;
|
|
206
|
-
}
|
|
213
|
+
}> | Simplify<U & {
|
|
207
214
|
[K in keyof T]?: never;
|
|
208
|
-
}
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Utility type that ensures at least one property from the specified
|
|
218
|
+
* keys of a given type T is required, while the rest remain optional.
|
|
219
|
+
*
|
|
220
|
+
* This is useful for scenarios where you want to enforce that at least one
|
|
221
|
+
* of several optional (nullable) properties must be provided in an object.
|
|
222
|
+
*
|
|
223
|
+
* ```ts
|
|
224
|
+
* type Example = AtLeastOne<{ a?: string; b?: number; c?: boolean }>;
|
|
225
|
+
* // Valid: { a: "hello" }, { b: 42 }, { c: true }, { a: "hello", b: 42 }
|
|
226
|
+
* // Invalid: {}, { a: undefined, b: undefined, c: undefined }
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
type AtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends keyof T ? Simplify<Required<Pick<T, Keys>> & Partial<Omit<T, Keys>>> : never;
|
|
209
230
|
|
|
210
231
|
/** Options for configuring the JWT service. */
|
|
211
232
|
type JWTServiceOptions = {
|
|
@@ -241,15 +262,18 @@ declare class ZodJWTService<TPayloadOrSchema> {
|
|
|
241
262
|
/**
|
|
242
263
|
* Decodes a JWT token, and if a Zod schema is provided, validates the payload against it.
|
|
243
264
|
* Returns the decoded payload if valid, or null if invalid or if the token cannot be decoded.
|
|
265
|
+
*
|
|
244
266
|
* Example usage: `const payload = await JWTServiceInstance.decode(token);`
|
|
245
267
|
*/
|
|
246
268
|
decode(token: string): Promise<Payload<TPayloadOrSchema> | null>;
|
|
247
269
|
/**
|
|
248
270
|
* Verifies and decodes a JWT token using the provided secret and configured algorithm,
|
|
249
|
-
* then validates the payload against the Zod schema if one is provided.
|
|
271
|
+
* then validates the payload against the Zod schema if one is provided.
|
|
272
|
+
*
|
|
273
|
+
* Throws an error if verification fails or if the payload is invalid according to the schema.
|
|
250
274
|
* Example usage: `const payload = await JWTServiceInstance.verifyOrThrow(token, 'my-secret');`
|
|
251
275
|
*/
|
|
252
276
|
verifyOrThrow(token: string, secret: string): Promise<Payload<TPayloadOrSchema>>;
|
|
253
277
|
}
|
|
254
278
|
|
|
255
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type SerializeDates, type SuccessStatusCode, type XOR, ZodJWTService, asQueryBoolean, asQueryNumber, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, measureExecutionTime, onHandlerError, respond, safeExecute, success };
|
|
279
|
+
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type SerializeDates, type Simplify, type SuccessStatusCode, type XOR, ZodJWTService, asQueryBoolean, asQueryNumber, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, measureExecutionTime, onHandlerError, respond, safeExecute, success };
|
package/dist/index.js
CHANGED
|
@@ -189,6 +189,7 @@ var ZodJWTService = class {
|
|
|
189
189
|
/**
|
|
190
190
|
* Decodes a JWT token, and if a Zod schema is provided, validates the payload against it.
|
|
191
191
|
* Returns the decoded payload if valid, or null if invalid or if the token cannot be decoded.
|
|
192
|
+
*
|
|
192
193
|
* Example usage: `const payload = await JWTServiceInstance.decode(token);`
|
|
193
194
|
*/
|
|
194
195
|
async decode(token) {
|
|
@@ -201,7 +202,9 @@ var ZodJWTService = class {
|
|
|
201
202
|
}
|
|
202
203
|
/**
|
|
203
204
|
* Verifies and decodes a JWT token using the provided secret and configured algorithm,
|
|
204
|
-
* then validates the payload against the Zod schema if one is provided.
|
|
205
|
+
* then validates the payload against the Zod schema if one is provided.
|
|
206
|
+
*
|
|
207
|
+
* Throws an error if verification fails or if the payload is invalid according to the schema.
|
|
205
208
|
* Example usage: `const payload = await JWTServiceInstance.verifyOrThrow(token, 'my-secret');`
|
|
206
209
|
*/
|
|
207
210
|
async verifyOrThrow(token, secret) {
|