timezest 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.
Files changed (3) hide show
  1. package/package.json +6 -2
  2. package/index.d.ts +0 -104
  3. package/index.ts +0 -174
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "timezest",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
- "types": "index.d.ts",
5
+ "files": [
6
+ "dist",
7
+ "README.md",
8
+ "LICENSE"
9
+ ],
6
10
  "scripts": {
7
11
  "build": "tsc",
8
12
  "test": "node dist/src/tests/test.js",
package/index.d.ts DELETED
@@ -1,104 +0,0 @@
1
- import { LogLevel, Logger, log } from "./logger.js";
2
- export { LogLevel, Logger, log } from "./logger.js";
3
- export {
4
- Agent,
5
- AppointmentType,
6
- Resource,
7
- SchedulingRequest,
8
- Team,
9
- } from "./src/entities/entities.d";
10
- export { TimeZestAPIConfig } from "./src/config/config.d";
11
-
12
- /**
13
- * Represents the main interface for the TimeZest API.
14
- */
15
- export interface TimeZestAPI {
16
- /**
17
- * Logs a message with a specified log level.
18
- * @param level - The log level (e.g., 'info', 'debug').
19
- * @param message - The message to log.
20
- * @param data - Optional additional data to log.
21
- */
22
- log: (level: LogLevel, message: string, data?: any) => void;
23
-
24
- /**
25
- * Retrieves a list of resources, optionally filtered by a query.
26
- * @param filter - An optional filter string in TQL format
27
- * @returns A promise that resolves to an array of resources.
28
- */
29
- getResources(filter?: string | null): Promise<Resource[]>;
30
-
31
- /**
32
- * Retrieves a list of agents, optionally filtered by a query.
33
- * @param filter - An optional filter string in TQL format
34
- * @returns A promise that resolves to an array of agents.
35
- */
36
- getAgents(filter?: string | null): Promise<Agent[]>;
37
-
38
- /**
39
- * Retrieves a list of teams, optionally filtered by a query.
40
- * @param filter - An optional filter string in TQL format
41
- * @returns A promise that resolves to an array of teams.
42
- */
43
- getTeams(filter?: string | null): Promise<Team[]>;
44
-
45
- /**
46
- * Retrieves a list of appointment types, optionally filtered by a query.
47
- * @param filter - An optional filter string in TQL format
48
- * @returns A promise that resolves to an array of appointment types.
49
- */
50
- getAppointmentTypes(filter?: string | null): Promise<AppointmentType[]>;
51
-
52
- /**
53
- * Retrieves a specific scheduling request by its ID.
54
- * @param id - The ID of the scheduling request.
55
- * @returns A promise that resolves to the scheduling request.
56
- */
57
- getSchedulingRequest(id: string): Promise<SchedulingRequest>;
58
-
59
- /**
60
- * Retrieves a list of scheduling requests, optionally filtered by a query.
61
- * @param filter - An optional filter string in TQL format
62
- * @returns A promise that resolves to an array of scheduling requests.
63
- */
64
- getSchedulingRequests(filter?: string | null): Promise<SchedulingRequest[]>;
65
-
66
- /**
67
- * Creates a new scheduling request.
68
- * @param data - The data for the new scheduling request.
69
- * @returns A promise that resolves to the created scheduling request.
70
- */
71
- createSchedulingRequest(data: SchedulingRequest): Promise<SchedulingRequest>;
72
-
73
- /**
74
- * Retrieves the API key.
75
- * @returns The API key as a string.
76
- */
77
- getApiKey(): string;
78
-
79
- /**
80
- * Retrieves the configuration object.
81
- * @returns The configuration object.
82
- */
83
- getConfig(): TimeZestAPIConfig;
84
- }
85
-
86
- /**
87
- * Options for configuring the TimeZest API.
88
- */
89
- export interface TimeZestAPIOptions {
90
- /** The log level for the API (e.g., 'info', 'debug'). */
91
- logLevel?: LogLevel;
92
-
93
- /** A custom logger implementation. */
94
- logger?: Logger;
95
-
96
- /** The base URL for the API. */
97
- baseUrl?: string;
98
-
99
- /** The maximum delay between retries, in milliseconds. */
100
- maxRetryDelayMs?: number;
101
-
102
- /** The maximum total retry time, in milliseconds. */
103
- maxRetryTimeMs?: number;
104
- }
package/index.ts DELETED
@@ -1,174 +0,0 @@
1
- import {
2
- TimeZestAPI as TimeZestAPIInterface,
3
- TimeZestAPIOptions,
4
- TimeZestAPIConfig,
5
- LogLevel,
6
- log,
7
- Agent,
8
- AppointmentType,
9
- Resource,
10
- SchedulingRequest,
11
- Team,
12
- } from "./index.d";
13
-
14
- import {
15
- ResourceSchema,
16
- AgentSchema,
17
- AppointmentTypeSchema,
18
- SchedulingRequestSchema,
19
- TeamSchema,
20
- } from "./src/entities/schemas";
21
- import { CONFIG } from "./src/config/config";
22
- import { makeRequest } from "./src/utils/makeRequest";
23
- import { API_ENDPOINTS } from "./src/constants/endpoints";
24
- import { buildLogger, withLogging } from "./src/utils/logger";
25
- import { makePaginatedRequest } from "./src/utils/makePaginatedRequest";
26
-
27
- class TimeZestAPI implements TimeZestAPIInterface {
28
- private config: TimeZestAPIConfig;
29
- private apiKey: string;
30
- log: log;
31
-
32
- constructor(apiKey: string, options?: TimeZestAPIOptions) {
33
- this.apiKey = apiKey;
34
- this.config = {
35
- logLevel: options?.logLevel || CONFIG.logLevel,
36
- logger: options?.logger || CONFIG.logger,
37
- baseUrl: options?.baseUrl || CONFIG.baseUrl,
38
- maxRetryDelayMs: options?.maxRetryDelayMs || CONFIG.maxRetryDelayMs,
39
- maxRetryTimeMs: options?.maxRetryTimeMs || CONFIG.maxRetryTimeMs,
40
- };
41
- this.log = buildLogger(this.config.logger, this.config.logLevel);
42
- // Log the initialization of the API client but remove apiKey
43
- this.log("info", "TimeZestAPI initialized");
44
- this.log("debug", "TimeZestAPI initialized with custom config", {
45
- ...options,
46
- });
47
- this.log("debug", "TimeZestAPI initialized with final config", {
48
- ...this.config,
49
- });
50
-
51
- // Wrap methods with logging middleware using the instance's log method
52
- this.getResources = withLogging(
53
- this.getResources.bind(this),
54
- this,
55
- "getResources",
56
- );
57
- this.getAgents = withLogging(this.getAgents.bind(this), this, "getAgents");
58
- this.getTeams = withLogging(this.getTeams.bind(this), this, "getTeams");
59
- this.getAppointmentTypes = withLogging(
60
- this.getAppointmentTypes.bind(this),
61
- this,
62
- "getAppointmentTypes",
63
- );
64
- this.getSchedulingRequest = withLogging(
65
- this.getSchedulingRequest.bind(this),
66
- this,
67
- "getSchedulingRequest",
68
- );
69
- this.createSchedulingRequest = withLogging(
70
- this.createSchedulingRequest.bind(this),
71
- this,
72
- "createSchedulingRequest",
73
- );
74
- }
75
-
76
- getApiKey(): string {
77
- return this.apiKey;
78
- }
79
-
80
- getConfig(): TimeZestAPIConfig {
81
- return this.config;
82
- }
83
-
84
- getResources = async (filter: string | null = null): Promise<Resource[]> => {
85
- const response = await makePaginatedRequest<Resource>(
86
- this,
87
- API_ENDPOINTS.RESOURCES,
88
- "GET",
89
- null,
90
- filter,
91
- );
92
- return response.map((item) => ResourceSchema.parse(item));
93
- };
94
-
95
- async getAgents(filter: string | null = null): Promise<Agent[]> {
96
- const response = await makePaginatedRequest<Agent>(
97
- this,
98
- API_ENDPOINTS.AGENTS,
99
- "GET",
100
- null,
101
- filter,
102
- );
103
- return response.map((item) => AgentSchema.parse(item));
104
- }
105
-
106
- async getTeams(filter: string | null = null): Promise<Team[]> {
107
- const response = await makePaginatedRequest<Team>(
108
- this,
109
- API_ENDPOINTS.TEAMS,
110
- "GET",
111
- null,
112
- filter,
113
- );
114
- return response.map((item) => TeamSchema.parse(item));
115
- }
116
-
117
- async getAppointmentTypes(
118
- filter: string | null = null,
119
- ): Promise<AppointmentType[]> {
120
- const response = await makePaginatedRequest<AppointmentType>(
121
- this,
122
- API_ENDPOINTS.APPOINTMENT_TYPES,
123
- "GET",
124
- null,
125
- filter,
126
- );
127
- return response.map((item) => AppointmentTypeSchema.parse(item));
128
- }
129
-
130
- async getSchedulingRequest(id: string): Promise<SchedulingRequest> {
131
- const response = await makeRequest<SchedulingRequest>(
132
- this.log,
133
- this.apiKey,
134
- this.config.baseUrl,
135
- `${API_ENDPOINTS.SCHEDULING_REQUESTS}/${id}`,
136
- "GET",
137
- null,
138
- this.config.maxRetryTimeMs,
139
- this.config.maxRetryDelayMs,
140
- );
141
- return SchedulingRequestSchema.parse(response);
142
- }
143
-
144
- async getSchedulingRequests(
145
- filter: string | null = null,
146
- ): Promise<SchedulingRequest[]> {
147
- const response = await makePaginatedRequest<SchedulingRequest>(
148
- this,
149
- API_ENDPOINTS.SCHEDULING_REQUESTS,
150
- "GET",
151
- null,
152
- filter,
153
- );
154
- return response.map((item) => SchedulingRequestSchema.parse(item));
155
- }
156
-
157
- async createSchedulingRequest(
158
- data: SchedulingRequest,
159
- ): Promise<SchedulingRequest> {
160
- const response = await makeRequest<SchedulingRequest>(
161
- this.log,
162
- this.apiKey,
163
- this.config.baseUrl,
164
- API_ENDPOINTS.SCHEDULING_REQUESTS,
165
- "POST",
166
- data,
167
- this.config.maxRetryTimeMs,
168
- this.config.maxRetryDelayMs,
169
- );
170
- return response;
171
- }
172
- }
173
-
174
- export default TimeZestAPI;