@star-insure/sdk 4.3.2 → 4.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.esm.js CHANGED
@@ -1214,6 +1214,98 @@ function calcPurchaseOptionPricing(_ref3) {
1214
1214
  };
1215
1215
  }
1216
1216
 
1217
+ /**
1218
+ * A wrapper around Inertia's usePage function that gives better type-safety
1219
+ */
1220
+
1221
+ function usePage() {
1222
+ // @ts-ignore
1223
+ return usePage$1();
1224
+ }
1225
+
1226
+ /**
1227
+ * A helper to return a fetch function including default headers and authorization.
1228
+ */
1229
+
1230
+ function useFetch(_ref) {
1231
+ var baseUrl = _ref.url,
1232
+ _ref$method = _ref.method,
1233
+ method = _ref$method === void 0 ? 'GET' : _ref$method,
1234
+ _ref$params = _ref.params,
1235
+ params = _ref$params === void 0 ? {} : _ref$params,
1236
+ _ref$headers = _ref.headers,
1237
+ headers = _ref$headers === void 0 ? {} : _ref$headers;
1238
+ var access_token = usePage().props.access_token;
1239
+ var url = baseUrl;
1240
+
1241
+ if (method === 'GET') {
1242
+ var queryParams = new URLSearchParams(params);
1243
+ url = url + "?" + queryParams.toString();
1244
+ }
1245
+
1246
+ return React__default.useMemo(function () {
1247
+ return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1248
+ var res, ok, body, parsedBody, message, data;
1249
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1250
+ while (1) {
1251
+ switch (_context.prev = _context.next) {
1252
+ case 0:
1253
+ _context.next = 2;
1254
+ return fetch(url, {
1255
+ method: method,
1256
+ headers: _extends({
1257
+ 'Content-Type': 'application/json',
1258
+ Accept: 'application/json',
1259
+ Authorization: access_token ? "Bearer " + access_token : ''
1260
+ }, headers),
1261
+ body: Object.keys(params).length > 0 && method !== 'GET' ? JSON.stringify(params) : null
1262
+ });
1263
+
1264
+ case 2:
1265
+ res = _context.sent;
1266
+ ok = res.ok;
1267
+ _context.next = 6;
1268
+ return res.text();
1269
+
1270
+ case 6:
1271
+ body = _context.sent;
1272
+ parsedBody = body;
1273
+
1274
+ try {
1275
+ parsedBody = JSON.parse(body);
1276
+ } catch (error) {// Response wasn't JSON, just use the text version.
1277
+ }
1278
+
1279
+ message = typeof parsedBody === 'string' ? parsedBody : undefined;
1280
+
1281
+ if (ok) {
1282
+ _context.next = 12;
1283
+ break;
1284
+ }
1285
+
1286
+ return _context.abrupt("return", {
1287
+ ok: ok,
1288
+ message: message
1289
+ });
1290
+
1291
+ case 12:
1292
+ data = typeof parsedBody !== 'string' ? parsedBody : undefined;
1293
+ return _context.abrupt("return", {
1294
+ ok: ok,
1295
+ data: data,
1296
+ message: message
1297
+ });
1298
+
1299
+ case 14:
1300
+ case "end":
1301
+ return _context.stop();
1302
+ }
1303
+ }
1304
+ }, _callee);
1305
+ }));
1306
+ }, [access_token, url, params, headers, method]);
1307
+ }
1308
+
1217
1309
  function Button(_ref) {
1218
1310
  var className = _ref.className,
1219
1311
  href = _ref.href,
@@ -2325,15 +2417,6 @@ function ErrorList(_ref) {
2325
2417
  }))));
2326
2418
  }
2327
2419
 
2328
- /**
2329
- * A wrapper around Inertia's usePage function that gives better type-safety
2330
- */
2331
-
2332
- function usePage() {
2333
- // @ts-ignore
2334
- return usePage$1();
2335
- }
2336
-
2337
2420
  function BackButton(_ref) {
2338
2421
  var back = _ref.back,
2339
2422
  className = _ref.className;
@@ -3173,5 +3256,5 @@ PageHeader.Action = function (_ref2) {
3173
3256
  return React__default.createElement("div", null, children);
3174
3257
  };
3175
3258
 
3176
- export { Button, Card, DateOfBirthField, ErrorList, FormTester, Modal, MoneyField, PageHeader, Pagination, QuoteRequestFormContext, QuoteRequestFormProvider, QuoteRequestOptionsProvider, RegistrationSearchField, SimplePagination, Table, TableActions, TableBody, TableCell, TableHead, TableHeader, TableRow, ToastItem, ToastProvider, Toasts, addGst, autocomplete, calcMonthlyEnhancementPrice, calcPurchaseOptionPricing, calculateAge, fixRoundingError, formatDate, formatDateForTable, formatDateNice, formatDateTime, formatMoney, formatNumber, getAddressData, getGst, gstCalc, initialData, round, sanitiseQuoteRequestFormData, sanitiseVehicleType, subtractGst, useAuth, useClickOutside, useInertiaOptions, useLocalStorage, useQuoteRequestForm, useQuoteRequestOptions, useToast };
3259
+ export { Button, Card, DateOfBirthField, ErrorList, FormTester, Modal, MoneyField, PageHeader, Pagination, QuoteRequestFormContext, QuoteRequestFormProvider, QuoteRequestOptionsProvider, RegistrationSearchField, SimplePagination, Table, TableActions, TableBody, TableCell, TableHead, TableHeader, TableRow, ToastItem, ToastProvider, Toasts, addGst, autocomplete, calcMonthlyEnhancementPrice, calcPurchaseOptionPricing, calculateAge, fixRoundingError, formatDate, formatDateForTable, formatDateNice, formatDateTime, formatMoney, formatNumber, getAddressData, getGst, gstCalc, initialData, round, sanitiseQuoteRequestFormData, sanitiseVehicleType, subtractGst, useAuth, useClickOutside, useFetch, useInertiaOptions, useLocalStorage, useQuoteRequestForm, useQuoteRequestOptions, useToast };
3177
3260
  //# sourceMappingURL=sdk.esm.js.map