@turndown/library 0.0.25 → 0.0.26

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,59 @@
1
+ /**
2
+ * API Response Types
3
+ * Standard response structure for all API endpoints
4
+ */
5
+ import { TurndownObject } from "../base";
6
+ export interface ApiError {
7
+ message: string;
8
+ code?: string;
9
+ details?: TurndownObject;
10
+ }
11
+ export interface ApiMeta {
12
+ timestamp: string;
13
+ version: string;
14
+ environment: string;
15
+ requestId?: string;
16
+ }
17
+ export interface ApiResponse<T = TurndownObject> {
18
+ success: boolean;
19
+ data?: T;
20
+ error?: ApiError;
21
+ meta?: ApiMeta;
22
+ }
23
+ /**
24
+ * Error Codes
25
+ * Standardized error codes used across the platform
26
+ */
27
+ export declare const ErrorCodes: {
28
+ readonly BAD_REQUEST: "BAD_REQUEST";
29
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
30
+ readonly MISSING_FIELDS: "MISSING_FIELDS";
31
+ readonly UNAUTHORIZED: "UNAUTHORIZED";
32
+ readonly INVALID_TOKEN: "INVALID_TOKEN";
33
+ readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
34
+ readonly FORBIDDEN: "FORBIDDEN";
35
+ readonly NOT_FOUND: "NOT_FOUND";
36
+ readonly CONFLICT: "CONFLICT";
37
+ readonly ALREADY_EXISTS: "ALREADY_EXISTS";
38
+ readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
39
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
40
+ readonly DATABASE_ERROR: "DATABASE_ERROR";
41
+ };
42
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
43
+ /**
44
+ * HTTP Status Codes
45
+ * Common status codes used in responses
46
+ */
47
+ export declare const HttpStatus: {
48
+ readonly OK: 200;
49
+ readonly CREATED: 201;
50
+ readonly NO_CONTENT: 204;
51
+ readonly BAD_REQUEST: 400;
52
+ readonly UNAUTHORIZED: 401;
53
+ readonly FORBIDDEN: 403;
54
+ readonly NOT_FOUND: 404;
55
+ readonly CONFLICT: 409;
56
+ readonly RATE_LIMIT: 429;
57
+ readonly INTERNAL_ERROR: 500;
58
+ };
59
+ export type HttpStatusCode = (typeof HttpStatus)[keyof typeof HttpStatus];
@@ -0,0 +1,46 @@
1
+ /**
2
+ * API Response Types
3
+ * Standard response structure for all API endpoints
4
+ */
5
+ /**
6
+ * Error Codes
7
+ * Standardized error codes used across the platform
8
+ */
9
+ export const ErrorCodes = {
10
+ // 400 - Bad Request
11
+ BAD_REQUEST: "BAD_REQUEST",
12
+ VALIDATION_ERROR: "VALIDATION_ERROR",
13
+ MISSING_FIELDS: "MISSING_FIELDS",
14
+ // 401 - Unauthorized
15
+ UNAUTHORIZED: "UNAUTHORIZED",
16
+ INVALID_TOKEN: "INVALID_TOKEN",
17
+ INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
18
+ // 403 - Forbidden
19
+ FORBIDDEN: "FORBIDDEN",
20
+ // 404 - Not Found
21
+ NOT_FOUND: "NOT_FOUND",
22
+ // 409 - Conflict
23
+ CONFLICT: "CONFLICT",
24
+ ALREADY_EXISTS: "ALREADY_EXISTS",
25
+ // 429 - Rate Limiting
26
+ RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED",
27
+ // 500 - Server Errors
28
+ INTERNAL_ERROR: "INTERNAL_ERROR",
29
+ DATABASE_ERROR: "DATABASE_ERROR",
30
+ };
31
+ /**
32
+ * HTTP Status Codes
33
+ * Common status codes used in responses
34
+ */
35
+ export const HttpStatus = {
36
+ OK: 200,
37
+ CREATED: 201,
38
+ NO_CONTENT: 204,
39
+ BAD_REQUEST: 400,
40
+ UNAUTHORIZED: 401,
41
+ FORBIDDEN: 403,
42
+ NOT_FOUND: 404,
43
+ CONFLICT: 409,
44
+ RATE_LIMIT: 429,
45
+ INTERNAL_ERROR: 500,
46
+ };
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Authentication Types
3
+ * Request/Response types for authentication endpoints
4
+ */
5
+ import { User, AccountType, DeviceInfo } from "../user";
6
+ /**
7
+ * Token Payload
8
+ * JWT token payload structure
9
+ */
10
+ export interface TokenPayload {
11
+ userId: string;
12
+ email: string;
13
+ name: string;
14
+ }
15
+ /**
16
+ * Auth Token Response
17
+ * Standard structure for authentication responses with tokens
18
+ */
19
+ export interface AuthTokenResponse {
20
+ user: User;
21
+ accessToken: string;
22
+ refreshToken: string;
23
+ expiresAt: string;
24
+ }
25
+ /**
26
+ * Signup Request
27
+ * Request body for user signup
28
+ */
29
+ export interface SignupRequest {
30
+ email: string;
31
+ password: string;
32
+ firstName: string;
33
+ lastName?: string;
34
+ accountType: AccountType;
35
+ deviceInfo?: DeviceInfo;
36
+ }
37
+ /**
38
+ * Signup Response
39
+ * Response from signup endpoint
40
+ */
41
+ export interface SignupResponse extends AuthTokenResponse {
42
+ }
43
+ /**
44
+ * Signin Request
45
+ * Request body for user signin
46
+ */
47
+ export interface SigninRequest {
48
+ email: string;
49
+ password: string;
50
+ deviceInfo?: DeviceInfo;
51
+ }
52
+ /**
53
+ * Signin Response
54
+ * Response from signin endpoint
55
+ */
56
+ export interface SigninResponse extends AuthTokenResponse {
57
+ }
58
+ /**
59
+ * Refresh Token Request
60
+ * Request body for token refresh
61
+ */
62
+ export interface RefreshTokenRequest {
63
+ refreshToken: string;
64
+ deviceInfo?: DeviceInfo;
65
+ }
66
+ /**
67
+ * Refresh Token Response
68
+ * Response from token refresh endpoint
69
+ */
70
+ export interface RefreshTokenResponse extends AuthTokenResponse {
71
+ }
72
+ /**
73
+ * Signout Request
74
+ * Request body for signout
75
+ */
76
+ export interface SignoutRequest {
77
+ refreshToken: string;
78
+ }
79
+ /**
80
+ * Signout All Request
81
+ * Request body for signing out from all devices
82
+ */
83
+ export interface SignoutAllRequest {
84
+ userId: string;
85
+ }
86
+ /**
87
+ * Get User Request
88
+ * Request parameters for getting user info
89
+ */
90
+ export interface GetUserRequest {
91
+ userId?: string;
92
+ email?: string;
93
+ }
94
+ /**
95
+ * Get User Response
96
+ * Response from get user endpoint
97
+ */
98
+ export interface GetUserResponse {
99
+ user: User | null;
100
+ }
101
+ /**
102
+ * Password Validation Rules
103
+ * Rules for password validation
104
+ */
105
+ export interface PasswordValidationRules {
106
+ minLength: number;
107
+ requireUppercase: boolean;
108
+ requireLowercase: boolean;
109
+ requireNumbers: boolean;
110
+ requireSpecialChars: boolean;
111
+ }
112
+ /**
113
+ * Password Validation Result
114
+ * Result of password validation
115
+ */
116
+ export interface PasswordValidationResult {
117
+ valid: boolean;
118
+ errors: string[];
119
+ }
120
+ /**
121
+ * Email Validation Result
122
+ * Result of email validation
123
+ */
124
+ export interface EmailValidationResult {
125
+ valid: boolean;
126
+ error?: string;
127
+ }
128
+ /**
129
+ * Rate Limit Status
130
+ * Information about rate limiting status
131
+ */
132
+ export interface RateLimitStatus {
133
+ isLimited: boolean;
134
+ attempts: number;
135
+ maxAttempts: number;
136
+ resetTime?: string;
137
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Authentication Types
3
+ * Request/Response types for authentication endpoints
4
+ */
5
+ export {};
@@ -3,16 +3,11 @@ export type TurndownObject<T = GenericTurndownObject> = Record<string, T> | T |
3
3
  export type ObjectValues<T> = T[keyof T];
4
4
  export type ObjectKeys<T> = [keyof T];
5
5
  export interface MetaData {
6
- company_id: string;
6
+ companyId: string;
7
7
  deleted: boolean;
8
- updated_by: string;
9
- created_by: string;
10
- created_at: Date;
11
- updated_at: Date;
8
+ updatedBy: string;
9
+ createdBy: string;
10
+ createdAt: Date;
11
+ updatedAt: Date;
12
12
  }
13
- export declare const STATUS: {
14
- readonly ACTIVE: "ACTIVE";
15
- readonly INACTIVE: "INACTIVE";
16
- };
17
- export type Status = ObjectValues<typeof STATUS>;
18
13
  export * from "./paging.types";
@@ -1,5 +1 @@
1
- export const STATUS = {
2
- ACTIVE: "ACTIVE",
3
- INACTIVE: "INACTIVE",
4
- };
5
1
  export * from "./paging.types";
@@ -1,16 +1,30 @@
1
+ /**
2
+ * Represents the pagination metadata for a paginated response.
3
+ */
1
4
  export interface PagingResult {
2
5
  hasNextPage: boolean;
3
6
  totalPages: number;
4
7
  totalRecords: number;
5
8
  }
9
+ /**
10
+ * A generic wrapper that combines data with pagination information.
11
+ * @template T - The type of data being paginated
12
+ */
6
13
  export interface DataWithPagingResult<T> {
7
14
  data: T;
8
15
  pagination: PagingResult;
9
16
  }
17
+ /**
18
+ * Defines a sorting condition for query results.
19
+ */
10
20
  export interface SortCondition {
11
21
  name: string;
12
22
  direction: "ASC" | "DESC";
13
23
  }
24
+ /**
25
+ * Defines a filter condition for querying data.
26
+ * Only one of valueString, valueNumber, or valueBoolean should be provided based on the field type.
27
+ */
14
28
  export interface FilterCondition {
15
29
  name: string;
16
30
  condition: "=" | ">" | "<" | "!=" | "LIKE" | "IN" | ">=" | "<=";
@@ -19,6 +33,9 @@ export interface FilterCondition {
19
33
  valueBoolean?: boolean;
20
34
  useAnd?: boolean;
21
35
  }
36
+ /**
37
+ * Represents a request for paginated data with optional sorting and filtering.
38
+ */
22
39
  export interface PaginationRequest {
23
40
  page: number;
24
41
  size: number;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Error Types
3
+ * Custom error types and validation error structures
4
+ */
5
+ import { ErrorCode } from "../api";
6
+ import { TurndownObject } from "../base";
7
+ /**
8
+ * Validation Error Detail
9
+ * Detailed information about a validation error
10
+ */
11
+ export interface ValidationErrorDetail {
12
+ field: string;
13
+ message: string;
14
+ value?: TurndownObject;
15
+ }
16
+ /**
17
+ * Missing Fields Error Detail
18
+ * Information about missing required fields
19
+ */
20
+ export interface MissingFieldsErrorDetail {
21
+ missingFields: string[];
22
+ }
23
+ /**
24
+ * Rate Limit Error Detail
25
+ * Information about rate limiting
26
+ */
27
+ export interface RateLimitErrorDetail {
28
+ retryAfter?: number;
29
+ message: string;
30
+ }
31
+ /**
32
+ * Error Response Detail
33
+ * Union type for all possible error details
34
+ */
35
+ export type ErrorResponseDetail = ValidationErrorDetail[] | MissingFieldsErrorDetail | RateLimitErrorDetail | Record<string, TurndownObject> | string;
36
+ /**
37
+ * Typed API Error
38
+ * API error with typed details
39
+ */
40
+ export interface TypedApiError<T = ErrorResponseDetail> {
41
+ message: string;
42
+ code: ErrorCode;
43
+ details?: T;
44
+ }
45
+ /**
46
+ * Error Helper Types
47
+ * For identifying specific error types
48
+ */
49
+ export type ValidationError = TypedApiError<ValidationErrorDetail[]>;
50
+ export type MissingFieldsError = TypedApiError<MissingFieldsErrorDetail>;
51
+ export type RateLimitError = TypedApiError<RateLimitErrorDetail>;
52
+ /**
53
+ * Type guard for ValidationError
54
+ */
55
+ export declare function isValidationError(error: TurndownObject): error is ValidationError;
56
+ /**
57
+ * Type guard for MissingFieldsError
58
+ */
59
+ export declare function isMissingFieldsError(error: TurndownObject): error is MissingFieldsError;
60
+ /**
61
+ * Type guard for RateLimitError
62
+ */
63
+ export declare function isRateLimitError(error: TurndownObject): error is RateLimitError;
64
+ /**
65
+ * Type guard for authentication errors
66
+ */
67
+ export declare function isAuthError(error: TurndownObject): boolean;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Error Types
3
+ * Custom error types and validation error structures
4
+ */
5
+ /**
6
+ * Type guard for ValidationError
7
+ */
8
+ export function isValidationError(error) {
9
+ return error?.code === "VALIDATION_ERROR" && Array.isArray(error?.details);
10
+ }
11
+ /**
12
+ * Type guard for MissingFieldsError
13
+ */
14
+ export function isMissingFieldsError(error) {
15
+ return (error?.code === "MISSING_FIELDS" &&
16
+ Array.isArray(error?.details?.missingFields));
17
+ }
18
+ /**
19
+ * Type guard for RateLimitError
20
+ */
21
+ export function isRateLimitError(error) {
22
+ return error?.code === "RATE_LIMIT_EXCEEDED";
23
+ }
24
+ /**
25
+ * Type guard for authentication errors
26
+ */
27
+ export function isAuthError(error) {
28
+ return (error?.code === "UNAUTHORIZED" ||
29
+ error?.code === "INVALID_TOKEN" ||
30
+ error?.code === "INVALID_CREDENTIALS");
31
+ }
@@ -1,2 +1,10 @@
1
- export * from "./user";
1
+ /**
2
+ * @turndown/shared-types
3
+ * Shared TypeScript types and interfaces for Turndown platform
4
+ * Used by both frontend (React Native/Web) and backend (Node.js)
5
+ */
6
+ export * from "./api";
7
+ export * from "./auth";
2
8
  export * from "./base";
9
+ export * from "./user";
10
+ export * from "./errors";
@@ -1,2 +1,10 @@
1
- export * from "./user";
1
+ /**
2
+ * @turndown/shared-types
3
+ * Shared TypeScript types and interfaces for Turndown platform
4
+ * Used by both frontend (React Native/Web) and backend (Node.js)
5
+ */
6
+ export * from "./api";
7
+ export * from "./auth";
2
8
  export * from "./base";
9
+ export * from "./user";
10
+ export * from "./errors";
@@ -1,24 +1,10 @@
1
- import { MetaData, ObjectValues, Status } from "@/types";
2
- export interface User extends Omit<MetaData, "created_by" | "updated_by"> {
1
+ import { MetaData, ObjectValues } from "@/types";
2
+ export interface User extends MetaData {
3
3
  id: string;
4
4
  firstName: string;
5
- lastName: string;
6
- mi: string;
7
- username: string;
5
+ lastName?: string | null;
8
6
  email: string;
9
- password: string;
10
- loginAttempts: number;
11
- locked: boolean;
12
- passwordLastReset: Date;
13
- passwordResetRequired: boolean;
14
- type: AccountType;
15
- status: Status;
16
- companyId: number;
17
- phoneNumber: string;
18
- phoneFormat: string;
19
- language: Language;
20
- biometrics: string;
21
- lastLogin: Date;
7
+ accountType: AccountType;
22
8
  }
23
9
  export declare const ACCOUNT_TYPE: {
24
10
  readonly TURNDOWN_ADMIN: "TURNDOWN_ADMIN";
@@ -35,3 +21,14 @@ export declare const LANGUAGE: {
35
21
  readonly GERMAN: "GERMAN";
36
22
  };
37
23
  export type Language = ObjectValues<typeof LANGUAGE>;
24
+ export interface DeviceInfo {
25
+ userAgent?: string;
26
+ ip?: string;
27
+ deviceName?: string;
28
+ }
29
+ export interface UserSession {
30
+ id: number;
31
+ deviceInfo?: DeviceInfo | null;
32
+ createdAt: string;
33
+ lastUsedAt: string;
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turndown/library",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "Shared TypeScript library for the Turndown suite.",
5
5
  "keywords": [
6
6
  "types",