monorise 1.14.1 → 2.0.0-dev.1

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.
Files changed (34) hide show
  1. package/dist/base/index.d.ts +227 -1
  2. package/dist/base/index.js +383 -1
  3. package/dist/base/index.js.map +1 -1
  4. package/dist/cli/cli.js +295 -122
  5. package/dist/cli/cli.js.map +1 -1
  6. package/dist/cli/templates/files/api-keys.ts +12 -0
  7. package/dist/cli/templates/files/monorise.config.ts +2 -0
  8. package/dist/cli/templates/files/proxy-route.ts +12 -22
  9. package/dist/cli/templates/files/sst.config.ts +4 -1
  10. package/dist/cli/templates/files/ws-ticket-route.ts +21 -0
  11. package/dist/core/index.d.ts +63 -36
  12. package/dist/core/index.js +783 -208
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/index.d.ts +24 -7
  15. package/dist/proxy/index.d.ts +275 -2
  16. package/dist/proxy/index.js +696 -37
  17. package/dist/proxy/index.js.map +1 -1
  18. package/dist/react/index.d.ts +2 -164
  19. package/dist/react/index.d.ts.map +1 -1
  20. package/dist/react/index.js +46 -188
  21. package/dist/react/index.js.map +1 -1
  22. package/dist/react/lib/api.d.ts +1 -2
  23. package/dist/react/lib/api.d.ts.map +1 -1
  24. package/dist/react/store/monorise.store.d.ts +0 -54
  25. package/dist/react/store/monorise.store.d.ts.map +1 -1
  26. package/dist/sst/components/monorise-core.d.ts.map +1 -1
  27. package/dist/sst/index.js +4 -1
  28. package/dist/sst/index.js.map +1 -1
  29. package/package.json +1 -1
  30. package/dist/cli/templates/files/proxy-request.ts +0 -50
  31. package/dist/react/actions/auth.action.d.ts +0 -24
  32. package/dist/react/actions/auth.action.d.ts.map +0 -1
  33. package/dist/react/services/auth.service.d.ts +0 -21
  34. package/dist/react/services/auth.service.d.ts.map +0 -1
@@ -1,13 +1,13 @@
1
- import { Entity as Entity$2, EntitySchemaMap, createEntityConfig, WhereConditions } from '../base/index';
1
+ import { Entity as Entity$2, EntitySchemaMap, createEntityConfig, WhereConditions, ApiKeyPolicies, ApiKeyRoutePermission, CompiledApiKeyPolicy } from '../base/index';
2
2
  import * as hono from 'hono';
3
- import { Hono } from 'hono';
3
+ import { Hono, MiddlewareHandler } from 'hono';
4
4
  import * as _aws_sdk_client_dynamodb from '@aws-sdk/client-dynamodb';
5
5
  import { DynamoDB, TransactWriteItemsInput, AttributeValue, TransactWriteItem, UpdateItemCommandInput, DynamoDBClient } from '@aws-sdk/client-dynamodb';
6
6
  import * as hono_utils_http_status from 'hono/utils/http-status';
7
7
  import * as hono_utils_types from 'hono/utils/types';
8
8
  import { createFactory } from 'hono/factory';
9
- import httpStatus4 from 'http-status';
10
9
  import { unmarshall, marshall } from '@aws-sdk/util-dynamodb';
10
+ import { AsyncLocalStorage } from 'async_hooks';
11
11
  import { EventBridgeClient } from '@aws-sdk/client-eventbridge';
12
12
  import { AthenaClient } from '@aws-sdk/client-athena';
13
13
  import { FirehoseClient } from '@aws-sdk/client-firehose';
@@ -566,22 +566,8 @@ var Entity = class _Entity extends Item {
566
566
  };
567
567
  }
568
568
  };
