@adobe/aio-cli-plugin-app 13.0.0 → 13.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/README.md CHANGED
@@ -72,7 +72,7 @@ DESCRIPTION
72
72
  Create, run, test, and deploy Adobe I/O Apps
73
73
  ```
74
74
 
75
- _See code: [src/commands/app/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/index.js)_
75
+ _See code: [src/commands/app/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/index.js)_
76
76
 
77
77
  ## `aio app add`
78
78
 
@@ -90,7 +90,7 @@ DESCRIPTION
90
90
  Add a new component to an existing Adobe I/O App
91
91
  ```
92
92
 
93
- _See code: [src/commands/app/add/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/add/index.js)_
93
+ _See code: [src/commands/app/add/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/add/index.js)_
94
94
 
95
95
  ## `aio app add action`
96
96
 
@@ -115,7 +115,7 @@ ALIASES
115
115
  $ aio app add actions
116
116
  ```
117
117
 
118
- _See code: [src/commands/app/add/action.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/add/action.js)_
118
+ _See code: [src/commands/app/add/action.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/add/action.js)_
119
119
 
120
120
  ## `aio app add ci`
121
121
 
@@ -133,7 +133,7 @@ DESCRIPTION
133
133
  Add CI files
134
134
  ```
135
135
 
136
- _See code: [src/commands/app/add/ci.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/add/ci.js)_
136
+ _See code: [src/commands/app/add/ci.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/add/ci.js)_
137
137
 
138
138
  ## `aio app add event`
139
139
 
@@ -158,7 +158,7 @@ ALIASES
158
158
  $ aio app add events
159
159
  ```
160
160
 
161
- _See code: [src/commands/app/add/event.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/add/event.js)_
161
+ _See code: [src/commands/app/add/event.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/add/event.js)_
162
162
 
163
163
  ## `aio app add extension`
164
164
 
@@ -184,7 +184,7 @@ ALIASES
184
184
  $ aio app add extensions
185
185
  ```
186
186
 
187
- _See code: [src/commands/app/add/extension.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/add/extension.js)_
187
+ _See code: [src/commands/app/add/extension.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/add/extension.js)_
188
188
 
189
189
  ## `aio app add service`
190
190
 
@@ -208,7 +208,7 @@ ALIASES
208
208
  $ aio app add services
209
209
  ```
210
210
 
211
- _See code: [src/commands/app/add/service.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/add/service.js)_
211
+ _See code: [src/commands/app/add/service.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/add/service.js)_
212
212
 
213
213
  ## `aio app add web-assets`
214
214
 
@@ -229,7 +229,7 @@ DESCRIPTION
229
229
  Add web assets support
230
230
  ```
231
231
 
232
- _See code: [src/commands/app/add/web-assets.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/add/web-assets.js)_
232
+ _See code: [src/commands/app/add/web-assets.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/add/web-assets.js)_
233
233
 
234
234
  ## `aio app build`
235
235
 
@@ -259,7 +259,7 @@ DESCRIPTION
259
259
  Use the --force-build flag to force a build even if one already exists.
260
260
  ```
261
261
 
262
- _See code: [src/commands/app/build.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/build.js)_
262
+ _See code: [src/commands/app/build.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/build.js)_
263
263
 
264
264
  ## `aio app create [PATH]`
265
265
 
@@ -281,7 +281,7 @@ DESCRIPTION
281
281
  Create a new Adobe I/O App with default parameters
282
282
  ```
283
283
 
284
- _See code: [src/commands/app/create.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/create.js)_
284
+ _See code: [src/commands/app/create.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/create.js)_
285
285
 
286
286
  ## `aio app delete`
287
287
 
@@ -299,7 +299,7 @@ DESCRIPTION
299
299
  Delete a component from an existing Adobe I/O App
300
300
  ```
301
301
 
302
- _See code: [src/commands/app/delete/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/delete/index.js)_
302
+ _See code: [src/commands/app/delete/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/delete/index.js)_
303
303
 
304
304
  ## `aio app delete action [ACTION-NAME]`
305
305
 
@@ -325,7 +325,7 @@ ALIASES
325
325
  $ aio app delete actions
326
326
  ```
327
327
 
328
- _See code: [src/commands/app/delete/action.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/delete/action.js)_
328
+ _See code: [src/commands/app/delete/action.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/delete/action.js)_
329
329
 
330
330
  ## `aio app delete ci`
331
331
 
@@ -344,7 +344,7 @@ DESCRIPTION
344
344
  Delete existing CI files
