@adobe/ccweb-add-on-analytics 3.0.0 → 3.1.0
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/.c8rc.json +4 -0
- package/dist/app/AnalyticsConsent.d.ts +16 -2
- package/dist/app/AnalyticsConsent.d.ts.map +1 -1
- package/dist/app/AnalyticsConsent.js +89 -1
- package/dist/app/AnalyticsService.d.ts +15 -3
- package/dist/app/AnalyticsService.d.ts.map +1 -1
- package/dist/app/AnalyticsService.js +88 -1
- package/dist/app/index.d.ts +0 -2
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +0 -2
- package/dist/base/BaseCommand.d.ts +6 -5
- package/dist/base/BaseCommand.d.ts.map +1 -1
- package/dist/config/inversify.config.d.ts +1 -1
- package/dist/config/inversify.config.d.ts.map +1 -1
- package/dist/config/inversify.config.js +4 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/app/AnalyticsConsent.ts +84 -4
- package/src/app/AnalyticsService.ts +74 -6
- package/src/app/index.ts +0 -2
- package/src/base/BaseCommand.ts +6 -5
- package/src/config/inversify.config.ts +5 -5
- package/src/test/app/{WxpAnalyticsConsent.spec.ts → AnalyticsConsent.spec.ts} +13 -14
- package/src/test/app/{WxpAnalyticsService.spec.ts → AnalyticsService.spec.ts} +12 -13
- package/src/test/models/CLIProgram.spec.ts +1 -1
- package/dist/app/WxpAnalyticsConsent.d.ts +0 -54
- package/dist/app/WxpAnalyticsConsent.d.ts.map +0 -1
- package/dist/app/WxpAnalyticsConsent.js +0 -113
- package/dist/app/WxpAnalyticsService.d.ts +0 -60
- package/dist/app/WxpAnalyticsService.d.ts.map +0 -1
- package/dist/app/WxpAnalyticsService.js +0 -112
- package/src/app/WxpAnalyticsConsent.ts +0 -119
- package/src/app/WxpAnalyticsService.ts +0 -120
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
import { __decorate, __metadata, __param } from "tslib";
|
|
25
|
-
import { ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import axios from "axios";
|
|
27
|
-
import { inject, injectable } from "inversify";
|
|
28
|
-
import osName from "os-name";
|
|
29
|
-
import "reflect-metadata";
|
|
30
|
-
import { ANALYTICS_API } from "../constants.js";
|
|
31
|
-
import { CLIProgram } from "../models/index.js";
|
|
32
|
-
/**
|
|
33
|
-
* Analytics service implementation.
|
|
34
|
-
*/
|
|
35
|
-
let WxpAnalyticsService = class WxpAnalyticsService {
|
|
36
|
-
_preferences;
|
|
37
|
-
_program;
|
|
38
|
-
_startTime;
|
|
39
|
-
/**
|
|
40
|
-
* Instantiate {@link WxpAnalyticsService}.
|
|
41
|
-
* @param preferences - {@link Preferences} reference.
|
|
42
|
-
* @returns Reference to a new {@link WxpAnalyticsService} instance.
|
|
43
|
-
*/
|
|
44
|
-
constructor(preferences) {
|
|
45
|
-
this._preferences = preferences;
|
|
46
|
-
this._program = new CLIProgram("", "");
|
|
47
|
-
this._startTime = Date.now();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Set the program which is being executed.
|
|
51
|
-
* @param program - {@link CLIProgram} reference.
|
|
52
|
-
*/
|
|
53
|
-
set program(program) {
|
|
54
|
-
this._program = program;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Set the start time of an operation.
|
|
58
|
-
*/
|
|
59
|
-
set startTime(time) {
|
|
60
|
-
this._startTime = time;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Post an event to Adobe analytics service.
|
|
64
|
-
* @param eventType - Event type, either a SUCCESS, or an ERROR.
|
|
65
|
-
* @param eventData - Event data.
|
|
66
|
-
* @param isSuccess - Does the event represent a successful operation.
|
|
67
|
-
* @returns Promise.
|
|
68
|
-
*/
|
|
69
|
-
async postEvent(eventType, eventData, isSuccess) {
|
|
70
|
-
try {
|
|
71
|
-
const userPreferences = this._preferences.get();
|
|
72
|
-
if (!userPreferences.hasTelemetryConsent) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const currentTime = Date.now();
|
|
76
|
-
const body = JSON.stringify({
|
|
77
|
-
id: Math.floor(currentTime * Math.random()),
|
|
78
|
-
timestamp: currentTime,
|
|
79
|
-
_adobeio: {
|
|
80
|
-
eventType,
|
|
81
|
-
eventData,
|
|
82
|
-
cliVersion: this._program.version,
|
|
83
|
-
clientId: this._getClientId(),
|
|
84
|
-
command: this._program.name,
|
|
85
|
-
commandDuration: currentTime - this._startTime,
|
|
86
|
-
commandSuccess: isSuccess,
|
|
87
|
-
nodeVersion: process.version,
|
|
88
|
-
osNameVersion: osName()
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
await axios.post(ANALYTICS_API.URL, body, { headers: ANALYTICS_API.HEADERS });
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
_getClientId() {
|
|
98
|
-
const userPreferences = this._preferences.get();
|
|
99
|
-
if (userPreferences.clientId === undefined) {
|
|
100
|
-
userPreferences.clientId = Math.floor(Date.now() * Math.random());
|
|
101
|
-
this._preferences.set(userPreferences);
|
|
102
|
-
}
|
|
103
|
-
return userPreferences.clientId;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
WxpAnalyticsService = __decorate([
|
|
107
|
-
injectable(),
|
|
108
|
-
__param(0, inject(ICoreTypes.Preferences)),
|
|
109
|
-
__metadata("design:paramtypes", [Object])
|
|
110
|
-
], WxpAnalyticsService);
|
|
111
|
-
export { WxpAnalyticsService };
|
|
112
|
-
//# sourceMappingURL=WxpAnalyticsService.js.map
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
|
|
25
|
-
import type { Logger, Preferences } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import { ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
|
|
27
|
-
import chalk from "chalk";
|
|
28
|
-
import { inject, injectable } from "inversify";
|
|
29
|
-
import prompts from "prompts";
|
|
30
|
-
import "reflect-metadata";
|
|
31
|
-
import type { AnalyticsConsent } from "./AnalyticsConsent.js";
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Implementation class to get and set user's consent
|
|
35
|
-
* on allowing the application to collect and send analytics to Adobe.
|
|
36
|
-
*/
|
|
37
|
-
@injectable()
|
|
38
|
-
export class WxpAnalyticsConsent implements AnalyticsConsent {
|
|
39
|
-
private readonly _preferences: Preferences;
|
|
40
|
-
private readonly _logger: Logger;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Instantiate {@link WxpAnalyticsConsent}.
|
|
44
|
-
* @param preferences - {@link Preferences} reference.
|
|
45
|
-
* @param logger - {@link Logger} reference.
|
|
46
|
-
* @returns Reference to a new {@link WxpAnalyticsConsent} instance.
|
|
47
|
-
*/
|
|
48
|
-
constructor(@inject(ICoreTypes.Preferences) preferences: Preferences, @inject(ICoreTypes.Logger) logger: Logger) {
|
|
49
|
-
this._preferences = preferences;
|
|
50
|
-
this._logger = logger;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Get user consent to collect and send analytics to Adobe.
|
|
55
|
-
* @returns Promise of boolean value representing whether the user has provided consent.
|
|
56
|
-
*/
|
|
57
|
-
async get(): Promise<boolean> {
|
|
58
|
-
// Always get the preference from cache
|
|
59
|
-
// for checking the analytics consent
|
|
60
|
-
// to avoid a file IO operation.
|
|
61
|
-
const preferenceData = this._preferences.get(true);
|
|
62
|
-
if (preferenceData.hasTelemetryConsent !== undefined) {
|
|
63
|
-
return preferenceData.hasTelemetryConsent;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this._logger.warning(LOGS.toolCollectsAnalytics, { prefix: LOGS.newLine });
|
|
67
|
-
|
|
68
|
-
const choices = [
|
|
69
|
-
{
|
|
70
|
-
title: this._promptMessageOption(LOGS.yesSendAnalytics),
|
|
71
|
-
value: true
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
title: this._promptMessageOption(LOGS.noDontSendAnalytics),
|
|
75
|
-
value: false
|
|
76
|
-
}
|
|
77
|
-
];
|
|
78
|
-
const response = await prompts.prompt({
|
|
79
|
-
type: "select",
|
|
80
|
-
name: "analyticsConsent",
|
|
81
|
-
message: this._promptMessage(LOGS.sendToAdobe),
|
|
82
|
-
choices,
|
|
83
|
-
initial: 0
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
if (!response || response.analyticsConsent === undefined) {
|
|
87
|
-
return process.exit(0);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
await this.set(response.analyticsConsent);
|
|
91
|
-
return response.analyticsConsent;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Set user consent to collect and send analytics to Adobe.
|
|
96
|
-
* @param consent - Boolean value representing whether the user has provided consent.
|
|
97
|
-
*/
|
|
98
|
-
async set(consent: boolean): Promise<void> {
|
|
99
|
-
const preferenceData = this._preferences.get();
|
|
100
|
-
preferenceData.hasTelemetryConsent = consent;
|
|
101
|
-
this._preferences.set(preferenceData);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private _promptMessage(message: string): string {
|
|
105
|
-
return chalk.hex("#E59400")(message);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private _promptMessageOption(message: string): string {
|
|
109
|
-
return chalk.green.bold(message);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const LOGS = {
|
|
114
|
-
newLine: "\n",
|
|
115
|
-
yesSendAnalytics: "Yes, send analytics to Adobe",
|
|
116
|
-
noDontSendAnalytics: "No, don't send analytics to Adobe",
|
|
117
|
-
toolCollectsAnalytics: "This tool collects and sends analytics to help Adobe improve its products.",
|
|
118
|
-
sendToAdobe: "Do you want to allow sending analytics to Adobe"
|
|
119
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* MIT License
|
|
3
|
-
|
|
4
|
-
* © Copyright 2023 Adobe. All rights reserved.
|
|
5
|
-
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
********************************************************************************/
|
|
24
|
-
|
|
25
|
-
import type { Preferences } from "@adobe/ccweb-add-on-core";
|
|
26
|
-
import { ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
|
|
27
|
-
import axios from "axios";
|
|
28
|
-
import { inject, injectable } from "inversify";
|
|
29
|
-
import osName from "os-name";
|
|
30
|
-
import "reflect-metadata";
|
|
31
|
-
import { ANALYTICS_API } from "../constants.js";
|
|
32
|
-
import { CLIProgram } from "../models/index.js";
|
|
33
|
-
import type { AnalyticsService } from "./AnalyticsService.js";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Analytics service implementation.
|
|
37
|
-
*/
|
|
38
|
-
@injectable()
|
|
39
|
-
export class WxpAnalyticsService implements AnalyticsService {
|
|
40
|
-
private readonly _preferences: Preferences;
|
|
41
|
-
|
|
42
|
-
private _program: CLIProgram;
|
|
43
|
-
|
|
44
|
-
private _startTime: number;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Instantiate {@link WxpAnalyticsService}.
|
|
48
|
-
* @param preferences - {@link Preferences} reference.
|
|
49
|
-
* @returns Reference to a new {@link WxpAnalyticsService} instance.
|
|
50
|
-
*/
|
|
51
|
-
constructor(@inject(ICoreTypes.Preferences) preferences: Preferences) {
|
|
52
|
-
this._preferences = preferences;
|
|
53
|
-
|
|
54
|
-
this._program = new CLIProgram("", "");
|
|
55
|
-
|
|
56
|
-
this._startTime = Date.now();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Set the program which is being executed.
|
|
61
|
-
* @param program - {@link CLIProgram} reference.
|
|
62
|
-
*/
|
|
63
|
-
set program(program: CLIProgram) {
|
|
64
|
-
this._program = program;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Set the start time of an operation.
|
|
69
|
-
*/
|
|
70
|
-
set startTime(time: number) {
|
|
71
|
-
this._startTime = time;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Post an event to Adobe analytics service.
|
|
76
|
-
* @param eventType - Event type, either a SUCCESS, or an ERROR.
|
|
77
|
-
* @param eventData - Event data.
|
|
78
|
-
* @param isSuccess - Does the event represent a successful operation.
|
|
79
|
-
* @returns Promise.
|
|
80
|
-
*/
|
|
81
|
-
async postEvent(eventType: string, eventData: string, isSuccess: boolean): Promise<void> {
|
|
82
|
-
try {
|
|
83
|
-
const userPreferences = this._preferences.get();
|
|
84
|
-
if (!userPreferences.hasTelemetryConsent) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const currentTime = Date.now();
|
|
89
|
-
const body = JSON.stringify({
|
|
90
|
-
id: Math.floor(currentTime * Math.random()),
|
|
91
|
-
timestamp: currentTime,
|
|
92
|
-
_adobeio: {
|
|
93
|
-
eventType,
|
|
94
|
-
eventData,
|
|
95
|
-
cliVersion: this._program.version,
|
|
96
|
-
clientId: this._getClientId(),
|
|
97
|
-
command: this._program.name,
|
|
98
|
-
commandDuration: currentTime - this._startTime,
|
|
99
|
-
commandSuccess: isSuccess,
|
|
100
|
-
nodeVersion: process.version,
|
|
101
|
-
osNameVersion: osName()
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
await axios.post(ANALYTICS_API.URL, body, { headers: ANALYTICS_API.HEADERS });
|
|
106
|
-
} catch {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private _getClientId(): number {
|
|
112
|
-
const userPreferences = this._preferences.get();
|
|
113
|
-
if (userPreferences.clientId === undefined) {
|
|
114
|
-
userPreferences.clientId = Math.floor(Date.now() * Math.random());
|
|
115
|
-
this._preferences.set(userPreferences);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return userPreferences.clientId;
|
|
119
|
-
}
|
|
120
|
-
}
|