Skip to content

Commit 08a163a

Browse files
authored
js: Fix handling of optional dates in response bodies (#1922)
## Motivation It's a bug! Actually produces invalid data as far as I can tell, as `new Date(null)` of course produces a valid date, rather than raising an exception... ## Solution Only call `new Date` on non-null data. The other change (first commit) is a drive-by improvement.
2 parents a0224c3 + 308ca8b commit 08a163a

24 files changed

+34
-26
lines changed

ChangeLog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Unreleased
4+
* Libs/JavaScript: Fix response processing code for endpoints with an optional datetime field in the response body
5+
36
## Version 1.65.0
47
* Libs/Python: Bring back the (deprecated) sync `dashboard_access` method, which was accidentally
58
removed in v1.64.1
@@ -16,7 +19,7 @@
1619
* Server: Add response duration tracking to webhook message attempts by @CodeMan62 in https://github.com/svix/svix-webhooks/pull/1877
1720
* Libs/Python: Specify minimum version of pydantic `pydantic >=2.10` in setup.py.
1821

19-
## Version 1.64.0
22+
## Version 1.64.0
2023
* CLI: Add interactive login with dashboard.svix.com
2124

2225
## Version 1.63.2

codegen-templates/javascript/types/macros.ts.jinja

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{% macro field_from_json(field_expr, type, field_required) %}
22
{%- if type.is_datetime() -%}
3-
new Date({{ field_expr }})
3+
{% if not field_required -%}
4+
{{ field_expr }} ? new Date({{ field_expr }}) : null
5+
{%- else -%}
6+
new Date({{ field_expr }})
7+
{%- endif -%}
48
{%- elif type.is_schema_ref() -%}
59
{# TODO(10055) remove this hack #}
610
{% if type.to_js() == "any" -%}
@@ -20,7 +24,8 @@
2024
or inner_t.is_list()
2125
or inner_t.is_set()
2226
or inner_t.is_map() -%}
23-
?.map((item: {{ inner_t.to_js() }}) => {{ field_from_json("item", inner_t, true) }})
27+
{% if not field_required -%}?{% endif -%}
28+
.map((item: {{ inner_t.to_js() }}) => {{ field_from_json("item", inner_t, true) }})
2429
{%- endif -%}
2530
{%- elif type.is_map() -%}
2631
{%- set value_t = type.value_type() -%}

javascript/src/models/apiTokenCensoredOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const ApiTokenCensoredOutSerializer = {
1616
return {
1717
censoredToken: object["censoredToken"],
1818
createdAt: new Date(object["createdAt"]),
19-
expiresAt: new Date(object["expiresAt"]),
19+
expiresAt: object["expiresAt"] ? new Date(object["expiresAt"]) : null,
2020
id: object["id"],
2121
name: object["name"],
2222
scopes: object["scopes"],

javascript/src/models/apiTokenOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const ApiTokenOutSerializer = {
1515
_fromJsonObject(object: any): ApiTokenOut {
1616
return {
1717
createdAt: new Date(object["createdAt"]),
18-
expiresAt: new Date(object["expiresAt"]),
18+
expiresAt: object["expiresAt"] ? new Date(object["expiresAt"]) : null,
1919
id: object["id"],
2020
name: object["name"],
2121
scopes: object["scopes"],

javascript/src/models/endpointDisabledEventData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const EndpointDisabledEventDataSerializer = {
2626
appUid: object["appUid"],
2727
endpointId: object["endpointId"],
2828
endpointUid: object["endpointUid"],
29-
failSince: new Date(object["failSince"]),
29+
failSince: object["failSince"] ? new Date(object["failSince"]) : null,
3030
trigger: object["trigger"]
3131
? EndpointDisabledTriggerSerializer._fromJsonObject(object["trigger"])
3232
: undefined,

javascript/src/models/endpointMessageOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const EndpointMessageOutSerializer = {
2626
eventId: object["eventId"],
2727
eventType: object["eventType"],
2828
id: object["id"],
29-
nextAttempt: new Date(object["nextAttempt"]),
29+
nextAttempt: object["nextAttempt"] ? new Date(object["nextAttempt"]) : null,
3030
payload: object["payload"],
3131
status: MessageStatusSerializer._fromJsonObject(object["status"]),
3232
tags: object["tags"],

javascript/src/models/environmentOut.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export const EnvironmentOutSerializer = {
1515
_fromJsonObject(object: any): EnvironmentOut {
1616
return {
1717
createdAt: new Date(object["createdAt"]),
18-
eventTypes: object["eventTypes"]?.map((item: EventTypeOut) =>
18+
eventTypes: object["eventTypes"].map((item: EventTypeOut) =>
1919
EventTypeOutSerializer._fromJsonObject(item)
2020
),
2121
settings: object["settings"],
22-
transformationTemplates: object["transformationTemplates"]?.map(
22+
transformationTemplates: object["transformationTemplates"].map(
2323
(item: ConnectorOut) => ConnectorOutSerializer._fromJsonObject(item)
2424
),
2525
version: object["version"],

javascript/src/models/listResponseApiTokenCensoredOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ListResponseApiTokenCensoredOut {
1515
export const ListResponseApiTokenCensoredOutSerializer = {
1616
_fromJsonObject(object: any): ListResponseApiTokenCensoredOut {
1717
return {
18-
data: object["data"]?.map((item: ApiTokenCensoredOut) =>
18+
data: object["data"].map((item: ApiTokenCensoredOut) =>
1919
ApiTokenCensoredOutSerializer._fromJsonObject(item)
2020
),
2121
done: object["done"],

javascript/src/models/listResponseApplicationOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseApplicationOut {
1212
export const ListResponseApplicationOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseApplicationOut {
1414
return {
15-
data: object["data"]?.map((item: ApplicationOut) =>
15+
data: object["data"].map((item: ApplicationOut) =>
1616
ApplicationOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseBackgroundTaskOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseBackgroundTaskOut {
1212
export const ListResponseBackgroundTaskOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseBackgroundTaskOut {
1414
return {
15-
data: object["data"]?.map((item: BackgroundTaskOut) =>
15+
data: object["data"].map((item: BackgroundTaskOut) =>
1616
BackgroundTaskOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseEndpointMessageOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseEndpointMessageOut {
1212
export const ListResponseEndpointMessageOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseEndpointMessageOut {
1414
return {
15-
data: object["data"]?.map((item: EndpointMessageOut) =>
15+
data: object["data"].map((item: EndpointMessageOut) =>
1616
EndpointMessageOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseEndpointOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseEndpointOut {
1212
export const ListResponseEndpointOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseEndpointOut {
1414
return {
15-
data: object["data"]?.map((item: EndpointOut) =>
15+
data: object["data"].map((item: EndpointOut) =>
1616
EndpointOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseEventTypeOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseEventTypeOut {
1212
export const ListResponseEventTypeOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseEventTypeOut {
1414
return {
15-
data: object["data"]?.map((item: EventTypeOut) =>
15+
data: object["data"].map((item: EventTypeOut) =>
1616
EventTypeOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseIngestEndpointOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseIngestEndpointOut {
1212
export const ListResponseIngestEndpointOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseIngestEndpointOut {
1414
return {
15-
data: object["data"]?.map((item: IngestEndpointOut) =>
15+
data: object["data"].map((item: IngestEndpointOut) =>
1616
IngestEndpointOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseIngestSourceOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseIngestSourceOut {
1212
export const ListResponseIngestSourceOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseIngestSourceOut {
1414
return {
15-
data: object["data"]?.map((item: IngestSourceOut) =>
15+
data: object["data"].map((item: IngestSourceOut) =>
1616
IngestSourceOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseIntegrationOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseIntegrationOut {
1212
export const ListResponseIntegrationOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseIntegrationOut {
1414
return {
15-
data: object["data"]?.map((item: IntegrationOut) =>
15+
data: object["data"].map((item: IntegrationOut) =>
1616
IntegrationOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseMessageAttemptOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseMessageAttemptOut {
1212
export const ListResponseMessageAttemptOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseMessageAttemptOut {
1414
return {
15-
data: object["data"]?.map((item: MessageAttemptOut) =>
15+
data: object["data"].map((item: MessageAttemptOut) =>
1616
MessageAttemptOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseMessageEndpointOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseMessageEndpointOut {
1212
export const ListResponseMessageEndpointOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseMessageEndpointOut {
1414
return {
15-
data: object["data"]?.map((item: MessageEndpointOut) =>
15+
data: object["data"].map((item: MessageEndpointOut) =>
1616
MessageEndpointOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseMessageOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ListResponseMessageOut {
1212
export const ListResponseMessageOutSerializer = {
1313
_fromJsonObject(object: any): ListResponseMessageOut {
1414
return {
15-
data: object["data"]?.map((item: MessageOut) =>
15+
data: object["data"].map((item: MessageOut) =>
1616
MessageOutSerializer._fromJsonObject(item)
1717
),
1818
done: object["done"],

javascript/src/models/listResponseOperationalWebhookEndpointOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ListResponseOperationalWebhookEndpointOut {
1515
export const ListResponseOperationalWebhookEndpointOutSerializer = {
1616
_fromJsonObject(object: any): ListResponseOperationalWebhookEndpointOut {
1717
return {
18-
data: object["data"]?.map((item: OperationalWebhookEndpointOut) =>
18+
data: object["data"].map((item: OperationalWebhookEndpointOut) =>
1919
OperationalWebhookEndpointOutSerializer._fromJsonObject(item)
2020
),
2121
done: object["done"],

javascript/src/models/messageEndpointOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const MessageEndpointOutSerializer = {
3131
disabled: object["disabled"],
3232
filterTypes: object["filterTypes"],
3333
id: object["id"],
34-
nextAttempt: new Date(object["nextAttempt"]),
34+
nextAttempt: object["nextAttempt"] ? new Date(object["nextAttempt"]) : null,
3535
rateLimit: object["rateLimit"],
3636
status: MessageStatusSerializer._fromJsonObject(object["status"]),
3737
uid: object["uid"],

javascript/src/models/pollingEndpointOut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface PollingEndpointOut {
1414
export const PollingEndpointOutSerializer = {
1515
_fromJsonObject(object: any): PollingEndpointOut {
1616
return {
17-
data: object["data"]?.map((item: PollingEndpointMessageOut) =>
17+
data: object["data"].map((item: PollingEndpointMessageOut) =>
1818
PollingEndpointMessageOutSerializer._fromJsonObject(item)
1919
),
2020
done: object["done"],

javascript/src/models/recoverIn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const RecoverInSerializer = {
1010
_fromJsonObject(object: any): RecoverIn {
1111
return {
1212
since: new Date(object["since"]),
13-
until: new Date(object["until"]),
13+
until: object["until"] ? new Date(object["until"]) : null,
1414
};
1515
},
1616

javascript/src/models/replayIn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const ReplayInSerializer = {
1010
_fromJsonObject(object: any): ReplayIn {
1111
return {
1212
since: new Date(object["since"]),
13-
until: new Date(object["until"]),
13+
until: object["until"] ? new Date(object["until"]) : null,
1414
};
1515
},
1616

0 commit comments

Comments
 (0)