Skip to content

Commit

Permalink
Recipe Module Manager in progress
Browse files Browse the repository at this point in the history
handleRoute

License to files + build

changes the npm run test command

remove npx from npm run test as it is unnecessary and would always fail

tsconfig.json es6 => es5

use package.json exports + remove useless index.js files at the base

use lowercase headers and query params

multiple changes

Add type descriptions

rename handleRoute => canHandleRoute

SuperTokens to singleton

getRoutingComponent

address bunch of feedbacks

dependencies fix

jsdom + canhHandleRoute + getRoutingComponent

Add routing component test with rid

add react-test-app

wip router

wip router

add recipe base

add tests for example app

Handle recipeId routing in react-router-dom

add emotion with shadow dom

use babel with emotion + utils tests

clean up

update npmignore

more clean up

react-router-dom verison up

fix syntax in EmailPassword init

add .gitattributes

fix gitattributes

test with query selectors in the shadow dom with puppeeter

recipeModule.init returns () => RecipeModule instead of RecipeModule
  • Loading branch information
kant01ne committed Oct 26, 2020
1 parent 71fc9e3 commit 8d5ed19
Show file tree
Hide file tree
Showing 69 changed files with 4,052 additions and 42 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
[
"@babel/preset-env"
]
]
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/build/* linguist-generated=true
4 changes: 1 addition & 3 deletions .mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ exit: true
spec: test/**/*.test.js
reporter: spec
slow: 20000
timeout: 30000
require:
- isomorphic-fetch
timeout: 30000
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
!**/*.d.ts
.git/
test/
react-test-app/
hooks/
.circleci/
lib/tsconfig.json
lib/babel.config.json
.mocharc.yml
lib/.prettierrc
lib/tslint.json
Expand Down
62 changes: 61 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
# Contributing

TODO
We're so excited you're interested in helping with SuperTokens! We are happy to help you get started, even if you don't have any previous open-source experience :blush:

## New to Open Source?
1. Take a look at [How to Contribute to an Open Source Project on GitHub](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github)
2. Go through the [SuperTokens Code of Conduct](https://github.com/supertokens/supertokens-auth-react/blob/master/CODE_OF_CONDUCT.md)

## Where to ask Questions?
1. Check our [Github Issues](https://github.com/supertokens/supertokens-auth-react/issues) to see if someone has already answered your question.
2. Join our community on [Discord](https://supertokens.io/discord) and feel free to ask us your questions


## Development Setup

### Prerequisites
- OS: Linux or macOS
- Nodejs & npm
- IDE: [VSCode](https://code.visualstudio.com/download)(recommended) or equivalent IDE

### Project Setup
1. `git clone https://github.com/supertokens/supertokens-auth-react.git`
3. `cd supertokens-auth-react`
4. Install the project dependencies
```
npm i -d
```
5. Add git pre-commit hooks
```
npm run set-up-hooks
```

## Modifying Code
1. Open the `supertokens-auth-react` project in your IDE.
2. You can start modifying the code.
3. After modification, you need to build the project:
```
npm run build-pretty
```

## Testing
1. `npm run test`


## Run the test application.
1. `(cd react-test-app && npm install)`
2. `./testApp.sh --start`


## Pull Request
1. Before submitting a pull request make sure all tests have passed
2. Reference the relevant issue or pull request and give a clear description of changes/features added when submitting a pull request

## SuperTokens Community
SuperTokens is made possible by a passionate team and a strong community of developers. If you have any questions or would like to get more involved in the SuperTokens community you can check out:
- [Github Issues](https://github.com/supertokens/supertokens-auth-react/issues)
- [Discord](https://supertokens.io/discord)
- [Twitter](https://twitter.com/supertokensio)
- or [email us](mailto:team@supertokens.io)

Additional resources you might find useful:
- [SuperTokens Docs](https://supertokens.io/docs/community/getting-started/installation)
- [Blog Posts](https://supertokens.io/blog/)
3 changes: 0 additions & 3 deletions index.d.ts

This file was deleted.

4 changes: 4 additions & 0 deletions lib/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@babel/preset-typescript', '@babel/preset-env', '@babel/preset-react'],
plugins: ["transform-class-properties"]
}
2 changes: 2 additions & 0 deletions lib/build/components/superTokensRoute.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="react" />
export declare function getSuperTokensRoutesForReactRouterDom(): JSX.Element[];
153 changes: 153 additions & 0 deletions lib/build/components/superTokensRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
"use strict";

function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function _typeof(obj) {
return typeof obj;
};
} else {
_typeof = function _typeof(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype
? "symbol"
: typeof obj;
};
}
return _typeof(obj);
}

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSuperTokensRoutesForReactRouterDom = getSuperTokensRoutesForReactRouterDom;

var React = _interopRequireWildcard(require("react"));

var _superTokens = _interopRequireDefault(require("../superTokens"));

var _utils = require("../utils");

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}

function _getRequireWildcardCache() {
if (typeof WeakMap !== "function") return null;
var cache = new WeakMap();
_getRequireWildcardCache = function _getRequireWildcardCache() {
return cache;
};
return cache;
}

function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
}
if (obj === null || (_typeof(obj) !== "object" && typeof obj !== "function")) {
return { default: obj };
}
var cache = _getRequireWildcardCache();
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj["default"] = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

/* Copyright (c) 2020, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

/*
* Imports.
*/

/*
* SuperTokensRouteWithRecipeId
* Using react-router-dom, we can only match based on the route and not on the combination of path and query params.
* having one route per component would lead to clashes when two components have the same route but different recipeId,
* the first one would always take precedence.
* Hence, the component rendered in the Route is an abstraction that decides which Feature to render based
* on the rId.
* See SuperTokensRouteWithRecipeId below.
*/
function getSuperTokensRoutesForReactRouterDom() {
try {
var pathsToComponentWithRecipeIdMap = {};

_superTokens["default"].getRecipeList().map(function(recipe) {
var features = recipe.getFeatures();
return Object.keys(features).map(function(featurePath) {
var fullPath = "".concat(_superTokens["default"].getAppInfo().websiteBasePath).concat(featurePath); // If no components yet for this route, initialize empty array.

if (pathsToComponentWithRecipeIdMap[fullPath] === undefined) {
pathsToComponentWithRecipeIdMap[fullPath] = [];
}

pathsToComponentWithRecipeIdMap[fullPath].push({
rid: recipe.getRecipeId(),
component: features[featurePath]
});
});
});

return Object.keys(pathsToComponentWithRecipeIdMap).map(function(path) {
return SuperTokensRouteWithRecipeId(path, pathsToComponentWithRecipeIdMap[path]);
});
} catch (e) {
return [];
}
}

function SuperTokensRouteWithRecipeId(path, routeComponents) {
var Route = require("react-router-dom").Route;

var recipeId = (0, _utils.getRecipeIdFromSearch)(window.location.search); // If recipeId provided, try to find a match.

if (recipeId !== null) {
for (var i = 0; i < routeComponents.length; i++) {
if (recipeId === routeComponents[i].rid) {
return /*#__PURE__*/ React.createElement(Route, {
exact: true,
key: "st-".concat(path),
path: path,
component: routeComponents[i].component
});
}
}
} // Otherwise, If no recipe Id provided, or if no recipe id matches, return the first matching component.

return /*#__PURE__*/ React.createElement(Route, {
exact: true,
key: "st-".concat(path),
path: path,
component: routeComponents[0].component
});
}
5 changes: 5 additions & 0 deletions lib/build/constants.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions lib/build/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion lib/build/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8d5ed19

Please sign in to comment.