@deephaven/jsapi-utils 0.41.2-beta.3 → 0.41.3
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.
package/dist/MessageUtils.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare function makeMessage<T>(message: string, id?: string, payload?: T
|
|
|
46
46
|
* @returns Response
|
|
47
47
|
*/
|
|
48
48
|
export declare function makeResponse<T>(messageId: string, payload: T): Response<T>;
|
|
49
|
+
export declare function getWindowParent(): Window | null;
|
|
49
50
|
/**
|
|
50
51
|
* Request data from the parent window and wait for response
|
|
51
52
|
* @param request Request message to send to the parent window
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageUtils.d.ts","sourceRoot":"","sources":["../src/MessageUtils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,qBAAqB,8CACW,CAAC;AAE9C,eAAO,MAAM,uBAAuB,gDACW,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,wBAAwB,kCAAkC,CAAC;AAExE,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,OAAO;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,CAAC;CACb;AAED,MAAM,WAAW,qBAAsB,SAAQ,OAAO,CAAC,IAAI,CAAC;IAC1D,OAAO,EAAE,OAAO,uBAAuB,CAAC;CACzC;AAED,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,IAAI,CAAC;IAC3D,OAAO,EAAE,OAAO,wBAAwB,CAAC;CAC1C;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,OAAO;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,wBAAgB,SA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EAAE,OAAO,uBAAuB,CAAC;CACzC;AAED,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,IAAI,CAAC;IAC3D,OAAO,EAAE,OAAO,wBAAwB,CAAC;CAC1C;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,OAAO;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,CAOtD;AAED,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,qBAAqB,CAE9B;AAED,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,sBAAsB,CAE/B;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,QAAQ,CAGxD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,OAAO,EAAE,MAAM,EACf,EAAE,SAAY,EACd,OAAO,CAAC,EAAE,CAAC,GACV,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAE1E;AAED,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAQ/C;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,OAAO,SAAQ,GACd,OAAO,CAAC,OAAO,CAAC,CA8BlB"}
|
package/dist/MessageUtils.js
CHANGED
|
@@ -65,6 +65,15 @@ export function makeResponse(messageId, payload) {
|
|
|
65
65
|
payload
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
export function getWindowParent() {
|
|
69
|
+
if (window.opener != null) {
|
|
70
|
+
return window.opener;
|
|
71
|
+
}
|
|
72
|
+
if (window.parent != null && window.parent !== window) {
|
|
73
|
+
return window.parent;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
68
77
|
|
|
69
78
|
/**
|
|
70
79
|
* Request data from the parent window and wait for response
|
|
@@ -78,8 +87,9 @@ export function requestParentResponse(_x) {
|
|
|
78
87
|
function _requestParentResponse() {
|
|
79
88
|
_requestParentResponse = _asyncToGenerator(function* (request) {
|
|
80
89
|
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 30000;
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
var parent = getWindowParent();
|
|
91
|
+
if (parent == null) {
|
|
92
|
+
throw new Error('window parent is null, unable to send request.');
|
|
83
93
|
}
|
|
84
94
|
return new Promise((resolve, reject) => {
|
|
85
95
|
var timeoutId;
|
|
@@ -106,7 +116,7 @@ function _requestParentResponse() {
|
|
|
106
116
|
window.removeEventListener('message', listener);
|
|
107
117
|
reject(new TimeoutError('Request timed out'));
|
|
108
118
|
}, timeout);
|
|
109
|
-
|
|
119
|
+
parent.postMessage(makeMessage(request, id), '*');
|
|
110
120
|
});
|
|
111
121
|
});
|
|
112
122
|
return _requestParentResponse.apply(this, arguments);
|
package/dist/MessageUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageUtils.js","names":["shortid","Log","TimeoutError","log","module","LOGIN_OPTIONS_REQUEST","SESSION_DETAILS_REQUEST","BROADCAST_CHANNEL_NAME","BROADCAST_LOGIN_MESSAGE","BROADCAST_LOGOUT_MESSAGE","isMessage","obj","message","id","isBroadcastLoginMessage","isBroadcastLogoutMessage","isResponse","response","makeMessage","payload","makeResponse","messageId","
|
|
1
|
+
{"version":3,"file":"MessageUtils.js","names":["shortid","Log","TimeoutError","log","module","LOGIN_OPTIONS_REQUEST","SESSION_DETAILS_REQUEST","BROADCAST_CHANNEL_NAME","BROADCAST_LOGIN_MESSAGE","BROADCAST_LOGOUT_MESSAGE","isMessage","obj","message","id","isBroadcastLoginMessage","isBroadcastLogoutMessage","isResponse","response","makeMessage","payload","makeResponse","messageId","getWindowParent","window","opener","parent","requestParentResponse","request","timeout","Error","Promise","resolve","reject","timeoutId","listener","event","data","debug","clearTimeout","removeEventListener","addEventListener","setTimeout","postMessage"],"sources":["../src/MessageUtils.ts"],"sourcesContent":["import shortid from 'shortid';\nimport Log from '@deephaven/log';\nimport { TimeoutError } from '@deephaven/utils';\n\nconst log = Log.module('MessageUtils');\n\nexport const LOGIN_OPTIONS_REQUEST =\n 'io.deephaven.message.LoginOptions.request';\n\nexport const SESSION_DETAILS_REQUEST =\n 'io.deephaven.message.SessionDetails.request';\n\n/**\n * Use a BroadcastChannel for sending messages between tabs, such as when the user logs out.\n */\nexport const BROADCAST_CHANNEL_NAME = 'io.deephaven.broadcast';\n\n/**\n * Event emitted when the user has logged in successfully\n */\nexport const BROADCAST_LOGIN_MESSAGE = 'io.deephaven.broadcast.Login';\n\n/**\n * Event emitted when the user has logged out\n */\nexport const BROADCAST_LOGOUT_MESSAGE = 'io.deephaven.broadcast.Logout';\n\nexport interface Message<T = unknown> {\n id: string;\n message: string;\n payload?: T;\n}\n\nexport interface BroadcastLoginMessage extends Message<void> {\n message: typeof BROADCAST_LOGIN_MESSAGE;\n}\n\nexport interface BroadcastLogoutMessage extends Message<void> {\n message: typeof BROADCAST_LOGOUT_MESSAGE;\n}\n\nexport interface Response<T = unknown> {\n id: string;\n payload: T;\n}\n\nexport function isMessage(obj: unknown): obj is Message {\n const message = obj as Message;\n return (\n message != null &&\n typeof message.id === 'string' &&\n typeof message.message === 'string'\n );\n}\n\nexport function isBroadcastLoginMessage(\n obj: unknown\n): obj is BroadcastLoginMessage {\n return isMessage(obj) && obj.message === BROADCAST_LOGIN_MESSAGE;\n}\n\nexport function isBroadcastLogoutMessage(\n obj: unknown\n): obj is BroadcastLogoutMessage {\n return isMessage(obj) && obj.message === BROADCAST_LOGOUT_MESSAGE;\n}\n\nexport function isResponse(obj: unknown): obj is Response {\n const response = obj as Response;\n return response != null && typeof response.id === 'string';\n}\n\n/**\n * Make message object with optional payload\n * @param message Message string\n * @param id Unique message id\n * @param payload Payload to send\n * @returns Message\n */\nexport function makeMessage<T>(\n message: string,\n id = shortid(),\n payload?: T\n): Message<T> {\n return { message, id, payload };\n}\n\n/**\n * Make response object for given message id\n * @param messageId Id of the request message to respond to\n * @param payload Payload to respond with\n * @returns Response\n */\nexport function makeResponse<T>(messageId: string, payload: T): Response<T> {\n return { id: messageId, payload };\n}\n\nexport function getWindowParent(): Window | null {\n if (window.opener != null) {\n return window.opener;\n }\n if (window.parent != null && window.parent !== window) {\n return window.parent;\n }\n return null;\n}\n\n/**\n * Request data from the parent window and wait for response\n * @param request Request message to send to the parent window\n * @param timeout Timeout in ms\n * @returns Payload of the given type, or undefined\n */\nexport async function requestParentResponse(\n request: string,\n timeout = 30000\n): Promise<unknown> {\n const parent = getWindowParent();\n if (parent == null) {\n throw new Error('window parent is null, unable to send request.');\n }\n return new Promise((resolve, reject) => {\n let timeoutId: number;\n const id = shortid();\n const listener = (event: MessageEvent) => {\n const { data } = event;\n if (!isResponse(data)) {\n log.debug('Ignoring non-deephaven response', data);\n return;\n }\n log.debug('Received message', data);\n if (data?.id !== id) {\n log.debug(\"Ignore message, id doesn't match\", data);\n return;\n }\n window.clearTimeout(timeoutId);\n window.removeEventListener('message', listener);\n resolve(data.payload);\n };\n window.addEventListener('message', listener);\n timeoutId = window.setTimeout(() => {\n window.removeEventListener('message', listener);\n reject(new TimeoutError('Request timed out'));\n }, timeout);\n parent.postMessage(makeMessage(request, id), '*');\n });\n}\n"],"mappings":";;AAAA,OAAOA,OAAO,MAAM,SAAS;AAC7B,OAAOC,GAAG,MAAM,gBAAgB;AAChC,SAASC,YAAY,QAAQ,kBAAkB;AAE/C,IAAMC,GAAG,GAAGF,GAAG,CAACG,MAAM,CAAC,cAAc,CAAC;AAEtC,OAAO,IAAMC,qBAAqB,GAChC,2CAA2C;AAE7C,OAAO,IAAMC,uBAAuB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N,QAAQ,CAAC;MAC5CD,SAAS,GAAGV,MAAM,CAACkB,UAAU,CAAC,MAAM;QAClClB,MAAM,CAACgB,mBAAmB,CAAC,SAAS,EAAEL,QAAQ,CAAC;QAC/CF,MAAM,CAAC,IAAI9B,YAAY,CAAC,mBAAmB,CAAC,CAAC;MAC/C,CAAC,EAAE0B,OAAO,CAAC;MACXH,MAAM,CAACiB,WAAW,CAACxB,WAAW,CAACS,OAAO,EAAEd,EAAE,CAAC,EAAE,GAAG,CAAC;IACnD,CAAC,CAAC;EACJ,CAAC;EAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/jsapi-utils",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.3",
|
|
4
4
|
"description": "Deephaven JSAPI Utils",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"build:babel": "babel ./src --out-dir ./dist --extensions \".ts,.tsx,.js,.jsx\" --source-maps --root-mode upward"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@deephaven/filters": "^0.41.
|
|
25
|
-
"@deephaven/jsapi-types": "^0.41.
|
|
26
|
-
"@deephaven/log": "^0.41.
|
|
27
|
-
"@deephaven/utils": "^0.41.
|
|
24
|
+
"@deephaven/filters": "^0.41.0",
|
|
25
|
+
"@deephaven/jsapi-types": "^0.41.0",
|
|
26
|
+
"@deephaven/log": "^0.41.0",
|
|
27
|
+
"@deephaven/utils": "^0.41.0",
|
|
28
28
|
"@react-stately/data": "^3.9.1",
|
|
29
29
|
"lodash.clamp": "^4.0.3",
|
|
30
30
|
"shortid": "^2.2.16"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@deephaven/jsapi-shim": "^0.41.
|
|
34
|
-
"@deephaven/tsconfig": "^0.41.
|
|
33
|
+
"@deephaven/jsapi-shim": "^0.41.0",
|
|
34
|
+
"@deephaven/tsconfig": "^0.41.0"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"dist"
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "e99b6e8a70e14f019dfe69739190c2eec9517353"
|
|
44
44
|
}
|