ar-design 0.3.12 → 0.3.13

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.
@@ -2,11 +2,13 @@ declare class Api {
2
2
  private _host?;
3
3
  private _core?;
4
4
  private _init?;
5
+ private _token?;
5
6
  private _url;
6
7
  constructor(values: {
7
8
  host?: string;
8
9
  core?: string;
9
10
  init?: RequestInit;
11
+ token?: string;
10
12
  });
11
13
  Get(values: {
12
14
  input?: RequestInfo | undefined;
@@ -38,6 +40,7 @@ declare class Api {
38
40
  init?: RequestInit;
39
41
  }): Promise<Response>;
40
42
  private HeaderProperties;
43
+ private Cookies;
41
44
  /**
42
45
  * Burada bir fetch işlemi gerçekleştirilmekte fakat farklı olarak burayı `interceptor` olarak kullanmaktayız.
43
46
  * @param input
@@ -2,6 +2,7 @@ class Api {
2
2
  _host;
3
3
  _core;
4
4
  _init;
5
+ _token;
5
6
  _url;
6
7
  constructor(values) {
7
8
  this._host = values.host || (typeof window !== "undefined" ? window.location.origin : "");
@@ -91,8 +92,20 @@ class Api {
91
92
  return {
92
93
  Accept: "application/json",
93
94
  "Content-Type": "application/json",
95
+ ...(this._token && { Authorization: `Bearer ${this.Cookies(this._token)}` }),
94
96
  };
95
97
  };
98
+ Cookies = (name) => {
99
+ if (typeof window === "undefined")
100
+ return undefined;
101
+ const cookies = document.cookie.split("; ");
102
+ const cookieObject = [];
103
+ cookies.forEach((cookie) => {
104
+ const [key, value] = cookie.split("=");
105
+ cookieObject.push({ key: key, value: value });
106
+ });
107
+ return decodeURIComponent(cookieObject.find((x) => x.key === name)?.value ?? "");
108
+ };
96
109
  /**
97
110
  * Burada bir fetch işlemi gerçekleştirilmekte fakat farklı olarak burayı `interceptor` olarak kullanmaktayız.
98
111
  * @param input
@@ -13,6 +13,7 @@ declare class Service {
13
13
  core?: string;
14
14
  endPoint?: string;
15
15
  init?: RequestInit;
16
+ token?: string;
16
17
  });
17
18
  Get<TResponse>(values?: {
18
19
  input?: string;
@@ -3,7 +3,7 @@ class Service {
3
3
  _api;
4
4
  _endPoint;
5
5
  constructor(values) {
6
- this._api = new Api({ host: values.host, core: values.core, init: values.init });
6
+ this._api = new Api({ host: values.host, core: values.core, init: values.init, token: values.token });
7
7
  this._endPoint = values.endPoint;
8
8
  }
9
9
  async Get(values) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",