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

Appsrn 264 documentacion de package y GitHub actions #3

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
25 changes: 25 additions & 0 deletions .github/workflows/buid-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build Status

on:
push:
branches: [ '*' ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm i -f

- run: npm run test:coverage

32 changes: 32 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Readme

on:
push:
tags: [ '*' ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:

- uses: actions/checkout@v3

- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: build readme
run: |
npm install -f
npm run build-docs
- name: auto-commit
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'build readme file'
24 changes: 24 additions & 0 deletions .github/workflows/coverage-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Coverage Status

on:
push:
branches:
- '**'

jobs:
coverage:
name: Coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install dependencies
run: npm install -f
- name: Run coverage
run: npm run test:coverage


43 changes: 43 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: NPM Publish

on:
push:
tags: [ '*' ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm i -f
- run: npm run test:coverage

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}


send-slack-message:
needs: publish-npm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: bash ./scripts/release-notes.sh
env:
RELEASE_SLACK_WEBHOOK_URL: ${{secrets.RELEASE_SLACK_WEBHOOK_URL}}
118 changes: 118 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# @janiscommerce/app-push-notification

![janis-logo](brand-logo.png)

Library for receiving notifications issued from firebase/janis.


## PeerDependencies installation:

In order to receive notifications it is necessary to include the dependency


```javascript
npm install @react-native-firebase/messaging
```

## Installation:


```javascript
npm install @janis-commerce/app-push-notification
```


## What is received from firebase?

What is received is an object called RemoteMessage, which contains the data emitted from Firebase and is what triggers the notification listeners.
Inside remoteMessage you get the notifications object that contains the information that we could use to render a component with the application in the foreground

For more information about this, read https://rnfirebase.io/reference/messaging/remotemessage

This library provides the following components and methods:

## Functions

<dl>
<dt><a href="#useNotification">useNotification()</a> ⇒ <code>object</code></dt>
<dd><p>is a hook, which returns the elements contained within the notifications context. Returns an object containing:</p>
<table>
<thead>
<tr>
<th>name</th>
<th>description</th>
</tr>
</thead>
<tbody><tr>
<td>deviceToken</td>
<td>is the token linked to the device, which we use to subscribe it to notifications.</td>
</tr>
</tbody></table>
</dd>
<dt><a href="#NotificationProvider">NotificationProvider(children, foregroundCallback, backgroundCallback, config, events, environment)</a> ⇒ <code>null</code> | <code>React.element</code></dt>
<dd><p>It is the main component of the package, it is a HOC that is responsible for handling the logic of subscribing to notifications and receiving messages from the Firebase console. The HOC contains listeners to listen to notifications in the foreground and background, so (unless we cancel the subscription), we will receive notifications from the app even when it is closed.</p>
</dd>
</dl>

<a name="useNotification"></a>

## useNotification() ⇒ <code>object</code>
is a hook, which returns the elements contained within the notifications context. Returns an object containing:
| name | description |
|----------|----------|
| deviceToken | is the token linked to the device, which we use to subscribe it to notifications. |

**Kind**: global function
**Example**
```js
import {useNotification} from '@janiscommerce/app-push-notification'

const {} = useNotification()
```
<a name="NotificationProvider"></a>

## NotificationProvider(children, foregroundCallback, backgroundCallback, config, events, environment) ⇒ <code>null</code> \| <code>React.element</code>
It is the main component of the package, it is a HOC that is responsible for handling the logic of subscribing to notifications and receiving messages from the Firebase console. The HOC contains listeners to listen to notifications in the foreground and background, so (unless we cancel the subscription), we will receive notifications from the app even when it is closed.

**Kind**: global function
**Throws**:

- null when not receive a children argument


| Param | Type | Description |
| --- | --- | --- |
| children | <code>React.element</code> | Component that will be rendered within the HOC, and about which the notification will be displayed |
| foregroundCallback | <code>function</code> | function that will be executed when a foreground notification is received. |
| backgroundCallback | <code>function</code> | function that will be executed when a background notification is received. |
| config | <code>object</code> | It is an object that contains the user's data, which will be used to subscribe the user to notifications. |
| config.appName | <code>string</code> | name of the aplication |
| config.accessToken | <code>string</code> | accessToken provided by janis |
| config.client | <code>string</code> | client provided by janis |
| events | <code>Array.&lt;string&gt;</code> | is an array that will contain the events to which the user wants to subscribe |
| environment | <code>string</code> | The environment is necessary for the API that we are going to use to subscribe the device to notifications. |

**Example**
```js
import NotificationProvider from '@janiscommerce/app-push-notification'


//...

const foregroundCallback = (remoteMessage) => console.log('a new FCM:',remoteMessage)
const backgrounCallback = (remoteMessage) => {
console.log('a new FCM was received in background', remoteMessage)
}

return (
<NotificationProvider
foregroundCallback={foregroundCallback}
backgroundCallback={backgroundCallback}
config={client:'fizzmod', accessToken:'access_token_push', appName:'janisAppName'}
events={['Notification','events','janis']}
environment='beta'
>
<MyComponent/>
</NotificationProvider>
)
```
13 changes: 13 additions & 0 deletions lib/NotificationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ import React from 'react';

export const NotificationContext = React.createContext(null);

/**
* @function useNotification
* @description is a hook, which returns the elements contained within the notifications context. Returns an object containing:
* | name | description |
* |----------|----------|
* | deviceToken | is the token linked to the device, which we use to subscribe it to notifications. |
* @returns {object}
* @example
* import {useNotification} from '@janiscommerce/app-push-notification'
*
* const {} = useNotification()
*/

export const useNotification = () => React.useContext(NotificationContext);
39 changes: 39 additions & 0 deletions lib/NotificationProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@ import {
topicsSubscription,
} from '../utils';

/**
* @function NotificationProvider
* @description It is the main component of the package, it is a HOC that is responsible for handling the logic of subscribing to notifications and receiving messages from the Firebase console. The HOC contains listeners to listen to notifications in the foreground and background, so (unless we cancel the subscription), we will receive notifications from the app even when it is closed.
* @param {React.element} children Component that will be rendered within the HOC, and about which the notification will be displayed
* @param {function} foregroundCallback function that will be executed when a foreground notification is received.
* @param {function} backgroundCallback function that will be executed when a background notification is received.
* @param {object} config It is an object that contains the user's data, which will be used to subscribe the user to notifications.
* @param {string} config.appName name of the aplication
* @param {string} config.accessToken accessToken provided by janis
* @param {string} config.client client provided by janis
* @param {Array<string>} events is an array that will contain the events to which the user wants to subscribe
* @param {string} environment The environment is necessary for the API that we are going to use to subscribe the device to notifications.
* @throws null when not receive a children argument
* @returns {null | React.element}
* @example
*
* import NotificationProvider from '@janiscommerce/app-push-notification'
*
*
* //...
*
* const foregroundCallback = (remoteMessage) => console.log('a new FCM:',remoteMessage)
* const backgrounCallback = (remoteMessage) => {
* console.log('a new FCM was received in background', remoteMessage)
* }
*
* return (
* <NotificationProvider
* foregroundCallback={foregroundCallback}
* backgroundCallback={backgroundCallback}
* config={client:'fizzmod', accessToken:'access_token_push', appName:'janisAppName'}
* events={['Notification','events','janis']}
* environment='beta'
* >
* <MyComponent/>
* </NotificationProvider>
* )
*/

const NotificationProvider = ({
children,
foregroundCallback,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"test": "jest",
"lint": "eslint .",
"build-docs": "jsdoc2md --template template-readme.hbs --files lib/*.js > README.md",
"build-docs": "jsdoc2md --template template-readme.hbs --files lib/*.js lib/NotificationProvider/*.js > README.md",
"test:coverage": "jest --collectCoverage",
"validate:code": "npm run lint -- --fix && jest --collectCoverage"
},
Expand Down
7 changes: 7 additions & 0 deletions scripts/release-notes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export TAG=$(echo $GITHUB_REF_NAME | sed -e 's/v//')

awk -v ver="$TAG" '
/^#+ \[/ { if (p) { exit }; if ($2 == "["ver"]") { p=1; next} } p
' CHANGELOG.md | sed '${/^[[:space:]]*$/d;}' > RELEASE_NOTES.md

node ./scripts/send-slack-message.cjs
Loading
Loading