@tiun/types 0.10.0 → 0.12.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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/index.d.ts +99 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,6 +51,10 @@ tiun.on('logout', () => {});
51
51
  // Paywall
52
52
  tiun.on('paywallShow', ({ isConnected }) => {});
53
53
  tiun.checkout({ productId: 'prod_123' });
54
+
55
+ // Products
56
+ const products = await tiun.listProducts();
57
+ const { hasAccess } = await tiun.checkProductAccess('prod_123');
54
58
  ```
55
59
 
56
60
  ## Auto-generated
package/index.d.ts CHANGED
@@ -143,10 +143,26 @@ export interface TiunError {
143
143
  export interface UserInfo {
144
144
  userId: string;
145
145
  email: string;
146
+ /** Whether the user has opted in to the newsletter. */
147
+ hasNewsletterOptIn: boolean;
148
+ /**
149
+ * IDs of the products the user has access to. Product IDs only, so it can't
150
+ * tell which references of a repeatable product were bought — use
151
+ * `checkProductAccess(productId, { referenceId })` for those.
152
+ */
146
153
  productAccess: string[];
147
154
  }
148
155
 
149
156
  export interface UserChangeEvent {
157
+ /**
158
+ * What changed:
159
+ * - 'init': first state after the snippet loads
160
+ * - 'login' / 'logout': the user signed in or out
161
+ * - 'checkout': the user's access changed — gained or lost, for any product
162
+ * type, including a repeatable product bought with a new reference
163
+ * (which doesn't change `productAccess`). Not only after a checkout.
164
+ * - 'update': profile details changed (email, newsletter opt-in)
165
+ */
150
166
  event: 'init' | 'login' | 'checkout' | 'logout' | 'update';
151
167
  isAuthenticated: boolean;
152
168
  user: UserInfo | null;
@@ -167,9 +183,62 @@ export interface GetUserResponse {
167
183
 
168
184
  export interface CheckoutOptions {
169
185
  /**
170
- * Specific product ID to checkout (optional, for future use)
186
+ * The product to check out, from your tiun dashboard.
171
187
  */
172
188
  productId?: string;
189
+ /**
190
+ * Your own identifier for this purchase (e.g. an order or booking ID).
191
+ * Required for repeatable products, which can be bought more than once —
192
+ * each purchase is tied to its reference ID.
193
+ */
194
+ referenceId?: string;
195
+ }
196
+
197
+ // =============================================================================
198
+ // Products
199
+ // =============================================================================
200
+
201
+ export type ProductType = 'Subscription' | 'OneTime';
202
+
203
+ export interface Product {
204
+ productId: string;
205
+ name: string;
206
+ type: ProductType;
207
+ }
208
+
209
+ export interface ProductDetail extends Product {
210
+ /** Localized price summary, e.g. "€9.90 / month". */
211
+ pricingLine: string;
212
+ /** Optional localized explanation shown under the price. */
213
+ explanationLine?: string | null;
214
+ }
215
+
216
+ export interface ProductAccess {
217
+ productId: string;
218
+ /** Purchase reference for repeatable products; null for ordinary access. */
219
+ referenceId?: string | null;
220
+ type: ProductType;
221
+ /** ISO 8601 date-time. */
222
+ activatedAt: string;
223
+ /**
224
+ * When the access ends (ISO 8601 date-time). null while a subscription is
225
+ * active and renewing; set to the end of the paid period once it's cancelled.
226
+ */
227
+ expiresAt?: string | null;
228
+ }
229
+
230
+ export interface ProductAccessCheck {
231
+ hasAccess: boolean;
232
+ /** Access details when `hasAccess` is true; null otherwise. */
233
+ access?: ProductAccess | null;
234
+ }
235
+
236
+ export interface ProductAccessOptions {
237
+ /**
238
+ * Purchase reference for repeatable products (the `referenceId` passed to
239
+ * `checkout()`). Omit for ordinary product access.
240
+ */
241
+ referenceId?: string;
173
242
  }
174
243
 
175
244
  // =============================================================================
@@ -251,6 +320,32 @@ export interface TiunSDK {
251
320
  */
252
321
  getUserVerificationToken(): Promise<string | null>;
253
322
 
323
+ /**
324
+ * List the products available on this snippet.
325
+ */
326
+ listProducts(): Promise<Product[]>;
327
+
328
+ /**
329
+ * Get a product's details and localized pricing.
330
+ * Rejects with a TiunError if the product doesn't exist.
331
+ */
332
+ getProduct(productId: string): Promise<ProductDetail>;
333
+
334
+ /**
335
+ * List the current user's active product access, fetched from the backend.
336
+ * Resolves to [] when the user is not authenticated.
337
+ */
338
+ listProductAccess(): Promise<ProductAccess[]>;
339
+
340
+ /**
341
+ * Check whether the current user has access to a product.
342
+ * Resolves to { hasAccess: false, access: null } when the user is not authenticated.
343
+ */
344
+ checkProductAccess(
345
+ productId: string,
346
+ options?: ProductAccessOptions
347
+ ): Promise<ProductAccessCheck>;
348
+
254
349
  /**
255
350
  * Subscribe to an event. Returns unsubscribe function.
256
351
  */
@@ -292,7 +387,9 @@ export interface TiunSDK {
292
387
  once(event: 'logout', callback: () => void): () => void;
293
388
 
294
389
  /**
295
- * Destroy the SDK and cleanup all listeners.
390
+ * Remove the SDK's listeners and reset its state. The snippet stays on the
391
+ * page; calling init() again works, but `user` stays empty until the next
392
+ * login, logout or checkout.
296
393
  */
297
394
  destroy(): void;
298
395
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiun/types",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "TypeScript type definitions for tiun SDK (for script tag users)",
5
5
  "types": "./index.d.ts",
6
6
  "files": [