@ez4/aws-function 0.28.1 → 0.30.0

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.
@@ -3,15 +3,19 @@ import type { Arn } from '@ez4/aws-common';
3
3
  import type { CreateRequest, ImportOrCreateResponse } from './client';
4
4
  export declare const FunctionServiceName = "AWS:Lambda/Function";
5
5
  export declare const FunctionServiceType = "aws:lambda.function";
6
- export type GetFunctionBundle = (context: StepContext) => Promise<string> | string;
7
6
  export type GetFunctionFiles = () => [string, string[]];
7
+ export type GetFunctionBundle = (context: StepContext) => Promise<string> | string;
8
+ export type GetFunctionHash = () => Promise<string | undefined> | string | undefined;
8
9
  export type FunctionParameters = Omit<CreateRequest, 'roleArn' | 'publish'> & {
9
- getFunctionBundle: GetFunctionBundle;
10
10
  getFunctionFiles: GetFunctionFiles;
11
+ getFunctionBundle: GetFunctionBundle;
12
+ getFunctionHash: GetFunctionHash;
11
13
  };
12
14
  export type FunctionResult = ImportOrCreateResponse & {
13
- logGroup?: string;
15
+ valuesHash?: string;
14
16
  sourceHash: string;
17
+ bundleHash: string;
18
+ logGroup?: string;
15
19
  roleArn: Arn;
16
20
  };
