Skip to content

Commit

Permalink
refactor: updating terminology; docstrings; refining readme
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Oct 22, 2023
1 parent a230f7e commit 7e4ae6f
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 91 deletions.
124 changes: 52 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## 🌟 About

Subtopia JS SDK is a JavaScript library for interacting with the Subtopia Platform. It provides a simple interface for creating and managing Subscription Management Infrastructures (`SMI`s).
Subtopia JS SDK is a JavaScript library for interacting with the Subtopia Platform. It provides a simple interface for creating and managing `Products` (Contracts that are responsible for subscription management).

> For detailed documentation, refer to [sdk.subtopia.io](https://sdk.subtopia.io).
Expand All @@ -39,7 +39,7 @@ yarn add subtopia-js
### Import the package:

```ts
import { SubtopiaClient } from "subtopia-js";
import { SubtopiaClient, SubtopiaRegistryClient } from "subtopia-js";
```

## 🛠️ Usage
Expand All @@ -53,16 +53,18 @@ Example snippets of using the Subtopia JS SDK.
```ts
// ... your code

const response = await SubtopiaClient.subscribe(
{
subscriber: { address: {PUT_WALLET_ADDRESS}, signer: {PUT_WALLET_SIGNER} },
smiID: { PUT_PRODUCT_ID_HERE }, // number - the ID of the SMI instance you want to subscribe to
duration: { PUT_EXPIRATION_TYPE_HERE }, // pick duration from Duration enum. If there is a discount available for this duration, it will be auto applied.
},
{ client: {PUT_ALGOD_INSTANCE_HERE} // object of type algosdk.Algodv2
const subtopiaClient = await SubtopiaClient.init(
{ PUT_ALGOD_INSTANCE_HERE },
{ PUT_PRODUCT_ID_HERE },
{ address: { PUT_WALLET_ADDRESS }, signer: { PUT_WALLET_SIGNER } }
);

const response = await subtopiaClient.subscribe(
{ address: { PUT_WALLET_ADDRESS }, signer: { PUT_WALLET_SIGNER } },
{ PUT_DURATION_HERE } // pick duration from Duration enum. If there is a discount available for this duration, it will be auto applied.
);

console.log(response.returnValue) // response is of type ABIResult
console.log(response.txID); // response is of type string

// ... rest of your code
```
Expand All @@ -71,58 +73,45 @@ console.log(response.returnValue) // response is of type ABIResult

```ts
// ... your code
const subscriberBox = await SubtopiaClient.getSubscriptionRecordForAccount(
client,
{ PUT_SUBSCRIBER_ADDRESS },
{ PUT_PRODUCT_ID_HERE }
);
const subscriptionRecord = await subtopiaClient.getSubscription({
subscriberAddress: { PUT_SUBSCRIBER_ADDRESS },
});

// SubscriptionRecord (throws Error if not subscribed)
console.log(subscriberBox);
console.log(subscriptionRecord);
// ... rest of your code
```

### Unsubscribing:

```ts
// ... your code
const deleteResult = await SubtopiaClient.unsubscribe(
{
subscriber: {
address: { PUT_SUBSCRIBER_ADDRESS },
signer: { PUT_SUBSCRIBER_SIGNER },
},
smiID: { PUT_INFRASTRUCTURE_ID },
const deleteResult = await subtopiaClient.unsubscribe({
subscriber: {
address: { PUT_SUBSCRIBER_ADDRESS },
signer: { PUT_SUBSCRIBER_SIGNER },
},
{
client: { PUT_ALGOD_CLIENT },
}
);
});

// ID of the deleted subscription ASA
console.log(deleteResult.returnValue);
// Transaction ID of the unsubscribe transaction
console.log(deleteResult.txID);
// ... your code
```

### Transfering subscription:

```ts
// ... your code
const transferResult = await SubtopiaClient.transferSubscriptionPass(
{
newOwnerAddress: { PUT_NEW_OWNER_ADDRESS },
oldOwner: {
address: { PUT_OLD_OWNER_ADDRESS },
signer: { PUT_OLD_OWNER_SIGNER },
},
smiID: { PUT_INFRASTRUCTURE_ID },
subID: Number(result.returnValue),
const transferResult = await subtopiaClient.transferSubscription({
oldSubscriber: {
address: { PUT_OLD_SUBSCRIBER_ADDRESS },
signer: { PUT_OLD_SUBSCRIBER_SIGNER },
},
{ client: { PUT_ALGOD_CLIENT } }
);
newSubscriberAddress: { PUT_NEW_SUBSCRIBER_ADDRESS },
});

// Transaction ID of the transfer transaction
console.log(deleteResult.txID);
console.log(transferResult.txID);
// ... your code
```

Expand All @@ -133,22 +122,23 @@ console.log(deleteResult.txID);
```ts
// ... your code

const discount = await SubtopiaClient.createDiscount(
{
creator: { address: {PUT_WALLET_ADDRESS}, signer: {PUT_WALLET_SIGNER} },
smiID: { PUT_PRODUCT_ID_HERE }, // number - the ID of the SMI instance you want to subscribe to
discount: {
duration: Duration // number - the type of expiration to apply. Also serves as static id for the discount.
discountType: {PUT_DISCOUNT_TYPE_HERE} // number - the type of discount to apply. FIXED or PERCENTAGE
discountValue: {PUT_DISCOUNT_VALUE_HERE} // number - the discount to be deducted from the subscription price
expiresIn: {PUT_EXPIRATION_TIME_HERE} // (Optional) Set 0 for discount to never expire. Else set number of seconds to append to unix timestamp at time of creation.
}, // number - the discount in percent
},
{ client: {PUT_ALGOD_INSTANCE_HERE} } // object of type algosdk.Algodv2
const subtopiaRegistryClient = await SubtopiaRegistryClient.init(
{ PUT_ALGOD_INSTANCE_HERE },
{ address: { PUT_WALLET_ADDRESS }, signer: { PUT_WALLET_SIGNER } },
{ PUT_CHAIN_TYPE_HERE }
);

const discount = await subtopiaRegistryClient.createDiscount({
productID: { PUT_PRODUCT_ID_HERE }, // number - the ID of the Product instance you want to create a discount for
discount: {
duration: { PUT_DURATION_HERE }, // number - the type of duration to apply. Also serves as static id for the discount.
discountType: { PUT_DISCOUNT_TYPE_HERE }, // number - the type of discount to apply. FIXED or PERCENTAGE
discountValue: { PUT_DISCOUNT_VALUE_HERE }, // number - the discount to be deducted from the subscription price
expiresIn: { PUT_EXPIRATION_TIME_HERE }, // (Optional) Set 0 for discount to never expire. Else set number of seconds to append to unix timestamp at time of creation.
}, // number - the discount in percent
});

console.log(discount.returnValue) // response is of type ABIResult
console.log(discount.txID); // response is of type string

// ... rest of your code
```
Expand All @@ -158,10 +148,9 @@ console.log(discount.returnValue) // response is of type ABIResult
```ts
// ... your code

const discount = await SubtopiaClient.getDiscountRecordForType(
client,
{ PUT_PRODUCT_ID_HERE }
{ PUT_EXPIRATION_TYPE_HERE },
const discount = await subtopiaRegistryClient.getDiscount(
productID: { PUT_PRODUCT_ID_HERE },
duration: { PUT_DURATION_HERE },
);

// DiscountRecord (throws Error if not found)
Expand All @@ -174,21 +163,12 @@ console.log(discount);
```ts
// ... your code

const deleteResult = await SubtopiaClient.deleteDiscount(
{
creator: {
address: { PUT_SUBSCRIBER_ADDRESS },
signer: { PUT_SUBSCRIBER_SIGNER },
},
smiID: { PUT_INFRASTRUCTURE_ID },
duration: { PUT_EXPIRATION_TYPE_HERE },
},
{
client: { PUT_ALGOD_CLIENT },
}
);
const deleteResult = await subtopiaRegistryClient.deleteDiscount({
productID: { PUT_PRODUCT_ID },
duration: { PUT_DURATION_HERE },
});

// ID of the deleted discount ASA txn
// Transaction ID of the delete discount transaction
console.log(deleteResult.txID);
// ... your code
```
Expand Down
Loading

0 comments on commit 7e4ae6f

Please sign in to comment.