@adobe/ccweb-add-on-analytics 2.5.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.
Files changed (46) hide show
  1. package/.c8rc.json +7 -2
  2. package/.mocharc.json +6 -1
  3. package/dist/app/AnalyticsConsent.d.ts +16 -2
  4. package/dist/app/AnalyticsConsent.d.ts.map +1 -1
  5. package/dist/app/AnalyticsConsent.js +89 -1
  6. package/dist/app/AnalyticsService.d.ts +15 -3
  7. package/dist/app/AnalyticsService.d.ts.map +1 -1
  8. package/dist/app/AnalyticsService.js +88 -1
  9. package/dist/app/index.d.ts +0 -2
  10. package/dist/app/index.d.ts.map +1 -1
  11. package/dist/app/index.js +0 -2
  12. package/dist/base/BaseCommand.d.ts +40 -0
  13. package/dist/base/BaseCommand.d.ts.map +1 -0
  14. package/dist/base/BaseCommand.js +59 -0
  15. package/dist/base/index.d.ts +25 -0
  16. package/dist/base/index.d.ts.map +1 -0
  17. package/dist/base/index.js +25 -0
  18. package/dist/config/inversify.config.d.ts +2 -1
  19. package/dist/config/inversify.config.d.ts.map +1 -1
  20. package/dist/config/inversify.config.js +4 -3
  21. package/dist/config/inversify.types.d.ts.map +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +10 -9
  27. package/src/app/AnalyticsConsent.ts +84 -4
  28. package/src/app/AnalyticsService.ts +74 -6
  29. package/src/app/index.ts +0 -2
  30. package/src/base/BaseCommand.ts +72 -0
  31. package/src/base/index.ts +25 -0
  32. package/src/config/inversify.config.ts +6 -5
  33. package/src/config/inversify.types.ts +4 -1
  34. package/src/index.ts +1 -0
  35. package/src/test/app/{WxpAnalyticsConsent.spec.ts → AnalyticsConsent.spec.ts} +13 -14
  36. package/src/test/app/{WxpAnalyticsService.spec.ts → AnalyticsService.spec.ts} +12 -13
  37. package/src/test/models/CLIProgram.spec.ts +1 -1
  38. package/tsconfig.json +3 -1
  39. package/dist/app/WxpAnalyticsConsent.d.ts +0 -54
  40. package/dist/app/WxpAnalyticsConsent.d.ts.map +0 -1
  41. package/dist/app/WxpAnalyticsConsent.js +0 -113
  42. package/dist/app/WxpAnalyticsService.d.ts +0 -60
  43. package/dist/app/WxpAnalyticsService.d.ts.map +0 -1
  44. package/dist/app/WxpAnalyticsService.js +0 -112
  45. package/src/app/WxpAnalyticsConsent.ts +0 -119
  46. package/src/app/WxpAnalyticsService.ts +0 -120
