Skip to content

Commit 6ef13e6

Browse files
committed
add IMSInterface
update global.window Interface
1 parent 0081233 commit 6ef13e6

2 files changed

Lines changed: 296 additions & 96 deletions

File tree

src/IMSInterface.ts

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
2+
export class IMSInterface {
3+
/**
4+
* Establishes an IMS session. Must be called before any IMS access methods.
5+
* This method is not thread safe.
6+
*
7+
* @return An IMS reference string, as returned from IMSLib, which you
8+
* can then use to make further IMS calls to this object's methods.
9+
*
10+
* @deprecated Please use imsConnectWithEndpoint instead.
11+
*/
12+
imsConnect(): string {
13+
return window.__adobe_cep__.imsConnect();
14+
}
15+
16+
imsDisconnect(imsRef: string): void {
17+
window.__adobe_cep__.imsDisconnect(imsRef);
18+
}
19+
20+
imsConnectWithEndpoint(imsEndpoint?: string): string {
21+
return JSON.parse(window.__adobe_cep__.invokeSync("imsConnectWithEndpoint", JSON.stringify({imsEndpoint: imsEndpoint}))).result
22+
}
23+
24+
imsFetchAccounts(imsRef: string, clientId: string): string {
25+
return window.__adobe_cep__.imsFetchAccounts(imsRef, clientId);
26+
}
27+
28+
imsFetchUserProfileData(imsRef: string, userAccountGuid: string): string {
29+
const data = {
30+
imsRef: imsRef,
31+
userAccountGuid: userAccountGuid
32+
};
33+
return window.__adobe_cep__.invokeSync("imsFetchUserProfileData", JSON.stringify(data))
34+
}
35+
36+
/**
37+
* Requests an access token from IMS for a given user and service.
38+
*
39+
* This function is asynchronous. To handle the result, register a callback for the event
40+
* "com.adobe.csxs.events.internal.ims.FetchAccessToken" or "com.adobe.csxs.events.internal.ims.FetchAccessTokenWithStatus".
41+
* For event "com.adobe.csxs.events.internal.ims.FetchAccessToken", the event data is a JSON string
42+
* with format {"toua":"...",...,"emailVerified":"false"}.
43+
* For event "com.adobe.csxs.events.internal.ims.FetchAccessTokenWithStatus", the event data is a JSON string
44+
* with format {"status":"0","details":{"toua":"...",...,"emailVerified":"false"}}.
45+
*
46+
* @see addEventListener()
47+
*
48+
* @param imsRef An IMS reference returned from the \c IMSConnect() call.
49+
* @param clientId The IMS client ID for your extension, assigned by the IMS team on registration.
50+
* This is the service-code value in the Renga Service Account Object for your client.
51+
* @param clientSecret The client secret associated with the provided client ID
52+
* @param userAccountGuid The unique person GUID for the Renga account, as returned by the <code>fetchAccounts()</code> method. The token is generated for this user.
53+
* @param serviceAccountGuid (optional, not currently used) A unique identifier for a Service Account Object (SAO).
54+
* @param scope (optional) A comma delimited list of services for which the refresh and access tokens are requested.
55+
*
56+
* By default, this is 'openid,AdobeID'. Scope strings are case sensitive.
57+
* If the cached version of the refresh token does not match the requested service scopes, a new refresh token is fetched.
58+
* To request your service's own SAO, add your service to the list;
59+
* for example, 'openid,AdobeID,browserlab'.
60+
*
61+
* @return A boolean status. Returning true means only the call to imsFetchAccessToken function itself is successful.
62+
* Returning false means that failed to fetch access token.
63+
*/
64+
imsFetchAccessToken(imsRef: string, clientId: string, clientSecret: string, userAccountGuid: string, serviceAccountGuid?: string, scope?: string): boolean {
65+
return window.__adobe_cep__.imsFetchAccessToken(imsRef, clientId, clientSecret, userAccountGuid, serviceAccountGuid, scope);
66+
}
67+
68+
imsFetchContinueToken(imsRef: any, bearerToken: string, targetClientId: string, redirectUri?: string, scope?: string, responseType?: string, locale?: string): string {
69+
const data = {
70+
imsRef: imsRef,
71+
bearerToken: bearerToken,
72+
targetClientId: targetClientId,
73+
redirectUri: redirectUri,
74+
scope: scope,
75+
responseType: responseType,
76+
locale: locale
77+
};
78+
79+
return JSON.parse(window.__adobe_cep__.invokeSync("imsFetchContinueToken", JSON.stringify(data))).result;
80+
}
81+
82+
imsRevokeDeviceToken(imsRef: string, clientId: string, clientSecret: string, userAccountGuid: string, serviceAccountGuid?: string): boolean {
83+
return window.__adobe_cep__.imsFetchAccessToken(imsRef, clientId, clientSecret, userAccountGuid, serviceAccountGuid, "REVOKE");
84+
}
85+
86+
imsSetProxyCredentials(proxyUsername: string, proxyPassword: string): void {
87+
window.__adobe_cep__.imsSetProxyCredentials(proxyUsername, proxyPassword);
88+
}
89+
90+
showAAM(clientId: string, clientSecret: string, redirectUri: string, userAccountGuid: string, serviceAccountGuid: string, scope: string): Boolean {
91+
return window.__adobe_cep__.showAAM(clientId, clientSecret, redirectUri, userAccountGuid, serviceAccountGuid, scope)
92+
}
93+
94+
imsGetCurrentUserId(): object {
95+
return window.__adobe_cep__.getCurrentImsUserId();
96+
}
97+
98+
imsGetCurrentUserIdHelper(callback: Function): void {
99+
const hostEnvironment = JSON.parse(window.__adobe_cep__.getHostEnvironment());
100+
const appName = hostEnvironment.appName;
101+
102+
if ("ILST" === appName) {
103+
window.__adobe_cep__.evalScript("app.userGUID", function (result: any) {
104+
callback(result);
105+
});
106+
} else if ("IDSN" === appName) {
107+
window.__adobe_cep__.evalScript("app.userGuid", function (result: any) {
108+
callback(result);
109+
});
110+
} else if ("PHSP" === appName || "PHXS" === appName) {
111+
window.__adobe_cep__.evalScript("var getUserIdPhotoshop = function() {var userId = '';try {var bhnc = app.charIDToTypeID('bhnc');var ref = new ActionReference();ref.putProperty(app.charIDToTypeID('Prpr'), bhnc);ref.putEnumerated(app.charIDToTypeID('capp'), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt'));var appDesc = app.executeActionGet(ref);if (appDesc.hasKey(bhnc)) {userId = appDesc.getString(bhnc);}} catch (e) {}return userId;};", function (result: any) {
112+
window.__adobe_cep__.evalScript("getUserIdPhotoshop()", function (result: any) {
113+
callback(result);
114+
})
115+
});
116+
} else {
117+
const clientId = window.__adobe_cep__.getCurrentImsUserId();
118+
callback(clientId)
119+
}
120+
}
121+
122+
imsLogoutUser(imsRef: string, userAccountGuid: string, clientId: string): object {
123+
const data = {
124+
imsRef: imsRef,
125+
userAccountGuid: userAccountGuid,
126+
clientId: clientId
127+
};
128+
return JSON.parse(window.__adobe_cep__.invokeSync("imsLogoutUser", JSON.stringify(data))).result
129+
}
130+
131+
imsAttemptSSOJumpWorkflows(openBrowser: boolean, url: string, imsRef: string, clientId?: string, clientSecret?: string, scope?: string, userAccountGuid?: string, targetClientId?: string, targetScope?: string, targetResponseType?: string, targetLocale?: string) {
132+
const data = {
133+
openBrowser: openBrowser,
134+
url: url,
135+
imsRef: imsRef,
136+
clientId: clientId,
137+
clientSecret: clientSecret,
138+
scope: scope,
139+
userAccountGuid: userAccountGuid,
140+
targetClientId: targetClientId,
141+
targetScope: targetScope,
142+
targetResponseType: targetResponseType,
143+
targetLocale: targetLocale
144+
};
145+
return JSON.parse(window.__adobe_cep__.invokeSync("imsAttemptSSOJumpWorkflows", JSON.stringify(data))).result
146+
}
147+
}
148+
149+
export namespace IMSInterface {
150+
export enum Events {
151+
imsFetchAccessTokenWithStatus = "com.adobe.csxs.events.internal.ims.FetchAccessTokenWithStatus",
152+
imsFetchAccessToken = "com.adobe.csxs.events.internal.ims.FetchAccessToken",
153+
imsRevokeAccessToken = "com.adobe.csxs.events.internal.ims.FetchAccessTokenWithStatus",
154+
imsFetchContinueToken = "com.adobe.csxs.events.internal.ims.FetchAccessTokenWithStatus",
155+
imsAAMIMSStatus = "vulcan.SuiteMessage.com.adobe.aam.AAMIMSStatus",
156+
imsLogoutUser = "com.adobe.csxs.events.internal.ims.LogoutUser",
157+
imsSSOStatus = "com.adobe.csxs.events.internal.ims.SSOStatus"
158+
}
159+
160+
export enum Status {
161+
IMS_SUCCESS = "0",
162+
IMS_ERROR_FAILURE = "1",
163+
IMS_ERROR_INVALID_ARGUMENTS = "2",
164+
IMS_ERROR_CANCEL = "20",
165+
IMS_ERROR_TIMEOUT = "21",
166+
IMS_ERROR_HTTPFAILURE = "22",
167+
IMS_ERROR_SSLFAILURE = "23",
168+
IMS_ERROR_AUTH_PROXY_REQUIRED = "24",
169+
IMS_ERROR_AUTH_PROXY_FAILED = "25",
170+
IMS_ERROR_IN_ACCESS_IDP = "26",
171+
IMS_ERROR_ANOTHER_REQUEST_IN_PROCESS = "40",
172+
IMS_ERROR_IN_READ_USER_DATA = "60",
173+
IMS_ERROR_IN_SAVE_USER_DATA = "61",
174+
IMS_ERROR_IN_REMOVE_USER_DATA = "62",
175+
IMS_ERROR_USER_DATA_NOT_PRESENT = "63",
176+
IMS_ERROR_IN_READ_DEVICE_TOKEN = "64",
177+
IMS_ERROR_IN_SAVE_DEVICE_TOKEN = "65",
178+
IMS_ERROR_IN_REMOVE_DEVICE_TOKEN = "66",
179+
IMS_ERROR_DEVICE_TOKEN_NOT_PRESENT = "67",
180+
IMS_ERROR_INVALID_DEVICE_TOKEN = "68",
181+
IMS_ERROR_CLIENTID_NOT_PRESENT = "69",
182+
IMS_ERROR_IN_FETCH_USER_ACCOUNTS = "70",
183+
IMS_ERROR_IN_SAVE_USER_FOR_CLIENTID = "71",
184+
IMS_ERROR_DEVICE_ID_NOT_PRESENT = "72",
185+
IMS_ERROR_DEFAULT_USER_FOR_CLIENTID_NOT_PRESENT = "73",
186+
IMS_ERROR_NO_USER_RECORDS_PRESENT = "74",
187+
IMS_ERROR_ACCESS_DENIED = "80",
188+
IMS_ERROR_INVALID_REQUEST = "81",
189+
IMS_ERROR_INVALID_CLIENT = "82",
190+
IMS_ERROR_INVALID_GRANT = "83",
191+
IMS_ERROR_UNAUTHORIZED_CLIENT = "84",
192+
IMS_ERROR_UNSUPPORTED_RESPONSE_TYPE = "85",
193+
IMS_ERROR_INVALID_SCOPE = "86",
194+
IMS_ERROR_UNSUPPORTED_GRANT_TYPE = "87",
195+
IMS_ERROR_BAD_REQUEST = "88",
196+
IMS_ERROR_INVALID_CREDENTIALS = "89",
197+
IMS_ERROR_IN_GET_AUTH_DATA_FROM_IDP = "100",
198+
IMS_ERROR_IN_GET_DEVICE_TOKEN_FROM_IDP = "101",
199+
IMS_ERROR_IN_GET_REFRESH_TOKEN_FROM_IDP = "102",
200+
IMS_ERROR_IN_GET_ACCESS_TOKEN_FROM_IDP = "103",
201+
IMS_ERROR_IN_GET_PROFILE_DATA_FROM_IDP = "104",
202+
IMS_ERROR_TOU_CHANGED = "120",
203+
IMS_ERROR_IN_REVOKE_DEVICE_TOKEN = "121",
204+
IMS_ERROR_TOU_NOT_CURRENT = "122",
205+
IMS_ERROR_EVS_INVALID = "123",
206+
IMS_ERROR_ACCT_ACT_REQ = "124",
207+
IMS_ERROR_ACCT_DISABLED = "125",
208+
IMS_ERROR_SUBS_ACT_REQ = "126",
209+
IMS_ERROR_SUBS_NO_SUB = "127",
210+
IMS_ERROR_NO_BUDDY_GROUP_FOR_CLIENT = "150",
211+
IMS_ERROR_CLIENT_REGISTERED_FOR_OTHER_GROUP = "151",
212+
IMS_ERROR_GROUP_ENTRY_NOT_PRESENT = "152",
213+
IMS_ERROR_IN_SAVE_GROUP_DATA = "153",
214+
IMS_ERROR_CNAME_ENTRY_NOT_PRESENT = "154",
215+
IMS_ERROR_IN_SAVE_BACKOFF_DATA = "155",
216+
IMSMANAGER_ERROR_EXCEPTION = "3000",
217+
IMSMANAGER_ERROR_ENCODING = "3001",
218+
IMSMANAGER_SUCCESS_BROWSER_OPENED = "3002",
219+
IMSMANAGER_ERROR_BROWSER_FAILED_TO_OPEN = "3003",
220+
IMS_UNKNOWN_ERROR = "0xFFFF"
221+
}
222+
}

