0.1.128 • Published 9 months ago

chsdk v0.1.128

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Development

Usage

let client = new Client({
    organisationId: "org-name-here",
    baseDomain: "https://api.ctrl-hub.dev",
    clientId: 'insert-client-id-here',
    clientSecret: 'insert-client-secret-here',
    authDomain: 'https://auth.ctrl-hub.dev' // a request will be sent to https://auth.ctrl-hub.dev/oauth2/token
});

// Get all submissions for 'org-name-here' organisation
let { data} = await client.submissions().get()
console.log(data)

Note that when the SDK is ran within a browser, cookies will be forwarded with the API requests in the Cookie header. When authenticated, the users session token is forwarded within that header

Adding a module (for this example, shoes)

  1. Create a new model file in src/Models, src/Models/Shoe.ts which implements the Model interface

  2. Create a new service which extends BaseService in src/services e.g.

import {BaseService} from "../services/BaseService";
import {Shoe} from "../models/Shoe";
import {Client} from "Client";

export class ShoeService extends BaseService<Form> {
    constructor(client: Client) {
        super(client, "/v3/orgs/:orgId/shoes", Shoe.hydrate);
    }
}
  1. In src/services/BaseService.ts, add the model within the constructor
        this.models["shoes"] = Shoe as ModelConstructor<Shoe>;

You will then be able to do the following

let client = new Client({
    organisationId: "org-name-here",
    baseDomain: "https://api.ctrl-hub.dev",
    clientId: 'insert-client-id-here',
    clientSecret: 'insert-client-secret-here',
    authUrl: 'https://auth.ctrl-hub.dev/oauth2/token'
});

// any options, sorts, filters etc.
let options = {
    limit: 10,
    offset: 0,
    sort: [
        {
            field: "name",
            direction: "desc",
        },
    ],
    filters: [
        {
            key: "category.id",
            value: "be780a63-6944-4305-943c-e715e9177371",
        },
    ],
    include: [
        "related-model-1", "related-model-2"
    ]
} 

let shoesResponse = client.shoes.get();

The above would send a GET request to https://base-endpoint.com/v3/orgs/org-name-here/shoes?limit=10&offset=0&sort=-name&filter[category.id]=be780a63-6944-4305-943c-e715e9177371

Building the project

Everything in the src/ directory will be compiled to the dist/ directory

bun run build

Hot usage while developing

Will auto reload on file changes (assuming you have a root file called index.ts)

bun --hot index.ts

Tests

Tests are all located in "tests" in the same structure as the source files

bun test

bun test --coverage

0.1.128

9 months ago

0.1.125

9 months ago

0.1.127

9 months ago

0.1.126

9 months ago

0.1.124

9 months ago

0.1.121

10 months ago

0.1.123

10 months ago

0.1.122

10 months ago

0.1.118

10 months ago

0.1.117

10 months ago

0.1.119

10 months ago

0.1.116

10 months ago

0.1.114

10 months ago

0.1.115

10 months ago

0.1.113

10 months ago

0.1.112

10 months ago

0.1.111

10 months ago

0.1.110

10 months ago

0.1.106

11 months ago

0.1.109

11 months ago

0.1.108

11 months ago

0.1.96

11 months ago

0.1.97

11 months ago

0.1.98

11 months ago

0.1.99

11 months ago

0.1.93

11 months ago

0.1.94

11 months ago

0.1.95

11 months ago

0.1.103

11 months ago

0.1.102

11 months ago

0.1.105

11 months ago

0.1.104

11 months ago

0.1.101

11 months ago

0.1.100

11 months ago

0.1.90

11 months ago

0.1.91

11 months ago

0.1.92

11 months ago

0.1.89

11 months ago

0.1.85

11 months ago

0.1.86

11 months ago

0.1.87

11 months ago

0.1.88

11 months ago

0.1.83

11 months ago

0.1.84

11 months ago

0.1.80

12 months ago

0.1.81

12 months ago

0.1.78

12 months ago

0.1.79

12 months ago

0.1.74

12 months ago

0.1.75

12 months ago

0.1.76

12 months ago

0.1.77

12 months ago

0.1.70

12 months ago

0.1.71

12 months ago

0.1.72

12 months ago

0.1.73

12 months ago

0.1.63

1 year ago

0.1.64

12 months ago

0.1.65

12 months ago

0.1.66

12 months ago

0.1.67

12 months ago

0.1.68

12 months ago

0.1.69

12 months ago

0.1.62

1 year ago

0.1.61

1 year ago

0.1.60

1 year ago

0.1.57

1 year ago

0.1.58

1 year ago

0.1.59

1 year ago

0.1.52

1 year ago

0.1.53

1 year ago

0.1.54

1 year ago

0.1.55

1 year ago

0.1.50

1 year ago

0.1.51

1 year ago

0.1.49

1 year ago

0.1.44

1 year ago

0.1.45

1 year ago

0.1.46

1 year ago

0.1.47

1 year ago

0.1.48

1 year ago

0.1.42

1 year ago

0.1.43

1 year ago

0.1.41

1 year ago

0.1.40

1 year ago

0.1.39

1 year ago

0.1.34

1 year ago

0.1.35

1 year ago

0.1.36

1 year ago

0.1.38

1 year ago

0.1.33

1 year ago

0.1.30

1 year ago

0.1.31

1 year ago

0.1.32

1 year ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.29

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.25

1 year ago

0.1.26

1 year ago

0.1.18

1 year ago

0.1.19

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

1.0.12

1 year ago