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.
Files changed (78) hide show
  1. package/README.md +6 -6
  2. package/dist/Kodzero.d.ts +1 -0
  3. package/dist/Kodzero.js +7 -3
  4. package/dist/__mocks__/fluid-fetch.d.ts +1 -0
  5. package/dist/__mocks__/fluid-fetch.js +23 -0
  6. package/dist/__mocks__/validno.d.ts +5 -0
  7. package/dist/__mocks__/validno.js +9 -0
  8. package/dist/auth/base.d.ts +3 -3
  9. package/dist/auth/base.js +8 -5
  10. package/dist/auth/email.d.ts +4 -4
  11. package/dist/auth/email.js +62 -60
  12. package/dist/auth/index.js +6 -3
  13. package/dist/auth/tokens.js +2 -0
  14. package/dist/errors/KodzeroApiError.js +3 -0
  15. package/dist/errors/KodzeroValidationError.js +1 -0
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.js +1 -48
  18. package/dist/model/BaseModel.d.ts +2 -2
  19. package/dist/model/BaseModel.js +25 -28
  20. package/dist/model/PaginatedResult.d.ts +28 -0
  21. package/dist/model/PaginatedResult.js +49 -0
  22. package/dist/model/createModel.d.ts +3 -1
  23. package/dist/model/createModel.js +145 -147
  24. package/dist/schemas/baseAuth.js +13 -13
  25. package/dist/schemas/baseModel.js +20 -20
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/dist/utils/buildURL.js +3 -1
  28. package/dist/utils/validateApiResponse.js +1 -1
  29. package/jest.config.ts +23 -19
  30. package/package.json +6 -5
  31. package/src/__mocks__/fluid-fetch.ts +35 -0
  32. package/src/__mocks__/validno.ts +12 -0
  33. package/src/__tests__/Kodzero.test.ts +9 -0
  34. package/src/__tests__/utils/buildURL.test.ts +18 -0
  35. package/src/auth/base.ts +3 -3
  36. package/src/auth/email.ts +11 -11
  37. package/src/auth/index.ts +3 -3
  38. package/src/index.ts +3 -0
  39. package/src/model/BaseModel.ts +10 -12
  40. package/src/model/PaginatedResult.ts +81 -0
  41. package/src/model/createModel.ts +39 -15
  42. package/src/schemas/baseAuth.ts +2 -1
  43. package/src/schemas/baseModel.ts +1 -1
  44. package/src/tsconfig.json +9 -8
  45. package/src/utils/buildURL.ts +2 -1
  46. package/dist/fetcher/InterceptorManager.d.ts +0 -9
  47. package/dist/fetcher/InterceptorManager.js +0 -42
  48. package/dist/fetcher/MiddlewareManager.d.ts +0 -9
  49. package/dist/fetcher/MiddlewareManager.js +0 -42
  50. package/dist/fetcher/index.d.ts +0 -77
  51. package/dist/fetcher/index.js +0 -194
  52. package/dist/model/baseModelOptionsSchema.d.ts +0 -2
  53. package/dist/model/baseModelOptionsSchema.js +0 -10
  54. package/dist/model/configSchema.d.ts +0 -0
  55. package/dist/model/configSchema.js +0 -1
  56. package/dist/model/errors/KodzeroApiError.d.ts +0 -7
  57. package/dist/model/errors/KodzeroApiError.js +0 -10
  58. package/dist/model/modelFactory.d.ts +0 -50
  59. package/dist/model/modelFactory.js +0 -41
  60. package/dist/model/modelSchema.d.ts +0 -0
  61. package/dist/model/modelSchema.js +0 -1
  62. package/dist/model/schemas/baseModel.d.ts +0 -6
  63. package/dist/model/schemas/baseModel.js +0 -25
  64. package/dist/model/schemas/baseModelOptionsSchema.d.ts +0 -2
  65. package/dist/model/schemas/baseModelOptionsSchema.js +0 -10
  66. package/dist/model/statics/getAll.d.ts +0 -2
  67. package/dist/model/statics/getAll.js +0 -4
  68. package/dist/model/utils/processUrl.d.ts +0 -2
  69. package/dist/model/utils/processUrl.js +0 -7
  70. package/dist/model/utils/validateApiResponse.d.ts +0 -2
  71. package/dist/model/utils/validateApiResponse.js +0 -14
  72. package/dist/schemas/baseModel copy.d.ts +0 -6
  73. package/dist/schemas/baseModel copy.js +0 -25
  74. package/dist/utils/buildURL_rename.d.ts +0 -2
  75. package/dist/utils/buildURL_rename.js +0 -7
  76. package/dist/utils/processUrl.d.ts +0 -2
  77. package/dist/utils/processUrl.js +0 -7
  78. /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
