altair-graphql-core 8.2.4 → 8.2.7
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/.turbo/turbo-bootstrap.log +4 -2
- package/build/cjs/config/index.js +11 -0
- package/build/cjs/request/response-builder.js +3 -1
- package/build/cjs/request/response-builder.spec.js +2 -0
- package/build/cjs/script/context.d.ts +1 -1
- package/build/cjs/script/context.js +7 -4
- package/build/cjs/script/context.spec.d.ts +2 -0
- package/build/cjs/script/context.spec.js +102 -0
- package/build/cjs/script/types.d.ts +6 -6
- package/build/cjs/types/state/query.interfaces.d.ts +1 -0
- package/build/cjs/types/state/settings.interfaces.d.ts +4 -0
- package/build/cjs/types/state/window.interfaces.d.ts +11 -11
- package/build/config/index.js +11 -0
- package/build/request/response-builder.js +3 -1
- package/build/request/response-builder.spec.js +2 -0
- package/build/script/context.d.ts +1 -1
- package/build/script/context.js +7 -4
- package/build/script/context.spec.d.ts +2 -0
- package/build/script/context.spec.js +100 -0
- package/build/script/types.d.ts +6 -6
- package/build/typegen/partial_settings.schema.json +4 -0
- package/build/typegen/settings.schema.json +4 -0
- package/build/typegen/validate-partial-settings.js +1 -1
- package/build/typegen/validate-settings.js +1 -1
- package/build/types/state/query.interfaces.d.ts +1 -0
- package/build/types/state/settings.interfaces.d.ts +4 -0
- package/build/types/state/window.interfaces.d.ts +11 -11
- package/package.json +3 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> altair-graphql-core@8.2.
|
|
2
|
+
> altair-graphql-core@8.2.7 bootstrap /home/runner/work/altair/altair/packages/altair-core
|
|
3
3
|
> pnpm build
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> altair-graphql-core@8.2.
|
|
6
|
+
> altair-graphql-core@8.2.7 build /home/runner/work/altair/altair/packages/altair-core
|
|
7
7
|
> node ./scripts/build.js
|
|
8
8
|
|
|
9
9
|
Generating types for partial-settings ...
|
|
@@ -80,6 +80,7 @@ Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/requ
|
|
|
80
80
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/request/types.js
|
|
81
81
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/request/utils.js
|
|
82
82
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/script/context.js
|
|
83
|
+
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/script/context.spec.js
|
|
83
84
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/script/errors.js
|
|
84
85
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/script/evaluator-client-engine.js
|
|
85
86
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/cjs/script/evaluator-worker-engine.js
|
|
@@ -184,6 +185,7 @@ Edited file: /home/runner/work/altair/altair/packages/altair-core/build/request/
|
|
|
184
185
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/request/types.js
|
|
185
186
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/request/utils.js
|
|
186
187
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/script/context.js
|
|
188
|
+
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/script/context.spec.js
|
|
187
189
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/script/errors.js
|
|
188
190
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/script/evaluator-client-engine.js
|
|
189
191
|
Edited file: /home/runner/work/altair/altair/packages/altair-core/build/script/evaluator-worker-engine.js
|
|
@@ -4,6 +4,7 @@ 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 crx_1 = require("../crx");
|
|
7
8
|
const types_1 = require("../request/types");
|
|
8
9
|
const is_electron_1 = __importDefault(require("../utils/is_electron"));
|
|
9
10
|
const urls_1 = require("./urls");
|
|
@@ -114,6 +115,16 @@ class AltairConfig {
|
|
|
114
115
|
this.initialData.initialAuthorization = initialAuthorization;
|
|
115
116
|
}
|
|
116
117
|
getPossibleLocalSandBoxUrl() {
|
|
118
|
+
if (crx_1.isExtension) {
|
|
119
|
+
// we only support mv3 extensions now
|
|
120
|
+
// and mv3 extensions doesn't allow using iframe
|
|
121
|
+
// sandbox with allow-same-origin so we have to open up
|
|
122
|
+
// the postMessage without origin verification
|
|
123
|
+
// This doesn't sit well with me, so for now we don't
|
|
124
|
+
// support local sandbox for extensions.
|
|
125
|
+
// We can revisit this later if needed.
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
117
128
|
// check document base url
|
|
118
129
|
if (document.baseURI &&
|
|
119
130
|
parseUrl(document.baseURI)?.origin === window.location.origin) {
|
|
@@ -44,6 +44,7 @@ const buildResponse__concatenate = (responses) => {
|
|
|
44
44
|
{
|
|
45
45
|
content: parsedContent ? JSON.stringify(parsedContent, null, 2) : content,
|
|
46
46
|
timestamp: responses.at(-1)?.timestamp ?? 0,
|
|
47
|
+
json: !!parsedContent, // if parsedContent is not null, then it's JSON
|
|
47
48
|
},
|
|
48
49
|
];
|
|
49
50
|
};
|
|
@@ -76,12 +77,13 @@ const buildResponse__patch = (responses) => {
|
|
|
76
77
|
{
|
|
77
78
|
content: JSON.stringify(obj, null, 2),
|
|
78
79
|
timestamp: responses.at(0)?.timestamp ?? 0,
|
|
80
|
+
json: true, // always JSON for patched responses
|
|
79
81
|
},
|
|
80
82
|
];
|
|
81
83
|
};
|
|
82
84
|
const patchResponse = (obj, nextData) => {
|
|
83
85
|
const result = { ...obj };
|
|
84
|
-
|
|
86
|
+
const errors = result.errors ? result.errors : [];
|
|
85
87
|
const extensions = {
|
|
86
88
|
...result.extensions,
|
|
87
89
|
...('extensions' in nextData ? nextData.extensions : {}),
|
|
@@ -149,6 +149,7 @@ const responseChunks = [
|
|
|
149
149
|
{
|
|
150
150
|
content: '',
|
|
151
151
|
timestamp: 0,
|
|
152
|
+
json: false,
|
|
152
153
|
},
|
|
153
154
|
]);
|
|
154
155
|
});
|
|
@@ -272,6 +273,7 @@ const responseChunks = [
|
|
|
272
273
|
{
|
|
273
274
|
content: '',
|
|
274
275
|
timestamp: 0,
|
|
276
|
+
json: false,
|
|
275
277
|
},
|
|
276
278
|
]);
|
|
277
279
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GlobalContextBuilderHandlers, GlobalHelperContext, ModuleImportsMap, ScriptContextData, ScriptContextResponse } from './types';
|
|
2
2
|
export declare const ModuleImports: ModuleImportsMap;
|
|
3
3
|
export declare const buildContextResponse: (data: ScriptContextData) => ScriptContextResponse | undefined;
|
|
4
|
-
export declare const importModuleHelper: (moduleName: string) => Promise<
|
|
4
|
+
export declare const importModuleHelper: (moduleName: string) => Promise<unknown>;
|
|
5
5
|
export declare const getGlobalContext: (data: ScriptContextData, handlers: GlobalContextBuilderHandlers) => GlobalHelperContext;
|
|
6
6
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getGlobalContext = exports.importModuleHelper = exports.buildContextResponse = exports.ModuleImports = void 0;
|
|
27
27
|
const types_1 = require("./types");
|
|
28
|
+
const object_path_1 = require("object-path");
|
|
28
29
|
exports.ModuleImports = {
|
|
29
30
|
atob: {
|
|
30
31
|
async exec() {
|
|
@@ -67,18 +68,20 @@ const getGlobalContext = (data, handlers) => {
|
|
|
67
68
|
data,
|
|
68
69
|
helpers: {
|
|
69
70
|
getEnvironment: (key) => {
|
|
70
|
-
|
|
71
|
+
// Support nested environment variable access using dot notation (e.g., 'user.name')
|
|
72
|
+
return (0, object_path_1.get)(data.environment, key);
|
|
71
73
|
},
|
|
72
74
|
/**
|
|
73
|
-
* @param key environment key
|
|
75
|
+
* @param key environment key (supports nested paths using dot notation, e.g., 'user.name')
|
|
74
76
|
* @param val value to set
|
|
75
77
|
* @param activeEnvironment if the value should be replaced in the currently active environment after execution
|
|
76
78
|
*/
|
|
77
79
|
setEnvironment: (key, val, activeEnvironment = false) => {
|
|
78
|
-
|
|
80
|
+
// Support nested environment variable setting using dot notation (e.g., 'user.name')
|
|
81
|
+
(0, object_path_1.set)(data.environment, key, val);
|
|
79
82
|
if (activeEnvironment) {
|
|
80
83
|
data.__toSetActiveEnvironment = data.__toSetActiveEnvironment ?? {};
|
|
81
|
-
data.__toSetActiveEnvironment
|
|
84
|
+
(0, object_path_1.set)(data.__toSetActiveEnvironment, key, val);
|
|
82
85
|
}
|
|
83
86
|
},
|
|
84
87
|
getCookie: (key) => {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const context_1 = require("./context");
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
describe('Script Context', () => {
|
|
6
|
+
let mockHandlers;
|
|
7
|
+
let mockData;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockHandlers = {
|
|
10
|
+
setCookie: jest.fn(),
|
|
11
|
+
request: jest.fn(),
|
|
12
|
+
getStorageItem: jest.fn(),
|
|
13
|
+
setStorageItem: jest.fn(),
|
|
14
|
+
};
|
|
15
|
+
mockData = {
|
|
16
|
+
headers: [],
|
|
17
|
+
variables: '{}',
|
|
18
|
+
operationName: '',
|
|
19
|
+
query: '',
|
|
20
|
+
url: '',
|
|
21
|
+
environment: {
|
|
22
|
+
baseUrl: 'https://api.example.com',
|
|
23
|
+
user: {
|
|
24
|
+
name: 'John Doe',
|
|
25
|
+
profile: {
|
|
26
|
+
email: 'john@example.com',
|
|
27
|
+
settings: {
|
|
28
|
+
theme: 'dark',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
apiKey: 'secret-key',
|
|
33
|
+
},
|
|
34
|
+
requestScriptLogs: [],
|
|
35
|
+
requestType: types_1.RequestType.QUERY,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
describe('getEnvironment helper', () => {
|
|
39
|
+
it('should get top-level environment variables', () => {
|
|
40
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
41
|
+
expect(context.helpers.getEnvironment('baseUrl')).toBe('https://api.example.com');
|
|
42
|
+
expect(context.helpers.getEnvironment('apiKey')).toBe('secret-key');
|
|
43
|
+
});
|
|
44
|
+
it('should get nested environment variables using dot notation', () => {
|
|
45
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
46
|
+
expect(context.helpers.getEnvironment('user.name')).toBe('John Doe');
|
|
47
|
+
expect(context.helpers.getEnvironment('user.profile.email')).toBe('john@example.com');
|
|
48
|
+
expect(context.helpers.getEnvironment('user.profile.settings.theme')).toBe('dark');
|
|
49
|
+
});
|
|
50
|
+
it('should return undefined for non-existent paths', () => {
|
|
51
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
52
|
+
expect(context.helpers.getEnvironment('nonexistent')).toBeUndefined();
|
|
53
|
+
expect(context.helpers.getEnvironment('user.nonexistent')).toBeUndefined();
|
|
54
|
+
expect(context.helpers.getEnvironment('user.profile.nonexistent')).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
it('should handle empty or invalid paths gracefully', () => {
|
|
57
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
58
|
+
expect(context.helpers.getEnvironment('')).toBe(mockData.environment);
|
|
59
|
+
expect(context.helpers.getEnvironment('user.')).toBeUndefined();
|
|
60
|
+
expect(context.helpers.getEnvironment('.user')).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('setEnvironment helper', () => {
|
|
64
|
+
it('should set top-level environment variables', () => {
|
|
65
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
66
|
+
context.helpers.setEnvironment('newVar', 'newValue');
|
|
67
|
+
expect(context.helpers.getEnvironment('newVar')).toBe('newValue');
|
|
68
|
+
});
|
|
69
|
+
it('should set nested environment variables using dot notation', () => {
|
|
70
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
71
|
+
context.helpers.setEnvironment('user.age', 30);
|
|
72
|
+
expect(context.helpers.getEnvironment('user.age')).toBe(30);
|
|
73
|
+
context.helpers.setEnvironment('user.profile.settings.language', 'en');
|
|
74
|
+
expect(context.helpers.getEnvironment('user.profile.settings.language')).toBe('en');
|
|
75
|
+
});
|
|
76
|
+
it('should create nested structure when setting deep paths', () => {
|
|
77
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
78
|
+
context.helpers.setEnvironment('new.nested.path', 'value');
|
|
79
|
+
expect(context.helpers.getEnvironment('new.nested.path')).toBe('value');
|
|
80
|
+
expect(context.helpers.getEnvironment('new.nested')).toEqual({
|
|
81
|
+
path: 'value',
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it('should set activeEnvironment when activeEnvironment flag is true', () => {
|
|
85
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
86
|
+
context.helpers.setEnvironment('testVar', 'testValue', true);
|
|
87
|
+
expect(context.data.__toSetActiveEnvironment).toEqual({
|
|
88
|
+
testVar: 'testValue',
|
|
89
|
+
});
|
|
90
|
+
context.helpers.setEnvironment('nested.var', 'nestedValue', true);
|
|
91
|
+
expect(context.data.__toSetActiveEnvironment?.nested).toEqual({
|
|
92
|
+
var: 'nestedValue',
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it('should not set activeEnvironment when activeEnvironment flag is false', () => {
|
|
96
|
+
const context = (0, context_1.getGlobalContext)(mockData, mockHandlers);
|
|
97
|
+
context.helpers.setEnvironment('testVar', 'testValue', false);
|
|
98
|
+
expect(context.data.__toSetActiveEnvironment).toBeUndefined();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=context.spec.js.map
|
|
@@ -19,11 +19,11 @@ export declare enum RequestType {
|
|
|
19
19
|
SUBSCRIPTION = "subscription"
|
|
20
20
|
}
|
|
21
21
|
export interface ScriptContextHelpers {
|
|
22
|
-
getEnvironment: (key: string) =>
|
|
23
|
-
setEnvironment: (key: string, value:
|
|
22
|
+
getEnvironment: (key: string) => unknown;
|
|
23
|
+
setEnvironment: (key: string, value: unknown, activeEnvironment?: boolean) => void;
|
|
24
24
|
getCookie: (key: string) => string;
|
|
25
25
|
setCookie: (key: string, value: string) => void;
|
|
26
|
-
request: (arg1:
|
|
26
|
+
request: (arg1: string, arg2: string, arg3: any) => Promise<ArrayBuffer | null>;
|
|
27
27
|
}
|
|
28
28
|
export interface ScriptContextStorage {
|
|
29
29
|
get: (key: string) => Promise<unknown>;
|
|
@@ -54,7 +54,7 @@ export interface GlobalHelperContext {
|
|
|
54
54
|
data: ScriptContextData;
|
|
55
55
|
helpers: ScriptContextHelpers;
|
|
56
56
|
storage: ScriptContextStorage;
|
|
57
|
-
importModule: (moduleName: string) =>
|
|
57
|
+
importModule: (moduleName: string) => unknown;
|
|
58
58
|
log: (d: unknown) => void;
|
|
59
59
|
response?: ScriptContextResponse;
|
|
60
60
|
}
|
|
@@ -79,13 +79,13 @@ export interface GlobalContextBuilderHandlers {
|
|
|
79
79
|
}
|
|
80
80
|
export interface ModuleImportsMap {
|
|
81
81
|
[name: string]: {
|
|
82
|
-
exec: () => Promise<
|
|
82
|
+
exec: () => Promise<unknown>;
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
export interface ScriptEventHandlers {
|
|
86
86
|
alert: (msg: string) => Promise<void>;
|
|
87
87
|
log: (d: unknown) => Promise<void>;
|
|
88
|
-
request: (arg1:
|
|
88
|
+
request: (arg1: string, arg2: string, arg3: any) => Promise<any>;
|
|
89
89
|
setCookie: (key: string, value: string, options?: CookieOptions) => Promise<void>;
|
|
90
90
|
getStorageItem: (key: string) => Promise<unknown>;
|
|
91
91
|
setStorageItem: (key: string, value: unknown) => Promise<void>;
|
|
@@ -19,17 +19,17 @@ export interface ExportWindowState {
|
|
|
19
19
|
}>;
|
|
20
20
|
variables: string;
|
|
21
21
|
subscriptionUrl: string;
|
|
22
|
-
subscriptionConnectionParams
|
|
23
|
-
requestHandlerId
|
|
24
|
-
requestHandlerAdditionalParams
|
|
25
|
-
subscriptionUseDefaultRequestHandler
|
|
26
|
-
subscriptionRequestHandlerId
|
|
27
|
-
preRequestScript
|
|
28
|
-
preRequestScriptEnabled
|
|
29
|
-
postRequestScript
|
|
30
|
-
postRequestScriptEnabled
|
|
31
|
-
authorizationType
|
|
32
|
-
authorizationData
|
|
22
|
+
subscriptionConnectionParams: string | undefined;
|
|
23
|
+
requestHandlerId: RequestHandlerIds | undefined;
|
|
24
|
+
requestHandlerAdditionalParams: string | undefined;
|
|
25
|
+
subscriptionUseDefaultRequestHandler: boolean | undefined;
|
|
26
|
+
subscriptionRequestHandlerId: RequestHandlerIds | undefined;
|
|
27
|
+
preRequestScript: string | undefined;
|
|
28
|
+
preRequestScriptEnabled: boolean | undefined;
|
|
29
|
+
postRequestScript: string | undefined;
|
|
30
|
+
postRequestScriptEnabled: boolean | undefined;
|
|
31
|
+
authorizationType: string | undefined;
|
|
32
|
+
authorizationData: unknown | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* ID of the collection this query belongs to
|
|
35
35
|
*/
|
package/build/config/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isExtension } from '../crx';
|
|
1
2
|
import { HTTP_HANDLER_ID, WEBSOCKET_HANDLER_ID, } from '../request/types';
|
|
2
3
|
import isElectron from '../utils/is_electron';
|
|
3
4
|
import { urlMap } from './urls';
|
|
@@ -108,6 +109,16 @@ export class AltairConfig {
|
|
|
108
109
|
this.initialData.initialAuthorization = initialAuthorization;
|
|
109
110
|
}
|
|
110
111
|
getPossibleLocalSandBoxUrl() {
|
|
112
|
+
if (isExtension) {
|
|
113
|
+
// we only support mv3 extensions now
|
|
114
|
+
// and mv3 extensions doesn't allow using iframe
|
|
115
|
+
// sandbox with allow-same-origin so we have to open up
|
|
116
|
+
// the postMessage without origin verification
|
|
117
|
+
// This doesn't sit well with me, so for now we don't
|
|
118
|
+
// support local sandbox for extensions.
|
|
119
|
+
// We can revisit this later if needed.
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
111
122
|
// check document base url
|
|
112
123
|
if (document.baseURI &&
|
|
113
124
|
parseUrl(document.baseURI)?.origin === window.location.origin) {
|
|
@@ -40,6 +40,7 @@ const buildResponse__concatenate = (responses) => {
|
|
|
40
40
|
{
|
|
41
41
|
content: parsedContent ? JSON.stringify(parsedContent, null, 2) : content,
|
|
42
42
|
timestamp: responses.at(-1)?.timestamp ?? 0,
|
|
43
|
+
json: !!parsedContent, // if parsedContent is not null, then it's JSON
|
|
43
44
|
},
|
|
44
45
|
];
|
|
45
46
|
};
|
|
@@ -72,12 +73,13 @@ const buildResponse__patch = (responses) => {
|
|
|
72
73
|
{
|
|
73
74
|
content: JSON.stringify(obj, null, 2),
|
|
74
75
|
timestamp: responses.at(0)?.timestamp ?? 0,
|
|
76
|
+
json: true, // always JSON for patched responses
|
|
75
77
|
},
|
|
76
78
|
];
|
|
77
79
|
};
|
|
78
80
|
const patchResponse = (obj, nextData) => {
|
|
79
81
|
const result = { ...obj };
|
|
80
|
-
|
|
82
|
+
const errors = result.errors ? result.errors : [];
|
|
81
83
|
const extensions = {
|
|
82
84
|
...result.extensions,
|
|
83
85
|
...('extensions' in nextData ? nextData.extensions : {}),
|
|
@@ -147,6 +147,7 @@ describe('response-builder', () => {
|
|
|
147
147
|
{
|
|
148
148
|
content: '',
|
|
149
149
|
timestamp: 0,
|
|
150
|
+
json: false,
|
|
150
151
|
},
|
|
151
152
|
]);
|
|
152
153
|
});
|
|
@@ -270,6 +271,7 @@ describe('response-builder', () => {
|
|
|
270
271
|
{
|
|
271
272
|
content: '',
|
|
272
273
|
timestamp: 0,
|
|
274
|
+
json: false,
|
|
273
275
|
},
|
|
274
276
|
]);
|
|
275
277
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GlobalContextBuilderHandlers, GlobalHelperContext, ModuleImportsMap, ScriptContextData, ScriptContextResponse } from './types';
|
|
2
2
|
export declare const ModuleImports: ModuleImportsMap;
|
|
3
3
|
export declare const buildContextResponse: (data: ScriptContextData) => ScriptContextResponse | undefined;
|
|
4
|
-
export declare const importModuleHelper: (moduleName: string) => Promise<
|
|
4
|
+
export declare const importModuleHelper: (moduleName: string) => Promise<unknown>;
|
|
5
5
|
export declare const getGlobalContext: (data: ScriptContextData, handlers: GlobalContextBuilderHandlers) => GlobalHelperContext;
|
|
6
6
|
//# sourceMappingURL=context.d.ts.map
|
package/build/script/context.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RequestType, } from './types';
|
|
2
|
+
import { get, set } from 'object-path';
|
|
2
3
|
export const ModuleImports = {
|
|
3
4
|
atob: {
|
|
4
5
|
async exec() {
|
|
@@ -39,18 +40,20 @@ export const getGlobalContext = (data, handlers) => {
|
|
|
39
40
|
data,
|
|
40
41
|
helpers: {
|
|
41
42
|
getEnvironment: (key) => {
|
|
42
|
-
|
|
43
|
+
// Support nested environment variable access using dot notation (e.g., 'user.name')
|
|
44
|
+
return get(data.environment, key);
|
|
43
45
|
},
|
|
44
46
|
/**
|
|
45
|
-
* @param key environment key
|
|
47
|
+
* @param key environment key (supports nested paths using dot notation, e.g., 'user.name')
|
|
46
48
|
* @param val value to set
|
|
47
49
|
* @param activeEnvironment if the value should be replaced in the currently active environment after execution
|
|
48
50
|
*/
|
|
49
51
|
setEnvironment: (key, val, activeEnvironment = false) => {
|
|
50
|
-
|
|
52
|
+
// Support nested environment variable setting using dot notation (e.g., 'user.name')
|
|
53
|
+
set(data.environment, key, val);
|
|
51
54
|
if (activeEnvironment) {
|
|
52
55
|
data.__toSetActiveEnvironment = data.__toSetActiveEnvironment ?? {};
|
|
53
|
-
data.__toSetActiveEnvironment
|
|
56
|
+
set(data.__toSetActiveEnvironment, key, val);
|
|
54
57
|
}
|
|
55
58
|
},
|
|
56
59
|
getCookie: (key) => {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { getGlobalContext } from './context';
|
|
2
|
+
import { RequestType, } from './types';
|
|
3
|
+
describe('Script Context', () => {
|
|
4
|
+
let mockHandlers;
|
|
5
|
+
let mockData;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
mockHandlers = {
|
|
8
|
+
setCookie: jest.fn(),
|
|
9
|
+
request: jest.fn(),
|
|
10
|
+
getStorageItem: jest.fn(),
|
|
11
|
+
setStorageItem: jest.fn(),
|
|
12
|
+
};
|
|
13
|
+
mockData = {
|
|
14
|
+
headers: [],
|
|
15
|
+
variables: '{}',
|
|
16
|
+
operationName: '',
|
|
17
|
+
query: '',
|
|
18
|
+
url: '',
|
|
19
|
+
environment: {
|
|
20
|
+
baseUrl: 'https://api.example.com',
|
|
21
|
+
user: {
|
|
22
|
+
name: 'John Doe',
|
|
23
|
+
profile: {
|
|
24
|
+
email: 'john@example.com',
|
|
25
|
+
settings: {
|
|
26
|
+
theme: 'dark',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
apiKey: 'secret-key',
|
|
31
|
+
},
|
|
32
|
+
requestScriptLogs: [],
|
|
33
|
+
requestType: RequestType.QUERY,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
describe('getEnvironment helper', () => {
|
|
37
|
+
it('should get top-level environment variables', () => {
|
|
38
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
39
|
+
expect(context.helpers.getEnvironment('baseUrl')).toBe('https://api.example.com');
|
|
40
|
+
expect(context.helpers.getEnvironment('apiKey')).toBe('secret-key');
|
|
41
|
+
});
|
|
42
|
+
it('should get nested environment variables using dot notation', () => {
|
|
43
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
44
|
+
expect(context.helpers.getEnvironment('user.name')).toBe('John Doe');
|
|
45
|
+
expect(context.helpers.getEnvironment('user.profile.email')).toBe('john@example.com');
|
|
46
|
+
expect(context.helpers.getEnvironment('user.profile.settings.theme')).toBe('dark');
|
|
47
|
+
});
|
|
48
|
+
it('should return undefined for non-existent paths', () => {
|
|
49
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
50
|
+
expect(context.helpers.getEnvironment('nonexistent')).toBeUndefined();
|
|
51
|
+
expect(context.helpers.getEnvironment('user.nonexistent')).toBeUndefined();
|
|
52
|
+
expect(context.helpers.getEnvironment('user.profile.nonexistent')).toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
it('should handle empty or invalid paths gracefully', () => {
|
|
55
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
56
|
+
expect(context.helpers.getEnvironment('')).toBe(mockData.environment);
|
|
57
|
+
expect(context.helpers.getEnvironment('user.')).toBeUndefined();
|
|
58
|
+
expect(context.helpers.getEnvironment('.user')).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('setEnvironment helper', () => {
|
|
62
|
+
it('should set top-level environment variables', () => {
|
|
63
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
64
|
+
context.helpers.setEnvironment('newVar', 'newValue');
|
|
65
|
+
expect(context.helpers.getEnvironment('newVar')).toBe('newValue');
|
|
66
|
+
});
|
|
67
|
+
it('should set nested environment variables using dot notation', () => {
|
|
68
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
69
|
+
context.helpers.setEnvironment('user.age', 30);
|
|
70
|
+
expect(context.helpers.getEnvironment('user.age')).toBe(30);
|
|
71
|
+
context.helpers.setEnvironment('user.profile.settings.language', 'en');
|
|
72
|
+
expect(context.helpers.getEnvironment('user.profile.settings.language')).toBe('en');
|
|
73
|
+
});
|
|
74
|
+
it('should create nested structure when setting deep paths', () => {
|
|
75
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
76
|
+
context.helpers.setEnvironment('new.nested.path', 'value');
|
|
77
|
+
expect(context.helpers.getEnvironment('new.nested.path')).toBe('value');
|
|
78
|
+
expect(context.helpers.getEnvironment('new.nested')).toEqual({
|
|
79
|
+
path: 'value',
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it('should set activeEnvironment when activeEnvironment flag is true', () => {
|
|
83
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
84
|
+
context.helpers.setEnvironment('testVar', 'testValue', true);
|
|
85
|
+
expect(context.data.__toSetActiveEnvironment).toEqual({
|
|
86
|
+
testVar: 'testValue',
|
|
87
|
+
});
|
|
88
|
+
context.helpers.setEnvironment('nested.var', 'nestedValue', true);
|
|
89
|
+
expect(context.data.__toSetActiveEnvironment?.nested).toEqual({
|
|
90
|
+
var: 'nestedValue',
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
it('should not set activeEnvironment when activeEnvironment flag is false', () => {
|
|
94
|
+
const context = getGlobalContext(mockData, mockHandlers);
|
|
95
|
+
context.helpers.setEnvironment('testVar', 'testValue', false);
|
|
96
|
+
expect(context.data.__toSetActiveEnvironment).toBeUndefined();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=context.spec.js.map
|
package/build/script/types.d.ts
CHANGED
|
@@ -19,11 +19,11 @@ export declare enum RequestType {
|
|
|
19
19
|
SUBSCRIPTION = "subscription"
|
|
20
20
|
}
|
|
21
21
|
export interface ScriptContextHelpers {
|
|
22
|
-
getEnvironment: (key: string) =>
|
|
23
|
-
setEnvironment: (key: string, value:
|
|
22
|
+
getEnvironment: (key: string) => unknown;
|
|
23
|
+
setEnvironment: (key: string, value: unknown, activeEnvironment?: boolean) => void;
|
|
24
24
|
getCookie: (key: string) => string;
|
|
25
25
|
setCookie: (key: string, value: string) => void;
|
|
26
|
-
request: (arg1:
|
|
26
|
+
request: (arg1: string, arg2: string, arg3: any) => Promise<ArrayBuffer | null>;
|
|
27
27
|
}
|
|
28
28
|
export interface ScriptContextStorage {
|
|
29
29
|
get: (key: string) => Promise<unknown>;
|
|
@@ -54,7 +54,7 @@ export interface GlobalHelperContext {
|
|
|
54
54
|
data: ScriptContextData;
|
|
55
55
|
helpers: ScriptContextHelpers;
|
|
56
56
|
storage: ScriptContextStorage;
|
|
57
|
-
importModule: (moduleName: string) =>
|
|
57
|
+
importModule: (moduleName: string) => unknown;
|
|
58
58
|
log: (d: unknown) => void;
|
|
59
59
|
response?: ScriptContextResponse;
|
|
60
60
|
}
|
|
@@ -79,13 +79,13 @@ export interface GlobalContextBuilderHandlers {
|
|
|
79
79
|
}
|
|
80
80
|
export interface ModuleImportsMap {
|
|
81
81
|
[name: string]: {
|
|
82
|
-
exec: () => Promise<
|
|
82
|
+
exec: () => Promise<unknown>;
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
export interface ScriptEventHandlers {
|
|
86
86
|
alert: (msg: string) => Promise<void>;
|
|
87
87
|
log: (d: unknown) => Promise<void>;
|
|
88
|
-
request: (arg1:
|
|
88
|
+
request: (arg1: string, arg2: string, arg3: any) => Promise<any>;
|
|
89
89
|
setCookie: (key: string, value: string, options?: CookieOptions) => Promise<void>;
|
|
90
90
|
getStorageItem: (key: string) => Promise<unknown>;
|
|
91
91
|
setStorageItem: (key: string, value: unknown) => Promise<void>;
|
|
@@ -269,6 +269,10 @@
|
|
|
269
269
|
"description": "Disable warning alerts",
|
|
270
270
|
"type": "boolean"
|
|
271
271
|
},
|
|
272
|
+
"banners.disable": {
|
|
273
|
+
"description": "Disable banners",
|
|
274
|
+
"type": "boolean"
|
|
275
|
+
},
|
|
272
276
|
"beta.disable.newEditor": {
|
|
273
277
|
"description": "Disable new editor beta",
|
|
274
278
|
"type": "boolean"
|
|
@@ -269,6 +269,10 @@
|
|
|
269
269
|
"description": "Disable warning alerts",
|
|
270
270
|
"type": "boolean"
|
|
271
271
|
},
|
|
272
|
+
"banners.disable": {
|
|
273
|
+
"description": "Disable banners",
|
|
274
|
+
"type": "boolean"
|
|
275
|
+
},
|
|
272
276
|
"beta.disable.newEditor": {
|
|
273
277
|
"description": "Disable new editor beta",
|
|
274
278
|
"type": "boolean"
|