569
- var factory = createFactory();
570
- var API_KEYS = process.env.API_KEYS ? JSON.parse(process.env.API_KEYS) : [];
571
- factory.createMiddleware((c, next) => __async(null, null, function* () {
572
- const xApiKey = c.req.header("x-api-key");
573
- if (c.req.url.match(/^\/core\/public\//)) {
574
- return yield next();
575
- }
576
- if (!xApiKey || Array.isArray(xApiKey) || !API_KEYS.includes(xApiKey)) {
577
- c.status(httpStatus4.UNAUTHORIZED);
578
- return c.json({
579
- status: httpStatus4.UNAUTHORIZED,
580
- message: httpStatus4["401_MESSAGE"]
581
- });
582
- }
583
- return yield next();
584
- }));
569
+ new AsyncLocalStorage();
570
+ createFactory();
585
571
 
586
572
  // helpers/event.ts
587
573
  new EventBridgeClient();
@@ -4564,7 +4550,7 @@ declare class EntityServiceLifeCycle {
4564
4550
  private publishEvent;
4565
4551
  private eventUtils;
4566
4552
  constructor(EntityConfig: any, publishEvent: typeof publishEvent, eventUtils: EventUtils);
4567
- afterCreateEntityHook<T extends Entity$2>(entity: Entity$1<T>, entityPayload?: Record<string, unknown>, accountId?: string | string[]): Promise<void>;
4553
+ afterCreateEntityHook<T extends Entity$2>(entity: Entity$1<T>, entityPayload?: Record<string, unknown>): Promise<void>;
4568
4554
  }
4569
4555
 
4570
4556
  declare class EntityService {
@@ -4574,38 +4560,34 @@ declare class EntityService {
4574
4560
  private publishEvent;
4575
4561
  private entityServiceLifeCycle;
4576
4562
  constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, EmailAuthEnabledEntities: Entity$2[], entityRepository: EntityRepository, publishEvent: typeof publishEvent, entityServiceLifeCycle: EntityServiceLifeCycle);
4577
- createEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, options, }: {
4563
+ createEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, options, }: {
4578
4564
  entityType: T;
4579
4565
  entityPayload: EntitySchemaMap[T] | Record<string, any>;
4580
4566
  entityId?: string;
4581
- accountId?: string | string[];
4582
4567
  options?: {
4583
4568
  createAndUpdateDatetime?: string;
4584
4569
  mutualId?: string;
4585
4570
  };
4586
4571
  }) => Promise<Entity<T>>;
4587
- adjustEntity: <T extends Entity$2>({ entityType, entityId, adjustments, accountId, condition, }: {
4572
+ adjustEntity: <T extends Entity$2>({ entityType, entityId, adjustments, condition, }: {
4588
4573
  entityType: T;
4589
4574
  entityId: string;
4590
4575
  adjustments: Record<string, number>;
4591
- accountId?: string;
4592
4576
  condition?: string;
4593
4577
  }) => Promise<Entity<T>>;
4594
- updateEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, condition, where, }: {
4578
+ updateEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, condition, where, }: {
4595
4579
  entityType: T;
4596
4580
  entityId: string;
4597
4581
  entityPayload: Partial<EntitySchemaMap[T]>;
4598
- accountId?: string | string[];
4599
4582
  condition?: string;
4600
4583
  /** @deprecated Use `condition` (named condition) instead of raw `where`. */
4601
4584
  where?: WhereConditions;
4602
4585
  }) => Promise<Entity<T>>;
4603
4586
  /** @deprecated Converts legacy adjustmentConstraints to condition expression opts. */
4604
4587
  private buildLegacyAdjustCondition;
