repzo 1.0.0 → 1.0.1

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/index.ts ADDED
@@ -0,0 +1,136 @@
1
+ import axios from "axios";
2
+ import { Params, Data, Service, Options, Headers } from "./types/index";
3
+
4
+ export default class Repzo {
5
+ private svAPIEndpoint: string;
6
+ headers: Headers;
7
+ constructor(apiKey: string, options?: Options) {
8
+ this.svAPIEndpoint =
9
+ !options?.env || options?.env == "production"
10
+ ? "https://sv.api.repzo.me"
11
+ : options?.env == "staging"
12
+ ? "https://staging.sv.api.repzo.me"
13
+ : options?.env == "local"
14
+ ? "http://localhost:3030"
15
+ : "";
16
+
17
+ this.headers = {
18
+ "api-key": apiKey,
19
+ "Content-Type": "application/json",
20
+ Accept: "application/json",
21
+ };
22
+ if (options.headers) Object.assign(this.headers, options.headers);
23
+ }
24
+
25
+ private async _fetch(baseUrl: string, path: string, params?: Params) {
26
+ let res = await axios.get(baseUrl + path, {
27
+ params,
28
+ headers: this.headers,
29
+ });
30
+ return res.data;
31
+ }
32
+
33
+ private async _create(
34
+ baseUrl: string,
35
+ path: string,
36
+ body: Data,
37
+ params?: Params
38
+ ) {
39
+ let res = await axios.post(baseUrl + path, body, {
40
+ params,
41
+ headers: this.headers,
42
+ });
43
+ return res.data;
44
+ }
45
+
46
+ private async _update(
47
+ baseUrl: string,
48
+ path: string,
49
+ body: Data,
50
+ params?: Params
51
+ ) {
52
+ let res = await axios.put(baseUrl + path, body, {
53
+ params,
54
+ headers: this.headers,
55
+ });
56
+ return res.data;
57
+ }
58
+
59
+ private async _delete(baseUrl: string, path: string, params?: Params) {
60
+ let res = await axios.delete(baseUrl + path, {
61
+ params,
62
+ headers: this.headers,
63
+ });
64
+ return res.data;
65
+ }
66
+
67
+ client = {
68
+ _path: "/client",
69
+ find: async (
70
+ params?: Service.Client.Find.Params
71
+ ): Promise<Service.Client.Find.Result> => {
72
+ let res: Service.Client.Find.Result = await this._fetch(
73
+ this.svAPIEndpoint,
74
+ this.client._path,
75
+ params
76
+ );
77
+ return res;
78
+ // return axios.get(this.svAPIEndpoint + this.client.path, {
79
+ // params: params,
80
+ // headers: this.headers,
81
+ // });
82
+ },
83
+
84
+ get: async (
85
+ id: Service.Client.Get.ID,
86
+ params?: Service.Client.Get.Params
87
+ ): Promise<Service.Client.Get.Result> => {
88
+ return await this._fetch(
89
+ this.svAPIEndpoint,
90
+ this.client._path + `/${id}`,
91
+ params
92
+ );
93
+ // return axios.get(this.svAPIEndpoint + this.client.path + `/${id}`, {
94
+ // params: params,
95
+ // });
96
+ },
97
+
98
+ create: async (
99
+ body: Service.Client.Create.Body
100
+ ): Promise<Service.Client.Create.Result> => {
101
+ let res = await this._create(this.svAPIEndpoint, this.client._path, body);
102
+ return res;
103
+ // return axios.post(this.svAPIEndpoint + this.client.path, body, {
104
+ // headers: this.headers,
105
+ // });
106
+ },
107
+
108
+ update: async (
109
+ id: Service.Client.Update.ID,
110
+ body: Service.Client.Update.Body
111
+ ): Promise<Service.Client.Update.Result> => {
112
+ let res: Service.Client.Update.Result = await this._update(
113
+ this.svAPIEndpoint,
114
+ this.client._path + `/${id}`,
115
+ body
116
+ );
117
+ return res;
118
+ // return axios.put(this.svAPIEndpoint + this.client.path + `/${id}`, body, {
119
+ // headers: this.headers,
120
+ // });
121
+ },
122
+
123
+ remove: async (
124
+ id: Service.Client.Remove.ID
125
+ ): Promise<Service.Client.Remove.Result> => {
126
+ let res: Service.Client.Remove.Result = await this._delete(
127
+ this.svAPIEndpoint,
128
+ this.client._path + `/${id}`
129
+ );
130
+ return res;
131
+ // return axios.delete(this.svAPIEndpoint + this.client.path + `/${id}`, {
132
+ // headers: this.headers,
133
+ // });
134
+ },
135
+ };
136
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repzo",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Repzo TypeScript SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,5 +18,8 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/Repzo/repzo-ts/issues"
20
20
  },
