1.5.15 • Published 4 years ago

@impesa/common v1.5.15

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

@impesa/common

This library is a set of utilities that uses googleapis and general functions commonly used in the impesa APIs infraestructure.

Microservice

Start a preconfigured Express server. This uses helmet, cors, body-parser and start the gcloud debugger and logger for issue tracking. It is also capable of loading configurations from the spanner setting table and datastore setting table entity using the settings parameter if it is set to true.

microservice.start({
    port: 8090,
    basepath: '/service',
    spanner: {
        instance: '{YOUR-INSTANCE-NAME}',
        database: '{YOUR-DATABASE-NAME}',
        settings: true
    },
    datastore: {
        namespace: '{YOUR-NAMESPACE-NAME}',
        settings: true
    },
    middleware: function (app) {
        console.log('...using middleware');
    },
    routing: function () {
        return router_paths;
    },
    listening: function (server) {
        console.log('...server listening');
    }
});

Endpoint Authorization

Set the following variables by settings loader (spanner or datastore)

AUTH_DOMAIN = '{YOUR-AUTHORIZATION-DOMAIN}';
// auth audience depends of each microservice basepath
AUTH_AUDIENCE = `{YOUR-API-DOMAIN}${basepath}`;

To access an endpoint set the Authorization header as "Bearer {access_token}".
Example: Authorization: Bearer 874887d6ecd0b106a47448c5beca1...

Add the auth function with scopes (optional) to the endpoint request handlers:

const auth = require('@impesa/common').auth;

router.route('/hi')
    .all(auth(['read:hi'])) //scopes is optional
    .get((req, res) => {
        res.send('Hello world!');
    });

Spanner

Add an spanner database by running spanner.add(options) using the following parameters: projectId, instance, database. Then get an spanner instance by running spanner.db(name:optional).

Datastore

Add an datastore c by running datastore.add(options) using the following parameters: projectId, datastore. Then get a datastore instance by running datastore.db(namespace:optional).

Subscriptions

Create many PubSub subscriptions

subs: [{
        name: 'topic-subscription-name',
        func: (msj, att) => {
            console.log('receiving...');
        }
    }]

WebSockets support

Listen many ws events

sockets: {
    login: (data)=>{ }, //login function, will set user property of client
    events: [{
        name: 'message',
        func: (event) => {
            //message received as {sender, user, ...event}
        }
    }]
} 

Debugger

In production mode, the debugger instance is initialized by running debugger.start(); this starts the debugger using the following environment variables: PROJECTID.

Logger

In production mode, the logger is initialized to write different kind of logs ('INFO', 'WARM', 'ERROR') in gcloud Logging or track errors in gcloud Error Reporting; the logger uses the following environment variables: PROJECTID.

Log: logger.log('Info message', 'General', 'INFO');

Error: logger.error(error);

1.5.15

4 years ago

2.0.0-beta.36

4 years ago

1.5.14

4 years ago

1.5.13

4 years ago

2.0.0-beta.33

4 years ago

2.0.0-beta.35

4 years ago

2.0.0-beta.34

4 years ago

2.0.0-beta.32

4 years ago

2.0.0-beta.31

4 years ago

2.0.0-beta.30

4 years ago

2.0.0-beta.29

4 years ago

2.0.0-beta.28

4 years ago

2.0.0-beta.27

4 years ago

2.0.0-beta.26

4 years ago

2.0.0-beta.25

4 years ago

2.0.0-beta.24

4 years ago

2.0.0-beta.23

4 years ago

2.0.0-beta.22

4 years ago

2.0.0-beta.21

4 years ago

2.0.0-beta.20

4 years ago

2.0.0-beta.19

4 years ago

2.0.0-beta.18

4 years ago

2.0.0-beta.17

4 years ago

2.0.0-beta.16

4 years ago

2.0.0-beta.15

5 years ago

2.0.0-beta.14

5 years ago

1.5.12

5 years ago

2.0.0-beta.13

5 years ago

2.0.0-beta.12

5 years ago

2.0.0-beta.11

5 years ago

2.0.0-beta.10

5 years ago

2.0.0-beta.9

5 years ago

2.0.0-beta.8

5 years ago

2.0.0-beta.7

5 years ago

2.0.0-beta.6

5 years ago

2.0.0-beta.5

5 years ago

2.0.0-beta.4

5 years ago

2.0.0-beta.3

5 years ago

2.0.0-beta.2

5 years ago

1.5.11

5 years ago

2.0.0-beta.1

5 years ago

2.0.0-beta.0

5 years ago

1.0.0-beta.0

5 years ago

0.0.1

5 years ago

1.5.10

5 years ago

1.5.9

5 years ago

1.5.8

5 years ago

1.5.7

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago