### Add and Run an Example Source: https://github.com/snag-solutions/typescript-sdk/blob/main/CONTRIBUTING.md Add new example files to the `examples/` directory and execute them using `yarn tsn`. ```ts // add an example to examples/.ts #!/usr/bin/env -S npm run tsn -T … ``` ```sh $ chmod +x examples/.ts # run the example against your api $ yarn tsn -T examples/.ts ``` -------------------------------- ### Install Dependencies and Build Project Source: https://github.com/snag-solutions/typescript-sdk/blob/main/CONTRIBUTING.md Run these commands to install all necessary dependencies and build the project output files. ```sh $ yarn $ yarn build ``` -------------------------------- ### Install from Git Source: https://github.com/snag-solutions/typescript-sdk/blob/main/CONTRIBUTING.md Install the repository directly from a Git URL using npm. ```sh $ npm install git+ssh://git@github.com:stainless-sdks/snag-solutions-typescript.git ``` -------------------------------- ### Install Snag Solutions TypeScript SDK Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Install the SDK directly from the Git repository. This is a temporary installation method until the package is published to npm. ```sh npm install git+ssh://git@github.com:stainless-sdks/snag-solutions-typescript.git ``` -------------------------------- ### Mock Server Setup Source: https://github.com/snag-solutions/typescript-sdk/blob/main/CONTRIBUTING.md Set up a mock server using Prism against your OpenAPI specification to run tests. ```sh $ npx prism mock path/to/your/openapi.yml ``` -------------------------------- ### Initiate OAuth Authentication Flow Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use this to start an OAuth authentication flow for services like Twitter or Discord. It returns a redirect URL or an authentication token. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const authResponse = await client.auth.connectAuth('twitter', { organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', redirectUrl: 'https://myapp.com/auth/callback', }); console.log('Redirect user to:', authResponse); ``` -------------------------------- ### client.users.list Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Lists users. This method corresponds to the GET /api/users endpoint. ```APIDOC ## GET /api/users ### Description Lists users. ### Method GET ### Endpoint /api/users ### Request Body - **params** (object) - Required - Parameters for listing users. ### Response #### Success Response (200) - **UserListResponse** (object) - The response object containing a list of users. ``` -------------------------------- ### List Loyalty Accounts and Retrieve Rank Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use `client.loyalty.accounts.list` to retrieve the loyalty leaderboard and `retrieveRank` to get a specific user's standing within a loyalty currency. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // Leaderboard const { data } = await client.loyalty.accounts.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', loyaltyCurrencyId: '456e1234-e89b-12d3-a456-426614174003', limit: 10, }); // Get rank for a specific account const rankData = await client.loyalty.accounts.retrieveRank( 'account-uuid', { loyaltyCurrencyId: '456e1234-e89b-12d3-a456-426614174003', websiteId: '123e4567-e89b-12d3-a456-426614174000', }, ); console.log('User rank:', rankData); ``` -------------------------------- ### client.users.count Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Counts users. This method corresponds to the GET /api/users/count endpoint. ```APIDOC ## GET /api/users/count ### Description Counts users. ### Method GET ### Endpoint /api/users/count ### Request Body - **params** (object) - Required - Parameters for counting users. ### Response #### Success Response (200) - **UserCountResponse** (object) - The response object containing the user count. ``` -------------------------------- ### Initialize SnagSolutions Client and Create Asset Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Initialize the client with an API key and create a new asset. The API key can be omitted if it's the default. The response contains a signed URL for the asset. ```js import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env['X_API_KEY'], // This is the default and can be omitted }); const response = await client.assets.createAsset({ fileName: 'REPLACE_ME', fileSize: 1024 }); console.log(response.signedUrl); ``` -------------------------------- ### client.auctions.listAuctions Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Lists all auctions. This method corresponds to the GET /api/auctions endpoint. ```APIDOC ## GET /api/auctions ### Description Lists all auctions. ### Method GET ### Endpoint /api/auctions ### Response #### Success Response (200) - **AuctionListAuctionsResponse** (object) - The response object containing a list of auctions. ``` -------------------------------- ### Initialize SnagSolutions Client Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Instantiate the client with an API key. The API key can be provided directly or read from the X_API_KEY environment variable. Options for timeout, retries, base URL, logging, and custom fetch can be configured. ```typescript import SnagSolutions from '@snagsolutions/sdk'; // Basic initialization using environment variable X_API_KEY const client = new SnagSolutions({ apiKey: 'my-api-key', // or set X_API_KEY env var baseURL: 'https://admin.snagsolutions.io/', // default timeout: 30_000, // 30 seconds (default: 60 seconds) maxRetries: 3, // default: 2 logLevel: 'debug', // 'debug' | 'info' | 'warn' | 'error' | 'off' }); // Clone a client with different options per-request context const sandboxClient = client.withOptions({ baseURL: 'https://sandbox.snagsolutions.io/' }); // Access raw response headers const { data: response, response: raw } = await client.assets .createAsset({ fileName: 'logo.png', fileSize: 2048 }) .withResponse(); console.log(raw.headers.get('X-Request-Id')); console.log(response.signedUrl); ``` -------------------------------- ### Client Initialization Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Instantiate the SnagSolutions client with an API key. Options include timeout, maxRetries, baseURL, logLevel, logger, and custom fetch. You can also clone a client with different options for per-request context. ```APIDOC ## Client Initialization Instantiate the `SnagSolutions` client with an API key. The key is read from `process.env['X_API_KEY']` by default. Options include `timeout`, `maxRetries`, `baseURL`, `logLevel`, `logger`, and custom `fetch`. ```ts import SnagSolutions from '@snagsolutions/sdk'; // Basic initialization using environment variable X_API_KEY const client = new SnagSolutions({ apiKey: 'my-api-key', // or set X_API_KEY env var baseURL: 'https://admin.snagsolutions.io/', // default timeout: 30_000, // 30 seconds (default: 60 seconds) maxRetries: 3, // default: 2 logLevel: 'debug', // 'debug' | 'info' | 'warn' | 'error' | 'off' }); // Clone a client with different options per-request context const sandboxClient = client.withOptions({ baseURL: 'https://sandbox.snagsolutions.io/' }); // Access raw response headers const { data: response, response: raw } = await client.assets .createAsset({ fileName: 'logo.png', fileSize: 2048 }) .withResponse(); console.log(raw.headers.get('X-Request-Id')); console.log(response.signedUrl); ``` ``` -------------------------------- ### client.auctions.listAuctionBids Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Lists auction bids. This method corresponds to the GET /api/auction_bids endpoint. ```APIDOC ## GET /api/auction_bids ### Description Lists auction bids. ### Method GET ### Endpoint /api/auction_bids ### Request Body - **params** (object) - Required - Parameters for listing auction bids. ### Response #### Success Response (200) - **AuctionListAuctionBidsResponse** (object) - The response object containing a list of auction bids. ``` -------------------------------- ### client.auctions.websiteUserAttributes.list Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Lists website user attributes. This method corresponds to the GET /api/website_user_attributes endpoint. ```APIDOC ## GET /api/website_user_attributes ### Description Lists website user attributes. ### Method GET ### Endpoint /api/website_user_attributes ### Request Body - **params** (object) - Required - Parameters for listing website user attributes. ### Response #### Success Response (200) - **WebsiteUserAttributeListResponse** (object) - The response object containing a list of website user attributes. ``` -------------------------------- ### Run Tests Source: https://github.com/snag-solutions/typescript-sdk/blob/main/CONTRIBUTING.md Execute the project's test suite. ```sh $ yarn run test ``` -------------------------------- ### client.auctions.getPageSections Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Retrieves page sections for auctions. This method corresponds to the GET /api/page_sections endpoint. ```APIDOC ## GET /api/page_sections ### Description Retrieves page sections for auctions. ### Method GET ### Endpoint /api/page_sections ### Request Body - **params** (object) - Required - Parameters for retrieving page sections. ### Response #### Success Response (200) - **AuctionGetPageSectionsResponse** (object) - The response object containing page sections. ``` -------------------------------- ### Configure Proxy with Deno Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Configure proxy behavior for Deno environments by creating a `Deno.HttpClient` with proxy settings and passing it as the `client` option within `fetchOptions`. This leverages Deno's built-in HTTP client capabilities. ```typescript import SnagSolutions from 'npm:@snagsolutions/sdk'; const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } }); const client = new SnagSolutions({ fetchOptions: { client: httpClient, }, }); ``` -------------------------------- ### Create and List User Metadata Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use `client.users.metadatas.create` to add profile information for a user and `client.users.metadatas.list` to retrieve it. Ensure you have the necessary user, website, and organization IDs. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // Create metadata for a user const created = await client.users.metadatas.create({ userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', websiteId: '123e4567-e89b-12d3-a456-426614174000', organizationId: '123e4567-e89b-12d3-a456-426614174001', displayName: 'CryptoArtist', bio: 'NFT creator and collector', twitterUser: 'cryptoartist', discordUser: 'cryptoartist#1234', }); // List metadata for filtering const { data } = await client.users.metadatas.list({ userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); console.log(data[0].displayName); ``` -------------------------------- ### client.auctions.websiteUserAttributes.values.list Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Lists values for website user attributes. This method corresponds to the GET /api/website_user_attributes/values endpoint. ```APIDOC ## GET /api/website_user_attributes/values ### Description Lists values for website user attributes. ### Method GET ### Endpoint /api/website_user_attributes/values ### Request Body - **params** (object) - Required - Parameters for listing values. ### Response #### Success Response (200) - **ValueListResponse** (object) - The response object containing a list of values. ``` -------------------------------- ### Create and List Websites Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use this to create new websites (projects) within an organization or to list existing websites. Requires an organization ID. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const website = await client.websites.create({ name: 'My NFT Project', organizationId: '123e4567-e89b-12d3-a456-426614174001', domain: 'mynftproject.com', }); const { data } = await client.websites.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', }); console.log(data.map(w => w.name)); ``` -------------------------------- ### Get Token Claim Proof Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Retrieves the proof for a specific token claim ID. Optional parameters can be provided. ```APIDOC ## GET /api/token_claims/{id}/proof ### Description Retrieves the proof associated with a specific token claim. ### Method GET ### Endpoint /api/token_claims/{id}/proof ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the token claim. #### Query Parameters - **params** (object) - Optional - Additional parameters for retrieving the proof. ``` -------------------------------- ### Websites Create Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Creates a new website. ```APIDOC ## POST /api/websites ### Description Creates a new website. ### Method POST ### Endpoint /api/websites ### Parameters #### Query Parameters - **params** (object) - Required - Parameters for the request. ### Response #### Success Response (200) - **WebsiteCreateResponse** (object) - The response containing the created website information. ``` -------------------------------- ### client.auth.connectAuth Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Connects authentication for a given auth type. This method corresponds to the GET /api/{authType}/auth endpoint. ```APIDOC ## GET /api/{authType}/auth ### Description Connects authentication for a given auth type. ### Method GET ### Endpoint /api/{authType}/auth ### Parameters #### Path Parameters - **authType** (string) - Required - The type of authentication. #### Request Body - **params** (object) - Required - Parameters for authentication connection. ### Response #### Success Response (200) - **AuthConnectAuthResponse** (object) - The response object for authentication connection. ``` -------------------------------- ### Instantiate Client with Fetch Options Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Provide a `fetchOptions` object when instantiating the client to set custom fetch options. Request-specific options will override client options. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ fetchOptions: { // `RequestInit` options }, }); ``` -------------------------------- ### Loyalty Transactions Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Reset all loyalty currency balances for a website, which is useful for events like season resets or starting fresh. ```APIDOC ## Loyalty Transactions — `client.loyalty.transactions.resetLoyaltyCurrency` Reset all loyalty currency balances for a website, useful for season resets or fresh starts. ```ts import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const result = await client.loyalty.transactions.resetLoyaltyCurrency({ loyaltyCurrencyId: '123e4567-e89b-12d3-a456-426614174000', type: 'loyalty_reset_balances', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); console.log('Reset result:', result); ``` ``` -------------------------------- ### Users Create Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Creates a new user. ```APIDOC ## POST /api/referral/users ### Description Creates a new user. ### Method POST ### Endpoint /api/referral/users ### Parameters #### Query Parameters - **params** (object) - Required - Parameters for the request. ### Response #### Success Response (200) - **UserCreateResponse** (object) - The response containing the created user information. ``` -------------------------------- ### Configure Proxy with Bun Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Configure proxy behavior for Bun environments by setting the `proxy` option within `fetchOptions`. This is a straightforward way to enable proxying for requests made with the SDK. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ fetchOptions: { proxy: 'http://localhost:8888', }, }); ``` -------------------------------- ### Retrieve and Update Minting Status Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use this to get the current minting status of an asset or to update its status and transaction hash. Requires the asset ID. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const status = await client.minting.status.retrieve('minting-asset-id'); console.log('Current status:', status); const updated = await client.minting.status.update('minting-asset-id', { status: 'minted', transactionHash: '0xdeadbeef...', }); ``` -------------------------------- ### Create and List Loyalty Currencies Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use this to create new point systems for your website and list existing ones. Ensure organization and website IDs are correctly provided. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const currency = await client.loyalty.currencies.create({ name: 'Diamond Points', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', symbol: 'DP', }); const { data } = await client.loyalty.currencies.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); console.log(data.map(c => `${c.name} (${c.id})`)); ``` -------------------------------- ### client.users.createDevice Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Creates a device for a user. This method corresponds to the POST /api/users/devices endpoint. ```APIDOC ## POST /api/users/devices ### Description Creates a device for a user. ### Method POST ### Endpoint /api/users/devices ### Request Body - **params** (object) - Required - Parameters for creating a user device. ### Response #### Success Response (200) - **UserCreateDeviceResponse** (object) - The response object for user device creation. ``` -------------------------------- ### Add Undocumented Request Parameters Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Use // @ts-expect-error to add undocumented parameters to requests. Extra parameters are sent as-is in the query for GET requests or body for others. ```typescript client.assets.createAsset({ // ... // @ts-expect-error baz is not yet public baz: 'undocumented option', }); ``` -------------------------------- ### Link Local Repository with pnpm Source: https://github.com/snag-solutions/typescript-sdk/blob/main/CONTRIBUTING.md Link a local clone of the repository to your project using pnpm for development. ```sh # With pnpm $ pnpm link --global $ cd ../my-package $ pnpm link -—global @snagsolutions/sdk ``` -------------------------------- ### Get Loyalty Rule Status Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Returns the processing status and progress (0–100) of queued rule completions for a user. Status values: `pending`, `processing`, `completed`, `failed`. ```APIDOC ## Loyalty Rules — `client.loyalty.rules.getStatus` Returns the processing status and progress (0–100) of queued rule completions for a user. Status values: `pending`, `processing`, `completed`, `failed`. ```ts import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const { data } = await client.loyalty.rules.getStatus({ userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', websiteId: '123e4567-e89b-12d3-a456-426614174000', loyaltyRuleId: ['rule-id-1', 'rule-id-2'], }); for (const entry of data) { console.log(`Rule ${entry.loyaltyRuleId}: ${entry.status} (${entry.progress}%)`); if (entry.message) console.log('Message:', entry.message); // Example messages: 'Quest Completed: You are a follower of @snagsolutions' // 'Quest Not Completed: Please follow @snagsolutions' } ``` ``` -------------------------------- ### Configure package.json for Bun Source: https://github.com/snag-solutions/typescript-sdk/blob/main/MIGRATION.md Include the '@types/bun' dependency in your package.json for Bun environments. A version of '>= 1.2.0' is recommended. ```json { "devDependencies": { "@types/bun": ">= 1.2.0" } } ``` -------------------------------- ### Make Undocumented HTTP Requests Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Use client.get, client.post, etc., for undocumented endpoints. Options like retries are respected. Extra parameters for GET requests go to query, others to body. ```typescript await client.post('/some/path', { body: { some_prop: 'foo' }, query: { some_query_arg: 'bar' }, }); ``` -------------------------------- ### Replace httpAgent with fetchOptions for Proxy Support Source: https://github.com/snag-solutions/typescript-sdk/blob/main/MIGRATION.md Migrate from using `httpAgent` to `fetchOptions` with `undici.ProxyAgent` for proxy configuration. This is necessary because `httpAgent` is not supported by built-in fetch implementations. ```typescript import SnagSolutions from '@snagsolutions/sdk'; import http from 'http'; import { HttpsProxyAgent } from 'https-proxy-agent'; // Configure the default for all requests: const client = new SnagSolutions({ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL), }); ``` ```typescript import SnagSolutions from '@snagsolutions/sdk'; import * as undici from 'undici'; const proxyAgent = new undici.ProxyAgent(process.env.PROXY_URL); const client = new SnagSolutions({ fetchOptions: { dispatcher: proxyAgent, }, }); ``` -------------------------------- ### Get Loyalty Rule Completion Status Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use `client.loyalty.rules.getStatus` to check the processing status and progress of queued rule completions for a user. Statuses include `pending`, `processing`, `completed`, and `failed`. You can query multiple rule IDs at once. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const { data } = await client.loyalty.rules.getStatus({ userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', websiteId: '123e4567-e89b-12d3-a456-426614174000', loyaltyRuleId: ['rule-id-1', 'rule-id-2'], }); for (const entry of data) { console.log(`Rule ${entry.loyaltyRuleId}: ${entry.status} (${entry.progress}%)`); if (entry.message) console.log('Message:', entry.message); // Example messages: 'Quest Completed: You are a follower of @snagsolutions' // 'Quest Not Completed: Please follow @snagsolutions' } ``` -------------------------------- ### Link Local Repository with Yarn Source: https://github.com/snag-solutions/typescript-sdk/blob/main/CONTRIBUTING.md Link a local clone of the repository to your project using Yarn for development. ```sh # Clone $ git clone https://www.github.com/stainless-sdks/snag-solutions-typescript $ cd snag-solutions-typescript # With yarn $ yarn link $ cd ../my-package $ yarn link @snagsolutions/sdk ``` -------------------------------- ### Access Raw Response Data with .asResponse() and .withResponse() Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Use .asResponse() to access the raw Response object without consuming the body, or .withResponse() to get both the raw Response and parsed data. Useful for custom parsing or streaming. ```typescript const client = new SnagSolutions(); const response = await client.assets .createAsset({ fileName: 'REPLACE_ME', fileSize: 1024 }) .asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object const { data: response, response: raw } = await client.assets .createAsset({ fileName: 'REPLACE_ME', fileSize: 1024 }) .withResponse(); console.log(raw.headers.get('X-My-Header')); console.log(response.signedUrl); ``` -------------------------------- ### Configure package.json for Node.js Source: https://github.com/snag-solutions/typescript-sdk/blob/main/MIGRATION.md Ensure your package.json includes the appropriate `@types/node` dependency for Node.js environments. A version of '>= 20' is recommended. ```json { "devDependencies": { "@types/node": ">= 20" } } ``` -------------------------------- ### Manage Auctions and Bids Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt This code demonstrates how to list all auctions, retrieve bids for a specific auction, and fetch page sections for auction display. Ensure correct IDs and parameters are provided for each function. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // List all auctions const auctions = await client.auctions.listAuctions(); // List bids for a specific auction const bids = await client.auctions.listAuctionBids({ auctionId: 'auction-uuid', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', limit: 20, }); // Get page sections (for UI rendering) const sections = await client.auctions.getPageSections({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); ``` -------------------------------- ### WebsiteCollections Create Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Creates a new website collection. ```APIDOC ## POST /api/website_collections ### Description Creates a new website collection. ### Method POST ### Endpoint /api/website_collections ### Parameters #### Query Parameters - **params** (object) - Required - Parameters for the request. ### Response #### Success Response (200) - **void** - Indicates successful creation. ``` -------------------------------- ### Websites List Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Retrieves a list of websites. ```APIDOC ## GET /api/websites ### Description Retrieves a list of websites. ### Method GET ### Endpoint /api/websites ### Parameters #### Query Parameters - **params** (object) - Required - Parameters for the request. ### Response #### Success Response (200) - **WebsiteListResponse** (object) - The response containing the list of websites. ``` -------------------------------- ### Create and Fetch Loyalty Transactions Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Manually create loyalty transactions with `client.loyalty.transactions.createTransaction` to credit or debit user balances. Fetch transaction history using `getTransactionEntries`. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const tx = await client.loyalty.transactions.createTransaction({ description: 'Manual bonus for customer support interaction', entries: [ { amount: 500, loyaltyCurrencyId: '456e1234-e89b-12d3-a456-426614174003', userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', }, ], organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); console.log('Transaction ID:', tx.id); console.log('Created at:', tx.createdAt); // Fetch transaction history for a user const entries = await client.loyalty.transactions.getTransactionEntries({ userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', websiteId: '123e4567-e89b-12d3-a456-426614174000', limit: 20, }); ``` -------------------------------- ### Websites Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Create and list websites (projects) within an organization. ```APIDOC ## Websites — `client.websites` Create and list websites (projects) within an organization. ```ts import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const website = await client.websites.create({ name: 'My NFT Project', organizationId: '123e4567-e89b-12d3-a456-426614174001', domain: 'mynftproject.com', }); const { data } = await client.websites.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', }); console.log(data.map(w => w.name)); ``` ``` -------------------------------- ### Create and Manage Referral Codes and Users Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Generate referral codes for users and manage referral relationships by creating associations or listing referred users. Requires user, organization, and website IDs. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // Create a referral code for a user const { code } = await client.referral.createCode({ userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); console.log('Share this code:', code); // Register a new user under a referral await client.referral.users.create({ referralCode: code, userId: 'new-user-uuid', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); // List users referred by a code const { data } = await client.referral.users.list({ referralCode: code, organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); ``` -------------------------------- ### Configure Proxy with Node.js (undici) Source: https://github.com/snag-solutions/typescript-sdk/blob/main/README.md Configure proxy behavior for Node.js environments by providing custom `fetchOptions` with an `undici.ProxyAgent`. This allows runtime-specific proxy options to be added to requests. ```typescript import SnagSolutions from '@snagsolutions/sdk'; import * as undici from 'undici'; const proxyAgent = new undici.ProxyAgent('http://localhost:8888'); const client = new SnagSolutions({ fetchOptions: { dispatcher: proxyAgent, }, }); ``` -------------------------------- ### Assets — client.assets.createAsset Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Generates a presigned S3 URL for uploading a file and returns both the presigned URL and the resulting public asset URL. After calling this endpoint, PUT the file binary to `signedUrl`. Supports images (up to 1 MB) and videos (up to 10 MB) across several path categories. ```APIDOC ## Assets — `client.assets.createAsset` Generates a presigned S3 URL for uploading a file and returns both the presigned URL and the resulting public asset URL. After calling this endpoint, PUT the file binary to `signedUrl`. Supports images (up to 1 MB) and videos (up to 10 MB) across several path categories. ```ts import SnagSolutions from '@snagsolutions/sdk'; import fs from 'node:fs'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // Step 1: Get presigned upload URL const { signedUrl, url } = await client.assets.createAsset({ fileName: 'banner.png', fileSize: 204800, // 200 KB in bytes filePath: 'banners', // 'images'|'videos'|'banners'|'fonts'|'posts'|'profiles'|'minting'|'loyalty'|'tokenClaims' organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); // Step 2: Upload the file using the presigned URL const fileBuffer = fs.readFileSync('./banner.png'); await fetch(signedUrl, { method: 'PUT', body: fileBuffer, headers: { 'Content-Type': 'image/png' }, }); console.log('File publicly accessible at:', url); // Output: { signedUrl: 'https://s3.amazonaws.com/...', url: 'https://cdn.snagsolutions.io/banners/banner.png' } ``` ``` -------------------------------- ### List Users with Filtering and Pagination Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Retrieves a paginated list of users, allowing filtering by various criteria such as wallet address, social accounts, user ID, organization, or website. Supports cursor-based pagination using `startingAfter`. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const { data, hasNextPage } = await client.users.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', limit: 50, twitterUser: 'vitalikbuterin', includeDelegation: true, }); for (const user of data) { console.log(user.id, user.walletAddress, user.userMetadata?.[0]?.twitterUser); } // Paginate to next page if (hasNextPage) { const nextPage = await client.users.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', startingAfter: data[data.length - 1].id, limit: 50, }); } ``` -------------------------------- ### Access Resource Classes Correctly Source: https://github.com/snag-solutions/typescript-sdk/blob/main/MIGRATION.md Resource classes like `Assets` are no longer directly importable from the package root. Reference them as static class properties or import them directly from their respective files. ```javascript // Before const { Assets } = require('@snagsolutions/sdk'); ``` ```javascript // After const { SnagSolutions } = require('@snagsolutions/sdk'); SnagSolutions.Assets; // or import directly from @snagsolutions/sdk/resources/assets ``` -------------------------------- ### Manage Loyalty Quiz Questions and Responses Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Create quiz/poll questions for loyalty rules and submit or list user responses. Ensure correct IDs for questions, choices, and users are used. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // Create a quiz question const question = await client.loyalty.questions.create({ text: 'What is the native token of Ethereum?', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', loyaltyRuleId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', choices: [ { text: 'ETH', isCorrect: true }, { text: 'BTC', isCorrect: false }, { text: 'SOL', isCorrect: false }, ], }); // Submit a response await client.loyalty.questionsResponses.submit({ loyaltyQuestionId: question.id, loyaltyQuestionChoiceId: 'correct-choice-uuid', userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); // List responses const { data } = await client.loyalty.questionsResponses.list({ loyaltyQuestionId: question.id, organizationId: '123e4567-e89b-12d3-a456-426614174001', }); ``` -------------------------------- ### client.users.connect Source: https://github.com/snag-solutions/typescript-sdk/blob/main/api.md Connects a user. This method corresponds to the POST /api/users/connect endpoint. ```APIDOC ## POST /api/users/connect ### Description Connects a user. ### Method POST ### Endpoint /api/users/connect ### Request Body - **params** (object) - Required - Parameters for connecting a user. ### Response #### Success Response (200) - **UserConnectResponse** (object) - The response object for user connection. ``` -------------------------------- ### Create a Loyalty Rule Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use `client.loyalty.rules.create` to define how users earn points or badges. This function supports over 60 rule types and various frequency options. Ensure `loyaltyCurrencyId`, `organizationId`, and `websiteId` are provided. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const rule = await client.loyalty.rules.create({ name: 'Follow on Twitter', type: 'twitter_follow', amount: 100, frequency: 'once', loyaltyCurrencyId: '456e1234-e89b-12d3-a456-426614174003', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', startTime: '2024-01-01T00:00:00Z', endTime: null, effectiveStartTime: '2024-01-01T00:00:00Z', effectiveEndTime: null, metadata: { twitterAccountUrl: 'https://twitter.com/snagsolutions', twitterUserId: '123456789', twitterUsername: 'snagsolutions', }, rewardType: 'points', description: 'Earn 100 points for following @snagsolutions on X', }); console.log('Created rule ID:', rule.id); console.log('Rule type:', rule.type); console.log('Reward amount:', rule.amount); ``` -------------------------------- ### List and Assign Website User Roles Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use this to list available roles for a website and assign specific roles to users. Ensure organizationId and websiteId are correctly set. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // List available roles const { data } = await client.websites.websiteUserRoles.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); // Assign a role to a user await client.websites.websiteUserRoles.assign({ roleId: data[0].id, userId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); ``` -------------------------------- ### Create and List Website NFT Collections Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Use this to associate NFT collections with a website or to list existing collections for a website. Requires collection address, network, organization ID, and website ID. ```typescript import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); await client.websites.websiteCollections.create({ collectionAddress: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d', network: 'mainnet', organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); const { data } = await client.websites.websiteCollections.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); ``` -------------------------------- ### Users - list Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Retrieves a paginated list of users, filterable by wallet address, social accounts, user ID, organization, or website. Supports cursor-based pagination via `startingAfter`. ```APIDOC ## Users — `client.users.list` ### Description Retrieves a paginated list of users, filterable by wallet address, social accounts (Twitter, Discord, Telegram, Steam, TikTok, etc.), user ID, organization, or website. Supports cursor-based pagination via `startingAfter`. ### Method ```ts client.users.list(options: { organizationId?: string; websiteId?: string; limit?: number; startingAfter?: string; twitterUser?: string; includeDelegation?: boolean; // ... other filter parameters }): Promise<{ data: User[]; hasNextPage: boolean }>; ``` ### Parameters #### Path Parameters None #### Query Parameters - **organizationId** (string) - Optional - The ID of the organization. - **websiteId** (string) - Optional - The ID of the website. - **limit** (number) - Optional - The maximum number of users to return per page. - **startingAfter** (string) - Optional - The ID of the last user from the previous page for cursor-based pagination. - **twitterUser** (string) - Optional - Filter users by their Twitter username. - **includeDelegation** (boolean) - Optional - Whether to include delegated users. ### Request Example ```ts import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); const { data, hasNextPage } = await client.users.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', limit: 50, twitterUser: 'vitalikbuterin', includeDelegation: true, }); for (const user of data) { console.log(user.id, user.walletAddress, user.userMetadata?.[0]?.twitterUser); } // Paginate to next page if (hasNextPage) { const nextPage = await client.users.list({ organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', startingAfter: data[data.length - 1].id, limit: 50, }); } ``` ### Response #### Success Response (200) - **data** (User[]) - An array of user objects. - **hasNextPage** (boolean) - Indicates if there are more pages of results. #### Response Example ```json { "data": [ { "id": "uuid", "walletAddress": "0x...", "userMetadata": [ { "twitterUser": "vitalikbuterin" } ] } ], "hasNextPage": true } ``` ``` -------------------------------- ### Minting Allowlist Source: https://context7.com/snag-solutions/typescript-sdk/llms.txt Manage minting allowlists — list eligible wallets and upsert (add/update) wallet entries. ```APIDOC ## Minting Allowlist — `client.minting.allowlist` Manage minting allowlists — list eligible wallets and upsert (add/update) wallet entries. ```ts import SnagSolutions from '@snagsolutions/sdk'; const client = new SnagSolutions({ apiKey: process.env.X_API_KEY! }); // Upsert allowlist entries await client.minting.allowlist.upsert({ mintingContractAssetId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', walletAddresses: [ '0x1234567890abcdef1234567890abcdef12345678', '0xabcdef1234567890abcdef1234567890abcdef12', ], organizationId: '123e4567-e89b-12d3-a456-426614174001', websiteId: '123e4567-e89b-12d3-a456-426614174000', }); // List current allowlist const { data } = await client.minting.allowlist.list({ mintingContractAssetId: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', organizationId: '123e4567-e89b-12d3-a456-426614174001', }); ``` ```