@offcoin/sdk
Advanced tools
| /** | ||
| * Permissions Resource | ||
| * API methods for managing purchasable permissions | ||
| */ | ||
| import type { HttpClient } from '../client.js'; | ||
| import type { Permission, PurchasePermissionResult, ListPermissionsOptions } from '../types.js'; | ||
| export declare class PermissionsResource { | ||
| private readonly client; | ||
| constructor(client: HttpClient); | ||
| /** | ||
| * List all purchasable permissions for the tenant | ||
| * @param options - Optional query parameters | ||
| * @param options.alias - If provided, includes whether member owns each permission | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // List all purchasable permissions | ||
| * const permissions = await offcoin.permissions.list(); | ||
| * | ||
| * // List with ownership info for a specific member | ||
| * const permissions = await offcoin.permissions.list({ alias: 'discord:123456' }); | ||
| * // Returns permissions with `owned` and `canPurchase` fields | ||
| * ``` | ||
| */ | ||
| list(options?: ListPermissionsOptions): Promise<Permission[]>; | ||
| /** | ||
| * Purchase a permission for a member | ||
| * @param alias - Member alias or ID | ||
| * @param permissionKey - The permission key to purchase | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = await offcoin.permissions.purchase('discord:123456', 'vip_access'); | ||
| * console.log(`Purchased ${result.permissionName} for ${result.tokenPrice} tokens`); | ||
| * console.log(`New balance: ${result.newBalance}`); | ||
| * ``` | ||
| */ | ||
| purchase(alias: string, permissionKey: string): Promise<PurchasePermissionResult>; | ||
| } |
| /** | ||
| * Permissions Resource | ||
| * API methods for managing purchasable permissions | ||
| */ | ||
| export class PermissionsResource { | ||
| client; | ||
| constructor(client) { | ||
| this.client = client; | ||
| } | ||
| /** | ||
| * List all purchasable permissions for the tenant | ||
| * @param options - Optional query parameters | ||
| * @param options.alias - If provided, includes whether member owns each permission | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // List all purchasable permissions | ||
| * const permissions = await offcoin.permissions.list(); | ||
| * | ||
| * // List with ownership info for a specific member | ||
| * const permissions = await offcoin.permissions.list({ alias: 'discord:123456' }); | ||
| * // Returns permissions with `owned` and `canPurchase` fields | ||
| * ``` | ||
| */ | ||
| list(options) { | ||
| const params = new URLSearchParams(); | ||
| if (options?.alias) { | ||
| params.set('alias', options.alias); | ||
| } | ||
| const query = params.toString(); | ||
| return this.client.get(`/api/v1/permissions${query ? `?${query}` : ''}`); | ||
| } | ||
| /** | ||
| * Purchase a permission for a member | ||
| * @param alias - Member alias or ID | ||
| * @param permissionKey - The permission key to purchase | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const result = await offcoin.permissions.purchase('discord:123456', 'vip_access'); | ||
| * console.log(`Purchased ${result.permissionName} for ${result.tokenPrice} tokens`); | ||
| * console.log(`New balance: ${result.newBalance}`); | ||
| * ``` | ||
| */ | ||
| purchase(alias, permissionKey) { | ||
| return this.client.post('/api/v1/permissions/purchase', { | ||
| alias, | ||
| permissionKey | ||
| }); | ||
| } | ||
| } |
+6
-1
@@ -8,2 +8,3 @@ /** | ||
| import { LeaderboardResource } from './resources/leaderboard.js'; | ||
| import { PermissionsResource } from './resources/permissions.js'; | ||
| import type { OffcoinClientOptions } from './types.js'; | ||
@@ -47,2 +48,6 @@ /** | ||
| /** | ||
| * Permissions API - list and purchase permissions | ||
| */ | ||
| readonly permissions: PermissionsResource; | ||
| /** | ||
| * Create a new Offcoin client | ||
@@ -56,3 +61,3 @@ * @param options - Client configuration | ||
| } | ||
| export type { OffcoinClientOptions, RetryOptions, Member, MemberBalance, MemberXp, TokenOperationResult, XpOperationResult, Achievement, UnlockResult, LeaderboardEntry, LeaderboardResponse, LeaderboardOptions, CreateMemberInput, UpdateMemberInput, MemberAlias, MemberAliasesResponse, AddAliasResult, RemoveAliasResult, ApiResponse } from './types.js'; | ||
| export type { OffcoinClientOptions, RetryOptions, Member, MemberBalance, MemberXp, TokenOperationResult, XpOperationResult, Achievement, UnlockResult, LeaderboardEntry, LeaderboardResponse, LeaderboardOptions, CreateMemberInput, UpdateMemberInput, MemberAlias, MemberAliasesResponse, AddAliasResult, RemoveAliasResult, Permission, PurchasePermissionResult, ListPermissionsOptions, ApiResponse } from './types.js'; | ||
| export { OffcoinError, AuthenticationError, NotFoundError, ValidationError, ForbiddenError, BadRequestError, InternalError, RateLimitedError, NetworkError } from './errors.js'; |
+6
-0
@@ -9,2 +9,3 @@ /** | ||
| import { LeaderboardResource } from './resources/leaderboard.js'; | ||
| import { PermissionsResource } from './resources/permissions.js'; | ||
| /** | ||
@@ -47,2 +48,6 @@ * Offcoin API Client | ||
| /** | ||
| * Permissions API - list and purchase permissions | ||
| */ | ||
| permissions; | ||
| /** | ||
| * Create a new Offcoin client | ||
@@ -59,2 +64,3 @@ * @param options - Client configuration | ||
| this.leaderboard = new LeaderboardResource(client); | ||
| this.permissions = new PermissionsResource(client); | ||
| } | ||
@@ -61,0 +67,0 @@ } |
+24
-0
@@ -21,2 +21,3 @@ /** | ||
| tokenBalance: number; | ||
| level: number; | ||
| createdAt: string; | ||
@@ -75,2 +76,25 @@ updatedAt: string; | ||
| } | ||
| export interface Permission { | ||
| id: string; | ||
| key: string; | ||
| name: string; | ||
| description: string | null; | ||
| tokenPrice: number; | ||
| purchaseRequiredLevel: number; | ||
| requiredLevel: number; | ||
| owned?: boolean; | ||
| canPurchase?: boolean; | ||
| } | ||
| export interface PurchasePermissionResult { | ||
| memberId: string; | ||
| permissionId: string; | ||
| permissionKey: string; | ||
| permissionName: string; | ||
| previousBalance: number; | ||
| newBalance: number; | ||
| tokenPrice: number; | ||
| } | ||
| export interface ListPermissionsOptions { | ||
| alias?: string; | ||
| } | ||
| export interface LeaderboardEntry { | ||
@@ -77,0 +101,0 @@ memberId: string; |
+5
-3
| { | ||
| "name": "@offcoin/sdk", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "description": "TypeScript/JavaScript SDK for the Offcoin API", | ||
@@ -16,3 +16,5 @@ "scripts": { | ||
| "test:unit": "vitest", | ||
| "test": "npm run test:unit -- --run" | ||
| "test": "npm run test:unit -- --run", | ||
| "npm:patch": "npm version patch", | ||
| "npm:publish": "pnpm build && npm publish --access public" | ||
| }, | ||
@@ -71,4 +73,4 @@ "files": [ | ||
| "type": "git", | ||
| "url": "https://github.com/your-org/offcoin" | ||
| "url": "https://github.com/mediakular/offcoin" | ||
| } | ||
| } |
+19
-1
@@ -113,2 +113,18 @@ # @offcoin/sdk | ||
| ### Permissions | ||
| ```typescript | ||
| // List all purchasable permissions | ||
| const permissions = await offcoin.permissions.list(); | ||
| // List permissions with ownership info for a specific member | ||
| const permissions = await offcoin.permissions.list({ alias: 'discord:123456' }); | ||
| // Returns permissions with `owned` and `canPurchase` fields | ||
| // Purchase a permission for a member | ||
| const result = await offcoin.permissions.purchase('discord:123456', 'vip_access'); | ||
| console.log(`Purchased ${result.permissionName} for ${result.tokenPrice} tokens`); | ||
| console.log(`New balance: ${result.newBalance}`); | ||
| ``` | ||
| ## Error Handling | ||
@@ -164,3 +180,5 @@ | ||
| XpOperationResult, | ||
| UnlockResult | ||
| UnlockResult, | ||
| Permission, | ||
| PurchasePermissionResult | ||
| } from '@offcoin/sdk'; | ||
@@ -167,0 +185,0 @@ ``` |
38202
14.93%18
12.5%957
15.02%205
9.63%