@forge/cli-shared 10.0.1-next.4 → 10.1.0-next.5
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/CHANGELOG.md +6 -0
- package/out/apps/get-app-owner.d.ts.map +1 -1
- package/out/graphql/gql/graphql.d.ts +29 -3
- package/out/graphql/gql/graphql.d.ts.map +1 -1
- package/out/service/statsig-service.d.ts +13 -2
- package/out/service/statsig-service.d.ts.map +1 -1
- package/out/service/statsig-service.js +90 -2
- package/package.json +2 -1
|
@@ -10,12 +10,18 @@ export type DynamicConfig = {
|
|
|
10
10
|
'xls-forge-cli-deprecated-runtimes': string[];
|
|
11
11
|
'forge-cli-enable-custom-spinner': string[];
|
|
12
12
|
'forge-cli-hints': string[];
|
|
13
|
-
'forge-cli-enable-create-with-module-templates': boolean;
|
|
14
13
|
};
|
|
15
14
|
export type DynamicConfigKey = keyof DynamicConfig;
|
|
15
|
+
export type Experiment = {
|
|
16
|
+
'forge-cli-create-with-module-templates': {
|
|
17
|
+
isEnabled: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type ExperimentKey = keyof Experiment;
|
|
16
21
|
export declare abstract class StatsigReader {
|
|
17
22
|
abstract checkGate<F extends FeatureGate>(flag: F, customAttributes?: Record<string, string>): Promise<boolean | null>;
|
|
18
23
|
abstract getDynamicConfig<F extends DynamicConfigKey>(flag: F, metadata?: Record<string, string>): Promise<DynamicConfig[F] | null>;
|
|
24
|
+
abstract getExperiment<E extends ExperimentKey>(experiment: E, customAttributes?: Record<string, string>): Promise<Partial<Experiment[E]> | null>;
|
|
19
25
|
testForgeCliTestGate(): Promise<boolean>;
|
|
20
26
|
getForgeCliTestDynamicConfig(): Promise<string[]>;
|
|
21
27
|
isLogsV2ApiEnabled(): Promise<boolean>;
|
|
@@ -34,16 +40,21 @@ export declare class StatsigService extends StatsigReader {
|
|
|
34
40
|
private readonly credentialStore;
|
|
35
41
|
private readonly appConfigReader;
|
|
36
42
|
private readonly getEnvironmentFn;
|
|
43
|
+
private readonly isAnalyticsEnabled;
|
|
37
44
|
constructor(logger: Logger, cliDetails: Pick<CLIDetails, 'version'> | undefined, credentialStore: CredentialGetter, appConfigReader: ConfigSectionReader<{
|
|
38
45
|
id: string;
|
|
39
|
-
}>, getEnvironmentFn?: typeof getEnvironmentConfig);
|
|
46
|
+
}>, getEnvironmentFn?: typeof getEnvironmentConfig, isAnalyticsEnabled?: () => boolean);
|
|
40
47
|
private appID;
|
|
41
48
|
private context;
|
|
42
49
|
private fetchGates;
|
|
43
50
|
private fetchDynamicConfigs;
|
|
51
|
+
private fetchExperiments;
|
|
44
52
|
private gatesClient;
|
|
45
53
|
private dynamicConfigClient;
|
|
54
|
+
private experimentsClient;
|
|
55
|
+
private logExperimentExposure;
|
|
46
56
|
checkGate<F extends FeatureGate>(gate: F, customAttributes?: Record<string, string>): Promise<boolean | null>;
|
|
47
57
|
getDynamicConfig<F extends DynamicConfigKey>(dynamicConfig: F, metadata?: Record<string, string>): Promise<DynamicConfig[F] | null>;
|
|
58
|
+
getExperiment<E extends ExperimentKey>(experiment: E, customAttributes?: Record<string, string>): Promise<Partial<Experiment[E]> | null>;
|
|
48
59
|
}
|
|
49
60
|
//# sourceMappingURL=statsig-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statsig-service.d.ts","sourceRoot":"","sources":["../../src/service/statsig-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"statsig-service.d.ts","sourceRoot":"","sources":["../../src/service/statsig-service.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EAEpB,MAAM,EAEP,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,WAAW,GACnB,qBAAqB,GACrB,yBAAyB,GACzB,iDAAiD,CAAC;AAEtD,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU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gChB;IAEF,OAAO,CAAC,mBAAmB,CAgCzB;IAEF,OAAO,CAAC,gBAAgB,CAgCtB;IAEF,OAAO,CAAC,WAAW,CAGhB;IAEH,OAAO,CAAC,mBAAmB,CAGxB;IAEH,OAAO,CAAC,iBAAiB,CAGtB;IAEH,OAAO,CAAC,qBAAqB,CAgC3B;IAEI,SAAS,CAAC,CAAC,SAAS,WAAW,EACnC,IAAI,EAAE,CAAC,EACP,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC5C,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAYpB,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,EAC/C,aAAa,EAAE,CAAC,EAChB,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAY7B,aAAa,CAAC,CAAC,SAAS,aAAa,EACzC,UAAU,EAAE,CAAC,EACb,gBAAgB,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC5C,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAY1C"}
|
|
@@ -50,7 +50,7 @@ export class StatsigReader {
|
|
|
50
50
|
if (isFedrampEnv()) {
|
|
51
51
|
return false;
|
|
52
52
|
}
|
|
53
|
-
return (await this.
|
|
53
|
+
return (await this.getExperiment('forge-cli-create-with-module-templates'))?.isEnabled ?? false;
|
|
54
54
|
}
|
|
55
55
|
async getCustomSpinnerConfig() {
|
|
56
56
|
return (await this.getDynamicConfig('forge-cli-enable-custom-spinner')) ?? null;
|
|
@@ -76,6 +76,14 @@ var BASE_FEATURE_FLAG_SERVICE_URL;
|
|
|
76
76
|
BASE_FEATURE_FLAG_SERVICE_URL["FEDRAMP_MODERATE_STAGING"] = "https://api.stg.atlassian.com/flags/api/v2/";
|
|
77
77
|
BASE_FEATURE_FLAG_SERVICE_URL["FEDRAMP_MODERATE_PROD"] = "https://api.atlassian.com/flags/api/v2/";
|
|
78
78
|
})(BASE_FEATURE_FLAG_SERVICE_URL || (BASE_FEATURE_FLAG_SERVICE_URL = {}));
|
|
79
|
+
var FEATURE_GATE_ENVIRONMENTS;
|
|
80
|
+
(function (FEATURE_GATE_ENVIRONMENTS) {
|
|
81
|
+
FEATURE_GATE_ENVIRONMENTS["DEV"] = "development";
|
|
82
|
+
FEATURE_GATE_ENVIRONMENTS["STG"] = "staging";
|
|
83
|
+
FEATURE_GATE_ENVIRONMENTS["PROD"] = "production";
|
|
84
|
+
FEATURE_GATE_ENVIRONMENTS["FEDRAMP_MODERATE_STAGING"] = "staging";
|
|
85
|
+
FEATURE_GATE_ENVIRONMENTS["FEDRAMP_MODERATE_PROD"] = "production";
|
|
86
|
+
})(FEATURE_GATE_ENVIRONMENTS || (FEATURE_GATE_ENVIRONMENTS = {}));
|
|
79
87
|
export function cacheStatsigResult(getter) {
|
|
80
88
|
const cacheDict = new Map();
|
|
81
89
|
return async function (...args) {
|
|
@@ -89,19 +97,28 @@ export function cacheStatsigResult(getter) {
|
|
|
89
97
|
return value;
|
|
90
98
|
};
|
|
91
99
|
}
|
|
100
|
+
function djb2Hash(value) {
|
|
101
|
+
let hash = 0;
|
|
102
|
+
for (let i = 0; i < value.length; i++) {
|
|
103
|
+
hash = ((hash << 5) - hash + value.charCodeAt(i)) | 0;
|
|
104
|
+
}
|
|
105
|
+
return String(hash >>> 0);
|
|
106
|
+
}
|
|
92
107
|
export class StatsigService extends StatsigReader {
|
|
93
108
|
logger;
|
|
94
109
|
cliDetails;
|
|
95
110
|
credentialStore;
|
|
96
111
|
appConfigReader;
|
|
97
112
|
getEnvironmentFn;
|
|
98
|
-
|
|
113
|
+
isAnalyticsEnabled;
|
|
114
|
+
constructor(logger, cliDetails, credentialStore, appConfigReader, getEnvironmentFn = getEnvironmentConfig, isAnalyticsEnabled = () => false) {
|
|
99
115
|
super();
|
|
100
116
|
this.logger = logger;
|
|
101
117
|
this.cliDetails = cliDetails;
|
|
102
118
|
this.credentialStore = credentialStore;
|
|
103
119
|
this.appConfigReader = appConfigReader;
|
|
104
120
|
this.getEnvironmentFn = getEnvironmentFn;
|
|
121
|
+
this.isAnalyticsEnabled = isAnalyticsEnabled;
|
|
105
122
|
}
|
|
106
123
|
appID = cacheStatsigResult(async () => {
|
|
107
124
|
try {
|
|
@@ -194,6 +211,38 @@ export class StatsigService extends StatsigReader {
|
|
|
194
211
|
return { 'forge-cli-test-dynamic-configs': { value: [] } };
|
|
195
212
|
}
|
|
196
213
|
};
|
|
214
|
+
fetchExperiments = async (customAttributes) => {
|
|
215
|
+
try {
|
|
216
|
+
const baseURL = this.getEnvironmentFn(BASE_FEATURE_FLAG_SERVICE_URL);
|
|
217
|
+
const apiKey = this.getEnvironmentFn(STATSIG_API_KEYS);
|
|
218
|
+
const context = await this.context();
|
|
219
|
+
const response = await fetch(`${baseURL}/frontend/experimentValues`, {
|
|
220
|
+
headers: {
|
|
221
|
+
'x-api-key': apiKey,
|
|
222
|
+
'Content-Type': 'application/json'
|
|
223
|
+
},
|
|
224
|
+
method: 'POST',
|
|
225
|
+
body: JSON.stringify({
|
|
226
|
+
identifiers: {
|
|
227
|
+
atlassianAccountId: context.accountId,
|
|
228
|
+
randomizationId: context.appId
|
|
229
|
+
},
|
|
230
|
+
customAttributes: {
|
|
231
|
+
appId: context.appId,
|
|
232
|
+
version: context.version,
|
|
233
|
+
atlassianAccountId: context.accountId,
|
|
234
|
+
...customAttributes
|
|
235
|
+
},
|
|
236
|
+
targetApp: 'forge_cli'
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
return await response.json();
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
this.logger.debug(`Failed to fetch experiments: ${error}`);
|
|
243
|
+
return {};
|
|
244
|
+
}
|
|
245
|
+
};
|
|
197
246
|
gatesClient = cacheStatsigResult(async (customAttributes) => {
|
|
198
247
|
const gates = await this.fetchGates(customAttributes);
|
|
199
248
|
return { gates };
|
|
@@ -202,6 +251,32 @@ export class StatsigService extends StatsigReader {
|
|
|
202
251
|
const dynamicConfigs = await this.fetchDynamicConfigs(metadata);
|
|
203
252
|
return { dynamicConfigs };
|
|
204
253
|
});
|
|
254
|
+
experimentsClient = cacheStatsigResult(async (customAttributes) => {
|
|
255
|
+
const response = await this.fetchExperiments(customAttributes);
|
|
256
|
+
return { experiments: response.experimentValues?.dynamic_configs ?? {}, response };
|
|
257
|
+
});
|
|
258
|
+
logExperimentExposure = async (experiment, { experimentValues, clientSdkKey, customAttributes }) => {
|
|
259
|
+
if (!clientSdkKey || !this.isAnalyticsEnabled()) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
const featureGates = (await import('@atlaskit/feature-gate-js-client')).default.default;
|
|
264
|
+
const context = await this.context();
|
|
265
|
+
await featureGates.initializeFromValues({
|
|
266
|
+
sdkKey: clientSdkKey,
|
|
267
|
+
environment: this.getEnvironmentFn(FEATURE_GATE_ENVIRONMENTS),
|
|
268
|
+
targetApp: 'forge_cli',
|
|
269
|
+
ignoreWindowUndefined: true,
|
|
270
|
+
loggingEnabled: 'always',
|
|
271
|
+
logLevel: 0
|
|
272
|
+
}, { atlassianAccountId: context.accountId }, customAttributes, experimentValues);
|
|
273
|
+
featureGates.manuallyLogExperimentExposure(experiment);
|
|
274
|
+
featureGates.shutdownStatsig();
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
this.logger.debug(`Failed to log experiment exposure: ${error}`);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
205
280
|
async checkGate(gate, customAttributes = {}) {
|
|
206
281
|
try {
|
|
207
282
|
const { gates } = await this.gatesClient(customAttributes, {});
|
|
@@ -226,4 +301,17 @@ export class StatsigService extends StatsigReader {
|
|
|
226
301
|
return null;
|
|
227
302
|
}
|
|
228
303
|
}
|
|
304
|
+
async getExperiment(experiment, customAttributes = {}) {
|
|
305
|
+
try {
|
|
306
|
+
const { experiments, response } = await this.experimentsClient(customAttributes, {});
|
|
307
|
+
await this.logExperimentExposure(experiment, response);
|
|
308
|
+
return experiments[djb2Hash(experiment)]?.value ?? null;
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
if (this.logger.traceEnabled) {
|
|
312
|
+
this.logger.warn(Text.warning.statsigFetchFailed('experiments'));
|
|
313
|
+
}
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
229
317
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/cli-shared",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0-next.5",
|
|
4
4
|
"description": "Common functionality for Forge CLI",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"prebuild": "yarn generate-graphql-types"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@atlaskit/feature-gate-js-client": "^6.0.0",
|
|
17
18
|
"@forge/manifest": "13.9.2-next.0",
|
|
18
19
|
"@forge/util": "4.1.0",
|
|
19
20
|
"@forge/i18n": "1.0.2",
|