skapi-js 1.0.47 → 1.0.48

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
@@ -8,9 +8,9 @@ import SkapiError from './error';
8
8
  import validator from '../utils/validator';
9
9
  import { getRecords, postRecord, deleteRecords, getTables, getIndexes, getTags, uploadFiles, getFile, grantPrivateRecordAccess, removePrivateRecordAccess, listPrivateRecordAccess, requestPrivateRecordAccessKey, deleteFiles, normalizeRecord } from '../methods/database';
10
10
  import { connectRealtime, joinRealtime, postRealtime, closeRealtime, getRealtimeUsers, getRealtimeGroups } from '../methods/realtime';
11
- import { request, secureRequest, mock, getFormResponse, formHandler, getConnection } from '../methods/request';
11
+ import { request, secureRequest, mock, getFormResponse, formHandler, getConnection, clientSecretRequest } from '../methods/request';
12
12
  import { subscribe, unsubscribe, blockSubscriber, unblockSubscriber, getSubscriptions, subscribeNewsletter, getNewsletters, unsubscribeNewsletter, getNewsletterSubscription } from '../methods/subscription';
13
- import { checkAdmin, getProfile, logout, recoverAccount, resendSignupConfirmation, authentication, login, signup, disableAccount, resetPassword, verifyEmail, verifyPhoneNumber, forgotPassword, changePassword, updateProfile, getUsers, setUserPool, userPool, lastVerifiedEmail, requestUsernameChange, consumeTicket, releaseTicket, getTicketKey, jwtLogin, clientSecretRequest } from '../methods/user';
13
+ import { checkAdmin, getProfile, logout, recoverAccount, resendSignupConfirmation, authentication, login, signup, disableAccount, resetPassword, verifyEmail, verifyPhoneNumber, forgotPassword, changePassword, updateProfile, getUsers, setUserPool, userPool, lastVerifiedEmail, requestUsernameChange, consumeTicket, releaseTicket, getTicketKey, jwtLogin } from '../methods/user';
14
14
  export default class Skapi {
15
15
  get user() {
16
16
  if (this.__user && Object.keys(this.__user).length) {
@@ -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.47';
26
+ this.version = '1.0.48';
27
27
  this.session = null;
28
28
  this.connection = null;
29
29
  this.host = 'skapi';
@@ -10,6 +10,14 @@ export declare function request(url: string, data?: Form<any> | null, options?:
10
10
  responseType?: string;
11
11
  contentType?: string;
12
12
  }): Promise<any>;
13
+ export declare function clientSecretRequest(params: {
14
+ url: string;
15
+ clientSecretName: string;
16
+ method: 'get' | 'post' | 'GET' | 'POST';
17
+ headers?: Record<string, string>;
18
+ data?: Record<string, string>;
19
+ params?: Record<string, string>;
20
+ }): any;
13
21
  export declare function secureRequest<RequestParams = {
14
22
  url: string;
15
23
  data?: any;
@@ -513,6 +513,50 @@ async function _get(url, params, option, progress, noParams) {
513
513
  return _fetch.bind(this)(url, opt, progress);
514
514
  }
515
515
  ;
516
+ export function clientSecretRequest(params) {
517
+ let hasSecret = false;
518
+ let checkClientSecretPlaceholder = (v) => {
519
+ for (let k in v) {
520
+ if (typeof v[k] === 'string' && v[k].includes('$CLIENT_SECRET')) {
521
+ hasSecret = true;
522
+ break;
523
+ }
524
+ }
525
+ };
526
+ validator.Params(params, {
527
+ url: 'string',
528
+ clientSecretName: 'string',
529
+ method: ['get', 'post', 'GET', 'POST'],
530
+ headers: (v) => {
531
+ if (v && typeof v !== 'object') {
532
+ throw new SkapiError('"headers" should be type: <object>.', { code: 'INVALID_PARAMETER' });
533
+ }
534
+ checkClientSecretPlaceholder(v);
535
+ return v;
536
+ },
537
+ data: (v) => {
538
+ if (v && typeof v !== 'object') {
539
+ throw new SkapiError('"data" should be type: <object>.', { code: 'INVALID_PARAMETER' });
540
+ }
541
+ checkClientSecretPlaceholder(v);
542
+ return v;
543
+ },
544
+ params: (v) => {
545
+ if (v && typeof v !== 'object') {
546
+ throw new SkapiError('"params" should be type: <object>.', { code: 'INVALID_PARAMETER' });
547
+ }
548
+ checkClientSecretPlaceholder(v);
549
+ return v;
550
+ }
551
+ }, ['clientSecretName', 'method', 'url']);
552
+ if (!params.data && !params.params) {
553
+ throw new SkapiError(`${params.method.toLowerCase() === 'post' ? '"data"' : '"params"'} is required.`, { code: 'INVALID_PARAMETER' });
554
+ }
555
+ if (!hasSecret) {
556
+ throw new SkapiError(`At least one parameter value should include "$CLIENT_SECRET" in ${params.method.toLowerCase() === 'post' ? '"data"' : '"params"'} or "headers".`, { code: 'INVALID_PARAMETER' });
557
+ }
558
+ return request.bind(this)("client-secret-request", params);
559
+ }
516
560
  export async function secureRequest(params) {
517
561
  await this.__connection;
518
562
  let paramsStruct = {
@@ -32,14 +32,6 @@ export declare function checkAdmin(): Promise<boolean>;
32
32
  export declare function logout(): Promise<'SUCCESS: The user has been logged out.'>;
33
33
  export declare function resendSignupConfirmation(redirect: string): Promise<'SUCCESS: Signup confirmation E-Mail has been sent.'>;
34
34
  export declare function recoverAccount(redirect?: boolean | string): Promise<"SUCCESS: Recovery e-mail has been sent.">;
35
- export declare function clientSecretRequest(params: {
36
- url: string;
37
- clientSecretName: string;
38
- method: 'get' | 'post' | 'GET' | 'POST';
39
- headers?: Record<string, string>;
40
- data?: Record<string, string>;
41
- params?: Record<string, string>;
42
- }): any;
43
35
  export declare function jwtLogin(params: {
44
36
  idToken: string;
45
37
  keyUrl: string;
@@ -341,58 +341,6 @@ export async function recoverAccount(redirect = false) {
341
341
  this.__disabledAccount = null;
342
342
  return 'SUCCESS: Recovery e-mail has been sent.';
343
343
  }
344
- export function clientSecretRequest(params) {
345
- validator.Params(params, {
346
- url: 'string',
347
- clientSecretName: 'string',
348
- method: ['get', 'post', 'GET', 'POST'],
349
- headers: (v) => v,
350
- data: (v) => {
351
- if (v && typeof v !== 'object') {
352
- throw new SkapiError('"data" should be type: <object>.', { code: 'INVALID_PARAMETER' });
353
- }
354
- return v;
355
- },
356
- params: (v) => {
357
- if (v && typeof v !== 'object') {
358
- throw new SkapiError('"params" should be type: <object>.', { code: 'INVALID_PARAMETER' });
359
- }
360
- return v;
361
- }
362
- }, ['clientSecretName', 'method', 'url']);
363
- let hasSecret = false;
364
- if (!params.data && !params.params) {
365
- throw new SkapiError(`${params.method.toLowerCase() === 'post' ? '"data"' : '"params"'} is required.`, { code: 'INVALID_PARAMETER' });
366
- }
367
- if (params.data) {
368
- for (let k in params.data) {
369
- if (typeof params.data[k] === 'string' && params.data[k].includes('$CLIENT_SECRET')) {
370
- hasSecret = true;
371
- break;
372
- }
373
- }
374
- }
375
- if (params.params) {
376
- for (let k in params.params) {
377
- if (typeof params.params[k] === 'string' && params.params[k].includes('$CLIENT_SECRET')) {
378
- hasSecret = true;
379
- break;
380
- }
381
- }
382
- }
383
- if (params.headers) {
384
- for (let k in params.headers) {
385
- if (typeof params.headers[k] === 'string' && params.headers[k].includes('$CLIENT_SECRET')) {
386
- hasSecret = true;
387
- break;
388
- }
389
- }
390
- }
391
- if (!hasSecret) {
392
- throw new SkapiError(`At least one parameter value should include "$CLIENT_SECRET" in ${params.method.toLowerCase() === 'post' ? '"data"' : '"params"'} or "headers".`, { code: 'INVALID_PARAMETER' });
393
- }
394
- return request.bind(this)("client-secret-request", params);
395
- }
396
344
  export async function jwtLogin(params) {
397
345
  validator.Params(params, {
398
346
  idToken: 'string',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "Skapi: Backend API Library for HTML frontend.",
5
5
  "main": "./dist/skapi.module.js",
6
6
  "types": "./js/Main.d.ts",