@sdlcworks/components 0.0.27 → 0.0.29

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.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,14 @@
3
3
  import { Input as PulumiInput, Output as PulumiOutput } from '@pulumi/pulumi';
4
4
  import { z } from 'zod';
5
5
 
6
+ /**
7
+ * Types copied from @sdlc/types for use in the published @sdlcworks/components package.
8
+ * These are duplicated here to avoid requiring users to install @sdlc/types
9
+ * (which is an internal monorepo package not published to npm).
10
+ *
11
+ * ⚠️ SYNC REQUIRED: When modifying these types, also update @sdlc/types/src/index.ts
12
+ * and vice versa. These files must be kept in sync manually.
13
+ */
6
14
  export declare enum CloudProvider {
7
15
  aws = "aws",
8
16
  gcloud = "gcloud",
@@ -11,14 +19,53 @@ export declare enum CloudProvider {
11
19
  hetzner = "hetzner",
12
20
  cloudflare = "cloudflare"
13
21
  }
22
+ export declare enum DeploymentArtifactType {
23
+ container_image = "container_image"
24
+ }
25
+ /**
26
+ * GCP credential fields required for authentication.
27
+ */
28
+ export type BranchMetadataCloudCredentialGCP = {
29
+ GCP_PROJECT_ID: string;
30
+ GCP_SERVICE_ACCOUNT_KEY: string;
31
+ };
32
+ /**
33
+ * AWS credential fields required for authentication.
34
+ */
35
+ export type BranchMetadataCloudCredentialAWS = {
36
+ AWS_ACCESS_KEY_ID: string;
37
+ AWS_SECRET_ACCESS_KEY: string;
38
+ AWS_REGION: string;
39
+ };
40
+ /**
41
+ * Cloudflare credential fields required for authentication.
42
+ */
43
+ export type BranchMetadataCloudCredentialCloudflare = {
44
+ CLOUDFLARE_API_TOKEN: string;
45
+ CLOUDFLARE_ACCOUNT_ID?: string;
46
+ };
47
+ /**
48
+ * Maps each CloudProvider to its corresponding credential type.
49
+ * Used to provide fully-typed credentials in handler contexts.
50
+ */
51
+ export type ProviderCredentialsMap = {
52
+ [CloudProvider.gcloud]: BranchMetadataCloudCredentialGCP;
53
+ [CloudProvider.aws]: BranchMetadataCloudCredentialAWS;
54
+ [CloudProvider.cloudflare]: BranchMetadataCloudCredentialCloudflare;
55
+ [CloudProvider.azure]: Record<string, unknown>;
56
+ [CloudProvider.linode]: Record<string, unknown>;
57
+ [CloudProvider.hetzner]: Record<string, unknown>;
58
+ };
59
+ /**
60
+ * Function type for getCredentials.
61
+ * Returns the typed credentials for the specified provider.
62
+ */
63
+ export type GetCredentialsFn<P extends CloudProvider> = () => ProviderCredentialsMap[P];
14
64
  export declare enum TCPUrlType {
15
65
  ipv4 = "ipv4",
16
66
  ipv6 = "ipv6",
17
67
  domain = "domain"
18
68
  }
19
- export declare enum DeploymentArtifactType {
20
- container_image = "container_image"
21
- }
22
69
  /**
23
70
  * Transforms any interface name to canonical hyphen-separated lowercase form.
24
71
  *
@@ -161,7 +208,7 @@ export type DeploymentInfo = {
161
208
  type: DeploymentArtifactType;
162
209
  };
163
210
  };
164
- export type ProviderPulumiCtx<I, S> = {
211
+ export type ProviderPulumiCtx<I, S, P extends CloudProvider = CloudProvider> = {
165
212
  componentName: string;
166
213
  $: {
167
214
  (name: string, ...values: any[]): string;
@@ -171,16 +218,18 @@ export type ProviderPulumiCtx<I, S> = {
171
218
  state: S;
172
219
  declareConnectionInterfaces: DeclareConnectionInterfacesFn;
173
220
  buildArtifacts: Record<string, ArtifactInfo>;
221
+ getCredentials: GetCredentialsFn<P>;
174
222
  };
175
223
  /**
176
224
  * Context passed to connection handlers.
177
225
  * Contains the provider state, typed data from the connecting component,
178
- * and the connection type chosen by the orchestrator.
226
+ * the connection type chosen by the orchestrator, and getCredentials function.
179
227
  */
180
- export type ConnectionHandlerCtx<S, ConnectorData, ConnectionType extends string = string> = {
228
+ export type ConnectionHandlerCtx<S, ConnectorData, ConnectionType extends string = string, P extends CloudProvider = CloudProvider> = {
181
229
  state: S;
182
230
  connectionData: ConnectorData;
183
231
  connectionType: ConnectionType;
232
+ getCredentials: GetCredentialsFn<P>;
184
233
  };
185
234
  /**
186
235
  * Result returned by connection handlers.
@@ -190,9 +239,9 @@ export type ConnectionHandlerResult = Record<string, PulumiOutput<string>>;
190
239
  /**
191
240
  * A connection handler entry mapping a ConnectionInterfaceDef to its handler function.
192
241
  */
193
- export type ConnectionHandlerEntry<S, ConnectionType extends string, D extends ConnectionInterfaceDef> = {
242
+ export type ConnectionHandlerEntry<S, ConnectionType extends string, D extends ConnectionInterfaceDef, P extends CloudProvider = CloudProvider> = {
194
243
  interface: D;
195
- handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<D>, ConnectionType>) => Promise<ConnectionHandlerResult>;
244
+ handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<D>, ConnectionType, P>) => Promise<ConnectionHandlerResult>;
196
245
  };
197
246
  /**
198
247
  * Type definition for a connection handler entry.
@@ -203,10 +252,11 @@ export type ConnectionHandlerDef<D extends ConnectionInterfaceDef> = {
203
252
  handler: (ctx: ConnectionHandlerCtx<any, InferConnectionData<D>, any>) => Promise<ConnectionHandlerResult>;
204
253
  };
205
254
  export declare function connectionHandler<D extends ConnectionInterfaceDef>(entry: ConnectionHandlerDef<D>): ConnectionHandlerDef<D>;
206
- export type ProviderDeployCtx<D, S> = {
255
+ export type ProviderDeployCtx<D, S, P extends CloudProvider = CloudProvider> = {
207
256
  state: S;
257
+ getCredentials: GetCredentialsFn<P>;
208
258
  } & Record<string, DeploymentInfo>;
209
- export type ProviderAllocateCtx<S> = {
259
+ export type ProviderAllocateCtx<S, P extends CloudProvider = CloudProvider> = {
210
260
  name: string;
211
261
  deploymentConfig: Record<string, any>;
212
262
  state: S;
@@ -214,8 +264,9 @@ export type ProviderAllocateCtx<S> = {
214
264
  (name: string, ...values: any[]): string;
215
265
  (strings: TemplateStringsArray, ...values: any[]): string;
216
266
  };
267
+ getCredentials: GetCredentialsFn<P>;
217
268
  };
218
- export type ProviderDeallocateCtx<S> = {
269
+ export type ProviderDeallocateCtx<S, P extends CloudProvider = CloudProvider> = {
219
270
  name: string;
220
271
  deploymentConfig: Record<string, any>;
221
272
  state: S;
@@ -223,16 +274,18 @@ export type ProviderDeallocateCtx<S> = {
223
274
  (name: string, ...values: any[]): string;
224
275
  (strings: TemplateStringsArray, ...values: any[]): string;
225
276
  };
277
+ getCredentials: GetCredentialsFn<P>;
226
278
  };
227
- export type ProviderUpsertArtifactsCtx<S> = {
279
+ export type ProviderUpsertArtifactsCtx<S, P extends CloudProvider = CloudProvider> = {
228
280
  buildArtifacts: Record<string, ArtifactInfo>;
229
281
  state: S;
282
+ getCredentials: GetCredentialsFn<P>;
230
283
  };
231
- export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
232
- export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
233
- export type ProviderAllocateFn<S> = (ctx: ProviderAllocateCtx<S>) => Promise<void>;
234
- export type ProviderDeallocateFn<S> = (ctx: ProviderDeallocateCtx<S>) => Promise<void>;
235
- export type ProviderUpsertArtifactsFn<S> = (ctx: ProviderUpsertArtifactsCtx<S>) => Promise<void>;
284
+ export type ProviderPulumiFn<I, S, O, P extends CloudProvider = CloudProvider> = (ctx: ProviderPulumiCtx<I, S, P>) => Promise<O>;
285
+ export type ProviderDeployFn<D, S, P extends CloudProvider = CloudProvider> = (ctx: ProviderDeployCtx<D, S, P>) => Promise<void>;
286
+ export type ProviderAllocateFn<S, P extends CloudProvider = CloudProvider> = (ctx: ProviderAllocateCtx<S, P>) => Promise<void>;
287
+ export type ProviderDeallocateFn<S, P extends CloudProvider = CloudProvider> = (ctx: ProviderDeallocateCtx<S, P>) => Promise<void>;
288
+ export type ProviderUpsertArtifactsFn<S, P extends CloudProvider = CloudProvider> = (ctx: ProviderUpsertArtifactsCtx<S, P>) => Promise<void>;
236
289
  declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
237
290
  export type EmptyStateShape = typeof emptyStateSchema.shape;
238
291
  export type InferredState<SShape extends z.ZodRawShape> = z.infer<z.ZodObject<SShape>>;
@@ -247,15 +300,15 @@ export type InferredState<SShape extends z.ZodRawShape> = z.infer<z.ZodObject<SS
247
300
  export type RuntimeState<SShape extends z.ZodRawShape> = {
248
301
  [K in keyof InferredState<SShape>]: InferredState<SShape>[K] | PulumiOutput<InferredState<SShape>[K]>;
249
302
  };
250
- export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string, S = RuntimeState<SShape>> = {
303
+ export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string, P extends CloudProvider = CloudProvider, S = RuntimeState<SShape>> = {
251
304
  stateSchema?: z.ZodObject<SShape>;
252
305
  initialState?: Partial<S>;
253
- pulumi: ProviderPulumiFn<I, S, O>;
306
+ pulumi: ProviderPulumiFn<I, S, O, P>;
254
307
  connect?: readonly ConnectionHandlerEntry<S, ConnectionType, any>[];
255
- deploy?: ProviderDeployFn<D, S>;
256
- allocateComponent?: ProviderAllocateFn<S>;
257
- deallocateComponent?: ProviderDeallocateFn<S>;
258
- upsertArtifacts?: ProviderUpsertArtifactsFn<S>;
308
+ deploy?: ProviderDeployFn<D, S, P>;
309
+ allocateComponent?: ProviderAllocateFn<S, P>;
310
+ deallocateComponent?: ProviderDeallocateFn<S, P>;
311
+ upsertArtifacts?: ProviderUpsertArtifactsFn<S, P>;
259
312
  };
260
313
  /**
261
314
  * Stored version of ConnectionHandlerEntry that preserves ConnectionInterfaceDef type.
@@ -264,17 +317,17 @@ export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateSha
264
317
  */
265
318
  export type StoredConnectionHandlerEntry = {
266
319
  interface: ConnectionInterfaceDef;
267
- handler: (ctx: ConnectionHandlerCtx<any, any, any>) => Promise<ConnectionHandlerResult>;
320
+ handler: (ctx: ConnectionHandlerCtx<any, any, any, any>) => Promise<ConnectionHandlerResult>;
268
321
  };
269
322
  export type StoredProviderFns = {
270
323
  stateSchema: z.ZodObject<any>;
271
324
  initialState?: any;
272
- pulumi: ProviderPulumiFn<any, any, any>;
325
+ pulumi: ProviderPulumiFn<any, any, any, any>;
273
326
  connect?: readonly StoredConnectionHandlerEntry[];
274
- deploy?: ProviderDeployFn<any, any>;
275
- allocateComponent?: ProviderAllocateFn<any>;
276
- deallocateComponent?: ProviderDeallocateFn<any>;
277
- upsertArtifacts?: ProviderUpsertArtifactsFn<any>;
327
+ deploy?: ProviderDeployFn<any, any, any>;
328
+ allocateComponent?: ProviderAllocateFn<any, any>;
329
+ deallocateComponent?: ProviderDeallocateFn<any, any>;
330
+ upsertArtifacts?: ProviderUpsertArtifactsFn<any, any>;
278
331
  };
279
332
  export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
280
333
  /**
@@ -297,7 +350,7 @@ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends
297
350
  validationDeploymentInputSchema: z.ZodTypeAny;
298
351
  private declaredConnectionInterfaces;
299
352
  constructor(opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>);
300
- implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InferZodType<CShape>, InferZodType<DShape>, InferOutputType<OShape>, SShape, keyof ConnTypes & string>): this;
353
+ implement<P extends CloudProvider, SShape extends z.ZodRawShape = EmptyStateShape>(provider: P, fns: ProviderFnsDef<InferZodType<CShape>, InferZodType<DShape>, InferOutputType<OShape>, SShape, keyof ConnTypes & string, P>): this;
301
354
  /**
302
355
  * Get the schema for a specific connection interface.
303
356
  * Used by the orchestrator at runtime.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{z as j}from"zod";import*as M from"@pulumi/pulumi";var W;((H)=>{H.aws="aws";H.gcloud="gcloud";H.azure="azure";H.linode="linode";H.hetzner="hetzner";H.cloudflare="cloudflare"})(W||={});var Q;((E)=>{E.ipv4="ipv4";E.ipv6="ipv6";E.domain="domain"})(Q||={});var X;((q)=>q.container_image="container_image")(X||={});var L=new Map;function Y(b){return b.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase().replace(/-+/g,"-").replace(/^-|-$/g,"")}function Z(b){let q=Y(b);if(q.length===0)throw new Error("Connection interface name cannot be empty");let B=L.get(q);if(B!==void 0&&B!==b)throw new Error(`Connection interface name collision: '${b}' resolves to '${q}' which is already registered by '${B}'`);return L.set(q,b),q}function _(b,q){return{name:Z(b),schema:q}}function x(b,q){return b.schema.merge(q)}var N=_("tcp",j.object({url:j.object({type:j.nativeEnum(Q),value:j.string()}),publicAccess:j.boolean()})),w=j.object({});function F(b){if(b instanceof j.ZodObject){let q=b.shape,B={};for(let E in q)B[E]=F(q[E]);return j.object(B)}if(b instanceof j.ZodOptional)return F(b.unwrap()).optional();if(b instanceof j.ZodNullable)return F(b.unwrap()).nullable();if(b instanceof j.ZodDefault)return F(b._def.innerType).default(b._def.defaultValue);if(b instanceof j.ZodArray)return j.array(F(b.element));if(b instanceof j.ZodDiscriminatedUnion){let q=b._def.options.map((B)=>F(B));return j.discriminatedUnion(b._def.discriminator,q)}if(b instanceof j.ZodRecord){let q=b._def.keyType,B=b._def.valueType,E=q?F(q):j.string(),J=B?F(B):j.any();return j.record(E,J)}return j.union([b,j.custom((q)=>M.Output.isInstance(q))])}var $=j.object({metadata:j.object({stateful:j.boolean(),proxiable:j.boolean()}),connectionTypes:j.record(j.string(),j.object({description:j.string().min(5)})),configSchema:j.custom(),deploymentInputSchema:j.custom(),outputSchema:j.custom()});function k(b){return b}var G=j.object({});class K{opts;providers;validationSchema;validationDeploymentInputSchema;declaredConnectionInterfaces=new Map;constructor(b){this.opts=$.parse(b),this.providers={},this.validationSchema=F(b.configSchema),this.validationDeploymentInputSchema=F(b.deploymentInputSchema)}implement(b,q){return this.providers[b]={...q,stateSchema:q.stateSchema??G,initialState:q.initialState},this}getConnectionSchema(b){return b.schema}createDeclareConnectionInterfacesFn(){return(b)=>{for(let q of b){let B=q.interface.schema,E=F(B),J=E.safeParse(q.data);if(!J.success)throw new Error(`Invalid data for connection interface '${q.interface.name}': ${J.error.message}`);this.declaredConnectionInterfaces.set(q.interface.name,{schema:E,data:q.data})}}}getDeclaredInterfaces(){return this.declaredConnectionInterfaces}}export{Y as toCanonicalInterfaceName,x as extendSchema,_ as defineConnectionInterface,k as connectionHandler,Q as TCPUrlType,N as TCPCI,K as InfraComponent,X as DeploymentArtifactType,W as CloudProvider};
1
+ import{z as j}from"zod";import*as Y from"@pulumi/pulumi";var Q;((L)=>{L.aws="aws";L.gcloud="gcloud";L.azure="azure";L.linode="linode";L.hetzner="hetzner";L.cloudflare="cloudflare"})(Q||={});var W;((B)=>B.container_image="container_image")(W||={});var Z;((H)=>{H.ipv4="ipv4";H.ipv6="ipv6";H.domain="domain"})(Z||={});var X=new Map;function _(b){return b.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase().replace(/-+/g,"-").replace(/^-|-$/g,"")}function $(b){let B=_(b);if(B.length===0)throw new Error("Connection interface name cannot be empty");let F=X.get(B);if(F!==void 0&&F!==b)throw new Error(`Connection interface name collision: '${b}' resolves to '${B}' which is already registered by '${F}'`);return X.set(B,b),B}function q(b,B){return{name:$(b),schema:B}}function w(b,B){return b.schema.merge(B)}var x=q("tcp",j.object({url:j.object({type:j.nativeEnum(Z),value:j.string()}),publicAccess:j.boolean()})),R=j.object({});function J(b){if(b instanceof j.ZodObject){let B=b.shape,F={};for(let H in B)F[H]=J(B[H]);return j.object(F)}if(b instanceof j.ZodOptional)return J(b.unwrap()).optional();if(b instanceof j.ZodNullable)return J(b.unwrap()).nullable();if(b instanceof j.ZodDefault)return J(b._def.innerType).default(b._def.defaultValue);if(b instanceof j.ZodArray)return j.array(J(b.element));if(b instanceof j.ZodDiscriminatedUnion){let B=b._def.options.map((F)=>J(F));return j.discriminatedUnion(b._def.discriminator,B)}if(b instanceof j.ZodRecord){let B=b._def.keyType,F=b._def.valueType,H=B?J(B):j.string(),M=F?J(F):j.any();return j.record(H,M)}return j.union([b,j.custom((B)=>Y.Output.isInstance(B))])}var E=j.object({metadata:j.object({stateful:j.boolean(),proxiable:j.boolean()}),connectionTypes:j.record(j.string(),j.object({description:j.string().min(5)})),configSchema:j.custom(),deploymentInputSchema:j.custom(),outputSchema:j.custom()});function U(b){return b}var G=j.object({});class K{opts;providers;validationSchema;validationDeploymentInputSchema;declaredConnectionInterfaces=new Map;constructor(b){this.opts=E.parse(b),this.providers={},this.validationSchema=J(b.configSchema),this.validationDeploymentInputSchema=J(b.deploymentInputSchema)}implement(b,B){return this.providers[b]={...B,stateSchema:B.stateSchema??G,initialState:B.initialState},this}getConnectionSchema(b){return b.schema}createDeclareConnectionInterfacesFn(){return(b)=>{for(let B of b){let F=B.interface.schema,H=J(F),M=H.safeParse(B.data);if(!M.success)throw new Error(`Invalid data for connection interface '${B.interface.name}': ${M.error.message}`);this.declaredConnectionInterfaces.set(B.interface.name,{schema:H,data:B.data})}}}getDeclaredInterfaces(){return this.declaredConnectionInterfaces}}export{_ as toCanonicalInterfaceName,w as extendSchema,q as defineConnectionInterface,U as connectionHandler,Z as TCPUrlType,x as TCPCI,K as InfraComponent,W as DeploymentArtifactType,Q as CloudProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"