monorise 1.8.0-dev.0 → 1.8.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.
- package/dist/cli/cli.js +239 -153
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/templates/files/proxy-request.ts +2 -1
- package/dist/cli/templates/files/sst.config.ts +5 -4
- package/dist/core/index.d.ts +54 -12
- package/dist/core/index.js +484 -135
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +106 -4
- package/dist/react/actions/core.action.d.ts.map +1 -1
- package/dist/react/helpers/transactional.d.ts +40 -0
- package/dist/react/helpers/transactional.d.ts.map +1 -0
- package/dist/react/index.d.ts +4 -17
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +390 -25645
- package/dist/react/index.js.map +1 -1
- package/dist/react/lib/utils.d.ts +7 -0
- package/dist/react/lib/utils.d.ts.map +1 -1
- package/dist/react/services/core.service.d.ts +2 -8
- package/dist/react/services/core.service.d.ts.map +1 -1
- package/dist/sst/components/analytics.d.ts +26 -6
- package/dist/sst/components/analytics.d.ts.map +1 -1
- package/dist/sst/components/monorise-core.d.ts +1 -0
- package/dist/sst/components/monorise-core.d.ts.map +1 -1
- package/dist/sst/components/single-table.d.ts +1 -0
- package/dist/sst/components/single-table.d.ts.map +1 -1
- package/dist/sst/index.js +173 -67
- package/dist/sst/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/react/bowser-RUCNDTEX.js +0 -2822
- package/dist/react/bowser-RUCNDTEX.js.map +0 -1
- package/dist/react/chunk-2U2REJF4.js +0 -138
- package/dist/react/chunk-2U2REJF4.js.map +0 -1
- package/dist/react/chunk-5CPIG7AN.js +0 -449
- package/dist/react/chunk-5CPIG7AN.js.map +0 -1
- package/dist/react/chunk-7BSJSLIL.js +0 -528
- package/dist/react/chunk-7BSJSLIL.js.map +0 -1
- package/dist/react/chunk-7MNBSDJI.js +0 -3362
- package/dist/react/chunk-7MNBSDJI.js.map +0 -1
- package/dist/react/chunk-JXBFOCBM.js +0 -2929
- package/dist/react/chunk-JXBFOCBM.js.map +0 -1
- package/dist/react/chunk-MIXAYX55.js +0 -147
- package/dist/react/chunk-MIXAYX55.js.map +0 -1
- package/dist/react/chunk-Q26JGAFF.js +0 -47
- package/dist/react/chunk-Q26JGAFF.js.map +0 -1
- package/dist/react/chunk-QZSEUOCY.js +0 -2298
- package/dist/react/chunk-QZSEUOCY.js.map +0 -1
- package/dist/react/chunk-W6S3JWZV.js +0 -1045
- package/dist/react/chunk-W6S3JWZV.js.map +0 -1
- package/dist/react/chunk-WUOPYF3V.js +0 -127
- package/dist/react/chunk-WUOPYF3V.js.map +0 -1
- package/dist/react/chunk-Z45ECZFO.js +0 -995
- package/dist/react/chunk-Z45ECZFO.js.map +0 -1
- package/dist/react/dist-es-2P6AKQM3.js +0 -325
- package/dist/react/dist-es-2P6AKQM3.js.map +0 -1
- package/dist/react/dist-es-CEMZ6HT6.js +0 -294
- package/dist/react/dist-es-CEMZ6HT6.js.map +0 -1
- package/dist/react/dist-es-NZWWHEBR.js +0 -89
- package/dist/react/dist-es-NZWWHEBR.js.map +0 -1
- package/dist/react/dist-es-QVQ2CPIM.js +0 -376
- package/dist/react/dist-es-QVQ2CPIM.js.map +0 -1
- package/dist/react/dist-es-VBWII54H.js +0 -70
- package/dist/react/dist-es-VBWII54H.js.map +0 -1
- package/dist/react/dist-es-VXN7IC3J.js +0 -23
- package/dist/react/dist-es-VXN7IC3J.js.map +0 -1
- package/dist/react/dist-es-YKVDPOOB.js +0 -221
- package/dist/react/dist-es-YKVDPOOB.js.map +0 -1
- package/dist/react/dist-es-ZPOY2Z6R.js +0 -178
- package/dist/react/dist-es-ZPOY2Z6R.js.map +0 -1
- package/dist/react/event-streams-NBH35WQC.js +0 -44
- package/dist/react/event-streams-NBH35WQC.js.map +0 -1
- package/dist/react/loadSso-2GPAQE3H.js +0 -583
- package/dist/react/loadSso-2GPAQE3H.js.map +0 -1
- package/dist/react/signin-HT4EDHQE.js +0 -821
- package/dist/react/signin-HT4EDHQE.js.map +0 -1
- package/dist/react/sso-oidc-WA3BK6FI.js +0 -830
- package/dist/react/sso-oidc-WA3BK6FI.js.map +0 -1
- package/dist/react/sts-V7PNNQ2L.js +0 -1114
- package/dist/react/sts-V7PNNQ2L.js.map +0 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Entity } from '../../base/index';
|
|
2
2
|
export declare const convertToMap: <T extends Record<string, any>>(data: T[], mapKey: string) => Map<any, any>;
|
|
3
3
|
export declare const getMutualStateKey: (byEntity: Entity, byEntityId: string | null, entity: Entity, entityId?: string, chainEntityQuery?: string) => string;
|
|
4
|
+
export declare const parseMutualStateKey: (stateKey: string) => {
|
|
5
|
+
byEntity: Entity;
|
|
6
|
+
byEntityId: string;
|
|
7
|
+
entity: Entity;
|
|
8
|
+
entityId: string;
|
|
9
|
+
chainEntityQuery: string | undefined;
|
|
10
|
+
};
|
|
4
11
|
export declare const getTagStateKey: (entityType: Entity, tagName: string, params?: Record<string, string>) => string;
|
|
5
12
|
export declare const getUniqueFieldStateKey: (fieldName: string, fieldValue: string) => string;
|
|
6
13
|
export declare const getEntityRequestKey: (mode: "create" | "upsert" | "edit" | "adjust" | "delete" | "get" | "list" | "search", entityType: Entity, entityId?: string) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxD,MAAM,CAAC,EAAE,EACT,QAAQ,MAAM,kBASf,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,UAAU,MAAM,EAChB,YAAY,MAAM,GAAG,IAAI,EACzB,QAAQ,MAAM,EACd,WAAW,MAAM,EACjB,mBAAmB,MAAM,WAG1B,CAA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AAM,WAG1B,CAAC;AAIF,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM;cAQf,MAAM;;YAEV,MAAM;;;CAItC,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,YAAY,MAAM,EAClB,SAAS,MAAM,EACf,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,WASpC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,WAAW,MAAM,EACjB,YAAY,MAAM,WAGnB,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,EACpF,YAAY,MAAM,EAClB,WAAW,MAAM,WAGlB,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,EACrD,cAAc,MAAM,EACpB,YAAY,MAAM,EAClB,YAAY,MAAM,GAAG,IAAI,EACzB,WAAW,MAAM,EACjB,mBAAmB,MAAM,WAG1B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,EACZ,YAAY,MAAM,EAClB,SAAS,MAAM,EACf,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,WAGpC,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,YAAY,MAAM,EAClB,WAAW,MAAM,EACjB,OAAO,MAAM,WAGd,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CreatedEntity, DraftEntity, Entity } from '../../base/index';
|
|
2
2
|
import type { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import type { TransactionOperation } from '../helpers/transactional';
|
|
3
4
|
import type { MonoriseStore } from '../store/monorise.store';
|
|
4
5
|
import type { ApplicationRequestError, AxiosInterceptor } from '../types/api.type';
|
|
5
6
|
import type { Mutual, MutualData } from '../types/mutual.type';
|
|
@@ -73,14 +74,7 @@ declare const initCoreService: (monoriseStore: MonoriseStore, axios: AxiosInterc
|
|
|
73
74
|
editMutual: (byEntityId: string, entityId: string, payload: MutualData<B, T> | Record<string, unknown>, opts?: {}) => Promise<import("axios").AxiosResponse<Mutual<B, T>, any, {}>>;
|
|
74
75
|
deleteMutual: (byEntityId: string, entityId: string, opts?: CommonOptions) => Promise<import("axios").AxiosResponse<any, any, {}>>;
|
|
75
76
|
};
|
|
76
|
-
transaction: (operations:
|
|
77
|
-
operation: "createEntity" | "updateEntity" | "adjustEntity" | "deleteEntity";
|
|
78
|
-
entityType: Entity;
|
|
79
|
-
entityId?: string;
|
|
80
|
-
payload?: Record<string, unknown>;
|
|
81
|
-
adjustments?: Record<string, number>;
|
|
82
|
-
condition?: string;
|
|
83
|
-
}>, opts?: CommonOptions) => Promise<import("axios").AxiosResponse<any, any, {}>>;
|
|
77
|
+
transaction: (operations: TransactionOperation[], opts?: CommonOptions) => Promise<import("axios").AxiosResponse<any, any, {}>>;
|
|
84
78
|
setOptions: (opts: ConfigOptions) => void;
|
|
85
79
|
};
|
|
86
80
|
export default initCoreService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.service.d.ts","sourceRoot":"","sources":["../../services/core.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"core.service.d.ts","sourceRoot":"","sources":["../../services/core.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AASrE,OAAO,KAAK,EAAE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8BA5PT,oBAAoB,EAAE,SAC5B,aAAa;uBA+PK,aAAa;CAaxC,CAAC;AAEF,eAAe,eAAe,CAAC;AAE/B,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -5,9 +5,6 @@ export type SuppliedAnalyticsResources = {
|
|
|
5
5
|
/** Set only when this bucket has no existing notifications and Monorise may manage them. */
|
|
6
6
|
notificationsManaged?: boolean;
|
|
7
7
|
};
|
|
8
|
-
key?: {
|
|
9
|
-
arn: $util.Input<string>;
|
|
10
|
-
};
|
|
11
8
|
glueDatabase?: {
|
|
12
9
|
name: $util.Input<string>;
|
|
13
10
|
};
|
|
@@ -27,15 +24,37 @@ export type AnalyticsArgs = {
|
|
|
27
24
|
importedTable?: {
|
|
28
25
|
pointInTimeRecoveryEnabled: true;
|
|
29
26
|
};
|
|
27
|
+
/** Server-to-server API for executing only these named Athena queries. */
|
|
28
|
+
queryApi?: {
|
|
29
|
+
enabled?: boolean;
|
|
30
|
+
queries: Record<string, {
|
|
31
|
+
sql: string;
|
|
32
|
+
parameters?: Record<string, {
|
|
33
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'timestamp';
|
|
34
|
+
}>;
|
|
35
|
+
/** Reuse an identical Athena result for this many minutes. Athena does not detect source-data changes. */
|
|
36
|
+
resultReuse?: {
|
|
37
|
+
maxAgeMinutes: number;
|
|
38
|
+
};
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
41
|
+
/** Deployment-managed reusable Athena views. */
|
|
42
|
+
views?: Record<string, {
|
|
43
|
+
sql: string;
|
|
44
|
+
}>;
|
|
45
|
+
/** Scheduled Iceberg tables refreshed over a trailing time window. */
|
|
46
|
+
models?: Record<string, {
|
|
47
|
+
sql: string;
|
|
48
|
+
schedule: string;
|
|
49
|
+
partitionColumn: string;
|
|
50
|
+
lookbackDays?: number;
|
|
51
|
+
}>;
|
|
30
52
|
};
|
|
31
53
|
export declare class Analytics {
|
|
32
54
|
readonly bucket: {
|
|
33
55
|
arn: $util.Input<string>;
|
|
34
56
|
name: $util.Input<string>;
|
|
35
57
|
};
|
|
36
|
-
readonly key: {
|
|
37
|
-
arn: $util.Input<string>;
|
|
38
|
-
};
|
|
39
58
|
readonly glueDatabase: {
|
|
40
59
|
name: $util.Input<string>;
|
|
41
60
|
};
|
|
@@ -45,6 +64,7 @@ export declare class Analytics {
|
|
|
45
64
|
readonly deliveryStream: aws.kinesis.FirehoseDeliveryStream;
|
|
46
65
|
readonly dlq: sst.aws.Queue;
|
|
47
66
|
readonly schedule: sst.aws.CronV2;
|
|
67
|
+
readonly queryApi?: sst.aws.ApiGatewayV2;
|
|
48
68
|
readonly processorFunctionName: string;
|
|
49
69
|
readonly backfillFunctionName: string;
|
|
50
70
|
constructor(id: string, args: AnalyticsArgs, table: sst.aws.Dynamo, alarmTopic: sst.aws.SnsTopic, configRoot?: string, logging?: sst.aws.FunctionArgs['logging']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../components/analytics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../components/analytics.ts"],"names":[],"mappings":"AA6BA,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,CAAC,EAAE;QACP,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1B,4FAA4F;QAC5F,oBAAoB,CAAC,EAAE,OAAO,CAAC;KAChC,CAAC;IACF,YAAY,CAAC,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IAC7C,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,aAA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AAG;IAC7B,aAAa,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD,mBAAmB,CAAC,EAAE;QACpB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,yEAAyE;IACzE,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF,qBAAa,YAAY;IACvB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC;IAC1C,SAAgB,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;IACjC,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,SAAgB,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC7C,SAAgB,SAAS,CAAC,EAAE,SAAS,CAAC;gBAE1B,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB;CAqOhD"}
|
|
@@ -2,6 +2,7 @@ type SingleTableArgs = {
|
|
|
2
2
|
runtime?: sst.aws.FunctionArgs['runtime'];
|
|
3
3
|
logging?: sst.aws.FunctionArgs['logging'];
|
|
4
4
|
configRoot?: string;
|
|
5
|
+
pointInTimeRecoveryEnabled?: boolean;
|
|
5
6
|
/**
|
|
6
7
|
* Name of an existing DynamoDB table to use instead of creating a new one.
|
|
7
8
|
* The table must already have DynamoDB Streams enabled with NEW_AND_OLD_IMAGES,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-table.d.ts","sourceRoot":"","sources":["../../components/single-table.ts"],"names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SAAgB,sBAAsB,EAAE,MAAM,CAAC;gBAEnC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe;CAoF/C"}
|
package/dist/sst/index.js
CHANGED
|
@@ -273,6 +273,31 @@ function createFunctionWidgets(title, functionName, y, region, dlqName) {
|
|
|
273
273
|
import fs from "fs";
|
|
274
274
|
import path from "path";
|
|
275
275
|
import { createHash } from "crypto";
|
|
276
|
+
function validateQueries(queries) {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
for (const [name, query] of Object.entries(queries)) {
|
|
279
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
280
|
+
throw new Error(`Invalid analytics query name: ${name}. Names must be lower-kebab-case.`);
|
|
281
|
+
}
|
|
282
|
+
if (!query.sql.trim() || !/^(select|with)\b/i.test(query.sql.trim()) || /;\s*\S/.test(query.sql)) {
|
|
283
|
+
throw new Error(`Analytics query ${name} must contain one read-only SELECT or WITH statement.`);
|
|
284
|
+
}
|
|
285
|
+
if (((_a = query.sql.match(/\?/g)) != null ? _a : []).length !== Object.keys((_b = query.parameters) != null ? _b : {}).length) {
|
|
286
|
+
throw new Error(`Analytics query ${name} must have one ? placeholder for each declared parameter.`);
|
|
287
|
+
}
|
|
288
|
+
if (query.resultReuse && (!Number.isInteger(query.resultReuse.maxAgeMinutes) || query.resultReuse.maxAgeMinutes < 1 || query.resultReuse.maxAgeMinutes > 10080)) {
|
|
289
|
+
throw new Error(`Analytics query ${name} resultReuse.maxAgeMinutes must be between 1 and 10080.`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function validateDefinitions(definitions, kind) {
|
|
294
|
+
for (const [name, definition] of Object.entries(definitions)) {
|
|
295
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) throw new Error(`Invalid analytics ${kind} name: ${name}. Names must be lower-kebab-case.`);
|
|
296
|
+
if (!definition || typeof definition !== "object" || !("sql" in definition) || typeof definition.sql !== "string" || !definition.sql.trim()) {
|
|
297
|
+
throw new Error(`Analytics ${kind} ${name} requires SQL.`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
276
301
|
function loadManifest(configRoot) {
|
|
277
302
|
const manifestPath = path.join(
|
|
278
303
|
configRoot != null ? configRoot : "",
|
|
@@ -292,7 +317,7 @@ function loadManifest(configRoot) {
|
|
|
292
317
|
`Analytics manifest at ${manifestPath} is invalid. Run the Monorise generator before deploying.`
|
|
293
318
|
);
|
|
294
319
|
}
|
|
295
|
-
if (manifest.version !==
|
|
320
|
+
if (manifest.version !== 2 || !Array.isArray(manifest.datasets) || !Array.isArray(manifest.unnamedMutuals) || typeof manifest.schemaFingerprint !== "string") {
|
|
296
321
|
throw new Error(
|
|
297
322
|
`Analytics manifest at ${manifestPath} is invalid. Run the Monorise generator before deploying.`
|
|
298
323
|
);
|
|
@@ -305,23 +330,18 @@ function loadManifest(configRoot) {
|
|
|
305
330
|
}
|
|
306
331
|
const identifiers = /* @__PURE__ */ new Set();
|
|
307
332
|
for (const dataset of manifest.datasets) {
|
|
308
|
-
if (!dataset.name || !dataset.identifier || !Array.isArray(dataset.columns) || identifiers.has(dataset.identifier)) {
|
|
333
|
+
if (!dataset.name || !dataset.identifier || !dataset.idColumn || !Array.isArray(dataset.columns) || !Array.isArray(dataset.endpoints) || identifiers.has(dataset.identifier)) {
|
|
309
334
|
throw new Error(
|
|
310
335
|
`Analytics manifest at ${manifestPath} contains invalid or colliding datasets. Run the Monorise generator before deploying.`
|
|
311
336
|
);
|
|
312
337
|
}
|
|
313
338
|
identifiers.add(dataset.identifier);
|
|
314
339
|
}
|
|
315
|
-
if (manifest.unnamedMutuals.length > 0) {
|
|
316
|
-
throw new Error(
|
|
317
|
-
`Analytics requires named mutual configs. Add names for: ${manifest.unnamedMutuals.join(", ")}.`
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
340
|
return manifest;
|
|
321
341
|
}
|
|
322
342
|
var Analytics = class {
|
|
323
343
|
constructor(id, args, table, alarmTopic, configRoot, logging) {
|
|
324
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p
|
|
344
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
325
345
|
const manifest = loadManifest(configRoot);
|
|
326
346
|
const datasets = manifest.datasets.map((dataset) => {
|
|
327
347
|
var _a2, _b2;
|
|
@@ -331,20 +351,17 @@ var Analytics = class {
|
|
|
331
351
|
}
|
|
332
352
|
});
|
|
333
353
|
});
|
|
354
|
+
const serializedManifest = JSON.stringify({
|
|
355
|
+
datasets: datasets.map(({ kind, name, partition }) => ({ kind, name, partition }))
|
|
356
|
+
});
|
|
334
357
|
this.processorFunctionName = `${$app.stage}-${$app.name}-${id}-analytics-processor`;
|
|
335
358
|
this.backfillFunctionName = `${$app.stage}-${$app.name}-${id}-analytics-backfill`;
|
|
336
|
-
const
|
|
337
|
-
description: "Monorise analytics encryption key",
|
|
338
|
-
enableKeyRotation: true,
|
|
339
|
-
deletionWindowInDays: 30
|
|
340
|
-
}, { retainOnDelete: true });
|
|
341
|
-
const managedBucket = ((_b = args.resources) == null ? void 0 : _b.bucket) ? void 0 : new aws.s3.Bucket(`${id}-analytics-bucket`, {
|
|
359
|
+
const managedBucket = ((_a = args.resources) == null ? void 0 : _a.bucket) ? void 0 : new aws.s3.Bucket(`${id}-analytics-bucket`, {
|
|
342
360
|
forceDestroy: false,
|
|
343
361
|
serverSideEncryptionConfiguration: {
|
|
344
362
|
rule: {
|
|
345
363
|
applyServerSideEncryptionByDefault: {
|
|
346
|
-
|
|
347
|
-
sseAlgorithm: "aws:kms"
|
|
364
|
+
sseAlgorithm: "AES256"
|
|
348
365
|
}
|
|
349
366
|
}
|
|
350
367
|
}
|
|
@@ -358,29 +375,90 @@ var Analytics = class {
|
|
|
358
375
|
restrictPublicBuckets: true
|
|
359
376
|
});
|
|
360
377
|
}
|
|
361
|
-
const managedDatabase = ((
|
|
362
|
-
const managedWorkgroup = ((
|
|
378
|
+
const managedDatabase = ((_b = args.resources) == null ? void 0 : _b.glueDatabase) ? void 0 : new aws.glue.CatalogDatabase(`${id}-analytics-database`, {}, { retainOnDelete: true });
|
|
379
|
+
const managedWorkgroup = ((_c = args.resources) == null ? void 0 : _c.workgroup) ? void 0 : new aws.athena.Workgroup(`${id}-analytics-workgroup`, {
|
|
363
380
|
configuration: {
|
|
364
381
|
enforceWorkgroupConfiguration: true,
|
|
365
382
|
publishCloudwatchMetricsEnabled: true,
|
|
366
383
|
resultConfiguration: {
|
|
367
384
|
outputLocation: $interpolate`s3://${managedBucket.bucket}/athena-results/`,
|
|
368
|
-
encryptionConfiguration: { encryptionOption: "
|
|
385
|
+
encryptionConfiguration: { encryptionOption: "SSE_S3" }
|
|
369
386
|
}
|
|
370
387
|
}
|
|
371
388
|
}, { retainOnDelete: true });
|
|
372
|
-
this.bucket = (
|
|
373
|
-
this.
|
|
374
|
-
this.
|
|
375
|
-
|
|
389
|
+
this.bucket = (_e = (_d = args.resources) == null ? void 0 : _d.bucket) != null ? _e : { arn: managedBucket.arn, name: managedBucket.bucket };
|
|
390
|
+
this.glueDatabase = (_g = (_f = args.resources) == null ? void 0 : _f.glueDatabase) != null ? _g : { name: managedDatabase.name };
|
|
391
|
+
this.workgroup = (_i = (_h = args.resources) == null ? void 0 : _h.workgroup) != null ? _i : { name: managedWorkgroup.name };
|
|
392
|
+
if (((_j = args.queryApi) == null ? void 0 : _j.enabled) !== false && args.queryApi) {
|
|
393
|
+
validateQueries(args.queryApi.queries);
|
|
394
|
+
const queryKeys = new sst.Secret("ANALYTICS_API_KEYS", '["analytics-secret-1", "analytics-secret-2"]');
|
|
395
|
+
const executions = new sst.aws.Dynamo(`${id}-analytics-executions`, {
|
|
396
|
+
fields: { id: "string" },
|
|
397
|
+
primaryIndex: { hashKey: "id" },
|
|
398
|
+
ttl: "expiresAt"
|
|
399
|
+
});
|
|
400
|
+
this.queryApi = new sst.aws.ApiGatewayV2(`${id}-analytics-api`);
|
|
401
|
+
this.queryApi.route("ANY /analytics/{proxy+}", {
|
|
402
|
+
name: `${$app.stage}-${$app.name}-${id}-analytics-query-api`,
|
|
403
|
+
handler: path.join(configRoot != null ? configRoot : "", ".monorise/handle.analyticsQueryHandler"),
|
|
404
|
+
runtime: "nodejs22.x",
|
|
405
|
+
timeout: "30 seconds",
|
|
406
|
+
memory: "512 MB",
|
|
407
|
+
logging,
|
|
408
|
+
link: [executions, queryKeys],
|
|
409
|
+
environment: {
|
|
410
|
+
ANALYTICS_API_KEYS: queryKeys.value,
|
|
411
|
+
ANALYTICS_EXECUTIONS_TABLE: executions.name,
|
|
412
|
+
ANALYTICS_QUERIES: JSON.stringify(args.queryApi.queries),
|
|
413
|
+
ANALYTICS_DATABASE: this.glueDatabase.name,
|
|
414
|
+
ANALYTICS_WORKGROUP: this.workgroup.name,
|
|
415
|
+
ANALYTICS_ATHENA_OUTPUT: $interpolate`s3://${this.bucket.name}/athena-results/`
|
|
416
|
+
},
|
|
417
|
+
permissions: [
|
|
418
|
+
{ actions: ["athena:StartQueryExecution", "athena:GetQueryExecution", "athena:GetQueryResults", "athena:StopQueryExecution"], resources: ["*"] },
|
|
419
|
+
{ actions: ["glue:GetDatabase", "glue:GetDatabases", "glue:GetTable", "glue:GetTables"], resources: ["*"] },
|
|
420
|
+
{ actions: ["s3:GetBucketLocation", "s3:GetObject", "s3:ListBucket", "s3:PutObject"], resources: [this.bucket.arn, $interpolate`${this.bucket.arn}/*`] }
|
|
421
|
+
]
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
const athenaPermissions = [
|
|
425
|
+
{ actions: ["athena:StartQueryExecution", "athena:GetQueryExecution"], resources: ["*"] },
|
|
426
|
+
{ actions: ["glue:GetDatabase", "glue:GetDatabases", "glue:GetTable", "glue:GetTables", "glue:CreateTable", "glue:UpdateTable"], resources: ["*"] },
|
|
427
|
+
{ actions: ["s3:GetBucketLocation", "s3:GetObject", "s3:ListBucket", "s3:PutObject", "s3:DeleteObject"], resources: [this.bucket.arn, $interpolate`${this.bucket.arn}/*`] }
|
|
428
|
+
];
|
|
429
|
+
if (args.models) {
|
|
430
|
+
validateDefinitions(args.models, "model");
|
|
431
|
+
for (const [name, model] of Object.entries(args.models)) {
|
|
432
|
+
if (!model.partitionColumn || !/^[a-z][a-z0-9_]*$/.test(model.partitionColumn)) throw new Error(`Analytics model ${name} requires a snake_case partitionColumn.`);
|
|
433
|
+
if (model.lookbackDays !== void 0 && (!Number.isInteger(model.lookbackDays) || model.lookbackDays < 1)) throw new Error(`Analytics model ${name} lookbackDays must be a positive integer.`);
|
|
434
|
+
new sst.aws.CronV2(`${id}-${name}-analytics-model`, {
|
|
435
|
+
schedule: model.schedule,
|
|
436
|
+
function: {
|
|
437
|
+
handler: path.join(configRoot != null ? configRoot : "", ".monorise/handle.analyticsModelHandler"),
|
|
438
|
+
runtime: "nodejs22.x",
|
|
439
|
+
timeout: "15 minutes",
|
|
440
|
+
memory: "1024 MB",
|
|
441
|
+
logging,
|
|
442
|
+
environment: {
|
|
443
|
+
ANALYTICS_MODEL: JSON.stringify({ name, sql: model.sql, partitionColumn: model.partitionColumn, lookbackDays: (_k = model.lookbackDays) != null ? _k : 3 }),
|
|
444
|
+
ANALYTICS_DATABASE: this.glueDatabase.name,
|
|
445
|
+
ANALYTICS_BUCKET: this.bucket.name,
|
|
446
|
+
ANALYTICS_WORKGROUP: this.workgroup.name,
|
|
447
|
+
ANALYTICS_ATHENA_OUTPUT: $interpolate`s3://${this.bucket.name}/athena-results/`
|
|
448
|
+
},
|
|
449
|
+
permissions: athenaPermissions
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
376
454
|
const firehoseRole = new aws.iam.Role(`${id}-analytics-firehose-role`, {
|
|
377
455
|
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "firehose.amazonaws.com" })
|
|
378
456
|
});
|
|
379
457
|
new aws.iam.RolePolicy(`${id}-analytics-firehose-policy`, {
|
|
380
458
|
role: firehoseRole.id,
|
|
381
|
-
policy: $resolve([this.bucket.arn
|
|
459
|
+
policy: $resolve([this.bucket.arn]).apply(([bucketArn]) => JSON.stringify({
|
|
382
460
|
Version: "2012-10-17",
|
|
383
|
-
Statement: [{ Effect: "Allow", Action: ["s3:AbortMultipartUpload", "s3:GetBucketLocation", "s3:GetObject", "s3:ListBucket", "s3:PutObject"], Resource: [bucketArn, `${bucketArn}/*`] }
|
|
461
|
+
Statement: [{ Effect: "Allow", Action: ["s3:AbortMultipartUpload", "s3:GetBucketLocation", "s3:GetObject", "s3:ListBucket", "s3:PutObject"], Resource: [bucketArn, `${bucketArn}/*`] }]
|
|
384
462
|
}))
|
|
385
463
|
});
|
|
386
464
|
this.deliveryStream = new aws.kinesis.FirehoseDeliveryStream(`${id}-analytics-delivery`, {
|
|
@@ -389,9 +467,9 @@ var Analytics = class {
|
|
|
389
467
|
roleArn: firehoseRole.arn,
|
|
390
468
|
bucketArn: this.bucket.arn,
|
|
391
469
|
bufferingInterval: 300,
|
|
392
|
-
|
|
470
|
+
// Firehose requires at least 64 MiB when dynamic partitioning is enabled.
|
|
471
|
+
bufferingSize: 64,
|
|
393
472
|
compressionFormat: "GZIP",
|
|
394
|
-
kmsKeyArn: this.key.arn,
|
|
395
473
|
prefix: "history/!{partitionKeyFromQuery:path}/",
|
|
396
474
|
errorOutputPrefix: "errors/!{firehose:error-output-type}/",
|
|
397
475
|
dynamicPartitioningConfiguration: { enabled: true },
|
|
@@ -412,8 +490,8 @@ var Analytics = class {
|
|
|
412
490
|
link: [table, this.dlq],
|
|
413
491
|
environment: {
|
|
414
492
|
ANALYTICS_DELIVERY_STREAM: this.deliveryStream.name,
|
|
415
|
-
ANALYTICS_MANIFEST:
|
|
416
|
-
ANALYTICS_OMIT_FIELDS: JSON.stringify((
|
|
493
|
+
ANALYTICS_MANIFEST: serializedManifest,
|
|
494
|
+
ANALYTICS_OMIT_FIELDS: JSON.stringify((_m = (_l = args.fields) == null ? void 0 : _l.omit) != null ? _m : [])
|
|
417
495
|
},
|
|
418
496
|
permissions: [{ actions: ["firehose:PutRecordBatch"], resources: [this.deliveryStream.arn] }]
|
|
419
497
|
}, {
|
|
@@ -455,11 +533,32 @@ var Analytics = class {
|
|
|
455
533
|
alarmActions: [alarmTopic.arn],
|
|
456
534
|
dimensions: { DeliveryStreamName: this.deliveryStream.name }
|
|
457
535
|
});
|
|
458
|
-
if (((
|
|
536
|
+
if (((_n = args.resources) == null ? void 0 : _n.bucket) && !args.resources.bucket.notificationsManaged) {
|
|
459
537
|
throw new Error(
|
|
460
538
|
"Analytics backfill requires exclusive management of S3 bucket notifications. S3 only permits one notification configuration; ensure the supplied bucket has no existing notifications, then set analytics.resources.bucket.notificationsManaged to true."
|
|
461
539
|
);
|
|
462
540
|
}
|
|
541
|
+
this.schedule = new sst.aws.CronV2(`${id}-analytics-daily`, {
|
|
542
|
+
schedule: "cron(0 0 * * ? *)",
|
|
543
|
+
function: {
|
|
544
|
+
handler: path.join(configRoot != null ? configRoot : "", ".monorise/handle.analyticsMaterializationHandler"),
|
|
545
|
+
runtime: "nodejs22.x",
|
|
546
|
+
timeout: "15 minutes",
|
|
547
|
+
memory: "1024 MB",
|
|
548
|
+
logging,
|
|
549
|
+
environment: {
|
|
550
|
+
ANALYTICS_DATABASE: this.glueDatabase.name,
|
|
551
|
+
ANALYTICS_BUCKET: this.bucket.name,
|
|
552
|
+
ANALYTICS_WORKGROUP: this.workgroup.name,
|
|
553
|
+
ANALYTICS_ATHENA_OUTPUT: $interpolate`s3://${this.bucket.name}/athena-results/`
|
|
554
|
+
},
|
|
555
|
+
permissions: [
|
|
556
|
+
{ actions: ["athena:StartQueryExecution", "athena:GetQueryExecution", "athena:GetQueryResults"], resources: ["*"] },
|
|
557
|
+
{ actions: ["glue:GetDatabase", "glue:GetDatabases", "glue:GetTable", "glue:GetTables", "glue:CreateTable", "glue:UpdateTable"], resources: ["*"] },
|
|
558
|
+
{ actions: ["s3:GetBucketLocation", "s3:GetObject", "s3:PutObject", "s3:ListBucket"], resources: [this.bucket.arn, $interpolate`${this.bucket.arn}/*`] }
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
});
|
|
463
562
|
const backfillPrefix = "backfill";
|
|
464
563
|
const backfillFunction = new sst.aws.Function(`${id}-analytics-backfill`, {
|
|
465
564
|
name: this.backfillFunctionName,
|
|
@@ -474,14 +573,16 @@ var Analytics = class {
|
|
|
474
573
|
ANALYTICS_BACKFILL_BUCKET: this.bucket.name,
|
|
475
574
|
ANALYTICS_BACKFILL_PREFIX: backfillPrefix,
|
|
476
575
|
ANALYTICS_DELIVERY_STREAM: this.deliveryStream.name,
|
|
477
|
-
|
|
478
|
-
|
|
576
|
+
ANALYTICS_MATERIALIZATION_FUNCTION: this.schedule.nodes.function.name,
|
|
577
|
+
ANALYTICS_MANIFEST: serializedManifest,
|
|
578
|
+
ANALYTICS_OMIT_FIELDS: JSON.stringify((_p = (_o = args.fields) == null ? void 0 : _o.omit) != null ? _p : [])
|
|
479
579
|
},
|
|
480
580
|
permissions: [
|
|
481
581
|
{ actions: ["dynamodb:ExportTableToPointInTime", "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:UpdateItem", "dynamodb:DeleteItem"], resources: [table.arn] },
|
|
482
|
-
{ actions: ["s3:
|
|
582
|
+
{ actions: ["s3:GetBucketLocation", "s3:ListBucket"], resources: [this.bucket.arn] },
|
|
583
|
+
{ actions: ["s3:AbortMultipartUpload", "s3:GetObject", "s3:PutObject"], resources: [$interpolate`${this.bucket.arn}/${backfillPrefix}/*`] },
|
|
483
584
|
{ actions: ["firehose:PutRecordBatch"], resources: [this.deliveryStream.arn] },
|
|
484
|
-
{ actions: ["
|
|
585
|
+
{ actions: ["lambda:InvokeFunction"], resources: [this.schedule.nodes.function.arn] }
|
|
485
586
|
]
|
|
486
587
|
});
|
|
487
588
|
const backfillPermission = new aws.lambda.Permission(`${id}-analytics-backfill-s3-permission`, {
|
|
@@ -512,6 +613,7 @@ var Analytics = class {
|
|
|
512
613
|
alarmActions: [alarmTopic.arn],
|
|
513
614
|
dimensions: { FunctionName: this.backfillFunctionName }
|
|
514
615
|
});
|
|
616
|
+
const rawTables = [];
|
|
515
617
|
for (const dataset of datasets) {
|
|
516
618
|
const rawTable = `${dataset.historyTable}_raw`;
|
|
517
619
|
const rawLocation = $resolve([this.bucket.name]).apply(
|
|
@@ -529,7 +631,7 @@ var Analytics = class {
|
|
|
529
631
|
(location) => `${location}event_date=\${event_date}/`
|
|
530
632
|
)
|
|
531
633
|
};
|
|
532
|
-
new aws.glue.CatalogTable(`${id}-${dataset.identifier}-raw`, {
|
|
634
|
+
rawTables.push(new aws.glue.CatalogTable(`${id}-${dataset.identifier}-raw`, {
|
|
533
635
|
databaseName: this.glueDatabase.name,
|
|
534
636
|
name: rawTable,
|
|
535
637
|
tableType: "EXTERNAL_TABLE",
|
|
@@ -560,31 +662,36 @@ var Analytics = class {
|
|
|
560
662
|
]
|
|
561
663
|
},
|
|
562
664
|
partitionKeys: [{ name: "event_date", type: "string" }, ...dataset.partition.granularity === "hour" ? [{ name: "event_hour", type: "string" }] : []]
|
|
563
|
-
});
|
|
665
|
+
}));
|
|
564
666
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
667
|
+
const initialMaterialization = new aws.lambda.Invocation(`${id}-analytics-materialization-initial`, {
|
|
668
|
+
functionName: this.schedule.nodes.function.name,
|
|
669
|
+
input: JSON.stringify({ schemaFingerprint: manifest.schemaFingerprint })
|
|
670
|
+
}, { dependsOn: rawTables });
|
|
671
|
+
if (args.views) {
|
|
672
|
+
validateDefinitions(args.views, "view");
|
|
673
|
+
for (const [name, view] of Object.entries(args.views)) {
|
|
674
|
+
const viewFunction = new sst.aws.Function(`${id}-${name}-analytics-view`, {
|
|
675
|
+
handler: path.join(configRoot != null ? configRoot : "", ".monorise/handle.analyticsViewHandler"),
|
|
676
|
+
runtime: "nodejs22.x",
|
|
677
|
+
timeout: "15 minutes",
|
|
678
|
+
memory: "512 MB",
|
|
679
|
+
logging,
|
|
680
|
+
environment: {
|
|
681
|
+
ANALYTICS_VIEW: JSON.stringify({ name, sql: view.sql }),
|
|
682
|
+
ANALYTICS_DATABASE: this.glueDatabase.name,
|
|
683
|
+
ANALYTICS_WORKGROUP: this.workgroup.name,
|
|
684
|
+
ANALYTICS_ATHENA_OUTPUT: $interpolate`s3://${this.bucket.name}/athena-results/`
|
|
685
|
+
},
|
|
686
|
+
permissions: athenaPermissions
|
|
687
|
+
});
|
|
688
|
+
new aws.lambda.Invocation(`${id}-${name}-analytics-view-apply`, {
|
|
689
|
+
// Changing the definition changes the invocation input and reapplies the view.
|
|
690
|
+
functionName: viewFunction.name,
|
|
691
|
+
input: JSON.stringify({ sql: view.sql })
|
|
692
|
+
}, { dependsOn: [initialMaterialization] });
|
|
586
693
|
}
|
|
587
|
-
}
|
|
694
|
+
}
|
|
588
695
|
}
|
|
589
696
|
};
|
|
590
697
|
|
|
@@ -660,7 +767,7 @@ var SingleTable = class {
|
|
|
660
767
|
this.id = id;
|
|
661
768
|
this.replicatorFunctionName = `${$app.stage}-${$app.name}-${id}-core-replicator`;
|
|
662
769
|
this.dlq = new sst.aws.Queue(`${id}-core-replicator-dlq`);
|
|
663
|
-
this.table = (args == null ? void 0 : args.fromTableName) ? sst.aws.Dynamo.get(`${id}-core-table`, args.fromTableName) : new sst.aws.Dynamo(`${id}-core-table`, {
|
|
770
|
+
this.table = (args == null ? void 0 : args.fromTableName) ? sst.aws.Dynamo.get(`${id}-core-table`, args.fromTableName) : new sst.aws.Dynamo(`${id}-core-table`, __spreadValues({
|
|
664
771
|
fields: {
|
|
665
772
|
PK: "string",
|
|
666
773
|
SK: "string",
|
|
@@ -697,11 +804,8 @@ var SingleTable = class {
|
|
|
697
804
|
}
|
|
698
805
|
},
|
|
699
806
|
stream: "new-and-old-images",
|
|
700
|
-
ttl: "expiresAt"
|
|
701
|
-
|
|
702
|
-
table: { pointInTimeRecovery: { enabled: true } }
|
|
703
|
-
}
|
|
704
|
-
});
|
|
807
|
+
ttl: "expiresAt"
|
|
808
|
+
}, (args == null ? void 0 : args.pointInTimeRecoveryEnabled) ? { transform: { table: { pointInTimeRecovery: { enabled: true } } } } : {}));
|
|
705
809
|
const environment = {
|
|
706
810
|
CORE_TABLE: this.table.name
|
|
707
811
|
};
|
|
@@ -766,18 +870,20 @@ var MonoriseCore = class {
|
|
|
766
870
|
}
|
|
767
871
|
});
|
|
768
872
|
this.bus = new sst.aws.Bus(`${id}-monorise-bus`);
|
|
873
|
+
const analyticsEnabled = Boolean((args == null ? void 0 : args.analytics) && args.analytics.enabled !== false);
|
|
769
874
|
this.table = new SingleTable(id, {
|
|
770
875
|
runtime,
|
|
771
876
|
configRoot: args == null ? void 0 : args.configRoot,
|
|
772
877
|
fromTableName: args == null ? void 0 : args.fromTableName,
|
|
773
|
-
logging
|
|
878
|
+
logging,
|
|
879
|
+
pointInTimeRecoveryEnabled: analyticsEnabled
|
|
774
880
|
});
|
|
775
881
|
const secretApiKeys = new sst.Secret("API_KEYS", '["secret1", "secret2"]');
|
|
776
882
|
const appHandlerName = `${$app.stage}-${$app.name}-${id}-app-handler`;
|
|
777
883
|
this.api.route("ANY /core/{proxy+}", {
|
|
778
884
|
name: appHandlerName,
|
|
779
885
|
handler: `${dotMonorisePath}/handle.appHandler`,
|
|
780
|
-
link: [this.table.table, this.bus, secretApiKeys],
|
|
886
|
+
link: [this.table.table, this.bus, secretApiKeys, ...(_b = args == null ? void 0 : args.link) != null ? _b : []],
|
|
781
887
|
environment: {
|
|
782
888
|
API_KEYS: secretApiKeys.value,
|
|
783
889
|
CORE_TABLE: this.table.table.name,
|
|
@@ -786,7 +892,7 @@ var MonoriseCore = class {
|
|
|
786
892
|
logging
|
|
787
893
|
});
|
|
788
894
|
this.alarmTopic = new sst.aws.SnsTopic(`${id}-monorise-dlq-alarm-topic`);
|
|
789
|
-
if (
|
|
895
|
+
if (analyticsEnabled && (args == null ? void 0 : args.analytics)) {
|
|
790
896
|
if (args.fromTableName && ((_c = args.analytics.importedTable) == null ? void 0 : _c.pointInTimeRecoveryEnabled) !== true) {
|
|
791
897
|
throw new Error(
|
|
792
898
|
"Analytics backfill requires point-in-time recovery on fromTableName. Enable it on the imported table and set analytics.importedTable.pointInTimeRecoveryEnabled to true."
|