cap-js / notifications

CDS Plugin that provides support for publishing business notifications in SAP Build WorkZone.
https://cap.cloud.sap/docs/
Apache License 2.0
6 stars 0 forks source link

Application crashing when trying to trigger alert #43

Open gopalanand333 opened 5 months ago

gopalanand333 commented 5 months ago

Hi, My application is crashing when it is trying to trigger the notification. I am getting the following error:

alertnotification","msg":"Emit failed {\n event: 'Default',\n cause: Error: Unauthorized\n at NotifyToRest.postNotification (/home/vcap/app/node_modules/@cap-js/notifications/srv/notifyToRest.js:34:21)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async Promise.all (index 0)\n at async NotifyToRest.handle (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:76:21)\n at async ODataRequest.<anonymous> (/home/vcap/app/node_modules/@sap/cds/libx/outbox/index.js:303:14)\n at async ODataRequest.emit (/home/vcap/app/node_modules/@sap/cds/lib/req/context.js:54:9)\n at async ProcessorService.commit (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-tx.js:139:7)\n at async /home/vcap/app/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js:61:9 {\n unrecoverable: true\n }\n}"}

Here's my MTA

_schema-version: '3.1'
ID: incident-management
version: 1.0.0
description: "A simple CAP project."
parameters:
  enable-parallel-deployments: true
build-parameters:
  before-all:
    - builder: custom
      commands:
        - rm -rf incident-management-ui-deployer/resources
        - npm install --production
        - npx -p @sap/cds-dk cds build --production
        - mkdir gen/ui-resources
modules:
  - name: incident-management-ui-resources
    type: com.sap.application.content
    path: gen/ui-resources
    requires:
      - name: incident-management-html5-repo-host
        parameters:
          content-target: true
    build-parameters:
      requires:
        - name: incident-management
          artifacts:
            - ./*.zip
          target-path: .
  - name: incident-management
    type: html5
    path: app/incidents
    build-parameters:
      builder: custom
      commands:
        - npm install
        - npx -p @ui5/cli ui5 build --dest ../../gen/app/incidents/dist
          --include-task=generateManifestBundle
          --include-task=generateCachebusterInfo
        - bash -c "cd ../../gen/app/incidents/dist && npx bestzip
          ../incidents.zip *"
      supported-platforms:
        []
      build-result: ../../gen/app/incidents
  - name: incident-management-portal-content-deployer
    type: com.sap.application.content
    path: packages/deploy-int/portal-content
    requires:
      - name: incident-management-portal
        parameters:
          content-target: true
          service-key:
            name: incident-management-portal-deploy-key
            config:
              content-endpoint: developer
      - name: incident-management-auth
      - name: incident-management-html5-repo-host
      - name: incident-management-ui-resources
  - name: incident-management-approuter
    type: nodejs
    path: packages/deploy-int/approuter
    parameters:
      memory: 128M
    requires:
      - name: incident-management-auth
      - name: incident-management-portal
      - name: incident-management-html5-repo-runtime
      - name: srv-api
        group: destinations
        properties:
          forwardAuthToken: true
          strictSSL: true
          name: srv-api
          url: '~{srv-url}'
  - name: incident-management-srv
    type: nodejs
    path: gen/srv
    parameters:
      buildpack: nodejs_buildpack
    build-parameters:
      builder: npm
    provides:
      - name: srv-api # required by consumers of CAP services (e.g. approuter)
        properties:
          srv-url: ${default-url}
    requires:
      - name: incident-management-db
      - name: incident-management-auth
      - name: incident-management-destination
      - name: incident-management-alerts

  - name: incident-management-db-deployer
    type: hdb
    path: gen/db
    parameters:
      buildpack: nodejs_buildpack
    requires:
      - name: incident-management-db
  - name: notification-content-deployment
    type: nodejs
    path: gen/srv
    parameters:
      no-route: true
      no-start: true
      memory: 500MB
      disk-quota: 500MB
      tasks:
        - name: notification-content-deployment
          command: "node node_modules/@cap-js/notifications/lib/content-deployment.js"
          memory: 500MB
          disk-quota: 500MB
    requires:
      - name: incident-management-destination
      - name: incident-management-auth
      - name: incident-management-db
      - name: incident-management-alerts
resources:
  - name: incident-management-portal
    type: org.cloudfoundry.managed-service
    parameters:
      service-plan: standard
      service: portal
  - name: incident-management-html5-repo-runtime
    type: org.cloudfoundry.managed-service
    parameters:
      service-plan: app-runtime
      service: html5-apps-repo
  - name: incident-management-html5-repo-host
    type: org.cloudfoundry.managed-service
    parameters:
      service-plan: app-host
      service: html5-apps-repo
  - name: incident-management-db
    type: com.sap.xs.hdi-container
    parameters:
      service: hana
      service-plan: hdi-shared
  - name: incident-management-auth
    type: org.cloudfoundry.managed-service
    parameters:
      service: xsuaa
      service-plan: application
      path: ./xs-security.json
      config:
        xsappname: incident-management-${org}-${space}
        tenant-mode: dedicated
  - name: incident-management-destination
    type: org.cloudfoundry.managed-service
    parameters:
      service: destination
      service-plan: lite
  - name: incident-management-alerts
    type: org.cloudfoundry.managed-service
    parameters:
      service: alert-notification
      service-plan: lite
anshuman92 commented 5 months ago

Hi @gopalanand333 ,

Did you define "notifications" under "Cds.requires" in package.json file ?

Ideally, the structure should be "cds" : {"requires": {"notifications":{"destination": "SAP_Notifications"}}}

"SAP_Notifications" should be defined as a destination in BTP Cockpit. You can get information about destination from the Site settings of Build Work Zone. Thanks, Anshuman

gopalanand333 commented 5 months ago

@anshuman92
https://github.com/cap-js/notifications?tab=readme-ov-file#notification-destination states that the above configuration is added by default. But in my application, it is not getting added automatically when adding the plugin

anshuman92 commented 5 months ago

@anshuman92 https://github.com/cap-js/notifications?tab=readme-ov-file#notification-destination states that the above configuration is added by default. But in my application, it is not getting added automatically when adding the plugin

@gopalanand333 No, the plugin does not add automatically as mentioned. Therefore, I added manually as a usual practice after setting destinations in BTP cockpit. Another issue I have raised here - https://github.com/cap-js/notifications/issues/44. Kindly see if you come across.

Regloom commented 2 months ago

@gopalanand333 No, the plugin does not add automatically as mentioned. Therefore, I added manually as a usual practice after setting destinations in BTP cockpit. Another issue I have raised here - #44. Kindly see if you come across.

Also stumbled on this. Here is a code snippet which I have added to 'server.js':

cds.on("served", async ()=>{
    const {deployNotificationTypes} = require("@cap-js/notifications/lib/content-deployment");
})
anshuman92 commented 2 months ago

@gopalanand333 No, the plugin does not add automatically as mentioned. Therefore, I added manually as a usual practice after setting destinations in BTP cockpit. Another issue I have raised here - #44. Kindly see if you come across.

Also stumbled on this. Here is a code snippet which I have added to 'server.js':

cds.on("served", async ()=>{
    const {deployNotificationTypes} = require("@cap-js/notifications/lib/content-deployment");
})

Yeah, I have added this too.