Skip to content

[BUG]: findAllCustomerPastUsage API result mismatches from the type #57

@avznog

Description

@avznog

Describe the bug
Hello,
When using the client to fetch the PastUsage of a customer using the findAllCustomerPastUsage method, the typing differs from what is returned from the API :
The typing returns a CustomerPastUsage type which has a usage_period: CustomerUsage[] attribute, but the data itself returned has a usage_period: CustomerUsageObject[] attribute instead.

To Reproduce
Steps to reproduce the behavior:

  1. Implement this method:
async getCurrentUsage(subscriptions: Subscription) {
    const currentUsage: {
      subscription: Subscription;
      customerPastUsage: CustomerPastUsage;
    }[] = [];
    await Promise.all(
      subscriptions.map(async sub => {
        const usage = await this.client.customers.findAllCustomerPastUsage(id, {
          external_subscription_id: sub.external_id
        });
        currentUsage.push({ subscription: sub, customerPastUsage: usage.data });
      })
    );
    console.log(currentUsage[2].customerPastUsage.usage_periods[0]);
    console.log(
      currentUsage[2].customerPastUsage.usage_periods[0].customer_usage
    );
    return currentUsage;
  }
  1. Check the data returned
{
  "from_datetime": "2024-11-18T12:56:43Z",
  "to_datetime": "2024-11-18T12:57:29Z",
  "issuing_date": "2024-11-18",
  "currency": "EUR",
  "amount_cents": 333,
  "total_amount_cents": 400,
  "taxes_amount_cents": 67,
  "lago_invoice_id": "8c69-8c69-8c69-8c69-4a08847d3318",
  "charges_usage": [
    {
      "units": "0.0",
      "events_count": 0,
      "amount_cents": 0,
      "amount_currency": "EUR",
      "charge": {
        "lago_id": "1e981898-8c69-8c69-8c69-a9f9bc3158ba",
        "charge_model": "standard",
        "invoice_display_name": ""
      },
      "billable_metric": {
        "lago_id": "1e656c4f-8c69-8c69-8c69-d45b442ab0a1",
        "name": "MyPlan active user seat",
        "code": "plan:active-user",
        "aggregation_type": "unique_count_agg"
      },
      "filters": [],
      "groups": [],
      "grouped_usage": []
    },
    {
      "units": "0.0",
      "events_count": 0,
      "amount_cents": 0,
      "amount_currency": "EUR",
      "charge": {
        "lago_id": "5a6896d3-8c69-8c69-8c69-775f2bfacb3b",
        "charge_model": "standard",
        "invoice_display_name": ""
      },
      "billable_metric": {
        "lago_id": "3253c24e-8c69-8c69-8c69-b13ca62525c2",
        "name": "myplan tome",
        "code": "myplan:ingested-tome",
        "aggregation_type": "count_agg"
      },
      "filters": [],
      "groups": [],
      "grouped_usage": []
    },
    {
      "units": "0.0",
      "events_count": 0,
      "amount_cents": 0,
      "amount_currency": "EUR",
      "charge": {
        "lago_id": "e434918d-8c69-8c69-8c69-895d8ada1510",
        "charge_model": "standard",
        "invoice_display_name": ""
      },
      "billable_metric": {
        "lago_id": "75ede326-8c69-8c69-8c69-bb8570e302b1",
        "name": "My plan query",
        "code": "myplan:user-query",
        "aggregation_type": "count_agg"
      },
      "filters": [],
      "groups": [],
      "grouped_usage": []
    }
  ]
}

Expected behavior
The API data returned should match the typing : as the documentation of Lago API Ref mentions here, the typing and the API should return a usage_period: CustomerUsage[] object.

Screenshots
image
image
The returned data

Support

  • OS: Linux Ubuntu
  • Browser: safari

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions