altair-static 8.2.7 → 8.2.8

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/index.d.ts CHANGED
@@ -108,66 +108,113 @@ export interface IInitialEnvironments {
108
108
  subEnvironments?: InitialEnvironmentState[];
109
109
  }
110
110
  export interface ITheme {
111
+ /** CSS transition easing function for smooth animations */
111
112
  easing: string;
112
113
  colors: {
114
+ /** Black color used for high contrast elements */
113
115
  black: string;
116
+ /** Dark gray color for muted text and secondary elements */
114
117
  darkGray: string;
118
+ /** Medium gray color for neutral backgrounds and borders */
115
119
  gray: string;
120
+ /** Light gray color for subtle backgrounds and dividers */
116
121
  lightGray: string;
122
+ /** White color for light backgrounds and text */
117
123
  white: string;
124
+ /** Green color typically used for success states and positive actions */
118
125
  green: string;
126
+ /** Blue color for informational elements and links */
119
127
  blue: string;
128
+ /** Rose/pink color for accent elements and highlights */
120
129
  rose: string;
130
+ /** Bright magenta/cerise color for special emphasis */
121
131
  cerise: string;
132
+ /** Red color for error states and destructive actions */
122
133
  red: string;
134
+ /** Orange color for warning states and secondary actions */
123
135
  orange: string;
136
+ /** Yellow color for caution states and highlights */
124
137
  yellow: string;
138
+ /** Light red/salmon color for subtle error indicators */
125
139
  lightRed: string;
140
+ /** Dark purple color for premium features or special elements */
126
141
  darkPurple: string;
142
+ /** Primary brand color used for main interactive elements */
127
143
  primary: string;
144
+ /** Secondary brand color used for supporting interactive elements */
128
145
  secondary: string;
146
+ /** Tertiary brand color used for accent and decorative elements */
129
147
  tertiary: string;
148
+ /** Main background color for the application */
130
149
  bg: string;
150
+ /** Alternative background color for cards, panels, and sections */
131
151
  offBg: string;
152
+ /** Primary text color for readable content */
132
153
  font: string;
154
+ /** Secondary text color for less emphasized content */
133
155
  offFont: string;
156
+ /** Primary border color for main UI elements */
134
157
  border: string;
158
+ /** Secondary border color for subtle divisions */
135
159
  offBorder: string;
160
+ /** Background color specifically for the header section */
136
161
  headerBg: string;
137
162
  };
138
163
  type: {
139
164
  fontSize: {
165
+ /** Base font size in pixels used for calculations */
140
166
  base: number;
167
+ /** Root em base size in pixels for responsive typography */
141
168
  remBase: number;
169
+ /** Standard body text font size */
142
170
  body: number;
171
+ /** Smaller body text font size for secondary content */
143
172
  bodySmaller: number;
144
173
  };
145
174
  fontFamily: {
175
+ /** Default system font stack for UI elements */
146
176
  default: string;
147
177
  };
148
178
  };
179
+ /** Whether this theme follows system preferences (light/dark mode) */
149
180
  isSystem: boolean;
150
181
  shadow: {
182
+ /** Color used for drop shadows and elevation effects */
151
183
  color: string;
184
+ /** Opacity level for shadow effects (0.0 to 1.0) */
152
185
  opacity: number;
153
186
  };
154
187
  editor: {
155
188
  fontFamily: {
189
+ /** Font family specifically for code editor and monospace content */
156
190
  default: string;
157
191
  };
192
+ /** Font size for code editor text */
158
193
  fontSize: number;
159
194
  colors: {
195
+ /** Color for code comments and documentation */
160
196
  comment: string;
197
+ /** Color for string literals in code */
161
198
  string: string;
199
+ /** Color for numeric literals in code */
162
200
  number: string;
201
+ /** Color for variable names and identifiers */
163
202
  variable: string;
203
+ /** Color for programming language keywords */
164
204
  keyword: string;
205
+ /** Color for atomic values like boolean literals */
165
206
  atom: string;
207
+ /** Color for HTML/XML/GraphQL attributes */
166
208
  attribute: string;
209
+ /** Color for properties */
167
210
  property: string;
211
+ /** Color for punctuation marks like brackets and commas */
168
212
  punctuation: string;
213
+ /** Color for function, class, type definitions */
169
214
  definition: string;
215
+ /** Color for built-in functions and types */
170
216
  builtin: string;
217
+ /** Color for the text cursor in the editor */
171
218
  cursor: string;
172
219
  };
173
220
  };
@@ -219,6 +266,7 @@ declare class AltairConfig {
219
266
  themes: string[];
220
267
  isTranslateMode: any;
221
268
  isWebApp: any;
269
+ cspNonce: string;
222
270
  initialData: {
223
271
  url: string;
224
272
  subscriptionsEndpoint: string;
@@ -242,7 +290,7 @@ declare class AltairConfig {
242
290
  disableAccount: boolean;
243
291
  initialAuthorization: AltairConfigOptions["initialAuthorization"];
244
292
  };
245
- constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, persistedSettings, initialRequestHandlerId, initialRequestHandlerAdditionalParams, initialSubscriptionRequestHandlerId, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, disableAccount, initialAuthorization, }?: AltairConfigOptions);
293
+ constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, persistedSettings, initialRequestHandlerId, initialRequestHandlerAdditionalParams, initialSubscriptionRequestHandlerId, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, disableAccount, initialAuthorization, cspNonce, }?: AltairConfigOptions);
246
294
  private getPossibleLocalSandBoxUrl;
