Skip to content

Commit

Permalink
Merge branch 'feat/create-lead-upload-files' of https://github.com/ba…
Browse files Browse the repository at this point in the history
…kaphp/kanvas-core-js into feat/create-lead-upload-files
  • Loading branch information
lizandro-mc committed Nov 8, 2023
2 parents a75c618 + f740b8b commit 2da070a
Showing 46 changed files with 2,165 additions and 71 deletions.
119 changes: 118 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,118 @@
# Kanvas Core JS
# Kanvas Core JS
## Introduction

Welcome to the documentation for the Kanvas SDK, a TypeScript SDK designed exclusively to seamlessly connect with the Kanvas Niche ecosystem. This SDK is crafted to enhance the development of headless applications by providing easy-to-use interfaces for interacting with various modules within the Kanvas Niche ecosystem.

## Table of Contents

1. [Getting Started](#getting-started)
- [Installation](#installation)
- [Initializate the sdk](#initializate-the-sdk)
2. [Modules](#modules)
- [Ecosystem](#ecosystem)
- [Inventory](#inventory)
- [Social](#social)
3. [Usage Examples](#usage-examples)
4. [API Reference](#api-reference)
5. [Contribution Guidelines](#contribution-guidelines)
6. [Contact and Support](#contact-and-support)


## Getting Started

### Installation

To begin using the Kanvas SDK in your project, follow these simple steps:

```bash
npm install @kanvas/core
```

### Initializate the sdk

Before using any module, you need to authenticate your application with the Kanvas Niche ecosystem. Obtain your API keys from the Kanvas Niche dashboard and initialize the SDK with the following code:

```typescript

import KanvasCore, { genericAuthMiddleware } from '@kanvas/core';

// Function to retrieve the authentication token from cookies
const getKey = async (): Promise<string | null> => {
return localStorage.getItem("token") || null // wherever you have saved the user token
};

// Initialize Kanvas Core
const client= new KanvasCore({
url: 'kanvas-url',
key: 'your-kanvas-api-key',
middlewares: [genericAuthMiddleware(getKey)]
});


```

## Modules

The Kanvas Niche SDK provides specific modules for common problems encountered during headless app development. Here are the key modules:

### Ecosystem

The Ecosystem module handles authentication, teams, and company-related functionalities.

### Inventory

The Inventory module manages products, variants, and distribution channels.

### Social

The Social module deals with follows, comments, reactions, and messaging features.

### CRM

The CRM module covers leads, deals, and pipelines for customer relationship management.


## Usage Examples

Here are some basic examples demonstrating how to use the Kanvas Niche SDK:

### Ecosystem - User Login

```typescript

const user = await client.auth.login(email, password);
console.log(user);
```

### Inventory

```typescript

const products = await client.inventory.getProduct();
console.log(products);
```


### CRM - Leads

```typescript

const leads = await client.lead.getAllLeads();
console.log(leads);
```



## API Reference

For a comprehensive list of available methods and their descriptions, refer to the [API Reference](https://documenter.getpostman.com/view/15472655/2s93CKNtdP).

## Contribution Guidelines

If you'd like to contribute to the Kanvas Niche SDK, please follow our [Contribution Guidelines](). TBD

## Contact and Support

If you have any questions, feedback, or issues, feel free to reach out to our team at the TBD

Happy coding with Kanvas!
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"version": "0.0.34",

"version": "0.0.56",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@@ -58,4 +59,4 @@
"graphql": "^16.6.0",
"typescript-transform-paths": "^3.4.6"
}
}
}
65 changes: 49 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { ApolloClient, ApolloLink, HttpLink, InMemoryCache, RequestHandler, NormalizedCacheObject } from "@apollo/client/core";
import { App, Auth, Users, CustomFields, Locations, Leads, Inventory } from './modules';
import {
ApolloClient,
ApolloLink,
HttpLink,
InMemoryCache,
RequestHandler,
NormalizedCacheObject,
} from '@apollo/client/core';
import {
App,
Auth,
Users,
CustomFields,
Locations,
Leads,
Inventory,
Agents,
Cart,
Order,
UsersLists,
UsersInteractions,
Messages
} from './modules';

import { setContext } from '@apollo/client/link/context';
import Settings from "./modules/settings";
import Settings from './modules/settings';

export * from './types';
export * from './queries';
@@ -19,17 +40,19 @@ interface Options {
adminKey?: string;
}

export function genericAuthMiddleware(fn: () => Promise<string | null | undefined>) {
export function genericAuthMiddleware(
fn: () => Promise<string | null | undefined>
) {
return setContext(async (_, context) => {
const key = await fn();

const headers = {
...context.headers,
'Authorization': key ? `Bearer ${key}` : '',
}
Authorization: key ? `Bearer ${key}` : '',
};

return { headers };
})
});
}

export function locationMiddleware(
@@ -57,8 +80,12 @@ export default class KanvasCore {
public locations: Locations;
public leads: Leads;
public inventory: Inventory;


public userInteraction: UsersInteractions;
public agents: Agents;
public cart: Cart;
public order: Order;
public usersLists: UsersLists;
public messages: Messages;
constructor(protected options: Options) {
this.client = new ApolloClient({
link: this.generateLink(),
@@ -70,10 +97,16 @@ export default class KanvasCore {
this.users = new Users(this.client);
this.customFields = new CustomFields(this.client);
this.settings = new Settings(this.client, this.options.key);
this.locations = new Locations(this.client)
this.locations = new Locations(this.client);
this.leads = new Leads(this.client);
this.inventory = new Inventory(this.client)

this.inventory = new Inventory(this.client);
this.userInteraction = new UsersInteractions(this.client);
this.inventory = new Inventory(this.client);
this.agents = new Agents(this.client);
this.cart = new Cart(this.client);
this.order = new Order(this.client);
this.usersLists = new UsersLists(this.client);
this.messages = new Messages(this.client);
}

protected generateURL() {
@@ -86,16 +119,16 @@ export default class KanvasCore {
...context.headers,
'X-Kanvas-App': this.options.key,
...(this.options.adminKey && { 'X-Kanvas-Key': this.options.adminKey }),
}
return { headers }
})
};
return { headers };
});
}

protected generateLink(): ApolloLink {
return ApolloLink.from([
...(this.options.middlewares || []),
this.generateMiddleware(),
this.generateURL(),
])
]);
}
}
38 changes: 38 additions & 0 deletions src/modules/agents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
GET_ALL_AGENTS_QUERY,
GET_AGENTS_BY_USER_ID_QUERY,
} from '../../queries';
import { ClientType } from '../../index';

import { AgentsData, WhereCondition } from '../../types';

export class Agents {
constructor(protected client: ClientType) {}

public async getAllAgents(
first?: number,
page?: number
): Promise<AgentsData> {
const response = await this.client.query({
query: GET_ALL_AGENTS_QUERY,
variables: { first, page },
});

return response.data;
}

public async getAgentsByUserID(id: string): Promise<AgentsData> {
const where: WhereCondition = {
column: 'USERS_ID',
operator: 'EQ',
value: id,
};

const response = await this.client.query({
query: GET_AGENTS_BY_USER_ID_QUERY,
variables: { where },
});

return response.data;
}
}
54 changes: 49 additions & 5 deletions src/modules/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { AppUserInterface, AppUpdatePasswordInterface } from '../../types';
import { USER_UPDATE_PASSWORD_MUTATION } from '../../mutations';
import { APP_USERS_QUERY } from '../../queries';
import type { AppUserInterface, AppUpdatePasswordInterface, WhereCondition, AllAppUsersInterface, OrderBy, AppCreateUserParams, CreatedAppCreateUser } from '../../types';
import { APP_CREATE_USER, USER_UPDATE_PASSWORD_MUTATION } from '../../mutations';
import { APP_USERS_QUERY, GET_ALL_APP_USERS } from '../../queries';
import type { ClientType } from '../../index';

class Users {
constructor(protected client: ClientType) {}
constructor(protected client: ClientType) { }

/**
* Update user password as admin
@@ -50,14 +50,58 @@ class Users {
return response.data.appUsers.data[0];
}

public async getAllAppUsers(
options: {
first?: number;
page?: number;
whereCondition?: WhereCondition;
orderByCondition?: OrderBy[];
search?: string;
} = {}
): Promise<AllAppUsersInterface> {
const { first, page, whereCondition, orderByCondition, search } = options;

const response = await this.client.query({
query: GET_ALL_APP_USERS,
variables: {
first,
page,
whereCondition,
orderByCondition,
search
},
fetchPolicy: 'network-only',
partialRefetch: true,
});
return response.data;
}

}


class Admin {
constructor(protected client: ClientType) { }



public async appCreateUser(data: AppCreateUserParams): Promise<CreatedAppCreateUser> {
const response = await this.client.mutate({
mutation: APP_CREATE_USER,
variables: { data: data },
});

return response.data
}


}

export class App {
public users: Users;
public admin: Admin;

constructor(protected client: ClientType) {
this.users = new Users(this.client);
this.admin = new Admin(this.client);

}
}
Loading

0 comments on commit 2da070a

Please sign in to comment.