Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bare React Native / Expo React Native Package Split #412

Merged
merged 27 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8431b6b
Create @magic-sdk/react-native-bare SDK
Ariflo Jan 3, 2023
73fe0ca
Create @magic-sdk/react-native-expo SDK
Ariflo Jan 3, 2023
33e288b
Updates @magic-sdk/provider SDK
Ariflo Jan 3, 2023
18a8898
Updates @magic-sdk/commons SDK
Ariflo Jan 3, 2023
c118fa7
Updates @magic-sdk/types SDK
Ariflo Jan 3, 2023
d6ec7b7
Adds @magic-ext/bare-react-native-oauth SDK
Ariflo Jan 3, 2023
9760799
Adds @magic-ext/expo-react-native-oauth SDK
Ariflo Jan 3, 2023
51fa01d
Updates compatibility version for bare oauth
Ariflo Jan 3, 2023
bc9e928
Adds version patch to new SDKs
Ariflo Jan 3, 2023
b4461b5
Updates build scripts to include new packages
Ariflo Jan 3, 2023
1405b69
Updates react-native-bare package README
Ariflo Jan 3, 2023
f0ae707
Updates @magic-ext/oauth compatibility settings
Ariflo Jan 3, 2023
42842c4
Updates main README
Ariflo Jan 3, 2023
e82e1fe
Removes Legacy @magic-sdk/react-native package
Ariflo Jan 3, 2023
917b2de
Removes Legacy @magic-ext/react-native-oauth package
Ariflo Jan 3, 2023
02b7c24
Upates @magic-sdk/react-native-expo patch version
Ariflo Jan 3, 2023
72aaf43
Update OAuth package names and adds peer dependencies
Ariflo Jan 4, 2023
75ef4d5
Update Yarn.lock
Ariflo Jan 5, 2023
2f180ed
Remove Legacy Packages
Ariflo Jan 5, 2023
97296cd
Update oauth package names and fix lint errors
Ariflo Jan 5, 2023
f0ccf7b
fix lint errors
Ariflo Jan 5, 2023
ff1fac6
More Yarn.lock updates
Ariflo Jan 5, 2023
22460a0
Fix Tests
Ariflo Jan 5, 2023
f6e1714
Expo README Update
Ariflo Jan 6, 2023
13080e3
Update core package versions
Ariflo Jan 6, 2023
4534149
Yarn update
Ariflo Jan 6, 2023
e2ea3c8
Maintains backwards compatibility
Ariflo Jan 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD_SYSTEM.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ We generate multiple outputs in order to maximize backwards compatibility and in
// One of: node | browser | neutral
//
// node: Targets Node-like runtimes; used for React Native & server-side
// packages (i.e.: `@magic-sdk/react-native`)
// packages (i.e.: `@magic-sdk/react-native-bare`)
//
// browser: Targets web-like runtimes; used for web-only packages
// (i.e.: `magic-sdk`)
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
## πŸ“– Documentation

- See the [developer documentation](https://docs.magic.link) to learn how you can master the Magic SDK in a matter of minutes.
- See the `@magic-sdk/react-native` [README](https://github.com/magiclabs/magic-js/tree/master/packages/%40magic-sdk/react-native#readme) for package specific information.
- See the `@magic-sdk/react-native-bare` [README](https://github.com/magiclabs/magic-js/tree/master/packages/%40magic-sdk/react-native-bare#readme) for Bare React Native package specific information.
- See the `@magic-sdk/react-native-expo` [README](https://github.com/magiclabs/magic-js/tree/master/packages/%40magic-sdk/react-native-expo#readme) for Expo React Native package specific information.

## ⚑️ Quick Start

Expand All @@ -24,14 +25,16 @@ Integrating your app with Magic will require our client-side NPM package:
```bash
# Via NPM:
npm install --save magic-sdk # If you're targeting web browsers
npm install --save @magic-sdk/react-native # If you're targeting React Native
npm install --save @magic-sdk/react-native-bare # If you're targeting Bare React Native
npm install --save @magic-sdk/react-native-expo # If you're targeting Expo React Native

# Via Yarn:
yarn add magic-sdk # If you're targeting web browsers
yarn add @magic-sdk/react-native # If you're targeting React Native
yarn add @magic-sdk/react-native-bare # If you're targeting Bare React Native
yarn add @magic-sdk/react-native-expo # If you're targeting Expo React Native
```

Alternatively, you can load via CDN with by adding a script tag to your app’s `<head>`:
Alternatively, you can load via CDN by adding a script tag to your app’s `<head>`:

```html
<script src="https://cdn.jsdelivr.net/npm/magic-sdk/dist/magic.js"></script>
Expand Down Expand Up @@ -60,7 +63,8 @@ These are packages _you_ can install to enable Magic JS SDK functionality for yo
| Package Name | Changelog | Description |
| ------------ | --------- | ----------- |
| [`magic-sdk`](https://www.npmjs.com/package/magic-sdk) | [CHANGELOG](./packages/magic-sdk/CHANGELOG.md) | Web/browser entry-point for Magic SDK. |
| [`@magic-sdk/react-native`](https://www.npmjs.com/package/@magic-sdk/react-native) | [CHANGELOG](./packages/@magic-sdk/react-native/CHANGELOG.md) | React Native entry-point for Magic SDK. |
| [`@magic-sdk/react-native-bare`](https://www.npmjs.com/package/@magic-sdk/react-native-bare) | [CHANGELOG](./packages/@magic-sdk/react-native-bare/CHANGELOG.md) | Bare React Native entry-point for Magic SDK. |
| [`@magic-sdk/react-native-expo`](https://www.npmjs.com/package/@magic-sdk/react-native-expo) | [CHANGELOG](./packages/@magic-sdk/react-native-expo/CHANGELOG.md) | Expo React Native entry-point for Magic SDK. |

## Extensions

Expand Down Expand Up @@ -88,7 +92,8 @@ yarn test
Test an individual package
```bash
PKG=magic-sdk yarn test
PKG=@magic-sdk/react-native yarn test
PKG=@magic-sdk/react-native-bare yarn test
PKG=@magic-sdk/react-native-expo yarn test
```

Test specific files
Expand Down
2 changes: 2 additions & 0 deletions packages/@magic-ext/oauth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class OAuthExtension extends Extension.Internal<'oauth'> {
compat = {
'magic-sdk': '>=2.4.6',
'@magic-sdk/react-native': false,
'@magic-sdk/react-native-bare': false,
'@magic-sdk/react-native-expo': false,
};

public loginWithRedirect(configuration: OAuthRedirectConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# v6.0.0 (Thu Jan 05 2023)

#### πŸ› Bug Fix

- Fix ESLint Issues [#419](https://github.com/magiclabs/magic-js/pull/419) ([@Ariflo](https://github.com/Ariflo))
- Cast json to string for oauth ([@Ariflo](https://github.com/Ariflo))

#### Authors: 1

- Arian Flores ([@Ariflo](https://github.com/Ariflo))

---

# v5.0.0 (Tue Dec 20 2022)

#### πŸ› Bug Fix
Expand Down
5 changes: 5 additions & 0 deletions packages/@magic-ext/react-native-bare-oauth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@





40 changes: 40 additions & 0 deletions packages/@magic-ext/react-native-bare-oauth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@magic-ext/react-native-bare-oauth",
"version": "7.0.0",
"description": "Magic SDK OAuth Extension for Bare React Native environments.",
"author": "Magic <[email protected]> (https://magic.link/)",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/magiclabs/magic-js"
},
"files": [
"dist"
],
"target": "node",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
"import": "./dist/es/index.mjs",
"require": "./dist/cjs/index.js"
},
"externals": {
"include": [
"@magic-sdk/react-native-bare"
]
},
"dependencies": {
"@magic-sdk/types": "^10.0.1",
"crypto-js": "^3.3.0",
"react-native-device-info": "^10.3.0",
"react-native-inappbrowser-reborn": "^3.7.0"
},
"devDependencies": {
"@magic-sdk/react-native-bare": "^13.0.1",
"@types/crypto-js": "~3.1.47"
},
"peerDependencies": {
"@magic-sdk/react-native-bare": ">=13.0.0"
}
}
133 changes: 133 additions & 0 deletions packages/@magic-ext/react-native-bare-oauth/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { InAppBrowser } from 'react-native-inappbrowser-reborn';
import { Extension } from '@magic-sdk/react-native-bare';
import { getBundleId } from 'react-native-device-info';
import { createCryptoChallenge } from './crypto';
import {
OAuthErrorData,
OAuthPayloadMethods,
OAuthRedirectConfiguration,
OAuthRedirectError,
OAuthRedirectResult,
} from './types';

export class OAuthExtension extends Extension.Internal<'oauth'> {
name = 'oauth' as const;
config = {};
compat = {
'magic-sdk': false,
'@magic-sdk/react-native-bare': '>=13.0.0',
'@magic-sdk/react-native-expo': false,
'@magic-sdk/react-native': false,
};

public loginWithPopup(configuration: OAuthRedirectConfiguration) {
return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {
try {
const { provider, query, redirectURI } = await createURI.call(this, configuration);
const url = `https://auth.magic.link/v1/oauth2/${provider}/start?${query}`;

/**
* Response Type Inspired by:
* https://docs.expo.io/versions/latest/sdk/webbrowser/#returns
*/
const res = await InAppBrowser.openAuth(url, redirectURI, {});

if (res.type === 'success') {
const queryString = new URL(res.url).search;

resolve(getResult.call(this, queryString.toString()));
} else {
reject(this.createError<object>(res.type, 'User has cancelled the authentication', {}));
}
} catch (err: any) {
reject(
this.createError<object>(err.message, 'An error has occurred', {
err,
}),
);
}
});
}
}

