@censys/platform-sdk 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +10 -6
  2. package/docs/sdks/accountmanagement/README.md +72 -2
  3. package/docs/sdks/collections/README.md +0 -1
  4. package/docs/sdks/globaldata/README.md +0 -1
  5. package/docs/sdks/threathunting/README.md +78 -1
  6. package/examples/package-lock.json +1 -1
  7. package/funcs/accountManagementGetOrganizationCredits.d.ts +1 -1
  8. package/funcs/accountManagementGetOrganizationCredits.js +1 -1
  9. package/funcs/accountManagementGetUserCredits.d.ts +18 -0
  10. package/funcs/accountManagementGetUserCredits.d.ts.map +1 -0
  11. package/funcs/accountManagementGetUserCredits.js +112 -0
  12. package/funcs/accountManagementGetUserCredits.js.map +1 -0
  13. package/funcs/threatHuntingListThreats.d.ts +18 -0
  14. package/funcs/threatHuntingListThreats.d.ts.map +1 -0
  15. package/funcs/threatHuntingListThreats.js +130 -0
  16. package/funcs/threatHuntingListThreats.js.map +1 -0
  17. package/jsr.json +1 -1
  18. package/lib/config.d.ts +4 -4
  19. package/lib/config.js +4 -4
  20. package/lib/encodings.d.ts +1 -0
  21. package/lib/encodings.d.ts.map +1 -1
  22. package/lib/encodings.js +12 -1
  23. package/lib/encodings.js.map +1 -1
  24. package/models/components/cobaltstrikeconfig.d.ts +1 -0
  25. package/models/components/cobaltstrikeconfig.d.ts.map +1 -1
  26. package/models/components/cobaltstrikeconfig.js +2 -0
  27. package/models/components/cobaltstrikeconfig.js.map +1 -1
  28. package/models/components/index.d.ts +6 -0
  29. package/models/components/index.d.ts.map +1 -1
  30. package/models/components/index.js +6 -0
  31. package/models/components/index.js.map +1 -1
  32. package/models/components/responseenvelopethreatslistresponse.d.ts +11 -0
  33. package/models/components/responseenvelopethreatslistresponse.d.ts.map +1 -0
  34. package/models/components/responseenvelopethreatslistresponse.js +51 -0
  35. package/models/components/responseenvelopethreatslistresponse.js.map +1 -0
  36. package/models/components/responseenvelopeusercredits.d.ts +11 -0
  37. package/models/components/responseenvelopeusercredits.d.ts.map +1 -0
  38. package/models/components/responseenvelopeusercredits.js +51 -0
  39. package/models/components/responseenvelopeusercredits.js.map +1 -0
  40. package/models/components/threatlistitem.d.ts +42 -0
  41. package/models/components/threatlistitem.d.ts.map +1 -0
  42. package/models/components/threatlistitem.js +66 -0
  43. package/models/components/threatlistitem.js.map +1 -0
  44. package/models/components/threatreference.d.ts +13 -0
  45. package/models/components/threatreference.d.ts.map +1 -0
  46. package/models/components/threatreference.js +50 -0
  47. package/models/components/threatreference.js.map +1 -0
  48. package/models/components/threatslistresponse.d.ts +14 -0
  49. package/models/components/threatslistresponse.d.ts.map +1 -0
  50. package/models/components/threatslistresponse.js +51 -0
  51. package/models/components/threatslistresponse.js.map +1 -0
  52. package/models/components/usercredits.d.ts +17 -0
  53. package/models/components/usercredits.d.ts.map +1 -0
  54. package/models/components/usercredits.js +57 -0
  55. package/models/components/usercredits.js.map +1 -0
  56. package/models/operations/index.d.ts +2 -0
  57. package/models/operations/index.d.ts.map +1 -1
  58. package/models/operations/index.js +2 -0
  59. package/models/operations/index.js.map +1 -1
  60. package/models/operations/v3accountmanagementusercredits.d.ts +14 -0
  61. package/models/operations/v3accountmanagementusercredits.d.ts.map +1 -0
  62. package/models/operations/v3accountmanagementusercredits.js +58 -0
  63. package/models/operations/v3accountmanagementusercredits.js.map +1 -0
  64. package/models/operations/v3globaldatasearchaggregate.d.ts +1 -1
  65. package/models/operations/v3globaldatasearchquery.d.ts +1 -1
  66. package/models/operations/v3threathuntingthreatslist.d.ts +35 -0
  67. package/models/operations/v3threathuntingthreatslist.d.ts.map +1 -0
  68. package/models/operations/v3threathuntingthreatslist.js +71 -0
  69. package/models/operations/v3threathuntingthreatslist.js.map +1 -0
  70. package/package.json +1 -1
  71. package/sdk/accountmanagement.d.ts +8 -1
  72. package/sdk/accountmanagement.d.ts.map +1 -1
  73. package/sdk/accountmanagement.js +11 -1
  74. package/sdk/accountmanagement.js.map +1 -1
  75. package/sdk/threathunting.d.ts +7 -0
  76. package/sdk/threathunting.d.ts.map +1 -1
  77. package/sdk/threathunting.js +10 -0
  78. package/sdk/threathunting.js.map +1 -1
  79. package/src/funcs/accountManagementGetOrganizationCredits.ts +1 -1
  80. package/src/funcs/accountManagementGetUserCredits.ts +163 -0
  81. package/src/funcs/threatHuntingListThreats.ts +187 -0
  82. package/src/lib/config.ts +4 -4
  83. package/src/lib/encodings.ts +17 -3
  84. package/src/models/components/cobaltstrikeconfig.ts +3 -0
  85. package/src/models/components/index.ts +6 -0
  86. package/src/models/components/responseenvelopethreatslistresponse.ts +36 -0
  87. package/src/models/components/responseenvelopeusercredits.ts +32 -0
  88. package/src/models/components/threatlistitem.ts +81 -0
  89. package/src/models/components/threatreference.ts +34 -0
  90. package/src/models/components/threatslistresponse.ts +38 -0
  91. package/src/models/components/usercredits.ts +45 -0
  92. package/src/models/operations/index.ts +2 -0
  93. package/src/models/operations/v3accountmanagementusercredits.ts +41 -0
  94. package/src/models/operations/v3globaldatasearchaggregate.ts +1 -1
  95. package/src/models/operations/v3globaldatasearchquery.ts +1 -1
  96. package/src/models/operations/v3threathuntingthreatslist.ts +86 -0
  97. package/src/sdk/accountmanagement.ts +17 -1
  98. package/src/sdk/threathunting.ts +18 -0
  99. package/src/types/enums.ts +38 -9
  100. package/src/types/index.ts +2 -2
  101. package/src/types/unrecognized.ts +35 -0
  102. package/tsconfig.json +1 -2
  103. package/types/enums.d.ts +8 -11
  104. package/types/enums.d.ts.map +1 -1
  105. package/types/enums.js +59 -3
  106. package/types/enums.js.map +1 -1
  107. package/types/index.d.ts +2 -2
  108. package/types/index.d.ts.map +1 -1
  109. package/types/index.js +16 -3
  110. package/types/index.js.map +1 -1
  111. package/types/unrecognized.d.ts +16 -0
  112. package/types/unrecognized.d.ts.map +1 -0
  113. package/types/unrecognized.js +34 -0
  114. package/types/unrecognized.js.map +1 -0
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v3";
6
+ import { safeParse } from "../../lib/schemas.js";
7
+ import { Result as SafeParseResult } from "../../types/fp.js";
8
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
+
10
+ export type ThreatReference = {
11
+ /**
12
+ * URL reference link for the threat.
13
+ */
14
+ link: string;
15
+ };
16
+
17
+ /** @internal */
18
+ export const ThreatReference$inboundSchema: z.ZodType<
19
+ ThreatReference,
20
+ z.ZodTypeDef,
21
+ unknown
22
+ > = z.object({
23
+ link: z.string(),
24
+ });
25
+
26
+ export function threatReferenceFromJSON(
27
+ jsonString: string,
28
+ ): SafeParseResult<ThreatReference, SDKValidationError> {
29
+ return safeParse(
30
+ jsonString,
31
+ (x) => ThreatReference$inboundSchema.parse(JSON.parse(x)),
32
+ `Failed to parse 'ThreatReference' from JSON`,
33
+ );
34
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v3";
6
+ import { safeParse } from "../../lib/schemas.js";
7
+ import { Result as SafeParseResult } from "../../types/fp.js";
8
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
+ import {
10
+ ThreatListItem,
11
+ ThreatListItem$inboundSchema,
12
+ } from "./threatlistitem.js";
13
+
14
+ export type ThreatsListResponse = {
15
+ /**
16
+ * List of active threats observed on the platform.
17
+ */
18
+ threats: Array<ThreatListItem> | null;
19
+ };
20
+
21
+ /** @internal */
22
+ export const ThreatsListResponse$inboundSchema: z.ZodType<
23
+ ThreatsListResponse,
24
+ z.ZodTypeDef,
25
+ unknown
26
+ > = z.object({
27
+ threats: z.nullable(z.array(ThreatListItem$inboundSchema)),
28
+ });
29
+
30
+ export function threatsListResponseFromJSON(
31
+ jsonString: string,
32
+ ): SafeParseResult<ThreatsListResponse, SDKValidationError> {
33
+ return safeParse(
34
+ jsonString,
35
+ (x) => ThreatsListResponse$inboundSchema.parse(JSON.parse(x)),
36
+ `Failed to parse 'ThreatsListResponse' from JSON`,
37
+ );
38
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v3";
6
+ import { remap as remap$ } from "../../lib/primitives.js";
7
+ import { safeParse } from "../../lib/schemas.js";
8
+ import { Result as SafeParseResult } from "../../types/fp.js";
9
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
10
+
11
+ export type UserCredits = {
12
+ /**
13
+ * The current credit balance for the user.
14
+ */
15
+ balance: number;
16
+ /**
17
+ * The date that the user's credits will be reset.
18
+ */
19
+ resetsAt?: Date | undefined;
20
+ };
21
+
22
+ /** @internal */
23
+ export const UserCredits$inboundSchema: z.ZodType<
24
+ UserCredits,
25
+ z.ZodTypeDef,
26
+ unknown
27
+ > = z.object({
28
+ balance: z.number().int(),
29
+ resets_at: z.string().datetime({ offset: true }).transform(v => new Date(v))
30
+ .optional(),
31
+ }).transform((v) => {
32
+ return remap$(v, {
33
+ "resets_at": "resetsAt",
34
+ });
35
+ });
36
+
37
+ export function userCreditsFromJSON(
38
+ jsonString: string,
39
+ ): SafeParseResult<UserCredits, SDKValidationError> {
40
+ return safeParse(
41
+ jsonString,
42
+ (x) => UserCredits$inboundSchema.parse(JSON.parse(x)),
43
+ `Failed to parse 'UserCredits' from JSON`,
44
+ );
45
+ }
@@ -10,6 +10,7 @@ export * from "./v3accountmanagementorgcreditsusage.js";
10
10
  export * from "./v3accountmanagementorgdetails.js";
11
11
  export * from "./v3accountmanagementremoveorgmember.js";
12
12
  export * from "./v3accountmanagementupdateorgmember.js";
13
+ export * from "./v3accountmanagementusercredits.js";
13
14
  export * from "./v3collectionscrudcreate.js";
14
15
  export * from "./v3collectionscruddelete.js";
15
16
  export * from "./v3collectionscrudget.js";
@@ -35,4 +36,5 @@ export * from "./v3globaldatasearchquery.js";
35
36
  export * from "./v3threathuntinggethostobservationswithcertificate.js";
36
37
  export * from "./v3threathuntingscansdiscovery.js";
37
38
  export * from "./v3threathuntingscansget.js";
39
+ export * from "./v3threathuntingthreatslist.js";
38
40
  export * from "./v3threathuntingvaluecounts.js";
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v3";
6
+ import { remap as remap$ } from "../../lib/primitives.js";
7
+ import { safeParse } from "../../lib/schemas.js";
8
+ import { Result as SafeParseResult } from "../../types/fp.js";
9
+ import * as components from "../components/index.js";
10
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
+
12
+ export type V3AccountmanagementUserCreditsResponse = {
13
+ headers: { [k: string]: Array<string> };
14
+ result: components.ResponseEnvelopeUserCredits;
15
+ };
16
+
17
+ /** @internal */
18
+ export const V3AccountmanagementUserCreditsResponse$inboundSchema: z.ZodType<
19
+ V3AccountmanagementUserCreditsResponse,
20
+ z.ZodTypeDef,
21
+ unknown
22
+ > = z.object({
23
+ Headers: z.record(z.array(z.string())).default({}),
24
+ Result: components.ResponseEnvelopeUserCredits$inboundSchema,
25
+ }).transform((v) => {
26
+ return remap$(v, {
27
+ "Headers": "headers",
28
+ "Result": "result",
29
+ });
30
+ });
31
+
32
+ export function v3AccountmanagementUserCreditsResponseFromJSON(
33
+ jsonString: string,
34
+ ): SafeParseResult<V3AccountmanagementUserCreditsResponse, SDKValidationError> {
35
+ return safeParse(
36
+ jsonString,
37
+ (x) =>
38
+ V3AccountmanagementUserCreditsResponse$inboundSchema.parse(JSON.parse(x)),
39
+ `Failed to parse 'V3AccountmanagementUserCreditsResponse' from JSON`,
40
+ );
41
+ }
@@ -15,7 +15,7 @@ export type V3GlobaldataSearchAggregateGlobals = {
15
15
 
16
16
  export type V3GlobaldataSearchAggregateRequest = {
17
17
  /**
18
- * The ID of a Censys organization to associate the request with. See the [Getting Started docs](https://docs.censys.com/reference/get-started#step-3-find-and-use-your-organization-id-optional) for more information.
18
+ * The ID of a Censys organization to associate the request with. If omitted, the request will be processed using the authenticated user's free wallet where applicable. See the [Getting Started docs](https://docs.censys.com/reference/get-started#step-3-find-and-use-your-organization-id-optional) for more information.
19
19
  */
20
20
  organizationId?: string | undefined;
21
21
  searchAggregateInputBody: components.SearchAggregateInputBody;
@@ -15,7 +15,7 @@ export type V3GlobaldataSearchQueryGlobals = {
15
15
 
16
16
  export type V3GlobaldataSearchQueryRequest = {
17
17
  /**
18
- * The ID of a Censys organization to associate the request with. See the [Getting Started docs](https://docs.censys.com/reference/get-started#step-3-find-and-use-your-organization-id-optional) for more information.
18
+ * The ID of a Censys organization to associate the request with. If omitted, the request will be processed using the authenticated user's free wallet where applicable. See the [Getting Started docs](https://docs.censys.com/reference/get-started#step-3-find-and-use-your-organization-id-optional) for more information.
19
19
  */
20
20
  organizationId?: string | undefined;
21
21
  searchQueryInputBody: components.SearchQueryInputBody;
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v3";
6
+ import { remap as remap$ } from "../../lib/primitives.js";
7
+ import { safeParse } from "../../lib/schemas.js";
8
+ import { Result as SafeParseResult } from "../../types/fp.js";
9
+ import * as components from "../components/index.js";
10
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
+
12
+ export type V3ThreathuntingThreatsListGlobals = {
13
+ organizationId?: string | undefined;
14
+ };
15
+
16
+ export type V3ThreathuntingThreatsListRequest = {
17
+ /**
18
+ * The ID of a Censys organization to associate the request with. See the [Getting Started docs](https://docs.censys.com/reference/get-started#step-3-find-and-use-your-organization-id-optional) for more information.
19
+ */
20
+ organizationId?: string | undefined;
21
+ /**
22
+ * Optional CenQL filter to constrain threats list
23
+ */
24
+ query?: string | undefined;
25
+ };
26
+
27
+ export type V3ThreathuntingThreatsListResponse = {
28
+ headers: { [k: string]: Array<string> };
29
+ result: components.ResponseEnvelopeThreatsListResponse;
30
+ };
31
+
32
+ /** @internal */
33
+ export type V3ThreathuntingThreatsListRequest$Outbound = {
34
+ organization_id?: string | undefined;
35
+ query?: string | undefined;
36
+ };
37
+
38
+ /** @internal */
39
+ export const V3ThreathuntingThreatsListRequest$outboundSchema: z.ZodType<
40
+ V3ThreathuntingThreatsListRequest$Outbound,
41
+ z.ZodTypeDef,
42
+ V3ThreathuntingThreatsListRequest
43
+ > = z.object({
44
+ organizationId: z.string().optional(),
45
+ query: z.string().optional(),
46
+ }).transform((v) => {
47
+ return remap$(v, {
48
+ organizationId: "organization_id",
49
+ });
50
+ });
51
+
52
+ export function v3ThreathuntingThreatsListRequestToJSON(
53
+ v3ThreathuntingThreatsListRequest: V3ThreathuntingThreatsListRequest,
54
+ ): string {
55
+ return JSON.stringify(
56
+ V3ThreathuntingThreatsListRequest$outboundSchema.parse(
57
+ v3ThreathuntingThreatsListRequest,
58
+ ),
59
+ );
60
+ }
61
+
62
+ /** @internal */
63
+ export const V3ThreathuntingThreatsListResponse$inboundSchema: z.ZodType<
64
+ V3ThreathuntingThreatsListResponse,
65
+ z.ZodTypeDef,
66
+ unknown
67
+ > = z.object({
68
+ Headers: z.record(z.array(z.string())).default({}),
69
+ Result: components.ResponseEnvelopeThreatsListResponse$inboundSchema,
70
+ }).transform((v) => {
71
+ return remap$(v, {
72
+ "Headers": "headers",
73
+ "Result": "result",
74
+ });
75
+ });
76
+
77
+ export function v3ThreathuntingThreatsListResponseFromJSON(
78
+ jsonString: string,
79
+ ): SafeParseResult<V3ThreathuntingThreatsListResponse, SDKValidationError> {
80
+ return safeParse(
81
+ jsonString,
82
+ (x) =>
83
+ V3ThreathuntingThreatsListResponse$inboundSchema.parse(JSON.parse(x)),
84
+ `Failed to parse 'V3ThreathuntingThreatsListResponse' from JSON`,
85
+ );
86
+ }
@@ -6,6 +6,7 @@ import { accountManagementGetMemberCreditUsage } from "../funcs/accountManagemen
6
6
  import { accountManagementGetOrganizationCredits } from "../funcs/accountManagementGetOrganizationCredits.js";
7
7
  import { accountManagementGetOrganizationCreditUsage } from "../funcs/accountManagementGetOrganizationCreditUsage.js";
8
8
  import { accountManagementGetOrganizationDetails } from "../funcs/accountManagementGetOrganizationDetails.js";
9
+ import { accountManagementGetUserCredits } from "../funcs/accountManagementGetUserCredits.js";
9
10
  import {
10
11
  accountManagementInviteUserToOrganization,
11
12
  InviteUserToOrganizationAcceptEnum,
@@ -48,7 +49,7 @@ export class AccountManagement extends ClientSDK {
48
49
  }
49
50
 
50
51
  /**
51
- * Get organization credit statistics
52
+ * Get organization credit details
52
53
  *
53
54
  * @remarks
54
55
  * Retrieve credit balance and expiration information for an organization. <br><br>Credits expire 12 months after they are acquired.<br><br>This endpoint does not cost any credits to execute.
@@ -177,4 +178,19 @@ export class AccountManagement extends ClientSDK {
177
178
  options,
178
179
  ));
179
180
  }
181
+
182
+ /**
183
+ * Get Free user credit details
184
+ *
185
+ * @remarks
186
+ * Retrieve your Free user account credit balance and refresh information. To retrieve the credit balance for a Starter or Enterprise account, use the [get organization credit details endpoint](https://docs.censys.com/reference/v3-accountmanagement-org-credits).<br><br>This endpoint does not cost any credits to execute.
187
+ */
188
+ async getUserCredits(
189
+ options?: RequestOptions,
190
+ ): Promise<operations.V3AccountmanagementUserCreditsResponse> {
191
+ return unwrapAsync(accountManagementGetUserCredits(
192
+ this,
193
+ options,
194
+ ));
195
+ }
180
196
  }
@@ -5,6 +5,7 @@
5
5
  import { threatHuntingCreateTrackedScan } from "../funcs/threatHuntingCreateTrackedScan.js";
6
6
  import { threatHuntingGetHostObservationsWithCertificate } from "../funcs/threatHuntingGetHostObservationsWithCertificate.js";
7
7
  import { threatHuntingGetTrackedScanThreatHunting } from "../funcs/threatHuntingGetTrackedScanThreatHunting.js";
8
+ import { threatHuntingListThreats } from "../funcs/threatHuntingListThreats.js";
8
9
  import { threatHuntingValueCounts } from "../funcs/threatHuntingValueCounts.js";
9
10
  import { ClientSDK, RequestOptions } from "../lib/sdks.js";
10
11
  import * as operations from "../models/operations/index.js";
@@ -65,6 +66,23 @@ export class ThreatHunting extends ClientSDK {
65
66
  ));
66
67
  }
67
68
 
69
+ /**
70
+ * List active threats
71
+ *
72
+ * @remarks
73
+ * Retrieve a list of active threats observed by Censys by aggregating threat IDs across hosts and web properties. Threats are active if their fingerprint has been identified on hosts or web properties by Censys scans. This information is also available on the [Explore Threats page in the Platform web UI](https://platform.censys.io/threats).
74
+ */
75
+ async listThreats(
76
+ request: operations.V3ThreathuntingThreatsListRequest,
77
+ options?: RequestOptions,
78
+ ): Promise<operations.V3ThreathuntingThreatsListResponse> {
79
+ return unwrapAsync(threatHuntingListThreats(
80
+ this,
81
+ request,
82
+ options,
83
+ ));
84
+ }
85
+
68
86
  /**
69
87
  * CensEye: Retrieve value counts to discover pivots
70
88
  *
@@ -2,15 +2,44 @@
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
3
  */
4
4
 
5
- declare const __brand: unique symbol;
6
- export type Unrecognized<T> = T & { [__brand]: "unrecognized" };
5
+ import * as z from "zod/v3";
6
+ import { Unrecognized, unrecognized } from "./unrecognized.js";
7
7
 
8
- export function catchUnrecognizedEnum<T>(value: T): Unrecognized<T> {
9
- return value as Unrecognized<T>;
8
+ export type ClosedEnum<T extends Readonly<Record<string, string | number>>> =
9
+ T[keyof T];
10
+ export type OpenEnum<T extends Readonly<Record<string, string | number>>> =
11
+ | T[keyof T]
12
+ | Unrecognized<T[keyof T] extends number ? number : string>;
13
+
14
+ export function inboundSchema<T extends Record<string, string>>(
15
+ enumObj: T,
16
+ ): z.ZodType<OpenEnum<T>, z.ZodTypeDef, unknown> {
17
+ const options = Object.values(enumObj);
18
+ return z.union([
19
+ ...options.map(x => z.literal(x)),
20
+ z.string().transform(x => unrecognized(x)),
21
+ ] as any);
10
22
  }
11
23
 
12
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
13
- export type ClosedEnum<T> = T[keyof T];
14
- export type OpenEnum<T> =
15
- | Prettify<T[keyof T]>
16
- | Unrecognized<T[keyof T] extends number ? number : string>;
24
+ export function inboundSchemaInt<T extends Record<string, number | string>>(
25
+ enumObj: T,
26
+ ): z.ZodType<OpenEnum<T>, z.ZodTypeDef, unknown> {
27
+ // For numeric enums, Object.values returns both numbers and string keys
28
+ const options = Object.values(enumObj).filter(v => typeof v === "number");
29
+ return z.union([
30
+ ...options.map(x => z.literal(x)),
31
+ z.number().int().transform(x => unrecognized(x)),
32
+ ] as any);
33
+ }
34
+
35
+ export function outboundSchema<T extends Record<string, string>>(
36
+ _: T,
37
+ ): z.ZodType<string, z.ZodTypeDef, OpenEnum<T>> {
38
+ return z.string() as any;
39
+ }
40
+
41
+ export function outboundSchemaInt<T extends Record<string, number | string>>(
42
+ _: T,
43
+ ): z.ZodType<number, z.ZodTypeDef, OpenEnum<T>> {
44
+ return z.number().int() as any;
45
+ }
@@ -3,9 +3,9 @@
3
3
  */
4
4
 
5
5
  export { blobLikeSchema, isBlobLike } from "./blobs.js";
6
- export { catchUnrecognizedEnum } from "./enums.js";
7
- export type { ClosedEnum, OpenEnum, Unrecognized } from "./enums.js";
6
+ export type { ClosedEnum, OpenEnum } from "./enums.js";
8
7
  export type { Result } from "./fp.js";
9
8
  export type { PageIterator, Paginator } from "./operations.js";
10
9
  export { createPageIterator } from "./operations.js";
11
10
  export { RFCDate } from "./rfcdate.js";
11
+ export * from "./unrecognized.js";
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ declare const __brand: unique symbol;
6
+ export type Unrecognized<T> = T & { [__brand]: "unrecognized" };
7
+
8
+ function unrecognized<T>(value: T): Unrecognized<T> {
9
+ globalCount++;
10
+ return value as Unrecognized<T>;
11
+ }
12
+
13
+ let globalCount = 0;
14
+ let refCount = 0;
15
+ export function startCountingUnrecognized() {
16
+ refCount++;
17
+ const start = globalCount;
18
+ return {
19
+ /**
20
+ * Ends counting and returns the delta.
21
+ * @param delta - If provided, only this amount is added to the parent counter
22
+ * (used for nested unions where we only want to record the winning option's count).
23
+ * If not provided, records all counts since start().
24
+ */
25
+ end: (delta?: number) => {
26
+ const count = globalCount - start;
27
+ // Reset globalCount back to start, then add only the specified delta
28
+ globalCount = start + (delta ?? count);
29
+ if (--refCount === 0) globalCount = 0;
30
+ return count;
31
+ },
32
+ };
33
+ }
34
+
35
+ export { unrecognized };
package/tsconfig.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "incremental": true,
4
- "tsBuildInfoFile": ".tsbuildinfo",
3
+ "incremental": false,
5
4
  "target": "ES2020",
6
5
  "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
6
  "jsx": "react-jsx",
package/types/enums.d.ts CHANGED
@@ -1,12 +1,9 @@
1
- declare const __brand: unique symbol;
2
- export type Unrecognized<T> = T & {
3
- [__brand]: "unrecognized";
4
- };
5
- export declare function catchUnrecognizedEnum<T>(value: T): Unrecognized<T>;
6
- type Prettify<T> = {
7
- [K in keyof T]: T[K];
8
- } & {};
9
- export type ClosedEnum<T> = T[keyof T];
10
- export type OpenEnum<T> = Prettify<T[keyof T]> | Unrecognized<T[keyof T] extends number ? number : string>;
11
- export {};
1
+ import * as z from "zod/v3";
2
+ import { Unrecognized } from "./unrecognized.js";
3
+ export type ClosedEnum<T extends Readonly<Record<string, string | number>>> = T[keyof T];
4
+ export type OpenEnum<T extends Readonly<Record<string, string | number>>> = T[keyof T] | Unrecognized<T[keyof T] extends number ? number : string>;
5
+ export declare function inboundSchema<T extends Record<string, string>>(enumObj: T): z.ZodType<OpenEnum<T>, z.ZodTypeDef, unknown>;
6
+ export declare function inboundSchemaInt<T extends Record<string, number | string>>(enumObj: T): z.ZodType<OpenEnum<T>, z.ZodTypeDef, unknown>;
7
+ export declare function outboundSchema<T extends Record<string, string>>(_: T): z.ZodType<string, z.ZodTypeDef, OpenEnum<T>>;
8
+ export declare function outboundSchemaInt<T extends Record<string, number | string>>(_: T): z.ZodType<number, z.ZodTypeDef, OpenEnum<T>>;
12
9
  //# sourceMappingURL=enums.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/types/enums.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,CAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAEhE,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAElE;AAED,KAAK,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC;AACjD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AACvC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAClB,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACpB,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/types/enums.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAE/D,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,IACxE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AACb,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,IACpE,CAAC,CAAC,MAAM,CAAC,CAAC,GACV,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;AAE9D,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5D,OAAO,EAAE,CAAC,GACT,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAM/C;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACxE,OAAO,EAAE,CAAC,GACT,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAO/C;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7D,CAAC,EAAE,CAAC,GACH,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAE9C;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACzE,CAAC,EAAE,CAAC,GACH,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAE9C"}
package/types/enums.js CHANGED
@@ -2,9 +2,65 @@
2
2
  /*
3
3
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
4
4
  */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.catchUnrecognizedEnum = catchUnrecognizedEnum;
7
- function catchUnrecognizedEnum(value) {
8
- return value;
39
+ exports.inboundSchema = inboundSchema;
40
+ exports.inboundSchemaInt = inboundSchemaInt;
41
+ exports.outboundSchema = outboundSchema;
42
+ exports.outboundSchemaInt = outboundSchemaInt;
43
+ const z = __importStar(require("zod/v3"));
44
+ const unrecognized_js_1 = require("./unrecognized.js");
45
+ function inboundSchema(enumObj) {
46
+ const options = Object.values(enumObj);
47
+ return z.union([
48
+ ...options.map(x => z.literal(x)),
49
+ z.string().transform(x => (0, unrecognized_js_1.unrecognized)(x)),
50
+ ]);
51
+ }
52
+ function inboundSchemaInt(enumObj) {
53
+ // For numeric enums, Object.values returns both numbers and string keys
54
+ const options = Object.values(enumObj).filter(v => typeof v === "number");
55
+ return z.union([
56
+ ...options.map(x => z.literal(x)),
57
+ z.number().int().transform(x => (0, unrecognized_js_1.unrecognized)(x)),
58
+ ]);
59
+ }
60
+ function outboundSchema(_) {
61
+ return z.string();
62
+ }
63
+ function outboundSchemaInt(_) {
64
+ return z.number().int();
9
65
  }
10
66
  //# sourceMappingURL=enums.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/types/enums.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH,sDAEC;AAFD,SAAgB,qBAAqB,CAAI,KAAQ;IAC/C,OAAO,KAAwB,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/types/enums.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWH,sCAQC;AAED,4CASC;AAED,wCAIC;AAED,8CAIC;AAxCD,0CAA4B;AAC5B,uDAA+D;AAQ/D,SAAgB,aAAa,CAC3B,OAAU;IAEV,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,CAAC,CAAC,KAAK,CAAC;QACb,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,8BAAY,EAAC,CAAC,CAAC,CAAC;KACpC,CAAC,CAAC;AACZ,CAAC;AAED,SAAgB,gBAAgB,CAC9B,OAAU;IAEV,wEAAwE;IACxE,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IAC1E,OAAO,CAAC,CAAC,KAAK,CAAC;QACb,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,8BAAY,EAAC,CAAC,CAAC,CAAC;KAC1C,CAAC,CAAC;AACZ,CAAC;AAED,SAAgB,cAAc,CAC5B,CAAI;IAEJ,OAAO,CAAC,CAAC,MAAM,EAAS,CAAC;AAC3B,CAAC;AAED,SAAgB,iBAAiB,CAC/B,CAAI;IAEJ,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAS,CAAC;AACjC,CAAC"}
package/types/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { blobLikeSchema, isBlobLike } from "./blobs.js";
2
- export { catchUnrecognizedEnum } from "./enums.js";
3
- export type { ClosedEnum, OpenEnum, Unrecognized } from "./enums.js";
2
+ export type { ClosedEnum, OpenEnum } from "./enums.js";
4
3
  export type { Result } from "./fp.js";
5
4
  export type { PageIterator, Paginator } from "./operations.js";
6
5
  export { createPageIterator } from "./operations.js";
7
6
  export { RFCDate } from "./rfcdate.js";
7
+ export * from "./unrecognized.js";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxD,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACvD,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,cAAc,mBAAmB,CAAC"}
package/types/index.js CHANGED
@@ -2,15 +2,28 @@
2
2
  /*
3
3
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
4
4
  */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
5
19
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RFCDate = exports.createPageIterator = exports.catchUnrecognizedEnum = exports.isBlobLike = exports.blobLikeSchema = void 0;
20
+ exports.RFCDate = exports.createPageIterator = exports.isBlobLike = exports.blobLikeSchema = void 0;
7
21
  var blobs_js_1 = require("./blobs.js");
8
22
  Object.defineProperty(exports, "blobLikeSchema", { enumerable: true, get: function () { return blobs_js_1.blobLikeSchema; } });
9
23
  Object.defineProperty(exports, "isBlobLike", { enumerable: true, get: function () { return blobs_js_1.isBlobLike; } });
10
- var enums_js_1 = require("./enums.js");
11
- Object.defineProperty(exports, "catchUnrecognizedEnum", { enumerable: true, get: function () { return enums_js_1.catchUnrecognizedEnum; } });
12
24
  var operations_js_1 = require("./operations.js");
13
25
  Object.defineProperty(exports, "createPageIterator", { enumerable: true, get: function () { return operations_js_1.createPageIterator; } });
14
26
  var rfcdate_js_1 = require("./rfcdate.js");
15
27
  Object.defineProperty(exports, "RFCDate", { enumerable: true, get: function () { return rfcdate_js_1.RFCDate; } });
28
+ __exportStar(require("./unrecognized.js"), exports);
16
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,uCAAwD;AAA/C,0GAAA,cAAc,OAAA;AAAE,sGAAA,UAAU,OAAA;AACnC,uCAAmD;AAA1C,iHAAA,qBAAqB,OAAA;AAI9B,iDAAqD;AAA5C,mHAAA,kBAAkB,OAAA;AAC3B,2CAAuC;AAA9B,qGAAA,OAAO,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,uCAAwD;AAA/C,0GAAA,cAAc,OAAA;AAAE,sGAAA,UAAU,OAAA;AAInC,iDAAqD;AAA5C,mHAAA,kBAAkB,OAAA;AAC3B,2CAAuC;AAA9B,qGAAA,OAAO,OAAA;AAChB,oDAAkC"}
@@ -0,0 +1,16 @@
1
+ declare const __brand: unique symbol;
2
+ export type Unrecognized<T> = T & {
3
+ [__brand]: "unrecognized";
4
+ };
5
+ declare function unrecognized<T>(value: T): Unrecognized<T>;
6
+ export declare function startCountingUnrecognized(): {
7
+ /**
8
+ * Ends counting and returns the delta.
9
+ * @param delta - If provided, only this amount is added to the parent counter
10
+ * (used for nested unions where we only want to record the winning option's count).
11
+ * If not provided, records all counts since start().
12
+ */
13
+ end: (delta?: number) => number;
14
+ };
15
+ export { unrecognized };
16
+ //# sourceMappingURL=unrecognized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unrecognized.d.ts","sourceRoot":"","sources":["../src/types/unrecognized.ts"],"names":[],"mappings":"AAIA,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,CAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,CAAC;AAEhE,iBAAS,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAGlD;AAID,wBAAgB,yBAAyB;IAIrC;;;;;OAKG;kBACW,MAAM;EAQvB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}