aws-service-stack 0.15.211 → 0.15.212

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { CognitoUser } from "../index.js";
1
+ import { CognitoUser } from "../../index.js";
2
2
  export declare function updateCognitoUser(userPoolId: string, user: CognitoUser, password?: string): Promise<CognitoUser>;
3
3
  export declare function createCognitoUser(userPoolId: string, user: CognitoUser, password?: string): Promise<CognitoUser>;
4
4
  export declare function getCognitoUser(userPoolId: string, username: string): Promise<CognitoUser>;
@@ -53,7 +53,7 @@ exports.setProfileId = setProfileId;
53
53
  exports.setCustomValue = setCustomValue;
54
54
  exports.persistCustomValue = persistCustomValue;
55
55
  exports.findAll = findAll;
56
- const core_1 = require("../index.js");
56
+ const core_1 = require("../../index.js");
57
57
  const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
58
58
  function mapCognitoAttributes(attributes) {
59
59
  const result = {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognito.function.js","sourceRoot":"","sources":["../../../src/function/cognito/cognito.function.ts"],"names":[],"mappings":";AAAA,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBtB,8CAyCC;AAED,8CA2CC;AAED,wCAuBC;AAED,kDAUC;AACD,kDAcC;AAKD,wDAQC;AAMD,oCAcC;AAMD,wCAmBC;AAGD,gDAeC;AAED,0BA+CC;AA9RD,yCAA0E;AAE1E,gGAOmD;AAEnD,SAAS,oBAAoB,CAAC,UAA4B;IACxD,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,UAAU,IAAI,EAAE,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACjC,CAAC;IACH,CA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MAAA,QAAQ,CAAC,KAAK,0CAAE,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE;;wBAC7B,MAAM,KAAK,GAA2B,EAAE,CAAC;wBACzC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;4BACnC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK;gCAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;wBACjD,CAAC;wBAED,OAAO;4BACL,QAAQ,EAAE,CAAC,CAAC,QAAQ;4BACpB,GAAG,EAAE,KAAK,CAAC,GAAG;4BACd,KAAK,EAAE,KAAK,CAAC,KAAK;4BAClB,WAAW,EAAE,KAAK,CAAC,YAAY;4BAC/B,SAAS,EAAE,KAAK,CAAC,UAAU;4BAC3B,UAAU,EAAE,KAAK,CAAC,WAAW;4BAC7B,UAAU,EAAE,KAAK;4BACjB,UAAU,EAAE,CAAC,CAAC,UAA+B;4BAC7C,OAAO,EAAE,CAAC,CAAC,OAAO;4BAClB,SAAS,EAAE,MAAA,CAAC,CAAC,cAAc,0CAAE,WAAW,EAAE;4BAC1C,SAAS,EAAE,MAAA,CAAC,CAAC,oBAAoB,0CAAE,WAAW,EAAE;4BAChD,SAAS,EAAE,IAAI;yBACD,CAAC;oBACnB,CAAC,CAAC,KAAI,EAAE,CAAC;YACb,CAAC;YAED,MAAM,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;YAClD,IAAI,CAAC,MAAM,CAAC,eAAe;gBAAE,MAAM;YAEnC,WAAW,EAAE,CAAC;QAChB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CAAA","sourcesContent":["// cognito.function.ts\n\nimport { CognitoUser, CognitoUserStatus, TokenUse } from \"@chinggis/core\";\n\nimport {\n AdminCreateUserCommand,\n AdminGetUserCommand,\n AdminUpdateUserAttributesCommand,\n AttributeType,\n CognitoIdentityProviderClient,\n ListUsersCommand,\n} from \"@aws-sdk/client-cognito-identity-provider\";\n\nfunction mapCognitoAttributes(attributes?: AttributeType[]): Record<string, string> {\n const result: Record<string, string> = {};\n for (const attr of attributes || []) {\n if (attr.Name && attr.Value) {\n result[attr.Name] = attr.Value;\n }\n }\n return result;\n}\n\nconst cognitoClient = new CognitoIdentityProviderClient({ region: process.env.AWS_REGION });\n\nexport async function updateCognitoUser(\n userPoolId: string,\n user: CognitoUser,\n password?: string,\n): Promise<CognitoUser> {\n const userAttributes: AttributeType[] = [];\n\n if (user.email) userAttributes.push({ Name: \"email\", Value: user.email });\n if (user.phone_number) userAttributes.push({ Name: \"phone_number\", Value: user.phone_number });\n if (user.givenName) userAttributes.push({ Name: \"given_name\", Value: user.givenName });\n if (user.familyName) userAttributes.push({ Name: \"family_name\", Value: user.familyName });\n\n if (user.attributes) {\n for (const [key, value] of Object.entries(user.attributes)) {\n const attrName = key.startsWith(\"custom:\") ? key : `custom:${key}`;\n userAttributes.push({ Name: attrName, Value: String(value) });\n }\n }\n\n await cognitoClient.send(\n new AdminUpdateUserAttributesCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n UserAttributes: userAttributes,\n }),\n );\n\n if (password) {\n const { AdminSetUserPasswordCommand } = await import(\"@aws-sdk/client-cognito-identity-provider\");\n await cognitoClient.send(\n new AdminSetUserPasswordCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n Password: password,\n Permanent: true,\n }),\n );\n }\n\n const updated = await getCognitoUser(userPoolId, user.username);\n return updated;\n}\n\nexport async function createCognitoUser(\n userPoolId: string,\n user: CognitoUser,\n password?: string,\n): Promise<CognitoUser> {\n const userAttributes: AttributeType[] = [\n { Name: \"email\", Value: user.email },\n { Name: \"email_verified\", Value: \"true\" },\n ];\n\n // Add custom attributes\n if (user.attributes) {\n for (const [key, value] of Object.entries(user.attributes)) {\n const attrName = key.startsWith(\"custom:\") ? key : `custom:${key}`;\n userAttributes.push({ Name: attrName, Value: value });\n }\n }\n\n const command = new AdminCreateUserCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n UserAttributes: userAttributes,\n TemporaryPassword: password,\n MessageAction: password ? undefined : \"SUPPRESS\", // Don't send welcome email if password provided\n });\n\n const response = await cognitoClient.send(command);\n const attrs = mapCognitoAttributes(response.User?.Attributes);\n\n return {\n username: response.User?.Username || user.username,\n sub: attrs.sub,\n email: attrs.email,\n phone_number: attrs.phone_number,\n givenName: attrs.given_name,\n familyName: attrs.family_name,\n attributes: attrs,\n userStatus: response.User?.UserStatus as CognitoUserStatus,\n enabled: response.User?.Enabled,\n createdAt: response.User?.UserCreateDate?.toISOString(),\n updatedAt: response.User?.UserLastModifiedDate?.toISOString(),\n token_use: TokenUse.ID,\n };\n}\n\nexport async function getCognitoUser(userPoolId: string, username: string): Promise<CognitoUser> {\n const command = new AdminGetUserCommand({\n UserPoolId: userPoolId,\n Username: username,\n });\n\n const response = await cognitoClient.send(command);\n const attrs = mapCognitoAttributes(response.UserAttributes);\n\n return {\n username,\n sub: attrs.sub,\n email: attrs.email,\n phone_number: attrs.phone_number,\n givenName: attrs.given_name,\n familyName: attrs.family_name,\n attributes: attrs,\n userStatus: response.UserStatus as CognitoUserStatus,\n enabled: response.Enabled,\n createdAt: response.UserCreateDate?.toISOString(),\n updatedAt: response.UserLastModifiedDate?.toISOString(),\n token_use: TokenUse.ID,\n };\n}\n\nexport async function setProfileIdByEmail(userPoolId: string, email: string, profileId: string): Promise<CognitoUser> {\n // Find the user by email first\n const users = await findAll(userPoolId, 1, 1000); // Get all users to find by email\n const user = users.find((u) => u.email === email);\n\n if (!user) {\n throw new Error(`User with email ${email} not found`);\n }\n\n return setProfileId(userPoolId, user, profileId);\n}\nexport async function setProfileIdByPhone(\n userPoolId: string,\n phoneNumber: string,\n profileId: string,\n): Promise<CognitoUser> {\n // Find the user by phone number first\n const users = await findAll(userPoolId, 1, 1000); // Get all users to find by phone\n const user = users.find((u) => u.phone_number === phoneNumber);\n\n if (!user) {\n throw new Error(`User with phone number ${phoneNumber} not found`);\n }\n\n return setProfileId(userPoolId, user, profileId);\n}\n/**\n * Sets a profileId as a Cognito custom attribute.\n * Returns a **new CognitoUser object** with the attribute updated.\n */\nexport async function setProfileIdByUsername(\n userPoolId: string,\n username: string,\n profileId: string,\n): Promise<CognitoUser> {\n // Get the user first\n const user = await getCognitoUser(userPoolId, username);\n return setProfileId(userPoolId, user, profileId);\n}\n\n/**\n * Sets a profileId as a Cognito custom attribute.\n * Saves the changes to the Cognito user pool and returns the updated CognitoUser object.\n */\nexport async function setProfileId(userPoolId: string, user: CognitoUser, profileId: string): Promise<CognitoUser> {\n // Persist the custom attribute to Cognito\n await persistCustomValue(userPoolId, user, \"custom:profileId\", profileId);\n\n // Return the updated user object\n const newAttributes = {\n ...user.attributes,\n \"custom:profileId\": profileId,\n };\n\n return {\n ...user,\n attributes: newAttributes,\n };\n}\n\n/**\n * Sets a custom attribute on a CognitoUser object.\n * Saves the changes to the Cognito user pool and returns the updated CognitoUser object.\n */\nexport async function setCustomValue(\n userPoolId: string,\n user: CognitoUser,\n customFieldName: string,\n fieldValue: any,\n): Promise<CognitoUser> {\n const attrName = customFieldName.startsWith(\"custom:\") ? customFieldName : `custom:${customFieldName}`;\n\n // Persist the custom attribute to Cognito\n await persistCustomValue(userPoolId, user, customFieldName, fieldValue);\n\n // Return the updated user object\n return {\n ...user,\n attributes: {\n ...user.attributes,\n [attrName]: fieldValue,\n },\n };\n}\n\n// Optional: Persist custom attribute to Cognito\nexport async function persistCustomValue(\n userPoolId: string,\n user: CognitoUser,\n customFieldName: string,\n fieldValue: any,\n): Promise<void> {\n const attrName = customFieldName.startsWith(\"custom:\") ? customFieldName : `custom:${customFieldName}`;\n\n await cognitoClient.send(\n new AdminUpdateUserAttributesCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n UserAttributes: [{ Name: attrName, Value: String(fieldValue) }],\n }),\n );\n}\n\nexport async function findAll(userPoolId: string, page: number = 1, size: number = 50): Promise<CognitoUser[]> {\n const params = {\n UserPoolId: userPoolId,\n Limit: size,\n PaginationToken: undefined as string | undefined,\n };\n\n // simple pagination logic\n let currentPage = 1;\n let users: CognitoUser[] = [];\n\n while (currentPage <= page) {\n const command = new ListUsersCommand(params);\n const response = (await cognitoClient.send(command)) as any;\n\n if (currentPage === page) {\n users =\n response.Users?.map((u: any) => {\n const attrs: Record<string, string> = {};\n for (const a of u.Attributes || []) {\n if (a.Name && a.Value) attrs[a.Name] = a.Value;\n }\n\n return {\n username: u.Username,\n sub: attrs.sub,\n email: attrs.email,\n phoneNumber: attrs.phone_number,\n givenName: attrs.given_name,\n familyName: attrs.family_name,\n attributes: attrs,\n userStatus: u.UserStatus as CognitoUserStatus,\n enabled: u.Enabled,\n createdAt: u.UserCreateDate?.toISOString(),\n updatedAt: u.UserLastModifiedDate?.toISOString(),\n token_use: \"id\",\n } as CognitoUser;\n }) || [];\n }\n\n params.PaginationToken = response.PaginationToken;\n if (!params.PaginationToken) break;\n\n currentPage++;\n }\n\n return users;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ export * from "./cognito.function";
2
+ import { createCognitoUser, findAll, getCognitoUser, persistCustomValue, setCustomValue, setProfileId, setProfileIdByEmail, setProfileIdByPhone, setProfileIdByUsername, updateCognitoUser } from "./cognito.function";
3
+ export declare const cognito: {
4
+ create: typeof createCognitoUser;
5
+ get: typeof getCognitoUser;
6
+ findAll: typeof findAll;
7
+ update: typeof updateCognitoUser;
8
+ setProfileIdByEmail: typeof setProfileIdByEmail;
9
+ setProfileIdByPhone: typeof setProfileIdByPhone;
10
+ setProfileIdByUsername: typeof setProfileIdByUsername;
11
+ setProfileId: typeof setProfileId;
12
+ setCustomValue: typeof setCustomValue;
13
+ persistCustomValue: typeof persistCustomValue;
14
+ };
15
+ export type CognitoApi = typeof cognito;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.cognito = void 0;
18
+ __exportStar(require("./cognito.function"), exports);
19
+ const cognito_function_1 = require("./cognito.function");
20
+ exports.cognito = {
21
+ create: cognito_function_1.createCognitoUser,
22
+ get: cognito_function_1.getCognitoUser,
23
+ findAll: cognito_function_1.findAll,
24
+ update: cognito_function_1.updateCognitoUser,
25
+ setProfileIdByEmail: cognito_function_1.setProfileIdByEmail,
26
+ setProfileIdByPhone: cognito_function_1.setProfileIdByPhone,
27
+ setProfileIdByUsername: cognito_function_1.setProfileIdByUsername,
28
+ setProfileId: cognito_function_1.setProfileId,
29
+ setCustomValue: cognito_function_1.setCustomValue,
30
+ persistCustomValue: cognito_function_1.persistCustomValue,
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/function/cognito/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAmC;AAEnC,yDAW4B;AAEf,QAAA,OAAO,GAAG;IACrB,MAAM,EAAE,oCAAiB;IACzB,GAAG,EAAE,iCAAc;IACnB,OAAO,EAAP,0BAAO;IACP,MAAM,EAAE,oCAAiB;IACzB,mBAAmB,EAAnB,sCAAmB;IACnB,mBAAmB,EAAnB,sCAAmB;IACnB,sBAAsB,EAAtB,yCAAsB;IACtB,YAAY,EAAZ,+BAAY;IACZ,cAAc,EAAd,iCAAc;IACd,kBAAkB,EAAlB,qCAAkB;CACnB,CAAC","sourcesContent":["export * from \"./cognito.function\";\n\nimport {\n createCognitoUser,\n findAll,\n getCognitoUser,\n persistCustomValue,\n setCustomValue,\n setProfileId,\n setProfileIdByEmail,\n setProfileIdByPhone,\n setProfileIdByUsername,\n updateCognitoUser,\n} from \"./cognito.function\";\n\nexport const cognito = {\n create: createCognitoUser,\n get: getCognitoUser,\n findAll,\n update: updateCognitoUser,\n setProfileIdByEmail,\n setProfileIdByPhone,\n setProfileIdByUsername,\n setProfileId,\n setCustomValue,\n persistCustomValue,\n};\n\nexport type CognitoApi = typeof cognito;\n"]}
@@ -1,17 +1,18 @@
1
- export * from "./cognito.function";
2
- import { CognitoUser } from "src/model/cognito-user.model";
3
- import { createCognitoUser, findAll, getCognitoUser, persistCustomValue, setCustomValue, setProfileId, setProfileIdByEmail, setProfileIdByPhone, setProfileIdByUsername, updateCognitoUser } from "./cognito.function";
4
- export declare const cognito: {
5
- create: typeof createCognitoUser;
6
- get: typeof getCognitoUser;
7
- find: typeof findAll;
8
- update: typeof updateCognitoUser;
9
- setProfileIdByEmail: typeof setProfileIdByEmail;
10
- setProfileIdByPhone: typeof setProfileIdByPhone;
11
- setProfileIdByUsername: typeof setProfileIdByUsername;
12
- setProfileId: typeof setProfileId;
13
- setCustomValue: typeof setCustomValue;
14
- persistCustomValue: typeof persistCustomValue;
1
+ export declare const fn: {
2
+ cognito: {
3
+ create: typeof import("./cognito").createCognitoUser;
4
+ get: typeof import("./cognito").getCognitoUser;
5
+ findAll: typeof import("./cognito").findAll;
6
+ update: typeof import("./cognito").updateCognitoUser;
7
+ setProfileIdByEmail: typeof import("./cognito").setProfileIdByEmail;
8
+ setProfileIdByPhone: typeof import("./cognito").setProfileIdByPhone;
9
+ setProfileIdByUsername: typeof import("./cognito").setProfileIdByUsername;
10
+ setProfileId: typeof import("./cognito").setProfileId;
11
+ setCustomValue: typeof import("./cognito").setCustomValue;
12
+ persistCustomValue: typeof import("./cognito").persistCustomValue;
13
+ };
14
+ s3: {
15
+ createBucket: typeof import("./s3").createBucket;
16
+ };
15
17
  };
16
- export type CognitoApi = typeof cognito;
17
- export type { CognitoUser };
18
+ export type FnApi = typeof fn;
@@ -1,32 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.cognito = void 0;
18
- __exportStar(require("./cognito.function"), exports);
19
- const cognito_function_1 = require("./cognito.function");
20
- exports.cognito = {
21
- create: cognito_function_1.createCognitoUser,
22
- get: cognito_function_1.getCognitoUser,
23
- find: cognito_function_1.findAll,
24
- update: cognito_function_1.updateCognitoUser,
25
- setProfileIdByEmail: cognito_function_1.setProfileIdByEmail,
26
- setProfileIdByPhone: cognito_function_1.setProfileIdByPhone,
27
- setProfileIdByUsername: cognito_function_1.setProfileIdByUsername,
28
- setProfileId: cognito_function_1.setProfileId,
29
- setCustomValue: cognito_function_1.setCustomValue,
30
- persistCustomValue: cognito_function_1.persistCustomValue,
3
+ exports.fn = void 0;
4
+ const cognito_1 = require("./cognito");
5
+ const s3_1 = require("./s3");
6
+ exports.fn = {
7
+ cognito: cognito_1.cognito,
8
+ s3: s3_1.s3,
9
+ // dynamo,
10
+ // opensearch,
31
11
  };
32
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/function/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAmC;AAGnC,yDAW4B;AAEf,QAAA,OAAO,GAAG;IACrB,MAAM,EAAE,oCAAiB;IACzB,GAAG,EAAE,iCAAc;IACnB,IAAI,EAAE,0BAAO;IACb,MAAM,EAAE,oCAAiB;IACzB,mBAAmB,EAAnB,sCAAmB;IACnB,mBAAmB,EAAnB,sCAAmB;IACnB,sBAAsB,EAAtB,yCAAsB;IACtB,YAAY,EAAZ,+BAAY;IACZ,cAAc,EAAd,iCAAc;IACd,kBAAkB,EAAlB,qCAAkB;CACnB,CAAC","sourcesContent":["export * from \"./cognito.function\";\n\nimport { CognitoUser } from \"src/model/cognito-user.model\";\nimport {\n createCognitoUser,\n findAll,\n getCognitoUser,\n persistCustomValue,\n setCustomValue,\n setProfileId,\n setProfileIdByEmail,\n setProfileIdByPhone,\n setProfileIdByUsername,\n updateCognitoUser,\n} from \"./cognito.function\";\n\nexport const cognito = {\n create: createCognitoUser,\n get: getCognitoUser,\n find: findAll,\n update: updateCognitoUser,\n setProfileIdByEmail,\n setProfileIdByPhone,\n setProfileIdByUsername,\n setProfileId,\n setCustomValue,\n persistCustomValue,\n};\n\n// optional: für Typ-IntelliSense exportieren\nexport type CognitoApi = typeof cognito;\nexport type { CognitoUser };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/function/index.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,6BAA0B;AAEb,QAAA,EAAE,GAAG;IAChB,OAAO,EAAP,iBAAO;IACP,EAAE,EAAF,OAAE;IACF,UAAU;IACV,cAAc;CACf,CAAC","sourcesContent":["import { cognito } from \"./cognito\";\nimport { s3 } from \"./s3\";\n\nexport const fn = {\n cognito,\n s3,\n // dynamo,\n // opensearch,\n};\n\nexport type FnApi = typeof fn;\n"]}
@@ -0,0 +1,6 @@
1
+ export * from "./s3.function";
2
+ import { createBucket } from "./s3.function";
3
+ export declare const s3: {
4
+ createBucket: typeof createBucket;
5
+ };
6
+ export type S3Api = typeof s3;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.s3 = void 0;
18
+ __exportStar(require("./s3.function"), exports);
19
+ const s3_function_1 = require("./s3.function");
20
+ exports.s3 = {
21
+ createBucket: s3_function_1.createBucket,
22
+ // uploadFile,
23
+ // deleteObject,
24
+ // listObjects,
25
+ };
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/function/s3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA8B;AAE9B,+CAA6C;AAEhC,QAAA,EAAE,GAAG;IAChB,YAAY,EAAZ,0BAAY;IACZ,eAAe;IACf,iBAAiB;IACjB,gBAAgB;CACjB,CAAC","sourcesContent":["export * from \"./s3.function\";\n\nimport { createBucket } from \"./s3.function\";\n\nexport const s3 = {\n createBucket,\n // uploadFile,\n // deleteObject,\n // listObjects,\n};\n\nexport type S3Api = typeof s3;\n"]}
@@ -0,0 +1 @@
1
+ export declare function createBucket(): void;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBucket = createBucket;
4
+ function createBucket() {
5
+ log.debug("S3 createBucket demo function");
6
+ }
7
+ //# sourceMappingURL=s3.function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.function.js","sourceRoot":"","sources":["../../../src/function/s3/s3.function.ts"],"names":[],"mappings":";;AAAA,oCAEC;AAFD,SAAgB,YAAY;IAC1B,GAAG,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["export function createBucket(): void {\n log.debug(\"S3 createBucket demo function\");\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export * from "./controller";
5
5
  export * from "./provider";
