repzo 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +18 -0
- package/lib/index.js +70 -0
- package/lib/types/index.d.ts +263 -0
- package/lib/types/index.js +1 -0
- package/package.json +4 -3
- package/{index.ts → src/index.ts} +7 -23
- package/{types → src/types}/index.ts +0 -0
- package/test.ts +1 -1
- package/tsconfig.json +16 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Service, Options, Headers } from "./types/index";
|
|
2
|
+
export default class Repzo {
|
|
3
|
+
private svAPIEndpoint;
|
|
4
|
+
headers: Headers;
|
|
5
|
+
constructor(apiKey: string, options?: Options);
|
|
6
|
+
private _fetch;
|
|
7
|
+
private _create;
|
|
8
|
+
private _update;
|
|
9
|
+
private _delete;
|
|
10
|
+
client: {
|
|
11
|
+
_path: string;
|
|
12
|
+
find: (params?: Service.Client.Find.Params | undefined) => Promise<Service.Client.Find.Result>;
|
|
13
|
+
get: (id: Service.Client.Get.ID, params?: Service.Client.Get.Params | undefined) => Promise<Service.Client.Get.Result>;
|
|
14
|
+
create: (body: Service.Client.Create.Body) => Promise<Service.Client.Create.Result>;
|
|
15
|
+
update: (id: Service.Client.Update.ID, body: Service.Client.Update.Body) => Promise<Service.Client.Update.Result>;
|
|
16
|
+
remove: (id: Service.Client.Remove.ID) => Promise<Service.Client.Remove.Result>;
|
|
17
|
+
};
|
|
18
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
export default class Repzo {
|
|
3
|
+
constructor(apiKey, options) {
|
|
4
|
+
this.client = {
|
|
5
|
+
_path: "/client",
|
|
6
|
+
find: async (params) => {
|
|
7
|
+
let res = await this._fetch(this.svAPIEndpoint, this.client._path, params);
|
|
8
|
+
return res;
|
|
9
|
+
},
|
|
10
|
+
get: async (id, params) => {
|
|
11
|
+
return await this._fetch(this.svAPIEndpoint, this.client._path + `/${id}`, params);
|
|
12
|
+
},
|
|
13
|
+
create: async (body) => {
|
|
14
|
+
let res = await this._create(this.svAPIEndpoint, this.client._path, body);
|
|
15
|
+
return res;
|
|
16
|
+
},
|
|
17
|
+
update: async (id, body) => {
|
|
18
|
+
let res = await this._update(this.svAPIEndpoint, this.client._path + `/${id}`, body);
|
|
19
|
+
return res;
|
|
20
|
+
},
|
|
21
|
+
remove: async (id) => {
|
|
22
|
+
let res = await this._delete(this.svAPIEndpoint, this.client._path + `/${id}`);
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
this.svAPIEndpoint =
|
|
27
|
+
!(options === null || options === void 0 ? void 0 : options.env) || (options === null || options === void 0 ? void 0 : options.env) == "production"
|
|
28
|
+
? "https://sv.api.repzo.me"
|
|
29
|
+
: (options === null || options === void 0 ? void 0 : options.env) == "staging"
|
|
30
|
+
? "https://staging.sv.api.repzo.me"
|
|
31
|
+
: (options === null || options === void 0 ? void 0 : options.env) == "local"
|
|
32
|
+
? "http://localhost:3030"
|
|
33
|
+
: "";
|
|
34
|
+
this.headers = {
|
|
35
|
+
"api-key": apiKey,
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Accept: "application/json"
|
|
38
|
+
};
|
|
39
|
+
if (options === null || options === void 0 ? void 0 : options.headers)
|
|
40
|
+
Object.assign(this.headers, options.headers);
|
|
41
|
+
}
|
|
42
|
+
async _fetch(baseUrl, path, params) {
|
|
43
|
+
let res = await axios.get(baseUrl + path, {
|
|
44
|
+
params,
|
|
45
|
+
headers: this.headers
|
|
46
|
+
});
|
|
47
|
+
return res.data;
|
|
48
|
+
}
|
|
49
|
+
async _create(baseUrl, path, body, params) {
|
|
50
|
+
let res = await axios.post(baseUrl + path, body, {
|
|
51
|
+
params,
|
|
52
|
+
headers: this.headers
|
|
53
|
+
});
|
|
54
|
+
return res.data;
|
|
55
|
+
}
|
|
56
|
+
async _update(baseUrl, path, body, params) {
|
|
57
|
+
let res = await axios.put(baseUrl + path, body, {
|
|
58
|
+
params,
|
|
59
|
+
headers: this.headers
|
|
60
|
+
});
|
|
61
|
+
return res.data;
|
|
62
|
+
}
|
|
63
|
+
async _delete(baseUrl, path, params) {
|
|
64
|
+
let res = await axios.delete(baseUrl + path, {
|
|
65
|
+
params,
|
|
66
|
+
headers: this.headers
|
|
67
|
+
});
|
|
68
|
+
return res.data;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
export interface Params {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
export interface Data {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export interface Options {
|
|
8
|
+
env?: "staging" | "local" | "production";
|
|
9
|
+
headers?: {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface Headers {
|
|
14
|
+
"api-key": string;
|
|
15
|
+
"Content-Type": string;
|
|
16
|
+
Accept: string;
|
|
17
|
+
[key: string]: string;
|
|
18
|
+
}
|
|
19
|
+
export declare namespace Service {
|
|
20
|
+
namespace Client {
|
|
21
|
+
interface Financials {
|
|
22
|
+
credit_limit?: number;
|
|
23
|
+
}
|
|
24
|
+
type JobType = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
25
|
+
interface JobObject {
|
|
26
|
+
type: JobType[];
|
|
27
|
+
description: string;
|
|
28
|
+
tag: string;
|
|
29
|
+
product_id?: string;
|
|
30
|
+
form_id?: string;
|
|
31
|
+
is_required?: boolean;
|
|
32
|
+
category_id?: string;
|
|
33
|
+
order?: number;
|
|
34
|
+
company_namespace: string[];
|
|
35
|
+
}
|
|
36
|
+
interface ShelfshareTarget {
|
|
37
|
+
msl: string;
|
|
38
|
+
contracted_checkout: number;
|
|
39
|
+
contracted_shelf_length: number;
|
|
40
|
+
total_category_length: number;
|
|
41
|
+
}
|
|
42
|
+
interface RepTarget {
|
|
43
|
+
rep: string;
|
|
44
|
+
target: number;
|
|
45
|
+
classification: string;
|
|
46
|
+
}
|
|
47
|
+
interface ClientSchema {
|
|
48
|
+
_id: string;
|
|
49
|
+
local_name?: string;
|
|
50
|
+
tags?: string[];
|
|
51
|
+
cell_phone?: string;
|
|
52
|
+
city?: string;
|
|
53
|
+
client_code?: string;
|
|
54
|
+
contact_name?: string;
|
|
55
|
+
contact_title?: string;
|
|
56
|
+
country?: string;
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
formatted_address?: string;
|
|
59
|
+
lat?: number;
|
|
60
|
+
lng?: number;
|
|
61
|
+
location_verified?: boolean;
|
|
62
|
+
name: string;
|
|
63
|
+
phone?: string;
|
|
64
|
+
state?: string;
|
|
65
|
+
zip?: string;
|
|
66
|
+
assigned_to?: string[];
|
|
67
|
+
last_location_update?: number;
|
|
68
|
+
credit_limit?: number;
|
|
69
|
+
tax_number?: string;
|
|
70
|
+
sync_id?: string;
|
|
71
|
+
rep_targets?: RepTarget[];
|
|
72
|
+
shelf_share_targets?: ShelfshareTarget[];
|
|
73
|
+
profile_pic?: string;
|
|
74
|
+
logo?: string;
|
|
75
|
+
website?: string;
|
|
76
|
+
email?: string;
|
|
77
|
+
comment?: string;
|
|
78
|
+
parent_client_id?: string;
|
|
79
|
+
target_visit?: number;
|
|
80
|
+
geofencing_radius?: number;
|
|
81
|
+
price_tag?: string;
|
|
82
|
+
jobs?: JobObject[];
|
|
83
|
+
status?: string;
|
|
84
|
+
job_category?: string[];
|
|
85
|
+
availability_msl?: string[];
|
|
86
|
+
territory?: string;
|
|
87
|
+
sv_priceList?: string;
|
|
88
|
+
assigned_media?: string[];
|
|
89
|
+
assigned_products?: string[];
|
|
90
|
+
assigned_product_groups?: string;
|
|
91
|
+
verifiedUntil?: number;
|
|
92
|
+
financials?: Financials;
|
|
93
|
+
customFields?: {
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
};
|
|
96
|
+
paymentTerm?: string;
|
|
97
|
+
speciality?: string[];
|
|
98
|
+
company_namespace: string[];
|
|
99
|
+
channel?: string;
|
|
100
|
+
isChain?: boolean;
|
|
101
|
+
chain?: string;
|
|
102
|
+
teams?: string[];
|
|
103
|
+
payment_type: "cash" | "credit";
|
|
104
|
+
integration_meta?: {
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
};
|
|
107
|
+
integrated_client_balance?: number;
|
|
108
|
+
createdAt: string;
|
|
109
|
+
updatedAt: string;
|
|
110
|
+
__v: number;
|
|
111
|
+
}
|
|
112
|
+
interface ClientBody {
|
|
113
|
+
name?: string;
|
|
114
|
+
local_name?: string;
|
|
115
|
+
tags?: string[];
|
|
116
|
+
cell_phone?: string;
|
|
117
|
+
city?: string;
|
|
118
|
+
client_code?: string;
|
|
119
|
+
contact_name?: string;
|
|
120
|
+
contact_title?: string;
|
|
121
|
+
country?: string;
|
|
122
|
+
disabled?: boolean;
|
|
123
|
+
formatted_address?: string;
|
|
124
|
+
lat?: number;
|
|
125
|
+
lng?: number;
|
|
126
|
+
location_verified?: boolean;
|
|
127
|
+
phone?: string;
|
|
128
|
+
state?: string;
|
|
129
|
+
zip?: string;
|
|
130
|
+
assigned_to?: string[];
|
|
131
|
+
last_location_update?: number;
|
|
132
|
+
credit_limit?: number;
|
|
133
|
+
tax_number?: string;
|
|
134
|
+
sync_id?: string;
|
|
135
|
+
rep_targets?: RepTarget[];
|
|
136
|
+
shelf_share_targets?: ShelfshareTarget[];
|
|
137
|
+
profile_pic?: string;
|
|
138
|
+
logo?: string;
|
|
139
|
+
website?: string;
|
|
140
|
+
email?: string;
|
|
141
|
+
comment?: string;
|
|
142
|
+
parent_client_id?: string;
|
|
143
|
+
target_visit?: number;
|
|
144
|
+
geofencing_radius?: number;
|
|
145
|
+
price_tag?: string;
|
|
146
|
+
jobs?: JobObject[];
|
|
147
|
+
status?: string;
|
|
148
|
+
job_category?: string[];
|
|
149
|
+
availability_msl?: string[];
|
|
150
|
+
territory?: string;
|
|
151
|
+
sv_priceList?: string;
|
|
152
|
+
assigned_media?: string[];
|
|
153
|
+
assigned_products?: string[];
|
|
154
|
+
assigned_product_groups?: string;
|
|
155
|
+
verifiedUntil?: number;
|
|
156
|
+
financials?: Financials;
|
|
157
|
+
customFields?: {
|
|
158
|
+
[key: string]: any;
|
|
159
|
+
};
|
|
160
|
+
paymentTerm?: string;
|
|
161
|
+
speciality?: string[];
|
|
162
|
+
company_namespace?: string[];
|
|
163
|
+
channel?: string;
|
|
164
|
+
isChain?: boolean;
|
|
165
|
+
chain?: string;
|
|
166
|
+
teams?: string[];
|
|
167
|
+
payment_type?: "cash" | "credit";
|
|
168
|
+
integration_meta?: {
|
|
169
|
+
[key: string]: any;
|
|
170
|
+
};
|
|
171
|
+
integrated_client_balance?: number;
|
|
172
|
+
}
|
|
173
|
+
type PopulatedKeys = "tags" | "reps" | "assigned_to" | "sv_priceList" | "paymentTerm" | "job_category" | "msl" | "chain" | "channel" | "status" | "product" | "assigned_products" | "assigned_product_groups" | "speciality" | "teams";
|
|
174
|
+
export namespace Find {
|
|
175
|
+
type Params = DefaultPaginationQueryParams & {
|
|
176
|
+
from_updatedAt?: number;
|
|
177
|
+
to_updatedAt?: number;
|
|
178
|
+
from_createdAt?: number;
|
|
179
|
+
to_createdAt?: number;
|
|
180
|
+
createdAt?: number;
|
|
181
|
+
updatedAt?: number;
|
|
182
|
+
name?: string;
|
|
183
|
+
search?: string;
|
|
184
|
+
disabled?: boolean;
|
|
185
|
+
active?: boolean;
|
|
186
|
+
tags?: string[] | string;
|
|
187
|
+
_id?: string[] | string;
|
|
188
|
+
assigned_to?: string[] | string;
|
|
189
|
+
availability_msl?: string[] | string;
|
|
190
|
+
status?: string[] | string;
|
|
191
|
+
CLIENT_TAGS?: string[] | string;
|
|
192
|
+
AREA_TAGS?: string[] | string;
|
|
193
|
+
isChain?: boolean;
|
|
194
|
+
chain?: string[] | string;
|
|
195
|
+
channel?: string[] | string;
|
|
196
|
+
city?: string[] | string;
|
|
197
|
+
client_code?: string[] | string;
|
|
198
|
+
country?: string[] | string;
|
|
199
|
+
location_verified?: boolean;
|
|
200
|
+
state?: string[] | string;
|
|
201
|
+
sv_priceList?: string[] | string;
|
|
202
|
+
assigned_media?: string[] | string;
|
|
203
|
+
assigned_products?: string[] | string;
|
|
204
|
+
teams?: string[] | string;
|
|
205
|
+
integrated_client_balance?: number;
|
|
206
|
+
tax_number?: string;
|
|
207
|
+
speciality?: string[] | string;
|
|
208
|
+
assigned_product_groups?: string[] | string;
|
|
209
|
+
populatedKeys?: PopulatedKeys[];
|
|
210
|
+
};
|
|
211
|
+
interface Result extends DefaultPaginationResult {
|
|
212
|
+
data: ClientSchema[];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
export namespace Get {
|
|
216
|
+
type ID = string;
|
|
217
|
+
interface Params {
|
|
218
|
+
populatedKeys: PopulatedKeys[];
|
|
219
|
+
}
|
|
220
|
+
type Result = ClientSchema;
|
|
221
|
+
}
|
|
222
|
+
export namespace Create {
|
|
223
|
+
interface Body extends ClientBody {
|
|
224
|
+
name: string;
|
|
225
|
+
}
|
|
226
|
+
type Result = ClientSchema;
|
|
227
|
+
}
|
|
228
|
+
export namespace Update {
|
|
229
|
+
type ID = string;
|
|
230
|
+
interface Body extends ClientBody {
|
|
231
|
+
_id?: string;
|
|
232
|
+
createdAt?: string;
|
|
233
|
+
updatedAt?: string;
|
|
234
|
+
__v?: number;
|
|
235
|
+
}
|
|
236
|
+
type Result = ClientSchema;
|
|
237
|
+
}
|
|
238
|
+
export namespace Remove {
|
|
239
|
+
type ID = string;
|
|
240
|
+
type Result = ClientSchema;
|
|
241
|
+
}
|
|
242
|
+
export {};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
export interface DefaultPaginationQueryParams {
|
|
246
|
+
per_page?: number;
|
|
247
|
+
page?: number;
|
|
248
|
+
sort?: "name" | "client_code" | "createdAt" | "updatedAt";
|
|
249
|
+
sortPageOrder?: "asc" | "dsc";
|
|
250
|
+
}
|
|
251
|
+
export interface DefaultPaginationResult {
|
|
252
|
+
total_result: number;
|
|
253
|
+
current_count: number;
|
|
254
|
+
total_pages: number;
|
|
255
|
+
current_page: number;
|
|
256
|
+
per_page: number;
|
|
257
|
+
first_page_url: string;
|
|
258
|
+
last_page_url: string;
|
|
259
|
+
next_page_url: string | null;
|
|
260
|
+
prev_page_url: string | null;
|
|
261
|
+
path: string;
|
|
262
|
+
data: any[];
|
|
263
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repzo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Repzo TypeScript SDK",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "npm run test"
|
|
7
|
+
"test": "npm run test",
|
|
8
|
+
"build": "tsc"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -17,15 +17,15 @@ export default class Repzo {
|
|
|
17
17
|
this.headers = {
|
|
18
18
|
"api-key": apiKey,
|
|
19
19
|
"Content-Type": "application/json",
|
|
20
|
-
Accept: "application/json"
|
|
20
|
+
Accept: "application/json"
|
|
21
21
|
};
|
|
22
|
-
if (options
|
|
22
|
+
if (options?.headers) Object.assign(this.headers, options.headers);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
private async _fetch(baseUrl: string, path: string, params?: Params) {
|
|
26
26
|
let res = await axios.get(baseUrl + path, {
|
|
27
27
|
params,
|
|
28
|
-
headers: this.headers
|
|
28
|
+
headers: this.headers
|
|
29
29
|
});
|
|
30
30
|
return res.data;
|
|
31
31
|
}
|
|
@@ -38,7 +38,7 @@ export default class Repzo {
|
|
|
38
38
|
) {
|
|
39
39
|
let res = await axios.post(baseUrl + path, body, {
|
|
40
40
|
params,
|
|
41
|
-
headers: this.headers
|
|
41
|
+
headers: this.headers
|
|
42
42
|
});
|
|
43
43
|
return res.data;
|
|
44
44
|
}
|
|
@@ -51,7 +51,7 @@ export default class Repzo {
|
|
|
51
51
|
) {
|
|
52
52
|
let res = await axios.put(baseUrl + path, body, {
|
|
53
53
|
params,
|
|
54
|
-
headers: this.headers
|
|
54
|
+
headers: this.headers
|
|
55
55
|
});
|
|
56
56
|
return res.data;
|
|
57
57
|
}
|
|
@@ -59,7 +59,7 @@ export default class Repzo {
|
|
|
59
59
|
private async _delete(baseUrl: string, path: string, params?: Params) {
|
|
60
60
|
let res = await axios.delete(baseUrl + path, {
|
|
61
61
|
params,
|
|
62
|
-
headers: this.headers
|
|
62
|
+
headers: this.headers
|
|
63
63
|
});
|
|
64
64
|
return res.data;
|
|
65
65
|
}
|
|
@@ -75,10 +75,6 @@ export default class Repzo {
|
|
|
75
75
|
params
|
|
76
76
|
);
|
|
77
77
|
return res;
|
|
78
|
-
// return axios.get(this.svAPIEndpoint + this.client.path, {
|
|
79
|
-
// params: params,
|
|
80
|
-
// headers: this.headers,
|
|
81
|
-
// });
|
|
82
78
|
},
|
|
83
79
|
|
|
84
80
|
get: async (
|
|
@@ -90,9 +86,6 @@ export default class Repzo {
|
|
|
90
86
|
this.client._path + `/${id}`,
|
|
91
87
|
params
|
|
92
88
|
);
|
|
93
|
-
// return axios.get(this.svAPIEndpoint + this.client.path + `/${id}`, {
|
|
94
|
-
// params: params,
|
|
95
|
-
// });
|
|
96
89
|
},
|
|
97
90
|
|
|
98
91
|
create: async (
|
|
@@ -100,9 +93,6 @@ export default class Repzo {
|
|
|
100
93
|
): Promise<Service.Client.Create.Result> => {
|
|
101
94
|
let res = await this._create(this.svAPIEndpoint, this.client._path, body);
|
|
102
95
|
return res;
|
|
103
|
-
// return axios.post(this.svAPIEndpoint + this.client.path, body, {
|
|
104
|
-
// headers: this.headers,
|
|
105
|
-
// });
|
|
106
96
|
},
|
|
107
97
|
|
|
108
98
|
update: async (
|
|
@@ -115,9 +105,6 @@ export default class Repzo {
|
|
|
115
105
|
body
|
|
116
106
|
);
|
|
117
107
|
return res;
|
|
118
|
-
// return axios.put(this.svAPIEndpoint + this.client.path + `/${id}`, body, {
|
|
119
|
-
// headers: this.headers,
|
|
120
|
-
// });
|
|
121
108
|
},
|
|
122
109
|
|
|
123
110
|
remove: async (
|
|
@@ -128,9 +115,6 @@ export default class Repzo {
|
|
|
128
115
|
this.client._path + `/${id}`
|
|
129
116
|
);
|
|
130
117
|
return res;
|
|
131
|
-
|
|
132
|
-
// headers: this.headers,
|
|
133
|
-
// });
|
|
134
|
-
},
|
|
118
|
+
}
|
|
135
119
|
};
|
|
136
120
|
}
|
|
File without changes
|
package/test.ts
CHANGED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2018",
|
|
4
|
+
"module": "ES6",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./lib",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noImplicitThis": false,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"moduleResolution": "Node"
|
|
11
|
+
},
|
|
12
|
+
"ts-node": { "esm": true },
|
|
13
|
+
"include": ["src"],
|
|
14
|
+
"exclude": ["node_modules", "**/__tests__/*", "*test*"]
|
|
15
|
+
}
|
|
16
|
+
|