345
345
  ```
346
346
 
347
- _See code: [src/commands/app/delete/ci.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/delete/ci.js)_
347
+ _See code: [src/commands/app/delete/ci.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/delete/ci.js)_
348
348
 
349
349
  ## `aio app delete extension`
350
350
 
@@ -370,7 +370,7 @@ ALIASES
370
370
  $ aio app delete extensions
371
371
  ```
372
372
 
373
- _See code: [src/commands/app/delete/extension.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/delete/extension.js)_
373
+ _See code: [src/commands/app/delete/extension.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/delete/extension.js)_
374
374
 
375
375
  ## `aio app delete service`
376
376
 
@@ -394,7 +394,7 @@ ALIASES
394
394
  $ aio app delete services
395
395
  ```
396
396
 
397
- _See code: [src/commands/app/delete/service.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/delete/service.js)_
397
+ _See code: [src/commands/app/delete/service.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/delete/service.js)_
398
398
 
399
399
  ## `aio app delete web-assets`
400
400
 
@@ -413,7 +413,7 @@ DESCRIPTION
413
413
  Delete existing web assets
414
414
  ```
415
415
 
416
- _See code: [src/commands/app/delete/web-assets.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/delete/web-assets.js)_
416
+ _See code: [src/commands/app/delete/web-assets.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/delete/web-assets.js)_
417
417
 
418
418
  ## `aio app deploy`
419
419
 
@@ -459,7 +459,7 @@ DESCRIPTION
459
459
  Use the --force-deploy flag to force deploy changes, regardless of production Workspace being published in Exchange.
460
460
  ```
461
461
 
462
- _See code: [src/commands/app/deploy.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/deploy.js)_
462
+ _See code: [src/commands/app/deploy.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/deploy.js)_
463
463
 
464
464
  ## `aio app get-url [ACTION]`
465
465
 
@@ -482,7 +482,7 @@ DESCRIPTION
482
482
  Get action URLs
483
483
  ```
484
484
 
485
- _See code: [src/commands/app/get-url.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/get-url.js)_
485
+ _See code: [src/commands/app/get-url.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/get-url.js)_
486
486
 
487
487
  ## `aio app info`
488
488
 
@@ -504,7 +504,7 @@ DESCRIPTION
504
504
  Display settings/configuration in use by an Adobe I/O App
505
505
  ```
506
506
 
507
- _See code: [src/commands/app/info.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/info.js)_
507
+ _See code: [src/commands/app/info.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/info.js)_
508
508
 
509
509
  ## `aio app init [PATH]`
510
510
 
@@ -543,7 +543,7 @@ DESCRIPTION
543
543
  Create a new Adobe I/O App
544
544
  ```
545
545
 
546
- _See code: [src/commands/app/init.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/init.js)_
546
+ _See code: [src/commands/app/init.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/init.js)_
547
547
 
548
548
  ## `aio app install PATH`
549
549
 
@@ -566,7 +566,7 @@ DESCRIPTION
566
566
  This command will support installing apps packaged by 'aio app pack'.
567
567
  ```
568
568
 
569
- _See code: [src/commands/app/install.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/install.js)_
569
+ _See code: [src/commands/app/install.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/install.js)_
570
570
 
571
571
  ## `aio app list`
572
572
 
@@ -584,7 +584,7 @@ DESCRIPTION
584
584
  List components for Adobe I/O App
585
585
  ```
586
586
 
587
- _See code: [src/commands/app/list/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/list/index.js)_
587
+ _See code: [src/commands/app/list/index.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/list/index.js)_
588
588
 
589
589
  ## `aio app list extension`
590
590
 
@@ -609,7 +609,7 @@ ALIASES
609
609
  $ aio app list extensions
610
610
  ```
611
611
 
612
- _See code: [src/commands/app/list/extension.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/list/extension.js)_
612
+ _See code: [src/commands/app/list/extension.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/list/extension.js)_
613
613
 
614
614
  ## `aio app logs`
615
615
 
@@ -633,7 +633,7 @@ DESCRIPTION
633
633
  Fetch logs for an Adobe I/O App
634
634
  ```
635
635
 
636
- _See code: [src/commands/app/logs.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/logs.js)_
636
+ _See code: [src/commands/app/logs.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/logs.js)_
637
637
 
638
638
  ## `aio app pack [PATH]`
639
639
 
@@ -655,7 +655,7 @@ DESCRIPTION
655
655
  This command will support packaging apps for redistribution.
