@ez4/aws-function 0.42.0 → 0.43.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.
@@ -1,20 +1,21 @@
1
1
  import type { Arn, OperationLogLine, ResourceTags } from '@ez4/aws-common';
2
- import type { ArchitectureType, RuntimeType } from '@ez4/project';
2
+ import type { ArchitectureType, LogLevel, RuntimeType } from '@ez4/project';
3
3
  import type { LinkedVariables } from '@ez4/project/library';
4
4
  export type CreateRequest = {
5
5
  roleArn: Arn;
6
+ files?: string[];
6
7
  sourceFile: string;
7
8
  functionName: string;
8
9
  handlerName: string;
9
10
  description?: string;
10
11
  logGroup?: string;
12
+ logLevel?: LogLevel;
11
13
  variables?: LinkedVariables;
12
14
  architecture: ArchitectureType;
13
15
  runtime: RuntimeType;
14
16
  timeout?: number;
15
17
  memory?: number;
16
18
  publish?: boolean;
17
- debug?: boolean;
18
19
  vpc?: boolean;
19
20
  tags?: ResourceTags;
20
21
  };
@@ -27,16 +28,17 @@ export type UpdateConfigurationRequest = {
27
28
  handlerName?: string;
28
29
  description?: string;
29
30
  logGroup?: string;
31
+ logLevel?: LogLevel;
30
32
  variables?: LinkedVariables;
31
33
  runtime?: RuntimeType;
32
34
  timeout?: number;
33
35
  memory?: number;
34
- debug?: boolean;
35
36
  vpc?: boolean;
36
37
  };
37
38
  export type UpdateSourceCodeRequest = {
38
- architecture?: ArchitectureType;
39
+ files?: string[];
39
40
  sourceFile: string;
41
+ architecture?: ArchitectureType;
40
42
  publish?: boolean;
41
43
  };
42
44
  export declare const importFunction: (logger: OperationLogLine, functionName: string, version?: string) => Promise<ImportOrCreateResponse | undefined>;
@@ -0,0 +1,2 @@
1
+ import { LogLevel } from '@ez4/project';
2
+ export declare const getLogLevel: (logLevel: LogLevel) => "ERROR" | "DEBUG" | "INFO" | "WARN";
@@ -1 +1 @@
1
- export declare const getZipBuffer: (filePath: string, entryName: string) => Promise<Buffer<ArrayBufferLike>>;
1
+ export declare const getZipBuffer: (filePath: string, entryName: string, additionalFiles?: string[]) => Promise<Buffer<ArrayBufferLike>>;
@@ -25,6 +25,7 @@ export type FunctionResult = ImportOrCreateResponse & {
25
25
  valuesHash?: string;
26
26
  sourceHash: string;
27
27
  bundleHash: string;
28
+ filesHash?: string;
28
29
  logGroup?: string;
29
30
  roleArn: Arn;
30
31
  };
