@sermonshots/analytics 1.0.0

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,16 @@
1
+ import type { UserEventReq } from './types.js';
2
+ export type { paths, webhooks, components, $defs, operations, DateTime, Date, UserEventReq, EventCountByDayRes, EventTotalRes, Ping, ProblemDetail, } from './types.js';
3
+ export { EventType } from './types.js';
4
+ export type AnalyticsClientConfig = {
5
+ baseUrl: string;
6
+ timeout?: number;
7
+ };
8
+ export declare class AnalyticsClient {
9
+ private readonly baseUrl;
10
+ private readonly timeout;
11
+ readonly ingest: {
12
+ event(req: UserEventReq): Promise<void>;
13
+ };
14
+ constructor(config: AnalyticsClientConfig);
15
+ private request;
16
+ }
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnalyticsClient = exports.EventType = void 0;
4
+ var types_js_1 = require("./types.js");
5
+ Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return types_js_1.EventType; } });
6
+ class AnalyticsClient {
7
+ constructor(config) {
8
+ this.baseUrl = config.baseUrl.replace(/\/$/, '');
9
+ this.timeout = config.timeout ?? 30000;
10
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
11
+ const self = this;
12
+ this.ingest = {
13
+ async event(req) {
14
+ await self.request('POST', '/v1/events', { body: req });
15
+ }
16
+ };
17
+ }
18
+ async request(method, path, opts = {}) {
19
+ const controller = new AbortController();
20
+ const timer = setTimeout(() => controller.abort(), this.timeout);
21
+ try {
22
+ const res = await fetch(`${this.baseUrl}${path}`, {
23
+ method,
24
+ headers: { 'Content-Type': 'application/json' },
25
+ body: opts.body != null ? JSON.stringify(opts.body) : undefined,
26
+ signal: controller.signal
27
+ });
28
+ if (!res.ok) {
29
+ throw new Error(`Analytics API ${method} ${path} failed with ${res.status}`);
30
+ }
31
+ const text = await res.text();
32
+ return (text ? JSON.parse(text) : undefined);
33
+ }
34
+ finally {
35
+ clearTimeout(timer);
36
+ }
37
+ }
38
+ }
39
+ exports.AnalyticsClient = AnalyticsClient;
@@ -0,0 +1,272 @@
1
+ /**
2
+ * This file was auto-generated by openapi-typescript.
3
+ * Do not make direct changes to the file.
4
+ */
5
+ export type paths = {
6
+ "/ping": {
7
+ parameters: {
8
+ query?: never;
9
+ header?: never;
10
+ path?: never;
11
+ cookie?: never;
12
+ };
13
+ /** Health check */
14
+ get: operations["get-ping"];
15
+ put?: never;
16
+ post?: never;
17
+ delete?: never;
18
+ options?: never;
19
+ head?: never;
20
+ patch?: never;
21
+ trace?: never;
22
+ };
23
+ "/v1/events": {
24
+ parameters: {
25
+ query?: never;
26
+ header?: never;
27
+ path?: never;
28
+ cookie?: never;
29
+ };
30
+ get?: never;
31
+ put?: never;
32
+ /** Ingest user analytics event */
33
+ post: operations["post-v1-events"];
34
+ delete?: never;
35
+ options?: never;
36
+ head?: never;
37
+ patch?: never;
38
+ trace?: never;
39
+ };
40
+ "/v1/dashboard/events/daily": {
41
+ parameters: {
42
+ query?: never;
43
+ header?: never;
44
+ path?: never;
45
+ cookie?: never;
46
+ };
47
+ /** Get event counts by day */
48
+ get: operations["get-v1-dashboard-events-daily"];
49
+ put?: never;
50
+ post?: never;
51
+ delete?: never;
52
+ options?: never;
53
+ head?: never;
54
+ patch?: never;
55
+ trace?: never;
56
+ };
57
+ "/v1/dashboard/events/totals": {
58
+ parameters: {
59
+ query?: never;
60
+ header?: never;
61
+ path?: never;
62
+ cookie?: never;
63
+ };
64
+ /** Get total event counts */
65
+ get: operations["get-v1-dashboard-events-totals"];
66
+ put?: never;
67
+ post?: never;
68
+ delete?: never;
69
+ options?: never;
70
+ head?: never;
71
+ patch?: never;
72
+ trace?: never;
73
+ };
74
+ };
75
+ export type webhooks = Record<string, never>;
76
+ export type components = {
77
+ schemas: {
78
+ /**
79
+ * @description Analytics user-event type. Kept in sync with the event package.
80
+ * @enum {string}
81
+ */
82
+ EventType: EventType;
83
+ UserEventReq: {
84
+ event: components["schemas"]["EventType"];
85
+ video_id: number;
86
+ user_id: number;
87
+ owner_id: number;
88
+ membership: string;
89
+ start_time: components["schemas"]["DateTime"];
90
+ end_time?: components["schemas"]["DateTime"];
91
+ metadata?: {
92
+ [key: string]: unknown;
93
+ };
94
+ };
95
+ EventCountByDayRes: {
96
+ date: string;
97
+ event: string;
98
+ count: number;
99
+ };
100
+ EventTotalRes: {
101
+ event: string;
102
+ total: number;
103
+ };
104
+ Ping: {
105
+ message: string;
106
+ };
107
+ /** Format: date-time */
108
+ DateTime: string;
109
+ ProblemDetail: {
110
+ instance: string;
111
+ title: string;
112
+ status: number;
113
+ detail: string;
114
+ };
115
+ /** Format: date */
116
+ Date: string;
117
+ };
118
+ responses: never;
119
+ parameters: never;
120
+ requestBodies: never;
121
+ headers: never;
122
+ pathItems: never;
123
+ };
124
+ export type UserEventReq = components['schemas']['UserEventReq'];
125
+ export type EventCountByDayRes = components['schemas']['EventCountByDayRes'];
126
+ export type EventTotalRes = components['schemas']['EventTotalRes'];
127
+ export type Ping = components['schemas']['Ping'];
128
+ export type DateTime = components['schemas']['DateTime'];
129
+ export type ProblemDetail = components['schemas']['ProblemDetail'];
130
+ export type Date = components['schemas']['Date'];
131
+ export type $defs = Record<string, never>;
132
+ export interface operations {
133
+ "get-ping": {
134
+ parameters: {
135
+ query?: never;
136
+ header?: never;
137
+ path?: never;
138
+ cookie?: never;
139
+ };
140
+ requestBody?: never;
141
+ responses: {
142
+ /** @description pong */
143
+ 200: {
144
+ headers: {
145
+ [name: string]: unknown;
146
+ };
147
+ content: {
148
+ "application/json": components["schemas"]["Ping"];
149
+ };
150
+ };
151
+ };
152
+ };
153
+ "post-v1-events": {
154
+ parameters: {
155
+ query?: never;
156
+ header?: never;
157
+ path?: never;
158
+ cookie?: never;
159
+ };
160
+ requestBody: {
161
+ content: {
162
+ "application/json": components["schemas"]["UserEventReq"];
163
+ };
164
+ };
165
+ responses: {
166
+ /** @description event accepted for processing */
167
+ 201: {
168
+ headers: {
169
+ [name: string]: unknown;
170
+ };
171
+ content?: never;
172
+ };
173
+ /** @description internal server error */
174
+ 500: {
175
+ headers: {
176
+ [name: string]: unknown;
177
+ };
178
+ content: {
179
+ "application/json": components["schemas"]["ProblemDetail"];
180
+ };
181
+ };
182
+ };
183
+ };
184
+ "get-v1-dashboard-events-daily": {
185
+ parameters: {
186
+ query: {
187
+ /** @description Start date in YYYY-MM-DD format */
188
+ from_date: components["schemas"]["Date"];
189
+ /** @description End date in YYYY-MM-DD format */
190
+ to_date: components["schemas"]["Date"];
191
+ };
192
+ header?: never;
193
+ path?: never;
194
+ cookie?: never;
195
+ };
196
+ requestBody?: never;
197
+ responses: {
198
+ /** @description event counts grouped by day and event type */
199
+ 200: {
200
+ headers: {
201
+ [name: string]: unknown;
202
+ };
203
+ content: {
204
+ "application/json": {
205
+ data?: components["schemas"]["EventCountByDayRes"][];
206
+ };
207
+ };
208
+ };
209
+ /** @description internal server error */
210
+ 500: {
211
+ headers: {
212
+ [name: string]: unknown;
213
+ };
214
+ content: {
215
+ "application/json": components["schemas"]["ProblemDetail"];
216
+ };
217
+ };
218
+ };
219
+ };
220
+ "get-v1-dashboard-events-totals": {
221
+ parameters: {
222
+ query: {
223
+ /** @description Start date in YYYY-MM-DD format */
224
+ from_date: components["schemas"]["Date"];
225
+ /** @description End date in YYYY-MM-DD format */
226
+ to_date: components["schemas"]["Date"];
227
+ };
228
+ header?: never;
229
+ path?: never;
230
+ cookie?: never;
231
+ };
232
+ requestBody?: never;
233
+ responses: {
234
+ /** @description total event counts per event type */
235
+ 200: {
236
+ headers: {
237
+ [name: string]: unknown;
238
+ };
239
+ content: {
240
+ "application/json": {
241
+ data?: components["schemas"]["EventTotalRes"][];
242
+ };
243
+ };
244
+ };
245
+ /** @description internal server error */
246
+ 500: {
247
+ headers: {
248
+ [name: string]: unknown;
249
+ };
250
+ content: {
251
+ "application/json": components["schemas"]["ProblemDetail"];
252
+ };
253
+ };
254
+ };
255
+ };
256
+ }
257
+ export declare enum EventType {
258
+ video_upload = "video.upload",
259
+ video_clip_generate = "video.clip.generate",
260
+ video_clip_download = "video.clip.download",
261
+ video_compile_time = "video.compile.time",
262
+ image_download = "image.download",
263
+ aicontent_download = "aicontent.download",
264
+ aicontent_socialcarousel_download = "aicontent.socialcarousel.download",
265
+ aicontent_quotesandverses_download = "aicontent.quotesandverses.download",
266
+ aicontent_discussionguide_download = "aicontent.discussionguide.download",
267
+ aicontent_devotional_download = "aicontent.devotional.download",
268
+ aicontent_transcription_download = "aicontent.transcription.download",
269
+ aicontent_blog_download = "aicontent.blog.download",
270
+ aicontent_audio_download = "aicontent.audio.download",
271
+ aicontent_summary_download = "aicontent.summary.download"
272
+ }
package/dist/types.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by openapi-typescript.
4
+ * Do not make direct changes to the file.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.EventType = void 0;
8
+ var EventType;
9
+ (function (EventType) {
10
+ EventType["video_upload"] = "video.upload";
11
+ EventType["video_clip_generate"] = "video.clip.generate";
12
+ EventType["video_clip_download"] = "video.clip.download";
13
+ EventType["video_compile_time"] = "video.compile.time";
14
+ EventType["image_download"] = "image.download";
15
+ EventType["aicontent_download"] = "aicontent.download";
16
+ EventType["aicontent_socialcarousel_download"] = "aicontent.socialcarousel.download";
17
+ EventType["aicontent_quotesandverses_download"] = "aicontent.quotesandverses.download";
18
+ EventType["aicontent_discussionguide_download"] = "aicontent.discussionguide.download";
19
+ EventType["aicontent_devotional_download"] = "aicontent.devotional.download";
20
+ EventType["aicontent_transcription_download"] = "aicontent.transcription.download";
21
+ EventType["aicontent_blog_download"] = "aicontent.blog.download";
22
+ EventType["aicontent_audio_download"] = "aicontent.audio.download";
23
+ EventType["aicontent_summary_download"] = "aicontent.summary.download";
24
+ })(EventType || (exports.EventType = EventType = {}));
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@sermonshots/analytics",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "tsc --watch"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^22.0.0",
15
+ "typescript": "^5.8.0"
16
+ }
17
+ }