Skip to content

Commit 9939ea9

Browse files
feat: support Date and DateTime types (box/box-codegen#476) (#152)
1 parent 6d09845 commit 9939ea9

20 files changed

+1210
-789
lines changed

.codegen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "f0bd1ce", "specHash": "1698c95", "version": "0.5.3" }
1+
{ "engineHash": "267eec8", "specHash": "1698c95", "version": "0.5.3" }

docs/tasks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ await client.tasks.createTask({
5959
id: file.id,
6060
} satisfies CreateTaskRequestBodyItemField,
6161
message: 'test message',
62-
dueAt: date,
62+
dueAt: dateTime,
6363
action: 'review' as CreateTaskRequestBodyActionField,
6464
completionRule: 'all_assignees' as CreateTaskRequestBodyCompletionRuleField,
6565
} satisfies CreateTaskRequestBody);

src/internal/utils.ts

+38
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,44 @@ export type Iterator<T = any> = AsyncIterator<T>;
2727
export type AgentOptions = any;
2828
export type Agent = any;
2929

30+
// using wrappers for date/datetime because of inability to export built-in Date types
31+
class DateWrapper {
32+
constructor(public readonly value: Date) {}
33+
}
34+
35+
class DateTimeWrapper {
36+
constructor(public readonly value: Date) {}
37+
}
38+
39+
export { DateWrapper as Date, DateTimeWrapper as DateTime };
40+
41+
export function dateFromString(value: string): DateWrapper {
42+
return new DateWrapper(new Date(value));
43+
}
44+
45+
export function dateToString(date: DateWrapper): string {
46+
return date.value.toISOString().match(/^\d{4}-\d{2}-\d{2}/)![0];
47+
}
48+
49+
export function dateTimeFromString(value: string): DateTimeWrapper {
50+
return new DateTimeWrapper(new Date(value));
51+
}
52+
53+
export function dateTimeToString(dateTime: DateTimeWrapper): string {
54+
return (
55+
dateTime.value
56+
.toISOString()
57+
.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)![0] + '+00:00'
58+
);
59+
}
60+
61+
export {
62+
dateToString as serializeDate,
63+
dateFromString as deserializeDate,
64+
dateTimeToString as serializeDateTime,
65+
dateTimeFromString as deserializeDateTime,
66+
};
67+
3068
// Function to convert a hexadecimal string to base64
3169
export function hexStrToBase64(hex: string) {
3270
const hexString = hex.toString(); // Ensure the input is a string

src/managers/events.generated.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { serializeClientError } from '../schemas.generated.js';
44
import { deserializeClientError } from '../schemas.generated.js';
55
import { serializeRealtimeServers } from '../schemas.generated.js';
66
import { deserializeRealtimeServers } from '../schemas.generated.js';
7+
import { serializeDateTime } from '../internal/utils.js';
8+
import { deserializeDateTime } from '../internal/utils.js';
79
import { Events } from '../schemas.generated.js';
810
import { ClientError } from '../schemas.generated.js';
911
import { RealtimeServers } from '../schemas.generated.js';
@@ -13,6 +15,7 @@ import { prepareParams } from '../internal/utils.js';
1315
import { toString } from '../internal/utils.js';
1416
import { ByteStream } from '../internal/utils.js';
1517
import { CancellationToken } from '../internal/utils.js';
18+
import { DateTime } from '../internal/utils.js';
1619
import { sdToJson } from '../serialization/json.js';
1720
import { FetchOptions } from '../networking/fetch.js';
1821
import { FetchResponse } from '../networking/fetch.js';
@@ -148,8 +151,8 @@ export interface GetEventsQueryParams {
148151
readonly streamPosition?: string;
149152
readonly limit?: number;
150153
readonly eventType?: readonly GetEventsQueryParamsEventTypeField[];
151-
readonly createdAfter?: string;
152-
readonly createdBefore?: string;
154+
readonly createdAfter?: DateTime;
155+
readonly createdBefore?: DateTime;
153156
}
154157
export class GetEventsHeaders {
155158
readonly extraHeaders?: {
@@ -219,8 +222,16 @@ export class EventsManager {
219222
['event_type']: queryParams.eventType
220223
? queryParams.eventType.map(toString).join(',')
221224
: undefined,
222-
['created_after']: toString(queryParams.createdAfter) as string,
223-
['created_before']: toString(queryParams.createdBefore) as string,
225+
['created_after']: sdToJson(
226+
queryParams.createdAfter
227+
? serializeDateTime(queryParams.createdAfter)
228+
: undefined
229+
) as string,
230+
['created_before']: sdToJson(
231+
queryParams.createdBefore
232+
? serializeDateTime(queryParams.createdBefore)
233+
: undefined
234+
) as string,
224235
});
225236
const headersMap: {
226237
readonly [key: string]: string;

src/managers/files.generated.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { serializeFileFull } from '../schemas.generated.js';
22
import { deserializeFileFull } from '../schemas.generated.js';
33
import { serializeClientError } from '../schemas.generated.js';
44
import { deserializeClientError } from '../schemas.generated.js';
5+
import { serializeDateTime } from '../internal/utils.js';
6+
import { deserializeDateTime } from '../internal/utils.js';
57
import { FileFull } from '../schemas.generated.js';
68
import { ClientError } from '../schemas.generated.js';
79
import { Authentication } from '../networking/auth.generated.js';
@@ -15,6 +17,7 @@ import { FetchOptions } from '../networking/fetch.js';
1517
import { FetchResponse } from '../networking/fetch.js';
1618
import { fetch } from '../networking/fetch.js';
1719
import { SerializedData } from '../serialization/json.js';
20+
import { DateTime } from '../internal/utils.js';
1821
import { BoxSdkError } from '../box/errors.js';
1922
import { sdIsEmpty } from '../serialization/json.js';
2023
import { sdIsBoolean } from '../serialization/json.js';
@@ -64,13 +67,13 @@ export interface UpdateFileByIdRequestBodySharedLinkField {
6467
readonly access?: UpdateFileByIdRequestBodySharedLinkAccessField;
6568
readonly password?: string;
6669
readonly vanityName?: string;
67-
readonly unsharedAt?: string;
70+
readonly unsharedAt?: DateTime;
6871
readonly permissions?: UpdateFileByIdRequestBodySharedLinkPermissionsField;
6972
}
7073
export type UpdateFileByIdRequestBodyLockAccessField = 'lock';
7174
export interface UpdateFileByIdRequestBodyLockField {
7275
readonly access?: UpdateFileByIdRequestBodyLockAccessField;
73-
readonly expiresAt?: string;
76+
readonly expiresAt?: DateTime;
7477
readonly isDownloadPrevented?: boolean;
7578
}
7679
export type UpdateFileByIdRequestBodyPermissionsCanDownloadField =
@@ -89,7 +92,7 @@ export interface UpdateFileByIdRequestBody {
8992
readonly parent?: UpdateFileByIdRequestBodyParentField;
9093
readonly sharedLink?: UpdateFileByIdRequestBodySharedLinkField;
9194
readonly lock?: UpdateFileByIdRequestBodyLockField;
92-
readonly dispositionAt?: string;
95+
readonly dispositionAt?: DateTime;
9396
readonly permissions?: UpdateFileByIdRequestBodyPermissionsField;
9497
readonly collections?: readonly UpdateFileByIdRequestBodyCollectionsField[];
9598
readonly tags?: readonly string[];
@@ -489,7 +492,8 @@ export function serializeUpdateFileByIdRequestBodySharedLinkField(
489492
: serializeUpdateFileByIdRequestBodySharedLinkAccessField(val.access),
490493
['password']: val.password == void 0 ? void 0 : val.password,
491494
['vanity_name']: val.vanityName == void 0 ? void 0 : val.vanityName,
492-
['unshared_at']: val.unsharedAt == void 0 ? void 0 : val.unsharedAt,
495+
['unshared_at']:
496+
val.unsharedAt == void 0 ? void 0 : serializeDateTime(val.unsharedAt),
493497
['permissions']:
494498
val.permissions == void 0
495499
? void 0
@@ -509,8 +513,8 @@ export function deserializeUpdateFileByIdRequestBodySharedLinkField(
509513
val.password == void 0 ? void 0 : val.password;
510514
const vanityName: undefined | string =
511515
val.vanity_name == void 0 ? void 0 : val.vanity_name;
512-
const unsharedAt: undefined | string =
513-
val.unshared_at == void 0 ? void 0 : val.unshared_at;
516+
const unsharedAt: undefined | DateTime =
517+
val.unshared_at == void 0 ? void 0 : deserializeDateTime(val.unshared_at);
514518
const permissions:
515519
| undefined
516520
| UpdateFileByIdRequestBodySharedLinkPermissionsField =
@@ -556,7 +560,8 @@ export function serializeUpdateFileByIdRequestBodyLockField(
556560
val.access == void 0
557561
? void 0
558562
: serializeUpdateFileByIdRequestBodyLockAccessField(val.access),
559-
['expires_at']: val.expiresAt == void 0 ? void 0 : val.expiresAt,
563+
['expires_at']:
564+
val.expiresAt == void 0 ? void 0 : serializeDateTime(val.expiresAt),
560565
['is_download_prevented']:
561566
val.isDownloadPrevented == void 0 ? void 0 : val.isDownloadPrevented,
562567
};
@@ -568,8 +573,8 @@ export function deserializeUpdateFileByIdRequestBodyLockField(
568573
val.access == void 0
569574
? void 0
570575
: deserializeUpdateFileByIdRequestBodyLockAccessField(val.access);
571-
const expiresAt: undefined | string =
572-
val.expires_at == void 0 ? void 0 : val.expires_at;
576+
const expiresAt: undefined | DateTime =
577+
val.expires_at == void 0 ? void 0 : deserializeDateTime(val.expires_at);
573578
const isDownloadPrevented: undefined | boolean =
574579
val.is_download_prevented == void 0 ? void 0 : val.is_download_prevented;
575580
return {
@@ -664,7 +669,9 @@ export function serializeUpdateFileByIdRequestBody(val: any): SerializedData {
664669
? void 0
665670
: serializeUpdateFileByIdRequestBodyLockField(val.lock),
666671
['disposition_at']:
667-
val.dispositionAt == void 0 ? void 0 : val.dispositionAt,
672+
val.dispositionAt == void 0
673+
? void 0
674+
: serializeDateTime(val.dispositionAt),
668675
['permissions']:
669676
val.permissions == void 0
670677
? void 0
@@ -703,8 +710,10 @@ export function deserializeUpdateFileByIdRequestBody(
703710
val.lock == void 0
704711
? void 0
705712
: deserializeUpdateFileByIdRequestBodyLockField(val.lock);
706-
const dispositionAt: undefined | string =
707-
val.disposition_at == void 0 ? void 0 : val.disposition_at;
713+
const dispositionAt: undefined | DateTime =
714+
val.disposition_at == void 0
715+
? void 0
716+
: deserializeDateTime(val.disposition_at);
708717
const permissions: undefined | UpdateFileByIdRequestBodyPermissionsField =
709718
val.permissions == void 0
710719
? void 0

src/managers/folders.generated.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { serializeClientError } from '../schemas.generated.js';
44
import { deserializeClientError } from '../schemas.generated.js';
55
import { serializeItems } from '../schemas.generated.js';
66
import { deserializeItems } from '../schemas.generated.js';
7+
import { serializeDateTime } from '../internal/utils.js';
8+
import { deserializeDateTime } from '../internal/utils.js';
79
import { FolderFull } from '../schemas.generated.js';
810
import { ClientError } from '../schemas.generated.js';
911
import { Items } from '../schemas.generated.js';
@@ -18,6 +20,7 @@ import { FetchOptions } from '../networking/fetch.js';
1820
import { FetchResponse } from '../networking/fetch.js';
1921
import { fetch } from '../networking/fetch.js';
2022
import { SerializedData } from '../serialization/json.js';
23+
import { DateTime } from '../internal/utils.js';
2124
import { BoxSdkError } from '../box/errors.js';
2225
import { sdIsEmpty } from '../serialization/json.js';
2326
import { sdIsBoolean } from '../serialization/json.js';
@@ -75,7 +78,7 @@ export interface UpdateFolderByIdRequestBodySharedLinkField {
7578
readonly access?: UpdateFolderByIdRequestBodySharedLinkAccessField;
7679
readonly password?: string;
7780
readonly vanityName?: string;
78-
readonly unsharedAt?: string;
81+
readonly unsharedAt?: DateTime;
7982
readonly permissions?: UpdateFolderByIdRequestBodySharedLinkPermissionsField;
8083
}
8184
export type UpdateFolderByIdRequestBodyFolderUploadEmailAccessField =
@@ -683,7 +686,8 @@ export function serializeUpdateFolderByIdRequestBodySharedLinkField(
683686
: serializeUpdateFolderByIdRequestBodySharedLinkAccessField(val.access),
684687
['password']: val.password == void 0 ? void 0 : val.password,
685688
['vanity_name']: val.vanityName == void 0 ? void 0 : val.vanityName,
686-
['unshared_at']: val.unsharedAt == void 0 ? void 0 : val.unsharedAt,
689+
['unshared_at']:
690+
val.unsharedAt == void 0 ? void 0 : serializeDateTime(val.unsharedAt),
687691
['permissions']:
688692
val.permissions == void 0
689693
? void 0
@@ -703,8 +707,8 @@ export function deserializeUpdateFolderByIdRequestBodySharedLinkField(
703707
val.password == void 0 ? void 0 : val.password;
704708
const vanityName: undefined | string =
705709
val.vanity_name == void 0 ? void 0 : val.vanity_name;
706-
const unsharedAt: undefined | string =
707-
val.unshared_at == void 0 ? void 0 : val.unshared_at;
710+
const unsharedAt: undefined | DateTime =
711+
val.unshared_at == void 0 ? void 0 : deserializeDateTime(val.unshared_at);
708712
const permissions:
709713
| undefined
710714
| UpdateFolderByIdRequestBodySharedLinkPermissionsField =

src/managers/legalHoldPolicies.generated.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { serializeClientError } from '../schemas.generated.js';
44
import { deserializeClientError } from '../schemas.generated.js';
55
import { serializeLegalHoldPolicy } from '../schemas.generated.js';
66
import { deserializeLegalHoldPolicy } from '../schemas.generated.js';
7+
import { serializeDateTime } from '../internal/utils.js';
8+
import { deserializeDateTime } from '../internal/utils.js';
79
import { LegalHoldPolicies } from '../schemas.generated.js';
810
import { ClientError } from '../schemas.generated.js';
911
import { LegalHoldPolicy } from '../schemas.generated.js';
@@ -18,6 +20,7 @@ import { FetchOptions } from '../networking/fetch.js';
1820
import { FetchResponse } from '../networking/fetch.js';
1921
import { fetch } from '../networking/fetch.js';
2022
import { SerializedData } from '../serialization/json.js';
23+
import { DateTime } from '../internal/utils.js';
2124
import { sdIsEmpty } from '../serialization/json.js';
2225
import { sdIsBoolean } from '../serialization/json.js';
2326
import { sdIsNumber } from '../serialization/json.js';
@@ -52,8 +55,8 @@ export interface GetLegalHoldPoliciesHeadersInput {
5255
export interface CreateLegalHoldPolicyRequestBody {
5356
readonly policyName: string;
5457
readonly description?: string;
55-
readonly filterStartedAt?: string;
56-
readonly filterEndedAt?: string;
58+
readonly filterStartedAt?: DateTime;
59+
readonly filterEndedAt?: DateTime;
5760
readonly isOngoing?: boolean;
5861
}
5962
export class CreateLegalHoldPolicyHeaders {
@@ -331,9 +334,13 @@ export function serializeCreateLegalHoldPolicyRequestBody(
331334
['policy_name']: val.policyName,
332335
['description']: val.description == void 0 ? void 0 : val.description,
333336
['filter_started_at']:
334-
val.filterStartedAt == void 0 ? void 0 : val.filterStartedAt,
337+
val.filterStartedAt == void 0
338+
? void 0
339+
: serializeDateTime(val.filterStartedAt),
335340
['filter_ended_at']:
336-
val.filterEndedAt == void 0 ? void 0 : val.filterEndedAt,
341+
val.filterEndedAt == void 0
342+
? void 0
343+
: serializeDateTime(val.filterEndedAt),
337344
['is_ongoing']: val.isOngoing == void 0 ? void 0 : val.isOngoing,
338345
};
339346
}
@@ -343,10 +350,14 @@ export function deserializeCreateLegalHoldPolicyRequestBody(
343350
const policyName: string = val.policy_name;
344351
const description: undefined | string =
345352
val.description == void 0 ? void 0 : val.description;
346-
const filterStartedAt: undefined | string =
347-
val.filter_started_at == void 0 ? void 0 : val.filter_started_at;
348-
const filterEndedAt: undefined | string =
349-
val.filter_ended_at == void 0 ? void 0 : val.filter_ended_at;
353+
const filterStartedAt: undefined | DateTime =
354+
val.filter_started_at == void 0
355+
? void 0
356+
: deserializeDateTime(val.filter_started_at);
357+
const filterEndedAt: undefined | DateTime =
358+
val.filter_ended_at == void 0
359+
? void 0
360+
: deserializeDateTime(val.filter_ended_at);
350361
const isOngoing: undefined | boolean =
351362
val.is_ongoing == void 0 ? void 0 : val.is_ongoing;
352363
return {

src/managers/sharedLinksFiles.generated.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { serializeFileFull } from '../schemas.generated.js';
22
import { deserializeFileFull } from '../schemas.generated.js';
33
import { serializeClientError } from '../schemas.generated.js';
44
import { deserializeClientError } from '../schemas.generated.js';
5+
import { serializeDateTime } from '../internal/utils.js';
6+
import { deserializeDateTime } from '../internal/utils.js';
57
import { FileFull } from '../schemas.generated.js';
68
import { ClientError } from '../schemas.generated.js';
79
import { Authentication } from '../networking/auth.generated.js';
@@ -15,6 +17,7 @@ import { FetchOptions } from '../networking/fetch.js';
1517
import { FetchResponse } from '../networking/fetch.js';
1618
import { fetch } from '../networking/fetch.js';
1719
import { SerializedData } from '../serialization/json.js';
20+
import { DateTime } from '../internal/utils.js';
1821
import { BoxSdkError } from '../box/errors.js';
1922
import { sdIsEmpty } from '../serialization/json.js';
2023
import { sdIsBoolean } from '../serialization/json.js';
@@ -83,7 +86,7 @@ export interface AddShareLinkToFileRequestBodySharedLinkField {
8386
readonly access?: AddShareLinkToFileRequestBodySharedLinkAccessField;
8487
readonly password?: string;
8588
readonly vanityName?: string;
86-
readonly unsharedAt?: string;
89+
readonly unsharedAt?: DateTime;
8790
readonly permissions?: AddShareLinkToFileRequestBodySharedLinkPermissionsField;
8891
}
8992
export interface AddShareLinkToFileRequestBody {
@@ -124,7 +127,7 @@ export interface UpdateSharedLinkOnFileRequestBodySharedLinkField {
124127
readonly access?: UpdateSharedLinkOnFileRequestBodySharedLinkAccessField;
125128
readonly password?: string;
126129
readonly vanityName?: string;
127-
readonly unsharedAt?: string;
130+
readonly unsharedAt?: DateTime;
128131
readonly permissions?: UpdateSharedLinkOnFileRequestBodySharedLinkPermissionsField;
129132
}
130133
export interface UpdateSharedLinkOnFileRequestBody {
@@ -460,7 +463,8 @@ export function serializeAddShareLinkToFileRequestBodySharedLinkField(
460463
),
461464
['password']: val.password == void 0 ? void 0 : val.password,
462465
['vanity_name']: val.vanityName == void 0 ? void 0 : val.vanityName,
463-
['unshared_at']: val.unsharedAt == void 0 ? void 0 : val.unsharedAt,
466+
['unshared_at']:
467+
val.unsharedAt == void 0 ? void 0 : serializeDateTime(val.unsharedAt),
464468
['permissions']:
465469
val.permissions == void 0
466470
? void 0
@@ -482,8 +486,8 @@ export function deserializeAddShareLinkToFileRequestBodySharedLinkField(
482486
val.password == void 0 ? void 0 : val.password;
483487
const vanityName: undefined | string =
484488
val.vanity_name == void 0 ? void 0 : val.vanity_name;
485-
const unsharedAt: undefined | string =
486-
val.unshared_at == void 0 ? void 0 : val.unshared_at;
489+
const unsharedAt: undefined | DateTime =
490+
val.unshared_at == void 0 ? void 0 : deserializeDateTime(val.unshared_at);
487491
const permissions:
488492
| undefined
489493
| AddShareLinkToFileRequestBodySharedLinkPermissionsField =
@@ -584,7 +588,8 @@ export function serializeUpdateSharedLinkOnFileRequestBodySharedLinkField(
584588
),
585589
['password']: val.password == void 0 ? void 0 : val.password,
586590
['vanity_name']: val.vanityName == void 0 ? void 0 : val.vanityName,
587-
['unshared_at']: val.unsharedAt == void 0 ? void 0 : val.unsharedAt,
591+
['unshared_at']:
592+
val.unsharedAt == void 0 ? void 0 : serializeDateTime(val.unsharedAt),
588593
['permissions']:
589594
val.permissions == void 0
590595
? void 0
@@ -608,8 +613,8 @@ export function deserializeUpdateSharedLinkOnFileRequestBodySharedLinkField(
608613
val.password == void 0 ? void 0 : val.password;
609614
const vanityName: undefined | string =
610615
val.vanity_name == void 0 ? void 0 : val.vanity_name;
611-
const unsharedAt: undefined | string =
612-
val.unshared_at == void 0 ? void 0 : val.unshared_at;
616+
const unsharedAt: undefined | DateTime =
617+
val.unshared_at == void 0 ? void 0 : deserializeDateTime(val.unshared_at);
613618
const permissions:
614619
| undefined
615620
| UpdateSharedLinkOnFileRequestBodySharedLinkPermissionsField =

0 commit comments

Comments
 (0)