21
- "homepage": "https://github.com/Repzo/repzo-ts#readme"
21
+ "homepage": "https://github.com/Repzo/repzo-ts#readme",
22
+ "dependencies": {
23
+ "axios": "^0.26.1"
24
+ }
22
25
  }
package/test.ts ADDED
@@ -0,0 +1,8 @@
1
+ import Repzo from "./index.js";
2
+ let repzo = new Repzo("");
3
+ let clients = repzo.client.find({ search: "Mecca" });
4
+ console.log(clients);
5
+ repzo.client.create({ name: "kf" });
6
+ repzo.headers["ho"] = "faf";
7
+ repzo.client.update("", {});
8
+ // repzo.
package/types/index.ts ADDED
@@ -0,0 +1,276 @@
1
+ export interface Params {
2
+ [key: string]: any;
3
+ }
4
+
5
+ export interface Data {
6
+ [key: string]: any;
7
+ }
8
+ export interface Options {
9
+ env?: "staging" | "local" | "production";
10
+ headers?: { [key: string]: string };
11
+ }
12
+ export interface Headers {
13
+ "api-key": string;
14
+ "Content-Type": string;
15
+ Accept: string;
16
+ [key: string]: string;
17
+ }
18
+ // <reference path = "vehicle.ts" />
19
+ export namespace Service {
20
+ export 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?: { [key: string]: any };
94
+ paymentTerm?: string;
95
+ speciality?: string[];
96
+ company_namespace: string[];
97
+ channel?: string;
98
+ isChain?: boolean;
99
+ chain?: string;
100
+ teams?: string[];
101
+ payment_type: "cash" | "credit";
102
+ integration_meta?: { [key: string]: any };
103
+ integrated_client_balance?: number;
104
+ createdAt: string;
105
+ updatedAt: string;
106
+ __v: number;
107
+ }
108
+ interface ClientBody {
109
+ name?: string;
110
+ local_name?: string;
111
+ tags?: string[];
112
+ cell_phone?: string;
113
+ city?: string;
114
+ client_code?: string;
115
+ contact_name?: string;
116
+ contact_title?: string;
117
+ country?: string;
118
+ disabled?: boolean;
119
+ formatted_address?: string;
120
+ lat?: number;
121
+ lng?: number;
122
+ location_verified?: boolean;
123
+ phone?: string;
124
+ state?: string;
125
+ zip?: string;
126
+ assigned_to?: string[];
127
+ last_location_update?: number;
128
+ credit_limit?: number;
129
+ tax_number?: string;
130
+ sync_id?: string;
131
+ rep_targets?: RepTarget[];
132
+ shelf_share_targets?: ShelfshareTarget[];
133
+ profile_pic?: string;
134
+ logo?: string;
135
+ website?: string;
136
+ email?: string;
137
+ comment?: string;
138
+ parent_client_id?: string;
139
+ target_visit?: number;
140
+ geofencing_radius?: number;
141
+ price_tag?: string;
142
+ jobs?: JobObject[];
143
+ status?: string;
144
+ job_category?: string[];
145
+ availability_msl?: string[];
146
+ territory?: string;
147
+ sv_priceList?: string;
148
+ assigned_media?: string[];
149
+ assigned_products?: string[];
150
+ assigned_product_groups?: string;
151
+ verifiedUntil?: number;
152
+ financials?: Financials;
153
+ customFields?: { [key: string]: any };
154
+ paymentTerm?: string;
155
+ speciality?: string[];
156
+ company_namespace?: string[];
157
+ channel?: string;
158
+ isChain?: boolean;
159
+ chain?: string;
160
+ teams?: string[];
161
+ payment_type?: "cash" | "credit";
162
+ integration_meta?: { [key: string]: any };
163
+ integrated_client_balance?: number;
164
+ }
165
+ type PopulatedKeys =
166
+ | "tags"
167
+ | "reps"
168
+ | "assigned_to"
169
+ | "sv_priceList"
170
+ | "paymentTerm"
171
+ | "job_category"
172
+ | "msl"
173
+ | "chain"
174
+ | "channel"
175
+ | "status"
176
+ | "product"
177
+ | "assigned_products"
178
+ | "assigned_product_groups"
179
+ | "speciality"
180
+ | "teams";
181
+
182
+ export namespace Find {
183
+ export type Params = DefaultPaginationQueryParams & {
184
+ from_updatedAt?: number;
185
+ to_updatedAt?: number;
186
+ from_createdAt?: number;
187
+ to_createdAt?: number;
188
+ createdAt?: number;
189
+ updatedAt?: number;
190
+ name?: string;
191
+ search?: string;
192
+ disabled?: boolean;
193
+ active?: boolean;
194
+ tags?: string[] | string;
195
+ _id?: string[] | string;
196
+ assigned_to?: string[] | string;
197
+ availability_msl?: string[] | string;
198
+ status?: string[] | string;
199
+ CLIENT_TAGS?: string[] | string;
200
+ AREA_TAGS?: string[] | string;
201
+ isChain?: boolean;
202
+ chain?: string[] | string;
203
+ channel?: string[] | string;
204
+ city?: string[] | string;
205
+ client_code?: string[] | string;
206
+ country?: string[] | string;
207
+ location_verified?: boolean;
208
+ state?: string[] | string;
209
+ sv_priceList?: string[] | string;
210
+ assigned_media?: string[] | string;
211
+ assigned_products?: string[] | string;
212
+ teams?: string[] | string;
213
+ integrated_client_balance?: number;
214
+ tax_number?: string;
215
+ speciality?: string[] | string;
216
+ assigned_product_groups?: string[] | string;
217
+ populatedKeys?: PopulatedKeys[];
218
+ };
219
+ export interface Result extends DefaultPaginationResult {
220
+ data: ClientSchema[];
221
+ }
222
+ }
223
+
224
+ export namespace Get {
225
+ export type ID = string;
226
+ export interface Params {
227
+ populatedKeys: PopulatedKeys[];
228
+ }
229
+ export type Result = ClientSchema;
230
+ }
231
+
232
+ export namespace Create {
233
+ export interface Body extends ClientBody {
234
+ name: string;
235
+ }
236
+ export type Result = ClientSchema;
237
+ }
238
+
239
+ export namespace Update {
240
+ export type ID = string;
241
+ export interface Body extends ClientBody {
242
+ _id?: string;
243
+ createdAt?: string;
244
+ updatedAt?: string;
245
+ __v?: number;
246
+ }
247
+ export type Result = ClientSchema;
248
+ }
249
+
250
+ export namespace Remove {
251
+ export type ID = string;
252
+ export type Result = ClientSchema;
253
+ }
254
+ }
255
+ }
256
+
257
+ export interface DefaultPaginationQueryParams {
258
+ per_page?: number;
259
+ page?: number;
260
+ sort?: "name" | "client_code" | "createdAt" | "updatedAt";
261
+ sortPageOrder?: "asc" | "dsc";
262
+ }
263
+
264
+ export interface DefaultPaginationResult {
265
+ total_result: number;
266
+ current_count: number;
267
+ total_pages: number;
268
+ current_page: number;
269
+ per_page: number;
270
+ first_page_url: string;
271
+ last_page_url: string;
272
+ next_page_url: string | null;
273
+ prev_page_url: string | null;
274
+ path: string;
275
+ data: any[];
276
+ }