This JavaScript library simplifies making authenticated requests to the Lista Robinson API using AWS Signature Version 4. It handles the complexities of generating the necessary authentication headers, signing requests, normalizing input data, and generating the required hashes, allowing developers to easily integrate with the Lista Robinson service.
- Support for All Channels: Integrates with all available channels provided by the Lista Robinson client-server.
- Automatic Data Normalization: Normalizes input data according to the service rules before generating the hash.
- Hash Generation: Generates the required SHA-256 hashes.
- AWS Signature Version 4 Authentication: Handles request signing according to AWS Signature Version 4 using crypto.js.
npm i robinson-list-js-api
-
Create a
.env
file in the root directory of your project:ACCESS_KEY=YOUR_ACCESS_KEY SECRET_KEY=YOUR_SECRET_KEY
Replace
YOUR_ACCESS_KEY
andYOUR_SECRET_KEY
with your actual AWS credentials.
In this example we use dotenv to loads environment variables from a .env file into process.env
If you want to use the same library
npm install dotenv --save
Here is an example of how to use the main function sendListaRobinsonRequest
to make a request to the API.
import { config } from "dotenv";
import { sendListaRobinsonRequest } from "robinson-list-js-api";
// Load .env variables
config();
const accessKey = process.env.ACCESS_KEY || "";
const secretKey = process.env.SECRET_KEY || "";
const region = "eu-west-1";
const service = "execute-api";
const endpoint = "https://api.listarobinson.es/v1/api/user";
// x3 Example Data
const testData = [
{
channel: "DNI_NIF_NIE",
data: ["12345678Z"],
},
{
channel: "PhoneSimple",
data: ["612345678"],
},
{
channel: "Email",
data: ["ejemplo.prueba@example.com"],
},
];
(async () => {
try {
for (const test of testData) {
const response = await sendListaRobinsonRequest({
accessKey,
secretKey,
region,
service,
endpoint,
channel: test.channel,
data: test.data,
});
console.log(`API Response for channel ${test.channel}:`, response);
}
} catch (error) {
console.error("Error:", error);
}
})();
Note: It is recommended to use environment variables to store sensitive information such as access keys, secret keys, and endpoint URLs. This ensures that sensitive data is not hardcoded in your source code, reducing security risks and allowing better flexibility across different environments (development, staging, production).
Running the Example:
npm run example
The following channels are supported, along with their required fields:
-
DNI_NIF_NIE
-
ID:
00
-
Fields:
dni
-
Field Types:
identity
-
Example Data:
['78493085L']
-
ID:
-
Email
-
ID:
02
-
Fields:
email
-
Field Types:
email
-
Example Data:
['example@example.com']
-
ID:
-
PhoneSimple
-
ID:
04
-
Fields:
phone
-
Field Types:
phone
-
Example Data:
['636238940']
-
ID:
-
SmsSimple
-
ID:
03
-
Fields:
phone
-
Field Types:
phone
-
Example Data:
['636238940']
-
ID:
-
PhoneFull
-
ID:
04
-
Fields:
name
,surname1
,surname2
,phone
-
Field Types:
text
,text
,text
,phone
-
Example Data:
['John', 'Doe', '', '636238940']
-
ID:
-
SmsFull
-
ID:
03
-
Fields:
name
,surname1
,surname2
,phone
-
Field Types:
text
,text
,text
,phone
-
Example Data:
['John', 'Doe', '', '636238940']
-
ID:
-
Postal
-
ID:
01
-
Fields:
name
,surname1
,surname2
,street
,portal
,zip
,province
-
Field Types:
text
,text
,text
,text
,portal
,preserve
,preserve
-
Example Data:
['John', 'Doe', '', 'Main St', '123', '28080', 'Madrid']
-
ID:
Each field type is normalized according to specific rules before generating the hash:
-
phone:
- Removes non-numeric characters.
- Adds country code if missing (default is Spain,
0034
). - If the phone number starts with
+
, it is replaced with00
.
-
text:
- Converts to lowercase.
- Removes accents and special characters.
- Removes any non-alphabetical character.
-
email:
- Converts to lowercase.
- Removes invalid characters.
- Maintains standard email characters.
-
identity:
- Converts letters to lowercase.
- Removes invalid characters.
- Keeps numbers and specific lowercase letters.
-
portal:
- Extracts the numeric part.
- Special handling for 'sn' (without number).
-
preserve:
- No normalization is applied.
-
Add your API credentials in the
.env
file as shown in the configuration section. -
Use the
example.js
file to test the library with different channels and data. -
Run the test script from the terminal:
npm run example