1.0.0 • Published 3 years ago

brookies-module v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Brookies

Cookies managment module for back-iko.

  1. INSTALLATION
  2. DATABASE / API
  3. MOBILE SDK's
  4. SUMMARY

Peer Dependencies

This module requires several dependencies which must be installed in your React.js Back-Iko project :

  • axios
  • formik
  • node-sass
  • react-color
  • react-redux
  • universal-cookie
  • yup

And implicitely by the way :

  • react
  • react-dom

You can install them in your main project by using npm command line:

npm install --save axios formik node-sass react react-color react-dom react-redux universal-cookie yup

1. Installation :

Add brookies to your main project :

npm install --save brookies-module

Back office, React.js project ( BACK-IKO )

Simply import BrookiesManager component and add it to your project to get complete administration form set up and almost ready to go.

import React from "react"
import {useSelector} from "react-redux";
import {BrookiesManager} from "brookies-module";
import {useTranslation} from "react-i18next";

import {defaultLang} from "../../utils/languages";
import SearchBar from "../../components/SearchBar";

export default function Brookies() {
    const {t} = useTranslation()
    const state = useSelector(state => state)

    return <BrookiesManager t={t} state={state} defaultLang={defaultLang} searchBarComponent={<SearchBar />}/>
}

Dont forget to provide .env vars to you project, in order to make BrookiesManager operational. They must be named EXACTLY like these :

#BROOKIES
REACT_APP_BROOKIES_API_URL=<your-api-route>
REACT_APP_BROOKIES_API_KEY=<your-api-key> 
REACT_APP_BROOKIES_API_SECRET_KEY=<your-api-secret>

These two parameters : REACT_APP_BROOKIES_API_KEY REACT_APP_BROOKIES_API_SECRET_KEY Are passed as HTTP headers each time the module will request your API.

2. Database and API

API Migration/Model/Seeder

You will need these .env vars inside your API as well. They must be named EXACTLY like these :

#BROOKIES
BROOKIES_API_KEY=<your-api-key>
BROOKIES_API_SECRET_KEY=<your-api-secret>

If you are using sequelize you can use the following migration/model/seeder

Migration

'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('brookies', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER,
      },
      apiKey: {
        allowNull: false,
        type: Sequelize.STRING(255),
      },
      apiSecret: {
        allowNull: false,
        type: Sequelize.STRING(255),
      },
      jsonData: {
        allowNull: false,
        type: Sequelize.TEXT('long'),
      },
      isActive: {
        type: Sequelize.BOOLEAN,
        defaultValue: true
      },
      createdAt: {
        type: Sequelize.DATE,
      },
      updatedAt: {
        type: Sequelize.DATE,
      },
      deletedAt: {
        type: Sequelize.DATE,
      }
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('brookies');
  }
};

Model

const Sequelize = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  return Brookies.init(sequelize, DataTypes);
}