4605
- deleteEntity: <T extends Entity$2>({ entityType, entityId, accountId, }: {
4588
+ deleteEntity: <T extends Entity$2>({ entityType, entityId, }: {
4606
4589
  entityType: T;
4607
4590
  entityId: string;
4608
- accountId?: string | string[];
4609
4591
  }) => Promise<void>;
4610
4592
  }
4611
4593
 
@@ -4686,7 +4668,6 @@ type CreateMutualParams<B extends Entity$2, T extends Entity$2, A extends Entity
4686
4668
  entityType: T;
4687
4669
  entityId: string;
4688
4670
  mutualPayload?: Record<string, unknown>;
4689
- accountId?: string | string[];
4690
4671
  options?: {
4691
4672
  asEntity?: A;
4692
4673
  mutualId?: string;
@@ -4751,7 +4732,6 @@ declare class MutualService {
4751
4732
  parsedMutualPayload: {
4752
4733
  [x: string]: any;
4753
4734
  };
4754
- accountId: string | string[] | undefined;
4755
4735
  publishedAt: string;
4756
4736
  };
4757
4737
  }>;
@@ -4787,13 +4767,12 @@ declare class MutualService {
4787
4767
  TransactItems: _aws_sdk_client_dynamodb.TransactWriteItem[];
4788
4768
  parsedMutualPayload: Record<string, unknown>;
4789
4769
  }>;
4790
- updateMutual: <B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>({ byEntityType, byEntityId, entityType, entityId, mutualPayload, accountId, options, }: {
4770
+ updateMutual: <B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>({ byEntityType, byEntityId, entityType, entityId, mutualPayload, options, }: {
4791
4771
  byEntityType: B;
4792
4772
  byEntityId: string;
4793
4773
  entityType: T;
4794
4774
  entityId: string;
4795
4775
  mutualPayload: M;
4796
- accountId?: string | string[];
4797
4776
  options?: {
4798
4777
  maxObjectUpdateLevel?: number;
4799
4778
  returnUpdatedValue?: boolean;
@@ -4813,12 +4792,11 @@ declare class MutualService {
4813
4792
  mutual: Mutual<Entity$2, Entity$2, Record<string, unknown>>;
4814
4793
  TransactItems: _aws_sdk_client_dynamodb.TransactWriteItem[];
4815
4794
  }>;
4816
- deleteMutual: ({ byEntityType, byEntityId, entityType, entityId, accountId, }: {
4795
+ deleteMutual: ({ byEntityType, byEntityId, entityType, entityId, }: {
4817
4796
  byEntityType: Entity$2;
4818
4797
  byEntityId: string;
4819
4798
  entityType: Entity$2;
4820
4799
  entityId: string;
4821
- accountId?: string | string[];
4822
4800
  }) => Promise<Mutual<Entity$2, Entity$2, Record<string, unknown>>>;
4823
4801
  }
4824
4802
 
@@ -4952,7 +4930,7 @@ declare class TransactionService {
4952
4930
  private eventUtils;
4953
4931
  private mutualService?;
4954
4932
  constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, EmailAuthEnabledEntities: Entity$2[], entityRepository: EntityRepository, dynamodbClient: DynamoDB, publishEvent: typeof publishEvent, entityServiceLifeCycle: EntityServiceLifeCycle, eventUtils: EventUtils, mutualService?: MutualService | undefined);
4955
- executeTransaction: (operations: TransactionOperation[], accountId?: string) => Promise<TransactionResult>;
4933
+ executeTransaction: (operations: TransactionOperation[]) => Promise<TransactionResult>;
4956
4934
  private processOperation;
4957
4935
  private processCreateMutual;
4958
4936
  private processUpdateMutual;
@@ -4988,6 +4966,8 @@ declare class DependencyContainer {
4988
4966
  EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
4989
4967
  AllowedEntityTypes: Entity$2[];
4990
4968
  EmailAuthEnabledEntities: Entity$2[];
4969
+ /** Policies from the file `apiKeys` points to in monorise.config.ts. */
4970
+ ApiKeyPolicies?: ApiKeyPolicies;
4991
4971
  tableName?: string;
4992
4972
  };
4993
4973
  private _instanceCache;
@@ -4997,6 +4977,8 @@ declare class DependencyContainer {
4997
4977
  EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
4998
4978
  AllowedEntityTypes: Entity$2[];
4999
4979
  EmailAuthEnabledEntities: Entity$2[];
4980
+ /** Policies from the file `apiKeys` points to in monorise.config.ts. */
4981
+ ApiKeyPolicies?: ApiKeyPolicies;
5000
4982
  tableName?: string;
5001
4983
  });
5002
4984
  createCachedInstance<T extends new (...args: any[]) => any>(ClassRef: T, ...args: ConstructorParameters<T>): InstanceType<T>;
@@ -5223,6 +5205,50 @@ declare const transactional: {
5223
5205
  deleteMutual: <B extends Entity$2, T extends Entity$2>(byEntityType: B, entityType: T, byEntityId: string, entityId: string) => TransactionDeleteMutual<B, T>;
5224
5206
  };
5225
5207
 
5208
+ /**
5209
+ * `read` is get, by ID or unique field. `list` is listing the whole type,
5210
+ * which also needs `read`.
5211
+ */
5212
+ type EntityAction = 'read' | 'list' | 'create' | 'update' | 'delete';
5213
+ /**
5214
+ * Declares the permission a custom route requires. Policies grant it by name
5215
+ * in `routes`; `full` keys always pass. Works per route or on a group:
5216
+ *
5217
+ * @example
5218
+ * ```ts
5219
+ * app.post('/checkout', requires('checkout'), handler);
5220
+ * app.use('/reports/*', requires('reports'));
5221
+ * ```
5222
+ */
5223
+ declare const requires: (permission: ApiKeyRoutePermission) => MiddlewareHandler;
5224
+
5225
+ type ApiKeyPrincipal = {
5226
+ /** Name of the policy the request's key maps to, e.g. `'full'`. */
5227
+ policy: string;
5228
+ /** SHA-256 hex digest of the key. Safe to log or store; the key itself is not. */
5229
+ fingerprint: string;
5230
+ /** What the policy grants, per entity type and relationship direction. */
5231
+ access: CompiledApiKeyPolicy;
5232
+ /**
5233
+ * Whether the policy allows an action on an entity type, and on every
5234
+ * listed field when `fields` is given. `read` is get by ID; `list` is
5235
+ * listing the whole type.
5236
+ */
5237
+ can(action: EntityAction, entityType: string, fields?: readonly string[]): boolean;
5238
+ /** Whether the policy grants a custom route permission. */
5239
+ has(permission: ApiKeyRoutePermission): boolean;
5240
+ /**
5241
+ * An entity, tag or relationship record with the fields the key cannot read
5242
+ * removed from `data` (and `mutualData`). Accepts an `Entity` or its JSON.
5243
+ */
5244
+ mask<T extends object>(entityType: string, entity: T): Record<string, unknown>;
5245
+ };
5246
+ declare module 'hono' {
5247
+ interface ContextVariableMap {
5248
+ apiKey: ApiKeyPrincipal;
5249
+ }
5250
+ }
5251
+
5226
5252
  declare class CoreFactory {
5227
5253
  private config;
5228
5254
  setupCommonRoutes: ReturnType<typeof setupCommonRoutes>;
@@ -5243,7 +5269,8 @@ declare class CoreFactory {
5243
5269
  EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
5244
5270
  AllowedEntityTypes: Entity$2[];
5245
5271
  EmailAuthEnabledEntities: Entity$2[];
5272
+ ApiKeyPolicies?: ApiKeyPolicies;
5246
5273
  });
5247
5274
  }
5248
5275
 
5249
- export { DependencyContainer, Entity$1 as Entity, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, TransactionService, WebSocketRepository, handler$7 as analyticsBackfillProcessor, handler$6 as analyticsMaterializationProcessor, handler$5 as analyticsModelProcessor, handler$8 as analyticsProcessor, analyticsQueryHandler, handler$4 as analyticsViewProcessor, appHandler, handler$9 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, setupCommonRoutes, startBackfill as startAnalyticsBackfill, handler as tagProcessor, transactional, broadcast as wsBroadcast, connect as wsConnect, $default as wsDefault, disconnect as wsDisconnect };
5276
+ export { type ApiKeyPrincipal, DependencyContainer, Entity$1 as Entity, type EntityAction, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, TransactionService, WebSocketRepository, handler$7 as analyticsBackfillProcessor, handler$6 as analyticsMaterializationProcessor, handler$5 as analyticsModelProcessor, handler$8 as analyticsProcessor, analyticsQueryHandler, handler$4 as analyticsViewProcessor, appHandler, handler$9 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, requires, setupCommonRoutes, startBackfill as startAnalyticsBackfill, handler as tagProcessor, transactional, broadcast as wsBroadcast, connect as wsConnect, $default as wsDefault, disconnect as wsDisconnect };