Skip to content

Commit 7c27ede

Browse files
authored
[@xmpp/client, @xmpp/sasl, @xmpp/sasl2] Update CredentialsFactory signatures (DefinitelyTyped#74322)
1 parent ebcd22f commit 7c27ede

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

types/xmpp__client/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { IQCaller } from "@xmpp/iq/caller";
77
import { IncomingContext, Middleware } from "@xmpp/middleware";
88
import { Reconnect } from "@xmpp/reconnect";
99
import { Resource } from "@xmpp/resource-binding";
10-
import { Credentials, SASL } from "@xmpp/sasl";
10+
import { SASL } from "@xmpp/sasl";
11+
import { CredentialsFactory, CredentialsObj } from "@xmpp/sasl2";
1112
import { StreamFeatures } from "@xmpp/stream-features";
1213
import { StreamManagement } from "@xmpp/stream-management";
1314
import koaCompose = require("koa-compose");
@@ -68,7 +69,7 @@ export interface Options extends ConnectionOptions {
6869
* Resource for `@xmpp/resource-binding`.
6970
*/
7071
resource?: Resource | undefined;
71-
credentials?: Credentials | undefined;
72+
credentials?: CredentialsObj | CredentialsFactory<Client> | undefined;
7273
/**
7374
* Username for `@xmpp/sasl`.
7475
*/

types/xmpp__client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@types/xmpp__reconnect": "*",
1616
"@types/xmpp__resource-binding": "*",
1717
"@types/xmpp__sasl": "*",
18+
"@types/xmpp__sasl2": "*",
1819
"@types/xmpp__stream-features": "*",
1920
"@types/xmpp__stream-management": "*"
2021
},

types/xmpp__sasl/index.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ declare function sasl<TEntity extends Entity>(
1313
streamFeatures: StreamFeatures<TEntity>;
1414
saslFactory: SASLFactory;
1515
},
16-
credentials: Credentials,
16+
credentials: Credentials<TEntity>,
1717
): SASL;
1818

19-
export type Credentials = Partial<CredentialsObj> | CredentialsFactory;
19+
export type Credentials<TEntity extends Entity> = Partial<CredentialsObj> | CredentialsFactory<TEntity>;
2020

2121
export interface CredentialsObj {
2222
username: string;
2323
password: string;
2424
}
2525

26-
export type CredentialsFactory = (
26+
export type CredentialsFactory<TEntity extends Entity> = (
2727
callback: (credentials: CredentialsObj) => Promise<void>,
28-
mechanism: string,
28+
mechanisms: string[],
29+
fast: null,
30+
entity: TEntity,
2931
) => Promise<void>;
3032

3133
export interface SASL {

types/xmpp__sasl/xmpp__sasl-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sasl({ streamFeatures: sf, saslFactory }, { password: "foo" }); // $ExpectType S
3434
// $ExpectType SASL
3535
sasl({ streamFeatures: sf, saslFactory }, async (cb, mech) => {
3636
cb; // $ExpectType (credentials: CredentialsObj) => Promise<void>
37-
mech; // $ExpectType string
37+
mech; // $ExpectType string[]
3838

3939
await cb({ username: "foo", password: "bar" });
4040
});

types/xmpp__sasl2/index.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FAST } from "@xmpp/client-core/src/fast/fast.js";
1+
import { FAST, Token } from "@xmpp/client-core/src/fast/fast.js";
22
import { Entity } from "@xmpp/middleware";
33
import { StreamFeatures } from "@xmpp/stream-features";
44
import { Element } from "@xmpp/xml";
@@ -7,22 +7,23 @@ import SASLFactory = require("saslmechanisms");
77
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
88
export default function sasl2<TEntity extends Entity>(
99
params: { streamFeatures: StreamFeatures<TEntity>; saslFactory: SASLFactory },
10-
onAuthenticate: CredentialsFactory,
10+
onAuthenticate: CredentialsFactory<TEntity>,
1111
): SASL2;
1212

1313
export interface SASL2 {
1414
use(ns: string, req: (element: Element) => Promise<void>, res: (element: Element) => Promise<void>): void;
1515
setup(params: { fast: FAST }): void;
1616
}
1717

18-
export type CredentialsFactory = (
19-
callback: (credentials: CredentialsObj, mechanism: string, userAgent: string) => Promise<void>,
18+
export type CredentialsFactory<TEntity extends Entity> = (
19+
callback: (credentials: CredentialsObj, mechanism: string, userAgent: Element) => Promise<void>,
2020
mechanisms: string[],
2121
fast: FAST | null,
22-
entity: Entity,
22+
entity: TEntity,
2323
) => Promise<void>;
2424

2525
export interface CredentialsObj {
26-
username: string;
27-
password: string;
26+
username?: string;
27+
password?: string;
28+
token?: Token;
2829
}

types/xmpp__sasl2/xmpp__sasl2-tests.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Connection from "@xmpp/connection";
22
import middleware, { Entity } from "@xmpp/middleware";
33
import sasl2, { CredentialsFactory, SASL2 } from "@xmpp/sasl2";
44
import streamFeatures from "@xmpp/stream-features";
5-
import { Element } from "@xmpp/xml";
5+
import xml, { Element } from "@xmpp/xml";
66
import SASLFactory = require("saslmechanisms");
77

88
class Foo extends Connection implements Entity {
@@ -23,7 +23,13 @@ const sf = streamFeatures({ middleware: mw });
2323

2424
const saslFactory = new SASLFactory();
2525

26-
const onAuthenticate = null as unknown as CredentialsFactory;
26+
const onAuthenticate: CredentialsFactory<Foo> = (callback, mechanisms, fast, entity) => {
27+
return callback(
28+
{},
29+
mechanisms[0],
30+
xml("user-agent"),
31+
);
32+
};
2733

2834
const saslMw = sasl2({ streamFeatures: sf, saslFactory }, onAuthenticate); // $ExpectType SASL2
2935

0 commit comments

Comments
 (0)