class Brookies extends Sequelize.Model {
  static init(sequelize, DataTypes) {
  super.init({
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    apiKey: {
      type: DataTypes.STRING(255),
      allowNull: false
    },
    apiSecret: {
      type: DataTypes.STRING(255),
      allowNull: false
    },
    jsonData: {
      type: DataTypes.TEXT('long'),
      allowNull: false
    },
    isActive: {
      type: DataTypes.BOOLEAN,
      defaultValue: true
    },
  }, {
    sequelize,
    tableName: 'brookies',
    timestamps: true,
    paranoid: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
  return Brookies;
  }
}

Seeder File

'use strict';

const {Brookies} = require('........../models'); // Specify your model path
const {brookiesSeeder} = require('........../brookiesSeeder'); // Specify your seeder data path ( file described just after )

module.exports = {
  up: async (queryInterface, Sequelize) => {
    return Brookies.bulkCreate(brookiesSeeder, {
      validate: true,
      individualHooks: true,
    });
  },

  down: async (queryInterface, Sequelize) => {
    return queryInterface.bulkDelete('brookies', null, {});
  }
};

brookiesSeeder

const brookiesEmptyData = require("./brookiesEmptyData.json");
const stringifiedBrookiesEmptyData = JSON.stringify(brookiesEmptyData)
const {languages} = require("./langSeeder")

const brookiesSeeder = languages.map(item => (
    {
        apiKey: process.env.BROOKIES_API_KEY,
        apiSecret: process.env.BROOKIES_API_SECRET_KEY,
        jsonData: stringifiedBrookiesEmptyData,
        isActive: true,
        languageId: item.id
    }
))

module.exports = {
    brookiesSeeder
}

brookiesEmptyData ( JSON File )

{
  "application": "",
  "validity": 0,
  "titleShort": "",
  "accessibility": "",
  "preferencesContent": "",
  "links": [],
  "buttons": [
    {
      "title": "",
      "type": "allow",
      "accessibility": ""
    },
    {
      "title": "",
      "type": "deny",
      "accessibility": ""
    },
    {
      "title": "",
      "type": "details",
      "accessibility": ""
    }
  ],
  "categories": [],
  "style": {
    "main": {
      "textColor": "#000000",
      "textColorDark": "#ffffff",
      "textPreferencesColor": "#000000",
      "textPreferencesColorDark": "#ffffff",
      "backgroundColor": "#ffffff",
      "backgroundColorDark": "#000000",
      "backgroundPreferencesColor": "#ffffff",
      "backgroundPreferencesColorDark": "#000000",
      "separatorColor":"#ffffff",
      "separatorColorDark":"#000000"
    },
    "statusBar": {
      "backgroundColor": "#ffffff",
      "backgroundColorDark": "#000000"
    },
    "topBar": {
      "backgroundColor": "#ffffff",
      "backgroundColorDark": "#000000"
    },
    "header": {
      "backgroundColor": "#ffffff",
      "backgroundColorDark": "#000000"
    },
    "buttons": {
      "textColor": "#ffffff",
      "textColorDark": "#000000",
      "backgroundColor": "#000000",
      "backgroundColorDark": "#ffffff"
    },
    "links": {
      "textColor": "#000000",
      "textColorDark": "#ffffff"
    }
  }
}

Database

Brookies have to be set inside your database. If you don't use sequelize within your API, here is the table schema. A table named:

brookies

Which contains at least the following columns :

id ( PRIMARY_KEY )
apiKey ( STRING )
apiSecret ( STRING )
jsonData ( LONG_TEXT )
isActive ( BOOLEAN )
languageId ( INTEGER )

3. Connections to mobile SDK

Based on .env vars for web admin pannel, which are :

#BROOKIES
REACT_APP_BROOKIES_API_URL=<your-api-route>
REACT_APP_BROOKIES_API_KEY=<your-api-key> 
REACT_APP_BROOKIES_API_SECRET_KEY=<your-api-secret>

Mobile SDK's which are oriented to consume the API must pass :

apikey: <your-api-key>
apisecret: <your-api-secret>

As headers inside the GET request to <your-api-route>

Also :

  • <your-api-route>?lang=<fr/en/..> will return the specific brookies instance you want.
  • <your-api-route>?validityType=sec will return the config values with validity formated as seconds.

Example : <your-api-route>?lang=fr&validityType=sec will return the config for the French brookies instance, with validity formated as seconds.

Handling response

You will need to send a GET request to <your-api-route>

SUCCESS

If your response is a success, API will return a JSON body with all the config data for your BROOKIES instance.

ERRORS

If your response is an error, API will return a JSON body formatted like this :

{
    "status": <INTEGER>,
    "error": <STRING>,
    "codeError": <STRING>
}

You must focus on the "codeError" key to handle your errors. In most cases, it will return "codeError": "SERVER_ERROR" for 400/404/500 status codes and "codeError": "BROOKIES_DESACTIVATED" for 403 status code.

400 - Bad request

If the body looks like this :

{
    "status": 400,
    "error": "MISSING_WRONG_VALUES",
    "codeError": "SERVER_ERROR"
}

It means that an error has been set when requesting the api route. Mostly, it can be related to the credentials you gave to your request headers.

403 - Desactivated

If the body looks like this :

{
    "status": 403,
    "error": "BROOKIES_DESACTIVATED",
    "codeError": "BROOKIES_DESACTIVATED"
}

It means that brookies is desactivated and the config data won't be available anymore. Handle it the way you want.

404 - Not found

If the body looks like this :

{
    "status": 404,
    "error": "RECORD_NOT_FOUND",
    "codeError": "SERVER_ERROR"
}

It means that the brookies instance you are requesting for is missing in the database.

500 - Internal server error

If the body looks like this :

{
    "status": 500,
    "error": "...description of the error...",
    "codeError": "SERVER_ERROR"
}

It means that the server seems to be facing an internal problem, and the "error" key can help you to know the possible causes of that problem.

4. Summary

WEB

  1. Add component to your React project
  2. Specify .env vars
  3. Integrate brookies to your DB schema ( migration/model/seeder )
  4. Specify .env vars for your API
  5. Make your route get/put inside your API
  6. Make your controllers for each routes
  7. Have fun !

MOBILE

  1. Pass apikey: <your-api-key> and apisecret: <your-api-secret> to your GET request headers to <your-api-route>. You will also need to pass parameter ?lang=<fr/en/...> for your specofoc brookies instance, and ?validityType=sec to get your validity value formatted as seconds.
  2. If success, consume the JSON config data for your app
  3. If errors, handle "codeError: "SERVER_ERROR" and "codeError": "BROOKIES_DESACTIVATED" the way you want
  4. Have fun !
1.0.288

2 years ago

1.0.200

2 years ago

1.0.206

2 years ago

1.0.205

2 years ago

1.0.208

2 years ago

1.0.207

2 years ago

1.0.202

2 years ago

1.0.201

2 years ago

1.0.204

2 years ago

1.0.203

2 years ago

1.0.187

2 years ago

1.0.189

2 years ago

1.0.188

2 years ago

1.0.183

2 years ago

1.0.182

2 years ago

1.0.185

2 years ago

1.0.184

2 years ago

1.0.181

2 years ago

1.0.180

2 years ago

1.0.176

2 years ago

1.0.175

2 years ago

1.0.178

2 years ago

1.0.177

2 years ago

1.0.172

2 years ago

1.0.171

2 years ago

1.0.174

2 years ago

1.0.173

2 years ago

1.0.179

2 years ago

1.0.170

2 years ago

1.0.197

2 years ago

1.0.199

2 years ago

1.0.194

2 years ago

1.0.193

2 years ago

1.0.196

2 years ago

1.0.195

2 years ago

1.0.190

2 years ago

1.0.192

2 years ago

1.0.191

2 years ago

1.0.264

2 years ago

1.0.263

2 years ago

1.0.266

2 years ago

1.0.265

2 years ago

1.0.260

2 years ago

1.0.262

2 years ago

1.0.261

2 years ago

1.0.268

2 years ago

1.0.267

2 years ago

1.0.149

3 years ago

1.0.269

2 years ago

1.0.148

3 years ago

1.0.253

2 years ago

1.0.252

2 years ago

1.0.255

2 years ago

1.0.254

2 years ago

1.0.251

2 years ago

1.0.250

2 years ago

1.0.257

2 years ago

1.0.256

2 years ago

1.0.259

2 years ago

1.0.258

2 years ago

1.0.286

2 years ago

1.0.165

2 years ago

1.0.285

2 years ago

1.0.164

2 years ago

1.0.167

2 years ago

1.0.287

2 years ago

1.0.166

2 years ago

1.0.282

2 years ago

1.0.161

2 years ago

1.0.281

2 years ago

1.0.160

2 years ago

1.0.284

2 years ago

1.0.163

2 years ago

1.0.283

2 years ago

1.0.162

2 years ago

1.0.169

2 years ago

1.0.168

2 years ago

1.0.280

2 years ago

1.0.275

2 years ago

1.0.154

3 years ago

1.0.274

2 years ago

1.0.153

3 years ago

1.0.277

2 years ago

1.0.156

2 years ago

1.0.276

2 years ago

1.0.155

2 years ago

1.0.271

2 years ago

1.0.150

3 years ago

1.0.270

2 years ago

1.0.152

3 years ago

1.0.272

2 years ago

1.0.151

3 years ago

1.0.279

2 years ago

1.0.158

2 years ago

1.0.278

2 years ago

1.0.157

2 years ago

1.0.159

2 years ago

1.0.220

2 years ago

1.0.222

2 years ago

1.0.221

2 years ago

1.0.228

2 years ago

1.0.227

2 years ago

1.0.229

2 years ago

1.0.224

2 years ago

1.0.223

2 years ago

1.0.226

2 years ago

1.0.225

2 years ago

1.0.211

2 years ago

1.0.210

2 years ago

1.0.217

2 years ago

1.0.216

2 years ago

1.0.219

2 years ago

1.0.218

2 years ago

1.0.213

2 years ago

1.0.212

2 years ago

1.0.215

2 years ago

1.0.214

2 years ago

1.0.209

2 years ago

1.0.242

2 years ago

1.0.241

2 years ago

1.0.244

2 years ago

1.0.243

2 years ago

1.0.240

2 years ago

1.0.246

2 years ago

1.0.245

2 years ago

1.0.248

2 years ago

1.0.247

2 years ago

1.0.231

2 years ago

1.0.230

2 years ago

1.0.233

2 years ago

1.0.232

2 years ago

1.0.239

2 years ago

1.0.235

2 years ago

1.0.234

2 years ago

1.0.237

2 years ago

1.0.236

2 years ago

1.0.143

3 years ago

1.0.142

3 years ago

1.0.145

3 years ago

1.0.144

3 years ago

1.0.141

3 years ago

1.0.140

3 years ago

1.0.147

3 years ago

1.0.146

3 years ago

1.0.62

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.66

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.68

3 years ago

1.0.67

3 years ago

1.0.132

3 years ago

1.0.131

3 years ago

1.0.134

3 years ago

1.0.133

3 years ago

1.0.130

3 years ago

1.0.139

3 years ago

1.0.136

3 years ago

1.0.135

3 years ago

1.0.138

3 years ago

1.0.137

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.70

3 years ago

1.0.77

3 years ago

1.0.76

3 years ago

1.0.75

3 years ago

1.0.74

3 years ago

1.0.79

3 years ago

1.0.78

3 years ago

1.0.39

3 years ago

1.0.38

3 years ago

1.0.40

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.55

3 years ago

1.0.54

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.101

3 years ago

1.0.100

3 years ago

1.0.107

3 years ago

1.0.106

3 years ago

1.0.109

3 years ago

1.0.108

3 years ago

1.0.103

3 years ago

1.0.102

3 years ago

1.0.105

3 years ago

1.0.104

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.121

3 years ago

1.0.120

3 years ago

1.0.123

3 years ago

1.0.122

3 years ago

1.0.129

3 years ago

1.0.128

3 years ago

1.0.125

3 years ago

1.0.124

3 years ago

1.0.127

3 years ago

1.0.126

3 years ago

1.0.80

3 years ago

1.0.84

3 years ago

1.0.83

3 years ago

1.0.82

3 years ago

1.0.81

3 years ago

1.0.88

3 years ago

1.0.87

3 years ago

1.0.86

3 years ago

1.0.85

3 years ago

1.0.89

3 years ago

1.0.110

3 years ago

1.0.112

3 years ago

1.0.111

3 years ago

1.0.118

3 years ago

1.0.117

3 years ago

1.0.119

3 years ago

1.0.114

3 years ago

1.0.113

3 years ago

1.0.116

3 years ago

1.0.115

3 years ago

1.0.91

3 years ago

1.0.90

3 years ago

1.0.95

3 years ago

1.0.94

3 years ago

1.0.93

3 years ago

1.0.92

3 years ago

1.0.99

3 years ago

1.0.98

3 years ago

1.0.97

3 years ago

1.0.96

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago