1.2.12 • Published 10 months ago

zod-cognito v1.2.12

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

Zod Cognito

This package includes a few useful Zod Schemas for AWS Cognito. It includes schemas for importing and exporting, as well as parsing user attributes.

Please check out the other packages, https://www.npmjs.com/package/cognito-export and https://www.npmjs.com/package/cognito-import for... exporting and importing.

Getting started

npm i zod-cognito

Documentation

Schema configurations are based on Cognito's documentation for importing.

### 1. Importing records

import z from "zod";
import { ImportRecordSchema, ImportSchema } from "zod-cognito";

// 1. Verify a single record for importing in the CSV file
const record = ImportRecordSchema.parse(user);

// 2. Verify a list of records for importing in a CSV file
const records = ImportSchema.parse(users);

// 3. Import with a custom attribute
const CustomRecordSchema = ImportRecordSchema.extend({
  "custom:thing": z.string(),
});
const customRecord = CustomRecordSchema.parse(user);
const customRecords = z.array(CustomRecordSchema).parse(users);

Check out https://www.npmjs.com/package/cognito-import for importing users, which automatically has this schema verification built in.

2. Parsing UserAttributes

import z from "zod";
import { AttributeListType } from "aws-sdk/clients/cognitoidentityserviceprovider";
import { parseUserAttributes } from "zod-cognito";

const userAttributes: AttributeListType = [
  /** UserAttributes from Cognito: { Name: string; Value?: string } **/
];

// 1. Parse default user attributes
const attribs = parseUserAttributes(userAttributes);

// 2. Parse with custom attributes
const CustomSchema = z.object({
  "custom:thing": "example",
});
const withCustomAttribs = parseUserAttributes(userAttributes, CustomSchema);
1.2.12

10 months ago

1.2.8

1 year ago

1.2.9

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.0

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.4

1 year ago

1.1.1

1 year ago

1.1.2

1 year ago

1.0.20

1 year ago

1.0.18

1 year ago

1.0.11

1 year ago

1.0.9

1 year ago

1.0.15

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago