Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Dec 18, 2023
1 parent bb89a38 commit 7e1090e
Show file tree
Hide file tree
Showing 26 changed files with 96 additions and 72 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,30 @@ CODE_TYPE_CHECK=all npm run start

You may need to add something to the code that is necessary for type checking but shouldn't appear in the output documentation. You can do this by adding a comment to the end of the line stating: `typecheck-only, removed from output`. Lines ending with this comment will be removed from the output but kept for type checking.

Omitting substrings from the final output while retaining them for type checking can be achieved using the `__OMIT_START__` and `__OMIT_END__` specifier. This is particularly useful for incorporating type annotations into code snippets without including them in the end result. Consider the following example:

```mjs
function square(num__OMIT_START__: number__OMIT_END__) {
return num * num;
}
```

During code checking, the plugin will analyze the following code:

```mjs
function square(num: number) {
return num * num;
}
```

However, the final output will exclude type annotations:

```mjs
function square(num) {
return num * num;
}
```

#### Tips JS / TS
- If you need to purposely tell TS to ignore errors in the next line, you can add a `// @ts-ignore` comment in your code snippets. This will make the TS checker pass. The type checking engine will also remove these from the final code output so that users don't see this unnecessarily.
- If you are working with snippets that use an older version of supertokens-node you can use a custom import for that version. For example some snippets use `supertokens-node7` as the import to fix typing. The type checking engine replaces this with `supertokens-node`. NOTE: If you need to add another node version as a custom import, please modify the type checking script to replace the import statement to use `supertokens-node`
Expand Down
20 changes: 10 additions & 10 deletions v2/emailpassword/serverless/with-aws-lambda/authorizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ Use the code below as the handler for the lambda. Remember that whenever we want

```tsx title="index.mjs"
import supertokens from "supertokens-node";
import { SessionEvent } from "supertokens-node/framework/awsLambda";
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda";
import { SessionEvent } from "supertokens-node/framework/awsLambda"; // typecheck-only, removed from output
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda"; // typecheck-only, removed from output
import Session from "supertokens-node/recipe/session";

// @ts-ignore
import { getBackendConfig } from "./config.mjs";

supertokens.init(getBackendConfig());

type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent;
type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent; // typecheck-only, removed from output

export const handler = async function (event: AuthorizerEvent) {
export const handler = async function (event__OMIT_START__: AuthorizerEvent__OMIT_END__) {
try {
const session = await Session.getSession(event, event, { sessionRequired: false });
if (session) {
Expand Down Expand Up @@ -198,22 +198,22 @@ export const handler = async function (event: AuthorizerEvent) {
}

// Help function to generate an IAM policy
const generatePolicy = function (principalId: string, effect: string, resource: string, context?: any) {
const generatePolicy = function (principalId__OMIT_START__: string__OMIT_END__, effect__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
// Required output:
const policyDocument: PolicyDocument = {
const policyDocument__OMIT_START__: PolicyDocument__OMIT_END__ = {
Version: '2012-10-17',
Statement: [],
};

const statementOne: Statement = {
const statementOne__OMIT_START__: Statement__OMIT_END__ = {
Action: 'execute-api:Invoke',
Effect: effect,
Resource: resource,
};

policyDocument.Statement[0] = statementOne;

const authResponse: AuthResponse = {
const authResponse__OMIT_START__: AuthResponse__OMIT_END__ = {
principalId: principalId,
policyDocument: policyDocument,
// Optional output with custom properties of the String, Number or Boolean type.
Expand All @@ -223,11 +223,11 @@ const generatePolicy = function (principalId: string, effect: string, resource:
return authResponse;
}

const generateAllow = function (principalId: string, resource: string, context?: any) {
const generateAllow = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Allow', resource, context);
};

const generateDeny = function (principalId: string, resource: string, context?: any) {
const generateDeny = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Deny', resource, context);
};
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ AWS supports JWT authorizers for HTTP APIs and not REST APIs on the API Gateway
```tsx title="config.mjs"

import Session from 'supertokens-node/recipe/session'
import SuperTokensTypes from 'supertokens-node/types';
import SuperTokensTypes from 'supertokens-node/types'; // typecheck-only, removed from output

