timezest 1.0.4 → 1.0.6

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.
@@ -0,0 +1,9 @@
1
+ import { LogLevel, Logger } from "../utils/logger";
2
+ export interface TimeZestAPIConfig {
3
+ logLevel: LogLevel;
4
+ logger: Logger;
5
+ baseUrl: string;
6
+ maxRetryDelayMs: number;
7
+ maxRetryTimeMs: number;
8
+ }
9
+ export declare const CONFIG: TimeZestAPIConfig;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG = void 0;
4
+ const logger_1 = require("../utils/logger");
5
+ exports.CONFIG = {
6
+ logLevel: "error",
7
+ logger: logger_1.defaultLogger,
8
+ baseUrl: "https://api.timezest.com/v1",
9
+ maxRetryDelayMs: 1.5 * 60 * 1000, // 1.5 minutes
10
+ maxRetryTimeMs: 15 * 1000, // 15 seconds
11
+ };
12
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":";;;AAAA,4CAAkE;AAUrD,QAAA,MAAM,GAAsB;IACvC,QAAQ,EAAE,OAAO;IACjB,MAAM,EAAE,sBAAa;IACrB,OAAO,EAAE,6BAA6B;IACtC,eAAe,EAAE,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,cAAc;IAChD,cAAc,EAAE,EAAE,GAAG,IAAI,EAAE,aAAa;CACzC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Defines the API endpoints used in the TimeZest application.
3
+ */
4
+ export type apiEndpoints = {
5
+ /** Endpoint for managing resources. */
6
+ RESOURCES: apiEndpoint;
7
+ /** Endpoint for managing agents. */
8
+ AGENTS: apiEndpoint;
9
+ /** Endpoint for managing teams. */
10
+ TEAMS: apiEndpoint;
11
+ /** Endpoint for managing appointment types. */
12
+ APPOINTMENT_TYPES: apiEndpoint;
13
+ /** Endpoint for managing scheduling requests. */
14
+ SCHEDULING_REQUESTS: apiEndpoint;
15
+ };
16
+ export type BaseApiEndpoint = "/resources" | "/agents" | "/teams" | "/appointment_types" | "/scheduling_requests";
17
+ export type apiEndpoint = BaseApiEndpoint | `${BaseApiEndpoint}/${string}`;
18
+ export declare const API_ENDPOINTS: apiEndpoints;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.API_ENDPOINTS = void 0;
4
+ exports.API_ENDPOINTS = {
5
+ RESOURCES: "/resources",
6
+ AGENTS: "/agents",
7
+ TEAMS: "/teams",
8
+ APPOINTMENT_TYPES: "/appointment_types",
9
+ SCHEDULING_REQUESTS: "/scheduling_requests",
10
+ };
11
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/constants/endpoints.ts"],"names":[],"mappings":";;;AA6Ba,QAAA,aAAa,GAAiB;IACzC,SAAS,EAAE,YAAY;IACvB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,QAAQ;IACf,iBAAiB,EAAE,oBAAoB;IACvC,mBAAmB,EAAE,sBAAsB;CAC5C,CAAC"}
@@ -0,0 +1,78 @@
1
+ export interface Agent {
2
+ id: string;
3
+ object: string;
4
+ name: string;
5
+ email: string;
6
+ role: string;
7
+ schedulable: boolean;
8
+ two_factor_enabled: boolean;
9
+ url_slug: string;
10
+ created_at: number;
11
+ updated_at: number;
12
+ }
13
+ export interface AppointmentType {
14
+ id: string;
15
+ object: string;
16
+ internal_name: string;
17
+ external_name: string;
18
+ duration_mins: number;
19
+ url_slug: string;
20
+ created_at: number;
21
+ updated_at: number;
22
+ }
23
+ export interface Resource {
24
+ id: string;
25
+ object: string;
26
+ name: string;
27
+ email: string;
28
+ role: string;
29
+ schedulable: boolean;
30
+ two_factor_enabled: boolean;
31
+ url_slug: string;
32
+ created_at: number;
33
+ updated_at: number;
34
+ }
35
+ export interface SchedulingRequest {
36
+ id: string;
37
+ object: string;
38
+ appointment_type_id: string;
39
+ end_user_email: string;
40
+ end_user_name: string;
41
+ associated_entities: Array<{
42
+ type: string;
43
+ id: number;
44
+ number?: string;
45
+ }>;
46
+ resources: Array<{
47
+ type: string;
48
+ id: string;
49
+ name: string;
50
+ }>;
51
+ scheduled_agents: Array<unknown>;
52
+ scheduled_at: number;
53
+ scheduling_url: string;
54
+ selected_start_time: number;
55
+ selected_time_zone: string;
56
+ status: string;
57
+ created_at: number;
58
+ updated_at: number;
59
+ }
60
+ export interface SchedulingRequestPost {
61
+ appointment_type_id: string;
62
+ trigger_mode: string;
63
+ associated_entities: Array<{
64
+ type: string;
65
+ number: string;
66
+ }>;
67
+ resource_ids: string[];
68
+ }
69
+ export interface Team {
70
+ id: string;
71
+ object: string;
72
+ internal_name: string;
73
+ external_name: string;
74
+ team_type: string;
75
+ url_slug: string;
76
+ created_at: number;
77
+ updated_at: number;
78
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/entities/entities.ts"],"names":[],"mappings":""}
@@ -0,0 +1,245 @@
1
+ import { z } from "zod";
2
+ export declare const AgentSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ object: z.ZodString;
5
+ name: z.ZodString;
6
+ email: z.ZodString;
7
+ role: z.ZodString;
8
+ schedulable: z.ZodBoolean;
9
+ two_factor_enabled: z.ZodBoolean;
10
+ url_slug: z.ZodString;
11
+ created_at: z.ZodNumber;
12
+ updated_at: z.ZodNumber;
13
+ }, "strip", z.ZodTypeAny, {
14
+ object: string;
15
+ id: string;
16
+ name: string;
17
+ email: string;
18
+ role: string;
19
+ schedulable: boolean;
20
+ two_factor_enabled: boolean;
21
+ url_slug: string;
22
+ created_at: number;
23
+ updated_at: number;
24
+ }, {
25
+ object: string;
26
+ id: string;
27
+ name: string;
28
+ email: string;
29
+ role: string;
30
+ schedulable: boolean;
31
+ two_factor_enabled: boolean;
32
+ url_slug: string;
33
+ created_at: number;
34
+ updated_at: number;
35
+ }>;
36
+ export declare const AppointmentTypeSchema: z.ZodObject<{
37
+ id: z.ZodString;
38
+ object: z.ZodString;
39
+ internal_name: z.ZodString;
40
+ external_name: z.ZodString;
41
+ duration_mins: z.ZodNumber;
42
+ url_slug: z.ZodString;
43
+ created_at: z.ZodNumber;
44
+ updated_at: z.ZodNumber;
45
+ }, "strip", z.ZodTypeAny, {
46
+ object: string;
47
+ id: string;
48
+ url_slug: string;
49
+ created_at: number;
50
+ updated_at: number;
51
+ internal_name: string;
52
+ external_name: string;
53
+ duration_mins: number;
54
+ }, {
55
+ object: string;
56
+ id: string;
57
+ url_slug: string;
58
+ created_at: number;
59
+ updated_at: number;
60
+ internal_name: string;
61
+ external_name: string;
62
+ duration_mins: number;
63
+ }>;
64
+ export declare const ResourceSchema: z.ZodObject<{
65
+ id: z.ZodString;
66
+ object: z.ZodString;
67
+ name: z.ZodString;
68
+ email: z.ZodString;
69
+ role: z.ZodString;
70
+ schedulable: z.ZodBoolean;
71
+ two_factor_enabled: z.ZodBoolean;
72
+ url_slug: z.ZodString;
73
+ created_at: z.ZodNumber;
74
+ updated_at: z.ZodNumber;
75
+ }, "strip", z.ZodTypeAny, {
76
+ object: string;
77
+ id: string;
78
+ name: string;
79
+ email: string;
80
+ role: string;
81
+ schedulable: boolean;
82
+ two_factor_enabled: boolean;
83
+ url_slug: string;
84
+ created_at: number;
85
+ updated_at: number;
86
+ }, {
87
+ object: string;
88
+ id: string;
89
+ name: string;
90
+ email: string;
91
+ role: string;
92
+ schedulable: boolean;
93
+ two_factor_enabled: boolean;
94
+ url_slug: string;
95
+ created_at: number;
96
+ updated_at: number;
97
+ }>;
98
+ export declare const SchedulingRequestSchema: z.ZodObject<{
99
+ id: z.ZodString;
100
+ object: z.ZodString;
101
+ appointment_type_id: z.ZodString;
102
+ end_user_email: z.ZodString;
103
+ end_user_name: z.ZodString;
104
+ associated_entities: z.ZodArray<z.ZodObject<{
105
+ type: z.ZodString;
106
+ id: z.ZodNumber;
107
+ number: z.ZodOptional<z.ZodString>;
108
+ }, "strip", z.ZodTypeAny, {
109
+ id: number;
110
+ type: string;
111
+ number?: string | undefined;
112
+ }, {
113
+ id: number;
114
+ type: string;
115
+ number?: string | undefined;
116
+ }>, "many">;
117
+ resources: z.ZodArray<z.ZodObject<{
118
+ type: z.ZodString;
119
+ id: z.ZodString;
120
+ name: z.ZodString;
121
+ }, "strip", z.ZodTypeAny, {
122
+ id: string;
123
+ name: string;
124
+ type: string;
125
+ }, {
126
+ id: string;
127
+ name: string;
128
+ type: string;
129
+ }>, "many">;
130
+ scheduled_agents: z.ZodArray<z.ZodUnknown, "many">;
131
+ scheduled_at: z.ZodNumber;
132
+ scheduling_url: z.ZodString;
133
+ selected_start_time: z.ZodNumber;
134
+ selected_time_zone: z.ZodString;
135
+ status: z.ZodString;
136
+ created_at: z.ZodNumber;
137
+ updated_at: z.ZodNumber;
138
+ }, "strip", z.ZodTypeAny, {
139
+ object: string;
140
+ id: string;
141
+ created_at: number;
142
+ updated_at: number;
143
+ status: string;
144
+ appointment_type_id: string;
145
+ end_user_email: string;
146
+ end_user_name: string;
147
+ associated_entities: {
148
+ id: number;
149
+ type: string;
150
+ number?: string | undefined;
151
+ }[];
152
+ resources: {
153
+ id: string;
154
+ name: string;
155
+ type: string;
156
+ }[];
157
+ scheduled_agents: unknown[];
158
+ scheduled_at: number;
159
+ scheduling_url: string;
160
+ selected_start_time: number;
161
+ selected_time_zone: string;
162
+ }, {
163
+ object: string;
164
+ id: string;
165
+ created_at: number;
166
+ updated_at: number;
167
+ status: string;
168
+ appointment_type_id: string;
169
+ end_user_email: string;
170
+ end_user_name: string;
171
+ associated_entities: {
172
+ id: number;
173
+ type: string;
174
+ number?: string | undefined;
175
+ }[];
176
+ resources: {
177
+ id: string;
178
+ name: string;
179
+ type: string;
180
+ }[];
181
+ scheduled_agents: unknown[];
182
+ scheduled_at: number;
183
+ scheduling_url: string;
184
+ selected_start_time: number;
185
+ selected_time_zone: string;
186
+ }>;
187
+ export declare const SchedulingRequestPostSchema: z.ZodObject<{
188
+ appointment_type_id: z.ZodString;
189
+ trigger_mode: z.ZodString;
190
+ associated_entities: z.ZodArray<z.ZodObject<{
191
+ type: z.ZodString;
192
+ number: z.ZodString;
193
+ }, "strip", z.ZodTypeAny, {
194
+ number: string;
195
+ type: string;
196
+ }, {
197
+ number: string;
198
+ type: string;
199
+ }>, "many">;
200
+ resource_ids: z.ZodArray<z.ZodString, "many">;
201
+ }, "strip", z.ZodTypeAny, {
202
+ appointment_type_id: string;
203
+ associated_entities: {
204
+ number: string;
205
+ type: string;
206
+ }[];
207
+ trigger_mode: string;
208
+ resource_ids: string[];
209
+ }, {
210
+ appointment_type_id: string;
211
+ associated_entities: {
212
+ number: string;
213
+ type: string;
214
+ }[];
215
+ trigger_mode: string;
216
+ resource_ids: string[];
217
+ }>;
218
+ export declare const TeamSchema: z.ZodObject<{
219
+ id: z.ZodString;
220
+ object: z.ZodString;
221
+ internal_name: z.ZodString;
222
+ external_name: z.ZodString;
223
+ team_type: z.ZodString;
224
+ url_slug: z.ZodString;
225
+ created_at: z.ZodNumber;
226
+ updated_at: z.ZodNumber;
227
+ }, "strip", z.ZodTypeAny, {
228
+ object: string;
229
+ id: string;
230
+ url_slug: string;
231
+ created_at: number;
232
+ updated_at: number;
233
+ internal_name: string;
234
+ external_name: string;
235
+ team_type: string;
236
+ }, {
237
+ object: string;
238
+ id: string;
239
+ url_slug: string;
240
+ created_at: number;
241
+ updated_at: number;
242
+ internal_name: string;
243
+ external_name: string;
244
+ team_type: string;
245
+ }>;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TeamSchema = exports.SchedulingRequestPostSchema = exports.SchedulingRequestSchema = exports.ResourceSchema = exports.AppointmentTypeSchema = exports.AgentSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.AgentSchema = zod_1.z.object({
6
+ id: zod_1.z.string(),
7
+ object: zod_1.z.string(),
8
+ name: zod_1.z.string(),
9
+ email: zod_1.z.string(),
10
+ role: zod_1.z.string(),
11
+ schedulable: zod_1.z.boolean(),
12
+ two_factor_enabled: zod_1.z.boolean(),
13
+ url_slug: zod_1.z.string(),
14
+ created_at: zod_1.z.number(),
15
+ updated_at: zod_1.z.number(),
16
+ });
17
+ exports.AppointmentTypeSchema = zod_1.z.object({
18
+ id: zod_1.z.string(),
19
+ object: zod_1.z.string(),
20
+ internal_name: zod_1.z.string(),
21
+ external_name: zod_1.z.string(),
22
+ duration_mins: zod_1.z.number(),
23
+ url_slug: zod_1.z.string(),
24
+ created_at: zod_1.z.number(),
25
+ updated_at: zod_1.z.number(),
26
+ });
27
+ exports.ResourceSchema = zod_1.z.object({
28
+ id: zod_1.z.string(),
29
+ object: zod_1.z.string(),
30
+ name: zod_1.z.string(),
31
+ email: zod_1.z.string(),
32
+ role: zod_1.z.string(),
33
+ schedulable: zod_1.z.boolean(),
34
+ two_factor_enabled: zod_1.z.boolean(),
35
+ url_slug: zod_1.z.string(),
36
+ created_at: zod_1.z.number(),
37
+ updated_at: zod_1.z.number(),
38
+ });
39
+ exports.SchedulingRequestSchema = zod_1.z.object({
40
+ id: zod_1.z.string(),
41
+ object: zod_1.z.string(),
42
+ appointment_type_id: zod_1.z.string(),
43
+ end_user_email: zod_1.z.string(),
44
+ end_user_name: zod_1.z.string(),
45
+ associated_entities: zod_1.z.array(zod_1.z.object({
46
+ type: zod_1.z.string(),
47
+ id: zod_1.z.number(),
48
+ number: zod_1.z.string().optional(),
49
+ })),
50
+ resources: zod_1.z.array(zod_1.z.object({
51
+ type: zod_1.z.string(),
52
+ id: zod_1.z.string(),
53
+ name: zod_1.z.string(),
54
+ })),
55
+ scheduled_agents: zod_1.z.array(zod_1.z.unknown()),
56
+ scheduled_at: zod_1.z.number(),
57
+ scheduling_url: zod_1.z.string(),
58
+ selected_start_time: zod_1.z.number(),
59
+ selected_time_zone: zod_1.z.string(),
60
+ status: zod_1.z.string(),
61
+ created_at: zod_1.z.number(),
62
+ updated_at: zod_1.z.number(),
63
+ });
64
+ exports.SchedulingRequestPostSchema = zod_1.z.object({
65
+ appointment_type_id: zod_1.z.string(),
66
+ trigger_mode: zod_1.z.string(),
67
+ associated_entities: zod_1.z.array(zod_1.z.object({
68
+ type: zod_1.z.string(),
69
+ number: zod_1.z.string(),
70
+ })),
71
+ resource_ids: zod_1.z.array(zod_1.z.string()),
72
+ });
73
+ exports.TeamSchema = zod_1.z.object({
74
+ id: zod_1.z.string(),
75
+ object: zod_1.z.string(),
76
+ internal_name: zod_1.z.string(),
77
+ external_name: zod_1.z.string(),
78
+ team_type: zod_1.z.string(),
79
+ url_slug: zod_1.z.string(),
80
+ created_at: zod_1.z.number(),
81
+ updated_at: zod_1.z.number(),
82
+ });
83
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/entities/schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;IACd,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,WAAW,EAAE,OAAC,CAAC,OAAO,EAAE;IACxB,kBAAkB,EAAE,OAAC,CAAC,OAAO,EAAE;IAC/B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;IACtB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAE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C,MAAM,EAAE;IACd,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE;IACzB,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE;IACzB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;IACrB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;IACtB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC"}
package/index.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ import { log, LogLevel, Logger } from "./utils/logger";
2
+ import { TimeZestAPIConfig } from "./config/config";
3
+ import { Agent, Resource, AppointmentType, SchedulingRequest, Team } from "./entities/entities";
4
+ /**
5
+ * Represents the main interface for the TimeZest API.
6
+ */
7
+ export interface TimeZestAPI {
8
+ /**
9
+ * Logs a message with a specified log level.
10
+ * @param level - The log level (e.g., 'info', 'debug').
11
+ * @param message - The message to log.
12
+ * @param data - Optional additional data to log.
13
+ */
14
+ log: (level: LogLevel, message: string, data?: any) => void;
15
+ /**
16
+ * Retrieves a list of resources, optionally filtered by a query.
17
+ * @param filter - An optional filter string in TQL format
18
+ * @returns A promise that resolves to an array of resources.
19
+ */
20
+ getResources(filter?: string | null): Promise<Resource[]>;
21
+ /**
22
+ * Retrieves a list of agents, optionally filtered by a query.
23
+ * @param filter - An optional filter string in TQL format
24
+ * @returns A promise that resolves to an array of agents.
25
+ */
26
+ getAgents(filter?: string | null): Promise<Agent[]>;
27
+ /**
28
+ * Retrieves a list of teams, optionally filtered by a query.
29
+ * @param filter - An optional filter string in TQL format
30
+ * @returns A promise that resolves to an array of teams.
31
+ */
32
+ getTeams(filter?: string | null): Promise<Team[]>;
33
+ /**
34
+ * Retrieves a list of appointment types, optionally filtered by a query.
35
+ * @param filter - An optional filter string in TQL format
36
+ * @returns A promise that resolves to an array of appointment types.
37
+ */
38
+ getAppointmentTypes(filter?: string | null): Promise<AppointmentType[]>;
39
+ /**
40
+ * Retrieves a specific scheduling request by its ID.
41
+ * @param id - The ID of the scheduling request.
42
+ * @returns A promise that resolves to the scheduling request.
43
+ */
44
+ getSchedulingRequest(id: string): Promise<SchedulingRequest>;
45
+ /**
46
+ * Retrieves a list of scheduling requests, 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 scheduling requests.
49
+ */
50
+ getSchedulingRequests(filter?: string | null): Promise<SchedulingRequest[]>;
51
+ /**
52
+ * Creates a new scheduling request.
53
+ * @param data - The data for the new scheduling request.
54
+ * @returns A promise that resolves to the created scheduling request.
55
+ */
56
+ createSchedulingRequest(data: SchedulingRequest): Promise<SchedulingRequest>;
57
+ /**
58
+ * Retrieves the API key.
59
+ * @returns The API key as a string.
60
+ */
61
+ getApiKey(): string;
62
+ /**
63
+ * Retrieves the configuration object.
64
+ * @returns The configuration object.
65
+ */
66
+ getConfig(): TimeZestAPIConfig;
67
+ }
68
+ /**
69
+ * Options for configuring the TimeZest API.
70
+ */
71
+ export interface TimeZestAPIOptions {
72
+ /** The log level for the API (e.g., 'info', 'debug'). */
73
+ logLevel?: LogLevel;
74
+ /** A custom logger implementation. */
75
+ logger?: Logger;
76
+ /** The base URL for the API. */
77
+ baseUrl?: string;
78
+ /** The maximum delay between retries, in milliseconds. */
79
+ maxRetryDelayMs?: number;
80
+ /** The maximum total retry time, in milliseconds. */
81
+ maxRetryTimeMs?: number;
82
+ }
83
+ export declare class TimeZestAPI implements TimeZestAPI {
84
+ private config;
85
+ private apiKey;
86
+ log: log;
87
+ constructor(apiKey: string, options?: TimeZestAPIOptions);
88
+ getResources: (filter?: string | null) => Promise<Resource[]>;
89
+ }
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,gDAM4B;AAC5B,4CAAyC;AACzC,qDAAkD;AAClD,qDAAsD;AACt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ACjC,KAAK,EACL,IAAI,EACJ,MAAM,CACP,CAAC;YACF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iCAAuB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACrE,CAAC;KAAA;IAEK,uBAAuB,CAC3B,IAAuB;;YAEvB,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAW,EAChC,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,CAAC,OAAO,EACnB,yBAAa,CAAC,mBAAmB,EACjC,MAAM,EACN,IAAI,EACJ,IAAI,CAAC,MAAM,CAAC,cAAc,EAC1B,IAAI,CAAC,MAAM,CAAC,eAAe,CAC5B,CAAC;YACF,OAAO,QAAQ,CAAC;QAClB,CAAC;KAAA;CACF;AAjJD,kCAiJC"}
package/package.json CHANGED
@@ -1,17 +1,14 @@
1
1
  {
2
2
  "name": "timezest",
3
- "version": "1.0.4",
4
- "main": "dist/index.js",
5
- "files": [
6
- "dist/index.js"
7
- ],
3
+ "version": "1.0.6",
4
+ "main": "index.js",
8
5
  "scripts": {
9
6
  "build": "tsc",
10
7
  "test": "node dist/src/tests/test.js",
11
8
  "format": "prettier --write .",
12
9
  "clean": "if exist dist rmdir /s /q dist",
13
10
  "prep-publish": "npm run clean && npm run build && copy package.json dist\\package.json && copy README.md dist\\README.md && copy LICENSE dist\\LICENSE",
14
- "publish": "npm run prep-publish && npm publish dist --access public"
11
+ "publish": "npm run prep-publish && npm publish .\\dist"
15
12
  },
16
13
  "keywords": [],
17
14
  "author": "",
@@ -0,0 +1,9 @@
1
+ import { LogLevel } from "./logger";
2
+ /**
3
+ * Handles errors from API requests.
4
+ * @param log - A logging function to log error details.
5
+ * @param error - The error object to handle.
6
+ * @returns An empty array if the error is a 404, otherwise throws an error.
7
+ */
8
+ export type handleError = (log: (level: LogLevel, message: string, data?: any) => void, error: any) => void | [];
9
+ export declare const handleError: handleError;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleError = void 0;
4
+ const handleError = (log, error) => {
5
+ if (error.response) {
6
+ const { status, data } = error.response;
7
+ if (status === 404) {
8
+ log("warn", "Resource not found, returning an empty array.", {
9
+ status,
10
+ data,
11
+ });
12
+ return [];
13
+ }
14
+ log("error", `API Error: ${status} - ${data.message || "Unknown error"}`, data);
15
+ if (data.errors) {
16
+ log("error", "Details:", data.errors);
17
+ }
18
+ throw new Error(data.message || `HTTP ${status}`);
19
+ }
20
+ else if (error.request) {
21
+ log("error", "No response received from the API.", {
22
+ message: error.message,
23
+ });
24
+ throw new Error("No response received from the API");
25
+ }
26
+ else {
27
+ log("error", "Error setting up the request.", { message: error.message });
28
+ throw new Error("Error setting up the request");
29
+ }
30
+ };
31
+ exports.handleError = handleError;
32
+ //# sourceMappingURL=handleError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleError.js","sourceRoot":"","sources":["../../src/utils/handleError.ts"],"names":[],"mappings":";;;AAaO,MAAM,WAAW,GAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;IACrD,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;QACxC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,GAAG,CAAC,MAAM,EAAE,+CAA+C,EAAE;gBAC3D,MAAM;gBACN,IAAI;aACL,CAAC,CAAC;YACH,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,GAAG,CACD,OAAO,EACP,cAAc,MAAM,MAAM,IAAI,CAAC,OAAO,IAAI,eAAe,EAAE,EAC3D,IAAI,CACL,CAAC;QACF,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,QAAQ,MAAM,EAAE,CAAC,CAAC;IACpD,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACzB,GAAG,CAAC,OAAO,EAAE,oCAAoC,EAAE;YACjD,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CAAC;QACH,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,OAAO,EAAE,+BAA+B,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1E,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;AACH,CAAC,CAAC;AA5BW,QAAA,WAAW,eA4BtB"}
@@ -0,0 +1,20 @@
1
+ export type log = {
2
+ (level: LogLevel, message: string, data?: any): void;
3
+ };
4
+ export interface Logger {
5
+ silent: (message: string, data?: any) => void;
6
+ error: (message: string, data?: any) => void;
7
+ warn: (message: string, data?: any) => void;
8
+ info: (message: string, data?: any) => void;
9
+ http: (message: string, data?: any) => void;
10
+ verbose: (message: string, data?: any) => void;
11
+ debug: (message: string, data?: any) => void;
12
+ silly: (message: string, data?: any) => void;
13
+ }
14
+ export type LogLevel = "silent" | "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
15
+ export declare const logLevelPriority: Record<LogLevel, number>;
16
+ export declare const defaultLogger: Logger;
17
+ export declare function buildLogger(logger: Logger, logLevel: LogLevel): (level: LogLevel, message: string, data?: any) => void;
18
+ export declare function withLogging<T>(fn: (...args: any[]) => Promise<T>, instance: {
19
+ log: (level: LogLevel, message: string, data?: any) => void;
20
+ }, functionName: string): (...args: any[]) => Promise<T>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.defaultLogger = exports.logLevelPriority = void 0;
13
+ exports.buildLogger = buildLogger;
14
+ exports.withLogging = withLogging;
15
+ exports.logLevelPriority = {
16
+ silent: -1,
17
+ error: 0,
18
+ warn: 1,
19
+ info: 2,
20
+ http: 3,
21
+ verbose: 4,
22
+ debug: 5,
23
+ silly: 6,
24
+ };
25
+ exports.defaultLogger = {
26
+ silent: (_message, _data) => { },
27
+ error: (message, data) => data ? console.error(message, data) : console.error(message),
28
+ warn: (message, data) => data ? console.warn(message, data) : console.warn(message),
29
+ info: (message, data) => data ? console.info(message, data) : console.info,
30
+ http: (message, data) => data ? console.log(message, data) : console.log(message),
31
+ verbose: (message, data) => data ? console.debug(message, data) : console.debug(message),
32
+ debug: (message, data) => data ? console.debug(message, data) : console.debug(message),
33
+ silly: (message, data) => data ? console.debug(message, data) : console.debug(message),
34
+ };
35
+ function buildLogger(logger, logLevel) {
36
+ return (level, message, data) => {
37
+ if (exports.logLevelPriority[level] <= exports.logLevelPriority[logLevel]) {
38
+ logger[level](message, data);
39
+ }
40
+ };
41
+ }
42
+ function withLogging(fn, instance, functionName) {
43
+ return (...args) => __awaiter(this, void 0, void 0, function* () {
44
+ instance.log("debug", `Entering ${functionName}`);
45
+ args ? instance.log("silly", `Entering ${functionName}`, { args }) : null;
46
+ try {
47
+ const result = yield fn(...args);
48
+ instance.log("debug", `Exiting ${functionName} successfully`);
49
+ result
50
+ ? instance.log("silly", `Exiting ${functionName} successfully`, {
51
+ result,
52
+ })
53
+ : null;
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ instance.log("error", `Error in ${functionName}`, { error });
58
+ throw error;
59
+ }
60
+ });
61
+ }
62
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAsDA,kCASC;AAED,kCAsBC;AA9DY,QAAA,gBAAgB,GAA6B;IACxD,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;CACT,CAAC;AAEW,QAAA,aAAa,GAAW;IACnC,MAAM,EAAE,CAAC,QAAgB,EAAE,KAAW,EAAE,EAAE,GAAE,CAAC;IAC7C,KAAK,EAAE,CAAC,OAAe,EAAE,IAAU,EAAE,EAAE,CACrC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAC9D,IAAI,EAAE,CAAC,OAAe,EAAE,IAAU,EAAE,EAAE,CACpC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IAC5D,IAAI,EAAE,CAAC,OAAe,EAAE,IAAU,EAAE,EAAE,CACpC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI;IACnD,IAAI,EAAE,CAAC,OAAe,EAAE,IAAU,EAAE,EAAE,CACpC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CA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AAI,CAAC;QAC1E,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACjC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,YAAY,eAAe,CAAC,CAAC;YAC9D,MAAM;gBACJ,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,YAAY,eAAe,EAAE;oBAC5D,MAAM;iBACP,CAAC;gBACJ,CAAC,CAAC,IAAI,CAAC;YACT,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAA,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { apiEndpoint } from "../constants/endpoints";
2
+ import { TimeZestAPI } from "../index";
3
+ /**
4
+ * Makes a paginated API request.
5
+ * @template T - The type of the response data.
6
+ * @param apiInstance - The instance of the TimeZestAPI.
7
+ * @param endpoint - The API endpoint to call.
8
+ * @param method - The HTTP method (GET or POST).
9
+ * @param data - The request payload.
10
+ * @param filter - An optional filter string.
11
+ * @returns A promise that resolves to an array of response data.
12
+ */
13
+ export declare const makePaginatedRequest: <T>(apiInstance: TimeZestAPI, endpoint: apiEndpoint, method?: "GET" | "POST", data?: any, filter?: string | null) => Promise<T[]>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.makePaginatedRequest = void 0;
13
+ const makeRequest_1 = require("./makeRequest");
14
+ const handleError_1 = require("./handleError");
15
+ /**
16
+ * Makes a paginated API request.
17
+ * @template T - The type of the response data.
18
+ * @param apiInstance - The instance of the TimeZestAPI.
19
+ * @param endpoint - The API endpoint to call.
20
+ * @param method - The HTTP method (GET or POST).
21
+ * @param data - The request payload.
22
+ * @param filter - An optional filter string.
23
+ * @returns A promise that resolves to an array of response data.
24
+ */
25
+ const makePaginatedRequest = (apiInstance_1, endpoint_1, ...args_1) => __awaiter(void 0, [apiInstance_1, endpoint_1, ...args_1], void 0, function* (apiInstance, endpoint, method = "GET", data = null, filter = null) {
26
+ const { log } = apiInstance;
27
+ const apiKey = apiInstance.getApiKey();
28
+ const { baseUrl, maxRetryTimeMs, maxRetryDelayMs } = apiInstance.getConfig();
29
+ let results = [];
30
+ let nextPage = 1;
31
+ try {
32
+ do {
33
+ log("debug", `Fetching page ${nextPage} for ${endpoint}`);
34
+ const response = yield (0, makeRequest_1.makeRequest)(log, apiKey, baseUrl, endpoint, method, Object.assign(Object.assign({}, data), { filter, page: nextPage }), maxRetryTimeMs, maxRetryDelayMs);
35
+ log("http", `Page ${nextPage} fetched successfully for ${endpoint}`);
36
+ results = results.concat(response.data);
37
+ nextPage = response.next_page;
38
+ } while (nextPage);
39
+ log("http", `Paginated request to ${endpoint} completed successfully`);
40
+ return results;
41
+ }
42
+ catch (error) {
43
+ log("error", `Paginated request to ${endpoint} failed with error: '${error.message}'`);
44
+ (0, handleError_1.handleError)(log, error);
45
+ }
46
+ return results;
47
+ });
48
+ exports.makePaginatedRequest = makePaginatedRequest;
49
+ //# sourceMappingURL=makePaginatedRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makePaginatedRequest.js","sourceRoot":"","sources":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,GAAG,CACzE,CAAC;QACF,IAAA,yBAAW,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAA,CAAC;AA/CW,QAAA,oBAAoB,wBA+C/B"}
@@ -0,0 +1,16 @@
1
+ import { apiEndpoint } from "../constants/endpoints";
2
+ import { LogLevel } from "./logger";
3
+ /**
4
+ * Makes an API request with retry logic.
5
+ * @template T - The type of the response data.
6
+ * @param log - A logging function to log request details.
7
+ * @param apiKey - The API key for authentication.
8
+ * @param baseUrl - The base URL of the API.
9
+ * @param endpoint - The API endpoint to call.
10
+ * @param method - The HTTP method (GET or POST).
11
+ * @param data - The request payload.
12
+ * @param maxRetryTimeMs - The maximum retry time in milliseconds.
13
+ * @param maxRetryDelayMs - The maximum delay between retries in milliseconds.
14
+ * @returns A promise that resolves to the response data.
15
+ */
16
+ export declare function makeRequest<T>(log: (level: LogLevel, message: string, data?: any) => void, apiKey: string, baseUrl: string, endpoint: apiEndpoint, method: "GET" | "POST", data: any, maxRetryTimeMs: number, maxRetryDelayMs: number): Promise<T>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.makeRequest = makeRequest;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const handleError_1 = require("./handleError");
18
+ /**
19
+ * Makes an API request with retry logic.
20
+ * @template T - The type of the response data.
21
+ * @param log - A logging function to log request details.
22
+ * @param apiKey - The API key for authentication.
23
+ * @param baseUrl - The base URL of the API.
24
+ * @param endpoint - The API endpoint to call.
25
+ * @param method - The HTTP method (GET or POST).
26
+ * @param data - The request payload.
27
+ * @param maxRetryTimeMs - The maximum retry time in milliseconds.
28
+ * @param maxRetryDelayMs - The maximum delay between retries in milliseconds.
29
+ * @returns A promise that resolves to the response data.
30
+ */
31
+ function makeRequest(log, apiKey, baseUrl, endpoint, method, data, maxRetryTimeMs, maxRetryDelayMs) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ var _a;
34
+ let totalElapsedTime = 0;
35
+ let retries = 0;
36
+ while (totalElapsedTime < maxRetryTimeMs) {
37
+ try {
38
+ log("debug", `Attempting request to ${endpoint}. Retry count: ${retries}`);
39
+ const response = yield (0, axios_1.default)({
40
+ url: `${baseUrl}${endpoint}`,
41
+ method,
42
+ headers: {
43
+ Authorization: `Bearer ${apiKey}`,
44
+ "Content-Type": "application/json",
45
+ },
46
+ data,
47
+ });
48
+ return response.data;
49
+ }
50
+ catch (error) {
51
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 429) {
52
+ const retryAfterHeader = parseInt(error.response.headers["retry-after"], 10);
53
+ const retryAfter = retryAfterHeader || Math.min(maxRetryDelayMs, Math.pow(2, retries));
54
+ if (totalElapsedTime + retryAfter * 1000 >= maxRetryTimeMs) {
55
+ log("error", `Max retry time exceeded for ${endpoint}`);
56
+ break;
57
+ }
58
+ log("warn", `Rate limited on ${endpoint}. Retrying after ${retryAfter} seconds...`);
59
+ yield new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
60
+ totalElapsedTime += retryAfter * 1000;
61
+ retries++;
62
+ }
63
+ else {
64
+ log("error", `Request to ${endpoint} failed with error: ${error.message}`);
65
+ (0, handleError_1.handleError)(log, error);
66
+ }
67
+ }
68
+ }
69
+ throw new Error(`Max retry time of ${maxRetryTimeMs} minutes exceeded for ${endpoint}`);
70
+ });
71
+ }
72
+ ;
73
+ //# sourceMappingURL=makeRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeRequest.js","sourceRoot":"","sources":["../../src/utils/makeRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAkBA,kCAgEC;AAlFD,kDAA0B;AAC1B,+CAA4C;AAI5C;;;;;;;;;;;;GAYG;AACH,SAAsB,WAAW,CAC/B,GAA2D,EAC3D,MAAc,EACd,OAAe,EACf,QAAqB,EACrB,MAAsB,EACtB,IAAS,EACT,cAAsB,EACtB,eAAuB;;;QAGvB,IAAI,gBAAgB,GAAG,CAAC,CAAC;QACzB,IAAI,OAAO,GAAG,CAAC,CAAC;QAEhB,OAAO,gBAAgB,GAAG,cAAc,EAAE,CAAC;YACzC,IAAI,CAAC;gBACH,GAAG,CACD,OAAO,EACP,yBAAyB,QAAQ,kBAAkB,OAAO,EAAE,CAC7D,CAAC;gBACF,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC;oBAC3B,GAAG,EAAE,GAAG,OAAO,GAAG,QAAQ,EAAE;oBAC5B,MAAM;oBACN,OAAO,EAAE;wBACP,aAAa,EAAE,UAAU,MAAM,EAAE;wBACjC,cAAc,EAAE,kBAAkB;qBACnC;oBACD,IAAI;iBACL,CAAC,CAAC;gBACH,OAAO,QAAQ,CAAC,IAAI,CAAC;YACvB,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,MAAK,GAAG,EAAE,CAAC;oBACnC,MAAM,gBAAgB,GAAG,QAAQ,CAC/B,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,EACrC,EAAE,CACH,CAAC;oBACF,MAAM,UAAU,GACd,gBAAgB,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,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