Skip to content

Commit

Permalink
Merge pull request #13 from vtex-apps/add/typescript
Browse files Browse the repository at this point in the history
🏗️ Migrate to TypeScript
  • Loading branch information
carolkrroo authored Aug 19, 2022
2 parents 90298f1 + e40ef03 commit 1abd5f2
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 83 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ build/Release
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Migrate to TypeScript

## [1.0.7] - 2019-12-26

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ In our *Payment* app, this validation is performed through the `transactionValid

```javascript
respondTransaction = (status) => {
$(window).trigger('transactionValidation.vtex', [status])
window.$(window).trigger('transactionValidation.vtex', [status])
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ In our *Payment* app, this validation is performed through the `transactionValid

```javascript
respondTransaction = (status) => {
$(window).trigger('transactionValidation.vtex', [status])
window.$(window).trigger('transactionValidation.vtex', [status])
}
```

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"version": "1.0.7",
"devDependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6"
"@types/node": "12.6.2",
"@vtex/prettier-config": "^1.0.0",
"typescript": "3.9.7"
}
}
53 changes: 36 additions & 17 deletions react/index.js → react/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import React, { Component, Fragment } from 'react'
import styles from './index.css'

class ExampleTransactionAuthApp extends Component {
constructor(props) {
interface InjectScriptProps {
id: string
src: string
onLoad: (this: GlobalEventHandlers, ev: Event) => void
}

type Props = {
appPayload: string
}

type State = {
scriptLoaded: boolean
loading: boolean
}

class ExampleTransactionAuthApp extends Component<Props, State> {
divContainer: React.RefObject<HTMLDivElement>

constructor(props: Props) {
super(props)
this.state = {
scriptLoaded: false,
Expand All @@ -13,34 +30,36 @@ class ExampleTransactionAuthApp extends Component {
}

componentWillMount = () => {
this.injectScript(
'google-recaptcha-v2',
'https://recaptcha.net/recaptcha/api.js?render=explicit',
this.handleOnLoad
)
this.injectScript({
id: 'google-recaptcha-v2',
src: 'https://recaptcha.net/recaptcha/api.js?render=explicit',
onLoad: this.handleOnLoad
})
}

componentDidMount() {
// In case you want to remove payment loading in order to show an UI.
$(window).trigger('removePaymentLoading.vtex')
window.$(window).trigger('removePaymentLoading.vtex')
}

respondTransaction = status => {
$(window).trigger('transactionValidation.vtex', [status])
respondTransaction = (status: boolean) => {
window.$(window).trigger('transactionValidation.vtex', [status])
}

handleOnLoad = () => {
this.setState({ scriptLoaded: true })
grecaptcha.ready(() => {
grecaptcha.render(this.divContainer.current, {
sitekey: '------>REPATCHA_V2_SITE_KEY<------', //Replace with site key
theme: 'dark',
callback: this.onVerify,
})
if (this.divContainer.current) {
grecaptcha.render(this.divContainer.current, {
sitekey: '------>REPATCHA_V2_SITE_KEY<------', //Replace with site key
theme: 'dark',
callback: this.onVerify,
})
}
})
}

onVerify = e => {
onVerify = () => {
const parsedPayload = JSON.parse(this.props.appPayload)
this.setState({ loading: true })

Expand All @@ -67,7 +86,7 @@ class ExampleTransactionAuthApp extends Component {
})
}

injectScript = (id, src, onLoad) => {
injectScript = ({ id, src, onLoad }: InjectScriptProps) => {
if (document.getElementById(id)) {
return
}
Expand Down
10 changes: 9 additions & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@
"version": "1.0.6",
"main": "index.js",
"license": "MIT",
"dependencies": {}
"dependencies": {
"react": "16.8.6",
"react-dom": "16.8.6"
},
"devDependencies": {
"@types/grecaptcha": "^3.0.4",
"@types/node": "12.6.2",
"@types/react": "16.8.6"
}
}
20 changes: 20 additions & 0 deletions react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"types": ["node", "grecaptcha"],
"allowSyntheticDefaultImports": true,
"jsx": "preserve",
"lib": ["es2017", "dom", "esnext"],
"sourceMap": true,
"skipLibCheck": true,
"strict": true,
"resolveJsonModule": true,
"module": "esnext",
"moduleResolution": "node",
"target": "es2017"
},
"typeAcquisition": {
"enable": false
},
"include": ["./**/*"],
"exclude": ["node_modules"]
}
12 changes: 12 additions & 0 deletions react/typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module '*.css' {
interface IClassNames {
[className: string]: string
}
const classNames: IClassNames
export = classNames
}

interface Window {
vtexjs: VTEXJS
$: any // JQuery types
}
86 changes: 86 additions & 0 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,89 @@
# yarn lockfile v1


"@types/grecaptcha@^3.0.4":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@types/grecaptcha/-/grecaptcha-3.0.4.tgz#3de601f3b0cd0298faf052dd5bd62aff64c2be2e"
integrity sha512-7l1Y8DTGXkx/r4pwU1nMVAR+yD/QC+MCHKXAyEX/7JZhwcN1IED09aZ9vCjjkcGdhSQiu/eJqcXInpl6eEEEwg==

"@types/node@12.6.2":
version "12.6.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.2.tgz#a5ccec6abb6060d5f20d256fb03ed743e9774999"
integrity sha512-gojym4tX0FWeV2gsW4Xmzo5wxGjXGm550oVUII7f7G5o4BV6c7DBdiG1RRQd+y1bvqRyYtPfMK85UM95vsapqQ==

"@types/prop-types@*":
version "15.7.5"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==

"@types/react@16.8.6":
version "16.8.6"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.6.tgz#fa1de3fe56cc9b6afeddc73d093d7f30fd5e31cc"
integrity sha512-bN9qDjEMltmHrl0PZRI4IF2AbB7V5UlRfG+OOduckVnRQ4VzXVSzy/1eLAh778IEqhTnW0mmgL9yShfinNverA==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"

csstype@^2.2.0:
version "2.6.20"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.20.tgz#9229c65ea0b260cf4d3d997cb06288e36a8d6dda"
integrity sha512-/WwNkdXfckNgw6S5R125rrW8ez139lBHWouiBvX8dfMFtcn6V81REDqnH7+CRpRipfYlyU1CmOnOxrmGcFOjeA==

"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

loose-envify@^1.1.0, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==

prop-types@^15.6.2:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
dependencies:
loose-envify "^1.4.0"
object-assign "^4.1.1"
react-is "^16.13.1"

react-dom@16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.6.tgz#71d6303f631e8b0097f56165ef608f051ff6e10f"
integrity sha512-1nL7PIq9LTL3fthPqwkvr2zY7phIPjYrT0jp4HjyEQrEROnw4dG41VVwi/wfoCneoleqrNX7iAD+pXebJZwrwA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.6"

react-is@^16.13.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react@16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe"
integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.6"

scheduler@^0.13.6:
version "0.13.6"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889"
integrity sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
77 changes: 19 additions & 58 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,22 @@
# yarn lockfile v1


"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

loose-envify@^1.1.0, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=

prop-types@^15.6.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
dependencies:
loose-envify "^1.4.0"
object-assign "^4.1.1"
react-is "^16.8.1"

react-dom@^16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.6.tgz#71d6303f631e8b0097f56165ef608f051ff6e10f"
integrity sha512-1nL7PIq9LTL3fthPqwkvr2zY7phIPjYrT0jp4HjyEQrEROnw4dG41VVwi/wfoCneoleqrNX7iAD+pXebJZwrwA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.6"

react-is@^16.8.1:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==

react@^16.8.6:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe"
integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.6"

scheduler@^0.13.6:
version "0.13.6"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889"
integrity sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
"@types/grecaptcha@^3.0.4":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@types/grecaptcha/-/grecaptcha-3.0.4.tgz#3de601f3b0cd0298faf052dd5bd62aff64c2be2e"
integrity sha512-7l1Y8DTGXkx/r4pwU1nMVAR+yD/QC+MCHKXAyEX/7JZhwcN1IED09aZ9vCjjkcGdhSQiu/eJqcXInpl6eEEEwg==

"@types/node@^18.7.2":
version "18.7.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.7.2.tgz#22306626110c459aedd2cdf131c749ec781e3b34"
integrity sha512-ce7MIiaYWCFv6A83oEultwhBXb22fxwNOQf5DIxWA4WXvDQ7K+L0fbWl/YOfCzlR5B/uFkSnVBhPcOfOECcWvA==

"@vtex/prettier-config@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@vtex/prettier-config/-/prettier-config-1.0.0.tgz#a7a7091ecff1da340d398000f4855dc9910aa9c9"
integrity sha512-4Uv67bK2eORhzWg/11J5/+fxPUWY6b0sYdhcqMzIgo0zluXlYqbZU6iueKZ48SxG4ODw8ZaqMRfpNsLd3Gw5+Q==

typescript@^4.7.4:
version "4.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

0 comments on commit 1abd5f2

Please sign in to comment.