package/dist/main.cjs CHANGED
@@ -1,185 +1,193 @@
1
- "use strict";var ut=Object.create;var T=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty;var o=(t,e)=>T(t,"name",{value:e,configurable:!0});var ft=(t,e)=>{for(var n in e)T(t,n,{get:e[n],enumerable:!0})},me=(t,e,n,r)=>{if(e&&
2
- typeof e=="object"||typeof e=="function")for(let i of lt(e))!dt.call(t,i)&&i!==n&&
3
- T(t,i,{get:()=>e[i],enumerable:!(r=mt(e,i))||r.enumerable});return t};var yt=(t,e,n)=>(n=t!=null?ut(gt(t)):{},me(e||!t||!t.__esModule?T(n,"default",{value:t,
4
- enumerable:!0}):n,t)),St=t=>me(T({},"__esModule",{value:!0}),t);var Xt={};ft(Xt,{FunctionArchitecture:()=>de,FunctionDefaults:()=>pt,FunctionRuntime:()=>ge,
5
- FunctionServiceName:()=>w,FunctionServiceType:()=>x,MappingService:()=>Ge,MappingServiceName:()=>v,
6
- MappingServiceType:()=>R,PermissionServiceName:()=>E,PermissionServiceType:()=>b,
7
- buildFunctionArn:()=>Kt,createFunction:()=>jt,createMapping:()=>_t,createPermission:()=>Zt,
8
- getDefaultVpcConfig:()=>q,getFunctionArchitecture:()=>D,getFunctionArn:()=>ht,getFunctionName:()=>N,
9
- getFunctionRuntime:()=>z,getFunctionState:()=>Rt,getPermission:()=>Qt,isFunctionState:()=>Y,
10
- isMappingState:()=>Jt,registerTriggers:()=>$t,tryGetFunctionArn:()=>xe,tryGetFunctionState:()=>vt});
11
- module.exports=St(Xt);var Ye=require("@ez4/aws-common"),et=require("@ez4/aws-identity"),tt=require("@ez4/aws-logs"),
12
- nt=require("@ez4/project/library");var Ne=require("@ez4/aws-common");var f=require("@ez4/aws-common"),C=require("@ez4/utils"),re=require("@ez4/aws-logs"),
13
- oe=require("@ez4/aws-identity");var s=require("@aws-sdk/client-lambda"),B=require("@ez4/aws-common");var U=require("@ez4/aws-common"),le=require("@aws-sdk/client-lambda");var d=o(()=>new le.LambdaClient((0,U.getAwsClientOptions)()),"getLambdaClient"),
14
- G=o(t=>({...(0,U.getAwsClientWaiter)(),client:t}),"getLambdaWaiter");var _=require("@ez4/project");var ge=(n=>(n.Node22="nodejs22.x",n.Node24="nodejs24.x",n))(ge||{});var wt={[_.RuntimeType.Node22]:"nodejs22.x",[_.RuntimeType.Node24]:"nodejs24.x"},
15
- z=o(t=>wt[t],"getFunctionRuntime");var J=require("@ez4/project");var de=(n=>(n.Arm="arm64",n.x86="x86_64",n))(de||{});var Ft={[J.ArchitectureType.Arm]:"arm64",[J.ArchitectureType.x86]:"x86_64"},D=o(
16
- t=>Ft[t],"getFunctionArchitecture");var fe=require("@ez4/aws-common"),ye=require("@ez4/utils");var w="AWS:Lambda/Function",x="aws:lambda.function";var xt=/[a-z][\w]+/i,bt=o(t=>xt.test(t),"isValidName"),K=o(t=>{for(let e in t)if(!bt(
17
- e))throw new fe.InvalidParameterError(w,`${e} is an invalid variable name .`)},"\
18
- assertVariables"),A=o(t=>{let e={};for(let n in t)e[n]=(0,ye.hashData)(t[n]);return e},
19
- "protectVariables");var Se=yt(require("adm-zip"),1),we=require("node:fs/promises");var Fe=o(async(t,e)=>{let n=new Se.default,r=await(0,we.readFile)(t);return n.addFile(
20
- e,r),n.toBufferPromise()},"getZipBuffer");var L=require("@ez4/aws-vpc"),X=require("@ez4/aws-common");var k=class extends Error{static{o(this,"FunctionNotFoundError")}constructor(e){
21
- super(`Function ${e} wasn't found.`)}},V=class extends Error{static{o(this,"Defa\
22
- ultVpcDetailsError")}constructor(){super("Unable to get the default VPC details.")}};var Y=o(t=>t.type===x,"isFunctionState"),vt=o((t,e,n)=>{try{let r=t.getServiceState(
23
- e,n);if(Y(r))return r}catch{}},"tryGetFunctionState"),Rt=o((t,e,n)=>{let r=t.getServiceState(
24
- e,n);if(!Y(r))throw new k(e);return r},"getFunctionState"),N=o((t,e,n)=>{let r=n.
25
- getDependencies(x).at(0)?.parameters;if(!r?.functionName)throw new X.IncompleteResourceError(
26
- t,e,"functionName");return r.functionName},"getFunctionName"),xe=o(t=>t.getDependencies(
27
- x)[0]?.result?.functionArn,"tryGetFunctionArn"),ht=o((t,e,n)=>{let r=xe(n);if(!r)
28
- throw new X.IncompleteResourceError(t,e,"functionArn");return r},"getFunctionArn"),
29
- q=o(async()=>{let t=await(0,L.getDefaultVpcId)();if(!t)throw new V;let[e,n]=await Promise.
30
- all([(0,L.getDefaultSubnetIds)(t),(0,L.getDefaultSecurityGroupId)(t)]);if(!e?.length||
31
- !n)throw new V;return{subnetIds:e.slice(0,2),securityGroupId:n}},"getDefaultVpcC\
32
- onfig");var be=o(async(t,e,n)=>{t.update("Importing function");try{let r=await d().send(
33
- new s.GetFunctionCommand({FunctionName:e,Qualifier:n})),i=r.Configuration.Version,
1
+ "use strict";var gt=Object.create;var V=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var o=(t,e)=>V(t,"name",{value:e,configurable:!0});var wt=(t,e)=>{for(var n in e)V(t,n,{get:e[n],enumerable:!0})},ye=(t,e,n,r)=>{if(e&&
2
+ typeof e=="object"||typeof e=="function")for(let i of ft(e))!St.call(t,i)&&i!==n&&
3
+ V(t,i,{get:()=>e[i],enumerable:!(r=dt(e,i))||r.enumerable});return t};var Ft=(t,e,n)=>(n=t!=null?gt(yt(t)):{},ye(e||!t||!t.__esModule?V(n,"default",{value:t,
4
+ enumerable:!0}):n,t)),xt=t=>ye(V({},"__esModule",{value:!0}),t);var tn={};wt(tn,{FunctionArchitecture:()=>we,FunctionDefaults:()=>O,FunctionRuntime:()=>Fe,
5
+ FunctionServiceName:()=>F,FunctionServiceType:()=>x,MappingService:()=>qe,MappingServiceName:()=>b,
6
+ MappingServiceType:()=>R,PermissionServiceName:()=>T,PermissionServiceType:()=>h,
7
+ buildFunctionArn:()=>en,createFunction:()=>_t,createMapping:()=>Xt,createPermission:()=>Jt,
8
+ getDefaultVpcConfig:()=>Q,getFunctionArchitecture:()=>W,getFunctionArn:()=>Pt,getFunctionName:()=>E,
9
+ getFunctionRuntime:()=>j,getFunctionState:()=>Ct,getPermission:()=>Kt,isFunctionState:()=>oe,
10
+ isMappingState:()=>Yt,registerTriggers:()=>Qt,tryGetFunctionArn:()=>Re,tryGetFunctionState:()=>Lt});
11
+ module.exports=xt(tn);var rt=require("@ez4/aws-common"),ot=require("@ez4/aws-identity"),it=require("@ez4/aws-logs"),
12
+ at=require("@ez4/project/library");var Te=require("@ez4/aws-common");var d=require("@ez4/aws-common"),C=require("@ez4/utils"),pe=require("@ez4/aws-logs"),
13
+ ce=require("@ez4/aws-identity");var p=require("@aws-sdk/client-lambda"),_=require("@ez4/aws-common");var q=require("@ez4/aws-common"),Se=require("@aws-sdk/client-lambda");var f=o(()=>new Se.LambdaClient((0,q.getAwsClientOptions)()),"getLambdaClient"),
14
+ B=o(t=>({...(0,q.getAwsClientWaiter)(),client:t}),"getLambdaWaiter");var Y=require("@ez4/project");var we=(n=>(n.Arm="arm64",n.x86="x86_64",n))(we||{});var vt={[Y.ArchitectureType.Arm]:"arm64",[Y.ArchitectureType.x86]:"x86_64"},W=o(
15
+ t=>vt[t],"getFunctionArchitecture");var ee=require("@ez4/project");var Fe=(n=>(n.Node22="nodejs22.x",n.Node24="nodejs24.x",n))(Fe||{});var ht={[ee.RuntimeType.Node22]:"nodejs22.x",[ee.RuntimeType.Node24]:"nodejs24.x"},
16
+ j=o(t=>ht[t],"getFunctionRuntime");var A=require("@ez4/project"),O;(s=>(s.LogRetention=90,s.LogLevel=A.LogLevel.Warning,
17
+ s.Architecture=A.ArchitectureType.x86,s.Runtime=A.RuntimeType.Node24,s.Timeout=90,
18
+ s.Memory=192))(O||={});var xe=require("@ez4/aws-common"),ve=require("@ez4/utils");var F="AWS:Lambda/Function",x="aws:lambda.function";var bt=/[a-z][\w]+/i,Rt=o(t=>bt.test(t),"isValidName"),te=o(t=>{for(let e in t)if(!Rt(
19
+ e))throw new xe.InvalidParameterError(F,`${e} is an invalid variable name .`)},"\
20
+ assertVariables"),N=o(t=>{let e={};for(let n in t)e[n]=(0,ve.hashData)(t[n]);return e},
21
+ "protectVariables");var U=require("@aws-sdk/client-lambda"),z=require("@ez4/project");var ne=o(t=>{switch(t){case z.LogLevel.Information:return U.ApplicationLogLevel.
22
+ Info;case z.LogLevel.Debug:return U.ApplicationLogLevel.Debug;case z.LogLevel.Error:
23
+ return U.ApplicationLogLevel.Error;default:case z.LogLevel.Warning:return U.ApplicationLogLevel.
24
+ Warn}},"getLogLevel");var $=require("node:path"),he=Ft(require("adm-zip"),1);var be=o(async(t,e,n)=>{let r=new he.default;return n?.forEach(i=>{r.addLocalFile(
25
+ i,(0,$.dirname)((0,$.normalize)(i)))}),r.addLocalFile(t,void 0,e),r.toBufferPromise()},
26
+ "getZipBuffer");var I=require("@ez4/aws-vpc"),re=require("@ez4/aws-common");var Z=class extends Error{static{o(this,"FunctionNotFoundError")}constructor(e){
27
+ super(`Function ${e} wasn't found.`)}},G=class extends Error{static{o(this,"Defa\
28
+ ultVpcDetailsError")}constructor(){super("Unable to get the default VPC details.")}};var oe=o(t=>t.type===x,"isFunctionState"),Lt=o((t,e,n)=>{try{let r=t.getServiceState(
29
+ e,n);if(oe(r))return r}catch{}},"tryGetFunctionState"),Ct=o((t,e,n)=>{let r=t.getServiceState(
30
+ e,n);if(!oe(r))throw new Z(e);return r},"getFunctionState"),E=o((t,e,n)=>{let r=n.
31
+ getDependencies(x).at(0)?.parameters;if(!r?.functionName)throw new re.IncompleteResourceError(
32
+ t,e,"functionName");return r.functionName},"getFunctionName"),Re=o(t=>t.getDependencies(
33
+ x)[0]?.result?.functionArn,"tryGetFunctionArn"),Pt=o((t,e,n)=>{let r=Re(n);if(!r)
34
+ throw new re.IncompleteResourceError(t,e,"functionArn");return r},"getFunctionAr\
35
+ n"),Q=o(async()=>{let t=await(0,I.getDefaultVpcId)();if(!t)throw new G;let[e,n]=await Promise.
36
+ all([(0,I.getDefaultSubnetIds)(t),(0,I.getDefaultSecurityGroupId)(t)]);if(!e?.length||
37
+ !n)throw new G;return{subnetIds:e.slice(0,2),securityGroupId:n}},"getDefaultVpcC\
38
+ onfig");var Le=o(async(t,e,n)=>{t.update("Importing function");try{let r=await f().send(
39
+ new p.GetFunctionCommand({FunctionName:e,Qualifier:n})),i=r.Configuration.Version,
34
40
  a=r.Configuration.FunctionArn;return{functionVersion:i,functionArn:a}}catch(r){if(!(r instanceof
35
- s.ResourceNotFoundException))throw r;return}},"importFunction"),ve=o(async(t,e)=>{
36
- t.update("Creating function");let{functionName:n,variables:r}=e;r&&K(r);let i=e.
37
- vpc?await q():void 0,a=Pe(e.handlerName),p=await Ce(e.sourceFile),{description:c,
38
- memory:l,timeout:u,publish:m,architecture:g,runtime:S,debug:F,roleArn:P,logGroup:Q}=e,
39
- O=d(),pe=await(0,B.waitCreation)(()=>O.send(new s.CreateFunctionCommand({FunctionName:n,
40
- Description:c,MemorySize:l,Timeout:u,Role:P,Publish:m,Handler:a,Architectures:[D(
41
- g)],Runtime:z(S),PackageType:"Zip",VpcConfig:{SecurityGroupIds:i?[i.securityGroupId]:
42
- [],SubnetIds:i?i.subnetIds:[]},LoggingConfig:{LogGroup:Q,ApplicationLogLevel:F?s.ApplicationLogLevel.
43
- Debug:s.ApplicationLogLevel.Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.
44
- Json},Code:{ZipFile:p},Environment:{Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}}))),
45
- ct=pe.FunctionArn,ce=pe.Version,ue=G(O);return await(0,s.waitUntilFunctionActive)(
46
- ue,{FunctionName:n}),m&&await(0,s.waitUntilPublishedVersionActive)(ue,{FunctionName:n,
47
- Qualifier:ce}),{functionArn:ct,...m&&{functionVersion:ce}}},"createFunction"),ee=o(
48
- async(t,e,n)=>{t.update("Updating source code");let r=await Ce(n.sourceFile),{publish:i,
49
- architecture:a}=n,p=d(),c=await p.send(new s.UpdateFunctionCodeCommand({Architectures:a&&
50
- [D(a)],FunctionName:e,ZipFile:r,Publish:i})),l=c.FunctionArn,u=c.Version,m=G(p);
51
- return await(0,s.waitUntilFunctionUpdated)(m,{FunctionName:e}),i&&await(0,s.waitUntilPublishedVersionActive)(
52
- m,{FunctionName:e,Qualifier:u}),{functionArn:l,...i&&{functionVersion:u}}},"upda\
53
- teSourceCode"),te=o(async(t,e,n)=>{t.update("Updating configuration");let{handlerName:r,
54
- variables:i}=n;i&&K(i);let a=n.vpc?await q():void 0,{description:p,memory:c,timeout:l,
55
- runtime:u,debug:m,roleArn:g,logGroup:S}=n,F=d();await F.send(new s.UpdateFunctionConfigurationCommand(
56
- {Runtime:u&&z(u),FunctionName:e,Description:p,MemorySize:c,Timeout:l,Role:g,...r&&
57
- {Handler:Pe(r)},VpcConfig:{SecurityGroupIds:a?[a.securityGroupId]:[],SubnetIds:a?
58
- a.subnetIds:[]},LoggingConfig:{LogGroup:S,ApplicationLogLevel:m?s.ApplicationLogLevel.
59
- Debug:s.ApplicationLogLevel.Warn,SystemLogLevel:s.SystemLogLevel.Warn,LogFormat:s.LogFormat.
60
- Json},Environment:{Variables:i}})),await(0,s.waitUntilFunctionUpdated)(G(F),{FunctionName:e})},
61
- "updateConfiguration"),Re=o(async(t,e)=>{e.update("Deleting function");let n=d();
62
- await(0,B.waitDeletion)(async()=>{try{await n.send(new s.DeleteFunctionCommand({
63
- FunctionName:t}))}catch(r){if(!(r instanceof s.ResourceNotFoundException))throw r}})},
64
- "deleteFunction");var ne=o(async(t,e,n)=>{t.update("Tag function"),await d().send(new s.TagResourceCommand(
65
- {Resource:e,Tags:{...n,ManagedBy:"EZ4"}}))},"tagFunction"),he=o(async(t,e,n)=>{t.
66
- update("Untag function"),await d().send(new s.UntagResourceCommand({Resource:e,TagKeys:n}))},
67
- "untagFunction"),Ce=o(t=>Fe(t,"main.mjs"),"getSourceZipFile"),Pe=o(t=>`main.${t}`,
68
- "getSourceHandlerName");var Ae=o(()=>({equals:Ct,create:Le,replace:At,preview:Pt,update:Lt,delete:Nt}),"\
69
- getFunctionHandler"),Ct=o((t,e)=>!!t.result&&t.result.functionArn===e.result?.functionArn,
70
- "equalsResource"),Pt=o(async(t,e)=>{let n=t.parameters,r=e.parameters,i=(0,C.deepCompare)(
71
- {...n,connections:t.connections,dependencies:t.dependencies,variables:A(await n.
72
- getFunctionVariables()),sourceHash:await(0,f.getBundleHash)(...n.getFunctionFiles()),
73
- valuesHash:n.getFunctionHash()},{...r,connections:e.connections,dependencies:e.dependencies,
74
- variables:e.result?.variables,sourceHash:e.result?.sourceHash,valuesHash:e.result?.
75
- valuesHash},{exclude:{release:!0}});if(i.counts)return{...i,name:n.functionName}},
76
- "previewResource"),At=o(async(t,e,n)=>{if(e.result)throw new f.ReplaceResourceError(
77
- w,t.entryId,e.entryId);return Le(t,n)},"replaceResource"),Le=o((t,e)=>{let{functionName:n,
78
- release:r,...i}=t.parameters;return f.OperationLogger.logExecution(w,n,"creation",
79
- async a=>{let p=(0,re.getLogGroupName)(w,n,e),c=(0,oe.getRoleArn)(w,n,e),[l,u,m,
80
- g]=await Promise.all([(0,f.getBundleHash)(...i.getFunctionFiles()),i.getFunctionBundle(
81
- e),i.getFunctionHash(),i.getFunctionVariables()]),S=await be(a,n),F=await(0,C.hashFile)(
82
- u);if(S)return await ee(a,n,{architecture:i.architecture,publish:!1,sourceFile:u}),
83
- await te(a,n,{...i,logGroup:p,roleArn:c,variables:{...g,...r?.variableName&&{[r.
84
- variableName]:r.version}}}),await ne(a,S.functionArn,{...i.tags,...r?.tagName&&{
85
- [r.tagName]:r.version}}),{functionArn:S.functionArn,functionVersion:S.functionVersion,
86
- variables:A(g),valuesHash:m,sourceHash:l,bundleHash:F,logGroup:p,roleArn:c};let P=await ve(
87
- a,{...i,publish:!0,functionName:n,sourceFile:u,logGroup:p,roleArn:c,variables:{...g,
88
- ...r?.variableName&&{[r.variableName]:r.version}},tags:{...i.tags,...r?.tagName&&
89
- {[r.tagName]:r.version}}});return{functionArn:P.functionArn,functionVersion:P.functionVersion,
90
- variables:A(g),valuesHash:m,sourceHash:l,bundleHash:F,logGroup:p,roleArn:c}})},"\
91
- createResource"),Lt=o((t,e,n)=>{let{parameters:r,result:i}=t,{functionName:a}=r;
92
- if(!i)throw new f.CorruptedResourceError(w,a);return f.OperationLogger.logExecution(
93
- w,a,"updates",async p=>{let c=await r.getFunctionVariables(),l=e.result?.variables??
94
- c,u=(0,oe.getRoleArn)(w,a,n),m=e.result?.roleArn??u,g=(0,re.getLogGroupName)(w,a,
95
- n),S=e.result?.logGroup??g,{isUpdated:F,...P}=await Mt(p,a,r,e.result,n),Q={...r,
96
- variables:c,roleArn:u,logGroup:g},O={...e.parameters,variables:l,roleArn:m,logGroup:S};
97
- return await It(p,a,Q,O,F,n),await Et(p,i.functionArn,r,e.parameters,F),{...i,...P,
98
- variables:A(c),logGroup:g,roleArn:u}})},"updateResource"),Nt=o(async t=>{let{result:e,
99
- parameters:n}=t;if(!e)return;let{functionName:r}=n;await f.OperationLogger.logExecution(
100
- w,r,"deletion",async i=>{await Re(r,i)})},"deleteResource"),It=o(async(t,e,n,r,i,a)=>{
101
- let{variables:p,...c}=n,l={variables:A(p),...c},u=!(0,C.deepEqual)(l,r,{exclude:{
102
- sourceFile:!0,functionName:!0,architecture:!0,release:!0,tags:!0}}),m=i?n.release:
103
- r.release,g=i&&m?.variableName;(u||g||a.force)&&await te(t,e,{...n,variables:{...n.
104
- variables,...m?.variableName&&{[m.variableName]:m.version}}})},"checkConfigurati\
105
- onUpdates"),Et=o(async(t,e,n,r,i)=>{let p=i&&n.release?.version!==r.release?.version?
106
- n.release:void 0,c={...n.tags,...p?.tagName&&{[p.tagName]:p.version}};await(0,f.applyTagUpdates)(
107
- c,r.tags,l=>ne(t,e,l),l=>he(t,e,l))},"checkTagUpdates"),Mt=o(async(t,e,n,r,i)=>{
108
- let[a,p]=await Promise.all([(0,f.getBundleHash)(...n.getFunctionFiles()),n.getFunctionHash()]),
109
- c=r?.sourceHash,l=r?.valuesHash;if(a!==c||p!==l||i.force){let u=await n.getFunctionBundle(
110
- i),m=await(0,C.hashFile)(u),g=r?.bundleHash;if(m===g&&p===l)return t.update("Ski\
111
- pping source code update"),{isUpdated:!1,valuesHash:p,sourceHash:a};let{functionVersion:S}=await ee(
112
- t,e,{architecture:n.architecture,publish:!r?.functionVersion,sourceFile:u});return{
113
- isUpdated:!0,valuesHash:p,sourceHash:a,bundleHash:m,...S&&{functionVersion:S}}}return{
114
- isUpdated:!1}},"checkSourceCodeUpdates");var Ie=o(()=>{(0,Ne.tryRegisterProvider)(x,Ae())},"registerFunctionProvider");var He=require("@ez4/aws-common");var H=require("@ez4/aws-common");var I=require("@aws-sdk/client-lambda");var Ee=o(async(t,e)=>{t.update("Creating permission");let n=e.statementId??`ID${Date.
115
- now()}`;return await d().send(new I.AddPermissionCommand({StatementId:n,FunctionName:e.
41
+ p.ResourceNotFoundException))throw r;return}},"importFunction"),Ce=o(async(t,e)=>{
42
+ t.update("Creating function");let{functionName:n,variables:r}=e;r&&te(r);let i=e.
43
+ vpc?await Q():void 0,a=await Ne(e.sourceFile,e.files),s=Ie(e.handlerName),{description:c,
44
+ memory:l,timeout:m,publish:u,architecture:g,runtime:w,roleArn:y,logGroup:v,logLevel:P}=e,
45
+ k=f(),ge=await(0,_.waitCreation)(()=>k.send(new p.CreateFunctionCommand({FunctionName:n,
46
+ Description:c,MemorySize:l,Timeout:m,Role:y,Publish:u,Handler:s,Architectures:[W(
47
+ g)],Runtime:j(w),PackageType:"Zip",VpcConfig:{SecurityGroupIds:i?[i.securityGroupId]:
48
+ [],SubnetIds:i?i.subnetIds:[]},LoggingConfig:{LogGroup:v,ApplicationLogLevel:ne(
49
+ P??O.LogLevel),SystemLogLevel:p.SystemLogLevel.Warn,LogFormat:p.LogFormat.Json},
50
+ Code:{ZipFile:a},Environment:{Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}}))),
51
+ lt=ge.FunctionArn,de=ge.Version,fe=B(k);return await(0,p.waitUntilFunctionActive)(
52
+ fe,{FunctionName:n}),u&&await(0,p.waitUntilPublishedVersionActive)(fe,{FunctionName:n,
53
+ Qualifier:de}),{functionArn:lt,...u&&{functionVersion:de}}},"createFunction"),ie=o(
54
+ async(t,e,n)=>{t.update("Updating source code");let r=await Ne(n.sourceFile,n.files),
55
+ {publish:i,architecture:a}=n,s=f(),c=await s.send(new p.UpdateFunctionCodeCommand(
56
+ {Architectures:a&&[W(a)],FunctionName:e,ZipFile:r,Publish:i})),l=c.FunctionArn,m=c.
57
+ Version,u=B(s);return await(0,p.waitUntilFunctionUpdated)(u,{FunctionName:e}),i&&
58
+ await(0,p.waitUntilPublishedVersionActive)(u,{FunctionName:e,Qualifier:m}),{functionArn:l,
59
+ ...i&&{functionVersion:m}}},"updateSourceCode"),ae=o(async(t,e,n)=>{t.update("Up\
60
+ dating configuration");let{handlerName:r,variables:i}=n;i&&te(i);let a=n.vpc?await Q():
61
+ void 0,{description:s,memory:c,timeout:l,runtime:m,roleArn:u,logGroup:g,logLevel:w}=n,
62
+ y=f();await y.send(new p.UpdateFunctionConfigurationCommand({Runtime:m&&j(m),FunctionName:e,
63
+ Description:s,MemorySize:c,Timeout:l,Role:u,...r&&{Handler:Ie(r)},VpcConfig:{SecurityGroupIds:a?
64
+ [a.securityGroupId]:[],SubnetIds:a?a.subnetIds:[]},LoggingConfig:{LogGroup:g,ApplicationLogLevel:ne(
65
+ w??O.LogLevel),SystemLogLevel:p.SystemLogLevel.Warn,LogFormat:p.LogFormat.Json},
66
+ Environment:{Variables:i}})),await(0,p.waitUntilFunctionUpdated)(B(y),{FunctionName:e})},
67
+ "updateConfiguration"),Pe=o(async(t,e)=>{e.update("Deleting function");let n=f();
68
+ await(0,_.waitDeletion)(async()=>{try{await n.send(new p.DeleteFunctionCommand({
69
+ FunctionName:t}))}catch(r){if(!(r instanceof p.ResourceNotFoundException))throw r}})},
70
+ "deleteFunction");var se=o(async(t,e,n)=>{t.update("Tag function"),await f().send(new p.TagResourceCommand(
71
+ {Resource:e,Tags:{...n,ManagedBy:"EZ4"}}))},"tagFunction"),Ae=o(async(t,e,n)=>{t.
72
+ update("Untag function"),await f().send(new p.UntagResourceCommand({Resource:e,TagKeys:n}))},
73
+ "untagFunction"),Ne=o((t,e)=>be(t,"main.mjs",e),"getSourceZipFile"),Ie=o(t=>`mai\
74
+ n.${t}`,"getSourceHandlerName");var Ee=o(()=>({equals:At,create:Me,replace:It,preview:Nt,update:Et,delete:Mt}),"\
75
+ getFunctionHandler"),At=o((t,e)=>!!t.result&&t.result.functionArn===e.result?.functionArn,
76
+ "equalsResource"),Nt=o(async(t,e)=>{let n=t.parameters,r=e.parameters,i=(0,C.deepCompare)(
77
+ {...n,connections:t.connections,dependencies:t.dependencies,variables:N(await n.
78
+ getFunctionVariables()),filesHash:n.files&&await(0,d.getBundleHash)(n.functionName,
79
+ n.files),sourceHash:await(0,d.getBundleHash)(...n.getFunctionFiles()),valuesHash:n.
80
+ getFunctionHash()},{...r,connections:e.connections,dependencies:e.dependencies,variables:e.
81
+ result?.variables,sourceHash:e.result?.sourceHash,valuesHash:e.result?.valuesHash,
82
+ filesHash:e.result?.filesHash},{exclude:{release:!0}});if(i.counts)return{...i,name:n.
83
+ functionName}},"previewResource"),It=o(async(t,e,n)=>{if(e.result)throw new d.ReplaceResourceError(
84
+ F,t.entryId,e.entryId);return Me(t,n)},"replaceResource"),Me=o((t,e)=>{let{functionName:n,
85
+ release:r,...i}=t.parameters;return d.OperationLogger.logExecution(F,n,"creation",
86
+ async a=>{let s=(0,pe.getLogGroupName)(F,n,e),c=(0,ce.getRoleArn)(F,n,e),[l,m,u,
87
+ g,w]=await Promise.all([(0,d.getBundleHash)(...i.getFunctionFiles()),i.files&&(0,d.getBundleHash)(
88
+ n,i.files),i.getFunctionBundle(e),i.getFunctionHash(),i.getFunctionVariables()]),
89
+ y=await Le(a,n),v=await(0,C.hashFile)(u);if(y)return await ie(a,n,{architecture:i.
90
+ architecture,files:i.files,publish:!1,sourceFile:u}),await ae(a,n,{...i,logGroup:s,
91
+ roleArn:c,variables:{...w,...r?.variableName&&{[r.variableName]:r.version}}}),await se(
92
+ a,y.functionArn,{...i.tags,...r?.tagName&&{[r.tagName]:r.version}}),{functionArn:y.
93
+ functionArn,functionVersion:y.functionVersion,variables:N(w),sourceHash:l,valuesHash:g,
94
+ bundleHash:v,filesHash:m,logGroup:s,roleArn:c};let P=await Ce(a,{...i,publish:!0,
95
+ functionName:n,sourceFile:u,logGroup:s,roleArn:c,variables:{...w,...r?.variableName&&
96
+ {[r.variableName]:r.version}},tags:{...i.tags,...r?.tagName&&{[r.tagName]:r.version}}});
97
+ return{functionArn:P.functionArn,functionVersion:P.functionVersion,variables:N(w),
98
+ sourceHash:l,valuesHash:g,bundleHash:v,filesHash:m,logGroup:s,roleArn:c}})},"cre\
99
+ ateResource"),Et=o((t,e,n)=>{let{parameters:r,result:i}=t,{functionName:a}=r;if(!i)
100
+ throw new d.CorruptedResourceError(F,a);return d.OperationLogger.logExecution(F,
101
+ a,"updates",async s=>{let c=await r.getFunctionVariables(),l=e.result?.variables??
102
+ c,m=(0,ce.getRoleArn)(F,a,n),u=e.result?.roleArn??m,g=(0,pe.getLogGroupName)(F,a,
103
+ n),w=e.result?.logGroup??g,{isUpdated:y,...v}=await Vt(s,a,r,e.result,n),P={...r,
104
+ variables:c,roleArn:m,logGroup:g},k={...e.parameters,variables:l,roleArn:u,logGroup:w};
105
+ return await Tt(s,a,P,k,y,n),await Ht(s,i.functionArn,r,e.parameters,y),{...i,...v,
106
+ variables:N(c),logGroup:g,roleArn:m}})},"updateResource"),Mt=o(async t=>{let{result:e,
107
+ parameters:n}=t;if(!e)return;let{functionName:r}=n;await d.OperationLogger.logExecution(
108
+ F,r,"deletion",async i=>{await Pe(r,i)})},"deleteResource"),Tt=o(async(t,e,n,r,i,a)=>{
109
+ let{variables:s,...c}=n,l={variables:N(s),...c},m=!(0,C.deepEqual)(l,r,{exclude:{
110
+ sourceFile:!0,functionName:!0,architecture:!0,release:!0,tags:!0}}),u=i?n.release:
111
+ r.release,g=i&&u?.variableName;(m||g||a.force)&&await ae(t,e,{...n,variables:{...n.
112
+ variables,...u?.variableName&&{[u.variableName]:u.version}}})},"checkConfigurati\
113
+ onUpdates"),Ht=o(async(t,e,n,r,i)=>{let s=i&&n.release?.version!==r.release?.version?
114
+ n.release:void 0,c={...n.tags,...s?.tagName&&{[s.tagName]:s.version}};await(0,d.applyTagUpdates)(
115
+ c,r.tags,l=>se(t,e,l),l=>Ae(t,e,l))},"checkTagUpdates"),Vt=o(async(t,e,n,r,i)=>{
116
+ let[a,s,c]=await Promise.all([(0,d.getBundleHash)(...n.getFunctionFiles()),n.files&&
117
+ (0,d.getBundleHash)(e,n.files),n.getFunctionHash()]),l=r?.sourceHash,m=r?.valuesHash,
118
+ u=r?.filesHash;if(a!==l||c!==m||s!==u||i.force){let g=await n.getFunctionBundle(
119
+ i),w=await(0,C.hashFile)(g),y=r?.bundleHash;if(w===y&&s===u&&c===m)return t.update(
120
+ "Skipping source code update"),{isUpdated:!1,sourceHash:a};let{functionVersion:v}=await ie(
121
+ t,e,{architecture:n.architecture,publish:!r?.functionVersion,sourceFile:g,files:n.
122
+ files});return{isUpdated:!0,valuesHash:c,sourceHash:a,bundleHash:w,filesHash:s,...v&&
123
+ {functionVersion:v}}}return{isUpdated:!1}},"checkSourceCodeUpdates");var He=o(()=>{(0,Te.tryRegisterProvider)(x,Ee())},"registerFunctionProvider");var Ge=require("@ez4/aws-common");var D=require("@ez4/aws-common");var M=require("@aws-sdk/client-lambda");var Ve=o(async(t,e)=>{t.update("Creating permission");let n=e.statementId??`ID${Date.
124
+ now()}`;return await f().send(new M.AddPermissionCommand({StatementId:n,FunctionName:e.
116
125
  functionName,SourceArn:e.sourceArn,Principal:e.principal,Action:e.action})),{statementId:n}},
117
- "createPermission"),Me=o(async(t,e,n)=>{t.update("Deleting permission");try{return await d().
118
- send(new I.RemovePermissionCommand({FunctionName:e,StatementId:n})),!0}catch(r){
119
- if(!(r instanceof I.ResourceNotFoundException))throw r;return!1}},"deletePermiss\
120
- ion");var E="AWS:Lambda/Permission",b="aws:lambda.permission";var Te=o(()=>({equals:Tt,create:Ve,replace:Ht,preview:Vt,update:Ot,delete:Ut}),"\
121
- getPermissionHandler"),Tt=o((t,e)=>!!t.result&&t.result.functionName===e.result?.
122
- functionName,"equalsResource"),Vt=o((t,e)=>{},"previewResource"),Ht=o(async(t,e,n)=>{
123
- if(e.result)throw new H.ReplaceResourceError(E,t.entryId,e.entryId);return Ve(t,
124
- n)},"replaceResource"),Ve=o((t,e)=>{let n=t.parameters,r=N(E,"permission",e);return H.OperationLogger.
125
- logExecution(E,r,"creation",async i=>{let a=await n.getPermission(e);return{statementId:(await Ee(
126
+ "createPermission"),Oe=o(async(t,e,n)=>{t.update("Deleting permission");try{return await f().
127
+ send(new M.RemovePermissionCommand({FunctionName:e,StatementId:n})),!0}catch(r){
128
+ if(!(r instanceof M.ResourceNotFoundException))throw r;return!1}},"deletePermiss\
129
+ ion");var T="AWS:Lambda/Permission",h="aws:lambda.permission";var Ue=o(()=>({equals:Ot,create:ze,replace:zt,preview:Ut,update:Gt,delete:Dt}),"\
130
+ getPermissionHandler"),Ot=o((t,e)=>!!t.result&&t.result.functionName===e.result?.
131
+ functionName,"equalsResource"),Ut=o((t,e)=>{},"previewResource"),zt=o(async(t,e,n)=>{
132
+ if(e.result)throw new D.ReplaceResourceError(T,t.entryId,e.entryId);return ze(t,
133
+ n)},"replaceResource"),ze=o((t,e)=>{let n=t.parameters,r=E(T,"permission",e);return D.OperationLogger.
134
+ logExecution(T,r,"creation",async i=>{let a=await n.getPermission(e);return{statementId:(await Ve(
126
135
  i,{action:"lambda:InvokeFunction",sourceArn:a.sourceArn,principal:a.principal,functionName:r})).
127
- statementId,functionName:r}})},"createResource"),Ot=o(async()=>{},"updateResourc\
128
- e"),Ut=o(async t=>{let e=t.result;if(!e)return;let{functionName:n,statementId:r}=e;
129
- await H.OperationLogger.logExecution(E,n,"deletion",async i=>{await Me(i,n,r)})},
130
- "deleteResource");var Oe=o(()=>{(0,He.tryRegisterProvider)(b,Te())},"registerPermissionProvider");var Ze=require("@ez4/aws-common");var h=require("@ez4/aws-common"),W=require("@ez4/utils");var y=require("@aws-sdk/client-lambda"),ze=require("@ez4/aws-common");var Ue=require("@aws-sdk/client-lambda"),ie=require("@ez4/utils");var ae=o(async(t,e)=>{let n=new Set(["Enabled","Disabled"]);await ie.Wait.until(
131
- async()=>{let r=await Gt(t,e);return n.has(r)?!0:ie.Wait.RetryAttempt})},"waitFo\
132
- rReadyState"),Gt=o(async(t,e)=>(await t.send(new Ue.GetEventSourceMappingCommand(
133
- {UUID:e}))).State,"getMappingState");var v="AWS:Lambda/Mapping",R="aws:lambda.mapping",Ge=(n=>(n.DynamoDB="dynamodb",
134
- n.Queue="sqs",n))(Ge||{});var De=o(async(t,e,n)=>{t.update("Importing mapping");let r=await d().send(new y.ListEventSourceMappingsCommand(
136
+ statementId,functionName:r}})},"createResource"),Gt=o(async()=>{},"updateResourc\
137
+ e"),Dt=o(async t=>{let e=t.result;if(!e)return;let{functionName:n,statementId:r}=e;
138
+ await D.OperationLogger.logExecution(T,n,"deletion",async i=>{await Oe(i,n,r)})},
139
+ "deleteResource");var De=o(()=>{(0,Ge.tryRegisterProvider)(h,Ue())},"registerPermissionProvider");var Ke=require("@ez4/aws-common");var L=require("@ez4/aws-common"),J=require("@ez4/utils");var S=require("@aws-sdk/client-lambda"),Be=require("@ez4/aws-common");var ke=require("@aws-sdk/client-lambda"),ue=require("@ez4/utils");var me=o(async(t,e)=>{let n=new Set(["Enabled","Disabled"]);await ue.Wait.until(
140
+ async()=>{let r=await kt(t,e);return n.has(r)?!0:ue.Wait.RetryAttempt})},"waitFo\
141
+ rReadyState"),kt=o(async(t,e)=>(await t.send(new ke.GetEventSourceMappingCommand(
142
+ {UUID:e}))).State,"getMappingState");var b="AWS:Lambda/Mapping",R="aws:lambda.mapping",qe=(n=>(n.DynamoDB="dynamodb",
143
+ n.Queue="sqs",n))(qe||{});var We=o(async(t,e,n)=>{t.update("Importing mapping");let r=await f().send(new S.ListEventSourceMappingsCommand(
135
144
  {FunctionName:e,EventSourceArn:n})),[i]=r.EventSourceMappings;return i?{eventId:i.
136
- UUID}:void 0},"importMapping"),ke=o(async(t,e)=>{t.update("Creating mapping");let{
137
- sourceArn:n,functionName:r}=e,i=d(),p=(await i.send(new y.CreateEventSourceMappingCommand(
138
- {FunctionName:r,EventSourceArn:n,...We(e)}))).UUID;return await ae(i,p),{eventId:p}},
139
- "createMapping"),qe=o(async(t,e,n)=>{t.update("Updating mapping");let{functionName:r}=n,
140
- i=d();await i.send(new y.UpdateEventSourceMappingCommand({UUID:e,FunctionName:r,
141
- ...We(n)})),await ae(i,e)},"updateMapping"),Be=o(async(t,e)=>{t.update("Deleting\
142
- mapping");try{return await d().send(new y.DeleteEventSourceMappingCommand({UUID:e})),
143
- !0}catch(n){if(!(n instanceof y.ResourceNotFoundException))throw n;return!1}},"d\
144
- eleteMapping"),We=o(t=>{let{sourceArn:e,enabled:n,concurrency:r,batch:i}=t,{service:a}=(0,ze.parseArn)(
145
- e);return{Enabled:n,FunctionResponseTypes:[y.FunctionResponseType.ReportBatchItemFailures],
145
+ UUID}:void 0},"importMapping"),je=o(async(t,e)=>{t.update("Creating mapping");let{
146
+ sourceArn:n,functionName:r}=e,i=f(),s=(await i.send(new S.CreateEventSourceMappingCommand(
147
+ {FunctionName:r,EventSourceArn:n,...Qe(e)}))).UUID;return await me(i,s),{eventId:s}},
148
+ "createMapping"),$e=o(async(t,e,n)=>{t.update("Updating mapping");let{functionName:r}=n,
149
+ i=f();await i.send(new S.UpdateEventSourceMappingCommand({UUID:e,FunctionName:r,
150
+ ...Qe(n)})),await me(i,e)},"updateMapping"),Ze=o(async(t,e)=>{t.update("Deleting\
151
+ mapping");try{return await f().send(new S.DeleteEventSourceMappingCommand({UUID:e})),
152
+ !0}catch(n){if(!(n instanceof S.ResourceNotFoundException))throw n;return!1}},"d\
153
+ eleteMapping"),Qe=o(t=>{let{sourceArn:e,enabled:n,concurrency:r,batch:i}=t,{service:a}=(0,Be.parseArn)(
154
+ e);return{Enabled:n,FunctionResponseTypes:[S.FunctionResponseType.ReportBatchItemFailures],
146
155
  MaximumBatchingWindowInSeconds:i?.maxWait,BatchSize:i?.size,...a==="dynamodb"&&{
147
- StartingPosition:y.EventSourcePosition.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:r}}}},
148
- "upsertMappingRequest");var $e=o(()=>({equals:zt,create:je,replace:kt,preview:Dt,update:qt,delete:Bt}),"\
149
- getMappingHandler"),zt=o((t,e)=>!!t.result&&t.result.eventId===e.result?.eventId,
150
- "equalsResource"),Dt=o((t,e)=>{let n={...t.parameters,dependencies:t.dependencies},
151
- r={...e.parameters,dependencies:e.dependencies},i=(0,W.deepCompare)(n,r,{exclude:{
156
+ StartingPosition:S.EventSourcePosition.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:r}}}},
157
+ "upsertMappingRequest");var _e=o(()=>({equals:qt,create:Je,replace:Wt,preview:Bt,update:jt,delete:$t}),"\
158
+ getMappingHandler"),qt=o((t,e)=>!!t.result&&t.result.eventId===e.result?.eventId,
159
+ "equalsResource"),Bt=o((t,e)=>{let n={...t.parameters,dependencies:t.dependencies},
160
+ r={...e.parameters,dependencies:e.dependencies},i=(0,J.deepCompare)(n,r,{exclude:{
152
161
  getSourceArn:!0}});if(i.counts)return{...i,name:n.fromService}},"previewResource"),
