Skip to content

About

Headless TypeScript SDK for uploading files to Shopify Files through staged Admin GraphQL uploads.

Topics

Resources

Stars

25 stars

Watchers

1 watching

Forks

Repository files navigation

@weaverse/shopify-file-upload

Headless TypeScript SDK for uploading an image, video, or generic file to Shopify Files.

stagedUploadsCreate
→ upload binary directly to Shopify staged storage
→ fileCreate
→ poll fileStatus
→ READY | FAILED

The SDK never receives or stores Shopify credentials. Your app supplies an already-authenticated GraphQL executor.

Install

npm install @weaverse/shopify-file-upload

Server upload

import {createShopifyFileUpload} from '@weaverse/shopify-file-upload/server'

const files = createShopifyFileUpload({
  shopify: {
    apiVersion: '2026-07',
    graphql: async (query, variables) => {
      // Use your app-owned authenticated Shopify Admin client here.
      const response = await admin.graphql(query, {variables})
      return response.json()
    },
  },
})

const uploaded = await files.upload({
  source: new Blob([bytes], {type: 'image/png'}),
  filename: 'hero.png',
})

console.log(uploaded.status) // ready | failed

The low-level server methods are also public:

const [prepared] = await files.prepare([
  {filename: 'hero.png', mimeType: 'image/png', size: fileSize},
])

await files.uploadBinary(prepared, blob)

const registered = await files.register({
  clientId: prepared.clientId,
  resourceUrl: prepared.target.resourceUrl,
  filename: prepared.input.filename,
  mimeType: prepared.input.mimeType,
  type: prepared.input.type,
})

const settled = await files.waitUntilReady([registered.id])

Browser upload

The browser asks your backend for Shopify GraphQL operations, but sends the binary directly to Shopify staged storage.

import {uploadShopifyFile} from '@weaverse/shopify-file-upload/browser'

const uploaded = await uploadShopifyFile(file, {
  transport: {
    prepare: (input, {signal}) =>
      fetch('/api/shopify-files/prepare', {
        method: 'POST',
        headers: {'content-type': 'application/json'},
        body: JSON.stringify(input),
        signal,
      }).then((response) => response.json()),

    register: (input) =>
      fetch('/api/shopify-files/register', {
        method: 'POST',
        headers: {'content-type': 'application/json'},
        body: JSON.stringify(input),
      }).then((response) => response.json()),

    getStatus: (fileId, {signal}) =>
      fetch(`/api/shopify-files/status?id=${encodeURIComponent(fileId)}`, {signal}).then(
        (response) => response.json(),
      ),
  },
  onProgress: ({percent}) => console.log(percent),
})

Backend handlers can map directly to:

files.prepare([input]).then(([prepared]) => prepared)
files.register(input)
files.getStatuses([fileId]).then(([result]) => result)

Important behavior

  • fileCreate is asynchronous; the SDK waits for READY or FAILED by default.
  • Browser Admin credentials are never supported.
  • Binary data does not go through Admin GraphQL.
  • No automatic retry occurs after fileCreate. A lost registration response is reported as REGISTRATION_AMBIGUOUS and is non-retryable to prevent duplicates.
  • AbortSignal cancels preparation and binary upload. After registration starts, cancellation only stops local status waiting; the Shopify file may already exist.
  • SVG and WebM are treated as generic FILE uploads in this version.

Entry points

@weaverse/shopify-file-upload          shared types, constants, errors
@weaverse/shopify-file-upload/server   Shopify GraphQL orchestration
@weaverse/shopify-file-upload/browser  one-file browser upload

MIT © Weaverse

About

Headless TypeScript SDK for uploading files to Shopify Files through staged Admin GraphQL uploads.

Topics

Resources

Stars

25 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages