Skip to content
32 changes: 31 additions & 1 deletion types/aws-lambda/test/cognito-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
DefineAuthChallengeTriggerEvent,
DefineAuthChallengeTriggerHandler,
Handler,
InboundFederationTriggerEvent,
InboundFederationTriggerHandler,
PostAuthenticationTriggerEvent,
PostAuthenticationTriggerHandler,
PostConfirmationTriggerEvent,
Expand Down Expand Up @@ -42,7 +44,8 @@ type CognitoTriggerEvent =
| PreTokenGenerationV3TriggerEvent
| UserMigrationTriggerEvent
| CustomMessageTriggerEvent
| CustomEmailSenderTriggerEvent;
| CustomEmailSenderTriggerEvent
| InboundFederationTriggerEvent;

const baseTest: Handler<CognitoTriggerEvent> = async (event: CognitoTriggerEvent, _, callback) => {
str = event.version;
Expand Down Expand Up @@ -399,3 +402,30 @@ const customSmsSender: CustomSMSSenderTriggerHandler = async (event, _, callback
triggerSource === "CustomSMSSender_SignUp";
triggerSource === "CustomSMSSender_Authentication";
};

const inboundFederation: InboundFederationTriggerHandler = async (event, _, callback) => {
const { request, response, triggerSource } = event;

str = request.providerName;
str = request.providerType;
request.providerType === "OIDC";
request.providerType === "SAML";
request.providerType === "Facebook";
request.providerType === "Google";
request.providerType === "SignInWithApple";
request.providerType === "LoginWithAmazon";

objectOrUndefined = request.attributes.tokenResponse;
objectOrUndefined = request.attributes.idToken;
objectOrUndefined = request.attributes.userInfo;
objectOrUndefined = request.attributes.samlResponse;
strOrUndefined = request.attributes.idToken?.["email"];
strOrUndefined = request.attributes.samlResponse?.["given_name"];

obj = response.userAttributesToMap;
str = response.userAttributesToMap["email"];
response.userAttributesToMap = {};
response.userAttributesToMap = { email: "user@example.com", given_name: "Jane" };

triggerSource === "InboundFederation_ExternalProvider";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Handler } from "../../handler";
import { BaseTriggerEvent, StringMap } from "./_common";

export type InboundFederationProviderType =
| "OIDC"
| "SAML"
| "Facebook"
| "Google"
| "SignInWithApple"
| "LoginWithAmazon";

/**
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-inbound-federation.html
*/
export interface InboundFederationTriggerEvent extends BaseTriggerEvent<"InboundFederation_ExternalProvider"> {
request: {
providerName: string;
providerType: InboundFederationProviderType;
attributes: {
/** OAuth token response. Present for OIDC and social providers. */
tokenResponse?: StringMap | undefined;
/** Decoded JWT claims. Present for OIDC and social providers. */
idToken?: StringMap | undefined;
/** Extended profile info. Present for OIDC and social providers. */
userInfo?: StringMap | undefined;
/** SAML assertion attributes. Present for SAML providers. */
samlResponse?: StringMap | undefined;
};
};
response: {
/**
* User attributes to apply to the user profile.
* All attributes to be retained must be included; omitted attributes are dropped.
* Return an empty object `{}` to retain all original attributes unchanged.
*/
userAttributesToMap: StringMap;
};
}

export type InboundFederationTriggerHandler = Handler<InboundFederationTriggerEvent>;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export interface CognitoUserPoolTriggerEvent {
| "TokenGeneration_RefreshTokens"
| "TokenGeneration_ClientCredentials"
| "UserMigration_Authentication"
| "UserMigration_ForgotPassword";
| "UserMigration_ForgotPassword"
| "InboundFederation_ExternalProvider";
region: string;
userPoolId: string;
userName?: string | undefined;
Expand Down Expand Up @@ -119,6 +120,7 @@ export * from "./custom-email-sender";
export * from "./custom-message";
export * from "./custom-sms-sender";
export * from "./define-auth-challenge";
export * from "./inbound-federation";
export * from "./post-authentication";
export * from "./post-confirmation";
export * from "./pre-authentication";
Expand Down
2 changes: 1 addition & 1 deletion types/dagre/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export namespace graphlib {
setParent(childName: string, parentName: string): void;
sinks(): string[];
sources(): string[];
successors(name: string): Array<Node<T>> | undefined;
successors(name: string): string[] | undefined;
}

namespace json {
Expand Down
2 changes: 1 addition & 1 deletion types/data-urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"https://github.com/jsdom/data-urls#readme"
],
"dependencies": {
"@types/whatwg-mimetype": "*",
"@types/whatwg-mimetype": "<=3.0.0",
"@types/whatwg-url": "*"
},
"devDependencies": {
Expand Down
31 changes: 31 additions & 0 deletions types/hafas-client/retry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Profile } from ".";

/**
* Retry options.
*
* Further opts could be used. Check {@link https://github.com/sindresorhus/p-retry | p-retry} for more info.
*/
export interface RetryOpts {
/**
* The maximum amount of times to retry the operation.
* @default 3
*/
retries?: number;
/**
* The exponential factor to use.
* @default 3
*/
factor?: number;
/**
* The number of milliseconds before starting the first retry.
* @default 5000
*/
minTimeout?: number;
}

/**
* Use {@link Profile} opt-in for retrying failed requests to the endpoint.
* @param profile - The base {@link Profile}
* @param retryOpts - The {@link RetryOpts}
*/
export function withRetrying(profile: Profile, retryOpts?: RetryOpts): Profile;
9 changes: 9 additions & 0 deletions types/hafas-client/throttle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Profile } from ".";

/**
* Use {@link Profile} opt-in for throttling requests to the endpoint.
* @param profile - The base {@link Profile}
* @param [limit=5] - The maximum number of calls within an {@link interval}.
* @param [interval=1000] - The timespan for {@link limit} in milliseconds.
*/
export function withThrottling(profile: Profile, limit?: number, interval?: number): Profile;
2 changes: 2 additions & 0 deletions types/hafas-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
},
"files": [
"index.d.ts",
"throttle.d.ts",
"retry.d.ts",
"hafas-client-tests.ts"
]
}
7 changes: 1 addition & 6 deletions types/node/process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,7 @@ declare module "node:process" {
isTTY?: true | undefined;
}
// Alias for compatibility
interface ProcessEnv extends Dict<string> {
/**
* Can be used to change the default timezone at runtime
*/
TZ?: string | undefined;
}
interface ProcessEnv extends Dict<string> {}
interface HRTime {
/**
* This is the legacy version of {@link process.hrtime.bigint()}
Expand Down
7 changes: 1 addition & 6 deletions types/node/v20/process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,7 @@ declare module "process" {
isTTY?: true | undefined;
}
// Alias for compatibility
interface ProcessEnv extends Dict<string> {
/**
* Can be used to change the default timezone at runtime
*/
TZ?: string | undefined;
}
interface ProcessEnv extends Dict<string> {}
interface HRTime {
/**
* This is the legacy version of {@link process.hrtime.bigint()}
Expand Down
7 changes: 1 addition & 6 deletions types/node/v22/process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,7 @@ declare module "process" {
isTTY?: true | undefined;
}
// Alias for compatibility
interface ProcessEnv extends Dict<string> {
/**
* Can be used to change the default timezone at runtime
*/
TZ?: string | undefined;
}
interface ProcessEnv extends Dict<string> {}
interface HRTime {
/**
* This is the legacy version of {@link process.hrtime.bigint()}
Expand Down
7 changes: 1 addition & 6 deletions types/node/v24/process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,7 @@ declare module "process" {
isTTY?: true | undefined;
}
// Alias for compatibility
interface ProcessEnv extends Dict<string> {
/**
* Can be used to change the default timezone at runtime
*/
TZ?: string | undefined;
}
interface ProcessEnv extends Dict<string> {}
interface HRTime {
/**
* This is the legacy version of {@link process.hrtime.bigint()}
Expand Down
2 changes: 2 additions & 0 deletions types/office-js-preview/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3331,6 +3331,8 @@ declare namespace Office {
* @returns A promise that is resolved when the UI is shown.
*
* @remarks
* This method applies only to centrally deployed or sideloaded add-ins. For add-ins published in the Microsoft Marketplace, the method is ignored and the task pane doesn't open.
*
* **Requirement set**: {@link https://learn.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
showAsTaskpane(): Promise<void>;
Expand Down
2 changes: 2 additions & 0 deletions types/office-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3331,6 +3331,8 @@ declare namespace Office {
* @returns A promise that is resolved when the UI is shown.
*
* @remarks
* This method applies only to centrally deployed or sideloaded add-ins. For add-ins published in the Microsoft Marketplace, the method is ignored and the task pane doesn't open.
*
* **Requirement set**: {@link https://learn.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
showAsTaskpane(): Promise<void>;
Expand Down
30 changes: 26 additions & 4 deletions types/whatwg-mimetype/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export = MIMEType;

/**
* This class will parse [MIME types](https://mimesniff.spec.whatwg.org/#understanding-mime-types) into a
* structured format, which can then be manipulated and serialized.
Expand All @@ -23,7 +21,7 @@ export = MIMEType;
* console.assert(mimeType.isHTML() === true);
* console.assert(mimeType.isXML() === false);
*/
declare class MIMEType {
export class MIMEType {
/**
* the MIME type's [type](https://mimesniff.spec.whatwg.org/#mime-type-type), e.g. `"text"`
*/
Expand Down Expand Up @@ -75,7 +73,7 @@ declare class MIMEType {
isJavaScript(opts?: { prohibitParameters?: boolean | undefined }): boolean;
}

declare namespace MIMEType {
export namespace MIMEType {
/**
* The `MIMETypeParameters` class, instances of which are returned by `mimeType.parameters`, has equivalent
* surface API to a [JavaScript `Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).
Expand Down Expand Up @@ -121,3 +119,27 @@ declare namespace MIMEType {
[Symbol.iterator](): IterableIterator<[string, string]>;
}
}

/**
* Determine the computed MIME type of a resource.
* https://mimesniff.spec.whatwg.org/#determining-the-computed-mime-type-of-a-resource
*
* @param resource - The resource bytes
* @returns The computed MIME type
*/
export function computedMIMEType(
resource: Uint8Array,
options?: {
/** The Content-Type header value (for HTTP resources) */
contentTypeHeader?: string;

/** MIME type from filesystem or other protocol (for non-HTTP resources) */
providedType?: string;

/** Whether the X-Content-Type-Options: nosniff header was present */
noSniff?: boolean;

/** Predicate to check if an image/audio/video MIME type is supported */
isSupported?: (mimeType: MIMEType) => boolean;
},
): MIMEType;
2 changes: 1 addition & 1 deletion types/whatwg-mimetype/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/whatwg-mimetype",
"version": "3.0.9999",
"version": "5.0.9999",
"projects": [
"https://github.com/jsdom/whatwg-mimetype#readme"
],
Expand Down
44 changes: 43 additions & 1 deletion types/whatwg-mimetype/whatwg-mimetype-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MIMEType = require("whatwg-mimetype");
import { computedMIMEType, MIMEType } from "whatwg-mimetype";

// test type exports
type MT = MIMEType;
Expand Down Expand Up @@ -39,3 +39,45 @@ if (mt != null) {
mt.parameters.entries(); // $ExpectType IterableIterator<[string, string]>
mt.parameters[Symbol.iterator](); // $ExpectType IterableIterator<[string, string]>
}

// test computedMIMEType function
const resource = new Uint8Array([0x00, 0x01, 0x02]);

// Test basic call with resource only
computedMIMEType(resource); // $ExpectType MIMEType

// Test with all options provided
// $ExpectType MIMEType
computedMIMEType(resource, {
contentTypeHeader: "text/html",
providedType: "text/plain",
noSniff: true,
isSupported: (mimeType: MIMEType) => true,
});

// Test with partial options
computedMIMEType(resource, { contentTypeHeader: "text/html" }); // $ExpectType MIMEType
computedMIMEType(resource, { providedType: "text/plain" }); // $ExpectType MIMEType
computedMIMEType(resource, { noSniff: false }); // $ExpectType MIMEType
//
// $ExpectType MIMEType
computedMIMEType(resource, {
isSupported: (mimeType) => {
mimeType; // $ExpectType MIMEType
return false;
},
});

// Test that invalid parameters are rejected
// @ts-expect-error
computedMIMEType();
// @ts-expect-error
computedMIMEType("not a Uint8Array");
// @ts-expect-error
computedMIMEType(resource, { invalidOption: true });
// @ts-expect-error
computedMIMEType(resource, { contentTypeHeader: 123 });
// @ts-expect-error
computedMIMEType(resource, { noSniff: "true" });
// @ts-expect-error
computedMIMEType(resource, { isSupported: "not a function" });
Loading