- 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;
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
- 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;
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
- 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;
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
- 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;
105
+ if (updates.some(update => !update._id)) {
106
+ throw new Error("All updates must have an _id");
145
107
  }
146
- constructor(data) {
147
- super(options, api);
148
- this.modelData = Object.assign(Object.assign({}, data), { _id: null });
149
- this.id = null;
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
- __setFunctionName(_a, "Model"),
153
- _a.host = options.host,
154
- _a.collection = options.collection,
155
- _a.api = api,
156
- _a);
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;
@@ -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"}
@@ -1,5 +1,7 @@
1
1
  const buildURL = (baseUrl, collection, id) => {
2
- let url = `${baseUrl}/${collection}`;
2
+ let url = `${baseUrl}`;
3
+ if (collection)
4
+ url += `/${collection}`;
3
5
  if (id)
4
6
  url += `/${id}`;
5
7
  return url.replace(/\/+/g, '/').replace(':/', '://');
@@ -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: ${(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);
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
- // moduleDirectories: [
68
- // "node_modules"
69
- // ],
67
+ moduleDirectories: ['node_modules'],
68
+
69
+ extensionsToTreatAsEsm: [".ts"],
70
70
 
71
71
  // An array of file extensions your modules use
72
- // moduleFileExtensions: [
73
- // "js",
74
- // "mjs",
75
- // "cjs",
76
- // "jsx",
77
- // "ts",
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
- // moduleNameMapper: {},
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
- // preset: undefined,
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
- // testEnvironment: "jest-environment-node",
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
- // transform: undefined,
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.4",
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": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
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
- "@jest/globals": "^29.7.0",
22
+ "@babel/plugin-transform-modules-commonjs": "^7.27.1",
23
23
  "@types/express": "^5.0.1",
24
- "@types/jest": "^29.5.14",
24
+ "@types/jest": "^30.0.0",
25
25
  "@types/node": "^22.14.0",
26
26
  "eslint": "^9.24.0",
27
- "jest": "^29.7.0"
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,12 @@
1
+ // Simple mock for fluid-fetch
2
+ export default function Schema() {
3
+ return {
4
+ // Mock the methods and properties you're using
5
+ validate: () => {
6
+ return {
7
+ ok: true
8
+ }
9
+ },
10
+ // Add other methods as needed
11
+ };
12
+ }
@@ -0,0 +1,9 @@
1
+ import Kodzero from '../Kodzero.js';
2
+
3
+ it('should create an instance if host provided', async () => {
4
+ const kodzero = new Kodzero({
5
+ host: 'http://localhost:6969'
6
+ });
7
+
8
+ expect(kodzero).toBeInstanceOf(Kodzero);
9
+ });
@@ -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
- signin = (...args: any[]): Promise<any> | void => {}
33
- signup = (...args: any[]): Promise<any> | void => {}
32
+ login = (...args: any[]): Promise<any> | void => {}
33
+ register = (...args: any[]): Promise<any> | void => {}
34
34
  refresh = (...args: any[]): Promise<any> | void => {}
35
- signout = (...args: any[]): Promise<any> | void => {}
35
+ logout = (...args: any[]): Promise<any> | void => {}
36
36
  verify = (...args: any[]): Promise<any> | void => {}
37
37
  }
38
38