1.0.3 • Published 1 year ago
@pacely-next/office v1.0.3
@pacely/office
Authentication
Strategies
Our authentication strategies currently includes:
Protocol | Grant type | Current stats |
---|---|---|
OAuth2 | Client Credentials | ready |
OAuth2 | Authorization Code | not started |
OAuth2 | Device Code | not started |
JWT | JSON Web Tokens | not started |
Constructor options
Option | Type | Description | Default |
---|---|---|---|
provider | string | Choose provider. | poweroffice |
auth | object | Object containing keys etc. | - |
testing | bool | Whether to authenticate with a demo api. | false |
Example
import Office from '@pacely/office'
let authenticated: boolean = false;
const office = new Office({
provider: 'poweroffice',
testing: true,
auth: {
client_id: '<Client ID>',
client_key: '<Client key>'
}
});
// Authenticate with the choosen provider
office.authenticate().then((authStatus: boolean) => {
authenticated = authStatus
});
Resources
Customers
const provider = office.provider;
if (provider.authenticated) {
const customers: CustomerModel[] = provider.customers({ allFields: true }).all();
customers.map((customer: CustomerModel) => {
console.log(customer.name); // ACME AS
})
}
Invoices
Get invoices
const provider = office.provider;
if (provider.authenticated) {
const invoices: Invoice[] = provider.invoices.find({
filter: {
projectCode: 1234,
totalAmount: {
operator: 'gt',
value: 200
}
},
order: {
totalAmount: 'asc'
},
top: 10
});
invoices.map((invoice: Invoice) => {
console.log(invoice.totalAmount);
})
}
Project
if (provider.authenticated) {
const projects: Project[] = provider.projects.all();
const project: Project = provider.projects.find(id);
const projectActivities: ProjectActivity[] = provider.projects.activities.all();
const customers: CustomerModel[] = await office.customers().all();
}
API'er
- PowerOffice - https://api.poweroffice.net/Web/docs/index.html#Reference/Rest/Services.md
- SuperOffice - https://community.superoffice.com/documentation/sdk/SO.NetServer.Web.Services/html/Reference-WebAPI-WebAPI.htm
- Fiken - https://api.fiken.no/api/v2/docs/#/companies/getCompanies
https://github.com/nuxt-community/auth-module/blob/dev/src/index.ts
1.0.3
1 year ago