Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Add Storefront API client package
Browse files Browse the repository at this point in the history
  • Loading branch information
melissaluu committed Oct 26, 2023
1 parent 29036ac commit 7b24590
Show file tree
Hide file tree
Showing 19 changed files with 1,080 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/storefront-api-client/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
extends: "../../.eslintrc.cjs",
overrides: [
{
files: ["**/*.cjs"],
env: {
node: true,
},
},
{
files: ["**/*.test.ts"],
rules: {
"@typescript-eslint/ban-ts-comment": 0,
},
},
],
};
18 changes: 18 additions & 0 deletions packages/storefront-api-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

node_modules/
dist/

package-lock.json
.vscode/
.DS_Store
.rollup.cache/

# ignore any locally packed packages
*.tgz
!*.d.ts
10 changes: 10 additions & 0 deletions packages/storefront-api-client/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
["@babel/preset-env"],
["@shopify/babel-preset", {"typescript": true}]
],
"plugins": [
["@babel/plugin-transform-runtime"],
["@babel/plugin-transform-async-to-generator"]
]
}
111 changes: 111 additions & 0 deletions packages/storefront-api-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"name": "@shopify/storefront-api-client",
"version": "0.0.0",
"description": "Shopify Storefront API Client - A lightweight JS client to interact with Shopify's Storefront API",
"repository": {
"type": "git",
"url": "git+https://github.com/Shopify/shopify-api-js.git"
},
"author": "Shopify",
"license": "MIT",
"main": "./dist/umd/storefront-api-client.min.js",
"browser": "./dist/umd/storefront-api-client.min.js",
"module": "./dist/index.mjs",
"types": "./dist/storefront-api-client.d.ts",
"exports": {
".": {
"module": {
"types": "./dist/ts/index.d.ts",
"default": "./dist/index.mjs"
},
"import": {
"types": "./dist/ts/index.d.ts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/ts/index.d.ts",
"default": "./dist/index.js"
},
"default": "./dist/index.mjs"
}
},
"scripts": {
"lint": "eslint . --ext .js,.ts",
"build": "yarn run rollup",
"test": "jest",
"test:ci": "yarn test",
"rollup": "rollup -c --bundleConfigAsCjs",
"clean": "rimraf dist/*",
"changeset": "changeset",
"version": "changeset version",
"release": "yarn build && changeset publish"
},
"jest": {
"testEnvironment": "jsdom",
"setupFilesAfterEnv": [
"./src/tests/setupTests.ts"
],
"transform": {
".*": "babel-jest"
}
},
"publishConfig": {
"access": "public"
},
"keywords": [
"shopify",
"node",
"graphql",
"Storefront API"
],
"files": [
"**/*.d.ts",
"**/*.d.ts.map",
"**/*.js",
"**/*.js.map",
"**/*.mjs",
"**/*.mjs.map",
"!node_modules"
],
"dependencies": {
"@shopify/graphql-client": "^0.3.0"
},
"devDependencies": {
"@babel/core": "^7.21.3",
"@babel/plugin-transform-async-to-generator": "^7.20.7",
"@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.21.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-eslint": "^9.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.0.0",
"@shopify/babel-preset": "^25.0.0",
"@shopify/eslint-plugin": "^42.0.3",
"@shopify/prettier-config": "^1.1.2",
"@shopify/typescript-configs": "^5.1.0",
"@types/jest": "^29.5.0",
"@types/regenerator-runtime": "^0.13.1",
"@typescript-eslint/parser": "^6.7.5",
"babel-jest": "^29.5.0",
"eslint": "^8.51.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.5.0",
"jest-fetch-mock": "^3.0.3",
"prettier": "^2.5.1",
"regenerator-runtime": "^0.13.11",
"rollup": "^3.19.1",
"rollup-plugin-dts": "^5.2.0",
"tslib": "^2.5.0",
"typescript": "^5.2.0"
},
"bugs": {
"url": "https://github.com/Shopify/shopify-api-js/issues"
},
"homepage": "https://github.com/Shopify/shopify-api-js/packages/storefront-api-client#readme"
}
101 changes: 101 additions & 0 deletions packages/storefront-api-client/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import dts from "rollup-plugin-dts";
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
import replace from "@rollup/plugin-replace";

import * as pkg from "./package.json";

export const mainSrcInput = "src/index.ts";

export function getPlugins({ tsconfig, minify } = {}) {
return [
replace({
preventAssignment: true,
ROLLUP_REPLACE_CLIENT_VERSION: pkg.version,
}),
resolve(),
commonjs(),
typescript({
tsconfig: tsconfig ? tsconfig : "./tsconfig.build.json",
outDir: "./dist/ts",
}),
...(minify === true ? [terser({ keep_fnames: new RegExp("fetch") })] : []),
];
}

const packageName = pkg.name.substring(1);
const repositoryName = pkg.repository.url.split(":")[1].split(".")[0];
export const bannerConfig = {
banner: `/*! ${packageName} -- Copyright (c) 2023-present, Shopify Inc. -- license (MIT): https://github.com/${repositoryName}/blob/main/LICENSE */`,
};

const config = [
{
input: mainSrcInput,
plugins: getPlugins({
minify: true,
tsconfig: "./tsconfig.build.umd.json",
}),
output: [
{
file: "./dist/umd/storefront-api-client.min.js",
format: "umd",
sourcemap: true,
name: "ShopifyStorefrontAPIClient",
...bannerConfig,
},
],
},
{
input: mainSrcInput,
plugins: getPlugins({
tsconfig: "./tsconfig.build.umd.json",
}),
output: [
{
file: "./dist/umd/storefront-api-client.js",
format: "umd",
sourcemap: true,
name: "ShopifyStorefrontAPIClient",
...bannerConfig,
},
],
},
{
input: mainSrcInput,
plugins: getPlugins(),
output: [
{
dir: "./dist",
format: "es",
sourcemap: true,
preserveModules: true,
preserveModulesRoot: "src",
entryFileNames: "[name].mjs",
},
],
},
{
input: mainSrcInput,
plugins: getPlugins(),
output: [
{
dir: "./dist",
format: "cjs",
sourcemap: true,
exports: "named",
preserveModules: true,
preserveModulesRoot: "src",
},
],
},
{
input: "./dist/ts/index.d.ts",
output: [{ file: "dist/storefront-api-client.d.ts", format: "es" }],
plugins: [dts.default()],
},
];

export default config;
12 changes: 12 additions & 0 deletions packages/storefront-api-client/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const DEFAULT_CONTENT_TYPE = "application/json";
export const DEFAULT_SDK_VARIANT = "storefront-api-client";
// This is value is replaced with package.json version during rollup build process
export const DEFAULT_CLIENT_VERSION = "ROLLUP_REPLACE_CLIENT_VERSION";

export const PUBLIC_ACCESS_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token";
export const PRIVATE_ACCESS_TOKEN_HEADER = "Shopify-Storefront-Private-Token";
export const SDK_VARIANT_HEADER = "X-SDK-Variant";
export const SDK_VERSION_HEADER = "X-SDK-Version";
export const SDK_VARIANT_SOURCE_HEADER = "X-SDK-Variant-Source";

export const ERROR_PREFIX = "Storefront API Client:";
1 change: 1 addition & 0 deletions packages/storefront-api-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { createStorefrontAPIClient } from "./storefront-api-client";
Loading

0 comments on commit 7b24590

Please sign in to comment.