npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xpkit-sdk

v1.0.0

Published

Helper functions to interact with XPKit API endpoints.

Downloads

67

Readme

XPKit JavaScript SDK

CI status Required node version

Create and manage your resources using the XPKit JavaScript SDK.

Getting started

The SDK can be used on both the server and in the browser. Firstly authenticate with XPKit and create a client.

Application authentication

Application authentication assumes you are running on a server or have a way of securely protetcting your XPKit OAuth 2 client secret.

// JavaScript
import { setup } from 'xpkit-sdk';

const client = await setup({
    auth: {
        client_id: 'YOUR_CLIENT_ID',
        client_secret: 'YOUR_CLIENT_SECRET',
    },
    base_url: 'emea.xpkit.net',
    logging: false
});

// TypeScript
import { setup } from 'xpkit-sdk';
import type { XPKitClient, ClientOptions } from 'xpkit-sdk';

const options: ClientOptions = {
    auth: {
        client_id: 'YOUR_CLIENT_ID',
        client_secret: 'YOUR_CLIENT_SECRET',
    },
    base_url: 'emea.xpkit.net',
    logging: false
};
const client: XPKitClient = await setup(options);

User authentication

Typically used in the browser, this flow prompts users to login via a provider such as Google.

// Login page. Generate authentication URLs for your login buttons
import { generateLoginUrls } from 'xpkit-sdk';

const redirectUrl = 'https://example.com/callback'
const buttonLinks = await generateLoginUrls(options, ['google', 'apple'], redirectUrl);

// Callback page. Exchange authorization code for access token
import { exchangeCodeForToken } from 'xpkit-sdk';

const code = ''; // Available as a query param on callback URL
const state = ''; // Available as a query param on callback URL
const accessToken = await exchangeCodeForToken(options, code, state, redirectUrl)['access_token'];

// Finally create the client
const client = await setup({
    auth: {
        client_id: 'YOUR_CLIENT_ID',
        client_secret: '', // Always an empty string in user authentication
        access_token: accessToken
    },
    base_url: 'emea.xpkit.net',
    logging: false
})

Full example available here.

Managing resources

For each XPKit resource type there is a corresponding class. This class should be imported and the client object passed on construction.

import { Activities } from 'xpkit-sdk/resources';
const activities = new Activities(client);

Functions corresponding to XPKit endpoints can then be called. Here is a (TypeScript) example calling the list endpoint on the activities resource:

import type { GetQueryableResourcesRequest } from 'xpkit-sdk';

const filterOptions: GetQueryableResourcesRequest = {
    'payload.object_id': 'sdk-js',
};

try {
    const res = await activities.listActivities(filterOptions);
    for (let result of res.results) {
        console.log(`Activity ID: ${result['resource_id']}`);
    }
    console.log(`Activities matching lookup criteria: ${res.count}`);
} catch (err) {
    if (err instanceof XPKitError) {
        console.error(`Error: ${err.message}. Status code: ${err.code}. Full error: ${err.response}`);
    } else {
        console.error(`Error: ${err.message}.`);
    }
}

Examples

import { Profiles, Notifications, Exports, VCC } from 'xpkit-sdk/resources';
import fs from 'node:fs';

// Create a (Profiles) resource
const profiles = new Profiles(client);
const res = await profiles.createProfile(
    {
        'first_name': 'John',
        'last_name': 'Doe',
        'email': ['[email protected]']
    }
);

// Upload a file (Notifications)
const notifications = new Notifications(client);
const data = new File([fs.readFileSync('/path/to/template.html')], 'template.html'); // Node example
// const data = document.getElementById('template').files[0]; // Browser example
const res = await notifications.uploadTemplate(data);

// Download a CSV file (Exports)
const exports = new Exports(client);
const res = await exports.downloadExport('resource-id');

// Trigger an asynchronous task (VCC)
const vcc = new Vcc(client);
const data = new File([fs.readFileSync('/path/to/asset.png')], 'asset.png');
const res = await vcc.triggerTask(
    {
        'configuration_name': 'example',
        'data': data
    }
);
console.log(`Job ID: ${res.job_id}. Info: ${res.info}`);

Full list of available functions

Activities

Full docs here.

listActivities(filterOptions: GetQueryableResourcesRequest): Promise<XPKitResources>
readActivity(resourceId: string): Promise<XPKitResource>
createActivity(resource: ActivityRequest): Promise<XPKitResource>
replaceActivity(resourceId: string, resource: ActivityRequest): Promise<XPKitResource>
updateActivity(resourceId: string, resource: XPKitRequest): Promise<XPKitResource>
deleteActivity(resourceId: string): Promise<boolean>
createBulkActivities(resource: ActivitiesBulkRequest): Promise<XPKitAcknowledgement>

Alerts

Full docs here.

listDistributions(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readDistribution(resourceId: string): Promise<XPKitResource>
createDistribution(resource: AlertDistributionRequest): Promise<XPKitResource>
replaceDistribution(resourceId: string, resource: AlertDistributionRequest): Promise<XPKitResource>
deleteDistribution(resourceId: string): Promise<boolean>
triggerAlert(resource: AlertTriggerRequest): Promise<XPKitAcknowledgement>

Catalogue

Full docs here.

readCatalogue(resource: CatalogueRequest): Promise<XPKitResource>

Exports

Full docs here.

listExports(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readExport(resourceId: string): Promise<XPKitResource>
triggerExport(resource: ExportTriggerRequest): Promise<XPKitAcknowledgement>
downloadExport(resourceId: string): Promise<string> // Format: text/csv

Health

Full docs here

listServiceConfigurations(filterOptions: GetResourcesRequest): Promise<XPKitResources>
createServiceConfiguration(resource: HealthServiceRequest): Promise<XPKitResource>
readServiceConfiguration(resourceId: string): Promise<XPKitResource>
replaceServiceConfiguration(resourceId: string, resource: HealthServiceRequest): Promise<XPKitResource>
deleteServiceConfiguration(resourceId: string): Promise<boolean>
listApplicationConfigurations(filterOptions: GetResourcesRequest): Promise<XPKitResources>
createApplicationConfiguration(resource: HealthApplicationRequest): Promise<XPKitResource>
readApplicationConfiguration(resourceId: string): Promise<XPKitResource>
replaceApplicationConfiguration(resourceId: string, resource: HealthApplicationRequest): Promise<XPKitResource>
deleteApplicationConfiguration(resourceId: string): Promise<boolean>
checkinApplication(accountId: string, token: string): Promise<XPKitAcknowledgement>

Identifications

Full docs here

createIdentity(identityType: string, accountId: string, options: IdentificationFilterOptions): Promise<string | Blob>
encodeIdentity(identityType: string, accountId: string, data: string, options: IdentificationFilterOptions): Promise<Blob>
verifyIdentity(accountId: string, data: string): Promise<boolean>
listBatches(filterOptions: GetResourcesRequest): Promise<XPKitResources>
createBatch(identityType: string, resource: IdentificationsBatchRequest): Promise<XPKitResource>
downloadBatch(resourceId: string): Promise<Blob>
deleteBatch(identityType: string, resourceId: string): Promise<boolean>
listWalletConfigurations(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readWalletConfiguration(resourceId: string): Promise<XPKitResource>
createWalletConfiguration(configurationName: string): Promise<XPKitResource>
uploadWalletConfigurationFile(resourceId: string, fileKey: string, file: File): Promise<XPKitResource>
updateWalletConfiguration(resourceId: string, field: string, value: string): Promise<XPKitResource>
deleteWalletConfiguration(resourceId: string): Promise<boolean>
generateWalletPassFile(resource: IdentificationGenerateWalletRequest): Promise<XPKitResource>

Jobs

Full docs here.

listJobs(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readJob(resourceId: string): Promise<XPKitResource>

Moments

Full docs here.

listMoments(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readMoment(resourceId: string): Promise<XPKitResource>
createMoment(resource: MomentRequest): Promise<XPKitResource>
replaceMoment(resourceId: string, resource: MomentRequest): Promise<XPKitResource>
updateMoment(resourceId: string, resource: XPKitRequest): Promise<XPKitResource>
deleteMoment(resourceId: string): Promise<boolean>
duplicateMoments(resource: MomentsDuplicateRequest): Promise<XPKitAcknowledgement>

NFTs

Full docs here.

listConfigurations(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readConfiguration(resourceId: string): Promise<XPKitResource>
createConfiguration(resource: NftConfigurationRequest): Promise<XPKitResource>
replaceConfiguration(resourceId: string, resource: NftConfigurationRequest): Promise<XPKitResource>
deleteConfiguration(resourceId: string): Promise<boolean>
mintNft(resource: NftMintRequest): Promise<XPKitAcknowledgement>

Notifications

Full docs here.

listTemplates(filterOptions: GetResourcesRequest): Promise<XPKitResources>
uploadTemplate(template: File): Promise<XPKitResource>
listCampaigns(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readCampaign(resourceId: string): Promise<XPKitResource>
createCampaign(resource: NotificationCampaignRequest): Promise<XPKitResource>
replaceCampaign(resourceId: string, resource: NotificationCampaignRequest): Promise<XPKitResource>
updateCampaign(resourceId: string, resource: XPKitRequest): Promise<XPKitResource>
deleteCampaign(resourceId: string): Promise<boolean>
listScheduledCampaigns(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readScheduledCampaign(resourceId: string): Promise<XPKitResource>
cancelScheduledCampaign(resourceId: string): Promise<boolean>
triggerNotificaton(resource: NotificationTriggerRequest): Promise<XPKitAcknowledgement>

Profiles

Full docs here.

listProfiles(filterOptions: GetQueryableResourcesRequest): Promise<XPKitResources>
readProfile(resourceId: string): Promise<XPKitResource>
createProfile(resource: XPKitRequest): Promise<XPKitResource>
replaceProfile(resourceId: string, resource: XPKitRequest): Promise<XPKitResource>
updateProfile(resourceId: string, resource: XPKitRequest): Promise<XPKitResource>
deleteProfile(resourceId: string): Promise<boolean>
createOrUpdateProfile(resource: XPKitRequest): Promise<XPKitResource>
mergeProfiles(resource: ProfilesMergeRequest): Promise<XPKitAcknowledgement>
createBulkProfiles(resource: ProfilesBulkRequest): Promise<XPKitAcknowledgement>

Queues

Full docs here.

listQueues(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readQueue(resourceId: string): Promise<XPKitResource>
createQueue(resource: QueueRequest): Promise<XPKitResource>
replaceQueue(resourceId: string, resource: QueueRequest): Promise<XPKitResource>
updateQueue(resourceId: string, resource: XPKitRequest): Promise<XPKitResource>
deleteQueue(resourceId: string): Promise<boolean>
listQueueItems(queueId: string, filterOptions: GetResourcesRequest): Promise<XPKitResources>
readQueueItem(resourceId: string, queueId: string): Promise<XPKitResource>
createQueueItem(queueId: string, resource: QueueItemRequest): Promise<XPKitResource>
replaceQueueItem(resourceId: string, queueId: string, resource: QueueItemRequest): Promise<XPKitResource>
updateQueueItem(resourceId: string, queueId: string, resource: XPKitRequest): Promise<XPKitResource>
deleteQueueItem(resourceId: string, queueId: string): Promise<boolean>
readQueueGroupStats(queueId: string): Promise<object>

Resources

Full docs here.

listResources(resourceType: string, filterOptions: GetQueryableResourcesRequest): Promise<XPKitResources>
readResource(resourceId: string, resourceType: string): Promise<XPKitResource>
createResource(resourceType: string, resource: ResourceRequest): Promise<XPKitResource>
replaceResource(resourceId: string, resourceType: string, resource: ResourceRequest): Promise<XPKitResource>
updateResource(resourceId: string, resourceType: string, resource: XPKitRequest): Promise<XPKitResource>
deleteResource(resourceId: string, resourceType: string): Promise<boolean>
readResourceSummary(): Promise<object>

Social Auth

Full docs here.

listConfigurations(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readConfiguration(resourceId: string): Promise<XPKitResource>
createConfiguration(resource: SocialAuthRequest): Promise<XPKitResource>
replaceConfiguration(resourceId: string, resource: SocialAuthRequest): Promise<XPKitResource>
deleteConfiguration(resourceId: string): Promise<boolean>

Souvenirs

Full docs here.

listSouvenirs(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readSouvenir(resourceId: string): Promise<XPKitResource>
createSouvenir(resource: SouvenirRequest): Promise<XPKitResource>
replaceSouvenir(resourceId: string, resource: SouvenirRequest): Promise<XPKitResource>
updateSouvenir(resourceId: string, resource: XPKitRequest): Promise<XPKitResource>
deleteSouvenir(resourceId: string): Promise<boolean>
duplicateSouvenirs(resource: SouvenirsDuplicateRequest): Promise<XPKitAcknowledgement>

Users

Full docs here.

readUser(): Promise<XPKitResource>
updateUser(resource: UserUpdateRequest): Promise<XPKitResource>
inviteUserToAccount(resource: UserInviteRequest): Promise<XPKitResource>

VCC

Full docs here.

listConfigurations(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readConfiguration(resourceId: string): Promise<XPKitResource>
createConfiguration(resource: VccConfigurationRequest): Promise<XPKitResource>
replaceConfiguration(resourceId: string, resource: VccConfigurationRequest): Promise<XPKitResource>
deleteConfiguration(resourceId: string): Promise<boolean>
uploadAsset(asset: File): Promise<boolean>
triggerTask(resource: VccTriggerTaskRequest): Promise<XPKitAcknowledgement>
triggerTaskGroup(resource: VccTriggerTaskGroupRequest): Promise<XPKitAcknowledgement>
listTasks(filterOptions: GetResourcesRequest): Promise<XPKitResources>
readTask(resourceId: string): Promise<XPKitResource>
retriggerTask(resourceId: string): Promise<XPKitResource>
retriggerTasks(resourceIds: string[]): Promise<XPKitResource>
cancelTask(resourceId: string): Promise<XPKitResource>