@fern-api/auth0-myaccount-snippets
v0.0.5
Published
Generate usage snippets for Auth0 MyAccount SDKs
Readme
Auth0 MyAccount Snippets SDK
The Auth0 MyAccount Snippets SDK produces valid usage snippets from arbitrary request data for the Auth0 MyAccount API.
Supported Languages
The SDK supports generating code snippets for the following languages:
- TypeScript - Node.js/TypeScript SDK snippets
Usage
The SDK can be used as follows:
import { SnippetResolver } from "@fern-api/auth0-myaccount-snippets";
const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const factors = typescript.endpoint("GET /factors");
const response = await factors.generate({
auth: {
type: "bearer",
token: "<YOUR_ACCESS_TOKEN>"
}
});The generated response.snippet will be set to the following:
import { MyAccountClient } from "@fern-api/auth0-myaccount-snippets";
async function main() {
const client = new MyAccountClient({
token: "<YOUR_ACCESS_TOKEN>",
});
await client.factors.list();
}
main();More Examples
List Authentication Methods
const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const authMethods = typescript.endpoint("GET /authentication-methods");
const response = await authMethods.generate({
auth: {
type: "bearer",
token: "<YOUR_ACCESS_TOKEN>"
}
});Generated snippet:
import { MyAccountClient } from "@fern-api/auth0-myaccount-snippets";
async function main() {
const client = new MyAccountClient({
token: "<YOUR_ACCESS_TOKEN>",
});
await client.authenticationMethods.list();
}
main();Create Authentication Method
const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const authMethod = typescript.endpoint("POST /authentication-methods");
const response = await authMethod.generate({
auth: {
type: "bearer",
token: "<YOUR_ACCESS_TOKEN>"
},
requestBody: {
type: "totp"
}
});Generated snippet:
import { MyAccountClient } from "@fern-api/auth0-myaccount-snippets";
async function main() {
const client = new MyAccountClient({
token: "<YOUR_ACCESS_TOKEN>",
});
await client.authenticationMethods.create({
type: "totp",
});
}
main();Default snippets
You can call the generate method without a request payload to retrieve the default example
of the endpoint like so:
import { SnippetResolver } from "@fern-api/auth0-myaccount-snippets";
const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const authMethods = typescript.endpoint("POST /authentication-methods");
const response = await authMethods.generate();The generated snippet will include required fields with example values:
import { MyAccountClient } from "@fern-api/auth0-myaccount-snippets";
async function main() {
const client = new MyAccountClient({
token: "<token>",
});
await client.authenticationMethods.create({
type: "totp",
});
}
main();Note that the result will omit optional properties, so if a request is entirely composed of optional values, you're better off providing your own request payload.
Sync Methods
The SDK also exposes a generateSync method for users that don't have access to async and await in specific contexts.
It uses the same parameters as generate and can be invoked like so:
import { SnippetResolver } from "@fern-api/auth0-myaccount-snippets";
const resolver = new SnippetResolver();
const typescript = resolver.sdk("typescript");
const factors = typescript.endpoint("GET /factors")
const response = factors.generateSync({ ... });Endpoint Filtering
For performance, the endpoint method filters the provided API specification to only contain the
selected endpoint (e.g. GET /factors). This means you can reuse the filtered result with a
simple variable for the endpoint like so:
// The 'authMethods' variable acts upon an API specification that only contains the 'POST /authentication-methods' endpoint.
const authMethods = typescript.endpoint("POST /authentication-methods")
// Generate multiple snippets using the same instance.
const one = authMethods.generateSync({ ... });
const two = authMethods.generateSync({ ... });
...