0.5.4 • Published 5 months ago

@awhere/api v0.5.4

Weekly downloads
100
License
Apache-2.0
Repository
gitlab
Last release
5 months ago

@awhere/api

1. Register the API with your credentials

- Register with API Key

import { APIKey, CredentialType, identityManager } from '@awhere/api/identity';
const credential = new APIKey({
    aWhereUrl: '<Your aWhere URL>',
    key: '<Your aWhere API Key>',
});
identityManager.registers([credential]);
identityManager.setDefaultCredential(credential);

- Register with OAuth2.0 flow

ES6

// signin.js

import { OAuth, CredentialType, identityManager } from '@awhere/api/identity';
const credential = new OAuth({
    aWhereUrl: '<Your aWhere URL>',
    appId: '<Your App Id>',
    callbackUrl: '/oauth-callback',
});
identityManager.registers([credential]);
identityManager.setDefaultCredential(credential);
credential.syncWithStorage().then(() => {
    if (!identityManager.defaultOAuth.signedIn) {
        return identityManager.defaultOAuth.signIn();
    }
    // go to the signed-in page
});
// oauth-callback.js

import { fetchToken } from '@awhere/api/identity';

fetchToken(location)
    .then(() => {
        // authorized page
        location.href = '/';
    })
    .catch((err) => {
        // oauth flow authorized page
        location.href = '/sigin?' + err;
    });

HTML

<script src="<Your aWhere JavaScript API URL>"></script>
<script>
    const credential = new awhere.identity.OAuth({
        aWhereUrl: '<Your aWhere URL>',
        appId: '<Your App Id>',
        callbackUrl: '/oauth-callback.html',
    });
    awhere.identity.identityManager.registers([credential]);
    awhere.identity.identityManager.setDefaultCredential(credential);
    credential.syncWithStorage().then(() => {
        if (!awhere.identity.identityManager.defaultOAuth.signedIn) {
            return awhere.identity.identityManager.defaultOAuth.signIn();
        }
        // go to the signed-in page
    });
</script>
<!-- oauth-callback.html -->

<script src="<Your aWhere JavaScript API URL>"></script>
<script>
    awhere.identity
        .fetchToken(location)
        .then(() => {
            // authorized page
            location.href = '/';
        })
        .catch((err) => {
            // oauth flow authorized page
            location.href = '/sigin?' + err;
        });
</script>

2. Use the API

import { Item, User } from '@awhere/api/core';
// Load item
Item.fromId('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').then((items) => {
    console.log('items', items);
});

// List users (admin only)
User.find().then((users) => {
    console.log('users', users);
});

HTML Page

<script src="<Your aWhere JavaScript API URL>"></script>
<script>
    // List your content
    awhere.core.Item.fromId('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx').then((item) => {
        console.log('item', item);
    });

    // List users (admin only)
    awhere.core.User.find().then((users) => {
        console.log('users', users);
    });
</script>
0.5.4

5 months ago

0.5.3

8 months ago

0.5.2-beta.1

1 year ago

0.5.2-beta.2

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.4.37

2 years ago

0.4.38

2 years ago

0.4.32

2 years ago

0.4.35

2 years ago

0.4.36

2 years ago

0.4.33

2 years ago

0.4.34

2 years ago

0.4.31

2 years ago

0.4.30

3 years ago

0.4.29

3 years ago

0.4.28

3 years ago

0.4.26

3 years ago

0.4.27

3 years ago

0.4.21

3 years ago

0.4.24

3 years ago

0.4.25

3 years ago

0.4.22

3 years ago

0.4.23

3 years ago

0.4.20

3 years ago

0.4.19

3 years ago

0.4.18

3 years ago

0.4.17

3 years ago

0.4.16

3 years ago

0.4.15

3 years ago

0.4.13

3 years ago

0.4.14

3 years ago

0.4.12

3 years ago

0.4.11

3 years ago

0.4.10

3 years ago

0.4.9

3 years ago

0.4.8

3 years ago

0.4.7

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.1

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.3.48

3 years ago

0.3.47

3 years ago

0.3.46

3 years ago

0.3.45

3 years ago

0.3.44

3 years ago

0.3.43

3 years ago

0.3.42

3 years ago

0.3.39

3 years ago

0.3.38

3 years ago

0.3.41

3 years ago

0.3.40

3 years ago

0.3.37

3 years ago

0.3.36

3 years ago

0.3.35

3 years ago

0.3.34

3 years ago

0.3.33

3 years ago

0.3.32

3 years ago

0.3.31

4 years ago

0.3.30

4 years ago

0.3.29

4 years ago

0.3.28

4 years ago

0.3.27

4 years ago

0.3.26

4 years ago

0.3.25

4 years ago

0.3.24

4 years ago

0.3.23

4 years ago

0.3.22

4 years ago

0.3.21

4 years ago

0.3.20

4 years ago

0.3.19

4 years ago

0.3.18

4 years ago

0.3.17

4 years ago

0.3.16

4 years ago

0.3.15

4 years ago

0.3.14

4 years ago

0.3.13

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.8

4 years ago

0.3.9

4 years ago

0.3.10

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.30

4 years ago

0.2.29

4 years ago

0.2.28

4 years ago

0.2.27

4 years ago

0.2.26

4 years ago

0.2.25

4 years ago

0.2.24

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.23

4 years ago

0.1.20

4 years ago

0.1.21

4 years ago

0.1.22

4 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.17

4 years ago

0.1.16

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago