@tiun/types 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/README.md +58 -0
- package/index.d.ts +243 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @tiun/types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for the Tiun SDK.
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
| Installation Method | Types Included? | Need This Package? |
|
|
8
|
+
| ------------------------ | --------------- | ------------------ |
|
|
9
|
+
| `npm install @tiun/sdk` | ✅ Yes | No |
|
|
10
|
+
| `<script>` tags (legacy) | ❌ No | **Yes** |
|
|
11
|
+
|
|
12
|
+
**NPM users:** Skip this package - types are bundled with `@tiun/sdk`.
|
|
13
|
+
|
|
14
|
+
**Script tag users:** Install this for TypeScript support.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @tiun/types --save-dev
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
Add to `tsconfig.json`:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"compilerOptions": {
|
|
29
|
+
"types": ["@tiun/types"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or add a reference directive to any `.d.ts` file:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
/// <reference types="@tiun/types" />
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Restart your TypeScript server after setup.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
The global `Tiun` object is now typed:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
Tiun.init();
|
|
48
|
+
Tiun.on('paywallShow', ({ isConnected }) => {});
|
|
49
|
+
Tiun.checkout({ productId: 'prod_123' });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Auto-generated
|
|
53
|
+
|
|
54
|
+
This package is auto-generated from `src/sdk/types.ts`.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiun SDK Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Install: npm install @tiun/types --save-dev
|
|
5
|
+
*
|
|
6
|
+
* These types are for the global `Tiun` object exposed by the Tiun script.
|
|
7
|
+
* Load the script in your HTML, then use Tiun.* with full TypeScript support.
|
|
8
|
+
*
|
|
9
|
+
* @generated from src/sdk/types.ts - Do not edit directly.
|
|
10
|
+
* Run `npm run generate:types` to regenerate.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Core Types
|
|
15
|
+
// =============================================================================
|
|
16
|
+
|
|
17
|
+
export type ContentType = 'active' | 'inactive' | 'paused';
|
|
18
|
+
export type MediaType = 'text' | 'audio' | 'video';
|
|
19
|
+
export type TiunEventType = 'ready' | 'paywallShow' | 'paywallHide' | 'error';
|
|
20
|
+
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Configuration
|
|
23
|
+
// =============================================================================
|
|
24
|
+
|
|
25
|
+
export interface TiunConfig {
|
|
26
|
+
/**
|
|
27
|
+
* Your unique Tiun snippet ID.
|
|
28
|
+
* Required for NPM package usage.
|
|
29
|
+
* For legacy script tag usage, this is provided via the backend.
|
|
30
|
+
*/
|
|
31
|
+
snippetId?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Language for the snippet UI.
|
|
35
|
+
* @default 'en'
|
|
36
|
+
*/
|
|
37
|
+
language?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* UI tone/style.
|
|
41
|
+
* - 'formal': More professional tone
|
|
42
|
+
* - 'informal': More casual/friendly tone
|
|
43
|
+
* @default 'formal'
|
|
44
|
+
*/
|
|
45
|
+
tone?: 'formal' | 'informal';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Corner style for UI elements.
|
|
49
|
+
* - 'rounded': Rounded corners
|
|
50
|
+
* - 'pointed': Sharp corners
|
|
51
|
+
* @default 'rounded'
|
|
52
|
+
*/
|
|
53
|
+
corners?: 'rounded' | 'pointed';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Enable WebView mode (for mobile app WebViews).
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
webView?: boolean;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* API base URL. Only needed for custom deployments.
|
|
63
|
+
* @default 'https://api.tiun.live/live_api'
|
|
64
|
+
*/
|
|
65
|
+
baseUrl?: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Enable debug logging to console.
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
debug?: boolean;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Called when the snippet has finished initializing and is ready
|
|
75
|
+
*/
|
|
76
|
+
onReady?: () => void;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Called when paywall should be shown to the user
|
|
80
|
+
*/
|
|
81
|
+
onPaywallShow?: (data: PaywallShowEvent) => void;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Called when paywall should be hidden (user has access)
|
|
85
|
+
*/
|
|
86
|
+
onPaywallHide?: (data: PaywallHideEvent) => void;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Called on any error
|
|
90
|
+
*/
|
|
91
|
+
onError?: (error: TiunError) => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// =============================================================================
|
|
95
|
+
// Event Payloads
|
|
96
|
+
// =============================================================================
|
|
97
|
+
|
|
98
|
+
export interface PaywallShowEvent {
|
|
99
|
+
/**
|
|
100
|
+
* Whether user has connected a payment method
|
|
101
|
+
*/
|
|
102
|
+
isConnected: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface PaywallHideEvent {
|
|
106
|
+
/**
|
|
107
|
+
* Active session ID
|
|
108
|
+
*/
|
|
109
|
+
sessionId: string;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Whether user is connected
|
|
113
|
+
*/
|
|
114
|
+
isConnected: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface TiunError {
|
|
118
|
+
code: string;
|
|
119
|
+
message: string;
|
|
120
|
+
details?: unknown;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// =============================================================================
|
|
124
|
+
// Checkout Options
|
|
125
|
+
// =============================================================================
|
|
126
|
+
|
|
127
|
+
export interface CheckoutOptions {
|
|
128
|
+
/**
|
|
129
|
+
* Specific product ID to checkout (optional, for future use)
|
|
130
|
+
*/
|
|
131
|
+
productId?: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Custom metadata to attach to this checkout
|
|
135
|
+
*/
|
|
136
|
+
metadata?: Record<string, string>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// =============================================================================
|
|
140
|
+
// Content Options
|
|
141
|
+
// =============================================================================
|
|
142
|
+
|
|
143
|
+
export interface ContentOptions {
|
|
144
|
+
/**
|
|
145
|
+
* Type of content (affects session state)
|
|
146
|
+
*/
|
|
147
|
+
type: ContentType;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Unique identifier for this content/route
|
|
151
|
+
*/
|
|
152
|
+
contentId?: string;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Media type being consumed
|
|
156
|
+
* @default 'text'
|
|
157
|
+
*/
|
|
158
|
+
mediaType?: MediaType;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// =============================================================================
|
|
162
|
+
// SDK Interface (for global Tiun object)
|
|
163
|
+
// =============================================================================
|
|
164
|
+
|
|
165
|
+
export interface TiunSDK {
|
|
166
|
+
/**
|
|
167
|
+
* Initialize the SDK. Call once at app startup.
|
|
168
|
+
*
|
|
169
|
+
* For NPM package usage, snippetId is required:
|
|
170
|
+
* ```typescript
|
|
171
|
+
* Tiun.init({ snippetId: 'your-snippet-id' });
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* For legacy script tag usage (backend-served), no config needed:
|
|
175
|
+
* ```typescript
|
|
176
|
+
* Tiun.init();
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
init(config?: TiunConfig): TiunSDK;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Open the checkout flow.
|
|
183
|
+
*/
|
|
184
|
+
checkout(options?: CheckoutOptions): Promise<void>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Update the current content context.
|
|
188
|
+
*/
|
|
189
|
+
setContent(options: ContentOptions): Promise<void>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Subscribe to an event. Returns unsubscribe function.
|
|
193
|
+
*/
|
|
194
|
+
on(event: 'ready', callback: () => void): () => void;
|
|
195
|
+
on(event: 'paywallShow', callback: (data: PaywallShowEvent) => void): () => void;
|
|
196
|
+
on(event: 'paywallHide', callback: (data: PaywallHideEvent) => void): () => void;
|
|
197
|
+
on(event: 'error', callback: (error: TiunError) => void): () => void;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Subscribe to an event once (auto-unsubscribes after first fire).
|
|
201
|
+
*/
|
|
202
|
+
once(event: 'ready', callback: () => void): () => void;
|
|
203
|
+
once(event: 'paywallShow', callback: (data: PaywallShowEvent) => void): () => void;
|
|
204
|
+
once(event: 'paywallHide', callback: (data: PaywallHideEvent) => void): () => void;
|
|
205
|
+
once(event: 'error', callback: (error: TiunError) => void): () => void;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Destroy the SDK and cleanup all listeners.
|
|
209
|
+
*/
|
|
210
|
+
destroy(): void;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Wait for the SDK to be ready.
|
|
214
|
+
*/
|
|
215
|
+
waitForReady(): Promise<void>;
|
|
216
|
+
|
|
217
|
+
/** SDK version */
|
|
218
|
+
readonly version: string;
|
|
219
|
+
|
|
220
|
+
/** Whether init() has been called */
|
|
221
|
+
readonly isInitialized: boolean;
|
|
222
|
+
|
|
223
|
+
/** Whether the snippet is ready */
|
|
224
|
+
readonly isReady: boolean;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// =============================================================================
|
|
228
|
+
// Global Declaration
|
|
229
|
+
// =============================================================================
|
|
230
|
+
|
|
231
|
+
declare global {
|
|
232
|
+
/**
|
|
233
|
+
* Global Tiun SDK instance.
|
|
234
|
+
* Available after loading the Tiun script.
|
|
235
|
+
*/
|
|
236
|
+
const Tiun: TiunSDK;
|
|
237
|
+
|
|
238
|
+
interface Window {
|
|
239
|
+
Tiun: TiunSDK;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tiun/types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript type definitions for Tiun SDK (for script tag users)",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.d.ts",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"tiun",
|
|
12
|
+
"types",
|
|
13
|
+
"typescript",
|
|
14
|
+
"paywall",
|
|
15
|
+
"subscriptions"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/tiun-app/tiun-snippet"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
}
|
|
25
|
+
}
|