Skip to content

Commit

Permalink
feat(host-mapping): Implement host to api mapping (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeevan-Kishore authored Dec 9, 2024
1 parent 83482cf commit 503b27e
Show file tree
Hide file tree
Showing 4 changed files with 16,407 additions and 13,193 deletions.
2 changes: 1 addition & 1 deletion bin-dev-scripts/standard-version-release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

npm install
npm install --legacy-peer-deps
git diff --quiet
npm run docs

Expand Down
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,32 @@ class Client {
return Config.build(cacheConfig);
}

/*
* This method is used to get the current in-memory cached host-to-api mapping for publishers. By default, this has a TTL of 4 minutes.
* @returns {(Promise<Config>)} A Promise that returns a in-memory cached instance of {@link Config}
*/
async getHostToAPIMappingCache(xHostAPIToken) {
// Cache key need not be unique across client instances
const cacheKeyAttribute = `hostToApiMapping`;
const hostToApiCache = await memoryCache.wrap(
cacheKeyAttribute,
async () => {
return this.getHostToAPIMapping(xHostAPIToken);
},
CACHE_TIME
);
return hostToApiCache;
}

async getHostToAPIMapping(xHostAPIToken) {
if (!xHostAPIToken) return new Promise(resolve => resolve({}));
return this.request("/api/v1/mappings/host-to-publisher-name", {
headers: {
"x-host-mapping-token": xHostAPIToken
}
});
}

getCurrentMember(authToken) {
return this.request("/api/v1/members/me", {
headers: {
Expand Down
Loading

0 comments on commit 503b27e

Please sign in to comment.