6
6
  export * from "./model";
7
7
  export * from "./exception";
8
- export * from "./function";
8
+ export * from "./function/cognito";
package/dist/index.js CHANGED
@@ -21,5 +21,5 @@ __exportStar(require("./controller"), exports);
21
21
  __exportStar(require("./provider"), exports);
22
22
  __exportStar(require("./model"), exports);
23
23
  __exportStar(require("./exception"), exports);
24
- __exportStar(require("./function"), exports);
24
+ __exportStar(require("./function/cognito"), exports);
25
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,4CAA0B;AAC1B,0CAAwB;AACxB,+CAA6B;AAC7B,6CAA2B;AAC3B,0CAAwB;AACxB,8CAA4B;AAC5B,6CAA2B","sourcesContent":["export * from \"./repositories\";\nexport * from \"./service\";\nexport * from \"./utils\";\nexport * from \"./controller\";\nexport * from \"./provider\";\nexport * from \"./model\";\nexport * from \"./exception\";\nexport * from \"./function\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,4CAA0B;AAC1B,0CAAwB;AACxB,+CAA6B;AAC7B,6CAA2B;AAC3B,0CAAwB;AACxB,8CAA4B;AAC5B,qDAAmC","sourcesContent":["export * from \"./repositories\";\nexport * from \"./service\";\nexport * from \"./utils\";\nexport * from \"./controller\";\nexport * from \"./provider\";\nexport * from \"./model\";\nexport * from \"./exception\";\nexport * from \"./function/cognito\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-service-stack",
3
- "version": "0.15.211",
3
+ "version": "0.15.212",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "chinggis.systems",
@@ -1 +0,0 @@
1
- {"version":3,"file":"cognito.function.js","sourceRoot":"","sources":["../../src/function/cognito.function.ts"],"names":[],"mappings":";AAAA,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBtB,8CAyCC;AAED,8CA2CC;AAED,wCAuBC;AAED,kDAUC;AACD,kDAcC;AAKD,wDAQC;AAMD,oCAcC;AAMD,wCAmBC;AAGD,gDAeC;AAED,0BA+CC;AA9RD,yCAA0E;AAE1E,gGAOmD;AAEnD,SAAS,oBAAoB,CAAC,UAA4B;IACxD,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,UAAU,IAAI,EAAE,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,aAAa,GAAG,IAAI,gEAA6B,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;AAE5F,SAAsB,iBAAiB,CACrC,UAAkB,EAClB,IAAiB,EACjB,QAAiB;;QAEjB,MAAM,cAAc,GAAoB,EAAE,CAAC;QAE3C,IAAI,IAAI,CAAC,KAAK;YAAE,cAAc,CA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AC,KAAK,CAAC;wBACjD,CAAC;wBAED,OAAO;4BACL,QAAQ,EAAE,CAAC,CAAC,QAAQ;4BACpB,GAAG,EAAE,KAAK,CAAC,GAAG;4BACd,KAAK,EAAE,KAAK,CAAC,KAAK;4BAClB,WAAW,EAAE,KAAK,CAAC,YAAY;4BAC/B,SAAS,EAAE,KAAK,CAAC,UAAU;4BAC3B,UAAU,EAAE,KAAK,CAAC,WAAW;4BAC7B,UAAU,EAAE,KAAK;4BACjB,UAAU,EAAE,CAAC,CAAC,UAA+B;4BAC7C,OAAO,EAAE,CAAC,CAAC,OAAO;4BAClB,SAAS,EAAE,MAAA,CAAC,CAAC,cAAc,0CAAE,WAAW,EAAE;4BAC1C,SAAS,EAAE,MAAA,CAAC,CAAC,oBAAoB,0CAAE,WAAW,EAAE;4BAChD,SAAS,EAAE,IAAI;yBACD,CAAC;oBACnB,CAAC,CAAC,KAAI,EAAE,CAAC;YACb,CAAC;YAED,MAAM,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;YAClD,IAAI,CAAC,MAAM,CAAC,eAAe;gBAAE,MAAM;YAEnC,WAAW,EAAE,CAAC;QAChB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CAAA","sourcesContent":["// cognito.function.ts\n\nimport { CognitoUser, CognitoUserStatus, TokenUse } from \"@chinggis/core\";\n\nimport {\n AdminCreateUserCommand,\n AdminGetUserCommand,\n AdminUpdateUserAttributesCommand,\n AttributeType,\n CognitoIdentityProviderClient,\n ListUsersCommand,\n} from \"@aws-sdk/client-cognito-identity-provider\";\n\nfunction mapCognitoAttributes(attributes?: AttributeType[]): Record<string, string> {\n const result: Record<string, string> = {};\n for (const attr of attributes || []) {\n if (attr.Name && attr.Value) {\n result[attr.Name] = attr.Value;\n }\n }\n return result;\n}\n\nconst cognitoClient = new CognitoIdentityProviderClient({ region: process.env.AWS_REGION });\n\nexport async function updateCognitoUser(\n userPoolId: string,\n user: CognitoUser,\n password?: string,\n): Promise<CognitoUser> {\n const userAttributes: AttributeType[] = [];\n\n if (user.email) userAttributes.push({ Name: \"email\", Value: user.email });\n if (user.phone_number) userAttributes.push({ Name: \"phone_number\", Value: user.phone_number });\n if (user.givenName) userAttributes.push({ Name: \"given_name\", Value: user.givenName });\n if (user.familyName) userAttributes.push({ Name: \"family_name\", Value: user.familyName });\n\n if (user.attributes) {\n for (const [key, value] of Object.entries(user.attributes)) {\n const attrName = key.startsWith(\"custom:\") ? key : `custom:${key}`;\n userAttributes.push({ Name: attrName, Value: String(value) });\n }\n }\n\n await cognitoClient.send(\n new AdminUpdateUserAttributesCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n UserAttributes: userAttributes,\n }),\n );\n\n if (password) {\n const { AdminSetUserPasswordCommand } = await import(\"@aws-sdk/client-cognito-identity-provider\");\n await cognitoClient.send(\n new AdminSetUserPasswordCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n Password: password,\n Permanent: true,\n }),\n );\n }\n\n const updated = await getCognitoUser(userPoolId, user.username);\n return updated;\n}\n\nexport async function createCognitoUser(\n userPoolId: string,\n user: CognitoUser,\n password?: string,\n): Promise<CognitoUser> {\n const userAttributes: AttributeType[] = [\n { Name: \"email\", Value: user.email },\n { Name: \"email_verified\", Value: \"true\" },\n ];\n\n // Add custom attributes\n if (user.attributes) {\n for (const [key, value] of Object.entries(user.attributes)) {\n const attrName = key.startsWith(\"custom:\") ? key : `custom:${key}`;\n userAttributes.push({ Name: attrName, Value: value });\n }\n }\n\n const command = new AdminCreateUserCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n UserAttributes: userAttributes,\n TemporaryPassword: password,\n MessageAction: password ? undefined : \"SUPPRESS\", // Don't send welcome email if password provided\n });\n\n const response = await cognitoClient.send(command);\n const attrs = mapCognitoAttributes(response.User?.Attributes);\n\n return {\n username: response.User?.Username || user.username,\n sub: attrs.sub,\n email: attrs.email,\n phone_number: attrs.phone_number,\n givenName: attrs.given_name,\n familyName: attrs.family_name,\n attributes: attrs,\n userStatus: response.User?.UserStatus as CognitoUserStatus,\n enabled: response.User?.Enabled,\n createdAt: response.User?.UserCreateDate?.toISOString(),\n updatedAt: response.User?.UserLastModifiedDate?.toISOString(),\n token_use: TokenUse.ID,\n };\n}\n\nexport async function getCognitoUser(userPoolId: string, username: string): Promise<CognitoUser> {\n const command = new AdminGetUserCommand({\n UserPoolId: userPoolId,\n Username: username,\n });\n\n const response = await cognitoClient.send(command);\n const attrs = mapCognitoAttributes(response.UserAttributes);\n\n return {\n username,\n sub: attrs.sub,\n email: attrs.email,\n phone_number: attrs.phone_number,\n givenName: attrs.given_name,\n familyName: attrs.family_name,\n attributes: attrs,\n userStatus: response.UserStatus as CognitoUserStatus,\n enabled: response.Enabled,\n createdAt: response.UserCreateDate?.toISOString(),\n updatedAt: response.UserLastModifiedDate?.toISOString(),\n token_use: TokenUse.ID,\n };\n}\n\nexport async function setProfileIdByEmail(userPoolId: string, email: string, profileId: string): Promise<CognitoUser> {\n // Find the user by email first\n const users = await findAll(userPoolId, 1, 1000); // Get all users to find by email\n const user = users.find((u) => u.email === email);\n\n if (!user) {\n throw new Error(`User with email ${email} not found`);\n }\n\n return setProfileId(userPoolId, user, profileId);\n}\nexport async function setProfileIdByPhone(\n userPoolId: string,\n phoneNumber: string,\n profileId: string,\n): Promise<CognitoUser> {\n // Find the user by phone number first\n const users = await findAll(userPoolId, 1, 1000); // Get all users to find by phone\n const user = users.find((u) => u.phone_number === phoneNumber);\n\n if (!user) {\n throw new Error(`User with phone number ${phoneNumber} not found`);\n }\n\n return setProfileId(userPoolId, user, profileId);\n}\n/**\n * Sets a profileId as a Cognito custom attribute.\n * Returns a **new CognitoUser object** with the attribute updated.\n */\nexport async function setProfileIdByUsername(\n userPoolId: string,\n username: string,\n profileId: string,\n): Promise<CognitoUser> {\n // Get the user first\n const user = await getCognitoUser(userPoolId, username);\n return setProfileId(userPoolId, user, profileId);\n}\n\n/**\n * Sets a profileId as a Cognito custom attribute.\n * Saves the changes to the Cognito user pool and returns the updated CognitoUser object.\n */\nexport async function setProfileId(userPoolId: string, user: CognitoUser, profileId: string): Promise<CognitoUser> {\n // Persist the custom attribute to Cognito\n await persistCustomValue(userPoolId, user, \"custom:profileId\", profileId);\n\n // Return the updated user object\n const newAttributes = {\n ...user.attributes,\n \"custom:profileId\": profileId,\n };\n\n return {\n ...user,\n attributes: newAttributes,\n };\n}\n\n/**\n * Sets a custom attribute on a CognitoUser object.\n * Saves the changes to the Cognito user pool and returns the updated CognitoUser object.\n */\nexport async function setCustomValue(\n userPoolId: string,\n user: CognitoUser,\n customFieldName: string,\n fieldValue: any,\n): Promise<CognitoUser> {\n const attrName = customFieldName.startsWith(\"custom:\") ? customFieldName : `custom:${customFieldName}`;\n\n // Persist the custom attribute to Cognito\n await persistCustomValue(userPoolId, user, customFieldName, fieldValue);\n\n // Return the updated user object\n return {\n ...user,\n attributes: {\n ...user.attributes,\n [attrName]: fieldValue,\n },\n };\n}\n\n// Optional: Persist custom attribute to Cognito\nexport async function persistCustomValue(\n userPoolId: string,\n user: CognitoUser,\n customFieldName: string,\n fieldValue: any,\n): Promise<void> {\n const attrName = customFieldName.startsWith(\"custom:\") ? customFieldName : `custom:${customFieldName}`;\n\n await cognitoClient.send(\n new AdminUpdateUserAttributesCommand({\n UserPoolId: userPoolId,\n Username: user.username,\n UserAttributes: [{ Name: attrName, Value: String(fieldValue) }],\n }),\n );\n}\n\nexport async function findAll(userPoolId: string, page: number = 1, size: number = 50): Promise<CognitoUser[]> {\n const params = {\n UserPoolId: userPoolId,\n Limit: size,\n PaginationToken: undefined as string | undefined,\n };\n\n // simple pagination logic\n let currentPage = 1;\n let users: CognitoUser[] = [];\n\n while (currentPage <= page) {\n const command = new ListUsersCommand(params);\n const response = (await cognitoClient.send(command)) as any;\n\n if (currentPage === page) {\n users =\n response.Users?.map((u: any) => {\n const attrs: Record<string, string> = {};\n for (const a of u.Attributes || []) {\n if (a.Name && a.Value) attrs[a.Name] = a.Value;\n }\n\n return {\n username: u.Username,\n sub: attrs.sub,\n email: attrs.email,\n phoneNumber: attrs.phone_number,\n givenName: attrs.given_name,\n familyName: attrs.family_name,\n attributes: attrs,\n userStatus: u.UserStatus as CognitoUserStatus,\n enabled: u.Enabled,\n createdAt: u.UserCreateDate?.toISOString(),\n updatedAt: u.UserLastModifiedDate?.toISOString(),\n token_use: \"id\",\n } as CognitoUser;\n }) || [];\n }\n\n params.PaginationToken = response.PaginationToken;\n if (!params.PaginationToken) break;\n\n currentPage++;\n }\n\n return users;\n}\n"]}