Skip to content

Notification creation fails for nested 'data' key when package-lock file is regenerated #465

@kshitij-k-osmosys

Description

@kshitij-k-osmosys

Description

When we regenerate package-lock.json file and run the api, we are unable to create notifications that have nested data fields.

Example of nested data field

{
    // Assuming providerId 3 also has channelType 3
    "providerId": 3,
    "data": {
        "to": "91xxxyyyzzzz",
        "type": "template",
        "template": {
            "namespace": "sample_namespace",
            "name": "sample_name",
            "language": {
                "policy": "deterministic",
                "code": "en"
            },
            "components": [
                {
                    "type": "body",
                    "parameters": [
                        {
                            "type": "text",
                            "text": "Placeholder 1"
                        },
                        {
                            "type": "text",
                            "text": "Placeholder 2"
                        }
                    ]
                }
            ]
        }
    }
}

When we try to create a notification for providers like 360Dialog (Channel Type = 3) or AWS SES (Channel Type = 11), response returns an Internal Server Error (Status Code 500)

Issue is seen in this function: https://github.com/OsmosysSoftware/osmo-x/blob/main/apps/api/src/common/decorators/is-data-valid.decorator.ts#L51

Steps to reproduce this issue

1. Clone the repository

git clone https://github.com/OsmosysSoftware/osmo-x.git
cd osmo-x/apps/api/scripts

2. Remove node_modules and package-lock.json file

rm -rf node_modules/ package-lock.json 

3. Re-generate packages

npm install

4. Start the api service

npm run start

5. Create a notification that has nested entries in the 'data' key

Create notification for providers like 360Dialog (Channel Type = 3) or AWS SES (Channel Type = 11)

Logs

[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","source":"5","message":"6"},"2025-08-04T10:32:19.817Z","info","low","08ad75e4-60dc-4b45-972b-eef0ffa96f93","RequestLoggerMiddleware","Incoming Request: POST /notifications"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","source":"5","message":"6"},"2025-08-04T10:32:19.817Z","info","low","995c4c34-815b-42cb-b63d-5429e4addd44","RequestLoggerMiddleware","Request Body: {\"providerId\":3,\"data\":{\"to\":\"91xxxyyyzzzz\",\"type\":\"template\",\"template\":{\"namespace\":\"sample_namespace\",\"name\":\"sample_name\",\"language\":{\"policy\":\"deterministic\",\"code\":\"en\"},\"components\":[{\"type\":\"body\",\"parameters\":[{\"type\":\"text\",\"text\":\"Placeholder 1\"},{\"type\":\"text\",\"text\":\"Placeholder 2\"}]}]}}}"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.818Z","debug","low","f57112b9-3acc-4d75-926a-643e158ea656","Request validation started for request body: {\"providerId\":3,\"data\":{\"to\":\"91xxxyyyzzzz\",\"type\":\"template\",\"template\":{\"namespace\":\"sample_namespace\",\"name\":\"sample_name\",\"language\":{\"policy\":\"deterministic\",\"code\":\"en\"},\"components\":[{\"type\":\"body\",\"parameters\":[{\"type\":\"text\",\"text\":\"Placeholder 1\"},{\"type\":\"text\",\"text\":\"Placeholder 2\"}]}]}}}"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.819Z","debug","low","ba719304-0e17-48ff-9884-e9bf5be1e44e","Fetching request header and provider ID: 3"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.819Z","debug","low","504926f2-67fa-4aa8-818f-1d33a9339d7b","Fetching provider Id"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.820Z","debug","low","3e52322f-9b4b-4b29-87c1-cec9182304bc","validateApiKeyHeader started"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.841Z","debug","low","2803d906-6254-4746-b13b-c19b3e4ba673","Fetched providerEntry from DB (using request providerId): {\"providerId\":3,\"name\":\"360dialog-whatsapp\",\"channelType\":3,\"isEnabled\":1,\"configuration\":{},\"applicationId\":1,\"userId\":1,\"createdOn\":\"2024-04-29T08:10:40.000Z\",\"updatedOn\":\"2025-05-01T11:36:02.000Z\",\"status\":1}"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.895Z","debug","low","6114e92c-991e-413a-aa21-5328a6e70a33","Valid API Key found for the application."]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.901Z","debug","low","79251cfc-fa3e-45b8-a24d-b137906a5a1f","Request data validation started"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.904Z","debug","low","aa57375d-f3b2-4417-bb77-4c2faf291bc9","Fetched channel type: 3 from provider Id: 3"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","message":"5"},"2025-08-04T10:32:19.905Z","debug","low","4886a92c-1e61-4d40-b935-274f320fa8c2","Awaiting Validation of request data as per request channel type"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","source":"5","message":"6","stackTrace":"7"},"2025-08-04T10:32:23.671Z","error","high","a27fabbf-87e7-471d-bbd1-256cb92b6714","ExceptionsHandler","Cannot convert undefined or null to object",["8"],"TypeError: Cannot convert undefined or null to object\n    at Function.values (<anonymous>)\n    at <anonymous> (/osmo-x/apps/api/src/common/decorators/is-data-valid.decorator.ts:55:61)\n    at Array.map (<anonymous>)\n    at validateAndThrowError (/osmo-x/apps/api/src/common/decorators/is-data-valid.decorator.ts:55:41)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async IsDataValidConstraint.validate (/osmo-x/apps/api/src/common/decorators/is-data-valid.decorator.ts:78:9)\n    at async Promise.all (index 0)\n    at async ValidationPipe.transform (/osmo-x/apps/api/node_modules/@nestjs/common/pipes/validation.pipe.js:72:24)\n    at async resolveParamValue (/osmo-x/apps/api/node_modules/@nestjs/core/router/router-execution-context.js:148:23)\n    at async Promise.all (index 0)"]
[{"timestamp":"1","level":"2","severity":"3","tracebackId":"4","source":"5","message":"6"},"2025-08-04T10:32:23.673Z","info","low","c6cf91b8-ecc5-4d66-8030-ea17c45d813c","RequestLoggerMiddleware","Outgoing Response: POST /notifications - statusCode 500 - contentLength 52 - delay 3856ms"]

Error

[osmox] 27899 4/8/2025, 4:02:23 pm   ERROR [ExceptionsHandler] Cannot convert undefined or null to object - {
  stack: [
    'TypeError: Cannot convert undefined or null to object\n' +
      '    at Function.values (<anonymous>)\n' +
      '    at <anonymous> (/osmo-x/apps/api/src/common/decorators/is-data-valid.decorator.ts:55:61)\n' +
      '    at Array.map (<anonymous>)\n' +
      '    at validateAndThrowError (/osmo-x/apps/api/src/common/decorators/is-data-valid.decorator.ts:55:41)\n' +
      '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
      '    at async IsDataValidConstraint.validate (/osmo-x/apps/api/src/common/decorators/is-data-valid.decorator.ts:78:9)\n' +
      '    at async Promise.all (index 0)\n' +
      '    at async ValidationPipe.transform (/osmo-x/apps/api/node_modules/@nestjs/common/pipes/validation.pipe.js:72:24)\n' +
      '    at async resolveParamValue (/osmo-x/apps/api/node_modules/@nestjs/core/router/router-execution-context.js:148:23)\n' +
      '    at async Promise.all (index 0)'
  ]
} +4s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions