Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,484 changes: 743 additions & 741 deletions api/api.gen.go

Large diffs are not rendered by default.

1,236 changes: 619 additions & 617 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions api/client/javascript/src/client/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7594,6 +7594,8 @@ export interface components {
readonly subject: components['schemas']['Subject']
/** Entitlement Value */
readonly value: components['schemas']['EntitlementValue']
/** Customer */
readonly customer?: components['schemas']['Customer']
/** Threshold */
readonly threshold: components['schemas']['NotificationRuleBalanceThresholdValue']
}
Expand Down Expand Up @@ -7643,6 +7645,8 @@ export interface components {
readonly subject: components['schemas']['Subject']
/** Entitlement Value */
readonly value: components['schemas']['EntitlementValue']
/** Customer */
readonly customer?: components['schemas']['Customer']
}
/** @description Payload for notification event with `invoice.created` type. */
NotificationEventInvoiceCreatedPayload: {
Expand Down
10 changes: 10 additions & 0 deletions api/openapi.cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19516,6 +19516,11 @@ components:
- $ref: '#/components/schemas/EntitlementValue'
title: Entitlement Value
readOnly: true
customer:
allOf:
- $ref: '#/components/schemas/Customer'
title: Customer
readOnly: true
threshold:
allOf:
- $ref: '#/components/schemas/NotificationRuleBalanceThresholdValue'
Expand Down Expand Up @@ -19598,6 +19603,11 @@ components:
- $ref: '#/components/schemas/EntitlementValue'
title: Entitlement Value
readOnly: true
customer:
allOf:
- $ref: '#/components/schemas/Customer'
title: Customer
readOnly: true
description: Base data for any payload with entitlement entitlement value.
NotificationEventInvoiceCreatedPayload:
type: object
Expand Down
10 changes: 10 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20203,6 +20203,11 @@ components:
- $ref: '#/components/schemas/EntitlementValue'
title: Entitlement Value
readOnly: true
customer:
allOf:
- $ref: '#/components/schemas/Customer'
title: Customer
readOnly: true
threshold:
allOf:
- $ref: '#/components/schemas/NotificationRuleBalanceThresholdValue'
Expand Down Expand Up @@ -20285,6 +20290,11 @@ components:
- $ref: '#/components/schemas/EntitlementValue'
title: Entitlement Value
readOnly: true
customer:
allOf:
- $ref: '#/components/schemas/Customer'
title: Customer
readOnly: true
description: Base data for any payload with entitlement entitlement value.
NotificationEventInvoiceCreatedPayload:
type: object
Expand Down
4 changes: 4 additions & 0 deletions api/spec/src/notification/entitlements.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ model NotificationEventEntitlementValuePayloadBase {
@visibility(Lifecycle.Read)
@summary("Entitlement Value")
value: OpenMeter.Entitlements.EntitlementValue;

@visibility(Lifecycle.Read)
@summary("Customer")
customer?: OpenMeter.Customer.Customer;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions openmeter/notification/consumer/entitlementbalancethreshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"golang.org/x/exp/slices"

"github.com/openmeterio/openmeter/api"
customerhttpdriver "github.com/openmeterio/openmeter/openmeter/customer/httpdriver"
"github.com/openmeterio/openmeter/openmeter/entitlement"
entitlementdriver "github.com/openmeterio/openmeter/openmeter/entitlement/driver"
"github.com/openmeterio/openmeter/openmeter/entitlement/snapshot"
Expand Down Expand Up @@ -201,6 +202,15 @@ func (b *EntitlementSnapshotHandler) createEvent(ctx context.Context, in createB
annotations[notification.AnnotationEventFeatureID] = in.Snapshot.Feature.ID
}

var cus api.Customer

if in.Snapshot.Customer != nil {
cus, err = customerhttpdriver.CustomerToAPI(*in.Snapshot.Customer, nil, nil)
if err != nil {
return fmt.Errorf("failed to map customer to API: %w", err)
}
}

_, err = b.Notification.CreateEvent(ctx, notification.CreateEventInput{
NamespacedModel: models.NamespacedModel{
Namespace: in.Snapshot.Namespace.ID,
Expand All @@ -216,6 +226,7 @@ func (b *EntitlementSnapshotHandler) createEvent(ctx context.Context, in createB
Entitlement: *entitlementAPIEntity,
Feature: productcatalogdriver.MapFeatureToResponse(in.Snapshot.Feature),
Subject: subjecthttphandler.FromSubject(in.Snapshot.Subject),
Customer: lo.EmptyableToPtr(cus),
Value: (api.EntitlementValue)(*in.Snapshot.Value),
},
Threshold: in.Threshold,
Expand Down
11 changes: 11 additions & 0 deletions openmeter/notification/consumer/entitlementreset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/exp/slices"

"github.com/openmeterio/openmeter/api"
customerhttpdriver "github.com/openmeterio/openmeter/openmeter/customer/httpdriver"
entitlementdriver "github.com/openmeterio/openmeter/openmeter/entitlement/driver"
"github.com/openmeterio/openmeter/openmeter/entitlement/snapshot"
"github.com/openmeterio/openmeter/openmeter/notification"
Expand Down Expand Up @@ -114,6 +115,15 @@ func (b *EntitlementSnapshotHandler) createResetEvent(ctx context.Context, in cr
annotations[notification.AnnotationEventFeatureID] = in.Snapshot.Feature.ID
}

var cus api.Customer

if in.Snapshot.Customer != nil {
cus, err = customerhttpdriver.CustomerToAPI(*in.Snapshot.Customer, nil, nil)
if err != nil {
return fmt.Errorf("failed to map customer to API: %w", err)
}
}

_, err = b.Notification.CreateEvent(ctx, notification.CreateEventInput{
NamespacedModel: models.NamespacedModel{
Namespace: in.Snapshot.Namespace.ID,
Expand All @@ -128,6 +138,7 @@ func (b *EntitlementSnapshotHandler) createResetEvent(ctx context.Context, in cr
Entitlement: *entitlementAPIEntity,
Feature: productcatalogdriver.MapFeatureToResponse(in.Snapshot.Feature),
Subject: subjecthttphandler.FromSubject(in.Snapshot.Subject),
Customer: lo.EmptyableToPtr(cus),
Value: (api.EntitlementValue)(*in.Snapshot.Value),
},
},
Expand Down
1 change: 1 addition & 0 deletions openmeter/notification/entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type EntitlementValuePayloadBase struct {
Feature api.Feature `json:"feature"`
Subject api.Subject `json:"subject"`
Value api.EntitlementValue `json:"value"`
Customer *api.Customer `json:"customer,omitempty"`
}

type BalanceThresholdPayload struct {
Expand Down
10 changes: 3 additions & 7 deletions openmeter/notification/httpdriver/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,17 +530,12 @@ func FromEventAsBalanceThresholdPayload(e notification.Event) (api.NotificationE
Id: e.ID,
Timestamp: e.CreatedAt,
Type: api.NotificationEventBalanceThresholdPayloadTypeEntitlementsBalanceThreshold,
Data: struct {
Entitlement api.EntitlementMetered `json:"entitlement"`
Feature api.Feature `json:"feature"`
Subject api.Subject `json:"subject"`
Threshold api.NotificationRuleBalanceThresholdValue `json:"threshold"`
Value api.EntitlementValue `json:"value"`
}{
Data: api.NotificationEventBalanceThresholdPayloadData{
Value: e.Payload.BalanceThreshold.Value,
Entitlement: e.Payload.BalanceThreshold.Entitlement,
Feature: e.Payload.BalanceThreshold.Feature,
Subject: e.Payload.BalanceThreshold.Subject,
Customer: e.Payload.BalanceThreshold.Customer,
Threshold: e.Payload.BalanceThreshold.Threshold,
},
}, nil
Expand All @@ -560,6 +555,7 @@ func FromEventAsEntitlementResetPayload(e notification.Event) (api.NotificationE
Entitlement: e.Payload.EntitlementReset.Entitlement,
Feature: e.Payload.EntitlementReset.Feature,
Subject: e.Payload.EntitlementReset.Subject,
Customer: e.Payload.BalanceThreshold.Customer,
},
}, nil
}
Expand Down