@sesamy/sesamy-js 1.35.10 → 1.36.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 +721 -2
- package/dist/sesamy-js.cjs +5 -5
- package/dist/sesamy-js.d.ts +16 -0
- package/dist/sesamy-js.iife.js +5 -5
- package/dist/sesamy-js.mjs +420 -384
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,7 @@ The following methods are available on the `sesamy` object:
|
|
|
67
67
|
- delete: deletes a feature flag
|
|
68
68
|
- fulfillments
|
|
69
69
|
- list: list the user's fulfillments for a SKU
|
|
70
|
+
- requestDelivery: requests delivery for a fulfillment by SKU and delivery method
|
|
70
71
|
- generateLink: creates a link to a Sesamy hosted service such as account, change-payment, consume, or checkout. If the user is authenticated, the link will be signed so that the user can access the service without logging in again.
|
|
71
72
|
- getPaymentIssues: returns a list of failed payments and cards that will expire
|
|
72
73
|
- getVersion: returns the version of the sesamy-js library
|
|
@@ -749,7 +750,7 @@ import { generateLink } from '@sesamy/sesamy-js';
|
|
|
749
750
|
// Generate a link to consume a product
|
|
750
751
|
const linkParams = {
|
|
751
752
|
target: 'consume',
|
|
752
|
-
sku: '
|
|
753
|
+
sku: 'sid:eUv45QXTrcGNhMJpaCQNe',
|
|
753
754
|
episodeId: 'episode-id',
|
|
754
755
|
shorten: true,
|
|
755
756
|
ttl: 3600, // 1 hour in seconds
|
|
@@ -828,7 +829,7 @@ import { createCheckout } from '@sesamy/sesamy-js';
|
|
|
828
829
|
const checkoutParams = {
|
|
829
830
|
items: [
|
|
830
831
|
{
|
|
831
|
-
sku: '
|
|
832
|
+
sku: 'sid:eUv45QXTrcGNhMJpaCQNe',
|
|
832
833
|
purchaseOptionsId: 'option-id', // optional
|
|
833
834
|
},
|
|
834
835
|
],
|
|
@@ -1507,6 +1508,652 @@ window.sesamy.amendments
|
|
|
1507
1508
|
});
|
|
1508
1509
|
```
|
|
1509
1510
|
|
|
1511
|
+
# Products API
|
|
1512
|
+
|
|
1513
|
+
The Products API provides methods for working with Sesamy products, including retrieving product information and linking accounts.
|
|
1514
|
+
|
|
1515
|
+
## `products.get(sku: string)`
|
|
1516
|
+
|
|
1517
|
+
Retrieves detailed information about a product by its SKU.
|
|
1518
|
+
|
|
1519
|
+
### Parameters
|
|
1520
|
+
|
|
1521
|
+
- `sku` (string): The Stock Keeping Unit (SKU) identifier for the product.
|
|
1522
|
+
|
|
1523
|
+
### Returns
|
|
1524
|
+
|
|
1525
|
+
- `Promise<Product>`: A promise that resolves to the product object.
|
|
1526
|
+
|
|
1527
|
+
### Example
|
|
1528
|
+
|
|
1529
|
+
```javascript
|
|
1530
|
+
// Get product information by SKU
|
|
1531
|
+
window.sesamy.products
|
|
1532
|
+
.get('sid:eUv45QXTrcGNhMJpaCQNe')
|
|
1533
|
+
.then(product => {
|
|
1534
|
+
console.log('Product details:', product);
|
|
1535
|
+
console.log('Product name:', product.name);
|
|
1536
|
+
console.log('Product price:', product.price);
|
|
1537
|
+
})
|
|
1538
|
+
.catch(error => {
|
|
1539
|
+
console.error('Error fetching product:', error);
|
|
1540
|
+
});
|
|
1541
|
+
```
|
|
1542
|
+
|
|
1543
|
+
## `products.autoOnboard(sku: string)`
|
|
1544
|
+
|
|
1545
|
+
Triggers the auto-onboarding process for a product by SKU, which helps users get started with a product they've purchased.
|
|
1546
|
+
|
|
1547
|
+
### Parameters
|
|
1548
|
+
|
|
1549
|
+
- `sku` (string): The Stock Keeping Unit (SKU) identifier for the product.
|
|
1550
|
+
|
|
1551
|
+
### Returns
|
|
1552
|
+
|
|
1553
|
+
- `Promise<boolean>`: A promise that resolves to `true` if the auto-onboarding process was successfully initiated.
|
|
1554
|
+
|
|
1555
|
+
### Example
|
|
1556
|
+
|
|
1557
|
+
```javascript
|
|
1558
|
+
// Trigger auto-onboarding for a product
|
|
1559
|
+
window.sesamy.products
|
|
1560
|
+
.autoOnboard('sid:eUv45QXTrcGNhMJpaCQNe')
|
|
1561
|
+
.then(success => {
|
|
1562
|
+
if (success) {
|
|
1563
|
+
console.log('Auto-onboarding process initiated successfully');
|
|
1564
|
+
}
|
|
1565
|
+
})
|
|
1566
|
+
.catch(error => {
|
|
1567
|
+
console.error('Error triggering auto-onboarding:', error);
|
|
1568
|
+
});
|
|
1569
|
+
```
|
|
1570
|
+
|
|
1571
|
+
## `products.linkSpotify()`
|
|
1572
|
+
|
|
1573
|
+
Links a user's Spotify account to enable Sesamy products that integrate with Spotify.
|
|
1574
|
+
|
|
1575
|
+
### Returns
|
|
1576
|
+
|
|
1577
|
+
- `Promise<boolean>`: A promise that resolves to `true` if the Spotify account was successfully linked.
|
|
1578
|
+
|
|
1579
|
+
### Example
|
|
1580
|
+
|
|
1581
|
+
```javascript
|
|
1582
|
+
// Link the user's Spotify account
|
|
1583
|
+
window.sesamy.products
|
|
1584
|
+
.linkSpotify()
|
|
1585
|
+
.then(success => {
|
|
1586
|
+
if (success) {
|
|
1587
|
+
console.log('Spotify account linked successfully');
|
|
1588
|
+
}
|
|
1589
|
+
})
|
|
1590
|
+
.catch(error => {
|
|
1591
|
+
console.error('Error linking Spotify account:', error);
|
|
1592
|
+
});
|
|
1593
|
+
```
|
|
1594
|
+
|
|
1595
|
+
# Tags API
|
|
1596
|
+
|
|
1597
|
+
The Tags API allows for managing user tags, which can be used for user segmentation and personalization.
|
|
1598
|
+
|
|
1599
|
+
## `tags.list()`
|
|
1600
|
+
|
|
1601
|
+
Fetches all tags associated with the current user.
|
|
1602
|
+
|
|
1603
|
+
### Returns
|
|
1604
|
+
|
|
1605
|
+
- `Promise<string[]>`: A promise that resolves to an array of tag strings.
|
|
1606
|
+
|
|
1607
|
+
### Example
|
|
1608
|
+
|
|
1609
|
+
```javascript
|
|
1610
|
+
// Get all tags for the current user
|
|
1611
|
+
window.sesamy.tags
|
|
1612
|
+
.list()
|
|
1613
|
+
.then(tags => {
|
|
1614
|
+
console.log('User tags:', tags);
|
|
1615
|
+
})
|
|
1616
|
+
.catch(error => {
|
|
1617
|
+
console.error('Error fetching tags:', error);
|
|
1618
|
+
});
|
|
1619
|
+
```
|
|
1620
|
+
|
|
1621
|
+
## `tags.set(tag: string)`
|
|
1622
|
+
|
|
1623
|
+
Sets a tag for the current user. If the tag already exists, it won't create a duplicate.
|
|
1624
|
+
|
|
1625
|
+
### Parameters
|
|
1626
|
+
|
|
1627
|
+
- `tag` (string): The tag to associate with the user.
|
|
1628
|
+
|
|
1629
|
+
### Returns
|
|
1630
|
+
|
|
1631
|
+
- `Promise<boolean>`: A promise that resolves to `true` if the tag was successfully set.
|
|
1632
|
+
|
|
1633
|
+
### Example
|
|
1634
|
+
|
|
1635
|
+
```javascript
|
|
1636
|
+
// Set a tag for the current user
|
|
1637
|
+
window.sesamy.tags
|
|
1638
|
+
.set('premium-subscriber')
|
|
1639
|
+
.then(success => {
|
|
1640
|
+
if (success) {
|
|
1641
|
+
console.log('Tag set successfully');
|
|
1642
|
+
}
|
|
1643
|
+
})
|
|
1644
|
+
.catch(error => {
|
|
1645
|
+
console.error('Error setting tag:', error);
|
|
1646
|
+
});
|
|
1647
|
+
```
|
|
1648
|
+
|
|
1649
|
+
## `tags.delete(tag: string)`
|
|
1650
|
+
|
|
1651
|
+
Deletes a specific tag from the current user.
|
|
1652
|
+
|
|
1653
|
+
### Parameters
|
|
1654
|
+
|
|
1655
|
+
- `tag` (string): The tag to remove from the user.
|
|
1656
|
+
|
|
1657
|
+
### Returns
|
|
1658
|
+
|
|
1659
|
+
- `Promise<boolean>`: A promise that resolves to `true` if the tag was successfully deleted.
|
|
1660
|
+
|
|
1661
|
+
### Example
|
|
1662
|
+
|
|
1663
|
+
```javascript
|
|
1664
|
+
// Delete a tag from the current user
|
|
1665
|
+
window.sesamy.tags
|
|
1666
|
+
.delete('trial-user')
|
|
1667
|
+
.then(success => {
|
|
1668
|
+
if (success) {
|
|
1669
|
+
console.log('Tag deleted successfully');
|
|
1670
|
+
}
|
|
1671
|
+
})
|
|
1672
|
+
.catch(error => {
|
|
1673
|
+
console.error('Error deleting tag:', error);
|
|
1674
|
+
});
|
|
1675
|
+
```
|
|
1676
|
+
|
|
1677
|
+
# Tallies API
|
|
1678
|
+
|
|
1679
|
+
The Tallies API allows for tracking counts of various user activities or metrics.
|
|
1680
|
+
|
|
1681
|
+
## `tallies.list()`
|
|
1682
|
+
|
|
1683
|
+
Lists all tallies for the current user.
|
|
1684
|
+
|
|
1685
|
+
### Returns
|
|
1686
|
+
|
|
1687
|
+
- `Promise<Tally[]>`: A promise that resolves to an array of tally objects.
|
|
1688
|
+
|
|
1689
|
+
### Example
|
|
1690
|
+
|
|
1691
|
+
```javascript
|
|
1692
|
+
// List all tallies for the current user
|
|
1693
|
+
window.sesamy.tallies
|
|
1694
|
+
.list()
|
|
1695
|
+
.then(tallies => {
|
|
1696
|
+
console.log('User tallies:', tallies);
|
|
1697
|
+
})
|
|
1698
|
+
.catch(error => {
|
|
1699
|
+
console.error('Error listing tallies:', error);
|
|
1700
|
+
});
|
|
1701
|
+
```
|
|
1702
|
+
|
|
1703
|
+
## `tallies.get(id: string)`
|
|
1704
|
+
|
|
1705
|
+
Retrieves a specific tally by its ID.
|
|
1706
|
+
|
|
1707
|
+
### Parameters
|
|
1708
|
+
|
|
1709
|
+
- `id` (string): The ID of the tally to retrieve.
|
|
1710
|
+
|
|
1711
|
+
### Returns
|
|
1712
|
+
|
|
1713
|
+
- `Promise<Tally>`: A promise that resolves to the tally object.
|
|
1714
|
+
|
|
1715
|
+
### Example
|
|
1716
|
+
|
|
1717
|
+
```javascript
|
|
1718
|
+
// Get a specific tally by ID
|
|
1719
|
+
window.sesamy.tallies
|
|
1720
|
+
.get('article-views')
|
|
1721
|
+
.then(tally => {
|
|
1722
|
+
console.log('Tally:', tally);
|
|
1723
|
+
console.log('Current count:', tally.count);
|
|
1724
|
+
})
|
|
1725
|
+
.catch(error => {
|
|
1726
|
+
console.error('Error getting tally:', error);
|
|
1727
|
+
});
|
|
1728
|
+
```
|
|
1729
|
+
|
|
1730
|
+
## `tallies.push(id: string, item: any)`
|
|
1731
|
+
|
|
1732
|
+
Adds an item to a specific tally, incrementing its count.
|
|
1733
|
+
|
|
1734
|
+
### Parameters
|
|
1735
|
+
|
|
1736
|
+
- `id` (string): The ID of the tally to update.
|
|
1737
|
+
- `item` (any): The item to add to the tally.
|
|
1738
|
+
|
|
1739
|
+
### Returns
|
|
1740
|
+
|
|
1741
|
+
- `Promise<Tally>`: A promise that resolves to the updated tally object.
|
|
1742
|
+
|
|
1743
|
+
### Example
|
|
1744
|
+
|
|
1745
|
+
```javascript
|
|
1746
|
+
// Increment an article view tally
|
|
1747
|
+
window.sesamy.tallies
|
|
1748
|
+
.push('article-views', { articleId: 'sid:eUv45QXTrcGNhMJpaCQNe', timestamp: new Date() })
|
|
1749
|
+
.then(updatedTally => {
|
|
1750
|
+
console.log('Updated tally:', updatedTally);
|
|
1751
|
+
console.log('New count:', updatedTally.count);
|
|
1752
|
+
})
|
|
1753
|
+
.catch(error => {
|
|
1754
|
+
console.error('Error updating tally:', error);
|
|
1755
|
+
});
|
|
1756
|
+
```
|
|
1757
|
+
|
|
1758
|
+
## `tallies.delete(id: string)`
|
|
1759
|
+
|
|
1760
|
+
Deletes a specific tally by its ID.
|
|
1761
|
+
|
|
1762
|
+
### Parameters
|
|
1763
|
+
|
|
1764
|
+
- `id` (string): The ID of the tally to delete.
|
|
1765
|
+
|
|
1766
|
+
### Returns
|
|
1767
|
+
|
|
1768
|
+
- `Promise<boolean>`: A promise that resolves to `true` if the tally was successfully deleted.
|
|
1769
|
+
|
|
1770
|
+
### Example
|
|
1771
|
+
|
|
1772
|
+
```javascript
|
|
1773
|
+
// Delete a specific tally
|
|
1774
|
+
window.sesamy.tallies
|
|
1775
|
+
.delete('article-views')
|
|
1776
|
+
.then(success => {
|
|
1777
|
+
if (success) {
|
|
1778
|
+
console.log('Tally deleted successfully');
|
|
1779
|
+
}
|
|
1780
|
+
})
|
|
1781
|
+
.catch(error => {
|
|
1782
|
+
console.error('Error deleting tally:', error);
|
|
1783
|
+
});
|
|
1784
|
+
```
|
|
1785
|
+
|
|
1786
|
+
# User Metadata API
|
|
1787
|
+
|
|
1788
|
+
The User Metadata API allows for storing and retrieving custom metadata associated with users.
|
|
1789
|
+
|
|
1790
|
+
## `userMetadata.list()`
|
|
1791
|
+
|
|
1792
|
+
Lists all metadata items for the current user.
|
|
1793
|
+
|
|
1794
|
+
### Returns
|
|
1795
|
+
|
|
1796
|
+
- `Promise<Record<string, any>>`: A promise that resolves to an object containing all metadata key-value pairs.
|
|
1797
|
+
|
|
1798
|
+
### Example
|
|
1799
|
+
|
|
1800
|
+
```javascript
|
|
1801
|
+
// List all user metadata
|
|
1802
|
+
window.sesamy.userMetadata
|
|
1803
|
+
.list()
|
|
1804
|
+
.then(metadata => {
|
|
1805
|
+
console.log('User metadata:', metadata);
|
|
1806
|
+
})
|
|
1807
|
+
.catch(error => {
|
|
1808
|
+
console.error('Error listing user metadata:', error);
|
|
1809
|
+
});
|
|
1810
|
+
```
|
|
1811
|
+
|
|
1812
|
+
## `userMetadata.get(id: string)`
|
|
1813
|
+
|
|
1814
|
+
Retrieves a specific metadata item by its ID.
|
|
1815
|
+
|
|
1816
|
+
### Parameters
|
|
1817
|
+
|
|
1818
|
+
- `id` (string): The ID of the metadata item to retrieve.
|
|
1819
|
+
|
|
1820
|
+
### Returns
|
|
1821
|
+
|
|
1822
|
+
- `Promise<any>`: A promise that resolves to the value of the metadata item.
|
|
1823
|
+
|
|
1824
|
+
### Example
|
|
1825
|
+
|
|
1826
|
+
```javascript
|
|
1827
|
+
// Get a specific metadata item
|
|
1828
|
+
window.sesamy.userMetadata
|
|
1829
|
+
.get('preferences')
|
|
1830
|
+
.then(value => {
|
|
1831
|
+
console.log('User preferences:', value);
|
|
1832
|
+
})
|
|
1833
|
+
.catch(error => {
|
|
1834
|
+
console.error('Error getting metadata:', error);
|
|
1835
|
+
});
|
|
1836
|
+
```
|
|
1837
|
+
|
|
1838
|
+
## `userMetadata.set(id: string, value: any)`
|
|
1839
|
+
|
|
1840
|
+
Sets a metadata item for the current user.
|
|
1841
|
+
|
|
1842
|
+
### Parameters
|
|
1843
|
+
|
|
1844
|
+
- `id` (string): The ID of the metadata item to set.
|
|
1845
|
+
- `value` (any): The value to assign to the metadata item.
|
|
1846
|
+
|
|
1847
|
+
### Returns
|
|
1848
|
+
|
|
1849
|
+
- `Promise<boolean>`: A promise that resolves to `true` if the metadata item was successfully set.
|
|
1850
|
+
|
|
1851
|
+
### Example
|
|
1852
|
+
|
|
1853
|
+
```javascript
|
|
1854
|
+
// Set a user preference metadata item
|
|
1855
|
+
window.sesamy.userMetadata
|
|
1856
|
+
.set('preferences', { theme: 'dark', fontSize: 'large' })
|
|
1857
|
+
.then(success => {
|
|
1858
|
+
if (success) {
|
|
1859
|
+
console.log('User preferences saved successfully');
|
|
1860
|
+
}
|
|
1861
|
+
})
|
|
1862
|
+
.catch(error => {
|
|
1863
|
+
console.error('Error setting metadata:', error);
|
|
1864
|
+
});
|
|
1865
|
+
```
|
|
1866
|
+
|
|
1867
|
+
## `userMetadata.delete(id: string)`
|
|
1868
|
+
|
|
1869
|
+
Deletes a specific metadata item by its ID.
|
|
1870
|
+
|
|
1871
|
+
### Parameters
|
|
1872
|
+
|
|
1873
|
+
- `id` (string): The ID of the metadata item to delete.
|
|
1874
|
+
|
|
1875
|
+
### Returns
|
|
1876
|
+
|
|
1877
|
+
- `Promise<boolean>`: A promise that resolves to `true` if the metadata item was successfully deleted.
|
|
1878
|
+
|
|
1879
|
+
### Example
|
|
1880
|
+
|
|
1881
|
+
```javascript
|
|
1882
|
+
// Delete a metadata item
|
|
1883
|
+
window.sesamy.userMetadata
|
|
1884
|
+
.delete('temporary-setting')
|
|
1885
|
+
.then(success => {
|
|
1886
|
+
if (success) {
|
|
1887
|
+
console.log('Metadata item deleted successfully');
|
|
1888
|
+
}
|
|
1889
|
+
})
|
|
1890
|
+
.catch(error => {
|
|
1891
|
+
console.error('Error deleting metadata:', error);
|
|
1892
|
+
});
|
|
1893
|
+
```
|
|
1894
|
+
|
|
1895
|
+
# Vendors API
|
|
1896
|
+
|
|
1897
|
+
The Vendors API provides methods for retrieving information about vendors (publishers) connected to a user.
|
|
1898
|
+
|
|
1899
|
+
## `vendors.get()`
|
|
1900
|
+
|
|
1901
|
+
Fetches settings for the current vendor based on the authenticated user context.
|
|
1902
|
+
|
|
1903
|
+
### Returns
|
|
1904
|
+
|
|
1905
|
+
- `Promise<VendorSettings>`: A promise that resolves to the vendor settings object.
|
|
1906
|
+
|
|
1907
|
+
### Example
|
|
1908
|
+
|
|
1909
|
+
```javascript
|
|
1910
|
+
// Get current vendor settings
|
|
1911
|
+
window.sesamy.vendors
|
|
1912
|
+
.get()
|
|
1913
|
+
.then(settings => {
|
|
1914
|
+
console.log('Vendor settings:', settings);
|
|
1915
|
+
console.log('Vendor name:', settings.name);
|
|
1916
|
+
console.log('Vendor currency:', settings.currency);
|
|
1917
|
+
})
|
|
1918
|
+
.catch(error => {
|
|
1919
|
+
console.error('Error fetching vendor settings:', error);
|
|
1920
|
+
});
|
|
1921
|
+
```
|
|
1922
|
+
|
|
1923
|
+
## `vendors.list()`
|
|
1924
|
+
|
|
1925
|
+
Lists all publishers connected to the user. This method is not available for publisher tokens.
|
|
1926
|
+
|
|
1927
|
+
### Returns
|
|
1928
|
+
|
|
1929
|
+
- `Promise<Vendor[]>`: A promise that resolves to an array of vendor objects.
|
|
1930
|
+
|
|
1931
|
+
### Example
|
|
1932
|
+
|
|
1933
|
+
```javascript
|
|
1934
|
+
// List all vendors connected to the user
|
|
1935
|
+
window.sesamy.vendors
|
|
1936
|
+
.list()
|
|
1937
|
+
.then(vendors => {
|
|
1938
|
+
console.log('Connected vendors:', vendors);
|
|
1939
|
+
vendors.forEach(vendor => {
|
|
1940
|
+
console.log('Vendor name:', vendor.name);
|
|
1941
|
+
console.log('Vendor ID:', vendor.id);
|
|
1942
|
+
});
|
|
1943
|
+
})
|
|
1944
|
+
.catch(error => {
|
|
1945
|
+
console.error('Error listing vendors:', error);
|
|
1946
|
+
});
|
|
1947
|
+
```
|
|
1948
|
+
|
|
1949
|
+
# Contracts API
|
|
1950
|
+
|
|
1951
|
+
The Contracts API provides methods for managing user contracts, including subscription services.
|
|
1952
|
+
|
|
1953
|
+
## `contracts.list()`
|
|
1954
|
+
|
|
1955
|
+
Lists all contracts associated with the current user.
|
|
1956
|
+
|
|
1957
|
+
### Returns
|
|
1958
|
+
|
|
1959
|
+
- `Promise<Contract[]>`: A promise that resolves to an array of contract objects.
|
|
1960
|
+
|
|
1961
|
+
### Example
|
|
1962
|
+
|
|
1963
|
+
```javascript
|
|
1964
|
+
// List all user contracts
|
|
1965
|
+
window.sesamy.contracts
|
|
1966
|
+
.list()
|
|
1967
|
+
.then(contracts => {
|
|
1968
|
+
console.log('User contracts:', contracts);
|
|
1969
|
+
contracts.forEach(contract => {
|
|
1970
|
+
console.log('Contract ID:', contract.id);
|
|
1971
|
+
console.log('Contract status:', contract.status);
|
|
1972
|
+
console.log('Contract start date:', contract.startDate);
|
|
1973
|
+
});
|
|
1974
|
+
})
|
|
1975
|
+
.catch(error => {
|
|
1976
|
+
console.error('Error listing contracts:', error);
|
|
1977
|
+
});
|
|
1978
|
+
```
|
|
1979
|
+
|
|
1980
|
+
## `contracts.get(id: string)`
|
|
1981
|
+
|
|
1982
|
+
Retrieves a specific contract by its ID.
|
|
1983
|
+
|
|
1984
|
+
### Parameters
|
|
1985
|
+
|
|
1986
|
+
- `id` (string): The ID of the contract to retrieve.
|
|
1987
|
+
|
|
1988
|
+
### Returns
|
|
1989
|
+
|
|
1990
|
+
- `Promise<Contract>`: A promise that resolves to the contract object.
|
|
1991
|
+
|
|
1992
|
+
### Example
|
|
1993
|
+
|
|
1994
|
+
```javascript
|
|
1995
|
+
// Get a specific contract by ID
|
|
1996
|
+
window.sesamy.contracts
|
|
1997
|
+
.get('contract-123')
|
|
1998
|
+
.then(contract => {
|
|
1999
|
+
console.log('Contract details:', contract);
|
|
2000
|
+
console.log('Contract status:', contract.status);
|
|
2001
|
+
console.log('Contract type:', contract.type);
|
|
2002
|
+
})
|
|
2003
|
+
.catch(error => {
|
|
2004
|
+
console.error('Error fetching contract:', error);
|
|
2005
|
+
});
|
|
2006
|
+
```
|
|
2007
|
+
|
|
2008
|
+
## `contracts.cancel(id: string)`
|
|
2009
|
+
|
|
2010
|
+
Cancels a specific contract by its ID.
|
|
2011
|
+
|
|
2012
|
+
### Parameters
|
|
2013
|
+
|
|
2014
|
+
- `id` (string): The ID of the contract to cancel.
|
|
2015
|
+
|
|
2016
|
+
### Returns
|
|
2017
|
+
|
|
2018
|
+
- `Promise<Contract>`: A promise that resolves to the updated contract object with its status set to canceling or canceled.
|
|
2019
|
+
|
|
2020
|
+
### Example
|
|
2021
|
+
|
|
2022
|
+
```javascript
|
|
2023
|
+
// Cancel a contract
|
|
2024
|
+
window.sesamy.contracts
|
|
2025
|
+
.cancel('contract-123')
|
|
2026
|
+
.then(contract => {
|
|
2027
|
+
console.log('Contract canceled successfully');
|
|
2028
|
+
console.log('Updated contract status:', contract.status);
|
|
2029
|
+
})
|
|
2030
|
+
.catch(error => {
|
|
2031
|
+
console.error('Error canceling contract:', error);
|
|
2032
|
+
});
|
|
2033
|
+
```
|
|
2034
|
+
|
|
2035
|
+
# Bills API
|
|
2036
|
+
|
|
2037
|
+
The Bills API allows for retrieving information about user bills.
|
|
2038
|
+
|
|
2039
|
+
## `bills.list()`
|
|
2040
|
+
|
|
2041
|
+
Lists all bills associated with the current user.
|
|
2042
|
+
|
|
2043
|
+
### Returns
|
|
2044
|
+
|
|
2045
|
+
- `Promise<Bill[]>`: A promise that resolves to an array of bill objects.
|
|
2046
|
+
|
|
2047
|
+
### Example
|
|
2048
|
+
|
|
2049
|
+
```javascript
|
|
2050
|
+
// List all user bills
|
|
2051
|
+
window.sesamy.bills
|
|
2052
|
+
.list()
|
|
2053
|
+
.then(bills => {
|
|
2054
|
+
console.log('User bills:', bills);
|
|
2055
|
+
bills.forEach(bill => {
|
|
2056
|
+
console.log('Bill ID:', bill.id);
|
|
2057
|
+
console.log('Amount:', bill.amount);
|
|
2058
|
+
console.log('Due date:', bill.dueDate);
|
|
2059
|
+
console.log('Status:', bill.status);
|
|
2060
|
+
});
|
|
2061
|
+
})
|
|
2062
|
+
.catch(error => {
|
|
2063
|
+
console.error('Error listing bills:', error);
|
|
2064
|
+
});
|
|
2065
|
+
```
|
|
2066
|
+
|
|
2067
|
+
## `bills.get(id: string)`
|
|
2068
|
+
|
|
2069
|
+
Retrieves a specific bill by its ID.
|
|
2070
|
+
|
|
2071
|
+
### Parameters
|
|
2072
|
+
|
|
2073
|
+
- `id` (string): The ID of the bill to retrieve.
|
|
2074
|
+
|
|
2075
|
+
### Returns
|
|
2076
|
+
|
|
2077
|
+
- `Promise<Bill>`: A promise that resolves to the bill object.
|
|
2078
|
+
|
|
2079
|
+
### Example
|
|
2080
|
+
|
|
2081
|
+
```javascript
|
|
2082
|
+
// Get a specific bill by ID
|
|
2083
|
+
window.sesamy.bills
|
|
2084
|
+
.get('bill-123')
|
|
2085
|
+
.then(bill => {
|
|
2086
|
+
console.log('Bill details:', bill);
|
|
2087
|
+
console.log('Amount:', bill.amount);
|
|
2088
|
+
console.log('Status:', bill.status);
|
|
2089
|
+
console.log('Due date:', bill.dueDate);
|
|
2090
|
+
})
|
|
2091
|
+
.catch(error => {
|
|
2092
|
+
console.error('Error fetching bill:', error);
|
|
2093
|
+
});
|
|
2094
|
+
```
|
|
2095
|
+
|
|
2096
|
+
# Transactions API
|
|
2097
|
+
|
|
2098
|
+
The Transactions API allows for retrieving information about user transactions.
|
|
2099
|
+
|
|
2100
|
+
## `transactions.list()`
|
|
2101
|
+
|
|
2102
|
+
Lists all transactions associated with the current user.
|
|
2103
|
+
|
|
2104
|
+
### Returns
|
|
2105
|
+
|
|
2106
|
+
- `Promise<Transaction[]>`: A promise that resolves to an array of transaction objects.
|
|
2107
|
+
|
|
2108
|
+
### Example
|
|
2109
|
+
|
|
2110
|
+
```javascript
|
|
2111
|
+
// List all user transactions
|
|
2112
|
+
window.sesamy.transactions
|
|
2113
|
+
.list()
|
|
2114
|
+
.then(transactions => {
|
|
2115
|
+
console.log('User transactions:', transactions);
|
|
2116
|
+
transactions.forEach(transaction => {
|
|
2117
|
+
console.log('Transaction ID:', transaction.id);
|
|
2118
|
+
console.log('Amount:', transaction.amount);
|
|
2119
|
+
console.log('Date:', transaction.createdAt);
|
|
2120
|
+
console.log('Status:', transaction.status);
|
|
2121
|
+
});
|
|
2122
|
+
})
|
|
2123
|
+
.catch(error => {
|
|
2124
|
+
console.error('Error listing transactions:', error);
|
|
2125
|
+
});
|
|
2126
|
+
```
|
|
2127
|
+
|
|
2128
|
+
## `transactions.get(id: string)`
|
|
2129
|
+
|
|
2130
|
+
Retrieves a specific transaction by its ID.
|
|
2131
|
+
|
|
2132
|
+
### Parameters
|
|
2133
|
+
|
|
2134
|
+
- `id` (string): The ID of the transaction to retrieve.
|
|
2135
|
+
|
|
2136
|
+
### Returns
|
|
2137
|
+
|
|
2138
|
+
- `Promise<Transaction>`: A promise that resolves to the transaction object.
|
|
2139
|
+
|
|
2140
|
+
### Example
|
|
2141
|
+
|
|
2142
|
+
```javascript
|
|
2143
|
+
// Get a specific transaction by ID
|
|
2144
|
+
window.sesamy.transactions
|
|
2145
|
+
.get('transaction-123')
|
|
2146
|
+
.then(transaction => {
|
|
2147
|
+
console.log('Transaction details:', transaction);
|
|
2148
|
+
console.log('Amount:', transaction.amount);
|
|
2149
|
+
console.log('Status:', transaction.status);
|
|
2150
|
+
console.log('Date:', transaction.createdAt);
|
|
2151
|
+
})
|
|
2152
|
+
.catch(error => {
|
|
2153
|
+
console.error('Error fetching transaction:', error);
|
|
2154
|
+
});
|
|
2155
|
+
```
|
|
2156
|
+
|
|
1510
2157
|
# Polyfills
|
|
1511
2158
|
|
|
1512
2159
|
The library polyfills the following methods for compatibility with older browsers:
|
|
@@ -1534,3 +2181,75 @@ The library tracks the following data for attribution purposes and pass it on to
|
|
|
1534
2181
|
- `ref`: The referrer passed in the querystring.
|
|
1535
2182
|
- `referrer`: The referrer URL of the initial page load.
|
|
1536
2183
|
- `item-src`: The url of the last locked article viewed.
|
|
2184
|
+
|
|
2185
|
+
# Events API
|
|
2186
|
+
|
|
2187
|
+
The Events API allows for emitting custom events that can be listened to and optionally canceled by other scripts on the page.
|
|
2188
|
+
|
|
2189
|
+
## `events.emit(eventName: string, data?: Record<string, any>, cancelable?: boolean)`
|
|
2190
|
+
|
|
2191
|
+
Emits a custom event that can optionally be canceled by event listeners.
|
|
2192
|
+
|
|
2193
|
+
### Parameters
|
|
2194
|
+
|
|
2195
|
+
- `eventName` (string): The name of the event to emit.
|
|
2196
|
+
- `data` (Record<string, any>, optional): Additional data to include with the event.
|
|
2197
|
+
- `cancelable` (boolean, optional): Whether the event can be canceled by listeners. Defaults to `false`.
|
|
2198
|
+
|
|
2199
|
+
### Returns
|
|
2200
|
+
|
|
2201
|
+
- `{ canceled: boolean, message?: string }`: An object indicating if the event was canceled and any cancellation message.
|
|
2202
|
+
|
|
2203
|
+
### Example
|
|
2204
|
+
|
|
2205
|
+
```javascript
|
|
2206
|
+
// Emit a non-cancelable event
|
|
2207
|
+
window.sesamy.events.emit('article-viewed', { articleId: '12345' });
|
|
2208
|
+
|
|
2209
|
+
// Emit a cancelable event and check if it was canceled
|
|
2210
|
+
const result = window.sesamy.events.emit('purchase-initiated', { productId: 'premium-sub' }, true);
|
|
2211
|
+
|
|
2212
|
+
if (result.canceled) {
|
|
2213
|
+
console.log(`Purchase was canceled: ${result.message}`);
|
|
2214
|
+
} else {
|
|
2215
|
+
// Proceed with purchase flow
|
|
2216
|
+
proceedWithPurchase();
|
|
2217
|
+
}
|
|
2218
|
+
```
|
|
2219
|
+
|
|
2220
|
+
## `events.cancel(event: CustomEvent<CancelableEventDetail>, message?: string)`
|
|
2221
|
+
|
|
2222
|
+
Cancels an event with an optional message explaining the reason.
|
|
2223
|
+
|
|
2224
|
+
### Parameters
|
|
2225
|
+
|
|
2226
|
+
- `event` (CustomEvent): The event to cancel.
|
|
2227
|
+
- `message` (string, optional): A message explaining why the event was canceled.
|
|
2228
|
+
|
|
2229
|
+
### Returns
|
|
2230
|
+
|
|
2231
|
+
- `void`
|
|
2232
|
+
|
|
2233
|
+
### Example
|
|
2234
|
+
|
|
2235
|
+
```javascript
|
|
2236
|
+
// Listen for a cancelable event
|
|
2237
|
+
window.addEventListener('purchase-initiated', event => {
|
|
2238
|
+
// Check if user already owns the product
|
|
2239
|
+
if (userOwnsProduct(event.detail.data.productId)) {
|
|
2240
|
+
// Cancel the event with a message
|
|
2241
|
+
window.sesamy.events.cancel(event, 'User already owns this product');
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
```
|
|
2245
|
+
|
|
2246
|
+
### Use Cases
|
|
2247
|
+
|
|
2248
|
+
The Events API can be used for various scenarios where you need to communicate between different components or scripts:
|
|
2249
|
+
|
|
2250
|
+
1. **Purchase Flow Interception**: Allow third-party scripts to intercept and potentially cancel purchase flows.
|
|
2251
|
+
2. **Content Locking**: Emit events when content is about to be locked/unlocked and allow other scripts to modify this behavior.
|
|
2252
|
+
3. **User Authentication**: Notify when users are about to be authenticated and allow other scripts to intervene.
|
|
2253
|
+
4. **Analytics**: Emit events for key user interactions that other scripts might want to track.
|
|
2254
|
+
|
|
2255
|
+
Events emitted through this API are also automatically tracked in analytics with the prefix `event:`.
|