@tiun/types 0.11.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 +91 -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
@@ -145,10 +145,24 @@ export interface UserInfo {
145
145
  email: string;
146
146
  /** Whether the user has opted in to the newsletter. */
147
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
+ */
148
153
  productAccess: string[];
149
154
  }
150
155
 
151
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
+ */
152
166
  event: 'init' | 'login' | 'checkout' | 'logout' | 'update';
153
167
  isAuthenticated: boolean;
154
168
  user: UserInfo | null;
@@ -169,7 +183,7 @@ export interface GetUserResponse {
169
183
 
170
184
  export interface CheckoutOptions {
171
185
  /**
172
- * Specific product ID to checkout (optional, for future use)
186
+ * The product to check out, from your tiun dashboard.
173
187
  */
174
188
  productId?: string;
175
189
  /**
@@ -180,6 +194,53 @@ export interface CheckoutOptions {
180
194
  referenceId?: string;
181
195
  }
182
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;
242
+ }
243
+
183
244
  // =============================================================================
184
245
  // Content Options
185
246
  // =============================================================================
@@ -259,6 +320,32 @@ export interface TiunSDK {
259
320
  */
260
321
  getUserVerificationToken(): Promise<string | null>;
261
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
+
262
349
  /**
263
350
  * Subscribe to an event. Returns unsubscribe function.
264
351
  */
@@ -300,7 +387,9 @@ export interface TiunSDK {
300
387
  once(event: 'logout', callback: () => void): () => void;
301
388
 
302
389
  /**
303
- * 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.
304
393
  */
305
394
  destroy(): void;
306
395
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiun/types",
3
- "version": "0.11.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": [