* refactor(push): the database and key names are written once for the page and both workers pushNames.js holds the puter-push database name, its stores, key prefixes and the subscription-changed message. pushStore.js re-exports them. push-sw.js and the GUI's sw.js are served as they are (push-sw.js also from npm's src/), so neither can import the module. Each carries a block generated from pushNames.js by tools/pushWorkerNames.mjs. The puter.js webpack build and the GUI build fail while either block is stale, and a test compares the names in both worker sources with the page module's. * refactor(push): the desktop reads the confirmed endpoint and the mark through puter.js puter.js now records the endpoint the server confirmed, and clears the subscription-changed mark, inside the Puter GUI as on a website. Three internal methods give the desktop what it kept itself: _webPushRecord() reads both, _noteWebPushSynced() records an endpoint a status check confirmed, and _dropRemovedWebPush() ends a removed subscription and forgets its receipt and the mark. webPushClient.js no longer opens the puter-push database or keeps its own localStorage record. An endpoint an earlier build kept there is read while puter.js has none, and removed once puter.js records one, so an already synced browser keeps its status without registering again. With a puter.js that lacks the methods, the client reads nothing from it and keeps the old record. * refactor(push): one-line comments on the push names and the record methods * fix(push): the worker names check reads CRLF checkouts, lives in tools/ and runs in PR CI The block helper moves to tools/pushNamesBlock.mjs, so it isn't part of the published puter.js sources. It compares and rewrites on LF text and writes back the file's own line endings. Both workers are pinned to LF in .gitattributes. The puter.js tests run when the GUI's sw.js or its build changes, and the GUI build checks sw.js before anything else. * fix(push): the desktop keeps a removed browser off with a puter.js that has no push record The desktop loads puter.js from its own URL, so it can run one without _webPushRecord(). The client then uses pushStore.js's helpers itself: it reads and clears the subscription-changed mark, ends a removed subscription and forgets its receipt and the mark, clears the mark after enable(), and keeps the confirmed endpoint in localStorage as before. _noteWebPushSynced() resolves whether it recorded the endpoint, and the localStorage endpoint is removed only after puter.js has it. A cached status reads only the mark before answering. The accessors carry JSDoc types. * fix(push): the removed-elsewhere check also asks about the endpoint in localStorage When loads alternate between puter.js versions, localStorage can hold a newer confirmed endpoint than puter.js does. The background check now asks about both, with the mark's old endpoint, before registering. * fix(push): with an older puter.js the desktop also asks about the endpoint puter.js recorded Once puter.js has recorded the confirmed endpoint, the desktop drops its localStorage copy. A later load that runs an older puter.js then read neither, so a browser that lost its subscription after being removed in Puter could register again. The fallback now reads puter.js's record from the store directly. * refactor(puter-js): the push record reads use try/catch instead of .catch() --------- Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
Puter.js
Learn More · Docs · Tutorials · Examples · X
Puter.js gives you auth, cloud storage, database, AI, and more through a single JavaScript library. It is the go-to backend for AI-generated apps.
There is nothing to configure, no API keys, no infrastructure to set up, whether you write the code yourself or have your AI tool do it. Tools like Claude Code, Codex, OpenCode, Lovable, and Replit can generate complete, production-ready apps in a single shot with fewer AI tokens.
Installation
NPM:
npm install @heyputer/puter.js
CDN:
Include Puter.js directly in your HTML via CDN in the <head> section:
<script src="https://js.puter.com/v2/"></script>
Usage
Browser
ES Modules
import {puter} from '@heyputer/puter.js';
// or
import puter from '@heyputer/puter.js';
// or
import '@heyputer/puter.js'; // puter will be available globally
CommonJS
const {puter} = require('@heyputer/puter.js');
// or
const puter = require('@heyputer/puter.js');
// or
require('@heyputer/puter.js'); // puter will be available globally
Node.js (with Auth Token)
const {init} = require("@heyputer/puter.js/src/init.cjs"); // NODE JS ONLY
// or
import {init} from "@heyputer/puter.js/src/init.cjs";
const puter = init(process.env.puterAuthToken); // uses your auth token
const puter2 = init(process.env.puterAuthToken2); // use some other auth token
Node.js (with Auth Token + Web Login)
const {init, getAuthToken} = require("@heyputer/puter.js/src/init.cjs");
// or
import {init, getAuthToken} from "@heyputer/puter.js/src/init.cjs";
const authToken = await getAuthToken(); // performs browser based auth and retrieves token (requires browser)
const puter = init(authToken); // uses your auth token
Usage Example
After importing, you can use the global puter object:
// Print a message
puter.print('Hello from Puter.js!');
// Chat with GPT-5 nano
puter.ai.chat('What color was Napoleon\'s white horse?').then(response => {
puter.print(response);
});
Starter Templates
You can also use one of the following templates:
- Client-side projects: Angular, React, Next.js, Vue.js, Vanilla.js
- Node.js + Express: Node.js + Express template
Setting Custom Origins
By default puter.js uses the official Puter API and GUI origins. You can customize these origins by setting global variables before importing the SDK like so:
// For API origin
globalThis.PUTER_API_ORIGIN = 'https://custom-api.puter.com';
// For GUI origin
globalThis.PUTER_ORIGIN = 'https://custom-gui.puter.com';
import {puter} from '@heyputer/puter.js'; // or however you import it for your env
Documentation & Community
License
Apache-2.0