const OAUTH_REDIRECT_METADATA_KEY = 'oauth_redirect_metadata';

export async function createURI(this: OAuthExtension, configuration: OAuthRedirectConfiguration) {
// Bust any old, in-progress OAuth flows.
await this.utils.storage.removeItem(OAUTH_REDIRECT_METADATA_KEY);

// Unpack configuration, generate crypto values, and persist to storage.
const { provider, redirectURI, scope, loginHint } = configuration;
const { verifier, challenge, state } = await createCryptoChallenge();
const bundleId = getBundleId();

/* Stringify for RN Async storage */
const storedData = JSON.stringify({
verifier,
state,
});

await this.utils.storage.setItem(OAUTH_REDIRECT_METADATA_KEY, storedData);

// Formulate the initial redirect query to Magic's OAuth hub.
// Required fields:
// - `magic_api_key`
// - `magic_challenge`
// - `state`
// - `redirect_uri`
// - `platform`
// Optional fields:
// - `bundleId`

const query = [
`magic_api_key=${encodeURIComponent(this.sdk.apiKey)}`,
`magic_challenge=${encodeURIComponent(challenge)}`,
`state=${encodeURIComponent(state)}`,
`platform=${encodeURIComponent('rn')}`,
scope && `scope=${encodeURIComponent(scope.join(' '))}`,
redirectURI && `redirect_uri=${encodeURIComponent(redirectURI)}`,
loginHint && `login_hint=${encodeURIComponent(loginHint)}`,
bundleId && `bundleId=${encodeURIComponent(bundleId)}`,
].reduce((prev, next) => (next ? `${prev}&${next}` : prev));

return {
query,
provider,
redirectURI,
};
}

export function getResult(this: OAuthExtension, queryString: string) {
return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {
const json: string = (await this.utils.storage.getItem(OAUTH_REDIRECT_METADATA_KEY)) as string;

const { verifier, state } = JSON.parse(json);

// Remove the save OAuth state from storage, it stays in memory now...
this.utils.storage.removeItem(OAUTH_REDIRECT_METADATA_KEY);

const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.ParseRedirectResult, [
queryString,
verifier,
state,
]);

// Parse the result, which may contain an OAuth-formatted error.
const resultOrError = await this.request<OAuthRedirectResult | OAuthRedirectError>(parseRedirectResult);
const maybeResult = resultOrError as OAuthRedirectResult;
const maybeError = resultOrError as OAuthRedirectError;

if (maybeError.error) {
reject(
this.createError<OAuthErrorData>(maybeError.error, maybeError.error_description ?? 'An error occurred.', {
errorURI: maybeError.error_uri,
provider: maybeError.provider,
}),
);
}

resolve(maybeResult);
});
}

export * from './types';
5 changes: 5 additions & 0 deletions packages/@magic-ext/react-native-expo-oauth/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/coverage
/dist
/.eslintrc.js
/jest.config.ts
7 changes: 7 additions & 0 deletions packages/@magic-ext/react-native-expo-oauth/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['../../../.eslintrc.js'],
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
}
110 changes: 110 additions & 0 deletions packages/@magic-ext/react-native-expo-oauth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# v5.0.0 (Tue Dec 20 2022)

#### πŸ› Bug Fix

- Merge branch 'master' into mushfichowdhury-sc-61149-implement-event-emitting-in-magic-sdk-based ([@mushfichowdhury-magic](https://github.com/mushfichowdhury-magic))
- Adds more Context about Expo dependency in `@magic-ext/react-native-oauth` to README [#386](https://github.com/magiclabs/magic-js/pull/386) ([@Ariflo](https://github.com/Ariflo))

#### ⚠️ Pushed to `master`

- Add bundleId to the OAuth query ([@Ethella](https://github.com/Ethella))

#### Authors: 3

- Arian Flores ([@Ariflo](https://github.com/Ariflo))
- Jerry Liu ([@Ethella](https://github.com/Ethella))
- Mushfi Chowdhury ([@mushfichowdhury-magic](https://github.com/mushfichowdhury-magic))

---

# v3.1.0 (Wed Aug 10 2022)

#### πŸš€ Enhancement

- bump web-expo-browser version [#345](https://github.com/magiclabs/magic-js/pull/345) ([@Ethella](https://github.com/Ethella))

#### Authors: 1

- Jerry Liu ([@Ethella](https://github.com/Ethella))

---

# v2.2.0 (Mon Mar 07 2022)

#### πŸ› Bug Fix

- Merge branch 'master' into smithki/better-build-system-documentation ([@smithki](https://github.com/smithki))

#### Authors: 1

- Ian K Smith ([@smithki](https://github.com/smithki))

---

# v2.0.0 (Tue Jan 25 2022)

#### πŸ’₯ Breaking Change

- Switch from `microbundle` to `esbuild` [#220](https://github.com/magiclabs/magic-js/pull/220) ([@smithki](https://github.com/smithki))

#### πŸ› Bug Fix

- Merge with master ([@smithki](https://github.com/smithki))
- Merge branch 'master' into feat/faster-builds ([@smithki](https://github.com/smithki))
- Fix build errors related to isolatedModules ([@smithki](https://github.com/smithki))

#### Authors: 1

- Ian K Smith ([@smithki](https://github.com/smithki))

---

# v0.5.4 (Thu Oct 21 2021)

#### πŸ› Bug Fix

- Revert to `.js` extension for ES module builds targeting webpack/CRA [#232](https://github.com/magiclabs/magic-js/pull/232) ([@smithki](https://github.com/smithki))

#### Authors: 1

- Ian K Smith ([@smithki](https://github.com/smithki))

---

# v0.5.3 (Wed Oct 20 2021)

#### ⚠️ Pushed to `master`

- Merge branch 'master' of github.com:magiclabs/magic-js ([@smithki](https://github.com/smithki))
- Force re-publish ([@smithki](https://github.com/smithki))

#### Authors: 1

- Ian K Smith ([@smithki](https://github.com/smithki))

---

# v0.5.2 (Wed Oct 20 2021)

#### πŸ› Bug Fix

- Use '.mjs' extension for ESM build files [#230](https://github.com/magiclabs/magic-js/pull/230) ([@smithki](https://github.com/smithki))

#### Authors: 1

- Ian K Smith ([@smithki](https://github.com/smithki))

---

# v0.4.1 (Thu Sep 23 2021)

#### πŸ› Bug Fix

- Port `@magic-ext/oauth`, `@magic-ext/react-native-oauth`, `@magic-ext/webauthn` extensions to Magic SDK monorepo [#218](https://github.com/magiclabs/magic-js/pull/218) ([@smithki](https://github.com/smithki))

#### Authors: 1

- Ian K Smith ([@smithki](https://github.com/smithki))

---

Loading