@loomcore/common 0.0.3 → 0.0.5

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.
Files changed (32) hide show
  1. package/dist/errors/custom.error.d.ts +6 -0
  2. package/dist/errors/index.d.ts +2 -0
  3. package/dist/errors/validation.error.d.ts +10 -0
  4. package/dist/models/address.interface.d.ts +11 -0
  5. package/dist/models/api-response.interface.d.ts +8 -0
  6. package/dist/models/auditable.model.d.ts +12 -0
  7. package/dist/models/entity.model.d.ts +8 -0
  8. package/dist/models/error.interface.d.ts +4 -0
  9. package/dist/models/geo-json.interface.d.ts +12 -0
  10. package/dist/models/index.d.ts +15 -0
  11. package/dist/models/login-response.model.d.ts +18 -0
  12. package/dist/models/model-spec.interface.d.ts +15 -0
  13. package/dist/models/organization.model.d.ts +19 -0
  14. package/dist/models/paged-result.interface.d.ts +7 -0
  15. package/dist/models/password-reset-token.interface.d.ts +12 -0
  16. package/dist/models/query-options.model.d.ts +33 -0
  17. package/dist/models/token-response.model.d.ts +11 -0
  18. package/dist/models/user-context.model.d.ts +11 -0
  19. package/dist/models/user.model.d.ts +30 -0
  20. package/dist/types/index.d.ts +1 -0
  21. package/dist/types/sort-direction.type.d.ts +3 -0
  22. package/dist/utils/entity.utils.d.ts +25 -0
  23. package/dist/utils/index.d.ts +1 -0
  24. package/dist/validation/formats/date-time.d.ts +1 -0
  25. package/dist/validation/formats/date.d.ts +1 -0
  26. package/dist/validation/formats/email.d.ts +1 -0
  27. package/dist/validation/formats/objectid.d.ts +1 -0
  28. package/dist/validation/formats/time.d.ts +1 -0
  29. package/dist/validation/index.d.ts +5 -0
  30. package/dist/validation/typebox-extensions.d.ts +13 -0
  31. package/dist/validation/typebox-setup.d.ts +2 -0
  32. package/package.json +7 -3
