@sayrio/public 1.0.2 → 1.0.4
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/LICENSE.md +87 -0
- package/README.md +42 -42
- package/dist/index.cjs +55 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -12
- package/dist/index.d.ts +34 -12
- package/dist/index.js +52 -41
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +62 -54
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +10 -10
- package/dist/react/index.d.ts +10 -10
- package/dist/react/index.js +61 -53
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -2
package/LICENSE.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Doras Media Ltd
|
|
4
|
+
|
|
5
|
+
All third party components incorporated into the Sayr Software are licensed under the original license provided by the owner of the applicable component.
|
|
6
|
+
|
|
7
|
+
All content not covered by the above is available under the "Sustainable Use License" as defined below, with the additional terms set out in the "Additional Terms" section.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Sustainable Use License
|
|
12
|
+
|
|
13
|
+
Version 1.0
|
|
14
|
+
|
|
15
|
+
### Acceptance
|
|
16
|
+
|
|
17
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
18
|
+
|
|
19
|
+
### Copyright License
|
|
20
|
+
|
|
21
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations below.
|
|
22
|
+
|
|
23
|
+
### Limitations
|
|
24
|
+
|
|
25
|
+
You may use or modify the software only for your own internal business purposes or for non-commercial or personal use. You may distribute the software or provide it to others only if you do so free of charge for non-commercial purposes. You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor's trademarks is subject to applicable law.
|
|
26
|
+
|
|
27
|
+
### Patents
|
|
28
|
+
|
|
29
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
30
|
+
|
|
31
|
+
### Notices
|
|
32
|
+
|
|
33
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms. If you modify the software, you must include in any modified copies of the software a prominent notice stating that you have modified the software.
|
|
34
|
+
|
|
35
|
+
### No Other Rights
|
|
36
|
+
|
|
37
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
38
|
+
|
|
39
|
+
### Termination
|
|
40
|
+
|
|
41
|
+
If you use the software in violation of these terms, such use is not licensed, and your license will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your license will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your license to terminate automatically and permanently.
|
|
42
|
+
|
|
43
|
+
### No Liability
|
|
44
|
+
|
|
45
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
46
|
+
|
|
47
|
+
### Definitions
|
|
48
|
+
|
|
49
|
+
The "licensor" is the entity offering these terms.
|
|
50
|
+
|
|
51
|
+
The "software" is the software the licensor makes available under these terms, including any portion of it.
|
|
52
|
+
|
|
53
|
+
"You" refers to the individual or entity agreeing to these terms.
|
|
54
|
+
|
|
55
|
+
"Your company" is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. Control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
56
|
+
|
|
57
|
+
"Your license" is the license granted to you for the software under these terms.
|
|
58
|
+
|
|
59
|
+
"Use" means anything you do with the software requiring your license.
|
|
60
|
+
|
|
61
|
+
"Trademark" means trademarks, service marks, and similar rights.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Additional Terms
|
|
66
|
+
|
|
67
|
+
These additional terms supplement the Sustainable Use License above and apply to all use of the Sayr software.
|
|
68
|
+
|
|
69
|
+
### Enterprise Edition
|
|
70
|
+
|
|
71
|
+
The Sayr software includes a Community Edition (CE) and an Enterprise Edition (EE). EE features are enabled by a valid enterprise license key issued by Doras Media Ltd. Use of EE features remains subject to all terms of this license, including the Limitations section. An enterprise license key does not grant any right to resell or sublicense the software or to offer it to third parties as a hosted or managed service.
|
|
72
|
+
|
|
73
|
+
### Anti-Circumvention
|
|
74
|
+
|
|
75
|
+
You may not remove, disable, modify, or circumvent the edition detection, feature-gating, or license key validation mechanisms in the software, including but not limited to the code in `packages/edition` and any build-time or runtime edition configuration. You may inspect and audit this code, but you may not alter its effect.
|
|
76
|
+
|
|
77
|
+
### Contributions
|
|
78
|
+
|
|
79
|
+
By submitting a contribution to this repository, you agree to the terms of the [Contributor License Agreement](./CLA.md). Contributions submitted without a signed CLA will not be accepted.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
This license does not grant any right to use the name "Sayr", "Sayr.io", or any associated logos or trademarks of Doras Media Ltd, except as required for reasonable attribution.
|
|
84
|
+
|
|
85
|
+
### Governing Law
|
|
86
|
+
|
|
87
|
+
This license is governed by the laws of Ireland. Any disputes arising under this license are subject to the exclusive jurisdiction of the courts of Ireland.
|
package/README.md
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Public JavaScript & TypeScript SDK for **Sayr.io**.
|
|
4
4
|
Provides **read‑only access** to Sayr organizations, tasks, comments, and
|
|
5
|
-
real‑time updates via
|
|
5
|
+
real‑time updates via **SSE (Server‑Sent Events)**.
|
|
6
6
|
|
|
7
|
-
- ✅ REST +
|
|
8
|
-
- ✅ Browser‑safe
|
|
9
|
-
- ✅ TypeScript‑first
|
|
10
|
-
- ✅ Zero runtime dependencies
|
|
11
|
-
- ✅ Versioned API (`v1`)
|
|
12
|
-
- ✅ Consistent `ApiResult<T>` responses
|
|
7
|
+
- ✅ REST + ServerEvents
|
|
8
|
+
- ✅ Browser‑safe
|
|
9
|
+
- ✅ TypeScript‑first
|
|
10
|
+
- ✅ Zero runtime dependencies
|
|
11
|
+
- ✅ Versioned API (`v1`)
|
|
12
|
+
- ✅ Consistent `ApiResult<T>` responses
|
|
13
|
+
- ✅ Real‑time public updates via **SSE**
|
|
13
14
|
|
|
14
15
|
> React hooks are available via the **`@sayrio/public/react`** sub‑path export.
|
|
15
16
|
|
|
@@ -21,7 +22,7 @@ real‑time updates via WebSockets.
|
|
|
21
22
|
npm install @sayrio/public
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
or
|
|
25
|
+
or:
|
|
25
26
|
|
|
26
27
|
```bash
|
|
27
28
|
pnpm add @sayrio/public
|
|
@@ -68,7 +69,7 @@ if (!res.success) {
|
|
|
68
69
|
console.log(res.data.name);
|
|
69
70
|
```
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
Explicit versioned API:
|
|
72
73
|
|
|
73
74
|
```ts
|
|
74
75
|
const res = await Sayr.v1.org.get("acme");
|
|
@@ -189,16 +190,12 @@ authenticated user.
|
|
|
189
190
|
> Authentication is required
|
|
190
191
|
> Set a token using `Sayr.client.setToken(...)`.
|
|
191
192
|
|
|
192
|
-
---
|
|
193
|
-
|
|
194
193
|
### Set Token
|
|
195
194
|
|
|
196
195
|
```ts
|
|
197
196
|
Sayr.client.setToken("********");
|
|
198
197
|
```
|
|
199
198
|
|
|
200
|
-
---
|
|
201
|
-
|
|
202
199
|
### Fetch Current User
|
|
203
200
|
|
|
204
201
|
```ts
|
|
@@ -209,8 +206,6 @@ if (res.success) {
|
|
|
209
206
|
}
|
|
210
207
|
```
|
|
211
208
|
|
|
212
|
-
---
|
|
213
|
-
|
|
214
209
|
### List Your Organizations
|
|
215
210
|
|
|
216
211
|
```ts
|
|
@@ -223,22 +218,22 @@ if (res.success) {
|
|
|
223
218
|
|
|
224
219
|
---
|
|
225
220
|
|
|
226
|
-
|
|
221
|
+
# Real‑Time Updates (SSE)
|
|
227
222
|
|
|
228
|
-
Subscribe to public real‑time events using
|
|
223
|
+
Subscribe to public real‑time events using **Server‑Sent Events**:
|
|
229
224
|
|
|
230
225
|
```ts
|
|
231
|
-
Sayr.
|
|
232
|
-
[Sayr.
|
|
226
|
+
Sayr.sse(org.eventsUrl, {
|
|
227
|
+
[Sayr.EVENTS.UPDATE_TASK]: (data) => {
|
|
233
228
|
console.log("Task updated", data);
|
|
234
229
|
},
|
|
235
230
|
});
|
|
236
231
|
```
|
|
237
232
|
|
|
238
|
-
###
|
|
233
|
+
### SSE Features
|
|
239
234
|
|
|
240
|
-
- Automatic reconnection
|
|
241
|
-
-
|
|
235
|
+
- Automatic reconnection (native in browsers)
|
|
236
|
+
- Lightweight, one‑way streaming
|
|
242
237
|
- Typed event constants
|
|
243
238
|
- Public‑safe payloads only
|
|
244
239
|
|
|
@@ -255,18 +250,23 @@ Sayr.ws(org.wsUrl, {
|
|
|
255
250
|
if (res.success) {
|
|
256
251
|
console.log(res.data);
|
|
257
252
|
}
|
|
253
|
+
|
|
254
|
+
// SSE Example
|
|
255
|
+
Sayr.sse("https://example.com/events", {
|
|
256
|
+
UPDATE_TASK: (data) => console.log("Task updated", data),
|
|
257
|
+
});
|
|
258
258
|
</script>
|
|
259
259
|
```
|
|
260
260
|
|
|
261
261
|
---
|
|
262
262
|
|
|
263
|
-
|
|
263
|
+
# API Overview
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
## `Sayr.org` (latest)
|
|
266
266
|
|
|
267
267
|
Alias for `Sayr.v1.org`.
|
|
268
268
|
|
|
269
|
-
|
|
269
|
+
### Organization
|
|
270
270
|
|
|
271
271
|
| Method | Description |
|
|
272
272
|
| ----------- | --------------------------- |
|
|
@@ -274,7 +274,7 @@ Alias for `Sayr.v1.org`.
|
|
|
274
274
|
|
|
275
275
|
---
|
|
276
276
|
|
|
277
|
-
|
|
277
|
+
### Tasks
|
|
278
278
|
|
|
279
279
|
| Method | Description |
|
|
280
280
|
| -------------------------- | ---------------------- |
|
|
@@ -283,7 +283,7 @@ Alias for `Sayr.v1.org`.
|
|
|
283
283
|
|
|
284
284
|
---
|
|
285
285
|
|
|
286
|
-
|
|
286
|
+
### Comments
|
|
287
287
|
|
|
288
288
|
| Method | Description |
|
|
289
289
|
| ------------------------------------- | ------------------------ |
|
|
@@ -291,7 +291,7 @@ Alias for `Sayr.v1.org`.
|
|
|
291
291
|
|
|
292
292
|
---
|
|
293
293
|
|
|
294
|
-
|
|
294
|
+
### Labels
|
|
295
295
|
|
|
296
296
|
| Method | Description |
|
|
297
297
|
| ------------------- | ------------------------ |
|
|
@@ -299,7 +299,7 @@ Alias for `Sayr.v1.org`.
|
|
|
299
299
|
|
|
300
300
|
---
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
### Categories
|
|
303
303
|
|
|
304
304
|
| Method | Description |
|
|
305
305
|
| ------------------------------- | --------------- |
|
|
@@ -307,7 +307,7 @@ Alias for `Sayr.v1.org`.
|
|
|
307
307
|
|
|
308
308
|
---
|
|
309
309
|
|
|
310
|
-
|
|
310
|
+
## `Sayr.me`
|
|
311
311
|
|
|
312
312
|
Authenticated user endpoints.
|
|
313
313
|
|
|
@@ -318,12 +318,14 @@ Authenticated user endpoints.
|
|
|
318
318
|
|
|
319
319
|
---
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
# Real‑Time API
|
|
322
322
|
|
|
323
|
-
|
|
323
|
+
## `Sayr.sse(url, handlers)`
|
|
324
|
+
|
|
325
|
+
Create an SSE connection for public events:
|
|
324
326
|
|
|
325
327
|
```ts
|
|
326
|
-
const conn = Sayr.
|
|
328
|
+
const conn = Sayr.sse(eventsUrl, {
|
|
327
329
|
UPDATE_TASK: () => {},
|
|
328
330
|
});
|
|
329
331
|
|
|
@@ -332,15 +334,15 @@ conn.close();
|
|
|
332
334
|
|
|
333
335
|
---
|
|
334
336
|
|
|
335
|
-
|
|
337
|
+
## `EVENTS`
|
|
336
338
|
|
|
337
|
-
Typed
|
|
339
|
+
Typed SSE event constants:
|
|
338
340
|
|
|
339
341
|
```ts
|
|
340
|
-
Sayr.
|
|
341
|
-
Sayr.
|
|
342
|
-
Sayr.
|
|
343
|
-
Sayr.
|
|
342
|
+
Sayr.EVENTS.CREATE_TASK;
|
|
343
|
+
Sayr.EVENTS.UPDATE_TASK;
|
|
344
|
+
Sayr.EVENTS.UPDATE_TASK_COMMENTS;
|
|
345
|
+
Sayr.EVENTS.ERROR;
|
|
344
346
|
```
|
|
345
347
|
|
|
346
348
|
---
|
|
@@ -374,6 +376,4 @@ import {
|
|
|
374
376
|
} from "@sayrio/public/react";
|
|
375
377
|
```
|
|
376
378
|
|
|
377
|
-
See **`@sayrio/public/react` README** for full hook documentation.
|
|
378
|
-
|
|
379
|
-
---
|
|
379
|
+
See **`@sayrio/public/react` README** for full hook documentation.
|
package/dist/index.cjs
CHANGED
|
@@ -21,10 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
SayrClient: () => SayrClient,
|
|
24
|
+
SayrSSE: () => SayrSSE,
|
|
25
|
+
SayrServerEvents: () => SayrServerEvents,
|
|
24
26
|
SayrV1: () => SayrV1,
|
|
25
|
-
|
|
26
|
-
SayrWSEvents: () => SayrWSEvents,
|
|
27
|
-
WS_EVENTS: () => WS_EVENTS,
|
|
27
|
+
ServerEvent_EVENTS: () => ServerEvent_EVENTS,
|
|
28
28
|
buildPaginationParams: () => buildPaginationParams,
|
|
29
29
|
default: () => index_default
|
|
30
30
|
});
|
|
@@ -354,6 +354,26 @@ var me_default = {
|
|
|
354
354
|
error: err?.message ?? "Failed to fetch organizations"
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
|
+
},
|
|
358
|
+
async createTask(body, opts) {
|
|
359
|
+
try {
|
|
360
|
+
const r = await request("/v1/me/task", {
|
|
361
|
+
...opts,
|
|
362
|
+
method: "POST",
|
|
363
|
+
body
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
success: true,
|
|
367
|
+
data: r.data,
|
|
368
|
+
error: null
|
|
369
|
+
};
|
|
370
|
+
} catch (err) {
|
|
371
|
+
return {
|
|
372
|
+
success: false,
|
|
373
|
+
data: null,
|
|
374
|
+
error: err?.message ?? "Failed to create task"
|
|
375
|
+
};
|
|
376
|
+
}
|
|
357
377
|
}
|
|
358
378
|
};
|
|
359
379
|
|
|
@@ -364,65 +384,56 @@ var v1 = {
|
|
|
364
384
|
};
|
|
365
385
|
var v1_default = v1;
|
|
366
386
|
|
|
367
|
-
// src/
|
|
368
|
-
|
|
369
|
-
CONNECTION_STATUS: "CONNECTION_STATUS",
|
|
370
|
-
SUBSCRIBED: "SUBSCRIBED",
|
|
371
|
-
ERROR: "ERROR",
|
|
372
|
-
PING: "PING",
|
|
373
|
-
PONG: "PONG",
|
|
374
|
-
UPDATE_ORG: "UPDATE_ORG",
|
|
375
|
-
CREATE_TASK: "CREATE_TASK",
|
|
376
|
-
UPDATE_TASK: "UPDATE_TASK",
|
|
377
|
-
UPDATE_TASK_COMMENTS: "UPDATE_TASK_COMMENTS",
|
|
378
|
-
UPDATE_TASK_VOTE: "UPDATE_TASK_VOTE",
|
|
379
|
-
UPDATE_LABELS: "UPDATE_LABELS",
|
|
380
|
-
UPDATE_VIEWS: "UPDATE_VIEWS",
|
|
381
|
-
UPDATE_CATEGORIES: "UPDATE_CATEGORIES",
|
|
382
|
-
UPDATE_ISSUE_TEMPLATES: "UPDATE_ISSUE_TEMPLATES",
|
|
383
|
-
DISCONNECTED: "DISCONNECTED"
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
// src/ws/index.ts
|
|
387
|
-
function ws(url, handlers = {}) {
|
|
387
|
+
// src/events/index.ts
|
|
388
|
+
function sse(url, handlers = {}) {
|
|
388
389
|
if (!url) {
|
|
389
390
|
throw new Error(
|
|
390
|
-
"[Sayr.
|
|
391
|
+
"[Sayr.sse] SSE URL is required. Did you forget to pass org.eventsUrl?"
|
|
391
392
|
);
|
|
392
393
|
}
|
|
393
|
-
let
|
|
394
|
-
let retry = 0;
|
|
394
|
+
let source = null;
|
|
395
395
|
let closed = false;
|
|
396
396
|
function connect() {
|
|
397
397
|
if (closed) return;
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
source = new EventSource(url);
|
|
399
|
+
source.onmessage = (e) => {
|
|
400
400
|
const msg = JSON.parse(e.data);
|
|
401
|
-
if (msg.type === WS_EVENTS.PING) {
|
|
402
|
-
socket.send(JSON.stringify({ type: WS_EVENTS.PONG }));
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
401
|
handlers[msg.type]?.(msg.data, msg);
|
|
406
402
|
};
|
|
407
|
-
|
|
403
|
+
source.onerror = () => {
|
|
408
404
|
if (closed) return;
|
|
409
|
-
|
|
405
|
+
source?.close();
|
|
406
|
+
setTimeout(connect, 2e3);
|
|
410
407
|
};
|
|
411
|
-
socket.onerror = () => socket.close();
|
|
412
408
|
}
|
|
413
409
|
connect();
|
|
414
410
|
return {
|
|
415
411
|
close() {
|
|
416
412
|
closed = true;
|
|
417
|
-
|
|
413
|
+
source?.close();
|
|
418
414
|
}
|
|
419
415
|
};
|
|
420
416
|
}
|
|
421
417
|
|
|
418
|
+
// src/events/types.ts
|
|
419
|
+
var ServerEvent_EVENTS = {
|
|
420
|
+
CONNECTION_STATUS: "CONNECTION_STATUS",
|
|
421
|
+
ERROR: "ERROR",
|
|
422
|
+
UPDATE_ORG: "UPDATE_ORG",
|
|
423
|
+
CREATE_TASK: "CREATE_TASK",
|
|
424
|
+
UPDATE_TASK: "UPDATE_TASK",
|
|
425
|
+
UPDATE_TASK_COMMENTS: "UPDATE_TASK_COMMENTS",
|
|
426
|
+
UPDATE_TASK_VOTE: "UPDATE_TASK_VOTE",
|
|
427
|
+
UPDATE_LABELS: "UPDATE_LABELS",
|
|
428
|
+
UPDATE_VIEWS: "UPDATE_VIEWS",
|
|
429
|
+
UPDATE_CATEGORIES: "UPDATE_CATEGORIES",
|
|
430
|
+
UPDATE_ISSUE_TEMPLATES: "UPDATE_ISSUE_TEMPLATES"
|
|
431
|
+
};
|
|
432
|
+
|
|
422
433
|
// src/index.ts
|
|
423
434
|
var SayrV1 = v1_default;
|
|
424
|
-
var
|
|
425
|
-
var
|
|
435
|
+
var SayrSSE = sse;
|
|
436
|
+
var SayrServerEvents = ServerEvent_EVENTS;
|
|
426
437
|
var SayrClient = {
|
|
427
438
|
setToken,
|
|
428
439
|
setHeaders,
|
|
@@ -438,17 +449,17 @@ var Sayr = {
|
|
|
438
449
|
org: v1_default.org,
|
|
439
450
|
me: v1_default.me,
|
|
440
451
|
// realtime
|
|
441
|
-
|
|
442
|
-
|
|
452
|
+
sse,
|
|
453
|
+
EVENTS: ServerEvent_EVENTS
|
|
443
454
|
};
|
|
444
455
|
var index_default = Sayr;
|
|
445
456
|
// Annotate the CommonJS export names for ESM import in node:
|
|
446
457
|
0 && (module.exports = {
|
|
447
458
|
SayrClient,
|
|
459
|
+
SayrSSE,
|
|
460
|
+
SayrServerEvents,
|
|
448
461
|
SayrV1,
|
|
449
|
-
|
|
450
|
-
SayrWSEvents,
|
|
451
|
-
WS_EVENTS,
|
|
462
|
+
ServerEvent_EVENTS,
|
|
452
463
|
buildPaginationParams
|
|
453
464
|
});
|
|
454
465
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client/index.ts","../src/api/v1/org/org.ts","../src/shared/index.ts","../src/api/v1/org/tasks.ts","../src/api/v1/org/comments.ts","../src/api/v1/org/labels.ts","../src/api/v1/org/categories.ts","../src/api/v1/org/index.ts","../src/api/v1/me/index.ts","../src/api/v1/index.ts","../src/ws/types.ts","../src/ws/index.ts"],"sourcesContent":["/* ────────────────────────────\r\n API versions\r\n──────────────────────────── */\r\nimport v1 from \"./api/v1\";\r\n\r\n/* ────────────────────────────\r\n Realtime\r\n──────────────────────────── */\r\nimport { ws } from \"./ws\";\r\nimport { WS_EVENTS } from \"./ws/types\";\r\n\r\n/* ────────────────────────────\r\n Client config\r\n──────────────────────────── */\r\nimport {\r\n setToken,\r\n setHeaders,\r\n setBaseUrl,\r\n resetClient,\r\n setHooks,\r\n} from \"./client\";\r\n\r\n/* ────────────────────────────\r\n Named exports (power users)\r\n──────────────────────────── */\r\n\r\n/**\r\n * Sayr Public API — Version 1.\r\n *\r\n * @since v1.0.0\r\n */\r\nexport const SayrV1 = v1;\r\n\r\n\r\n/**\r\n * Create a WebSocket connection for public real‑time updates.\r\n */\r\nexport const SayrWS = ws;\r\n\r\n/**\r\n * Typed WebSocket event constants.\r\n */\r\nexport const SayrWSEvents = WS_EVENTS;\r\n\r\n/**\r\n * Global client configuration helpers.\r\n */\r\nexport const SayrClient = {\r\n setToken,\r\n setHeaders,\r\n setBaseUrl,\r\n resetClient,\r\n setHooks,\r\n};\r\n\r\n/* ────────────────────────────\r\n Default facade\r\n──────────────────────────── */\r\n\r\n/**\r\n * Sayr Public SDK.\r\n *\r\n * Read‑only access to public Sayr data via REST and WebSockets.\r\n *\r\n * @since v1.0.0\r\n */\r\nconst Sayr: {\r\n /**\r\n * Client configuration helpers.\r\n */\r\n client: typeof SayrClient;\r\n\r\n /**\r\n * Versioned API namespaces.\r\n */\r\n v1: typeof v1;\r\n\r\n /**\r\n * Alias for the current API version (`v1`).\r\n *\r\n * @since v1.0.0\r\n */\r\n org: typeof v1.org;\r\n me: typeof v1.me;\r\n\r\n /**\r\n * WebSocket helper for real‑time updates.\r\n */\r\n ws: typeof ws;\r\n\r\n /**\r\n * WebSocket event constants.\r\n */\r\n WS_EVENTS: typeof WS_EVENTS;\r\n} = {\r\n // client configuration\r\n client: SayrClient,\r\n\r\n // APIs\r\n v1,\r\n org: v1.org,\r\n me: v1.me,\r\n\r\n // realtime\r\n ws,\r\n WS_EVENTS\r\n};\r\n\r\nexport default Sayr;\r\n\r\n/* ────────────────────────────\r\n Types & shared helpers\r\n──────────────────────────── */\r\nexport * from \"./types\";\r\nexport * from \"./shared\";\r\nexport * from \"./ws/types\";","import { ApiError } from \"../types\";\r\n\r\n/* ────────────────────────────\r\n Types\r\n──────────────────────────── */\r\nexport type RequestOptions = {\r\n method?: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\r\n headers?: Record<string, string>;\r\n body?: Record<string, string>;\r\n signal?: AbortSignal;\r\n};\r\n\r\nexport interface ApiResult<T> {\r\n success: boolean;\r\n data: T | null;\r\n error: string | null;\r\n}\r\n\r\ntype Hooks = {\r\n onRequest?: (url: string, opts: RequestOptions) => void;\r\n onResponse?: (res: Response) => void;\r\n onError?: (error: ApiError | unknown) => void;\r\n};\r\n\r\ntype ClientConfig = {\r\n token?: string;\r\n headers?: Record<string, string>;\r\n baseUrl: string;\r\n};\r\n\r\n/* ────────────────────────────\r\n Internal state\r\n──────────────────────────── */\r\nconst DEFAULT_API = \"https://api.sayr.io\";\r\n\r\nconst config: ClientConfig = {\r\n baseUrl: DEFAULT_API\r\n};\r\n\r\nconst hooks: Hooks = {};\r\n\r\n/* ────────────────────────────\r\n Public config API\r\n──────────────────────────── */\r\nexport function setToken(token?: string) {\r\n config.token = token;\r\n}\r\n\r\nexport function getToken() {\r\n return config.token;\r\n}\r\n\r\nexport function setHeaders(headers?: Record<string, string>) {\r\n config.headers = {\r\n ...config.headers,\r\n ...headers\r\n };\r\n}\r\n\r\nexport function setBaseUrl(url: string) {\r\n config.baseUrl = url.replace(/\\/$/, \"\");\r\n}\r\n\r\nexport function setHooks(h: Hooks) {\r\n Object.assign(hooks, h);\r\n}\r\nexport function resetClient() {\r\n config.token = undefined;\r\n config.headers = undefined;\r\n config.baseUrl = DEFAULT_API;\r\n}\r\n\r\n/* ────────────────────────────\r\n Request helper\r\n──────────────────────────── */\r\nexport async function request<T>(\r\n path: string,\r\n opts: RequestOptions = {}\r\n): Promise<T> {\r\n\r\n let url: string;\r\n try {\r\n url = path.startsWith(\"http\")\r\n ? path\r\n : `${config.baseUrl}${path}`;\r\n } catch (err) {\r\n throw err;\r\n }\r\n\r\n try {\r\n hooks.onRequest?.(url, opts);\r\n } catch (err) {\r\n throw err;\r\n }\r\n\r\n let res: Response;\r\n\r\n try {\r\n const method = opts.method ?? \"GET\";\r\n\r\n\r\n // 🔴 Guard: GET must not have body\r\n if (method === \"GET\" && opts.body !== undefined) {\r\n throw new Error(\"GET request cannot have a body\");\r\n }\r\n\r\n res = await fetch(url, {\r\n method,\r\n headers: {\r\n ...(config.token\r\n ? { Authorization: `Bearer ${config.token}` }\r\n : {}),\r\n ...(opts.body && method !== \"GET\"\r\n ? { \"Content-Type\": \"application/json\" }\r\n : {}),\r\n ...config.headers,\r\n ...opts.headers\r\n },\r\n body:\r\n opts.body && method !== \"GET\"\r\n ? JSON.stringify(opts.body)\r\n : undefined,\r\n signal: opts.signal\r\n });\r\n } catch (err) {\r\n const error: ApiError = {\r\n success: false,\r\n error: \"NETWORK_ERROR\",\r\n message: \"Failed to reach Sayr API\",\r\n // 👇 keep raw error so we can see it\r\n // @ts-ignore\r\n raw: err\r\n };\r\n\r\n hooks.onError?.(error);\r\n throw error;\r\n }\r\n\r\n try {\r\n hooks.onResponse?.(res);\r\n } catch (err) {\r\n throw err;\r\n }\r\n\r\n let json: any;\r\n try {\r\n json = await res.json();\r\n } catch (err) {\r\n const error: ApiError = {\r\n success: false,\r\n error: \"INVALID_RESPONSE\",\r\n message: \"Server returned invalid JSON\",\r\n status: res.status\r\n };\r\n hooks.onError?.(error);\r\n throw error;\r\n }\r\n if (!res.ok || !json.success) {\r\n const error: ApiError = {\r\n ...json,\r\n success: false,\r\n status: res.status\r\n };\r\n hooks.onError?.(error);\r\n throw error;\r\n }\r\n return json;\r\n}","import { Organization, ApiSuccess } from \"../../../types\";\r\nimport { ApiResult, request, type RequestOptions } from \"../../../client\";\r\n\r\n/**\r\n * Organization core operations.\r\n */\r\nexport default {\r\n /**\r\n * Fetches a public organization by slug.\r\n *\r\n * @since v1.0.0\r\n */\r\n async get(\r\n slug: string,\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Organization>> {\r\n try {\r\n const r = await request<ApiSuccess<Organization>>(\r\n `/v1/organization/${slug}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch organization\",\r\n };\r\n }\r\n },\r\n};","/* =======================\r\n * Shared params & helpers\r\n * ======================= */\r\n\r\nexport type Order = \"asc\" | \"desc\";\r\n\r\nexport interface PaginationParams {\r\n page?: number;\r\n limit?: number;\r\n}\r\n\r\nexport interface OrderedPaginationParams extends PaginationParams {\r\n order?: Order;\r\n}\r\n\r\nexport function buildPaginationParams(\r\n params?: OrderedPaginationParams\r\n): URLSearchParams {\r\n return new URLSearchParams({\r\n order: params?.order ?? \"desc\",\r\n limit: String(params?.limit ?? 5),\r\n page: String(params?.page ?? 1)\r\n });\r\n}","import {\r\n Task,\r\n Pagination,\r\n ApiSuccess,\r\n} from \"../../../types\";\r\nimport {\r\n ApiResult,\r\n request,\r\n type RequestOptions,\r\n} from \"../../../client\";\r\nimport {\r\n type OrderedPaginationParams,\r\n buildPaginationParams,\r\n} from \"../../../shared\";\r\n\r\n/**\r\n * Organization tasks.\r\n */\r\nexport default {\r\n /**\r\n * Lists public tasks for an organization.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n params?: OrderedPaginationParams,\r\n opts?: RequestOptions,\r\n ): Promise<\r\n ApiResult<{\r\n items: Task[];\r\n pagination: Pagination;\r\n }>\r\n > {\r\n try {\r\n const q = buildPaginationParams(params);\r\n\r\n const r = await request<\r\n ApiSuccess<Task[]> & { pagination: Pagination }\r\n >(\r\n `/v1/organization/${slug}/tasks?${q}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: {\r\n items: r.data,\r\n pagination: r.pagination,\r\n },\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch tasks\",\r\n };\r\n }\r\n },\r\n\r\n /**\r\n * Fetches a single public task by short ID.\r\n *\r\n * @since v1.0.0\r\n */\r\n async get(\r\n slug: string,\r\n shortId: number,\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Task>> {\r\n try {\r\n const r = await request<ApiSuccess<Task>>(\r\n `/v1/organization/${slug}/tasks/${shortId}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch task\",\r\n };\r\n }\r\n },\r\n};","import {\r\n Comment,\r\n Pagination,\r\n ApiSuccess,\r\n} from \"../../../types\";\r\nimport {\r\n ApiResult,\r\n request,\r\n type RequestOptions,\r\n} from \"../../../client\";\r\nimport {\r\n type OrderedPaginationParams,\r\n buildPaginationParams,\r\n} from \"../../../shared\";\r\n\r\n/**\r\n * Organization task comments.\r\n */\r\nexport default {\r\n /**\r\n * Lists public comments for a task.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n shortId: number,\r\n params?: OrderedPaginationParams,\r\n opts?: RequestOptions,\r\n ): Promise<\r\n ApiResult<{\r\n items: Comment[];\r\n pagination: Pagination;\r\n }>\r\n > {\r\n try {\r\n const q = buildPaginationParams(params);\r\n\r\n const r = await request<\r\n ApiSuccess<Comment[]> & { pagination: Pagination }\r\n >(\r\n `/v1/organization/${slug}/tasks/${shortId}/comments?${q}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: {\r\n items: r.data,\r\n pagination: r.pagination,\r\n },\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch task comments\",\r\n };\r\n }\r\n },\r\n};","import { Label, ApiSuccess } from \"../../../types\";\r\nimport { ApiResult, request, type RequestOptions } from \"../../../client\";\r\n\r\n/**\r\n * Organization labels.\r\n */\r\nexport default {\r\n /**\r\n * Lists public labels for an organization.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Label[]>> {\r\n try {\r\n const r = await request<ApiSuccess<Label[]>>(\r\n `/v1/organization/${slug}/labels`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch labels\",\r\n };\r\n }\r\n },\r\n};","import {\r\n Category,\r\n ApiSuccess,\r\n} from \"../../../types\";\r\nimport {\r\n ApiResult,\r\n request,\r\n type RequestOptions,\r\n} from \"../../../client\";\r\nimport { type Order } from \"../../../shared\";\r\n\r\n/**\r\n * Organization categories.\r\n */\r\nexport default {\r\n /**\r\n * Lists public categories for an organization.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n order: Order = \"desc\",\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Category[]>> {\r\n try {\r\n const r = await request<ApiSuccess<Category[]>>(\r\n `/v1/organization/${slug}/categories?order=${order}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch categories\",\r\n };\r\n }\r\n },\r\n};","import org from \"./org\";\r\nimport tasks from \"./tasks\";\r\nimport comments from \"./comments\";\r\nimport labels from \"./labels\";\r\nimport categories from \"./categories\";\r\n\r\n/**\r\n * Public Sayr Organization API — Version 1.\r\n *\r\n * @since v1.0.0\r\n */\r\nconst OrgAPI = {\r\n ...org,\r\n tasks,\r\n comments,\r\n labels,\r\n categories\r\n};\r\n\r\nexport default OrgAPI;","import { ApiResult, request, type RequestOptions } from \"../../../client\";\r\nimport { ApiSuccess, Organization } from \"../../../types\";\r\n\r\nexport interface Me {\r\n id: string;\r\n name: string | null;\r\n email: string | null;\r\n image: string | null;\r\n createdAt: string;\r\n}\r\n\r\n/**\r\n * Authenticated user API — Version 1.\r\n *\r\n * @since v1.0.0\r\n */\r\nexport default {\r\n async get(opts?: RequestOptions): Promise<ApiResult<Me>> {\r\n try {\r\n const r = await request<ApiSuccess<Me>>(\"/v1/me\", opts);\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch user\",\r\n };\r\n }\r\n },\r\n\r\n async organizations(\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Organization[]>> {\r\n try {\r\n const r = await request<ApiSuccess<Organization[]>>(\r\n \"/v1/me/organizations\",\r\n opts,\r\n );\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch organizations\",\r\n };\r\n }\r\n },\r\n};","import org from \"./org\";\r\nimport me from \"./me\";\r\nexport const v1 = {\r\n org,\r\n me\r\n};\r\n\r\nexport default v1;","export type WSMessageType =\r\n | \"CONNECTION_STATUS\"\r\n | \"SUBSCRIBED\"\r\n | \"ERROR\"\r\n | \"PING\"\r\n | \"PONG\"\r\n | \"UPDATE_ORG\"\r\n | \"CREATE_TASK\"\r\n | \"UPDATE_TASK\"\r\n | \"UPDATE_TASK_COMMENTS\"\r\n | \"UPDATE_TASK_VOTE\"\r\n | \"UPDATE_LABELS\"\r\n | \"UPDATE_VIEWS\"\r\n | \"UPDATE_CATEGORIES\"\r\n | \"UPDATE_ISSUE_TEMPLATES\"\r\n | \"DISCONNECTED\";\r\n\r\n/**\r\n * String enum replacement for WS event names.\r\n * Use this instead of raw strings.\r\n */\r\nexport const WS_EVENTS: Record<WSMessageType, WSMessageType> = {\r\n CONNECTION_STATUS: \"CONNECTION_STATUS\",\r\n SUBSCRIBED: \"SUBSCRIBED\",\r\n ERROR: \"ERROR\",\r\n PING: \"PING\",\r\n PONG: \"PONG\",\r\n UPDATE_ORG: \"UPDATE_ORG\",\r\n CREATE_TASK: \"CREATE_TASK\",\r\n UPDATE_TASK: \"UPDATE_TASK\",\r\n UPDATE_TASK_COMMENTS: \"UPDATE_TASK_COMMENTS\",\r\n UPDATE_TASK_VOTE: \"UPDATE_TASK_VOTE\",\r\n UPDATE_LABELS: \"UPDATE_LABELS\",\r\n UPDATE_VIEWS: \"UPDATE_VIEWS\",\r\n UPDATE_CATEGORIES: \"UPDATE_CATEGORIES\",\r\n UPDATE_ISSUE_TEMPLATES: \"UPDATE_ISSUE_TEMPLATES\",\r\n DISCONNECTED: \"DISCONNECTED\"\r\n};\r\n\r\nexport interface WSMessage<T = unknown> {\r\n type: WSMessageType;\r\n scope: \"PUBLIC\";\r\n data: T;\r\n meta?: { ts: number };\r\n}","import { WS_EVENTS, type WSMessage, type WSMessageType } from \"./types\";\r\n\r\ntype Handlers = Partial<\r\n Record<WSMessageType, (data: any, msg: WSMessage) => void>\r\n>;\r\n\r\nexport function ws(url: string, handlers: Handlers = {}) {\r\n if (!url) {\r\n throw new Error(\r\n \"[Sayr.ws] WebSocket URL is required. \" +\r\n \"Did you forget to pass org.wsUrl?\"\r\n );\r\n }\r\n let socket: WebSocket;\r\n let retry = 0;\r\n let closed = false;\r\n\r\n function connect() {\r\n if (closed) return;\r\n\r\n socket = new WebSocket(url);\r\n\r\n socket.onmessage = (e) => {\r\n const msg = JSON.parse(e.data) as WSMessage;\r\n\r\n if (msg.type === WS_EVENTS.PING) {\r\n socket.send(JSON.stringify({ type: WS_EVENTS.PONG }));\r\n return;\r\n }\r\n\r\n handlers[msg.type]?.(msg.data, msg);\r\n };\r\n\r\n socket.onclose = () => {\r\n if (closed) return;\r\n setTimeout(connect, Math.min(1000 * 2 ** retry++, 30000));\r\n };\r\n\r\n socket.onerror = () => socket.close();\r\n }\r\n\r\n connect();\r\n\r\n return {\r\n close() {\r\n closed = true;\r\n socket?.close();\r\n }\r\n };\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiCA,IAAM,cAAc;AAEpB,IAAM,SAAuB;AAAA,EACzB,SAAS;AACb;AAEA,IAAM,QAAe,CAAC;AAKf,SAAS,SAAS,OAAgB;AACrC,SAAO,QAAQ;AACnB;AAMO,SAAS,WAAW,SAAkC;AACzD,SAAO,UAAU;AAAA,IACb,GAAG,OAAO;AAAA,IACV,GAAG;AAAA,EACP;AACJ;AAEO,SAAS,WAAW,KAAa;AACpC,SAAO,UAAU,IAAI,QAAQ,OAAO,EAAE;AAC1C;AAEO,SAAS,SAAS,GAAU;AAC/B,SAAO,OAAO,OAAO,CAAC;AAC1B;AACO,SAAS,cAAc;AAC1B,SAAO,QAAQ;AACf,SAAO,UAAU;AACjB,SAAO,UAAU;AACrB;AAKA,eAAsB,QAClB,MACA,OAAuB,CAAC,GACd;AAEV,MAAI;AACJ,MAAI;AACA,UAAM,KAAK,WAAW,MAAM,IACtB,OACA,GAAG,OAAO,OAAO,GAAG,IAAI;AAAA,EAClC,SAAS,KAAK;AACV,UAAM;AAAA,EACV;AAEA,MAAI;AACA,UAAM,YAAY,KAAK,IAAI;AAAA,EAC/B,SAAS,KAAK;AACV,UAAM;AAAA,EACV;AAEA,MAAI;AAEJ,MAAI;AACA,UAAM,SAAS,KAAK,UAAU;AAI9B,QAAI,WAAW,SAAS,KAAK,SAAS,QAAW;AAC7C,YAAM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AA,EACf,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,wBAAwB;AAAA,EACxB,cAAc;AAClB;;;AC/BO,SAAS,GAAG,KAAa,WAAqB,CAAC,GAAG;AACrD,MAAI,CAAC,KAAK;AACN,UAAM,IAAI;AAAA,MACN;AAAA,IAEJ;AAAA,EACJ;AACA,MAAI;AACJ,MAAI,QAAQ;AACZ,MAAI,SAAS;AAEb,WAAS,UAAU;AACf,QAAI,OAAQ;AAEZ,aAAS,IAAI,UAAU,GAAG;AAE1B,WAAO,YAAY,CAAC,MAAM;AACtB,YAAM,MAAM,KAAK,MAAM,EAAE,IAAI;AAE7B,UAAI,IAAI,SAAS,UAAU,MAAM;AAC7B,eAAO,KAAK,KAAK,UAAU,EAAE,MAAM,UAAU,KAAK,CAAC,CAAC;AACpD;AAAA,MACJ;AAEA,eAAS,IAAI,IAAI,IAAI,IAAI,MAAM,GAAG;AAAA,IACtC;AAEA,WAAO,UAAU,MAAM;AACnB,UAAI,OAAQ;AACZ,iBAAW,SAAS,KAAK,IAAI,MAAO,KAAK,SAAS,GAAK,CAAC;AAAA,IAC5D;AAEA,WAAO,UAAU,MAAM,OAAO,MAAM;AAAA,EACxC;AAEA,UAAQ;AAER,SAAO;AAAA,IACH,QAAQ;AACJ,eAAS;AACT,cAAQ,MAAM;AAAA,IAClB;AAAA,EACJ;AACJ;;;AZlBO,IAAM,SAAS;AAMf,IAAM,SAAS;AAKf,IAAM,eAAe;AAKrB,IAAM,aAAa;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACH;AAaA,IAAM,OA4BF;AAAA;AAAA,EAED,QAAQ;AAAA;AAAA,EAGR;AAAA,EACA,KAAK,WAAG;AAAA,EACR,IAAI,WAAG;AAAA;AAAA,EAGP;AAAA,EACA;AACH;AAEA,IAAO,gBAAQ;","names":["org_default","org_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client/index.ts","../src/api/v1/org/org.ts","../src/shared/index.ts","../src/api/v1/org/tasks.ts","../src/api/v1/org/comments.ts","../src/api/v1/org/labels.ts","../src/api/v1/org/categories.ts","../src/api/v1/org/index.ts","../src/api/v1/me/index.ts","../src/api/v1/index.ts","../src/events/index.ts","../src/events/types.ts"],"sourcesContent":["/* ────────────────────────────\r\n API versions\r\n──────────────────────────── */\r\nimport v1 from \"./api/v1\";\r\n\r\n/* ────────────────────────────\r\n Realtime\r\n──────────────────────────── */\r\nimport { ws } from \"./ws\";\r\nimport { WS_EVENTS } from \"./ws/types\";\r\nimport { sse } from \"./events\";\r\nimport { ServerEvent_EVENTS } from \"./events/types\";\r\n\r\n/* ────────────────────────────\r\n Client config\r\n──────────────────────────── */\r\nimport {\r\n setToken,\r\n setHeaders,\r\n setBaseUrl,\r\n resetClient,\r\n setHooks,\r\n} from \"./client\";\r\n\r\n/* ────────────────────────────\r\n Named exports (power users)\r\n──────────────────────────── */\r\n\r\n/**\r\n * Sayr Public API — Version 1.\r\n *\r\n * @since v1.0.0\r\n */\r\nexport const SayrV1 = v1;\r\n\r\n\r\n/**\r\n * Create a WebSocket connection for public real‑time updates.\r\n */\r\nexport const SayrSSE = sse;\r\n\r\n/**\r\n * Typed WebSocket event constants.\r\n */\r\nexport const SayrServerEvents = ServerEvent_EVENTS;\r\n\r\n/**\r\n * Global client configuration helpers.\r\n */\r\nexport const SayrClient = {\r\n setToken,\r\n setHeaders,\r\n setBaseUrl,\r\n resetClient,\r\n setHooks,\r\n};\r\n\r\n/* ────────────────────────────\r\n Default facade\r\n──────────────────────────── */\r\n\r\n/**\r\n * Sayr Public SDK.\r\n *\r\n * Read‑only access to public Sayr data via REST and WebSockets.\r\n *\r\n * @since v1.0.0\r\n */\r\nconst Sayr: {\r\n /**\r\n * Client configuration helpers.\r\n */\r\n client: typeof SayrClient;\r\n\r\n /**\r\n * Versioned API namespaces.\r\n */\r\n v1: typeof v1;\r\n\r\n /**\r\n * Alias for the current API version (`v1`).\r\n *\r\n * @since v1.0.0\r\n */\r\n org: typeof v1.org;\r\n me: typeof v1.me;\r\n\r\n /**\r\n * WebSocket helper for real‑time updates.\r\n */\r\n sse: typeof sse;\r\n\r\n /**\r\n * WebSocket event constants.\r\n */\r\n EVENTS: typeof ServerEvent_EVENTS;\r\n} = {\r\n // client configuration\r\n client: SayrClient,\r\n\r\n // APIs\r\n v1,\r\n org: v1.org,\r\n me: v1.me,\r\n\r\n // realtime\r\n sse,\r\n EVENTS: ServerEvent_EVENTS\r\n};\r\n\r\nexport default Sayr;\r\n\r\n/* ────────────────────────────\r\n Types & shared helpers\r\n──────────────────────────── */\r\nexport * from \"./types\";\r\nexport * from \"./shared\";\r\n// export * from \"./ws/types\";\r\nexport * from \"./events/types\";","import { ApiError } from \"../types\";\r\n\r\n/* ────────────────────────────\r\n Types\r\n──────────────────────────── */\r\nexport type RequestOptions = {\r\n method?: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\r\n headers?: Record<string, string>;\r\n body?: Record<string, string>;\r\n signal?: AbortSignal;\r\n};\r\n\r\nexport interface ApiResult<T> {\r\n success: boolean;\r\n data: T | null;\r\n error: string | null;\r\n}\r\n\r\ntype Hooks = {\r\n onRequest?: (url: string, opts: RequestOptions) => void;\r\n onResponse?: (res: Response) => void;\r\n onError?: (error: ApiError | unknown) => void;\r\n};\r\n\r\ntype ClientConfig = {\r\n token?: string;\r\n headers?: Record<string, string>;\r\n baseUrl: string;\r\n};\r\n\r\n/* ────────────────────────────\r\n Internal state\r\n──────────────────────────── */\r\nconst DEFAULT_API = \"https://api.sayr.io\";\r\n\r\nconst config: ClientConfig = {\r\n baseUrl: DEFAULT_API\r\n};\r\n\r\nconst hooks: Hooks = {};\r\n\r\n/* ────────────────────────────\r\n Public config API\r\n──────────────────────────── */\r\nexport function setToken(token?: string) {\r\n config.token = token;\r\n}\r\n\r\nexport function getToken() {\r\n return config.token;\r\n}\r\n\r\nexport function setHeaders(headers?: Record<string, string>) {\r\n config.headers = {\r\n ...config.headers,\r\n ...headers\r\n };\r\n}\r\n\r\nexport function setBaseUrl(url: string) {\r\n config.baseUrl = url.replace(/\\/$/, \"\");\r\n}\r\n\r\nexport function setHooks(h: Hooks) {\r\n Object.assign(hooks, h);\r\n}\r\nexport function resetClient() {\r\n config.token = undefined;\r\n config.headers = undefined;\r\n config.baseUrl = DEFAULT_API;\r\n}\r\n\r\n/* ────────────────────────────\r\n Request helper\r\n──────────────────────────── */\r\nexport async function request<T>(\r\n path: string,\r\n opts: RequestOptions = {}\r\n): Promise<T> {\r\n\r\n let url: string;\r\n try {\r\n url = path.startsWith(\"http\")\r\n ? path\r\n : `${config.baseUrl}${path}`;\r\n } catch (err) {\r\n throw err;\r\n }\r\n\r\n try {\r\n hooks.onRequest?.(url, opts);\r\n } catch (err) {\r\n throw err;\r\n }\r\n\r\n let res: Response;\r\n\r\n try {\r\n const method = opts.method ?? \"GET\";\r\n\r\n\r\n // 🔴 Guard: GET must not have body\r\n if (method === \"GET\" && opts.body !== undefined) {\r\n throw new Error(\"GET request cannot have a body\");\r\n }\r\n\r\n res = await fetch(url, {\r\n method,\r\n headers: {\r\n ...(config.token\r\n ? { Authorization: `Bearer ${config.token}` }\r\n : {}),\r\n ...(opts.body && method !== \"GET\"\r\n ? { \"Content-Type\": \"application/json\" }\r\n : {}),\r\n ...config.headers,\r\n ...opts.headers\r\n },\r\n body:\r\n opts.body && method !== \"GET\"\r\n ? JSON.stringify(opts.body)\r\n : undefined,\r\n signal: opts.signal\r\n });\r\n } catch (err) {\r\n const error: ApiError = {\r\n success: false,\r\n error: \"NETWORK_ERROR\",\r\n message: \"Failed to reach Sayr API\",\r\n // 👇 keep raw error so we can see it\r\n // @ts-ignore\r\n raw: err\r\n };\r\n\r\n hooks.onError?.(error);\r\n throw error;\r\n }\r\n\r\n try {\r\n hooks.onResponse?.(res);\r\n } catch (err) {\r\n throw err;\r\n }\r\n\r\n let json: any;\r\n try {\r\n json = await res.json();\r\n } catch (err) {\r\n const error: ApiError = {\r\n success: false,\r\n error: \"INVALID_RESPONSE\",\r\n message: \"Server returned invalid JSON\",\r\n status: res.status\r\n };\r\n hooks.onError?.(error);\r\n throw error;\r\n }\r\n if (!res.ok || !json.success) {\r\n const error: ApiError = {\r\n ...json,\r\n success: false,\r\n status: res.status\r\n };\r\n hooks.onError?.(error);\r\n throw error;\r\n }\r\n return json;\r\n}","import { Organization, ApiSuccess } from \"../../../types\";\r\nimport { ApiResult, request, type RequestOptions } from \"../../../client\";\r\n\r\n/**\r\n * Organization core operations.\r\n */\r\nexport default {\r\n /**\r\n * Fetches a public organization by slug.\r\n *\r\n * @since v1.0.0\r\n */\r\n async get(\r\n slug: string,\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Organization>> {\r\n try {\r\n const r = await request<ApiSuccess<Organization>>(\r\n `/v1/organization/${slug}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch organization\",\r\n };\r\n }\r\n },\r\n};","/* =======================\r\n * Shared params & helpers\r\n * ======================= */\r\n\r\nexport type Order = \"asc\" | \"desc\";\r\n\r\nexport interface PaginationParams {\r\n page?: number;\r\n limit?: number;\r\n}\r\n\r\nexport interface OrderedPaginationParams extends PaginationParams {\r\n order?: Order;\r\n}\r\n\r\nexport function buildPaginationParams(\r\n params?: OrderedPaginationParams\r\n): URLSearchParams {\r\n return new URLSearchParams({\r\n order: params?.order ?? \"desc\",\r\n limit: String(params?.limit ?? 5),\r\n page: String(params?.page ?? 1)\r\n });\r\n}","import {\r\n Task,\r\n Pagination,\r\n ApiSuccess,\r\n} from \"../../../types\";\r\nimport {\r\n ApiResult,\r\n request,\r\n type RequestOptions,\r\n} from \"../../../client\";\r\nimport {\r\n type OrderedPaginationParams,\r\n buildPaginationParams,\r\n} from \"../../../shared\";\r\n\r\n/**\r\n * Organization tasks.\r\n */\r\nexport default {\r\n /**\r\n * Lists public tasks for an organization.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n params?: OrderedPaginationParams,\r\n opts?: RequestOptions,\r\n ): Promise<\r\n ApiResult<{\r\n items: Task[];\r\n pagination: Pagination;\r\n }>\r\n > {\r\n try {\r\n const q = buildPaginationParams(params);\r\n\r\n const r = await request<\r\n ApiSuccess<Task[]> & { pagination: Pagination }\r\n >(\r\n `/v1/organization/${slug}/tasks?${q}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: {\r\n items: r.data,\r\n pagination: r.pagination,\r\n },\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch tasks\",\r\n };\r\n }\r\n },\r\n\r\n /**\r\n * Fetches a single public task by short ID.\r\n *\r\n * @since v1.0.0\r\n */\r\n async get(\r\n slug: string,\r\n shortId: number,\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Task>> {\r\n try {\r\n const r = await request<ApiSuccess<Task>>(\r\n `/v1/organization/${slug}/tasks/${shortId}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch task\",\r\n };\r\n }\r\n },\r\n};","import {\r\n Comment,\r\n Pagination,\r\n ApiSuccess,\r\n} from \"../../../types\";\r\nimport {\r\n ApiResult,\r\n request,\r\n type RequestOptions,\r\n} from \"../../../client\";\r\nimport {\r\n type OrderedPaginationParams,\r\n buildPaginationParams,\r\n} from \"../../../shared\";\r\n\r\n/**\r\n * Organization task comments.\r\n */\r\nexport default {\r\n /**\r\n * Lists public comments for a task.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n shortId: number,\r\n params?: OrderedPaginationParams,\r\n opts?: RequestOptions,\r\n ): Promise<\r\n ApiResult<{\r\n items: Comment[];\r\n pagination: Pagination;\r\n }>\r\n > {\r\n try {\r\n const q = buildPaginationParams(params);\r\n\r\n const r = await request<\r\n ApiSuccess<Comment[]> & { pagination: Pagination }\r\n >(\r\n `/v1/organization/${slug}/tasks/${shortId}/comments?${q}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: {\r\n items: r.data,\r\n pagination: r.pagination,\r\n },\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch task comments\",\r\n };\r\n }\r\n },\r\n};","import { Label, ApiSuccess } from \"../../../types\";\r\nimport { ApiResult, request, type RequestOptions } from \"../../../client\";\r\n\r\n/**\r\n * Organization labels.\r\n */\r\nexport default {\r\n /**\r\n * Lists public labels for an organization.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Label[]>> {\r\n try {\r\n const r = await request<ApiSuccess<Label[]>>(\r\n `/v1/organization/${slug}/labels`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch labels\",\r\n };\r\n }\r\n },\r\n};","import {\r\n Category,\r\n ApiSuccess,\r\n} from \"../../../types\";\r\nimport {\r\n ApiResult,\r\n request,\r\n type RequestOptions,\r\n} from \"../../../client\";\r\nimport { type Order } from \"../../../shared\";\r\n\r\n/**\r\n * Organization categories.\r\n */\r\nexport default {\r\n /**\r\n * Lists public categories for an organization.\r\n *\r\n * @since v1.0.0\r\n */\r\n async list(\r\n slug: string,\r\n order: Order = \"desc\",\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Category[]>> {\r\n try {\r\n const r = await request<ApiSuccess<Category[]>>(\r\n `/v1/organization/${slug}/categories?order=${order}`,\r\n opts,\r\n );\r\n\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error:\r\n err?.message ??\r\n \"Failed to fetch categories\",\r\n };\r\n }\r\n },\r\n};","import org from \"./org\";\r\nimport tasks from \"./tasks\";\r\nimport comments from \"./comments\";\r\nimport labels from \"./labels\";\r\nimport categories from \"./categories\";\r\n\r\n/**\r\n * Public Sayr Organization API — Version 1.\r\n *\r\n * @since v1.0.0\r\n */\r\nconst OrgAPI = {\r\n ...org,\r\n tasks,\r\n comments,\r\n labels,\r\n categories\r\n};\r\n\r\nexport default OrgAPI;","import { ApiResult, request, type RequestOptions } from \"../../../client\";\r\nimport { ApiSuccess, Organization, TaskPriority, TaskStatus } from \"../../../types\";\r\n\r\nexport interface TaskCreated {\r\n id: string;\r\n shortId: number;\r\n title: string;\r\n orgSlug: string;\r\n publicPortalUrl: string;\r\n}\r\n\r\nexport interface CreateTaskInput {\r\n title: string;\r\n description?: string;\r\n status?: TaskStatus;\r\n priority?: TaskPriority;\r\n category?: string;\r\n orgId: string;\r\n integration?: {\r\n id: string;\r\n name: string;\r\n platform: string;\r\n };\r\n}\r\n\r\nexport interface Me {\r\n id: string;\r\n name: string | null;\r\n email: string | null;\r\n image: string | null;\r\n createdAt: string;\r\n}\r\n\r\n/**\r\n * Authenticated user API — Version 1.\r\n *\r\n * @since v1.0.0\r\n */\r\nexport default {\r\n async get(opts?: RequestOptions): Promise<ApiResult<Me>> {\r\n try {\r\n const r = await request<ApiSuccess<Me>>(\"/v1/me\", opts);\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch user\",\r\n };\r\n }\r\n },\r\n\r\n async organizations(\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<Organization[]>> {\r\n try {\r\n const r = await request<ApiSuccess<Organization[]>>(\r\n \"/v1/me/organizations\",\r\n opts,\r\n );\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to fetch organizations\",\r\n };\r\n }\r\n },\r\n\r\n async createTask(\r\n body: CreateTaskInput,\r\n opts?: RequestOptions,\r\n ): Promise<ApiResult<TaskCreated>> {\r\n try {\r\n const r = await request<ApiSuccess<TaskCreated>>(\"/v1/me/task\", {\r\n ...opts,\r\n method: \"POST\",\r\n body: body as any,\r\n });\r\n return {\r\n success: true,\r\n data: r.data,\r\n error: null,\r\n };\r\n } catch (err: any) {\r\n return {\r\n success: false,\r\n data: null,\r\n error: err?.message ?? \"Failed to create task\",\r\n };\r\n }\r\n },\r\n};","import org from \"./org\";\r\nimport me from \"./me\";\r\nexport const v1 = {\r\n org,\r\n me\r\n};\r\n\r\nexport default v1;","import { type ServerEventMessage, type ServerEventMessageType } from \"./types\";\r\n\r\ntype Handlers = Partial<\r\n Record<ServerEventMessageType, (data: any, msg: ServerEventMessage) => void>\r\n>;\r\n\r\nexport function sse(url: string, handlers: Handlers = {}) {\r\n if (!url) {\r\n throw new Error(\r\n \"[Sayr.sse] SSE URL is required. Did you forget to pass org.eventsUrl?\"\r\n );\r\n }\r\n\r\n let source: EventSource | null = null;\r\n let closed = false;\r\n\r\n function connect() {\r\n if (closed) return;\r\n\r\n source = new EventSource(url);\r\n\r\n source.onmessage = (e) => {\r\n const msg = JSON.parse(e.data) as ServerEventMessage;\r\n handlers[msg.type]?.(msg.data, msg);\r\n };\r\n\r\n source.onerror = () => {\r\n if (closed) return;\r\n source?.close();\r\n setTimeout(connect, 2000); // simple retry\r\n };\r\n }\r\n\r\n connect();\r\n\r\n return {\r\n close() {\r\n closed = true;\r\n source?.close();\r\n }\r\n };\r\n}","export type ServerEventMessageType =\r\n | \"CONNECTION_STATUS\"\r\n | \"ERROR\"\r\n | \"UPDATE_ORG\"\r\n | \"CREATE_TASK\"\r\n | \"UPDATE_TASK\"\r\n | \"UPDATE_TASK_COMMENTS\"\r\n | \"UPDATE_TASK_VOTE\"\r\n | \"UPDATE_LABELS\"\r\n | \"UPDATE_VIEWS\"\r\n | \"UPDATE_CATEGORIES\"\r\n | \"UPDATE_ISSUE_TEMPLATES\";\r\n\r\n/**\r\n * String enum replacement for WS event names.\r\n * Use this instead of raw strings.\r\n */\r\nexport const ServerEvent_EVENTS: Record<ServerEventMessageType, ServerEventMessageType> = {\r\n CONNECTION_STATUS: \"CONNECTION_STATUS\",\r\n ERROR: \"ERROR\",\r\n UPDATE_ORG: \"UPDATE_ORG\",\r\n CREATE_TASK: \"CREATE_TASK\",\r\n UPDATE_TASK: \"UPDATE_TASK\",\r\n UPDATE_TASK_COMMENTS: \"UPDATE_TASK_COMMENTS\",\r\n UPDATE_TASK_VOTE: \"UPDATE_TASK_VOTE\",\r\n UPDATE_LABELS: \"UPDATE_LABELS\",\r\n UPDATE_VIEWS: \"UPDATE_VIEWS\",\r\n UPDATE_CATEGORIES: \"UPDATE_CATEGORIES\",\r\n UPDATE_ISSUE_TEMPLATES: \"UPDATE_ISSUE_TEMPLATES\",\r\n};\r\n\r\nexport interface ServerEventMessage<T = unknown> {\r\n type: ServerEventMessageType;\r\n scope: \"PUBLIC\";\r\n data: T;\r\n meta?: { ts: number };\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiCA,IAAM,cAAc;AAEpB,IAAM,SAAuB;AAAA,EACzB,SAAS;AACb;AAEA,IAAM,QAAe,CAAC;AAKf,SAAS,SAAS,OAAgB;AACrC,SAAO,QAAQ;AACnB;AAMO,SAAS,WAAW,SAAkC;AACzD,SAAO,UAAU;AAAA,IACb,GAAG,OAAO;AAAA,IACV,GAAG;AAAA,EACP;AACJ;AAEO,SAAS,WAAW,KAAa;AACpC,SAAO,UAAU,IAAI,QAAQ,OAAO,EAAE;AAC1C;AAEO,SAAS,SAAS,GAAU;AAC/B,SAAO,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