@vtecx/vtecxnext 3.0.5 → 3.1.0
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 +9 -0
- package/dist/vtecxnext.js +96 -23
- package/package.json +4 -4
package/dist/vtecxnext.d.ts
CHANGED
|
@@ -142,10 +142,14 @@ export declare class VtecxNext {
|
|
|
142
142
|
private bufferData;
|
|
143
143
|
/** Access Token (for batch) */
|
|
144
144
|
private accessToken;
|
|
145
|
+
/** Whether or not to use accesstoken (for batch) */
|
|
146
|
+
private useAccessToken;
|
|
145
147
|
/** login cookies */
|
|
146
148
|
private loginCookies;
|
|
147
149
|
/** next cookies (for server action) */
|
|
148
150
|
private cookieStore;
|
|
151
|
+
/** Whether server action cookies() should be used */
|
|
152
|
+
private useCookieStore;
|
|
149
153
|
/** flag whether the next cookies should be created */
|
|
150
154
|
private shouldBeCreatedCookieStore;
|
|
151
155
|
/**
|
|
@@ -154,6 +158,11 @@ export declare class VtecxNext {
|
|
|
154
158
|
* @param accessToken Access token (for batch)
|
|
155
159
|
*/
|
|
156
160
|
constructor(req?: NextRequest, accessToken?: string);
|
|
161
|
+
constructor(accessToken?: string);
|
|
162
|
+
/**
|
|
163
|
+
* Initial processing for batch.
|
|
164
|
+
*/
|
|
165
|
+
init: () => Promise<void>;
|
|
157
166
|
/**
|
|
158
167
|
* get url parameter.
|
|
159
168
|
* @param name parameter name
|
package/dist/vtecxnext.js
CHANGED
|
@@ -53,27 +53,60 @@ class VtecxNext {
|
|
|
53
53
|
bufferData = null;
|
|
54
54
|
/** Access Token (for batch) */
|
|
55
55
|
accessToken;
|
|
56
|
+
/** Whether or not to use accesstoken (for batch) */
|
|
57
|
+
useAccessToken;
|
|
56
58
|
/** login cookies */
|
|
57
59
|
loginCookies = {};
|
|
58
60
|
/** next cookies (for server action) */
|
|
59
61
|
cookieStore; // ReadonlyRequestCookies
|
|
62
|
+
/** Whether server action cookies() should be used */
|
|
63
|
+
useCookieStore = false;
|
|
60
64
|
/** flag whether the next cookies should be created */
|
|
61
|
-
shouldBeCreatedCookieStore =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* @param req Request (for api)
|
|
65
|
-
* @param accessToken Access token (for batch)
|
|
66
|
-
*/
|
|
67
|
-
constructor(req, accessToken) {
|
|
68
|
-
if (req) {
|
|
69
|
-
this.req = req;
|
|
70
|
-
this.shouldBeCreatedCookieStore = false;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
65
|
+
shouldBeCreatedCookieStore = false;
|
|
66
|
+
constructor(reqOrAccessToken, accessToken) {
|
|
67
|
+
if (typeof reqOrAccessToken === 'string') {
|
|
73
68
|
this.req = undefined;
|
|
74
|
-
this.accessToken =
|
|
75
|
-
|
|
69
|
+
this.accessToken = reqOrAccessToken;
|
|
70
|
+
this.useAccessToken = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (reqOrAccessToken) {
|
|
74
|
+
this.req = reqOrAccessToken;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.req = undefined;
|
|
78
|
+
this.accessToken = accessToken;
|
|
79
|
+
this.useAccessToken = accessToken ? true : undefined;
|
|
80
|
+
this.useCookieStore = true;
|
|
81
|
+
this.shouldBeCreatedCookieStore = true;
|
|
76
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Initial processing for batch.
|
|
85
|
+
*/
|
|
86
|
+
init = async () => {
|
|
87
|
+
//console.log(`[vtecxnext init] start.`)
|
|
88
|
+
if (this.accessToken && this.useAccessToken) {
|
|
89
|
+
// vte.cxへリクエスト
|
|
90
|
+
const method = 'POST';
|
|
91
|
+
const url = `${SERVLETPATH_DATA}/?_createsession`;
|
|
92
|
+
let response;
|
|
93
|
+
try {
|
|
94
|
+
response = await this.requestVtecx(method, url);
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
throw newFetchError(e, true);
|
|
98
|
+
}
|
|
99
|
+
//console.log(`[vtecxnext init] response. status=${response.status}`)
|
|
100
|
+
// vte.cxからのset-cookieを転記
|
|
101
|
+
this.setCookie(response);
|
|
102
|
+
// バッチ実行用にセッションCookieを保持する
|
|
103
|
+
this.setLoginCookie(response);
|
|
104
|
+
// レスポンスのエラーチェック
|
|
105
|
+
await checkVtecxResponse(response);
|
|
106
|
+
// 以降アクセストークンは使用しない
|
|
107
|
+
this.useAccessToken = false;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
77
110
|
/**
|
|
78
111
|
* get url parameter.
|
|
79
112
|
* @param name parameter name
|
|
@@ -4051,8 +4084,8 @@ class VtecxNext {
|
|
|
4051
4084
|
const cookie = await this.editRequestCookie();
|
|
4052
4085
|
//console.log(`[requestVtecx] cookie = ${cookie}`)
|
|
4053
4086
|
const headers = cookie ? { Cookie: cookie } : {};
|
|
4054
|
-
if (this.accessToken) {
|
|
4055
|
-
headers.Authorization = `
|
|
4087
|
+
if (this.accessToken && this.useAccessToken) {
|
|
4088
|
+
headers.Authorization = `Bearer ${this.accessToken}`;
|
|
4056
4089
|
}
|
|
4057
4090
|
if (additionalHeaders) {
|
|
4058
4091
|
//console.log(`[vtecxnext requestVtecx] additionalHeaders for`)
|
|
@@ -4151,12 +4184,18 @@ class VtecxNext {
|
|
|
4151
4184
|
*/
|
|
4152
4185
|
setLoginCookie = (response) => {
|
|
4153
4186
|
// set-cookieの値をレスポンスヘッダ格納変数にセット
|
|
4154
|
-
|
|
4187
|
+
const setCookieVal = response.headers.get('set-cookie');
|
|
4155
4188
|
if (setCookieVal) {
|
|
4156
|
-
const
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4189
|
+
for (const cookie of splitSetCookieHeader(setCookieVal)) {
|
|
4190
|
+
const idx = cookie.indexOf('=');
|
|
4191
|
+
if (idx <= 0) {
|
|
4192
|
+
continue;
|
|
4193
|
+
}
|
|
4194
|
+
const name = cookie.substring(0, idx).trim();
|
|
4195
|
+
const value = cookie.substring(idx + 1).trim();
|
|
4196
|
+
if (name) {
|
|
4197
|
+
this.loginCookies[name] = value;
|
|
4198
|
+
}
|
|
4160
4199
|
}
|
|
4161
4200
|
}
|
|
4162
4201
|
};
|
|
@@ -4183,7 +4222,7 @@ class VtecxNext {
|
|
|
4183
4222
|
}
|
|
4184
4223
|
}
|
|
4185
4224
|
else {
|
|
4186
|
-
if (this.shouldBeCreatedCookieStore) {
|
|
4225
|
+
if (this.useCookieStore && this.shouldBeCreatedCookieStore) {
|
|
4187
4226
|
//console.log(`[editRequestCookie] shouldBeCreatedCookieStore === true`)
|
|
4188
4227
|
try {
|
|
4189
4228
|
this.cookieStore = await (0, headers_1.cookies)();
|
|
@@ -4194,7 +4233,7 @@ class VtecxNext {
|
|
|
4194
4233
|
}
|
|
4195
4234
|
this.shouldBeCreatedCookieStore = false;
|
|
4196
4235
|
}
|
|
4197
|
-
if (this.cookieStore) {
|
|
4236
|
+
if (this.useCookieStore && this.cookieStore) {
|
|
4198
4237
|
//console.log(`[editRequestCookie] this.cookieStore === true. ${JSON.stringify(this.cookieStore)}`)
|
|
4199
4238
|
// server action用
|
|
4200
4239
|
const cookieArray = this.cookieStore.getAll();
|
|
@@ -4873,6 +4912,40 @@ const createURLSearchParams = (data) => {
|
|
|
4873
4912
|
Object.keys(data).forEach((key) => params.append(key, data[key]));
|
|
4874
4913
|
return params;
|
|
4875
4914
|
};
|
|
4915
|
+
/**
|
|
4916
|
+
* set-cookie header から Cookie 名と値だけを抽出する。
|
|
4917
|
+
* @param setCookieVal set-cookie header value
|
|
4918
|
+
* @returns cookie pair list
|
|
4919
|
+
*/
|
|
4920
|
+
const splitSetCookieHeader = (setCookieVal) => {
|
|
4921
|
+
const cookies = [];
|
|
4922
|
+
let current = '';
|
|
4923
|
+
let inExpires = false;
|
|
4924
|
+
for (let i = 0; i < setCookieVal.length; i++) {
|
|
4925
|
+
const char = setCookieVal[i];
|
|
4926
|
+
if (!inExpires && setCookieVal.substring(i, i + 8).toLowerCase() === 'expires=') {
|
|
4927
|
+
inExpires = true;
|
|
4928
|
+
}
|
|
4929
|
+
if (char === ',' && !inExpires) {
|
|
4930
|
+
if (current) {
|
|
4931
|
+
cookies.push(current);
|
|
4932
|
+
}
|
|
4933
|
+
current = '';
|
|
4934
|
+
continue;
|
|
4935
|
+
}
|
|
4936
|
+
current += char;
|
|
4937
|
+
if (inExpires && char === ';') {
|
|
4938
|
+
inExpires = false;
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
if (current) {
|
|
4942
|
+
cookies.push(current);
|
|
4943
|
+
}
|
|
4944
|
+
return cookies.map((cookie) => {
|
|
4945
|
+
const firstPart = cookie.split(';')[0];
|
|
4946
|
+
return firstPart.trim();
|
|
4947
|
+
}).filter((cookie) => cookie.length > 0);
|
|
4948
|
+
};
|
|
4876
4949
|
/**
|
|
4877
4950
|
* URIのパラメータ部分を連想配列にして返却
|
|
4878
4951
|
* @param uri URI
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtecx/vtecxnext",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "vte.cx Next.js api",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/reflexworks/vtecxnext#readme",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@types/node": "^25.
|
|
21
|
+
"@types/node": "^25.9.1",
|
|
22
22
|
"@types/sqlstring": "^2.3.2",
|
|
23
23
|
"ts-node": "^10.9.2",
|
|
24
|
-
"typescript": "^
|
|
24
|
+
"typescript": "^6.0.3"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"next": "^16.
|
|
27
|
+
"next": "^16.2.6",
|
|
28
28
|
"sqlstring": "^2.3.3"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|