Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pragatimodi committed Aug 20, 2024
1 parent 6bc1c6b commit 6b4e59d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 64 deletions.
94 changes: 47 additions & 47 deletions spec/common/providers/identity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,53 +749,53 @@ describe("identity", () => {

expect(identity.parseAuthEventContext(decodedJwt, "project-id", time)).to.deep.equal(context);
});
it("should parse a beforeSendSms event", () => {
const time = now.getTime();
const decodedJwt = {
iss: "https://securetoken.google.com/project_id",
aud: "https://us-east1-project_id.cloudfunctions.net/function-1",
iat: 1,
exp: 60 * 60 + 1,
event_id: "EVENT_ID",
event_type: "beforeSendSms",
user_agent: "USER_AGENT",
ip_address: "1.2.3.4",
locale: "en",
recaptcha_score: TEST_RECAPTCHA_SCORE,
sms_type: "SIGN_IN_OR_SIGN_UP",
phone_number: "+11234567890",
};
const context = {
locale: "en",
ipAddress: "1.2.3.4",
userAgent: "USER_AGENT",
eventId: "EVENT_ID",
eventType: "providers/cloud.auth/eventTypes/user.beforeSendSms",
emailType: undefined,
smsType: "SIGN_IN_OR_SIGN_UP",
authType: "UNAUTHENTICATED",
resource: {
service: "identitytoolkit.googleapis.com",
name: "projects/project-id",
},
timestamp: new Date(1000).toUTCString(),
additionalUserInfo: {
isNewUser: false,
profile: undefined,
providerId: undefined,
username: undefined,
recaptchaScore: TEST_RECAPTCHA_SCORE,
email: undefined,
phoneNumber: "+11234567890",
},
credential: null,
params: {},
};
expect(identity.parseAuthEventContext(decodedJwt, "project-id", time)).to.deep.equal(context);
});
});

it("should parse a beforeSendSms event", () => {
const time = now.getTime();
const decodedJwt = {
iss: "https://securetoken.google.com/project_id",
aud: "https://us-east1-project_id.cloudfunctions.net/function-1",
iat: 1,
exp: 60 * 60 + 1,
event_id: "EVENT_ID",
event_type: "beforeSendSms",
user_agent: "USER_AGENT",
ip_address: "1.2.3.4",
locale: "en",
recaptcha_score: TEST_RECAPTCHA_SCORE,
sms_type: "SIGN_IN_OR_SIGN_UP",
phone_number: "+11234567890",
};
const context = {
locale: "en",
ipAddress: "1.2.3.4",
userAgent: "USER_AGENT",
eventId: "EVENT_ID",
eventType: "providers/cloud.auth/eventTypes/user.beforeSendSms",
emailType: undefined,
smsType: "SIGN_IN_OR_SIGN_UP",
authType: "UNAUTHENTICATED",
resource: {
service: "identitytoolkit.googleapis.com",
name: "projects/project-id",
},
timestamp: new Date(1000).toUTCString(),
additionalUserInfo: {
isNewUser: false,
profile: undefined,
providerId: undefined,
username: undefined,
recaptchaScore: TEST_RECAPTCHA_SCORE,
email: undefined,
phoneNumber: "+11234567890",
},
credential: null,
params: {},
};

expect(identity.parseAuthEventContext(decodedJwt, "project-id", time)).to.deep.equal(context);
});
});

describe("validateAuthResponse", () => {
it("should not throw on undefined request", () => {
Expand Down
10 changes: 5 additions & 5 deletions spec/v1/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,11 @@ describe("Auth Functions", () => {
]);
});
});

describe("beforeSms", () => {
it("should create function without options", () => {
const fn = auth.user().beforeSms(() => Promise.resolve());

expect(fn.__trigger).to.deep.equal({
labels: {},
blockingTrigger: {
Expand Down Expand Up @@ -430,7 +430,7 @@ describe("Auth Functions", () => {
},
]);
});

it("should create the function with options", () => {
const fn = functions
.region("us-east1")
Expand All @@ -445,7 +445,7 @@ describe("Auth Functions", () => {
},
})
.beforeSms(() => Promise.resolve());

expect(fn.__trigger).to.deep.equal({
labels: {},
regions: ["us-east1"],
Expand Down Expand Up @@ -483,7 +483,7 @@ describe("Auth Functions", () => {
},
]);
});
});
});