656
656
  ```
657
657
 
658
- _See code: [src/commands/app/pack.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/pack.js)_
658
+ _See code: [src/commands/app/pack.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/pack.js)_
659
659
 
660
660
  ## `aio app run`
661
661
 
@@ -679,7 +679,7 @@ DESCRIPTION
679
679
  Run an Adobe I/O App
680
680
  ```
681
681
 
682
- _See code: [src/commands/app/run.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/run.js)_
682
+ _See code: [src/commands/app/run.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/run.js)_
683
683
 
684
684
  ## `aio app test`
685
685
 
@@ -707,7 +707,7 @@ DESCRIPTION
707
707
  If the extension has a hook called 'test' in its 'ext.config.yaml', the script specified will be run instead.
708
708
  ```
709
709
 
710
- _See code: [src/commands/app/test.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/test.js)_
710
+ _See code: [src/commands/app/test.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/test.js)_
711
711
 
712
712
  ## `aio app undeploy`
713
713
 
@@ -732,7 +732,7 @@ DESCRIPTION
732
732
  Undeploys an Adobe I/O App
733
733
  ```
734
734
 
735
- _See code: [src/commands/app/undeploy.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/undeploy.js)_
735
+ _See code: [src/commands/app/undeploy.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/undeploy.js)_
736
736
 
737
737
  ## `aio app use [CONFIG_FILE_PATH]`
738
738
 
@@ -779,5 +779,5 @@ DESCRIPTION
779
779
  page in https://developer.adobe.com/console/
