Skip to content

Commit 754e475

Browse files
authored
Merge pull request #79 from ExpressApp/fix/ki/web-pipline
fix web credentials set/get
2 parents 3b4ebfb + 9751849 commit 754e475

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@expressms/smartapp-sdk",
3-
"version": "1.12.0-alpha.9",
3+
"version": "1.12.0-alpha.13",
44
"description": "Smartapp SDK",
55
"main": "build/main/index.js",
66
"typings": "build/main/index.d.ts",

src/lib/proxy/index.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import bridge from '@expressms/smartapp-bridge'
22
import { 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
*/
4646
export 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
}

src/types/bridge.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export enum METHODS {
4343
SET_ALLOWED_NAVIGATION_DOMAINS = 'set_allowed_navigation_domains',
4444
GET_CREDENTIALS = 'get_credentials',
4545
SET_CREDENTIALS = 'set_credentials',
46+
DELETE_CREDENTIALS = 'delete_credentials',
4647
RUN_WEB_COMMANDS_PIPELINE = 'run_web_commands_pipeline',
4748
ENABLE_BLUETOOTH = 'enable_bluetooth',
4849
SCAN_BLE_DEVICES = 'scan_ble_devices',

src/types/proxy.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { EmitterEventPayload } from '@expressms/smartapp-bridge/build/main/types/eventEmitter'
22
import { STATUS } from './bridge'
33

4+
export type CredentialsType = 'login_password' | 'cookie'
5+
46
export interface GetCredentialsResponse extends Omit<EmitterEventPayload, 'payload'> {
57
payload: {
68
status: STATUS
79
errorCode?: string | null
8-
credentials: {
10+
credentials: Array<{
11+
type: CredentialsType
912
login: string
1013
password: string
11-
}
14+
}>
1215
}
1316
}
1417

@@ -40,9 +43,7 @@ export interface WebCommandsJob {
4043
interval: number
4144
retryCount: number
4245
onSuccess: Array<WebCommandsJob>
43-
onError: {
44-
command: WebCommand
45-
} | null
46+
onError: Array<WebCommandsJob>
4647
}
4748

4849
export type WebCommandsPipeline = Array<WebCommandsJob>

0 commit comments

Comments
 (0)