export function getBackendConfig(): SuperTokensTypes.TypeInput {
export function getBackendConfig()__OMIT_START__: SuperTokensTypes.TypeInput__OMIT_END__ {
return {
framework: "awsLambda",
supertokens: {
Expand Down
20 changes: 10 additions & 10 deletions v2/passwordless/serverless/with-aws-lambda/authorizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ Use the code below as the handler for the lambda. Remember that whenever we want

```tsx title="index.mjs"
import supertokens from "supertokens-node";
import { SessionEvent } from "supertokens-node/framework/awsLambda";
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda";
import { SessionEvent } from "supertokens-node/framework/awsLambda"; // typecheck-only, removed from output
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda"; // typecheck-only, removed from output
import Session from "supertokens-node/recipe/session";

// @ts-ignore
import { getBackendConfig } from "./config.mjs";

supertokens.init(getBackendConfig());

type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent;
type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent; // typecheck-only, removed from output

export const handler = async function (event: AuthorizerEvent) {
export const handler = async function (event__OMIT_START__: AuthorizerEvent__OMIT_END__) {
try {
const session = await Session.getSession(event, event, { sessionRequired: false });
if (session) {
Expand Down Expand Up @@ -198,22 +198,22 @@ export const handler = async function (event: AuthorizerEvent) {
}

// Help function to generate an IAM policy
const generatePolicy = function (principalId: string, effect: string, resource: string, context?: any) {
const generatePolicy = function (principalId__OMIT_START__: string__OMIT_END__, effect__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
// Required output:
const policyDocument: PolicyDocument = {
const policyDocument__OMIT_START__: PolicyDocument__OMIT_END__ = {
Version: '2012-10-17',
Statement: [],
};

const statementOne: Statement = {
const statementOne__OMIT_START__: Statement__OMIT_END__ = {
Action: 'execute-api:Invoke',
Effect: effect,
Resource: resource,
};

policyDocument.Statement[0] = statementOne;

const authResponse: AuthResponse = {
const authResponse__OMIT_START__: AuthResponse__OMIT_END__ = {
principalId: principalId,
policyDocument: policyDocument,
// Optional output with custom properties of the String, Number or Boolean type.
Expand All @@ -223,11 +223,11 @@ const generatePolicy = function (principalId: string, effect: string, resource:
return authResponse;
}

const generateAllow = function (principalId: string, resource: string, context?: any) {
const generateAllow = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Allow', resource, context);
};

const generateDeny = function (principalId: string, resource: string, context?: any) {
const generateDeny = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Deny', resource, context);
};
```
Expand Down
4 changes: 2 additions & 2 deletions v2/passwordless/serverless/with-aws-lambda/jwt-authorizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ AWS supports JWT authorizers for HTTP APIs and not REST APIs on the API Gateway
```tsx title="config.mjs"

import Session from 'supertokens-node/recipe/session'
import SuperTokensTypes from 'supertokens-node/types';
import SuperTokensTypes from 'supertokens-node/types'; // typecheck-only, removed from output

export function getBackendConfig(): SuperTokensTypes.TypeInput {
export function getBackendConfig()__OMIT_START__: SuperTokensTypes.TypeInput__OMIT_END__ {
return {
framework: "awsLambda",
supertokens: {
Expand Down
20 changes: 10 additions & 10 deletions v2/session/serverless/with-aws-lambda/authorizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ Use the code below as the handler for the lambda. Remember that whenever we want

```tsx title="index.mjs"
import supertokens from "supertokens-node";
import { SessionEvent } from "supertokens-node/framework/awsLambda";
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda";
import { SessionEvent } from "supertokens-node/framework/awsLambda"; // typecheck-only, removed from output
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda"; // typecheck-only, removed from output
import Session from "supertokens-node/recipe/session";

// @ts-ignore
import { getBackendConfig } from "./config.mjs";

supertokens.init(getBackendConfig());

type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent;
type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent; // typecheck-only, removed from output

export const handler = async function (event: AuthorizerEvent) {
export const handler = async function (event__OMIT_START__: AuthorizerEvent__OMIT_END__) {
try {
const session = await Session.getSession(event, event, { sessionRequired: false });
if (session) {
Expand Down Expand Up @@ -198,22 +198,22 @@ export const handler = async function (event: AuthorizerEvent) {
}

// Help function to generate an IAM policy
const generatePolicy = function (principalId: string, effect: string, resource: string, context?: any) {
const generatePolicy = function (principalId__OMIT_START__: string__OMIT_END__, effect__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
// Required output:
const policyDocument: PolicyDocument = {
const policyDocument__OMIT_START__: PolicyDocument__OMIT_END__ = {
Version: '2012-10-17',
Statement: [],
};

const statementOne: Statement = {
const statementOne__OMIT_START__: Statement__OMIT_END__ = {
Action: 'execute-api:Invoke',
Effect: effect,
Resource: resource,
};

policyDocument.Statement[0] = statementOne;

const authResponse: AuthResponse = {
const authResponse__OMIT_START__: AuthResponse__OMIT_END__ = {
principalId: principalId,
policyDocument: policyDocument,
// Optional output with custom properties of the String, Number or Boolean type.
Expand All @@ -223,11 +223,11 @@ const generatePolicy = function (principalId: string, effect: string, resource:
return authResponse;
}

const generateAllow = function (principalId: string, resource: string, context?: any) {
const generateAllow = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Allow', resource, context);
};

const generateDeny = function (principalId: string, resource: string, context?: any) {
const generateDeny = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Deny', resource, context);
};
```
Expand Down
4 changes: 2 additions & 2 deletions v2/session/serverless/with-aws-lambda/jwt-authorizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ AWS supports JWT authorizers for HTTP APIs and not REST APIs on the API Gateway
```tsx title="config.mjs"

import Session from 'supertokens-node/recipe/session'
import SuperTokensTypes from 'supertokens-node/types';
import SuperTokensTypes from 'supertokens-node/types'; // typecheck-only, removed from output

export function getBackendConfig(): SuperTokensTypes.TypeInput {
export function getBackendConfig()__OMIT_START__: SuperTokensTypes.TypeInput__OMIT_END__ {
return {
framework: "awsLambda",
supertokens: {
Expand Down
Binary file modified v2/static/img/integration-lambda/add-a-layer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/add-auth-middleware-node.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/add-env-var-node.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/add-layer-detail-node.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/click-enable-cors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/configure-cors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/create-api-gateway.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/create-function-node.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/create-function-python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/create-proxy-route.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/node-lambda-layer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified v2/static/img/integration-lambda/route-creation-complete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions v2/thirdparty/serverless/with-aws-lambda/authorizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ Use the code below as the handler for the lambda. Remember that whenever we want

```tsx title="index.mjs"
import supertokens from "supertokens-node";
import { SessionEvent } from "supertokens-node/framework/awsLambda";
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda";
import { SessionEvent } from "supertokens-node/framework/awsLambda"; // typecheck-only, removed from output
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda"; // typecheck-only, removed from output
import Session from "supertokens-node/recipe/session";

// @ts-ignore
import { getBackendConfig } from "./config.mjs";

supertokens.init(getBackendConfig());

type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent;
type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent; // typecheck-only, removed from output

export const handler = async function (event: AuthorizerEvent) {
export const handler = async function (event__OMIT_START__: AuthorizerEvent__OMIT_END__) {
try {
const session = await Session.getSession(event, event, { sessionRequired: false });
if (session) {
Expand Down Expand Up @@ -198,22 +198,22 @@ export const handler = async function (event: AuthorizerEvent) {
}

// Help function to generate an IAM policy
const generatePolicy = function (principalId: string, effect: string, resource: string, context?: any) {
const generatePolicy = function (principalId__OMIT_START__: string__OMIT_END__, effect__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
// Required output:
const policyDocument: PolicyDocument = {
const policyDocument__OMIT_START__: PolicyDocument__OMIT_END__ = {
Version: '2012-10-17',
Statement: [],
};

const statementOne: Statement = {
const statementOne__OMIT_START__: Statement__OMIT_END__ = {
Action: 'execute-api:Invoke',
Effect: effect,
Resource: resource,
};

policyDocument.Statement[0] = statementOne;

const authResponse: AuthResponse = {
const authResponse__OMIT_START__: AuthResponse__OMIT_END__ = {
principalId: principalId,
policyDocument: policyDocument,
// Optional output with custom properties of the String, Number or Boolean type.
Expand All @@ -223,11 +223,11 @@ const generatePolicy = function (principalId: string, effect: string, resource:
return authResponse;
}

const generateAllow = function (principalId: string, resource: string, context?: any) {
const generateAllow = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Allow', resource, context);
};

const generateDeny = function (principalId: string, resource: string, context?: any) {
const generateDeny = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Deny', resource, context);
};
```
Expand Down
4 changes: 2 additions & 2 deletions v2/thirdparty/serverless/with-aws-lambda/jwt-authorizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ AWS supports JWT authorizers for HTTP APIs and not REST APIs on the API Gateway
```tsx title="config.mjs"

import Session from 'supertokens-node/recipe/session'
import SuperTokensTypes from 'supertokens-node/types';
import SuperTokensTypes from 'supertokens-node/types'; // typecheck-only, removed from output

export function getBackendConfig(): SuperTokensTypes.TypeInput {
export function getBackendConfig()__OMIT_START__: SuperTokensTypes.TypeInput__OMIT_END__ {
return {
framework: "awsLambda",
supertokens: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ Use the code below as the handler for the lambda. Remember that whenever we want

```tsx title="index.mjs"
import supertokens from "supertokens-node";
import { SessionEvent } from "supertokens-node/framework/awsLambda";
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda";
import { SessionEvent } from "supertokens-node/framework/awsLambda"; // typecheck-only, removed from output
import { APIGatewayAuthorizerEvent, PolicyDocument, Statement, AuthResponse } from "aws-lambda"; // typecheck-only, removed from output
import Session from "supertokens-node/recipe/session";

// @ts-ignore
import { getBackendConfig } from "./config.mjs";

supertokens.init(getBackendConfig());

type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent;
type AuthorizerEvent = SessionEvent & APIGatewayAuthorizerEvent; // typecheck-only, removed from output

export const handler = async function (event: AuthorizerEvent) {
export const handler = async function (event__OMIT_START__: AuthorizerEvent__OMIT_END__) {
try {
const session = await Session.getSession(event, event, { sessionRequired: false });
if (session) {
Expand Down Expand Up @@ -198,22 +198,22 @@ export const handler = async function (event: AuthorizerEvent) {
}

// Help function to generate an IAM policy
const generatePolicy = function (principalId: string, effect: string, resource: string, context?: any) {
const generatePolicy = function (principalId__OMIT_START__: string__OMIT_END__, effect__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
// Required output:
const policyDocument: PolicyDocument = {
const policyDocument__OMIT_START__: PolicyDocument__OMIT_END__ = {
Version: '2012-10-17',
Statement: [],
};

const statementOne: Statement = {
const statementOne__OMIT_START__: Statement__OMIT_END__ = {
Action: 'execute-api:Invoke',
Effect: effect,
Resource: resource,
};

policyDocument.Statement[0] = statementOne;

const authResponse: AuthResponse = {
const authResponse__OMIT_START__: AuthResponse__OMIT_END__ = {
principalId: principalId,
policyDocument: policyDocument,
// Optional output with custom properties of the String, Number or Boolean type.
Expand All @@ -223,11 +223,11 @@ const generatePolicy = function (principalId: string, effect: string, resource:
return authResponse;
}

const generateAllow = function (principalId: string, resource: string, context?: any) {
const generateAllow = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Allow', resource, context);
};

const generateDeny = function (principalId: string, resource: string, context?: any) {
const generateDeny = function (principalId__OMIT_START__: string__OMIT_END__, resource__OMIT_START__: string__OMIT_END__, context__OMIT_START__?: any__OMIT_END__) {
return generatePolicy(principalId, 'Deny', resource, context);
};
```
Expand Down
Loading

0 comments on commit 7e1090e

Please sign in to comment.