skapi-js 1.0.24 → 1.0.27

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.24';
26
+ this.version = '1.0.27';
27
27
  this.session = null;
28
28
  this.connection = null;
29
29
  this.host = 'skapi';
@@ -796,19 +796,14 @@ export async function postRecord(form, config) {
796
796
  to_bin = formMeta.to_bin;
797
797
  }
798
798
  if (formMeta.files.length) {
799
- let formData = new FormData();
800
- for (let f of formMeta.files) {
801
- formData.append(f.name, f.file, f.file.name);
799
+ if (!to_bin) {
800
+ to_bin = [];
802
801
  }
803
- options.meta = config;
804
- if (Object.keys(formMeta.meta).length) {
805
- options.meta.data = formMeta.meta;
802
+ for (let f of formMeta.files) {
803
+ to_bin.push(f);
806
804
  }
807
- postData = formData;
808
- }
809
- else {
810
- postData = Object.assign({ data: formMeta.meta }, config);
811
805
  }
806
+ postData = Object.assign({ data: formMeta.meta }, config);
812
807
  }
813
808
  else {
814
809
  postData = Object.assign({ data: form }, config);
@@ -12,19 +12,19 @@ export function consumeTicket(params) {
12
12
  if (!params.ticket_id) {
13
13
  throw new SkapiError('Ticket ID is required.', { code: 'INVALID_PARAMETER' });
14
14
  }
15
- return request.bind(this)('ticket', { ticket_id: params, exec: 'consume' }, { auth: true });
15
+ return request.bind(this)('ticket', { ticket_id: params.ticket_id, exec: 'consume' }, { auth: true });
16
16
  }
17
17
  export function releaseTicket(params) {
18
18
  if (!params.ticket_id) {
19
19
  throw new SkapiError('Ticket ID is required.', { code: 'INVALID_PARAMETER' });
20
20
  }
21
- return request.bind(this)('ticket', { ticket_id: params, exec: 'release' }, { auth: true });
21
+ return request.bind(this)('ticket', { ticket_id: params.ticket_id, exec: 'release' }, { auth: true });
22
22
  }
23
23
  export function getTicketKey(params) {
24
24
  if (!params.ticket_id) {
25
25
  throw new SkapiError('Ticket ID is required.', { code: 'INVALID_PARAMETER' });
26
26
  }
27
- return request.bind(this)('ticket', { ticket_id: params, exec: 'request' }, { auth: true });
27
+ return request.bind(this)('ticket', { ticket_id: params.ticket_id, exec: 'request' }, { auth: true });
28
28
  }
29
29
  export function authentication() {
30
30
  if (!userPool)
@@ -160,14 +160,26 @@ export function authentication() {
160
160
  rej(new SkapiError('Current session does not exist.', { code: 'INVALID_REQUEST' }));
161
161
  return;
162
162
  }
163
+ let respond = (session) => {
164
+ let idToken = session.getIdToken().payload;
165
+ if (idToken['custom:service'] !== this.service) {
166
+ cognitoUser.signOut();
167
+ this.session = null;
168
+ rej(new SkapiError('Invalid session.', { code: 'INVALID_REQUEST' }));
169
+ return;
170
+ }
171
+ this.session = session;
172
+ normalizeUserAttributes(idToken);
173
+ res(session);
174
+ };
163
175
  if (refreshToken || !session.isValid()) {
164
176
  cognitoUser.refreshSession(session.getRefreshToken(), (refreshErr, refreshedSession) => {
165
177
  if (refreshErr) {
166
178
  rej(refreshErr);
167
179
  }
168
180
  else {
169
- if (!refreshedSession.isValid()) {
170
- session = refreshedSession;
181
+ if (refreshedSession.isValid()) {
182
+ return respond(refreshedSession);
171
183
  }
172
184
  else {
173
185
  rej(new SkapiError('Invalid session.', { code: 'INVALID_REQUEST' }));
@@ -176,16 +188,9 @@ export function authentication() {
176
188
  }
177
189
  });
178
190
  }
179
- let idToken = session.getIdToken().payload;
180
- if (idToken['custom:service'] !== this.service) {
181
- cognitoUser.signOut();
182
- this.session = null;
183
- rej(new SkapiError('Invalid session.', { code: 'INVALID_REQUEST' }));
184
- return;
191
+ else {
192
+ return respond(session);
185
193
  }
186
- this.session = session;
187
- normalizeUserAttributes(idToken);
188
- res(session);
189
194
  });
190
195
  });
191
196
  };
@@ -701,6 +706,7 @@ export async function getUsers(params, fetchOptions) {
701
706
  'address': 'string',
702
707
  'gender': 'string',
703
708
  'birthdate': (v) => validator.Birthdate(v),
709
+ 'subscribers': 'number',
704
710
  'timestamp': 'number',
705
711
  'access_group': 'number',
706
712
  'approved': (v) => {
@@ -758,9 +764,6 @@ export async function getUsers(params, fetchOptions) {
758
764
  if (params.searchFor === 'user_id' && params.condition !== '=') {
759
765
  throw new SkapiError(`Conditions are not allowed on "user_id"`, { code: 'INVALID_PARAMETER' });
760
766
  }
761
- if (params.searchFor === 'access_group') {
762
- params.searchFor = 'group';
763
- }
764
767
  if (typeof params?.value === 'string' && !params?.value) {
765
768
  throw new SkapiError('Value should not be an empty string.', { code: 'INVALID_PARAMETER' });
766
769
  }
package/js/utils/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import SkapiError from "../main/error";
1
2
  class MD5 {
2
3
  static hash(str) {
3
4
  if (typeof str !== 'string') {
@@ -279,6 +280,12 @@ function extractFormMeta(form) {
279
280
  }
280
281
  }
281
282
  }
283
+ function sizeof(object) {
284
+ return new Blob([JSON.stringify(object)]).size;
285
+ }
286
+ if (sizeof(meta) > 2 * 1024 * 1024) {
287
+ throw new SkapiError('JSON Data should not exceed 2MB', { code: 'INVALID_REQUEST' });
288
+ }
282
289
  return { meta, files, to_bin };
283
290
  }
284
291
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.24",
3
+ "version": "1.0.27",
4
4
  "description": "Skapi: JS Backend API with no deployment required.",
5
5
  "main": "./dist/skapi.module.js",
6
6
  "types": "./js/Main.d.ts",