-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Procaptcha-bundle: renderLogic improvements and introducing "for-devs…
….md" (#1563)
- Loading branch information
1 parent
2fdbbf4
commit daad137
Showing
11 changed files
with
454 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
## Developer Information | ||
|
||
This file is intended for developers. It provides details on the project's structure and instructions on how to work | ||
with it. | ||
|
||
### 1. Commands | ||
|
||
* Installation: `npm install` | ||
* Building packages: `npm run build:all` | ||
* Building the bundle: `npm run build:bundle` | ||
* Linting: `npm run lint-fix` (formatting & code validation) | ||
|
||
### 2. Environment Setup for Tests (Once) | ||
|
||
To set up the environment for testing, run the following commands: | ||
|
||
``` | ||
cp demos/client-example-server/env.development demos/client-example-server/.env.test | ||
cp demos/client-example/env.development demos/client-example/.env.test | ||
cp demos/client-bundle-example/env.development demos/client-bundle-example/.env.test | ||
cp dev/scripts/env.test .env.test | ||
cp dev/scripts/env.test dev/scripts/.env.test | ||
cp dev/scripts/env.test packages/cli/.env.test | ||
cp dev/scripts/env.test packages/procaptcha-bundle/.env.test | ||
``` | ||
|
||
### 3. Running E2E Client Tests Locally | ||
|
||
#### 3.1) Launching services | ||
|
||
The DB is docked, and to start the DB service, run the following: | ||
|
||
``` | ||
docker compose --file ./docker/docker-compose.test.yml up -d --remove-orphans --force-recreate --always-recreate-deps | ||
NODE_ENV="test" npm run setup | ||
``` | ||
|
||
> Note: the second command should be called once per the container lifetime, and adds the initial data, like domains, | ||
> siteKeys, etc. | ||
Then start the services: | ||
|
||
``` | ||
npm run -w @prosopo/client-example-server build && NODE_ENV=test npm run start:server | ||
NODE_ENV=test npm run start:demo | ||
NODE_ENV=test npm run start:provider:admin | ||
``` | ||
|
||
#### 3.2) Running the Tests | ||
|
||
``` | ||
NODE_ENV=test npm run -w @prosopo/cypress-shared cypress:open:client-example | ||
``` | ||
|
||
#### 3.3) Stopping Docker Services | ||
|
||
After the tests finish, stop the Docker services with: | ||
|
||
``` | ||
docker compose --file ./docker/docker-compose.test.yml down | ||
``` | ||
|
||
### 4. Running E2E Bundle Tests Locally | ||
|
||
#### 4.1) Launching Services | ||
|
||
For bundle tests, use the same services as for the E2E client tests, plus the following: | ||
|
||
``` | ||
NODE_ENV="development" npm -w @prosopo/procaptcha-bundle run bundle | ||
NODE_ENV=test npm run start:bundle | ||
``` | ||
|
||
#### 4.2) Running the Tests | ||
|
||
``` | ||
NODE_ENV=test npm -w @prosopo/cypress-shared run cypress:open:client-bundle-example | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/procaptcha-bundle/src/util/renderLogic/captcha/captcha.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2021-2024 Prosopo (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// 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. | ||
import type { ProcaptchaClientConfigOutput } from "@prosopo/types"; | ||
import React from "react"; | ||
import type { Callbacks } from "../../defaultCallbacks.js"; | ||
|
||
interface CaptchaProps { | ||
config: ProcaptchaClientConfigOutput; | ||
callbacks: Callbacks; | ||
} | ||
|
||
abstract class CaptchaElement extends React.Component<CaptchaProps> {} | ||
|
||
export { type CaptchaProps, CaptchaElement }; |
37 changes: 37 additions & 0 deletions
37
packages/procaptcha-bundle/src/util/renderLogic/captcha/captchaRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2021-2024 Prosopo (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// 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. | ||
import type { FeaturesEnum } from "@prosopo/types"; | ||
import type { ReactNode } from "react"; | ||
import type { CaptchaProps } from "./captcha.js"; | ||
import { componentsList } from "./componentsList.js"; | ||
|
||
class CaptchaRenderer { | ||
public render( | ||
captchaType: FeaturesEnum, | ||
captchaProps: CaptchaProps, | ||
): ReactNode { | ||
const CaptchaComponent = componentsList[captchaType]; | ||
|
||
console.log(`rendering ${captchaType}`); | ||
|
||
return ( | ||
<CaptchaComponent | ||
config={captchaProps.config} | ||
callbacks={captchaProps.callbacks} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export { CaptchaRenderer }; |
26 changes: 26 additions & 0 deletions
26
packages/procaptcha-bundle/src/util/renderLogic/captcha/components/frictionlessCaptcha.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2021-2024 Prosopo (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// 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. | ||
import { ProcaptchaFrictionless } from "@prosopo/procaptcha-frictionless"; | ||
import React from "react"; | ||
import { CaptchaElement } from "../captcha.js"; | ||
|
||
class FrictionlessCaptcha extends CaptchaElement { | ||
public override render() { | ||
const { config, callbacks } = this.props; | ||
|
||
return <ProcaptchaFrictionless config={config} callbacks={callbacks} />; | ||
} | ||
} | ||
|
||
export { FrictionlessCaptcha }; |
26 changes: 26 additions & 0 deletions
26
packages/procaptcha-bundle/src/util/renderLogic/captcha/components/imageCaptcha.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2021-2024 Prosopo (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// 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. | ||
import { Procaptcha } from "@prosopo/procaptcha-react"; | ||
import React from "react"; | ||
import { CaptchaElement } from "../captcha.js"; | ||
|
||
class ImageCaptcha extends CaptchaElement { | ||
public override render() { | ||
const { config, callbacks } = this.props; | ||
|
||
return <Procaptcha config={config} callbacks={callbacks} />; | ||
} | ||
} | ||
|
||
export { ImageCaptcha }; |
26 changes: 26 additions & 0 deletions
26
packages/procaptcha-bundle/src/util/renderLogic/captcha/components/powCaptcha.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2021-2024 Prosopo (UK) Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// 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. | ||
import { ProcaptchaPow } from "@prosopo/procaptcha-pow"; | ||
import React from "react"; | ||
import { CaptchaElement } from "../captcha.js"; | ||
|
||
class PowCaptcha extends CaptchaElement { | ||
public override render() { | ||
const { config, callbacks } = this.props; | ||
|
||
return <ProcaptchaPow config={config} callbacks={callbacks} />; | ||
} | ||
} | ||
|
||
export { PowCaptcha }; |
Oops, something went wrong.