@vtecx/vtecxnext 2.2.2 → 2.2.3

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.
@@ -35,6 +35,8 @@ export declare class VtecxNext {
35
35
  private bufferData;
36
36
  /** Access Token (for batch) */
37
37
  private accessToken;
38
+ /** login cookies */
39
+ private loginCookies;
38
40
  /**
39
41
  * constructor
40
42
  * @param req Request
@@ -904,6 +906,16 @@ export declare class VtecxNext {
904
906
  * @param response vte.cxからのレスポンス
905
907
  */
906
908
  private setCookie;
909
+ /**
910
+ * ログイン時にレスポンスされたvte.cxからのset-cookieを保持する。
911
+ * @param response vte.cxからのレスポンス
912
+ */
913
+ private setLoginCookie;
914
+ /**
915
+ * ログイン後のCookie編集
916
+ * @returns cookie
917
+ */
918
+ private editRequestCookie;
907
919
  /**
908
920
  * vte.cxからのレスポンスヘッダを、ブラウザへレスポンスする。
909
921
  * コンテンツの戻し時に使用。
package/dist/vtecxnext.js CHANGED
@@ -56,6 +56,8 @@ class VtecxNext {
56
56
  bufferData = null;
57
57
  /** Access Token (for batch) */
58
58
  accessToken;
59
+ /** login cookies */
60
+ loginCookies = {};
59
61
  /**
60
62
  * constructor
61
63
  * @param req Request
@@ -383,6 +385,8 @@ class VtecxNext {
383
385
  }
384
386
  // vte.cxからのset-cookieを転記
385
387
  this.setCookie(response);
388
+ // 引き続きAPIで処理を行う場合のため、set-cookie情報を保持しておく
389
+ this.setLoginCookie(response);
386
390
  const data = await response.json();
387
391
  return { status: response.status, message: data.feed.title };
388
392
  };
@@ -3589,7 +3593,8 @@ class VtecxNext {
3589
3593
  */
3590
3594
  requestVtecx = async (method, url, body, additionalHeaders, targetService, mode) => {
3591
3595
  // cookieの値をvte.cxへのリクエストヘッダに設定
3592
- const cookie = this.req ? this.req.headers.get('cookie') : undefined;
3596
+ const cookie = this.editRequestCookie();
3597
+ //console.log(`[requestVtecx] cookie = ${cookie}`)
3593
3598
  const headers = cookie ? { 'Cookie': cookie } : {};
3594
3599
  if (this.accessToken) {
3595
3600
  headers.Authorization = `Token ${this.accessToken}`;
@@ -3634,6 +3639,50 @@ class VtecxNext {
3634
3639
  this.resHeaders['set-cookie'] = setCookieVal;
3635
3640
  }
3636
3641
  };
3642
+ /**
3643
+ * ログイン時にレスポンスされたvte.cxからのset-cookieを保持する。
3644
+ * @param response vte.cxからのレスポンス
3645
+ */
3646
+ setLoginCookie = (response) => {
3647
+ // set-cookieの値をレスポンスヘッダ格納変数にセット
3648
+ let setCookieVal = response.headers.get('set-cookie');
3649
+ if (setCookieVal) {
3650
+ const tmpCookies = setCookieVal.split(';');
3651
+ for (const tmpCookie of tmpCookies) {
3652
+ const tmpKeyVal = tmpCookie.split('=');
3653
+ this.loginCookies[tmpKeyVal[0]] = tmpKeyVal[1];
3654
+ }
3655
+ }
3656
+ };
3657
+ /**
3658
+ * ログイン後のCookie編集
3659
+ * @returns cookie
3660
+ */
3661
+ editRequestCookie = () => {
3662
+ let cookie = this.req ? this.req.headers.get('cookie') : null;
3663
+ if (!this.loginCookies) {
3664
+ return cookie;
3665
+ }
3666
+ let retCookie = '';
3667
+ if (cookie) {
3668
+ const tmpCookies = cookie.split(';');
3669
+ for (const tmpCookie of tmpCookies) {
3670
+ const tmpKeyVal = tmpCookie.trim().split('=');
3671
+ const tmpName = tmpKeyVal[0];
3672
+ const tmpVal = tmpKeyVal[1];
3673
+ if (!this.loginCookies.hasOwnProperty(tmpName)) {
3674
+ retCookie = `${retCookie}${tmpName}=${tmpVal}; `;
3675
+ //} else {
3676
+ //console.log(`[editRequestCookie] hasOwnProperty (not set) : ${tmpName}=${tmpVal}`)
3677
+ }
3678
+ }
3679
+ }
3680
+ for (const tmpName in this.loginCookies) {
3681
+ const tmpVal = this.loginCookies[tmpName];
3682
+ retCookie = `${retCookie}${tmpName}=${tmpVal};`;
3683
+ }
3684
+ return retCookie;
3685
+ };
3637
3686
  /**
3638
3687
  * vte.cxからのレスポンスヘッダを、ブラウザへレスポンスする。
3639
3688
  * コンテンツの戻し時に使用。
@@ -3967,6 +4016,7 @@ const fetchVtecx = async (method, url, pHeaders, body, mode) => {
3967
4016
  const headers = [];
3968
4017
  if (pHeaders) {
3969
4018
  for (const key in pHeaders) {
4019
+ //console.log(`[vtecxnext fetchVtecx] request header = ${key}: ${pHeaders[key]}`)
3970
4020
  headers.push([key, pHeaders[key]]);
3971
4021
  }
3972
4022
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtecx/vtecxnext",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "vte.cx Next.js api",
5
5
  "main": "dist/index.js",
6
6
  "files": [