describe("#_dataConstructor", () => {
let cloudFunctionDelete: CloudFunction<UserRecord>;
Expand Down
11 changes: 5 additions & 6 deletions spec/v2/providers/identity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const BEFORE_EMAIL_TRIGGER = {
options: {},
};


const BEFORE_SMS_TRIGGER = {
eventType: "providers/cloud.auth/eventTypes/user.beforeSendSms",
options: {},
Expand Down Expand Up @@ -238,11 +237,11 @@ describe("identity", () => {
]);
});
});

describe("beforeSmsSent", () => {
it("should accept a handler", () => {
const fn = identity.beforeSmsSent(() => Promise.resolve());

expect(fn.__endpoint).to.deep.equal({
...MINIMAL_V2_ENDPOINT,
platform: "gcfv2",
Expand All @@ -256,13 +255,13 @@ describe("identity", () => {
},
]);
});

it("should accept options and a handler", () => {
const fn = identity.beforeSmsSent(
{ region: opts.region, minInstances: opts.minInstances },
() => Promise.resolve()
);

expect(fn.__endpoint).to.deep.equal({
...MINIMAL_V2_ENDPOINT,
platform: "gcfv2",
Expand All @@ -280,7 +279,7 @@ describe("identity", () => {
},
]);
});
});
});

describe("beforeOperation", () => {
it("should handle eventType and handler for before create events", () => {
Expand Down
14 changes: 11 additions & 3 deletions src/common/providers/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ const CLAIMS_MAX_PAYLOAD_SIZE = 1000;
* @hidden
* @alpha
*/
export type AuthBlockingEventType = "beforeCreate" | "beforeSignIn" | "beforeSendEmail" | "beforeSendSms";
export type AuthBlockingEventType =
| "beforeCreate"
| "beforeSignIn"
| "beforeSendEmail"
| "beforeSendSms";

const EVENT_MAPPING: Record<string, string> = {
beforeCreate: "providers/cloud.auth/eventTypes/user.beforeCreate",
Expand Down Expand Up @@ -488,11 +492,15 @@ export type MaybeAsync<T> = T | Promise<T>;
export type HandlerV1 = (
userOrContext: AuthUserRecord | AuthEventContext,
context?: AuthEventContext
) => MaybeAsync<BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void>;
) => MaybeAsync<
BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void
>;

export type HandlerV2 = (
event: AuthBlockingEvent
) => MaybeAsync<BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void>;
) => MaybeAsync<
BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void
>;

export type AuthBlockingEventHandler = (HandlerV1 | HandlerV2) & {
// Specify the GCF gen of the trigger that the auth blocking event handler was written for
Expand Down
2 changes: 1 addition & 1 deletion src/v1/providers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class UserBuilder {
): BlockingFunction {
return this.beforeOperation(handler, "beforeSendEmail");
}

beforeSms(
handler: (context: AuthEventContext) => MaybeAsync<BeforeSmsResponse | void>
): BlockingFunction {
Expand Down
8 changes: 6 additions & 2 deletions src/v2/providers/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,17 @@ export function beforeOperation(
| BlockingOptions
| ((
event: AuthBlockingEvent
) => MaybeAsync<BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void>),
) => MaybeAsync<
BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void
>),
handler: HandlerV2
): BlockingFunction {
if (!handler || typeof optsOrHandler === "function") {
handler = optsOrHandler as (
event: AuthBlockingEvent
) => MaybeAsync<BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void>;
) => MaybeAsync<
BeforeCreateResponse | BeforeSignInResponse | BeforeEmailResponse | BeforeSmsResponse | void
>;
optsOrHandler = {};
}

Expand Down

0 comments on commit 6b4e59d

Please sign in to comment.