@vtecx/vtecxnext 2.3.0 → 3.0.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 +190 -77
- package/dist/vtecxnext.js +289 -111
- package/package.json +3 -3
package/dist/vtecxnext.js
CHANGED
|
@@ -1,44 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.isVtecxNextError = exports.FetchError = exports.VtecxNextError = exports.
|
|
6
|
+
exports.isVtecxNextError = exports.FetchError = exports.VtecxNextError = exports.VtecxNext = exports.hello = void 0;
|
|
7
|
+
const headers_1 = require("next/headers");
|
|
40
8
|
const sqlstring_1 = __importDefault(require("sqlstring"));
|
|
41
|
-
const url_1 = __importStar(require("url"));
|
|
42
9
|
/**
|
|
43
10
|
* Hello world.
|
|
44
11
|
*/
|
|
@@ -59,8 +26,24 @@ const HEADER_NEXTPAGE = 'x-vtecx-nextpage';
|
|
|
59
26
|
const PAGINATION_NUM = 7;
|
|
60
27
|
/** pagination memorysort */
|
|
61
28
|
const MEMORYSORT = 'memorysort';
|
|
29
|
+
/** parameter : nextpage */
|
|
30
|
+
const PARAM_NEXTPAGE = 'p';
|
|
31
|
+
/**
|
|
32
|
+
* vtecxnext.
|
|
33
|
+
* Executes various operations for the vte.cx service.
|
|
34
|
+
*
|
|
35
|
+
* The following environment variables must be defined.
|
|
36
|
+
*
|
|
37
|
+
* - VTECX_URL: URL of the vte.cx service
|
|
38
|
+
* - VTECX_APIKEY: API key
|
|
39
|
+
*
|
|
40
|
+
* When connecting to other vte.cx services, define the following environment variables.
|
|
41
|
+
*
|
|
42
|
+
* - SERVICEKEY_{service name}: Service key of the target service
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
62
45
|
class VtecxNext {
|
|
63
|
-
/** Request */
|
|
46
|
+
/** Request (for api) */
|
|
64
47
|
req;
|
|
65
48
|
/** Response status */
|
|
66
49
|
resStatus = 200;
|
|
@@ -72,14 +55,19 @@ class VtecxNext {
|
|
|
72
55
|
accessToken;
|
|
73
56
|
/** login cookies */
|
|
74
57
|
loginCookies = {};
|
|
58
|
+
/** next cookies (for server action) */
|
|
59
|
+
cookieStore; // ReadonlyRequestCookies
|
|
60
|
+
/** flag whether the next cookies should be created */
|
|
61
|
+
shouldBeCreatedCookieStore = true;
|
|
75
62
|
/**
|
|
76
63
|
* constructor
|
|
77
|
-
* @param req Request
|
|
64
|
+
* @param req Request (for api)
|
|
78
65
|
* @param accessToken Access token (for batch)
|
|
79
66
|
*/
|
|
80
67
|
constructor(req, accessToken) {
|
|
81
68
|
if (req) {
|
|
82
69
|
this.req = req;
|
|
70
|
+
this.shouldBeCreatedCookieStore = false;
|
|
83
71
|
}
|
|
84
72
|
else {
|
|
85
73
|
this.req = undefined;
|
|
@@ -319,6 +307,7 @@ class VtecxNext {
|
|
|
319
307
|
await checkVtecxResponse(response);
|
|
320
308
|
// 戻り値
|
|
321
309
|
const data = await getJson(response);
|
|
310
|
+
//console.log(`[vtecxnext account] data = ${JSON.stringify(data)}`)
|
|
322
311
|
return data.feed.title;
|
|
323
312
|
};
|
|
324
313
|
/**
|
|
@@ -611,12 +600,13 @@ class VtecxNext {
|
|
|
611
600
|
await checkVtecxResponse(response);
|
|
612
601
|
// 戻り値
|
|
613
602
|
const data = await getJson(response);
|
|
614
|
-
|
|
603
|
+
let header = undefined;
|
|
615
604
|
const nextpage = response.headers.get(HEADER_NEXTPAGE);
|
|
616
605
|
if (nextpage) {
|
|
606
|
+
header = {};
|
|
617
607
|
header[HEADER_NEXTPAGE] = nextpage;
|
|
618
608
|
}
|
|
619
|
-
return
|
|
609
|
+
return vtecxResponse(response.status, header, data);
|
|
620
610
|
};
|
|
621
611
|
/**
|
|
622
612
|
* get count
|
|
@@ -625,11 +615,36 @@ class VtecxNext {
|
|
|
625
615
|
* @return count
|
|
626
616
|
*/
|
|
627
617
|
count = async (uri, targetService) => {
|
|
628
|
-
//console.log(
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
618
|
+
//console.log(`[vtecxnext count] start. uri=${uri}`)
|
|
619
|
+
let cnt = 0;
|
|
620
|
+
let noRepeat = false;
|
|
621
|
+
let nextpage = '';
|
|
622
|
+
const params = getParamMap(uri);
|
|
623
|
+
if (params[PARAM_NEXTPAGE]) {
|
|
624
|
+
noRepeat = true;
|
|
625
|
+
}
|
|
626
|
+
do {
|
|
627
|
+
const editedUri = noRepeat ? uri : addNextpage(uri, nextpage);
|
|
628
|
+
//console.log(`[vtecxnext count] editedUri=${editedUri}`)
|
|
629
|
+
nextpage = '';
|
|
630
|
+
const vtecxRes = await this.countResponse(editedUri, targetService);
|
|
631
|
+
if (vtecxRes.status === 200) {
|
|
632
|
+
const data = vtecxRes.data;
|
|
633
|
+
if (!data?.feed?.title) {
|
|
634
|
+
if (!cnt) {
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
cnt += Number(data.feed.title);
|
|
640
|
+
}
|
|
641
|
+
if (vtecxRes.header?.hasOwnProperty(HEADER_NEXTPAGE)) {
|
|
642
|
+
nextpage = vtecxRes.header[HEADER_NEXTPAGE];
|
|
643
|
+
//console.log(`[vtecxnext count] ${HEADER_NEXTPAGE}=${nextpage}`)
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
} while (!noRepeat && nextpage);
|
|
647
|
+
return cnt;
|
|
633
648
|
};
|
|
634
649
|
/**
|
|
635
650
|
* get count
|
|
@@ -658,12 +673,13 @@ class VtecxNext {
|
|
|
658
673
|
await checkVtecxResponse(response);
|
|
659
674
|
// 戻り値
|
|
660
675
|
const data = await getJson(response);
|
|
661
|
-
|
|
676
|
+
let header = undefined;
|
|
662
677
|
const nextpage = response.headers.get(HEADER_NEXTPAGE);
|
|
663
678
|
if (nextpage) {
|
|
679
|
+
header = {};
|
|
664
680
|
header[HEADER_NEXTPAGE] = nextpage;
|
|
665
681
|
}
|
|
666
|
-
return
|
|
682
|
+
return vtecxResponse(response.status, header, data);
|
|
667
683
|
};
|
|
668
684
|
/**
|
|
669
685
|
* register entries
|
|
@@ -1016,7 +1032,7 @@ class VtecxNext {
|
|
|
1016
1032
|
/**
|
|
1017
1033
|
* set a addition range
|
|
1018
1034
|
* @param uri key
|
|
1019
|
-
* @param range addition range
|
|
1035
|
+
* @param range addition range. delete if blank.
|
|
1020
1036
|
* @param targetService target service name (for service linkage)
|
|
1021
1037
|
* @return addition range
|
|
1022
1038
|
*/
|
|
@@ -1024,7 +1040,7 @@ class VtecxNext {
|
|
|
1024
1040
|
//console.log(`[vtecxnext rangeids] start. range=${range}`)
|
|
1025
1041
|
// 入力値チェック
|
|
1026
1042
|
checkUri(uri);
|
|
1027
|
-
checkNotNull(range, 'range')
|
|
1043
|
+
//checkNotNull(range, 'range') // 空の場合加算枠削除
|
|
1028
1044
|
// vte.cxへリクエスト
|
|
1029
1045
|
const method = 'PUT';
|
|
1030
1046
|
const url = `${SERVLETPATH_PROVIDER}${uri}?_rangeids`;
|
|
@@ -1043,7 +1059,12 @@ class VtecxNext {
|
|
|
1043
1059
|
await checkVtecxResponse(response);
|
|
1044
1060
|
// 戻り値
|
|
1045
1061
|
const data = await getJson(response);
|
|
1046
|
-
|
|
1062
|
+
if (data.feed?.title) {
|
|
1063
|
+
return data.feed.title;
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
return '';
|
|
1067
|
+
}
|
|
1047
1068
|
};
|
|
1048
1069
|
/**
|
|
1049
1070
|
* get a addition range
|
|
@@ -1072,7 +1093,8 @@ class VtecxNext {
|
|
|
1072
1093
|
await checkVtecxResponse(response);
|
|
1073
1094
|
// 戻り値
|
|
1074
1095
|
const data = await getJson(response);
|
|
1075
|
-
|
|
1096
|
+
//console.log(`[vtecxnext getRangeids] status=${String(response.status)} data=${JSON.stringify(data)}`)
|
|
1097
|
+
return data.feed?.title;
|
|
1076
1098
|
};
|
|
1077
1099
|
/**
|
|
1078
1100
|
* set feed to session
|
|
@@ -1108,14 +1130,14 @@ class VtecxNext {
|
|
|
1108
1130
|
* @return true if successful
|
|
1109
1131
|
*/
|
|
1110
1132
|
setSessionEntry = async (name, entry) => {
|
|
1111
|
-
//console.log(`[vtecxnext setSessionEntry] start. name=${name} entry=${entry}`)
|
|
1133
|
+
//console.log(`[vtecxnext setSessionEntry] start. name=${name} entry=${JSON.stringify(entry)}`)
|
|
1112
1134
|
// 入力チェック
|
|
1113
1135
|
checkNotNull(name, 'Name');
|
|
1114
1136
|
checkNotNull(entry, 'Entry');
|
|
1115
1137
|
// vte.cxへリクエスト
|
|
1116
1138
|
const method = 'PUT';
|
|
1117
1139
|
const url = `${SERVLETPATH_PROVIDER}/?_sessionentry=${name}`;
|
|
1118
|
-
const feed = { feed: { entry: entry } };
|
|
1140
|
+
const feed = { feed: { entry: [entry] } };
|
|
1119
1141
|
let response;
|
|
1120
1142
|
try {
|
|
1121
1143
|
response = await this.requestVtecx(method, url, JSON.stringify(feed));
|
|
@@ -1590,7 +1612,8 @@ class VtecxNext {
|
|
|
1590
1612
|
// 入力チェック
|
|
1591
1613
|
checkNotNull(feed, 'Feed');
|
|
1592
1614
|
// リクエストデータ
|
|
1593
|
-
const reqFeed = 'feed' in feed ? feed : { feed: { entry: feed } }
|
|
1615
|
+
//const reqFeed = 'feed' in feed ? feed : { feed: { entry: feed } }
|
|
1616
|
+
const reqFeed = { feed: { entry: feed } };
|
|
1594
1617
|
// テーブル名の指定がある場合は指定
|
|
1595
1618
|
const tablenamesStr = editBqTableNames(tablenames);
|
|
1596
1619
|
if (tablenamesStr) {
|
|
@@ -1665,7 +1688,7 @@ class VtecxNext {
|
|
|
1665
1688
|
* @return query results in JSON format
|
|
1666
1689
|
*/
|
|
1667
1690
|
getBQ = async (sql, values, parent) => {
|
|
1668
|
-
return this.execBQ(sql, values);
|
|
1691
|
+
return this.execBQ(sql, values, parent);
|
|
1669
1692
|
};
|
|
1670
1693
|
/**
|
|
1671
1694
|
* query bigquery
|
|
@@ -1759,7 +1782,7 @@ class VtecxNext {
|
|
|
1759
1782
|
checkUri(uri);
|
|
1760
1783
|
}
|
|
1761
1784
|
// リクエストデータ
|
|
1762
|
-
const reqFeed =
|
|
1785
|
+
const reqFeed = { feed: { entry: feed } };
|
|
1763
1786
|
// テーブル名の指定がある場合は指定
|
|
1764
1787
|
const tablenamesStr = editBqTableNames(tablenames);
|
|
1765
1788
|
if (tablenamesStr) {
|
|
@@ -1800,7 +1823,7 @@ class VtecxNext {
|
|
|
1800
1823
|
checkUri(uri);
|
|
1801
1824
|
}
|
|
1802
1825
|
// リクエストデータ
|
|
1803
|
-
const reqFeed =
|
|
1826
|
+
const reqFeed = { feed: { entry: feed } };
|
|
1804
1827
|
// テーブル名の指定がある場合は指定
|
|
1805
1828
|
const tablenamesStr = editBqTableNames(tablenames);
|
|
1806
1829
|
//console.log(`[putBDBQ] tableamesStr=${tablenamesStr}`)
|
|
@@ -2651,7 +2674,7 @@ class VtecxNext {
|
|
|
2651
2674
|
* @returns entry
|
|
2652
2675
|
*/
|
|
2653
2676
|
convertAdduserInfoToEntry = (adduserInfo, isNoPswd) => {
|
|
2654
|
-
|
|
2677
|
+
const retEntry = {
|
|
2655
2678
|
contributor: [
|
|
2656
2679
|
{
|
|
2657
2680
|
uri: `urn:vte.cx:auth:${this.null2blank(adduserInfo.username)}${isNoPswd ? '' : ',' + this.null2blank(adduserInfo.pswd)}`,
|
|
@@ -2659,9 +2682,12 @@ class VtecxNext {
|
|
|
2659
2682
|
}
|
|
2660
2683
|
],
|
|
2661
2684
|
title: adduserInfo.emailSubject,
|
|
2662
|
-
summary: adduserInfo.emailText
|
|
2663
|
-
content: { ______text: adduserInfo.emailHtml }
|
|
2685
|
+
summary: adduserInfo.emailText
|
|
2664
2686
|
};
|
|
2687
|
+
if (adduserInfo.emailHtml) {
|
|
2688
|
+
retEntry.content = { ______text: adduserInfo.emailHtml };
|
|
2689
|
+
}
|
|
2690
|
+
return retEntry;
|
|
2665
2691
|
};
|
|
2666
2692
|
/**
|
|
2667
2693
|
* add user by user admin
|
|
@@ -2762,9 +2788,10 @@ class VtecxNext {
|
|
|
2762
2788
|
* @param newpswd new password
|
|
2763
2789
|
* @param oldpswd old password
|
|
2764
2790
|
* @param passresetToken password reset token
|
|
2791
|
+
* @param rxid RXID
|
|
2765
2792
|
* @return message feed
|
|
2766
2793
|
*/
|
|
2767
|
-
changepass = async (newpswd, oldpswd, passresetToken) => {
|
|
2794
|
+
changepass = async (newpswd, oldpswd, passresetToken, rxid) => {
|
|
2768
2795
|
//console.log(`[vtecxnext changepass] start. feed=${feed}`)
|
|
2769
2796
|
// 入力チェック
|
|
2770
2797
|
checkNotNull(newpswd, 'new password');
|
|
@@ -2782,7 +2809,7 @@ class VtecxNext {
|
|
|
2782
2809
|
const feed = [{ contributor: contributors }];
|
|
2783
2810
|
// vte.cxへリクエスト
|
|
2784
2811
|
const method = 'PUT';
|
|
2785
|
-
const url = `${SERVLETPATH_DATA}/?_changephash`;
|
|
2812
|
+
const url = `${SERVLETPATH_DATA}/?_changephash${rxid ? '&_RXID=' + rxid : ''}`;
|
|
2786
2813
|
let response;
|
|
2787
2814
|
try {
|
|
2788
2815
|
response = await this.requestVtecx(method, url, JSON.stringify(feed));
|
|
@@ -2803,7 +2830,7 @@ class VtecxNext {
|
|
|
2803
2830
|
* @return message feed
|
|
2804
2831
|
*/
|
|
2805
2832
|
changepassByAdmin = async (changepassByAdminInfos) => {
|
|
2806
|
-
//console.log(`[vtecxnext changepassByAdmin] start.
|
|
2833
|
+
//console.log(`[vtecxnext changepassByAdmin] start. changepassByAdminInfos=${JSON.stringify(changepassByAdminInfos)}`)
|
|
2807
2834
|
// 入力チェック
|
|
2808
2835
|
checkNotNull(changepassByAdminInfos, 'password change information');
|
|
2809
2836
|
const feed = [];
|
|
@@ -3117,7 +3144,7 @@ class VtecxNext {
|
|
|
3117
3144
|
* @return message feed
|
|
3118
3145
|
*/
|
|
3119
3146
|
deleteusers = async (accounts, uids) => {
|
|
3120
|
-
//console.log(`[vtecxnext deleteusers] start.
|
|
3147
|
+
//console.log(`[vtecxnext deleteusers] start. accounts=${accounts ? JSON.stringify(accounts) : 'undefined'} uids=${uids ? JSON.stringify(uids) : 'undefined'}`)
|
|
3121
3148
|
// 入力チェック
|
|
3122
3149
|
if (isBlank(accounts) && isBlank(uids)) {
|
|
3123
3150
|
throw new VtecxNextError(400, `account or uid is required.`);
|
|
@@ -3276,16 +3303,26 @@ class VtecxNext {
|
|
|
3276
3303
|
* save files
|
|
3277
3304
|
* @param uri key
|
|
3278
3305
|
* @param bysize true if registering with specified size
|
|
3306
|
+
* @param saFormData formData by server action
|
|
3279
3307
|
* @returns message
|
|
3280
3308
|
*/
|
|
3281
|
-
savefiles = async (uri, bysize) => {
|
|
3309
|
+
savefiles = async (uri, bysize, saFormData) => {
|
|
3282
3310
|
//console.log(`[vtecxnext savefiles] start. uri=${uri}`)
|
|
3283
|
-
if (!this.req) {
|
|
3284
|
-
throw new VtecxNextError(421, '
|
|
3311
|
+
if (!this.req && !saFormData) {
|
|
3312
|
+
throw new VtecxNextError(421, 'Form data is required.');
|
|
3285
3313
|
}
|
|
3286
3314
|
// キー入力値チェック
|
|
3287
3315
|
checkUri(uri);
|
|
3288
|
-
|
|
3316
|
+
let formData;
|
|
3317
|
+
if (saFormData) {
|
|
3318
|
+
formData = saFormData;
|
|
3319
|
+
}
|
|
3320
|
+
else if (this.req) {
|
|
3321
|
+
formData = await this.req.formData();
|
|
3322
|
+
}
|
|
3323
|
+
else {
|
|
3324
|
+
throw new VtecxNextError(421, 'Form data is required.');
|
|
3325
|
+
}
|
|
3289
3326
|
const promiseKeyBuffers = [];
|
|
3290
3327
|
const promises = [];
|
|
3291
3328
|
// bufferの取得(非同期)
|
|
@@ -3326,17 +3363,18 @@ class VtecxNext {
|
|
|
3326
3363
|
/**
|
|
3327
3364
|
* save files registering with specified size
|
|
3328
3365
|
* @param uri key
|
|
3366
|
+
* @param saFormData formData by server action
|
|
3329
3367
|
* @returns message
|
|
3330
3368
|
*/
|
|
3331
|
-
savefilesBySize = async (uri) => {
|
|
3332
|
-
return this.savefiles(uri, true);
|
|
3369
|
+
savefilesBySize = async (uri, saFormData) => {
|
|
3370
|
+
return this.savefiles(uri, true, saFormData);
|
|
3333
3371
|
};
|
|
3334
3372
|
/**
|
|
3335
3373
|
* upload content
|
|
3336
3374
|
* @param uri key
|
|
3337
3375
|
* @param bysize true if registering with specified size
|
|
3338
3376
|
* @param filename attachment file name
|
|
3339
|
-
* @param arrayBuffer content (for batch)
|
|
3377
|
+
* @param arrayBuffer content (for batch or server action)
|
|
3340
3378
|
* @return message
|
|
3341
3379
|
*/
|
|
3342
3380
|
putcontent = async (uri, filename, arrayBuffer) => {
|
|
@@ -3347,7 +3385,7 @@ class VtecxNext {
|
|
|
3347
3385
|
* @param uri key
|
|
3348
3386
|
* @param bysize true if registering with specified size
|
|
3349
3387
|
* @param filename attachment file name
|
|
3350
|
-
* @param arrayBuffer content (for batch)
|
|
3388
|
+
* @param arrayBuffer content (for batch or server action)
|
|
3351
3389
|
* @return message
|
|
3352
3390
|
*/
|
|
3353
3391
|
putcontentProc = async (uri, bysize, filename, arrayBuffer) => {
|
|
@@ -3365,14 +3403,13 @@ class VtecxNext {
|
|
|
3365
3403
|
if (filename) {
|
|
3366
3404
|
headers['Content-Disposition'] = `attachment; filename="${encodeURIComponent(filename)}"`;
|
|
3367
3405
|
}
|
|
3368
|
-
//const buf = await buffer(this.req)
|
|
3369
3406
|
let buf;
|
|
3370
|
-
if (
|
|
3371
|
-
buf = arrayBuffer;
|
|
3372
|
-
}
|
|
3373
|
-
else if (this.req) {
|
|
3407
|
+
if (this.req) {
|
|
3374
3408
|
buf = await this.req.arrayBuffer();
|
|
3375
3409
|
}
|
|
3410
|
+
else if (arrayBuffer) {
|
|
3411
|
+
buf = arrayBuffer;
|
|
3412
|
+
}
|
|
3376
3413
|
let response;
|
|
3377
3414
|
try {
|
|
3378
3415
|
response = await this.requestVtecx(method, url, buf, headers);
|
|
@@ -3390,21 +3427,23 @@ class VtecxNext {
|
|
|
3390
3427
|
/**
|
|
3391
3428
|
* upload content registering with specified size
|
|
3392
3429
|
* @param uri key
|
|
3430
|
+
* @param arrayBuffer file array buffer by server action
|
|
3393
3431
|
* @return message
|
|
3394
3432
|
*/
|
|
3395
|
-
putcontentBySize = async (uri) => {
|
|
3396
|
-
return this.putcontentProc(uri, true);
|
|
3433
|
+
putcontentBySize = async (uri, arrayBuffer) => {
|
|
3434
|
+
return this.putcontentProc(uri, true, undefined, arrayBuffer);
|
|
3397
3435
|
};
|
|
3398
3436
|
/**
|
|
3399
3437
|
* upload content and numbering
|
|
3400
3438
|
* @param parenturi parent key
|
|
3401
3439
|
* @param extension extension
|
|
3402
3440
|
* @param filename attachment file name
|
|
3441
|
+
* @param arrayBuffer file array buffer by server action
|
|
3403
3442
|
* @return numbered key
|
|
3404
3443
|
*/
|
|
3405
|
-
postcontent = async (parenturi, extension, filename) => {
|
|
3444
|
+
postcontent = async (parenturi, extension, filename, arrayBuffer) => {
|
|
3406
3445
|
//console.log(`[vtecxnext postcontent] start. parenturi=${parenturi} extension=${extension} filename=${filename}`)
|
|
3407
|
-
if (!this.req) {
|
|
3446
|
+
if (!this.req && !arrayBuffer) {
|
|
3408
3447
|
throw new VtecxNextError(421, 'Request is required.');
|
|
3409
3448
|
}
|
|
3410
3449
|
// キー入力値チェック
|
|
@@ -3413,12 +3452,18 @@ class VtecxNext {
|
|
|
3413
3452
|
const method = 'POST';
|
|
3414
3453
|
const url = `${SERVLETPATH_PROVIDER}${parenturi}?_content${extension ? '&_ext=' + extension : ''}`;
|
|
3415
3454
|
//console.log(`[vtecxnext postcontent] request. url=${url}`)
|
|
3416
|
-
const headers = { 'Content-Type': this.req
|
|
3455
|
+
const headers = { 'Content-Type': this.req?.headers.get('content-type') };
|
|
3417
3456
|
if (filename) {
|
|
3418
3457
|
headers['Content-Disposition'] = `attachment; filename="${encodeURIComponent(filename)}"`;
|
|
3419
3458
|
}
|
|
3420
3459
|
//const buf = await buffer(this.req)
|
|
3421
|
-
|
|
3460
|
+
let buf;
|
|
3461
|
+
if (this.req) {
|
|
3462
|
+
buf = await this.req.arrayBuffer();
|
|
3463
|
+
}
|
|
3464
|
+
else if (arrayBuffer) {
|
|
3465
|
+
buf = arrayBuffer;
|
|
3466
|
+
}
|
|
3422
3467
|
let response;
|
|
3423
3468
|
try {
|
|
3424
3469
|
response = await this.requestVtecx(method, url, buf, headers);
|
|
@@ -3730,7 +3775,7 @@ class VtecxNext {
|
|
|
3730
3775
|
/**
|
|
3731
3776
|
* Merge an existing user with an line oauth user.
|
|
3732
3777
|
* @param rxid RXID
|
|
3733
|
-
* @return
|
|
3778
|
+
* @return user entry
|
|
3734
3779
|
*/
|
|
3735
3780
|
mergeOAuthUserLine = async (rxid) => {
|
|
3736
3781
|
//console.log(`[vtecxnext mergeOAuthUserLine] start. feed=${feed}`)
|
|
@@ -3855,7 +3900,7 @@ class VtecxNext {
|
|
|
3855
3900
|
*/
|
|
3856
3901
|
requestVtecx = async (method, url, body, additionalHeaders, targetService, mode) => {
|
|
3857
3902
|
// cookieの値をvte.cxへのリクエストヘッダに設定
|
|
3858
|
-
const cookie = this.editRequestCookie();
|
|
3903
|
+
const cookie = await this.editRequestCookie();
|
|
3859
3904
|
//console.log(`[requestVtecx] cookie = ${cookie}`)
|
|
3860
3905
|
const headers = cookie ? { Cookie: cookie } : {};
|
|
3861
3906
|
if (this.accessToken) {
|
|
@@ -3894,11 +3939,62 @@ class VtecxNext {
|
|
|
3894
3939
|
* @param response vte.cxからのレスポンス
|
|
3895
3940
|
*/
|
|
3896
3941
|
setCookie = (response) => {
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3942
|
+
try {
|
|
3943
|
+
// set-cookieの値をレスポンスヘッダ格納変数にセット
|
|
3944
|
+
let setCookieVal = response.headers.get('set-cookie');
|
|
3945
|
+
if (setCookieVal === '' || setCookieVal) {
|
|
3946
|
+
//console.log(`[vtecxnext setCookie] setCookieVal=${setCookieVal}`)
|
|
3947
|
+
this.resHeaders['set-cookie'] = setCookieVal;
|
|
3948
|
+
if (this.cookieStore) {
|
|
3949
|
+
// server action用
|
|
3950
|
+
//console.log(`[vtecxnext setCookie] server action用`)
|
|
3951
|
+
const idx = setCookieVal.indexOf('=');
|
|
3952
|
+
const name = setCookieVal.substring(0, idx);
|
|
3953
|
+
const parts = setCookieVal.substring(idx + 1).split(';');
|
|
3954
|
+
// 最初は値
|
|
3955
|
+
const value = parts[0];
|
|
3956
|
+
const options = {
|
|
3957
|
+
'name': name,
|
|
3958
|
+
'value': value
|
|
3959
|
+
};
|
|
3960
|
+
const len = parts.length;
|
|
3961
|
+
for (let i = 1; i < len; i++) {
|
|
3962
|
+
const tmp = parts[i].trim();
|
|
3963
|
+
const tmpIdx = tmp.indexOf('=');
|
|
3964
|
+
let tmpName;
|
|
3965
|
+
let tmpVal;
|
|
3966
|
+
if (tmpIdx > 0) {
|
|
3967
|
+
tmpName = tmp.substring(0, tmpIdx);
|
|
3968
|
+
tmpVal = tmp.substring(tmpIdx + 1);
|
|
3969
|
+
}
|
|
3970
|
+
else {
|
|
3971
|
+
tmpName = tmp;
|
|
3972
|
+
tmpVal = '';
|
|
3973
|
+
}
|
|
3974
|
+
// 先頭を小文字にする
|
|
3975
|
+
tmpName = `${tmpName.substring(0, 1).toLocaleLowerCase()}${tmpName.substring(1)}`;
|
|
3976
|
+
if (tmpName === 'expires') {
|
|
3977
|
+
options['expires'] = new Date(tmpVal);
|
|
3978
|
+
}
|
|
3979
|
+
else if (tmpName === 'maxAge' || tmpName === 'max-Age') {
|
|
3980
|
+
options['maxAge'] = Number(tmpVal);
|
|
3981
|
+
}
|
|
3982
|
+
else if (tmpVal === '') {
|
|
3983
|
+
options[tmpName] = true;
|
|
3984
|
+
}
|
|
3985
|
+
else {
|
|
3986
|
+
options[tmpName] = tmpVal;
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
//console.log(`[vtecxnext setCookie] options=${JSON.stringify(options)}`)
|
|
3990
|
+
this.cookieStore.set(options);
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3994
|
+
catch (e) {
|
|
3995
|
+
// Server Componentで実行された場合「Cookies can only be modified in a Server Action or Route Handler.」エラーが発生する。
|
|
3996
|
+
//console.log(`[vtecxnext setCookie] Error occured. ${e}`)
|
|
3997
|
+
// Do nothing.
|
|
3902
3998
|
}
|
|
3903
3999
|
};
|
|
3904
4000
|
/**
|
|
@@ -3920,7 +4016,8 @@ class VtecxNext {
|
|
|
3920
4016
|
* ログイン後のCookie編集
|
|
3921
4017
|
* @returns cookie
|
|
3922
4018
|
*/
|
|
3923
|
-
editRequestCookie = () => {
|
|
4019
|
+
editRequestCookie = async () => {
|
|
4020
|
+
//console.log(`[editRequestCookie] start.`)
|
|
3924
4021
|
let cookie = this.req ? this.req.headers.get('cookie') : null;
|
|
3925
4022
|
if (!this.loginCookies) {
|
|
3926
4023
|
return cookie;
|
|
@@ -3934,8 +4031,31 @@ class VtecxNext {
|
|
|
3934
4031
|
const tmpVal = tmpKeyVal[1];
|
|
3935
4032
|
if (!this.loginCookies.hasOwnProperty(tmpName)) {
|
|
3936
4033
|
retCookie = `${retCookie}${tmpName}=${tmpVal}; `;
|
|
3937
|
-
|
|
3938
|
-
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
else {
|
|
4038
|
+
if (this.shouldBeCreatedCookieStore) {
|
|
4039
|
+
//console.log(`[editRequestCookie] shouldBeCreatedCookieStore === true`)
|
|
4040
|
+
try {
|
|
4041
|
+
this.cookieStore = await (0, headers_1.cookies)();
|
|
4042
|
+
}
|
|
4043
|
+
catch (e) {
|
|
4044
|
+
// Do nothing.
|
|
4045
|
+
//console.log(`[editRequestCookie] Error occured by await cookies() : ${e}`)
|
|
4046
|
+
}
|
|
4047
|
+
this.shouldBeCreatedCookieStore = false;
|
|
4048
|
+
}
|
|
4049
|
+
if (this.cookieStore) {
|
|
4050
|
+
//console.log(`[editRequestCookie] this.cookieStore === true. ${JSON.stringify(this.cookieStore)}`)
|
|
4051
|
+
// server action用
|
|
4052
|
+
const cookieArray = this.cookieStore.getAll();
|
|
4053
|
+
if (cookieArray && cookieArray.length > 0) {
|
|
4054
|
+
for (const tmpCookie of cookieArray) {
|
|
4055
|
+
if (!this.loginCookies.hasOwnProperty(tmpCookie.name)) {
|
|
4056
|
+
retCookie = `${retCookie}${tmpCookie.name}=${tmpCookie.value}; `;
|
|
4057
|
+
}
|
|
4058
|
+
}
|
|
3939
4059
|
}
|
|
3940
4060
|
}
|
|
3941
4061
|
}
|
|
@@ -4028,9 +4148,13 @@ class VtecxNext {
|
|
|
4028
4148
|
throw new VtecxNextError(421, 'Request is required.');
|
|
4029
4149
|
}
|
|
4030
4150
|
// stateチェック
|
|
4031
|
-
const parseUrl =
|
|
4032
|
-
const state = parseUrl.query.state
|
|
4033
|
-
const code = parseUrl.query.code
|
|
4151
|
+
//const parseUrl = urlmodule.parse(this.req.url ?? '', true)
|
|
4152
|
+
//const state = parseUrl.query.state
|
|
4153
|
+
//const code = parseUrl.query.code
|
|
4154
|
+
const url = this.req.nextUrl;
|
|
4155
|
+
const searchParams = url.searchParams;
|
|
4156
|
+
const state = searchParams.get('state');
|
|
4157
|
+
const code = searchParams.get('code');
|
|
4034
4158
|
if (!state) {
|
|
4035
4159
|
throw new VtecxNextError(401, `Could not get state on redirect.`);
|
|
4036
4160
|
}
|
|
@@ -4195,7 +4319,7 @@ class VtecxNext {
|
|
|
4195
4319
|
* Merge an existing user with an oauth user.
|
|
4196
4320
|
* @param provider OAuth provider name
|
|
4197
4321
|
* @param rxid RXID
|
|
4198
|
-
* @return
|
|
4322
|
+
* @return user entry
|
|
4199
4323
|
*/
|
|
4200
4324
|
mergeOAuthUser = async (provider, rxid) => {
|
|
4201
4325
|
//console.log(`[vtecxnext mergeOAuthUser] start. feed=${feed}`)
|
|
@@ -4222,21 +4346,26 @@ class VtecxNext {
|
|
|
4222
4346
|
};
|
|
4223
4347
|
}
|
|
4224
4348
|
exports.VtecxNext = VtecxNext;
|
|
4225
|
-
|
|
4349
|
+
/*
|
|
4350
|
+
export type VtecxResponse {
|
|
4351
|
+
status: number
|
|
4352
|
+
header: any
|
|
4353
|
+
data: any
|
|
4354
|
+
constructor(status: number, header: any, data: any) {
|
|
4355
|
+
this.status = status
|
|
4356
|
+
this.header = header
|
|
4357
|
+
this.data = data
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
*/
|
|
4226
4361
|
/**
|
|
4227
|
-
* response
|
|
4362
|
+
* vtecx response create helper
|
|
4363
|
+
* @param status status
|
|
4364
|
+
* @param header header
|
|
4365
|
+
* @param data data
|
|
4366
|
+
* @returns vtecx response object
|
|
4228
4367
|
*/
|
|
4229
|
-
|
|
4230
|
-
status;
|
|
4231
|
-
header;
|
|
4232
|
-
data;
|
|
4233
|
-
constructor(status, header, data) {
|
|
4234
|
-
this.status = status;
|
|
4235
|
-
this.header = header;
|
|
4236
|
-
this.data = data;
|
|
4237
|
-
}
|
|
4238
|
-
}
|
|
4239
|
-
exports.VtecxResponse = VtecxResponse;
|
|
4368
|
+
const vtecxResponse = (status, header, data) => ({ status, header, data });
|
|
4240
4369
|
/**
|
|
4241
4370
|
* Error returned from vte.cx
|
|
4242
4371
|
*/
|
|
@@ -4432,7 +4561,7 @@ const checkContainSlash = (val, name) => {
|
|
|
4432
4561
|
*/
|
|
4433
4562
|
const checkUri = (str, name) => {
|
|
4434
4563
|
checkNotNull(str, name);
|
|
4435
|
-
if (!str
|
|
4564
|
+
if (!str?.startsWith('/')) {
|
|
4436
4565
|
throw new VtecxNextError(400, `${name ?? 'Key'} must start with a slash.`);
|
|
4437
4566
|
}
|
|
4438
4567
|
};
|
|
@@ -4586,7 +4715,56 @@ const getOrigin = (oauthUrl) => {
|
|
|
4586
4715
|
* @returns URLSearchParams
|
|
4587
4716
|
*/
|
|
4588
4717
|
const createURLSearchParams = (data) => {
|
|
4589
|
-
const params = new
|
|
4718
|
+
const params = new URLSearchParams();
|
|
4590
4719
|
Object.keys(data).forEach((key) => params.append(key, data[key]));
|
|
4591
4720
|
return params;
|
|
4592
4721
|
};
|
|
4722
|
+
/**
|
|
4723
|
+
* URIのパラメータ部分を連想配列にして返却
|
|
4724
|
+
* @param uri URI
|
|
4725
|
+
* @returns パラメータを連想配列にしたオブジェクト
|
|
4726
|
+
*/
|
|
4727
|
+
const getParamMap = (uri) => {
|
|
4728
|
+
if (!uri) {
|
|
4729
|
+
return {};
|
|
4730
|
+
}
|
|
4731
|
+
const idxQ = uri.indexOf('?');
|
|
4732
|
+
if (idxQ < 0) {
|
|
4733
|
+
return {};
|
|
4734
|
+
}
|
|
4735
|
+
const paramStr = uri.substring(idxQ + 1);
|
|
4736
|
+
if (!paramStr) {
|
|
4737
|
+
return {};
|
|
4738
|
+
}
|
|
4739
|
+
const params = {};
|
|
4740
|
+
const paramStrParts = paramStr.split('&');
|
|
4741
|
+
for (const paramStrPart of paramStrParts) {
|
|
4742
|
+
let name = '';
|
|
4743
|
+
let value = '';
|
|
4744
|
+
const idxE = paramStrPart.indexOf('=');
|
|
4745
|
+
if (idxE < 0) {
|
|
4746
|
+
name = paramStrPart;
|
|
4747
|
+
}
|
|
4748
|
+
else {
|
|
4749
|
+
name = paramStrPart.substring(0, idxE);
|
|
4750
|
+
value = paramStrPart.substring(idxE + 1);
|
|
4751
|
+
}
|
|
4752
|
+
params[name] = value;
|
|
4753
|
+
}
|
|
4754
|
+
return params;
|
|
4755
|
+
};
|
|
4756
|
+
/**
|
|
4757
|
+
* URIにカーソルを付加
|
|
4758
|
+
* @param uri URI
|
|
4759
|
+
* @param nextpage カーソル
|
|
4760
|
+
* @returns URIにカーソルを付加した文字列
|
|
4761
|
+
*/
|
|
4762
|
+
const addNextpage = (uri, nextpage) => {
|
|
4763
|
+
if (nextpage) {
|
|
4764
|
+
const rchar = uri.indexOf('?') < 0 ? '?' : '&';
|
|
4765
|
+
return `${uri}${rchar}${PARAM_NEXTPAGE}=${nextpage}`;
|
|
4766
|
+
}
|
|
4767
|
+
else {
|
|
4768
|
+
return uri;
|
|
4769
|
+
}
|
|
4770
|
+
};
|