skapi-js 1.0.62-beta.12 → 1.0.62-beta.13

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.
@@ -468,7 +468,7 @@ export async function getRecords(query, fetchOptions) {
468
468
  private_key: 'string'
469
469
  };
470
470
  let isAdmin = await this.checkAdmin();
471
- validator.Params(query || {}, struct, ref_user || isAdmin ? [] : ['table']);
471
+ query = validator.Params(query || {}, struct, ref_user || isAdmin ? [] : ['table']);
472
472
  }
473
473
  let result = await request.bind(this)('get-records', query, {
474
474
  fetchOptions,
@@ -492,7 +492,6 @@ export async function postRecord(form, config) {
492
492
  if (!this.user) {
493
493
  throw new SkapiError('Login is required.', { code: 'INVALID_REQUEST' });
494
494
  }
495
- let fetchOptions = {};
496
495
  if (typeof config.table === 'string') {
497
496
  config.table = {
498
497
  name: config.table
@@ -506,7 +505,7 @@ export async function postRecord(form, config) {
506
505
  record_id: config.reference
507
506
  };
508
507
  }
509
- validator.Params(config || {}, {
508
+ let _config = validator.Params(config || {}, {
510
509
  record_id: ['string', () => {
511
510
  if (!config.table || !config.table.name) {
512
511
  throw new SkapiError('"table.name" is required.', { code: 'INVALID_PARAMETER' });
@@ -525,9 +524,8 @@ export async function postRecord(form, config) {
525
524
  if (!config.record_id && !config.table.access_group || config.table.access_group === 0 || config.table.access_group === 'public') {
526
525
  throw new SkapiError('Public records cannot require subscription.', { code: 'INVALID_REQUEST' });
527
526
  }
528
- delete config.table.subscription;
529
- Object.assign(config.table, { subscription_group: 1 });
530
527
  }
528
+ return v;
531
529
  },
532
530
  access_group: v => {
533
531
  if (typeof v === 'string') {
@@ -648,7 +646,11 @@ export async function postRecord(form, config) {
648
646
  progress: 'function',
649
647
  });
650
648
  let progress = config.progress || null;
651
- delete config.progress;
649
+ if (config.table.hasOwnProperty('subscription')) {
650
+ _config.table.subscription_group = config.table.subscription ? 1 : null;
651
+ delete _config.table.subscription;
652
+ }
653
+ delete _config.progress;
652
654
  let options = { auth: true };
653
655
  let postData = null;
654
656
  let to_bin = null;
@@ -657,11 +659,12 @@ export async function postRecord(form, config) {
657
659
  if (extractedForm.files.length) {
658
660
  to_bin = extractedForm.files;
659
661
  }
660
- postData = Object.assign({ data: extractedForm.data }, config);
662
+ postData = Object.assign({ data: extractedForm.data }, _config);
661
663
  }
662
664
  else {
663
- postData = Object.assign({ data: form }, config);
665
+ postData = Object.assign({ data: form }, _config);
664
666
  }
667
+ let fetchOptions = {};
665
668
  if (typeof progress === 'function') {
666
669
  fetchOptions.progress = progress;
667
670
  }
@@ -678,8 +681,8 @@ export async function postRecord(form, config) {
678
681
  record_id: rec.rec,
679
682
  progress
680
683
  };
681
- if (config.hasOwnProperty('service')) {
682
- uploadFileParams['service'] = config.service;
684
+ if (_config.hasOwnProperty('service')) {
685
+ uploadFileParams['service'] = _config.service;
683
686
  }
684
687
  let { bin_endpoints } = await uploadFiles.bind(this)(bin_formData, uploadFileParams);
685
688
  if (!rec.bin) {
@@ -820,9 +823,6 @@ export async function deleteRecords(params) {
820
823
  }
821
824
  else {
822
825
  if (!params?.table) {
823
- if (isAdmin) {
824
- return null;
825
- }
826
826
  throw new SkapiError('Either "table" or "record_id" is required.', { code: 'INVALID_PARAMETER' });
827
827
  }
828
828
  let struct = {
@@ -844,38 +844,31 @@ export async function deleteRecords(params) {
844
844
  },
845
845
  name: 'string',
846
846
  subscription: (v) => {
847
- if (isAdmin && typeof params?.table?.subscription === 'string') {
848
- return validator.UserId(v, 'User ID in "table.subscription"');
849
- }
850
847
  if (typeof v === 'boolean') {
851
848
  if (v) {
852
- return this.__user.user_id;
853
- }
854
- else {
855
- return null;
849
+ v = this.__user.user_id;
850
+ return v;
856
851
  }
857
852
  }
858
- throw new SkapiError('"table.subscription" is an invalid parameter key.', { code: 'INVALID_PARAMETER' });
859
- },
860
- };
861
- let table_p = validator.Params(params.table || {}, struct, isAdmin ? [] : ['name']);
862
- if (table_p.hasOwnProperty('subscription')) {
863
- if (table_p.subscription === null) {
864
- delete table_p.subscription;
865
- }
866
- else {
867
- if (!table_p.hasOwnProperty('access_group')) {
853
+ if (!params.table.hasOwnProperty('access_group')) {
868
854
  throw new SkapiError('"table.access_group" is required for subscription records.', { code: 'INVALID_PARAMETER' });
869
855
  }
870
- else if (table_p.access_group === 0) {
856
+ else if (params.table.access_group === 0) {
871
857
  throw new SkapiError('Public tables does not hold subscription records.', { code: 'INVALID_REQUEST' });
872
858
  }
873
- table_p.subscription_group = 1;
859
+ if (isAdmin && typeof v === 'string') {
860
+ return validator.UserId(v, 'User ID in "table.subscription"');
861
+ }
862
+ throw new SkapiError('"table.subscription" is an invalid parameter key.', { code: 'INVALID_PARAMETER' });
874
863
  }
864
+ };
865
+ let table = validator.Params(params.table || {}, struct, isAdmin ? [] : ['name']);
866
+ if (table.subscription) {
867
+ table.subscription_group = 1;
875
868
  }
876
- params.table = table_p;
869
+ let toDelete = Object.assign({}, params, { table });
870
+ return await request.bind(this)('del-records', toDelete, { auth: true });
877
871
  }
878
- return await request.bind(this)('del-records', params, { auth: true });
879
872
  }
880
873
  export function grantPrivateRecordAccess(params) {
881
874
  if (!params.record_id) {
@@ -49,7 +49,6 @@ export async function consumeTicket(params) {
49
49
  throw new SkapiError('Ticket ID is required.', { code: 'INVALID_PARAMETER' });
50
50
  }
51
51
  let ticket_id = params.ticket_id;
52
- delete params.ticket_id;
53
52
  await this.__connection;
54
53
  let resp = await request.bind(this)(`https://${this.service.slice(0, 4)}.skapi.dev/auth/consume/${this.service}/${this.owner}/${ticket_id}`, params, { auth: true });
55
54
  return map_ticket_obj(resp);
@@ -149,11 +149,20 @@ function specialChars(string, p = 'parameter', allowPeriods = false, allowWhiteS
149
149
  return string;
150
150
  }
151
151
  function Params(params, struct, required = []) {
152
- struct.service = 'string';
153
- struct.owner = 'string';
154
152
  let p = extractFormData(params)?.data || params;
153
+ let toCheck = {};
154
+ for (let s in struct) {
155
+ if (p.hasOwnProperty(s)) {
156
+ try {
157
+ toCheck[s] = JSON.parse(JSON.stringify(p[s]));
158
+ }
159
+ catch (err) {
160
+ toCheck[s] = p[s];
161
+ }
162
+ }
163
+ }
155
164
  try {
156
- return checkParams(p, struct, required);
165
+ return checkParams(toCheck, struct, required);
157
166
  }
158
167
  catch (err) {
159
168
  throw new SkapiError(err, { code: 'INVALID_PARAMETER' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.62-beta.12",
3
+ "version": "1.0.62-beta.13",
4
4
  "description": "Skapi: Backend API Library for HTML frontend.",
5
5
  "main": "js/Main.js",
6
6
  "types": "js/Main.d.ts",