@juniyadi/cognito 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Cognito.d.ts +48 -0
- package/dist/Cognito.js +113 -0
- package/dist/Cognito.js.map +1 -0
- package/dist/Cognito.mjs +93 -0
- package/dist/Cognito.mjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
import * as _aws_sdk_client_cognito_identity_provider from '@aws-sdk/client-cognito-identity-provider';
|
2
|
+
import { CognitoIdentityProviderClient, AdminSetUserPasswordCommandOutput } from '@aws-sdk/client-cognito-identity-provider';
|
3
|
+
|
4
|
+
interface ICognito {
|
5
|
+
region?: string;
|
6
|
+
userPoolId?: string;
|
7
|
+
clientId?: string;
|
8
|
+
}
|
9
|
+
interface ICognitoAttributes {
|
10
|
+
Name: string;
|
11
|
+
Value: string;
|
12
|
+
}
|
13
|
+
interface ICognitoInviteUser {
|
14
|
+
name: string;
|
15
|
+
email: string;
|
16
|
+
password: string;
|
17
|
+
passwordTemporary?: string;
|
18
|
+
autoConfirm?: boolean;
|
19
|
+
phoneNumber?: string;
|
20
|
+
sendEmail?: boolean;
|
21
|
+
attributes?: ICognitoAttributes[];
|
22
|
+
}
|
23
|
+
declare class Cognito {
|
24
|
+
region: string;
|
25
|
+
userPoolId: string;
|
26
|
+
clientId: string;
|
27
|
+
cognitoIdentityProvider: CognitoIdentityProviderClient;
|
28
|
+
constructor(opts?: ICognito);
|
29
|
+
/**
|
30
|
+
* Generate a random password of a given length
|
31
|
+
* @param length
|
32
|
+
* @returns string
|
33
|
+
*/
|
34
|
+
randomPassword: (length?: number) => string;
|
35
|
+
/**
|
36
|
+
* Invite a user to the Cognito User Pool
|
37
|
+
* @param opts
|
38
|
+
*/
|
39
|
+
inviteUser: (opts: ICognitoInviteUser) => Promise<_aws_sdk_client_cognito_identity_provider.AdminCreateUserCommandOutput>;
|
40
|
+
/**
|
41
|
+
* Change user password in Cognito User Pool
|
42
|
+
* @param username - Username of the user
|
43
|
+
* @param password - New password for the user
|
44
|
+
*/
|
45
|
+
changePassword: (username: string, password: string) => Promise<AdminSetUserPasswordCommandOutput>;
|
46
|
+
}
|
47
|
+
|
48
|
+
export { Cognito, ICognito, ICognitoAttributes, ICognitoInviteUser };
|
package/dist/Cognito.js
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var Cognito_exports = {};
|
20
|
+
__export(Cognito_exports, {
|
21
|
+
Cognito: () => Cognito
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(Cognito_exports);
|
24
|
+
var import_client_cognito_identity_provider = require("@aws-sdk/client-cognito-identity-provider");
|
25
|
+
class Cognito {
|
26
|
+
constructor(opts) {
|
27
|
+
this.randomPassword = (length = 12) => {
|
28
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
29
|
+
let pass = "";
|
30
|
+
for (let x = 0; x < length; x++) {
|
31
|
+
const i = Math.floor(Math.random() * chars.length);
|
32
|
+
pass += chars.charAt(i);
|
33
|
+
}
|
34
|
+
return pass;
|
35
|
+
};
|
36
|
+
this.inviteUser = async (opts) => {
|
37
|
+
var _a, _b;
|
38
|
+
const temporaryPassword = opts.passwordTemporary || this.randomPassword();
|
39
|
+
const items = {
|
40
|
+
UserPoolId: this.userPoolId,
|
41
|
+
Username: opts.email,
|
42
|
+
UserAttributes: [
|
43
|
+
{
|
44
|
+
Name: "email",
|
45
|
+
Value: opts.email
|
46
|
+
},
|
47
|
+
{
|
48
|
+
Name: "name",
|
49
|
+
Value: opts.name
|
50
|
+
},
|
51
|
+
{
|
52
|
+
Name: "email_verified",
|
53
|
+
Value: "true"
|
54
|
+
}
|
55
|
+
],
|
56
|
+
DesiredDeliveryMediums: ["EMAIL"],
|
57
|
+
ForceAliasCreation: false,
|
58
|
+
MessageAction: opts.sendEmail ? "RESEND" : "SUPPRESS",
|
59
|
+
TemporaryPassword: temporaryPassword
|
60
|
+
};
|
61
|
+
if (opts.phoneNumber && items.UserAttributes) {
|
62
|
+
items.UserAttributes.push({
|
63
|
+
Name: "phone_number",
|
64
|
+
Value: opts.phoneNumber
|
65
|
+
});
|
66
|
+
}
|
67
|
+
if (opts.attributes && items.UserAttributes) {
|
68
|
+
items.UserAttributes = items.UserAttributes.concat(opts.attributes);
|
69
|
+
}
|
70
|
+
const command = new import_client_cognito_identity_provider.AdminCreateUserCommand(items);
|
71
|
+
try {
|
72
|
+
const response = await this.cognitoIdentityProvider.send(command);
|
73
|
+
if (opts.autoConfirm && ((_a = response == null ? void 0 : response.User) == null ? void 0 : _a.UserStatus) === "FORCE_CHANGE_PASSWORD") {
|
74
|
+
const changePassword = await this.changePassword(
|
75
|
+
opts.email,
|
76
|
+
opts.password
|
77
|
+
);
|
78
|
+
if (((_b = changePassword == null ? void 0 : changePassword.$metadata) == null ? void 0 : _b.httpStatusCode) !== 200) {
|
79
|
+
throw new Error("Error changing password");
|
80
|
+
}
|
81
|
+
}
|
82
|
+
return response;
|
83
|
+
} catch (error) {
|
84
|
+
throw error;
|
85
|
+
}
|
86
|
+
};
|
87
|
+
this.changePassword = async (username, password) => {
|
88
|
+
const command = new import_client_cognito_identity_provider.AdminSetUserPasswordCommand({
|
89
|
+
UserPoolId: this.userPoolId,
|
90
|
+
Username: username,
|
91
|
+
Password: password,
|
92
|
+
Permanent: true
|
93
|
+
});
|
94
|
+
try {
|
95
|
+
const response = await this.cognitoIdentityProvider.send(command);
|
96
|
+
return response;
|
97
|
+
} catch (error) {
|
98
|
+
throw error;
|
99
|
+
}
|
100
|
+
};
|
101
|
+
this.region = (opts == null ? void 0 : opts.region) || process.env.AWS_REGION || "";
|
102
|
+
this.userPoolId = (opts == null ? void 0 : opts.userPoolId) || process.env.COGNITO_USER_POOL_ID || "";
|
103
|
+
this.clientId = (opts == null ? void 0 : opts.clientId) || process.env.COGNITO_CLIENT_ID || "";
|
104
|
+
this.cognitoIdentityProvider = new import_client_cognito_identity_provider.CognitoIdentityProviderClient({
|
105
|
+
region: this.region
|
106
|
+
});
|
107
|
+
}
|
108
|
+
}
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
110
|
+
0 && (module.exports = {
|
111
|
+
Cognito
|
112
|
+
});
|
113
|
+
//# sourceMappingURL=Cognito.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Cognito.ts"],"sourcesContent":["import {\n AdminCreateUserCommand,\n AdminCreateUserCommandInput,\n CognitoIdentityProviderClient,\n AdminSetUserPasswordCommand,\n AdminSetUserPasswordCommandOutput,\n} from \"@aws-sdk/client-cognito-identity-provider\";\n\nexport interface ICognito {\n region?: string;\n userPoolId?: string;\n clientId?: string;\n}\n\nexport interface ICognitoAttributes {\n Name: string;\n Value: string;\n}\n\nexport interface ICognitoInviteUser {\n name: string;\n email: string;\n password: string;\n passwordTemporary?: string;\n autoConfirm?: boolean;\n phoneNumber?: string;\n sendEmail?: boolean;\n attributes?: ICognitoAttributes[];\n}\n\nexport class Cognito {\n public region: string;\n public userPoolId: string;\n public clientId: string;\n public cognitoIdentityProvider: CognitoIdentityProviderClient;\n\n constructor(opts?: ICognito) {\n this.region = opts?.region || process.env.AWS_REGION || \"\";\n this.userPoolId =\n opts?.userPoolId || process.env.COGNITO_USER_POOL_ID || \"\";\n this.clientId = opts?.clientId || process.env.COGNITO_CLIENT_ID || \"\";\n\n this.cognitoIdentityProvider = new CognitoIdentityProviderClient({\n region: this.region,\n });\n }\n\n /**\n * Generate a random password of a given length\n * @param length\n * @returns string\n */\n public randomPassword = (length = 12): string => {\n const chars =\n \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n let pass = \"\";\n for (let x = 0; x < length; x++) {\n const i = Math.floor(Math.random() * chars.length);\n pass += chars.charAt(i);\n }\n return pass;\n };\n\n /**\n * Invite a user to the Cognito User Pool\n * @param opts\n */\n public inviteUser = async (opts: ICognitoInviteUser) => {\n const temporaryPassword = opts.passwordTemporary || this.randomPassword();\n\n const items: AdminCreateUserCommandInput = {\n UserPoolId: this.userPoolId,\n Username: opts.email,\n UserAttributes: [\n {\n Name: \"email\",\n Value: opts.email,\n },\n {\n Name: \"name\",\n Value: opts.name,\n },\n {\n Name: \"email_verified\",\n Value: \"true\",\n },\n ],\n DesiredDeliveryMediums: [\"EMAIL\"],\n ForceAliasCreation: false,\n MessageAction: opts.sendEmail ? \"RESEND\" : \"SUPPRESS\",\n TemporaryPassword: temporaryPassword,\n };\n\n // Add Phone Number to User Attributes if provided\n if (opts.phoneNumber && items.UserAttributes) {\n items.UserAttributes.push({\n Name: \"phone_number\",\n Value: opts.phoneNumber,\n });\n }\n\n // Add Other Attributes to User Attributes if provided\n if (opts.attributes && items.UserAttributes) {\n items.UserAttributes = items.UserAttributes.concat(opts.attributes);\n }\n\n const command = new AdminCreateUserCommand(items);\n try {\n const response = await this.cognitoIdentityProvider.send(command);\n\n /**\n * If the user is FORCE_CHANGE_PASSWORD, then change the password to the one provided\n * So that the user can login with the password provided\n */\n if (\n opts.autoConfirm &&\n response?.User?.UserStatus === \"FORCE_CHANGE_PASSWORD\"\n ) {\n const changePassword = await this.changePassword(\n opts.email,\n opts.password\n );\n\n if (changePassword?.$metadata?.httpStatusCode !== 200) {\n throw new Error(\"Error changing password\");\n }\n }\n\n return response;\n } catch (error) {\n throw error;\n }\n };\n\n /**\n * Change user password in Cognito User Pool\n * @param username - Username of the user\n * @param password - New password for the user\n */\n public changePassword = async (\n username: string,\n password: string\n ): Promise<AdminSetUserPasswordCommandOutput> => {\n const command = new AdminSetUserPasswordCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n Password: password,\n Permanent: true,\n });\n\n try {\n const response = await this.cognitoIdentityProvider.send(command);\n return response;\n } catch (error) {\n throw error;\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAMO;AAwBA,MAAM,QAAQ;AAAA,EAMnB,YAAY,MAAiB;AAgB7B,SAAO,iBAAiB,CAAC,SAAS,OAAe;AAC/C,YAAM,QACJ;AACF,UAAI,OAAO;AACX,eAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,cAAM,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,MAAM,MAAM;AACjD,gBAAQ,MAAM,OAAO,CAAC;AAAA,MACxB;AACA,aAAO;AAAA,IACT;AAMA,SAAO,aAAa,OAAO,SAA6B;AAnE1D;AAoEI,YAAM,oBAAoB,KAAK,qBAAqB,KAAK,eAAe;AAExE,YAAM,QAAqC;AAAA,QACzC,YAAY,KAAK;AAAA,QACjB,UAAU,KAAK;AAAA,QACf,gBAAgB;AAAA,UACd;AAAA,YACE,MAAM;AAAA,YACN,OAAO,KAAK;AAAA,UACd;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,OAAO,KAAK;AAAA,UACd;AAAA,UACA;AAAA,YACE,MAAM;AAAA,YACN,OAAO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IAAI,qBAAqB;AAEnE,SAAK,0BAA0B,IAAI,sEAA8B;AAAA,MAC/D,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAgHF;","names":[]}
|
package/dist/Cognito.mjs
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
import {
|
2
|
+
AdminCreateUserCommand,
|
3
|
+
CognitoIdentityProviderClient,
|
4
|
+
AdminSetUserPasswordCommand
|
5
|
+
} from "@aws-sdk/client-cognito-identity-provider";
|
6
|
+
class Cognito {
|
7
|
+
constructor(opts) {
|
8
|
+
this.randomPassword = (length = 12) => {
|
9
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
10
|
+
let pass = "";
|
11
|
+
for (let x = 0; x < length; x++) {
|
12
|
+
const i = Math.floor(Math.random() * chars.length);
|
13
|
+
pass += chars.charAt(i);
|
14
|
+
}
|
15
|
+
return pass;
|
16
|
+
};
|
17
|
+
this.inviteUser = async (opts) => {
|
18
|
+
var _a, _b;
|
19
|
+
const temporaryPassword = opts.passwordTemporary || this.randomPassword();
|
20
|
+
const items = {
|
21
|
+
UserPoolId: this.userPoolId,
|
22
|
+
Username: opts.email,
|
23
|
+
UserAttributes: [
|
24
|
+
{
|
25
|
+
Name: "email",
|
26
|
+
Value: opts.email
|
27
|
+
},
|
28
|
+
{
|
29
|
+
Name: "name",
|
30
|
+
Value: opts.name
|
31
|
+
},
|
32
|
+
{
|
33
|
+
Name: "email_verified",
|
34
|
+
Value: "true"
|
35
|
+
}
|
36
|
+
],
|
37
|
+
DesiredDeliveryMediums: ["EMAIL"],
|
38
|
+
ForceAliasCreation: false,
|
39
|
+
MessageAction: opts.sendEmail ? "RESEND" : "SUPPRESS",
|
40
|
+
TemporaryPassword: temporaryPassword
|
41
|
+
};
|
42
|
+
if (opts.phoneNumber && items.UserAttributes) {
|
43
|
+
items.UserAttributes.push({
|
44
|
+
Name: "phone_number",
|
45
|
+
Value: opts.phoneNumber
|
46
|
+
});
|
47
|
+
}
|
48
|
+
if (opts.attributes && items.UserAttributes) {
|
49
|
+
items.UserAttributes = items.UserAttributes.concat(opts.attributes);
|
50
|
+
}
|
51
|
+
const command = new AdminCreateUserCommand(items);
|
52
|
+
try {
|
53
|
+
const response = await this.cognitoIdentityProvider.send(command);
|
54
|
+
if (opts.autoConfirm && ((_a = response == null ? void 0 : response.User) == null ? void 0 : _a.UserStatus) === "FORCE_CHANGE_PASSWORD") {
|
55
|
+
const changePassword = await this.changePassword(
|
56
|
+
opts.email,
|
57
|
+
opts.password
|
58
|
+
);
|
59
|
+
if (((_b = changePassword == null ? void 0 : changePassword.$metadata) == null ? void 0 : _b.httpStatusCode) !== 200) {
|
60
|
+
throw new Error("Error changing password");
|
61
|
+
}
|
62
|
+
}
|
63
|
+
return response;
|
64
|
+
} catch (error) {
|
65
|
+
throw error;
|
66
|
+
}
|
67
|
+
};
|
68
|
+
this.changePassword = async (username, password) => {
|
69
|
+
const command = new AdminSetUserPasswordCommand({
|
70
|
+
UserPoolId: this.userPoolId,
|
71
|
+
Username: username,
|
72
|
+
Password: password,
|
73
|
+
Permanent: true
|
74
|
+
});
|
75
|
+
try {
|
76
|
+
const response = await this.cognitoIdentityProvider.send(command);
|
77
|
+
return response;
|
78
|
+
} catch (error) {
|
79
|
+
throw error;
|
80
|
+
}
|
81
|
+
};
|
82
|
+
this.region = (opts == null ? void 0 : opts.region) || process.env.AWS_REGION || "";
|
83
|
+
this.userPoolId = (opts == null ? void 0 : opts.userPoolId) || process.env.COGNITO_USER_POOL_ID || "";
|
84
|
+
this.clientId = (opts == null ? void 0 : opts.clientId) || process.env.COGNITO_CLIENT_ID || "";
|
85
|
+
this.cognitoIdentityProvider = new CognitoIdentityProviderClient({
|
86
|
+
region: this.region
|
87
|
+
});
|
88
|
+
}
|
89
|
+
}
|
90
|
+
export {
|
91
|
+
Cognito
|
92
|
+
};
|
93
|
+
//# sourceMappingURL=Cognito.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Cognito.ts"],"sourcesContent":["import {\n AdminCreateUserCommand,\n AdminCreateUserCommandInput,\n CognitoIdentityProviderClient,\n AdminSetUserPasswordCommand,\n AdminSetUserPasswordCommandOutput,\n} from \"@aws-sdk/client-cognito-identity-provider\";\n\nexport interface ICognito {\n region?: string;\n userPoolId?: string;\n clientId?: string;\n}\n\nexport interface ICognitoAttributes {\n Name: string;\n Value: string;\n}\n\nexport interface ICognitoInviteUser {\n name: string;\n email: string;\n password: string;\n passwordTemporary?: string;\n autoConfirm?: boolean;\n phoneNumber?: string;\n sendEmail?: boolean;\n attributes?: ICognitoAttributes[];\n}\n\nexport class Cognito {\n public region: string;\n public userPoolId: string;\n public clientId: string;\n public cognitoIdentityProvider: CognitoIdentityProviderClient;\n\n constructor(opts?: ICognito) {\n this.region = opts?.region || process.env.AWS_REGION || \"\";\n this.userPoolId =\n opts?.userPoolId || process.env.COGNITO_USER_POOL_ID || \"\";\n this.clientId = opts?.clientId || process.env.COGNITO_CLIENT_ID || \"\";\n\n this.cognitoIdentityProvider = new CognitoIdentityProviderClient({\n region: this.region,\n });\n }\n\n /**\n * Generate a random password of a given length\n * @param length\n * @returns string\n */\n public randomPassword = (length = 12): string => {\n const chars =\n \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n let pass = \"\";\n for (let x = 0; x < length; x++) {\n const i = Math.floor(Math.random() * chars.length);\n pass += chars.charAt(i);\n }\n return pass;\n };\n\n /**\n * Invite a user to the Cognito User Pool\n * @param opts\n */\n public inviteUser = async (opts: ICognitoInviteUser) => {\n const temporaryPassword = opts.passwordTemporary || this.randomPassword();\n\n const items: AdminCreateUserCommandInput = {\n UserPoolId: this.userPoolId,\n Username: opts.email,\n UserAttributes: [\n {\n Name: \"email\",\n Value: opts.email,\n },\n {\n Name: \"name\",\n Value: opts.name,\n },\n {\n Name: \"email_verified\",\n Value: \"true\",\n },\n ],\n DesiredDeliveryMediums: [\"EMAIL\"],\n ForceAliasCreation: false,\n MessageAction: opts.sendEmail ? \"RESEND\" : \"SUPPRESS\",\n TemporaryPassword: temporaryPassword,\n };\n\n // Add Phone Number to User Attributes if provided\n if (opts.phoneNumber && items.UserAttributes) {\n items.UserAttributes.push({\n Name: \"phone_number\",\n Value: opts.phoneNumber,\n });\n }\n\n // Add Other Attributes to User Attributes if provided\n if (opts.attributes && items.UserAttributes) {\n items.UserAttributes = items.UserAttributes.concat(opts.attributes);\n }\n\n const command = new AdminCreateUserCommand(items);\n try {\n const response = await this.cognitoIdentityProvider.send(command);\n\n /**\n * If the user is FORCE_CHANGE_PASSWORD, then change the password to the one provided\n * So that the user can login with the password provided\n */\n if (\n opts.autoConfirm &&\n response?.User?.UserStatus === \"FORCE_CHANGE_PASSWORD\"\n ) {\n const changePassword = await this.changePassword(\n opts.email,\n opts.password\n );\n\n if (changePassword?.$metadata?.httpStatusCode !== 200) {\n throw new Error(\"Error changing password\");\n }\n }\n\n return response;\n } catch (error) {\n throw error;\n }\n };\n\n /**\n * Change user password in Cognito User Pool\n * @param username - Username of the user\n * @param password - New password for the user\n */\n public changePassword = async (\n username: string,\n password: string\n ): Promise<AdminSetUserPasswordCommandOutput> => {\n const command = new AdminSetUserPasswordCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n Password: password,\n Permanent: true,\n });\n\n try {\n const response = await this.cognitoIdentityProvider.send(command);\n return response;\n } catch (error) {\n throw error;\n }\n };\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OAEK;AAwBA,MAAM,QAAQ;AAAA,EAMnB,YAAY,MAAiB;AAgB7B,SAAO,iBAAiB,CAAC,SAAS,OAAe;AAC/C,YAAM,QACJ;AACF,UAAI,OAAO;AACX,eAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,cAAM,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,MAAM,MAAM;AACjD,gBAAQ,MAAM,OAAO,CAA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AI,4BAA4B;AAAA,QAC9C,YAAY,KAAK;AAAA,QACjB,UAAU;AAAA,QACV,UAAU;AAAA,QACV,WAAW;AAAA,MACb,CAAC;AAED,UAAI;AACF,cAAM,WAAW,MAAM,KAAK,wBAAwB,KAAK,OAAO;AAChE,eAAO;AAAA,MACT,SAAS,OAAP;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAvHE,SAAK,UAAS,6BAAM,WAAU,QAAQ,IAAI,cAAc;AACxD,SAAK,cACH,6BAAM,eAAc,QAAQ,IAAI,wBAAwB;AAC1D,SAAK,YAAW,6BAAM,aAAY,QAAQ,IAAI,qBAAqB;AAEnE,SAAK,0BAA0B,IAAI,8BAA8B;AAAA,MAC/D,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AAgHF;","names":[]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
for (let key of __getOwnPropNames(from))
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
11
|
+
}
|
12
|
+
return to;
|
13
|
+
};
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
16
|
+
var src_exports = {};
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
18
|
+
__reExport(src_exports, require("./Cognito"), module.exports);
|
19
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./Cognito\";\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,sBAAd;","names":[]}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./Cognito\";\n"],"mappings":"AAAA,cAAc;","names":[]}
|
package/package.json
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
{
|
2
|
+
"name": "@juniyadi/cognito",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"main": "./dist/index.js",
|
5
|
+
"module": "./dist/index.mjs",
|
6
|
+
"types": "./dist/index.d.ts",
|
7
|
+
"sideEffects": false,
|
8
|
+
"license": "MIT",
|
9
|
+
"files": [
|
10
|
+
"dist/**"
|
11
|
+
],
|
12
|
+
"devDependencies": {
|
13
|
+
"@aws-sdk/client-cognito-identity": "^3.388.0",
|
14
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.388.0",
|
15
|
+
"@types/jest": "^29.5.3",
|
16
|
+
"@types/node": "^20.4.9",
|
17
|
+
"aws-sdk-client-mock": "^3.0.0",
|
18
|
+
"eslint": "^8.46.0",
|
19
|
+
"jest": "^29.6.2",
|
20
|
+
"ts-jest": "^29.1.1",
|
21
|
+
"tsup": "^5.12.9",
|
22
|
+
"typescript": "^4.9.5",
|
23
|
+
"@juniyadi/tsconfig": "0.0.0",
|
24
|
+
"eslint-config-juniyadi": "0.0.1"
|
25
|
+
},
|
26
|
+
"publishConfig": {
|
27
|
+
"access": "public"
|
28
|
+
},
|
29
|
+
"peerDependencies": {
|
30
|
+
"@aws-sdk/client-cognito-identity": "^3.388.0",
|
31
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.388.0"
|
32
|
+
},
|
33
|
+
"scripts": {
|
34
|
+
"build": "tsup",
|
35
|
+
"dev": "tsup --watch",
|
36
|
+
"lint": "eslint \"src/**/*.ts*\"",
|
37
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
38
|
+
"test": "jest --coverage",
|
39
|
+
"test:watch": "jest --watch"
|
40
|
+
}
|
41
|
+
}
|