kodzero-front-sdk-alfa 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -7,7 +7,6 @@ A lightweight OOP library for frontend applications to easily interact with Kodz
7
7
  ```bash
8
8
  npm install kodzero-front-sdk-alfa
9
9
  ```
10
- ```
11
10
 
12
11
  ## Authentication
13
12
 
@@ -54,8 +53,6 @@ Creating and using models is the core functionality of the SDK. Models provide a
54
53
  ### Creating a Model
55
54
 
56
55
  ```javascript
57
- import Schema from 'validno';
58
-
59
56
  // Define your data model interface
60
57
  interface User {
61
58
  _id?: string;
@@ -64,13 +61,13 @@ interface User {
64
61
  createdAt?: Date;
65
62
  }
66
63
 
67
- // Optional: Create a schema for validation
68
- const userSchema = new Schema({
64
+ // Optional: Create a schema object for validation
65
+ const userSchema = {
69
66
  _id: { type: String },
70
67
  name: { type: String },
71
68
  email: { type: String },
72
69
  createdAt: { type: Date }
73
- });
70
+ };
74
71
 
75
72
  // Create a model for the 'users' collection
76
73
  const User = kodzero.createModel<User>({
@@ -142,6 +139,14 @@ interface CarMethods {
142
139
  isVintage: () => boolean;
143
140
  }
144
141
 
142
+ // Define your schema
143
+ const carSchema = {
144
+ _id: { type: String },
145
+ make: { type: String },
146
+ model: { type: String },
147
+ year: { type: Number }
148
+ };
149
+
145
150
  // Create the model with the custom methods type
146
151
  const Car = kodzero.createModel<Car, CarMethods>({
147
152
  collection: 'cars',
@@ -224,16 +229,16 @@ const deleteResults = await User.deleteMany(['id1', 'id2', 'id3']);
224
229
 
225
230
  ## Validation
226
231
 
227
- The SDK uses the `validno` library for schema-based validation. When creating a model with a schema, you can validate your data:
232
+ The SDK has built-in validation capabilities based on `validno` package ([Validno docs](https://validno.kodzero.pro/)). When creating a model with a schema, you can validate your data:
228
233
 
229
234
  ```javascript
230
235
  // Define a schema with validation rules
231
- const carSchema = new Schema({
236
+ const carSchema = {
232
237
  _id: { type: String },
233
238
  make: { type: String, required: true },
234
239
  model: { type: String, required: true },
235
- year: { type: Number, min: 1900, max: 2100 }
236
- });
240
+ year: { type: Number }
241
+ };
237
242
 
238
243
  const Car = kodzero.createModel<Car>({
239
244
  collection: 'cars',
@@ -269,8 +274,20 @@ interface Profile {
269
274
  }
270
275
  }
271
276
 
277
+ const profileSchema = {
278
+ _id: { type: String },
279
+ user: {
280
+ name: { type: String },
281
+ contact: {
282
+ email: { type: String },
283
+ phone: { type: String }
284
+ }
285
+ }
286
+ };
287
+
272
288
  const Profile = kodzero.createModel<Profile>({
273
- collection: 'profiles'
289
+ collection: 'profiles',
290
+ schema: profileSchema
274
291
  });
275
292
 
276
293
  const profile = new Profile({
package/dist/Kodzero.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import FluidFetch from "fluid-fetch";
2
- import { KodzeroAuth } from "./auth/index.js";
2
+ import KodzeroAuth from "./auth/index.js";
3
3
  import { ModelOptions } from "./model/BaseModel.js";
4
- import { TokensManagerClass } from "./auth/tokens.js";
4
+ import TokensManagerClass from "./auth/tokens.js";
5
5
  interface Options {
6
6
  host: string;
7
7
  }
package/dist/Kodzero.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import FluidFetch from "fluid-fetch";
2
- import { KodzeroAuth } from "./auth/index.js";
2
+ import KodzeroAuth from "./auth/index.js";
3
3
  import createModel from "./model/createModel.js";
4
- import { TokensManagerClass } from "./auth/tokens.js";
4
+ import TokensManagerClass from "./auth/tokens.js";
5
5
  class Kodzero {
6
6
  constructor(options) {
7
7
  this.createModel = (options) => {
@@ -1,7 +1,7 @@
1
1
  import FluidFetch from "fluid-fetch";
2
2
  import { AuthOptions } from "./index.js";
3
- import { TokensManagerClass } from "./tokens.js";
4
- export declare class KodzeroAuthBase {
3
+ import TokensManagerClass from "./tokens.js";
4
+ declare class KodzeroAuthBase {
5
5
  host: string;
6
6
  api: typeof FluidFetch;
7
7
  tokensManager: TokensManagerClass;
@@ -13,3 +13,4 @@ export declare class KodzeroAuthBase {
13
13
  signout: (...args: any[]) => Promise<any> | void;
14
14
  verify: (...args: any[]) => Promise<any> | void;
15
15
  }
16
+ export default KodzeroAuthBase;
package/dist/auth/base.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import BaseAuthSchema from "../schemas/baseAuth.js";
2
2
  import validateApiResponse from "../utils/validateApiResponse.js";
3
- export class KodzeroAuthBase {
3
+ class KodzeroAuthBase {
4
4
  constructor(options, api, tokensManager) {
5
5
  this.signin = (...args) => { };
6
6
  this.signup = (...args) => { };
@@ -16,3 +16,4 @@ export class KodzeroAuthBase {
16
16
  return validateApiResponse(response);
17
17
  }
18
18
  }
19
+ export default KodzeroAuthBase;
@@ -1,7 +1,7 @@
1
1
  import FluidFetch from "fluid-fetch";
2
2
  import { AuthOptions } from "./index.js";
3
- import { KodzeroAuthBase } from "./base.js";
4
- import { TokensManagerClass } from "./tokens.js";
3
+ import KodzeroAuthBase from "./base.js";
4
+ import TokensManagerClass from "./tokens.js";
5
5
  interface KodzeroAuthEmailSignin {
6
6
  email: string;
7
7
  password: string;
@@ -1,5 +1,5 @@
1
- import { KodzeroAuthBase } from "./base.js";
2
- import buildURL from "../utils/buildURL_rename.js";
1
+ import buildURL from "../utils/buildURL.js";
2
+ import KodzeroAuthBase from "./base.js";
3
3
  class KodzeroAuthEmail extends KodzeroAuthBase {
4
4
  constructor(options, api, tokensManager) {
5
5
  super(options, api, tokensManager);
@@ -1,13 +1,14 @@
1
1
  import FluidFetch from "fluid-fetch";
2
- import { KodzeroAuthBase } from "./base.js";
2
+ import KodzeroAuthBase from "./base.js";
3
3
  import KodzeroAuthEmail from "./email.js";
4
- import { TokensManagerClass } from "./tokens.js";
4
+ import TokensManagerClass from "./tokens.js";
5
5
  export interface AuthOptions {
6
6
  host: string;
7
7
  }
8
- export declare class KodzeroAuth extends KodzeroAuthBase {
8
+ declare class KodzeroAuth extends KodzeroAuthBase {
9
9
  email: KodzeroAuthEmail;
10
10
  setTokens: (access: string, refresh?: string) => void;
11
11
  clearTokens: () => void;
12
12
  constructor(options: AuthOptions, api: typeof FluidFetch, tokensManager: TokensManagerClass);
13
13
  }
14
+ export default KodzeroAuth;
@@ -1,6 +1,6 @@
1
- import { KodzeroAuthBase } from "./base.js";
1
+ import KodzeroAuthBase from "./base.js";
2
2
  import KodzeroAuthEmail from "./email.js";
3
- export class KodzeroAuth extends KodzeroAuthBase {
3
+ class KodzeroAuth extends KodzeroAuthBase {
4
4
  constructor(options, api, tokensManager) {
5
5
  super(options, api, tokensManager);
6
6
  this.email = new KodzeroAuthEmail(options, api, tokensManager);
@@ -19,3 +19,4 @@ export class KodzeroAuth extends KodzeroAuthBase {
19
19
  };
20
20
  }
21
21
  }
22
+ export default KodzeroAuth;
@@ -1,4 +1,4 @@
1
- export declare class TokensManagerClass {
1
+ declare class TokensManagerClass {
2
2
  access: string;
3
3
  refresh: string;
4
4
  constructor(access?: string, refresh?: string);
@@ -8,3 +8,4 @@ export declare class TokensManagerClass {
8
8
  setRefresh(token: string): void;
9
9
  clear(): void;
10
10
  }
11
+ export default TokensManagerClass;
@@ -1,4 +1,4 @@
1
- export class TokensManagerClass {
1
+ class TokensManagerClass {
2
2
  constructor(access = '', refresh = '') {
3
3
  this.access = access;
4
4
  this.refresh = refresh;
@@ -20,3 +20,4 @@ export class TokensManagerClass {
20
20
  this.refresh = '';
21
21
  }
22
22
  }
23
+ export default TokensManagerClass;
@@ -3,7 +3,7 @@ import FluidFetch from "fluid-fetch";
3
3
  export interface ModelOptions {
4
4
  host: string;
5
5
  collection: string;
6
- schema?: typeof Schema;
6
+ schema?: Record<string, any>;
7
7
  }
8
8
  declare class BaseModel<T extends {
9
9
  _id?: string;
@@ -9,10 +9,11 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
+ import Schema from "validno";
12
13
  import constants from "./constants.js";
13
14
  import validateApiResponse from "../utils/validateApiResponse.js";
14
15
  import BaseModelSchema from "../schemas/baseModel.js";
15
- import buildURL from "../utils/buildURL_rename.js";
16
+ import buildURL from "../utils/buildURL.js";
16
17
  class BaseModel {
17
18
  constructor(options, api) {
18
19
  this.modelData = {};
@@ -26,7 +27,7 @@ class BaseModel {
26
27
  BaseModelSchema.validateOrThrow(options);
27
28
  this.host = options.host;
28
29
  this.collection = options.collection;
29
- this.schema = options.schema;
30
+ this.schema = options.schema ? new Schema(Object.assign({}, options.schema)) : null;
30
31
  this.api = api;
31
32
  this.id = null;
32
33
  }
@@ -15,7 +15,7 @@ var __rest = (this && this.__rest) || function (s, e) {
15
15
  };
16
16
  import BaseModel from './BaseModel.js';
17
17
  import validateApiResponse from '../utils/validateApiResponse.js';
18
- import buildURL from '../utils/buildURL_rename.js';
18
+ import buildURL from '../utils/buildURL.js';
19
19
  import constants from './constants.js';
20
20
  const createModel = (options, api) => {
21
21
  var _a;
@@ -1 +1 @@
1
- {"root":["../src/kodzero.ts","../src/dev.ts","../src/auth/base.ts","../src/auth/email.ts","../src/auth/index.ts","../src/auth/tokens.ts","../src/errors/kodzeroapierror.ts","../src/errors/kodzerovalidationerror.ts","../src/model/basemodel.ts","../src/model/constants.ts","../src/model/createmodel.ts","../src/model/index.ts","../src/schemas/baseauth.ts","../src/schemas/basemodel.ts","../src/types/module.d.ts","../src/types/responses.ts","../src/utils/buildurl_rename.ts","../src/utils/validateapiresponse.ts"],"version":"5.8.3"}
1
+ {"root":["../src/kodzero.ts","../src/dev.ts","../src/auth/base.ts","../src/auth/email.ts","../src/auth/index.ts","../src/auth/tokens.ts","../src/errors/kodzeroapierror.ts","../src/errors/kodzerovalidationerror.ts","../src/model/basemodel.ts","../src/model/constants.ts","../src/model/createmodel.ts","../src/model/index.ts","../src/schemas/baseauth.ts","../src/schemas/basemodel.ts","../src/types/module.d.ts","../src/types/responses.ts","../src/utils/buildurl.ts","../src/utils/validateapiresponse.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "kodzero-front-sdk-alfa",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "tsc": "tsc -b src/",
7
7
  "tsc-watch": "tsc --b --watch src/",
8
8
  "tscw": "tsc --b --watch src/",
9
- "dev": "nodemon dist/index.js",
9
+ "dev": "nodemon dist/dev.js",
10
10
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
11
11
  "prepare": "npm version patch && npm run tsc"
12
12
  },
package/src/Kodzero.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import FluidFetch from "fluid-fetch"
2
- import { KodzeroAuth } from "./auth/index.js"
2
+ import KodzeroAuth from "./auth/index.js"
3
3
  import createModel from "./model/createModel.js"
4
4
  import { ModelOptions } from "./model/BaseModel.js"
5
- import { TokensManagerClass } from "./auth/tokens.js"
5
+ import TokensManagerClass from "./auth/tokens.js"
6
6
 
7
7
  interface Options {
8
8
  host: string
package/src/auth/base.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import FluidFetch from "fluid-fetch";
2
2
  import { AuthOptions } from "./index.js";
3
- import { TokensManagerClass } from "./tokens.js";
3
+ import TokensManagerClass from "./tokens.js";
4
4
  import BaseAuthSchema from "../schemas/baseAuth.js";
5
5
  import validateApiResponse from "../utils/validateApiResponse.js";
6
6
 
7
- export class KodzeroAuthBase {
7
+ class KodzeroAuthBase {
8
8
  host: string;
9
9
  api: typeof FluidFetch
10
10
  tokensManager: TokensManagerClass
@@ -34,4 +34,6 @@ export class KodzeroAuthBase {
34
34
  refresh = (...args: any[]): Promise<any> | void => {}
35
35
  signout = (...args: any[]): Promise<any> | void => {}
36
36
  verify = (...args: any[]): Promise<any> | void => {}
37
- }
37
+ }
38
+
39
+ export default KodzeroAuthBase
package/src/auth/email.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import FluidFetch from "fluid-fetch"
2
2
  import { AuthOptions } from "./index.js"
3
- import { KodzeroAuthBase } from "./base.js"
4
- import { TokensManagerClass } from "./tokens.js"
5
- import buildURL from "../utils/buildURL_rename.js"
3
+ import buildURL from "../utils/buildURL.js"
4
+ import KodzeroAuthBase from "./base.js"
5
+ import TokensManagerClass from "./tokens.js"
6
6
 
7
7
  interface KodzeroAuthEmailSignin {
8
8
  email: string
package/src/auth/index.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import FluidFetch from "fluid-fetch";
2
- import { KodzeroAuthBase } from "./base.js";
2
+ import KodzeroAuthBase from "./base.js";
3
3
  import KodzeroAuthEmail from "./email.js";
4
- import { TokensManagerClass } from "./tokens.js";
4
+ import TokensManagerClass from "./tokens.js";
5
5
 
6
6
  export interface AuthOptions {
7
7
  host: string
8
8
  }
9
9
 
10
- export class KodzeroAuth extends KodzeroAuthBase {
10
+ class KodzeroAuth extends KodzeroAuthBase {
11
11
  email: KodzeroAuthEmail
12
12
  setTokens: (access: string, refresh?: string) => void
13
13
  clearTokens: () => void;
@@ -40,4 +40,6 @@ export class KodzeroAuth extends KodzeroAuthBase {
40
40
  tokensManager.clear()
41
41
  }
42
42
  }
43
- }
43
+ }
44
+
45
+ export default KodzeroAuth
@@ -2,7 +2,7 @@
2
2
  * TokensManagerClass is responsible for managing access and refresh tokens.
3
3
  * It provides methods to set, get, check existence, and clear tokens.
4
4
  */
5
- export class TokensManagerClass {
5
+ class TokensManagerClass {
6
6
  access: string
7
7
  refresh: string
8
8
 
@@ -46,4 +46,6 @@ export class TokensManagerClass {
46
46
  this.access = ''
47
47
  this.refresh = ''
48
48
  }
49
- }
49
+ }
50
+
51
+ export default TokensManagerClass
@@ -1,15 +1,14 @@
1
1
  import Schema from "validno";
2
2
  import FluidFetch from "fluid-fetch";
3
-
4
3
  import constants from "./constants.js";
5
4
  import validateApiResponse from "../utils/validateApiResponse.js";
6
5
  import BaseModelSchema from "../schemas/baseModel.js";
7
- import buildURL from "../utils/buildURL_rename.js";
6
+ import buildURL from "../utils/buildURL.js";
8
7
 
9
8
  export interface ModelOptions {
10
9
  host: string
11
10
  collection: string
12
- schema?: typeof Schema
11
+ schema?: Record<string, any>
13
12
  }
14
13
 
15
14
  /**
@@ -33,7 +32,7 @@ class BaseModel<T extends { _id?: string }> {
33
32
 
34
33
  this.host = options.host
35
34
  this.collection = options.collection
36
- this.schema = options.schema
35
+ this.schema = options.schema ? new Schema({...options.schema}) : null
37
36
  this.api = api
38
37
  this.id = null;
39
38
  }
@@ -2,7 +2,7 @@ import FluidFetch from 'fluid-fetch'
2
2
  import BaseModel, { ModelOptions } from './BaseModel.js'
3
3
  import {KzResponseFindMany } from '../types/responses.js'
4
4
  import validateApiResponse from '../utils/validateApiResponse.js'
5
- import buildURL from '../utils/buildURL_rename.js'
5
+ import buildURL from '../utils/buildURL.js'
6
6
  import constants from './constants.js'
7
7
 
8
8
  export interface FindManyOptions {
File without changes