Skip to content

Refactor OCPI adapter into sdk-like modular components & bug fixes - #3

Draft
ameetdesh wants to merge 37 commits into
beckn:mainfrom
ameetdesh:main
Draft

Refactor OCPI adapter into sdk-like modular components & bug fixes#3
ameetdesh wants to merge 37 commits into
beckn:mainfrom
ameetdesh:main

Conversation

@ameetdesh

@ameetdesh ameetdesh commented Nov 19, 2025

Copy link
Copy Markdown
Contributor
  • Refactored packages into core, cache-redis, log-clickhouse packages for modularity.
  • Replaced original beckn v1 yaml file ref_docs/specs_yaml/simple-energy_EV_1.1.0_openapi_3.1.yaml with modular v1 yaml files from https://github.com/beckn/protocol-specifications-new. Earlier file was giving serialization error due to long monolithic lines, after the package refactor.
  • The beckn:id was a very long string due to concatenation of base64 encoding for provider, evse, tariff and connector. It was replaced by a shorter id, provider|evse|tariff|connector format. This helps keep json payloads smaller.
  • The beckn v2 on_select and on_init calls were not hitting the OCPI server, and refreshing of cache was hitting it thrice. These bugs are fixed now.

P.S. due to size of refactor, I did an overwrite of remote changes by always choosing this branch, git merge -s ours upstream/main. Going forward this will NOT be done, as the diffs are expected to be smaller and reviewable.

…rver ill-formed response. Fixed non0functional select & init flows. Now they actually ping ocpi server for availability and respond.
@ameetdesh
ameetdesh marked this pull request as ready for review November 19, 2025 05:34
@ameetdesh
ameetdesh requested a review from nirmalnr November 19, 2025 05:39
// Start the server
app.listen(config.port, () => {
console.log(`[${new Date().toISOString()}] Server is running on http://localhost:${config.port}`);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Start the server
    app.listen(config.port, () => {
        console.log(`[${new Date().toISOString()}] Server is running on http://localhost/:${config.port}`);
    }).on('error', (error: Error) => {
        console.error(`[${new Date().toISOString()}] Failed to start server:`, error);
        process.exit(1);
    });

Will show error if server start fails

@nirmalnr

Copy link
Copy Markdown
Collaborator

Can we recheck if the v1 schema is as expected or not. I was able to get the following on_search for v1:

{
    "context": {
        "domain": "deg",
        "action": "on_search",
        "version": "1.0.0",
        "bap_id": "bookmycharger.com",
        "bap_uri": "https://api.bookmycharger.com/v1",
        "transaction_id": "e6d86146-92b9-44c5-9581-f6be88f14e42",
        "message_id": "search-1111-2222-3333-4444",
        "timestamp": "2025-11-19T10:02:01.301Z",
        "location": {},
        "bpp_id": "connector-bpp",
        "bpp_uri": "https://bpp_url.com/"
    },
    "message": {
        "catalog": {
            "@context": "https://becknprotocol.io/schemas/core/v1/Catalog/schema-context.jsonld",
            "@type": "Catalog",
            "beckn:id": "catalog-1",
            "beckn:items": [
                {
                    "id": "HrKNUxJ9Ara6AL6PaUlF|v5bXyAlSr8G6lvUAN1A_1|1|dz2SXdIDJDfNjsPfw",
                    "descriptor": {
                        "name": "Test QR Code - T",
                        "code": "energy"
                    },
                    "tags": [
                        {
                            "descriptor": {
                                "code": "connector-specifications",
                                "name": "Connector Specifications"
                            },
                            "list": [
                                {
                                    "descriptor": {
                                        "name": "connector Id",
                                        "code": "connector-id"
                                    },
                                    "value": "1"
                                },
                                {
                                    "descriptor": {
                                        "name": "Connector Type",
                                        "code": "connector_type"
                                    },
                                    "value": "IEC_62196_T2"
                                },
                                {
                                    "descriptor": {
                                        "name": "Power Type",
                                        "code": "power_type"
                                    },
                                    "value": "AC_3_PHASE"
                                }
                            ]
                        }
                    ],
                    "price": {
                        "currency": "INR/kWh",
                        "value": "12.00"
                    },
                    "location_ids": [
                        "HrKNUxJ9Ara6AL6PaUlF"
                    ],
                    "beckn:provider": {
                        "beckn:id": "THP-HrKNUxJ9Ara6AL6PaUlF",
                        "beckn:descriptor": {
                            "@type": "beckn:Descriptor",
                            "schema:name": "Thunder Plus"
                        }
                    },
                    "beckn:availableAt": [
                        {
                            "geo": {
                                "type": "Point",
                                "coordinates": [
                                    77.2584309,
                                    28.5503906
                                ]
                            }
                        }
                    ]
                },
                {
                    "id": "HrKNUxJ9Ara6AL6PaUlF|v5bXyAlSr8G6lvUAN1A_2|1|dz2SXdIDJDfNjsPfw",
                    "descriptor": {
                        "name": "Test QR Code - T",
                        "code": "energy"
                    },
                    "tags": [
                        {
                            "descriptor": {
                                "code": "connector-specifications",
                                "name": "Connector Specifications"
                            },
                            "list": [
                                {
                                    "descriptor": {
                                        "name": "connector Id",
                                        "code": "connector-id"
                                    },
                                    "value": "1"
                                },
                                {
                                    "descriptor": {
                                        "name": "Connector Type",
                                        "code": "connector_type"
                                    },
                                    "value": "IEC_62196_T2"
                                },
                                {
                                    "descriptor": {
                                        "name": "Power Type",
                                        "code": "power_type"
                                    },
                                    "value": "AC_3_PHASE"
                                }
                            ]
                        }
                    ],
                    "price": {
                        "currency": "INR/kWh",
                        "value": "12.00"
                    },
                    "location_ids": [
                        "HrKNUxJ9Ara6AL6PaUlF"
                    ],
                    "beckn:provider": {
                        "beckn:id": "THP-HrKNUxJ9Ara6AL6PaUlF",
                        "beckn:descriptor": {
                            "@type": "beckn:Descriptor",
                            "schema:name": "Thunder Plus"
                        }
                    },
                    "beckn:availableAt": [
                        {
                            "geo": {
                                "type": "Point",
                                "coordinates": [
                                    77.2584309,
                                    28.5503906
                                ]
                            }
                        }
                    ]
                },
                {
                    "id": "HrKNUxJ9Ara6AL6PaUlF|af7c3MVQklXwBshPj8_2|1|ajcx2DQt07uERmEqprnQ",
                    "descriptor": {
                        "name": "Testing",
                        "code": "energy"
                    },
                    "tags": [
                        {
                            "descriptor": {
                                "code": "connector-specifications",
                                "name": "Connector Specifications"
                            },
                            "list": [
                                {
                                    "descriptor": {
                                        "name": "connector Id",
                                        "code": "connector-id"
                                    },
                                    "value": "1"
                                },
                                {
                                    "descriptor": {
                                        "name": "Connector Type",
                                        "code": "connector_type"
                                    },
                                    "value": "IEC_60309_2_three_16"
                                },
                                {
                                    "descriptor": {
                                        "name": "Power Type",
                                        "code": "power_type"
                                    },
                                    "value": "AC_1_PHASE"
                                }
                            ]
                        }
                    ],
                    "price": {
                        "currency": "INR/kWh",
                        "value": "20.00"
                    },
                    "location_ids": [
                        "HrKNUxJ9Ara6AL6PaUlF"
                    ],
                    "beckn:provider": {
                        "beckn:id": "THP-HrKNUxJ9Ara6AL6PaUlF",
                        "beckn:descriptor": {
                            "@type": "beckn:Descriptor",
                            "schema:name": "Thunder Plus"
                        }
                    },
                    "beckn:availableAt": [
                        {
                            "geo": {
                                "type": "Point",
                                "coordinates": [
                                    77.2584309,
                                    28.5503906
                                ]
                            }
                        }
                    ]
                },
                {
                    "id": "HrKNUxJ9Ara6AL6PaUlF|af7c3MVQklXwBshPj8_1|1|ajcx2DQt07uERmEqprnQ",
                    "descriptor": {
                        "name": "Testing",
                        "code": "energy"
                    },
                    "tags": [
                        {
                            "descriptor": {
                                "code": "connector-specifications",
                                "name": "Connector Specifications"
                            },
                            "list": [
                                {
                                    "descriptor": {
                                        "name": "connector Id",
                                        "code": "connector-id"
                                    },
                                    "value": "1"
                                },
                                {
                                    "descriptor": {
                                        "name": "Connector Type",
                                        "code": "connector_type"
                                    },
                                    "value": "DOMESTIC_D"
                                },
                                {
                                    "descriptor": {
                                        "name": "Power Type",
                                        "code": "power_type"
                                    },
                                    "value": "AC_1_PHASE"
                                }
                            ]
                        }
                    ],
                    "price": {
                        "currency": "INR/kWh",
                        "value": "20.00"
                    },
                    "location_ids": [
                        "HrKNUxJ9Ara6AL6PaUlF"
                    ],
                    "beckn:provider": {
                        "beckn:id": "THP-HrKNUxJ9Ara6AL6PaUlF",
                        "beckn:descriptor": {
                            "@type": "beckn:Descriptor",
                            "schema:name": "Thunder Plus"
                        }
                    },
                    "beckn:availableAt": [
                        {
                            "geo": {
                                "type": "Point",
                                "coordinates": [
                                    77.2584309,
                                    28.5503906
                                ]
                            }
                        }
                    ]
                },
                {
                    "id": "HrKNUxJ9Ara6AL6PaUlF|tLAj42jrr0dYtDqdqTDK_1|1|ajcx2DQt07uERmEqprnQ",
                    "descriptor": {
                        "name": "Thunder+ Test CP",
                        "code": "energy"
                    },
                    "tags": [
                        {
                            "descriptor": {
                                "code": "connector-specifications",
                                "name": "Connector Specifications"
                            },
                            "list": [
                                {
                                    "descriptor": {
                                        "name": "connector Id",
                                        "code": "connector-id"
                                    },
                                    "value": "1"
                                },
                                {
                                    "descriptor": {
                                        "name": "Connector Type",
                                        "code": "connector_type"
                                    },
                                    "value": "IEC_62196_T2"
                                },
                                {
                                    "descriptor": {
                                        "name": "Power Type",
                                        "code": "power_type"
                                    },
                                    "value": "AC_3_PHASE"
                                }
                            ]
                        }
                    ],
                    "price": {
                        "currency": "INR/kWh",
                        "value": "20.00"
                    },
                    "location_ids": [
                        "HrKNUxJ9Ara6AL6PaUlF"
                    ],
                    "beckn:provider": {
                        "beckn:id": "THP-HrKNUxJ9Ara6AL6PaUlF",
                        "beckn:descriptor": {
                            "@type": "beckn:Descriptor",
                            "schema:name": "Thunder Plus"
                        }
                    },
                    "beckn:availableAt": [
                        {
                            "geo": {
                                "type": "Point",
                                "coordinates": [
                                    77.2584309,
                                    28.5503906
                                ]
                            }
                        }
                    ]
                },
                {
                    "id": "HrKNUxJ9Ara6AL6PaUlF|tLAj42jrr0dYtDqdqTDK_2|1|ajcx2DQt07uERmEqprnQ",
                    "descriptor": {
                        "name": "Thunder+ Test CP",
                        "code": "energy"
                    },
                    "tags": [
                        {
                            "descriptor": {
                                "code": "connector-specifications",
                                "name": "Connector Specifications"
                            },
                            "list": [
                                {
                                    "descriptor": {
                                        "name": "connector Id",
                                        "code": "connector-id"
                                    },
                                    "value": "1"
                                },
                                {
                                    "descriptor": {
                                        "name": "Connector Type",
                                        "code": "connector_type"
                                    },
                                    "value": "DOMESTIC_D"
                                },
                                {
                                    "descriptor": {
                                        "name": "Power Type",
                                        "code": "power_type"
                                    },
                                    "value": "AC_1_PHASE"
                                }
                            ]
                        }
                    ],
                    "price": {
                        "currency": "INR/kWh",
                        "value": "20.00"
                    },
                    "location_ids": [
                        "HrKNUxJ9Ara6AL6PaUlF"
                    ],
                    "beckn:provider": {
                        "beckn:id": "THP-HrKNUxJ9Ara6AL6PaUlF",
                        "beckn:descriptor": {
                            "@type": "beckn:Descriptor",
                            "schema:name": "Thunder Plus"
                        }
                    },
                    "beckn:availableAt": [
                        {
                            "geo": {
                                "type": "Point",
                                "coordinates": [
                                    77.2584309,
                                    28.5503906
                                ]
                            }
                        }
                    ]
                }
            ]
        }
    }
}

I think beckn:availableAt, @context, @type etc are part of v2 specs?

@ameetdesh
ameetdesh marked this pull request as draft November 19, 2025 17:16
@ameetdesh

Copy link
Copy Markdown
Contributor Author

converting to draft to fix Nirmal's findings.

…hema from specs/beckn-schemas/becknv1. This schema may be wrong.. will fix that in a followup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants