Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+112
-25
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import {
|
||||
ANALYTICS_COOKIE_ID_MAX_LENGTH,
|
||||
ANALYTICS_URL_MAX_LENGTH,
|
||||
API_KEY_MAX_LENGTH,
|
||||
parseAnalyticsEventPayload,
|
||||
parseAnalyticsPageViewPayload,
|
||||
parseApiKeyValidationPayload,
|
||||
@@ -41,7 +44,15 @@ describe("request schema validators", () => {
|
||||
expectValidationError(parseLoginCredentialsPayload(null), { reason: "body_invalid", bodyType: "login_credentials" });
|
||||
expectValidationError(parseLoginCredentialsPayload([]), { reason: "body_invalid", bodyType: "login_credentials" });
|
||||
expectValidationError(parseLoginCredentialsPayload({ password: "present" }), { reason: "field_required", field: "email" });
|
||||
expectValidationError(parseLoginCredentialsPayload({ email: 123, password: secretValue }), { reason: "field_type_invalid", field: "email", expected: "string" });
|
||||
expectValidationError(parseLoginCredentialsPayload({ email: 123, password: secretValue }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "email",
|
||||
expected: "string",
|
||||
});
|
||||
expectValidationError(parseLoginCredentialsPayload({ email: "user@example.com", password: "x".repeat(1_025) }), {
|
||||
reason: "field_value_invalid",
|
||||
field: "password",
|
||||
});
|
||||
});
|
||||
|
||||
test("accepts API-key validation bodies without leaking invalid secret-like values", () => {
|
||||
@@ -49,10 +60,14 @@ describe("request schema validators", () => {
|
||||
expect(parseApiKeyValidationPayload({})).toEqual({ ok: true, value: {} });
|
||||
|
||||
expectErrorWithoutSecret(parseApiKeyValidationPayload({ apiKey: { plaintext: secretValue } }));
|
||||
expectValidationError(parseApiKeyValidationPayload({ apiKey: "k".repeat(API_KEY_MAX_LENGTH + 1) }), {
|
||||
reason: "field_value_invalid",
|
||||
field: "apiKey",
|
||||
});
|
||||
expectValidationError(parseApiKeyValidationPayload(null), { reason: "body_invalid", bodyType: "api_key_validation" });
|
||||
});
|
||||
|
||||
test("accepts valid analytics events with optional string fields", () => {
|
||||
test("accepts valid anonymous analytics events with optional string fields", () => {
|
||||
expect(
|
||||
parseAnalyticsEventPayload({
|
||||
action: "clicked",
|
||||
@@ -63,11 +78,11 @@ describe("request schema validators", () => {
|
||||
route: "/page",
|
||||
analytics: {
|
||||
userAnalyticsId: "visitor-1",
|
||||
portalId: "portal-1",
|
||||
portalUserId: "portal-user-1",
|
||||
referrer: "https://referrer.test",
|
||||
referrer: { http: "https://referrer.test/path?token=redacted", source: "newsletter" },
|
||||
userAgent: { type: "desktop", os: { family: "Linux" }, browser: { name: "Firefox" } },
|
||||
},
|
||||
}),
|
||||
ignored: "must-not-survive-validation",
|
||||
})
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
@@ -79,9 +94,8 @@ describe("request schema validators", () => {
|
||||
route: "/page",
|
||||
analytics: {
|
||||
userAnalyticsId: "visitor-1",
|
||||
portalId: "portal-1",
|
||||
portalUserId: "portal-user-1",
|
||||
referrer: "https://referrer.test",
|
||||
referrer: { http: "https://referrer.test/path?token=redacted", source: "newsletter" },
|
||||
userAgent: { type: "desktop", os: { family: "Linux" }, browser: { name: "Firefox" } },
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -89,10 +103,49 @@ describe("request schema validators", () => {
|
||||
|
||||
test("rejects malformed analytics event bodies and analytics fields without echoing values", () => {
|
||||
expectValidationError(parseAnalyticsEventPayload([]), { reason: "body_invalid", bodyType: "analytics_event" });
|
||||
expectValidationError(parseAnalyticsEventPayload({ category: "featureFlag", analytics: { userAnalyticsId: "visitor-1" } }), { reason: "field_required", field: "action" });
|
||||
expectValidationError(parseAnalyticsEventPayload({ action: "clicked", category: 42, analytics: { userAnalyticsId: "visitor-1" } }), { reason: "field_type_invalid", field: "category", expected: "string" });
|
||||
expectValidationError(parseAnalyticsEventPayload({ action: "clicked", category: "featureFlag", analytics: null }), { reason: "field_type_invalid", field: "analytics", expected: "object" });
|
||||
expectErrorWithoutSecret(parseAnalyticsEventPayload({ action: "clicked", category: "featureFlag", analytics: { userAnalyticsId: { token: secretValue } } }));
|
||||
expectValidationError(parseAnalyticsEventPayload({ category: "featureFlag", analytics: { userAnalyticsId: "visitor-1" } }), {
|
||||
reason: "field_required",
|
||||
field: "action",
|
||||
});
|
||||
expectValidationError(parseAnalyticsEventPayload({ action: "clicked", category: 42, analytics: { userAnalyticsId: "visitor-1" } }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "category",
|
||||
expected: "string",
|
||||
});
|
||||
expectValidationError(parseAnalyticsEventPayload({ action: "clicked", category: "featureFlag", analytics: null }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "analytics",
|
||||
expected: "object",
|
||||
});
|
||||
expectErrorWithoutSecret(
|
||||
parseAnalyticsEventPayload({ action: "clicked", category: "featureFlag", analytics: { userAnalyticsId: { token: secretValue } } })
|
||||
);
|
||||
expectValidationError(
|
||||
parseAnalyticsEventPayload({
|
||||
action: "clicked",
|
||||
category: "featureFlag",
|
||||
analytics: { userAnalyticsId: "v".repeat(ANALYTICS_COOKIE_ID_MAX_LENGTH + 1) },
|
||||
}),
|
||||
{ reason: "field_value_invalid", field: "analytics.userAnalyticsId" }
|
||||
);
|
||||
expectValidationError(
|
||||
parseAnalyticsEventPayload({
|
||||
action: "clicked",
|
||||
category: "featureFlag",
|
||||
url: "u".repeat(ANALYTICS_URL_MAX_LENGTH + 1),
|
||||
analytics: { userAnalyticsId: "visitor-1" },
|
||||
}),
|
||||
{ reason: "field_value_invalid", field: "url" }
|
||||
);
|
||||
});
|
||||
|
||||
test.each(["userId", "portalId", "portalUserId"])("rejects browser-supplied analytics identity field %s", (field) => {
|
||||
const result = parseAnalyticsEventPayload({
|
||||
action: "clicked",
|
||||
category: "button",
|
||||
analytics: { userAnalyticsId: "visitor-1", [field]: secretValue },
|
||||
});
|
||||
expectErrorWithoutSecret(result);
|
||||
});
|
||||
|
||||
test("accepts and rejects analytics page-view payloads", () => {
|
||||
@@ -100,12 +153,16 @@ describe("request schema validators", () => {
|
||||
ok: true,
|
||||
value: { url: "https://example.test", analytics: { userAnalyticsId: "visitor-1" } },
|
||||
});
|
||||
expect(parseAnalyticsPageViewPayload({ url: "https://example.test", route: "/home", analytics: { userAnalyticsId: "visitor-1", portalId: null } })).toEqual({
|
||||
expect(parseAnalyticsPageViewPayload({ url: "https://example.test", route: "/home", analytics: { userAnalyticsId: "visitor-1" } })).toEqual({
|
||||
ok: true,
|
||||
value: { url: "https://example.test", route: "/home", analytics: { userAnalyticsId: "visitor-1", portalId: null } },
|
||||
value: { url: "https://example.test", route: "/home", analytics: { userAnalyticsId: "visitor-1" } },
|
||||
});
|
||||
expectValidationError(parseAnalyticsPageViewPayload(null), { reason: "body_invalid", bodyType: "analytics_page_view" });
|
||||
expectValidationError(parseAnalyticsPageViewPayload({ url: 123, analytics: { userAnalyticsId: "visitor-1" } }), { reason: "field_type_invalid", field: "url", expected: "string" });
|
||||
expectValidationError(parseAnalyticsPageViewPayload({ url: 123, analytics: { userAnalyticsId: "visitor-1" } }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "url",
|
||||
expected: "string",
|
||||
});
|
||||
expectErrorWithoutSecret(parseAnalyticsPageViewPayload({ url: "https://example.test", analytics: { userAnalyticsId: secretValue, portalId: 123 } }));
|
||||
});
|
||||
|
||||
@@ -116,7 +173,11 @@ describe("request schema validators", () => {
|
||||
});
|
||||
expectValidationError(parseRelationshipCreatePayload(null), { reason: "body_invalid", bodyType: "relationship" });
|
||||
expectValidationError(parseRelationshipCreatePayload({ child: "row-child" }), { reason: "field_required", field: "parent" });
|
||||
expectValidationError(parseRelationshipCreatePayload({ parent: secretValue, child: 7 }), { reason: "field_type_invalid", field: "child", expected: "string" });
|
||||
expectValidationError(parseRelationshipCreatePayload({ parent: secretValue, child: 7 }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "child",
|
||||
expected: "string",
|
||||
});
|
||||
});
|
||||
|
||||
test("entity row bodies only require non-array JSON objects and preserve arbitrary data", () => {
|
||||
@@ -136,7 +197,7 @@ describe("request schema validators", () => {
|
||||
lastName: "Lovelace",
|
||||
type: 2,
|
||||
expiresAt: "2026-06-01T12:00:00.000Z",
|
||||
}),
|
||||
})
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
@@ -152,9 +213,20 @@ describe("request schema validators", () => {
|
||||
test("rejects malformed workspace invite create payloads without echoing values", () => {
|
||||
expectValidationError(parseWorkspaceInviteCreatePayload(null), { reason: "body_invalid", bodyType: "workspace_invite_create" });
|
||||
expectValidationError(parseWorkspaceInviteCreatePayload({ firstName: "Ada", lastName: "Lovelace", type: 2 }), { reason: "field_required", field: "email" });
|
||||
expectValidationError(parseWorkspaceInviteCreatePayload({ email: 7, firstName: "Ada", lastName: "Lovelace", type: 2 }), { reason: "field_type_invalid", field: "email", expected: "string" });
|
||||
expectValidationError(parseWorkspaceInviteCreatePayload({ email: "member@example.com", firstName: secretValue, lastName: "Lovelace", type: "2" }), { reason: "field_type_invalid", field: "type", expected: "number" });
|
||||
expectValidationError(parseWorkspaceInviteCreatePayload({ email: "member@example.com", firstName: "Ada", lastName: "Lovelace", type: 2, expiresAt: "tomorrow" }), { reason: "field_value_invalid", field: "expiresAt", expected: "datetime" });
|
||||
expectValidationError(parseWorkspaceInviteCreatePayload({ email: 7, firstName: "Ada", lastName: "Lovelace", type: 2 }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "email",
|
||||
expected: "string",
|
||||
});
|
||||
expectValidationError(parseWorkspaceInviteCreatePayload({ email: "member@example.com", firstName: secretValue, lastName: "Lovelace", type: "2" }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "type",
|
||||
expected: "number",
|
||||
});
|
||||
expectValidationError(
|
||||
parseWorkspaceInviteCreatePayload({ email: "member@example.com", firstName: "Ada", lastName: "Lovelace", type: 2, expiresAt: "tomorrow" }),
|
||||
{ reason: "field_value_invalid", field: "expiresAt", expected: "datetime" }
|
||||
);
|
||||
expectErrorWithoutSecret(parseWorkspaceInviteCreatePayload({ email: "member@example.com", firstName: secretValue, lastName: 99, type: 2 }));
|
||||
});
|
||||
|
||||
@@ -162,7 +234,11 @@ describe("request schema validators", () => {
|
||||
expect(parseWorkspaceInviteAcceptPayload({ token: secretValue, userId: "user_1" })).toEqual({ ok: true, value: { token: secretValue, userId: "user_1" } });
|
||||
expectValidationError(parseWorkspaceInviteAcceptPayload(null), { reason: "body_invalid", bodyType: "workspace_invite_accept" });
|
||||
expectValidationError(parseWorkspaceInviteAcceptPayload({ userId: "user_1" }), { reason: "field_required", field: "token" });
|
||||
expectValidationError(parseWorkspaceInviteAcceptPayload({ token: { plaintext: secretValue }, userId: "user_1" }), { reason: "field_type_invalid", field: "token", expected: "string" });
|
||||
expectValidationError(parseWorkspaceInviteAcceptPayload({ token: { plaintext: secretValue }, userId: "user_1" }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "token",
|
||||
expected: "string",
|
||||
});
|
||||
expectErrorWithoutSecret(parseWorkspaceInviteAcceptPayload({ token: secretValue, userId: 123 }));
|
||||
});
|
||||
|
||||
@@ -173,16 +249,27 @@ describe("request schema validators", () => {
|
||||
});
|
||||
expect(parseWorkspaceInviteRevokePayload({})).toEqual({ ok: true, value: {} });
|
||||
expectValidationError(parseWorkspaceInviteRevokePayload([]), { reason: "body_invalid", bodyType: "workspace_invite_revoke" });
|
||||
expectValidationError(parseWorkspaceInviteRevokePayload({ reason: 404, revokedByUserId: secretValue }), { reason: "field_type_invalid", field: "reason", expected: "string" });
|
||||
expectValidationError(parseWorkspaceInviteRevokePayload({ reason: 404, revokedByUserId: secretValue }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "reason",
|
||||
expected: "string",
|
||||
});
|
||||
expectErrorWithoutSecret(parseWorkspaceInviteRevokePayload({ reason: "duplicate", revokedByUserId: { token: secretValue } }));
|
||||
});
|
||||
|
||||
test("accepts and rejects workspace context revalidation payloads without echoing secret-like values", () => {
|
||||
expect(parseWorkspaceContextRevalidationPayload({ userId: "user_1" })).toEqual({ ok: true, value: { userId: "user_1" } });
|
||||
expect(parseWorkspaceContextRevalidationPayload({ userId: "user_1", providerSlug: "okta" })).toEqual({ ok: true, value: { userId: "user_1", providerSlug: "okta" } });
|
||||
expect(parseWorkspaceContextRevalidationPayload({ userId: "user_1", providerSlug: "okta" })).toEqual({
|
||||
ok: true,
|
||||
value: { userId: "user_1", providerSlug: "okta" },
|
||||
});
|
||||
expectValidationError(parseWorkspaceContextRevalidationPayload(null), { reason: "body_invalid", bodyType: "workspace_context_revalidation" });
|
||||
expectValidationError(parseWorkspaceContextRevalidationPayload({ providerSlug: "okta" }), { reason: "field_required", field: "userId" });
|
||||
expectValidationError(parseWorkspaceContextRevalidationPayload({ userId: 123, providerSlug: secretValue }), { reason: "field_type_invalid", field: "userId", expected: "string" });
|
||||
expectValidationError(parseWorkspaceContextRevalidationPayload({ userId: 123, providerSlug: secretValue }), {
|
||||
reason: "field_type_invalid",
|
||||
field: "userId",
|
||||
expected: "string",
|
||||
});
|
||||
expectErrorWithoutSecret(parseWorkspaceContextRevalidationPayload({ userId: "user_1", providerSlug: { secret: secretValue } }));
|
||||
});
|
||||
});
|
||||
+64
-23
@@ -10,6 +10,17 @@ export type RequestValidationError = {
|
||||
|
||||
export type ParseResult<T> = { ok: true; value: T } | { ok: false; error: RequestValidationError };
|
||||
|
||||
export const LOGIN_PASSWORD_MAX_LENGTH = 1_024;
|
||||
export const EMAIL_MAX_LENGTH = 320;
|
||||
export const API_KEY_MAX_LENGTH = 4_096;
|
||||
export const ANALYTICS_IDENTIFIER_MAX_LENGTH = 512;
|
||||
export const ANALYTICS_COOKIE_ID_MAX_LENGTH = 191;
|
||||
export const ANALYTICS_NAME_MAX_LENGTH = 128;
|
||||
export const ANALYTICS_LABEL_MAX_LENGTH = 512;
|
||||
export const ANALYTICS_VALUE_MAX_LENGTH = 2_048;
|
||||
export const ANALYTICS_URL_MAX_LENGTH = 4_096;
|
||||
export const ANALYTICS_ROUTE_MAX_LENGTH = 1_024;
|
||||
|
||||
export type LoginCredentialsPayload = {
|
||||
email: string;
|
||||
password: string;
|
||||
@@ -21,9 +32,21 @@ export type ApiKeyValidationPayload = {
|
||||
|
||||
export type AnalyticsInfoPayload = {
|
||||
userAnalyticsId: string;
|
||||
portalId?: string | null;
|
||||
portalUserId?: string | null;
|
||||
[key: string]: unknown;
|
||||
userAgent?: {
|
||||
type?: string;
|
||||
os: { family?: string; version?: string };
|
||||
browser: { name?: string; version?: string };
|
||||
};
|
||||
referrer?: {
|
||||
via?: string | null;
|
||||
http?: string;
|
||||
source?: string;
|
||||
utm_medium?: string;
|
||||
utm_campaign?: string;
|
||||
utm_content?: string;
|
||||
utm_term?: string;
|
||||
};
|
||||
region?: { country?: string; city?: string };
|
||||
};
|
||||
|
||||
export type AnalyticsEventPayload = {
|
||||
@@ -73,49 +96,67 @@ export type WorkspaceContextRevalidationPayload = {
|
||||
const jsonObjectSchema = z.object({}).passthrough();
|
||||
const requiredString = z.string().min(1);
|
||||
const optionalString = z.string().optional();
|
||||
const optionalNullableString = z.string().nullable().optional();
|
||||
const optionalDateTimeString = z.string().datetime().optional();
|
||||
|
||||
const optionalBoundedAnalyticsString = z.string().max(ANALYTICS_IDENTIFIER_MAX_LENGTH).optional();
|
||||
const optionalNullableBoundedAnalyticsString = z.string().max(ANALYTICS_IDENTIFIER_MAX_LENGTH).nullable().optional();
|
||||
const analyticsInfoSchema = z
|
||||
.object({
|
||||
userAnalyticsId: requiredString,
|
||||
portalId: optionalNullableString,
|
||||
portalUserId: optionalNullableString,
|
||||
userAnalyticsId: requiredString.trim().max(ANALYTICS_COOKIE_ID_MAX_LENGTH),
|
||||
userAgent: z
|
||||
.object({
|
||||
type: optionalBoundedAnalyticsString,
|
||||
os: z.object({ family: optionalBoundedAnalyticsString, version: optionalBoundedAnalyticsString }),
|
||||
browser: z.object({ name: optionalBoundedAnalyticsString, version: optionalBoundedAnalyticsString }),
|
||||
})
|
||||
.optional(),
|
||||
referrer: z
|
||||
.object({
|
||||
via: optionalNullableBoundedAnalyticsString,
|
||||
http: z.string().max(ANALYTICS_URL_MAX_LENGTH).optional(),
|
||||
source: optionalBoundedAnalyticsString,
|
||||
utm_medium: optionalBoundedAnalyticsString,
|
||||
utm_campaign: optionalBoundedAnalyticsString,
|
||||
utm_content: optionalBoundedAnalyticsString,
|
||||
utm_term: optionalBoundedAnalyticsString,
|
||||
})
|
||||
.optional(),
|
||||
region: z.object({ country: optionalBoundedAnalyticsString, city: optionalBoundedAnalyticsString }).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
.strict();
|
||||
|
||||
const loginCredentialsSchema = z
|
||||
.object({
|
||||
email: requiredString,
|
||||
password: requiredString,
|
||||
email: requiredString.max(EMAIL_MAX_LENGTH),
|
||||
password: requiredString.max(LOGIN_PASSWORD_MAX_LENGTH),
|
||||
})
|
||||
.passthrough();
|
||||
.strip();
|
||||
|
||||
const apiKeyValidationSchema = z
|
||||
.object({
|
||||
apiKey: optionalString,
|
||||
apiKey: z.string().max(API_KEY_MAX_LENGTH).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
.strip();
|
||||
|
||||
const analyticsEventSchema = z
|
||||
.object({
|
||||
action: requiredString,
|
||||
category: requiredString,
|
||||
label: optionalString,
|
||||
value: optionalString,
|
||||
url: optionalString,
|
||||
route: optionalString,
|
||||
action: requiredString.max(ANALYTICS_NAME_MAX_LENGTH),
|
||||
category: requiredString.max(ANALYTICS_NAME_MAX_LENGTH),
|
||||
label: z.string().max(ANALYTICS_LABEL_MAX_LENGTH).optional(),
|
||||
value: z.string().max(ANALYTICS_VALUE_MAX_LENGTH).optional(),
|
||||
url: z.string().max(ANALYTICS_URL_MAX_LENGTH).optional(),
|
||||
route: z.string().max(ANALYTICS_ROUTE_MAX_LENGTH).optional(),
|
||||
analytics: analyticsInfoSchema,
|
||||
})
|
||||
.passthrough();
|
||||
.strip();
|
||||
|
||||
const analyticsPageViewSchema = z
|
||||
.object({
|
||||
url: requiredString,
|
||||
route: optionalString,
|
||||
url: requiredString.max(ANALYTICS_URL_MAX_LENGTH),
|
||||
route: z.string().max(ANALYTICS_ROUTE_MAX_LENGTH).optional(),
|
||||
analytics: analyticsInfoSchema,
|
||||
})
|
||||
.passthrough();
|
||||
.strip();
|
||||
|
||||
const relationshipCreateSchema = z
|
||||
.object({
|
||||
|
||||
Reference in new issue
Block a user