kodzero-front-sdk-alfa 0.0.2

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 (91) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/.eslintrc.json +16 -0
  3. package/README.md +313 -0
  4. package/dist/Kodzero.d.ts +33 -0
  5. package/dist/Kodzero.js +22 -0
  6. package/dist/auth/base.d.ts +15 -0
  7. package/dist/auth/base.js +18 -0
  8. package/dist/auth/email.d.ts +23 -0
  9. package/dist/auth/email.js +70 -0
  10. package/dist/auth/index.d.ts +13 -0
  11. package/dist/auth/index.js +21 -0
  12. package/dist/auth/tokens.d.ts +10 -0
  13. package/dist/auth/tokens.js +22 -0
  14. package/dist/errors/KodzeroApiError.d.ts +7 -0
  15. package/dist/errors/KodzeroApiError.js +10 -0
  16. package/dist/errors/KodzeroValidationError.d.ts +5 -0
  17. package/dist/errors/KodzeroValidationError.js +8 -0
  18. package/dist/fetcher/InterceptorManager.d.ts +9 -0
  19. package/dist/fetcher/InterceptorManager.js +42 -0
  20. package/dist/fetcher/MiddlewareManager.d.ts +9 -0
  21. package/dist/fetcher/MiddlewareManager.js +42 -0
  22. package/dist/fetcher/index.d.ts +77 -0
  23. package/dist/fetcher/index.js +194 -0
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.js +49 -0
  26. package/dist/model/BaseModel.d.ts +38 -0
  27. package/dist/model/BaseModel.js +119 -0
  28. package/dist/model/baseModelOptionsSchema.d.ts +2 -0
  29. package/dist/model/baseModelOptionsSchema.js +10 -0
  30. package/dist/model/configSchema.d.ts +0 -0
  31. package/dist/model/configSchema.js +1 -0
  32. package/dist/model/constants.d.ts +8 -0
  33. package/dist/model/constants.js +7 -0
  34. package/dist/model/createModel.d.ts +28 -0
  35. package/dist/model/createModel.js +159 -0
  36. package/dist/model/errors/KodzeroApiError.d.ts +7 -0
  37. package/dist/model/errors/KodzeroApiError.js +10 -0
  38. package/dist/model/index.d.ts +4 -0
  39. package/dist/model/index.js +4 -0
  40. package/dist/model/modelFactory.d.ts +50 -0
  41. package/dist/model/modelFactory.js +41 -0
  42. package/dist/model/modelSchema.d.ts +0 -0
  43. package/dist/model/modelSchema.js +1 -0
  44. package/dist/model/schemas/baseModel.d.ts +6 -0
  45. package/dist/model/schemas/baseModel.js +25 -0
  46. package/dist/model/schemas/baseModelOptionsSchema.d.ts +2 -0
  47. package/dist/model/schemas/baseModelOptionsSchema.js +10 -0
  48. package/dist/model/statics/getAll.d.ts +2 -0
  49. package/dist/model/statics/getAll.js +4 -0
  50. package/dist/model/utils/processUrl.d.ts +2 -0
  51. package/dist/model/utils/processUrl.js +7 -0
  52. package/dist/model/utils/validateApiResponse.d.ts +2 -0
  53. package/dist/model/utils/validateApiResponse.js +14 -0
  54. package/dist/schemas/baseAuth.d.ts +6 -0
  55. package/dist/schemas/baseAuth.js +18 -0
  56. package/dist/schemas/baseModel copy.d.ts +6 -0
  57. package/dist/schemas/baseModel copy.js +25 -0
  58. package/dist/schemas/baseModel.d.ts +6 -0
  59. package/dist/schemas/baseModel.js +25 -0
  60. package/dist/tsconfig.tsbuildinfo +1 -0
  61. package/dist/types/responses.d.ts +14 -0
  62. package/dist/types/responses.js +1 -0
  63. package/dist/utils/buildURL.d.ts +2 -0
  64. package/dist/utils/buildURL.js +7 -0
  65. package/dist/utils/buildURL_rename.d.ts +2 -0
  66. package/dist/utils/buildURL_rename.js +7 -0
  67. package/dist/utils/processUrl.d.ts +2 -0
  68. package/dist/utils/processUrl.js +7 -0
  69. package/dist/utils/validateApiResponse.d.ts +2 -0
  70. package/dist/utils/validateApiResponse.js +14 -0
  71. package/jest.config.ts +190 -0
  72. package/nodemon.json +4 -0
  73. package/package.json +29 -0
  74. package/src/Kodzero.ts +35 -0
  75. package/src/auth/base.ts +37 -0
  76. package/src/auth/email.ts +123 -0
  77. package/src/auth/index.ts +43 -0
  78. package/src/auth/tokens.ts +49 -0
  79. package/src/errors/KodzeroApiError.ts +17 -0
  80. package/src/errors/KodzeroValidationError.ts +12 -0
  81. package/src/model/BaseModel.ts +210 -0
  82. package/src/model/constants.ts +7 -0
  83. package/src/model/createModel.ts +237 -0
  84. package/src/model/index.ts +12 -0
  85. package/src/schemas/baseAuth.ts +28 -0
  86. package/src/schemas/baseModel.ts +35 -0
  87. package/src/tsconfig.json +103 -0
  88. package/src/types/module.d.ts +2 -0
  89. package/src/types/responses.ts +14 -0
  90. package/src/utils/buildURL_rename.ts +8 -0
  91. package/src/utils/validateApiResponse.ts +17 -0
@@ -0,0 +1,159 @@
1
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
2
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
3
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
4
+ };
5
+ var __rest = (this && this.__rest) || function (s, e) {
6
+ var t = {};
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
8
+ t[p] = s[p];
9
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
10
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
12
+ t[p[i]] = s[p[i]];
13
+ }
14
+ return t;
15
+ };
16
+ import BaseModel from './BaseModel.js';
17
+ import validateApiResponse from '../utils/validateApiResponse.js';
18
+ import buildURL from '../utils/buildURL_rename.js';
19
+ import constants from './constants.js';
20
+ const createModel = (options, api) => {
21
+ var _a;
22
+ const Model = (_a = class extends BaseModel {
23
+ static async _handleApiError(response) {
24
+ return validateApiResponse(response);
25
+ }
26
+ static async get(id) {
27
+ if (!id)
28
+ throw new Error(constants.RequiresId);
29
+ const getUrl = buildURL(Model.host, Model.collection, id);
30
+ const response = await Model.api.get(getUrl);
31
+ await Model._handleApiError(response);
32
+ const json = await response.json();
33
+ return new Model(json.result);
34
+ }
35
+ static registerMethod(name, fn) {
36
+ Model.prototype[name] = fn;
37
+ }
38
+ static async find(id) {
39
+ if (!id)
40
+ throw new Error(constants.RequiresId);
41
+ const getUrl = buildURL(Model.host, Model.collection, id);
42
+ const response = await Model.api.get(getUrl);
43
+ await Model._handleApiError(response);
44
+ const data = await response.json();
45
+ return data.result;
46
+ }
47
+ static async findMany(options) {
48
+ const getUrl = buildURL(Model.host, Model.collection);
49
+ const params = Object.assign({}, options);
50
+ const response = await Model.api.get(getUrl).params(params);
51
+ await Model._handleApiError(response);
52
+ const data = await response.json();
53
+ return data.result.found;
54
+ }
55
+ static async create(data) {
56
+ const createUrl = buildURL(Model.host, Model.collection);
57
+ const _b = data, { _id } = _b, dataWithoutId = __rest(_b, ["_id"]);
58
+ const response = await Model.api.post(createUrl)
59
+ .body(dataWithoutId)
60
+ .headers({
61
+ 'Content-Type': 'application/json'
62
+ });
63
+ await Model._handleApiError(response);
64
+ const json = await response.json();
65
+ return json.result;
66
+ }
67
+ static async createMany(records) {
68
+ if (!records || !Array.isArray(records) || !records.length) {
69
+ throw new Error(constants.DataTypeNotArray);
70
+ }
71
+ const createUrl = buildURL(Model.host, Model.collection) + '/batch';
72
+ const dataWithoutId = records.map(item => {
73
+ const _b = item, { _id } = _b, rest = __rest(_b, ["_id"]);
74
+ return rest;
75
+ });
76
+ const response = await Model.api.post(createUrl)
77
+ .body(dataWithoutId)
78
+ .headers({
79
+ 'Content-Type': 'application/json'
80
+ });
81
+ await Model._handleApiError(response);
82
+ const json = await response.json();
83
+ return json.result;
84
+ }
85
+ static async update(id, data) {
86
+ if (!id) {
87
+ throw new Error(constants.RequiresId);
88
+ }
89
+ const updateUrl = buildURL(Model.host, Model.collection, id);
90
+ const _b = data, { _id } = _b, dataWithoutId = __rest(_b, ["_id"]);
91
+ const response = await Model.api.patch(updateUrl)
92
+ .body(dataWithoutId)
93
+ .headers({ 'Content-Type': 'application/json' });
94
+ await Model._handleApiError(response);
95
+ const json = await response.json();
96
+ return json.result;
97
+ }
98
+ static async updateMany(updates) {
99
+ if (!updates || !Array.isArray(updates) || updates.length === 0) {
100
+ throw new Error(constants.DataTypeNotArray);
101
+ }
102
+ if (updates.some(update => !update._id)) {
103
+ throw new Error("All updates must have an _id");
104
+ }
105
+ const updateUrl = buildURL(Model.host, Model.collection) + '/batch';
106
+ const response = await Model.api.patch(updateUrl)
107
+ .body(updates)
108
+ .headers({ 'Content-Type': 'application/json' });
109
+ await Model._handleApiError(response);
110
+ const json = await response.json();
111
+ return json.result;
112
+ }
113
+ static async delete(id) {
114
+ if (!id)
115
+ throw new Error(constants.RequiresId);
116
+ const deleteUrl = buildURL(Model.host, Model.collection, id);
117
+ const response = await Model.api.delete(deleteUrl);
118
+ await Model._handleApiError(response);
119
+ const json = await response.json();
120
+ return json.result;
121
+ }
122
+ static async deleteMany(ids) {
123
+ if (!ids || ids.length === 0) {
124
+ throw new Error(constants.RequiresIdsArray);
125
+ }
126
+ const deleteUrl = buildURL(Model.host, Model.collection) + '/batch';
127
+ const response = await Model.api.delete(deleteUrl)
128
+ .body({ ids })
129
+ .headers({ 'Content-Type': 'application/json' });
130
+ await Model._handleApiError(response);
131
+ const json = await response.json();
132
+ return json.result;
133
+ }
134
+ static async distinct(fields, filter) {
135
+ if (!fields || fields.length === 0) {
136
+ throw new Error(constants.DistinctRequiresFieldsArray);
137
+ }
138
+ const distinctUrl = buildURL(Model.host, Model.collection, 'distinct');
139
+ const response = await Model.api.post(distinctUrl)
140
+ .params({ fields: fields.join(','), filter: filter ? JSON.stringify(filter) : undefined })
141
+ .headers({ 'Content-Type': 'application/json' });
142
+ await Model._handleApiError(response);
143
+ const json = await response.json();
144
+ return json.result;
145
+ }
146
+ constructor(data) {
147
+ super(options, api);
148
+ this.modelData = Object.assign(Object.assign({}, data), { _id: null });
149
+ this.id = null;
150
+ }
151
+ },
152
+ __setFunctionName(_a, "Model"),
153
+ _a.host = options.host,
154
+ _a.collection = options.collection,
155
+ _a.api = api,
156
+ _a);
157
+ return Model;
158
+ };
159
+ export default createModel;
@@ -0,0 +1,7 @@
1
+ declare class KodzeroApiError extends Error {
2
+ url: string;
3
+ statusCode: number;
4
+ details: string;
5
+ constructor(url: string, statusCode: number, message: string, details?: string);
6
+ }
7
+ export default KodzeroApiError;
@@ -0,0 +1,10 @@
1
+ class KodzeroApiError extends Error {
2
+ constructor(url, statusCode, message, details) {
3
+ super(message);
4
+ this.name = "KodzeroApiError";
5
+ this.url = url;
6
+ this.statusCode = statusCode;
7
+ this.details = details || '';
8
+ }
9
+ }
10
+ export default KodzeroApiError;
@@ -0,0 +1,4 @@
1
+ import BaseModel from "./BaseModel.js";
2
+ import createModel from "./createModel.js";
3
+ import KodzeroApiError from "../errors/KodzeroApiError.js";
4
+ export { createModel, BaseModel, KodzeroApiError };
@@ -0,0 +1,4 @@
1
+ import BaseModel from "./BaseModel.js";
2
+ import createModel from "./createModel.js";
3
+ import KodzeroApiError from "../errors/KodzeroApiError.js";
4
+ export { createModel, BaseModel, KodzeroApiError };
@@ -0,0 +1,50 @@
1
+ import FluidFetch from 'fluid-fetch';
2
+ import BaseModel, { ModelOptions } from './BaseModel.js';
3
+ export declare const createModel: (options: ModelOptions) => {
4
+ new (data: Record<string, any>): {
5
+ url: string;
6
+ collection: string;
7
+ api: typeof FluidFetch;
8
+ modelData: Record<string, any>;
9
+ id: string | null;
10
+ _setId: (id: string | null) => void;
11
+ _setModelData: (data: Record<string, any>) => void;
12
+ _handleApiError(response: Response): Promise<void>;
13
+ data(): Record<string, any>;
14
+ dataWithoutId(): {
15
+ [x: string]: any;
16
+ };
17
+ setNested(key: string, value: any): Record<string, any>;
18
+ set(data: Record<string, any> | string, value?: any): Record<string, any>;
19
+ update(): Promise<Record<string, any>>;
20
+ delete(): Promise<boolean>;
21
+ create(): Promise<Record<string, any>>;
22
+ save(): Promise<Record<string, any>>;
23
+ };
24
+ url: string;
25
+ collection: string;
26
+ api: any;
27
+ _handleApiError(response: Response): Promise<void>;
28
+ get(id: string): Promise<{
29
+ url: string;
30
+ collection: string;
31
+ api: typeof FluidFetch;
32
+ modelData: Record<string, any>;
33
+ id: string | null;
34
+ _setId: (id: string | null) => void;
35
+ _setModelData: (data: Record<string, any>) => void;
36
+ _handleApiError(response: Response): Promise<void>;
37
+ data(): Record<string, any>;
38
+ dataWithoutId(): {
39
+ [x: string]: any;
40
+ };
41
+ setNested(key: string, value: any): Record<string, any>;
42
+ set(data: Record<string, any> | string, value?: any): Record<string, any>;
43
+ update(): Promise<Record<string, any>>;
44
+ delete(): Promise<boolean>;
45
+ create(): Promise<Record<string, any>>;
46
+ save(): Promise<Record<string, any>>;
47
+ }>;
48
+ getAll(): Promise<any>;
49
+ };
50
+ export default BaseModel;
@@ -0,0 +1,41 @@
1
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
2
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
3
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
4
+ };
5
+ import FluidFetch from 'fluid-fetch';
6
+ import BaseModel from './BaseModel.js';
7
+ import validateApiResponse from './utils/validateApiResponse.js';
8
+ export const createModel = (options) => {
9
+ var _a;
10
+ const Model = (_a = class extends BaseModel {
11
+ static async _handleApiError(response) {
12
+ return validateApiResponse(response);
13
+ }
14
+ static async get(id) {
15
+ const getUrl = Model.url + '/' + Model.collection + '/' + id;
16
+ const response = await Model.api.get(getUrl);
17
+ await Model._handleApiError(response);
18
+ const json = await response.json();
19
+ return new Model(json.result);
20
+ }
21
+ static async getAll() {
22
+ const getUrl = Model.url + '/' + Model.collection;
23
+ const response = await Model.api.get(getUrl);
24
+ await Model._handleApiError(response);
25
+ const data = await response.json();
26
+ return data;
27
+ }
28
+ constructor(data) {
29
+ super(options);
30
+ this.modelData = data;
31
+ this.id = (data === null || data === void 0 ? void 0 : data._id) || null;
32
+ }
33
+ },
34
+ __setFunctionName(_a, "Model"),
35
+ _a.url = options.url,
36
+ _a.collection = options.collection,
37
+ _a.api = new FluidFetch(),
38
+ _a);
39
+ return Model;
40
+ };
41
+ export default BaseModel;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,6 @@
1
+ declare class BaseModelSchema {
2
+ static schema: any;
3
+ static validate: (options: Record<string, any>) => any;
4
+ static validateOrThrow: (options: Record<string, any>) => boolean;
5
+ }
6
+ export default BaseModelSchema;
@@ -0,0 +1,25 @@
1
+ import Schema from 'validno';
2
+ import KodzeroValidationError from '../../errors/KodzeroValidationError.js';
3
+ class BaseModelSchema {
4
+ }
5
+ BaseModelSchema.schema = new Schema({
6
+ host: {
7
+ type: String
8
+ },
9
+ collection: {
10
+ type: String
11
+ },
12
+ schema: {
13
+ type: Schema,
14
+ required: false
15
+ }
16
+ });
17
+ BaseModelSchema.validate = (options) => BaseModelSchema.schema.validate(options);
18
+ BaseModelSchema.validateOrThrow = (options) => {
19
+ const validation = BaseModelSchema.schema.validate(options);
20
+ if (!validation.ok) {
21
+ throw new KodzeroValidationError('Invalid model options: ' + validation.failed.join(', '), validation.errors);
22
+ }
23
+ return true;
24
+ };
25
+ export default BaseModelSchema;
@@ -0,0 +1,2 @@
1
+ declare const baseModelOptionsSchema: any;
2
+ export default baseModelOptionsSchema;
@@ -0,0 +1,10 @@
1
+ import Schema from 'validno';
2
+ const baseModelOptionsSchema = new Schema({
3
+ url: {
4
+ type: String
5
+ },
6
+ collection: {
7
+ type: String
8
+ }
9
+ });
10
+ export default baseModelOptionsSchema;
@@ -0,0 +1,2 @@
1
+ declare const getAll: () => Promise<never[]>;
2
+ export default getAll;
@@ -0,0 +1,4 @@
1
+ const getAll = async () => {
2
+ return [];
3
+ };
4
+ export default getAll;
@@ -0,0 +1,2 @@
1
+ declare const processUrl: (baseUrl: string, collection: string, id?: string) => string;
2
+ export default processUrl;
@@ -0,0 +1,7 @@
1
+ const processUrl = (baseUrl, collection, id) => {
2
+ let url = `${baseUrl}/${collection}`;
3
+ if (id)
4
+ url += `/${id}`;
5
+ return url.replace(/\/+/g, '/').replace(':/', '://');
6
+ };
7
+ export default processUrl;
@@ -0,0 +1,2 @@
1
+ declare const validateApiResponse: (response: Response) => Promise<void>;
2
+ export default validateApiResponse;
@@ -0,0 +1,14 @@
1
+ import KodzeroApiError from "../errors/KodzeroApiError.js";
2
+ const validateApiResponse = async (response) => {
3
+ if (response.ok)
4
+ return;
5
+ let json;
6
+ try {
7
+ json = await response.json();
8
+ }
9
+ catch (err) {
10
+ json = null;
11
+ }
12
+ throw new KodzeroApiError(response.url, response.status, `API Request failed with status ${response.status}. Details: ${(json === null || json === void 0 ? void 0 : json.details) || (json === null || json === void 0 ? void 0 : json.error) || response.statusText}`, (json === null || json === void 0 ? void 0 : json.details) || (json === null || json === void 0 ? void 0 : json.error) || response.statusText);
13
+ };
14
+ export default validateApiResponse;
@@ -0,0 +1,6 @@
1
+ declare class BaseAuthSchema {
2
+ static schema: any;
3
+ static validate: (options: Record<string, any>) => any;
4
+ static validateOrThrow: (options: Record<string, any>) => boolean;
5
+ }
6
+ export default BaseAuthSchema;
@@ -0,0 +1,18 @@
1
+ import Schema from 'validno';
2
+ import KodzeroValidationError from '../errors/KodzeroValidationError.js';
3
+ class BaseAuthSchema {
4
+ }
5
+ BaseAuthSchema.schema = new Schema({
6
+ host: {
7
+ type: String
8
+ }
9
+ });
10
+ BaseAuthSchema.validate = (options) => BaseAuthSchema.schema.validate(options);
11
+ BaseAuthSchema.validateOrThrow = (options) => {
12
+ const validation = BaseAuthSchema.schema.validate(options);
13
+ if (!validation.ok) {
14
+ throw new KodzeroValidationError('Invalid auth options: ' + validation.failed.join(', '), validation.errors);
15
+ }
16
+ return true;
17
+ };
18
+ export default BaseAuthSchema;
@@ -0,0 +1,6 @@
1
+ declare class BaseModelSchema {
2
+ static schema: any;
3
+ static validate: (options: Record<string, any>) => any;
4
+ static validateOrThrow: (options: Record<string, any>) => boolean;
5
+ }
6
+ export default BaseModelSchema;
@@ -0,0 +1,25 @@
1
+ import Schema from 'validno';
2
+ import KodzeroValidationError from '../../errors/KodzeroValidationError.js';
3
+ class BaseModelSchema {
4
+ }
5
+ BaseModelSchema.schema = new Schema({
6
+ host: {
7
+ type: String
8
+ },
9
+ collection: {
10
+ type: String
11
+ },
12
+ schema: {
13
+ type: Schema,
14
+ required: false
15
+ }
16
+ });
17
+ BaseModelSchema.validate = (options) => BaseModelSchema.schema.validate(options);
18
+ BaseModelSchema.validateOrThrow = (options) => {
19
+ const validation = BaseModelSchema.schema.validate(options);
20
+ if (!validation.ok) {
21
+ throw new KodzeroValidationError('Invalid model options: ' + validation.failed.join(', '), validation.errors);
22
+ }
23
+ return true;
24
+ };
25
+ export default BaseModelSchema;
@@ -0,0 +1,6 @@
1
+ declare class BaseModelSchema {
2
+ static schema: any;
3
+ static validate: (options: Record<string, any>) => any;
4
+ static validateOrThrow: (options: Record<string, any>) => boolean;
5
+ }
6
+ export default BaseModelSchema;
@@ -0,0 +1,25 @@
1
+ import Schema from 'validno';
2
+ import KodzeroValidationError from '../errors/KodzeroValidationError.js';
3
+ class BaseModelSchema {
4
+ }
5
+ BaseModelSchema.schema = new Schema({
6
+ host: {
7
+ type: String
8
+ },
9
+ collection: {
10
+ type: String
11
+ },
12
+ schema: {
13
+ type: Schema,
14
+ required: false
15
+ }
16
+ });
17
+ BaseModelSchema.validate = (options) => BaseModelSchema.schema.validate(options);
18
+ BaseModelSchema.validateOrThrow = (options) => {
19
+ const validation = BaseModelSchema.schema.validate(options);
20
+ if (!validation.ok) {
21
+ throw new KodzeroValidationError('Invalid model options: ' + validation.failed.join(', '), validation.errors);
22
+ }
23
+ return true;
24
+ };
25
+ export default BaseModelSchema;
@@ -0,0 +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"}
@@ -0,0 +1,14 @@
1
+ export interface KzResponse<T = any> {
2
+ ok: boolean;
3
+ result: T;
4
+ }
5
+ export interface KzResponseFindMany<T = any> extends KzResponse<{
6
+ skip: number;
7
+ limit: number;
8
+ page: number;
9
+ total: number;
10
+ totalPages: number;
11
+ left: number;
12
+ found: T[];
13
+ }> {
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const buildURL: (baseUrl: string, collection: string, id?: string) => string;
2
+ export default buildURL;
@@ -0,0 +1,7 @@
1
+ const buildURL = (baseUrl, collection, id) => {
2
+ let url = `${baseUrl}/${collection}`;
3
+ if (id)
4
+ url += `/${id}`;
5
+ return url.replace(/\/+/g, '/').replace(':/', '://');
6
+ };
7
+ export default buildURL;
@@ -0,0 +1,2 @@
1
+ declare const buildURL: (baseUrl: string, collection: string, id?: string) => string;
2
+ export default buildURL;
@@ -0,0 +1,7 @@
1
+ const buildURL = (baseUrl, collection, id) => {
2
+ let url = `${baseUrl}/${collection}`;
3
+ if (id)
4
+ url += `/${id}`;
5
+ return url.replace(/\/+/g, '/').replace(':/', '://');
6
+ };
7
+ export default buildURL;
@@ -0,0 +1,2 @@
1
+ declare const buildURL: (baseUrl: string, collection: string, id?: string) => string;
2
+ export default buildURL;
@@ -0,0 +1,7 @@
1
+ const buildURL = (baseUrl, collection, id) => {
2
+ let url = `${baseUrl}/${collection}`;
3
+ if (id)
4
+ url += `/${id}`;
5
+ return url.replace(/\/+/g, '/').replace(':/', '://');
6
+ };
7
+ export default buildURL;
@@ -0,0 +1,2 @@
1
+ declare const validateApiResponse: (response: Response) => Promise<void>;
2
+ export default validateApiResponse;
@@ -0,0 +1,14 @@
1
+ import KodzeroApiError from "../errors/KodzeroApiError.js";
2
+ const validateApiResponse = async (response) => {
3
+ if (response.ok)
4
+ return;
5
+ let json;
6
+ try {
7
+ json = await response.json();
8
+ }
9
+ catch (err) {
10
+ json = null;
11
+ }
12
+ throw new KodzeroApiError(response.url, response.status, `API Request failed with status ${response.status}. Details: ${(json === null || json === void 0 ? void 0 : json.details) || (json === null || json === void 0 ? void 0 : json.error) || response.statusText}`, (json === null || json === void 0 ? void 0 : json.details) || (json === null || json === void 0 ? void 0 : json.error) || response.statusText);
13
+ };
14
+ export default validateApiResponse;