Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@superfaceai/one-sdk-cloudflare
Advanced tools
**One SDK for all the APIs you want to integrate with.**
Website | Get Started | Documentation | GitHub Discussions | Twitter | Support
One SDK for all the APIs you want to integrate with.
OneClient
is a universal API client which provides an unparalleled developer experience for every HTTP API. It enhances resiliency to API changes, and comes with built-in integration monitoring and provider failover.
For more details about Superface, visit How it Works and Get Started.
To install OneSDK into the project, run:
npm install @superfaceai/one-sdk-cloudflare@beta
OneClient uses three files (also called Comlink) which together make the integration:
/
and required name [scope/]<name>
To glue all the parts together, OneClient uses name and file structure convention.
.
└── superface/ - directory with all the Comlinks in project root
├── <profileScope>.<profileName>.profile - profile file
├── <providerName>.provider.json - provider file
├── <profileScope>.<profileName>.<providerName>.map.js - map file
└── ... - repeat for all the Comlinks
As an example, lets send an email with Mailchimp. The use-case is described in the profile communication/send-email and the map with implementation.
superface
in the root of your project./
with .
. So, the profile with name communication/send-email
have corresponding filename communication.send-email.profile
.mailchimp
have corresponding filename mailchimp.provider.json
.communication.send-email.mailchimp.map.js
.The final structure should look like this:
.
└── superface/
├── communication.send-email.mailchimp.map.js
├── communication.send-email.profile
└── mailchimp.provider.json
The main difference compared to Node.js is a need to use a virtual filesystem to load the Comlink files. It is needed due to the deployment process, where all files need to be bundled together.
import {
OneClient,
PerformError,
} from '@superfaceai/one-sdk-cloudflare';
import profileFile from './superface/[scope.]<name>.profile';
import mapFile from './superface/[scope.]<name>.<providerName>.map.js';
import providerFile from './superface/<providerName>.provider.json';
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const client = new OneClient({
env: {
ONESDK_LOG: 'off' // use `on` for debugging
},
// preopens describes the virtual filesystem whith the OneClient file convention mapped to assets
preopens: {
'superface/[scope.]<name>.profile': new Uint8Array(profileFile),
'superface/[scope.]<name>.<providerName>.map.js': new Uint8Array(mapFile),
'superface/<providerName>.provider.json': new Uint8Array(providerFile)
}
});
const profile = await client.getProfile('<profileName>'); // profile id as defined in *.profile
const usecase = profile.getUseCase('<usecaseName>'); // use case name as defined in the profile
const result = usecase.perform(
// Input parameters as defined in profile:
{
'<key>': '<value>',
},
// provider configuration
{
provider: '<providerName>', // provider name as defined in *.provider.json
parameters: {
// Provider specific integration parameters:
'<integrationParameterName>': '<integrationParameterValue>'
},
security: {
// Provider specific security values:
'<securityValueId>': {
// Security values as described in provider or on profile page
}
}
}
);
try {
// result as defined in the profile
const ok = await result;
return new Response(`Result: ${JSON.stringify(ok, null, 2)}`);
} catch (error) {
if (error instanceof PerformError) {
// error as defined in the profile
return new Response(`Error: ${JSON.stringify(error.errorResult, null, 2)}`, { status: 400 });
} else {
// exception - should not be part of a normal flow
return new Response(`${error.name}\n${error.message}`, { status: 500 });
}
}
}
}
And Wrangler configuration to properly load all files:
name = "example"
main = "index.ts"
compatibility_date = "2023-04-18"
workers_dev = true
rules = [
{ type = "Data", globs = ["**/*.map.js", "**/*.profile", "**/*.provider.json"], fallthrough = true }
]
Check full demo with Shopify use-cases and more details.
The next-gen OneSDK is still in beta stage and several features are not yet implemented. We welcome any and all feedback. The current limitations include:
OneSDK Client can't be instantiated in the global scope
Build-time integrations only
The compiled WASM OneSDK is hitting the 1MB limit of the Cloudflare workers free tier
OneSDK is licensed under the MIT License.
© 2023 Superface s.r.o.
FAQs
**One SDK for all the APIs you want to integrate with.**
We found that @superfaceai/one-sdk-cloudflare demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.