153
- kt=o(async(t,e,n)=>{if(e.result)throw new h.ReplaceResourceError(v,t.entryId,e.entryId);
154
- return je(t,n)},"replaceResource"),je=o((t,e)=>{let n=t.parameters,r=N(v,"mappin\
155
- g",e);return h.OperationLogger.logExecution(v,r,"creation",async i=>{let a=await n.
156
- getSourceArn(e);return{eventId:(await De(i,r,a)??await ke(i,{...t.parameters,functionName:r,
157
- sourceArn:a})).eventId,functionName:r,sourceArn:a}})},"createResource"),qt=o((t,e,n)=>{
158
- let{result:r,parameters:i}=t,{fromService:a}=i;if(!r)throw new h.CorruptedResourceError(
159
- v,"mapping");return h.OperationLogger.logExecution(v,a,"updates",async p=>{let c=N(
160
- v,"mapping",n),l=e.result?.functionName??r.functionName,u=r.sourceArn,m={...t.parameters,
161
- functionName:c,sourceArn:u},g={...e.parameters,functionName:l,sourceArn:u};return await Wt(
162
- p,r.eventId,m,g),{...r,functionName:c}})},"updateResource"),Bt=o(async t=>{let e=t.
163
- result;if(!e)return;let{functionName:n}=e;await h.OperationLogger.logExecution(v,
164
- n,"deletion",async r=>{await Be(r,e.eventId)})},"deleteResource"),Wt=o(async(t,e,n,r)=>{
165
- !(0,W.deepEqual)(n,r,{exclude:{getSourceArn:!0,fromService:!0}})&&await qe(t,e,n)},
166
- "checkGeneralUpdates");var Qe=o(()=>{(0,Ze.tryRegisterProvider)(R,$e())},"registerMappingProvider");var _e=o(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");var $=require("@ez4/aws-identity"),Ke=require("@ez4/project/library");var M=require("@ez4/aws-identity");var Je=o(async t=>{let[e,n]=await Promise.all([(0,M.getRegion)(),(0,M.getAccountId)()]);
167
- return(0,M.createPolicyDocument)([{permissions:["logs:CreateLogStream","logs:Put\
162
+ Wt=o(async(t,e,n)=>{if(e.result)throw new L.ReplaceResourceError(b,t.entryId,e.entryId);
163
+ return Je(t,n)},"replaceResource"),Je=o((t,e)=>{let n=t.parameters,r=E(b,"mappin\
164
+ g",e);return L.OperationLogger.logExecution(b,r,"creation",async i=>{let a=await n.
165
+ getSourceArn(e);return{eventId:(await We(i,r,a)??await je(i,{...t.parameters,functionName:r,
166
+ sourceArn:a})).eventId,functionName:r,sourceArn:a}})},"createResource"),jt=o((t,e,n)=>{
167
+ let{result:r,parameters:i}=t,{fromService:a}=i;if(!r)throw new L.CorruptedResourceError(
168
+ b,"mapping");return L.OperationLogger.logExecution(b,a,"updates",async s=>{let c=E(
169
+ b,"mapping",n),l=e.result?.functionName??r.functionName,m=r.sourceArn,u={...t.parameters,
170
+ functionName:c,sourceArn:m},g={...e.parameters,functionName:l,sourceArn:m};return await Zt(
171
+ s,r.eventId,u,g),{...r,functionName:c}})},"updateResource"),$t=o(async t=>{let e=t.
172
+ result;if(!e)return;let{functionName:n}=e;await L.OperationLogger.logExecution(b,
173
+ n,"deletion",async r=>{await Ze(r,e.eventId)})},"deleteResource"),Zt=o(async(t,e,n,r)=>{
174
+ !(0,J.deepEqual)(n,r,{exclude:{getSourceArn:!0,fromService:!0}})&&await $e(t,e,n)},
175
+ "checkGeneralUpdates");var Xe=o(()=>{(0,Ke.tryRegisterProvider)(R,_e())},"registerMappingProvider");var Ye=o(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");var K=require("@ez4/aws-identity"),tt=require("@ez4/project/library");var H=require("@ez4/aws-identity");var et=o(async t=>{let[e,n]=await Promise.all([(0,H.getRegion)(),(0,H.getAccountId)()]);
176
+ return(0,H.createPolicyDocument)([{permissions:["logs:CreateLogStream","logs:Put\
168
177
  LogEvents"],resourceIds:[`arn:aws:logs:${e}:${n}:log-group:${t}-*:*`]},{permissions:[
169
178
  "ec2:CreateNetworkInterface","ec2:DescribeNetworkInterfaces","ec2:DeleteNetworkI\
170
- nterface"],resourceIds:["*"]}])},"getPolicyDocument");var Xe=o(async t=>{let{state:e,options:n}=t,r=(0,Ke.getServiceName)("",n),i=`${r}\
171
- -lambda-policy`;return(0,$.tryGetPolicy)(e,i)??(0,$.createPolicy)(e,{tags:n.tags,
172
- policyDocument:await Je(r),policyName:i})},"prepareExecutionPolicy");var $t=o(()=>{(0,Ye.registerTriggers)(),(0,et.registerTriggers)(),(0,tt.registerTriggers)(),
173
- (0,nt.tryCreateTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":_e,
174
- "deploy:prepareExecutionPolicy":Xe}),Ie(),Oe(),Qe()},"registerTriggers");var j=require("@ez4/utils"),rt=require("@ez4/stateful");var jt=o((t,e,n,r)=>{let i=(0,j.toKebabCase)(r.functionName),a=(0,j.hashData)(x,
175
- e.entryId,i),p=[e.entryId];return n&&p.push(n.entryId),(0,rt.attachEntry)(t,{type:x,
176
- entryId:a,dependencies:p,parameters:{...r,functionName:i}})},"createFunction");var it=require("@ez4/stateful"),se=require("@ez4/utils");var ot=o(t=>t.type===b,"isPermissionState");var Zt=o((t,e,n,r)=>{let i=(0,se.hashData)(b,e.entryId,n.entryId);return(0,it.attachEntry)(
177
- t,{type:b,entryId:i,dependencies:[e.entryId,n.entryId],parameters:r})},"createPe\
178
- rmission"),Qt=o((t,e,n)=>{let r=(0,se.hashData)(b,e.entryId,n.entryId),i=t[r];return i&&
179
- ot(i)?i:null},"getPermission");var at=require("@ez4/utils"),st=require("@ez4/stateful");var _t=o((t,e,n,r)=>{let i=(0,at.hashData)(R,e.entryId,n.entryId);return(0,st.attachEntry)(
179
+ nterface"],resourceIds:["*"]}])},"getPolicyDocument");var nt=o(async t=>{let{state:e,options:n}=t,r=(0,tt.getServiceName)("",n),i=`${r}\
180
+ -lambda-policy`;return(0,K.tryGetPolicy)(e,i)??(0,K.createPolicy)(e,{tags:n.tags,
181
+ policyDocument:await et(r),policyName:i})},"prepareExecutionPolicy");var Qt=o(()=>{(0,rt.registerTriggers)(),(0,ot.registerTriggers)(),(0,it.registerTriggers)(),
182
+ (0,at.tryCreateTrigger)("@ez4/aws-function",{"deploy:prepareIdentityAccount":Ye,
183
+ "deploy:prepareExecutionPolicy":nt}),He(),De(),Xe()},"registerTriggers");var X=require("@ez4/utils"),st=require("@ez4/stateful");var _t=o((t,e,n,r)=>{let i=(0,X.toKebabCase)(r.functionName),a=(0,X.hashData)(x,
184
+ e.entryId,i),s=[e.entryId];return n&&s.push(n.entryId),(0,st.attachEntry)(t,{type:x,
185
+ entryId:a,dependencies:s,parameters:{...r,functionName:i}})},"createFunction");var ct=require("@ez4/stateful"),le=require("@ez4/utils");var pt=o(t=>t.type===h,"isPermissionState");var Jt=o((t,e,n,r)=>{let i=(0,le.hashData)(h,e.entryId,n.entryId);return(0,ct.attachEntry)(
186
+ t,{type:h,entryId:i,dependencies:[e.entryId,n.entryId],parameters:r})},"createPe\
187
+ rmission"),Kt=o((t,e,n)=>{let r=(0,le.hashData)(h,e.entryId,n.entryId),i=t[r];return i&&
188
+ pt(i)?i:null},"getPermission");var ut=require("@ez4/utils"),mt=require("@ez4/stateful");var Xt=o((t,e,n,r)=>{let i=(0,ut.hashData)(R,e.entryId,n.entryId);return(0,mt.attachEntry)(
180
189
  t,{type:R,entryId:i,dependencies:[e.entryId,n.entryId],parameters:r})},"createMa\
181
- pping");var Jt=o(t=>t.type===R,"isMappingState");var Kt=o((t,e,n)=>`arn:aws:lambda:${t}:${e}:function:${n}`,"buildFunctionArn");var Z=require("@ez4/project"),pt;(a=>(a.LogRetention=90,a.Architecture=Z.ArchitectureType.
182
- x86,a.Runtime=Z.RuntimeType.Node24,a.Timeout=90,a.Memory=192))(pt||={});0&&(module.exports={FunctionArchitecture,FunctionDefaults,FunctionRuntime,FunctionServiceName,
190
+ pping");var Yt=o(t=>t.type===R,"isMappingState");var en=o((t,e,n)=>`arn:aws:lambda:${t}:${e}:function:${n}`,"buildFunctionArn");0&&(module.exports={FunctionArchitecture,FunctionDefaults,FunctionRuntime,FunctionServiceName,
183
191
  FunctionServiceType,MappingService,MappingServiceName,MappingServiceType,PermissionServiceName,
184
192
  PermissionServiceType,buildFunctionArn,createFunction,createMapping,createPermission,
185
193
  getDefaultVpcConfig,getFunctionArchitecture,getFunctionArn,getFunctionName,getFunctionRuntime,
package/dist/main.mjs CHANGED
@@ -1,171 +1,175 @@
1
- var Ve=Object.defineProperty;var o=(t,e)=>Ve(t,"name",{value:e,configurable:!0});import{registerTriggers as sn}from"@ez4/aws-common";import{registerTriggers as pn}from"@ez4/aws-identity";
2
- import{registerTriggers as cn}from"@ez4/aws-logs";import{tryCreateTrigger as un}from"@ez4/project/library";import{tryRegisterProvider as bt}from"@ez4/aws-common";import{applyTagUpdates as pt,CorruptedResourceError as ct,getBundleHash as G,OperationLogger as z,
3
- ReplaceResourceError as ut}from"@ez4/aws-common";import{deepCompare as mt,deepEqual as lt,
4
- hashFile as se}from"@ez4/utils";import{getLogGroupName as pe}from"@ez4/aws-logs";
5
- import{getRoleArn as ce}from"@ez4/aws-identity";import{GetFunctionCommand as Xe,CreateFunctionCommand as Ye,DeleteFunctionCommand as et,
6
- UpdateFunctionCodeCommand as tt,UpdateFunctionConfigurationCommand as nt,PublishVersionCommand as tr,
7
- TagResourceCommand as rt,UntagResourceCommand as ot,waitUntilFunctionActive as it,
8
- waitUntilFunctionUpdated as J,waitUntilPublishedVersionActive as K,ResourceNotFoundException as X,
9
- ApplicationLogLevel as N,SystemLogLevel as Y,LogFormat as ee}from"@aws-sdk/client-lambda";
10
- import{waitCreation as at,waitDeletion as st}from"@ez4/aws-common";import{getAwsClientOptions as He,getAwsClientWaiter as Oe}from"@ez4/aws-common";
11
- import{LambdaClient as Ue}from"@aws-sdk/client-lambda";var g=o(()=>new Ue(He()),"getLambdaClient"),A=o(t=>({...Oe(),client:t}),"getLamb\
12
- daWaiter");import{RuntimeType as $}from"@ez4/project";var Ge=(n=>(n.Node22="nodejs22.x",n.Node24="nodejs24.x",n))(Ge||{});var ze={[$.Node22]:"nodejs22.x",[$.Node24]:"nodejs24.x"},E=o(t=>ze[t],"getFuncti\
13
- onRuntime");import{ArchitectureType as j}from"@ez4/project";var De=(n=>(n.Arm="arm64",n.x86="x86_64",n))(De||{});var ke={[j.Arm]:"arm64",[j.x86]:"x86_64"},M=o(t=>ke[t],"getFunctionArchitecture");import{InvalidParameterError as qe}from"@ez4/aws-common";import{hashData as Be}from"@ez4/utils";var f="AWS:Lambda/Function",S="aws:lambda.function";var We=/[a-z][\w]+/i,$e=o(t=>We.test(t),"isValidName"),T=o(t=>{for(let e in t)if(!$e(
14
- e))throw new qe(f,`${e} is an invalid variable name .`)},"assertVariables"),v=o(
15
- t=>{let e={};for(let n in t)e[n]=Be(t[n]);return e},"protectVariables");import je from"adm-zip";import{readFile as Ze}from"node:fs/promises";var Z=o(async(t,e)=>{let n=new je,r=await Ze(t);return n.addFile(e,r),n.toBufferPromise()},
16
- "getZipBuffer");import{getDefaultSecurityGroupId as Qe,getDefaultSubnetIds as _e,getDefaultVpcId as Je}from"@ez4/aws-vpc";
17
- import{IncompleteResourceError as Q}from"@ez4/aws-common";var L=class extends Error{static{o(this,"FunctionNotFoundError")}constructor(e){
18
- super(`Function ${e} wasn't found.`)}},R=class extends Error{static{o(this,"Defa\
19
- ultVpcDetailsError")}constructor(){super("Unable to get the default VPC details.")}};var _=o(t=>t.type===S,"isFunctionState"),_n=o((t,e,n)=>{try{let r=t.getServiceState(
20
- e,n);if(_(r))return r}catch{}},"tryGetFunctionState"),Jn=o((t,e,n)=>{let r=t.getServiceState(
21
- e,n);if(!_(r))throw new L(e);return r},"getFunctionState"),h=o((t,e,n)=>{let r=n.
22
- getDependencies(S).at(0)?.parameters;if(!r?.functionName)throw new Q(t,e,"functi\
23
- onName");return r.functionName},"getFunctionName"),Ke=o(t=>t.getDependencies(S)[0]?.
24
- result?.functionArn,"tryGetFunctionArn"),Kn=o((t,e,n)=>{let r=Ke(n);if(!r)throw new Q(
25
- t,e,"functionArn");return r},"getFunctionArn"),V=o(async()=>{let t=await Je();if(!t)
26
- throw new R;let[e,n]=await Promise.all([_e(t),Qe(t)]);if(!e?.length||!n)throw new R;
27
- return{subnetIds:e.slice(0,2),securityGroupId:n}},"getDefaultVpcConfig");var te=o(async(t,e,n)=>{t.update("Importing function");try{let r=await g().send(
28
- new Xe({FunctionName:e,Qualifier:n})),i=r.Configuration.Version,a=r.Configuration.
29
- FunctionArn;return{functionVersion:i,functionArn:a}}catch(r){if(!(r instanceof X))
30
- throw r;return}},"importFunction"),ne=o(async(t,e)=>{t.update("Creating function");
31
- let{functionName:n,variables:r}=e;r&&T(r);let i=e.vpc?await V():void 0,a=ae(e.handlerName),
32
- s=await ie(e.sourceFile),{description:p,memory:m,timeout:c,publish:u,architecture:l,
33
- runtime:d,debug:y,roleArn:b,logGroup:I}=e,P=g(),q=await at(()=>P.send(new Ye({FunctionName:n,
34
- Description:p,MemorySize:m,Timeout:c,Role:b,Publish:u,Handler:a,Architectures:[M(
35
- l)],Runtime:E(d),PackageType:"Zip",VpcConfig:{SecurityGroupIds:i?[i.securityGroupId]:
36
- [],SubnetIds:i?i.subnetIds:[]},LoggingConfig:{LogGroup:I,ApplicationLogLevel:y?N.
37
- Debug:N.Warn,SystemLogLevel:Y.Warn,LogFormat:ee.Json},Code:{ZipFile:s},Environment:{
38
- Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}}))),Te=q.FunctionArn,B=q.Version,W=A(
39
- P);return await it(W,{FunctionName:n}),u&&await K(W,{FunctionName:n,Qualifier:B}),
40
- {functionArn:Te,...u&&{functionVersion:B}}},"createFunction"),H=o(async(t,e,n)=>{
41
- t.update("Updating source code");let r=await ie(n.sourceFile),{publish:i,architecture:a}=n,
42
- s=g(),p=await s.send(new tt({Architectures:a&&[M(a)],FunctionName:e,ZipFile:r,Publish:i})),
43
- m=p.FunctionArn,c=p.Version,u=A(s);return await J(u,{FunctionName:e}),i&&await K(
44
- u,{FunctionName:e,Qualifier:c}),{functionArn:m,...i&&{functionVersion:c}}},"upda\
45
- teSourceCode"),O=o(async(t,e,n)=>{t.update("Updating configuration");let{handlerName:r,
46
- variables:i}=n;i&&T(i);let a=n.vpc?await V():void 0,{description:s,memory:p,timeout:m,
47
- runtime:c,debug:u,roleArn:l,logGroup:d}=n,y=g();await y.send(new nt({Runtime:c&&
48
- E(c),FunctionName:e,Description:s,MemorySize:p,Timeout:m,Role:l,...r&&{Handler:ae(
1
+ var Ue=Object.defineProperty;var o=(n,e)=>Ue(n,"name",{value:e,configurable:!0});import{registerTriggers as dn}from"@ez4/aws-common";import{registerTriggers as fn}from"@ez4/aws-identity";
2
+ import{registerTriggers as yn}from"@ez4/aws-logs";import{tryCreateTrigger as Sn}from"@ez4/project/library";import{tryRegisterProvider as At}from"@ez4/aws-common";import{applyTagUpdates as ft,CorruptedResourceError as yt,getBundleHash as R,OperationLogger as q,
3
+ ReplaceResourceError as St}from"@ez4/aws-common";import{deepCompare as wt,deepEqual as Ft,
4
+ hashFile as ue}from"@ez4/utils";import{getLogGroupName as me}from"@ez4/aws-logs";
5
+ import{getRoleArn as le}from"@ez4/aws-identity";import{GetFunctionCommand as it,CreateFunctionCommand as at,DeleteFunctionCommand as st,
6
+ UpdateFunctionCodeCommand as pt,UpdateFunctionConfigurationCommand as ct,PublishVersionCommand as mr,
7
+ TagResourceCommand as ut,UntagResourceCommand as mt,waitUntilFunctionActive as lt,
8
+ waitUntilFunctionUpdated as Y,waitUntilPublishedVersionActive as ee,ResourceNotFoundException as te,
9
+ SystemLogLevel as ne,LogFormat as re}from"@aws-sdk/client-lambda";import{waitCreation as gt,
10
+ waitDeletion as dt}from"@ez4/aws-common";import{getAwsClientOptions as ze,getAwsClientWaiter as Ge}from"@ez4/aws-common";
11
+ import{LambdaClient as De}from"@aws-sdk/client-lambda";var g=o(()=>new De(ze()),"getLambdaClient"),N=o(n=>({...Ge(),client:n}),"getLamb\
12
+ daWaiter");import{ArchitectureType as Q}from"@ez4/project";var ke=(t=>(t.Arm="arm64",t.x86="x86_64",t))(ke||{});var qe={[Q.Arm]:"arm64",[Q.x86]:"x86_64"},H=o(n=>qe[n],"getFunctionArchitecture");import{RuntimeType as _}from"@ez4/project";var Be=(t=>(t.Node22="nodejs22.x",t.Node24="nodejs24.x",t))(Be||{});var We={[_.Node22]:"nodejs22.x",[_.Node24]:"nodejs24.x"},V=o(n=>We[n],"getFuncti\
13
+ onRuntime");import{ArchitectureType as je,RuntimeType as $e,LogLevel as Ze}from"@ez4/project";
14
+ var I;(s=>(s.LogRetention=90,s.LogLevel=Ze.Warning,s.Architecture=je.x86,s.Runtime=
15
+ $e.Node24,s.Timeout=90,s.Memory=192))(I||={});import{InvalidParameterError as Qe}from"@ez4/aws-common";import{hashData as _e}from"@ez4/utils";var y="AWS:Lambda/Function",w="aws:lambda.function";var Je=/[a-z][\w]+/i,Ke=o(n=>Je.test(n),"isValidName"),O=o(n=>{for(let e in n)if(!Ke(
16
+ e))throw new Qe(y,`${e} is an invalid variable name .`)},"assertVariables"),b=o(
17
+ n=>{let e={};for(let t in n)e[t]=_e(n[t]);return e},"protectVariables");import{ApplicationLogLevel as E}from"@aws-sdk/client-lambda";import{LogLevel as M}from"@ez4/project";var U=o(n=>{switch(n){case M.Information:return E.Info;case M.Debug:return E.Debug;case M.
18
+ Error:return E.Error;default:case M.Warning:return E.Warn}},"getLogLevel");import{dirname as Xe,normalize as Ye}from"node:path";import et from"adm-zip";var J=o(async(n,e,t)=>{let r=new et;return t?.forEach(i=>{r.addLocalFile(i,Xe(Ye(
19
+ i)))}),r.addLocalFile(n,void 0,e),r.toBufferPromise()},"getZipBuffer");import{getDefaultSecurityGroupId as tt,getDefaultSubnetIds as nt,getDefaultVpcId as rt}from"@ez4/aws-vpc";
20
+ import{IncompleteResourceError as K}from"@ez4/aws-common";var T=class extends Error{static{o(this,"FunctionNotFoundError")}constructor(e){
21
+ super(`Function ${e} wasn't found.`)}},L=class extends Error{static{o(this,"Defa\
22
+ ultVpcDetailsError")}constructor(){super("Unable to get the default VPC details.")}};var X=o(n=>n.type===w,"isFunctionState"),ir=o((n,e,t)=>{try{let r=n.getServiceState(
23
+ e,t);if(X(r))return r}catch{}},"tryGetFunctionState"),ar=o((n,e,t)=>{let r=n.getServiceState(
24
+ e,t);if(!X(r))throw new T(e);return r},"getFunctionState"),C=o((n,e,t)=>{let r=t.
25
+ getDependencies(w).at(0)?.parameters;if(!r?.functionName)throw new K(n,e,"functi\
26
+ onName");return r.functionName},"getFunctionName"),ot=o(n=>n.getDependencies(w)[0]?.
27
+ result?.functionArn,"tryGetFunctionArn"),sr=o((n,e,t)=>{let r=ot(t);if(!r)throw new K(
28
+ n,e,"functionArn");return r},"getFunctionArn"),z=o(async()=>{let n=await rt();if(!n)
29
+ throw new L;let[e,t]=await Promise.all([nt(n),tt(n)]);if(!e?.length||!t)throw new L;
30
+ return{subnetIds:e.slice(0,2),securityGroupId:t}},"getDefaultVpcConfig");var oe=o(async(n,e,t)=>{n.update("Importing function");try{let r=await g().send(
31
+ new it({FunctionName:e,Qualifier:t})),i=r.Configuration.Version,a=r.Configuration.
32
+ FunctionArn;return{functionVersion:i,functionArn:a}}catch(r){if(!(r instanceof te))
33
+ throw r;return}},"importFunction"),ie=o(async(n,e)=>{n.update("Creating function");
34
+ let{functionName:t,variables:r}=e;r&&O(r);let i=e.vpc?await z():void 0,a=await pe(
35
+ e.sourceFile,e.files),s=ce(e.handlerName),{description:p,memory:m,timeout:u,publish:c,
36
+ architecture:l,runtime:f,roleArn:d,logGroup:S,logLevel:h}=e,A=g(),j=await gt(()=>A.
37
+ send(new at({FunctionName:t,Description:p,MemorySize:m,Timeout:u,Role:d,Publish:c,
38
+ Handler:s,Architectures:[H(l)],Runtime:V(f),PackageType:"Zip",VpcConfig:{SecurityGroupIds:i?
39
+ [i.securityGroupId]:[],SubnetIds:i?i.subnetIds:[]},LoggingConfig:{LogGroup:S,ApplicationLogLevel:U(
40
+ h??I.LogLevel),SystemLogLevel:ne.Warn,LogFormat:re.Json},Code:{ZipFile:a},Environment:{
41
+ Variables:r},Tags:{...e.tags,ManagedBy:"EZ4"}}))),Oe=j.FunctionArn,$=j.Version,Z=N(
42
+ A);return await lt(Z,{FunctionName:t}),c&&await ee(Z,{FunctionName:t,Qualifier:$}),
43
+ {functionArn:Oe,...c&&{functionVersion:$}}},"createFunction"),G=o(async(n,e,t)=>{
44
+ n.update("Updating source code");let r=await pe(t.sourceFile,t.files),{publish:i,
45
+ architecture:a}=t,s=g(),p=await s.send(new pt({Architectures:a&&[H(a)],FunctionName:e,
46
+ ZipFile:r,Publish:i})),m=p.FunctionArn,u=p.Version,c=N(s);return await Y(c,{FunctionName:e}),
47
+ i&&await ee(c,{FunctionName:e,Qualifier:u}),{functionArn:m,...i&&{functionVersion:u}}},
48
+ "updateSourceCode"),D=o(async(n,e,t)=>{n.update("Updating configuration");let{handlerName:r,
49
+ variables:i}=t;i&&O(i);let a=t.vpc?await z():void 0,{description:s,memory:p,timeout:m,
50
+ runtime:u,roleArn:c,logGroup:l,logLevel:f}=t,d=g();await d.send(new ct({Runtime:u&&
51
+ V(u),FunctionName:e,Description:s,MemorySize:p,Timeout:m,Role:c,...r&&{Handler:ce(
49
52
  r)},VpcConfig:{SecurityGroupIds:a?[a.securityGroupId]:[],SubnetIds:a?a.subnetIds:
50
- []},LoggingConfig:{LogGroup:d,ApplicationLogLevel:u?N.Debug:N.Warn,SystemLogLevel:Y.
51
- Warn,LogFormat:ee.Json},Environment:{Variables:i}})),await J(A(y),{FunctionName:e})},
52
- "updateConfiguration"),re=o(async(t,e)=>{e.update("Deleting function");let n=g();
53
- await st(async()=>{try{await n.send(new et({FunctionName:t}))}catch(r){if(!(r instanceof
54
- X))throw r}})},"deleteFunction");var U=o(async(t,e,n)=>{t.update("Tag function"),await g().send(new rt({Resource:e,
55
- Tags:{...n,ManagedBy:"EZ4"}}))},"tagFunction"),oe=o(async(t,e,n)=>{t.update("Unt\
56
- ag function"),await g().send(new ot({Resource:e,TagKeys:n}))},"untagFunction"),ie=o(
57
- t=>Z(t,"main.mjs"),"getSourceZipFile"),ae=o(t=>`main.${t}`,"getSourceHandlerName");var ue=o(()=>({equals:gt,create:me,replace:ft,preview:dt,update:yt,delete:St}),"\
58
- getFunctionHandler"),gt=o((t,e)=>!!t.result&&t.result.functionArn===e.result?.functionArn,
59
- "equalsResource"),dt=o(async(t,e)=>{let n=t.parameters,r=e.parameters,i=mt({...n,
60
- connections:t.connections,dependencies:t.dependencies,variables:v(await n.getFunctionVariables()),
61
- sourceHash:await G(...n.getFunctionFiles()),valuesHash:n.getFunctionHash()},{...r,
62
- connections:e.connections,dependencies:e.dependencies,variables:e.result?.variables,
63
- sourceHash:e.result?.sourceHash,valuesHash:e.result?.valuesHash},{exclude:{release:!0}});
64
- if(i.counts)return{...i,name:n.functionName}},"previewResource"),ft=o(async(t,e,n)=>{
65
- if(e.result)throw new ut(f,t.entryId,e.entryId);return me(t,n)},"replaceResource"),
66
- me=o((t,e)=>{let{functionName:n,release:r,...i}=t.parameters;return z.logExecution(
67
- f,n,"creation",async a=>{let s=pe(f,n,e),p=ce(f,n,e),[m,c,u,l]=await Promise.all(
68
- [G(...i.getFunctionFiles()),i.getFunctionBundle(e),i.getFunctionHash(),i.getFunctionVariables()]),
69
- d=await te(a,n),y=await se(c);if(d)return await H(a,n,{architecture:i.architecture,
70
- publish:!1,sourceFile:c}),await O(a,n,{...i,logGroup:s,roleArn:p,variables:{...l,
71
- ...r?.variableName&&{[r.variableName]:r.version}}}),await U(a,d.functionArn,{...i.
72
- tags,...r?.tagName&&{[r.tagName]:r.version}}),{functionArn:d.functionArn,functionVersion:d.
73
- functionVersion,variables:v(l),valuesHash:u,sourceHash:m,bundleHash:y,logGroup:s,
74
- roleArn:p};let b=await ne(a,{...i,publish:!0,functionName:n,sourceFile:c,logGroup:s,
75
- roleArn:p,variables:{...l,...r?.variableName&&{[r.variableName]:r.version}},tags:{
76
- ...i.tags,...r?.tagName&&{[r.tagName]:r.version}}});return{functionArn:b.functionArn,
77
- functionVersion:b.functionVersion,variables:v(l),valuesHash:u,sourceHash:m,bundleHash:y,
78
- logGroup:s,roleArn:p}})},"createResource"),yt=o((t,e,n)=>{let{parameters:r,result:i}=t,
79
- {functionName:a}=r;if(!i)throw new ct(f,a);return z.logExecution(f,a,"updates",async s=>{
80
- let p=await r.getFunctionVariables(),m=e.result?.variables??p,c=ce(f,a,n),u=e.result?.
81
- roleArn??c,l=pe(f,a,n),d=e.result?.logGroup??l,{isUpdated:y,...b}=await xt(s,a,r,
82
- e.result,n),I={...r,variables:p,roleArn:c,logGroup:l},P={...e.parameters,variables:m,
83
- roleArn:u,logGroup:d};return await wt(s,a,I,P,y,n),await Ft(s,i.functionArn,r,e.
84
- parameters,y),{...i,...b,variables:v(p),logGroup:l,roleArn:c}})},"updateResource"),
85
- St=o(async t=>{let{result:e,parameters:n}=t;if(!e)return;let{functionName:r}=n;await z.
86
- logExecution(f,r,"deletion",async i=>{await re(r,i)})},"deleteResource"),wt=o(async(t,e,n,r,i,a)=>{
87
- let{variables:s,...p}=n,m={variables:v(s),...p},c=!lt(m,r,{exclude:{sourceFile:!0,
88
- functionName:!0,architecture:!0,release:!0,tags:!0}}),u=i?n.release:r.release,l=i&&
89
- u?.variableName;(c||l||a.force)&&await O(t,e,{...n,variables:{...n.variables,...u?.
90
- variableName&&{[u.variableName]:u.version}}})},"checkConfigurationUpdates"),Ft=o(
91
- async(t,e,n,r,i)=>{let s=i&&n.release?.version!==r.release?.version?n.release:void 0,
92
- p={...n.tags,...s?.tagName&&{[s.tagName]:s.version}};await pt(p,r.tags,m=>U(t,e,
93
- m),m=>oe(t,e,m))},"checkTagUpdates"),xt=o(async(t,e,n,r,i)=>{let[a,s]=await Promise.
94
- all([G(...n.getFunctionFiles()),n.getFunctionHash()]),p=r?.sourceHash,m=r?.valuesHash;
95
- if(a!==p||s!==m||i.force){let c=await n.getFunctionBundle(i),u=await se(c),l=r?.
96
- bundleHash;if(u===l&&s===m)return t.update("Skipping source code update"),{isUpdated:!1,
97
- valuesHash:s,sourceHash:a};let{functionVersion:d}=await H(t,e,{architecture:n.architecture,
98
- publish:!r?.functionVersion,sourceFile:c});return{isUpdated:!0,valuesHash:s,sourceHash:a,
99
- bundleHash:u,...d&&{functionVersion:d}}}return{isUpdated:!1}},"checkSourceCodeUp\
100
- dates");var le=o(()=>{bt(S,ue())},"registerFunctionProvider");import{tryRegisterProvider as Et}from"@ez4/aws-common";import{OperationLogger as fe,ReplaceResourceError as Ct}from"@ez4/aws-common";import{AddPermissionCommand as vt,RemovePermissionCommand as Rt,ResourceNotFoundException as ht}from"@aws-sdk/client-lambda";var ge=o(async(t,e)=>{t.update("Creating permission");let n=e.statementId??`ID${Date.
101
- now()}`;return await g().send(new vt({StatementId:n,FunctionName:e.functionName,
102
- SourceArn:e.sourceArn,Principal:e.principal,Action:e.action})),{statementId:n}},
103
- "createPermission"),de=o(async(t,e,n)=>{t.update("Deleting permission");try{return await g().
104
- send(new Rt({FunctionName:e,StatementId:n})),!0}catch(r){if(!(r instanceof ht))throw r;
105
- return!1}},"deletePermission");var C="AWS:Lambda/Permission",w="aws:lambda.permission";var ye=o(()=>({equals:Pt,create:Se,replace:Lt,preview:At,update:Nt,delete:It}),"\
106
- getPermissionHandler"),Pt=o((t,e)=>!!t.result&&t.result.functionName===e.result?.
107
- functionName,"equalsResource"),At=o((t,e)=>{},"previewResource"),Lt=o(async(t,e,n)=>{
108
- if(e.result)throw new Ct(C,t.entryId,e.entryId);return Se(t,n)},"replaceResource"),
109
- Se=o((t,e)=>{let n=t.parameters,r=h(C,"permission",e);return fe.logExecution(C,r,
110
- "creation",async i=>{let a=await n.getPermission(e);return{statementId:(await ge(
53
+ []},LoggingConfig:{LogGroup:l,ApplicationLogLevel:U(f??I.LogLevel),SystemLogLevel:ne.
54
+ Warn,LogFormat:re.Json},Environment:{Variables:i}})),await Y(N(d),{FunctionName:e})},
55
+ "updateConfiguration"),ae=o(async(n,e)=>{e.update("Deleting function");let t=g();
56
+ await dt(async()=>{try{await t.send(new st({FunctionName:n}))}catch(r){if(!(r instanceof
57
+ te))throw r}})},"deleteFunction");var k=o(async(n,e,t)=>{n.update("Tag function"),await g().send(new ut({Resource:e,
58
+ Tags:{...t,ManagedBy:"EZ4"}}))},"tagFunction"),se=o(async(n,e,t)=>{n.update("Unt\
59
+ ag function"),await g().send(new mt({Resource:e,TagKeys:t}))},"untagFunction"),pe=o(
60
+ (n,e)=>J(n,"main.mjs",e),"getSourceZipFile"),ce=o(n=>`main.${n}`,"getSourceHandl\
61
+ erName");var ge=o(()=>({equals:xt,create:de,replace:ht,preview:vt,update:bt,delete:Rt}),"\
62
+ getFunctionHandler"),xt=o((n,e)=>!!n.result&&n.result.functionArn===e.result?.functionArn,
63
+ "equalsResource"),vt=o(async(n,e)=>{let t=n.parameters,r=e.parameters,i=wt({...t,
64
+ connections:n.connections,dependencies:n.dependencies,variables:b(await t.getFunctionVariables()),
65
+ filesHash:t.files&&await R(t.functionName,t.files),sourceHash:await R(...t.getFunctionFiles()),
66
+ valuesHash:t.getFunctionHash()},{...r,connections:e.connections,dependencies:e.dependencies,
67
+ variables:e.result?.variables,sourceHash:e.result?.sourceHash,valuesHash:e.result?.
68
+ valuesHash,filesHash:e.result?.filesHash},{exclude:{release:!0}});if(i.counts)return{
69
+ ...i,name:t.functionName}},"previewResource"),ht=o(async(n,e,t)=>{if(e.result)throw new St(
70
+ y,n.entryId,e.entryId);return de(n,t)},"replaceResource"),de=o((n,e)=>{let{functionName:t,
71
+ release:r,...i}=n.parameters;return q.logExecution(y,t,"creation",async a=>{let s=me(
72
+ y,t,e),p=le(y,t,e),[m,u,c,l,f]=await Promise.all([R(...i.getFunctionFiles()),i.files&&
73
+ R(t,i.files),i.getFunctionBundle(e),i.getFunctionHash(),i.getFunctionVariables()]),
74
+ d=await oe(a,t),S=await ue(c);if(d)return await G(a,t,{architecture:i.architecture,
75
+ files:i.files,publish:!1,sourceFile:c}),await D(a,t,{...i,logGroup:s,roleArn:p,variables:{
76
+ ...f,...r?.variableName&&{[r.variableName]:r.version}}}),await k(a,d.functionArn,
77
+ {...i.tags,...r?.tagName&&{[r.tagName]:r.version}}),{functionArn:d.functionArn,functionVersion:d.
78
+ functionVersion,variables:b(f),sourceHash:m,valuesHash:l,bundleHash:S,filesHash:u,
79
+ logGroup:s,roleArn:p};let h=await ie(a,{...i,publish:!0,functionName:t,sourceFile:c,
80
+ logGroup:s,roleArn:p,variables:{...f,...r?.variableName&&{[r.variableName]:r.version}},
81
+ tags:{...i.tags,...r?.tagName&&{[r.tagName]:r.version}}});return{functionArn:h.functionArn,
82
+ functionVersion:h.functionVersion,variables:b(f),sourceHash:m,valuesHash:l,bundleHash:S,
83
+ filesHash:u,logGroup:s,roleArn:p}})},"createResource"),bt=o((n,e,t)=>{let{parameters:r,
84
+ result:i}=n,{functionName:a}=r;if(!i)throw new yt(y,a);return q.logExecution(y,a,
85
+ "updates",async s=>{let p=await r.getFunctionVariables(),m=e.result?.variables??
86
+ p,u=le(y,a,t),c=e.result?.roleArn??u,l=me(y,a,t),f=e.result?.logGroup??l,{isUpdated:d,
87
+ ...S}=await Pt(s,a,r,e.result,t),h={...r,variables:p,roleArn:u,logGroup:l},A={...e.
88
+ parameters,variables:m,roleArn:c,logGroup:f};return await Lt(s,a,h,A,d,t),await Ct(
89
+ s,i.functionArn,r,e.parameters,d),{...i,...S,variables:b(p),logGroup:l,roleArn:u}})},
90
+ "updateResource"),Rt=o(async n=>{let{result:e,parameters:t}=n;if(!e)return;let{functionName:r}=t;
91
+ await q.logExecution(y,r,"deletion",async i=>{await ae(r,i)})},"deleteResource"),
92
+ Lt=o(async(n,e,t,r,i,a)=>{let{variables:s,...p}=t,m={variables:b(s),...p},u=!Ft(
93
+ m,r,{exclude:{sourceFile:!0,functionName:!0,architecture:!0,release:!0,tags:!0}}),
94
+ c=i?t.release:r.release,l=i&&c?.variableName;(u||l||a.force)&&await D(n,e,{...t,
95
+ variables:{...t.variables,...c?.variableName&&{[c.variableName]:c.version}}})},"\
96
+ checkConfigurationUpdates"),Ct=o(async(n,e,t,r,i)=>{let s=i&&t.release?.version!==
97
+ r.release?.version?t.release:void 0,p={...t.tags,...s?.tagName&&{[s.tagName]:s.version}};
98
+ await ft(p,r.tags,m=>k(n,e,m),m=>se(n,e,m))},"checkTagUpdates"),Pt=o(async(n,e,t,r,i)=>{
99
+ let[a,s,p]=await Promise.all([R(...t.getFunctionFiles()),t.files&&R(e,t.files),t.
100
+ getFunctionHash()]),m=r?.sourceHash,u=r?.valuesHash,c=r?.filesHash;if(a!==m||p!==
101
+ u||s!==c||i.force){let l=await t.getFunctionBundle(i),f=await ue(l),d=r?.bundleHash;
102
+ if(f===d&&s===c&&p===u)return n.update("Skipping source code update"),{isUpdated:!1,
103
+ sourceHash:a};let{functionVersion:S}=await G(n,e,{architecture:t.architecture,publish:!r?.
104
+ functionVersion,sourceFile:l,files:t.files});return{isUpdated:!0,valuesHash:p,sourceHash:a,
105
+ bundleHash:f,filesHash:s,...S&&{functionVersion:S}}}return{isUpdated:!1}},"check\
106
+ SourceCodeUpdates");var fe=o(()=>{At(w,ge())},"registerFunctionProvider");import{tryRegisterProvider as zt}from"@ez4/aws-common";import{OperationLogger as we,ReplaceResourceError as Mt}from"@ez4/aws-common";import{AddPermissionCommand as Nt,RemovePermissionCommand as It,ResourceNotFoundException as Et}from"@aws-sdk/client-lambda";var ye=o(async(n,e)=>{n.update("Creating permission");let t=e.statementId??`ID${Date.
107
+ now()}`;return await g().send(new Nt({StatementId:t,FunctionName:e.functionName,
108
+ SourceArn:e.sourceArn,Principal:e.principal,Action:e.action})),{statementId:t}},
109
+ "createPermission"),Se=o(async(n,e,t)=>{n.update("Deleting permission");try{return await g().
110
+ send(new It({FunctionName:e,StatementId:t})),!0}catch(r){if(!(r instanceof Et))throw r;
111
+ return!1}},"deletePermission");var P="AWS:Lambda/Permission",F="aws:lambda.permission";var Fe=o(()=>({equals:Tt,create:xe,replace:Vt,preview:Ht,update:Ot,delete:Ut}),"\
112
+ getPermissionHandler"),Tt=o((n,e)=>!!n.result&&n.result.functionName===e.result?.
113
+ functionName,"equalsResource"),Ht=o((n,e)=>{},"previewResource"),Vt=o(async(n,e,t)=>{
114
+ if(e.result)throw new Mt(P,n.entryId,e.entryId);return xe(n,t)},"replaceResource"),
115
+ xe=o((n,e)=>{let t=n.parameters,r=C(P,"permission",e);return we.logExecution(P,r,
116
+ "creation",async i=>{let a=await t.getPermission(e);return{statementId:(await ye(
111
117
  i,{action:"lambda:InvokeFunction",sourceArn:a.sourceArn,principal:a.principal,functionName:r})).
112
- statementId,functionName:r}})},"createResource"),Nt=o(async()=>{},"updateResourc\
113
- e"),It=o(async t=>{let e=t.result;if(!e)return;let{functionName:n,statementId:r}=e;
114
- await fe.logExecution(C,n,"deletion",async i=>{await de(i,n,r)})},"deleteResourc\
115
- e");var we=o(()=>{Et(w,ye())},"registerPermissionProvider");import{tryRegisterProvider as Yt}from"@ez4/aws-common";import{CorruptedResourceError as Bt,OperationLogger as k,ReplaceResourceError as Wt}from"@ez4/aws-common";
116
- import{deepCompare as $t,deepEqual as jt}from"@ez4/utils";import{CreateEventSourceMappingCommand as Ht,UpdateEventSourceMappingCommand as Ot,
117
- DeleteEventSourceMappingCommand as Ut,ListEventSourceMappingsCommand as Gt,FunctionResponseType as zt,
118
- EventSourcePosition as Dt,ResourceNotFoundException as kt}from"@aws-sdk/client-lambda";
119
- import{parseArn as qt}from"@ez4/aws-common";import{GetEventSourceMappingCommand as Mt}from"@aws-sdk/client-lambda";import{Wait as Fe}from"@ez4/utils";var D=o(async(t,e)=>{let n=new Set(["Enabled","Disabled"]);await Fe.until(async()=>{
120
- let r=await Tt(t,e);return n.has(r)?!0:Fe.RetryAttempt})},"waitForReadyState"),Tt=o(
121
- async(t,e)=>(await t.send(new Mt({UUID:e}))).State,"getMappingState");var F="AWS:Lambda/Mapping",x="aws:lambda.mapping",Vt=(n=>(n.DynamoDB="dynamodb",
122
- n.Queue="sqs",n))(Vt||{});var xe=o(async(t,e,n)=>{t.update("Importing mapping");let r=await g().send(new Gt(
123
- {FunctionName:e,EventSourceArn:n})),[i]=r.EventSourceMappings;return i?{eventId:i.
124
- UUID}:void 0},"importMapping"),be=o(async(t,e)=>{t.update("Creating mapping");let{
125
- sourceArn:n,functionName:r}=e,i=g(),s=(await i.send(new Ht({FunctionName:r,EventSourceArn:n,
126
- ...he(e)}))).UUID;return await D(i,s),{eventId:s}},"createMapping"),ve=o(async(t,e,n)=>{
127
- t.update("Updating mapping");let{functionName:r}=n,i=g();await i.send(new Ot({UUID:e,
128
- FunctionName:r,...he(n)})),await D(i,e)},"updateMapping"),Re=o(async(t,e)=>{t.update(
129
- "Deleting mapping");try{return await g().send(new Ut({UUID:e})),!0}catch(n){if(!(n instanceof
130
- kt))throw n;return!1}},"deleteMapping"),he=o(t=>{let{sourceArn:e,enabled:n,concurrency:r,
131
- batch:i}=t,{service:a}=qt(e);return{Enabled:n,FunctionResponseTypes:[zt.ReportBatchItemFailures],
118
+ statementId,functionName:r}})},"createResource"),Ot=o(async()=>{},"updateResourc\
119
+ e"),Ut=o(async n=>{let e=n.result;if(!e)return;let{functionName:t,statementId:r}=e;
120
+ await we.logExecution(P,t,"deletion",async i=>{await Se(i,t,r)})},"deleteResourc\
121
+ e");var ve=o(()=>{zt(F,Fe())},"registerPermissionProvider");import{tryRegisterProvider as sn}from"@ez4/aws-common";import{CorruptedResourceError as Jt,OperationLogger as W,ReplaceResourceError as Kt}from"@ez4/aws-common";
122
+ import{deepCompare as Xt,deepEqual as Yt}from"@ez4/utils";import{CreateEventSourceMappingCommand as qt,UpdateEventSourceMappingCommand as Bt,
123
+ DeleteEventSourceMappingCommand as Wt,ListEventSourceMappingsCommand as jt,FunctionResponseType as $t,
124
+ EventSourcePosition as Zt,ResourceNotFoundException as Qt}from"@aws-sdk/client-lambda";
125
+ import{parseArn as _t}from"@ez4/aws-common";import{GetEventSourceMappingCommand as Gt}from"@aws-sdk/client-lambda";import{Wait as he}from"@ez4/utils";var B=o(async(n,e)=>{let t=new Set(["Enabled","Disabled"]);await he.until(async()=>{
126
+ let r=await Dt(n,e);return t.has(r)?!0:he.RetryAttempt})},"waitForReadyState"),Dt=o(
127
+ async(n,e)=>(await n.send(new Gt({UUID:e}))).State,"getMappingState");var x="AWS:Lambda/Mapping",v="aws:lambda.mapping",kt=(t=>(t.DynamoDB="dynamodb",
128
+ t.Queue="sqs",t))(kt||{});var be=o(async(n,e,t)=>{n.update("Importing mapping");let r=await g().send(new jt(
129
+ {FunctionName:e,EventSourceArn:t})),[i]=r.EventSourceMappings;return i?{eventId:i.
130
+ UUID}:void 0},"importMapping"),Re=o(async(n,e)=>{n.update("Creating mapping");let{
131
+ sourceArn:t,functionName:r}=e,i=g(),s=(await i.send(new qt({FunctionName:r,EventSourceArn:t,
132
+ ...Pe(e)}))).UUID;return await B(i,s),{eventId:s}},"createMapping"),Le=o(async(n,e,t)=>{
133
+ n.update("Updating mapping");let{functionName:r}=t,i=g();await i.send(new Bt({UUID:e,
134
+ FunctionName:r,...Pe(t)})),await B(i,e)},"updateMapping"),Ce=o(async(n,e)=>{n.update(
135
+ "Deleting mapping");try{return await g().send(new Wt({UUID:e})),!0}catch(t){if(!(t instanceof
136
+ Qt))throw t;return!1}},"deleteMapping"),Pe=o(n=>{let{sourceArn:e,enabled:t,concurrency:r,
137
+ batch:i}=n,{service:a}=_t(e);return{Enabled:t,FunctionResponseTypes:[$t.ReportBatchItemFailures],
132
138
  MaximumBatchingWindowInSeconds:i?.maxWait,BatchSize:i?.size,...a==="dynamodb"&&{
133
- StartingPosition:Dt.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:r}}}},
134
- "upsertMappingRequest");var Ce=o(()=>({equals:Zt,create:Pe,replace:_t,preview:Qt,update:Jt,delete:Kt}),"\
135
- getMappingHandler"),Zt=o((t,e)=>!!t.result&&t.result.eventId===e.result?.eventId,
136
- "equalsResource"),Qt=o((t,e)=>{let n={...t.parameters,dependencies:t.dependencies},
137
- r={...e.parameters,dependencies:e.dependencies},i=$t(n,r,{exclude:{getSourceArn:!0}});
138
- if(i.counts)return{...i,name:n.fromService}},"previewResource"),_t=o(async(t,e,n)=>{
139
- if(e.result)throw new Wt(F,t.entryId,e.entryId);return Pe(t,n)},"replaceResource"),
140
- Pe=o((t,e)=>{let n=t.parameters,r=h(F,"mapping",e);return k.logExecution(F,r,"cr\
141
- eation",async i=>{let a=await n.getSourceArn(e);return{eventId:(await xe(i,r,a)??
142
- await be(i,{...t.parameters,functionName:r,sourceArn:a})).eventId,functionName:r,
143
- sourceArn:a}})},"createResource"),Jt=o((t,e,n)=>{let{result:r,parameters:i}=t,{fromService:a}=i;
144
- if(!r)throw new Bt(F,"mapping");return k.logExecution(F,a,"updates",async s=>{let p=h(
145
- F,"mapping",n),m=e.result?.functionName??r.functionName,c=r.sourceArn,u={...t.parameters,
146
- functionName:p,sourceArn:c},l={...e.parameters,functionName:m,sourceArn:c};return await Xt(
147
- s,r.eventId,u,l),{...r,functionName:p}})},"updateResource"),Kt=o(async t=>{let e=t.
148
- result;if(!e)return;let{functionName:n}=e;await k.logExecution(F,n,"deletion",async r=>{
149
- await Re(r,e.eventId)})},"deleteResource"),Xt=o(async(t,e,n,r)=>{!jt(n,r,{exclude:{
150
- getSourceArn:!0,fromService:!0}})&&await ve(t,e,n)},"checkGeneralUpdates");var Ae=o(()=>{Yt(x,Ce())},"registerMappingProvider");var Le=o(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");import{createPolicy as rn,tryGetPolicy as on}from"@ez4/aws-identity";import{getServiceName as an}from"@ez4/project/library";import{getAccountId as en,getRegion as tn,createPolicyDocument as nn}from"@ez4/aws-identity";var Ne=o(async t=>{let[e,n]=await Promise.all([tn(),en()]);return nn([{permissions:[
151
- "logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:logs:${e}:${n}\
152
- :log-group:${t}-*:*`]},{permissions:["ec2:CreateNetworkInterface","ec2:DescribeN\
139
+ StartingPosition:Zt.LATEST},...a==="sqs"&&{ScalingConfig:{MaximumConcurrency:r}}}},
140
+ "upsertMappingRequest");var Ae=o(()=>({equals:en,create:Ne,replace:nn,preview:tn,update:rn,delete:on}),"\
141
+ getMappingHandler"),en=o((n,e)=>!!n.result&&n.result.eventId===e.result?.eventId,
142
+ "equalsResource"),tn=o((n,e)=>{let t={...n.parameters,dependencies:n.dependencies},
143
+ r={...e.parameters,dependencies:e.dependencies},i=Xt(t,r,{exclude:{getSourceArn:!0}});
144
+ if(i.counts)return{...i,name:t.fromService}},"previewResource"),nn=o(async(n,e,t)=>{
145
+ if(e.result)throw new Kt(x,n.entryId,e.entryId);return Ne(n,t)},"replaceResource"),
146
+ Ne=o((n,e)=>{let t=n.parameters,r=C(x,"mapping",e);return W.logExecution(x,r,"cr\
147
+ eation",async i=>{let a=await t.getSourceArn(e);return{eventId:(await be(i,r,a)??
148
+ await Re(i,{...n.parameters,functionName:r,sourceArn:a})).eventId,functionName:r,
149
+ sourceArn:a}})},"createResource"),rn=o((n,e,t)=>{let{result:r,parameters:i}=n,{fromService:a}=i;
150
+ if(!r)throw new Jt(x,"mapping");return W.logExecution(x,a,"updates",async s=>{let p=C(
151
+ x,"mapping",t),m=e.result?.functionName??r.functionName,u=r.sourceArn,c={...n.parameters,
152
+ functionName:p,sourceArn:u},l={...e.parameters,functionName:m,sourceArn:u};return await an(
153
+ s,r.eventId,c,l),{...r,functionName:p}})},"updateResource"),on=o(async n=>{let e=n.
154
+ result;if(!e)return;let{functionName:t}=e;await W.logExecution(x,t,"deletion",async r=>{
155
+ await Ce(r,e.eventId)})},"deleteResource"),an=o(async(n,e,t,r)=>{!Yt(t,r,{exclude:{
156
+ getSourceArn:!0,fromService:!0}})&&await Le(n,e,t)},"checkGeneralUpdates");var Ie=o(()=>{sn(v,Ae())},"registerMappingProvider");var Ee=o(()=>[{account:"lambda.amazonaws.com"}],"prepareIdentityAccount");import{createPolicy as mn,tryGetPolicy as ln}from"@ez4/aws-identity";import{getServiceName as gn}from"@ez4/project/library";import{getAccountId as pn,getRegion as cn,createPolicyDocument as un}from"@ez4/aws-identity";var Me=o(async n=>{let[e,t]=await Promise.all([cn(),pn()]);return un([{permissions:[
157
+ "logs:CreateLogStream","logs:PutLogEvents"],resourceIds:[`arn:aws:logs:${e}:${t}\
158
+ :log-group:${n}-*:*`]},{permissions:["ec2:CreateNetworkInterface","ec2:DescribeN\
153
159
  etworkInterfaces","ec2:DeleteNetworkInterface"],resourceIds:["*"]}])},"getPolicy\
154
- Document");var Ie=o(async t=>{let{state:e,options:n}=t,r=an("",n),i=`${r}-lambda-policy`;return on(
155
- e,i)??rn(e,{tags:n.tags,policyDocument:await Ne(r),policyName:i})},"prepareExecu\
156
- tionPolicy");var Io=o(()=>{sn(),pn(),cn(),un("@ez4/aws-function",{"deploy:prepareIdentityAcco\
157
- unt":Le,"deploy:prepareExecutionPolicy":Ie}),le(),we(),Ae()},"registerTriggers");import{toKebabCase as mn,hashData as ln}from"@ez4/utils";import{attachEntry as gn}from"@ez4/stateful";var Oo=o((t,e,n,r)=>{let i=mn(r.functionName),a=ln(S,e.entryId,i),s=[e.entryId];
158
- return n&&s.push(n.entryId),gn(t,{type:S,entryId:a,dependencies:s,parameters:{...r,
159
- functionName:i}})},"createFunction");import{attachEntry as dn}from"@ez4/stateful";import{hashData as Me}from"@ez4/utils";var Ee=o(t=>t.type===w,"isPermissionState");var jo=o((t,e,n,r)=>{let i=Me(w,e.entryId,n.entryId);return dn(t,{type:w,entryId:i,
160
- dependencies:[e.entryId,n.entryId],parameters:r})},"createPermission"),Zo=o((t,e,n)=>{
161
- let r=Me(w,e.entryId,n.entryId),i=t[r];return i&&Ee(i)?i:null},"getPermission");import{hashData as fn}from"@ez4/utils";import{attachEntry as yn}from"@ez4/stateful";var Yo=o((t,e,n,r)=>{let i=fn(x,e.entryId,n.entryId);return yn(t,{type:x,entryId:i,
162
- dependencies:[e.entryId,n.entryId],parameters:r})},"createMapping");var ri=o(t=>t.type===x,"isMappingState");var ai=o((t,e,n)=>`arn:aws:lambda:${t}:${e}:function:${n}`,"buildFunctionArn");import{ArchitectureType as Sn,RuntimeType as wn}from"@ez4/project";var Fn;(a=>(a.
163
- LogRetention=90,a.Architecture=Sn.x86,a.Runtime=wn.Node24,a.Timeout=90,a.Memory=
164
- 192))(Fn||={});export{De as FunctionArchitecture,Fn as FunctionDefaults,Ge as FunctionRuntime,f as FunctionServiceName,
165
- S as FunctionServiceType,Vt as MappingService,F as MappingServiceName,x as MappingServiceType,
166
- C as PermissionServiceName,w as PermissionServiceType,ai as buildFunctionArn,Oo as createFunction,
167
- Yo as createMapping,jo as createPermission,V as getDefaultVpcConfig,M as getFunctionArchitecture,
168
- Kn as getFunctionArn,h as getFunctionName,E as getFunctionRuntime,Jn as getFunctionState,
169
- Zo as getPermission,_ as isFunctionState,ri as isMappingState,Io as registerTriggers,
170
- Ke as tryGetFunctionArn,_n as tryGetFunctionState};
160
+ Document");var Te=o(async n=>{let{state:e,options:t}=n,r=gn("",t),i=`${r}-lambda-policy`;return ln(
161
+ e,i)??mn(e,{tags:t.tags,policyDocument:await Me(r),policyName:i})},"prepareExecu\
162
+ tionPolicy");var qo=o(()=>{dn(),fn(),yn(),Sn("@ez4/aws-function",{"deploy:prepareIdentityAcco\
163
+ unt":Ee,"deploy:prepareExecutionPolicy":Te}),fe(),ve(),Ie()},"registerTriggers");import{toKebabCase as wn,hashData as Fn}from"@ez4/utils";import{attachEntry as xn}from"@ez4/stateful";var Qo=o((n,e,t,r)=>{let i=wn(r.functionName),a=Fn(w,e.entryId,i),s=[e.entryId];
164
+ return t&&s.push(t.entryId),xn(n,{type:w,entryId:a,dependencies:s,parameters:{...r,
165
+ functionName:i}})},"createFunction");import{attachEntry as vn}from"@ez4/stateful";import{hashData as Ve}from"@ez4/utils";var He=o(n=>n.type===F,"isPermissionState");var oi=o((n,e,t,r)=>{let i=Ve(F,e.entryId,t.entryId);return vn(n,{type:F,entryId:i,
166
+ dependencies:[e.entryId,t.entryId],parameters:r})},"createPermission"),ii=o((n,e,t)=>{
167
+ let r=Ve(F,e.entryId,t.entryId),i=n[r];return i&&He(i)?i:null},"getPermission");import{hashData as hn}from"@ez4/utils";import{attachEntry as bn}from"@ez4/stateful";var mi=o((n,e,t,r)=>{let i=hn(v,e.entryId,t.entryId);return bn(n,{type:v,entryId:i,
168
+ dependencies:[e.entryId,t.entryId],parameters:r})},"createMapping");var fi=o(n=>n.type===v,"isMappingState");var wi=o((n,e,t)=>`arn:aws:lambda:${n}:${e}:function:${t}`,"buildFunctionArn");export{ke as FunctionArchitecture,I as FunctionDefaults,Be as FunctionRuntime,y as FunctionServiceName,
169
+ w as FunctionServiceType,kt as MappingService,x as MappingServiceName,v as MappingServiceType,
170
+ P as PermissionServiceName,F as PermissionServiceType,wi as buildFunctionArn,Qo as createFunction,
171
+ mi as createMapping,oi as createPermission,z as getDefaultVpcConfig,H as getFunctionArchitecture,
172
+ sr as getFunctionArn,C as getFunctionName,V as getFunctionRuntime,ar as getFunctionState,
173
+ ii as getPermission,X as isFunctionState,fi as isMappingState,qo as registerTriggers,
174
+ ot as tryGetFunctionArn,ir as tryGetFunctionState};
171
175
  //# sourceMappingURL=main.mjs.map
@@ -1,9 +1,13 @@
1
- import { ArchitectureType, RuntimeType } from '@ez4/project';
1
+ import { ArchitectureType, RuntimeType, LogLevel as ProjectLogLevel } from '@ez4/project';
2
2
  export declare namespace FunctionDefaults {
3
3
  /**
4
4
  * Default log retention in days.
5
5
  */
6
6
  const LogRetention = 90;
7
+ /**
8
+ * Default function log level.
9
+ */
10
+ const LogLevel = ProjectLogLevel.Warning;
7
11
  /**
8
12
  * Default function architecture.
9
13
  */
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.42.0",
4
+ "version": "0.43.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -42,15 +42,15 @@
42
42
  "live:publish": "npm run build && npm publish --access public"
43
43
  },
44
44
  "dependencies": {
45
- "@aws-sdk/client-lambda": "^3.958.0",
46
- "@ez4/aws-common": "^0.42.0",
47
- "@ez4/aws-identity": "^0.42.0",
48
- "@ez4/aws-logs": "^0.42.0",
49
- "@ez4/aws-vpc": "^0.42.0",
50
- "@ez4/project": "^0.42.0",
51
- "@ez4/common": "^0.42.0",
52
- "@ez4/stateful": "^0.42.0",
53
- "@ez4/utils": "^0.42.0",
45
+ "@aws-sdk/client-lambda": "^3.996.0",
46
+ "@ez4/aws-common": "^0.43.0",
47
+ "@ez4/aws-identity": "^0.43.0",
48
+ "@ez4/aws-logs": "^0.43.0",
49
+ "@ez4/aws-vpc": "^0.43.0",
50
+ "@ez4/project": "^0.43.0",
51
+ "@ez4/common": "^0.43.0",
52
+ "@ez4/stateful": "^0.43.0",
53
+ "@ez4/utils": "^0.43.0",
54
54
  "@types/adm-zip": "^0.5.5",
55
55
  "adm-zip": "^0.5.14"
56
56
  }