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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@towerai/web-foundation

v1.0.4

Published

TowerAI web foundation

Downloads

66

Readme

@towerai/web-foundation

TowerAI web foundation. It is aligned with the TowerAI backend contracts:

  • POST /api/v1/auth/login
  • POST /api/v1/auth/refresh-token
  • GET /api/v1/users/me
  • GET /api/v1/menus/routes
  • GET /api/v1/menus
  • POST /api/v1/files/upload-session
  • POST /api/v1/files/access-url
  • POST /api/v1/files/upload
  • POST /api/v1/files/complete
  • GET /api/v1/files/chunk/{uploadId}
  • POST /api/v1/files/chunk
  • DELETE /api/v1/files/chunk/{uploadId}
pnpm add @towerai/web-foundation

The Web Foundation package is framework agnostic. It does not depend on Vue, Pinia, Vue Router, Element Plus, or any app module.

Docs

Auth + HTTP

import {
  createAuthClient,
  createAuthSession,
  createAuthStore,
  createAuthTokenStorage,
  createCurrentUserClient,
  createHttpClient,
} from "@towerai/web-foundation";

const tokenStorage = createAuthTokenStorage({
  accessToken: "access_token",
  refreshToken: "refresh_token",
  rememberMe: "remember_me",
  username: "username",
  password: "password",
});

// By default, tokenStorage only persists the username for remembered login.
// If a project must persist password, pass { persistPassword: true } and
// provide its own encryption/storage policy at the application layer.

const request = createHttpClient({
  baseURL: "/api",
  appId: "tower-admin",
  deviceId: () => deviceId,
  resultCodes: {
    success: 200,
    accessTokenInvalid: 40101,
    refreshTokenInvalid: 40102,
  },
  tokenStorage,
  refreshToken: async () => authSession.refreshToken(),
  onAuthExpired: async () => {
    tokenStorage.clearAllAuth();
  },
  logger: {
    request(ctx) {
      console.debug("[request]", ctx.method, ctx.url);
    },
    response(ctx) {
      console.debug("[response]", ctx.method, ctx.url, ctx.status, ctx.duration);
    },
    error(ctx) {
      console.warn("[request:error]", ctx.method, ctx.url, ctx.status, ctx.msg);
    },
  },
});

const passwordSecretParts = [
  import.meta.env.VITE_APP_BIZ_SECRET_P1,
  import.meta.env.VITE_APP_BIZ_SECRET_P2,
];

const authClient = createAuthClient({
  request,
  passwordSecretParts,
});
const authSession = createAuthSession({ authClient, tokenStorage });
const currentUserClient = createCurrentUserClient({
  request,
  passwordSecretParts,
});

const user = await currentUserClient.getInfo();

const authStore = createAuthStore({
  authClient,
  currentUserClient,
  tokenStorage,
});

authStore.subscribe((state) => {
  console.log(state.currentUser, state.rememberMe);
});

await authStore.login({
  username: "admin",
  password: "123456",
  rememberMe: true,
});

Permission

import { hasPermission, hasRole } from "@towerai/web-foundation";

hasPermission(user, "sys:user:add");
hasRole(user, ["ADMIN", "TENANT_ADMIN"]);

Menu

import {
  createMenuClient,
  createModuleViewPathResolver,
  filterMenuTree,
  filterMenuTreeByPermission,
  flattenMenuTree,
  transformMenuRoutes,
} from "@towerai/web-foundation";

const menuClient = createMenuClient({ request });
const serverRoutes = await menuClient.getRoutes();

const visibleMenus = filterMenuTree(menus, (menu) => !menu.meta?.hidden);
const authorizedMenus = filterMenuTreeByPermission(visibleMenus, user);
const flatMenus = flattenMenuTree(visibleMenus);

const resolveComponentPath = createModuleViewPathResolver({
  moduleRoot: "/src/modules",
  viewDir: "views",
  mobileDir: "mobile",
  routeComponentPathMap: {
    "system/tenant/index": "tenant/tenant-manage/index",
  },
});

const routes = transformMenuRoutes(serverRoutes, {
  isMobile,
  layoutComponent,
  notFoundComponent,
  resolveComponentPath,
  resolveComponent: (path) => modules[path],
});

File

import {
  createFileClient,
  createFileUploader,
  downloadFile,
  resolvePreviewUrl,
  type FileInfo,
  type PageResult,
} from "@towerai/web-foundation";

const fileClient = createFileClient({
  request,
  baseUrl: "/api/v1/files",
});

const fileUploader = createFileUploader(fileClient, {
  defaultUploadMode: "direct",
  chunkedUploadThresholdMb: 50,
});

const uploaded = await fileUploader.uploadFile(file, {
  businessType: "avatar",
  onProgress: (percent) => console.log(percent),
});

const uploadResult = await fileClient.uploadFile(file, "design-source");
console.log(uploadResult.fileInfo, uploadResult.processResult);

const url = await resolvePreviewUrl("tenant/logo.png", fileClient);
await downloadFile({ objectKey: "tenant/logo.png", name: "logo.png" }, fileClient);

const page: PageResult<FileInfo[]> = {
  list: [uploaded],
  total: 1,
};

Watermark

import { createWatermark } from "@towerai/web-foundation";

const watermark = createWatermark({
  text: ["TowerAI", "tenant / username"],
});

watermark.update({ text: "new text" });
watermark.remove();