# nestjs-expo-sdk

> Just a little integration of expo-server-sdk in nestjs

Latest version **1.1.3** (published 2021-12-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install nestjs-expo-sdk
pnpm add nestjs-expo-sdk
yarn add nestjs-expo-sdk
bun add nestjs-expo-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2021-12-08 |
| First published | 2021-12-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 101.1 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jorge Fernandez |
| Maintainers | fsjorgeluis |
| Keywords | typescript, tsc, nestjs, expo, sdk, integration |

## Links

- npm: https://www.npmjs.com/package/nestjs-expo-sdk
- Repository: https://github.com/fsjorgeluis/nestjs-expo-sdk
- Homepage: https://github.com/fsjorgeluis/nestjs-expo-sdk#readme
- Issues: https://github.com/fsjorgeluis/nestjs-expo-sdk/issues
- npm.io page: https://npm.io/package/nestjs-expo-sdk

## Dependencies (7)

- [rxjs](https://npm.io/package/rxjs.md) ^7.2.0
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^8.0.0
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^8.0.0
- [expo-server-sdk](https://npm.io/package/expo-server-sdk.md) ^3.6.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) ^8.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2021-12-08
- 1.1.2 — 2021-12-08
- 1.1.1 — 2021-12-08
- 1.1.0 — 2021-12-08
- 1.0.0 — 2021-12-08

## README

<p align="center">
    <img src="https://user-images.githubusercontent.com/20530235/145147022-769c8020-a92b-4e63-b964-f8fc3aebb09e.png">
</p>
<p align="center">
    <img alt="Lines of code" src="https://img.shields.io/tokei/lines/github/fsjorgeluis/nestjs-expo-sdk">
    <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/nestjs-expo-sdk">
    <img alt="GitHub package.json dependency version (dev dep on branch)" src="https://img.shields.io/github/package-json/dependency-version/fsjorgeluis/nestjs-expo-sdk/dev/typescript">
    <img alt="GitHub package.json dependency version (dev dep on branch)" src="https://img.shields.io/github/package-json/dependency-version/fsjorgeluis/nestjs-expo-sdk/dev/jest">
    <img alt="GitHub" src="https://img.shields.io/github/license/fsjorgeluis/nestjs-expo-sdk">
    <a href="https://twitter.com/intent/follow?screen_name=fsjorgeluis">
        <img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/fsjorgeluis?logo=twitter&logoColor=blue&style=social">
    </a>
</p>

# NestJs + Expo push notifications

A little module to make push notifications with react native in nestjs a bit easier work, hand by hand with `expo-server-sdk`.

Feel free to use it, if you like it! :D

## Ready to use

Just `npm install nestjs-expo-sdk` this package use `expo-server-sdk` under the hood, then

```
import { ExpoSdkModule } from 'nestjs-expo-sdk';

@Module()
imports: [
  // Create a new Expo SDK client
  // optionally providing an access token if you have
  enabled push security
  // second optional arg boolean to define if
  // this module is global or not. True by default
  ExpoSdkModule.forRoot(
    {
      accessToken: process.env.EXPO_ACCESS_TOKEN,
    },
    true,
  ),
],
```

`ExpoSdkModule` also includes `forRootAsync` method to pass args asynchronously

```
ExpoSdkModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (configService: ConfigService) => ({
    accessToken: configService.get<string>('SOME_ENV_VAR'),
  }),
  inject: [ConfigService],
}),
```

now it's time to use it in your provider

```
@Injectable()
export class AppService {
  // You can inject expo now and use as any or
  // Expo if you have previously installed expo-server-sdk
  // just to get types, declarations or another functions :D
  constructor(@InjectExpo() private expo: any) {}

  async sendPush(somePushTokens): Promise<any> {
    let messages = [];
    for (let pushToken of somePushTokens) {
      // Each push token looks like ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]

      // Check that all your push tokens appear to be valid Expo push tokens
      if (!Expo.isExpoPushToken(pushToken)) {
        console.error(`Push token ${pushToken} is not a valid Expo push token`);
        continue;
      }

      // Construct a message
      messages.push({
        to: pushToken,
        sound: 'default',
        body: 'This is a test notification',
        data: { withSome: 'data' },
      });
    }

    let chunks = this.expo.chunkPushNotifications(messages);
    let tickets = [];

    for (let chunk of chunks) {
      try {
        let ticketChunk = await this.expo.sendPushNotificationsAsync(messages);
        console.log(ticketChunk);
        console.log(ticketChunk);
        tickets.push(...ticketChunk);
        // NOTE: If a ticket contains an error code in ticket.details.error, you
        // must handle it appropriately. The error codes are listed in the Expo
        // documentation
      } catch (error) {
        console.error(error);
      }
    }
  }
}
```

and you are ready to go.

_Note:_ if you need more info feel free to read [Expo Docs](https://docs.expo.dev/push-notifications/sending-notifications/)

### TODO

- Add maybe more fuctionality.
- Add test

### DONE

- Make this module an npm package just for fun, and educative purposes.
- Added more functions for flexibility
- Added more documentation.
- Added changelog.
- Added tags.

---
_Source: https://npm.io/package/nestjs-expo-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
