@vtecx/vtecxnext 2.3.1 → 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.
@@ -4,6 +4,73 @@ import type { Readable } from 'node:stream';
4
4
  * Hello world.
5
5
  */
6
6
  export declare const hello: () => void;
7
+ /** Request feed */
8
+ export interface LegacyFeed {
9
+ feed: Feed;
10
+ }
11
+ /** Message response */
12
+ export interface MessageResponse {
13
+ feed: Feed;
14
+ }
15
+ /** Feed */
16
+ export interface Feed {
17
+ author?: Author[];
18
+ category?: Category[];
19
+ contributor?: Contributor[];
20
+ generator?: Generator;
21
+ icon?: string;
22
+ id?: string;
23
+ link?: Link[];
24
+ logo?: string;
25
+ rights?: string;
26
+ title?: string;
27
+ subtitle?: string;
28
+ updated?: string;
29
+ entry?: Entry[];
30
+ }
31
+ /** Entry */
32
+ export interface Entry {
33
+ author?: Author[];
34
+ category?: Category[];
35
+ content?: Content;
36
+ contributor?: Contributor[];
37
+ id?: string;
38
+ link?: Link[];
39
+ published?: string;
40
+ rights?: string;
41
+ summary?: string;
42
+ title?: string;
43
+ subtitle?: string;
44
+ updated?: string;
45
+ }
46
+ /** Author */
47
+ export interface Author {
48
+ name?: string;
49
+ uri?: string;
50
+ email?: string;
51
+ }
52
+ /** Category */
53
+ export interface Category {
54
+ ___term?: string;
55
+ ___scheme?: string;
56
+ ___label?: string;
57
+ }
58
+ /** Content */
59
+ export interface Content {
60
+ ______text: string;
61
+ }
62
+ /** Link */
63
+ export interface Link {
64
+ ___href?: string;
65
+ ___rel?: string;
66
+ ___title?: string;
67
+ }
68
+ /** Contributor */
69
+ export interface Contributor {
70
+ uri?: string;
71
+ email?: string;
72
+ name?: string;
73
+ }
7
74
  export type StatusMessage = {
8
75
  status: number;
9
76
  message: string;
@@ -34,8 +101,34 @@ export type ContentSignedUrl = {
34
101
  url: string;
35
102
  key: string;
36
103
  };
104
+ export interface OAuthInfo {
105
+ client_id?: string;
106
+ client_secret?: string;
107
+ redirect_uri?: string;
108
+ state?: string | string[];
109
+ access_token?: string;
110
+ }
111
+ export interface OAuthUserInfo {
112
+ guid?: string;
113
+ nickname?: string;
114
+ state?: string | string[];
115
+ }
116
+ /**
117
+ * vtecxnext.
118
+ * Executes various operations for the vte.cx service.
119
+ *
120
+ * The following environment variables must be defined.
121
+ *
122
+ * - VTECX_URL: URL of the vte.cx service
123
+ * - VTECX_APIKEY: API key
124
+ *
125
+ * When connecting to other vte.cx services, define the following environment variables.
126
+ *
127
+ * - SERVICEKEY_{service name}: Service key of the target service
128
+ *
129
+ */
37
130
  export declare class VtecxNext {
38
- /** Request */
131
+ /** Request (for api) */
39
132
  readonly req: NextRequest | undefined;
40
133
  /** Response status */
41
134
  private resStatus;
@@ -47,9 +140,13 @@ export declare class VtecxNext {
47
140
  private accessToken;
48
141
  /** login cookies */
49
142
  private loginCookies;
143
+ /** next cookies (for server action) */
144
+ private cookieStore;
145
+ /** flag whether the next cookies should be created */
146
+ private shouldBeCreatedCookieStore;
50
147
  /**
51
148
  * constructor
52
- * @param req Request
149
+ * @param req Request (for api)
53
150
  * @param accessToken Access token (for batch)
54
151
  */
55
152
  constructor(req?: NextRequest, accessToken?: string);
@@ -173,7 +270,7 @@ export declare class VtecxNext {
173
270
  * get login whoami
174
271
  * @return login user information
175
272
  */
176
- whoami: () => Promise<any>;
273
+ whoami: () => Promise<Entry[]>;
177
274
  /**
178
275
  * register a log entry
179
276
  * @param message message
@@ -188,21 +285,21 @@ export declare class VtecxNext {
188
285
  * @param targetService target service name (for service linkage)
189
286
  * @return entry
190
287
  */
191
- getEntry: (uri: string, targetService?: string) => Promise<any>;
288
+ getEntry: (uri: string, targetService?: string) => Promise<Entry | undefined>;
192
289
  /**
193
290
  * get feed
194
291
  * @param uri key and conditions
195
292
  * @param targetService target service name (for service linkage)
196
293
  * @return feed (entry array)
197
294
  */
198
- getFeed: (uri: string, targetService?: string) => Promise<any>;
295
+ getFeed: (uri: string, targetService?: string) => Promise<Entry[] | undefined>;
199
296
  /**
200
297
  * get feed
201
298
  * @param uri key and conditions
202
299
  * @param targetService target service name (for service linkage)
203
300
  * @return feed (entry array). Returns a cursor in the header if more data is available. (x-vtecx-nextpage)
204
301
  */
205
- getFeedResponse: (uri: string, targetService?: string) => Promise<VtecxResponse>;
302
+ getFeedResponse: (uri: string, targetService?: string) => Promise<VtecxResponse<Entry[] | undefined>>;
206
303
  /**
207
304
  * get count
208
305
  * @param uri key and conditions
@@ -216,7 +313,7 @@ export declare class VtecxNext {
216
313
  * @param targetService target service name (for service linkage)
217
314
  * @return feed. Returns a cursor in the header if more data is available. (x-vtecx-nextpage)
218
315
  */
219
- countResponse: (uri: string, targetService?: string) => Promise<VtecxResponse>;
316
+ countResponse: (uri: string, targetService?: string) => Promise<VtecxResponse<MessageResponse>>;
220
317
  /**
221
318
  * register entries
222
319
  * @param feed entries (JSON)
@@ -224,7 +321,7 @@ export declare class VtecxNext {
224
321
  * @param targetService target service name (for service linkage)
225
322
  * @return registed entries
226
323
  */
227
- post: (feed: any, uri?: string, targetService?: string) => Promise<any>;
324
+ post: (feed: Entry[], uri?: string, targetService?: string) => Promise<MessageResponse>;
228
325
  /**
229
326
  * update entries
230
327
  * @param feed entries (JSON)
@@ -234,7 +331,7 @@ export declare class VtecxNext {
234
331
  * @param targetService target service name (for service linkage)
235
332
  * @return updated entries
236
333
  */
237
- put: (feed: any, isbulk?: boolean, parallel?: boolean, async?: boolean, targetService?: string) => Promise<any>;
334
+ put: (feed: Entry[], isbulk?: boolean, parallel?: boolean, async?: boolean, targetService?: string) => Promise<Entry[] | MessageResponse>;
238
335
  /**
239
336
  * delete entry
240
337
  * @param uri key
@@ -252,7 +349,7 @@ export declare class VtecxNext {
252
349
  * @param targetService target service name (for service linkage)
253
350
  * @return true if successful
254
351
  */
255
- deleteEntries: (feed: any, isbulk?: boolean, parallel?: boolean, async?: boolean, targetService?: string) => Promise<boolean>;
352
+ deleteEntries: (feed: Entry[], isbulk?: boolean, parallel?: boolean, async?: boolean, targetService?: string) => Promise<boolean>;
256
353
  /**
257
354
  * delete folder
258
355
  * @param uri parent key
@@ -303,7 +400,7 @@ export declare class VtecxNext {
303
400
  /**
304
401
  * set a addition range
305
402
  * @param uri key
306
- * @param range addition range
403
+ * @param range addition range. delete if blank.
307
404
  * @param targetService target service name (for service linkage)
308
405
  * @return addition range
309
406
  */
@@ -314,21 +411,21 @@ export declare class VtecxNext {
314
411
  * @param targetService target service name (for service linkage)
315
412
  * @return addition range
316
413
  */
317
- getRangeids: (uri: string) => Promise<string>;
414
+ getRangeids: (uri: string) => Promise<string | undefined>;
318
415
  /**
319
416
  * set feed to session
320
417
  * @param name name
321
418
  * @param feed entries (JSON)
322
419
  * @return true if successful
323
420
  */
324
- setSessionFeed: (name: string, feed: any) => Promise<boolean>;
421
+ setSessionFeed: (name: string, feed: Entry[]) => Promise<boolean>;
325
422
  /**
326
423
  * set entry to session
327
424
  * @param name name
328
425
  * @param entry entry (JSON)
329
426
  * @return true if successful
330
427
  */
331
- setSessionEntry: (name: string, entry: any) => Promise<boolean>;
428
+ setSessionEntry: (name: string, entry: Entry) => Promise<boolean>;
332
429
  /**
333
430
  * set string to session
334
431
  * @param name name
@@ -379,13 +476,13 @@ export declare class VtecxNext {
379
476
  * @param name name
380
477
  * @return feed
381
478
  */
382
- getSessionFeed: (name: string) => Promise<any>;
479
+ getSessionFeed: (name: string) => Promise<Entry[] | undefined>;
383
480
  /**
384
481
  * get entry from session
385
482
  * @param name name
386
483
  * @return entry
387
484
  */
388
- getSessionEntry: (name: string) => Promise<any>;
485
+ getSessionEntry: (name: string) => Promise<Entry | undefined>;
389
486
  /**
390
487
  * get string from session
391
488
  * @param name name
@@ -413,7 +510,7 @@ export declare class VtecxNext {
413
510
  * @param targetService target service name (for service linkage)
414
511
  * @return feed (entry array)
415
512
  */
416
- getPage: (uri: string, num: number, targetService?: string) => Promise<any>;
513
+ getPage: (uri: string, num: number, targetService?: string) => Promise<Entry[] | undefined>;
417
514
  /**
418
515
  * practical paging
419
516
  * If you specify page 1, a new cursor list will be created.
@@ -422,7 +519,7 @@ export declare class VtecxNext {
422
519
  * @param targetService target service name (for service linkage)
423
520
  * @return feed (entry array)
424
521
  */
425
- getPageWithPagination: (uri: string, num: number, targetService?: string) => Promise<any>;
522
+ getPageWithPagination: (uri: string, num: number, targetService?: string) => Promise<Entry[] | undefined>;
426
523
  /**
427
524
  * ページングのカーソルリスト作成処理
428
525
  * 続きがある場合、次のカーソルリスト作成処理を実行する
@@ -439,7 +536,9 @@ export declare class VtecxNext {
439
536
  * @param tablenames key:entity's prop name, value:BigQuery table name
440
537
  * @return true if successful
441
538
  */
442
- postBQ: (feed: any, async?: boolean, tablenames?: any) => Promise<boolean>;
539
+ postBQ: (feed: Entry[], async?: boolean, tablenames?: {
540
+ [key: string]: string;
541
+ }) => Promise<boolean>;
443
542
  /**
444
543
  * delete data from bigquery
445
544
  * @param keys delete keys
@@ -447,7 +546,9 @@ export declare class VtecxNext {
447
546
  * @param tablenames key:entity's prop name, value:BigQuery table name
448
547
  * @return true if successful
449
548
  */
450
- deleteBQ: (keys: string[], async?: boolean, tablenames?: any) => Promise<boolean>;
549
+ deleteBQ: (keys: string[], async?: boolean, tablenames?: {
550
+ [key: string]: string;
551
+ }) => Promise<boolean>;
451
552
  /**
452
553
  * query bigquery
453
554
  * @param sql query sql
@@ -481,7 +582,9 @@ export declare class VtecxNext {
481
582
  * @param async execute async
482
583
  * @return registed entries
483
584
  */
484
- postBDBQ: (feed: any, uri?: string, tablenames?: any, async?: boolean) => Promise<any>;
585
+ postBDBQ: (feed: Entry[], uri?: string, tablenames?: {
586
+ [key: string]: string;
587
+ }, async?: boolean) => Promise<Entry[] | MessageResponse>;
485
588
  /**
486
589
  * put data to bdb and post bigquery
487
590
  * @param feed entries (JSON)
@@ -491,7 +594,9 @@ export declare class VtecxNext {
491
594
  * @param isbulk Forcibly execute even if it exceeds the upper limit of entries of request feed.
492
595
  * @return true if successful
493
596
  */
494
- putBDBQ: (feed: any, uri?: string, tablenames?: any, async?: boolean, isbulk?: boolean) => Promise<any>;
597
+ putBDBQ: (feed: Entry[], uri?: string, tablenames?: {
598
+ [key: string]: string;
599
+ }, async?: boolean, isbulk?: boolean) => Promise<Entry[] | MessageResponse>;
495
600
  /**
496
601
  * delete data from bdb and bigquery
497
602
  * @param keys delete keys
@@ -499,7 +604,9 @@ export declare class VtecxNext {
499
604
  * @param async execute async
500
605
  * @return true if successful
501
606
  */
502
- deleteBDBQ: (keys: string[], tablenames?: any, async?: boolean) => Promise<boolean>;
607
+ deleteBDBQ: (keys: string[], tablenames?: {
608
+ [key: string]: string;
609
+ }, async?: boolean) => Promise<boolean>;
503
610
  /**
504
611
  * Execute a query SQL to the database and get the result.
505
612
  * @param sql query sql
@@ -541,13 +648,13 @@ export declare class VtecxNext {
541
648
  * @param revision revision
542
649
  * @return signed entry
543
650
  */
544
- putSignature: (uri: string, revision?: number) => Promise<any>;
651
+ putSignature: (uri: string, revision?: number) => Promise<Entry>;
545
652
  /**
546
653
  * puts the signature of uri and revision.
547
654
  * @param feed entries
548
655
  * @return signed entries
549
656
  */
550
- putSignatures: (feed: any) => Promise<any>;
657
+ putSignatures: (feed: Entry[]) => Promise<Entry[]>;
551
658
  /**
552
659
  * delete the signature.
553
660
  * @param uri key
@@ -570,7 +677,7 @@ export declare class VtecxNext {
570
677
  * @param attachments keys of attachment files
571
678
  * @return true if successful
572
679
  */
573
- sendMail: (entry: any, to: string[], cc?: string[], bcc?: string[], attachments?: string[]) => Promise<boolean>;
680
+ sendMail: (entry: Entry, to: string[], cc?: string[], bcc?: string[], attachments?: string[]) => Promise<boolean>;
574
681
  /**
575
682
  * push notification to clients.
576
683
  * @param message message
@@ -581,7 +688,9 @@ export declare class VtecxNext {
581
688
  * @param data key value data (Expo)
582
689
  * @return true if successful
583
690
  */
584
- pushNotification: (message: string, to: string[], title?: string, subtitle?: string, imageUrl?: string, data?: any) => Promise<boolean>;
691
+ pushNotification: (message: string, to: string[], title?: string, subtitle?: string, imageUrl?: string, data?: {
692
+ [key: string]: string;
693
+ }) => Promise<boolean>;
585
694
  /**
586
695
  * set status of MessageQueue.
587
696
  * @param flag true if on, false if off
@@ -593,20 +702,20 @@ export declare class VtecxNext {
593
702
  * @param name name
594
703
  * @return feed
595
704
  */
596
- getMessageQueueStatus: (channel: string) => Promise<any>;
705
+ getMessageQueueStatus: (channel: string) => Promise<MessageResponse>;
597
706
  /**
598
707
  * set MessageQueue.
599
708
  * @param feed entries (JSON)
600
709
  * @param channel channel
601
710
  * @return true if successful
602
711
  */
603
- setMessageQueue: (feed: any, channel: string) => Promise<boolean>;
712
+ setMessageQueue: (feed: Entry[], channel: string) => Promise<boolean>;
604
713
  /**
605
714
  * get messageQueue.
606
715
  * @param name name
607
716
  * @return feed
608
717
  */
609
- getMessageQueue: (channel: string) => Promise<any>;
718
+ getMessageQueue: (channel: string) => Promise<Entry[] | undefined>;
610
719
  /**
611
720
  * add group
612
721
  * (not yet joined)
@@ -614,7 +723,7 @@ export declare class VtecxNext {
614
723
  * @param selfid hierarchical name under my group alias
615
724
  * @return feed
616
725
  */
617
- addGroup: (group: string, selfid?: string) => Promise<any>;
726
+ addGroup: (group: string, selfid?: string) => Promise<Entry>;
618
727
  /**
619
728
  * add group by admin
620
729
  * (not yet joined)
@@ -623,14 +732,14 @@ export declare class VtecxNext {
623
732
  * @param selfid hierarchical name under my group alias
624
733
  * @return feed
625
734
  */
626
- addGroupByAdmin: (uids: string[], group: string, selfid?: string) => Promise<any>;
735
+ addGroupByAdmin: (uids: string[], group: string, selfid?: string) => Promise<Entry[]>;
627
736
  /**
628
737
  * join to the group
629
738
  * @param group group
630
739
  * @param selfid hierarchical name under my group alias
631
740
  * @return feed
632
741
  */
633
- joinGroup: (group: string, selfid?: string) => Promise<any>;
742
+ joinGroup: (group: string, selfid?: string) => Promise<Entry>;
634
743
  /**
635
744
  * leave from the group
636
745
  * @param group group
@@ -643,14 +752,14 @@ export declare class VtecxNext {
643
752
  * @param group group
644
753
  * @return feed
645
754
  */
646
- leaveGroupByAdmin: (uids: string[], group: string) => Promise<any>;
755
+ leaveGroupByAdmin: (uids: string[], group: string) => Promise<Entry>;
647
756
  /**
648
757
  * Get entries that have entries in a group, but are not in the group.
649
758
  * (for entries with no signature or with an incorrect signature, if the user group requires a signature)
650
759
  * @param uri group key
651
760
  * @return feed (entry array)
652
761
  */
653
- noGroupMember: (uri: string) => Promise<any>;
762
+ noGroupMember: (uri: string) => Promise<Entry[]>;
654
763
  /**
655
764
  * Get groups
656
765
  * @param uri group key
@@ -674,7 +783,7 @@ export declare class VtecxNext {
674
783
  * @param reCaptchaToken reCAPTCHA token
675
784
  * @return message feed (uid)
676
785
  */
677
- adduser: (adduserInfo: AdduserInfo, reCaptchaToken: string) => Promise<any>;
786
+ adduser: (adduserInfo: AdduserInfo, reCaptchaToken: string) => Promise<MessageResponse>;
678
787
  /**
679
788
  * convert adduser info to argument entry
680
789
  * @param adduserInfo adduser info
@@ -687,60 +796,61 @@ export declare class VtecxNext {
687
796
  * @param feed entries (JSON)
688
797
  * @return message feed
689
798
  */
690
- adduserByAdmin: (adduserInfos: AdduserInfo[]) => Promise<any>;
799
+ adduserByAdmin: (adduserInfos: AdduserInfo[]) => Promise<MessageResponse>;
691
800
  /**
692
801
  * add user by group admin
693
802
  * @param feed entries (JSON)
694
803
  * @param groupname group name
695
804
  * @return message feed
696
805
  */
697
- adduserByGroupadmin: (adduserInfos: AdduserInfo[], groupname: string) => Promise<any>;
806
+ adduserByGroupadmin: (adduserInfos: AdduserInfo[], groupname: string) => Promise<MessageResponse>;
698
807
  /**
699
808
  * Send email for password reset
700
809
  * @param adduserInfo mailaddress
701
810
  * @param reCaptchaToken reCAPTCHA token
702
811
  * @return message feed
703
812
  */
704
- passreset: (adduserInfo: AdduserInfo, reCaptchaToken?: string) => Promise<any>;
813
+ passreset: (adduserInfo: AdduserInfo, reCaptchaToken?: string) => Promise<MessageResponse>;
705
814
  /**
706
815
  * change password
707
816
  * @param newpswd new password
708
817
  * @param oldpswd old password
709
818
  * @param passresetToken password reset token
819
+ * @param rxid RXID
710
820
  * @return message feed
711
821
  */
712
- changepass: (newpswd: string, oldpswd?: string, passresetToken?: string) => Promise<any>;
822
+ changepass: (newpswd: string, oldpswd?: string, passresetToken?: string, rxid?: string) => Promise<MessageResponse>;
713
823
  /**
714
824
  * change password by user admin
715
825
  * @param changepassByAdminInfos password change information (uid, password)
716
826
  * @return message feed
717
827
  */
718
- changepassByAdmin: (changepassByAdminInfos: ChangepassByAdminInfo[]) => Promise<any>;
828
+ changepassByAdmin: (changepassByAdminInfos: ChangepassByAdminInfo[]) => Promise<MessageResponse>;
719
829
  /**
720
830
  * change login user's account
721
831
  * @param adduserInfo change user info
722
832
  * @return message feed
723
833
  */
724
- changeaccount: (adduserInfo: AdduserInfo) => Promise<any>;
834
+ changeaccount: (adduserInfo: AdduserInfo) => Promise<MessageResponse>;
725
835
  /**
726
836
  * verify to change login user's account
727
837
  * @param verifyCode verify code
728
838
  * @return message feed
729
839
  */
730
- changeaccount_verify: (verifyCode: string) => Promise<any>;
840
+ changeaccount_verify: (verifyCode: string) => Promise<MessageResponse>;
731
841
  /**
732
842
  * get user status
733
843
  * @param account account
734
844
  * @return user status
735
845
  */
736
- userstatus: (account?: string) => Promise<string | any>;
846
+ userstatus: (account?: string) => Promise<string | Entry[]>;
737
847
  /**
738
848
  * revoke user
739
849
  * @param account account
740
850
  * @param isDeleteGroups true if delete groups
741
851
  * @return message feed
742
852
  */
743
- revokeuser: (account: string, isDeleteGroups?: boolean) => Promise<any>;
853
+ revokeuser: (account: string, isDeleteGroups?: boolean) => Promise<Entry>;
744
854
  /**
745
855
  * revoke users
746
856
  * @param accounts account list
@@ -748,63 +858,63 @@ export declare class VtecxNext {
748
858
  * @param isDeleteGroups true if delete groups
749
859
  * @return message feed
750
860
  */
751
- revokeusers: (accounts?: string[], uids?: string[], isDeleteGroups?: boolean) => Promise<any>;
861
+ revokeusers: (accounts?: string[], uids?: string[], isDeleteGroups?: boolean) => Promise<Entry[]>;
752
862
  /**
753
863
  * activate user
754
864
  * @param account account
755
865
  * @return message feed
756
866
  */
757
- activateuser: (account: string) => Promise<any>;
867
+ activateuser: (account: string) => Promise<Entry>;
758
868
  /**
759
869
  * activate users
760
870
  * @param accounts account list
761
871
  * @param uids uid list
762
872
  * @return message feed
763
873
  */
764
- activateusers: (accounts?: string[], uids?: string[]) => Promise<any>;
874
+ activateusers: (accounts?: string[], uids?: string[]) => Promise<Entry[]>;
765
875
  /**
766
876
  * cancel user.
767
877
  * @param isDeleteGroups true if delete groups
768
878
  * @return message feed
769
879
  */
770
- canceluser: (isDeleteGroups?: boolean) => Promise<any>;
880
+ canceluser: (isDeleteGroups?: boolean) => Promise<MessageResponse>;
771
881
  /**
772
882
  * delete user
773
883
  * @param account account
774
884
  * @return message feed
775
885
  */
776
- deleteuser: (account: string) => Promise<any>;
886
+ deleteuser: (account: string) => Promise<MessageResponse>;
777
887
  /**
778
888
  * revoke users
779
889
  * @param accounts account list
780
890
  * @param uids uid list
781
891
  * @return message feed
782
892
  */
783
- deleteusers: (accounts?: string[], uids?: string[]) => Promise<any>;
893
+ deleteusers: (accounts?: string[], uids?: string[]) => Promise<MessageResponse>;
784
894
  /**
785
895
  * add acl
786
896
  * @param feed entries
787
897
  * @return message
788
898
  */
789
- addacl: (feed: any) => Promise<any>;
899
+ addacl: (feed: Entry[]) => Promise<MessageResponse>;
790
900
  /**
791
901
  * remove acl
792
902
  * @param feed entries
793
903
  * @return message
794
904
  */
795
- removeacl: (feed: any) => Promise<any>;
905
+ removeacl: (feed: Entry[]) => Promise<MessageResponse>;
796
906
  /**
797
907
  * add alias
798
908
  * @param feed entries
799
909
  * @return message
800
910
  */
801
- addalias: (feed: any) => Promise<any>;
911
+ addalias: (feed: Entry[]) => Promise<MessageResponse>;
802
912
  /**
803
913
  * remove alias
804
914
  * @param feed entries
805
915
  * @return message
806
916
  */
807
- removealias: (feed: any) => Promise<any>;
917
+ removealias: (feed: Entry[]) => Promise<MessageResponse>;
808
918
  /**
809
919
  * get content url.
810
920
  * @param uri key
@@ -815,53 +925,57 @@ export declare class VtecxNext {
815
925
  * save files
816
926
  * @param uri key
817
927
  * @param bysize true if registering with specified size
928
+ * @param saFormData formData by server action
818
929
  * @returns message
819
930
  */
820
- savefiles: (uri: string, bysize?: boolean) => Promise<any>;
931
+ savefiles: (uri: string, bysize?: boolean, saFormData?: FormData) => Promise<MessageResponse>;
821
932
  /**
822
933
  * save files registering with specified size
823
934
  * @param uri key
935
+ * @param saFormData formData by server action
824
936
  * @returns message
825
937
  */
826
- savefilesBySize: (uri: string) => Promise<any>;
938
+ savefilesBySize: (uri: string, saFormData?: FormData) => Promise<MessageResponse>;
827
939
  /**
828
940
  * upload content
829
941
  * @param uri key
830
942
  * @param bysize true if registering with specified size
831
943
  * @param filename attachment file name
832
- * @param arrayBuffer content (for batch)
944
+ * @param arrayBuffer content (for batch or server action)
833
945
  * @return message
834
946
  */
835
- putcontent: (uri: string, filename?: string, arrayBuffer?: ArrayBuffer) => Promise<any>;
947
+ putcontent: (uri: string, filename?: string, arrayBuffer?: ArrayBuffer) => Promise<Entry[]>;
836
948
  /**
837
949
  * upload content
838
950
  * @param uri key
839
951
  * @param bysize true if registering with specified size
840
952
  * @param filename attachment file name
841
- * @param arrayBuffer content (for batch)
953
+ * @param arrayBuffer content (for batch or server action)
842
954
  * @return message
843
955
  */
844
956
  private putcontentProc;
845
957
  /**
846
958
  * upload content registering with specified size
847
959
  * @param uri key
960
+ * @param arrayBuffer file array buffer by server action
848
961
  * @return message
849
962
  */
850
- putcontentBySize: (uri: string) => Promise<any>;
963
+ putcontentBySize: (uri: string, arrayBuffer?: ArrayBuffer) => Promise<Entry[]>;
851
964
  /**
852
965
  * upload content and numbering
853
966
  * @param parenturi parent key
854
967
  * @param extension extension
855
968
  * @param filename attachment file name
969
+ * @param arrayBuffer file array buffer by server action
856
970
  * @return numbered key
857
971
  */
858
- postcontent: (parenturi: string, extension?: string, filename?: string) => Promise<any>;
972
+ postcontent: (parenturi: string, extension?: string, filename?: string, arrayBuffer?: ArrayBuffer) => Promise<Entry[]>;
859
973
  /**
860
974
  * delete content
861
975
  * @param uri key
862
976
  * @return message
863
977
  */
864
- deletecontent: (uri: string) => Promise<any>;
978
+ deletecontent: (uri: string) => Promise<Entry>;
865
979
  /**
866
980
  * get content.
867
981
  * Writes a content to the response.
@@ -903,44 +1017,44 @@ export declare class VtecxNext {
903
1017
  * @param chs length of one side of QR code
904
1018
  * @return QR code URL in feed.title
905
1019
  */
906
- getTotpLink: (chs?: number) => Promise<any>;
1020
+ getTotpLink: (chs?: number) => Promise<Entry[]>;
907
1021
  /**
908
1022
  * create TOTP
909
1023
  * @param feed one-time password for feed.title when you do book registration
910
1024
  * @return message
911
1025
  */
912
- createTotp: (feed: any) => Promise<any>;
1026
+ createTotp: (feed: LegacyFeed) => Promise<MessageResponse>;
913
1027
  /**
914
1028
  * delete TOTP
915
1029
  * @param account target account (for service admin user)
916
1030
  * @return message
917
1031
  */
918
- deleteTotp: (account?: string) => Promise<any>;
1032
+ deleteTotp: (account?: string) => Promise<MessageResponse>;
919
1033
  /**
920
1034
  * change TDID (Trusted device ID)
921
1035
  * @param account target account (for service admin user)
922
1036
  * @return message
923
1037
  */
924
- changeTdid: () => Promise<any>;
1038
+ changeTdid: () => Promise<MessageResponse>;
925
1039
  /**
926
1040
  * Merge an existing user with an line oauth user.
927
1041
  * @param rxid RXID
928
- * @return message feed
1042
+ * @return user entry
929
1043
  */
930
- mergeOAuthUserLine: (rxid: string) => Promise<any>;
1044
+ mergeOAuthUserLine: (rxid: string) => Promise<Entry>;
931
1045
  /**
932
1046
  * create group admin
933
1047
  * @param CreateGroupadminInfo group name and uid list
934
1048
  * @return message feed
935
1049
  */
936
- createGroupadmin: (createGroupadminInfos: CreateGroupadminInfo[]) => Promise<any>;
1050
+ createGroupadmin: (createGroupadminInfos: CreateGroupadminInfo[]) => Promise<MessageResponse>;
937
1051
  /**
938
1052
  * delete group admin group
939
1053
  * @param groupNames group name list
940
1054
  * @param async execute async
941
1055
  * @return message feed
942
1056
  */
943
- deleteGroupadmin: (groupNames: string[], async?: boolean) => Promise<any>;
1057
+ deleteGroupadmin: (groupNames: string[], async?: boolean) => Promise<MessageResponse>;
944
1058
  /**
945
1059
  * get property
946
1060
  * @param name property name
@@ -1012,19 +1126,18 @@ export declare class VtecxNext {
1012
1126
  * Merge an existing user with an oauth user.
1013
1127
  * @param provider OAuth provider name
1014
1128
  * @param rxid RXID
1015
- * @return message feed
1129
+ * @return user entry
1016
1130
  */
1017
1131
  private mergeOAuthUser;
1018
1132
  }
1019
1133
  /**
1020
1134
  * response class
1021
1135
  */
1022
- export declare class VtecxResponse {
1136
+ export type VtecxResponse<T = unknown> = {
1023
1137
  status: number;
1024
- header: any;
1025
- data: any;
1026
- constructor(status: number, header: any, data: any);
1027
- }
1138
+ header: Record<string, string>;
1139
+ data: T;
1140
+ };
1028
1141
  /**
1029
1142
  * Error returned from vte.cx
1030
1143
  */
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.VtecxResponse = exports.VtecxNext = exports.hello = void 0;
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
  */
@@ -61,8 +28,22 @@ const PAGINATION_NUM = 7;
61
28
  const MEMORYSORT = 'memorysort';
62
29
  /** parameter : nextpage */
63
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
+ */
64
45
  class VtecxNext {
65
- /** Request */
46
+ /** Request (for api) */
66
47
  req;
67
48
  /** Response status */
68
49
  resStatus = 200;
@@ -74,14 +55,19 @@ class VtecxNext {
74
55
  accessToken;
75
56
  /** login cookies */
76
57
  loginCookies = {};
58
+ /** next cookies (for server action) */
59
+ cookieStore; // ReadonlyRequestCookies
60
+ /** flag whether the next cookies should be created */
61
+ shouldBeCreatedCookieStore = true;
77
62
  /**
78
63
  * constructor
79
- * @param req Request
64
+ * @param req Request (for api)
80
65
  * @param accessToken Access token (for batch)
81
66
  */
82
67
  constructor(req, accessToken) {
83
68
  if (req) {
84
69
  this.req = req;
70
+ this.shouldBeCreatedCookieStore = false;
85
71
  }
86
72
  else {
87
73
  this.req = undefined;
@@ -321,6 +307,7 @@ class VtecxNext {
321
307
  await checkVtecxResponse(response);
322
308
  // 戻り値
323
309
  const data = await getJson(response);
310
+ //console.log(`[vtecxnext account] data = ${JSON.stringify(data)}`)
324
311
  return data.feed.title;
325
312
  };
326
313
  /**
@@ -613,12 +600,13 @@ class VtecxNext {
613
600
  await checkVtecxResponse(response);
614
601
  // 戻り値
615
602
  const data = await getJson(response);
616
- const header = {};
603
+ let header = undefined;
617
604
  const nextpage = response.headers.get(HEADER_NEXTPAGE);
618
605
  if (nextpage) {
606
+ header = {};
619
607
  header[HEADER_NEXTPAGE] = nextpage;
620
608
  }
621
- return new VtecxResponse(response.status, header, data);
609
+ return vtecxResponse(response.status, header, data);
622
610
  };
623
611
  /**
624
612
  * get count
@@ -650,7 +638,7 @@ class VtecxNext {
650
638
  else {
651
639
  cnt += Number(data.feed.title);
652
640
  }
653
- if (vtecxRes.header.hasOwnProperty(HEADER_NEXTPAGE)) {
641
+ if (vtecxRes.header?.hasOwnProperty(HEADER_NEXTPAGE)) {
654
642
  nextpage = vtecxRes.header[HEADER_NEXTPAGE];
655
643
  //console.log(`[vtecxnext count] ${HEADER_NEXTPAGE}=${nextpage}`)
656
644
  }
@@ -685,12 +673,13 @@ class VtecxNext {
685
673
  await checkVtecxResponse(response);
686
674
  // 戻り値
687
675
  const data = await getJson(response);
688
- const header = {};
676
+ let header = undefined;
689
677
  const nextpage = response.headers.get(HEADER_NEXTPAGE);
690
678
  if (nextpage) {
679
+ header = {};
691
680
  header[HEADER_NEXTPAGE] = nextpage;
692
681
  }
693
- return new VtecxResponse(response.status, header, data);
682
+ return vtecxResponse(response.status, header, data);
694
683
  };
695
684
  /**
696
685
  * register entries
@@ -1043,7 +1032,7 @@ class VtecxNext {
1043
1032
  /**
1044
1033
  * set a addition range
1045
1034
  * @param uri key
1046
- * @param range addition range
1035
+ * @param range addition range. delete if blank.
1047
1036
  * @param targetService target service name (for service linkage)
1048
1037
  * @return addition range
1049
1038
  */
@@ -1051,7 +1040,7 @@ class VtecxNext {
1051
1040
  //console.log(`[vtecxnext rangeids] start. range=${range}`)
1052
1041
  // 入力値チェック
1053
1042
  checkUri(uri);
1054
- checkNotNull(range, 'range');
1043
+ //checkNotNull(range, 'range') // 空の場合加算枠削除
1055
1044
  // vte.cxへリクエスト
1056
1045
  const method = 'PUT';
1057
1046
  const url = `${SERVLETPATH_PROVIDER}${uri}?_rangeids`;
@@ -1070,7 +1059,12 @@ class VtecxNext {
1070
1059
  await checkVtecxResponse(response);
1071
1060
  // 戻り値
1072
1061
  const data = await getJson(response);
1073
- return data.feed.title;
1062
+ if (data.feed?.title) {
1063
+ return data.feed.title;
1064
+ }
1065
+ else {
1066
+ return '';
1067
+ }
1074
1068
  };
1075
1069
  /**
1076
1070
  * get a addition range
@@ -1099,7 +1093,8 @@ class VtecxNext {
1099
1093
  await checkVtecxResponse(response);
1100
1094
  // 戻り値
1101
1095
  const data = await getJson(response);
1102
- return data.feed.title;
1096
+ //console.log(`[vtecxnext getRangeids] status=${String(response.status)} data=${JSON.stringify(data)}`)
1097
+ return data.feed?.title;
1103
1098
  };
1104
1099
  /**
1105
1100
  * set feed to session
@@ -1135,14 +1130,14 @@ class VtecxNext {
1135
1130
  * @return true if successful
1136
1131
  */
1137
1132
  setSessionEntry = async (name, entry) => {
1138
- //console.log(`[vtecxnext setSessionEntry] start. name=${name} entry=${entry}`)
1133
+ //console.log(`[vtecxnext setSessionEntry] start. name=${name} entry=${JSON.stringify(entry)}`)
1139
1134
  // 入力チェック
1140
1135
  checkNotNull(name, 'Name');
1141
1136
  checkNotNull(entry, 'Entry');
1142
1137
  // vte.cxへリクエスト
1143
1138
  const method = 'PUT';
1144
1139
  const url = `${SERVLETPATH_PROVIDER}/?_sessionentry=${name}`;
1145
- const feed = { feed: { entry: entry } };
1140
+ const feed = { feed: { entry: [entry] } };
1146
1141
  let response;
1147
1142
  try {
1148
1143
  response = await this.requestVtecx(method, url, JSON.stringify(feed));
@@ -1617,7 +1612,8 @@ class VtecxNext {
1617
1612
  // 入力チェック
1618
1613
  checkNotNull(feed, 'Feed');
1619
1614
  // リクエストデータ
1620
- 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 } };
1621
1617
  // テーブル名の指定がある場合は指定
1622
1618
  const tablenamesStr = editBqTableNames(tablenames);
1623
1619
  if (tablenamesStr) {
@@ -1692,7 +1688,7 @@ class VtecxNext {
1692
1688
  * @return query results in JSON format
1693
1689
  */
1694
1690
  getBQ = async (sql, values, parent) => {
1695
- return this.execBQ(sql, values);
1691
+ return this.execBQ(sql, values, parent);
1696
1692
  };
1697
1693
  /**
1698
1694
  * query bigquery
@@ -1786,7 +1782,7 @@ class VtecxNext {
1786
1782
  checkUri(uri);
1787
1783
  }
1788
1784
  // リクエストデータ
1789
- const reqFeed = 'feed' in feed ? feed : { feed: { entry: feed } };
1785
+ const reqFeed = { feed: { entry: feed } };
1790
1786
  // テーブル名の指定がある場合は指定
1791
1787
  const tablenamesStr = editBqTableNames(tablenames);
1792
1788
  if (tablenamesStr) {
@@ -1827,7 +1823,7 @@ class VtecxNext {
1827
1823
  checkUri(uri);
1828
1824
  }
1829
1825
  // リクエストデータ
1830
- const reqFeed = 'feed' in feed ? feed : { feed: { entry: feed } };
1826
+ const reqFeed = { feed: { entry: feed } };
1831
1827
  // テーブル名の指定がある場合は指定
1832
1828
  const tablenamesStr = editBqTableNames(tablenames);
1833
1829
  //console.log(`[putBDBQ] tableamesStr=${tablenamesStr}`)
@@ -2678,7 +2674,7 @@ class VtecxNext {
2678
2674
  * @returns entry
2679
2675
  */
2680
2676
  convertAdduserInfoToEntry = (adduserInfo, isNoPswd) => {
2681
- return {
2677
+ const retEntry = {
2682
2678
  contributor: [
2683
2679
  {
2684
2680
  uri: `urn:vte.cx:auth:${this.null2blank(adduserInfo.username)}${isNoPswd ? '' : ',' + this.null2blank(adduserInfo.pswd)}`,
@@ -2686,9 +2682,12 @@ class VtecxNext {
2686
2682
  }
2687
2683
  ],
2688
2684
  title: adduserInfo.emailSubject,
2689
- summary: adduserInfo.emailText,
2690
- content: { ______text: adduserInfo.emailHtml }
2685
+ summary: adduserInfo.emailText
2691
2686
  };
2687
+ if (adduserInfo.emailHtml) {
2688
+ retEntry.content = { ______text: adduserInfo.emailHtml };
2689
+ }
2690
+ return retEntry;
2692
2691
  };
2693
2692
  /**
2694
2693
  * add user by user admin
@@ -2789,9 +2788,10 @@ class VtecxNext {
2789
2788
  * @param newpswd new password
2790
2789
  * @param oldpswd old password
2791
2790
  * @param passresetToken password reset token
2791
+ * @param rxid RXID
2792
2792
  * @return message feed
2793
2793
  */
2794
- changepass = async (newpswd, oldpswd, passresetToken) => {
2794
+ changepass = async (newpswd, oldpswd, passresetToken, rxid) => {
2795
2795
  //console.log(`[vtecxnext changepass] start. feed=${feed}`)
2796
2796
  // 入力チェック
2797
2797
  checkNotNull(newpswd, 'new password');
@@ -2809,7 +2809,7 @@ class VtecxNext {
2809
2809
  const feed = [{ contributor: contributors }];
2810
2810
  // vte.cxへリクエスト
2811
2811
  const method = 'PUT';
2812
- const url = `${SERVLETPATH_DATA}/?_changephash`;
2812
+ const url = `${SERVLETPATH_DATA}/?_changephash${rxid ? '&_RXID=' + rxid : ''}`;
2813
2813
  let response;
2814
2814
  try {
2815
2815
  response = await this.requestVtecx(method, url, JSON.stringify(feed));
@@ -2830,7 +2830,7 @@ class VtecxNext {
2830
2830
  * @return message feed
2831
2831
  */
2832
2832
  changepassByAdmin = async (changepassByAdminInfos) => {
2833
- //console.log(`[vtecxnext changepassByAdmin] start. feed=${feed}`)
2833
+ //console.log(`[vtecxnext changepassByAdmin] start. changepassByAdminInfos=${JSON.stringify(changepassByAdminInfos)}`)
2834
2834
  // 入力チェック
2835
2835
  checkNotNull(changepassByAdminInfos, 'password change information');
2836
2836
  const feed = [];
@@ -3144,7 +3144,7 @@ class VtecxNext {
3144
3144
  * @return message feed
3145
3145
  */
3146
3146
  deleteusers = async (accounts, uids) => {
3147
- //console.log(`[vtecxnext deleteusers] start. feed=${feed}`)
3147
+ //console.log(`[vtecxnext deleteusers] start. accounts=${accounts ? JSON.stringify(accounts) : 'undefined'} uids=${uids ? JSON.stringify(uids) : 'undefined'}`)
3148
3148
  // 入力チェック
3149
3149
  if (isBlank(accounts) && isBlank(uids)) {
3150
3150
  throw new VtecxNextError(400, `account or uid is required.`);
@@ -3303,16 +3303,26 @@ class VtecxNext {
3303
3303
  * save files
3304
3304
  * @param uri key
3305
3305
  * @param bysize true if registering with specified size
3306
+ * @param saFormData formData by server action
3306
3307
  * @returns message
3307
3308
  */
3308
- savefiles = async (uri, bysize) => {
3309
+ savefiles = async (uri, bysize, saFormData) => {
3309
3310
  //console.log(`[vtecxnext savefiles] start. uri=${uri}`)
3310
- if (!this.req) {
3311
- throw new VtecxNextError(421, 'Request is required.');
3311
+ if (!this.req && !saFormData) {
3312
+ throw new VtecxNextError(421, 'Form data is required.');
3312
3313
  }
3313
3314
  // キー入力値チェック
3314
3315
  checkUri(uri);
3315
- const formData = await this.req.formData();
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
+ }
3316
3326
  const promiseKeyBuffers = [];
3317
3327
  const promises = [];
3318
3328
  // bufferの取得(非同期)
@@ -3353,17 +3363,18 @@ class VtecxNext {
3353
3363
  /**
3354
3364
  * save files registering with specified size
3355
3365
  * @param uri key
3366
+ * @param saFormData formData by server action
3356
3367
  * @returns message
3357
3368
  */
3358
- savefilesBySize = async (uri) => {
3359
- return this.savefiles(uri, true);
3369
+ savefilesBySize = async (uri, saFormData) => {
3370
+ return this.savefiles(uri, true, saFormData);
3360
3371
  };
3361
3372
  /**
3362
3373
  * upload content
3363
3374
  * @param uri key
3364
3375
  * @param bysize true if registering with specified size
3365
3376
  * @param filename attachment file name
3366
- * @param arrayBuffer content (for batch)
3377
+ * @param arrayBuffer content (for batch or server action)
3367
3378
  * @return message
3368
3379
  */
3369
3380
  putcontent = async (uri, filename, arrayBuffer) => {
@@ -3374,7 +3385,7 @@ class VtecxNext {
3374
3385
  * @param uri key
3375
3386
  * @param bysize true if registering with specified size
3376
3387
  * @param filename attachment file name
3377
- * @param arrayBuffer content (for batch)
3388
+ * @param arrayBuffer content (for batch or server action)
3378
3389
  * @return message
3379
3390
  */
3380
3391
  putcontentProc = async (uri, bysize, filename, arrayBuffer) => {
@@ -3392,14 +3403,13 @@ class VtecxNext {
3392
3403
  if (filename) {
3393
3404
  headers['Content-Disposition'] = `attachment; filename="${encodeURIComponent(filename)}"`;
3394
3405
  }
3395
- //const buf = await buffer(this.req)
3396
3406
  let buf;
3397
- if (arrayBuffer) {
3398
- buf = arrayBuffer;
3399
- }
3400
- else if (this.req) {
3407
+ if (this.req) {
3401
3408
  buf = await this.req.arrayBuffer();
3402
3409
  }
3410
+ else if (arrayBuffer) {
3411
+ buf = arrayBuffer;
3412
+ }
3403
3413
  let response;
3404
3414
  try {
3405
3415
  response = await this.requestVtecx(method, url, buf, headers);
@@ -3417,21 +3427,23 @@ class VtecxNext {
3417
3427
  /**
3418
3428
  * upload content registering with specified size
3419
3429
  * @param uri key
3430
+ * @param arrayBuffer file array buffer by server action
3420
3431
  * @return message
3421
3432
  */
3422
- putcontentBySize = async (uri) => {
3423
- return this.putcontentProc(uri, true);
3433
+ putcontentBySize = async (uri, arrayBuffer) => {
3434
+ return this.putcontentProc(uri, true, undefined, arrayBuffer);
3424
3435
  };
3425
3436
  /**
3426
3437
  * upload content and numbering
3427
3438
  * @param parenturi parent key
3428
3439
  * @param extension extension
3429
3440
  * @param filename attachment file name
3441
+ * @param arrayBuffer file array buffer by server action
3430
3442
  * @return numbered key
3431
3443
  */
3432
- postcontent = async (parenturi, extension, filename) => {
3444
+ postcontent = async (parenturi, extension, filename, arrayBuffer) => {
3433
3445
  //console.log(`[vtecxnext postcontent] start. parenturi=${parenturi} extension=${extension} filename=${filename}`)
3434
- if (!this.req) {
3446
+ if (!this.req && !arrayBuffer) {
3435
3447
  throw new VtecxNextError(421, 'Request is required.');
3436
3448
  }
3437
3449
  // キー入力値チェック
@@ -3440,12 +3452,18 @@ class VtecxNext {
3440
3452
  const method = 'POST';
3441
3453
  const url = `${SERVLETPATH_PROVIDER}${parenturi}?_content${extension ? '&_ext=' + extension : ''}`;
3442
3454
  //console.log(`[vtecxnext postcontent] request. url=${url}`)
3443
- const headers = { 'Content-Type': this.req.headers.get('content-type') };
3455
+ const headers = { 'Content-Type': this.req?.headers.get('content-type') };
3444
3456
  if (filename) {
3445
3457
  headers['Content-Disposition'] = `attachment; filename="${encodeURIComponent(filename)}"`;
3446
3458
  }
3447
3459
  //const buf = await buffer(this.req)
3448
- const buf = await this.req.arrayBuffer();
3460
+ let buf;
3461
+ if (this.req) {
3462
+ buf = await this.req.arrayBuffer();
3463
+ }
3464
+ else if (arrayBuffer) {
3465
+ buf = arrayBuffer;
3466
+ }
3449
3467
  let response;
3450
3468
  try {
3451
3469
  response = await this.requestVtecx(method, url, buf, headers);
@@ -3757,7 +3775,7 @@ class VtecxNext {
3757
3775
  /**
3758
3776
  * Merge an existing user with an line oauth user.
3759
3777
  * @param rxid RXID
3760
- * @return message feed
3778
+ * @return user entry
3761
3779
  */
3762
3780
  mergeOAuthUserLine = async (rxid) => {
3763
3781
  //console.log(`[vtecxnext mergeOAuthUserLine] start. feed=${feed}`)
@@ -3882,7 +3900,7 @@ class VtecxNext {
3882
3900
  */
3883
3901
  requestVtecx = async (method, url, body, additionalHeaders, targetService, mode) => {
3884
3902
  // cookieの値をvte.cxへのリクエストヘッダに設定
3885
- const cookie = this.editRequestCookie();
3903
+ const cookie = await this.editRequestCookie();
3886
3904
  //console.log(`[requestVtecx] cookie = ${cookie}`)
3887
3905
  const headers = cookie ? { Cookie: cookie } : {};
3888
3906
  if (this.accessToken) {
@@ -3921,11 +3939,62 @@ class VtecxNext {
3921
3939
  * @param response vte.cxからのレスポンス
3922
3940
  */
3923
3941
  setCookie = (response) => {
3924
- // set-cookieの値をレスポンスヘッダ格納変数にセット
3925
- let setCookieVal = response.headers.get('set-cookie');
3926
- if (setCookieVal === '' || setCookieVal) {
3927
- //console.log(`[vtecxnext setCookie] setCookieVal=${setCookieVal}`)
3928
- this.resHeaders['set-cookie'] = setCookieVal;
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.
3929
3998
  }
3930
3999
  };
3931
4000
  /**
@@ -3947,7 +4016,8 @@ class VtecxNext {
3947
4016
  * ログイン後のCookie編集
3948
4017
  * @returns cookie
3949
4018
  */
3950
- editRequestCookie = () => {
4019
+ editRequestCookie = async () => {
4020
+ //console.log(`[editRequestCookie] start.`)
3951
4021
  let cookie = this.req ? this.req.headers.get('cookie') : null;
3952
4022
  if (!this.loginCookies) {
3953
4023
  return cookie;
@@ -3961,8 +4031,31 @@ class VtecxNext {
3961
4031
  const tmpVal = tmpKeyVal[1];
3962
4032
  if (!this.loginCookies.hasOwnProperty(tmpName)) {
3963
4033
  retCookie = `${retCookie}${tmpName}=${tmpVal}; `;
3964
- //} else {
3965
- //console.log(`[editRequestCookie] hasOwnProperty (not set) : ${tmpName}=${tmpVal}`)
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
+ }
3966
4059
  }
3967
4060
  }
3968
4061
  }
@@ -4055,9 +4148,13 @@ class VtecxNext {
4055
4148
  throw new VtecxNextError(421, 'Request is required.');
4056
4149
  }
4057
4150
  // stateチェック
4058
- const parseUrl = url_1.default.parse(this.req.url ?? '', true);
4059
- const state = parseUrl.query.state;
4060
- 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');
4061
4158
  if (!state) {
4062
4159
  throw new VtecxNextError(401, `Could not get state on redirect.`);
4063
4160
  }
@@ -4222,7 +4319,7 @@ class VtecxNext {
4222
4319
  * Merge an existing user with an oauth user.
4223
4320
  * @param provider OAuth provider name
4224
4321
  * @param rxid RXID
4225
- * @return message feed
4322
+ * @return user entry
4226
4323
  */
4227
4324
  mergeOAuthUser = async (provider, rxid) => {
4228
4325
  //console.log(`[vtecxnext mergeOAuthUser] start. feed=${feed}`)
@@ -4249,21 +4346,26 @@ class VtecxNext {
4249
4346
  };
4250
4347
  }
4251
4348
  exports.VtecxNext = VtecxNext;
4252
- //---------------------------------------------
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
+ */
4253
4361
  /**
4254
- * response class
4362
+ * vtecx response create helper
4363
+ * @param status status
4364
+ * @param header header
4365
+ * @param data data
4366
+ * @returns vtecx response object
4255
4367
  */
4256
- class VtecxResponse {
4257
- status;
4258
- header;
4259
- data;
4260
- constructor(status, header, data) {
4261
- this.status = status;
4262
- this.header = header;
4263
- this.data = data;
4264
- }
4265
- }
4266
- exports.VtecxResponse = VtecxResponse;
4368
+ const vtecxResponse = (status, header, data) => ({ status, header, data });
4267
4369
  /**
4268
4370
  * Error returned from vte.cx
4269
4371
  */
@@ -4459,7 +4561,7 @@ const checkContainSlash = (val, name) => {
4459
4561
  */
4460
4562
  const checkUri = (str, name) => {
4461
4563
  checkNotNull(str, name);
4462
- if (!str.startsWith('/')) {
4564
+ if (!str?.startsWith('/')) {
4463
4565
  throw new VtecxNextError(400, `${name ?? 'Key'} must start with a slash.`);
4464
4566
  }
4465
4567
  };
@@ -4613,7 +4715,7 @@ const getOrigin = (oauthUrl) => {
4613
4715
  * @returns URLSearchParams
4614
4716
  */
4615
4717
  const createURLSearchParams = (data) => {
4616
- const params = new url_1.URLSearchParams();
4718
+ const params = new URLSearchParams();
4617
4719
  Object.keys(data).forEach((key) => params.append(key, data[key]));
4618
4720
  return params;
4619
4721
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtecx/vtecxnext",
3
- "version": "2.3.1",
3
+ "version": "3.0.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": "^24.10.1",
21
+ "@types/node": "^25.0.8",
22
22
  "@types/sqlstring": "^2.3.2",
23
23
  "ts-node": "^10.9.2",
24
24
  "typescript": "^5.9.3"
25
25
  },
26
26
  "dependencies": {
27
- "next": "^16.0.7",
27
+ "next": "^16.1.2",
28
28
  "sqlstring": "^2.3.3"
29
29
  },
30
30
  "scripts": {