-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41517e2
commit 2eb4352
Showing
455 changed files
with
20,287 additions
and
0 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,75 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"es6": true, | ||
"es2021": true, | ||
"node": true, | ||
"jest/globals": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"google", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:jest/recommended", | ||
"plugin:jest-formatting/recommended", | ||
"prettier" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"deprecation", | ||
"jest", | ||
"jest-extended", | ||
"jest-formatting", | ||
"prettier" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"semi": "warn", | ||
"comma-dangle": "warn", | ||
"jest-extended/prefer-to-be-true": "warn", | ||
"jest-extended/prefer-to-be-false": "error", | ||
"jest-formatting/padding-around-describe-blocks": 2, | ||
"jest-formatting/padding-around-test-blocks": 2, | ||
"jest/expect-expect": "error", | ||
"curly": [ | ||
"error", | ||
"all" | ||
], | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"object-curly-spacing": [ | ||
"error", | ||
"always", | ||
{ | ||
"objectsInObjects": true, | ||
"arraysInObjects": true | ||
} | ||
], | ||
"require-jsdoc": [ | ||
"off" | ||
], | ||
"operator-linebreak": [ | ||
"error", | ||
"before" | ||
], | ||
"max-len": [ | ||
"error", | ||
{ | ||
"code": 120, | ||
"ignoreUrls": true, | ||
"ignoreComments": true, | ||
"ignoreTemplateLiterals": true, | ||
"ignoreRegExpLiterals": true, | ||
"ignorePattern": "^import.+|test" | ||
} | ||
] | ||
} | ||
} |
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 @@ | ||
name: Test Sinch Node.js SDK | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x, 20.x] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: yarn install | ||
- run: npx eslint "packages/**/src/**/*.ts" | ||
- run: npx eslint "packages/**/tests/**/*.ts" | ||
- run: yarn run build | ||
- run: yarn run test |
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,6 @@ | ||
.DS_Store | ||
.idea | ||
node_modules | ||
tsconfig.tsbuildinfo | ||
packages/**/dist | ||
.env |
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,17 @@ | ||
{ | ||
"trailingComma": "all", | ||
"endOfLine": "lf", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"overrides": [ | ||
{ | ||
"files": "*.json", | ||
"options": { | ||
"parser": "json", | ||
"proseWrap": "always" | ||
} | ||
} | ||
] | ||
} |
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,110 @@ | ||
<h1 align="center"> | ||
|
||
[![Sinch Logo](https://developers.sinch.com/static/logo-07afe977d6d9dcd21b066d1612978e5c.svg)](https://www.sinch.com) | ||
|
||
Node.js SDK | ||
|
||
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/sinch/sinch-sdk-node/run_tests.yaml?branch=main) | ||
[![Node.js LTS](https://img.shields.io/badge/Node.js-LTS%20supported-brightgreen)](https://nodejs.org/en/download/) | ||
![Latest Release](https://img.shields.io/npm/v/@sinch/sdk-core?label=%40sinch%2Fsdk-core&labelColor=FFC658) | ||
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/sinch/sinch-sdk-python/blob/main/LICENSE) | ||
|
||
</h1> | ||
|
||
## Welcome to Sinch's Node.js SDK. | ||
|
||
Here you'll find documentation to start developing Node.js code using Sinch services. | ||
|
||
To use this SDK you'll need a Sinch account. Please [sign up](https://dashboard.sinch.com/signup) or [log in](https://dashboard.sinch.com/login) if you already have one. | ||
|
||
Once logged-in you'll find different sets of credentials to access to the various Sinch APIs: | ||
- On the [Account dashboard](https://dashboard.sinch.com/account/access-keys), you will find your `projectId` and access keys composed of pairs of `keyId` / `keySecret`. Unless mentionned otherwise, these are the credentials you will need to access most of the Sinch APIs | ||
- For the **Verification** and **Voice** APIs, you will find pairs of `App key` / `App secret` in the [Verification dashboard](https://dashboard.sinch.com/verification/apps) and the [Voice dashboard](https://dashboard.sinch.com/voice/apps) respectively. Note that the apps are the same, wherever you access them. | ||
- For the **SMS** API, the standard credentials (`projectId`, `keyId`, `keySecret`) are available only in the US and EU regions. If your business involves any of the other regions (BR, CA, AU), you will need to use your `servicePlanId` that you can find on the [Service APIs dashboard](https://dashboard.sinch.com/sms/api/services). Note that the `servicePlanId` supports all the regions (US, EU, BR, CA, AU). | ||
|
||
For more in depth information about the Sinch APIs, please refer to the official developer portal - [developers.sinch.com](https://developers.sinch.com/) | ||
|
||
<span style="color:red; font-weight:bold">Warning:</span> | ||
**This SDK is currently available for preview purposes only. It should not be used in production environments.** | ||
|
||
## Installation | ||
|
||
### With NPM | ||
|
||
```bash | ||
npm install @sinch/sdk-core | ||
``` | ||
|
||
### With Yarn | ||
|
||
```bash | ||
yarn add @sinch/sdk-core | ||
``` | ||
|
||
## Constructor | ||
|
||
```typescript | ||
import { | ||
SinchClient, | ||
} from '@sinch/sdk-core'; | ||
|
||
const sinchClient = new SinchClient(sinchClientParameters); | ||
``` | ||
where `sinchClientParameters` is an object containing the properties required to access the API you want to use: | ||
- for **Verification** and **Voice** APIs: | ||
- `applicationKey` | ||
- `applicationSecret` | ||
- for **SMS** API when using the AU, BR or CA region (works also for US and EU) | ||
- `servicePlanId` | ||
- `apiToken` | ||
- for all the other APIs (including SMS is using the US and EU regions only) | ||
- `projectId` | ||
- `keyId` | ||
- `keySecret` | ||
|
||
## Promises | ||
All the methods that interact with the Sinch APIs use Promises. | ||
```typescript | ||
const response: SendSMSResponse = await sinchClient.sms.batches.send({ | ||
SendSMSRequest: { | ||
to: [ | ||
'+12223334444', | ||
'+12223335555' | ||
], | ||
from: '+12228889999', | ||
parameters: { | ||
name: { | ||
'+12223334444': 'John', | ||
default: 'there', | ||
} | ||
}, | ||
body: 'Hi ${name}', | ||
type: 'mt_text', | ||
}, | ||
}); | ||
console.log(`The SMS has been sent successfully. Here is the batch id: ${response.id}`) | ||
``` | ||
|
||
## Examples | ||
You can find an example of each request in the [examples/simple-examples](./examples/simple-examples/) folder. | ||
|
||
## Contact | ||
Developer Experience team: [[email protected]](mailto:[email protected]) | ||
|
||
## Supported APIs | ||
|
||
Here is the list of the Sinch API and there level of support by the Node.js SDK: | ||
|
||
| API Category | API Name | Status | | ||
|------------------------|-------------------------------------|:------:| | ||
| Messaging | SMS API | ✅ | | ||
| | Conversation API | ❌ | | ||
| | RCS API | ❌ | | ||
| | MMS API | ❌ | | ||
| | Provisioning API | ❌ | | ||
| Voice and Video | Voice API | ❌ | | ||
| | Elastic SIP Trunking | ❌ | | ||
| Numbers & Connectivity | Numbers API | ✅ | | ||
| | Brand and Campaign Registration API | ❌ | | ||
| | Number Lookup API | ❌ | | ||
| Verification | Verification API | ✅ | |
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,7 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', { targets: { node: 'current' } }], | ||
'@babel/preset-typescript', | ||
], | ||
|
||
}; |
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,5 @@ | ||
# Credentials for APIs using OAuth2 authentication | ||
PROJECT_ID=project-id found at https://dashboard.sinch.com/account/access-keys | ||
KEY_ID=access-key-id found at https://dashboard.sinch.com/account/access-keys | ||
KEY_SECRET=access-key-secret found at access-key creation time | ||
|
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,8 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# OS | ||
.DS_Store | ||
|
||
.env |
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,68 @@ | ||
# Integrated flows with the Sinch Node.js SDK | ||
|
||
This directory contains some code samples to illustrate how to chain services supported in the Sinch Node.js SDK. | ||
|
||
## Prerequisites | ||
|
||
Before trying to run a sample, make sure you have Node.js installed: please download and install the LTS version from [nodejs.org](https://nodejs.org). | ||
|
||
Once installed, check you can run node with the following command: | ||
|
||
```bash | ||
node --version | ||
``` | ||
|
||
You should see a result such as `v20.10.0`, matching the LTS you have downloaded or the version you had previously installed. | ||
|
||
To use the Sinch Node.js SDK packages, you will need a package manager such as `NPM` (already installed with Node.js) or `yarn`. | ||
|
||
To install `yarn` (optional), run the following command: | ||
|
||
```bash | ||
npm install --global yarn | ||
``` | ||
|
||
## Configuration | ||
|
||
To be able to send requests to the Sinch APIs, you need to have a Sinch account. Please [sign up](https://dashboard.sinch.com/signup) or [log in](https://dashboard.sinch.com/login) if you already have one. | ||
|
||
With the credentials found on the Sinch dashboards, you will have to fill the file `.env.template` and **rename it to `.env`**. This file needs to be located at the same place where you will be executing the sample applications. | ||
|
||
```properties | ||
# Credentials for APIs using OAuth2 authentication | ||
PROJECT_ID=project-id found at https://dashboard.sinch.com/account/access-keys | ||
KEY_ID=access-key-id found at https://dashboard.sinch.com/account/access-keys | ||
KEY_SECRET=access-key-secret found at access-key creation time | ||
``` | ||
|
||
**Note**: If you prefer using environment variables, the sample app is also supporting them: they take precedence over the value from the `.env` file. | ||
|
||
## Execution | ||
You will find all the scripts in the `package.json` file to run the samples. | ||
|
||
### With NPM | ||
|
||
```bash | ||
npm run numbers:app | ||
``` | ||
|
||
### With Yarn | ||
|
||
```bash | ||
yarn run numbers:app | ||
``` | ||
|
||
## Available flows | ||
|
||
### Numbers | ||
|
||
This app will try to rent a number or type `LOCAL` and manage it. the following requests will be chained: | ||
- the first request will return all the regions where we can rent a number of type `LOCAL`. We will store one of the values from the response. | ||
- Now that we have a region, we list all the numbers of type `LOCAL` available for rental in this region. | ||
- From the list of available numbers in the response, we select one, and we send another request to rent it | ||
- *Alternative*: renting a number can be done in only one step with the `rentAny` method. The application will rent a second number with this method. | ||
- Once a number is rented, it becomes an "active" number. | ||
- A possibility to check is a number belongs to us, is to request it in the "active" domain | ||
- Another possibility is to list our active numbers and check if the numbers we have rented are part of the list. This example illustrates the pagination. | ||
- The next request will update some properties of our numbers | ||
- Finally, we will release our numbers to not be charged for more than 1 month. |
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,22 @@ | ||
{ | ||
"name": "@sinch/integrated-flows-examples", | ||
"version": "0.0.0", | ||
"author": "Sinch", | ||
"private": true, | ||
"main": "dist/app.js", | ||
"scripts": { | ||
"build": "yarn run clean && yarn run compile", | ||
"clean": "rimraf dist tsconfig.tsbuildinfo", | ||
"compile": "tsc --build --verbose", | ||
"numbers:app": "ts-node src/numbers/app.ts" | ||
}, | ||
"dependencies": { | ||
"@sinch/sdk-core": "^0.0.0", | ||
"@types/node": "^20.8.7", | ||
"dotenv": "^16.3.1", | ||
"typescript": "^5.2.2" | ||
}, | ||
"devDependencies": { | ||
"ts-node": "^10.9.1" | ||
} | ||
} |
Oops, something went wrong.