0.1.128 • Published 12 months ago

chsdk v0.1.128

Weekly downloads
-
License
-
Repository
github
Last release
12 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

12 months ago

0.1.125

12 months ago

0.1.127

12 months ago

0.1.126

12 months ago

0.1.124

1 year ago

0.1.121

1 year ago

0.1.123

1 year ago

0.1.122

1 year ago

0.1.118

1 year ago

0.1.117

1 year ago

0.1.119

1 year ago

0.1.116

1 year ago

0.1.114

1 year ago

0.1.115

1 year ago

0.1.113

1 year ago

0.1.112

1 year ago

0.1.111

1 year ago

0.1.110

1 year ago

0.1.106

1 year ago

0.1.109

1 year ago

0.1.108

1 year ago

0.1.96

1 year ago

0.1.97

1 year ago

0.1.98

1 year ago

0.1.99

1 year ago

0.1.93

1 year ago

0.1.94

1 year ago

0.1.95

1 year ago

0.1.103

1 year ago

0.1.102

1 year ago

0.1.105

1 year ago

0.1.104

1 year ago

0.1.101

1 year ago

0.1.100

1 year ago

0.1.90

1 year ago

0.1.91

1 year ago

0.1.92

1 year ago

0.1.89

1 year ago

0.1.85

1 year ago

0.1.86

1 year ago

0.1.87

1 year ago

0.1.88

1 year ago

0.1.83

1 year ago

0.1.84

1 year ago

0.1.80

1 year ago

0.1.81

1 year ago

0.1.78

1 year ago

0.1.79

1 year ago

0.1.74

1 year ago

0.1.75

1 year ago

0.1.76

1 year ago

0.1.77

1 year ago

0.1.70

1 year ago

0.1.71

1 year ago

0.1.72

1 year ago

0.1.73

1 year ago

0.1.63

1 year ago

0.1.64

1 year ago

0.1.65

1 year ago

0.1.66

1 year ago

0.1.67

1 year ago

0.1.68

1 year ago

0.1.69

1 year 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