altair-graphql-core 7.2.3 → 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.
Files changed (37) hide show
  1. package/build/authorization/authorization-provider.d.ts +1 -1
  2. package/build/authorization/providers/api-key.js +5 -0
  3. package/build/authorization/providers/basic.js +1 -1
  4. package/build/authorization/providers/bearer.js +5 -0
  5. package/build/authorization/providers/oauth2.js +5 -0
  6. package/build/cjs/authorization/authorization-provider.d.ts +1 -1
  7. package/build/cjs/authorization/providers/api-key.js +5 -0
  8. package/build/cjs/authorization/providers/basic.js +1 -1
  9. package/build/cjs/authorization/providers/bearer.js +5 -0
  10. package/build/cjs/authorization/providers/oauth2.js +5 -0
  11. package/build/cjs/{config.spec.js → config/config.spec.js} +2 -2
  12. package/build/cjs/config/environment.d.ts +2 -0
  13. package/build/cjs/config/environment.js +3 -0
  14. package/build/cjs/config/index.d.ts +74 -0
  15. package/build/cjs/{config.js → config/index.js} +49 -3
  16. package/build/cjs/{config.d.ts → config/options.d.ts} +6 -66
  17. package/build/cjs/config/options.js +3 -0
  18. package/build/cjs/config/urls.d.ts +8 -0
  19. package/build/cjs/config/urls.js +23 -0
  20. package/build/cjs/plugin/v3/panel.js +2 -0
  21. package/build/cjs/plugin/v3/parent-engine.js +2 -0
  22. package/build/{config.spec.js → config/config.spec.js} +1 -1
  23. package/build/config/environment.d.ts +2 -0
  24. package/build/config/environment.js +2 -0
  25. package/build/config/index.d.ts +74 -0
  26. package/build/{config.js → config/index.js} +49 -3
  27. package/build/{config.d.ts → config/options.d.ts} +6 -66
  28. package/build/config/options.js +2 -0
  29. package/build/config/urls.d.ts +8 -0
  30. package/build/config/urls.js +20 -0
  31. package/build/plugin/v3/panel.js +2 -0
  32. package/build/plugin/v3/parent-engine.js +2 -0
  33. package/package.json +4 -4
  34. package/scripts/build.js +63 -0
  35. package/scripts/copy_settings_d_ts.js +25 -22
  36. /package/build/cjs/{config.spec.d.ts → config/config.spec.d.ts} +0 -0
  37. /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.username || !options.data.password) {
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.username || !options.data.password) {
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 config_1 = require("./config");
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 config_1.AltairConfig();
7
+ const config = new _1.AltairConfig();
8
8
  (0, globals_1.expect)(config).toMatchSnapshot();
9
9
  });
10
10
  });
@@ -0,0 +1,2 @@
1
+ export type ConfigEnvironment = 'development' | 'production' | 'testing';
2
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=environment.js.map
@@ -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("./request/types");
8
- const is_electron_1 = __importDefault(require("./utils/is_electron"));
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=config.js.map
162
+ //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
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';
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
- export declare class AltairConfig {
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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1,8 @@
1
+ import { ConfigEnvironment } from './environment';
2
+ export interface UrlConfig {
3
+ api: string;
4
+ loginClient: string;
5
+ sandbox: string;
6
+ }
7
+ export declare const urlMap: Record<ConfigEnvironment, UrlConfig>;
8
+ //# sourceMappingURL=urls.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
@@ -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,5 +1,5 @@
1
1
  import { describe, expect, it } from '@jest/globals';
2
- import { AltairConfig } from './config';
2
+ import { AltairConfig } from '.';
3
3
  describe('config', () => {
4
4
  it('creates config object with expected properties', () => {
5
5
  const config = new AltairConfig();
@@ -0,0 +1,2 @@
1
+ export type ConfigEnvironment = 'development' | 'production' | 'testing';
2
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=environment.js.map
@@ -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
@@ -1,8 +1,10 @@
1
- import { HTTP_HANDLER_ID, WEBSOCKET_HANDLER_ID, } from './request/types';
2
- import isElectron from './utils/is_electron';
1
+ import { HTTP_HANDLER_ID, WEBSOCKET_HANDLER_ID, } from '../request/types';
2
+ import isElectron from '../utils/is_electron';
3
+ import { urlMap } from './urls';
3
4
  const isTranslateMode = window.__ALTAIR_TRANSLATE__;
4
5
  export class AltairConfig {
5
6
  constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript = '', instanceStorageNamespace, initialSettings, persistedSettings, initialRequestHandlerId = HTTP_HANDLER_ID, initialRequestHandlerAdditionalParams = {}, initialSubscriptionRequestHandlerId = WEBSOCKET_HANDLER_ID, initialSubscriptionsPayload = {}, initialHttpMethod = 'POST', preserveState = true, initialWindows = [], disableAccount = false, } = {}) {
7
+ this.useLocalSandboxUrl = false;
6
8
  this.donation = {
7
9
  url: 'https://opencollective.com/altair/donate',
8
10
  action_count_threshold: 50,
@@ -95,6 +97,50 @@ export class AltairConfig {
95
97
  this.initialData.windows = initialWindows;
96
98
  this.initialData.disableAccount = disableAccount;
97
99
  }
100
+ getPossibleLocalSandBoxUrl() {
101
+ // check document base url
102
+ if (document.baseURI) {
103
+ // add iframe-sandbox path to base url
104
+ if (document.baseURI.endsWith('/')) {
105
+ return new URL(document.baseURI + 'iframe-sandbox/index.html');
106
+ }
107
+ else {
108
+ // remove the last part of the url
109
+ return new URL(document.baseURI.slice(0, document.baseURI.lastIndexOf('/') + 1) +
110
+ 'iframe-sandbox/index.html');
111
+ }
112
+ }
113
+ }
114
+ async getLocalSandBoxUrl() {
115
+ if (typeof this.localSandboxUrl === 'undefined') {
116
+ this.localSandboxUrl = this.getPossibleLocalSandBoxUrl()?.href ?? '';
117
+ if (this.localSandboxUrl) {
118
+ const res = await fetch(this.localSandboxUrl);
119
+ if (res.ok) {
120
+ this.useLocalSandboxUrl = true;
121
+ }
122
+ }
123
+ }
124
+ if (this.useLocalSandboxUrl) {
125
+ return this.localSandboxUrl;
126
+ }
127
+ }
128
+ getUrlConfig(environment = 'production') {
129
+ return urlMap[environment];
130
+ }
131
+ async getUrlConfigWithLocal(environment = 'production') {
132
+ // Check for local sandbox url first
133
+ const localSandboxUrl = await this.getLocalSandBoxUrl();
134
+ const urls = urlMap[environment];
135
+ if (localSandboxUrl) {
136
+ urls.sandbox = localSandboxUrl;
137
+ }
138
+ return urls;
139
+ }
140
+ async getUrl(name, environment = 'production') {
141
+ const urlConfig = await this.getUrlConfigWithLocal(environment);
142
+ return urlConfig[name];
143
+ }
98
144
  }
99
145
  let config = new AltairConfig();
100
146
  export const setAltairConfig = (_config) => {
@@ -104,4 +150,4 @@ export const getAltairConfig = () => {
104
150
  return config;
105
151
  };
106
152
  window.getAltairConfig = getAltairConfig;
107
- //# sourceMappingURL=config.js.map
153
+ //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
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';
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
- export declare class AltairConfig {
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1,8 @@
1
+ import { ConfigEnvironment } from './environment';
2
+ export interface UrlConfig {
3
+ api: string;
4
+ loginClient: string;
5
+ sandbox: string;
6
+ }
7
+ export declare const urlMap: Record<ConfigEnvironment, UrlConfig>;
8
+ //# sourceMappingURL=urls.d.ts.map
@@ -0,0 +1,20 @@
1
+ export const urlMap = {
2
+ development: {
3
+ api: 'http://localhost:3000',
4
+ loginClient: 'http://localhost:1234',
5
+ sandbox: 'http://localhost:5123',
6
+ },
7
+ production: {
8
+ api: undefined ?? 'https://api.altairgraphql.dev',
9
+ loginClient: undefined ??
10
+ 'https://redir.altairgraphql.dev',
11
+ sandbox: undefined ??
12
+ 'https://sandbox.altairgraphql.dev',
13
+ },
14
+ testing: {
15
+ api: 'http://localhost:3000',
16
+ loginClient: 'http://localhost:1234',
17
+ sandbox: 'http://localhost:5123',
18
+ },
19
+ };
20
+ //# sourceMappingURL=urls.js.map
@@ -18,6 +18,8 @@ export class AltairV3Panel {
18
18
  data.styleUrls.forEach((styleUrl) => {
19
19
  const link = document.createElement('link');
20
20
  link.rel = 'stylesheet';
21
+ link.type = 'text/css';
22
+ link.crossOrigin = 'anonymous';
21
23
  link.href = styleUrl;
22
24
  document.head.appendChild(link);
23
25
  });
@@ -63,6 +63,8 @@ export class PluginParentEngine {
63
63
  this.worker.respond(PLUGIN_GET_APP_STYLE_URL_EVENT, async () => {
64
64
  const styleSheets = Array.from(document.styleSheets);
65
65
  // Get the style sheet URLs
66
+ // FYI for some reason I haven't figured out yet, we can't link to the stylesheets
67
+ // in the browser extensions directly from the sandboxed iframe.
66
68
  const styleUrls = styleSheets
67
69
  .map((sheet) => {
68
70
  if (sheet?.href) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "altair-graphql-core",
3
3
  "description": "Several of the core logic for altair graphql client",
4
- "version": "7.2.3",
4
+ "version": "7.2.4",
5
5
  "author": "Samuel Imolorhe <altair@sirmuel.design> (https://sirmuel.design)",
6
6
  "bugs": "https://github.com/altair-graphql/altair/issues",
7
7
  "dependencies": {
@@ -71,10 +71,10 @@
71
71
  "main": "./build/index.js",
72
72
  "repository": "altair-graphql/altair.git",
73
73
  "scripts": {
74
- "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node ./scripts/copy_settings_d_ts.js",
75
- "prepare": "npm run build",
74
+ "build": "node ./scripts/build.js",
75
+ "prepare": "yarn build",
76
76
  "test": "jest"
77
77
  },
78
78
  "types": "./build/index.d.ts",
79
- "gitHead": "ddd163425d45994df9b5f214f848f597a9c85f81"
79
+ "gitHead": "99ad41572f40136876cff51027eca0e575092441"
80
80
  }
@@ -0,0 +1,63 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { execSync } = require('child_process');
4
+ const { copySettingsDTS } = require('./copy_settings_d_ts');
5
+
6
+ const walk = (dir, callback = () => {}) => {
7
+ try {
8
+ let results = [];
9
+ const list = fs.readdirSync(dir);
10
+ list.forEach((file) => {
11
+ file = path.join(dir, file);
12
+ const stat = fs.statSync(file);
13
+ if (stat && stat.isDirectory()) {
14
+ // Recurse into subdir
15
+ results = [...results, ...walk(file, callback)];
16
+ } else {
17
+ // Is a file
18
+ callback(file);
19
+ results.push(file);
20
+ }
21
+ });
22
+ return results;
23
+ } catch (error) {
24
+ console.error(`Error when walking dir ${dir}`, error);
25
+ }
26
+ };
27
+ const replaceProcessEnv = (pkgRoot) => {
28
+ const BUILD_DIR = path.join(pkgRoot, 'build');
29
+
30
+ // Replace process.env variables with actual values in the build directory
31
+ // Iterate over each JavaScript file in the input directory
32
+ walk(BUILD_DIR, (file) => {
33
+ // only replace process.env variables in .js files
34
+ if (!file.endsWith('.js')) {
35
+ return;
36
+ }
37
+ const fileContents = fs.readFileSync(file, 'utf8');
38
+ const replacedContents = fileContents.replace(
39
+ /process\.env\.([A-Za-z0-9_]+)/g,
40
+ (_, p1) => {
41
+ if (!process.env[p1]) {
42
+ return `undefined`;
43
+ }
44
+ return `"${process.env[p1]}"`;
45
+ }
46
+ );
47
+ fs.writeFileSync(file, replacedContents, 'utf8');
48
+ console.log(`Edited file: ${file}`);
49
+ });
50
+ };
51
+
52
+ const main = async () => {
53
+ const CONFIG_PKG_ROOT = path.resolve(__dirname, '../');
54
+ // Build the package
55
+ execSync('yarn tsc -p tsconfig.json', { cwd: CONFIG_PKG_ROOT, stdio: 'inherit' });
56
+ execSync('yarn tsc -p tsconfig.cjs.json', {
57
+ cwd: CONFIG_PKG_ROOT,
58
+ stdio: 'inherit',
59
+ });
60
+ copySettingsDTS();
61
+ replaceProcessEnv(CONFIG_PKG_ROOT);
62
+ };
63
+ main();
@@ -2,29 +2,32 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { execSync } = require('child_process');
4
4
 
5
- const srcDir = path.resolve(__dirname, '../src');
6
- const distSrc = path.resolve(__dirname, '../build');
5
+ const copySettingsDTS = () => {
6
+ const srcDir = path.resolve(__dirname, '../src');
7
+ const distSrc = path.resolve(__dirname, '../build');
7
8
 
8
- execSync(
9
- 'yarn typescript-json-schema --ignoreErrors src/types/state/settings.interfaces.ts SettingsState --out build/settings.schema.json'
10
- );
11
- execSync(
12
- 'yarn ajv compile -s build/settings.schema.json -o build/validate-settings.js'
13
- );
9
+ execSync(
10
+ 'yarn typescript-json-schema --ignoreErrors src/types/state/settings.interfaces.ts SettingsState --out build/settings.schema.json'
11
+ );
12
+ execSync(
13
+ 'yarn ajv compile -s build/settings.schema.json -o build/validate-settings.js'
14
+ );
14
15
 
15
- execSync(
16
- 'yarn typescript-json-schema --ignoreErrors src/types/state/settings.interfaces.ts PartialSettingsState --out build/partial_settings.schema.json'
17
- );
18
- execSync(
19
- 'yarn ajv compile -s build/partial_settings.schema.json -o build/validate-partial-settings.js'
20
- );
16
+ execSync(
17
+ 'yarn typescript-json-schema --ignoreErrors src/types/state/settings.interfaces.ts PartialSettingsState --out build/partial_settings.schema.json'
18
+ );
19
+ execSync(
20
+ 'yarn ajv compile -s build/partial_settings.schema.json -o build/validate-partial-settings.js'
21
+ );
21
22
 
22
- fs.copyFileSync(
23
- path.resolve(srcDir, 'validate-settings.d.ts'),
24
- path.resolve(distSrc, 'validate-settings.d.ts')
25
- );
23
+ fs.copyFileSync(
24
+ path.resolve(srcDir, 'validate-settings.d.ts'),
25
+ path.resolve(distSrc, 'validate-settings.d.ts')
26
+ );
26
27
 
27
- fs.copyFileSync(
28
- path.resolve(srcDir, 'validate-partial-settings.d.ts'),
29
- path.resolve(distSrc, 'validate-partial-settings.d.ts')
30
- );
28
+ fs.copyFileSync(
29
+ path.resolve(srcDir, 'validate-partial-settings.d.ts'),
30
+ path.resolve(distSrc, 'validate-partial-settings.d.ts')
31
+ );
32
+ };
33
+ module.exports.copySettingsDTS = copySettingsDTS;