lz-api-client
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -1,2 +0,2 @@ | ||
import { Account, Authorization, SignUpBody } from "lz-schema"; | ||
import { Account, Authorization, InsertedId, SignUpBody } from "lz-schema"; | ||
import { Client } from "../Client"; | ||
@@ -6,5 +6,15 @@ export declare class AccountService { | ||
constructor(client: Client); | ||
/** | ||
* Get account details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }: { | ||
id: string; | ||
}): Promise<Account>; | ||
/** | ||
* Sign in an account | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
signIn({ email, password }: { | ||
@@ -14,7 +24,20 @@ email: string; | ||
}): Promise<Authorization>; | ||
signUp({ name, email, password }: SignUpBody): Promise<{ | ||
insertedId: string; | ||
}>; | ||
/** | ||
* Sign up a new account | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
signUp({ name, email, password }: SignUpBody): Promise<InsertedId>; | ||
/** | ||
* Sign out the current account. | ||
* This will remove the bearer token from the client. | ||
* Redirection to the sign-in page is recommended. | ||
*/ | ||
signOut(): void; | ||
/** | ||
* Get the account details of the currently authenticated user. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getAuth(): Promise<Account>; | ||
} |
@@ -17,5 +17,15 @@ "use strict"; | ||
} | ||
/** | ||
* Get account details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }) { | ||
return this.client.get(`/accounts/${id}`, {}); | ||
} | ||
/** | ||
* Sign in an account | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
signIn(_a) { | ||
@@ -28,2 +38,7 @@ return __awaiter(this, arguments, void 0, function* ({ email, password }) { | ||
} | ||
/** | ||
* Sign up a new account | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
signUp(_a) { | ||
@@ -34,5 +49,15 @@ return __awaiter(this, arguments, void 0, function* ({ name, email, password }) { | ||
} | ||
/** | ||
* Sign out the current account. | ||
* This will remove the bearer token from the client. | ||
* Redirection to the sign-in page is recommended. | ||
*/ | ||
signOut() { | ||
this.client.token = null; | ||
} | ||
/** | ||
* Get the account details of the currently authenticated user. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getAuth() { | ||
@@ -39,0 +64,0 @@ return this.client.get("/account-auth", {}); |
@@ -6,5 +6,16 @@ import { Campaign, Journey, CampaignStatus, CreateCampaignBody } from 'lz-schema'; | ||
constructor(client: Client); | ||
/** | ||
* Get campaign details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }: { | ||
id: string; | ||
}): Promise<Campaign>; | ||
/** | ||
* Search campaigns by name and/or status. | ||
* If no params are provided, it will return all campaigns. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
search(params: { | ||
@@ -16,11 +27,31 @@ name?: string; | ||
}): Promise<Campaign[]>; | ||
/** | ||
* Create a new campaign | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
create(params: CreateCampaignBody): Promise<{ | ||
id: string; | ||
}>; | ||
/** | ||
* Update a campaign by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
update({ id, ...params }: { | ||
id: string; | ||
} & CreateCampaignBody): Promise<unknown>; | ||
/** | ||
* Delete a campaign by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
delete({ id }: { | ||
id: string; | ||
}): Promise<unknown>; | ||
/** | ||
* Get all journeys of a specific campaign | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getJourneys({ campaignId }: { | ||
@@ -27,0 +58,0 @@ campaignId: string; |
@@ -19,11 +19,32 @@ "use strict"; | ||
} | ||
/** | ||
* Get campaign details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }) { | ||
return this.client.get(`/campaigns/${id}`, {}); | ||
} | ||
/** | ||
* Search campaigns by name and/or status. | ||
* If no params are provided, it will return all campaigns. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
search(params) { | ||
return this.client.get(`/campaigns`, params); | ||
} | ||
/** | ||
* Create a new campaign | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
create(params) { | ||
return this.client.post(`/campaigns`, params); | ||
} | ||
/** | ||
* Update a campaign by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
update(_a) { | ||
@@ -33,5 +54,15 @@ var { id } = _a, params = __rest(_a, ["id"]); | ||
} | ||
/** | ||
* Delete a campaign by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
delete({ id }) { | ||
return this.client.delete(`/campaigns/${id}`, {}); | ||
} | ||
/** | ||
* Get all journeys of a specific campaign | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getJourneys({ campaignId }) { | ||
@@ -38,0 +69,0 @@ return this.client.get(`/campaigns/${campaignId}/journeys`, {}); |
@@ -6,6 +6,21 @@ import { CreateJourneyParams, InsertedId, Journey } from 'lz-schema'; | ||
constructor(client: Client); | ||
/** | ||
* Get journey details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }: { | ||
id: string; | ||
}): Promise<Journey>; | ||
/** | ||
* Create a new journey | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
create(journey: CreateJourneyParams): Promise<InsertedId>; | ||
/** | ||
* Update a journey by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
update({ id, ...journey }: { | ||
@@ -12,0 +27,0 @@ id: string; |
@@ -19,8 +19,23 @@ "use strict"; | ||
} | ||
/** | ||
* Get journey details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }) { | ||
return this.client.get(`/journeys/${id}`, {}); | ||
} | ||
/** | ||
* Create a new journey | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
create(journey) { | ||
return this.client.post('/journeys', journey); | ||
} | ||
/** | ||
* Update a journey by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
update(_a) { | ||
@@ -27,0 +42,0 @@ var { id } = _a, journey = __rest(_a, ["id"]); |
@@ -6,5 +6,16 @@ import { Layer } from 'lz-schema'; | ||
constructor(client: Client); | ||
/** | ||
* Get layer details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }: { | ||
id: string; | ||
}): Promise<Layer>; | ||
/** | ||
* Search layers by name. | ||
* If no params are provided, it will return all layers. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
search(params: { | ||
@@ -11,0 +22,0 @@ name?: string; |
@@ -8,5 +8,16 @@ "use strict"; | ||
} | ||
/** | ||
* Get layer details by id | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
get({ id }) { | ||
return this.client.get(`/layers/${id}`, {}); | ||
} | ||
/** | ||
* Search layers by name. | ||
* If no params are provided, it will return all layers. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
search(params) { | ||
@@ -13,0 +24,0 @@ return this.client.get(`/layers`, params); |
@@ -1,2 +0,2 @@ | ||
import { CreateUserEventParams, CreateUserParams, CreateUserResponse, User, UserCampaign, UserEventsCountQuery } from 'lz-schema'; | ||
import { CreateUserEventParams, CreateUserParams, CreateUserResponse, User, UserCampaign, UserEventsCountQuery, UserMetric } from 'lz-schema'; | ||
import { Client } from '../Client'; | ||
@@ -6,16 +6,57 @@ export declare class UserService { | ||
constructor(client: Client); | ||
/** | ||
* Authenticate a user in a workspace. | ||
* @returns the user details. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
authenticate({ workspaceId }: { | ||
workspaceId: string; | ||
}): Promise<User>; | ||
/** | ||
* Create a new anonymous user in a workspace. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
create({ workspaceId, trafficSource, variables }: CreateUserParams): Promise<CreateUserResponse>; | ||
/** | ||
* Get the active campaign for the user. | ||
* An active campaign is a campaign that the user is currently targeted by. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getActiveCampaign(): Promise<UserCampaign>; | ||
getMetric(metricName: string): Promise<{ | ||
name: string; | ||
value: number; | ||
}>; | ||
/** | ||
* Get the user's metric by metric name. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getMetric(metricName: string): Promise<UserMetric>; | ||
/** | ||
* Get the count of occurrences of a specific event for a user. | ||
* @param key - The event key. | ||
* @param from - The date from which to count the events as a timestamp. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getEventsCount({ key, from }: UserEventsCountQuery): Promise<{ | ||
count: number; | ||
}>; | ||
/** | ||
* Track an event occurrence for a user. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
trackEvent(event: CreateUserEventParams): Promise<unknown>; | ||
/** | ||
* Set the user's metrics. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
setMetrics(metrics: Record<string, number>): Promise<void>; | ||
/** | ||
* Mark a campaign as completed for the user, so it won't be targeted again. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
setCompletedCampaign({ campaignId }: { | ||
@@ -22,0 +63,0 @@ campaignId: string; |
@@ -8,5 +8,16 @@ "use strict"; | ||
} | ||
/** | ||
* Authenticate a user in a workspace. | ||
* @returns the user details. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
authenticate({ workspaceId }) { | ||
return this.client.get(`/workspaces/${workspaceId}/user-auth`, {}); | ||
} | ||
/** | ||
* Create a new anonymous user in a workspace. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
create({ workspaceId, trafficSource, variables }) { | ||
@@ -19,17 +30,50 @@ return this.client.post('/users', { | ||
} | ||
/** | ||
* Get the active campaign for the user. | ||
* An active campaign is a campaign that the user is currently targeted by. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getActiveCampaign() { | ||
return this.client.get('/user-active-campaign', {}); | ||
} | ||
/** | ||
* Get the user's metric by metric name. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getMetric(metricName) { | ||
return this.client.get(`/user-metrics/${metricName}`, {}); | ||
} | ||
/** | ||
* Get the count of occurrences of a specific event for a user. | ||
* @param key - The event key. | ||
* @param from - The date from which to count the events as a timestamp. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
getEventsCount({ key, from }) { | ||
return this.client.get('/user-events-count', { key, from }); | ||
} | ||
/** | ||
* Track an event occurrence for a user. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
trackEvent(event) { | ||
return this.client.post('/user-events', Object.assign({}, event)); | ||
} | ||
/** | ||
* Set the user's metrics. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
setMetrics(metrics) { | ||
return this.client.post(`/user-metrics`, metrics); | ||
} | ||
/** | ||
* Mark a campaign as completed for the user, so it won't be targeted again. | ||
* @throws { ClientError } | ||
* @throws { ServerError } | ||
*/ | ||
setCompletedCampaign({ campaignId }) { | ||
@@ -36,0 +80,0 @@ return this.client.post('/user-completed-campaign', { campaignId }); |
{ | ||
"name": "lz-api-client", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "client sdk for layerZ api", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -67,3 +67,22 @@ # lz-api-client | ||
### Handling errors | ||
Every service method throws errors if something goes wrong. The errors that could be thrown | ||
are: | ||
- `ClientError` Means that something is wrong with the client request, for example invalid | ||
parameters. This error type encapsulate all HTTP errors from 400 to 499. | ||
The error includes these | ||
fields: | ||
- **status** (equal to `fail`) | ||
- **message** | ||
- **data** (object like, where keys are the invalid params and values the error message) | ||
- `ServerError` Means that something is wrong in the server, for example server is | ||
not available. This error type encapsulate all HTTP errors from 500. The error includes these | ||
fields: | ||
- **status** equal to `error` | ||
- **message** | ||
## License | ||
This project is licensed under the MIT License. See the LICENSE file for details. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
39651
758
87
3