kodzero-front-sdk-alfa 0.0.4 → 0.0.6
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 +6 -6
- package/dist/Kodzero.d.ts +1 -0
- package/dist/Kodzero.js +7 -3
- package/dist/__mocks__/fluid-fetch.d.ts +1 -0
- package/dist/__mocks__/fluid-fetch.js +23 -0
- package/dist/__mocks__/validno.d.ts +5 -0
- package/dist/__mocks__/validno.js +9 -0
- package/dist/auth/base.d.ts +3 -3
- package/dist/auth/base.js +8 -5
- package/dist/auth/email.d.ts +4 -4
- package/dist/auth/email.js +62 -60
- package/dist/auth/index.js +6 -3
- package/dist/auth/tokens.js +2 -0
- package/dist/errors/KodzeroApiError.js +3 -0
- package/dist/errors/KodzeroValidationError.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -48
- package/dist/model/BaseModel.d.ts +2 -2
- package/dist/model/BaseModel.js +25 -28
- package/dist/model/PaginatedResult.d.ts +28 -0
- package/dist/model/PaginatedResult.js +49 -0
- package/dist/model/createModel.d.ts +3 -1
- package/dist/model/createModel.js +145 -147
- package/dist/schemas/baseAuth.js +13 -13
- package/dist/schemas/baseModel.js +20 -20
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/buildURL.js +3 -1
- package/dist/utils/validateApiResponse.js +1 -1
- package/jest.config.ts +23 -19
- package/package.json +6 -5
- package/src/__mocks__/fluid-fetch.ts +35 -0
- package/src/__mocks__/validno.ts +12 -0
- package/src/__tests__/Kodzero.test.ts +9 -0
- package/src/__tests__/utils/buildURL.test.ts +18 -0
- package/src/auth/base.ts +3 -3
- package/src/auth/email.ts +11 -11
- package/src/auth/index.ts +3 -3
- package/src/index.ts +3 -0
- package/src/model/BaseModel.ts +10 -12
- package/src/model/PaginatedResult.ts +81 -0
- package/src/model/createModel.ts +39 -15
- package/src/schemas/baseAuth.ts +2 -1
- package/src/schemas/baseModel.ts +1 -1
- package/src/tsconfig.json +9 -8
- package/src/utils/buildURL.ts +2 -1
- package/dist/fetcher/InterceptorManager.d.ts +0 -9
- package/dist/fetcher/InterceptorManager.js +0 -42
- package/dist/fetcher/MiddlewareManager.d.ts +0 -9
- package/dist/fetcher/MiddlewareManager.js +0 -42
- package/dist/fetcher/index.d.ts +0 -77
- package/dist/fetcher/index.js +0 -194
- package/dist/model/baseModelOptionsSchema.d.ts +0 -2
- package/dist/model/baseModelOptionsSchema.js +0 -10
- package/dist/model/configSchema.d.ts +0 -0
- package/dist/model/configSchema.js +0 -1
- package/dist/model/errors/KodzeroApiError.d.ts +0 -7
- package/dist/model/errors/KodzeroApiError.js +0 -10
- package/dist/model/modelFactory.d.ts +0 -50
- package/dist/model/modelFactory.js +0 -41
- package/dist/model/modelSchema.d.ts +0 -0
- package/dist/model/modelSchema.js +0 -1
- package/dist/model/schemas/baseModel.d.ts +0 -6
- package/dist/model/schemas/baseModel.js +0 -25
- package/dist/model/schemas/baseModelOptionsSchema.d.ts +0 -2
- package/dist/model/schemas/baseModelOptionsSchema.js +0 -10
- package/dist/model/statics/getAll.d.ts +0 -2
- package/dist/model/statics/getAll.js +0 -4
- package/dist/model/utils/processUrl.d.ts +0 -2
- package/dist/model/utils/processUrl.js +0 -7
- package/dist/model/utils/validateApiResponse.d.ts +0 -2
- package/dist/model/utils/validateApiResponse.js +0 -14
- package/dist/schemas/baseModel copy.d.ts +0 -6
- package/dist/schemas/baseModel copy.js +0 -25
- package/dist/utils/buildURL_rename.d.ts +0 -2
- package/dist/utils/buildURL_rename.js +0 -7
- package/dist/utils/processUrl.d.ts +0 -2
- package/dist/utils/processUrl.js +0 -7
- /package/{.eslintrc.cjs → eslintrc.cjs} +0 -0
|
@@ -1,159 +1,157 @@
|
|
|
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
1
|
import BaseModel from './BaseModel.js';
|
|
17
2
|
import validateApiResponse from '../utils/validateApiResponse.js';
|
|
18
3
|
import buildURL from '../utils/buildURL.js';
|
|
19
4
|
import constants from './constants.js';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const Model =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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;
|
|
5
|
+
import PaginatedResult from './PaginatedResult.js';
|
|
6
|
+
const createModel = (options, apiClient) => {
|
|
7
|
+
const Model = class extends BaseModel {
|
|
8
|
+
static host = options.host;
|
|
9
|
+
static collection = options.collection;
|
|
10
|
+
static apiClient = apiClient;
|
|
11
|
+
static async _handleApiError(response) {
|
|
12
|
+
return validateApiResponse(response);
|
|
13
|
+
}
|
|
14
|
+
static async get(id) {
|
|
15
|
+
if (!id)
|
|
16
|
+
throw new Error(constants.RequiresId);
|
|
17
|
+
const getUrl = buildURL(Model.host, Model.collection, id);
|
|
18
|
+
const response = await Model.api.get(getUrl);
|
|
19
|
+
await Model._handleApiError(response);
|
|
20
|
+
const json = await response.json();
|
|
21
|
+
return new Model(json.result);
|
|
22
|
+
}
|
|
23
|
+
static registerMethod(name, fn) {
|
|
24
|
+
Model.prototype[name] = fn;
|
|
25
|
+
}
|
|
26
|
+
static async find(id) {
|
|
27
|
+
if (!id)
|
|
28
|
+
throw new Error(constants.RequiresId);
|
|
29
|
+
const getUrl = buildURL(Model.host, Model.collection, id);
|
|
30
|
+
const response = await Model.apiClient.get(getUrl);
|
|
31
|
+
await Model._handleApiError(response);
|
|
32
|
+
const data = await response.json();
|
|
33
|
+
return data.result;
|
|
34
|
+
}
|
|
35
|
+
static async findMany(options) {
|
|
36
|
+
const getUrl = buildURL(Model.host, Model.collection);
|
|
37
|
+
const params = { ...options };
|
|
38
|
+
const response = await Model.apiClient.get(getUrl).params(params);
|
|
39
|
+
await Model._handleApiError(response);
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
return data.result.found;
|
|
42
|
+
}
|
|
43
|
+
static async findManyPaginated(options = {}, page = 1, perPage = 25) {
|
|
44
|
+
if (!page || page < 1)
|
|
45
|
+
throw new Error('Page number must be greater than 0');
|
|
46
|
+
const getUrl = buildURL(Model.host, Model.collection);
|
|
47
|
+
const params = { ...options, page, perPage };
|
|
48
|
+
const response = await Model.apiClient.get(getUrl).params(params);
|
|
49
|
+
await Model._handleApiError(response);
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
return new PaginatedResult({
|
|
52
|
+
data: data.result.found,
|
|
53
|
+
state: data.result,
|
|
54
|
+
options,
|
|
55
|
+
findManyFunction: Model.findManyPaginated
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
static async create(data) {
|
|
59
|
+
const createUrl = buildURL(Model.host, Model.collection);
|
|
60
|
+
const { _id, ...dataWithoutId } = data;
|
|
61
|
+
const response = await Model.apiClient.post(createUrl)
|
|
62
|
+
.body(dataWithoutId)
|
|
63
|
+
.headers({
|
|
64
|
+
'Content-Type': 'application/json'
|
|
65
|
+
});
|
|
66
|
+
await Model._handleApiError(response);
|
|
67
|
+
const json = await response.json();
|
|
68
|
+
return json.result;
|
|
69
|
+
}
|
|
70
|
+
static async createMany(records) {
|
|
71
|
+
if (!records || !Array.isArray(records) || !records.length) {
|
|
72
|
+
throw new Error(constants.DataTypeNotArray);
|
|
112
73
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
74
|
+
const createUrl = buildURL(Model.host, Model.collection) + '/batch';
|
|
75
|
+
const dataWithoutId = records.map(item => {
|
|
76
|
+
const { _id, ...rest } = item;
|
|
77
|
+
return rest;
|
|
78
|
+
});
|
|
79
|
+
const response = await Model.apiClient.post(createUrl)
|
|
80
|
+
.body(dataWithoutId)
|
|
81
|
+
.headers({
|
|
82
|
+
'Content-Type': 'application/json'
|
|
83
|
+
});
|
|
84
|
+
await Model._handleApiError(response);
|
|
85
|
+
const json = await response.json();
|
|
86
|
+
return json.result;
|
|
87
|
+
}
|
|
88
|
+
static async update(id, data) {
|
|
89
|
+
if (!id) {
|
|
90
|
+
throw new Error(constants.RequiresId);
|
|
121
91
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
92
|
+
const updateUrl = buildURL(Model.host, Model.collection, id);
|
|
93
|
+
const { _id, ...dataWithoutId } = data;
|
|
94
|
+
const response = await Model.apiClient.patch(updateUrl)
|
|
95
|
+
.body(dataWithoutId)
|
|
96
|
+
.headers({ 'Content-Type': 'application/json' });
|
|
97
|
+
await Model._handleApiError(response);
|
|
98
|
+
const json = await response.json();
|
|
99
|
+
return json.result;
|
|
100
|
+
}
|
|
101
|
+
static async updateMany(updates) {
|
|
102
|
+
if (!updates || !Array.isArray(updates) || updates.length === 0) {
|
|
103
|
+
throw new Error(constants.DataTypeNotArray);
|
|
133
104
|
}
|
|
134
|
-
|
|
135
|
-
|
|
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;
|
|
105
|
+
if (updates.some(update => !update._id)) {
|
|
106
|
+
throw new Error("All updates must have an _id");
|
|
145
107
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
108
|
+
const updateUrl = buildURL(Model.host, Model.collection) + '/batch';
|
|
109
|
+
const response = await Model.apiClient.patch(updateUrl)
|
|
110
|
+
.body(updates)
|
|
111
|
+
.headers({ 'Content-Type': 'application/json' });
|
|
112
|
+
await Model._handleApiError(response);
|
|
113
|
+
const json = await response.json();
|
|
114
|
+
return json.result;
|
|
115
|
+
}
|
|
116
|
+
static async delete(id) {
|
|
117
|
+
if (!id)
|
|
118
|
+
throw new Error(constants.RequiresId);
|
|
119
|
+
const deleteUrl = buildURL(Model.host, Model.collection, id);
|
|
120
|
+
const response = await Model.apiClient.delete(deleteUrl);
|
|
121
|
+
await Model._handleApiError(response);
|
|
122
|
+
const json = await response.json();
|
|
123
|
+
return json.result;
|
|
124
|
+
}
|
|
125
|
+
static async deleteMany(ids) {
|
|
126
|
+
if (!ids || ids.length === 0)
|
|
127
|
+
throw new Error(constants.RequiresIdsArray);
|
|
128
|
+
const deleteUrl = buildURL(Model.host, Model.collection) + '/batch';
|
|
129
|
+
const response = await Model.apiClient.delete(deleteUrl)
|
|
130
|
+
.body({ ids })
|
|
131
|
+
.headers({ 'Content-Type': 'application/json' });
|
|
132
|
+
await Model._handleApiError(response);
|
|
133
|
+
const json = await response.json();
|
|
134
|
+
return json.result;
|
|
135
|
+
}
|
|
136
|
+
static async distinct(fields, filter) {
|
|
137
|
+
throw new Error('Distinct method is disabled in this SDK version');
|
|
138
|
+
if (!fields || fields.length === 0) {
|
|
139
|
+
throw new Error(constants.DistinctRequiresFieldsArray);
|
|
150
140
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
const distinctUrl = buildURL(Model.host, Model.collection, 'distinct');
|
|
142
|
+
const response = await Model.apiClient.get(distinctUrl)
|
|
143
|
+
.params({ fields: fields.join(','), filter: filter ? JSON.stringify(filter) : undefined })
|
|
144
|
+
.headers({ 'Content-Type': 'application/json' });
|
|
145
|
+
await Model._handleApiError(response);
|
|
146
|
+
const json = await response.json();
|
|
147
|
+
return json.result;
|
|
148
|
+
}
|
|
149
|
+
constructor(data) {
|
|
150
|
+
super(options, apiClient);
|
|
151
|
+
this.modelData = { ...data, _id: null };
|
|
152
|
+
this.id = null;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
157
155
|
return Model;
|
|
158
156
|
};
|
|
159
157
|
export default createModel;
|
package/dist/schemas/baseAuth.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import Schema from 'validno';
|
|
2
2
|
import KodzeroValidationError from '../errors/KodzeroValidationError.js';
|
|
3
3
|
class BaseAuthSchema {
|
|
4
|
+
static schema = new Schema({
|
|
5
|
+
host: {
|
|
6
|
+
type: String
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
static validate = (options) => BaseAuthSchema.schema.validate(options);
|
|
10
|
+
static validateOrThrow = (options) => {
|
|
11
|
+
const validation = BaseAuthSchema.schema.validate(options);
|
|
12
|
+
if (!validation.ok) {
|
|
13
|
+
throw new KodzeroValidationError('Invalid auth options: ' + validation.failed.join(', '), validation.errors);
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
4
17
|
}
|
|
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
18
|
export default BaseAuthSchema;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import Schema from 'validno';
|
|
2
2
|
import KodzeroValidationError from '../errors/KodzeroValidationError.js';
|
|
3
3
|
class BaseModelSchema {
|
|
4
|
+
static schema = new Schema({
|
|
5
|
+
host: {
|
|
6
|
+
type: String
|
|
7
|
+
},
|
|
8
|
+
collection: {
|
|
9
|
+
type: String
|
|
10
|
+
},
|
|
11
|
+
schema: {
|
|
12
|
+
type: Schema,
|
|
13
|
+
required: false
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
static validate = (options) => BaseModelSchema.schema.validate(options);
|
|
17
|
+
static validateOrThrow = (options) => {
|
|
18
|
+
const validation = BaseModelSchema.schema.validate(options);
|
|
19
|
+
if (!validation.ok) {
|
|
20
|
+
throw new KodzeroValidationError('Invalid model options: ' + validation.failed.join(', '), validation.errors);
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
4
24
|
}
|
|
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
25
|
export default BaseModelSchema;
|
|
@@ -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.ts","../src/utils/validateapiresponse.ts"],"version":"5.8.3"}
|
|
1
|
+
{"root":["../src/kodzero.ts","../src/dev.ts","../src/index.ts","../src/__mocks__/fluid-fetch.ts","../src/__mocks__/validno.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/paginatedresult.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/dist/utils/buildURL.js
CHANGED
|
@@ -9,6 +9,6 @@ const validateApiResponse = async (response) => {
|
|
|
9
9
|
catch (err) {
|
|
10
10
|
json = null;
|
|
11
11
|
}
|
|
12
|
-
throw new KodzeroApiError(response.url, response.status, `API Request failed with status ${response.status}. Details: ${
|
|
12
|
+
throw new KodzeroApiError(response.url, response.status, `API Request failed with status ${response.status}. Details: ${json?.details || json?.error || response.statusText}`, json?.details || json?.error || response.statusText);
|
|
13
13
|
};
|
|
14
14
|
export default validateApiResponse;
|
package/jest.config.ts
CHANGED
|
@@ -64,25 +64,22 @@ const config: Config = {
|
|
|
64
64
|
// maxWorkers: "50%",
|
|
65
65
|
|
|
66
66
|
// An array of directory names to be searched recursively up from the requiring module's location
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
moduleDirectories: ['node_modules'],
|
|
68
|
+
|
|
69
|
+
extensionsToTreatAsEsm: [".ts"],
|
|
70
70
|
|
|
71
71
|
// An array of file extensions your modules use
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// "tsx",
|
|
79
|
-
// "json",
|
|
80
|
-
// "node"
|
|
81
|
-
// ],
|
|
72
|
+
moduleFileExtensions: [
|
|
73
|
+
"js",
|
|
74
|
+
"ts",
|
|
75
|
+
"json",
|
|
76
|
+
"node"
|
|
77
|
+
],
|
|
82
78
|
|
|
83
79
|
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
moduleNameMapper: {
|
|
81
|
+
"^(\\.{1,2}/.*)\\.js$": "$1",
|
|
82
|
+
},
|
|
86
83
|
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
87
84
|
// modulePathIgnorePatterns: [],
|
|
88
85
|
|
|
@@ -93,7 +90,7 @@ const config: Config = {
|
|
|
93
90
|
// notifyMode: "failure-change",
|
|
94
91
|
|
|
95
92
|
// A preset that is used as a base for Jest's configuration
|
|
96
|
-
|
|
93
|
+
preset: 'ts-jest',
|
|
97
94
|
|
|
98
95
|
// Run tests from one or more projects
|
|
99
96
|
// projects: undefined,
|
|
@@ -137,14 +134,14 @@ const config: Config = {
|
|
|
137
134
|
// snapshotSerializers: [],
|
|
138
135
|
|
|
139
136
|
// The test environment that will be used for testing
|
|
140
|
-
|
|
137
|
+
testEnvironment: "node",
|
|
141
138
|
|
|
142
139
|
// Options that will be passed to the testEnvironment
|
|
143
140
|
// testEnvironmentOptions: {},
|
|
144
141
|
|
|
145
142
|
// Adds a location field to test results
|
|
146
143
|
// testLocationInResults: false,
|
|
147
|
-
|
|
144
|
+
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
|
|
148
145
|
// The glob patterns Jest uses to detect test files
|
|
149
146
|
// testMatch: [
|
|
150
147
|
// "**/__tests__/**/*.[jt]s?(x)",
|
|
@@ -166,7 +163,14 @@ const config: Config = {
|
|
|
166
163
|
// testRunner: "jest-circus/runner",
|
|
167
164
|
|
|
168
165
|
// A map from regular expressions to paths to transformers
|
|
169
|
-
|
|
166
|
+
transform: {
|
|
167
|
+
"^.+\\.ts?$": [
|
|
168
|
+
"ts-jest",
|
|
169
|
+
{
|
|
170
|
+
useESM: true,
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
170
174
|
|
|
171
175
|
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
172
176
|
// transformIgnorePatterns: [
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kodzero-front-sdk-alfa",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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
9
|
"dev": "nodemon dist/dev.js",
|
|
10
|
-
"test": "
|
|
10
|
+
"test": "npx jest",
|
|
11
11
|
"prepare": "npm version patch && npm run tsc"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
"validno": "^0.3.5"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@
|
|
22
|
+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
23
23
|
"@types/express": "^5.0.1",
|
|
24
|
-
"@types/jest": "^
|
|
24
|
+
"@types/jest": "^30.0.0",
|
|
25
25
|
"@types/node": "^22.14.0",
|
|
26
26
|
"eslint": "^9.24.0",
|
|
27
|
-
"jest": "^
|
|
27
|
+
"jest": "^30.1.3",
|
|
28
|
+
"ts-jest": "^29.4.3"
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Mock for fluid-fetch as a constructor with options
|
|
2
|
+
export default function FluidFetch(this: any, options = {}) {
|
|
3
|
+
// Store options
|
|
4
|
+
this.options = options;
|
|
5
|
+
|
|
6
|
+
// Define middlewares
|
|
7
|
+
const middlewares = {
|
|
8
|
+
request: {
|
|
9
|
+
use: jest.fn()
|
|
10
|
+
},
|
|
11
|
+
response: {
|
|
12
|
+
use: jest.fn()
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Define request method
|
|
17
|
+
const request = jest.fn().mockImplementation(() => Promise.resolve({
|
|
18
|
+
data: {},
|
|
19
|
+
headers: {},
|
|
20
|
+
status: 200
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
// Assign properties to this.api
|
|
24
|
+
this.middlewares = middlewares;
|
|
25
|
+
this.request = request;
|
|
26
|
+
|
|
27
|
+
// Create api property for compatibility
|
|
28
|
+
this.api = {
|
|
29
|
+
middlewares,
|
|
30
|
+
request
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Make it constructable without 'new'
|
|
35
|
+
FluidFetch.prototype.constructor = FluidFetch;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import buildURL from '../../utils/buildURL.js';
|
|
2
|
+
|
|
3
|
+
describe('buildURL', () => {
|
|
4
|
+
test('buildURL constructs a URL without an ID', () => {
|
|
5
|
+
const url = buildURL('https://example.com', 'collection');
|
|
6
|
+
expect(url).toBe('https://example.com/collection');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('buildURL constructs a URL with an ID', () => {
|
|
10
|
+
const url = buildURL('https://example.com', 'collection', '123');
|
|
11
|
+
expect(url).toBe('https://example.com/collection/123');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('buildURL handles trailing slashes in baseUrl and collection', () => {
|
|
15
|
+
const url = buildURL('https://example.com/', '/collection/', '123');
|
|
16
|
+
expect(url).toBe('https://example.com/collection/123');
|
|
17
|
+
});
|
|
18
|
+
})
|
package/src/auth/base.ts
CHANGED
|
@@ -29,10 +29,10 @@ class KodzeroAuthBase {
|
|
|
29
29
|
* Base auth methods.
|
|
30
30
|
* These will be overridden by specific strategies (e.g. email, social, etc.)
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
login = (...args: any[]): Promise<any> | void => {}
|
|
33
|
+
register = (...args: any[]): Promise<any> | void => {}
|
|
34
34
|
refresh = (...args: any[]): Promise<any> | void => {}
|
|
35
|
-
|
|
35
|
+
logout = (...args: any[]): Promise<any> | void => {}
|
|
36
36
|
verify = (...args: any[]): Promise<any> | void => {}
|
|
37
37
|
}
|
|
38
38
|
|