@monkvision/network 4.0.0

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 (124) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +225 -0
  3. package/lib/package.json +84 -0
  4. package/lib/src/api/api.d.ts +18 -0
  5. package/lib/src/api/api.js +22 -0
  6. package/lib/src/api/api.js.map +1 -0
  7. package/lib/src/api/config.d.ts +20 -0
  8. package/lib/src/api/config.js +41 -0
  9. package/lib/src/api/config.js.map +1 -0
  10. package/lib/src/api/error.d.ts +34 -0
  11. package/lib/src/api/error.js +118 -0
  12. package/lib/src/api/error.js.map +1 -0
  13. package/lib/src/api/hooks/index.d.ts +1 -0
  14. package/lib/src/api/hooks/index.js +18 -0
  15. package/lib/src/api/hooks/index.js.map +1 -0
  16. package/lib/src/api/hooks/useInspectionPoll.d.ts +34 -0
  17. package/lib/src/api/hooks/useInspectionPoll.js +21 -0
  18. package/lib/src/api/hooks/useInspectionPoll.js.map +1 -0
  19. package/lib/src/api/image/index.d.ts +1 -0
  20. package/lib/src/api/image/index.js +18 -0
  21. package/lib/src/api/image/index.js.map +1 -0
  22. package/lib/src/api/image/mappers.d.ts +3 -0
  23. package/lib/src/api/image/mappers.js +166 -0
  24. package/lib/src/api/image/mappers.js.map +1 -0
  25. package/lib/src/api/image/requests.d.ts +141 -0
  26. package/lib/src/api/image/requests.js +312 -0
  27. package/lib/src/api/image/requests.js.map +1 -0
  28. package/lib/src/api/index.d.ts +10 -0
  29. package/lib/src/api/index.js +27 -0
  30. package/lib/src/api/index.js.map +1 -0
  31. package/lib/src/api/inspection/index.d.ts +1 -0
  32. package/lib/src/api/inspection/index.js +18 -0
  33. package/lib/src/api/inspection/index.js.map +1 -0
  34. package/lib/src/api/inspection/mappers.d.ts +5 -0
  35. package/lib/src/api/inspection/mappers.js +392 -0
  36. package/lib/src/api/inspection/mappers.js.map +1 -0
  37. package/lib/src/api/inspection/requests.d.ts +47 -0
  38. package/lib/src/api/inspection/requests.js +122 -0
  39. package/lib/src/api/inspection/requests.js.map +1 -0
  40. package/lib/src/api/liveConfigs/index.d.ts +1 -0
  41. package/lib/src/api/liveConfigs/index.js +18 -0
  42. package/lib/src/api/liveConfigs/index.js.map +1 -0
  43. package/lib/src/api/liveConfigs/requests.d.ts +7 -0
  44. package/lib/src/api/liveConfigs/requests.js +66 -0
  45. package/lib/src/api/liveConfigs/requests.js.map +1 -0
  46. package/lib/src/api/models/common.d.ts +13 -0
  47. package/lib/src/api/models/common.js +3 -0
  48. package/lib/src/api/models/common.js.map +1 -0
  49. package/lib/src/api/models/compliance.d.ts +58 -0
  50. package/lib/src/api/models/compliance.js +3 -0
  51. package/lib/src/api/models/compliance.js.map +1 -0
  52. package/lib/src/api/models/damage.d.ts +11 -0
  53. package/lib/src/api/models/damage.js +3 -0
  54. package/lib/src/api/models/damage.js.map +1 -0
  55. package/lib/src/api/models/image.d.ts +76 -0
  56. package/lib/src/api/models/image.js +3 -0
  57. package/lib/src/api/models/image.js.map +1 -0
  58. package/lib/src/api/models/index.d.ts +13 -0
  59. package/lib/src/api/models/index.js +30 -0
  60. package/lib/src/api/models/index.js.map +1 -0
  61. package/lib/src/api/models/inspection.d.ts +40 -0
  62. package/lib/src/api/models/inspection.js +3 -0
  63. package/lib/src/api/models/inspection.js.map +1 -0
  64. package/lib/src/api/models/part.d.ts +10 -0
  65. package/lib/src/api/models/part.js +3 -0
  66. package/lib/src/api/models/part.js.map +1 -0
  67. package/lib/src/api/models/pricingV2.d.ts +15 -0
  68. package/lib/src/api/models/pricingV2.js +3 -0
  69. package/lib/src/api/models/pricingV2.js.map +1 -0
  70. package/lib/src/api/models/renderedOutput.d.ts +8 -0
  71. package/lib/src/api/models/renderedOutput.js +3 -0
  72. package/lib/src/api/models/renderedOutput.js.map +1 -0
  73. package/lib/src/api/models/severityResult.d.ts +37 -0
  74. package/lib/src/api/models/severityResult.js +3 -0
  75. package/lib/src/api/models/severityResult.js.map +1 -0
  76. package/lib/src/api/models/task.d.ts +76 -0
  77. package/lib/src/api/models/task.js +3 -0
  78. package/lib/src/api/models/task.js.map +1 -0
  79. package/lib/src/api/models/vehicle.d.ts +58 -0
  80. package/lib/src/api/models/vehicle.js +3 -0
  81. package/lib/src/api/models/vehicle.js.map +1 -0
  82. package/lib/src/api/models/view.d.ts +24 -0
  83. package/lib/src/api/models/view.js +3 -0
  84. package/lib/src/api/models/view.js.map +1 -0
  85. package/lib/src/api/models/wheelAnalysis.d.ts +13 -0
  86. package/lib/src/api/models/wheelAnalysis.js +3 -0
  87. package/lib/src/api/models/wheelAnalysis.js.map +1 -0
  88. package/lib/src/api/react.d.ts +69 -0
  89. package/lib/src/api/react.js +105 -0
  90. package/lib/src/api/react.js.map +1 -0
  91. package/lib/src/api/task/index.d.ts +1 -0
  92. package/lib/src/api/task/index.js +18 -0
  93. package/lib/src/api/task/index.js.map +1 -0
  94. package/lib/src/api/task/requests.d.ts +67 -0
  95. package/lib/src/api/task/requests.js +135 -0
  96. package/lib/src/api/task/requests.js.map +1 -0
  97. package/lib/src/api/types.d.ts +24 -0
  98. package/lib/src/api/types.js +3 -0
  99. package/lib/src/api/types.js.map +1 -0
  100. package/lib/src/api/utils.d.ts +9 -0
  101. package/lib/src/api/utils.js +22 -0
  102. package/lib/src/api/utils.js.map +1 -0
  103. package/lib/src/api/vehicle/index.d.ts +1 -0
  104. package/lib/src/api/vehicle/index.js +18 -0
  105. package/lib/src/api/vehicle/index.js.map +1 -0
  106. package/lib/src/api/vehicle/mappers.d.ts +3 -0
  107. package/lib/src/api/vehicle/mappers.js +33 -0
  108. package/lib/src/api/vehicle/mappers.js.map +1 -0
  109. package/lib/src/api/vehicle/requests.d.ts +31 -0
  110. package/lib/src/api/vehicle/requests.js +88 -0
  111. package/lib/src/api/vehicle/requests.js.map +1 -0
  112. package/lib/src/auth/hooks.d.ts +34 -0
  113. package/lib/src/auth/hooks.js +112 -0
  114. package/lib/src/auth/hooks.js.map +1 -0
  115. package/lib/src/auth/index.d.ts +2 -0
  116. package/lib/src/auth/index.js +19 -0
  117. package/lib/src/auth/index.js.map +1 -0
  118. package/lib/src/auth/token.d.ts +25 -0
  119. package/lib/src/auth/token.js +36 -0
  120. package/lib/src/auth/token.js.map +1 -0
  121. package/lib/src/index.d.ts +2 -0
  122. package/lib/src/index.js +19 -0
  123. package/lib/src/index.js.map +1 -0
  124. package/package.json +85 -0
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.updateInspectionVehicle = void 0;
54
+ var ky_1 = __importDefault(require("ky"));
55
+ var config_1 = require("../config");
56
+ var mappers_1 = require("./mappers");
57
+ /**
58
+ * Update the vehicle of an inspection.
59
+ *
60
+ * @param options The options of the request.
61
+ * @param config The API config.
62
+ * @param [_dispatch] Optional MonkState dispatch function that you can pass if you want this request to handle React
63
+ * state management for you.
64
+ */
65
+ function updateInspectionVehicle(options, config, _dispatch) {
66
+ return __awaiter(this, void 0, void 0, function () {
67
+ var kyOptions, response, body;
68
+ return __generator(this, function (_a) {
69
+ switch (_a.label) {
70
+ case 0:
71
+ kyOptions = (0, config_1.getDefaultOptions)(config);
72
+ return [4 /*yield*/, ky_1.default.patch("inspections/".concat(options.inspectionId, "/vehicle"), __assign(__assign({}, kyOptions), { json: (0, mappers_1.mapApiVehiclePatch)(options.vehicle) }))];
73
+ case 1:
74
+ response = _a.sent();
75
+ return [4 /*yield*/, response.json()];
76
+ case 2:
77
+ body = _a.sent();
78
+ return [2 /*return*/, {
79
+ id: body.id,
80
+ response: response,
81
+ body: body,
82
+ }];
83
+ }
84
+ });
85
+ });
86
+ }
87
+ exports.updateInspectionVehicle = updateInspectionVehicle;
88
+ //# sourceMappingURL=requests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requests.js","sourceRoot":"","sources":["../../../../src/api/vehicle/requests.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAoB;AAIpB,oCAA6D;AAE7D,qCAA+C;AAe/C;;;;;;;GAOG;AAEH,SAAsB,uBAAuB,CAC3C,OAAuC,EACvC,MAAqB,EACrB,SAAgC;;;;;;oBAE1B,SAAS,GAAG,IAAA,0BAAiB,EAAC,MAAM,CAAC,CAAC;oBAC3B,qBAAM,YAAE,CAAC,KAAK,CAAC,sBAAe,OAAO,CAAC,YAAY,aAAU,wBACxE,SAAS,KACZ,IAAI,EAAE,IAAA,4BAAkB,EAAC,OAAO,CAAC,OAAO,CAAC,IACzC,EAAA;;oBAHI,QAAQ,GAAG,SAGf;oBACW,qBAAM,QAAQ,CAAC,IAAI,EAAe,EAAA;;oBAAzC,IAAI,GAAG,SAAkC;oBAC/C,sBAAO;4BACL,EAAE,EAAE,IAAI,CAAC,EAAE;4BACX,QAAQ,UAAA;4BACR,IAAI,MAAA;yBACL,EAAC;;;;CACH;AAhBD,0DAgBC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Parameters of the `useAuth` hook.
3
+ */
4
+ export interface UseAuthParams {
5
+ /**
6
+ * Boolean indicating if the authentication token should be stored in the local storage or not.
7
+ *
8
+ * @default true
9
+ */
10
+ storeToken?: boolean;
11
+ }
12
+ /**
13
+ * Handle used to manage the authentication state of a Monk app using the `useAuth` hook.
14
+ */
15
+ export interface MonkAuthHandle {
16
+ /**
17
+ * Callback used to ask the user to log in using an Auth0 pop-up window. This callback returns the resulting token if
18
+ * the process was successful, but it also automatically stores the token in the local storage (if `storeToken` is
19
+ * `true`) and updates the current auth token value in the `useMonkAppState` hook.
20
+ */
21
+ login: () => Promise<string | null>;
22
+ /**
23
+ * Callback used to log out the user, both from this application and from Auth0. It also automatically removes the
24
+ * token in the local storage (if `storeToken` is `true`) and clears the current auth token value in the
25
+ * `useMonkAppState` hook.
26
+ */
27
+ logout: () => Promise<void>;
28
+ }
29
+ /**
30
+ * Custom hook used to easily handle authentication in Monk applications. It stores the current user's authentication
31
+ * token in the `useMonkAppState` hook, and returns callbacks used to log in and out of the application using Auth0
32
+ * pop-ups.
33
+ */
34
+ export declare function useAuth(params?: UseAuthParams): MonkAuthHandle;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.useAuth = void 0;
51
+ var auth0_react_1 = require("@auth0/auth0-react");
52
+ var react_1 = require("react");
53
+ var common_1 = require("@monkvision/common");
54
+ var defaultOptions = {
55
+ storeToken: true,
56
+ };
57
+ /**
58
+ * Custom hook used to easily handle authentication in Monk applications. It stores the current user's authentication
59
+ * token in the `useMonkAppState` hook, and returns callbacks used to log in and out of the application using Auth0
60
+ * pop-ups.
61
+ */
62
+ function useAuth(params) {
63
+ var _this = this;
64
+ var options = __assign(__assign({}, defaultOptions), (params !== null && params !== void 0 ? params : {}));
65
+ var _a = (0, auth0_react_1.useAuth0)(), getAccessTokenWithPopup = _a.getAccessTokenWithPopup, logout = _a.logout;
66
+ var setAuthToken = (0, common_1.useMonkAppState)().setAuthToken;
67
+ (0, react_1.useEffect)(function () {
68
+ if (options.storeToken) {
69
+ var token = localStorage.getItem(common_1.STORAGE_KEY_AUTH_TOKEN);
70
+ if (token) {
71
+ setAuthToken(token);
72
+ }
73
+ }
74
+ }, []);
75
+ var handleLogin = (0, react_1.useCallback)(function () { return __awaiter(_this, void 0, void 0, function () {
76
+ var token;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0: return [4 /*yield*/, getAccessTokenWithPopup()];
80
+ case 1:
81
+ token = _a.sent();
82
+ if (token) {
83
+ setAuthToken(token);
84
+ if (options.storeToken) {
85
+ localStorage.setItem(common_1.STORAGE_KEY_AUTH_TOKEN, token);
86
+ }
87
+ return [2 /*return*/, token];
88
+ }
89
+ return [2 /*return*/, null];
90
+ }
91
+ });
92
+ }); }, [getAccessTokenWithPopup, options.storeToken, setAuthToken]);
93
+ var handleLogout = (0, react_1.useCallback)(function () { return __awaiter(_this, void 0, void 0, function () {
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0:
97
+ setAuthToken(null);
98
+ localStorage.removeItem(common_1.STORAGE_KEY_AUTH_TOKEN);
99
+ return [4 /*yield*/, logout({ logoutParams: { returnTo: window.location.origin } })];
100
+ case 1:
101
+ _a.sent();
102
+ return [2 /*return*/];
103
+ }
104
+ });
105
+ }); }, [logout, setAuthToken]);
106
+ return (0, common_1.useObjectMemo)({
107
+ login: handleLogin,
108
+ logout: handleLogout,
109
+ });
110
+ }
111
+ exports.useAuth = useAuth;
112
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/auth/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA8C;AAC9C,+BAA+C;AAC/C,6CAA4F;AAgC5F,IAAM,cAAc,GAAG;IACrB,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF;;;;GAIG;AACH,SAAgB,OAAO,CAAC,MAAsB;IAA9C,iBAoCC;IAnCC,IAAM,OAAO,yBAAQ,cAAc,GAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAE,CAAC;IACnD,IAAA,KAAsC,IAAA,sBAAQ,GAAE,EAA9C,uBAAuB,6BAAA,EAAE,MAAM,YAAe,CAAC;IAC/C,IAAA,YAAY,GAAK,IAAA,wBAAe,GAAE,aAAtB,CAAuB;IAE3C,IAAA,iBAAS,EAAC;QACR,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,+BAAsB,CAAC,CAAC;YAC3D,IAAI,KAAK,EAAE;gBACT,YAAY,CAAC,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAM,WAAW,GAAG,IAAA,mBAAW,EAAC;;;;wBAChB,qBAAM,uBAAuB,EAAE,EAAA;;oBAAvC,KAAK,GAAG,SAA+B;oBAC7C,IAAI,KAAK,EAAE;wBACT,YAAY,CAAC,KAAK,CAAC,CAAC;wBACpB,IAAI,OAAO,CAAC,UAAU,EAAE;4BACtB,YAAY,CAAC,OAAO,CAAC,+BAAsB,EAAE,KAAK,CAAC,CAAC;yBACrD;wBACD,sBAAO,KAAK,EAAC;qBACd;oBACD,sBAAO,IAAI,EAAC;;;SACb,EAAE,CAAC,uBAAuB,EAAE,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAEhE,IAAM,YAAY,GAAG,IAAA,mBAAW,EAAC;;;;oBAC/B,YAAY,CAAC,IAAI,CAAC,CAAC;oBACnB,YAAY,CAAC,UAAU,CAAC,+BAAsB,CAAC,CAAC;oBAChD,qBAAM,MAAM,CAAC,EAAE,YAAY,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,EAAA;;oBAApE,SAAoE,CAAC;;;;SACtE,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3B,OAAO,IAAA,sBAAa,EAAC;QACnB,KAAK,EAAE,WAAW;QAClB,MAAM,EAAE,YAAY;KACrB,CAAC,CAAC;AACL,CAAC;AApCD,0BAoCC"}
@@ -0,0 +1,2 @@
1
+ export * from './token';
2
+ export * from './hooks';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./token"), exports);
18
+ __exportStar(require("./hooks"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,0CAAwB"}
@@ -0,0 +1,25 @@
1
+ import { JwtPayload } from 'jsonwebtoken';
2
+ import { MonkApiPermission } from '@monkvision/types';
3
+ /**
4
+ * The payload of the authentication token used with the Monk API.
5
+ */
6
+ export interface MonkJwtPayload extends JwtPayload {
7
+ /**
8
+ * The array of permissions that the user has.
9
+ */
10
+ permissions?: MonkApiPermission[];
11
+ }
12
+ /**
13
+ * Decode the given Monk auth token and returns the MonkJwtPayload.
14
+ */
15
+ export declare function decodeMonkJwt(token: string): MonkJwtPayload;
16
+ /**
17
+ * Utility function that checks if the given user has all the required authroizations. You can either pass an auth token
18
+ * to be decoded or the JWT payload directly.
19
+ */
20
+ export declare function isUserAuthorized(tokenOrPayload: MonkJwtPayload | string | null, permissions: MonkApiPermission[]): boolean;
21
+ /**
22
+ * Utility function that checks if an authorization token is expired or not. You can either pass an auth token to be
23
+ * decoded or the JWT payload directly.
24
+ */
25
+ export declare function isTokenExpired(tokenOrPayload: MonkJwtPayload | string | null): boolean;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTokenExpired = exports.isUserAuthorized = exports.decodeMonkJwt = void 0;
4
+ var jwt_decode_1 = require("jwt-decode");
5
+ /**
6
+ * Decode the given Monk auth token and returns the MonkJwtPayload.
7
+ */
8
+ function decodeMonkJwt(token) {
9
+ return (0, jwt_decode_1.jwtDecode)(token);
10
+ }
11
+ exports.decodeMonkJwt = decodeMonkJwt;
12
+ /**
13
+ * Utility function that checks if the given user has all the required authroizations. You can either pass an auth token
14
+ * to be decoded or the JWT payload directly.
15
+ */
16
+ function isUserAuthorized(tokenOrPayload, permissions) {
17
+ if (!tokenOrPayload) {
18
+ return false;
19
+ }
20
+ var payload = typeof tokenOrPayload === 'object' ? tokenOrPayload : decodeMonkJwt(tokenOrPayload);
21
+ return permissions.every(function (requiredPermission) { var _a; return (_a = payload.permissions) === null || _a === void 0 ? void 0 : _a.includes(requiredPermission); });
22
+ }
23
+ exports.isUserAuthorized = isUserAuthorized;
24
+ /**
25
+ * Utility function that checks if an authorization token is expired or not. You can either pass an auth token to be
26
+ * decoded or the JWT payload directly.
27
+ */
28
+ function isTokenExpired(tokenOrPayload) {
29
+ if (!tokenOrPayload) {
30
+ return false;
31
+ }
32
+ var payload = typeof tokenOrPayload === 'object' ? tokenOrPayload : decodeMonkJwt(tokenOrPayload);
33
+ return !payload.exp || Math.round(Date.now() / 1000) >= payload.exp;
34
+ }
35
+ exports.isTokenExpired = isTokenExpired;
36
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../../src/auth/token.ts"],"names":[],"mappings":";;;AACA,yCAAuC;AAavC;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAa;IACzC,OAAO,IAAA,sBAAS,EAAiB,KAAK,CAAC,CAAC;AAC1C,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAC9B,cAA8C,EAC9C,WAAgC;IAEhC,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IACD,IAAM,OAAO,GACX,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IACtF,OAAO,WAAW,CAAC,KAAK,CAAC,UAAC,kBAAkB,YAC1C,OAAA,MAAA,OAAO,CAAC,WAAW,0CAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAA,EAAA,CAClD,CAAC;AACJ,CAAC;AAZD,4CAYC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,cAA8C;IAC3E,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IACD,IAAM,OAAO,GACX,OAAO,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IACtF,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC;AACtE,CAAC;AAPD,wCAOC"}
@@ -0,0 +1,2 @@
1
+ export * from './api';
2
+ export * from './auth';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
18
+ __exportStar(require("./auth"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAAuB"}
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@monkvision/network",
3
+ "version": "4.0.0",
4
+ "license": "BSD-3-Clause-Clear",
5
+ "packageManager": "yarn@3.2.4",
6
+ "description": "MonkJs core package used to communicate with the API",
7
+ "author": "monkvision",
8
+ "main": "lib/src/index.js",
9
+ "types": "lib/src/index.d.ts",
10
+ "files": [
11
+ "package.json",
12
+ "README.md",
13
+ "lib"
14
+ ],
15
+ "scripts": {
16
+ "clean": "rimraf lib && mkdirp lib",
17
+ "build": "yarn run clean && tsc -p tsconfig.build.json",
18
+ "test": "jest",
19
+ "test:coverage": "jest --coverage",
20
+ "prettier": "prettier --check ./src ./test",
21
+ "prettier:fix": "prettier --write ./src ./test",
22
+ "eslint": "eslint --format=pretty ./src ./test",
23
+ "eslint:fix": "eslint --fix --format=pretty ./src ./test",
24
+ "lint": "yarn run prettier && yarn run eslint",
25
+ "lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
26
+ },
27
+ "dependencies": {
28
+ "@monkvision/common": "^4.0.0",
29
+ "@monkvision/sights": "^4.0.0",
30
+ "jsonwebtoken": "^9.0.2",
31
+ "jwt-decode": "^4.0.0",
32
+ "ky": "^1.2.0",
33
+ "uuid": "^9.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@auth0/auth0-react": "^2.2.4",
37
+ "react": "^17.0.2",
38
+ "react-dom": "^17.0.2",
39
+ "react-router-dom": "^6.22.3"
40
+ },
41
+ "devDependencies": {
42
+ "@monkvision/eslint-config-base": "4.0.0",
43
+ "@monkvision/eslint-config-typescript": "4.0.0",
44
+ "@monkvision/jest-config": "4.0.0",
45
+ "@monkvision/prettier-config": "4.0.0",
46
+ "@monkvision/types": "^4.0.0",
47
+ "@monkvision/typescript-config": "4.0.0",
48
+ "@types/jest": "^29.2.2",
49
+ "@types/jsonwebtoken": "^9.0.5",
50
+ "@types/node": "^18.11.9",
51
+ "@types/uuid": "^9",
52
+ "@typescript-eslint/eslint-plugin": "^5.43.0",
53
+ "@typescript-eslint/parser": "^5.43.0",
54
+ "eslint": "^8.29.0",
55
+ "eslint-config-airbnb-base": "^15.0.0",
56
+ "eslint-config-prettier": "^8.5.0",
57
+ "eslint-formatter-pretty": "^4.1.0",
58
+ "eslint-plugin-eslint-comments": "^3.2.0",
59
+ "eslint-plugin-import": "^2.26.0",
60
+ "eslint-plugin-jest": "^25.3.0",
61
+ "eslint-plugin-prettier": "^4.2.1",
62
+ "eslint-plugin-promise": "^6.1.1",
63
+ "eslint-utils": "^3.0.0",
64
+ "jest": "^29.3.1",
65
+ "mkdirp": "^1.0.4",
66
+ "prettier": "^2.7.1",
67
+ "regexpp": "^3.2.0",
68
+ "rimraf": "^3.0.2",
69
+ "ts-jest": "^29.0.3",
70
+ "typescript": "^4.8.4"
71
+ },
72
+ "prettier": "@monkvision/prettier-config",
73
+ "publishConfig": {
74
+ "access": "public"
75
+ },
76
+ "repository": {
77
+ "type": "git",
78
+ "url": "https://github.com/monkvision/monkjs.git"
79
+ },
80
+ "bugs": {
81
+ "url": "https://github.com/monkvision/monkjs/issues"
82
+ },
83
+ "homepage": "https://github.com/monkvision/monkjs",
84
+ "gitHead": "5114d93fcce7b2939cf846df3f584cc3621e682e"
85
+ }