11declare module 'pryv' {
22 type Timestamp = number ;
33 type Identifier = string ;
4+
5+ /**
6+ * Common metadata returned by all API responses
7+ * @see https://api.pryv.com/reference/#in-method-results
8+ */
9+ export type ApiMeta = {
10+ /** API version in format {major}.{minor}.{revision} */
11+ apiVersion : string ;
12+ /** Current server time as Unix timestamp in seconds */
13+ serverTime : Timestamp ;
14+ /** Serial that changes when core or register is updated */
15+ serial : string ;
16+ } ;
417 export type PermissionLevel = 'read' | 'contribute' | 'manage' | 'create-only' ;
518 export type KeyValue = { [ key : string ] : string | number } ;
619
@@ -104,7 +117,16 @@ declare module 'pryv' {
104117 export type HFSeries = {
105118 format : 'flatJSON' ;
106119 fields : string [ ] ;
107- points : Array < number | string > ;
120+ points : Array < Array < number | string > > ;
121+ } ;
122+
123+ /**
124+ * Response from adding data points to an HF series event
125+ * @see https://api.pryv.com/reference/#add-hf-series-data-points
126+ */
127+ export type HFSeriesAddResult = {
128+ status : 'ok' ;
129+ meta : ApiMeta ;
108130 } ;
109131
110132 type Run = {
@@ -537,11 +559,7 @@ declare module 'pryv' {
537559 export type StreamedEventsResult = {
538560 eventsCount ?: number ;
539561 eventsDeletionsCount ?: number ;
540- meta : {
541- apiVersion : string ;
542- serverTime : number ;
543- serial : string ;
544- } ;
562+ meta : ApiMeta ;
545563 } ;
546564
547565 export type EventFileCreationParams = Partial <
@@ -604,10 +622,10 @@ declare module 'pryv' {
604622 filename : string ,
605623 ) : Promise < EventAPICallRes > ;
606624 addPointsToHFEvent (
607- id : Identifier ,
625+ eventId : Identifier ,
608626 fields : string [ ] ,
609- values : Array < string | number > ,
610- ) : Promise < any > ;
627+ points : Array < Array < number | string > > ,
628+ ) : Promise < HFSeriesAddResult > ;
611629 accessInfo ( ) : Promise < AccessInfo > ;
612630 revoke ( throwOnFail ?: boolean , usingConnection ?: Connection ) : Promise < any > ;
613631 readonly deltaTime : number ;
@@ -726,19 +744,19 @@ declare module 'pryv' {
726744 export type StateChangeTypes = {
727745 ERROR : {
728746 message ?: string ;
729- error ?: any ;
747+ error ?: Error | unknown ;
730748 } ;
731749 LOADING : { } ;
732750 INITIALIZED : {
733751 serviceInfo : ServiceInfo ;
734752 } ;
735753 NEED_SIGNIN : {
736754 authUrl : string ;
737- clientData : any ;
738- code : number ;
755+ clientData ?: KeyValue ;
756+ code ? : number ;
739757 key : string ;
740758 lang : string ;
741- oauthState : any ;
759+ oauthState ?: string ;
742760 poll : string ;
743761 poll_rate_ms : number ;
744762 requestedPermissions : Array < {
@@ -747,24 +765,48 @@ declare module 'pryv' {
747765 defaultName : string ;
748766 } > ;
749767 requestingAppId : string ;
750- returnUrl : any ;
751- serviceInfo : ServiceInfo ;
768+ returnUrl ?: string | null ;
769+ serviceInfo ? : ServiceInfo ;
752770 } ;
753771 ACCEPTED : {
754- serviceInfo : ServiceInfo ;
772+ serviceInfo ? : ServiceInfo ;
755773 apiEndpoint : string ;
756774 username : string ;
757- token : string ;
775+ token ? : string ;
758776 } ;
759777 SIGNOUT : { } ;
760- REFUSED : { } ;
778+ REFUSED : {
779+ reasonID ?: string ;
780+ message ?: string ;
781+ serviceInfo ?: ServiceInfo ;
782+ } ;
761783 } ;
762784
763785 export type StateChange < K extends States > = StateChangeTypes [ K ] & {
764786 id : K ;
765787 status : K ;
766788 } ;
767789
790+ /**
791+ * Response from auth-request POST endpoint
792+ * @see https://pryv.github.io/reference/#auth-request
793+ */
794+ export type AuthRequestResponse = {
795+ status : 'NEED_SIGNIN' ;
796+ authUrl : string ;
797+ /** @deprecated Use authUrl instead */
798+ url ?: string ;
799+ key : string ;
800+ poll : string ;
801+ poll_rate_ms : number ;
802+ requestingAppId : string ;
803+ requestedPermissions : AuthRequestedPermission [ ] ;
804+ lang ?: string ;
805+ returnURL ?: string ;
806+ clientData ?: KeyValue ;
807+ serviceInfo ?: ServiceInfo ;
808+ } ;
809+
768810 export type AuthSettings = {
769811 spanButtonID ?: string ;
770812 onStateChange ?: ( state : StateChange < States > ) => void ;
@@ -775,15 +817,23 @@ declare module 'pryv' {
775817 requestedPermissions : AuthRequestedPermission [ ] ;
776818 returnUrl ?: string | boolean ;
777819 referer ?: string ;
778- clientData ?: Object ;
820+ clientData ?: KeyValue ;
821+ deviceName ?: string ;
822+ expireAfter ?: number ;
823+ serviceInfo ?: Partial < ServiceInfo > ;
779824 } ;
780825 } ;
781826
827+ export type LoginButtonConstructor = new (
828+ authSettings : AuthSettings ,
829+ service : Service ,
830+ ) => CustomLoginButton ;
831+
782832 export type SetupAuth = (
783833 settings : AuthSettings ,
784834 serviceInfoUrl : string ,
785835 serviceCustomizations ?: serviceCustomizations ,
786- humanInteraction ?: any ,
836+ humanInteraction ?: LoginButtonConstructor ,
787837 ) => Promise < Service > ;
788838
789839 export type AuthStates = {
@@ -799,14 +849,20 @@ declare module 'pryv' {
799849 type AuthStatePayload = {
800850 status : AuthStates [ keyof AuthStates ] ;
801851 message ?: string ;
852+ error ?: Error | unknown ;
802853 } ;
803854
855+ export type StoredAuthorizationData = {
856+ apiEndpoint : string ;
857+ username : string ;
858+ } | null ;
859+
804860 export type CustomLoginButton = {
805861 init ?: ( ) => Promise < Service > ;
806- getAuthorizationData ( ) : any ;
862+ getAuthorizationData ( ) : StoredAuthorizationData ;
807863 onStateChange ( state : AuthStatePayload ) : Promise < void > ;
808864 onClick ( ) : void ;
809- saveAuthorizationData ?: ( authData : any ) => void ;
865+ saveAuthorizationData ?: ( authData : StoredAuthorizationData ) => void ;
810866 deleteAuthorizationData ?: ( ) => Promise < void > ;
811867 finishAuthProcessAfterRedirection ?: ( authController : AuthController ) => Promise < void > ;
812868 } ;
@@ -827,8 +883,8 @@ declare module 'pryv' {
827883 init ( ) : Promise < Service > ;
828884 onClick ( ) : void ;
829885 onStateChange ( state : AuthStatePayload ) : Promise < void > ;
830- getAuthorizationData ( ) : any ;
831- saveAuthorizationData ( authData : any ) : void ;
886+ getAuthorizationData ( ) : StoredAuthorizationData ;
887+ saveAuthorizationData ( authData : StoredAuthorizationData ) : void ;
832888 deleteAuthorizationData ( ) : Promise < void > ;
833889 finishAuthProcessAfterRedirection ( authController : AuthController ) : Promise < void > ;
834890 }
@@ -856,7 +912,7 @@ declare module 'pryv' {
856912 windowLocationForTest ?: string ,
857913 navigatorForTests ?: string ,
858914 ) : string | boolean ;
859- startAuthRequest ( ) : Promise < any > ;
915+ startAuthRequest ( ) : Promise < AuthRequestResponse > ;
860916 set state ( newState : AuthStatePayload ) ;
861917 get state ( ) : AuthStatePayload ;
862918 }
@@ -872,8 +928,8 @@ declare module 'pryv' {
872928 export const Browser : {
873929 LoginButton : typeof LoginButton ;
874930 CookieUtils : {
875- set ( cookieKey : string , value : any , expireInDays ?: number ) : void ;
876- get ( cookieKey : string ) : any ;
931+ set < T = unknown > ( cookieKey : string , value : T , expireInDays ?: number ) : void ;
932+ get < T = unknown > ( cookieKey : string ) : T | undefined ;
877933 del ( cookieKey : string ) : void ;
878934 } ;
879935 AuthStates : AuthStates ;
@@ -912,8 +968,8 @@ declare module 'pryv' {
912968 Browser : {
913969 LoginButton : typeof LoginButton ;
914970 CookieUtils : {
915- set ( cookieKey : string , value : any , expireInDays ?: number ) : void ;
916- get ( cookieKey : string ) : any ;
971+ set < T = unknown > ( cookieKey : string , value : T , expireInDays ?: number ) : void ;
972+ get < T = unknown > ( cookieKey : string ) : T | undefined ;
917973 del ( cookieKey : string ) : void ;
918974 } ;
919975 AuthStates : AuthStates ;
0 commit comments