window.d.ts

Lines changed: 74 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,78 @@
1-
interface Window {
2-
cep: {
3-
encoding: {
4-
Base64: string
5-
UTF8: string
6-
convertion: {
7-
ascii_to_b64: Function
8-
b64_to_ascii: Function
9-
b64_to_binary: Function
10-
b64_to_utf8: Function
11-
binary_to_b64: Function
12-
utf8_to_b64: Function
13-
}
14-
}
15-
fs: {
16-
NO_ERROR: number
17-
ERR_UNKNOWN: number
18-
ERR_INVALID_PARAMS: number
19-
ERR_NOT_FOUND: number
20-
ERR_CANT_READ: number
21-
ERR_UNSUPPORTED_ENCODING: number
22-
ERR_CANT_WRITE: number
23-
ERR_OUT_OF_SPACE: number
24-
ERR_NOT_FILE: number
25-
ERR_NOT_DIRECTORY: number
26-
ERR_FILE_EXISTS: number
27-
chmod: Function
28-
deleteFile: Function
29-
makedir: Function
30-
readFile: Function
31-
readdir: Function
32-
rename: Function
33-
showOpenDialog: Function
34-
showOpenDialogEx: Function
35-
showSaveDialogEx: Function
36-
stat: Function
37-
writeFile: Function
38-
}
39-
process: {
40-
ERR_EXCEED_MAX_NUM_PROCESS: number
41-
createProcess: Function
42-
getWorkingDirectory: Function
43-
isRunning: Function
44-
onquit: Function
45-
stderr: Function
46-
stdin: Function
47-
stdout: Function
48-
terminate: Function
49-
waitfor: Function
50-
}
51-
util: {
52-
DEPRECATED_API: number
53-
ERR_INVALID_URL: number
54-
openURLInDefaultBrowser: (url: string) => number
55-
registerExtensionUnloadCallback: (callback: Function) => {}
56-
storeProxyCredentials: (username: string, password: string) => {}
57-
}
1+
import {Encoding, FS, Process, Util} from "./CEPEngine_extensions";
2+
import {CSEvent, SystemPath} from "./src"
3+
4+
declare global {
5+
6+
interface IMSInterface {
7+
imsConnect(): string
8+
imsDisconnect(imsRef: string): void
9+
imsFetchAccounts(imsRef: string, clientId: string): string
10+
imsFetchUserProfileData(imsRef: string, userAccountGuid: string): string
11+
imsConnectWithEndpoint(imsEndpoint: any): string
12+
13+
imsFetchAccounts(imsRef: string, clientId: string): string
14+
imsFetchAccessToken(imsRef: string, clientId: string, clientSecret: string, userAccountGuid: string, serviceAccountGuid?: string, scope?: string): boolean
15+
imsFetchContinueToken(imsRef: any, bearerToken: string, targetClientId: string, redirectUri?: string, scope?: string, responseType?: string, locale?: string): string
16+
imsRevokeDeviceToken(imsRef: string, clientId: string, clientSecret: string, userAccountGuid: string, serviceAccountGuid?: string): boolean
17+
18+
imsSetProxyCredentials(proxyUsername: string, proxyPassword: string): void
19+
20+
showAAM(clientId: string, clientSecret: string, redirectUri: string, userAccountGuid: string, serviceAccountGuid: string, scope: string): boolean
21+
22+
imsGetCurrentUserId(): object
23+
imsGetCurrentUserIdHelper(callback: Function): void
24+
25+
imsLogoutUser(imsRef: string, userAccountGuid: string, clientId: string): object
5826
}
59-
cep_node: {
60-
Buffer: Buffer
61-
global: Window
62-
process: NodeJS.Process
63-
require: NodeRequireFunction
64-
__dirname: string
65-
__filename: string
27+
28+
interface CEP extends IMSInterface {
29+
addEventListener(type: string, listener: Function, obj?: object): void
30+
removeEventListener(type: string, listener: any, obj?: object): void
31+
requestOpenExtension(extensionId: string, startupParams?: string): void
32+
closeExtension(): void
33+
34+
dispatchEvent(event: CSEvent): void
35+
dumpInstallationInfo(): string
36+
evalScript(script: string, callback?: Function): void
37+
getCurrentApiVersion(): string
38+
getCurrentImsUserId(): object
39+
getExtensionId(): string
40+
getExtensions(extensionIds?: string): string
41+
getHostCapabilities(): string
42+
getHostEnvironment(): string
43+
getMonitorScaleFactor(): number
44+
getNetworkPreferences(): string
45+
getScaleFactor(): number
46+
getSystemPath(pathType: SystemPath): string
47+
initResourceBundle(): string
48+
49+
invokeAsync(type: string, params: string, callback: Function, obj?: object): Function
50+
invokeSync(type: string, a?: string): string
51+
52+
registerInvalidCertificateCallback(callback: Function): void
53+
registerKeyEventsInterest(keyEventsInterest?: string): void
54+
55+
resizeContent(width: number, height: number): void
56+
setScaleFactorChangedHandler(handler: Function): void
57+
58+
loadSnapshot(unknown: string): void
6659
}
67-
__adobe_cep__: {
68-
addEventListener: Function
69-
closeExtension: Function
70-
dispatchEvent: Function
71-
dumpInstallationInfo: Function
72-
evalScript: Function
73-
getCurrentApiVersion: Function
74-
getCurrentImsUserId: Function
75-
getExtensionId: Function
76-
getExtensions: Function
77-
getHostCapabilities: Function
78-
getHostEnvironment: Function
79-
getMonitorScaleFactor: Function
80-
getNetworkPreferences: Function
81-
getScaleFactor: Function
82-
getSystemPath: Function
83-
imsConnect: Function
84-
imsDisconnect: Function
85-
imsFetchAccessToken: Function
86-
imsFetchAccounts: Function
87-
imsSetProxyCredentials: Function
88-
initResourceBundle: Function
89-
invokeAsync: Function
90-
invokeSync: Function
91-
registerInvalidCertificateCallback: Function
92-
registerKeyEventsInterest: Function
93-
removeEventListener: Function
94-
requestOpenExtension: Function
95-
resizeContent: Function
96-
setScaleFactorChangedHandler: Function
97-
showAAM: Function
98-
loadSnapshot: Function
60+
61+
interface Window {
62+
cep: {
63+
fs: FS,
64+
process: Process,
65+
util: Util,
66+
encoding: Encoding
67+
},
68+
cep_node: {
69+
Buffer: Buffer
70+
global: Window
71+
process: NodeJS.Process
72+
require: NodeRequireFunction
73+
__dirname: string
74+
__filename: string
75+
}
76+
__adobe_cep__: CEP
9977
}
10078
}

0 commit comments

Comments
 (0)