talkie-sync 0.1.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.
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/package.json +27 -0
- package/src/client.ts +126 -0
- package/src/index.ts +15 -0
- package/src/types.ts +66 -0
- package/tsconfig.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pretty Neat Sync
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Talkie Sync Client
|
|
2
|
+
|
|
3
|
+
TypeScript client library for Talkie Sync API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install talkie-sync
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { TalkieClient } from "talkie-sync";
|
|
15
|
+
|
|
16
|
+
const client = new TalkieClient({
|
|
17
|
+
baseUrl: "https://your-server.com",
|
|
18
|
+
apiKey: "your-api-key",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Create a pair (initiator)
|
|
22
|
+
const { words, session_id, channel_id } = await client.createPair();
|
|
23
|
+
|
|
24
|
+
// Claim a pair (matcher)
|
|
25
|
+
const { session_id, channel_id } = await client.claimPair("aardvark absurd accrue");
|
|
26
|
+
|
|
27
|
+
// Send a message
|
|
28
|
+
await client.pushMessage(channel_id, "hello");
|
|
29
|
+
|
|
30
|
+
// Poll for messages
|
|
31
|
+
const { messages, next_seq } = await client.pollMessages(channel_id, 0, 25000);
|
|
32
|
+
|
|
33
|
+
// Or list messages (no polling)
|
|
34
|
+
const { messages } = await client.listMessages(channel_id);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
- `createPair(channelId?, sessionId?)` — Create a new pair, returns words
|
|
40
|
+
- `claimPair(words)` — Claim a pair with words
|
|
41
|
+
- `pushMessage(channelId, payload)` — Send a message
|
|
42
|
+
- `pollMessages(channelId, after?, timeout?)` — Long-poll for messages
|
|
43
|
+
- `listMessages(channelId, after?)` — List messages without polling
|
|
44
|
+
- `getUser()` — Get current user info
|
|
45
|
+
- `listProjects()` — List projects
|
|
46
|
+
- `getConfig()` — Get tier configuration
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "talkie-sync",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "tsc --watch",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"typescript": "^5.8.0",
|
|
22
|
+
"vitest": "^3.1.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"typescript": ">=5.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CreatePairResponse,
|
|
3
|
+
ClaimPairRequest,
|
|
4
|
+
ClaimPairResponse,
|
|
5
|
+
PushMessageRequest,
|
|
6
|
+
MessageListResponse,
|
|
7
|
+
UserMe,
|
|
8
|
+
ConfigResponse,
|
|
9
|
+
Project,
|
|
10
|
+
ApiError,
|
|
11
|
+
} from "./types";
|
|
12
|
+
|
|
13
|
+
export interface TalkieClientOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
apiKey: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class TalkieClient {
|
|
19
|
+
private baseUrl: string;
|
|
20
|
+
private apiKey: string;
|
|
21
|
+
|
|
22
|
+
constructor(options: TalkieClientOptions) {
|
|
23
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
24
|
+
this.apiKey = options.apiKey;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private async request<T>(
|
|
28
|
+
method: string,
|
|
29
|
+
path: string,
|
|
30
|
+
body?: unknown
|
|
31
|
+
): Promise<T> {
|
|
32
|
+
const headers: Record<string, string> = {
|
|
33
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const init: RequestInit = {
|
|
38
|
+
method,
|
|
39
|
+
headers,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (body) {
|
|
43
|
+
init.body = JSON.stringify(body);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const response = await fetch(`${this.baseUrl}${path}`, init);
|
|
47
|
+
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const error: ApiError = await response.json().catch(() => ({
|
|
50
|
+
error: "Unknown error",
|
|
51
|
+
}));
|
|
52
|
+
throw new Error(`${error.error}: ${error.message || response.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return response.json();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async createPair(channelId?: string, sessionId?: string): Promise<CreatePairResponse> {
|
|
59
|
+
const query = new URLSearchParams();
|
|
60
|
+
if (channelId) query.set("channel_id", channelId);
|
|
61
|
+
if (sessionId) query.set("session_id", sessionId);
|
|
62
|
+
const qs = query.toString();
|
|
63
|
+
return this.request("POST", `/api/pair${qs ? `?${qs}` : ""}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async claimPair(words: string): Promise<ClaimPairResponse> {
|
|
67
|
+
return this.request<ClaimPairResponse>("POST", "/api/pair", { words } as ClaimPairRequest);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async pushMessage(channelId: string, payload: string): Promise<{ id: string }> {
|
|
71
|
+
const cleanChannelId = channelId.split(":")[0];
|
|
72
|
+
return this.request("POST", `/api/pair/${cleanChannelId}/messages`, { payload } as PushMessageRequest);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async pollMessages(channelId: string, after = 0, timeout?: number): Promise<MessageListResponse> {
|
|
76
|
+
const cleanChannelId = channelId.split(":")[0];
|
|
77
|
+
const params = new URLSearchParams({ after: String(after) });
|
|
78
|
+
if (timeout) params.set("timeout", String(timeout));
|
|
79
|
+
return this.request("GET", `/api/pair/${cleanChannelId}/messages?${params}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async listMessages(channelId: string, after = 0): Promise<MessageListResponse> {
|
|
83
|
+
const cleanChannelId = channelId.split(":")[0];
|
|
84
|
+
return this.request("GET", `/api/pair/${cleanChannelId}/messages?after=${after}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async getUser(): Promise<UserMe> {
|
|
88
|
+
return this.request("GET", "/api/user/me");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async listProjects(): Promise<{ projects: Project[] }> {
|
|
92
|
+
return this.request("GET", "/api/projects");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async getProject(id: string): Promise<Project> {
|
|
96
|
+
return this.request("GET", `/api/projects/${id}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async createProject(name: string): Promise<Project> {
|
|
100
|
+
return this.request("POST", "/api/projects", { name });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async deleteProject(id: string): Promise<{ success: boolean }> {
|
|
104
|
+
return this.request("DELETE", `/api/projects/${id}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async getConfig(): Promise<ConfigResponse> {
|
|
108
|
+
return this.request("GET", "/api/config/tiers");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async createCheckoutUrl(priceId: string, successUrl: string, cancelUrl: string): Promise<{ url: string }> {
|
|
112
|
+
return this.request("POST", "/api/billing/checkout", {
|
|
113
|
+
price_id: priceId,
|
|
114
|
+
success_url: successUrl,
|
|
115
|
+
cancel_url: cancelUrl,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async createPortalUrl(): Promise<{ url: string }> {
|
|
120
|
+
return this.request("POST", "/api/billing/portal");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async upgradeSubscription(priceId: string): Promise<{ success: boolean }> {
|
|
124
|
+
return this.request("POST", "/api/billing/upgrade", { price_id: priceId });
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { TalkieClient } from "./client";
|
|
2
|
+
export type { TalkieClientOptions } from "./client";
|
|
3
|
+
export type {
|
|
4
|
+
CreatePairResponse,
|
|
5
|
+
ClaimPairRequest,
|
|
6
|
+
ClaimPairResponse,
|
|
7
|
+
Message,
|
|
8
|
+
PushMessageRequest,
|
|
9
|
+
MessageListResponse,
|
|
10
|
+
Project,
|
|
11
|
+
UserMe,
|
|
12
|
+
TierConfig,
|
|
13
|
+
ConfigResponse,
|
|
14
|
+
ApiError,
|
|
15
|
+
} from "./types";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface CreatePairResponse {
|
|
2
|
+
words: string;
|
|
3
|
+
session_id: string;
|
|
4
|
+
channel_id: string;
|
|
5
|
+
expires_in: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ClaimPairRequest {
|
|
9
|
+
words: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ClaimPairResponse {
|
|
13
|
+
session_id: string;
|
|
14
|
+
channel_id: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Message {
|
|
18
|
+
id: string;
|
|
19
|
+
seq: number;
|
|
20
|
+
payload: string;
|
|
21
|
+
created_at: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PushMessageRequest {
|
|
25
|
+
payload: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface MessageListResponse {
|
|
29
|
+
messages: Message[];
|
|
30
|
+
next_seq: number | null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Project {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
tier: "free" | "creator" | "pro";
|
|
37
|
+
created_at: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface UserMe {
|
|
41
|
+
id: string;
|
|
42
|
+
email: string;
|
|
43
|
+
tier: string;
|
|
44
|
+
projects: Project[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TierConfig {
|
|
48
|
+
label: string;
|
|
49
|
+
maxProjects: number | null;
|
|
50
|
+
maxChannels: number | null;
|
|
51
|
+
maxPairsPerDay: number | null;
|
|
52
|
+
pairsPerMonth: number | null;
|
|
53
|
+
pairTTLSec: number | null;
|
|
54
|
+
creemProductId: string | null;
|
|
55
|
+
maxMessagesPerChannel: number | null;
|
|
56
|
+
messagesPerSecond: number | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ConfigResponse {
|
|
60
|
+
tiers: Record<string, TierConfig>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ApiError {
|
|
64
|
+
error: string;
|
|
65
|
+
message?: string;
|
|
66
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"rootDir": "./src",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"isolatedModules": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"noUnusedParameters": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true
|
|
21
|
+
},
|
|
22
|
+
"include": ["src/**/*"],
|
|
23
|
+
"exclude": ["node_modules", "dist"]
|
|
24
|
+
}
|