@vtecx/vtecxnext 3.0.6 → 3.1.1
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/dist/vtecxnext.d.ts +8 -0
- package/dist/vtecxnext.js +93 -20
- package/package.json +1 -1
package/dist/vtecxnext.d.ts
CHANGED
|
@@ -148,6 +148,8 @@ export declare class VtecxNext {
|
|
|
148
148
|
private loginCookies;
|
|
149
149
|
/** next cookies (for server action) */
|
|
150
150
|
private cookieStore;
|
|
151
|
+
/** Whether server action cookies() should be used */
|
|
152
|
+
private useCookieStore;
|
|
151
153
|
/** flag whether the next cookies should be created */
|
|
152
154
|
private shouldBeCreatedCookieStore;
|
|
153
155
|
/**
|
|
@@ -156,6 +158,7 @@ export declare class VtecxNext {
|
|
|
156
158
|
* @param accessToken Access token (for batch)
|
|
157
159
|
*/
|
|
158
160
|
constructor(req?: NextRequest, accessToken?: string);
|
|
161
|
+
constructor(accessToken?: string);
|
|
159
162
|
/**
|
|
160
163
|
* Initial processing for batch.
|
|
161
164
|
*/
|
|
@@ -1093,6 +1096,11 @@ export declare class VtecxNext {
|
|
|
1093
1096
|
* @return storage usage
|
|
1094
1097
|
*/
|
|
1095
1098
|
storageusage: () => Promise<number>;
|
|
1099
|
+
/**
|
|
1100
|
+
* get batchjob execute time
|
|
1101
|
+
* @return batchjob execute time
|
|
1102
|
+
*/
|
|
1103
|
+
batchjobexectime: () => Promise<number>;
|
|
1096
1104
|
/**
|
|
1097
1105
|
* convert index informations to argument entry
|
|
1098
1106
|
* @param indexInfos index informations
|
package/dist/vtecxnext.js
CHANGED
|
@@ -59,23 +59,26 @@ class VtecxNext {
|
|
|
59
59
|
loginCookies = {};
|
|
60
60
|
/** next cookies (for server action) */
|
|
61
61
|
cookieStore; // ReadonlyRequestCookies
|
|
62
|
+
/** Whether server action cookies() should be used */
|
|
63
|
+
useCookieStore = false;
|
|
62
64
|
/** flag whether the next cookies should be created */
|
|
63
|
-
shouldBeCreatedCookieStore =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param req Request (for api)
|
|
67
|
-
* @param accessToken Access token (for batch)
|
|
68
|
-
*/
|
|
69
|
-
constructor(req, accessToken) {
|
|
70
|
-
if (req) {
|
|
71
|
-
this.req = req;
|
|
72
|
-
this.shouldBeCreatedCookieStore = false;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
65
|
+
shouldBeCreatedCookieStore = false;
|
|
66
|
+
constructor(reqOrAccessToken, accessToken) {
|
|
67
|
+
if (typeof reqOrAccessToken === 'string') {
|
|
75
68
|
this.req = undefined;
|
|
76
|
-
this.accessToken =
|
|
69
|
+
this.accessToken = reqOrAccessToken;
|
|
77
70
|
this.useAccessToken = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (reqOrAccessToken) {
|
|
74
|
+
this.req = reqOrAccessToken;
|
|
75
|
+
return;
|
|
78
76
|
}
|
|
77
|
+
this.req = undefined;
|
|
78
|
+
this.accessToken = accessToken;
|
|
79
|
+
this.useAccessToken = accessToken ? true : undefined;
|
|
80
|
+
this.useCookieStore = true;
|
|
81
|
+
this.shouldBeCreatedCookieStore = true;
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
81
84
|
* Initial processing for batch.
|
|
@@ -96,6 +99,8 @@ class VtecxNext {
|
|
|
96
99
|
//console.log(`[vtecxnext init] response. status=${response.status}`)
|
|
97
100
|
// vte.cxからのset-cookieを転記
|
|
98
101
|
this.setCookie(response);
|
|
102
|
+
// バッチ実行用にセッションCookieを保持する
|
|
103
|
+
this.setLoginCookie(response);
|
|
99
104
|
// レスポンスのエラーチェック
|
|
100
105
|
await checkVtecxResponse(response);
|
|
101
106
|
// 以降アクセストークンは使用しない
|
|
@@ -4022,6 +4027,34 @@ class VtecxNext {
|
|
|
4022
4027
|
}
|
|
4023
4028
|
return 0;
|
|
4024
4029
|
};
|
|
4030
|
+
/**
|
|
4031
|
+
* get batchjob execute time
|
|
4032
|
+
* @return batchjob execute time
|
|
4033
|
+
*/
|
|
4034
|
+
batchjobexectime = async () => {
|
|
4035
|
+
//console.log('[vtecxnext batchjobexectime] start.')
|
|
4036
|
+
// vte.cxへリクエスト
|
|
4037
|
+
const method = 'GET';
|
|
4038
|
+
const url = `${SERVLETPATH_DATA}/?_batchjobexectime`;
|
|
4039
|
+
let response;
|
|
4040
|
+
try {
|
|
4041
|
+
response = await this.requestVtecx(method, url);
|
|
4042
|
+
}
|
|
4043
|
+
catch (e) {
|
|
4044
|
+
throw newFetchError(e, true);
|
|
4045
|
+
}
|
|
4046
|
+
//console.log(`[vtecxnext batchjobexectime] response=${response}`)
|
|
4047
|
+
// vte.cxからのset-cookieを転記
|
|
4048
|
+
this.setCookie(response);
|
|
4049
|
+
// レスポンスのエラーチェック
|
|
4050
|
+
await checkVtecxResponse(response);
|
|
4051
|
+
// 戻り値
|
|
4052
|
+
const data = await getJson(response);
|
|
4053
|
+
if (isIntegerString(data.feed.title)) {
|
|
4054
|
+
return Number(data.feed.title);
|
|
4055
|
+
}
|
|
4056
|
+
return 0;
|
|
4057
|
+
};
|
|
4025
4058
|
/**
|
|
4026
4059
|
* convert index informations to argument entry
|
|
4027
4060
|
* @param indexInfos index informations
|
|
@@ -4179,12 +4212,18 @@ class VtecxNext {
|
|
|
4179
4212
|
*/
|
|
4180
4213
|
setLoginCookie = (response) => {
|
|
4181
4214
|
// set-cookieの値をレスポンスヘッダ格納変数にセット
|
|
4182
|
-
|
|
4215
|
+
const setCookieVal = response.headers.get('set-cookie');
|
|
4183
4216
|
if (setCookieVal) {
|
|
4184
|
-
const
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4217
|
+
for (const cookie of splitSetCookieHeader(setCookieVal)) {
|
|
4218
|
+
const idx = cookie.indexOf('=');
|
|
4219
|
+
if (idx <= 0) {
|
|
4220
|
+
continue;
|
|
4221
|
+
}
|
|
4222
|
+
const name = cookie.substring(0, idx).trim();
|
|
4223
|
+
const value = cookie.substring(idx + 1).trim();
|
|
4224
|
+
if (name) {
|
|
4225
|
+
this.loginCookies[name] = value;
|
|
4226
|
+
}
|
|
4188
4227
|
}
|
|
4189
4228
|
}
|
|
4190
4229
|
};
|
|
@@ -4211,7 +4250,7 @@ class VtecxNext {
|
|
|
4211
4250
|
}
|
|
4212
4251
|
}
|
|
4213
4252
|
else {
|
|
4214
|
-
if (this.shouldBeCreatedCookieStore) {
|
|
4253
|
+
if (this.useCookieStore && this.shouldBeCreatedCookieStore) {
|
|
4215
4254
|
//console.log(`[editRequestCookie] shouldBeCreatedCookieStore === true`)
|
|
4216
4255
|
try {
|
|
4217
4256
|
this.cookieStore = await (0, headers_1.cookies)();
|
|
@@ -4222,7 +4261,7 @@ class VtecxNext {
|
|
|
4222
4261
|
}
|
|
4223
4262
|
this.shouldBeCreatedCookieStore = false;
|
|
4224
4263
|
}
|
|
4225
|
-
if (this.cookieStore) {
|
|
4264
|
+
if (this.useCookieStore && this.cookieStore) {
|
|
4226
4265
|
//console.log(`[editRequestCookie] this.cookieStore === true. ${JSON.stringify(this.cookieStore)}`)
|
|
4227
4266
|
// server action用
|
|
4228
4267
|
const cookieArray = this.cookieStore.getAll();
|
|
@@ -4901,6 +4940,40 @@ const createURLSearchParams = (data) => {
|
|
|
4901
4940
|
Object.keys(data).forEach((key) => params.append(key, data[key]));
|
|
4902
4941
|
return params;
|
|
4903
4942
|
};
|
|
4943
|
+
/**
|
|
4944
|
+
* set-cookie header から Cookie 名と値だけを抽出する。
|
|
4945
|
+
* @param setCookieVal set-cookie header value
|
|
4946
|
+
* @returns cookie pair list
|
|
4947
|
+
*/
|
|
4948
|
+
const splitSetCookieHeader = (setCookieVal) => {
|
|
4949
|
+
const cookies = [];
|
|
4950
|
+
let current = '';
|
|
4951
|
+
let inExpires = false;
|
|
4952
|
+
for (let i = 0; i < setCookieVal.length; i++) {
|
|
4953
|
+
const char = setCookieVal[i];
|
|
4954
|
+
if (!inExpires && setCookieVal.substring(i, i + 8).toLowerCase() === 'expires=') {
|
|
4955
|
+
inExpires = true;
|
|
4956
|
+
}
|
|
4957
|
+
if (char === ',' && !inExpires) {
|
|
4958
|
+
if (current) {
|
|
4959
|
+
cookies.push(current);
|
|
4960
|
+
}
|
|
4961
|
+
current = '';
|
|
4962
|
+
continue;
|
|
4963
|
+
}
|
|
4964
|
+
current += char;
|
|
4965
|
+
if (inExpires && char === ';') {
|
|
4966
|
+
inExpires = false;
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
if (current) {
|
|
4970
|
+
cookies.push(current);
|
|
4971
|
+
}
|
|
4972
|
+
return cookies.map((cookie) => {
|
|
4973
|
+
const firstPart = cookie.split(';')[0];
|
|
4974
|
+
return firstPart.trim();
|
|
4975
|
+
}).filter((cookie) => cookie.length > 0);
|
|
4976
|
+
};
|
|
4904
4977
|
/**
|
|
4905
4978
|
* URIのパラメータ部分を連想配列にして返却
|
|
4906
4979
|
* @param uri URI
|