@collective-intelligence/external-apps-server-sdk 0.1.37 → 0.1.39
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/README.md +114 -14
- package/dist/admin.d.ts +1 -0
- package/dist/{runtime/effect.js → chunks/index-7b0e6810.js} +11 -2
- package/dist/effect.d.ts +1349 -0
- package/dist/effect.js +1 -0
- package/dist/gateway.d.ts +9 -3
- package/dist/gateway.js +1 -1
- package/dist/index.d.ts +84 -37
- package/dist/index.js +1 -16
- package/dist/next.d.ts +358 -0
- package/dist/next.js +1 -0
- package/dist/persistence/drizzle-effect.d.ts +23 -4
- package/dist/resources.d.ts +5 -1
- package/dist/resources.js +1 -1
- package/dist/runtime/effect.d.ts +137 -106
- package/dist/runtime/nestjs.js +1 -1
- package/dist/runtime/next.d.ts +126 -86
- package/dist/runtime/web.d.ts +11 -5
- package/dist/runtime/web.js +1 -1
- package/package.json +20 -11
- package/dist/persistence/drizzle-effect.js +0 -1
- package/dist/runtime/next.js +0 -1
package/dist/runtime/effect.d.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { Bounds, ConnectorContext, ConsumerProfileDiagnostic, ConsumerProfileId, DatasetAggregateOperation, DatasetDefinition, DatasetFilter, DatasetOperation, DatasetOrder, DatasetPredicate, DatasetPredicateOperator, DatasetProviderCapabilities, DatasetProviderError, DatasetProviderResult, DatasetQueryIntent, DatasetRecordPage, DatasetResultPage, DatasetScalarType, DatasetSourceLocation, DatasetTimeBucket, DatasetValue, DynamicFormAiFillConfig, FieldUiSchema, FieldValidationRule, FieldVisibilityRule, FormLayout, FormMarkdownBlock, FormMetadata, FormSection, FormSectionItem, FormStep, JsonObject, JsonPrimitive, JsonSchemaDocument, JsonValue, OperationDomainDeclaration, PackageSchemaProjection, PlainFormWidget, PortableOperationAuthorization, PortableOperationDeclaration, PortableOperationDelegatedSubjectPolicy, PortableOperationEffect, PortableOperationExecutionPolicy, PortableOperationIdempotency, PortableOperationLimits, PortableOperationPrincipalKind, PortableOperationRetryPolicy, ProjectionFidelity, QueryInput, SafeDiagnostic, SelectFormWidget, SelectOptions, StructuredFileBrowserOptions, StructuredFileUploadOptions, VisibilityCondition } from '@collective-intelligence/extensions-sdk';
|
|
4
4
|
import { EntityCreateInput, EntityDeleteInput, EntityListQuery, EntityMemberValue, EntityOperation, EntityOperationResult, EntityPage, EntityRequest, EntityUpdateInput, EntityUploadInput, EntityUploadSlot, IdempotencyKey, PortableResourceSchema, ResourceCapabilities, ResourceCreateInput, ResourceCreateRequest, ResourceCursor, ResourceDefinition, ResourceError, ResourceErrorCode, ResourceFilter, ResourceGetRequest, ResourceId, ResourceIdentityField, ResourceJsonValue, ResourceLifecycleInput, ResourceLifecycleRequest, ResourceListQuery, ResourceListRequest, ResourceListResult, ResourceMutationInput, ResourcePagination, ResourcePaginationMode, ResourceRecord, ResourceRecordId, ResourceResult, ResourceRevision, ResourceSort, ResourceTransportRequest, ResourceUpdateRequest } from '@collective-intelligence/external-apps-client-sdk/resources';
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
5
6
|
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Layer from 'effect/Layer';
|
|
6
8
|
import * as Schema from 'effect/Schema';
|
|
7
9
|
|
|
8
10
|
/** Application login identities are separate from gateway machine callers. */
|
|
@@ -246,17 +248,32 @@ export interface GatewayKernel {
|
|
|
246
248
|
readonly handle: (request: Request) => Promise<Response>;
|
|
247
249
|
readonly manifest: DefinedGateway["manifest"];
|
|
248
250
|
}
|
|
251
|
+
declare const GatewayEffectRuntimeError_base: Schema.Class<GatewayEffectRuntimeError, Schema.TaggedStruct<"GatewayEffectRuntimeError", {
|
|
252
|
+
readonly cause: Schema.Defect;
|
|
253
|
+
}>, import("effect/Cause").YieldableError>;
|
|
254
|
+
declare class GatewayEffectRuntimeError extends GatewayEffectRuntimeError_base {
|
|
255
|
+
/** The positional form of `./runtime/effect`: one argument is the cause. */
|
|
256
|
+
constructor(cause: unknown);
|
|
257
|
+
/** The Schema form; Schema decoding gives the fields and the options. */
|
|
258
|
+
constructor(fields: Readonly<{
|
|
259
|
+
cause: unknown;
|
|
260
|
+
}>, options: Schema.MakeOptions | undefined);
|
|
261
|
+
get message(): string;
|
|
262
|
+
}
|
|
249
263
|
export type GatewayRuntimeKernel = Pick<GatewayKernel, "handle">;
|
|
264
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
250
265
|
export type EffectCrudResourceOptions<Entity, Create, Update, Error, Requirements> = Readonly<{
|
|
251
266
|
definition: ResourceDefinition<Entity, Create, Update>;
|
|
252
267
|
authorization: GatewayResourceAuthorization;
|
|
253
268
|
repository: Effect.Effect<CrudRepository<Entity, Create, Update>, Error, Requirements>;
|
|
254
269
|
}>;
|
|
270
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
255
271
|
export type ResourceProjectionDiagnostic = Readonly<{
|
|
256
272
|
code: "unsupported_refinement" | "unsupported_transform" | "unsupported_schema" | ConsumerProfileDiagnostic["code"];
|
|
257
273
|
location: string;
|
|
258
274
|
reason: string;
|
|
259
275
|
}>;
|
|
276
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
260
277
|
export type ResourceSchemaProjection = Readonly<{
|
|
261
278
|
success: true;
|
|
262
279
|
schema: JsonSchemaDocument;
|
|
@@ -266,17 +283,15 @@ export type ResourceSchemaProjection = Readonly<{
|
|
|
266
283
|
success: false;
|
|
267
284
|
diagnostics: readonly ResourceProjectionDiagnostic[];
|
|
268
285
|
}>;
|
|
269
|
-
|
|
270
|
-
readonly _tag = "GatewayEffectRuntimeError";
|
|
271
|
-
readonly name = "GatewayEffectRuntimeError";
|
|
272
|
-
readonly cause: unknown;
|
|
273
|
-
constructor(cause: unknown);
|
|
274
|
-
}
|
|
286
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
275
287
|
export type GatewayEffectHandler = (request: Request) => Effect.Effect<Response, GatewayEffectRuntimeError>;
|
|
288
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
276
289
|
export type ResourceEffectHandlerOptions<E = never, R = never, Value = unknown, Create = Value, Patch = Partial<Value>> = Omit<ResourceHttpHandlerOptions<Value, Create, Patch>, "authorize"> & Readonly<{
|
|
277
290
|
authorize: (request: Request, operation: Parameters<ResourceHttpHandlerOptions["authorize"]>[1]) => Effect.Effect<EntityInvocationContext | Response, E, R>;
|
|
278
291
|
}>;
|
|
279
|
-
/** One file of a File field, as every CI read surface returns it.
|
|
292
|
+
/** One file of a File field, as every CI read surface returns it.
|
|
293
|
+
* @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`.
|
|
294
|
+
*/
|
|
280
295
|
export declare const EntityFileValue: Schema.Struct<{
|
|
281
296
|
readonly filename: Schema.String;
|
|
282
297
|
readonly id: Schema.String;
|
|
@@ -288,11 +303,13 @@ export declare const EntityFileValue: Schema.Struct<{
|
|
|
288
303
|
]>;
|
|
289
304
|
readonly url: Schema.String;
|
|
290
305
|
}>;
|
|
306
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
291
307
|
export type EntityFileValue = typeof EntityFileValue.Type;
|
|
292
308
|
/**
|
|
293
309
|
* One file of a File field write: `{ upload }` adds the File upload of an
|
|
294
310
|
* upload slot's `uploadId`; `{ id }` keeps a file, so a File value read before
|
|
295
311
|
* decodes as the file it names.
|
|
312
|
+
* @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`.
|
|
296
313
|
*/
|
|
297
314
|
export declare const EntityFileWrite: Schema.Union<readonly [
|
|
298
315
|
Schema.Struct<{
|
|
@@ -304,11 +321,13 @@ export declare const EntityFileWrite: Schema.Union<readonly [
|
|
|
304
321
|
readonly upload: Schema.optionalKey<Schema.Never>;
|
|
305
322
|
}>
|
|
306
323
|
]>;
|
|
324
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
307
325
|
export type EntityFileWrite = typeof EntityFileWrite.Type;
|
|
308
326
|
/**
|
|
309
327
|
* The write form of a File field key: one file or `null` for a single field,
|
|
310
328
|
* an ordered array for a multiple field; `null` removes every file. Omit the
|
|
311
329
|
* key to keep its files unchanged.
|
|
330
|
+
* @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`.
|
|
312
331
|
*/
|
|
313
332
|
export declare const EntityFileFieldWrite: Schema.NullOr<Schema.Union<readonly [
|
|
314
333
|
Schema.Union<readonly [
|
|
@@ -332,114 +351,126 @@ export declare const EntityFileFieldWrite: Schema.NullOr<Schema.Union<readonly [
|
|
|
332
351
|
}>
|
|
333
352
|
]>>
|
|
334
353
|
]>>;
|
|
354
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
335
355
|
export type EntityFileFieldWrite = typeof EntityFileFieldWrite.Type;
|
|
356
|
+
declare const GatewayEffectRuntimeError$1: typeof GatewayEffectRuntimeError;
|
|
357
|
+
type GatewayEffectRuntimeError$1 = GatewayEffectRuntimeError;
|
|
358
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
336
359
|
export declare const createGatewayEffectHandler: (kernel: GatewayRuntimeKernel) => GatewayEffectHandler;
|
|
337
|
-
|
|
360
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
361
|
+
export declare const createResourceEffectHandler: <E, R, Value = unknown, Create = Value, Patch = Partial<Value>>(options: ResourceEffectHandlerOptions<E, R, Value, Create, Patch>) => (request: Request) => import("effect/Effect").Effect<Response, GatewayEffectRuntimeError | E, R>;
|
|
362
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
338
363
|
export declare const DateTimeString: import("effect/Schema").String;
|
|
339
|
-
|
|
364
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
365
|
+
declare const GatewayEffectRuntimeError$2: typeof GatewayEffectRuntimeError;
|
|
366
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
367
|
+
type GatewayEffectRuntimeError$2 = GatewayEffectRuntimeError$1;
|
|
368
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
340
369
|
export declare const jsonSchema: (schema: import("effect/Schema").Top) => import("@collective-intelligence/extensions-sdk").JsonSchemaDocument;
|
|
370
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
341
371
|
export declare const projectResourceSchema: (schema: import("effect/Schema").Top, metadata?: import("@collective-intelligence/extensions-sdk").FormMetadata<string>) => ResourceSchemaProjection;
|
|
372
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
342
373
|
export declare const makeEffectCrudResource: <Entity, Create = Entity, Update = Partial<Entity>, Error = never, Requirements = never>(options: EffectCrudResourceOptions<Entity, Create, Update, Error, Requirements>) => import("effect/Effect").Effect<CrudResource<Entity, Create, Update>, Error, Requirements>;
|
|
374
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-server-sdk/effect`. */
|
|
343
375
|
export declare const UuidV7: import("effect/Schema").String;
|
|
344
|
-
type GatewayEffectRuntimeError$1 = GatewayEffectRuntimeError;
|
|
345
376
|
|
|
346
377
|
export {
|
|
347
|
-
Bounds,
|
|
348
|
-
ConnectorContext,
|
|
349
|
-
ConsumerProfileDiagnostic,
|
|
350
|
-
ConsumerProfileId,
|
|
351
|
-
DatasetAggregateOperation,
|
|
352
|
-
DatasetDefinition,
|
|
353
|
-
DatasetFilter,
|
|
354
|
-
DatasetOperation,
|
|
355
|
-
DatasetOrder,
|
|
356
|
-
DatasetPredicate,
|
|
357
|
-
DatasetPredicateOperator,
|
|
358
|
-
DatasetProviderCapabilities,
|
|
359
|
-
DatasetProviderError,
|
|
360
|
-
DatasetProviderResult,
|
|
361
|
-
DatasetQueryIntent,
|
|
362
|
-
DatasetRecordPage,
|
|
363
|
-
DatasetResultPage,
|
|
364
|
-
DatasetScalarType,
|
|
365
|
-
DatasetSourceLocation,
|
|
366
|
-
DatasetTimeBucket,
|
|
367
|
-
DatasetValue,
|
|
368
|
-
DynamicFormAiFillConfig,
|
|
369
|
-
EntityCreateInput,
|
|
370
|
-
EntityDeleteInput,
|
|
371
|
-
EntityListQuery,
|
|
372
|
-
EntityMemberValue,
|
|
373
|
-
EntityOperation,
|
|
374
|
-
EntityOperationResult,
|
|
375
|
-
EntityPage,
|
|
376
|
-
EntityRequest,
|
|
377
|
-
EntityUpdateInput,
|
|
378
|
-
EntityUploadInput,
|
|
379
|
-
EntityUploadSlot,
|
|
380
|
-
FieldUiSchema,
|
|
381
|
-
FieldValidationRule,
|
|
382
|
-
FieldVisibilityRule,
|
|
383
|
-
FormLayout,
|
|
384
|
-
FormMarkdownBlock,
|
|
385
|
-
FormMetadata,
|
|
386
|
-
FormSection,
|
|
387
|
-
FormSectionItem,
|
|
388
|
-
FormStep,
|
|
389
|
-
GatewayEffectRuntimeError$
|
|
390
|
-
IdempotencyKey,
|
|
391
|
-
JsonObject,
|
|
392
|
-
JsonPrimitive,
|
|
393
|
-
JsonSchemaDocument,
|
|
394
|
-
JsonValue,
|
|
395
|
-
OperationDomainDeclaration,
|
|
396
|
-
PackageSchemaProjection,
|
|
397
|
-
PlainFormWidget,
|
|
398
|
-
PortableOperationAuthorization,
|
|
399
|
-
PortableOperationDeclaration,
|
|
400
|
-
PortableOperationDelegatedSubjectPolicy,
|
|
401
|
-
PortableOperationEffect,
|
|
402
|
-
PortableOperationExecutionPolicy,
|
|
403
|
-
PortableOperationIdempotency,
|
|
404
|
-
PortableOperationLimits,
|
|
405
|
-
PortableOperationPrincipalKind,
|
|
406
|
-
PortableOperationRetryPolicy,
|
|
407
|
-
PortableResourceSchema,
|
|
408
|
-
ProjectionFidelity,
|
|
409
|
-
QueryInput,
|
|
410
|
-
ResourceCapabilities,
|
|
411
|
-
ResourceCreateInput,
|
|
412
|
-
ResourceCreateRequest,
|
|
413
|
-
ResourceCursor,
|
|
414
|
-
ResourceDefinition,
|
|
415
|
-
ResourceError,
|
|
416
|
-
ResourceErrorCode,
|
|
417
|
-
ResourceFilter,
|
|
418
|
-
ResourceGetRequest,
|
|
419
|
-
ResourceId,
|
|
420
|
-
ResourceIdentityField,
|
|
421
|
-
ResourceJsonValue,
|
|
422
|
-
ResourceLifecycleInput,
|
|
423
|
-
ResourceLifecycleRequest,
|
|
424
|
-
ResourceListQuery,
|
|
425
|
-
ResourceListRequest,
|
|
426
|
-
ResourceListResult,
|
|
427
|
-
ResourceMutationInput,
|
|
428
|
-
ResourcePagination,
|
|
429
|
-
ResourcePaginationMode,
|
|
430
|
-
ResourceRecord,
|
|
431
|
-
ResourceRecordId,
|
|
432
|
-
ResourceResult,
|
|
433
|
-
ResourceRevision,
|
|
434
|
-
ResourceSort,
|
|
435
|
-
ResourceTransportRequest,
|
|
436
|
-
ResourceUpdateRequest,
|
|
437
|
-
SafeDiagnostic,
|
|
438
|
-
SelectFormWidget,
|
|
439
|
-
SelectOptions,
|
|
440
|
-
StructuredFileBrowserOptions,
|
|
441
|
-
StructuredFileUploadOptions,
|
|
442
|
-
VisibilityCondition,
|
|
378
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ Bounds,
|
|
379
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ ConnectorContext,
|
|
380
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ ConsumerProfileDiagnostic,
|
|
381
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ ConsumerProfileId,
|
|
382
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetAggregateOperation,
|
|
383
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetDefinition,
|
|
384
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetFilter,
|
|
385
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetOperation,
|
|
386
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetOrder,
|
|
387
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetPredicate,
|
|
388
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetPredicateOperator,
|
|
389
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetProviderCapabilities,
|
|
390
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetProviderError,
|
|
391
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetProviderResult,
|
|
392
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetQueryIntent,
|
|
393
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetRecordPage,
|
|
394
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetResultPage,
|
|
395
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetScalarType,
|
|
396
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetSourceLocation,
|
|
397
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetTimeBucket,
|
|
398
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DatasetValue,
|
|
399
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ DynamicFormAiFillConfig,
|
|
400
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityCreateInput,
|
|
401
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityDeleteInput,
|
|
402
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityListQuery,
|
|
403
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityMemberValue,
|
|
404
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityOperation,
|
|
405
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityOperationResult,
|
|
406
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityPage,
|
|
407
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityRequest,
|
|
408
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityUpdateInput,
|
|
409
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityUploadInput,
|
|
410
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ EntityUploadSlot,
|
|
411
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FieldUiSchema,
|
|
412
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FieldValidationRule,
|
|
413
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FieldVisibilityRule,
|
|
414
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FormLayout,
|
|
415
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FormMarkdownBlock,
|
|
416
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FormMetadata,
|
|
417
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FormSection,
|
|
418
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FormSectionItem,
|
|
419
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ FormStep,
|
|
420
|
+
GatewayEffectRuntimeError$2 as GatewayEffectRuntimeError,
|
|
421
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ IdempotencyKey,
|
|
422
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ JsonObject,
|
|
423
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ JsonPrimitive,
|
|
424
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ JsonSchemaDocument,
|
|
425
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ JsonValue,
|
|
426
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ OperationDomainDeclaration,
|
|
427
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PackageSchemaProjection,
|
|
428
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PlainFormWidget,
|
|
429
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationAuthorization,
|
|
430
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationDeclaration,
|
|
431
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationDelegatedSubjectPolicy,
|
|
432
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationEffect,
|
|
433
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationExecutionPolicy,
|
|
434
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationIdempotency,
|
|
435
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationLimits,
|
|
436
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationPrincipalKind,
|
|
437
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ PortableOperationRetryPolicy,
|
|
438
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ PortableResourceSchema,
|
|
439
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ ProjectionFidelity,
|
|
440
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ QueryInput,
|
|
441
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceCapabilities,
|
|
442
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceCreateInput,
|
|
443
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceCreateRequest,
|
|
444
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceCursor,
|
|
445
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceDefinition,
|
|
446
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceError,
|
|
447
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceErrorCode,
|
|
448
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceFilter,
|
|
449
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceGetRequest,
|
|
450
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceId,
|
|
451
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceIdentityField,
|
|
452
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceJsonValue,
|
|
453
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceLifecycleInput,
|
|
454
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceLifecycleRequest,
|
|
455
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceListQuery,
|
|
456
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceListRequest,
|
|
457
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceListResult,
|
|
458
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceMutationInput,
|
|
459
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourcePagination,
|
|
460
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourcePaginationMode,
|
|
461
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceRecord,
|
|
462
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceRecordId,
|
|
463
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceResult,
|
|
464
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceRevision,
|
|
465
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceSort,
|
|
466
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceTransportRequest,
|
|
467
|
+
/** @deprecated Import it from `@collective-intelligence/external-apps-client-sdk/resources`. */ ResourceUpdateRequest,
|
|
468
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ SafeDiagnostic,
|
|
469
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ SelectFormWidget,
|
|
470
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ SelectOptions,
|
|
471
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ StructuredFileBrowserOptions,
|
|
472
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ StructuredFileUploadOptions,
|
|
473
|
+
/** @deprecated Import it from `@collective-intelligence/extensions-sdk`. */ VisibilityCondition,
|
|
443
474
|
};
|
|
444
475
|
|
|
445
476
|
export {};
|
package/dist/runtime/nestjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __defProp=Object.defineProperty;var __returnValue=(v)=>v;function __exportSetter(name,newValue){this[name]=__returnValue.bind(null,newValue)}var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true,configurable:true,set:__exportSetter.bind(all,name)})};var exports_nestjs={};__export(exports_nestjs,{CrudResourceNestModule:()=>CrudResourceNestModule,GatewayNestModule:()=>GatewayNestModule,bindNestOperation:()=>bindNestOperation,createGatewayNestHandler:()=>createGatewayNestHandler});import{All,Controller,Inject,Module,Req,Res}from"@nestjs/common";import{createEntityProtocol}from"@collective-intelligence/external-apps-client-sdk/resources";var unavailableBrand=Symbol.for("@collective-intelligence/external-apps-server-sdk/ApplicationUserAuthUnavailableError");class ApplicationUserAuthUnavailableError extends Error{[unavailableBrand]=true;code="user_auth_unavailable";static[Symbol.hasInstance](value){return value instanceof Error&&unavailableBrand in value&&value[unavailableBrand]===true&&"code"in value&&value.code==="user_auth_unavailable"}constructor(cause){super("Application user authentication is unavailable",{cause});this.name="ApplicationUserAuthUnavailableError"}}var credential=Symbol.for("@collective-intelligence/external-apps-server-sdk/ci-entity-invocation");var matchesEntityContext=(context,resourceId)=>context?.resourceId===resourceId&&context.applicationId.length>0&&context.user?.kind==="ci_user"&&context.user.id.length>0&&context.user.issuer===context.issuer&&context.user.organizationId===context.organizationId;var record=(value)=>typeof value==="object"&&value!==null&&!Array.isArray(value)?Object.fromEntries(Object.entries(value)):null;var json=(body,status,correlationId)=>Response.json(body,{headers:{"cache-control":"no-store","x-correlation-id":correlationId},status});var resourceResult=(result)=>{if(result.ok){return json(result,200,result.correlationId)}let status;switch(result.error.code){case"unauthenticated":{status=401;break}case"forbidden":{status=403;break}case"not_found":{status=404;break}case"conflict":{status=409;break}case"rate_limited":{status=429;break}case"unavailable":case"transport_error":{status=503;break}case"internal":{status=500;break}case"capability_not_supported":case"invalid_request":case"upload_not_supported":{status=400;break}default:{status=500}}return json(result,status,result.correlationId)};var resourceRequest=(request,body,resourceId,externalId,action,correlationId)=>{if(request.method==="POST"&&externalId===undefined&&(action==="scan"||action==="search")){const pagination=record(body.pagination);if(pagination===null||pagination.mode!=="cursor"&&pagination.mode!=="page"){return null}const query=body;return{operation:"list",query,requestId:correlationId,resourceId}}if(request.method==="GET"&&externalId!==undefined&&action===undefined){return{id:externalId,operation:"get",requestId:correlationId,resourceId}}if(request.method==="POST"&&externalId===undefined&&action==="records"){if(typeof body.idempotencyKey!=="string"||!("value"in body)){return null}return{idempotencyKey:body.idempotencyKey,operation:"create",requestId:correlationId,resourceId,value:body.value}}if(externalId===undefined||typeof body.expectedRevision!=="string"){return null}const idempotencyKey=typeof body.idempotencyKey==="string"?{idempotencyKey:body.idempotencyKey}:{};if(request.method==="PATCH"&&action===undefined&&"value"in body){return{expectedRevision:body.expectedRevision,id:externalId,...idempotencyKey,operation:"update",requestId:correlationId,resourceId,value:body.value}}const operation=request.method==="DELETE"&&action===undefined?"hard_delete":request.method==="POST"&&action==="soft-delete"?"soft_delete":request.method==="POST"&&action==="restore"?"restore":null;return operation===null?null:{expectedRevision:body.expectedRevision,id:externalId,...idempotencyKey,operation,requestId:correlationId,resourceId}};var readResourceBody=async(request,maximum)=>{if(Number(request.headers.get("content-length"))>maximum){await request.body?.cancel();return null}const reader=request.body?.getReader();if(reader===undefined){return null}const decoder=new TextDecoder("utf-8",{fatal:true});let size=0;let text="";try{for(;;){const{done,value}=await reader.read();if(done){break}size+=value.byteLength;if(size>maximum){await reader.cancel();return null}text+=decoder.decode(value,{stream:true})}text+=decoder.decode();const parsed=JSON.parse(text);if(typeof parsed!=="object"||parsed===null||Array.isArray(parsed)){return null}return Object.fromEntries(Object.entries(parsed))}catch{return null}finally{reader.releaseLock()}};var trimTrailingSlash=(value)=>value.endsWith("/")?value.slice(0,-1):value;var matchEntityHttpRoute=(pathname,basePath)=>{const prefix=trimTrailingSlash(basePath);if(!pathname.startsWith(`${prefix}/`)){return null}let parts;try{parts=pathname.slice(prefix.length+1).split("/").map(decodeURIComponent)}catch{return null}const[head,id,action]=parts;if(head==="search"&&parts.length===1){return{kind:"search"}}if(head==="records"&&parts.length===1){return{kind:"collection"}}if(head==="uploads"&&parts.length===1){return{kind:"uploads"}}if(head!=="records"||id===undefined||id.length===0){return null}if(parts.length===2){return{id,kind:"record"}}if(parts.length===3&&action==="soft-delete"){return{id,kind:"soft_delete"}}if(parts.length===4&&action==="relation-members"&&parts[3]==="search"){return{id,kind:"relation_members"}}return null};var decodeEntityRoute=(protocol,input,body)=>{if(input.operation==="list_members"){const{field,...query}=body;return protocol.decodeRequest({...input,field,query})}if(input.operation==="upload"){return protocol.decodeRequest({...body,...input})}if(input.operation!=="list"&&input.operation!=="get"){const allowed=["idempotencyKey"];if(input.operation!=="create"){allowed.push("expectedRevision")}if(input.operation==="create"||input.operation==="update"){allowed.push("value")}if(Object.keys(body).some((key)=>!allowed.includes(key))){return{correlationId:input.requestId,error:{code:"invalid_request",details:{issues:[{field:"",keyword:"additionalProperties"}]},message:"Request contains unsupported entity fields",retryable:false},ok:false}}}return protocol.decodeRequest({...input,operation:input.operation==="soft_delete"?"delete":input.operation})};var readResourceRoute=async(request,basePath,resourceId,requestId,maximum)=>{const invalid=(message)=>resourceResult({correlationId:requestId,error:{code:"invalid_request",message,retryable:false},ok:false});const path=new URL(request.url).pathname;const route=matchEntityHttpRoute(path,basePath);if(route===null){return new Response(null,{status:404})}const body=request.method==="GET"?{}:await readResourceBody(request,maximum);if(body===null){return invalid("Request body is invalid or exceeds its limit")}if(route.kind==="relation_members"){const member={operation:"list_members",parentId:route.id,requestId,resourceId};return request.method==="POST"?{body,input:member}:invalid("Invalid resource route or request")}if(route.kind==="uploads"){const upload={operation:"upload",requestId,resourceId};return request.method==="POST"?{body,input:upload}:invalid("Invalid resource route or request")}let externalId;let action;switch(route.kind){case"search":{action="search";break}case"collection":{action="records";break}case"record":{externalId=route.id;break}case"soft_delete":{action="soft-delete";externalId=route.id;break}default:{break}}const input=resourceRequest(request,body,resourceId,externalId,action,requestId);return input===null?invalid("Invalid resource route or request"):{body,input}};var createResourceHttpHandler=(options)=>{const protocol="executeCrud"in options.resource?null:createEntityProtocol(options.resource.definition);return async(request)=>{const requestId=request.headers.get("x-correlation-id")?.match(/^[\w.-]{1,128}$/u)?.[0]??crypto.randomUUID();const{resource}=options;const route=await readResourceRoute(request,options.basePath,resource.definition.id,requestId,options.maxBodyBytes??1048576);if(route instanceof Response){return route}const{body,input}=route;const decoded=protocol===null?null:decodeEntityRoute(protocol,input,body);if(decoded!==null&&!decoded.ok){return resourceResult(decoded)}try{const operation=decoded?.ok?decoded.value.operation:input.operation;const authorized=await options.authorize(request,operation);if(authorized instanceof Response){return authorized}if(!matchesEntityContext(authorized,resource.definition.id)){return resourceResult({correlationId:requestId,error:{code:"forbidden",message:"The current identity is not authorized for this resource",retryable:false},ok:false})}if("executeCrud"in resource){return input.operation==="upload"||input.operation==="list_members"?new Response(null,{status:404}):resourceResult(await resource.executeCrud(input,authorized))}if(decoded?.ok){return resourceResult(await resource.execute(decoded.value,authorized,{signal:request.signal}))}throw new TypeError("Entity request was not decoded")}catch(error){return resourceResult({correlationId:requestId,error:{code:error instanceof ApplicationUserAuthUnavailableError?"unavailable":"internal",message:"Resource authorization or execution is unavailable",retryable:false},ok:false})}}};var headersFromNode=(input)=>{const headers=new Headers;for(const[name,value]of Object.entries(input)){if(typeof value==="string"){headers.set(name,value)}else if(Array.isArray(value)){headers.set(name,value.join(", "))}}return headers};var nodeChunk=(chunk)=>{if(typeof chunk==="string"){return new TextEncoder().encode(chunk)}return chunk};var bodyFromNode=(request,onBodyCancelled)=>{if(request.body!==undefined){return typeof request.body==="string"?request.body:JSON.stringify(request.body)}const iterator=request.iterator?.({destroyOnReturn:false})??request[Symbol.asyncIterator]?.();if(iterator===undefined){return}return new ReadableStream({cancel:async()=>{onBodyCancelled?.();await iterator.return?.()},pull:async(controller)=>{try{const next=await iterator.next();if(next.done===true){controller.close()}else{controller.enqueue(nodeChunk(next.value))}}catch(error){controller.error(error)}}},{highWaterMark:0})};var webRequestFromNode=async(request,signal,onBodyCancelled)=>{const method=request.method??"GET";const headers=headersFromNode(request.headers);const host=headers.get("host")??"gateway.local";const protocol=request.protocol??"http";const url=new URL(request.originalUrl??request.url??"/",`${protocol}://${host}`);const body=method==="GET"||method==="HEAD"?undefined:bodyFromNode(request,onBodyCancelled);const requestInit={headers,method,signal};if(body!==undefined){requestInit.body=body;requestInit.duplex="half"}return new Request(url,requestInit)};var sendWebResponseToNode=async(response,result)=>{if(response.status===undefined){response.statusCode=result.status}else{response.status(result.status)}for(const[name,value]of result.headers){if(response.setHeader===undefined){response.header?.(name,value)}else{response.setHeader(name,value)}}if(result.body===null){response.end();return}const reader=result.body.getReader();while(true){const next=await reader.read();if(next.done){break}response.write?.(next.value)}response.end()};var handleNodeRequest=async(kernel,request,response)=>{const controller=new AbortController;const onAborted=()=>{controller.abort()};request.once?.("aborted",onAborted);response?.once?.("close",onAborted);try{let bodyCancelled=false;let result=await kernel.handle(await webRequestFromNode(request,controller.signal,()=>{bodyCancelled=true}));if(bodyCancelled){const headers=new Headers(result.headers);headers.set("connection","close");result=new Response(result.body,{headers,status:result.status,statusText:result.statusText})}if(response!==undefined){await sendWebResponseToNode(response,result.clone())}return result}finally{request.off?.("aborted",onAborted);response?.off?.("close",onAborted)}};var defineOperation=(definition)=>Object.freeze(definition);var brand=Symbol.for("@collective-intelligence/external-apps-server-sdk/GatewayOperationError");class GatewayOperationError extends Error{[brand]=true;code;static[Symbol.hasInstance](value){return value instanceof Error&&brand in value&&value[brand]===true&&"code"in value&&(value.code==="authorization_denied"||value.code==="capability_not_supported"||value.code==="invalid_request")}constructor(code,message){super(message.slice(0,512));this.code=code;this.name="GatewayOperationError"}}var bindNestOperation=(binding)=>defineOperation({...binding.declaration,handler:async(request)=>{request.signal.throwIfAborted();const input=await binding.normalize(request);request.signal.throwIfAborted();const normalized={...request,input};if(!await binding.authorize(normalized)){throw new GatewayOperationError("authorization_denied","Application authorization denied")}request.signal.throwIfAborted();return await binding.execute(normalized)}});var createGatewayNestHandler=(kernel)=>async(request,response)=>await handleNodeRequest(kernel,request,response);var registerHttpModule=(input)=>{const source=Symbol("Gateway/NestSource");const handler=Symbol("Gateway/NestHandler");class HttpController{handleRequest;constructor(handleRequest){this.handleRequest=handleRequest}async handle(request,response){return await this.handleRequest(request,response)}}Controller()(HttpController);Inject(handler)(HttpController,undefined,0);const descriptor=Object.getOwnPropertyDescriptor(HttpController.prototype,"handle");if(descriptor===undefined){throw new TypeError("Missing Nest HTTP method")}All(input.routes)(HttpController.prototype,"handle",descriptor);Req()(HttpController.prototype,"handle",0);Res()(HttpController.prototype,"handle",1);class RegisteredHttpModule{}Module({})(RegisteredHttpModule);return{controllers:[HttpController],imports:input.options.imports??[],module:RegisteredHttpModule,providers:[{inject:input.options.inject??[],provide:source,useFactory:input.options.useFactory},{inject:[source],provide:handler,useFactory:input.createHandler}]}};var GatewayNestModule={registerAsync(options){return registerHttpModule({createHandler:createGatewayNestHandler,options,routes:["v1/*",".well-known/collective-intelligence-gateway"]})}};var CrudResourceNestModule={registerAsync(options){const path=options.path.replace(/\/$/u,"");return registerHttpModule({createHandler:(value)=>createGatewayNestHandler({handle:createResourceHttpHandler({...value,basePath:path})}),options,routes:[`${path}/*`]})}};var{bindNestOperation:bindNestOperation2,createGatewayNestHandler:createGatewayNestHandler2,CrudResourceNestModule:CrudResourceNestModule2,GatewayNestModule:GatewayNestModule2}=exports_nestjs;export{CrudResourceNestModule2 as CrudResourceNestModule,GatewayNestModule2 as GatewayNestModule,bindNestOperation2 as bindNestOperation,createGatewayNestHandler2 as createGatewayNestHandler};
|
|
1
|
+
var __defProp=Object.defineProperty;var __returnValue=(v)=>v;function __exportSetter(name,newValue){this[name]=__returnValue.bind(null,newValue)}var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true,configurable:true,set:__exportSetter.bind(all,name)})};var exports_nestjs={};__export(exports_nestjs,{CrudResourceNestModule:()=>CrudResourceNestModule,GatewayNestModule:()=>GatewayNestModule,bindNestOperation:()=>bindNestOperation,createGatewayNestHandler:()=>createGatewayNestHandler});import{All,Controller,Inject,Module,Req,Res}from"@nestjs/common";import{createEntityProtocol}from"@collective-intelligence/external-apps-client-sdk/resources";var unavailableBrand=Symbol.for("@collective-intelligence/external-apps-server-sdk/ApplicationUserAuthUnavailableError");class ApplicationUserAuthUnavailableError extends Error{[unavailableBrand]=true;code="user_auth_unavailable";static[Symbol.hasInstance](value){return value instanceof Error&&unavailableBrand in value&&value[unavailableBrand]===true&&"code"in value&&value.code==="user_auth_unavailable"}constructor(cause){super("Application user authentication is unavailable",{cause});this.name="ApplicationUserAuthUnavailableError"}}var credential=Symbol.for("@collective-intelligence/external-apps-server-sdk/ci-entity-invocation");var matchesEntityContext=(context,resourceId)=>context?.resourceId===resourceId&&context.applicationId.length>0&&context.user?.kind==="ci_user"&&context.user.id.length>0&&context.user.issuer===context.issuer&&context.user.organizationId===context.organizationId;var record=(value)=>typeof value==="object"&&value!==null&&!Array.isArray(value)?Object.fromEntries(Object.entries(value)):null;var json=(body,status,correlationId)=>Response.json(body,{headers:{"cache-control":"no-store","x-correlation-id":correlationId},status});var resourceResult=(result)=>{if(result.ok){return json(result,200,result.correlationId)}let status;switch(result.error.code){case"unauthenticated":{status=401;break}case"forbidden":{status=403;break}case"not_found":{status=404;break}case"conflict":{status=409;break}case"rate_limited":{status=429;break}case"unavailable":case"transport_error":{status=503;break}case"internal":{status=500;break}case"capability_not_supported":case"invalid_request":case"upload_not_supported":{status=400;break}default:{status=500}}return json(result,status,result.correlationId)};var resourceRequest=(request,body,resourceId,externalId,action,correlationId)=>{if(request.method==="POST"&&externalId===undefined&&(action==="scan"||action==="search")){const pagination=record(body.pagination);if(pagination===null||pagination.mode!=="cursor"&&pagination.mode!=="page"){return null}const query=body;return{operation:"list",query,requestId:correlationId,resourceId}}if(request.method==="GET"&&externalId!==undefined&&action===undefined){return{id:externalId,operation:"get",requestId:correlationId,resourceId}}if(request.method==="POST"&&externalId===undefined&&action==="records"){if(typeof body.idempotencyKey!=="string"||!("value"in body)){return null}return{idempotencyKey:body.idempotencyKey,operation:"create",requestId:correlationId,resourceId,value:body.value}}if(externalId===undefined||typeof body.expectedRevision!=="string"){return null}const idempotencyKey=typeof body.idempotencyKey==="string"?{idempotencyKey:body.idempotencyKey}:{};if(request.method==="PATCH"&&action===undefined&&"value"in body){return{expectedRevision:body.expectedRevision,id:externalId,...idempotencyKey,operation:"update",requestId:correlationId,resourceId,value:body.value}}const operation=request.method==="DELETE"&&action===undefined?"hard_delete":request.method==="POST"&&action==="soft-delete"?"soft_delete":request.method==="POST"&&action==="restore"?"restore":null;return operation===null?null:{expectedRevision:body.expectedRevision,id:externalId,...idempotencyKey,operation,requestId:correlationId,resourceId}};var readResourceBody=async(request,maximum)=>{if(Number(request.headers.get("content-length"))>maximum){await request.body?.cancel();return null}const reader=request.body?.getReader();if(reader===undefined){return null}const decoder=new TextDecoder("utf-8",{fatal:true});let size=0;let text="";try{for(;;){const{done,value}=await reader.read();if(done){break}size+=value.byteLength;if(size>maximum){await reader.cancel();return null}text+=decoder.decode(value,{stream:true})}text+=decoder.decode();const parsed=JSON.parse(text);if(typeof parsed!=="object"||parsed===null||Array.isArray(parsed)){return null}return Object.fromEntries(Object.entries(parsed))}catch{return null}finally{reader.releaseLock()}};var trimTrailingSlash=(value)=>value.endsWith("/")?value.slice(0,-1):value;var matchEntityHttpRoute=(pathname,basePath)=>{const prefix=trimTrailingSlash(basePath);if(!pathname.startsWith(`${prefix}/`)){return null}let parts;try{parts=pathname.slice(prefix.length+1).split("/").map(decodeURIComponent)}catch{return null}const[head,id,action]=parts;if(head==="search"&&parts.length===1){return{kind:"search"}}if(head==="records"&&parts.length===1){return{kind:"collection"}}if(head==="uploads"&&parts.length===1){return{kind:"uploads"}}if(head!=="records"||id===undefined||id.length===0){return null}if(parts.length===2){return{id,kind:"record"}}if(parts.length===3&&action==="soft-delete"){return{id,kind:"soft_delete"}}if(parts.length===3&&action==="restore"){return{id,kind:"restore"}}if(parts.length===4&&action==="relation-members"&&parts[3]==="search"){return{id,kind:"relation_members"}}return null};var decodeEntityRoute=(protocol,input,body)=>{if(input.operation==="list_members"){const{field,...query}=body;return protocol.decodeRequest({...input,field,query})}if(input.operation==="upload"){return protocol.decodeRequest({...body,...input})}if(input.operation!=="list"&&input.operation!=="get"){const allowed=["idempotencyKey"];if(input.operation!=="create"){allowed.push("expectedRevision")}if(input.operation==="create"||input.operation==="update"){allowed.push("value")}if(Object.keys(body).some((key)=>!allowed.includes(key))){return{correlationId:input.requestId,error:{code:"invalid_request",details:{issues:[{field:"",keyword:"additionalProperties"}]},message:"Request contains unsupported entity fields",retryable:false},ok:false}}}return protocol.decodeRequest({...input,operation:input.operation==="soft_delete"?"delete":input.operation})};var readResourceRoute=async(request,basePath,resourceId,requestId,maximum)=>{const invalid=(message)=>resourceResult({correlationId:requestId,error:{code:"invalid_request",message,retryable:false},ok:false});const path=new URL(request.url).pathname;const route=matchEntityHttpRoute(path,basePath);if(route===null){return new Response(null,{status:404})}const body=request.method==="GET"?{}:await readResourceBody(request,maximum);if(body===null){return invalid("Request body is invalid or exceeds its limit")}if(route.kind==="relation_members"){const member={operation:"list_members",parentId:route.id,requestId,resourceId};return request.method==="POST"?{body,input:member}:invalid("Invalid resource route or request")}if(route.kind==="uploads"){const upload={operation:"upload",requestId,resourceId};return request.method==="POST"?{body,input:upload}:invalid("Invalid resource route or request")}let externalId;let action;switch(route.kind){case"search":{action="search";break}case"collection":{action="records";break}case"record":{externalId=route.id;break}case"soft_delete":{action="soft-delete";externalId=route.id;break}case"restore":{action="restore";externalId=route.id;break}default:{break}}const input=resourceRequest(request,body,resourceId,externalId,action,requestId);return input===null?invalid("Invalid resource route or request"):{body,input}};var createResourceHttpHandler=(options)=>{const protocol="executeCrud"in options.resource?null:createEntityProtocol(options.resource.definition);return async(request)=>{const requestId=request.headers.get("x-correlation-id")?.match(/^[\w.-]{1,128}$/u)?.[0]??crypto.randomUUID();const{resource}=options;const route=await readResourceRoute(request,options.basePath,resource.definition.id,requestId,options.maxBodyBytes??1048576);if(route instanceof Response){return route}const{body,input}=route;const decoded=protocol===null?null:decodeEntityRoute(protocol,input,body);if(decoded!==null&&!decoded.ok){return resourceResult(decoded)}try{const operation=decoded?.ok?decoded.value.operation:input.operation;const authorized=await options.authorize(request,operation);if(authorized instanceof Response){return authorized}if(!matchesEntityContext(authorized,resource.definition.id)){return resourceResult({correlationId:requestId,error:{code:"forbidden",message:"The current identity is not authorized for this resource",retryable:false},ok:false})}if("executeCrud"in resource){return input.operation==="upload"||input.operation==="list_members"?new Response(null,{status:404}):resourceResult(await resource.executeCrud(input,authorized))}if(decoded?.ok){return resourceResult(await resource.execute(decoded.value,authorized,{signal:request.signal}))}throw new TypeError("Entity request was not decoded")}catch(error){return resourceResult({correlationId:requestId,error:{code:error instanceof ApplicationUserAuthUnavailableError?"unavailable":"internal",message:"Resource authorization or execution is unavailable",retryable:false},ok:false})}}};var headersFromNode=(input)=>{const headers=new Headers;for(const[name,value]of Object.entries(input)){if(typeof value==="string"){headers.set(name,value)}else if(Array.isArray(value)){headers.set(name,value.join(", "))}}return headers};var nodeChunk=(chunk)=>{if(typeof chunk==="string"){return new TextEncoder().encode(chunk)}return chunk};var bodyFromNode=(request,onBodyCancelled)=>{if(request.body!==undefined){return typeof request.body==="string"?request.body:JSON.stringify(request.body)}const iterator=request.iterator?.({destroyOnReturn:false})??request[Symbol.asyncIterator]?.();if(iterator===undefined){return}return new ReadableStream({cancel:async()=>{onBodyCancelled?.();await iterator.return?.()},pull:async(controller)=>{try{const next=await iterator.next();if(next.done===true){controller.close()}else{controller.enqueue(nodeChunk(next.value))}}catch(error){controller.error(error)}}},{highWaterMark:0})};var webRequestFromNode=async(request,signal,onBodyCancelled)=>{const method=request.method??"GET";const headers=headersFromNode(request.headers);const host=headers.get("host")??"gateway.local";const protocol=request.protocol??"http";const url=new URL(request.originalUrl??request.url??"/",`${protocol}://${host}`);const body=method==="GET"||method==="HEAD"?undefined:bodyFromNode(request,onBodyCancelled);const requestInit={headers,method,signal};if(body!==undefined){requestInit.body=body;requestInit.duplex="half"}return new Request(url,requestInit)};var sendWebResponseToNode=async(response,result)=>{if(response.status===undefined){response.statusCode=result.status}else{response.status(result.status)}for(const[name,value]of result.headers){if(response.setHeader===undefined){response.header?.(name,value)}else{response.setHeader(name,value)}}if(result.body===null){response.end();return}const reader=result.body.getReader();while(true){const next=await reader.read();if(next.done){break}response.write?.(next.value)}response.end()};var handleNodeRequest=async(kernel,request,response)=>{const controller=new AbortController;const onAborted=()=>{controller.abort()};request.once?.("aborted",onAborted);response?.once?.("close",onAborted);try{let bodyCancelled=false;let result=await kernel.handle(await webRequestFromNode(request,controller.signal,()=>{bodyCancelled=true}));if(bodyCancelled){const headers=new Headers(result.headers);headers.set("connection","close");result=new Response(result.body,{headers,status:result.status,statusText:result.statusText})}if(response!==undefined){await sendWebResponseToNode(response,result.clone())}return result}finally{request.off?.("aborted",onAborted);response?.off?.("close",onAborted)}};var defineOperation=(definition)=>Object.freeze(definition);var brand=Symbol.for("@collective-intelligence/external-apps-server-sdk/GatewayOperationError");class GatewayOperationError extends Error{[brand]=true;code;static[Symbol.hasInstance](value){return value instanceof Error&&brand in value&&value[brand]===true&&"code"in value&&(value.code==="authorization_denied"||value.code==="capability_not_supported"||value.code==="invalid_request")}constructor(code,message){super(message.slice(0,512));this.code=code;this.name="GatewayOperationError"}}var bindNestOperation=(binding)=>defineOperation({...binding.declaration,handler:async(request)=>{request.signal.throwIfAborted();const input=await binding.normalize(request);request.signal.throwIfAborted();const normalized={...request,input};if(!await binding.authorize(normalized)){throw new GatewayOperationError("authorization_denied","Application authorization denied")}request.signal.throwIfAborted();return await binding.execute(normalized)}});var createGatewayNestHandler=(kernel)=>async(request,response)=>await handleNodeRequest(kernel,request,response);var registerHttpModule=(input)=>{const source=Symbol("Gateway/NestSource");const handler=Symbol("Gateway/NestHandler");class HttpController{handleRequest;constructor(handleRequest){this.handleRequest=handleRequest}async handle(request,response){return await this.handleRequest(request,response)}}Controller()(HttpController);Inject(handler)(HttpController,undefined,0);const descriptor=Object.getOwnPropertyDescriptor(HttpController.prototype,"handle");if(descriptor===undefined){throw new TypeError("Missing Nest HTTP method")}All(input.routes)(HttpController.prototype,"handle",descriptor);Req()(HttpController.prototype,"handle",0);Res()(HttpController.prototype,"handle",1);class RegisteredHttpModule{}Module({})(RegisteredHttpModule);return{controllers:[HttpController],imports:input.options.imports??[],module:RegisteredHttpModule,providers:[{inject:input.options.inject??[],provide:source,useFactory:input.options.useFactory},{inject:[source],provide:handler,useFactory:input.createHandler}]}};var GatewayNestModule={registerAsync(options){return registerHttpModule({createHandler:createGatewayNestHandler,options,routes:["v1/*",".well-known/collective-intelligence-gateway"]})}};var CrudResourceNestModule={registerAsync(options){const path=options.path.replace(/\/$/u,"");return registerHttpModule({createHandler:(value)=>createGatewayNestHandler({handle:createResourceHttpHandler({...value,basePath:path})}),options,routes:[`${path}/*`]})}};var{bindNestOperation:bindNestOperation2,createGatewayNestHandler:createGatewayNestHandler2,CrudResourceNestModule:CrudResourceNestModule2,GatewayNestModule:GatewayNestModule2}=exports_nestjs;export{CrudResourceNestModule2 as CrudResourceNestModule,GatewayNestModule2 as GatewayNestModule,bindNestOperation2 as bindNestOperation,createGatewayNestHandler2 as createGatewayNestHandler};
|