@mspkapps/auth-client 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mspkapps/auth-client",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Lightweight client for Your Auth Service",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/AuthClient.js CHANGED
@@ -6,6 +6,7 @@ export class AuthClient {
6
6
  apiKey,
7
7
  apiSecret,
8
8
  baseUrl = 'https://cpanel.backend.mspkapps.in/api/v1',
9
+ keyInPath = true,
9
10
  storage,
10
11
  fetch: fetchFn
11
12
  } = {}) {
@@ -14,6 +15,7 @@ export class AuthClient {
14
15
  this.apiKey = apiKey;
15
16
  this.apiSecret = apiSecret;
16
17
  this.baseUrl = baseUrl.replace(/\/$/, '');
18
+ this.keyInPath = !!keyInPath;
17
19
  this.fetch = fetchFn || (typeof fetch !== 'undefined' ? fetch : null);
18
20
  if (!this.fetch) throw new Error('No fetch available. Pass { fetch } or run on Node 18+/browsers.');
19
21
 
@@ -39,12 +41,15 @@ export class AuthClient {
39
41
  // ---------- internal builders ----------
40
42
  _buildUrl(path) {
41
43
  const p = path.startsWith('/') ? path.slice(1) : path;
42
- return `${this.baseUrl}/${encodeURIComponent(this.apiKey)}/${p}`;
44
+ return this.keyInPath
45
+ ? `${this.baseUrl}/${encodeURIComponent(this.apiKey)}/${p}`
46
+ : `${this.baseUrl}/${p}`;
43
47
  }
44
48
 
45
49
  _headers(extra = {}) {
46
50
  return {
47
51
  'Content-Type': 'application/json',
52
+ 'X-API-Key': this.apiKey,
48
53
  'X-API-Secret': this.apiSecret,
49
54
  ...(this.token ? { Authorization: `UserToken ${this.token}` } : {}),
50
55
  ...extra