247
295
  private getLocalSandBoxUrl;
248
296
  getUrlConfig(environment?: ConfigEnvironment): UrlConfig;
@@ -525,6 +573,10 @@ export interface AltairConfigOptions extends AltairWindowOptions {
525
573
  * Disable the account and remote syncing functionality
526
574
  */
527
575
  disableAccount?: boolean;
576
+ /**
577
+ * CSP nonce value to be used in Altair
578
+ */
579
+ cspNonce?: string;
528
580
  }
529
581
  /**
530
582
  * Returns the path to Altair assets, for resolving the assets when rendering Altair
@@ -558,6 +610,7 @@ export declare const renderInitSnippet: (options?: RenderOptions) => string;
558
610
  * @param renderOptions
559
611
  */
560
612
  export declare const renderAltair: (options?: RenderOptions) => string;
613
+ export declare const isSandboxFrame: (path: string) => boolean;
561
614
 
562
615
  export {
563
616
  renderAltair as default,
package/build/index.js CHANGED
@@ -23,6 +23,7 @@ __export(src_exports, {
23
23
  default: () => src_default,
24
24
  getAltairHtml: () => getAltairHtml,
25
25
  getDistDirectory: () => getDistDirectory,
26
+ isSandboxFrame: () => isSandboxFrame,
26
27
  renderAltair: () => renderAltair,
27
28
  renderInitSnippet: () => renderInitSnippet,
28
29
  renderInitialOptions: () => renderInitialOptions
@@ -65,7 +66,8 @@ var optionsProperties = {
65
66
  disableAccount: void 0,
66
67
  persistedSettings: void 0,
67
68
  initialName: void 0,
68
- initialAuthorization: void 0
69
+ initialAuthorization: void 0,
70
+ cspNonce: void 0
69
71
  };
70
72
  var allowedProperties = Object.keys(
71
73
  optionsProperties
@@ -91,18 +93,29 @@ var renderInitSnippet = (options = {}) => {
91
93
  `;
92
94
  };
93
95
  var renderAltair = (options = {}) => {
96
+ var _a, _b;
94
97
  const altairHtml = getAltairHtml();
95
98
  const initialOptions = renderInitSnippet(options);
96
99
  const baseURL = options.baseURL || "./";
97
100
  if (options.serveInitialOptionsInSeperateRequest) {
98
- const scriptName = typeof options.serveInitialOptionsInSeperateRequest === "string" ? options.serveInitialOptionsInSeperateRequest : "initial_options.js";
99
- return altairHtml.replace(/<base.*>/, `<base href="${baseURL}">`).replace(
100
- "</body>",
101
- () => `<script src="${scriptName.replace(/["'<>=]/g, "")}"><\/script></body>`
102
- );
103
- } else {
104
- return altairHtml.replace(/<base.*>/, `<base href="${baseURL}">`).replace("</body>", () => `<script>${initialOptions}<\/script></body>`);
101
+ if (!options.cspNonce) {
102
+ const scriptName = typeof options.serveInitialOptionsInSeperateRequest === "string" ? options.serveInitialOptionsInSeperateRequest : "initial_options.js";
103
+ return altairHtml.replace(/<base.*>/, `<base href="${baseURL}">`).replace("<style>", `<style nonce="${(_a = options.cspNonce) != null ? _a : ""}">`).replace(
104
+ "</body>",
105
+ () => {
106
+ var _a2;
107
+ return `<script nonce="${(_a2 = options.cspNonce) != null ? _a2 : ""}" src="${scriptName.replace(/["'<>=]/g, "")}"><\/script></body>`;
108
+ }
109
+ );
110
+ }
105
111
  }
112
+ return altairHtml.replace(/<base.*>/, `<base href="${baseURL}">`).replace("<style>", `<style nonce="${(_b = options.cspNonce) != null ? _b : ""}">`).replace(
113
+ "</body>",
114
+ () => {
115
+ var _a2;
116
+ return `<script nonce="${(_a2 = options.cspNonce) != null ? _a2 : ""}">${initialOptions}<\/script></body>`;
117
+ }
118
+ );
106
119
  };
107
120
  var getRenderedAltairOpts = (renderOptions) => {
108
121
  const optProps = Object.keys(renderOptions).filter(
@@ -110,11 +123,15 @@ var getRenderedAltairOpts = (renderOptions) => {
110
123
  ).map((key) => getObjectPropertyForOption(renderOptions[key], key));
111
124
  return ["{", ...optProps, "}"].join("\n");
112
125
  };
126
+ var isSandboxFrame = (path) => {
127
+ return path.split("/").includes("iframe-sandbox");
128
+ };
113
129
  var src_default = renderAltair;
114
130
  // Annotate the CommonJS export names for ESM import in node:
115
131
  0 && (module.exports = {
116
132
  getAltairHtml,
117
133
  getDistDirectory,
134
+ isSandboxFrame,
118
135
  renderAltair,
119
136
  renderInitSnippet,
120
137
  renderInitialOptions
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "altair-static",
3
3
  "description": "Static package for altair graphql client",
4
- "version": "8.2.7",
4
+ "version": "8.2.8",
5
5
  "author": "Samuel Imolorhe <altair@sirmuel.design> (https://sirmuel.design)",
6
6
  "bugs": "https://github.com/altair-graphql/altair/issues",
7
7
  "devDependencies": {
@@ -13,8 +13,8 @@
13
13
  "ncp": "2.0.0",
14
14
  "ts-jest": "29.0.5",
15
15
  "typescript": "^5.5.4",
16
- "@altairgraphql/app": "8.2.7",
17
- "altair-graphql-core": "8.2.7"
16
+ "@altairgraphql/app": "8.2.8",
17
+ "altair-graphql-core": "8.2.8"
18
18
  },
19
19
  "engines": {
20
20
  "node": ">= 6.9.1"
@@ -14,7 +14,7 @@ exports[`renderAltair should return expected string 1`] = `
14
14
 
15
15
  <body>
16
16
  <app-root>
17
- <style>
17
+ <style nonce="">
18
18
  .loading-screen {
19
19
  /*Prevents the loading screen from showing until CSS is downloaded*/
20
20
  display: none;
@@ -51,7 +51,7 @@ exports[`renderAltair should return expected string 1`] = `
51
51
  type="text/javascript"
52
52
  src="[% MAIN_SCRIPT %]"
53
53
  ></script>
54
- <script>
54
+ <script nonce="">
55
55
  AltairGraphQL.init({
56
56
  initialQuery: \`query {
57
57
  Hello
@@ -78,7 +78,7 @@ exports[`renderAltair should return expected string with $$ 1`] = `
78
78
 
79
79
  <body>
80
80
  <app-root>
81
- <style>
81
+ <style nonce="">
82
82
  .loading-screen {
83
83
  /*Prevents the loading screen from showing until CSS is downloaded*/
84
84
  display: none;
@@ -115,7 +115,7 @@ exports[`renderAltair should return expected string with $$ 1`] = `
115
115
  type="text/javascript"
116
116
  src="[% MAIN_SCRIPT %]"
117
117
  ></script>
118
- <script>
118
+ <script nonce="">
119
119
  AltairGraphQL.init({
120
120
  initialQuery: \`{
121
121
  MyDomains (
package/src/index.ts CHANGED
@@ -43,6 +43,7 @@ const optionsProperties: AltairConfigOptionsObject = {
43
43
  persistedSettings: undefined,
44
44
  initialName: undefined,
45
45
  initialAuthorization: undefined,
46
+ cspNonce: undefined,
46
47
  };
47
48
  const allowedProperties = Object.keys(
48
49
  optionsProperties
@@ -92,21 +93,34 @@ export const renderAltair = (options: RenderOptions = {}) => {
92
93
  const initialOptions = renderInitSnippet(options);
93
94
  const baseURL = options.baseURL || './';
94
95
  if (options.serveInitialOptionsInSeperateRequest) {
95
- const scriptName =
96
- typeof options.serveInitialOptionsInSeperateRequest === 'string'
97
- ? options.serveInitialOptionsInSeperateRequest
98
- : 'initial_options.js';
99
- return altairHtml
100
- .replace(/<base.*>/, `<base href="${baseURL}">`)
101
- .replace(
102
- '</body>',
103
- () => `<script src="${scriptName.replace(/["'<>=]/g, '')}"></script></body>`
104
- );
105
- } else {
106
- return altairHtml
107
- .replace(/<base.*>/, `<base href="${baseURL}">`)
108
- .replace('</body>', () => `<script>${initialOptions}</script></body>`);
96
+ if (!options.cspNonce) {
97
+ // When using cspNonce, the initial options must be inlined to avoid CSP issues
98
+ // because loading a the script in a separate request will likely cause a new CSP nonce to be generated
99
+ // which will not match the original nonce used in the main HTML file
100
+ // and thus the script will be blocked by the browser.
101
+ const scriptName =
102
+ typeof options.serveInitialOptionsInSeperateRequest === 'string'
103
+ ? options.serveInitialOptionsInSeperateRequest
104
+ : 'initial_options.js';
105
+ return altairHtml
106
+ .replace(/<base.*>/, `<base href="${baseURL}">`)
107
+ .replace('<style>', `<style nonce="${options.cspNonce ?? ''}">`)
108
+ .replace(
109
+ '</body>',
110
+ () =>
111
+ `<script nonce="${options.cspNonce ?? ''}" src="${scriptName.replace(/["'<>=]/g, '')}"></script></body>`
112
+ );
113
+ }
109
114
  }
115
+
116
+ return altairHtml
117
+ .replace(/<base.*>/, `<base href="${baseURL}">`)
118
+ .replace('<style>', `<style nonce="${options.cspNonce ?? ''}">`)
119
+ .replace(
120
+ '</body>',
121
+ () =>
122
+ `<script nonce="${options.cspNonce ?? ''}">${initialOptions}</script></body>`
123
+ );
110
124
  };
111
125
 
112
126
  const getRenderedAltairOpts = (renderOptions: RenderOptions) => {
@@ -119,6 +133,10 @@ const getRenderedAltairOpts = (renderOptions: RenderOptions) => {
119
133
  return ['{', ...optProps, '}'].join('\n');
120
134
  };
121
135
 
136
+ export const isSandboxFrame = (path: string) => {
137
+ return path.split('/').includes('iframe-sandbox');
138
+ };
139
+
122
140
  export { getDistDirectory } from './get-dist';
123
141
  export { getAltairHtml };
124
142