jourycms-sdk 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. package/dist/base.app-container.d.ts +7 -0
  2. package/dist/base.app-container.d.ts.map +1 -0
  3. package/dist/base.app-container.js +10 -0
  4. package/dist/base.client.d.ts +10 -0
  5. package/dist/base.client.d.ts.map +1 -0
  6. package/dist/base.client.js +16 -0
  7. package/dist/base.service-container.d.ts +8 -0
  8. package/dist/base.service-container.d.ts.map +1 -0
  9. package/dist/base.service-container.js +12 -0
  10. package/dist/containers/auth/clients/api-keys.client.d.ts +13 -0
  11. package/dist/containers/auth/clients/api-keys.client.d.ts.map +1 -0
  12. package/dist/containers/auth/clients/api-keys.client.js +48 -0
  13. package/dist/containers/auth/clients/auth.client.d.ts +12 -0
  14. package/dist/containers/auth/clients/auth.client.d.ts.map +1 -0
  15. package/dist/containers/auth/clients/auth.client.js +39 -0
  16. package/dist/containers/auth/clients/permission-groups.client.d.ts +12 -0
  17. package/dist/containers/auth/clients/permission-groups.client.d.ts.map +1 -0
  18. package/dist/containers/auth/clients/permission-groups.client.js +42 -0
  19. package/dist/containers/auth/clients/permissions.client.d.ts +13 -0
  20. package/dist/containers/auth/clients/permissions.client.d.ts.map +1 -0
  21. package/dist/containers/auth/clients/permissions.client.js +48 -0
  22. package/dist/containers/auth/clients/roles.client.d.ts +17 -0
  23. package/dist/containers/auth/clients/roles.client.d.ts.map +1 -0
  24. package/dist/containers/auth/clients/roles.client.js +72 -0
  25. package/dist/containers/auth/clients/users.client.d.ts +26 -0
  26. package/dist/containers/auth/clients/users.client.d.ts.map +1 -0
  27. package/dist/containers/auth/clients/users.client.js +128 -0
  28. package/dist/containers/auth/service-container.d.ts +23 -0
  29. package/dist/containers/auth/service-container.d.ts.map +1 -0
  30. package/dist/containers/auth/service-container.js +48 -0
  31. package/dist/containers/content/clients/article-types.client.d.ts +15 -0
  32. package/dist/containers/content/clients/article-types.client.d.ts.map +1 -0
  33. package/dist/containers/content/clients/article-types.client.js +60 -0
  34. package/dist/containers/content/clients/articles.client.d.ts +15 -0
  35. package/dist/containers/content/clients/articles.client.d.ts.map +1 -0
  36. package/dist/containers/content/clients/articles.client.js +60 -0
  37. package/dist/containers/content/clients/comments.client.d.ts +15 -0
  38. package/dist/containers/content/clients/comments.client.d.ts.map +1 -0
  39. package/dist/containers/content/clients/comments.client.js +60 -0
  40. package/dist/containers/content/clients/reviews.client.d.ts +15 -0
  41. package/dist/containers/content/clients/reviews.client.d.ts.map +1 -0
  42. package/dist/containers/content/clients/reviews.client.js +60 -0
  43. package/dist/containers/content/clients/taxonomies.client.d.ts +15 -0
  44. package/dist/containers/content/clients/taxonomies.client.d.ts.map +1 -0
  45. package/dist/containers/content/clients/taxonomies.client.js +60 -0
  46. package/dist/containers/content/clients/terms.client.d.ts +15 -0
  47. package/dist/containers/content/clients/terms.client.d.ts.map +1 -0
  48. package/dist/containers/content/clients/terms.client.js +60 -0
  49. package/dist/containers/content/clients/translation.items.client.d.ts +16 -0
  50. package/dist/containers/content/clients/translation.items.client.d.ts.map +1 -0
  51. package/dist/containers/content/clients/translation.items.client.js +66 -0
  52. package/dist/containers/content/clients/translation.namespaces.client.d.ts +16 -0
  53. package/dist/containers/content/clients/translation.namespaces.client.d.ts.map +1 -0
  54. package/dist/containers/content/clients/translation.namespaces.client.js +66 -0
  55. package/dist/containers/content/clients/translation.projects.client.d.ts +16 -0
  56. package/dist/containers/content/clients/translation.projects.client.d.ts.map +1 -0
  57. package/dist/containers/content/clients/translation.projects.client.js +66 -0
  58. package/dist/containers/content/service-container.d.ts +29 -0
  59. package/dist/containers/content/service-container.d.ts.map +1 -0
  60. package/dist/containers/content/service-container.js +66 -0
  61. package/dist/containers/storage/clients/files.client.d.ts +13 -0
  62. package/dist/containers/storage/clients/files.client.d.ts.map +1 -0
  63. package/dist/containers/storage/clients/files.client.js +48 -0
  64. package/dist/containers/storage/clients/uploader.client.d.ts +6 -0
  65. package/dist/containers/storage/clients/uploader.client.d.ts.map +1 -0
  66. package/dist/containers/storage/clients/uploader.client.js +12 -0
  67. package/dist/containers/storage/clients/utils.client.d.ts +15 -0
  68. package/dist/containers/storage/clients/utils.client.d.ts.map +1 -0
  69. package/dist/containers/storage/clients/utils.client.js +45 -0
  70. package/dist/containers/storage/service-container.d.ts +31 -0
  71. package/dist/containers/storage/service-container.d.ts.map +1 -0
  72. package/dist/containers/storage/service-container.js +63 -0
  73. package/dist/containers/system/clients/apps.client.d.ts +16 -0
  74. package/dist/containers/system/clients/apps.client.d.ts.map +1 -0
  75. package/dist/containers/system/clients/apps.client.js +66 -0
  76. package/dist/containers/system/service-container.d.ts +13 -0
  77. package/dist/containers/system/service-container.d.ts.map +1 -0
  78. package/dist/containers/system/service-container.js +18 -0
  79. package/dist/exceptions/api-response.exception.d.ts +15 -0
  80. package/dist/exceptions/api-response.exception.d.ts.map +1 -0
  81. package/dist/exceptions/api-response.exception.js +26 -0
  82. package/dist/http-client.d.ts +20 -0
  83. package/dist/http-client.d.ts.map +1 -0
  84. package/dist/http-client.js +187 -0
  85. package/dist/index.d.ts +37 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +237 -0
  88. package/dist/init-sdk.d.ts +21 -0
  89. package/dist/init-sdk.d.ts.map +1 -0
  90. package/dist/init-sdk.js +17 -0
  91. package/dist/sdk.test.d.ts +1 -0
  92. package/dist/sdk.test.d.ts.map +1 -0
  93. package/dist/sdk.test.js +1 -0
  94. package/dist/utils/helpers.d.ts +5 -0
  95. package/dist/utils/helpers.d.ts.map +1 -0
  96. package/dist/utils/helpers.js +13 -0
  97. package/dist/utils/logger.d.ts +133 -0
  98. package/dist/utils/logger.d.ts.map +1 -0
  99. package/dist/utils/logger.js +176 -0
  100. package/package.json +49 -0
  101. package/typings/index.d.ts +1 -0
  102. package/typings/v1/cache-manager/class.d.ts +0 -0
  103. package/typings/v1/cache-manager/entity.d.ts +83 -0
  104. package/typings/v1/cache-manager/index.d.ts +5 -0
  105. package/typings/v1/cache-manager/store.d.ts +35 -0
  106. package/typings/v1/events/index.d.ts +3 -0
  107. package/typings/v1/events/payloads.d.ts +339 -0
  108. package/typings/v1/index.d.ts +8 -0
  109. package/typings/v1/lib/execution-scenario/index.d.ts +27 -0
  110. package/typings/v1/lib/index.d.ts +4 -0
  111. package/typings/v1/lib/logger/index.d.ts +3 -0
  112. package/typings/v1/lib/logger/logger.d.ts +53 -0
  113. package/typings/v1/modules/express/express.d.ts +40 -0
  114. package/typings/v1/modules/express/index.d.ts +3 -0
  115. package/typings/v1/modules/index.d.ts +4 -0
  116. package/typings/v1/modules/mongoose/index.d.ts +3 -0
  117. package/typings/v1/modules/mongoose/mongoose.d.ts +48 -0
  118. package/typings/v1/sdk/index.d.ts +3 -0
  119. package/typings/v1/sdk/sdk.d.ts +158 -0
  120. package/typings/v1/security/auth-data.d.ts +36 -0
  121. package/typings/v1/security/index.d.ts +4 -0
  122. package/typings/v1/security/jwt.d.ts +36 -0
  123. package/typings/v1/services/auth/api/api-key.d.ts +144 -0
  124. package/typings/v1/services/auth/api/auth.d.ts +168 -0
  125. package/typings/v1/services/auth/api/index.d.ts +9 -0
  126. package/typings/v1/services/auth/api/permission-group.d.ts +95 -0
  127. package/typings/v1/services/auth/api/permission.d.ts +128 -0
  128. package/typings/v1/services/auth/api/role.d.ts +193 -0
  129. package/typings/v1/services/auth/api/tools.d.ts +33 -0
  130. package/typings/v1/services/auth/api/user.d.ts +391 -0
  131. package/typings/v1/services/auth/entities/_shared.d.ts +11 -0
  132. package/typings/v1/services/auth/entities/api-key.d.ts +29 -0
  133. package/typings/v1/services/auth/entities/federated-credential.d.ts +22 -0
  134. package/typings/v1/services/auth/entities/index.d.ts +9 -0
  135. package/typings/v1/services/auth/entities/permission-group.d.ts +20 -0
  136. package/typings/v1/services/auth/entities/permission.d.ts +24 -0
  137. package/typings/v1/services/auth/entities/role.d.ts +25 -0
  138. package/typings/v1/services/auth/entities/user.d.ts +153 -0
  139. package/typings/v1/services/auth/index.d.ts +5 -0
  140. package/typings/v1/services/auth/models/.DS_Store +0 -0
  141. package/typings/v1/services/auth/models/api-key.d.ts +19 -0
  142. package/typings/v1/services/auth/models/api-key.model.d.ts +3 -0
  143. package/typings/v1/services/auth/models/federated-credential.d.ts +24 -0
  144. package/typings/v1/services/auth/models/index.d.ts +9 -0
  145. package/typings/v1/services/auth/models/permission-group.d.ts +24 -0
  146. package/typings/v1/services/auth/models/permission.d.ts +22 -0
  147. package/typings/v1/services/auth/models/role.d.ts +22 -0
  148. package/typings/v1/services/auth/models/user.d.ts +22 -0
  149. package/typings/v1/services/content/api/article-type.d.ts +160 -0
  150. package/typings/v1/services/content/api/article.d.ts +108 -0
  151. package/typings/v1/services/content/api/comment.d.ts +106 -0
  152. package/typings/v1/services/content/api/index.d.ts +12 -0
  153. package/typings/v1/services/content/api/review.d.ts +105 -0
  154. package/typings/v1/services/content/api/taxonomy.d.ts +101 -0
  155. package/typings/v1/services/content/api/term.d.ts +101 -0
  156. package/typings/v1/services/content/api/translation.item.d.ts +195 -0
  157. package/typings/v1/services/content/api/translation.namespace.d.ts +135 -0
  158. package/typings/v1/services/content/api/translation.project.d.ts +196 -0
  159. package/typings/v1/services/content/api/translation.tools.d.ts +85 -0
  160. package/typings/v1/services/content/entities/article-type.d.ts +51 -0
  161. package/typings/v1/services/content/entities/article.d.ts +53 -0
  162. package/typings/v1/services/content/entities/comment.d.ts +34 -0
  163. package/typings/v1/services/content/entities/index.d.ts +11 -0
  164. package/typings/v1/services/content/entities/review.d.ts +35 -0
  165. package/typings/v1/services/content/entities/taxonomy.d.ts +40 -0
  166. package/typings/v1/services/content/entities/term.d.ts +43 -0
  167. package/typings/v1/services/content/entities/translation.item.d.ts +48 -0
  168. package/typings/v1/services/content/entities/translation.namespace.d.ts +29 -0
  169. package/typings/v1/services/content/entities/translation.project.d.ts +98 -0
  170. package/typings/v1/services/content/index.d.ts +5 -0
  171. package/typings/v1/services/content/models/article-type.d.ts +19 -0
  172. package/typings/v1/services/content/models/article.d.ts +19 -0
  173. package/typings/v1/services/content/models/comment.d.ts +19 -0
  174. package/typings/v1/services/content/models/index.d.ts +11 -0
  175. package/typings/v1/services/content/models/review.d.ts +19 -0
  176. package/typings/v1/services/content/models/taxonomy.d.ts +19 -0
  177. package/typings/v1/services/content/models/term.d.ts +19 -0
  178. package/typings/v1/services/content/models/translation.item.d.ts +21 -0
  179. package/typings/v1/services/content/models/translation.namespace.d.ts +22 -0
  180. package/typings/v1/services/content/models/translation.project.d.ts +21 -0
  181. package/typings/v1/services/index.d.ts +4 -0
  182. package/typings/v1/services/storage/api/index.d.ts +3 -0
  183. package/typings/v1/services/storage/api/uploaded-file.d.ts +166 -0
  184. package/typings/v1/services/storage/entities/index.d.ts +3 -0
  185. package/typings/v1/services/storage/entities/uploaded-file.d.ts +49 -0
  186. package/typings/v1/services/storage/index.d.ts +5 -0
  187. package/typings/v1/services/storage/models/index.d.ts +3 -0
  188. package/typings/v1/services/storage/models/uploaded-file.d.ts +19 -0
  189. package/typings/v1/services/system/api/app.d.ts +130 -0
  190. package/typings/v1/services/system/api/index.d.ts +3 -0
  191. package/typings/v1/services/system/entities/app.d.ts +97 -0
  192. package/typings/v1/services/system/entities/index.d.ts +3 -0
  193. package/typings/v1/services/system/index.d.ts +5 -0
  194. package/typings/v1/services/system/models/app.d.ts +19 -0
  195. package/typings/v1/services/system/models/index.d.ts +3 -0
  196. package/typings/v1/ui/admin/index.d.ts +1 -0
  197. package/typings/v1/ui/forms/article/custom-fieds/custom-field.d.ts +189 -0
  198. package/typings/v1/ui/forms/article/custom-fieds/fields/article_object.custom-field.d.ts +29 -0
  199. package/typings/v1/ui/forms/article/custom-fieds/fields/boolean.custom-field.d.ts +24 -0
  200. package/typings/v1/ui/forms/article/custom-fieds/fields/checkbox.custom-field.d.ts +26 -0
  201. package/typings/v1/ui/forms/article/custom-fieds/fields/date.custom-field.d.ts +23 -0
  202. package/typings/v1/ui/forms/article/custom-fieds/fields/date_range.custom-field.d.ts +26 -0
  203. package/typings/v1/ui/forms/article/custom-fieds/fields/file.custom-field.d.ts +26 -0
  204. package/typings/v1/ui/forms/article/custom-fieds/fields/image.custom-field.d.ts +25 -0
  205. package/typings/v1/ui/forms/article/custom-fieds/fields/index.d.ts +11 -0
  206. package/typings/v1/ui/forms/article/custom-fieds/fields/number.custom-field.d.ts +26 -0
  207. package/typings/v1/ui/forms/article/custom-fieds/fields/radiobox.custom-field.d.ts +27 -0
  208. package/typings/v1/ui/forms/article/custom-fieds/fields/select.custom-field.d.ts +27 -0
  209. package/typings/v1/ui/forms/article/custom-fieds/fields/text.custom-field.d.ts +26 -0
  210. package/typings/v1/ui/forms/article/custom-fieds/fields/time.custom-field.d.ts +24 -0
  211. package/typings/v1/ui/forms/article/custom-fieds/index.d.ts +1 -0
  212. package/typings/v1/ui/forms/article/index.d.ts +1 -0
  213. package/typings/v1/ui/forms/index.d.ts +1 -0
  214. package/typings/v1/ui/index.d.ts +3 -0
  215. package/typings/v1/ui/routes/index.d.ts +1 -0
  216. package/typings/v1/ui/routes/routes.d.ts +73 -0
  217. package/typings/v1/utils/api/index.d.ts +4 -0
  218. package/typings/v1/utils/api/request.d.ts +215 -0
  219. package/typings/v1/utils/api/response.d.ts +188 -0
  220. package/typings/v1/utils/common/common.d.ts +53 -0
  221. package/typings/v1/utils/common/index.d.ts +3 -0
  222. package/typings/v1/utils/dev/config.d.ts +135 -0
  223. package/typings/v1/utils/dev/index.d.ts +4 -0
  224. package/typings/v1/utils/dev/instrumentation.d.ts +41 -0
  225. package/typings/v1/utils/entities/entities.d.ts +66 -0
  226. package/typings/v1/utils/entities/index.d.ts +4 -0
  227. package/typings/v1/utils/entities/snapshots.d.ts +69 -0
  228. package/typings/v1/utils/index.d.ts +10 -0
  229. package/typings/v1/utils/models/index.d.ts +3 -0
  230. package/typings/v1/utils/models/models.d.ts +50 -0
  231. package/typings/v1/utils/seed/index.d.ts +3 -0
  232. package/typings/v1/utils/seed/locations.d.ts +41 -0
  233. package/typings/v1/utils/system/microservice.d.ts +11 -0
  234. package/typings/v1/utils/system/models.d.ts +21 -0
  235. package/typings/v1/utils/utils.d.ts +171 -0
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const base_client_1 = __importDefault(require("../../../base.client"));
7
+ class AppsClient extends base_client_1.default {
8
+ constructor(container) {
9
+ super(container, '/apps');
10
+ }
11
+ // create
12
+ async create(data, config) {
13
+ return await this.container.sdk.httpClient.post(this.generatePrefix(), data, {
14
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
15
+ });
16
+ }
17
+ // update
18
+ async update(id, data, config) {
19
+ return await this.container.sdk.httpClient.put(this.generatePrefix("/:id", { id }), data, {
20
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
21
+ });
22
+ }
23
+ // delete
24
+ async delete(id, config) {
25
+ return await this.container.sdk.httpClient.delete(this.generatePrefix("/:id", { id }), {}, {
26
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
27
+ });
28
+ }
29
+ // restore
30
+ async restore(id, config) {
31
+ return await this.container.sdk.httpClient.delete(this.generatePrefix(`/${id}/restore`), {}, {
32
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
33
+ });
34
+ }
35
+ // bulkDelete
36
+ async bulkDelete(data, config) {
37
+ return await this.container.sdk.httpClient.delete(this.generatePrefix(`/bulk-delete`), data, {
38
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
39
+ });
40
+ }
41
+ // list
42
+ async list(query, config) {
43
+ return await this.container.sdk.httpClient.get(this.generatePrefix(), query, {
44
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
45
+ });
46
+ }
47
+ // getById
48
+ async getById(id, params, config) {
49
+ return await this.container.sdk.httpClient.get(this.generatePrefix("/:id", { id }), params, {
50
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
51
+ });
52
+ }
53
+ // getByTrackingId
54
+ async getByTrackingId(tracking_id, params, config) {
55
+ return await this.container.sdk.httpClient.get(this.generatePrefix("/by-tracking-id/:tracking_id", { tracking_id }), params, {
56
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
57
+ });
58
+ }
59
+ // getByName
60
+ async getByName(name, params, config) {
61
+ return await this.container.sdk.httpClient.get(this.generatePrefix(`/by-name/${name}`), params, {
62
+ headers: this.container.sdk.generateHeadersFromRequestConfig(config)
63
+ });
64
+ }
65
+ }
66
+ exports.default = AppsClient;
@@ -0,0 +1,13 @@
1
+ import BaseServiceContainer from '../../base.service-container';
2
+ /**
3
+ * @description Typing aliasing
4
+ */
5
+ import SDK = Levelup.CMS.V1.SDK;
6
+ import AppsClient from './clients/apps.client';
7
+ type TClientName = 'apps';
8
+ export default class SystemServiceContainer extends BaseServiceContainer<TClientName> {
9
+ constructor(sdk: SDK.ISdk);
10
+ get apps(): AppsClient;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=service-container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-container.d.ts","sourceRoot":"","sources":["../../../src/containers/system/service-container.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAEhE;;GAEG;AACH,OAAO,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC;AAChC,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,KAAK,WAAW,GACd,MAAM,CAAC;AAET,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,oBAAoB,CAAC,WAAW,CAAC;gBAEvE,GAAG,EAAE,GAAG,CAAC,IAAI;IAKzB,IAAI,IAAI,IAEsB,UAAU,CACvC;CAGF"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const base_service_container_1 = __importDefault(require("../../base.service-container"));
7
+ const apps_client_1 = __importDefault(require("./clients/apps.client"));
8
+ class SystemServiceContainer extends base_service_container_1.default {
9
+ constructor(sdk) {
10
+ super(sdk, '/api/v1/system');
11
+ }
12
+ get apps() {
13
+ if (!this.clients.apps)
14
+ this.clients.apps = new apps_client_1.default(this);
15
+ return this.clients.apps;
16
+ }
17
+ }
18
+ exports.default = SystemServiceContainer;
@@ -0,0 +1,15 @@
1
+ export default class ApiResponseError extends Error {
2
+ status: number;
3
+ backend_stack: string[] | string | undefined;
4
+ fields: Levelup.CMS.V1.Utils.Api.Response.ErrorFields | undefined;
5
+ constructor(error: Levelup.CMS.V1.Utils.Api.Response.Error);
6
+ toJSON(): {
7
+ name: string;
8
+ message: string;
9
+ stack: string | undefined;
10
+ status: number;
11
+ fields: Levelup.CMS.V1.Utils.Api.Response.ErrorFields<string> | undefined;
12
+ backend_stack: string | string[] | undefined;
13
+ };
14
+ }
15
+ //# sourceMappingURL=api-response.exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-response.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/api-response.exception.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,KAAK;IAE1C,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC;IAC7C,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,GAAG,SAAS,CAAC;gBAC7D,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK;IAY1D,MAAM;;;;;;;;CAUP"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ApiResponseError extends Error {
4
+ status;
5
+ backend_stack;
6
+ fields;
7
+ constructor(error) {
8
+ super(error.message);
9
+ this.name = error.name || this.constructor.name;
10
+ this.status = error.status || 500;
11
+ this.backend_stack = error.stack;
12
+ this.fields = error.fields;
13
+ Object.setPrototypeOf(this, ApiResponseError.prototype);
14
+ }
15
+ toJSON() {
16
+ return {
17
+ name: this.name,
18
+ message: this.message,
19
+ stack: this.stack,
20
+ status: this.status,
21
+ fields: this.fields,
22
+ backend_stack: this.backend_stack,
23
+ };
24
+ }
25
+ }
26
+ exports.default = ApiResponseError;
@@ -0,0 +1,20 @@
1
+ import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ import SDK = Levelup.CMS.V1.SDK;
3
+ export default class HttpClient implements SDK.IHttpClient {
4
+ readonly sdk: SDK.ISdk;
5
+ readonly client: AxiosInstance;
6
+ constructor(sdk: SDK.ISdk);
7
+ get<T extends SDK.IResponse>(path: string, query?: object, config?: AxiosRequestConfig): Promise<SDK.TResponseDatum<T>>;
8
+ delete<T extends SDK.IResponse>(path: string, query?: object, config?: AxiosRequestConfig): Promise<SDK.TResponseDatum<T>>;
9
+ head<T extends SDK.IResponse>(path: string, query?: object, config?: AxiosRequestConfig): Promise<SDK.TResponseDatum<T>>;
10
+ options<T extends SDK.IResponse>(path: string, query?: object, config?: AxiosRequestConfig): Promise<SDK.TResponseDatum<T>>;
11
+ post<T extends SDK.IResponse, D = any>(path: string, data?: D, config?: AxiosRequestConfig<D>): Promise<SDK.TResponseDatum<T>>;
12
+ put<T extends SDK.IResponse, D = any>(path: string, data?: D, config?: AxiosRequestConfig<D>): Promise<SDK.TResponseDatum<T>>;
13
+ patch<T extends SDK.IResponse, D = any>(path: string, data?: D, config?: AxiosRequestConfig<D>): Promise<SDK.TResponseDatum<T>>;
14
+ postForm<T extends SDK.IResponse, D = any>(path: string, data?: D, config?: AxiosRequestConfig<D>): Promise<SDK.TResponseDatum<T>>;
15
+ putForm<T extends SDK.IResponse, D = any>(path: string, data?: D, config?: AxiosRequestConfig<D>): Promise<SDK.TResponseDatum<T>>;
16
+ patchForm<T extends SDK.IResponse, D = any>(path: string, data?: D, config?: AxiosRequestConfig<D>): Promise<SDK.TResponseDatum<T>>;
17
+ request<T extends SDK.IResponse, D = any>(config: AxiosRequestConfig<D>): Promise<SDK.TResponseDatum<T>>;
18
+ get axios(): AxiosInstance;
19
+ }
20
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const axios_1 = __importStar(require("axios"));
30
+ const qs_1 = __importDefault(require("qs"));
31
+ class HttpClient {
32
+ sdk;
33
+ client;
34
+ constructor(sdk) {
35
+ this.sdk = sdk;
36
+ this.client = axios_1.default.create({
37
+ baseURL: sdk.config.baseURL.endsWith('/') ? sdk.config.baseURL.slice(0, -1) : sdk.config.baseURL,
38
+ paramsSerializer: function (params) {
39
+ return qs_1.default.stringify(params, { arrayFormat: 'brackets' });
40
+ },
41
+ validateStatus: () => {
42
+ return true;
43
+ // return status >= 200 && status < 300; // default
44
+ },
45
+ });
46
+ this.client.interceptors.request.use(async (config) => {
47
+ this.sdk.incrementRequestCount();
48
+ /**
49
+ * Load headers
50
+ */
51
+ const headers = await sdk.config.headers();
52
+ for (let idx = 0; idx < Object.keys(headers).length; idx++) {
53
+ const key = Object.keys(headers)[idx];
54
+ config.headers[key] = headers[key];
55
+ }
56
+ /**
57
+ * Add meta info
58
+ */
59
+ config.meta = config.meta || {};
60
+ config.meta.requestStartedAt = new Date().getTime();
61
+ config.meta.reqHeaders = config.headers;
62
+ return config;
63
+ }, (error) => {
64
+ // Handle the error without logging it to the console
65
+ if (error instanceof axios_1.AxiosError) {
66
+ // You can choose to handle specific status codes or other error properties here
67
+ // For example, you might want to log errors to a logging service instead:
68
+ // logErrorToService(error);
69
+ }
70
+ // You can still reject the error to let the calling code handle it if needed
71
+ return Promise.reject(error);
72
+ });
73
+ }
74
+ async get(path, query = {}, config) {
75
+ try {
76
+ const response = await this.client.get(path, {
77
+ ...config,
78
+ params: query,
79
+ });
80
+ return await this.sdk.handleResponse(response, this.client.get, path, { ...config, params: query, });
81
+ }
82
+ catch (err) {
83
+ throw this.sdk.handleError(err);
84
+ }
85
+ }
86
+ async delete(path, query = {}, config) {
87
+ try {
88
+ const response = await this.client.delete(path, {
89
+ ...config,
90
+ params: query
91
+ });
92
+ return await this.sdk.handleResponse(response, this.client.delete, path, { ...config, params: query });
93
+ }
94
+ catch (error) {
95
+ throw this.sdk.handleError(error);
96
+ }
97
+ }
98
+ async head(path, query = {}, config) {
99
+ try {
100
+ const response = await this.client.head(path, { ...config, params: query });
101
+ return await this.sdk.handleResponse(response, (this.client.head), path, { ...config, params: query });
102
+ }
103
+ catch (error) {
104
+ throw this.sdk.handleError(error);
105
+ }
106
+ }
107
+ async options(path, query = {}, config) {
108
+ try {
109
+ const response = await this.client.options(path, {
110
+ ...config,
111
+ params: query
112
+ });
113
+ return await this.sdk.handleResponse(response, (this.client.options), path, { ...config, params: query });
114
+ }
115
+ catch (error) {
116
+ throw this.sdk.handleError(error);
117
+ }
118
+ }
119
+ async post(path, data, config) {
120
+ try {
121
+ const response = await this.client.post(path, data, config);
122
+ return await this.sdk.handleResponse(response, (this.client.post), path, data, config);
123
+ }
124
+ catch (error) {
125
+ throw this.sdk.handleError(error);
126
+ }
127
+ }
128
+ async put(path, data, config) {
129
+ try {
130
+ const response = await this.client.put(path, data, config);
131
+ return await this.sdk.handleResponse(response, (this.client.put), path, data, config);
132
+ }
133
+ catch (error) {
134
+ throw this.sdk.handleError(error);
135
+ }
136
+ }
137
+ async patch(path, data, config) {
138
+ try {
139
+ const response = await this.client.patch(path, data, config);
140
+ return await this.sdk.handleResponse(response, (this.client.patch), path, data, config);
141
+ }
142
+ catch (error) {
143
+ throw this.sdk.handleError(error);
144
+ }
145
+ }
146
+ async postForm(path, data, config) {
147
+ try {
148
+ const response = await this.client.postForm(path, data, config);
149
+ return await this.sdk.handleResponse(response, (this.client.postForm), path, data, config);
150
+ }
151
+ catch (error) {
152
+ throw this.sdk.handleError(error);
153
+ }
154
+ }
155
+ async putForm(path, data, config) {
156
+ try {
157
+ const response = await this.client.putForm(path, data, config);
158
+ return await this.sdk.handleResponse(response, (this.client.putForm), path, data, config);
159
+ }
160
+ catch (error) {
161
+ throw this.sdk.handleError(error);
162
+ }
163
+ }
164
+ async patchForm(path, data, config) {
165
+ try {
166
+ const response = await this.client.patchForm(path, data, config);
167
+ return await this.sdk.handleResponse(response, (this.client.patchForm), path, data, config);
168
+ }
169
+ catch (error) {
170
+ throw this.sdk.handleError(error);
171
+ }
172
+ }
173
+ //
174
+ async request(config) {
175
+ try {
176
+ const response = await this.client.request(config);
177
+ return await this.sdk.handleResponse(response, (this.client.request), config.url, config);
178
+ }
179
+ catch (error) {
180
+ throw this.sdk.handleError(error);
181
+ }
182
+ }
183
+ get axios() {
184
+ return this.client;
185
+ }
186
+ }
187
+ exports.default = HttpClient;
@@ -0,0 +1,37 @@
1
+ import { AxiosHeaderValue, AxiosResponse } from "axios";
2
+ import AuthServiceContainer from "./containers/auth/service-container";
3
+ import ContentServiceContainer from "./containers/content/service-container";
4
+ import StorageServiceContainer from "./containers/storage/service-container";
5
+ import ApiResponseError from "./exceptions/api-response.exception";
6
+ import HttpClient from "./http-client";
7
+ import { initSdk, LevelupClientAppApiCallHeaders, LevelupInternalAppApiCallHeaders } from "./init-sdk";
8
+ import JouryCMSSdkHelpers from "./utils/helpers";
9
+ import SDK = Levelup.CMS.V1.SDK;
10
+ import SystemServiceContainer from "./containers/system/service-container";
11
+ export default class JouryCMSSdk implements SDK.ISdk {
12
+ readonly httpClient: HttpClient;
13
+ readonly config: SDK.ISdkConfig;
14
+ private static instances;
15
+ private _requestCount;
16
+ protected serviceContainers: Partial<Record<Levelup.CMS.V1.Utils.SystemStructure.TMicroService | "insights", SDK.IServiceContainer>>;
17
+ protected _helpersInstance: JouryCMSSdkHelpers;
18
+ static getInstance(config: SDK.ISdkConfig, id?: string): JouryCMSSdk;
19
+ constructor(config: SDK.ISdkConfig);
20
+ get auth(): AuthServiceContainer;
21
+ get content(): ContentServiceContainer;
22
+ get storage(): StorageServiceContainer;
23
+ get system(): SystemServiceContainer;
24
+ get helpers(): JouryCMSSdkHelpers;
25
+ generateHeadersFromRequestConfig(config?: SDK.TRequestConfig): {
26
+ [key: string]: AxiosHeaderValue;
27
+ };
28
+ handleResponse<T extends SDK.IResponse>(response: AxiosResponse<T, any>): Promise<SDK.TResponseDatum<T>>;
29
+ handleError(error: any): SDK.IError;
30
+ isApiResponseError(error: any): error is ApiResponseError;
31
+ logResponse<T extends SDK.IResponse>(response: AxiosResponse<T, any>): AxiosResponse<T, any> | undefined;
32
+ reinitRequestCount(): void;
33
+ incrementRequestCount(): void;
34
+ getRequestCount(): number;
35
+ }
36
+ export { ApiResponseError, initSdk, LevelupClientAppApiCallHeaders, LevelupInternalAppApiCallHeaders };
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,aAAa,EAEd,MAAM,OAAO,CAAC;AAEf,OAAO,oBAAoB,MAAM,qCAAqC,CAAC;AACvE,OAAO,uBAAuB,MAAM,wCAAwC,CAAC;AAC7E,OAAO,uBAAuB,MAAM,wCAAwC,CAAC;AAC7E,OAAO,gBAAgB,MAAM,qCAAqC,CAAC;AACnE,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EACL,OAAO,EACP,8BAA8B,EAC9B,gCAAgC,EACjC,MAAM,YAAY,CAAC;AACpB,OAAO,kBAAkB,MAAM,iBAAiB,CAAC;AAIjD,OAAO,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC;AAChC,OAAO,sBAAsB,MAAM,uCAAuC,CAAC;AAE3E,MAAM,CAAC,OAAO,OAAO,WAAY,YAAW,GAAG,CAAC,IAAI;IAClD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC;IAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAEjB;IACP,OAAO,CAAC,aAAa,CAAK;IAC1B,SAAS,CAAC,iBAAiB,EAAE,OAAO,CAClC,MAAM,CACJ,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,aAAa,GAAG,UAAU,EAC/D,GAAG,CAAC,iBAAiB,CACtB,CACF,CAAM;IACP,SAAS,CAAC,gBAAgB,EAAE,kBAAkB,CAAC;IAE/C,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,EAAE,GAAE,MAAkB;gBAKrD,MAAM,EAAE,GAAG,CAAC,UAAU;IAMlC,IAAI,IAAI,IAGgC,oBAAoB,CAC3D;IAED,IAAI,OAAO,IAGgC,uBAAuB,CACjE;IAED,IAAI,OAAO,IAGgC,uBAAuB,CACjE;IAED,IAAI,MAAM,IAGgC,sBAAsB,CAC/D;IAED,IAAI,OAAO,uBAGV;IAKD,gCAAgC,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,cAAc,GAAG;QAC7D,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAC;KACjC;IAkBK,cAAc,CAAC,CAAC,SAAS,GAAG,CAAC,SAAS,EAC1C,QAAQ,EAAE,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC,GAC9B,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAkCjC,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM;IAanC,kBAAkB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,gBAAgB;IAIzD,WAAW,CAAC,CAAC,SAAS,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,EAAE,GAAG,CAAC;IAuJ7D,kBAAkB;IAIlB,qBAAqB;IAIrB,eAAe;CAGvB;AAED,OAAO,EACL,gBAAgB,EAAE,OAAO,EACzB,8BAA8B,EAC9B,gCAAgC,EACjC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initSdk = exports.ApiResponseError = void 0;
7
+ const axios_1 = require("axios");
8
+ const colors_1 = __importDefault(require("colors"));
9
+ const service_container_1 = __importDefault(require("./containers/auth/service-container"));
10
+ const service_container_2 = __importDefault(require("./containers/content/service-container"));
11
+ const service_container_3 = __importDefault(require("./containers/storage/service-container"));
12
+ const api_response_exception_1 = __importDefault(require("./exceptions/api-response.exception"));
13
+ exports.ApiResponseError = api_response_exception_1.default;
14
+ const http_client_1 = __importDefault(require("./http-client"));
15
+ const init_sdk_1 = require("./init-sdk");
16
+ Object.defineProperty(exports, "initSdk", { enumerable: true, get: function () { return init_sdk_1.initSdk; } });
17
+ const helpers_1 = __importDefault(require("./utils/helpers"));
18
+ colors_1.default.enable();
19
+ const service_container_4 = __importDefault(require("./containers/system/service-container"));
20
+ class JouryCMSSdk {
21
+ httpClient;
22
+ config;
23
+ static instances = {};
24
+ _requestCount = 0;
25
+ serviceContainers = {};
26
+ _helpersInstance;
27
+ static getInstance(config, id = "DEFAULT") {
28
+ if (!this.instances[id])
29
+ this.instances[id] = new JouryCMSSdk(config);
30
+ return this.instances[id];
31
+ }
32
+ constructor(config) {
33
+ this.config = config;
34
+ this.httpClient = new http_client_1.default(this);
35
+ this._helpersInstance = new helpers_1.default();
36
+ }
37
+ get auth() {
38
+ if (!this.serviceContainers.auth)
39
+ this.serviceContainers.auth = new service_container_1.default(this);
40
+ return this.serviceContainers.auth;
41
+ }
42
+ get content() {
43
+ if (!this.serviceContainers.content)
44
+ this.serviceContainers.content = new service_container_2.default(this);
45
+ return this.serviceContainers.content;
46
+ }
47
+ get storage() {
48
+ if (!this.serviceContainers.storage)
49
+ this.serviceContainers.storage = new service_container_3.default(this);
50
+ return this.serviceContainers.storage;
51
+ }
52
+ get system() {
53
+ if (!this.serviceContainers.system)
54
+ this.serviceContainers.system = new service_container_4.default(this);
55
+ return this.serviceContainers.system;
56
+ }
57
+ get helpers() {
58
+ if (!this._helpersInstance)
59
+ this._helpersInstance = new helpers_1.default();
60
+ return this._helpersInstance;
61
+ }
62
+ /* -------------------------------------------------------------------------- */
63
+ /* end PharmaDz */
64
+ /* -------------------------------------------------------------------------- */
65
+ generateHeadersFromRequestConfig(config) {
66
+ const headers = {};
67
+ if (config?.serviceName) {
68
+ headers["X-Service-Secret"] = config.serviceToken;
69
+ headers["X-Service-Name"] = config.serviceName;
70
+ }
71
+ if (config?.token)
72
+ headers["Authorization"] = `Bearer ${config.token}`;
73
+ if (config?.app)
74
+ headers["X-App-Id"] = config.app;
75
+ if (config?.company)
76
+ headers["X-Company-Id"] = config.company;
77
+ if (config?.office)
78
+ headers["X-Office-Id"] = config.office;
79
+ if (config?.store)
80
+ headers["X-Store-Id"] = config.store;
81
+ if (config?.throw_not_found_error === false)
82
+ headers["X-Throw-Not-Found-Error"] = "false";
83
+ return headers;
84
+ }
85
+ async handleResponse(response) {
86
+ this.logResponse(response);
87
+ if (response.data?.error) {
88
+ if (response.data.error.name === "JWTTokenExpired" &&
89
+ this.config.refreshTokenHandler) {
90
+ // implement refresh token logic here
91
+ console.log("SDK.REFRESHING TOKEN".magenta);
92
+ await this.config.refreshTokenHandler(this);
93
+ const newResponse = await this.httpClient.request(response.config);
94
+ console.log("SDK.NEW RESPONSE", newResponse);
95
+ return newResponse;
96
+ }
97
+ else if (response.data?.error.status === 404 &&
98
+ response.config?.headers["X-Throw-Not-Found-Error"] === "false") {
99
+ return {
100
+ data: response.data.data,
101
+ edge: response.data.edge,
102
+ pagination: response.data.pagination,
103
+ };
104
+ }
105
+ else
106
+ throw new api_response_exception_1.default(response.data.error);
107
+ }
108
+ const result = {
109
+ data: response.data.data,
110
+ edge: response.data.edge,
111
+ pagination: response.data.pagination,
112
+ };
113
+ return result;
114
+ }
115
+ handleError(error) {
116
+ if (this.isApiResponseError(error))
117
+ return error;
118
+ if ((0, axios_1.isAxiosError)(error)) {
119
+ return new api_response_exception_1.default({
120
+ name: error.name,
121
+ message: error.message,
122
+ status: error.response?.status || 500,
123
+ isAxios: true,
124
+ });
125
+ }
126
+ return new Error(error);
127
+ }
128
+ isApiResponseError(error) {
129
+ return error instanceof api_response_exception_1.default;
130
+ }
131
+ logResponse(response) {
132
+ if (!this.config.debug) {
133
+ return;
134
+ }
135
+ const config = response.config;
136
+ const statusLabel = response.status >= 500
137
+ ? colors_1.default.red(`${response.status}`)
138
+ : response.status >= 400
139
+ ? colors_1.default.yellow(`${response.status}`)
140
+ : colors_1.default.green(`${response.status}`);
141
+ const dataLengthLabel = colors_1.default.gray(`${((+response.headers?.["content-length"] ||
142
+ +response.request?.responseText?.length ||
143
+ 0) / 1024).toFixed(2)} Kb`);
144
+ const fromCacheOrNetworkLabel = typeof window !== "undefined"
145
+ ? response.request?.fromCache
146
+ ? colors_1.default.yellow(`[CACHE]`)
147
+ : colors_1.default.cyan(`[NETWORK]`)
148
+ : "";
149
+ const label = `${colors_1.default.gray("[API Response]")} ${colors_1.default.cyan(`${new Date().getTime() - (config.meta?.requestStartedAt || 0)}ms`)} ${statusLabel} ${dataLengthLabel} ${fromCacheOrNetworkLabel}`;
150
+ let methodLabel = config.method?.toUpperCase();
151
+ if (methodLabel === "GET")
152
+ methodLabel = colors_1.default.magenta(methodLabel);
153
+ if (methodLabel === "POST")
154
+ methodLabel = colors_1.default.yellow(methodLabel);
155
+ if (methodLabel === "PUT")
156
+ methodLabel = colors_1.default.blue(methodLabel);
157
+ if (methodLabel === "DELETE")
158
+ methodLabel = colors_1.default.red(methodLabel);
159
+ if (typeof window !== "undefined") {
160
+ // Any status code that lie within the range of 2xx cause this function to trigger
161
+ // Do something with response data
162
+ console.groupCollapsed(`SDK.${methodLabel} ${config.url?.replace("http://localhost:5100", "")}`);
163
+ console.log(label, config.method?.toUpperCase(), config.url);
164
+ if (config.method?.toLowerCase() === "get") {
165
+ console.log(colors_1.default.cyan(`headers: %o`), config.headers);
166
+ console.log(colors_1.default.cyan(`params: %o`), config.params);
167
+ console.log(colors_1.default.cyan(`request: %o`), response.request);
168
+ if (config.params?.filters) {
169
+ console.log(colors_1.default.cyan(`filters: %o`), config.params?.filters);
170
+ }
171
+ }
172
+ else {
173
+ try {
174
+ console.log(colors_1.default.cyan(`params: %o`), config.data ? JSON.parse(config.data) : null);
175
+ }
176
+ catch (error) {
177
+ console.log(colors_1.default.cyan(`params: %o`), config.url?.includes("upload") ? "UPLOAD" : null);
178
+ }
179
+ }
180
+ console.log(colors_1.default.cyan(`data: %o`), response.data);
181
+ // Handle Auth errors
182
+ if (response.data.error?.message) {
183
+ console.log(colors_1.default.red(`axios response error: %s`), response.data.error.message);
184
+ if ((response.data?.error?.message === "jwt expired" ||
185
+ response.data?.error?.message === "User not found" ||
186
+ response.data?.error?.message ===
187
+ "No authorization token was found" ||
188
+ response.data?.error?.message === "invalid signature") &&
189
+ typeof window !== "undefined" &&
190
+ !window.location.pathname.includes("auth")) {
191
+ window.localStorage.clear();
192
+ // window.location.reload();
193
+ }
194
+ }
195
+ console.groupEnd();
196
+ }
197
+ else {
198
+ /**
199
+ * Log response in nodejs
200
+ */
201
+ console.log("");
202
+ console.log(`┌────────────────────────────────────────── start sdk log`.gray);
203
+ console.log(colors_1.default.gray("├── "), label, methodLabel, config.url?.gray);
204
+ console.log(colors_1.default.gray("│"));
205
+ console.log(colors_1.default.gray("├── "), colors_1.default.cyan("Status"), response.status, response.statusText);
206
+ console.log(colors_1.default.gray("├── "), colors_1.default.cyan("Request Headers"), config.headers);
207
+ console.log(colors_1.default.gray("├── "), colors_1.default.cyan("Response Headers"), response.headers);
208
+ if (config.method?.toLowerCase() === "get") {
209
+ console.log(colors_1.default.gray("├── "), colors_1.default.cyan("Request Params"), config.params);
210
+ }
211
+ else {
212
+ try {
213
+ console.log(colors_1.default.gray("├── "), colors_1.default.cyan("Request Params"), config.data ? JSON.parse(config.data) : null);
214
+ }
215
+ catch (error) {
216
+ console.log(colors_1.default.gray("├── "), colors_1.default.cyan("Request Params"), config.url?.includes("upload") ? "UPLOAD" : null);
217
+ }
218
+ }
219
+ if (response.data?.error) {
220
+ console.log(colors_1.default.gray("├── "), colors_1.default.red(`${response.status}: ${response.data?.error.message}`), response.data?.error);
221
+ }
222
+ console.log(`└────────────────────────────────────────── end sdk log`.gray);
223
+ console.log("");
224
+ }
225
+ return response;
226
+ }
227
+ reinitRequestCount() {
228
+ this._requestCount = 0;
229
+ }
230
+ incrementRequestCount() {
231
+ this._requestCount++;
232
+ }
233
+ getRequestCount() {
234
+ return this._requestCount;
235
+ }
236
+ }
237
+ exports.default = JouryCMSSdk;