Shopify API Fetcher
From: BSS Group > BSS Commerce > Division Shopify/Blockchain
API References
-
BucketManager
: Manage Token bucket rate limiter of active store
-
initializeAll: (activeStores: Shop[]) => number;
: Initialize rate limiter for all given stores
-
initializeOne: (domain: string) => TokenBucketRateLimiter
: Initialize rate limiter for specific domain
-
get: (domain: string) => TokenBucketRateLimiter
: Get initialized rate limiter of a specific domain
-
clear: (domain: string) => void
: Clear rate limiter of a specific domain, used when app is uninstalled
-
safeFetch: (domain: string, url: RequestInfo, params?: RequestInit) => Promise<Response>
: use this instead of normal fetch
, with additional parameter domain
, which specify a store.
Example
const shops = [
{ id: 1, domain: 'dev-mida-dean.myshopify.com' },
{ id: 2, domain: 'dev-mida-store.myshopify.com' },
]
const intialized = BucketManager.initializeAll(shops);
BucketManager.initializeOne({
id: 1,
domain: 'dev-mida-dean.myshopify.com',
});
const bucket = BucketManager.get('dev-mida-dean.myshopify.com');
BucketManager.clear('dev-mida-dean.myshopify.com');
const response = await safeFetch(domain, url, params);
Roadmap
Because of numbers of services
, it is difficult to listen to app/uninstalled
webhook event. So, auto clear bucket is necessary