17
21
  export type FunctionState = EntryState & {
package/dist/main.cjs CHANGED
@@ -1,150 +1,156 @@
1
- "use strict";var Qe=Object.create;var A=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var n=(e,t)=>A(e,"name",{value:t,configurable:!0});var Ye=(e,t)=>{for(var r in t)A(e,r,{get:t[r],enumerable:!0})},Q=(e,t,r,o)=>{if(t&&
2
- typeof t=="object"||typeof t=="function")for(let i of Ke(t))!Xe.call(e,i)&&i!==r&&
3
- A(e,i,{get:()=>t[i],enumerable:!(o=Je(t,i))||o.enumerable});return e};var et=(e,t,r)=>(r=e!=null?Qe(_e(e)):{},Q(t||!e||!e.__esModule?A(r,"default",{value:e,
4
- enumerable:!0}):r,e)),tt=e=>Q(A({},"__esModule",{value:!0}),e);var Ut={};Ye(Ut,{FunctionServiceName:()=>p,FunctionServiceType:()=>f,MappingService:()=>Z,
5
- MappingServiceName:()=>y,MappingServiceType:()=>x,PermissionServiceName:()=>P,PermissionServiceType:()=>S,
6
- createFunction:()=>ht,createMapping:()=>Nt,createPermission:()=>It,getFunctionArn:()=>ft,
7
- getFunctionName:()=>C,getFunctionState:()=>gt,getPermission:()=>Mt,isFunctionState:()=>q,
8
- isMappingState:()=>Tt,registerTriggers:()=>Et,tryGetFunctionArn:()=>ue,tryGetFunctionState:()=>lt});
9
- module.exports=tt(Ut);var ze=require("@ez4/aws-common"),Ge=require("@ez4/aws-identity"),Ve=require("@ez4/aws-logs"),
10
- He=require("@ez4/project/library");var ce=require("@ez4/aws-common");var F=require("@ez4/aws-common"),M=require("@ez4/utils"),O=require("@ez4/aws-logs"),
11
- B=require("@ez4/aws-identity");var s=require("@aws-sdk/client-lambda"),c=require("@ez4/aws-common");var J=require("@ez4/aws-common"),K=require("@ez4/utils");var p="AWS:Lambda/Function",f="aws:lambda.function";var rt=/[a-z][\w]+/i,nt=n(e=>rt.test(e),"isValidName"),L=n(e=>{for(let t in e)if(!nt(
12
- t))throw new J.InvalidParameterError(p,`${t} is an invalid variable name .`)},"a\
13
- ssertVariables"),h=n(e=>{let t={};for(let r in e)t[r]=(0,K.hashData)(e[r]);return t},
14
- "protectVariables");var _=et(require("adm-zip"),1),X=require("node:fs/promises");var Y=n(async(e,t)=>{let r=new _.default,o=await(0,X.readFile)(e);return r.addFile(
15
- t,o),r.toBufferPromise()},"getZipBuffer");var d=new s.LambdaClient({}),I={minDelay:15,maxWaitTime:1800,maxDelay:60,client:d},
16
- ee=n(async(e,t)=>{c.Logger.logImport(p,e);try{let r=await d.send(new s.GetFunctionCommand(
17
- {FunctionName:e,Qualifier:t})),o=r.Configuration.Version,i=r.Configuration.FunctionArn;
18
- return{functionVersion:o,functionArn:i}}catch(r){if(!(r instanceof s.ResourceNotFoundException))
19
- throw r;return}},"importFunction"),te=n(async e=>{let{functionName:t,variables:r}=e;
20
- c.Logger.logCreate(p,t),r&&L(r);let o=se(e.handlerName),i=await ie(e.sourceFile),
21
- a=await(0,c.waitCreation)(()=>d.send(new s.CreateFunctionCommand({FunctionName:e.
1
+ "use strict";var Qe=Object.create;var I=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var r=(e,t)=>I(e,"name",{value:t,configurable:!0});var Ye=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,o)=>{if(t&&
2
+ typeof t=="object"||typeof t=="function")for(let i of Ke(t))!Xe.call(e,i)&&i!==n&&
3
+ I(e,i,{get:()=>t[i],enumerable:!(o=Je(t,i))||o.enumerable});return e};var et=(e,t,n)=>(n=e!=null?Qe(_e(e)):{},K(t||!e||!e.__esModule?I(n,"default",{value:e,
4
+ enumerable:!0}):n,e)),tt=e=>K(I({},"__esModule",{value:!0}),e);var Ut={};Ye(Ut,{FunctionServiceName:()=>p,FunctionServiceType:()=>f,MappingService:()=>j,
5
+ MappingServiceName:()=>y,MappingServiceType:()=>P,PermissionServiceName:()=>C,PermissionServiceType:()=>w,
6
+ buildFunctionArn:()=>Tt,createFunction:()=>Et,createMapping:()=>Nt,createPermission:()=>It,
7
+ getFunctionArn:()=>ft,getFunctionName:()=>b,getFunctionState:()=>gt,getPermission:()=>Mt,
8
+ isFunctionState:()=>k,isMappingState:()=>Ht,registerTriggers:()=>bt,tryGetFunctionArn:()=>ge,
9
+ tryGetFunctionState:()=>lt});module.exports=tt(Ut);var Ge=require("@ez4/aws-common"),Ve=require("@ez4/aws-identity"),Be=require("@ez4/aws-logs"),
10
+ Oe=require("@ez4/project/library");var ue=require("@ez4/aws-common");var d=require("@ez4/aws-common"),R=require("@ez4/utils"),W=require("@ez4/aws-logs"),
11
+ $=require("@ez4/aws-identity");var s=require("@aws-sdk/client-lambda"),c=require("@ez4/aws-common");var _=require("@ez4/aws-common"),X=require("@ez4/utils");var p="AWS:Lambda/Function",f="aws:lambda.function";var nt=/[a-z][\w]+/i,rt=r(e=>nt.test(e),"isValidName"),z=r(e=>{for(let t in e)if(!rt(
12
+ t))throw new _.InvalidParameterError(p,`${t} is an invalid variable name .`)},"a\
13
+ ssertVariables"),N=r(e=>{let t={};for(let n in e)t[n]=(0,X.hashData)(e[n]);return t},
14
+ "protectVariables");var Y=et(require("adm-zip"),1),ee=require("node:fs/promises");var te=r(async(e,t)=>{let n=new Y.default,o=await(0,ee.readFile)(e);return n.addFile(
15
+ t,o),n.toBufferPromise()},"getZipBuffer");var F=new s.LambdaClient({}),H={minDelay:15,maxWaitTime:1800,maxDelay:60,client:F},
16
+ ne=r(async(e,t)=>{c.Logger.logImport(p,e);try{let n=await F.send(new s.GetFunctionCommand(
17
+ {FunctionName:e,Qualifier:t})),o=n.Configuration.Version,i=n.Configuration.FunctionArn;
18
+ return{functionVersion:o,functionArn:i}}catch(n){if(!(n instanceof s.ResourceNotFoundException))
19
+ throw n;return}},"importFunction"),re=r(async e=>{let{functionName:t,variables:n}=e;
20
+ c.Logger.logCreate(p,t),n&&z(n);let o=pe(e.handlerName),i=await ae(e.sourceFile),
21
+ a=await(0,c.waitCreation)(()=>F.send(new s.CreateFunctionCommand({FunctionName:e.
22
22
  functionName,Description:e.description,MemorySize:e.memory,Timeout:e.timeout,Role:e.
23
23
  roleArn,Handler:o,Runtime:"nodejs22.x",PackageType:"Zip",LoggingConfig:{LogGroup:e.
24
24
  logGroup,ApplicationLogLevel:e.debug?s.ApplicationLogLevel.Debug:s.ApplicationLogLevel.
25
25
  Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.Json},Code:{ZipFile:i},
26
- Environment:{Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.Logger.logWait(
27
- p,t),await(0,s.waitUntilFunctionActive)(I,{FunctionName:t});let u=a.FunctionArn;
28
- return e.publish?{functionVersion:await ne(t),functionArn:u}:{functionArn:u}},"c\
29
- reateFunction"),z=n(async(e,t)=>{c.Logger.logUpdate(p,`${e} source code`);let r=await ie(
30
- t.sourceFile),o=await d.send(new s.UpdateFunctionCodeCommand({FunctionName:e,Publish:t.
31
- publish,ZipFile:r}));c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(I,
32
- {FunctionName:e});let i=o.FunctionArn;return t.publish?{functionVersion:await ne(
33
- e),functionArn:i}:{functionArn:i}},"updateSourceCode"),G=n(async(e,t)=>{let{handlerName:r,
34
- variables:o}=t;c.Logger.logUpdate(p,`${e} configuration`),o&&L(o),await d.send(new s.UpdateFunctionConfigurationCommand(
26
+ Environment:{Variables:n},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.Logger.logWait(
27
+ p,t),await(0,s.waitUntilFunctionActive)(H,{FunctionName:t});let u=a.FunctionArn;
28
+ return e.publish?{functionVersion:await ie(t),functionArn:u}:{functionArn:u}},"c\
29
+ reateFunction"),G=r(async(e,t)=>{c.Logger.logUpdate(p,`${e} source code`);let n=await ae(
30
+ t.sourceFile),o=await F.send(new s.UpdateFunctionCodeCommand({FunctionName:e,Publish:t.
31
+ publish,ZipFile:n}));c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(H,
32
+ {FunctionName:e});let i=o.FunctionArn;return t.publish?{functionVersion:await ie(
33
+ e),functionArn:i}:{functionArn:i}},"updateSourceCode"),V=r(async(e,t)=>{let{handlerName:n,
34
+ variables:o}=t;c.Logger.logUpdate(p,`${e} configuration`),o&&z(o),await F.send(new s.UpdateFunctionConfigurationCommand(
35
35
  {FunctionName:e,Description:t.description,MemorySize:t.memory,Timeout:t.timeout,
36
- Role:t.roleArn,Runtime:"nodejs22.x",...r&&{Handler:se(r)},LoggingConfig:{LogGroup:t.
36
+ Role:t.roleArn,Runtime:"nodejs22.x",...n&&{Handler:pe(n)},LoggingConfig:{LogGroup:t.
37
37
  logGroup,ApplicationLogLevel:t.debug?s.ApplicationLogLevel.Debug:s.ApplicationLogLevel.
38
38
  Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.Json},Environment:{
39
- Variables:o}})),c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(I,{FunctionName:e})},
40
- "updateConfiguration"),re=n(async e=>{c.Logger.logDelete(p,e),await(0,c.waitDeletion)(
41
- async()=>{try{await d.send(new s.DeleteFunctionCommand({FunctionName:e}))}catch(t){
42
- if(!(t instanceof s.ResourceNotFoundException))throw t}})},"deleteFunction"),ne=n(
43
- async e=>{c.Logger.logPublish(p,e);let t=await d.send(new s.PublishVersionCommand(
44
- {FunctionName:e}));c.Logger.logWait(p,e);let r=t.Version;return await(0,s.waitUntilPublishedVersionActive)(
45
- I,{FunctionName:e,Qualifier:r}),r},"publishFunction"),V=n(async(e,t)=>{let r=(0,c.tryParseArn)(
46
- e)?.resourceName??e;c.Logger.logTag(p,r),await d.send(new s.TagResourceCommand({
47
- Resource:e,Tags:{...t,ManagedBy:"EZ4"}}))},"tagFunction"),oe=n(async(e,t)=>{let r=(0,c.tryParseArn)(
48
- e)?.resourceName??e;c.Logger.logUntag(p,r),await d.send(new s.UntagResourceCommand(
49
- {Resource:e,TagKeys:t}))},"untagFunction"),ie=n(e=>Y(e,"main.mjs"),"getSourceZip\
50
- File"),se=n(e=>`main.${e}`,"getSourceHandlerName");var ae=n(()=>({equals:ot,create:pe,replace:st,preview:it,update:at,delete:pt}),"\
51
- getFunctionHandler"),ot=n((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
52
- "equalsResource"),it=n(async(e,t)=>{let r=e.parameters,o=t.parameters,i=(0,M.deepCompare)(
53
- {...r,dependencies:e.dependencies,sourceHash:await(0,F.getBundleHash)(...r.getFunctionFiles()),
54
- ...r.variables&&{variables:h(r.variables)}},{...o,dependencies:t.dependencies,sourceHash:t.
55
- result?.sourceHash});if(i.counts)return{...i,name:r.functionName}},"previewResou\
56
- rce"),st=n(async(e,t,r)=>{if(t.result)throw new F.ReplaceResourceError(p,e.entryId,
57
- t.entryId);return pe(e,r)},"replaceResource"),pe=n(async(e,t)=>{let r=e.parameters,
58
- o=r.functionName,i=(0,B.getRoleArn)(p,o,t),a=(0,O.getLogGroupName)(p,o,t),[u,l]=await Promise.
59
- all([(0,F.getBundleHash)(...r.getFunctionFiles()),r.getFunctionBundle(t)]),g=await ee(
60
- o);if(g)return await G(o,{...r,logGroup:a,roleArn:i}),await z(o,{publish:!1,sourceFile:l}),
61
- await V(g.functionArn,{...r.tags}),H(e),{functionArn:g.functionArn,functionVersion:g.
62
- functionVersion,sourceHash:u,logGroup:a,roleArn:i};let E=await te({...r,publish:!0,
63
- sourceFile:l,logGroup:a,roleArn:i});return H(e),{functionArn:E.functionArn,functionVersion:E.
64
- functionVersion,sourceHash:u,logGroup:a,roleArn:i}},"createResource"),at=n(async(e,t,r)=>{
65
- let{parameters:o,result:i}=e;if(!i)return;let a=o.functionName,u=(0,B.getRoleArn)(
66
- p,a,r),l=t.result?.roleArn??u,g=(0,O.getLogGroupName)(p,a,r),E=t.result?.logGroup??
67
- g,Ze={...o,roleArn:u,logGroup:g},ke={...t.parameters,roleArn:l,logGroup:E};await ct(
68
- a,Ze,ke),await mt(i.functionArn,o,t.parameters);let je=await ut(a,o,t.result,r);
69
- return H(e),{...i,...je,logGroup:g,roleArn:u}},"updateResource"),pt=n(async e=>{
70
- let{result:t,parameters:r}=e;t&&await re(r.functionName)},"deleteResource"),H=n(
71
- e=>{let{parameters:t}=e;return t.variables&&(t.variables=h(t.variables)),e},"loc\
72
- kSensitiveData"),ct=n(async(e,t,r)=>{let o={...t,...t.variables&&{variables:h(t.
73
- variables)}};!(0,M.deepEqual)(o,r,{exclude:{sourceFile:!0,functionName:!0,tags:!0}})&&
74
- await G(e,t)},"checkConfigurationUpdates"),mt=n(async(e,t,r)=>{await(0,F.applyTagUpdates)(
75
- t.tags,r.tags,o=>V(e,o),o=>oe(e,o))},"checkTagUpdates"),ut=n(async(e,t,r,o)=>{let i=await(0,F.getBundleHash)(
76
- ...t.getFunctionFiles()),a=r?.sourceHash;if(i===a&&!o.force)return r;let u=await t.
77
- getFunctionBundle(o),{functionVersion:l}=await z(e,{publish:!r?.functionVersion,
78
- sourceFile:u});return{sourceHash:i,...l&&{functionVersion:l}}},"checkSourceCodeU\
79
- pdates");var me=n(()=>{(0,ce.registerProvider)(f,ae())},"registerFunctionProvider");var Fe=require("@ez4/aws-common");var ye=require("@ez4/aws-common");var W=require("@ez4/aws-common");var N=class extends Error{static{n(this,"FunctionNotFoundError")}constructor(t){
80
- super(`Function ${t} wasn't found.`)}};var q=n(e=>e.type===f,"isFunctionState"),lt=n((e,t,r)=>{try{let o=e.getServiceState(
81
- t,r);if(q(o))return o}catch{}},"tryGetFunctionState"),gt=n((e,t,r)=>{let o=e.getServiceState(
82
- t,r);if(!q(o))throw new N(t);return o},"getFunctionState"),C=n((e,t,r)=>{let o=r.
83
- getDependencies(f).at(0)?.parameters;if(!o?.functionName)throw new W.IncompleteResourceError(
84
- e,t,"functionName");return o.functionName},"getFunctionName"),ue=n(e=>e.getDependencies(
85
- f)[0]?.result?.functionArn,"tryGetFunctionArn"),ft=n((e,t,r)=>{let o=ue(r);if(!o)
86
- throw new W.IncompleteResourceError(e,t,"functionArn");return o},"getFunctionArn");var w=require("@aws-sdk/client-lambda"),$=require("@ez4/aws-common");var P="AWS:Lambda/Permission",S="aws:lambda.permission";var le=new w.LambdaClient({}),ge=n(async e=>{$.Logger.logCreate(P,e.functionName);
87
- let t=e.statementId??`SID${Date.now()}`;return await le.send(new w.AddPermissionCommand(
39
+ Variables:o}})),c.Logger.logWait(p,e),await(0,s.waitUntilFunctionUpdated)(H,{FunctionName:e})},
40
+ "updateConfiguration"),oe=r(async e=>{c.Logger.logDelete(p,e),await(0,c.waitDeletion)(
41
+ async()=>{try{await F.send(new s.DeleteFunctionCommand({FunctionName:e}))}catch(t){
42
+ if(!(t instanceof s.ResourceNotFoundException))throw t}})},"deleteFunction"),ie=r(
43
+ async e=>{c.Logger.logPublish(p,e);let t=await F.send(new s.PublishVersionCommand(
44
+ {FunctionName:e}));c.Logger.logWait(p,e);let n=t.Version;return await(0,s.waitUntilPublishedVersionActive)(
45
+ H,{FunctionName:e,Qualifier:n}),n},"publishFunction"),B=r(async(e,t)=>{let n=(0,c.tryParseArn)(
46
+ e)?.resourceName??e;c.Logger.logTag(p,n),await F.send(new s.TagResourceCommand({
47
+ Resource:e,Tags:{...t,ManagedBy:"EZ4"}}))},"tagFunction"),se=r(async(e,t)=>{let n=(0,c.tryParseArn)(
48
+ e)?.resourceName??e;c.Logger.logUntag(p,n),await F.send(new s.UntagResourceCommand(
49
+ {Resource:e,TagKeys:t}))},"untagFunction"),ae=r(e=>te(e,"main.mjs"),"getSourceZi\
50
+ pFile"),pe=r(e=>`main.${e}`,"getSourceHandlerName");var ce=r(()=>({equals:ot,create:me,replace:st,preview:it,update:at,delete:pt}),"\
51
+ getFunctionHandler"),ot=r((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
52
+ "equalsResource"),it=r(async(e,t)=>{let n=e.parameters,o=t.parameters,i=(0,R.deepCompare)(
53
+ {...n,connections:e.connections,dependencies:e.dependencies,variables:n.variables&&
54
+ N(n.variables),sourceHash:await(0,d.getBundleHash)(...n.getFunctionFiles()),valuesHash:n.
55
+ getFunctionHash()},{...o,connections:t.connections,dependencies:t.dependencies,sourceHash:t.
56
+ result?.sourceHash,valuesHash:t.result?.valuesHash});if(i.counts)return{...i,name:n.
57
+ functionName}},"previewResource"),st=r(async(e,t,n)=>{if(t.result)throw new d.ReplaceResourceError(
58
+ p,e.entryId,t.entryId);return me(e,n)},"replaceResource"),me=r(async(e,t)=>{let{
59
+ functionName:n,...o}=e.parameters,i=(0,W.getLogGroupName)(p,n,t),a=(0,$.getRoleArn)(
60
+ p,n,t),[u,g,l]=await Promise.all([(0,d.getBundleHash)(...o.getFunctionFiles()),o.
61
+ getFunctionBundle(t),o.getFunctionHash()]),S=await ne(n),A=await(0,R.hashFile)(g);
62
+ if(S)return await V(n,{...o,logGroup:i,roleArn:a}),await G(n,{publish:!1,sourceFile:g}),
63
+ await B(S.functionArn,{...o.tags}),O(e),{functionArn:S.functionArn,functionVersion:S.
64
+ functionVersion,valuesHash:l,sourceHash:u,bundleHash:A,logGroup:i,roleArn:a};let v=await re(
65
+ {...o,publish:!0,functionName:n,sourceFile:g,logGroup:i,roleArn:a});return O(e),
66
+ {functionArn:v.functionArn,functionVersion:v.functionVersion,valuesHash:l,sourceHash:u,
67
+ bundleHash:A,logGroup:i,roleArn:a}},"createResource"),at=r(async(e,t,n)=>{let{parameters:o,
68
+ result:i}=e;if(!i)return;let a=o.functionName,u=(0,$.getRoleArn)(p,a,n),g=t.result?.
69
+ roleArn??u,l=(0,W.getLogGroupName)(p,a,n),S=t.result?.logGroup??l,A={...o,roleArn:u,
70
+ logGroup:l},v={...t.parameters,roleArn:g,logGroup:S};await ct(a,A,v),await mt(i.
71
+ functionArn,o,t.parameters);let je=await ut(a,o,t.result,n);return O(e),{...i,...je,
72
+ logGroup:l,roleArn:u}},"updateResource"),pt=r(async e=>{let{result:t,parameters:n}=e;
73
+ t&&await oe(n.functionName)},"deleteResource"),O=r(e=>{let{parameters:t}=e;return t.
74
+ variables&&(t.variables=N(t.variables)),e},"lockSensitiveData"),ct=r(async(e,t,n)=>{
75
+ let o={...t,...t.variables&&{variables:N(t.variables)}};!(0,R.deepEqual)(o,n,{exclude:{
76
+ sourceFile:!0,functionName:!0,tags:!0}})&&await V(e,t)},"checkConfigurationUpdat\
77
+ es"),mt=r(async(e,t,n)=>{await(0,d.applyTagUpdates)(t.tags,n.tags,o=>B(e,o),o=>se(
78
+ e,o))},"checkTagUpdates"),ut=r(async(e,t,n,o)=>{let[i,a]=await Promise.all([(0,d.getBundleHash)(
79
+ ...t.getFunctionFiles()),t.getFunctionHash()]),u=n?.sourceHash,g=n?.valuesHash;if(i!==
80
+ u||a!==g||o.force){let l=await t.getFunctionBundle(o),S=await(0,R.hashFile)(l),A=n?.
81
+ bundleHash;if(S===A)return d.Logger.logSkip(p,`${e} source code`),{valuesHash:a,
82
+ sourceHash:i};let{functionVersion:v}=await G(e,{publish:!n?.functionVersion,sourceFile:l});
83
+ return{valuesHash:a,sourceHash:i,bundleHash:S,...v&&{functionVersion:v}}}},"chec\
84
+ kSourceCodeUpdates");var le=r(()=>{(0,ue.registerProvider)(f,ce())},"registerFunctionProvider");var xe=require("@ez4/aws-common");var Se=require("@ez4/aws-common");var q=require("@ez4/aws-common");var T=class extends Error{static{r(this,"FunctionNotFoundError")}constructor(t){
85
+ super(`Function ${t} wasn't found.`)}};var k=r(e=>e.type===f,"isFunctionState"),lt=r((e,t,n)=>{try{let o=e.getServiceState(
86
+ t,n);if(k(o))return o}catch{}},"tryGetFunctionState"),gt=r((e,t,n)=>{let o=e.getServiceState(
87
+ t,n);if(!k(o))throw new T(t);return o},"getFunctionState"),b=r((e,t,n)=>{let o=n.
88
+ getDependencies(f).at(0)?.parameters;if(!o?.functionName)throw new q.IncompleteResourceError(
89
+ e,t,"functionName");return o.functionName},"getFunctionName"),ge=r(e=>e.getDependencies(
90
+ f)[0]?.result?.functionArn,"tryGetFunctionArn"),ft=r((e,t,n)=>{let o=ge(n);if(!o)
91
+ throw new q.IncompleteResourceError(e,t,"functionArn");return o},"getFunctionArn");var x=require("@aws-sdk/client-lambda"),Z=require("@ez4/aws-common");var C="AWS:Lambda/Permission",w="aws:lambda.permission";var fe=new x.LambdaClient({}),de=r(async e=>{Z.Logger.logCreate(C,e.functionName);
92
+ let t=e.statementId??`ID${Date.now()}`;return await fe.send(new x.AddPermissionCommand(
88
93
  {StatementId:t,FunctionName:e.functionName,SourceArn:e.sourceArn,Principal:e.principal,
89
- Action:e.action})),{statementId:t}},"createPermission"),fe=n(async(e,t)=>{$.Logger.
90
- logDelete(P,e);try{return await le.send(new w.RemovePermissionCommand({FunctionName:e,
91
- StatementId:t})),!0}catch(r){if(!(r instanceof w.ResourceNotFoundException))throw r;
92
- return!1}},"deletePermission");var de=n(()=>({equals:yt,create:Se,replace:St,preview:dt,update:Ft,delete:wt}),"\
93
- getPermissionHandler"),yt=n((e,t)=>!!e.result&&e.result.functionName===t.result?.
94
- functionName,"equalsResource"),dt=n(async(e,t)=>{},"previewResource"),St=n(async(e,t,r)=>{
95
- if(t.result)throw new ye.ReplaceResourceError(P,e.entryId,t.entryId);return Se(e,
96
- r)},"replaceResource"),Se=n(async(e,t)=>{let r=e.parameters,o=C(P,"permission",t),
97
- i=await r.getPermission(t);return{statementId:(await ge({functionName:o,principal:i.
98
- principal,sourceArn:i.sourceArn,action:"lambda:InvokeFunction"})).statementId,functionName:o}},
99
- "createResource"),Ft=n(async()=>{},"updateResource"),wt=n(async e=>{let t=e.result;
100
- t&&await fe(t.functionName,t.statementId)},"deleteResource");var we=n(()=>{(0,Fe.registerProvider)(S,de())},"registerPermissionProvider");var Ie=require("@ez4/aws-common");var be=require("@ez4/aws-common"),T=require("@ez4/utils");var m=require("@aws-sdk/client-lambda"),R=require("@ez4/aws-common"),k=require("@ez4/utils");var y="AWS:Lambda/Mapping",x="aws:lambda.mapping",Z=(r=>(r.DynamoDB="dynamodb",r.
101
- Queue="sqs",r))(Z||{});var b=new m.LambdaClient({}),xe=n(async(e,t)=>{R.Logger.logImport(y,e);let r=await b.
102
- send(new m.ListEventSourceMappingsCommand({FunctionName:e,EventSourceArn:t})),[o]=r.
103
- EventSourceMappings;return o?{eventId:o.UUID}:void 0},"importMapping"),Pe=n(async e=>{
104
- let{sourceArn:t,functionName:r}=e;R.Logger.logCreate(y,r);let i=(await b.send(new m.CreateEventSourceMappingCommand(
105
- {FunctionName:r,EventSourceArn:t,...Ae(e)}))).UUID;return await ve(i),{eventId:i}},
106
- "createMapping"),Re=n(async(e,t)=>{let{functionName:r}=t;R.Logger.logUpdate(y,`${r}\
107
- (${e})`),await b.send(new m.UpdateEventSourceMappingCommand({UUID:e,FunctionName:r,
108
- ...Ae(t)})),await ve(e)},"updateMapping"),Ce=n(async e=>{R.Logger.logDelete(y,e);
109
- try{return await b.send(new m.DeleteEventSourceMappingCommand({UUID:e})),!0}catch(t){
94
+ Action:e.action})),{statementId:t}},"createPermission"),ye=r(async(e,t)=>{Z.Logger.
95
+ logDelete(C,e);try{return await fe.send(new x.RemovePermissionCommand({FunctionName:e,
96
+ StatementId:t})),!0}catch(n){if(!(n instanceof x.ResourceNotFoundException))throw n;
97
+ return!1}},"deletePermission");var Fe=r(()=>({equals:dt,create:we,replace:St,preview:yt,update:Ft,delete:wt}),"\
98
+ getPermissionHandler"),dt=r((e,t)=>!!e.result&&e.result.functionName===t.result?.
99
+ functionName,"equalsResource"),yt=r((e,t)=>{},"previewResource"),St=r(async(e,t,n)=>{
100
+ if(t.result)throw new Se.ReplaceResourceError(C,e.entryId,t.entryId);return we(e,
101
+ n)},"replaceResource"),we=r(async(e,t)=>{let n=e.parameters,o=b(C,"permission",t),
102
+ i=await n.getPermission(t);return{statementId:(await de({action:"lambda:InvokeFu\
103
+ nction",sourceArn:i.sourceArn,principal:i.principal,functionName:o})).statementId,
104
+ functionName:o}},"createResource"),Ft=r(async()=>{},"updateResource"),wt=r(async e=>{
105
+ let t=e.result;t&&await ye(t.functionName,t.statementId)},"deleteResource");var Pe=r(()=>{(0,xe.registerProvider)(w,Fe())},"registerPermissionProvider");var Ne=require("@ez4/aws-common");var Ee=require("@ez4/aws-common"),U=require("@ez4/utils");var m=require("@aws-sdk/client-lambda"),h=require("@ez4/aws-common"),Q=require("@ez4/utils");var y="AWS:Lambda/Mapping",P="aws:lambda.mapping",j=(n=>(n.DynamoDB="dynamodb",n.
106
+ Queue="sqs",n))(j||{});var M=new m.LambdaClient({}),ve=r(async(e,t)=>{h.Logger.logImport(y,e);let n=await M.
107
+ send(new m.ListEventSourceMappingsCommand({FunctionName:e,EventSourceArn:t})),[o]=n.
108
+ EventSourceMappings;return o?{eventId:o.UUID}:void 0},"importMapping"),Re=r(async e=>{
109
+ let{sourceArn:t,functionName:n}=e;h.Logger.logCreate(y,n);let i=(await M.send(new m.CreateEventSourceMappingCommand(
110
+ {FunctionName:n,EventSourceArn:t,...be(e)}))).UUID;return await Ae(i),{eventId:i}},
111
+ "createMapping"),Ce=r(async(e,t)=>{let{functionName:n}=t;h.Logger.logUpdate(y,`${n}\
112
+ (${e})`),await M.send(new m.UpdateEventSourceMappingCommand({UUID:e,FunctionName:n,
113
+ ...be(t)})),await Ae(e)},"updateMapping"),he=r(async e=>{h.Logger.logDelete(y,e);
114
+ try{return await M.send(new m.DeleteEventSourceMappingCommand({UUID:e})),!0}catch(t){
110
115
  if(!(t instanceof m.ResourceNotFoundException))throw t;return!1}},"deleteMapping"),
111
- xt=n(async e=>(await b.send(new m.GetEventSourceMappingCommand({UUID:e}))).State,
112
- "getMappingState"),ve=n(async e=>{let t=new Set(["Enabled","Disabled"]);await k.Wait.
113
- until(async()=>{let r=await xt(e);return t.has(r)?!0:k.Wait.RetryAttempt})},"wai\
114
- tForReadyState"),Ae=n(e=>{let{sourceArn:t,enabled:r,concurrency:o,batch:i}=e,{service:a}=(0,R.parseArn)(
115
- t);return{Enabled:r,FunctionResponseTypes:[m.FunctionResponseType.ReportBatchItemFailures],
116
+ xt=r(async e=>(await M.send(new m.GetEventSourceMappingCommand({UUID:e}))).State,
117
+ "getMappingState"),Ae=r(async e=>{let t=new Set(["Enabled","Disabled"]);await Q.Wait.
118
+ until(async()=>{let n=await xt(e);return t.has(n)?!0:Q.Wait.RetryAttempt})},"wai\
119
+ tForReadyState"),be=r(e=>{let{sourceArn:t,enabled:n,concurrency:o,batch:i}=e,{service:a}=(0,h.parseArn)(
120
+ t);return{Enabled:n,FunctionResponseTypes:[m.FunctionResponseType.ReportBatchItemFailures],
116
121
  MaximumBatchingWindowInSeconds:i?.maxWait,BatchSize:i?.size,...a==="dynamodb"&&{
117
122
  StartingPosition:m.EventSourcePosition.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},
118
- "upsertMappingRequest");var Ee=n(()=>({equals:Pt,create:he,replace:Ct,preview:Rt,update:vt,delete:At}),"\
119
- getMappingHandler"),Pt=n((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
120
- "equalsResource"),Rt=n(async(e,t)=>{let r={...e.parameters,dependencies:e.dependencies},
121
- o={...t.parameters,dependencies:t.dependencies},i=(0,T.deepCompare)(r,o,{exclude:{
122
- getSourceArn:!0}});if(i.counts)return{...i,name:r.fromService}},"previewResource"),
123
- Ct=n(async(e,t,r)=>{if(t.result)throw new be.ReplaceResourceError(y,e.entryId,t.
124
- entryId);return he(e,r)},"replaceResource"),he=n(async(e,t)=>{let r=e.parameters,
125
- o=C(y,"mapping",t),i=await r.getSourceArn(t);return{eventId:(await xe(o,i)??await Pe(
123
+ "upsertMappingRequest");var Ie=r(()=>({equals:Pt,create:Me,replace:Rt,preview:vt,update:Ct,delete:ht}),"\
124
+ getMappingHandler"),Pt=r((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
125
+ "equalsResource"),vt=r((e,t)=>{let n={...e.parameters,dependencies:e.dependencies},
126
+ o={...t.parameters,dependencies:t.dependencies},i=(0,U.deepCompare)(n,o,{exclude:{
127
+ getSourceArn:!0}});if(i.counts)return{...i,name:n.fromService}},"previewResource"),
128
+ Rt=r(async(e,t,n)=>{if(t.result)throw new Ee.ReplaceResourceError(y,e.entryId,t.
129
+ entryId);return Me(e,n)},"replaceResource"),Me=r(async(e,t)=>{let n=e.parameters,
130
+ o=b(y,"mapping",t),i=await n.getSourceArn(t);return{eventId:(await ve(o,i)??await Re(
126
131
  {...e.parameters,functionName:o,sourceArn:i})).eventId,functionName:o,sourceArn:i}},
127
- "createResource"),vt=n(async(e,t,r)=>{let o=e.result;if(!o)return;let i=o.sourceArn,
128
- a=C(y,"mapping",r),u=t.result?.functionName??o.functionName,l={...e.parameters,functionName:a,
129
- sourceArn:i},g={...t.parameters,functionName:u,sourceArn:i};return await bt(o.eventId,
130
- l,g),{...o,functionName:a}},"updateResource"),At=n(async e=>{let t=e.result;t&&await Ce(
131
- t.eventId)},"deleteResource"),bt=n(async(e,t,r)=>{!(0,T.deepEqual)(t,r,{exclude:{
132
- getSourceArn:!0,fromService:!0}})&&await Re(e,t)},"checkGeneralUpdates");var Me=n(()=>{(0,Ie.registerProvider)(x,Ee())},"registerMappingProvider");var Ne=n(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");var U=require("@ez4/aws-identity"),Ue=require("@ez4/project/library");var v=require("@ez4/aws-identity");var Te=n(async e=>{let[t,r]=await Promise.all([(0,v.getRegion)(),(0,v.getAccountId)()]);
133
- return(0,v.createPolicyDocument)([{permissions:["logs:CreateLogStream","logs:Put\
134
- LogEvents"],resourceIds:[`arn:aws:logs:${t}:${r}:log-group:${e}-*:*`]}])},"getPo\
135
- licyDocument");var De=n(async e=>{let{state:t,options:r}=e,o=(0,Ue.getServiceName)("",r),i=`${o}\
136
- -lambda-policy`;return(0,U.tryGetPolicy)(t,i)??(0,U.createPolicy)(t,{tags:r.tags,
137
- policyDocument:await Te(o),policyName:i})},"prepareExecutionPolicy");var Le=!1,Et=n(()=>{Le||((0,ze.registerTriggers)(),(0,Ge.registerTriggers)(),(0,Ve.registerTriggers)(),
138
- (0,He.createTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":Ne,"de\
139
- ploy:prepareExecutionPolicy":De}),me(),we(),Me(),Le=!0)},"registerTriggers");var D=require("@ez4/utils"),Oe=require("@ez4/stateful");var ht=n((e,t,r,o)=>{let i=(0,D.toKebabCase)(o.functionName),a=(0,D.hashData)(f,
140
- t.entryId,i),u=[t.entryId];return r&&u.push(r.entryId),(0,Oe.attachEntry)(e,{type:f,
141
- entryId:a,dependencies:u,parameters:{...o,functionName:i}})},"createFunction");var We=require("@ez4/stateful"),j=require("@ez4/utils");var Be=n(e=>e.type===S,"isPermissionState");var It=n((e,t,r,o)=>{let i=(0,j.hashData)(S,t.entryId,r.entryId);return(0,We.attachEntry)(
142
- e,{type:S,entryId:i,dependencies:[t.entryId,r.entryId],parameters:o})},"createPe\
143
- rmission"),Mt=n((e,t,r)=>{let o=(0,j.hashData)(S,t.entryId,r.entryId),i=e[o];return i&&
144
- Be(i)?i:null},"getPermission");var qe=require("@ez4/utils"),$e=require("@ez4/stateful");var Nt=n((e,t,r,o)=>{let i=(0,qe.hashData)(x,t.entryId,r.entryId);return(0,$e.attachEntry)(
145
- e,{type:x,entryId:i,dependencies:[t.entryId,r.entryId],parameters:o})},"createMa\
146
- pping");var Tt=n(e=>e.type===x,"isMappingState");0&&(module.exports={FunctionServiceName,FunctionServiceType,MappingService,MappingServiceName,
147
- MappingServiceType,PermissionServiceName,PermissionServiceType,createFunction,createMapping,
148
- createPermission,getFunctionArn,getFunctionName,getFunctionState,getPermission,isFunctionState,
149
- isMappingState,registerTriggers,tryGetFunctionArn,tryGetFunctionState});
132
+ "createResource"),Ct=r(async(e,t,n)=>{let o=e.result;if(!o)return;let i=o.sourceArn,
133
+ a=b(y,"mapping",n),u=t.result?.functionName??o.functionName,g={...e.parameters,functionName:a,
134
+ sourceArn:i},l={...t.parameters,functionName:u,sourceArn:i};return await At(o.eventId,
135
+ g,l),{...o,functionName:a}},"updateResource"),ht=r(async e=>{let t=e.result;t&&await he(
136
+ t.eventId)},"deleteResource"),At=r(async(e,t,n)=>{!(0,U.deepEqual)(t,n,{exclude:{
137
+ getSourceArn:!0,fromService:!0}})&&await Ce(e,t)},"checkGeneralUpdates");var He=r(()=>{(0,Ne.registerProvider)(P,Ie())},"registerMappingProvider");var Te=r(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");var L=require("@ez4/aws-identity"),Le=require("@ez4/project/library");var E=require("@ez4/aws-identity");var Ue=r(async e=>{let[t,n]=await Promise.all([(0,E.getRegion)(),(0,E.getAccountId)()]);
138
+ return(0,E.createPolicyDocument)([{permissions:["logs:CreateLogStream","logs:Put\
139
+ LogEvents"],resourceIds:[`arn:aws:logs:${t}:${n}:log-group:${e}-*:*`]}])},"getPo\
140
+ licyDocument");var De=r(async e=>{let{state:t,options:n}=e,o=(0,Le.getServiceName)("",n),i=`${o}\
141
+ -lambda-policy`;return(0,L.tryGetPolicy)(t,i)??(0,L.createPolicy)(t,{tags:n.tags,
142
+ policyDocument:await Ue(o),policyName:i})},"prepareExecutionPolicy");var ze=!1,bt=r(()=>{ze||((0,Ge.registerTriggers)(),(0,Ve.registerTriggers)(),(0,Be.registerTriggers)(),
143
+ (0,Oe.createTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":Te,"de\
144
+ ploy:prepareExecutionPolicy":De}),le(),Pe(),He(),ze=!0)},"registerTriggers");var D=require("@ez4/utils"),We=require("@ez4/stateful");var Et=r((e,t,n,o)=>{let i=(0,D.toKebabCase)(o.functionName),a=(0,D.hashData)(f,
145
+ t.entryId,i),u=[t.entryId];return n&&u.push(n.entryId),(0,We.attachEntry)(e,{type:f,
146
+ entryId:a,dependencies:u,parameters:{...o,functionName:i}})},"createFunction");var qe=require("@ez4/stateful"),J=require("@ez4/utils");var $e=r(e=>e.type===w,"isPermissionState");var It=r((e,t,n,o)=>{let i=(0,J.hashData)(w,t.entryId,n.entryId);return(0,qe.attachEntry)(
147
+ e,{type:w,entryId:i,dependencies:[t.entryId,n.entryId],parameters:o})},"createPe\
148
+ rmission"),Mt=r((e,t,n)=>{let o=(0,J.hashData)(w,t.entryId,n.entryId),i=e[o];return i&&
149
+ $e(i)?i:null},"getPermission");var ke=require("@ez4/utils"),Ze=require("@ez4/stateful");var Nt=r((e,t,n,o)=>{let i=(0,ke.hashData)(P,t.entryId,n.entryId);return(0,Ze.attachEntry)(
150
+ e,{type:P,entryId:i,dependencies:[t.entryId,n.entryId],parameters:o})},"createMa\
151
+ pping");var Ht=r(e=>e.type===P,"isMappingState");var Tt=r((e,t,n)=>`arn:aws:lambda:${e}:${t}:function:${n}`,"buildFunctionArn");0&&(module.exports={FunctionServiceName,FunctionServiceType,MappingService,MappingServiceName,
152
+ MappingServiceType,PermissionServiceName,PermissionServiceType,buildFunctionArn,
153
+ createFunction,createMapping,createPermission,getFunctionArn,getFunctionName,getFunctionState,
154
+ getPermission,isFunctionState,isMappingState,registerTriggers,tryGetFunctionArn,
155
+ tryGetFunctionState});
150
156
  //# sourceMappingURL=main.cjs.map
package/dist/main.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './permission/types';
8
8
  export * from './mapping/service';
9
9
  export * from './mapping/types';
10
10
  export * from './mapping/utils';
11
+ export * from './utils/arn';
package/dist/main.mjs CHANGED
@@ -1,137 +1,141 @@
1
- var Ae=Object.defineProperty;var n=(e,t)=>Ae(e,"name",{value:t,configurable:!0});import{registerTriggers as qt}from"@ez4/aws-common";import{registerTriggers as $t}from"@ez4/aws-identity";
2
- import{registerTriggers as Zt}from"@ez4/aws-logs";import{createTrigger as kt}from"@ez4/project/library";import{registerProvider as nt}from"@ez4/aws-common";import{applyTagUpdates as Ze,getBundleHash as N,ReplaceResourceError as ke}from"@ez4/aws-common";
3
- import{deepCompare as je,deepEqual as Qe}from"@ez4/utils";import{getLogGroupName as Z}from"@ez4/aws-logs";
4
- import{getRoleArn as k}from"@ez4/aws-identity";import{LambdaClient as Te,GetFunctionCommand as Ue,CreateFunctionCommand as De,DeleteFunctionCommand as Le,
1
+ var Ae=Object.defineProperty;var r=(e,t)=>Ae(e,"name",{value:t,configurable:!0});import{registerTriggers as kt}from"@ez4/aws-common";import{registerTriggers as Zt}from"@ez4/aws-identity";
2
+ import{registerTriggers as jt}from"@ez4/aws-logs";import{createTrigger as Qt}from"@ez4/project/library";import{registerProvider as it}from"@ez4/aws-common";import{applyTagUpdates as Ze,getBundleHash as T,Logger as je,ReplaceResourceError as Qe}from"@ez4/aws-common";
3
+ import{deepCompare as Je,deepEqual as Ke,hashFile as j}from"@ez4/utils";import{getLogGroupName as Q}from"@ez4/aws-logs";
4
+ import{getRoleArn as J}from"@ez4/aws-identity";import{LambdaClient as Te,GetFunctionCommand as Ue,CreateFunctionCommand as Le,DeleteFunctionCommand as De,
5
5
  UpdateFunctionCodeCommand as ze,UpdateFunctionConfigurationCommand as Ge,PublishVersionCommand as Ve,
6
- TagResourceCommand as He,UntagResourceCommand as Oe,waitUntilFunctionActive as Be,
7
- waitUntilFunctionUpdated as U,waitUntilPublishedVersionActive as We,ResourceNotFoundException as D,
8
- ApplicationLogLevel as R,SystemLogLevel as L,LogFormat as z}from"@aws-sdk/client-lambda";
9
- import{Logger as c,tryParseArn as G,waitCreation as qe,waitDeletion as $e}from"@ez4/aws-common";import{InvalidParameterError as be}from"@ez4/aws-common";import{hashData as Ee}from"@ez4/utils";var a="AWS:Lambda/Function",l="aws:lambda.function";var he=/[a-z][\w]+/i,Ie=n(e=>he.test(e),"isValidName"),b=n(e=>{for(let t in e)if(!Ie(
10
- t))throw new be(a,`${t} is an invalid variable name .`)},"assertVariables"),P=n(
11
- e=>{let t={};for(let r in e)t[r]=Ee(e[r]);return t},"protectVariables");import Me from"adm-zip";import{readFile as Ne}from"node:fs/promises";var T=n(async(e,t)=>{let r=new Me,o=await Ne(e);return r.addFile(t,o),r.toBufferPromise()},
12
- "getZipBuffer");var g=new Te({}),C={minDelay:15,maxWaitTime:1800,maxDelay:60,client:g},V=n(async(e,t)=>{
13
- c.logImport(a,e);try{let r=await g.send(new Ue({FunctionName:e,Qualifier:t})),o=r.
14
- Configuration.Version,i=r.Configuration.FunctionArn;return{functionVersion:o,functionArn:i}}catch(r){
15
- if(!(r instanceof D))throw r;return}},"importFunction"),H=n(async e=>{let{functionName:t,
16
- variables:r}=e;c.logCreate(a,t),r&&b(r);let o=$(e.handlerName),i=await q(e.sourceFile),
17
- s=await qe(()=>g.send(new De({FunctionName:e.functionName,Description:e.description,
6
+ TagResourceCommand as Be,UntagResourceCommand as Oe,waitUntilFunctionActive as We,
7
+ waitUntilFunctionUpdated as L,waitUntilPublishedVersionActive as $e,ResourceNotFoundException as D,
8
+ ApplicationLogLevel as C,SystemLogLevel as z,LogFormat as G}from"@aws-sdk/client-lambda";
9
+ import{Logger as c,tryParseArn as V,waitCreation as qe,waitDeletion as ke}from"@ez4/aws-common";import{InvalidParameterError as be}from"@ez4/aws-common";import{hashData as Ee}from"@ez4/utils";var a="AWS:Lambda/Function",g="aws:lambda.function";var Ie=/[a-z][\w]+/i,Me=r(e=>Ie.test(e),"isValidName"),E=r(e=>{for(let t in e)if(!Me(
10
+ t))throw new be(a,`${t} is an invalid variable name .`)},"assertVariables"),R=r(
11
+ e=>{let t={};for(let n in e)t[n]=Ee(e[n]);return t},"protectVariables");import Ne from"adm-zip";import{readFile as He}from"node:fs/promises";var U=r(async(e,t)=>{let n=new Ne,o=await He(e);return n.addFile(t,o),n.toBufferPromise()},
12
+ "getZipBuffer");var f=new Te({}),h={minDelay:15,maxWaitTime:1800,maxDelay:60,client:f},B=r(async(e,t)=>{
13
+ c.logImport(a,e);try{let n=await f.send(new Ue({FunctionName:e,Qualifier:t})),o=n.
14
+ Configuration.Version,i=n.Configuration.FunctionArn;return{functionVersion:o,functionArn:i}}catch(n){
15
+ if(!(n instanceof D))throw n;return}},"importFunction"),O=r(async e=>{let{functionName:t,
16
+ variables:n}=e;c.logCreate(a,t),n&&E(n);let o=Z(e.handlerName),i=await k(e.sourceFile),
17
+ s=await qe(()=>f.send(new Le({FunctionName:e.functionName,Description:e.description,
18
18
  MemorySize:e.memory,Timeout:e.timeout,Role:e.roleArn,Handler:o,Runtime:"nodejs22\
19
19
  .x",PackageType:"Zip",LoggingConfig:{LogGroup:e.logGroup,ApplicationLogLevel:e.debug?
20
- R.Debug:R.Warn,SystemLogLevel:L.Warn,LogFormat:z.Json},Code:{ZipFile:i},Environment:{
21
- Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.logWait(a,t),await Be(C,{FunctionName:t});
22
- let p=s.FunctionArn;return e.publish?{functionVersion:await B(t),functionArn:p}:
23
- {functionArn:p}},"createFunction"),E=n(async(e,t)=>{c.logUpdate(a,`${e} source c\
24
- ode`);let r=await q(t.sourceFile),o=await g.send(new ze({FunctionName:e,Publish:t.
25
- publish,ZipFile:r}));c.logWait(a,e),await U(C,{FunctionName:e});let i=o.FunctionArn;
26
- return t.publish?{functionVersion:await B(e),functionArn:i}:{functionArn:i}},"up\
27
- dateSourceCode"),h=n(async(e,t)=>{let{handlerName:r,variables:o}=t;c.logUpdate(a,
28
- `${e} configuration`),o&&b(o),await g.send(new Ge({FunctionName:e,Description:t.
20
+ C.Debug:C.Warn,SystemLogLevel:z.Warn,LogFormat:G.Json},Code:{ZipFile:i},Environment:{
21
+ Variables:n},Tags:{...e.tags,ManagedBy:"EZ4"}})));c.logWait(a,t),await We(h,{FunctionName:t});
22
+ let p=s.FunctionArn;return e.publish?{functionVersion:await $(t),functionArn:p}:
23
+ {functionArn:p}},"createFunction"),I=r(async(e,t)=>{c.logUpdate(a,`${e} source c\
24
+ ode`);let n=await k(t.sourceFile),o=await f.send(new ze({FunctionName:e,Publish:t.
25
+ publish,ZipFile:n}));c.logWait(a,e),await L(h,{FunctionName:e});let i=o.FunctionArn;
26
+ return t.publish?{functionVersion:await $(e),functionArn:i}:{functionArn:i}},"up\
27
+ dateSourceCode"),M=r(async(e,t)=>{let{handlerName:n,variables:o}=t;c.logUpdate(a,
28
+ `${e} configuration`),o&&E(o),await f.send(new Ge({FunctionName:e,Description:t.
29
29
  description,MemorySize:t.memory,Timeout:t.timeout,Role:t.roleArn,Runtime:"nodejs\
30
- 22.x",...r&&{Handler:$(r)},LoggingConfig:{LogGroup:t.logGroup,ApplicationLogLevel:t.
31
- debug?R.Debug:R.Warn,SystemLogLevel:L.Warn,LogFormat:z.Json},Environment:{Variables:o}})),
32
- c.logWait(a,e),await U(C,{FunctionName:e})},"updateConfiguration"),O=n(async e=>{
33
- c.logDelete(a,e),await $e(async()=>{try{await g.send(new Le({FunctionName:e}))}catch(t){
34
- if(!(t instanceof D))throw t}})},"deleteFunction"),B=n(async e=>{c.logPublish(a,
35
- e);let t=await g.send(new Ve({FunctionName:e}));c.logWait(a,e);let r=t.Version;return await We(
36
- C,{FunctionName:e,Qualifier:r}),r},"publishFunction"),I=n(async(e,t)=>{let r=G(e)?.
37
- resourceName??e;c.logTag(a,r),await g.send(new He({Resource:e,Tags:{...t,ManagedBy:"\
38
- EZ4"}}))},"tagFunction"),W=n(async(e,t)=>{let r=G(e)?.resourceName??e;c.logUntag(
39
- a,r),await g.send(new Oe({Resource:e,TagKeys:t}))},"untagFunction"),q=n(e=>T(e,"\
40
- main.mjs"),"getSourceZipFile"),$=n(e=>`main.${e}`,"getSourceHandlerName");var j=n(()=>({equals:Je,create:Q,replace:_e,preview:Ke,update:Xe,delete:Ye}),"ge\
41
- tFunctionHandler"),Je=n((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
42
- "equalsResource"),Ke=n(async(e,t)=>{let r=e.parameters,o=t.parameters,i=je({...r,
43
- dependencies:e.dependencies,sourceHash:await N(...r.getFunctionFiles()),...r.variables&&
44
- {variables:P(r.variables)}},{...o,dependencies:t.dependencies,sourceHash:t.result?.
45
- sourceHash});if(i.counts)return{...i,name:r.functionName}},"previewResource"),_e=n(
46
- async(e,t,r)=>{if(t.result)throw new ke(a,e.entryId,t.entryId);return Q(e,r)},"r\
47
- eplaceResource"),Q=n(async(e,t)=>{let r=e.parameters,o=r.functionName,i=k(a,o,t),
48
- s=Z(a,o,t),[p,m]=await Promise.all([N(...r.getFunctionFiles()),r.getFunctionBundle(
49
- t)]),u=await V(o);if(u)return await h(o,{...r,logGroup:s,roleArn:i}),await E(o,{
50
- publish:!1,sourceFile:m}),await I(u.functionArn,{...r.tags}),M(e),{functionArn:u.
51
- functionArn,functionVersion:u.functionVersion,sourceHash:p,logGroup:s,roleArn:i};
52
- let x=await H({...r,publish:!0,sourceFile:m,logGroup:s,roleArn:i});return M(e),{
53
- functionArn:x.functionArn,functionVersion:x.functionVersion,sourceHash:p,logGroup:s,
54
- roleArn:i}},"createResource"),Xe=n(async(e,t,r)=>{let{parameters:o,result:i}=e;if(!i)
55
- return;let s=o.functionName,p=k(a,s,r),m=t.result?.roleArn??p,u=Z(a,s,r),x=t.result?.
56
- logGroup??u,Re={...o,roleArn:p,logGroup:u},Ce={...t.parameters,roleArn:m,logGroup:x};
57
- await et(s,Re,Ce),await tt(i.functionArn,o,t.parameters);let ve=await rt(s,o,t.result,
58
- r);return M(e),{...i,...ve,logGroup:u,roleArn:p}},"updateResource"),Ye=n(async e=>{
59
- let{result:t,parameters:r}=e;t&&await O(r.functionName)},"deleteResource"),M=n(e=>{
60
- let{parameters:t}=e;return t.variables&&(t.variables=P(t.variables)),e},"lockSen\
61
- sitiveData"),et=n(async(e,t,r)=>{let o={...t,...t.variables&&{variables:P(t.variables)}};
62
- !Qe(o,r,{exclude:{sourceFile:!0,functionName:!0,tags:!0}})&&await h(e,t)},"check\
63
- ConfigurationUpdates"),tt=n(async(e,t,r)=>{await Ze(t.tags,r.tags,o=>I(e,o),o=>W(
64
- e,o))},"checkTagUpdates"),rt=n(async(e,t,r,o)=>{let i=await N(...t.getFunctionFiles()),
65
- s=r?.sourceHash;if(i===s&&!o.force)return r;let p=await t.getFunctionBundle(o),{
66
- functionVersion:m}=await E(e,{publish:!r?.functionVersion,sourceFile:p});return{
67
- sourceHash:i,...m&&{functionVersion:m}}},"checkSourceCodeUpdates");var J=n(()=>{nt(l,j())},"registerFunctionProvider");import{registerProvider as yt}from"@ez4/aws-common";import{ReplaceResourceError as ct}from"@ez4/aws-common";import{IncompleteResourceError as K}from"@ez4/aws-common";var v=class extends Error{static{n(this,"FunctionNotFoundError")}constructor(t){
68
- super(`Function ${t} wasn't found.`)}};var _=n(e=>e.type===l,"isFunctionState"),zr=n((e,t,r)=>{try{let o=e.getServiceState(
69
- t,r);if(_(o))return o}catch{}},"tryGetFunctionState"),Gr=n((e,t,r)=>{let o=e.getServiceState(
70
- t,r);if(!_(o))throw new v(t);return o},"getFunctionState"),F=n((e,t,r)=>{let o=r.
71
- getDependencies(l).at(0)?.parameters;if(!o?.functionName)throw new K(e,t,"functi\
72
- onName");return o.functionName},"getFunctionName"),ot=n(e=>e.getDependencies(l)[0]?.
73
- result?.functionArn,"tryGetFunctionArn"),Vr=n((e,t,r)=>{let o=ot(r);if(!o)throw new K(
74
- e,t,"functionArn");return o},"getFunctionArn");import{LambdaClient as it,AddPermissionCommand as st,RemovePermissionCommand as at,
75
- ResourceNotFoundException as pt}from"@aws-sdk/client-lambda";import{Logger as X}from"@ez4/aws-common";var S="AWS:Lambda/Permission",y="aws:lambda.permission";var Y=new it({}),ee=n(async e=>{X.logCreate(S,e.functionName);let t=e.statementId??
76
- `SID${Date.now()}`;return await Y.send(new st({StatementId:t,FunctionName:e.functionName,
30
+ 22.x",...n&&{Handler:Z(n)},LoggingConfig:{LogGroup:t.logGroup,ApplicationLogLevel:t.
31
+ debug?C.Debug:C.Warn,SystemLogLevel:z.Warn,LogFormat:G.Json},Environment:{Variables:o}})),
32
+ c.logWait(a,e),await L(h,{FunctionName:e})},"updateConfiguration"),W=r(async e=>{
33
+ c.logDelete(a,e),await ke(async()=>{try{await f.send(new De({FunctionName:e}))}catch(t){
34
+ if(!(t instanceof D))throw t}})},"deleteFunction"),$=r(async e=>{c.logPublish(a,
35
+ e);let t=await f.send(new Ve({FunctionName:e}));c.logWait(a,e);let n=t.Version;return await $e(
36
+ h,{FunctionName:e,Qualifier:n}),n},"publishFunction"),N=r(async(e,t)=>{let n=V(e)?.
37
+ resourceName??e;c.logTag(a,n),await f.send(new Be({Resource:e,Tags:{...t,ManagedBy:"\
38
+ EZ4"}}))},"tagFunction"),q=r(async(e,t)=>{let n=V(e)?.resourceName??e;c.logUntag(
39
+ a,n),await f.send(new Oe({Resource:e,TagKeys:t}))},"untagFunction"),k=r(e=>U(e,"\
40
+ main.mjs"),"getSourceZipFile"),Z=r(e=>`main.${e}`,"getSourceHandlerName");var K=r(()=>({equals:_e,create:_,replace:Ye,preview:Xe,update:et,delete:tt}),"ge\
41
+ tFunctionHandler"),_e=r((e,t)=>!!e.result&&e.result.functionArn===t.result?.functionArn,
42
+ "equalsResource"),Xe=r(async(e,t)=>{let n=e.parameters,o=t.parameters,i=Je({...n,
43
+ connections:e.connections,dependencies:e.dependencies,variables:n.variables&&R(n.
44
+ variables),sourceHash:await T(...n.getFunctionFiles()),valuesHash:n.getFunctionHash()},
45
+ {...o,connections:t.connections,dependencies:t.dependencies,sourceHash:t.result?.
46
+ sourceHash,valuesHash:t.result?.valuesHash});if(i.counts)return{...i,name:n.functionName}},
47
+ "previewResource"),Ye=r(async(e,t,n)=>{if(t.result)throw new Qe(a,e.entryId,t.entryId);
48
+ return _(e,n)},"replaceResource"),_=r(async(e,t)=>{let{functionName:n,...o}=e.parameters,
49
+ i=Q(a,n,t),s=J(a,n,t),[p,u,m]=await Promise.all([T(...o.getFunctionFiles()),o.getFunctionBundle(
50
+ t),o.getFunctionHash()]),l=await B(n),w=await j(u);if(l)return await M(n,{...o,logGroup:i,
51
+ roleArn:s}),await I(n,{publish:!1,sourceFile:u}),await N(l.functionArn,{...o.tags}),
52
+ H(e),{functionArn:l.functionArn,functionVersion:l.functionVersion,valuesHash:m,sourceHash:p,
53
+ bundleHash:w,logGroup:i,roleArn:s};let S=await O({...o,publish:!0,functionName:n,
54
+ sourceFile:u,logGroup:i,roleArn:s});return H(e),{functionArn:S.functionArn,functionVersion:S.
55
+ functionVersion,valuesHash:m,sourceHash:p,bundleHash:w,logGroup:i,roleArn:s}},"c\
56
+ reateResource"),et=r(async(e,t,n)=>{let{parameters:o,result:i}=e;if(!i)return;let s=o.
57
+ functionName,p=J(a,s,n),u=t.result?.roleArn??p,m=Q(a,s,n),l=t.result?.logGroup??
58
+ m,w={...o,roleArn:p,logGroup:m},S={...t.parameters,roleArn:u,logGroup:l};await nt(
59
+ s,w,S),await rt(i.functionArn,o,t.parameters);let he=await ot(s,o,t.result,n);return H(
60
+ e),{...i,...he,logGroup:m,roleArn:p}},"updateResource"),tt=r(async e=>{let{result:t,
61
+ parameters:n}=e;t&&await W(n.functionName)},"deleteResource"),H=r(e=>{let{parameters:t}=e;
62
+ return t.variables&&(t.variables=R(t.variables)),e},"lockSensitiveData"),nt=r(async(e,t,n)=>{
63
+ let o={...t,...t.variables&&{variables:R(t.variables)}};!Ke(o,n,{exclude:{sourceFile:!0,
64
+ functionName:!0,tags:!0}})&&await M(e,t)},"checkConfigurationUpdates"),rt=r(async(e,t,n)=>{
65
+ await Ze(t.tags,n.tags,o=>N(e,o),o=>q(e,o))},"checkTagUpdates"),ot=r(async(e,t,n,o)=>{
66
+ let[i,s]=await Promise.all([T(...t.getFunctionFiles()),t.getFunctionHash()]),p=n?.
67
+ sourceHash,u=n?.valuesHash;if(i!==p||s!==u||o.force){let m=await t.getFunctionBundle(
68
+ o),l=await j(m),w=n?.bundleHash;if(l===w)return je.logSkip(a,`${e} source code`),
69
+ {valuesHash:s,sourceHash:i};let{functionVersion:S}=await I(e,{publish:!n?.functionVersion,
70
+ sourceFile:m});return{valuesHash:s,sourceHash:i,bundleHash:l,...S&&{functionVersion:S}}}},
71
+ "checkSourceCodeUpdates");var X=r(()=>{it(g,K())},"registerFunctionProvider");import{registerProvider as St}from"@ez4/aws-common";import{ReplaceResourceError as ut}from"@ez4/aws-common";import{IncompleteResourceError as Y}from"@ez4/aws-common";var A=class extends Error{static{r(this,"FunctionNotFoundError")}constructor(t){
72
+ super(`Function ${t} wasn't found.`)}};var ee=r(e=>e.type===g,"isFunctionState"),Vn=r((e,t,n)=>{try{let o=e.getServiceState(
73
+ t,n);if(ee(o))return o}catch{}},"tryGetFunctionState"),Bn=r((e,t,n)=>{let o=e.getServiceState(
74
+ t,n);if(!ee(o))throw new A(t);return o},"getFunctionState"),P=r((e,t,n)=>{let o=n.
75
+ getDependencies(g).at(0)?.parameters;if(!o?.functionName)throw new Y(e,t,"functi\
76
+ onName");return o.functionName},"getFunctionName"),st=r(e=>e.getDependencies(g)[0]?.
77
+ result?.functionArn,"tryGetFunctionArn"),On=r((e,t,n)=>{let o=st(n);if(!o)throw new Y(
78
+ e,t,"functionArn");return o},"getFunctionArn");import{LambdaClient as at,AddPermissionCommand as pt,RemovePermissionCommand as ct,
79
+ ResourceNotFoundException as mt}from"@aws-sdk/client-lambda";import{Logger as te}from"@ez4/aws-common";var x="AWS:Lambda/Permission",y="aws:lambda.permission";var ne=new at({}),re=r(async e=>{te.logCreate(x,e.functionName);let t=e.statementId??
80
+ `ID${Date.now()}`;return await ne.send(new pt({StatementId:t,FunctionName:e.functionName,
77
81
  SourceArn:e.sourceArn,Principal:e.principal,Action:e.action})),{statementId:t}},
78
- "createPermission"),te=n(async(e,t)=>{X.logDelete(S,e);try{return await Y.send(new at(
79
- {FunctionName:e,StatementId:t})),!0}catch(r){if(!(r instanceof pt))throw r;return!1}},
80
- "deletePermission");var re=n(()=>({equals:mt,create:ne,replace:lt,preview:ut,update:gt,delete:ft}),"\
81
- getPermissionHandler"),mt=n((e,t)=>!!e.result&&e.result.functionName===t.result?.
82
- functionName,"equalsResource"),ut=n(async(e,t)=>{},"previewResource"),lt=n(async(e,t,r)=>{
83
- if(t.result)throw new ct(S,e.entryId,t.entryId);return ne(e,r)},"replaceResource"),
84
- ne=n(async(e,t)=>{let r=e.parameters,o=F(S,"permission",t),i=await r.getPermission(
85
- t);return{statementId:(await ee({functionName:o,principal:i.principal,sourceArn:i.
86
- sourceArn,action:"lambda:InvokeFunction"})).statementId,functionName:o}},"create\
87
- Resource"),gt=n(async()=>{},"updateResource"),ft=n(async e=>{let t=e.result;t&&await te(
88
- t.functionName,t.statementId)},"deleteResource");var oe=n(()=>{yt(y,re())},"registerPermissionProvider");import{registerProvider as zt}from"@ez4/aws-common";import{ReplaceResourceError as Et}from"@ez4/aws-common";import{deepCompare as ht,
89
- deepEqual as It}from"@ez4/utils";import{LambdaClient as dt,GetEventSourceMappingCommand as St,CreateEventSourceMappingCommand as Ft,
90
- UpdateEventSourceMappingCommand as wt,DeleteEventSourceMappingCommand as xt,ListEventSourceMappingsCommand as Pt,
91
- FunctionResponseType as Rt,EventSourcePosition as Ct,ResourceNotFoundException as vt}from"@aws-sdk/client-lambda";
92
- import{Logger as A,parseArn as At}from"@ez4/aws-common";import{Wait as se}from"@ez4/utils";var f="AWS:Lambda/Mapping",d="aws:lambda.mapping",ie=(r=>(r.DynamoDB="dynamodb",
93
- r.Queue="sqs",r))(ie||{});var w=new dt({}),ae=n(async(e,t)=>{A.logImport(f,e);let r=await w.send(new Pt({FunctionName:e,
94
- EventSourceArn:t})),[o]=r.EventSourceMappings;return o?{eventId:o.UUID}:void 0},
95
- "importMapping"),pe=n(async e=>{let{sourceArn:t,functionName:r}=e;A.logCreate(f,
96
- r);let i=(await w.send(new Ft({FunctionName:r,EventSourceArn:t,...le(e)}))).UUID;
97
- return await ue(i),{eventId:i}},"createMapping"),ce=n(async(e,t)=>{let{functionName:r}=t;
98
- A.logUpdate(f,`${r} (${e})`),await w.send(new wt({UUID:e,FunctionName:r,...le(t)})),
99
- await ue(e)},"updateMapping"),me=n(async e=>{A.logDelete(f,e);try{return await w.
100
- send(new xt({UUID:e})),!0}catch(t){if(!(t instanceof vt))throw t;return!1}},"del\
101
- eteMapping"),bt=n(async e=>(await w.send(new St({UUID:e}))).State,"getMappingSta\
102
- te"),ue=n(async e=>{let t=new Set(["Enabled","Disabled"]);await se.until(async()=>{
103
- let r=await bt(e);return t.has(r)?!0:se.RetryAttempt})},"waitForReadyState"),le=n(
104
- e=>{let{sourceArn:t,enabled:r,concurrency:o,batch:i}=e,{service:s}=At(t);return{
105
- Enabled:r,FunctionResponseTypes:[Rt.ReportBatchItemFailures],MaximumBatchingWindowInSeconds:i?.
106
- maxWait,BatchSize:i?.size,...s==="dynamodb"&&{StartingPosition:Ct.LATEST},...s===
107
- "sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},"upsertMappingRequest");var ge=n(()=>({equals:Mt,create:fe,replace:Tt,preview:Nt,update:Ut,delete:Dt}),"\
108
- getMappingHandler"),Mt=n((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
109
- "equalsResource"),Nt=n(async(e,t)=>{let r={...e.parameters,dependencies:e.dependencies},
110
- o={...t.parameters,dependencies:t.dependencies},i=ht(r,o,{exclude:{getSourceArn:!0}});
111
- if(i.counts)return{...i,name:r.fromService}},"previewResource"),Tt=n(async(e,t,r)=>{
112
- if(t.result)throw new Et(f,e.entryId,t.entryId);return fe(e,r)},"replaceResource"),
113
- fe=n(async(e,t)=>{let r=e.parameters,o=F(f,"mapping",t),i=await r.getSourceArn(t);
114
- return{eventId:(await ae(o,i)??await pe({...e.parameters,functionName:o,sourceArn:i})).
115
- eventId,functionName:o,sourceArn:i}},"createResource"),Ut=n(async(e,t,r)=>{let o=e.
116
- result;if(!o)return;let i=o.sourceArn,s=F(f,"mapping",r),p=t.result?.functionName??
117
- o.functionName,m={...e.parameters,functionName:s,sourceArn:i},u={...t.parameters,
118
- functionName:p,sourceArn:i};return await Lt(o.eventId,m,u),{...o,functionName:s}},
119
- "updateResource"),Dt=n(async e=>{let t=e.result;t&&await me(t.eventId)},"deleteR\
120
- esource"),Lt=n(async(e,t,r)=>{!It(t,r,{exclude:{getSourceArn:!0,fromService:!0}})&&
121
- await ce(e,t)},"checkGeneralUpdates");var ye=n(()=>{zt(d,ge())},"registerMappingProvider");var de=n(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");import{createPolicy as Ot,tryGetPolicy as Bt}from"@ez4/aws-identity";import{getServiceName as Wt}from"@ez4/project/library";import{getAccountId as Gt,getRegion as Vt,createPolicyDocument as Ht}from"@ez4/aws-identity";var Se=n(async e=>{let[t,r]=await Promise.all([Vt(),Gt()]);return Ht([{permissions:[
122
- "logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:logs:${t}:${r}\
123
- :log-group:${e}-*:*`]}])},"getPolicyDocument");var Fe=n(async e=>{let{state:t,options:r}=e,o=Wt("",r),i=`${o}-lambda-policy`;return Bt(
124
- t,i)??Ot(t,{tags:r.tags,policyDocument:await Se(o),policyName:i})},"prepareExecu\
125
- tionPolicy");var we=!1,qn=n(()=>{we||(qt(),$t(),Zt(),kt("@ez4/aws-function",{"deploy:prepareI\
126
- dentityAccount":de,"deploy:prepareExecutionPolicy":Fe}),J(),oe(),ye(),we=!0)},"r\
127
- egisterTriggers");import{toKebabCase as jt,hashData as Qt}from"@ez4/utils";import{attachEntry as Jt}from"@ez4/stateful";var Jn=n((e,t,r,o)=>{let i=jt(o.functionName),s=Qt(l,t.entryId,i),p=[t.entryId];
128
- return r&&p.push(r.entryId),Jt(e,{type:l,entryId:s,dependencies:p,parameters:{...o,
129
- functionName:i}})},"createFunction");import{attachEntry as Kt}from"@ez4/stateful";import{hashData as Pe}from"@ez4/utils";var xe=n(e=>e.type===y,"isPermissionState");var io=n((e,t,r,o)=>{let i=Pe(y,t.entryId,r.entryId);return Kt(e,{type:y,entryId:i,
130
- dependencies:[t.entryId,r.entryId],parameters:o})},"createPermission"),so=n((e,t,r)=>{
131
- let o=Pe(y,t.entryId,r.entryId),i=e[o];return i&&xe(i)?i:null},"getPermission");import{hashData as _t}from"@ez4/utils";import{attachEntry as Xt}from"@ez4/stateful";var lo=n((e,t,r,o)=>{let i=_t(d,t.entryId,r.entryId);return Xt(e,{type:d,entryId:i,
132
- dependencies:[t.entryId,r.entryId],parameters:o})},"createMapping");var So=n(e=>e.type===d,"isMappingState");export{a as FunctionServiceName,l as FunctionServiceType,ie as MappingService,f as MappingServiceName,
133
- d as MappingServiceType,S as PermissionServiceName,y as PermissionServiceType,Jn as createFunction,
134
- lo as createMapping,io as createPermission,Vr as getFunctionArn,F as getFunctionName,
135
- Gr as getFunctionState,so as getPermission,_ as isFunctionState,So as isMappingState,
136
- qn as registerTriggers,ot as tryGetFunctionArn,zr as tryGetFunctionState};
82
+ "createPermission"),oe=r(async(e,t)=>{te.logDelete(x,e);try{return await ne.send(
83
+ new ct({FunctionName:e,StatementId:t})),!0}catch(n){if(!(n instanceof mt))throw n;
84
+ return!1}},"deletePermission");var ie=r(()=>({equals:lt,create:se,replace:ft,preview:gt,update:dt,delete:yt}),"\
85
+ getPermissionHandler"),lt=r((e,t)=>!!e.result&&e.result.functionName===t.result?.
86
+ functionName,"equalsResource"),gt=r((e,t)=>{},"previewResource"),ft=r(async(e,t,n)=>{
87
+ if(t.result)throw new ut(x,e.entryId,t.entryId);return se(e,n)},"replaceResource"),
88
+ se=r(async(e,t)=>{let n=e.parameters,o=P(x,"permission",t),i=await n.getPermission(
89
+ t);return{statementId:(await re({action:"lambda:InvokeFunction",sourceArn:i.sourceArn,
90
+ principal:i.principal,functionName:o})).statementId,functionName:o}},"createReso\
91
+ urce"),dt=r(async()=>{},"updateResource"),yt=r(async e=>{let t=e.result;t&&await oe(
92
+ t.functionName,t.statementId)},"deleteResource");var ae=r(()=>{St(y,ie())},"registerPermissionProvider");import{registerProvider as Gt}from"@ez4/aws-common";import{ReplaceResourceError as It}from"@ez4/aws-common";import{deepCompare as Mt,
93
+ deepEqual as Nt}from"@ez4/utils";import{LambdaClient as Ft,GetEventSourceMappingCommand as wt,CreateEventSourceMappingCommand as xt,
94
+ UpdateEventSourceMappingCommand as Pt,DeleteEventSourceMappingCommand as vt,ListEventSourceMappingsCommand as Rt,
95
+ FunctionResponseType as Ct,EventSourcePosition as ht,ResourceNotFoundException as At}from"@aws-sdk/client-lambda";
96
+ import{Logger as b,parseArn as bt}from"@ez4/aws-common";import{Wait as ce}from"@ez4/utils";var d="AWS:Lambda/Mapping",F="aws:lambda.mapping",pe=(n=>(n.DynamoDB="dynamodb",
97
+ n.Queue="sqs",n))(pe||{});var v=new Ft({}),me=r(async(e,t)=>{b.logImport(d,e);let n=await v.send(new Rt({FunctionName:e,
98
+ EventSourceArn:t})),[o]=n.EventSourceMappings;return o?{eventId:o.UUID}:void 0},
99
+ "importMapping"),ue=r(async e=>{let{sourceArn:t,functionName:n}=e;b.logCreate(d,
100
+ n);let i=(await v.send(new xt({FunctionName:n,EventSourceArn:t,...de(e)}))).UUID;
101
+ return await fe(i),{eventId:i}},"createMapping"),le=r(async(e,t)=>{let{functionName:n}=t;
102
+ b.logUpdate(d,`${n} (${e})`),await v.send(new Pt({UUID:e,FunctionName:n,...de(t)})),
103
+ await fe(e)},"updateMapping"),ge=r(async e=>{b.logDelete(d,e);try{return await v.
104
+ send(new vt({UUID:e})),!0}catch(t){if(!(t instanceof At))throw t;return!1}},"del\
105
+ eteMapping"),Et=r(async e=>(await v.send(new wt({UUID:e}))).State,"getMappingSta\
106
+ te"),fe=r(async e=>{let t=new Set(["Enabled","Disabled"]);await ce.until(async()=>{
107
+ let n=await Et(e);return t.has(n)?!0:ce.RetryAttempt})},"waitForReadyState"),de=r(
108
+ e=>{let{sourceArn:t,enabled:n,concurrency:o,batch:i}=e,{service:s}=bt(t);return{
109
+ Enabled:n,FunctionResponseTypes:[Ct.ReportBatchItemFailures],MaximumBatchingWindowInSeconds:i?.
110
+ maxWait,BatchSize:i?.size,...s==="dynamodb"&&{StartingPosition:ht.LATEST},...s===
111
+ "sqs"&&{ScalingConfig:{MaximumConcurrency:o}}}},"upsertMappingRequest");var ye=r(()=>({equals:Ht,create:Se,replace:Ut,preview:Tt,update:Lt,delete:Dt}),"\
112
+ getMappingHandler"),Ht=r((e,t)=>!!e.result&&e.result.eventId===t.result?.eventId,
113
+ "equalsResource"),Tt=r((e,t)=>{let n={...e.parameters,dependencies:e.dependencies},
114
+ o={...t.parameters,dependencies:t.dependencies},i=Mt(n,o,{exclude:{getSourceArn:!0}});
115
+ if(i.counts)return{...i,name:n.fromService}},"previewResource"),Ut=r(async(e,t,n)=>{
116
+ if(t.result)throw new It(d,e.entryId,t.entryId);return Se(e,n)},"replaceResource"),
117
+ Se=r(async(e,t)=>{let n=e.parameters,o=P(d,"mapping",t),i=await n.getSourceArn(t);
118
+ return{eventId:(await me(o,i)??await ue({...e.parameters,functionName:o,sourceArn:i})).
119
+ eventId,functionName:o,sourceArn:i}},"createResource"),Lt=r(async(e,t,n)=>{let o=e.
120
+ result;if(!o)return;let i=o.sourceArn,s=P(d,"mapping",n),p=t.result?.functionName??
121
+ o.functionName,u={...e.parameters,functionName:s,sourceArn:i},m={...t.parameters,
122
+ functionName:p,sourceArn:i};return await zt(o.eventId,u,m),{...o,functionName:s}},
123
+ "updateResource"),Dt=r(async e=>{let t=e.result;t&&await ge(t.eventId)},"deleteR\
124
+ esource"),zt=r(async(e,t,n)=>{!Nt(t,n,{exclude:{getSourceArn:!0,fromService:!0}})&&
125
+ await le(e,t)},"checkGeneralUpdates");var Fe=r(()=>{Gt(F,ye())},"registerMappingProvider");var we=r(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");import{createPolicy as Wt,tryGetPolicy as $t}from"@ez4/aws-identity";import{getServiceName as qt}from"@ez4/project/library";import{getAccountId as Vt,getRegion as Bt,createPolicyDocument as Ot}from"@ez4/aws-identity";var xe=r(async e=>{let[t,n]=await Promise.all([Bt(),Vt()]);return Ot([{permissions:[
126
+ "logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:logs:${t}:${n}\
127
+ :log-group:${e}-*:*`]}])},"getPolicyDocument");var Pe=r(async e=>{let{state:t,options:n}=e,o=qt("",n),i=`${o}-lambda-policy`;return $t(
128
+ t,i)??Wt(t,{tags:n.tags,policyDocument:await xe(o),policyName:i})},"prepareExecu\
129
+ tionPolicy");var ve=!1,kr=r(()=>{ve||(kt(),Zt(),jt(),Qt("@ez4/aws-function",{"deploy:prepareI\
130
+ dentityAccount":we,"deploy:prepareExecutionPolicy":Pe}),X(),ae(),Fe(),ve=!0)},"r\
131
+ egisterTriggers");import{toKebabCase as Jt,hashData as Kt}from"@ez4/utils";import{attachEntry as _t}from"@ez4/stateful";var _r=r((e,t,n,o)=>{let i=Jt(o.functionName),s=Kt(g,t.entryId,i),p=[t.entryId];
132
+ return n&&p.push(n.entryId),_t(e,{type:g,entryId:s,dependencies:p,parameters:{...o,
133
+ functionName:i}})},"createFunction");import{attachEntry as Xt}from"@ez4/stateful";import{hashData as Ce}from"@ez4/utils";var Re=r(e=>e.type===y,"isPermissionState");var ao=r((e,t,n,o)=>{let i=Ce(y,t.entryId,n.entryId);return Xt(e,{type:y,entryId:i,
134
+ dependencies:[t.entryId,n.entryId],parameters:o})},"createPermission"),po=r((e,t,n)=>{
135
+ let o=Ce(y,t.entryId,n.entryId),i=e[o];return i&&Re(i)?i:null},"getPermission");import{hashData as Yt}from"@ez4/utils";import{attachEntry as en}from"@ez4/stateful";var fo=r((e,t,n,o)=>{let i=Yt(F,t.entryId,n.entryId);return en(e,{type:F,entryId:i,
136
+ dependencies:[t.entryId,n.entryId],parameters:o})},"createMapping");var wo=r(e=>e.type===F,"isMappingState");var vo=r((e,t,n)=>`arn:aws:lambda:${e}:${t}:function:${n}`,"buildFunctionArn");export{a as FunctionServiceName,g as FunctionServiceType,pe as MappingService,d as MappingServiceName,
137
+ F as MappingServiceType,x as PermissionServiceName,y as PermissionServiceType,vo as buildFunctionArn,
138
+ _r as createFunction,fo as createMapping,ao as createPermission,On as getFunctionArn,
139
+ P as getFunctionName,Bn as getFunctionState,po as getPermission,ee as isFunctionState,
140
+ wo as isMappingState,kr as registerTriggers,st as tryGetFunctionArn,Vn as tryGetFunctionState};
137
141
  //# sourceMappingURL=main.mjs.map
@@ -0,0 +1,2 @@
1
+ import type { Arn } from '@ez4/aws-common';
2
+ export declare const buildFunctionArn: (region: string, accountId: string, functionName: string) => Arn;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ez4/aws-function",
3
3
  "description": "EZ4: Self-managed AWS lambda function provider",
4
- "version": "0.28.1",
4
+ "version": "0.30.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -23,6 +23,10 @@
23
23
  "import": "./dist/main.mjs"
24
24
  }
25
25
  },
26
+ "sideEffects": [
27
+ "./dist/main.cjs",
28
+ "./dist/main.mjs"
29
+ ],
26
30
  "workspaces": [
27
31
  "foundation/*",
28
32
  "contracts/*",
@@ -38,13 +42,13 @@
38
42
  "live:publish": "npm run build && npm publish --access public"
39
43
  },
40
44
  "dependencies": {
41
- "@aws-sdk/client-lambda": "^3.758.0",
42
- "@ez4/aws-common": "^0.28.0",
43
- "@ez4/aws-identity": "^0.28.0",
44
- "@ez4/aws-logs": "^0.28.0",
45
- "@ez4/project": "^0.28.0",
46
- "@ez4/stateful": "^0.28.0",
47
- "@ez4/utils": "^0.28.0",
45
+ "@aws-sdk/client-lambda": "^3.913.0",
46
+ "@ez4/aws-common": "^0.30.0",
47
+ "@ez4/aws-identity": "^0.30.0",
48
+ "@ez4/aws-logs": "^0.30.0",
49
+ "@ez4/project": "^0.30.0",
50
+ "@ez4/stateful": "^0.30.0",
51
+ "@ez4/utils": "^0.30.0",
48
52
  "@types/adm-zip": "^0.5.5",
49
53
  "adm-zip": "^0.5.14"
50
54
  }