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

@epcc-sdk/sdks-files

v0.5.1

Published

A TypeScript client for the Elastic Path files API. The functions, types and Zod schemas are generated from the OpenAPI spec of the API.

Readme

@epcc-sdk/sdks-files

A TypeScript client for the Elastic Path files API. The functions, types and Zod schemas are generated from the OpenAPI spec of the API.

Installation

npm install @epcc-sdk/sdks-files

Quick start

import { createFilesClient, getAllFiles } from "@epcc-sdk/sdks-files"

const client = createFilesClient({
  baseUrl: "https://euwest.api.elasticpath.com",
  clientId: process.env.EPCC_CLIENT_ID!,
  clientSecret: process.env.EPCC_CLIENT_SECRET!,
})

const { data, error } = await getAllFiles({ client })

The client gets an access token and adds it to each request. It gets a new token before the token expires. After a 401 response, it gets a new token and sends the request one more time. After a 408 or 429 response, or after some server and network errors, it waits and sends the request again.

Pass the client to each operation. The package also exports a client that has no credentials. If you call an operation without { client }, it uses that client and the API returns a 401 response.

A failed request does not throw. The operation returns the error in error. To make operations throw, add config: { throwOnError: true } to the factory options.

Base URL

Set baseUrl to the API host of your region, with no path. Each operation adds its own path.

Credentials

| Option | Grant type | | ----------------------------- | ---------------------------------------------------------------------------------------- | | clientId and clientSecret | Client credentials. Use it only on a server, because it contains a secret. | | clientId | Implicit. You can use it in a browser. | | token | A token that you got yourself. The client cannot replace it, so a 401 response is final. | | provider | Your own TokenProvider function. | | source | A TokenSource that you keep, for example to clear the token when a user signs out. |

These options change the default behavior:

| Option | What it does | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | storage | Where the client keeps the token. The default is memoryStorage. localStorageAdapter keeps the token across page loads and browser tabs. | | leewaySeconds | How many seconds before expiry the client gets a new token. | | retry | The options of createRetryFetch. Set it to false to stop the retries. | | fetch | The fetch function that the client uses for all requests, including token requests. | | config | Client configuration, for example headers. It overrides the values that the factory sets. |

Upload a file

createAFile sends the file in a multipart request. Give the file as a File in body.file. The name of the File becomes the name of the file in Elastic Path.

import { readFile } from "node:fs/promises"
import { createAFile } from "@epcc-sdk/sdks-files"

const file = new File([await readFile("photo.png")], "photo.png", {
  type: "image/png",
})

const { data, error } = await createAFile({ client, body: { file } })

In a browser, use the File from an <input type="file"> element. In Node, File is global in version 20 and later.

For a file that is already at a URL, give the URL in body.file_location and do not send body.file.

Make the client yourself

The package exports the parts that the factory uses. Use them when you need your own token source or your own fetch.

import {
  clientCredentialsProvider,
  createAuthCallback,
  createAuthenticatedFetch,
  createClient,
  createConfig,
  createRetryFetch,
  createTokenSource,
} from "@epcc-sdk/sdks-files"

const source = createTokenSource(
  clientCredentialsProvider({
    baseUrl: "https://euwest.api.elasticpath.com",
    clientId: process.env.EPCC_CLIENT_ID!,
    clientSecret: process.env.EPCC_CLIENT_SECRET!,
  }),
)

const client = createClient(
  createConfig({
    baseUrl: "https://euwest.api.elasticpath.com",
    auth: createAuthCallback(source),
    fetch: createRetryFetch({ fetch: createAuthenticatedFetch(source) }),
  }),
)
  1. Make both wrappers from the same source. createAuthenticatedFetch replaces only a token that came from its own source.
  2. Put createAuthenticatedFetch inside createRetryFetch. In the other order, each retry sends the expired token again.

Do not add the token with a request interceptor. An interceptor cannot see the response, so it cannot get a new token after a 401 response.

Zod schemas

The ./zod export has a Zod schema for each request and response. zod 4 is an optional peer dependency, so the main export does not import it.

import { zGetAllFilesResponse } from "@epcc-sdk/sdks-files/zod"

const result = zGetAllFilesResponse.safeParse(data)

A field that the spec gives as int64 is a number in the types and in the schemas.

MCP tools

The ./mcp export has one Model Context Protocol (MCP) tool for each operation, for MCP SDK v2. You need zod 4 and @modelcontextprotocol/server 2 only for this export.

import { McpServer } from "@modelcontextprotocol/server"
import { tools } from "@epcc-sdk/sdks-files/mcp"

const server = new McpServer({ name: "files", version: "1.0.0" })

for (const tool of tools({ client })) {
  server.registerTool(tool.name, tool.config, tool.handler)
}
  • Each tool sends its requests with the client that you give it. To send a header with each request, such as EP-Store-Id, set it in config.headers of the client.
  • For one tool, use its factory. The name of the factory is the operation name with Tool added, for example getAllFilesTool.
  • The name of a tool is files_ and the operation name in snake case, for example files_get_all_files.
  • The arguments of a tool are in path, query, headers and body. The Authorization header comes from the client.
  • tool.config._meta["com.elasticpath/operation"].risk is read, create, update or delete. The tool annotations come from it. To register only the read tools, keep the tools where risk is read.
  • A tool returns an API error as an isError result. It does not throw.

files_create_a_file uploads a file. Give the file in file as a data: URI, for example data:<media type>;base64,<data>, and its name in file_name. The largest file is 8,388,608 bytes (8 MiB). The limit is the default limit of the API. If the file is larger, the URI is not valid, or the value is a URL, the tool returns an isError result and sends nothing. The tool never downloads a URL.