11import bridge from '@expressms/smartapp-bridge'
22import { CookieItem , ERROR_CODES , METHODS , StatusResponse } from '../../types'
3- import { GetCredentialsResponse , WebCommandsPipeline } from '../../types/proxy'
3+ import { CredentialsType , GetCredentialsResponse , WebCommandsPipeline } from '../../types/proxy'
44
55/**
66 * Set cookies for web resouce. It's needed for SSO auth cases.
@@ -40,7 +40,7 @@ export const setAllowedNavigationDomains = (domains: string[]): Promise<StatusRe
4040}
4141
4242/**
43- * DRAFT: Get saved credentials of web resource
43+ * Get saved web resource credentials
4444 * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
4545 */
4646export const getCredentials = ( ) : Promise < GetCredentialsResponse > => {
@@ -51,27 +51,55 @@ export const getCredentials = (): Promise<GetCredentialsResponse> => {
5151 method : METHODS . GET_CREDENTIALS ,
5252 params : { } ,
5353 timeout : 10_000 ,
54+ hide_recv_event_data : true ,
5455 } )
5556 . then ( event => event as GetCredentialsResponse )
5657}
5758
5859/**
59- * DRAFT: Save credentials of web resource
60+ * Save web resource credentials
6061 * @param login User login
6162 * @param password User pass
6263 * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
6364 */
64- export const setCredentials = ( { login, password } : { login : string ; password : string } ) : Promise < StatusResponse > => {
65+ export const setCredentials = ( {
66+ login,
67+ password,
68+ type,
69+ } : {
70+ login : string
71+ password : string
72+ type : CredentialsType
73+ } ) : Promise < StatusResponse > => {
6574 if ( ! bridge ) return Promise . reject ( ERROR_CODES . NO_BRIDGE )
6675
6776 return bridge
6877 . sendClientEvent ( {
6978 method : METHODS . SET_CREDENTIALS ,
7079 params : {
71- login,
72- password,
80+ credentials : {
81+ login,
82+ password,
83+ type,
84+ } ,
7385 } ,
7486 timeout : 10_000 ,
87+ hide_send_event_data : true ,
88+ } )
89+ . then ( event => event as StatusResponse )
90+ }
91+
92+ /**
93+ * Delete web resource credentials
94+ * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
95+ */
96+ export const deleteCredentials = ( ) : Promise < StatusResponse > => {
97+ if ( ! bridge ) return Promise . reject ( ERROR_CODES . NO_BRIDGE )
98+
99+ return bridge
100+ . sendClientEvent ( {
101+ method : METHODS . DELETE_CREDENTIALS ,
102+ params : { } ,
75103 } )
76104 . then ( event => event as StatusResponse )
77105}
@@ -91,6 +119,7 @@ export const runWebCommandsPipeline = (pipeline: WebCommandsPipeline): Promise<S
91119 pipeline,
92120 } ,
93121 timeout : 1000 ,
122+ hide_send_event_data : true ,
94123 } )
95124 . then ( event => event as StatusResponse )
96125}
0 commit comments