skapi-js 1.0.38 → 1.0.40

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/error.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export default class SkapiError extends Error {
2
2
  constructor(error, options) {
3
3
  if (Array.isArray(error) && error.length <= 2) {
4
- super(error[1] || 'Something went wrong.');
4
+ super((error[1] || 'Something went wrong.').trim());
5
5
  this.name = options && options.name || "SKAPI";
6
6
  this.code = error[0] || "ERROR";
7
7
  if (options) {
@@ -27,7 +27,7 @@ export default class SkapiError extends Error {
27
27
  }
28
28
  }
29
29
  else if (error instanceof Error) {
30
- super(error.message || 'Something went wrong.');
30
+ super((error.message || 'Something went wrong.').trim());
31
31
  this.cause = error;
32
32
  this.name = error.name;
33
33
  if (error.hasOwnProperty('code')) {
@@ -49,6 +49,14 @@ export default class Skapi {
49
49
  provider: string;
50
50
  nonce?: string;
51
51
  }): Promise<string>;
52
+ clientSecretRequest(params: {
53
+ url: string;
54
+ clientSecretName: string;
55
+ method: 'get' | 'post' | 'GET' | 'POST';
56
+ headers?: Record<string, string>;
57
+ data?: Record<string, string>;
58
+ params?: Record<string, string>;
59
+ }): Promise<string>;
52
60
  consumeTicket(params: {
53
61
  ticket_id: string;
54
62
  }): Promise<string>;
package/js/main/skapi.js CHANGED
@@ -10,7 +10,7 @@ import { getRecords, postRecord, deleteRecords, getTables, getIndexes, getTags,
10
10
  import { connectRealtime, joinRealtime, postRealtime, closeRealtime, getRealtimeUsers, getRealtimeGroups } from '../methods/realtime';
11
11
  import { request, secureRequest, mock, getFormResponse, formHandler, getConnection } 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 } 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, clientSecretRequest } 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.38';
26
+ this.version = '1.0.40';
27
27
  this.session = null;
28
28
  this.connection = null;
29
29
  this.host = 'skapi';
@@ -202,6 +202,9 @@ export default class Skapi {
202
202
  jwtLogin(params) {
203
203
  return jwtLogin.bind(this)(params);
204
204
  }
205
+ clientSecretRequest(params) {
206
+ return clientSecretRequest.bind(this)(params);
207
+ }
205
208
  consumeTicket(params) {
206
209
  return consumeTicket.bind(this)(params);
207
210
  }
@@ -67,6 +67,7 @@ export async function request(url, data = null, options) {
67
67
  case 'get-newsletter-subscription':
68
68
  case 'request-username-change':
69
69
  case 'jwt-login':
70
+ case 'client-secret-request':
70
71
  return {
71
72
  public: admin.admin_public,
72
73
  private: admin.admin_private
@@ -32,6 +32,14 @@ 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;
35
43
  export declare function jwtLogin(params: {
36
44
  idToken: string;
37
45
  keyUrl: string;
@@ -341,6 +341,50 @@ 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 (!hasSecret) {
384
+ throw new SkapiError(`At least one parameter value should include "$CLIENT_SECRET" in ${params.method.toLowerCase() === 'post' ? '"data"' : '"params"'}.`, { code: 'INVALID_PARAMETER' });
385
+ }
386
+ return request.bind(this)("client-secret-request", params);
387
+ }
344
388
  export async function jwtLogin(params) {
345
389
  validator.Params(params, {
346
390
  idToken: 'string',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
4
4
  "description": "Skapi: Backend API Library for HTML frontend.",
5
5
  "main": "./dist/skapi.module.js",
6
6
  "types": "./js/Main.d.ts",