From 5b6ebc8180f277c8d354158a8f918140250ba634 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 30 Jul 2021 09:49:06 -0700 Subject: [PATCH 01/17] add sms api method --- packages/provider/src/modules/auth.ts | 16 +++++++++++++++- packages/types/src/core/json-rpc-types.ts | 2 ++ packages/types/src/modules/auth-types.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/provider/src/modules/auth.ts b/packages/provider/src/modules/auth.ts index a712df38e..7989feb83 100644 --- a/packages/provider/src/modules/auth.ts +++ b/packages/provider/src/modules/auth.ts @@ -1,4 +1,4 @@ -import { MagicPayloadMethod, LoginWithMagicLinkConfiguration } from '@magic-sdk/types'; +import { MagicPayloadMethod, LoginWithMagicLinkConfiguration, LoginWithSmsConfiguration } from '@magic-sdk/types'; import { BaseModule } from './base-module'; import { createJsonRpcRequestPayload } from '../core/json-rpc'; import { SDKEnvironment } from '../core/sdk-environment'; @@ -24,6 +24,20 @@ export class AuthModule extends BaseModule { return this.request(requestPayload); } + /** + * Initiate an SMS login flow for a user. If successful, + * this method will return a Decenteralized ID token (with a default lifespan + * of 15 minutes) + */ + public loginWithSMS(configuration: LoginWithSmsConfiguration) { + const { phoneNumber } = configuration; + const requestPayload = createJsonRpcRequestPayload( + this.sdk.testMode ? MagicPayloadMethod.LoginWithSmsTestMode : MagicPayloadMethod.LoginWithSms, + [{ phoneNumber, showUI: true }], + ); + return this.request(requestPayload); + } + /** * Log a user in with a special one-time-use credential token. This is * currently used during magic link flows with a configured redirect to diff --git a/packages/types/src/core/json-rpc-types.ts b/packages/types/src/core/json-rpc-types.ts index 31064d224..f48028692 100644 --- a/packages/types/src/core/json-rpc-types.ts +++ b/packages/types/src/core/json-rpc-types.ts @@ -40,6 +40,7 @@ export interface JsonRpcResponsePayload { * relayer. */ export enum MagicPayloadMethod { + LoginWithSms = 'magic_auth_login_with_sms', LoginWithMagicLink = 'magic_auth_login_with_magic_link', LoginWithCredential = 'magic_auth_login_with_credential', GetIdToken = 'magic_auth_get_id_token', @@ -48,6 +49,7 @@ export enum MagicPayloadMethod { IsLoggedIn = 'magic_auth_is_logged_in', Logout = 'magic_auth_logout', UpdateEmail = 'magic_auth_update_email', + LoginWithSmsTestMode = 'magic_auth_login_with_sms_testing_mode', LoginWithMagicLinkTestMode = 'magic_login_with_magic_link_testing_mode', LoginWithCredentialTestMode = 'magic_auth_login_with_credential_testing_mode', GetIdTokenTestMode = 'magic_auth_get_id_token_testing_mode', diff --git a/packages/types/src/modules/auth-types.ts b/packages/types/src/modules/auth-types.ts index ec69c434f..df906f031 100644 --- a/packages/types/src/modules/auth-types.ts +++ b/packages/types/src/modules/auth-types.ts @@ -19,3 +19,7 @@ export interface LoginWithMagicLinkConfiguration { */ redirectURI?: string; } + +export interface LoginWithSmsConfiguration { + phoneNumber: string; +} From ce0753616e5a3bd31bc85ed073960b357492d47e Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 30 Jul 2021 09:49:06 -0700 Subject: [PATCH 02/17] add sms api method --- packages/@magic-sdk/provider/src/modules/auth.ts | 16 +++++++++++++++- .../@magic-sdk/types/src/core/json-rpc-types.ts | 2 ++ .../@magic-sdk/types/src/modules/auth-types.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/@magic-sdk/provider/src/modules/auth.ts b/packages/@magic-sdk/provider/src/modules/auth.ts index 295ff4f20..2209d5a09 100644 --- a/packages/@magic-sdk/provider/src/modules/auth.ts +++ b/packages/@magic-sdk/provider/src/modules/auth.ts @@ -1,4 +1,4 @@ -import { MagicPayloadMethod, LoginWithMagicLinkConfiguration } from '@magic-sdk/types'; +import { MagicPayloadMethod, LoginWithMagicLinkConfiguration, LoginWithSmsConfiguration } from '@magic-sdk/types'; import { BaseModule } from './base-module'; import { createJsonRpcRequestPayload } from '../core/json-rpc'; import { SDKEnvironment } from '../core/sdk-environment'; @@ -25,6 +25,20 @@ export class AuthModule extends BaseModule { return this.request(requestPayload); } + /** + * Initiate an SMS login flow for a user. If successful, + * this method will return a Decenteralized ID token (with a default lifespan + * of 15 minutes) + */ + public loginWithSMS(configuration: LoginWithSmsConfiguration) { + const { phoneNumber } = configuration; + const requestPayload = createJsonRpcRequestPayload( + this.sdk.testMode ? MagicPayloadMethod.LoginWithSmsTestMode : MagicPayloadMethod.LoginWithSms, + [{ phoneNumber, showUI: true }], + ); + return this.request(requestPayload); + } + /** * Log a user in with a special one-time-use credential token. This is * currently used during magic link flows with a configured redirect to diff --git a/packages/@magic-sdk/types/src/core/json-rpc-types.ts b/packages/@magic-sdk/types/src/core/json-rpc-types.ts index 31064d224..f48028692 100644 --- a/packages/@magic-sdk/types/src/core/json-rpc-types.ts +++ b/packages/@magic-sdk/types/src/core/json-rpc-types.ts @@ -40,6 +40,7 @@ export interface JsonRpcResponsePayload { * relayer. */ export enum MagicPayloadMethod { + LoginWithSms = 'magic_auth_login_with_sms', LoginWithMagicLink = 'magic_auth_login_with_magic_link', LoginWithCredential = 'magic_auth_login_with_credential', GetIdToken = 'magic_auth_get_id_token', @@ -48,6 +49,7 @@ export enum MagicPayloadMethod { IsLoggedIn = 'magic_auth_is_logged_in', Logout = 'magic_auth_logout', UpdateEmail = 'magic_auth_update_email', + LoginWithSmsTestMode = 'magic_auth_login_with_sms_testing_mode', LoginWithMagicLinkTestMode = 'magic_login_with_magic_link_testing_mode', LoginWithCredentialTestMode = 'magic_auth_login_with_credential_testing_mode', GetIdTokenTestMode = 'magic_auth_get_id_token_testing_mode', diff --git a/packages/@magic-sdk/types/src/modules/auth-types.ts b/packages/@magic-sdk/types/src/modules/auth-types.ts index ec69c434f..df906f031 100644 --- a/packages/@magic-sdk/types/src/modules/auth-types.ts +++ b/packages/@magic-sdk/types/src/modules/auth-types.ts @@ -19,3 +19,7 @@ export interface LoginWithMagicLinkConfiguration { */ redirectURI?: string; } + +export interface LoginWithSmsConfiguration { + phoneNumber: string; +} From 8602b3b8643e88555f1b7abb185ae360a9d29821 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:26:12 -0700 Subject: [PATCH 03/17] add unit test for login with sms --- .../spec/modules/auth/loginWithSms.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts diff --git a/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts new file mode 100644 index 000000000..3b55c90a8 --- /dev/null +++ b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts @@ -0,0 +1,42 @@ +/* eslint-disable global-require, @typescript-eslint/no-var-requires */ + +import browserEnv from '@ikscodes/browser-env'; +import { MagicPayloadMethod } from '@magic-sdk/types'; +import { isPromiEvent } from '../../../../src/util'; +import { createMagicSDK, createMagicSDKTestMode } from '../../../factories'; + +beforeEach(() => { + browserEnv.restore(); + jest.restoreAllMocks(); +}); + +const expectedPhoneNumber = 'hey hey I am a number but jk'; + +test('Generates JSON RPC request payload with `phone` parameter', async () => { + const magic = createMagicSDK(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSms); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('If `testMode` is enabled, testing-specific RPC method is used', async () => { + const magic = createMagicSDKTestMode(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSmsTestMode); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('method should return a PromiEvent', () => { + const magic = createMagicSDK(); + expect(isPromiEvent(magic.auth.loginWithSMS({ email: 'blag' }))).toBeTruthy(); +}); From 5fb8a52a55e272a34937a0740868665e362f052c Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:28:58 -0700 Subject: [PATCH 04/17] add release tag --- .circleci/config.yml | 3 ++- package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 55540a0f0..ebca22922 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,7 +39,7 @@ aliases: [ &filter-default-branches { filters: { branches: { - ignore: "/^master$|^next$/" + ignore: "/^master$|^next$/|^dgerrells" } } }, @@ -51,6 +51,7 @@ aliases: [ only: [ "master", "next", + "dgerrells-ch42053-sms-feature" ] } } diff --git a/package.json b/package.json index 8207e24fd..2689d6618 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "plugins": [ "npm", "released" - ] + ], + "prereleaseBranches": ["dgerrells-ch42053-sms-feature"] } } From 9b9502049312f953b1901196bb4875638601b128 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 30 Jul 2021 09:49:06 -0700 Subject: [PATCH 05/17] add sms api method --- packages/@magic-sdk/provider/src/modules/auth.ts | 16 +++++++++++++++- .../@magic-sdk/types/src/core/json-rpc-types.ts | 2 ++ .../@magic-sdk/types/src/modules/auth-types.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/@magic-sdk/provider/src/modules/auth.ts b/packages/@magic-sdk/provider/src/modules/auth.ts index 295ff4f20..2209d5a09 100644 --- a/packages/@magic-sdk/provider/src/modules/auth.ts +++ b/packages/@magic-sdk/provider/src/modules/auth.ts @@ -1,4 +1,4 @@ -import { MagicPayloadMethod, LoginWithMagicLinkConfiguration } from '@magic-sdk/types'; +import { MagicPayloadMethod, LoginWithMagicLinkConfiguration, LoginWithSmsConfiguration } from '@magic-sdk/types'; import { BaseModule } from './base-module'; import { createJsonRpcRequestPayload } from '../core/json-rpc'; import { SDKEnvironment } from '../core/sdk-environment'; @@ -25,6 +25,20 @@ export class AuthModule extends BaseModule { return this.request(requestPayload); } + /** + * Initiate an SMS login flow for a user. If successful, + * this method will return a Decenteralized ID token (with a default lifespan + * of 15 minutes) + */ + public loginWithSMS(configuration: LoginWithSmsConfiguration) { + const { phoneNumber } = configuration; + const requestPayload = createJsonRpcRequestPayload( + this.sdk.testMode ? MagicPayloadMethod.LoginWithSmsTestMode : MagicPayloadMethod.LoginWithSms, + [{ phoneNumber, showUI: true }], + ); + return this.request(requestPayload); + } + /** * Log a user in with a special one-time-use credential token. This is * currently used during magic link flows with a configured redirect to diff --git a/packages/@magic-sdk/types/src/core/json-rpc-types.ts b/packages/@magic-sdk/types/src/core/json-rpc-types.ts index 31064d224..f48028692 100644 --- a/packages/@magic-sdk/types/src/core/json-rpc-types.ts +++ b/packages/@magic-sdk/types/src/core/json-rpc-types.ts @@ -40,6 +40,7 @@ export interface JsonRpcResponsePayload { * relayer. */ export enum MagicPayloadMethod { + LoginWithSms = 'magic_auth_login_with_sms', LoginWithMagicLink = 'magic_auth_login_with_magic_link', LoginWithCredential = 'magic_auth_login_with_credential', GetIdToken = 'magic_auth_get_id_token', @@ -48,6 +49,7 @@ export enum MagicPayloadMethod { IsLoggedIn = 'magic_auth_is_logged_in', Logout = 'magic_auth_logout', UpdateEmail = 'magic_auth_update_email', + LoginWithSmsTestMode = 'magic_auth_login_with_sms_testing_mode', LoginWithMagicLinkTestMode = 'magic_login_with_magic_link_testing_mode', LoginWithCredentialTestMode = 'magic_auth_login_with_credential_testing_mode', GetIdTokenTestMode = 'magic_auth_get_id_token_testing_mode', diff --git a/packages/@magic-sdk/types/src/modules/auth-types.ts b/packages/@magic-sdk/types/src/modules/auth-types.ts index ec69c434f..df906f031 100644 --- a/packages/@magic-sdk/types/src/modules/auth-types.ts +++ b/packages/@magic-sdk/types/src/modules/auth-types.ts @@ -19,3 +19,7 @@ export interface LoginWithMagicLinkConfiguration { */ redirectURI?: string; } + +export interface LoginWithSmsConfiguration { + phoneNumber: string; +} From 2f20e8b0c59a3e95376b9bcb8d44cfa233e1c866 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:26:12 -0700 Subject: [PATCH 06/17] add unit test for login with sms --- .../spec/modules/auth/loginWithSms.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts diff --git a/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts new file mode 100644 index 000000000..3b55c90a8 --- /dev/null +++ b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts @@ -0,0 +1,42 @@ +/* eslint-disable global-require, @typescript-eslint/no-var-requires */ + +import browserEnv from '@ikscodes/browser-env'; +import { MagicPayloadMethod } from '@magic-sdk/types'; +import { isPromiEvent } from '../../../../src/util'; +import { createMagicSDK, createMagicSDKTestMode } from '../../../factories'; + +beforeEach(() => { + browserEnv.restore(); + jest.restoreAllMocks(); +}); + +const expectedPhoneNumber = 'hey hey I am a number but jk'; + +test('Generates JSON RPC request payload with `phone` parameter', async () => { + const magic = createMagicSDK(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSms); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('If `testMode` is enabled, testing-specific RPC method is used', async () => { + const magic = createMagicSDKTestMode(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSmsTestMode); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('method should return a PromiEvent', () => { + const magic = createMagicSDK(); + expect(isPromiEvent(magic.auth.loginWithSMS({ email: 'blag' }))).toBeTruthy(); +}); From 9aa00a44664b74bfb6026d092d31c29a3c35abb6 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:28:58 -0700 Subject: [PATCH 07/17] add release tag --- .circleci/config.yml | 3 ++- package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 55540a0f0..ebca22922 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,7 +39,7 @@ aliases: [ &filter-default-branches { filters: { branches: { - ignore: "/^master$|^next$/" + ignore: "/^master$|^next$/|^dgerrells" } } }, @@ -51,6 +51,7 @@ aliases: [ only: [ "master", "next", + "dgerrells-ch42053-sms-feature" ] } } diff --git a/package.json b/package.json index 8207e24fd..2689d6618 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "plugins": [ "npm", "released" - ] + ], + "prereleaseBranches": ["dgerrells-ch42053-sms-feature"] } } From 3dd528cfeee117ba50f27b58d4407bc16d15b17d Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 30 Jul 2021 09:49:06 -0700 Subject: [PATCH 08/17] add sms api method --- packages/@magic-sdk/provider/src/modules/auth.ts | 16 +++++++++++++++- .../@magic-sdk/types/src/core/json-rpc-types.ts | 2 ++ .../@magic-sdk/types/src/modules/auth-types.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/@magic-sdk/provider/src/modules/auth.ts b/packages/@magic-sdk/provider/src/modules/auth.ts index 295ff4f20..2209d5a09 100644 --- a/packages/@magic-sdk/provider/src/modules/auth.ts +++ b/packages/@magic-sdk/provider/src/modules/auth.ts @@ -1,4 +1,4 @@ -import { MagicPayloadMethod, LoginWithMagicLinkConfiguration } from '@magic-sdk/types'; +import { MagicPayloadMethod, LoginWithMagicLinkConfiguration, LoginWithSmsConfiguration } from '@magic-sdk/types'; import { BaseModule } from './base-module'; import { createJsonRpcRequestPayload } from '../core/json-rpc'; import { SDKEnvironment } from '../core/sdk-environment'; @@ -25,6 +25,20 @@ export class AuthModule extends BaseModule { return this.request(requestPayload); } + /** + * Initiate an SMS login flow for a user. If successful, + * this method will return a Decenteralized ID token (with a default lifespan + * of 15 minutes) + */ + public loginWithSMS(configuration: LoginWithSmsConfiguration) { + const { phoneNumber } = configuration; + const requestPayload = createJsonRpcRequestPayload( + this.sdk.testMode ? MagicPayloadMethod.LoginWithSmsTestMode : MagicPayloadMethod.LoginWithSms, + [{ phoneNumber, showUI: true }], + ); + return this.request(requestPayload); + } + /** * Log a user in with a special one-time-use credential token. This is * currently used during magic link flows with a configured redirect to diff --git a/packages/@magic-sdk/types/src/core/json-rpc-types.ts b/packages/@magic-sdk/types/src/core/json-rpc-types.ts index 31064d224..f48028692 100644 --- a/packages/@magic-sdk/types/src/core/json-rpc-types.ts +++ b/packages/@magic-sdk/types/src/core/json-rpc-types.ts @@ -40,6 +40,7 @@ export interface JsonRpcResponsePayload { * relayer. */ export enum MagicPayloadMethod { + LoginWithSms = 'magic_auth_login_with_sms', LoginWithMagicLink = 'magic_auth_login_with_magic_link', LoginWithCredential = 'magic_auth_login_with_credential', GetIdToken = 'magic_auth_get_id_token', @@ -48,6 +49,7 @@ export enum MagicPayloadMethod { IsLoggedIn = 'magic_auth_is_logged_in', Logout = 'magic_auth_logout', UpdateEmail = 'magic_auth_update_email', + LoginWithSmsTestMode = 'magic_auth_login_with_sms_testing_mode', LoginWithMagicLinkTestMode = 'magic_login_with_magic_link_testing_mode', LoginWithCredentialTestMode = 'magic_auth_login_with_credential_testing_mode', GetIdTokenTestMode = 'magic_auth_get_id_token_testing_mode', diff --git a/packages/@magic-sdk/types/src/modules/auth-types.ts b/packages/@magic-sdk/types/src/modules/auth-types.ts index ec69c434f..df906f031 100644 --- a/packages/@magic-sdk/types/src/modules/auth-types.ts +++ b/packages/@magic-sdk/types/src/modules/auth-types.ts @@ -19,3 +19,7 @@ export interface LoginWithMagicLinkConfiguration { */ redirectURI?: string; } + +export interface LoginWithSmsConfiguration { + phoneNumber: string; +} From 3dbf3ef472ead6df341c592d8978ba620d64f94a Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:26:12 -0700 Subject: [PATCH 09/17] add unit test for login with sms --- .../spec/modules/auth/loginWithSms.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts diff --git a/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts new file mode 100644 index 000000000..3b55c90a8 --- /dev/null +++ b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts @@ -0,0 +1,42 @@ +/* eslint-disable global-require, @typescript-eslint/no-var-requires */ + +import browserEnv from '@ikscodes/browser-env'; +import { MagicPayloadMethod } from '@magic-sdk/types'; +import { isPromiEvent } from '../../../../src/util'; +import { createMagicSDK, createMagicSDKTestMode } from '../../../factories'; + +beforeEach(() => { + browserEnv.restore(); + jest.restoreAllMocks(); +}); + +const expectedPhoneNumber = 'hey hey I am a number but jk'; + +test('Generates JSON RPC request payload with `phone` parameter', async () => { + const magic = createMagicSDK(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSms); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('If `testMode` is enabled, testing-specific RPC method is used', async () => { + const magic = createMagicSDKTestMode(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSmsTestMode); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('method should return a PromiEvent', () => { + const magic = createMagicSDK(); + expect(isPromiEvent(magic.auth.loginWithSMS({ email: 'blag' }))).toBeTruthy(); +}); From eed0fa37591eb38572138cb0a5c23aa467544085 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:28:58 -0700 Subject: [PATCH 10/17] add release tag --- .circleci/config.yml | 3 ++- package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ec4a38dd..c579bbe0e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,7 +40,7 @@ aliases: [ &filter-default-branches { filters: { branches: { - ignore: "/^master$|^next$/" + ignore: "/^master$|^next$/|^dgerrells" } } }, @@ -52,6 +52,7 @@ aliases: [ only: [ "master", "next", + "dgerrells-ch42053-sms-feature" ] } } diff --git a/package.json b/package.json index 57f144c3b..4bb14aade 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "plugins": [ "npm", "released" - ] + ], + "prereleaseBranches": ["dgerrells-ch42053-sms-feature"] } } From d71e3e51c05e50c56eea6a6cb7fe6d4734a87a13 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 17 Sep 2021 11:33:06 -0700 Subject: [PATCH 11/17] update yarn lock file --- package.json | 4 +++- yarn.lock | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4bb14aade..3999dc13d 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,8 @@ "npm", "released" ], - "prereleaseBranches": ["dgerrells-ch42053-sms-feature"] + "prereleaseBranches": [ + "dgerrells-ch42053-sms-feature" + ] } } diff --git a/yarn.lock b/yarn.lock index 0d963c2e1..58dc107dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4118,11 +4118,11 @@ __metadata: languageName: node linkType: hard -"@magic-sdk/commons@^2.0.2, @magic-sdk/commons@workspace:packages/@magic-sdk/commons": +"@magic-sdk/commons@^2.0.3, @magic-sdk/commons@workspace:packages/@magic-sdk/commons": version: 0.0.0-use.local resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons" dependencies: - "@magic-sdk/provider": ^6.0.2 + "@magic-sdk/provider": ^6.0.3 "@magic-sdk/types": ^5.0.1 peerDependencies: "@magic-sdk/provider": ">=4.3.0" @@ -4130,7 +4130,7 @@ __metadata: languageName: unknown linkType: soft -"@magic-sdk/provider@^6.0.2, @magic-sdk/provider@workspace:packages/@magic-sdk/provider": +"@magic-sdk/provider@^6.0.3, @magic-sdk/provider@workspace:packages/@magic-sdk/provider": version: 0.0.0-use.local resolution: "@magic-sdk/provider@workspace:packages/@magic-sdk/provider" dependencies: @@ -4155,8 +4155,8 @@ __metadata: "@babel/core": ^7.15.0 "@babel/plugin-transform-flow-strip-types": ^7.14.5 "@babel/runtime": ~7.10.4 - "@magic-sdk/commons": ^2.0.2 - "@magic-sdk/provider": ^6.0.2 + "@magic-sdk/commons": ^2.0.3 + "@magic-sdk/provider": ^6.0.3 "@magic-sdk/types": ^5.0.1 "@react-native-async-storage/async-storage": ^1.15.5 "@types/lodash": ^4.14.158 @@ -13746,8 +13746,8 @@ fsevents@^1.2.7: "@babel/core": ^7.9.6 "@babel/plugin-proposal-optional-chaining": ^7.9.0 "@babel/runtime": ^7.9.6 - "@magic-sdk/commons": ^2.0.2 - "@magic-sdk/provider": ^6.0.2 + "@magic-sdk/commons": ^2.0.3 + "@magic-sdk/provider": ^6.0.3 "@magic-sdk/types": ^5.0.1 localforage: ^1.7.4 localforage-driver-memory: ^1.0.5 From b44a6dfdf778957685fb4737dba41f5bae1cae69 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 30 Jul 2021 09:49:06 -0700 Subject: [PATCH 12/17] add sms api method --- packages/@magic-sdk/provider/src/modules/auth.ts | 16 +++++++++++++++- .../@magic-sdk/types/src/core/json-rpc-types.ts | 2 ++ .../@magic-sdk/types/src/modules/auth-types.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/@magic-sdk/provider/src/modules/auth.ts b/packages/@magic-sdk/provider/src/modules/auth.ts index 295ff4f20..2209d5a09 100644 --- a/packages/@magic-sdk/provider/src/modules/auth.ts +++ b/packages/@magic-sdk/provider/src/modules/auth.ts @@ -1,4 +1,4 @@ -import { MagicPayloadMethod, LoginWithMagicLinkConfiguration } from '@magic-sdk/types'; +import { MagicPayloadMethod, LoginWithMagicLinkConfiguration, LoginWithSmsConfiguration } from '@magic-sdk/types'; import { BaseModule } from './base-module'; import { createJsonRpcRequestPayload } from '../core/json-rpc'; import { SDKEnvironment } from '../core/sdk-environment'; @@ -25,6 +25,20 @@ export class AuthModule extends BaseModule { return this.request(requestPayload); } + /** + * Initiate an SMS login flow for a user. If successful, + * this method will return a Decenteralized ID token (with a default lifespan + * of 15 minutes) + */ + public loginWithSMS(configuration: LoginWithSmsConfiguration) { + const { phoneNumber } = configuration; + const requestPayload = createJsonRpcRequestPayload( + this.sdk.testMode ? MagicPayloadMethod.LoginWithSmsTestMode : MagicPayloadMethod.LoginWithSms, + [{ phoneNumber, showUI: true }], + ); + return this.request(requestPayload); + } + /** * Log a user in with a special one-time-use credential token. This is * currently used during magic link flows with a configured redirect to diff --git a/packages/@magic-sdk/types/src/core/json-rpc-types.ts b/packages/@magic-sdk/types/src/core/json-rpc-types.ts index 31064d224..f48028692 100644 --- a/packages/@magic-sdk/types/src/core/json-rpc-types.ts +++ b/packages/@magic-sdk/types/src/core/json-rpc-types.ts @@ -40,6 +40,7 @@ export interface JsonRpcResponsePayload { * relayer. */ export enum MagicPayloadMethod { + LoginWithSms = 'magic_auth_login_with_sms', LoginWithMagicLink = 'magic_auth_login_with_magic_link', LoginWithCredential = 'magic_auth_login_with_credential', GetIdToken = 'magic_auth_get_id_token', @@ -48,6 +49,7 @@ export enum MagicPayloadMethod { IsLoggedIn = 'magic_auth_is_logged_in', Logout = 'magic_auth_logout', UpdateEmail = 'magic_auth_update_email', + LoginWithSmsTestMode = 'magic_auth_login_with_sms_testing_mode', LoginWithMagicLinkTestMode = 'magic_login_with_magic_link_testing_mode', LoginWithCredentialTestMode = 'magic_auth_login_with_credential_testing_mode', GetIdTokenTestMode = 'magic_auth_get_id_token_testing_mode', diff --git a/packages/@magic-sdk/types/src/modules/auth-types.ts b/packages/@magic-sdk/types/src/modules/auth-types.ts index ec69c434f..df906f031 100644 --- a/packages/@magic-sdk/types/src/modules/auth-types.ts +++ b/packages/@magic-sdk/types/src/modules/auth-types.ts @@ -19,3 +19,7 @@ export interface LoginWithMagicLinkConfiguration { */ redirectURI?: string; } + +export interface LoginWithSmsConfiguration { + phoneNumber: string; +} From b3ec51d9717e60e4ddd7e2b44df3c436995939d6 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:26:12 -0700 Subject: [PATCH 13/17] add unit test for login with sms --- .../spec/modules/auth/loginWithSms.spec.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts diff --git a/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts new file mode 100644 index 000000000..3b55c90a8 --- /dev/null +++ b/packages/@magic-sdk/provider/test/spec/modules/auth/loginWithSms.spec.ts @@ -0,0 +1,42 @@ +/* eslint-disable global-require, @typescript-eslint/no-var-requires */ + +import browserEnv from '@ikscodes/browser-env'; +import { MagicPayloadMethod } from '@magic-sdk/types'; +import { isPromiEvent } from '../../../../src/util'; +import { createMagicSDK, createMagicSDKTestMode } from '../../../factories'; + +beforeEach(() => { + browserEnv.restore(); + jest.restoreAllMocks(); +}); + +const expectedPhoneNumber = 'hey hey I am a number but jk'; + +test('Generates JSON RPC request payload with `phone` parameter', async () => { + const magic = createMagicSDK(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSms); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('If `testMode` is enabled, testing-specific RPC method is used', async () => { + const magic = createMagicSDKTestMode(); + magic.auth.request = jest.fn(); + + await magic.auth.loginWithSMS({ phoneNumber: expectedPhoneNumber }); + + const requestPayload = magic.auth.request.mock.calls[0][0]; + expect(requestPayload.jsonrpc).toBe('2.0'); + expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithSmsTestMode); + expect(requestPayload.params).toEqual([{ phoneNumber: expectedPhoneNumber, showUI: true }]); +}); + +test('method should return a PromiEvent', () => { + const magic = createMagicSDK(); + expect(isPromiEvent(magic.auth.loginWithSMS({ email: 'blag' }))).toBeTruthy(); +}); From 5d8387c5dc8aa99d6c2f40b35c0a069b61e26646 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Tue, 31 Aug 2021 14:28:58 -0700 Subject: [PATCH 14/17] add release tag --- .circleci/config.yml | 3 ++- package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ec4a38dd..c579bbe0e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,7 +40,7 @@ aliases: [ &filter-default-branches { filters: { branches: { - ignore: "/^master$|^next$/" + ignore: "/^master$|^next$/|^dgerrells" } } }, @@ -52,6 +52,7 @@ aliases: [ only: [ "master", "next", + "dgerrells-ch42053-sms-feature" ] } } diff --git a/package.json b/package.json index 2757f5fda..e1a634d70 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "plugins": [ "npm", "released" - ] + ], + "prereleaseBranches": ["dgerrells-ch42053-sms-feature"] } } From f049e42020885d1135f33a19ed6e4cc5b7a6a0ca Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 17 Sep 2021 11:33:06 -0700 Subject: [PATCH 15/17] update yarn lock file --- package.json | 4 +++- yarn.lock | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e1a634d70..c8ca63c4b 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,8 @@ "npm", "released" ], - "prereleaseBranches": ["dgerrells-ch42053-sms-feature"] + "prereleaseBranches": [ + "dgerrells-ch42053-sms-feature" + ] } } diff --git a/yarn.lock b/yarn.lock index f83a790f0..7d486bc6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4118,19 +4118,32 @@ __metadata: languageName: node linkType: hard +<<<<<<< HEAD "@magic-sdk/commons@^2.0.4, @magic-sdk/commons@workspace:packages/@magic-sdk/commons": version: 0.0.0-use.local resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons" dependencies: "@magic-sdk/provider": ^6.0.4 "@magic-sdk/types": ^5.0.2 +======= +"@magic-sdk/commons@^2.0.3, @magic-sdk/commons@workspace:packages/@magic-sdk/commons": + version: 0.0.0-use.local + resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons" + dependencies: + "@magic-sdk/provider": ^6.0.3 + "@magic-sdk/types": ^5.0.1 +>>>>>>> update yarn lock file peerDependencies: "@magic-sdk/provider": ">=4.3.0" "@magic-sdk/types": ">=3.1.1" languageName: unknown linkType: soft +<<<<<<< HEAD "@magic-sdk/provider@^6.0.4, @magic-sdk/provider@workspace:packages/@magic-sdk/provider": +======= +"@magic-sdk/provider@^6.0.3, @magic-sdk/provider@workspace:packages/@magic-sdk/provider": +>>>>>>> update yarn lock file version: 0.0.0-use.local resolution: "@magic-sdk/provider@workspace:packages/@magic-sdk/provider" dependencies: @@ -4155,9 +4168,15 @@ __metadata: "@babel/core": ^7.15.0 "@babel/plugin-transform-flow-strip-types": ^7.14.5 "@babel/runtime": ~7.10.4 +<<<<<<< HEAD "@magic-sdk/commons": ^2.0.4 "@magic-sdk/provider": ^6.0.4 "@magic-sdk/types": ^5.0.2 +======= + "@magic-sdk/commons": ^2.0.3 + "@magic-sdk/provider": ^6.0.3 + "@magic-sdk/types": ^5.0.1 +>>>>>>> update yarn lock file "@react-native-async-storage/async-storage": ^1.15.5 "@types/lodash": ^4.14.158 buffer: ~5.6.0 @@ -13746,9 +13765,15 @@ fsevents@^1.2.7: "@babel/core": ^7.9.6 "@babel/plugin-proposal-optional-chaining": ^7.9.0 "@babel/runtime": ^7.9.6 +<<<<<<< HEAD "@magic-sdk/commons": ^2.0.4 "@magic-sdk/provider": ^6.0.4 "@magic-sdk/types": ^5.0.2 +======= + "@magic-sdk/commons": ^2.0.3 + "@magic-sdk/provider": ^6.0.3 + "@magic-sdk/types": ^5.0.1 +>>>>>>> update yarn lock file localforage: ^1.7.4 localforage-driver-memory: ^1.0.5 languageName: unknown From 9518b6eaa7a5581ff08553a551257771f4d7a037 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 17 Sep 2021 15:52:18 -0700 Subject: [PATCH 16/17] update lock to yarn v2 --- yarn.lock | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/yarn.lock b/yarn.lock index 7d486bc6e..9c07195ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4118,32 +4118,19 @@ __metadata: languageName: node linkType: hard -<<<<<<< HEAD -"@magic-sdk/commons@^2.0.4, @magic-sdk/commons@workspace:packages/@magic-sdk/commons": +"@magic-sdk/commons@^2.0.5, @magic-sdk/commons@workspace:packages/@magic-sdk/commons": version: 0.0.0-use.local resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons" dependencies: - "@magic-sdk/provider": ^6.0.4 + "@magic-sdk/provider": ^6.0.5 "@magic-sdk/types": ^5.0.2 -======= -"@magic-sdk/commons@^2.0.3, @magic-sdk/commons@workspace:packages/@magic-sdk/commons": - version: 0.0.0-use.local - resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons" - dependencies: - "@magic-sdk/provider": ^6.0.3 - "@magic-sdk/types": ^5.0.1 ->>>>>>> update yarn lock file peerDependencies: "@magic-sdk/provider": ">=4.3.0" "@magic-sdk/types": ">=3.1.1" languageName: unknown linkType: soft -<<<<<<< HEAD -"@magic-sdk/provider@^6.0.4, @magic-sdk/provider@workspace:packages/@magic-sdk/provider": -======= -"@magic-sdk/provider@^6.0.3, @magic-sdk/provider@workspace:packages/@magic-sdk/provider": ->>>>>>> update yarn lock file +"@magic-sdk/provider@^6.0.5, @magic-sdk/provider@workspace:packages/@magic-sdk/provider": version: 0.0.0-use.local resolution: "@magic-sdk/provider@workspace:packages/@magic-sdk/provider" dependencies: @@ -4168,15 +4155,9 @@ __metadata: "@babel/core": ^7.15.0 "@babel/plugin-transform-flow-strip-types": ^7.14.5 "@babel/runtime": ~7.10.4 -<<<<<<< HEAD - "@magic-sdk/commons": ^2.0.4 - "@magic-sdk/provider": ^6.0.4 + "@magic-sdk/commons": ^2.0.5 + "@magic-sdk/provider": ^6.0.5 "@magic-sdk/types": ^5.0.2 -======= - "@magic-sdk/commons": ^2.0.3 - "@magic-sdk/provider": ^6.0.3 - "@magic-sdk/types": ^5.0.1 ->>>>>>> update yarn lock file "@react-native-async-storage/async-storage": ^1.15.5 "@types/lodash": ^4.14.158 buffer: ~5.6.0 @@ -13765,15 +13746,9 @@ fsevents@^1.2.7: "@babel/core": ^7.9.6 "@babel/plugin-proposal-optional-chaining": ^7.9.0 "@babel/runtime": ^7.9.6 -<<<<<<< HEAD - "@magic-sdk/commons": ^2.0.4 - "@magic-sdk/provider": ^6.0.4 + "@magic-sdk/commons": ^2.0.5 + "@magic-sdk/provider": ^6.0.5 "@magic-sdk/types": ^5.0.2 -======= - "@magic-sdk/commons": ^2.0.3 - "@magic-sdk/provider": ^6.0.3 - "@magic-sdk/types": ^5.0.1 ->>>>>>> update yarn lock file localforage: ^1.7.4 localforage-driver-memory: ^1.0.5 languageName: unknown From 8eca712f578fbaa1f9973cf622846655f4cbec08 Mon Sep 17 00:00:00 2001 From: David Gerrells Date: Fri, 1 Oct 2021 13:54:27 -0700 Subject: [PATCH 17/17] remove prerelease tags --- .circleci/config.yml | 3 +-- package.json | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c579bbe0e..1ec4a38dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,7 +40,7 @@ aliases: [ &filter-default-branches { filters: { branches: { - ignore: "/^master$|^next$/|^dgerrells" + ignore: "/^master$|^next$/" } } }, @@ -52,7 +52,6 @@ aliases: [ only: [ "master", "next", - "dgerrells-ch42053-sms-feature" ] } } diff --git a/package.json b/package.json index c8ca63c4b..2757f5fda 100644 --- a/package.json +++ b/package.json @@ -80,9 +80,6 @@ "plugins": [ "npm", "released" - ], - "prereleaseBranches": [ - "dgerrells-ch42053-sms-feature" ] } }