{"id":15198768,"url":"https://github.com/localtools/nest-sns","last_synced_at":"2026-02-03T21:03:31.954Z","repository":{"id":251088907,"uuid":"836333075","full_name":"localtools/nest-sns","owner":"localtools","description":"Amazon Simple Notification Service module 🌐 https://www.npmjs.com/package/nest-sns","archived":false,"fork":false,"pushed_at":"2024-07-31T16:24:12.000Z","size":162,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-09-29T01:41:00.812Z","etag":null,"topics":["aws","aws-sdk","nest","nestjs","sns","sns-client","sns-notifications","sns-topic"],"latest_commit_sha":null,"homepage":"https://localtools.github.io/nest-sns/#/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localtools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"hebertcisco","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2024-07-31T16:14:43.000Z","updated_at":"2024-07-31T16:28:15.000Z","dependencies_parsed_at":"2024-07-31T21:28:44.790Z","dependency_job_id":"58e00244-a1d5-402a-af83-ce2a35641196","html_url":"https://github.com/localtools/nest-sns","commit_stats":null,"previous_names":["localtools/nest-sns"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localtools%2Fnest-sns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localtools%2Fnest-sns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localtools%2Fnest-sns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localtools%2Fnest-sns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localtools","download_url":"https://codeload.github.com/localtools/nest-sns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859638,"owners_count":16556034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-sdk","nest","nestjs","sns","sns-client","sns-notifications","sns-topic"],"created_at":"2024-09-28T01:41:08.479Z","updated_at":"2025-10-28T11:31:40.617Z","avatar_url":"https://github.com/localtools.png","language":"TypeScript","funding_links":["https://github.com/sponsors/hebertcisco","https://www.buymeacoffee.com/hebertcisco","https://img.buymeacoffee.com/button-api/?text=Buy"],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://dl.circleci.com/status-badge/img/gh/localtools/nest-sns/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/localtools/nest-sns/tree/main)\n\n[![Node.js build and publish package](https://github.com/localtools/nest-sns/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/localtools/nest-sns/actions/workflows/npm-publish.yml)\n\n[![Running Code Coverage](https://github.com/localtools/nest-sns/actions/workflows/coverage.yml/badge.svg)](https://github.com/localtools/nest-sns/actions/workflows/coverage.yml)\n\n[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat\u0026logo=typescript\u0026logoColor=white)](https://www.typescriptlang.org/)\n[![Nestjs](https://img.shields.io/badge/Nestjs-ea2845?style=flat\u0026logo=nestjs\u0026logoColor=white)](https://nestjs.com/)\n[![Free. Built on open source. Runs everywhere.](https://img.shields.io/badge/VS_Code-0078D4?style=flat\u0026logo=visual%20studio%20code\u0026logoColor=white)](https://code.visualstudio.com/)\n[![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=flat\u0026logo=githubactions\u0026logoColor=white)](https://github.com/localtools/nest-sns/actions)\n\n\u003e Amazon Simple Notification Service module 🌐\n\n## Installation\n\n\u003e Install with yarn or npm: `yarn` or `npm`:\n\n```bash\n# yarn\nyarn add nest-sns\n```\n\n```bash\n# npm\nnpm i nest-sns --save\n```\n\n```bash\n# pnpm\npnpm add nest-sns --save\n```\n\n## Usage\n\n### SnsModule\n\nThe SnsModule is a module that provides the `SnsService` and `SmsService` for\nsending SMS messages using AWS SNS.\n\n#### Importing the module\n\nTo use the SnsModule in your NestJS application, you will need to import it. You\ncan do this by adding the following line to the top of the file where you want\nto use the module:\n\n```js\nimport { SnsModule } from \"nest-sns\";\n```\n\n#### Registering the module\n\nTo use the SnsModule, you will need to register it and provide the necessary AWS\nSNS credentials. You can do this by calling the `register` method and passing it\nan object containing the `credentials` property. The `register` method returns\nan object that you can use to include the module in the `imports` array of the\nroot AppModule or the module where you want to use it.\n\nHere is an example of how you can register the SnsModule:\n\n```js\nSnsModule.register({\n  credentials: {\n    accessKeyId: AWS_ACCESS_KEY_ID,\n    secretAccessKey: AWS_SECRET_ACCESS_KEY,\n  },\n});\n```\n\n#### Using the module\n\nTo use the SnsModule, you will need to inject the `SnsService` or `SmsService`\ninto your component or controller. You can do this by adding it to the\nconstructor arguments and adding a public or private property for it:\n\n```js\nexport class YourComponent {\n  constructor(private snsService: SnsService) {}\n}\n```\n\nYou can then use the `snsService` or `smsService` to perform the necessary\noperations, such as creating an SNS topic, publishing to a topic, or subscribing\nto a topic.\n\n### SmsService\n\nThis service is responsible for sending SMS messages using AWS SNS.\n\n#### Importing the SmsService\n\nTo use the SmsService in your NestJS application, you will need to import it.\nYou can do this by adding the following line to the top of the file where you\nwant to use the service:\n\n```js\nimport { SmsService } from \"nest-sns\";\n```\n\n#### Injecting the SmsService\n\nTo use the SmsService, you will need to inject it into your component or\ncontroller. You can do this by adding it to the constructor arguments and adding\na public or private property for it:\n\n```js\nexport class YourComponent {   \n constructor(private smsService: SmsService) {} \n}\n```\n\n#### Sending an SMS\n\nTo send an SMS using the SmsService, you can call the `sendSMS` method and pass\nit an object containing the SMS options. The `sendSMS` method returns a Promise\nthat resolves to an object with a `statusCode`, `message`, and `data`\nproperties.\n\nHere is an example of how you can use the `sendSMS` method:\n\n```js\nconst smsOptions = {\n  PhoneNumber: \"+1234567890\",\n  Message: \"Hello, this is a test SMS message.\",\n};\n\ntry {\n  const response = await this.smsService.sendSMS(smsOptions);\n  console.log(response);\n} catch (error) {\n  console.error(error);\n}\n```\n\n#### Interfaces and Types\n\nThe `SendSMSInput` interface defines the shape of the options object that should\nbe passed to the `sendSMS` method. It contains the following properties:\n\n```js\nexport type SendSMSInput = {\n  Message: string;\n  PhoneNumber: string;\n  Subject?: string;\n};\n```\n\n### SnsService\n\nThis service is a wrapper for the AWS SNS client, which allows you to create,\npublish, and subscribe to AWS SNS topics.\n\n#### Importing the SnsService\n\nTo use the SnsService in your NestJS application, you will need to import it.\nYou can do this by adding the following line to the top of the file where you\nwant to use the service:\n\n```js\nimport { SnsService } from \"nest-sns\";\n```\n\n#### Injecting the SnsService\n\nTo use the SnsService, you will need to inject it into your component or\ncontroller. You can do this by adding it to the constructor arguments and adding\na public or private property for it:\n\n```js\nexport class YourComponent {\n  constructor(private snsService: SnsService) {}\n}\n```\n\n#### Creating an SNS Topic\n\nTo create an SNS topic using the SnsService, you can call the `createTopic`\nmethod and pass it an object containing the topic options. The `createTopic`\nmethod returns a Promise that resolves to an object with the `TopicArn`\nproperty, which is the Amazon Resource Name (ARN) of the created topic.\n\nHere is an example of how you can use the `createTopic` method:\n\n```js\nconst topicOptions = {\n  Name: \"my-topic\",\n};\n\ntry {\n  const response = await this.snsService.createTopic(topicOptions);\n  console.log(response);\n} catch (error) {\n  console.error(error);\n}\n```\n\n#### Publishing to an SNS Topic\n\nTo publish a message to an SNS topic using the SnsService, you can call the\n`publish` method and pass it an object containing the publish options. The\n`publish` method returns a Promise that resolves to an object with the\n`MessageId` property, which is the ID of the message that was published.\n\nHere is an example of how you can use the `publish` method:\n\n```js\nconst publishOptions = {\n  TopicArn: \"arn:aws:sns:region:account-id:my-topic\",\n  Message: \"Hello, this is a test message.\",\n};\n\ntry {\n  const response = await this.snsService.publish(publishOptions);\n  console.log(response);\n} catch (error) {\n  console.error(error);\n}\n```\n\n#### Subscribing to an SNS Topic\n\nTo subscribe to an SNS topic using the SnsService, you can call the `subscribe`\nmethod and pass it an object containing the subscribe options. The `subscribe`\nmethod returns a Promise that resolves to an object with the `SubscriptionArn`\nproperty, which is the ARN of the subscription.\n\nHere is an example of how you can use the `subscribe` method:\n\n```js\nconst subscribeOptions = {\n  TopicArn: \"arn:aws:sns:region:account-id:my-topic\",\n  Protocol: \"email\",\n  Endpoint: \"my-email@example.com\",\n};\n\ntry {\n  const response = await this.snsService.subscribe(subscribeOptions);\n  console.log(response);\n} catch (error) {\n  console.error(error);\n}\n```\n\n#### Interfaces for SNS Options\n\nThe `CreateTopicInput` interface defines the shape of the options object that\nshould be passed to the `createTopic` method. It contains the following\nproperties:\n\n```js\nexport interface CreateTopicInput {\n  Name: string;\n}\n```\n\nThe `PublishInput` interface defines the shape of the options object that should\nbe passed to the `publish` method. It contains the following properties:\n\n```js\nexport interface PublishInput {\n  TopicArn: string;\n  Message: string;\n  Subject?: string;\n}\n```\n\nThe `SubscribeInput` interface defines the shape of the options object that\nshould be passed to the `subscribe` method. It contains the following\nproperties:\n\n```js\nexport interface SubscribeInput {\n  TopicArn: string;\n  Protocol: string;\n  Endpoint: string;\n}\n```\n\n## 🤝 Contributing\n\nContributions, issues and feature requests are welcome!\u003cbr /\u003eFeel free to check\n[issues page](issues).\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\nOr buy me a coffee 🙌🏾\n\n\u003ca href=\"https://www.buymeacoffee.com/hebertcisco\"\u003e\n    \u003cimg src=\"https://img.buymeacoffee.com/button-api/?text=Buy me a coffee\u0026emoji=\u0026slug=hebertcisco\u0026button_colour=FFDD00\u0026font_colour=000000\u0026font_family=Inter\u0026outline_colour=000000\u0026coffee_colour=ffffff\" /\u003e\n\u003c/a\u003e\n\n## Star History\n\n\u003ca\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=localtools/nest-sns\u0026type=Date\u0026theme=dark\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=localtools/nest-sns\u0026type=Date\" /\u003e\n   \u003cimg alt=\"Star History Chart\" src=\"https://api.star-history.com/svg?repos=localtools/nest-sns\u0026type=Date\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n\n## 📝 License\n\nCopyright © 2024 [Hebert F Barros](https://github.com/hebertcisco).\u003cbr /\u003e This\nproject is [MIT](LICENSE) licensed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocaltools%2Fnest-sns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocaltools%2Fnest-sns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocaltools%2Fnest-sns/lists"}