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