skapi-js 1.0.44 → 1.0.45-beta.1

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/js/main/skapi.js CHANGED
@@ -23,7 +23,7 @@ export default class Skapi {
23
23
  set user(value) {
24
24
  }
25
25
  constructor(service, owner, options, __etc) {
26
- this.version = '1.0.44';
26
+ this.version = '1.0.45';
27
27
  this.session = null;
28
28
  this.connection = null;
29
29
  this.host = 'skapi';
@@ -718,10 +718,13 @@ export async function postRecord(form, config) {
718
718
  arr.push(i.url);
719
719
  }
720
720
  else {
721
- throw new SkapiError(`"remove_bin" should be type: <string | BinaryFile[]>`, { code: 'INVALID_PARAMETER' });
721
+ throw new SkapiError(`"remove_bin" should be type: <string[] | BinaryFile[]>`, { code: 'INVALID_PARAMETER' });
722
722
  }
723
723
  }
724
724
  }
725
+ else {
726
+ throw new SkapiError(`"remove_bin" should be type: <string[] | BinaryFile[]>`, { code: 'INVALID_PARAMETER' });
727
+ }
725
728
  return arr;
726
729
  }
727
730
  }, [], ['response', 'onerror', 'progress'], null);
@@ -569,17 +569,50 @@ export function formHandler(options) {
569
569
  let routeWithDataKey = true;
570
570
  let formEl = null;
571
571
  let actionDestination = '';
572
+ let fileBase64String = {};
572
573
  if (form instanceof SubmitEvent) {
573
574
  form.preventDefault();
574
575
  let currentUrl = window.location.href;
575
576
  formEl = form.target;
576
577
  let href = new URL(formEl.action);
577
578
  actionDestination = href.href;
579
+ let placeholders = actionDestination ? actionDestination.match(/(?<=\{).*?(?=\})/g) : '';
580
+ if (placeholders) {
581
+ for (let p of placeholders) {
582
+ if (!p) {
583
+ continue;
584
+ }
585
+ let inputElement = formEl.querySelector(`[name="${p}"]`);
586
+ if (!inputElement) {
587
+ continue;
588
+ }
589
+ if (inputElement.type === 'file') {
590
+ for (let i = 0; i <= inputElement.files.length - 1; i++) {
591
+ if (!inputElement.files[i])
592
+ continue;
593
+ if (!fileBase64String[p]) {
594
+ fileBase64String[p] = [];
595
+ }
596
+ fileBase64String[p].push(new Promise((res, rej) => {
597
+ let reader = new FileReader();
598
+ reader.onload = function () {
599
+ res(reader.result);
600
+ };
601
+ reader.readAsDataURL(inputElement.files[i]);
602
+ }));
603
+ }
604
+ }
605
+ else {
606
+ var value = inputElement.value;
607
+ actionDestination = actionDestination.replace(`{${p}}`, value);
608
+ }
609
+ }
610
+ }
578
611
  if (!formEl.action || href.href === currentUrl) {
579
612
  routeWithDataKey = false;
580
613
  }
581
614
  }
582
- const handleResponse = (response) => {
615
+ const handleResponse = async (response) => {
583
616
  if (option?.response) {
584
617
  if (typeof option.response === 'function') {
585
618
  return option.response(response);
@@ -588,6 +621,13 @@ export function formHandler(options) {
588
621
  throw new SkapiError('Callback "response" should be type: function.', { code: 'INVALID_PARAMETER' });
589
622
  }
590
623
  }
624
+ if (actionDestination) {
625
+ for (let k in fileBase64String) {
626
+ if (fileBase64String[k].length) {
627
+ actionDestination = actionDestination.replace(`{${k}}`, (await Promise.all(fileBase64String[k])).join(','));
628
+ }
629
+ }
630
+ }
591
631
  if (formEl) {
592
632
  if (routeWithDataKey) {
593
633
  window.sessionStorage.setItem(`${this.service}:${MD5.hash(actionDestination)}`, JSON.stringify(response));
@@ -632,7 +672,8 @@ export function formHandler(options) {
632
672
  return (async () => {
633
673
  try {
634
674
  let resolved = await response;
635
- return handleResponse(resolved);
675
+ let data = await handleResponse(resolved);
676
+ return data;
636
677
  }
637
678
  catch (err) {
638
679
  let is_err = handleError(err);
@@ -441,7 +441,14 @@ export async function signup(form, option) {
441
441
  birthdate_public: ['boolean', () => false],
442
442
  phone_number_public: ['boolean', () => false],
443
443
  access_group: 'number',
444
- misc: 'string'
444
+ misc: 'string',
445
+ picture: (v) => validator.Url(v),
446
+ profile: (v) => validator.Url(v),
447
+ family_name: 'string',
448
+ given_name: 'string',
449
+ middle_name: 'string',
450
+ nickname: 'string',
451
+ website: (v) => validator.Url(v),
445
452
  }, is_admin ? ['email'] : ['email', 'password']);
446
453
  let admin_creating_account = is_admin && params.service && this.service !== params.service;
447
454
  if (admin_creating_account) {
@@ -681,7 +688,14 @@ export async function updateProfile(form) {
681
688
  address_public: 'boolean',
682
689
  gender_public: 'boolean',
683
690
  birthdate_public: 'boolean',
684
- misc: 'string'
691
+ misc: 'string',
692
+ picture: (v) => validator.Url(v),
693
+ profile: (v) => validator.Url(v),
694
+ family_name: 'string',
695
+ given_name: 'string',
696
+ middle_name: 'string',
697
+ nickname: 'string',
698
+ website: (v) => validator.Url(v),
685
699
  });
686
700
  if (params && typeof params === 'object' && !Object.keys(params).length) {
687
701
  return this.user;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.44",
3
+ "version": "1.0.45-beta.1",
4
4
  "description": "Skapi: Backend API Library for HTML frontend.",
5
5
  "main": "./dist/skapi.module.js",
6
6
  "types": "./js/Main.d.ts",