altair-graphql-core 7.2.2 → 7.2.4
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/build/authorization/authorization-provider.d.ts +1 -1
- package/build/authorization/providers/api-key.js +5 -0
- package/build/authorization/providers/basic.js +1 -1
- package/build/authorization/providers/bearer.js +5 -0
- package/build/authorization/providers/oauth2.js +5 -0
- package/build/cjs/authorization/authorization-provider.d.ts +1 -1
- package/build/cjs/authorization/providers/api-key.js +5 -0
- package/build/cjs/authorization/providers/basic.js +1 -1
- package/build/cjs/authorization/providers/bearer.js +5 -0
- package/build/cjs/authorization/providers/oauth2.js +5 -0
- package/build/cjs/{config.spec.js → config/config.spec.js} +2 -2
- package/build/cjs/config/environment.d.ts +2 -0
- package/build/cjs/config/environment.js +3 -0
- package/build/cjs/config/index.d.ts +74 -0
- package/build/cjs/{config.js → config/index.js} +49 -3
- package/build/cjs/{config.d.ts → config/options.d.ts} +6 -66
- package/build/cjs/config/options.js +3 -0
- package/build/cjs/config/urls.d.ts +8 -0
- package/build/cjs/config/urls.js +23 -0
- package/build/cjs/plugin/v3/frame-worker.d.ts +14 -2
- package/build/cjs/plugin/v3/frame-worker.js +6 -3
- package/build/cjs/plugin/v3/manifest.d.ts +7 -1
- package/build/cjs/plugin/v3/panel.js +2 -0
- package/build/cjs/plugin/v3/parent-engine.js +2 -0
- package/build/cjs/plugin/v3/parent-worker.d.ts +13 -2
- package/build/cjs/plugin/v3/parent-worker.js +25 -5
- package/build/cjs/utils/inject.d.ts +3 -0
- package/build/cjs/utils/inject.js +35 -0
- package/build/{config.spec.js → config/config.spec.js} +1 -1
- package/build/config/environment.d.ts +2 -0
- package/build/config/environment.js +2 -0
- package/build/config/index.d.ts +74 -0
- package/build/{config.js → config/index.js} +49 -3
- package/build/{config.d.ts → config/options.d.ts} +6 -66
- package/build/config/options.js +2 -0
- package/build/config/urls.d.ts +8 -0
- package/build/config/urls.js +20 -0
- package/build/plugin/v3/frame-worker.d.ts +14 -2
- package/build/plugin/v3/frame-worker.js +6 -3
- package/build/plugin/v3/manifest.d.ts +7 -1
- package/build/plugin/v3/panel.js +2 -0
- package/build/plugin/v3/parent-engine.js +2 -0
- package/build/plugin/v3/parent-worker.d.ts +13 -2
- package/build/plugin/v3/parent-worker.js +25 -5
- package/build/utils/inject.d.ts +3 -0
- package/build/utils/inject.js +30 -0
- package/package.json +4 -4
- package/scripts/build.js +63 -0
- package/scripts/copy_settings_d_ts.js +25 -22
- /package/build/cjs/{config.spec.d.ts → config/config.spec.d.ts} +0 -0
- /package/build/{config.spec.d.ts → config/config.spec.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthorizationResult } from '../types/state/authorization.interface';
|
|
2
2
|
export interface AuthorizationProviderExecuteOptions<T = unknown> {
|
|
3
|
-
data: T;
|
|
3
|
+
data: T | undefined;
|
|
4
4
|
}
|
|
5
5
|
export declare abstract class AuthorizationProvider<T = unknown> {
|
|
6
6
|
private hydrator;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { AuthorizationProvider, } from '../authorization-provider';
|
|
2
2
|
export default class ApiKeyAuthorizationProvider extends AuthorizationProvider {
|
|
3
3
|
async execute(options) {
|
|
4
|
+
if (!options.data?.key || !options.data?.value) {
|
|
5
|
+
return {
|
|
6
|
+
headers: {},
|
|
7
|
+
};
|
|
8
|
+
}
|
|
4
9
|
return {
|
|
5
10
|
headers: {
|
|
6
11
|
[options.data.key]: this.hydrate(options.data.value),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AuthorizationProvider, } from '../authorization-provider';
|
|
2
2
|
export default class BasicAuthorizationProvider extends AuthorizationProvider {
|
|
3
3
|
async execute(options) {
|
|
4
|
-
if (!options.data
|
|
4
|
+
if (!options.data?.username || !options.data?.password) {
|
|
5
5
|
return {
|
|
6
6
|
headers: {},
|
|
7
7
|
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { AuthorizationProvider, } from '../authorization-provider';
|
|
2
2
|
export default class BearerAuthorizationProvider extends AuthorizationProvider {
|
|
3
3
|
async execute(options) {
|
|
4
|
+
if (!options.data?.token) {
|
|
5
|
+
return {
|
|
6
|
+
headers: {},
|
|
7
|
+
};
|
|
8
|
+
}
|
|
4
9
|
return {
|
|
5
10
|
headers: {
|
|
6
11
|
Authorization: `Bearer ${this.hydrate(options.data.token)}`,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { AuthorizationProvider, } from '../authorization-provider';
|
|
2
2
|
export default class OAuth2AuthorizationProvider extends AuthorizationProvider {
|
|
3
3
|
async execute(options) {
|
|
4
|
+
if (!options.data?.accessTokenResponse) {
|
|
5
|
+
return {
|
|
6
|
+
headers: {},
|
|
7
|
+
};
|
|
8
|
+
}
|
|
4
9
|
return {
|
|
5
10
|
headers: {
|
|
6
11
|
Authorization: `Bearer ${this.hydrate(options.data.accessTokenResponse.access_token)}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthorizationResult } from '../types/state/authorization.interface';
|
|
2
2
|
export interface AuthorizationProviderExecuteOptions<T = unknown> {
|
|
3
|
-
data: T;
|
|
3
|
+
data: T | undefined;
|
|
4
4
|
}
|
|
5
5
|
export declare abstract class AuthorizationProvider<T = unknown> {
|
|
6
6
|
private hydrator;
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const authorization_provider_1 = require("../authorization-provider");
|
|
4
4
|
class ApiKeyAuthorizationProvider extends authorization_provider_1.AuthorizationProvider {
|
|
5
5
|
async execute(options) {
|
|
6
|
+
if (!options.data?.key || !options.data?.value) {
|
|
7
|
+
return {
|
|
8
|
+
headers: {},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
return {
|
|
7
12
|
headers: {
|
|
8
13
|
[options.data.key]: this.hydrate(options.data.value),
|
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const authorization_provider_1 = require("../authorization-provider");
|
|
27
27
|
class BasicAuthorizationProvider extends authorization_provider_1.AuthorizationProvider {
|
|
28
28
|
async execute(options) {
|
|
29
|
-
if (!options.data
|
|
29
|
+
if (!options.data?.username || !options.data?.password) {
|
|
30
30
|
return {
|
|
31
31
|
headers: {},
|
|
32
32
|
};
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const authorization_provider_1 = require("../authorization-provider");
|
|
4
4
|
class BearerAuthorizationProvider extends authorization_provider_1.AuthorizationProvider {
|
|
5
5
|
async execute(options) {
|
|
6
|
+
if (!options.data?.token) {
|
|
7
|
+
return {
|
|
8
|
+
headers: {},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
return {
|
|
7
12
|
headers: {
|
|
8
13
|
Authorization: `Bearer ${this.hydrate(options.data.token)}`,
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const authorization_provider_1 = require("../authorization-provider");
|
|
4
4
|
class OAuth2AuthorizationProvider extends authorization_provider_1.AuthorizationProvider {
|
|
5
5
|
async execute(options) {
|
|
6
|
+
if (!options.data?.accessTokenResponse) {
|
|
7
|
+
return {
|
|
8
|
+
headers: {},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
return {
|
|
7
12
|
headers: {
|
|
8
13
|
Authorization: `Bearer ${this.hydrate(options.data.accessTokenResponse.access_token)}`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const globals_1 = require("@jest/globals");
|
|
4
|
-
const
|
|
4
|
+
const _1 = require(".");
|
|
5
5
|
(0, globals_1.describe)('config', () => {
|
|
6
6
|
(0, globals_1.it)('creates config object with expected properties', () => {
|
|
7
|
-
const config = new
|
|
7
|
+
const config = new _1.AltairConfig();
|
|
8
8
|
(0, globals_1.expect)(config).toMatchSnapshot();
|
|
9
9
|
});
|
|
10
10
|
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { RequestHandlerIds } from '../request/types';
|
|
2
|
+
import { IDictionary } from '../types/shared';
|
|
3
|
+
import { IInitialEnvironments } from '../types/state/environments.interfaces';
|
|
4
|
+
import { ConfigEnvironment } from './environment';
|
|
5
|
+
import { AltairConfigOptions, AltairWindowOptions } from './options';
|
|
6
|
+
import { UrlConfig } from './urls';
|
|
7
|
+
export declare class AltairConfig {
|
|
8
|
+
private localSandboxUrl;
|
|
9
|
+
private useLocalSandboxUrl;
|
|
10
|
+
donation: {
|
|
11
|
+
url: string;
|
|
12
|
+
action_count_threshold: number;
|
|
13
|
+
};
|
|
14
|
+
ga: string;
|
|
15
|
+
add_query_depth_limit: number;
|
|
16
|
+
tab_size: number;
|
|
17
|
+
max_windows: number;
|
|
18
|
+
default_language: string;
|
|
19
|
+
languages: {
|
|
20
|
+
'en-US': string;
|
|
21
|
+
'fr-FR': string;
|
|
22
|
+
'es-ES': string;
|
|
23
|
+
'cs-CZ': string;
|
|
24
|
+
'de-DE': string;
|
|
25
|
+
'pt-BR': string;
|
|
26
|
+
'ru-RU': string;
|
|
27
|
+
'uk-UA': string;
|
|
28
|
+
'zh-CN': string;
|
|
29
|
+
'ja-JP': string;
|
|
30
|
+
'sr-SP': string;
|
|
31
|
+
'it-IT': string;
|
|
32
|
+
'pl-PL': string;
|
|
33
|
+
'ko-KR': string;
|
|
34
|
+
'ro-RO': string;
|
|
35
|
+
'vi-VN': string;
|
|
36
|
+
};
|
|
37
|
+
query_history_depth: number;
|
|
38
|
+
disableLineNumbers: boolean;
|
|
39
|
+
defaultTheme: string;
|
|
40
|
+
themes: string[];
|
|
41
|
+
isTranslateMode: any;
|
|
42
|
+
isWebApp: any;
|
|
43
|
+
initialData: {
|
|
44
|
+
url: string;
|
|
45
|
+
subscriptionsEndpoint: string;
|
|
46
|
+
subscriptionsProtocol: string;
|
|
47
|
+
query: string;
|
|
48
|
+
variables: string;
|
|
49
|
+
headers: IDictionary;
|
|
50
|
+
environments: IInitialEnvironments;
|
|
51
|
+
preRequestScript: string;
|
|
52
|
+
postRequestScript: string;
|
|
53
|
+
instanceStorageNamespace: string;
|
|
54
|
+
settings: Partial<import("../types/state/settings.interfaces").SettingsState> | undefined;
|
|
55
|
+
persistedSettings: Partial<import("../types/state/settings.interfaces").SettingsState> | undefined;
|
|
56
|
+
initialSubscriptionRequestHandlerId: RequestHandlerIds | undefined;
|
|
57
|
+
initialSubscriptionsPayload: IDictionary;
|
|
58
|
+
initialRequestHandlerId: RequestHandlerIds;
|
|
59
|
+
initialRequestHandlerAdditionalParams: Record<string, unknown>;
|
|
60
|
+
initialHttpMethod: "POST" | "GET" | "PUT" | "DELETE";
|
|
61
|
+
preserveState: boolean;
|
|
62
|
+
windows: AltairWindowOptions[];
|
|
63
|
+
disableAccount: boolean;
|
|
64
|
+
};
|
|
65
|
+
constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, persistedSettings, initialRequestHandlerId, initialRequestHandlerAdditionalParams, initialSubscriptionRequestHandlerId, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, disableAccount, }?: AltairConfigOptions);
|
|
66
|
+
private getPossibleLocalSandBoxUrl;
|
|
67
|
+
private getLocalSandBoxUrl;
|
|
68
|
+
getUrlConfig(environment?: ConfigEnvironment): UrlConfig;
|
|
69
|
+
getUrlConfigWithLocal(environment?: ConfigEnvironment): Promise<UrlConfig>;
|
|
70
|
+
getUrl(name: keyof UrlConfig, environment?: ConfigEnvironment): Promise<string>;
|
|
71
|
+
}
|
|
72
|
+
export declare const setAltairConfig: (_config: AltairConfig) => void;
|
|
73
|
+
export declare const getAltairConfig: () => AltairConfig;
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -4,11 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getAltairConfig = exports.setAltairConfig = exports.AltairConfig = void 0;
|
|
7
|
-
const types_1 = require("
|
|
8
|
-
const is_electron_1 = __importDefault(require("
|
|
7
|
+
const types_1 = require("../request/types");
|
|
8
|
+
const is_electron_1 = __importDefault(require("../utils/is_electron"));
|
|
9
|
+
const urls_1 = require("./urls");
|
|
9
10
|
const isTranslateMode = window.__ALTAIR_TRANSLATE__;
|
|
10
11
|
class AltairConfig {
|
|
11
12
|
constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript = '', instanceStorageNamespace, initialSettings, persistedSettings, initialRequestHandlerId = types_1.HTTP_HANDLER_ID, initialRequestHandlerAdditionalParams = {}, initialSubscriptionRequestHandlerId = types_1.WEBSOCKET_HANDLER_ID, initialSubscriptionsPayload = {}, initialHttpMethod = 'POST', preserveState = true, initialWindows = [], disableAccount = false, } = {}) {
|
|
13
|
+
this.useLocalSandboxUrl = false;
|
|
12
14
|
this.donation = {
|
|
13
15
|
url: 'https://opencollective.com/altair/donate',
|
|
14
16
|
action_count_threshold: 50,
|
|
@@ -101,6 +103,50 @@ class AltairConfig {
|
|
|
101
103
|
this.initialData.windows = initialWindows;
|
|
102
104
|
this.initialData.disableAccount = disableAccount;
|
|
103
105
|
}
|
|
106
|
+
getPossibleLocalSandBoxUrl() {
|
|
107
|
+
// check document base url
|
|
108
|
+
if (document.baseURI) {
|
|
109
|
+
// add iframe-sandbox path to base url
|
|
110
|
+
if (document.baseURI.endsWith('/')) {
|
|
111
|
+
return new URL(document.baseURI + 'iframe-sandbox/index.html');
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// remove the last part of the url
|
|
115
|
+
return new URL(document.baseURI.slice(0, document.baseURI.lastIndexOf('/') + 1) +
|
|
116
|
+
'iframe-sandbox/index.html');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async getLocalSandBoxUrl() {
|
|
121
|
+
if (typeof this.localSandboxUrl === 'undefined') {
|
|
122
|
+
this.localSandboxUrl = this.getPossibleLocalSandBoxUrl()?.href ?? '';
|
|
123
|
+
if (this.localSandboxUrl) {
|
|
124
|
+
const res = await fetch(this.localSandboxUrl);
|
|
125
|
+
if (res.ok) {
|
|
126
|
+
this.useLocalSandboxUrl = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (this.useLocalSandboxUrl) {
|
|
131
|
+
return this.localSandboxUrl;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
getUrlConfig(environment = 'production') {
|
|
135
|
+
return urls_1.urlMap[environment];
|
|
136
|
+
}
|
|
137
|
+
async getUrlConfigWithLocal(environment = 'production') {
|
|
138
|
+
// Check for local sandbox url first
|
|
139
|
+
const localSandboxUrl = await this.getLocalSandBoxUrl();
|
|
140
|
+
const urls = urls_1.urlMap[environment];
|
|
141
|
+
if (localSandboxUrl) {
|
|
142
|
+
urls.sandbox = localSandboxUrl;
|
|
143
|
+
}
|
|
144
|
+
return urls;
|
|
145
|
+
}
|
|
146
|
+
async getUrl(name, environment = 'production') {
|
|
147
|
+
const urlConfig = await this.getUrlConfigWithLocal(environment);
|
|
148
|
+
return urlConfig[name];
|
|
149
|
+
}
|
|
104
150
|
}
|
|
105
151
|
exports.AltairConfig = AltairConfig;
|
|
106
152
|
let config = new AltairConfig();
|
|
@@ -113,4 +159,4 @@ const getAltairConfig = () => {
|
|
|
113
159
|
};
|
|
114
160
|
exports.getAltairConfig = getAltairConfig;
|
|
115
161
|
window.getAltairConfig = exports.getAltairConfig;
|
|
116
|
-
//# sourceMappingURL=
|
|
162
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RequestHandlerIds } from '
|
|
2
|
-
import { IDictionary } from '
|
|
3
|
-
import { IInitialEnvironments } from '
|
|
4
|
-
import { HttpVerb } from '
|
|
5
|
-
import { SettingsState } from '
|
|
1
|
+
import { RequestHandlerIds } from '../request/types';
|
|
2
|
+
import { IDictionary } from '../types/shared';
|
|
3
|
+
import { IInitialEnvironments } from '../types/state/environments.interfaces';
|
|
4
|
+
import { HttpVerb } from '../types/state/query.interfaces';
|
|
5
|
+
import { SettingsState } from '../types/state/settings.interfaces';
|
|
6
6
|
export interface AltairWindowOptions {
|
|
7
7
|
/**
|
|
8
8
|
* Initial name of the window
|
|
@@ -118,64 +118,4 @@ export interface AltairConfigOptions extends AltairWindowOptions {
|
|
|
118
118
|
*/
|
|
119
119
|
disableAccount?: boolean;
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
donation: {
|
|
123
|
-
url: string;
|
|
124
|
-
action_count_threshold: number;
|
|
125
|
-
};
|
|
126
|
-
ga: string;
|
|
127
|
-
add_query_depth_limit: number;
|
|
128
|
-
tab_size: number;
|
|
129
|
-
max_windows: number;
|
|
130
|
-
default_language: string;
|
|
131
|
-
languages: {
|
|
132
|
-
'en-US': string;
|
|
133
|
-
'fr-FR': string;
|
|
134
|
-
'es-ES': string;
|
|
135
|
-
'cs-CZ': string;
|
|
136
|
-
'de-DE': string;
|
|
137
|
-
'pt-BR': string;
|
|
138
|
-
'ru-RU': string;
|
|
139
|
-
'uk-UA': string;
|
|
140
|
-
'zh-CN': string;
|
|
141
|
-
'ja-JP': string;
|
|
142
|
-
'sr-SP': string;
|
|
143
|
-
'it-IT': string;
|
|
144
|
-
'pl-PL': string;
|
|
145
|
-
'ko-KR': string;
|
|
146
|
-
'ro-RO': string;
|
|
147
|
-
'vi-VN': string;
|
|
148
|
-
};
|
|
149
|
-
query_history_depth: number;
|
|
150
|
-
disableLineNumbers: boolean;
|
|
151
|
-
defaultTheme: string;
|
|
152
|
-
themes: string[];
|
|
153
|
-
isTranslateMode: any;
|
|
154
|
-
isWebApp: any;
|
|
155
|
-
initialData: {
|
|
156
|
-
url: string;
|
|
157
|
-
subscriptionsEndpoint: string;
|
|
158
|
-
subscriptionsProtocol: string;
|
|
159
|
-
query: string;
|
|
160
|
-
variables: string;
|
|
161
|
-
headers: IDictionary;
|
|
162
|
-
environments: IInitialEnvironments;
|
|
163
|
-
preRequestScript: string;
|
|
164
|
-
postRequestScript: string;
|
|
165
|
-
instanceStorageNamespace: string;
|
|
166
|
-
settings: Partial<SettingsState> | undefined;
|
|
167
|
-
persistedSettings: Partial<SettingsState> | undefined;
|
|
168
|
-
initialSubscriptionRequestHandlerId: RequestHandlerIds | undefined;
|
|
169
|
-
initialSubscriptionsPayload: IDictionary;
|
|
170
|
-
initialRequestHandlerId: RequestHandlerIds;
|
|
171
|
-
initialRequestHandlerAdditionalParams: Record<string, unknown>;
|
|
172
|
-
initialHttpMethod: "POST" | "GET" | "PUT" | "DELETE";
|
|
173
|
-
preserveState: boolean;
|
|
174
|
-
windows: AltairWindowOptions[];
|
|
175
|
-
disableAccount: boolean;
|
|
176
|
-
};
|
|
177
|
-
constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, persistedSettings, initialRequestHandlerId, initialRequestHandlerAdditionalParams, initialSubscriptionRequestHandlerId, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, disableAccount, }?: AltairConfigOptions);
|
|
178
|
-
}
|
|
179
|
-
export declare const setAltairConfig: (_config: AltairConfig) => void;
|
|
180
|
-
export declare const getAltairConfig: () => AltairConfig;
|
|
181
|
-
//# sourceMappingURL=config.d.ts.map
|
|
121
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.urlMap = void 0;
|
|
4
|
+
exports.urlMap = {
|
|
5
|
+
development: {
|
|
6
|
+
api: 'http://localhost:3000',
|
|
7
|
+
loginClient: 'http://localhost:1234',
|
|
8
|
+
sandbox: 'http://localhost:5123',
|
|
9
|
+
},
|
|
10
|
+
production: {
|
|
11
|
+
api: undefined ?? 'https://api.altairgraphql.dev',
|
|
12
|
+
loginClient: undefined ??
|
|
13
|
+
'https://redir.altairgraphql.dev',
|
|
14
|
+
sandbox: undefined ??
|
|
15
|
+
'https://sandbox.altairgraphql.dev',
|
|
16
|
+
},
|
|
17
|
+
testing: {
|
|
18
|
+
api: 'http://localhost:3000',
|
|
19
|
+
loginClient: 'http://localhost:1234',
|
|
20
|
+
sandbox: 'http://localhost:5123',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=urls.js.map
|
|
@@ -4,10 +4,22 @@ export declare const instanceTypes: {
|
|
|
4
4
|
readonly PANEL: "panel";
|
|
5
5
|
};
|
|
6
6
|
export type InstanceType = (typeof instanceTypes)[keyof typeof instanceTypes];
|
|
7
|
-
export interface
|
|
7
|
+
export interface FrameOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Source origin of the parent window
|
|
10
|
+
*/
|
|
8
11
|
sc: string;
|
|
12
|
+
/**
|
|
13
|
+
* Plugin ID
|
|
14
|
+
*/
|
|
9
15
|
id: string;
|
|
16
|
+
/**
|
|
17
|
+
* Instance type of the plugin
|
|
18
|
+
*/
|
|
10
19
|
instanceType: InstanceType;
|
|
20
|
+
/**
|
|
21
|
+
* Additional parameters
|
|
22
|
+
*/
|
|
11
23
|
[key: string]: string;
|
|
12
24
|
}
|
|
13
25
|
export declare class PluginFrameWorker extends EvaluatorWorker {
|
|
@@ -17,7 +29,7 @@ export declare class PluginFrameWorker extends EvaluatorWorker {
|
|
|
17
29
|
private params;
|
|
18
30
|
constructor();
|
|
19
31
|
getInstanceType(): InstanceType;
|
|
20
|
-
getParams():
|
|
32
|
+
getParams(): FrameOptions;
|
|
21
33
|
onMessage<T extends string, P = unknown>(handler: (e: EventData<T, P>) => void): void;
|
|
22
34
|
send(type: string, payload: any): void;
|
|
23
35
|
onError(handler: (err: any) => void): void;
|
|
@@ -10,10 +10,13 @@ class PluginFrameWorker extends worker_1.EvaluatorWorker {
|
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
12
|
this.instanceType = exports.instanceTypes.MAIN;
|
|
13
|
-
|
|
13
|
+
// Check for params in special params object on the window object first. Using srcdoc, we will set the params on the window object
|
|
14
|
+
const paramFromWindow = window.__ALTAIR_PLUGIN_PARAMS__;
|
|
15
|
+
const paramsFromUrl = Object.fromEntries(new URLSearchParams(window.location.search));
|
|
16
|
+
const params = paramFromWindow ?? paramsFromUrl;
|
|
14
17
|
this.params = params;
|
|
15
|
-
// Get the source origin that embeds the iframe from the URL query parameter
|
|
16
18
|
if (!params.sc) {
|
|
19
|
+
console.log('Invalid source provided!', paramFromWindow, paramsFromUrl);
|
|
17
20
|
throw new Error('Invalid source provided!');
|
|
18
21
|
}
|
|
19
22
|
if (!params.id) {
|
|
@@ -38,7 +41,7 @@ class PluginFrameWorker extends worker_1.EvaluatorWorker {
|
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
43
|
send(type, payload) {
|
|
41
|
-
window.parent.postMessage({ type, payload }, this.origin);
|
|
44
|
+
window.parent.postMessage({ type, payload, frameId: this.id }, this.origin);
|
|
42
45
|
}
|
|
43
46
|
onError(handler) {
|
|
44
47
|
window.addEventListener('error', handler);
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { PluginCapabilities } from './capabilities';
|
|
2
|
-
interface
|
|
2
|
+
interface PluginHtmlEntry {
|
|
3
3
|
type: 'html';
|
|
4
4
|
path: string;
|
|
5
5
|
}
|
|
6
|
+
interface PluginJsEntry {
|
|
7
|
+
type: 'js';
|
|
8
|
+
scripts: string[];
|
|
9
|
+
styles: string[];
|
|
10
|
+
}
|
|
11
|
+
type PluginEntry = PluginHtmlEntry | PluginJsEntry;
|
|
6
12
|
export interface PluginV3Manifest {
|
|
7
13
|
/**
|
|
8
14
|
* Version of manifest (should be 3). It is a control measure for variations in the plugin versions
|
|
@@ -21,6 +21,8 @@ class AltairV3Panel {
|
|
|
21
21
|
data.styleUrls.forEach((styleUrl) => {
|
|
22
22
|
const link = document.createElement('link');
|
|
23
23
|
link.rel = 'stylesheet';
|
|
24
|
+
link.type = 'text/css';
|
|
25
|
+
link.crossOrigin = 'anonymous';
|
|
24
26
|
link.href = styleUrl;
|
|
25
27
|
document.head.appendChild(link);
|
|
26
28
|
});
|
|
@@ -66,6 +66,8 @@ class PluginParentEngine {
|
|
|
66
66
|
this.worker.respond(events_1.PLUGIN_GET_APP_STYLE_URL_EVENT, async () => {
|
|
67
67
|
const styleSheets = Array.from(document.styleSheets);
|
|
68
68
|
// Get the style sheet URLs
|
|
69
|
+
// FYI for some reason I haven't figured out yet, we can't link to the stylesheets
|
|
70
|
+
// in the browser extensions directly from the sandboxed iframe.
|
|
69
71
|
const styleUrls = styleSheets
|
|
70
72
|
.map((sheet) => {
|
|
71
73
|
if (sheet?.href) {
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { EvaluatorWorker, EventData } from '../../evaluator/worker';
|
|
2
2
|
import { InstanceType } from './frame-worker';
|
|
3
|
-
|
|
3
|
+
interface BasePluginParentWorkerOptions {
|
|
4
4
|
id: string;
|
|
5
|
-
pluginEntrypointUrl: string;
|
|
6
5
|
disableAppend?: boolean;
|
|
7
6
|
instanceType?: InstanceType;
|
|
8
7
|
additionalParams?: Record<string, string>;
|
|
9
8
|
additionalSandboxAttributes?: string[];
|
|
10
9
|
}
|
|
10
|
+
interface PluginParentWorkerOptionsWithScripts extends BasePluginParentWorkerOptions {
|
|
11
|
+
type: 'scripts';
|
|
12
|
+
sandboxUrl: string;
|
|
13
|
+
scriptUrls: string[];
|
|
14
|
+
styleUrls: string[];
|
|
15
|
+
}
|
|
16
|
+
interface PluginParentWorkerOptionsWithUrl extends BasePluginParentWorkerOptions {
|
|
17
|
+
type: 'url';
|
|
18
|
+
pluginEntrypointUrl: string;
|
|
19
|
+
}
|
|
20
|
+
export type PluginParentWorkerOptions = PluginParentWorkerOptionsWithScripts | PluginParentWorkerOptionsWithUrl;
|
|
11
21
|
export declare class PluginParentWorker extends EvaluatorWorker {
|
|
12
22
|
private opts;
|
|
13
23
|
constructor(opts: PluginParentWorkerOptions);
|
|
@@ -22,4 +32,5 @@ export declare class PluginParentWorker extends EvaluatorWorker {
|
|
|
22
32
|
onError(handler: (err: unknown) => void): void;
|
|
23
33
|
destroy(): void;
|
|
24
34
|
}
|
|
35
|
+
export {};
|
|
25
36
|
//# sourceMappingURL=parent-worker.d.ts.map
|
|
@@ -32,16 +32,26 @@ class PluginParentWorker extends worker_1.EvaluatorWorker {
|
|
|
32
32
|
id: this.opts.id,
|
|
33
33
|
instanceType: this.getInstanceType(),
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
iframe.src = url;
|
|
35
|
+
// NOTE: Don't add allow-same-origin to the sandbox attribute!
|
|
37
36
|
iframe.sandbox.add('allow-scripts');
|
|
38
|
-
iframe.sandbox.add('allow-same-origin');
|
|
39
37
|
if (this.opts.additionalSandboxAttributes) {
|
|
40
38
|
this.opts.additionalSandboxAttributes.forEach((attr) => {
|
|
41
39
|
iframe.sandbox.add(attr);
|
|
42
40
|
});
|
|
43
41
|
}
|
|
44
42
|
iframe.referrerPolicy = 'no-referrer';
|
|
43
|
+
if (this.opts.type === 'scripts') {
|
|
44
|
+
const url = (0, url_1.urlWithParams)(this.opts.sandboxUrl, {
|
|
45
|
+
...params,
|
|
46
|
+
sandbox_type: 'plugin',
|
|
47
|
+
plugin_sandbox_opts: JSON.stringify(this.opts),
|
|
48
|
+
});
|
|
49
|
+
iframe.src = url;
|
|
50
|
+
}
|
|
51
|
+
else if (this.opts.type === 'url') {
|
|
52
|
+
const url = (0, url_1.urlWithParams)(this.opts.pluginEntrypointUrl, params);
|
|
53
|
+
iframe.src = url;
|
|
54
|
+
}
|
|
45
55
|
if (!this.opts.disableAppend) {
|
|
46
56
|
document.body.appendChild(iframe);
|
|
47
57
|
}
|
|
@@ -58,7 +68,11 @@ class PluginParentWorker extends worker_1.EvaluatorWorker {
|
|
|
58
68
|
}
|
|
59
69
|
onMessage(handler) {
|
|
60
70
|
window.addEventListener('message', (e) => {
|
|
61
|
-
if (e.origin !==
|
|
71
|
+
if (e.origin !== 'null' || e.source !== this.iframe.contentWindow) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (e.data.frameId !== this.opts.id) {
|
|
75
|
+
console.error('Invalid frameId in data', e.data.frameId, this.opts.id);
|
|
62
76
|
return;
|
|
63
77
|
}
|
|
64
78
|
handler(e.data);
|
|
@@ -66,7 +80,13 @@ class PluginParentWorker extends worker_1.EvaluatorWorker {
|
|
|
66
80
|
}
|
|
67
81
|
send(type, payload) {
|
|
68
82
|
this.frameReady().then(() => {
|
|
69
|
-
this.iframe.contentWindow?.postMessage({ type, payload },
|
|
83
|
+
this.iframe.contentWindow?.postMessage({ type, payload },
|
|
84
|
+
// https://web.dev/articles/sandboxed-iframes#safely_sandboxing_eval
|
|
85
|
+
// Note that we're sending the message to "*", rather than some specific
|
|
86
|
+
// origin. Sandboxed iframes which lack the 'allow-same-origin' header
|
|
87
|
+
// don't have an origin which you can target: you'll have to send to any
|
|
88
|
+
// origin, which might alow some esoteric attacks. Validate your output!
|
|
89
|
+
'*');
|
|
70
90
|
});
|
|
71
91
|
}
|
|
72
92
|
onError(handler) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.injectStylesheet = exports.injectScript = void 0;
|
|
4
|
+
const injectScript = (url) => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const head = document.getElementsByTagName('head')[0];
|
|
7
|
+
if (!head) {
|
|
8
|
+
return reject(new Error('No head found!'));
|
|
9
|
+
}
|
|
10
|
+
const script = document.createElement('script');
|
|
11
|
+
script.type = 'text/javascript';
|
|
12
|
+
script.src = url;
|
|
13
|
+
script.onload = () => resolve(null);
|
|
14
|
+
script.onerror = (err) => reject(err);
|
|
15
|
+
head.appendChild(script);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.injectScript = injectScript;
|
|
19
|
+
const injectStylesheet = (url) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const head = document.getElementsByTagName('head')[0];
|
|
22
|
+
if (!head) {
|
|
23
|
+
return reject(new Error('No head found!'));
|
|
24
|
+
}
|
|
25
|
+
const style = document.createElement('link');
|
|
26
|
+
style.type = 'text/css';
|
|
27
|
+
style.rel = 'stylesheet';
|
|
28
|
+
style.href = url;
|
|
29
|
+
style.onload = () => resolve(null);
|
|
30
|
+
style.onerror = (err) => reject(err);
|
|
31
|
+
head.appendChild(style);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.injectStylesheet = injectStylesheet;
|
|
35
|
+
//# sourceMappingURL=inject.js.map
|