phx-react 1.3.495 → 1.3.496

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.
@@ -0,0 +1,6 @@
1
+ interface RequestOptions {
2
+ method: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET';
3
+ body?: BodyInit;
4
+ }
5
+ declare function PHXFetchAPI(url: string, options: RequestOptions): Promise<any>;
6
+ export default PHXFetchAPI;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ var tslib_1 = require("tslib");
4
+ var js_cookie_1 = tslib_1.__importDefault(require("js-cookie"));
5
+ var constants_1 = require("../../utils/constants");
6
+ function PHXFetchAPI(url, options) {
7
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
8
+ var authTokenInfo, method, body, response, error_1;
9
+ return tslib_1.__generator(this, function (_a) {
10
+ switch (_a.label) {
11
+ case 0:
12
+ _a.trys.push([0, 3, , 4]);
13
+ authTokenInfo = js_cookie_1["default"].get(constants_1.AUTH_TOKEN) && JSON.parse(js_cookie_1["default"].get(constants_1.AUTH_TOKEN));
14
+ method = options.method, body = options.body;
15
+ return [4 /*yield*/, fetch(url, {
16
+ method: method,
17
+ headers: {
18
+ Authorization: authTokenInfo.token,
19
+ 'authorization-id': authTokenInfo.userInfo.id,
20
+ 'Content-Type': 'application/json'
21
+ },
22
+ body: body
23
+ })];
24
+ case 1:
25
+ response = _a.sent();
26
+ if (!response.ok) {
27
+ throw new Error("HTTP error! Status: ".concat(response.status));
28
+ }
29
+ return [4 /*yield*/, response.json()];
30
+ case 2: return [2 /*return*/, _a.sent()];
31
+ case 3:
32
+ error_1 = _a.sent();
33
+ console.error('Error calling API:', error_1);
34
+ throw error_1;
35
+ case 4: return [2 /*return*/];
36
+ }
37
+ });
38
+ });
39
+ }
40
+ exports["default"] = PHXFetchAPI;
41
+ //# sourceMappingURL=PHXFetchAPI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PHXFetchAPI.js","sourceRoot":"","sources":["../../../../src/components/Func/PHXFetchAPI.ts"],"names":[],"mappings":";;;AAAA,gEAA+B;AAC/B,mDAAkD;AAOlD,SAAe,WAAW,CAAC,GAAW,EAAE,OAAuB;;;;;;;oBAErD,aAAa,GAAG,sBAAO,CAAC,GAAG,CAAC,sBAAU,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,sBAAO,CAAC,GAAG,CAAC,sBAAU,CAAW,CAAC,CAAA;oBACtF,MAAM,GAAW,OAAO,OAAlB,EAAE,IAAI,GAAK,OAAO,KAAZ,CAAY;oBACf,qBAAM,KAAK,CAAC,GAAG,EAAE;4BAChC,MAAM,QAAA;4BACN,OAAO,EAAE;gCACP,aAAa,EAAE,aAAa,CAAC,KAAK;gCAClC,kBAAkB,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE;gCAC7C,cAAc,EAAE,kBAAkB;6BACnC;4BACD,IAAI,MAAA;yBACL,CAAC,EAAA;;oBARI,QAAQ,GAAG,SAQf;oBAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;wBAChB,MAAM,IAAI,KAAK,CAAC,8BAAuB,QAAQ,CAAC,MAAM,CAAE,CAAC,CAAA;qBAC1D;oBAEM,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;wBAA5B,sBAAO,SAAqB,EAAA;;;oBAE5B,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,OAAK,CAAC,CAAA;oBAC1C,MAAM,OAAK,CAAA;;;;;CAEd;AAED,qBAAe,WAAW,CAAA"}
@@ -0,0 +1,6 @@
1
+ interface RequestOptions {
2
+ method: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET';
3
+ body?: BodyInit;
4
+ }
5
+ declare function PHXFetchAPI(url: string, options: RequestOptions): Promise<any>;
6
+ export default PHXFetchAPI;
@@ -0,0 +1,39 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import Cookies from 'js-cookie';
3
+ import { AUTH_TOKEN } from '../../utils/constants';
4
+ function PHXFetchAPI(url, options) {
5
+ return __awaiter(this, void 0, void 0, function () {
6
+ var authTokenInfo, method, body, response, error_1;
7
+ return __generator(this, function (_a) {
8
+ switch (_a.label) {
9
+ case 0:
10
+ _a.trys.push([0, 3, , 4]);
11
+ authTokenInfo = Cookies.get(AUTH_TOKEN) && JSON.parse(Cookies.get(AUTH_TOKEN));
12
+ method = options.method, body = options.body;
13
+ return [4 /*yield*/, fetch(url, {
14
+ method: method,
15
+ headers: {
16
+ Authorization: authTokenInfo.token,
17
+ 'authorization-id': authTokenInfo.userInfo.id,
18
+ 'Content-Type': 'application/json'
19
+ },
20
+ body: body
21
+ })];
22
+ case 1:
23
+ response = _a.sent();
24
+ if (!response.ok) {
25
+ throw new Error("HTTP error! Status: ".concat(response.status));
26
+ }
27
+ return [4 /*yield*/, response.json()];
28
+ case 2: return [2 /*return*/, _a.sent()];
29
+ case 3:
30
+ error_1 = _a.sent();
31
+ console.error('Error calling API:', error_1);
32
+ throw error_1;
33
+ case 4: return [2 /*return*/];
34
+ }
35
+ });
36
+ });
37
+ }
38
+ export default PHXFetchAPI;
39
+ //# sourceMappingURL=PHXFetchAPI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PHXFetchAPI.js","sourceRoot":"","sources":["../../../../src/components/Func/PHXFetchAPI.ts"],"names":[],"mappings":";AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAOlD,SAAe,WAAW,CAAC,GAAW,EAAE,OAAuB;;;;;;;oBAErD,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAW,CAAC,CAAA;oBACtF,MAAM,GAAW,OAAO,OAAlB,EAAE,IAAI,GAAK,OAAO,KAAZ,CAAY;oBACf,qBAAM,KAAK,CAAC,GAAG,EAAE;4BAChC,MAAM,QAAA;4BACN,OAAO,EAAE;gCACP,aAAa,EAAE,aAAa,CAAC,KAAK;gCAClC,kBAAkB,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE;gCAC7C,cAAc,EAAE,kBAAkB;6BACnC;4BACD,IAAI,MAAA;yBACL,CAAC,EAAA;;oBARI,QAAQ,GAAG,SAQf;oBAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;wBAChB,MAAM,IAAI,KAAK,CAAC,8BAAuB,QAAQ,CAAC,MAAM,CAAE,CAAC,CAAA;qBAC1D;oBAEM,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;wBAA5B,sBAAO,SAAqB,EAAA;;;oBAE5B,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,OAAK,CAAC,CAAA;oBAC1C,MAAM,OAAK,CAAA;;;;;CAEd;AAED,eAAe,WAAW,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phx-react",
3
- "version": "1.3.495",
3
+ "version": "1.3.496",
4
4
  "description": "PHX REACT",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",