skapi-js 1.0.41 → 1.0.43

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.
@@ -103,7 +103,11 @@ export default class Skapi {
103
103
  url: string;
104
104
  data?: any;
105
105
  sync?: boolean;
106
- }>(params: Params | Params[]): Promise<any>;
106
+ }, Response = {
107
+ response: any;
108
+ statusCode: number;
109
+ url: string;
110
+ }>(params: Params | Params[]): Promise<Response | Response[]>;
107
111
  getFormResponse(): Promise<any>;
108
112
  getRecords(query: GetRecordQuery, fetchOptions?: FetchOptions): Promise<DatabaseResponse<RecordData>>;
109
113
  getTables(query: {
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.41';
26
+ this.version = '1.0.43';
27
27
  this.session = null;
28
28
  this.connection = null;
29
29
  this.host = 'skapi';
@@ -97,7 +97,7 @@ export default class Skapi {
97
97
  }
98
98
  this.service = service;
99
99
  this.owner = owner;
100
- let autoLogin = typeof options?.autoLogin === 'boolean' ? options.autoLogin : true;
100
+ let autoLogin = !!options.autoLogin;
101
101
  this.target_cdn = __etc?.target_cdn || this.target_cdn;
102
102
  this.hostDomain = __etc?.hostDomain || this.hostDomain;
103
103
  const cdn_domain = `https://${this.target_cdn}.cloudfront.net`;
@@ -14,7 +14,11 @@ export declare function secureRequest<RequestParams = {
14
14
  url: string;
15
15
  data?: any;
16
16
  sync?: boolean;
17
- }>(params: RequestParams | RequestParams[]): Promise<any>;
17
+ }, Response = {
18
+ response: any;
19
+ statusCode: number;
20
+ url: string;
21
+ }>(params: RequestParams | RequestParams[]): Promise<Response | Response[]>;
18
22
  export declare function mock(data: Form<any | {
19
23
  raise?: 'ERR_INVALID_REQUEST' | 'ERR_INVALID_PARAMETER' | 'SOMETHING_WENT_WRONG' | 'ERR_EXISTS' | 'ERR_NOT_EXISTS';
20
24
  }>, options?: {
@@ -396,7 +396,7 @@ async function _fetch(url, opt, progress) {
396
396
  xhr.responseType = opt.responseType;
397
397
  }
398
398
  xhr.onload = () => {
399
- if (xhr.status >= 200 && xhr.status < 300) {
399
+ if (xhr.status < 400) {
400
400
  if (opts.responseType == 'json' || opts.responseType == 'blob') {
401
401
  res(xhr.response);
402
402
  }
@@ -432,7 +432,10 @@ async function _fetch(url, opt, progress) {
432
432
  }
433
433
  else if (typeof result === 'object' && result?.message) {
434
434
  let code = (result?.code || (status ? status.toString() : null) || 'ERROR');
435
- rej(new SkapiError(result?.message, { code: code }));
435
+ rej(new SkapiError(result.message.trim(), { code: code }));
436
+ }
437
+ else {
438
+ rej(result);
436
439
  }
437
440
  }
438
441
  };
@@ -510,6 +513,7 @@ async function _get(url, params, option, progress, noParams) {
510
513
  }
511
514
  ;
512
515
  export async function secureRequest(params) {
516
+ await this.__connection;
513
517
  let paramsStruct = {
514
518
  url: (v) => {
515
519
  return validator.Url(v);
@@ -525,10 +529,11 @@ export async function secureRequest(params) {
525
529
  else {
526
530
  params = validator.Params(params, paramsStruct);
527
531
  }
528
- return await request.bind(this)('post-secure', params, { auth: true });
532
+ return request.bind(this)('post-secure', params, { auth: true });
529
533
  }
530
534
  ;
531
535
  export async function mock(data, options) {
536
+ await this.__connection;
532
537
  let { auth = true, method = 'POST', meta, bypassAwaitConnection = false, responseType, contentType } = options || {};
533
538
  let { response, onerror, formData, progress } = options || {};
534
539
  if (options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "Skapi: Backend API Library for HTML frontend.",
5
5
  "main": "./dist/skapi.module.js",
6
6
  "types": "./js/Main.d.ts",