@@ -0,0 +1,72 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2025 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 { Config } from "@oclif/core";
26
+ import { Command, Flags } from "@oclif/core";
27
+ import type { BooleanFlag, CustomOptions, OptionFlag } from "@oclif/core/lib/interfaces/parser.js";
28
+ import type { AnalyticsConsent } from "../app/AnalyticsConsent.js";
29
+ import type { AnalyticsService } from "../app/AnalyticsService.js";
30
+ import { IContainer, ITypes } from "../config/index.js";
31
+ import type { CLIProgram } from "../models/CLIProgram.js";
32
+
33
+ export abstract class BaseCommand extends Command {
34
+ protected readonly _analyticsConsent: AnalyticsConsent;
35
+ protected readonly _analyticsService: AnalyticsService;
36
+
37
+ constructor(argv: string[], config: Config, program: CLIProgram) {
38
+ super(argv, config);
39
+
40
+ this._analyticsConsent = IContainer.get<AnalyticsConsent>(ITypes.AnalyticsConsent);
41
+
42
+ this._analyticsService = IContainer.get<AnalyticsService>(ITypes.AnalyticsService);
43
+ this._analyticsService.program = program;
44
+ this._analyticsService.startTime = Date.now();
45
+ }
46
+
47
+ static baseFlags: {
48
+ analytics: OptionFlag<string | undefined, CustomOptions>;
49
+ verbose: BooleanFlag<boolean>;
50
+ } = {
51
+ analytics: Flags.string({
52
+ char: "a",
53
+ description: "Turn on/off sending analytics to Adobe.",
54
+ options: ["on", "off"],
55
+ required: false
56
+ }),
57
+ verbose: Flags.boolean({
58
+ char: "v",
59
+ description: "Enable verbose logging.",
60
+ default: false,
61
+ required: false
62
+ })
63
+ };
64
+
65
+ protected async _seekAnalyticsConsent(analytics: string | undefined): Promise<void> {
66
+ if (analytics === undefined) {
67
+ await this._analyticsConsent.get();
68
+ } else {
69
+ await this._analyticsConsent.set(analytics === "on");
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,25 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2025 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
+ export * from "./BaseCommand.js";
@@ -23,15 +23,16 @@
23
23
  ********************************************************************************/
24
24
 
25
25
  import { IContainer as ICoreContainer } from "@adobe/ccweb-add-on-core";
26
+ import type { Container } from "inversify";
26
27
  import "reflect-metadata";
27
- import type { AnalyticsConsent, AnalyticsService } from "../app/index.js";
28
- import { WxpAnalyticsConsent, WxpAnalyticsService } from "../app/index.js";
28
+ import { AnalyticsConsent } from "../app/AnalyticsConsent.js";
29
+ import { AnalyticsService } from "../app/AnalyticsService.js";
29
30
  import { ITypes } from "./inversify.types.js";
30
31
 
31
- const container = ICoreContainer;
32
+ const container: Container = ICoreContainer;
32
33
 
33
- container.bind<AnalyticsConsent>(ITypes.AnalyticsConsent).to(WxpAnalyticsConsent).inSingletonScope();
34
+ container.bind<AnalyticsConsent>(ITypes.AnalyticsConsent).to(AnalyticsConsent).inSingletonScope();
34
35
 
35
- container.bind<AnalyticsService>(ITypes.AnalyticsService).to(WxpAnalyticsService).inSingletonScope();
36
+ container.bind<AnalyticsService>(ITypes.AnalyticsService).to(AnalyticsService).inSingletonScope();
36
37
 
37
38
  export { container as IContainer };
@@ -22,7 +22,10 @@
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
24
 
25
- export const ITypes = {
25
+ export const ITypes: {
26
+ AnalyticsService: symbol;
27
+ AnalyticsConsent: symbol;
28
+ } = {
26
29
  AnalyticsService: Symbol.for("AnalyticsService"),
27
30
  AnalyticsConsent: Symbol.for("AnalyticsConsent")
28
31
  };
package/src/index.ts CHANGED
@@ -23,6 +23,7 @@
23
23
  ********************************************************************************/
24
24
 
25
25
  export * from "./app/index.js";
26
+ export * from "./base/index.js";
26
27
  export * from "./config/index.js";
27
28
  export * from "./constants.js";
28
29
  export * from "./models/index.js";
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
24
 
25
- import type { Logger, Preferences } from "@adobe/ccweb-add-on-core";
25
+ import type { Logger, UserPreferences } from "@adobe/ccweb-add-on-core";
26
26
  import { ADD_ON_PREFERENCES_FILE, PreferenceJson } from "@adobe/ccweb-add-on-core";
27
27
  import { assert } from "chai";
28
28
  import chalk from "chalk";
@@ -32,13 +32,12 @@ import type { SinonSandbox } from "sinon";
32
32
  import sinon from "sinon";
33
33
  import type { StubbedInstance } from "ts-sinon";
34
34
  import { stubInterface } from "ts-sinon";
35
- import type { AnalyticsConsent } from "../../app/index.js";
36
- import { WxpAnalyticsConsent } from "../../app/index.js";
35
+ import { AnalyticsConsent } from "../../app/AnalyticsConsent.js";
37
36
 
38
- describe("WxpAnalyticsConsent", () => {
37
+ describe("AnalyticsConsent", () => {
39
38
  let sandbox: SinonSandbox;
40
39
 
41
- let cliPreferences: StubbedInstance<Preferences>;
40
+ let preferences: StubbedInstance<UserPreferences>;
42
41
  let logger: StubbedInstance<Logger>;
43
42
  let analyticsConsent: AnalyticsConsent;
44
43
 
@@ -55,12 +54,12 @@ describe("WxpAnalyticsConsent", () => {
55
54
  beforeEach(() => {
56
55
  sandbox = sinon.createSandbox();
57
56
 
58
- cliPreferences = stubInterface<Preferences>();
57
+ preferences = stubInterface<UserPreferences>();
59
58
 
60
59
  logger = stubInterface<Logger>();
61
60
  logger.warning.returns();
62
61
 
63
- analyticsConsent = new WxpAnalyticsConsent(cliPreferences, logger);
62
+ analyticsConsent = new AnalyticsConsent(preferences, logger);
64
63
  });
65
64
 
66
65
  afterEach(() => {
@@ -81,7 +80,7 @@ describe("WxpAnalyticsConsent", () => {
81
80
  promptsStub.resolves({ analyticsConsent: choices[0].value });
82
81
 
83
82
  const preferenceJson = new PreferenceJson({});
84
- cliPreferences.get.returns(preferenceJson);
83
+ preferences.get.returns(preferenceJson);
85
84
 
86
85
  const userConsent = await analyticsConsent.get();
87
86
 
@@ -114,7 +113,7 @@ describe("WxpAnalyticsConsent", () => {
114
113
  promptsStub.resolves({ analyticsConsent: choices[0].value });
115
114
 
116
115
  const preferenceJson = new PreferenceJson({ hasTelemetryConsent: true });
117
- cliPreferences.get.returns(preferenceJson);
116
+ preferences.get.returns(preferenceJson);
118
117
 
119
118
  const userConsent = await analyticsConsent.get();
120
119
 
@@ -128,7 +127,7 @@ describe("WxpAnalyticsConsent", () => {
128
127
  promptsStub.resolves({ analyticsConsent: undefined });
129
128
 
130
129
  const preferenceJson = new PreferenceJson({});
131
- cliPreferences.get.returns(preferenceJson);
130
+ preferences.get.returns(preferenceJson);
132
131
 
133
132
  const userConsent = await analyticsConsent.get();
134
133
 
@@ -169,14 +168,14 @@ describe("WxpAnalyticsConsent", () => {
169
168
 
170
169
  it(`should set the user's analytics consent in ${ADD_ON_PREFERENCES_FILE}.`, async () => {
171
170
  const preferenceJson = new PreferenceJson({ hasTelemetryConsent: false });
172
- cliPreferences.get.returns(preferenceJson);
171
+ preferences.get.returns(preferenceJson);
173
172
 
174
- const analyticsConsent: AnalyticsConsent = new WxpAnalyticsConsent(cliPreferences, logger);
173
+ const analyticsConsent: AnalyticsConsent = new AnalyticsConsent(preferences, logger);
175
174
 
176
175
  await analyticsConsent.set(true);
177
176
 
178
- assert.equal(cliPreferences.set.callCount, 1);
179
- assert.equal(cliPreferences.set.calledWith(new PreferenceJson({ hasTelemetryConsent: true })), true);
177
+ assert.equal(preferences.set.callCount, 1);
178
+ assert.equal(preferences.set.calledWith(new PreferenceJson({ hasTelemetryConsent: true })), true);
180
179
  });
181
180
  });
182
181
  });
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
24
 
25
- import type { Preferences } from "@adobe/ccweb-add-on-core";
25
+ import type { UserPreferences } from "@adobe/ccweb-add-on-core";
26
26
  import { PreferenceJson } from "@adobe/ccweb-add-on-core";
27
27
  import axios from "axios";
28
28
  import { assert } from "chai";
@@ -32,15 +32,14 @@ import type { SinonSandbox } from "sinon";
32
32
  import sinon from "sinon";
33
33
  import type { StubbedInstance } from "ts-sinon";
34
34
  import { stubInterface } from "ts-sinon";
35
- import type { AnalyticsService } from "../../app/AnalyticsService.js";
36
- import { WxpAnalyticsService } from "../../app/WxpAnalyticsService.js";
35
+ import { AnalyticsService } from "../../app/AnalyticsService.js";
37
36
  import { ANALYTICS_API } from "../../constants.js";
38
37
  import { CLIProgram } from "../../models/CLIProgram.js";
39
38
 
40
- describe("WxpAnalyticsService", () => {
39
+ describe("AnalyticsService", () => {
41
40
  let sandbox: SinonSandbox;
42
41
 
43
- let cliPreferences: StubbedInstance<Preferences>;
42
+ let preferences: StubbedInstance<UserPreferences>;
44
43
  let analyticsService: AnalyticsService;
45
44
 
46
45
  const program = new CLIProgram("test-program", "1.0.0");
@@ -48,8 +47,8 @@ describe("WxpAnalyticsService", () => {
48
47
  beforeEach(() => {
49
48
  sandbox = sinon.createSandbox();
50
49
 
51
- cliPreferences = stubInterface<Preferences>();
52
- analyticsService = new WxpAnalyticsService(cliPreferences);
50
+ preferences = stubInterface<UserPreferences>();
51
+ analyticsService = new AnalyticsService(preferences);
53
52
  });
54
53
 
55
54
  afterEach(() => {
@@ -64,7 +63,7 @@ describe("WxpAnalyticsService", () => {
64
63
  const clientId = 10001;
65
64
  const preferenceJSON = new PreferenceJson({ clientId, hasTelemetryConsent: true });
66
65
 
67
- cliPreferences.get.returns(preferenceJSON);
66
+ preferences.get.returns(preferenceJSON);
68
67
 
69
68
  sandbox.stub(Math, "random").returns(0.3);
70
69
 
@@ -95,7 +94,7 @@ describe("WxpAnalyticsService", () => {
95
94
 
96
95
  await analyticsService.postEvent(eventType, eventData, true);
97
96
 
98
- assert.equal(cliPreferences.set.callCount, 0);
97
+ assert.equal(preferences.set.callCount, 0);
99
98
  assert.equal(
100
99
  axiosPostStub.calledOnceWith(ANALYTICS_API.URL, expectedApiRequestBody, {
101
100
  headers: ANALYTICS_API.HEADERS
@@ -113,7 +112,7 @@ describe("WxpAnalyticsService", () => {
113
112
  const clientId = 10001;
114
113
  const preferenceJSON = new PreferenceJson({ clientId, hasTelemetryConsent });
115
114
 
116
- cliPreferences.get.returns(preferenceJSON);
115
+ preferences.get.returns(preferenceJSON);
117
116
 
118
117
  sandbox.stub(Math, "random").returns(0.3);
119
118
 
@@ -137,8 +136,8 @@ describe("WxpAnalyticsService", () => {
137
136
 
138
137
  const preferenceJSON = new PreferenceJson({ hasTelemetryConsent: true });
139
138
 
140
- cliPreferences.get.returns(preferenceJSON);
141
- cliPreferences.set.returns();
139
+ preferences.get.returns(preferenceJSON);
140
+ preferences.set.returns();
142
141
 
143
142
  sandbox.stub(Math, "random").returns(0.3);
144
143
 
@@ -155,7 +154,7 @@ describe("WxpAnalyticsService", () => {
155
154
 
156
155
  preferenceJSON.clientId = Math.floor(Date.now() * Math.random());
157
156
 
158
- assert.equal(cliPreferences.set.calledOnceWith(preferenceJSON), true);
157
+ assert.equal(preferences.set.calledOnceWith(preferenceJSON), true);
159
158
  assert.equal(axiosPostStub.callCount, 1);
160
159
  });
161
160
  });
@@ -24,7 +24,7 @@
24
24
 
25
25
  import { assert } from "chai";
26
26
  import "mocha";
27
- import { CLIProgram } from "../../models/index.js";
27
+ import { CLIProgram } from "../../models/CLIProgram.js";
28
28
 
29
29
  describe("CLIProgram", () => {
30
30
  describe("constructor", () => {
package/tsconfig.json CHANGED
@@ -17,11 +17,13 @@
17
17
  "outDir": "dist",
18
18
  "preserveConstEnums": true,
19
19
  "resolveJsonModule": true,
20
+ "skipLibCheck": true,
20
21
  "sourceMap": true,
21
22
  "strict": true,
22
23
  "target": "ESNext",
23
24
  "types": ["reflect-metadata"],
24
- "useUnknownInCatchVariables": false
25
+ "useUnknownInCatchVariables": false,
26
+ "isolatedDeclarations": true
25
27
  },
26
28
  "exclude": ["node_modules", "src/test/**/*"],
27
29
  "include": ["src/**/*"],
@@ -1,54 +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 type { Logger, Preferences } from "@adobe/ccweb-add-on-core";
25
- import "reflect-metadata";
26
- import type { AnalyticsConsent } from "./AnalyticsConsent.js";
27
- /**
28
- * Implementation class to get and set user's consent
29
- * on allowing the application to collect and send analytics to Adobe.
30
- */
31
- export declare class WxpAnalyticsConsent implements AnalyticsConsent {
32
- private readonly _preferences;
33
- private readonly _logger;
34
- /**
35
- * Instantiate {@link WxpAnalyticsConsent}.
36
- * @param preferences - {@link Preferences} reference.
37
- * @param logger - {@link Logger} reference.
38
- * @returns Reference to a new {@link WxpAnalyticsConsent} instance.
39
- */
40
- constructor(preferences: Preferences, logger: Logger);
41
- /**
42
- * Get user consent to collect and send analytics to Adobe.
43
- * @returns Promise of boolean value representing whether the user has provided consent.
44
- */
45
- get(): Promise<boolean>;
46
- /**
47
- * Set user consent to collect and send analytics to Adobe.
48
- * @param consent - Boolean value representing whether the user has provided consent.
49
- */
50
- set(consent: boolean): Promise<void>;
51
- private _promptMessage;
52
- private _promptMessageOption;
53
- }
54
- //# sourceMappingURL=WxpAnalyticsConsent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WxpAnalyticsConsent.d.ts","sourceRoot":"","sources":["../../src/app/WxpAnalyticsConsent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKpE,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,qBACa,mBAAoB,YAAW,gBAAgB;IACxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;;;OAKG;gBACyC,WAAW,EAAE,WAAW,EAA6B,MAAM,EAAE,MAAM;IAK/G;;;OAGG;IACG,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;IAqC7B;;;OAGG;IACG,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;CAG/B"}
@@ -1,113 +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 chalk from "chalk";
27
- import { inject, injectable } from "inversify";
28
- import prompts from "prompts";
29
- import "reflect-metadata";
30
- /**
31
- * Implementation class to get and set user's consent
32
- * on allowing the application to collect and send analytics to Adobe.
33
- */
34
- let WxpAnalyticsConsent = class WxpAnalyticsConsent {
35
- _preferences;
36
- _logger;
37
- /**
38
- * Instantiate {@link WxpAnalyticsConsent}.
39
- * @param preferences - {@link Preferences} reference.
40
- * @param logger - {@link Logger} reference.
41
- * @returns Reference to a new {@link WxpAnalyticsConsent} instance.
42
- */
43
- constructor(preferences, logger) {
44
- this._preferences = preferences;
45
- this._logger = logger;
46
- }
47
- /**
48
- * Get user consent to collect and send analytics to Adobe.
49
- * @returns Promise of boolean value representing whether the user has provided consent.
50
- */
51
- async get() {
52
- // Always get the preference from cache
53
- // for checking the analytics consent
54
- // to avoid a file IO operation.
55
- const preferenceData = this._preferences.get(true);
56
- if (preferenceData.hasTelemetryConsent !== undefined) {
57
- return preferenceData.hasTelemetryConsent;
58
- }
59
- this._logger.warning(LOGS.toolCollectsAnalytics, { prefix: LOGS.newLine });
60
- const choices = [
61
- {
62
- title: this._promptMessageOption(LOGS.yesSendAnalytics),
63
- value: true
64
- },
65
- {
66
- title: this._promptMessageOption(LOGS.noDontSendAnalytics),
67
- value: false
68
- }
69
- ];
70
- const response = await prompts.prompt({
71
- type: "select",
72
- name: "analyticsConsent",
73
- message: this._promptMessage(LOGS.sendToAdobe),
74
- choices,
75
- initial: 0
76
- });
77
- if (!response || response.analyticsConsent === undefined) {
78
- return process.exit(0);
79
- }
80
- await this.set(response.analyticsConsent);
81
- return response.analyticsConsent;
82
- }
83
- /**
84
- * Set user consent to collect and send analytics to Adobe.
85
- * @param consent - Boolean value representing whether the user has provided consent.
86
- */
87
- async set(consent) {
88
- const preferenceData = this._preferences.get();
89
- preferenceData.hasTelemetryConsent = consent;
90
- this._preferences.set(preferenceData);
91
- }
92
- _promptMessage(message) {
93
- return chalk.hex("#E59400")(message);
94
- }
95
- _promptMessageOption(message) {
96
- return chalk.green.bold(message);
97
- }
98
- };
99
- WxpAnalyticsConsent = __decorate([
100
- injectable(),
101
- __param(0, inject(ICoreTypes.Preferences)),
102
- __param(1, inject(ICoreTypes.Logger)),
103
- __metadata("design:paramtypes", [Object, Object])
104
- ], WxpAnalyticsConsent);
105
- export { WxpAnalyticsConsent };
106
- const LOGS = {
107
- newLine: "\n",
108
- yesSendAnalytics: "Yes, send analytics to Adobe",
109
- noDontSendAnalytics: "No, don't send analytics to Adobe",
110
- toolCollectsAnalytics: "This tool collects and sends analytics to help Adobe improve its products.",
111
- sendToAdobe: "Do you want to allow sending analytics to Adobe"
112
- };
113
- //# sourceMappingURL=WxpAnalyticsConsent.js.map
@@ -1,60 +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 type { Preferences } from "@adobe/ccweb-add-on-core";
25
- import "reflect-metadata";
26
- import { CLIProgram } from "../models/index.js";
27
- import type { AnalyticsService } from "./AnalyticsService";
28
- /**
29
- * Analytics service implementation.
30
- */
31
- export declare class WxpAnalyticsService implements AnalyticsService {
32
- private readonly _preferences;
33
- private _program;
34
- private _startTime;
35
- /**
36
- * Instantiate {@link WxpAnalyticsService}.
37
- * @param preferences - {@link Preferences} reference.
38
- * @returns Reference to a new {@link WxpAnalyticsService} instance.
39
- */
40
- constructor(preferences: Preferences);
41
- /**
42
- * Set the program which is being executed.
43
- * @param program - {@link CLIProgram} reference.
44
- */
45
- set program(program: CLIProgram);
46
- /**
47
- * Set the start time of an operation.
48
- */
49
- set startTime(time: number);
50
- /**
51
- * Post an event to Adobe analytics service.
52
- * @param eventType - Event type, either a SUCCESS, or an ERROR.
53
- * @param eventData - Event data.
54
- * @param isSuccess - Does the event represent a successful operation.
55
- * @returns Promise.
56
- */
57
- postEvent(eventType: string, eventData: string, isSuccess: boolean): Promise<void>;
58
- private _getClientId;
59
- }
60
- //# sourceMappingURL=WxpAnalyticsService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WxpAnalyticsService.d.ts","sourceRoot":"","sources":["../../src/app/WxpAnalyticsService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAK5D,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;GAEG;AACH,qBACa,mBAAoB,YAAW,gBAAgB;IACxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAE3C,OAAO,CAAC,QAAQ,CAAa;IAE7B,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;OAIG;gBACyC,WAAW,EAAE,WAAW;IAQpE;;;OAGG;IACH,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAE9B;IAED;;OAEG;IACH,IAAI,SAAS,CAAC,IAAI,EAAE,MAAM,EAEzB;IAED;;;;;;OAMG;IACG,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BxF,OAAO,CAAC,YAAY;CASvB"}