780
780
  ```
781
781
 
782
- _See code: [src/commands/app/use.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.0.0/src/commands/app/use.js)_
782
+ _See code: [src/commands/app/use.js](https://github.com/adobe/aio-cli-plugin-app/blob/13.1.0/src/commands/app/use.js)_
783
783
  <!-- commandsstop -->
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "13.0.0",
2
+ "version": "13.1.0",
3
3
  "commands": {
4
4
  "app:build": {
5
5
  "id": "app:build",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adobe/aio-cli-plugin-app",
3
3
  "description": "Create, Build and Deploy Adobe I/O Applications",
4
- "version": "13.0.0",
4
+ "version": "13.1.0",
5
5
  "author": "Adobe Inc.",
6
6
  "bugs": "https://github.com/adobe/aio-cli-plugin-app/issues",
7
7
  "dependencies": {
@@ -42,6 +42,13 @@ class BaseCommand extends Command {
42
42
  await super.init()
43
43
  // setup a prompt that outputs to stderr
44
44
  this.prompt = inquirer.createPromptModule({ output: process.stderr })
45
+
46
+ // set User-Agent for runtime calls
47
+ // ex. aio-cli-plugin-app/@adobe/aio-cli/10.3.1 (darwin-arm64; node-v18.20.4; zsh)
48
+ const vs = this.config.versionDetails
49
+ // some tests might not have this set, so we use ? nullish coalescing
50
+ process.env.__OW_USER_AGENT =
51
+ `aio-cli-plugin-app/${vs?.cliVersion} (${vs?.architecture}; ${vs?.nodeVersion}; ${vs?.shell})`
45
52
  }
46
53
 
47
54
  async getLibConsoleCLI () {
@@ -18,9 +18,10 @@ const BaseCommand = require('../../BaseCommand')
18
18
  const BuildCommand = require('./build')
19
19
  const webLib = require('@adobe/aio-lib-web')
20
20
  const { Flags } = require('@oclif/core')
21
- const { createWebExportFilter, runInProcess, buildExtensionPointPayloadWoMetadata, buildExcShellViewExtensionMetadata } = require('../../lib/app-helper')
21
+ const { createWebExportFilter, runInProcess, buildExtensionPointPayloadWoMetadata, buildExcShellViewExtensionMetadata, getCliInfo } = require('../../lib/app-helper')
22
22
  const rtLib = require('@adobe/aio-lib-runtime')
23
23
  const LogForwarding = require('../../lib/log-forwarding')
24
+ const { sendAuditLogs, getAuditLogEvent, getFilesCountWithExtension } = require('../../lib/audit-logger')
24
25
 
25
26
  const PRE_DEPLOY_EVENT_REG = 'pre-deploy-event-reg'
26
27
  const POST_DEPLOY_EVENT_REG = 'post-deploy-event-reg'
@@ -32,6 +33,7 @@ class Deploy extends BuildCommand {
32
33
 
33
34
  // flags
34
35
  flags['web-assets'] = flags['web-assets'] && !flags.action
36
+ // Deploy only a specific action, the flags can be specified multiple times, this will set --no-publish
35
37
  flags.publish = flags.publish && !flags.action
36
38
 
37
39
  const deployConfigs = await this.getAppExtConfigs(flags)
@@ -51,12 +53,11 @@ class Deploy extends BuildCommand {
51
53
 
52
54
  try {
53
55
  const aioConfig = (await this.getFullConfig()).aio
56
+ const cliDetails = await getCliInfo()
54
57
 
55
58
  // 1. update log forwarding configuration
56
59
  // note: it is possible that .aio file does not exist, which means there is no local lg config
57
- if (aioConfig?.project?.workspace &&
58
- flags['log-forwarding-update'] &&
59
- flags.actions) {
60
+ if (aioConfig?.project?.workspace && flags['log-forwarding-update'] && flags.actions) {
60
61
  spinner.start('Updating log forwarding configuration')
61
62
  try {
62
63
  const lf = await LogForwarding.init(aioConfig)
@@ -80,7 +81,8 @@ class Deploy extends BuildCommand {
80
81
  }
81
82
 
82
83
  // 2. If workspace is prod and has extensions, check if the app is published
83
- if (!isStandaloneApp && aioConfig?.project?.workspace?.name === 'Production') {
84
+ // if --no-publish, we skip this check
85
+ if (flags.publish && aioConfig?.project?.workspace?.name === 'Production') {
84
86
  const extension = await this.getApplicationExtension(aioConfig)
85
87
  if (extension && extension.status === 'PUBLISHED') {
86
88
  flags.publish = false // if the app is production and published, then skip publish later on
@@ -92,7 +94,15 @@ class Deploy extends BuildCommand {
92
94
  }
93
95
  }
94
96
 
95
- // 3. deploy actions and web assets for each extension
97
+ // 3. send deploy log event
98
+ const logEvent = getAuditLogEvent(flags, aioConfig.project, 'AB_APP_DEPLOY')
99
+ if (logEvent) {
100
+ await sendAuditLogs(cliDetails.accessToken, logEvent, cliDetails.env)
101
+ } else {
102
+ this.log(chalk.red(chalk.bold('Warning: No valid config data found to send audit log event for deployment.')))
103
+ }
104
+
105
+ // 4. deploy actions and web assets for each extension
96
106
  // Possible improvements:
97
107
  // - parallelize
98
108
  // - break into smaller pieces deploy, allowing to first deploy all actions then all web assets
@@ -100,6 +110,14 @@ class Deploy extends BuildCommand {
100
110
  const k = keys[i]
101
111
  const v = values[i]
102
112
  await this.deploySingleConfig(k, v, flags, spinner)
113
+ if (v.app.hasFrontend && flags['web-assets']) {
114
+ const opItems = getFilesCountWithExtension(v.web.distProd)
115
+ const assetDeployedLogEvent = getAuditLogEvent(flags, aioConfig.project, 'AB_APP_ASSETS_DEPLOYED')
116
+ if (assetDeployedLogEvent) {
117
+ assetDeployedLogEvent.data.opItems = opItems
118
+ await sendAuditLogs(cliDetails.accessToken, assetDeployedLogEvent, cliDetails.env)
119
+ }
120
+ }
103
121
  }
104
122
 
105
123
  // 4. deploy extension manifest
@@ -204,6 +222,11 @@ class Deploy extends BuildCommand {
204
222
  } else {
205
223
  deployedFrontendUrl = await webLib.deployWeb(config, onProgress)
206
224
  spinner.succeed(chalk.green(message))
225
+ const filesLogCount = getFilesCountWithExtension(config.web.distProd)
226
+ const filesDeployedMessage = `All static assets for the App Builder application in workspace: ${name} were successfully deployed to the CDN. Files deployed :`
227
+ const filesLogFormatted = filesLogCount?.map(file => ` • ${file}`).join('')
228
+ const finalMessage = chalk.green(`${filesDeployedMessage}\n${filesLogFormatted}`)
229
+ spinner.succeed(chalk.green(finalMessage))
207
230
  }
208
231
  } catch (err) {
209
232
  spinner.fail(chalk.green(message))
@@ -17,8 +17,9 @@ const { Flags } = require('@oclif/core')
17
17
 
18
18
  const BaseCommand = require('../../BaseCommand')
19
19
  const webLib = require('@adobe/aio-lib-web')
20
- const { runInProcess, buildExtensionPointPayloadWoMetadata } = require('../../lib/app-helper')
20
+ const { runInProcess, buildExtensionPointPayloadWoMetadata, getCliInfo } = require('../../lib/app-helper')
21
21
  const rtLib = require('@adobe/aio-lib-runtime')
22
+ const { sendAuditLogs, getAuditLogEvent } = require('../../lib/audit-logger')
22
23
 
23
24
  class Undeploy extends BaseCommand {
24
25
  async run () {
@@ -44,14 +45,29 @@ class Undeploy extends BaseCommand {
44
45
 
45
46
  const spinner = ora()
46
47
  try {
48
+ const aioConfig = (await this.getFullConfig()).aio
49
+ const cliDetails = await getCliInfo()
50
+ const logEvent = getAuditLogEvent(flags, aioConfig.project, 'AB_APP_UNDEPLOY')
51
+
52
+ // 1.1. send audit log event for successful undeploy
53
+ if (logEvent) {
54
+ await sendAuditLogs(cliDetails.accessToken, logEvent, cliDetails.env)
55
+ } else {
56
+ this.log(chalk.red(chalk.bold('Warning: No valid config data found to send audit log event for deployment.')))
57
+ }
58
+
47
59
  for (let i = 0; i < keys.length; ++i) {
48
60
  const k = keys[i]
49
61
  const v = values[i]
50
62
  await this.undeployOneExt(k, v, flags, spinner)
63
+ const assetUndeployLogEvent = getAuditLogEvent(flags, aioConfig.project, 'AB_APP_ASSETS_UNDEPLOYED')
64
+ if (assetUndeployLogEvent) {
65
+ await sendAuditLogs(cliDetails.accessToken, assetUndeployLogEvent, cliDetails.env)
66
+ }
51
67
  }
52
- // 2. unpublish extension manifest
68
+
69
+ // 1.2. unpublish extension manifest
53
70
  if (flags.unpublish && !(keys.length === 1 && keys[0] === 'application')) {
54
- const aioConfig = (await this.getFullConfig()).aio
55
71
  const payload = await this.unpublishExtensionPoints(libConsoleCLI, undeployConfigs, aioConfig, flags['force-unpublish'])
56
72
  this.log(chalk.blue(chalk.bold(`New Extension Point(s) in Workspace '${aioConfig.project.workspace.name}': '${Object.keys(payload.endpoints)}'`)))
57
73
  } else {
@@ -110,6 +126,7 @@ class Undeploy extends BaseCommand {
110
126
  if (!script) {
111
127
  await webLib.undeployWeb(config, onProgress)
112
128
  }
129
+
113
130
  spinner.succeed(chalk.green(`Un-Deploying web assets for ${extName}`))
114
131
  } catch (err) {
115
132
  spinner.fail(chalk.green(`Un-Deploying web assets for ${extName}`))
@@ -0,0 +1,156 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ Unless required by applicable law or agreed to in writing, software distributed under
7
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
+ OF ANY KIND, either express or implied. See the License for the specific language
9
+ governing permissions and limitations under the License.
10
+ */
11
+ const fetch = require('node-fetch')
12
+ const fs = require('fs')
13
+ const path = require('path')
14
+ const chalk = require('chalk')
15
+ const { getCliEnv, PROD_ENV } = require('@adobe/aio-lib-env')
16
+ const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:lib-audit-logger', { provider: 'debug' })
17
+
18
+ const OPERATIONS = {
19
+ AB_APP_DEPLOY: 'ab_app_deploy',
20
+ AB_APP_UNDEPLOY: 'ab_app_undeploy',
21
+ AB_APP_TEST: 'ab_app_test', // todo : remove after testing
22
+ AB_APP_ASSETS_DEPLOYED: 'ab_app_assets_deployed',
23
+ AB_APP_ASSETS_UNDEPLOYED: 'ab_app_assets_undeployed'
24
+ }
25
+
26
+ const AUDIT_SERVICE_ENPOINTS = {
27
+ stage: 'https://adp-auditlog-service-stage.adobeioruntime.net/api/v1/web/audit-log-api/event-post',
28
+ prod: 'https://adp-auditlog-service-prod.adobeioruntime.net/api/v1/web/audit-log-api/event-post'
29
+ }
30
+
31
+ /**
32
+ * Send audit log events to audit service
33
+ * @param {string} accessToken valid access token
34
+ * @param {object} logEvent logEvent details
35
+ * @param {string} env valid env stage|prod
36
+ */
37
+ async function sendAuditLogs (accessToken, logEvent, env = 'prod') {
38
+ // TODO: this is blocked by the audit service only being available in stage
39
+ // remove this check once the service is available in prod
40
+ if (env !== 'stage') {
41
+ return
42
+ }
43
+ const url = AUDIT_SERVICE_ENPOINTS[env]
44
+ const payload = {
45
+ event: logEvent
46
+ }
47
+ const options = {
48
+ method: 'POST',
49
+ headers: {
50
+ Authorization: 'Bearer ' + accessToken,
51
+ 'Content-type': 'application/json'
52
+ },
53
+ body: JSON.stringify(payload)
54
+ }
55
+ const response = await fetch(url, options)
56
+ if (response.status !== 200) {
57
+ const err = await response.text()
58
+ throw new Error('Failed to send audit log - ' + response.status + ' ' + err)
59
+ }
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param {object} flags cli flags
65
+ * @param {object} project details
66
+ * @param {string} event log name
67
+ * @returns {object} logEvent
68
+ */
69
+ function getAuditLogEvent (flags, project, event) {
70
+ if (getCliEnv() === PROD_ENV) {
71
+ aioLogger.debug('Audit logging is currently disabled in production environment')
72
+ return null
73
+ }
74
+
75
+ let logEvent, logStrMsg
76
+ if (project && project.org && project.workspace) {
77
+ if (event === 'AB_APP_DEPLOY') {
78
+ logStrMsg = `Starting deployment for the App Builder application in workspace ${project.workspace.name}`
79
+ } else if (event === 'AB_APP_UNDEPLOY') {
80
+ logStrMsg = `Starting undeployment for the App Builder application in workspace ${project.workspace.name}`
81
+ } else if (event === 'AB_APP_ASSETS_UNDEPLOYED') {
82
+ logStrMsg = `All static assets for the App Builder application in workspace: ${project.workspace.name} were successfully undeployed from the CDN`
83
+ } else if (event === 'AB_APP_ASSETS_DEPLOYED') {
84
+ logStrMsg = `All static assets for the App Builder application in workspace: ${project.workspace.name} were successfully deployed to the CDN.\n Files deployed - `
85
+ }
86
+
87
+ logEvent = {
88
+ orgId: project.org.id,
89
+ projectId: project.id,
90
+ workspaceId: project.workspace.id,
91
+ workspaceName: project.workspace.name,
92
+ operation: event in OPERATIONS ? OPERATIONS[event] : OPERATIONS.AB_APP_TEST,
93
+ timestamp: new Date().valueOf(),
94
+ data: {
95
+ cliCommandFlags: flags,
96
+ opDetailsStr: logStrMsg
97
+ }
98
+ }
99
+ }
100
+ return logEvent
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @param {string} directory | path to assets directory
106
+ * @returns {Array} log | array of log messages
107
+ */
108
+ function getFilesCountWithExtension (directory) {
109
+ const log = []
110
+
111
+ if (!fs.existsSync(directory)) {
112
+ this.log(chalk.red(chalk.bold(`Error: Directory ${directory} does not exist.`)))
113
+ return log
114
+ }
115
+
116
+ const files = fs.readdirSync(directory)
117
+
118
+ if (files.length === 0) {
119
+ this.log(chalk.red(chalk.bold(`Error: No files found in directory ${directory}.`)))
120
+ return log
121
+ }
122
+
123
+ const fileTypeCounts = {}
124
+
125
+ files.forEach(file => {
126
+ const ext = path.extname(file).toLowerCase() || 'no extension'
127
+ if (fileTypeCounts[ext]) {
128
+ fileTypeCounts[ext]++
129
+ } else {
130
+ fileTypeCounts[ext] = 1
131
+ }
132
+ })
133
+
134
+ Object.keys(fileTypeCounts).forEach(ext => {
135
+ const count = fileTypeCounts[ext]
136
+ let description
137
+
138
+ if (ext === '.js') description = 'Javascript file(s)'
139
+ else if (ext === '.css') description = 'CSS file(s)'
140
+ else if (ext === '.html') description = 'HTML page(s)'
141
+ else if (['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'].includes(ext)) description = 'image(s)'
142
+ else if (ext === 'no extension') description = 'file(s) without extension'
143
+ else description = `${ext} file(s)`
144
+
145
+ log.push(`${count} ${description}\n`)
146
+ })
147
+
148
+ return log
149
+ }
150
+
151
+ module.exports = {
152
+ sendAuditLogs,
153
+ getAuditLogEvent,
154
+ AUDIT_SERVICE_ENPOINTS,
155
+ getFilesCountWithExtension
156
+ }