@@ -0,0 +1,6 @@
1
+ import { IError } from '../models/error.interface.js';
2
+ export declare abstract class CustomError extends Error {
3
+ abstract statusCode: number;
4
+ protected constructor(message: string);
5
+ abstract serializeErrors(): IError[];
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from './custom.error.js';
2
+ export * from './validation.error.js';
@@ -0,0 +1,10 @@
1
+ import { CustomError } from './custom.error.js';
2
+ export declare class ValidationError extends CustomError {
3
+ statusCode: number;
4
+ protected validationError: any;
5
+ constructor(validationError: any);
6
+ serializeErrors(): {
7
+ message: string;
8
+ field?: string | undefined;
9
+ }[];
10
+ }
@@ -0,0 +1,11 @@
1
+ export interface IAddress {
2
+ address1?: string;
3
+ address2?: string;
4
+ address3?: string;
5
+ city?: string;
6
+ state?: string;
7
+ postalCode?: string;
8
+ countryCode?: string;
9
+ description?: string;
10
+ formattedAddress?: string;
11
+ }
@@ -0,0 +1,8 @@
1
+ import { IError } from './error.interface.js';
2
+ export type IApiResponse<T> = {
3
+ success?: boolean;
4
+ status?: number;
5
+ errors?: IError[];
6
+ messages?: string[];
7
+ data?: T | null;
8
+ };
@@ -0,0 +1,12 @@
1
+ export interface IAuditable {
2
+ _created: Date;
3
+ _createdBy: string;
4
+ _updated: Date;
5
+ _updatedBy: string;
6
+ }
7
+ export declare const AuditableSchema: import("@sinclair/typebox").TObject<{
8
+ _created: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
9
+ _createdBy: import("@sinclair/typebox").TString;
10
+ _updated: import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
11
+ _updatedBy: import("@sinclair/typebox").TString;
12
+ }>;
@@ -0,0 +1,8 @@
1
+ export interface IEntity {
2
+ _id: string;
3
+ _orgId?: string;
4
+ }
5
+ export declare const EntitySchema: import("@sinclair/typebox").TObject<{
6
+ _id: import("@sinclair/typebox").TString;
7
+ _orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
8
+ }>;
@@ -0,0 +1,4 @@
1
+ export interface IError {
2
+ message: string;
3
+ field?: string;
4
+ }
@@ -0,0 +1,12 @@
1
+ export interface IGeoJSON<T> {
2
+ type: string;
3
+ features: IGeoJSONFeature<T>[];
4
+ }
5
+ export interface IGeoJSONFeature<T> {
6
+ type: string;
7
+ geometry: {
8
+ type: string;
9
+ coordinates: number[];
10
+ };
11
+ properties: T;
12
+ }
@@ -0,0 +1,15 @@
1
+ export * from './user.model.js';
2
+ export * from './organization.model.js';
3
+ export * from './user-context.model.js';
4
+ export * from './entity.model.js';
5
+ export * from './login-response.model.js';
6
+ export * from './token-response.model.js';
7
+ export * from './auditable.model.js';
8
+ export * from './query-options.model.js';
9
+ export * from './password-reset-token.interface.js';
10
+ export * from './model-spec.interface.js';
11
+ export * from './paged-result.interface.js';
12
+ export * from './geo-json.interface.js';
13
+ export * from './address.interface.js';
14
+ export * from './error.interface.js';
15
+ export * from './api-response.interface.js';
@@ -0,0 +1,18 @@
1
+ import { ITokenResponse } from './token-response.model.js';
2
+ import { IUserContext } from './user-context.model.js';
3
+ export interface ILoginResponse {
4
+ tokens: ITokenResponse;
5
+ userContext: IUserContext;
6
+ }
7
+ export declare const LoginResponseSchema: import("@sinclair/typebox").TObject<{
8
+ tokens: import("@sinclair/typebox").TObject<{
9
+ accessToken: import("@sinclair/typebox").TString;
10
+ refreshToken: import("@sinclair/typebox").TString;
11
+ expiresOn: import("@sinclair/typebox").TNumber;
12
+ }>;
13
+ userContext: import("@sinclair/typebox").TObject<{
14
+ user: import("@sinclair/typebox").TObject<{}>;
15
+ _orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
16
+ }>;
17
+ }>;
18
+ export declare const LoginResponseSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
@@ -0,0 +1,15 @@
1
+ import { TSchema } from '@sinclair/typebox';
2
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
3
+ export interface IModelSpec<T extends TSchema = TSchema> {
4
+ schema: T;
5
+ partialSchema: TSchema;
6
+ fullSchema: T;
7
+ validator: ReturnType<typeof TypeCompiler.Compile>;
8
+ partialValidator: ReturnType<typeof TypeCompiler.Compile>;
9
+ fullValidator: ReturnType<typeof TypeCompiler.Compile>;
10
+ isAuditable?: boolean;
11
+ isMultiTenant?: boolean;
12
+ encode: <E>(entity: E, overrideSchema?: TSchema) => E;
13
+ decode: <E>(entity: E) => E;
14
+ clean: <E>(entity: E) => E;
15
+ }
@@ -0,0 +1,19 @@
1
+ import { IAuditable } from './auditable.model.js';
2
+ export interface IOrganization extends IAuditable {
3
+ _id: string;
4
+ name: string;
5
+ code: string;
6
+ description?: string;
7
+ status: number;
8
+ isMetaOrg: boolean;
9
+ authToken?: string;
10
+ }
11
+ export declare const OrganizationSchema: import("@sinclair/typebox").TObject<{
12
+ name: import("@sinclair/typebox").TString;
13
+ code: import("@sinclair/typebox").TString;
14
+ description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
15
+ status: import("@sinclair/typebox").TNumber;
16
+ isMetaOrg: import("@sinclair/typebox").TBoolean;
17
+ authToken: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
18
+ }>;
19
+ export declare const OrganizationSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
@@ -0,0 +1,7 @@
1
+ export interface IPagedResult<T> {
2
+ entities?: T[];
3
+ total?: number;
4
+ page?: number;
5
+ pageSize?: number;
6
+ totalPages?: number;
7
+ }
@@ -0,0 +1,12 @@
1
+ import { IEntity, IAuditable } from './index.js';
2
+ export interface IPasswordResetToken extends IEntity, IAuditable {
3
+ email: string;
4
+ token: string;
5
+ expiresOn: number;
6
+ }
7
+ export declare const PasswordResetTokenSchema: import("@sinclair/typebox").TObject<{
8
+ email: import("@sinclair/typebox").TString;
9
+ token: import("@sinclair/typebox").TString;
10
+ expiresOn: import("@sinclair/typebox").TNumber;
11
+ }>;
12
+ export declare const PasswordResetTokenSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
@@ -0,0 +1,33 @@
1
+ import { SortDirection } from '../types/sort-direction.type.js';
2
+ export type Filter = {
3
+ eq?: string | number | boolean | Date;
4
+ ne?: string | number | boolean | Date;
5
+ any?: string[] | number[];
6
+ all?: string[] | number[];
7
+ lt?: number | Date;
8
+ lte?: number | Date;
9
+ gt?: number | Date;
10
+ gte?: number | Date;
11
+ startsWith?: string;
12
+ endsWith?: string;
13
+ contains?: string;
14
+ };
15
+ export interface IQueryOptions {
16
+ orderBy?: string;
17
+ sortDirection?: SortDirection;
18
+ page?: number;
19
+ pageSize?: number;
20
+ filters?: {
21
+ [key: string]: Filter;
22
+ };
23
+ }
24
+ export declare class QueryOptions implements IQueryOptions {
25
+ orderBy?: string;
26
+ sortDirection: SortDirection;
27
+ page: number;
28
+ pageSize: number;
29
+ filters?: {
30
+ [key: string]: Filter;
31
+ };
32
+ constructor(options?: IQueryOptions);
33
+ }
@@ -0,0 +1,11 @@
1
+ export interface ITokenResponse {
2
+ accessToken: string;
3
+ refreshToken: string;
4
+ expiresOn: number;
5
+ }
6
+ export declare const TokenResponseSchema: import("@sinclair/typebox").TObject<{
7
+ accessToken: import("@sinclair/typebox").TString;
8
+ refreshToken: import("@sinclair/typebox").TString;
9
+ expiresOn: import("@sinclair/typebox").TNumber;
10
+ }>;
11
+ export declare const TokenResponseSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
@@ -0,0 +1,11 @@
1
+ import { IUser } from './user.model.js';
2
+ export interface IUserContext {
3
+ user: IUser;
4
+ _orgId?: string;
5
+ }
6
+ export declare const EmptyUserContext: IUserContext;
7
+ export declare const UserContextSchema: import("@sinclair/typebox").TObject<{
8
+ user: import("@sinclair/typebox").TObject<{}>;
9
+ _orgId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
10
+ }>;
11
+ export declare const UserContextSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
@@ -0,0 +1,30 @@
1
+ import { IAuditable } from './auditable.model.js';
2
+ import { IEntity } from './entity.model.js';
3
+ export interface IUser extends IAuditable, IEntity {
4
+ email: string;
5
+ firstName?: string;
6
+ lastName?: string;
7
+ displayName?: string;
8
+ password: string;
9
+ roles?: string[];
10
+ _lastLoggedIn?: Date;
11
+ _lastPasswordChange?: Date;
12
+ }
13
+ export declare const UserPasswordSchema: import("@sinclair/typebox").TObject<{
14
+ password: import("@sinclair/typebox").TString;
15
+ }>;
16
+ export declare const passwordValidator: import("@sinclair/typebox/compiler").TypeCheck<import("@sinclair/typebox").TObject<{
17
+ password: import("@sinclair/typebox").TString;
18
+ }>>;
19
+ export declare const UserSchema: import("@sinclair/typebox").TObject<{
20
+ email: import("@sinclair/typebox").TString;
21
+ firstName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
22
+ lastName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
23
+ displayName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
24
+ password: import("@sinclair/typebox").TString;
25
+ roles: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
26
+ _lastLoggedIn: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>>;
27
+ _lastPasswordChange: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>>;
28
+ }>;
29
+ export declare const UserSpec: import("./model-spec.interface.js").IModelSpec<import("@sinclair/typebox").TSchema>;
30
+ export declare const PublicUserSchema: import("@sinclair/typebox").TObject<{}>;
@@ -0,0 +1 @@
1
+ export * from './sort-direction.type.js';
@@ -0,0 +1,3 @@
1
+ export type SortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending' | {
2
+ $meta: string;
3
+ };
@@ -0,0 +1,25 @@
1
+ import { TSchema } from '@sinclair/typebox';
2
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
3
+ import { ValueError } from '@sinclair/typebox/errors';
4
+ import { IAuditable } from '../models/auditable.model.js';
5
+ import { IModelSpec } from '../models/model-spec.interface.js';
6
+ declare function getValidator(schema: TSchema): ReturnType<typeof TypeCompiler.Compile>;
7
+ declare function getModelSpec<T extends TSchema>(schema: T, options?: {
8
+ isAuditable?: boolean;
9
+ isMultiTenant?: boolean;
10
+ }): IModelSpec;
11
+ declare function validate(validator: ReturnType<typeof TypeCompiler.Compile>, data: unknown): ValueError[] | null;
12
+ declare function handleValidationResult(validationErrors: ValueError[] | null, methodName: string): void;
13
+ declare function isValidObjectId(id: any): boolean;
14
+ declare function isAuditable(entity: any): entity is IAuditable;
15
+ declare function isDecimalMultipleOf(value: number, multipleOf: number, precision?: number): boolean;
16
+ export declare const entityUtils: {
17
+ handleValidationResult: typeof handleValidationResult;
18
+ isValidObjectId: typeof isValidObjectId;
19
+ isAuditable: typeof isAuditable;
20
+ getValidator: typeof getValidator;
21
+ getModelSpec: typeof getModelSpec;
22
+ validate: typeof validate;
23
+ isDecimalMultipleOf: typeof isDecimalMultipleOf;
24
+ };
25
+ export {};
@@ -0,0 +1 @@
1
+ export * from './entity.utils.js';
@@ -0,0 +1 @@
1
+ export declare function IsDateTime(value: string, strictTimeZone?: boolean): boolean;
@@ -0,0 +1 @@
1
+ export declare function IsDate(value: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function IsEmail(value: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function IsObjectId(value: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function IsTime(value: string, strictTimeZone?: boolean): boolean;
@@ -0,0 +1,5 @@
1
+ export * from './typebox-setup.js';
2
+ export * from './typebox-extensions.js';
3
+ export * from './formats/date.js';
4
+ export * from './formats/time.js';
5
+ export * from './formats/date-time.js';
@@ -0,0 +1,13 @@
1
+ import { Kind, TSchema, NumberOptions } from '@sinclair/typebox';
2
+ export declare function TypeboxIsoDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
3
+ export declare function TypeboxDate(options?: object): import("@sinclair/typebox").TTransform<import("@sinclair/typebox").TString, Date>;
4
+ export declare function TypeboxObjectId(options?: object): import("@sinclair/typebox").TString;
5
+ export interface TDecimal extends TSchema, NumberOptions {
6
+ [Kind]: 'Decimal';
7
+ type: 'number';
8
+ static: number;
9
+ }
10
+ export declare function TypeboxDecimal(options?: NumberOptions): TDecimal;
11
+ export declare function TypeboxMoney(options?: NumberOptions): TDecimal;
12
+ export declare function TypeboxPercentage(options?: NumberOptions): TDecimal;
13
+ export declare function testMoneyType(): void;
@@ -0,0 +1,2 @@
1
+ import './typebox-extensions.js';
2
+ export declare const initializeTypeBox: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/common",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "description": "Loom Core Models- common models, interfaces, types, and utils for Loom Core. All things common to both api and client apps.",
6
6
  "scripts": {
@@ -14,7 +14,10 @@
14
14
  "gar-login": "npx --yes google-artifactregistry-auth",
15
15
  "publishMe": "npm publish --access public",
16
16
  "pub": "npm-run-all -s add commit patch build push publishMe",
17
- "auth-and-pub": "npm-run-all -s add commit patch build push gar-login publishMe"
17
+ "auth-and-pub": "npm-run-all -s add commit patch build push gar-login publishMe",
18
+ "test": "cross-env NODE_ENV=test vitest run",
19
+ "test:ci": "cross-env NODE_ENV=test vitest run --reporter=json --outputFile=test-results.json",
20
+ "test:watch": "cross-env NODE_ENV=test vitest"
18
21
  },
19
22
  "keywords": [],
20
23
  "author": "Tim Hardy",
@@ -42,6 +45,7 @@
42
45
  },
43
46
  "devDependencies": {
44
47
  "npm-run-all": "^4.1.5",
45
- "typescript": "^5.8.3"
48
+ "typescript": "^5.8.3",
49
+ "vitest": "^3.0.9"
46
50
  }
47
51
  }