@webiny/api-sync-system 6.4.5-beta.0 → 6.6.0-alpha.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/index.d.ts +11 -3
- package/index.js +8 -3
- package/package.json +15 -11
- package/resolver/SyncResolverConfig.d.ts +17 -0
- package/resolver/SyncResolverConfig.js +5 -0
- package/resolver/SyncResolverConfig.js.map +1 -0
- package/resolver/SyncResolverLambdaHandler.d.ts +14 -0
- package/resolver/SyncResolverLambdaHandler.js +159 -0
- package/resolver/SyncResolverLambdaHandler.js.map +1 -0
- package/resolver/app/validation/body.d.ts +5 -5
- package/resolver/app/validation/detail.d.ts +5 -5
- package/resolver/app/validation/event.d.ts +5 -5
- package/sync/ApiGatewaySyncDecorator.d.ts +14 -0
- package/sync/ApiGatewaySyncDecorator.js +49 -0
- package/sync/ApiGatewaySyncDecorator.js.map +1 -0
- package/sync/SyncSystemConfig.d.ts +11 -0
- package/sync/SyncSystemConfig.js +5 -0
- package/sync/SyncSystemConfig.js.map +1 -0
- package/sync/utils/manifest.d.ts +2 -6
- package/sync/utils/manifest.js +2 -4
- package/sync/utils/manifest.js.map +1 -1
- package/types.d.ts +0 -2
- package/types.js.map +1 -1
- package/worker/SyncWorkerConfig.d.ts +9 -0
- package/worker/SyncWorkerConfig.js +5 -0
- package/worker/SyncWorkerConfig.js.map +1 -0
- package/worker/SyncWorkerEventHandler.d.ts +14 -0
- package/worker/SyncWorkerEventHandler.js +5 -0
- package/worker/SyncWorkerEventHandler.js.map +1 -0
- package/worker/SyncWorkerEventType.d.ts +10 -0
- package/worker/SyncWorkerEventType.js +24 -0
- package/worker/SyncWorkerEventType.js.map +1 -0
- package/worker/SyncWorkerLambdaHandler.d.ts +13 -0
- package/worker/SyncWorkerLambdaHandler.js +61 -0
- package/worker/SyncWorkerLambdaHandler.js.map +1 -0
- package/resolver/createEventHandlerPlugin.d.ts +0 -11
- package/resolver/createEventHandlerPlugin.js +0 -91
- package/resolver/createEventHandlerPlugin.js.map +0 -1
- package/resolver/createResolverHandler.d.ts +0 -21
- package/resolver/createResolverHandler.js +0 -64
- package/resolver/createResolverHandler.js.map +0 -1
- package/sync/createSendDataToEventBridgeOnRequestEnd.d.ts +0 -2
- package/sync/createSendDataToEventBridgeOnRequestEnd.js +0 -39
- package/sync/createSendDataToEventBridgeOnRequestEnd.js.map +0 -1
- package/sync/createSyncSystem.d.ts +0 -16
- package/sync/createSyncSystem.js +0 -33
- package/sync/createSyncSystem.js.map +0 -1
- package/sync/requestPlugin.d.ts +0 -9
- package/sync/requestPlugin.js +0 -43
- package/sync/requestPlugin.js.map +0 -1
- package/worker/createWorkerHandler.d.ts +0 -11
- package/worker/createWorkerHandler.js +0 -35
- package/worker/createWorkerHandler.js.map +0 -1
- package/worker/handler/eventHandler.d.ts +0 -1
- package/worker/handler/eventHandler.js +0 -22
- package/worker/handler/eventHandler.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { SyncResolverConfig } from "./resolver/SyncResolverConfig.js";
|
|
2
|
+
export type { ISyncResolverConfig } from "./resolver/SyncResolverConfig.js";
|
|
3
|
+
export { SyncResolverLambdaHandler } from "./resolver/SyncResolverLambdaHandler.js";
|
|
4
|
+
export { SyncWorkerConfig } from "./worker/SyncWorkerConfig.js";
|
|
5
|
+
export type { ISyncWorkerConfig } from "./worker/SyncWorkerConfig.js";
|
|
6
|
+
export { SyncWorkerEventType } from "./worker/SyncWorkerEventType.js";
|
|
7
|
+
export { SyncWorkerEventHandler } from "./worker/SyncWorkerEventHandler.js";
|
|
8
|
+
export { SyncWorkerLambdaHandler } from "./worker/SyncWorkerLambdaHandler.js";
|
|
9
|
+
export { SyncSystemConfig } from "./sync/SyncSystemConfig.js";
|
|
10
|
+
export type { ISyncSystemConfig } from "./sync/SyncSystemConfig.js";
|
|
11
|
+
export { ApiGatewaySyncDecorator } from "./sync/ApiGatewaySyncDecorator.js";
|
package/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { SyncResolverConfig } from "./resolver/SyncResolverConfig.js";
|
|
2
|
+
export { SyncResolverLambdaHandler } from "./resolver/SyncResolverLambdaHandler.js";
|
|
3
|
+
export { SyncWorkerConfig } from "./worker/SyncWorkerConfig.js";
|
|
4
|
+
export { SyncWorkerEventType } from "./worker/SyncWorkerEventType.js";
|
|
5
|
+
export { SyncWorkerEventHandler } from "./worker/SyncWorkerEventHandler.js";
|
|
6
|
+
export { SyncWorkerLambdaHandler } from "./worker/SyncWorkerLambdaHandler.js";
|
|
7
|
+
export { SyncSystemConfig } from "./sync/SyncSystemConfig.js";
|
|
8
|
+
export { ApiGatewaySyncDecorator } from "./sync/ApiGatewaySyncDecorator.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-sync-system",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -14,13 +14,16 @@
|
|
|
14
14
|
"author": "Webiny LTD",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@webiny/api": "6.
|
|
18
|
-
"@webiny/
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"@webiny/handler-aws": "6.
|
|
22
|
-
"@webiny/
|
|
23
|
-
"@webiny/
|
|
17
|
+
"@webiny/api": "6.6.0-alpha.0",
|
|
18
|
+
"@webiny/api-core": "6.6.0-alpha.0",
|
|
19
|
+
"@webiny/aws-sdk": "6.6.0-alpha.0",
|
|
20
|
+
"@webiny/error": "6.6.0-alpha.0",
|
|
21
|
+
"@webiny/event-handler-aws": "6.6.0-alpha.0",
|
|
22
|
+
"@webiny/event-handler-core": "6.6.0-alpha.0",
|
|
23
|
+
"@webiny/feature": "6.6.0-alpha.0",
|
|
24
|
+
"@webiny/handler": "6.6.0-alpha.0",
|
|
25
|
+
"@webiny/plugins": "6.6.0-alpha.0",
|
|
26
|
+
"@webiny/utils": "6.6.0-alpha.0",
|
|
24
27
|
"bytes": "3.1.2",
|
|
25
28
|
"lodash": "4.18.1",
|
|
26
29
|
"semver": "7.8.5",
|
|
@@ -29,12 +32,13 @@
|
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@faker-js/faker": "10.5.0",
|
|
31
34
|
"@types/lodash": "4.17.24",
|
|
32
|
-
"@webiny/
|
|
33
|
-
"@webiny/
|
|
35
|
+
"@webiny/api-core-ddb": "6.6.0-alpha.0",
|
|
36
|
+
"@webiny/build-tools": "6.6.0-alpha.0",
|
|
37
|
+
"@webiny/project-utils": "6.6.0-alpha.0",
|
|
34
38
|
"aws-sdk-client-mock": "4.1.0",
|
|
35
39
|
"jest-dynalite": "3.6.1",
|
|
36
40
|
"rimraf": "6.1.3",
|
|
37
|
-
"typescript": "
|
|
41
|
+
"typescript": "7.0.2",
|
|
38
42
|
"vitest": "4.1.10"
|
|
39
43
|
},
|
|
40
44
|
"publishConfig": {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DynamoDBClientConfig, DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { LambdaClient, LambdaClientConfig } from "@webiny/aws-sdk/client-lambda/index.js";
|
|
3
|
+
import type { S3Client, S3ClientConfig } from "@webiny/aws-sdk/client-s3/index.js";
|
|
4
|
+
import type { CognitoIdentityProvider, CognitoIdentityProviderClientConfig } from "@webiny/aws-sdk/client-cognito-identity-provider/index.js";
|
|
5
|
+
import type { TransformRecordPlugin } from "./plugins/TransformRecordPlugin.js";
|
|
6
|
+
import type { CommandHandlerPlugin } from "./plugins/CommandHandlerPlugin.js";
|
|
7
|
+
export type AllowedResolverPlugins = TransformRecordPlugin | CommandHandlerPlugin;
|
|
8
|
+
export interface ISyncResolverConfig {
|
|
9
|
+
tableName?: string;
|
|
10
|
+
awsWorkerLambdaArn?: string;
|
|
11
|
+
createDocumentClient(params: Partial<DynamoDBClientConfig>): Pick<DynamoDBDocument, "send">;
|
|
12
|
+
createLambdaClient?(config: Partial<LambdaClientConfig>): Pick<LambdaClient, "send">;
|
|
13
|
+
createS3Client?(config: S3ClientConfig): Pick<S3Client, "send">;
|
|
14
|
+
createCognitoIdentityProviderClient?(config: Partial<CognitoIdentityProviderClientConfig>): Pick<CognitoIdentityProvider, "send">;
|
|
15
|
+
plugins?: AllowedResolverPlugins[];
|
|
16
|
+
}
|
|
17
|
+
export declare const SyncResolverConfig: import("@webiny/di").Abstraction<ISyncResolverConfig>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver/SyncResolverConfig.js","sources":["../../src/resolver/SyncResolverConfig.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type {\n DynamoDBClientConfig,\n DynamoDBDocument\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { LambdaClient, LambdaClientConfig } from \"@webiny/aws-sdk/client-lambda/index.js\";\nimport type { S3Client, S3ClientConfig } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport type {\n CognitoIdentityProvider,\n CognitoIdentityProviderClientConfig\n} from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport type { TransformRecordPlugin } from \"./plugins/TransformRecordPlugin.js\";\nimport type { CommandHandlerPlugin } from \"./plugins/CommandHandlerPlugin.js\";\n\nexport type AllowedResolverPlugins = TransformRecordPlugin | CommandHandlerPlugin;\n\nexport interface ISyncResolverConfig {\n tableName?: string;\n awsWorkerLambdaArn?: string;\n createDocumentClient(params: Partial<DynamoDBClientConfig>): Pick<DynamoDBDocument, \"send\">;\n createLambdaClient?(config: Partial<LambdaClientConfig>): Pick<LambdaClient, \"send\">;\n createS3Client?(config: S3ClientConfig): Pick<S3Client, \"send\">;\n createCognitoIdentityProviderClient?(\n config: Partial<CognitoIdentityProviderClientConfig>\n ): Pick<CognitoIdentityProvider, \"send\">;\n plugins?: AllowedResolverPlugins[];\n}\n\nexport const SyncResolverConfig = createAbstraction<ISyncResolverConfig>(\"SyncResolverConfig\");\n"],"names":["SyncResolverConfig","createAbstraction"],"mappings":";AA4BO,MAAMA,qBAAqBC,kBAAuC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SqsEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js";
|
|
2
|
+
import type { SqsResult } from "@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js";
|
|
3
|
+
import type { EventContext, NextFunction } from "@webiny/event-handler-core";
|
|
4
|
+
import type { SQSEvent } from "@webiny/aws-sdk/types/index.js";
|
|
5
|
+
import type { ISyncResolverConfig } from "./SyncResolverConfig.js";
|
|
6
|
+
declare class SyncResolverLambdaHandlerImpl implements SqsEventHandler.Interface {
|
|
7
|
+
private config;
|
|
8
|
+
constructor(config: ISyncResolverConfig);
|
|
9
|
+
execute(eventCtx: EventContext<SQSEvent>, _next: NextFunction): Promise<SqsResult>;
|
|
10
|
+
}
|
|
11
|
+
export declare const SyncResolverLambdaHandler: typeof SyncResolverLambdaHandlerImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js").ISqsEventHandler>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { SqsEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import { WebinyError } from "@webiny/error";
|
|
4
|
+
import { convertException } from "@webiny/utils";
|
|
5
|
+
import { SyncResolverConfig } from "./SyncResolverConfig.js";
|
|
6
|
+
import { createFetcher } from "./app/fetcher/Fetcher.js";
|
|
7
|
+
import { createDeploymentsFetcher } from "./deployment/DeploymentsFetcher.js";
|
|
8
|
+
import { createStorer } from "./app/storer/Storer.js";
|
|
9
|
+
import { TransformHandler } from "./app/transform/TransformHandler.js";
|
|
10
|
+
import { createRecordHandler } from "./app/RecordHandler.js";
|
|
11
|
+
import { createResolverApp } from "./app/ResolverApplication.js";
|
|
12
|
+
import { createBundler } from "./app/bundler/Bundler.js";
|
|
13
|
+
import { createBundles } from "./app/bundler/Bundles.js";
|
|
14
|
+
import { createCommandBundle } from "./app/bundler/CommandBundle.js";
|
|
15
|
+
import { createTableBundle } from "./app/bundler/TableBundle.js";
|
|
16
|
+
import { SourceDataContainer } from "./app/data/SourceDataContainer.js";
|
|
17
|
+
import { StorerAfterEachPlugin } from "./plugins/StorerAfterEachPlugin.js";
|
|
18
|
+
import { createFileManagerPlugins } from "./recordTypes/fileManager/fileManager.js";
|
|
19
|
+
import { LambdaTrigger } from "./lambda/LambdaTrigger.js";
|
|
20
|
+
import { CopyFile } from "./recordTypes/fileManager/CopyFile.js";
|
|
21
|
+
import { DeleteFile } from "./recordTypes/fileManager/DeleteFile.js";
|
|
22
|
+
import { createUsersPlugins } from "./recordTypes/users/users.js";
|
|
23
|
+
import { CopyUser } from "./recordTypes/users/CopyUser.js";
|
|
24
|
+
import { DeleteUser } from "./recordTypes/users/DeleteUser.js";
|
|
25
|
+
import { createPutCommandHandlerPlugin } from "./app/commandHandler/put.js";
|
|
26
|
+
import { createDeleteCommandHandlerPlugin } from "./app/commandHandler/delete.js";
|
|
27
|
+
async function processResolverEvent(records, config, plugins) {
|
|
28
|
+
const tableName = config.tableName || process.env.DB_TABLE;
|
|
29
|
+
if (!tableName) throw new WebinyError({
|
|
30
|
+
message: "Table name variable is not set."
|
|
31
|
+
});
|
|
32
|
+
const fetcher = createFetcher({
|
|
33
|
+
maxRetries: 10,
|
|
34
|
+
retryDelay: 1000,
|
|
35
|
+
createDocumentClient: (deployment)=>config.createDocumentClient({
|
|
36
|
+
region: deployment.region
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
const deploymentsFetcher = createDeploymentsFetcher({
|
|
40
|
+
client: config.createDocumentClient({
|
|
41
|
+
region: process.env.AWS_REGION
|
|
42
|
+
}),
|
|
43
|
+
table: tableName
|
|
44
|
+
});
|
|
45
|
+
const deployments = await deploymentsFetcher.fetch();
|
|
46
|
+
const storerAfterEachPlugins = plugins.byType(StorerAfterEachPlugin.type);
|
|
47
|
+
const storer = createStorer({
|
|
48
|
+
createDocumentClient: (deployment)=>config.createDocumentClient({
|
|
49
|
+
region: deployment.region
|
|
50
|
+
}),
|
|
51
|
+
afterEach: async (params)=>{
|
|
52
|
+
for (const plugin of storerAfterEachPlugins)if (plugin.canHandle(params)) await plugin.handle(params);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const transformHandler = new TransformHandler({
|
|
56
|
+
plugins
|
|
57
|
+
});
|
|
58
|
+
const recordHandler = createRecordHandler({
|
|
59
|
+
plugins,
|
|
60
|
+
fetcher,
|
|
61
|
+
storer,
|
|
62
|
+
deployments,
|
|
63
|
+
transformHandler,
|
|
64
|
+
commandBundler: createBundler({
|
|
65
|
+
createBundles: ()=>createBundles({
|
|
66
|
+
createBundle: createCommandBundle
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
tableBundler: createBundler({
|
|
70
|
+
createBundles: ()=>createBundles({
|
|
71
|
+
createBundle: createTableBundle
|
|
72
|
+
})
|
|
73
|
+
}),
|
|
74
|
+
createSourceDataContainer: ()=>SourceDataContainer.create()
|
|
75
|
+
});
|
|
76
|
+
const app = createResolverApp({
|
|
77
|
+
recordHandler,
|
|
78
|
+
deployments
|
|
79
|
+
});
|
|
80
|
+
await app.resolve({
|
|
81
|
+
records
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
class SyncResolverLambdaHandlerImpl {
|
|
85
|
+
constructor(config){
|
|
86
|
+
this.config = config;
|
|
87
|
+
}
|
|
88
|
+
async execute(eventCtx, _next) {
|
|
89
|
+
const { createLambdaClient, createS3Client, createCognitoIdentityProviderClient } = this.config;
|
|
90
|
+
const awsWorkerLambdaArn = this.config.awsWorkerLambdaArn || process.env.AWS_SYNC_WORKER_LAMBDA_ARN;
|
|
91
|
+
const copyFileTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
|
|
92
|
+
arn: awsWorkerLambdaArn,
|
|
93
|
+
createLambdaClient
|
|
94
|
+
}) : void 0;
|
|
95
|
+
const deleteFileTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
|
|
96
|
+
arn: awsWorkerLambdaArn,
|
|
97
|
+
createLambdaClient
|
|
98
|
+
}) : void 0;
|
|
99
|
+
const copyUserTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
|
|
100
|
+
arn: awsWorkerLambdaArn,
|
|
101
|
+
createLambdaClient
|
|
102
|
+
}) : void 0;
|
|
103
|
+
const deleteUserTrigger = createLambdaClient && awsWorkerLambdaArn ? new LambdaTrigger({
|
|
104
|
+
arn: awsWorkerLambdaArn,
|
|
105
|
+
createLambdaClient
|
|
106
|
+
}) : void 0;
|
|
107
|
+
const copyFile = createS3Client && copyFileTrigger ? new CopyFile({
|
|
108
|
+
createS3Client,
|
|
109
|
+
getLambdaTrigger: ()=>copyFileTrigger
|
|
110
|
+
}) : void 0;
|
|
111
|
+
const deleteFile = createS3Client && deleteFileTrigger ? new DeleteFile({
|
|
112
|
+
createS3Client,
|
|
113
|
+
getLambdaTrigger: ()=>deleteFileTrigger
|
|
114
|
+
}) : void 0;
|
|
115
|
+
const copyUser = createCognitoIdentityProviderClient && copyUserTrigger ? new CopyUser({
|
|
116
|
+
createCognitoIdentityProviderClient,
|
|
117
|
+
getLambdaTrigger: ()=>copyUserTrigger
|
|
118
|
+
}) : void 0;
|
|
119
|
+
const deleteUser = createCognitoIdentityProviderClient && deleteUserTrigger ? new DeleteUser({
|
|
120
|
+
createCognitoIdentityProviderClient,
|
|
121
|
+
getLambdaTrigger: ()=>deleteUserTrigger
|
|
122
|
+
}) : void 0;
|
|
123
|
+
const plugins = new PluginsContainer([
|
|
124
|
+
...copyFile && deleteFile ? createFileManagerPlugins({
|
|
125
|
+
copyFile,
|
|
126
|
+
deleteFile
|
|
127
|
+
}) : [],
|
|
128
|
+
...copyUser && deleteUser ? createUsersPlugins({
|
|
129
|
+
copyUser,
|
|
130
|
+
deleteUser
|
|
131
|
+
}) : [],
|
|
132
|
+
createPutCommandHandlerPlugin(),
|
|
133
|
+
createDeleteCommandHandlerPlugin(),
|
|
134
|
+
...this.config.plugins || []
|
|
135
|
+
]);
|
|
136
|
+
try {
|
|
137
|
+
await processResolverEvent(eventCtx.event.Records, this.config, plugins);
|
|
138
|
+
return {
|
|
139
|
+
success: true
|
|
140
|
+
};
|
|
141
|
+
} catch (ex) {
|
|
142
|
+
const error = convertException(ex);
|
|
143
|
+
console.error(error);
|
|
144
|
+
return {
|
|
145
|
+
success: false,
|
|
146
|
+
message: error.message
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const SyncResolverLambdaHandler = SqsEventHandler.createImplementation({
|
|
152
|
+
implementation: SyncResolverLambdaHandlerImpl,
|
|
153
|
+
dependencies: [
|
|
154
|
+
SyncResolverConfig
|
|
155
|
+
]
|
|
156
|
+
});
|
|
157
|
+
export { SyncResolverLambdaHandler };
|
|
158
|
+
|
|
159
|
+
//# sourceMappingURL=SyncResolverLambdaHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver/SyncResolverLambdaHandler.js","sources":["../../src/resolver/SyncResolverLambdaHandler.ts"],"sourcesContent":["import { SqsEventHandler } from \"@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js\";\nimport type { SqsResult } from \"@webiny/event-handler-aws/abstractions/handlers/SqsEventHandler.js\";\nimport type { EventContext, NextFunction } from \"@webiny/event-handler-core\";\nimport type { SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { WebinyError } from \"@webiny/error\";\nimport { convertException } from \"@webiny/utils\";\nimport { SyncResolverConfig } from \"./SyncResolverConfig.js\";\nimport type { ISyncResolverConfig } from \"./SyncResolverConfig.js\";\nimport { createFetcher } from \"~/resolver/app/fetcher/Fetcher.js\";\nimport { createDeploymentsFetcher } from \"~/resolver/deployment/DeploymentsFetcher.js\";\nimport { createStorer } from \"~/resolver/app/storer/Storer.js\";\nimport { TransformHandler } from \"~/resolver/app/transform/TransformHandler.js\";\nimport { createRecordHandler } from \"~/resolver/app/RecordHandler.js\";\nimport { createResolverApp } from \"~/resolver/app/ResolverApplication.js\";\nimport { createBundler } from \"~/resolver/app/bundler/Bundler.js\";\nimport { createBundles } from \"~/resolver/app/bundler/Bundles.js\";\nimport { createCommandBundle } from \"~/resolver/app/bundler/CommandBundle.js\";\nimport { createTableBundle } from \"~/resolver/app/bundler/TableBundle.js\";\nimport { SourceDataContainer } from \"~/resolver/app/data/SourceDataContainer.js\";\nimport { StorerAfterEachPlugin } from \"~/resolver/plugins/StorerAfterEachPlugin.js\";\nimport { createFileManagerPlugins } from \"~/resolver/recordTypes/fileManager/fileManager.js\";\nimport { LambdaTrigger } from \"~/resolver/lambda/LambdaTrigger.js\";\nimport { CopyFile } from \"~/resolver/recordTypes/fileManager/CopyFile.js\";\nimport { DeleteFile } from \"~/resolver/recordTypes/fileManager/DeleteFile.js\";\nimport { createUsersPlugins } from \"~/resolver/recordTypes/users/users.js\";\nimport { CopyUser } from \"~/resolver/recordTypes/users/CopyUser.js\";\nimport { DeleteUser } from \"~/resolver/recordTypes/users/DeleteUser.js\";\nimport { createPutCommandHandlerPlugin } from \"~/resolver/app/commandHandler/put.js\";\nimport { createDeleteCommandHandlerPlugin } from \"~/resolver/app/commandHandler/delete.js\";\nimport type {\n ICopyFileLambdaPayload,\n IDeleteFileLambdaPayload,\n ICopyUserLambdaPayload,\n IDeleteUserLambdaPayload\n} from \"~/types.js\";\n\nasync function processResolverEvent(\n records: SQSEvent[\"Records\"],\n config: ISyncResolverConfig,\n plugins: PluginsContainer\n): Promise<void> {\n const tableName = config.tableName || process.env.DB_TABLE;\n if (!tableName) {\n throw new WebinyError({ message: \"Table name variable is not set.\" });\n }\n\n const fetcher = createFetcher({\n maxRetries: 10,\n retryDelay: 1000,\n createDocumentClient: deployment =>\n config.createDocumentClient({ region: deployment.region })\n });\n\n const deploymentsFetcher = createDeploymentsFetcher({\n client: config.createDocumentClient({ region: process.env.AWS_REGION }),\n table: tableName\n });\n\n const deployments = await deploymentsFetcher.fetch();\n\n const storerAfterEachPlugins = plugins.byType<StorerAfterEachPlugin>(\n StorerAfterEachPlugin.type\n );\n\n const storer = createStorer({\n createDocumentClient: deployment =>\n config.createDocumentClient({ region: deployment.region }),\n afterEach: async params => {\n for (const plugin of storerAfterEachPlugins) {\n if (!plugin.canHandle(params)) {\n continue;\n }\n await plugin.handle(params);\n }\n }\n });\n\n const transformHandler = new TransformHandler({ plugins });\n const recordHandler = createRecordHandler({\n plugins,\n fetcher,\n storer,\n deployments,\n transformHandler,\n commandBundler: createBundler({\n createBundles: () => createBundles({ createBundle: createCommandBundle })\n }),\n tableBundler: createBundler({\n createBundles: () => createBundles({ createBundle: createTableBundle })\n }),\n createSourceDataContainer: () => SourceDataContainer.create()\n });\n\n const app = createResolverApp({ recordHandler, deployments });\n await app.resolve({ records });\n}\n\nclass SyncResolverLambdaHandlerImpl implements SqsEventHandler.Interface {\n constructor(private config: ISyncResolverConfig) {}\n\n async execute(eventCtx: EventContext<SQSEvent>, _next: NextFunction): Promise<SqsResult> {\n const { createLambdaClient, createS3Client, createCognitoIdentityProviderClient } =\n this.config;\n\n const awsWorkerLambdaArn =\n this.config.awsWorkerLambdaArn || process.env.AWS_SYNC_WORKER_LAMBDA_ARN;\n\n const copyFileTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<ICopyFileLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const deleteFileTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<IDeleteFileLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const copyUserTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<ICopyUserLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const deleteUserTrigger =\n createLambdaClient && awsWorkerLambdaArn\n ? new LambdaTrigger<IDeleteUserLambdaPayload>({\n arn: awsWorkerLambdaArn,\n createLambdaClient\n })\n : undefined;\n\n const copyFile =\n createS3Client && copyFileTrigger\n ? new CopyFile({\n createS3Client,\n getLambdaTrigger: () => copyFileTrigger\n })\n : undefined;\n\n const deleteFile =\n createS3Client && deleteFileTrigger\n ? new DeleteFile({\n createS3Client,\n getLambdaTrigger: () => deleteFileTrigger\n })\n : undefined;\n\n const copyUser =\n createCognitoIdentityProviderClient && copyUserTrigger\n ? new CopyUser({\n createCognitoIdentityProviderClient,\n getLambdaTrigger: () => copyUserTrigger\n })\n : undefined;\n\n const deleteUser =\n createCognitoIdentityProviderClient && deleteUserTrigger\n ? new DeleteUser({\n createCognitoIdentityProviderClient,\n getLambdaTrigger: () => deleteUserTrigger\n })\n : undefined;\n\n const plugins = new PluginsContainer([\n ...(copyFile && deleteFile ? createFileManagerPlugins({ copyFile, deleteFile }) : []),\n ...(copyUser && deleteUser ? createUsersPlugins({ copyUser, deleteUser }) : []),\n createPutCommandHandlerPlugin(),\n createDeleteCommandHandlerPlugin(),\n ...(this.config.plugins || [])\n ]);\n\n try {\n await processResolverEvent(eventCtx.event.Records, this.config, plugins);\n return { success: true };\n } catch (ex) {\n const error = convertException(ex);\n console.error(error);\n return { success: false, message: error.message };\n }\n }\n}\n\nexport const SyncResolverLambdaHandler = SqsEventHandler.createImplementation({\n implementation: SyncResolverLambdaHandlerImpl,\n dependencies: [SyncResolverConfig]\n});\n"],"names":["processResolverEvent","records","config","plugins","tableName","process","WebinyError","fetcher","createFetcher","deployment","deploymentsFetcher","createDeploymentsFetcher","deployments","storerAfterEachPlugins","StorerAfterEachPlugin","storer","createStorer","params","plugin","transformHandler","TransformHandler","recordHandler","createRecordHandler","createBundler","createBundles","createCommandBundle","createTableBundle","SourceDataContainer","app","createResolverApp","SyncResolverLambdaHandlerImpl","eventCtx","_next","createLambdaClient","createS3Client","createCognitoIdentityProviderClient","awsWorkerLambdaArn","copyFileTrigger","LambdaTrigger","undefined","deleteFileTrigger","copyUserTrigger","deleteUserTrigger","copyFile","CopyFile","deleteFile","DeleteFile","copyUser","CopyUser","deleteUser","DeleteUser","PluginsContainer","createFileManagerPlugins","createUsersPlugins","createPutCommandHandlerPlugin","createDeleteCommandHandlerPlugin","ex","error","convertException","console","SyncResolverLambdaHandler","SqsEventHandler","SyncResolverConfig"],"mappings":"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"}
|
|
@@ -14,14 +14,14 @@ export declare const createBodyValidation: () => zod.ZodObject<{
|
|
|
14
14
|
SK: zod.ZodString;
|
|
15
15
|
tableName: zod.ZodString;
|
|
16
16
|
tableType: zod.ZodPipe<zod.ZodEnum<{
|
|
17
|
-
|
|
17
|
+
log: "log";
|
|
18
18
|
opensearch: "opensearch";
|
|
19
|
+
regular: "regular";
|
|
19
20
|
unknown: "unknown";
|
|
20
|
-
|
|
21
|
-
}>, zod.ZodTransform<import("../../../types.js").DynamoDBTableType, "regular" | "opensearch" | "unknown" | "log">>;
|
|
21
|
+
}>, zod.ZodTransform<import("../../../types.js").DynamoDBTableType, "log" | "opensearch" | "regular" | "unknown">>;
|
|
22
22
|
command: zod.ZodEnum<{
|
|
23
|
-
put: "put";
|
|
24
23
|
delete: "delete";
|
|
24
|
+
put: "put";
|
|
25
25
|
update: "update";
|
|
26
26
|
}>;
|
|
27
27
|
}, zod.core.$strip>>, zod.ZodTransform<import("@webiny/api/types.js").NonEmptyArray<import("../abstractions/ResolverRecord.js").IResolverRecordBodyItem>, {
|
|
@@ -29,7 +29,7 @@ export declare const createBodyValidation: () => zod.ZodObject<{
|
|
|
29
29
|
SK: string;
|
|
30
30
|
tableName: string;
|
|
31
31
|
tableType: import("../../../types.js").DynamoDBTableType;
|
|
32
|
-
command: "
|
|
32
|
+
command: "delete" | "put" | "update";
|
|
33
33
|
}[]>>;
|
|
34
34
|
source: zod.ZodObject<{
|
|
35
35
|
name: zod.ZodString;
|
|
@@ -8,14 +8,14 @@ export declare const createDetailValidation: () => zod.ZodObject<{
|
|
|
8
8
|
SK: zod.ZodString;
|
|
9
9
|
tableName: zod.ZodString;
|
|
10
10
|
tableType: zod.ZodPipe<zod.ZodEnum<{
|
|
11
|
-
|
|
11
|
+
log: "log";
|
|
12
12
|
opensearch: "opensearch";
|
|
13
|
+
regular: "regular";
|
|
13
14
|
unknown: "unknown";
|
|
14
|
-
|
|
15
|
-
}>, zod.ZodTransform<DynamoDBTableType, "regular" | "opensearch" | "unknown" | "log">>;
|
|
15
|
+
}>, zod.ZodTransform<DynamoDBTableType, "log" | "opensearch" | "regular" | "unknown">>;
|
|
16
16
|
command: zod.ZodEnum<{
|
|
17
|
-
put: "put";
|
|
18
17
|
delete: "delete";
|
|
18
|
+
put: "put";
|
|
19
19
|
update: "update";
|
|
20
20
|
}>;
|
|
21
21
|
}, zod.core.$strip>>, zod.ZodTransform<NonEmptyArray<IResolverRecordBodyItem>, {
|
|
@@ -23,7 +23,7 @@ export declare const createDetailValidation: () => zod.ZodObject<{
|
|
|
23
23
|
SK: string;
|
|
24
24
|
tableName: string;
|
|
25
25
|
tableType: DynamoDBTableType;
|
|
26
|
-
command: "
|
|
26
|
+
command: "delete" | "put" | "update";
|
|
27
27
|
}[]>>;
|
|
28
28
|
source: zod.ZodObject<{
|
|
29
29
|
name: zod.ZodString;
|
|
@@ -17,14 +17,14 @@ export declare const createEventValidation: () => zod.ZodArray<zod.ZodObject<{
|
|
|
17
17
|
SK: zod.ZodString;
|
|
18
18
|
tableName: zod.ZodString;
|
|
19
19
|
tableType: zod.ZodPipe<zod.ZodEnum<{
|
|
20
|
-
|
|
20
|
+
log: "log";
|
|
21
21
|
opensearch: "opensearch";
|
|
22
|
+
regular: "regular";
|
|
22
23
|
unknown: "unknown";
|
|
23
|
-
|
|
24
|
-
}>, zod.ZodTransform<import("../../../types").DynamoDBTableType, "regular" | "opensearch" | "unknown" | "log">>;
|
|
24
|
+
}>, zod.ZodTransform<import("../../../types").DynamoDBTableType, "log" | "opensearch" | "regular" | "unknown">>;
|
|
25
25
|
command: zod.ZodEnum<{
|
|
26
|
-
put: "put";
|
|
27
26
|
delete: "delete";
|
|
27
|
+
put: "put";
|
|
28
28
|
update: "update";
|
|
29
29
|
}>;
|
|
30
30
|
}, zod.core.$strip>>, zod.ZodTransform<import("@webiny/api/types").NonEmptyArray<import("../abstractions/ResolverRecord").IResolverRecordBodyItem>, {
|
|
@@ -32,7 +32,7 @@ export declare const createEventValidation: () => zod.ZodArray<zod.ZodObject<{
|
|
|
32
32
|
SK: string;
|
|
33
33
|
tableName: string;
|
|
34
34
|
tableType: import("../../../types").DynamoDBTableType;
|
|
35
|
-
command: "
|
|
35
|
+
command: "delete" | "put" | "update";
|
|
36
36
|
}[]>>;
|
|
37
37
|
source: zod.ZodObject<{
|
|
38
38
|
name: zod.ZodString;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { APIGatewayProxyEvent } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import { ApiGatewayEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/ApiGatewayEventHandler.js";
|
|
3
|
+
import type { EventContext, NextFunction } from "@webiny/event-handler-core";
|
|
4
|
+
import type { ISyncSystemConfig } from "./SyncSystemConfig.js";
|
|
5
|
+
declare class ApiGatewaySyncDecoratorImpl implements ApiGatewayEventHandler.Interface {
|
|
6
|
+
private config;
|
|
7
|
+
private inner;
|
|
8
|
+
constructor(config: ISyncSystemConfig, inner: ApiGatewayEventHandler.Interface);
|
|
9
|
+
execute(ctx: EventContext<APIGatewayProxyEvent>, next: NextFunction): Promise<any>;
|
|
10
|
+
}
|
|
11
|
+
export declare const ApiGatewaySyncDecorator: typeof ApiGatewaySyncDecoratorImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-aws/abstractions/handlers/ApiGatewayEventHandler.js").IApiGatewayEventHandler>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ApiGatewayEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/ApiGatewayEventHandler.js";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import { SyncSystemConfig } from "./SyncSystemConfig.js";
|
|
4
|
+
import { createHandler } from "./createHandler.js";
|
|
5
|
+
import { getManifest } from "./utils/manifest.js";
|
|
6
|
+
import { decorateClientWithHandler } from "./attachToDynamoDbDocument.js";
|
|
7
|
+
import { createDefaultFilterOutRecordPlugins } from "./filter/createDefaultFilterOutRecordPlugins.js";
|
|
8
|
+
class ApiGatewaySyncDecoratorImpl {
|
|
9
|
+
constructor(config, inner){
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.inner = inner;
|
|
12
|
+
}
|
|
13
|
+
async execute(ctx, next) {
|
|
14
|
+
const { data: manifest, error } = await getManifest();
|
|
15
|
+
if (error || !manifest?.sync?.region) {
|
|
16
|
+
if ("true" === process.env.DEBUG) console.warn("[ApiGatewaySyncDecorator] Manifest not available — sync disabled.");
|
|
17
|
+
return this.inner.execute(ctx, next);
|
|
18
|
+
}
|
|
19
|
+
const filterPlugins = [
|
|
20
|
+
...createDefaultFilterOutRecordPlugins(),
|
|
21
|
+
...this.config.plugins || []
|
|
22
|
+
];
|
|
23
|
+
const { handler } = createHandler({
|
|
24
|
+
getEventBridgeClient: this.config.getEventBridgeClient,
|
|
25
|
+
system: this.config.system,
|
|
26
|
+
manifest,
|
|
27
|
+
getPlugins: ()=>new PluginsContainer(filterPlugins)
|
|
28
|
+
});
|
|
29
|
+
const documentClient = this.config.getDocumentClient();
|
|
30
|
+
decorateClientWithHandler({
|
|
31
|
+
handler,
|
|
32
|
+
client: documentClient
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
return await this.inner.execute(ctx, next);
|
|
36
|
+
} finally{
|
|
37
|
+
await handler.flush();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const ApiGatewaySyncDecorator = ApiGatewayEventHandler.createDecorator({
|
|
42
|
+
decorator: ApiGatewaySyncDecoratorImpl,
|
|
43
|
+
dependencies: [
|
|
44
|
+
SyncSystemConfig
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
export { ApiGatewaySyncDecorator };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=ApiGatewaySyncDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync/ApiGatewaySyncDecorator.js","sources":["../../src/sync/ApiGatewaySyncDecorator.ts"],"sourcesContent":["import type { APIGatewayProxyEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { ApiGatewayEventHandler } from \"@webiny/event-handler-aws/abstractions/handlers/ApiGatewayEventHandler.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport type { EventContext, NextFunction } from \"@webiny/event-handler-core\";\nimport { SyncSystemConfig } from \"./SyncSystemConfig.js\";\nimport type { ISyncSystemConfig } from \"./SyncSystemConfig.js\";\nimport { createHandler } from \"~/sync/createHandler.js\";\nimport { getManifest } from \"~/sync/utils/manifest.js\";\nimport { decorateClientWithHandler } from \"~/sync/attachToDynamoDbDocument.js\";\nimport { createDefaultFilterOutRecordPlugins } from \"~/sync/filter/createDefaultFilterOutRecordPlugins.js\";\n\nclass ApiGatewaySyncDecoratorImpl implements ApiGatewayEventHandler.Interface {\n constructor(\n private config: ISyncSystemConfig,\n private inner: ApiGatewayEventHandler.Interface\n ) {}\n\n async execute(ctx: EventContext<APIGatewayProxyEvent>, next: NextFunction): Promise<any> {\n const { data: manifest, error } = await getManifest();\n if (error || !manifest?.sync?.region) {\n if (process.env.DEBUG === \"true\") {\n console.warn(\"[ApiGatewaySyncDecorator] Manifest not available — sync disabled.\");\n }\n return this.inner.execute(ctx, next);\n }\n\n const filterPlugins = [\n ...createDefaultFilterOutRecordPlugins(),\n ...(this.config.plugins || [])\n ];\n\n const { handler } = createHandler({\n getEventBridgeClient: this.config.getEventBridgeClient,\n system: this.config.system,\n manifest,\n getPlugins: () => new PluginsContainer(filterPlugins)\n });\n\n const documentClient = this.config.getDocumentClient();\n decorateClientWithHandler({ handler, client: documentClient as any });\n\n try {\n return await this.inner.execute(ctx, next);\n } finally {\n await handler.flush();\n }\n }\n}\n\nexport const ApiGatewaySyncDecorator = ApiGatewayEventHandler.createDecorator({\n decorator: ApiGatewaySyncDecoratorImpl,\n dependencies: [SyncSystemConfig]\n});\n"],"names":["ApiGatewaySyncDecoratorImpl","config","inner","ctx","next","manifest","error","getManifest","process","console","filterPlugins","createDefaultFilterOutRecordPlugins","handler","createHandler","PluginsContainer","documentClient","decorateClientWithHandler","ApiGatewaySyncDecorator","ApiGatewayEventHandler","SyncSystemConfig"],"mappings":";;;;;;;AAWA,MAAMA;IACF,YACYC,MAAyB,EACzBC,KAAuC,CACjD;aAFUD,MAAM,GAANA;aACAC,KAAK,GAALA;IACT;IAEH,MAAM,QAAQC,GAAuC,EAAEC,IAAkB,EAAgB;QACrF,MAAM,EAAE,MAAMC,QAAQ,EAAEC,KAAK,EAAE,GAAG,MAAMC;QACxC,IAAID,SAAS,CAACD,UAAU,MAAM,QAAQ;YAClC,IAAIG,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK,EACjBC,QAAQ,IAAI,CAAC;YAEjB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAACN,KAAKC;QACnC;QAEA,MAAMM,gBAAgB;eACfC;eACC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE;SAChC;QAED,MAAM,EAAEC,OAAO,EAAE,GAAGC,cAAc;YAC9B,sBAAsB,IAAI,CAAC,MAAM,CAAC,oBAAoB;YACtD,QAAQ,IAAI,CAAC,MAAM,CAAC,MAAM;YAC1BR;YACA,YAAY,IAAM,IAAIS,iBAAiBJ;QAC3C;QAEA,MAAMK,iBAAiB,IAAI,CAAC,MAAM,CAAC,iBAAiB;QACpDC,0BAA0B;YAAEJ;YAAS,QAAQG;QAAsB;QAEnE,IAAI;YACA,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAACZ,KAAKC;QACzC,SAAU;YACN,MAAMQ,QAAQ,KAAK;QACvB;IACJ;AACJ;AAEO,MAAMK,0BAA0BC,uBAAuB,eAAe,CAAC;IAC1E,WAAWlB;IACX,cAAc;QAACmB;KAAiB;AACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EventBridgeClient } from "@webiny/aws-sdk/client-eventbridge/index.js";
|
|
2
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
|
+
import type { ISystem } from "./types.js";
|
|
4
|
+
import type { FilterOutRecordPlugin } from "./plugins/FilterOutRecordPlugin.js";
|
|
5
|
+
export interface ISyncSystemConfig {
|
|
6
|
+
getDocumentClient(): Pick<DynamoDBDocument, "send">;
|
|
7
|
+
getEventBridgeClient(): Pick<EventBridgeClient, "send">;
|
|
8
|
+
system: ISystem;
|
|
9
|
+
plugins?: FilterOutRecordPlugin[];
|
|
10
|
+
}
|
|
11
|
+
export declare const SyncSystemConfig: import("@webiny/di").Abstraction<ISyncSystemConfig>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync/SyncSystemConfig.js","sources":["../../src/sync/SyncSystemConfig.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { EventBridgeClient } from \"@webiny/aws-sdk/client-eventbridge/index.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { ISystem } from \"./types.js\";\nimport type { FilterOutRecordPlugin } from \"./plugins/FilterOutRecordPlugin.js\";\n\nexport interface ISyncSystemConfig {\n getDocumentClient(): Pick<DynamoDBDocument, \"send\">;\n getEventBridgeClient(): Pick<EventBridgeClient, \"send\">;\n system: ISystem;\n plugins?: FilterOutRecordPlugin[];\n}\n\nexport const SyncSystemConfig = createAbstraction<ISyncSystemConfig>(\"SyncSystemConfig\");\n"],"names":["SyncSystemConfig","createAbstraction"],"mappings":";AAaO,MAAMA,mBAAmBC,kBAAqC"}
|
package/sync/utils/manifest.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export interface IGetManifestParams {
|
|
3
|
-
getDocumentClient(): Pick<DynamoDBDocument, "send">;
|
|
4
|
-
}
|
|
5
|
-
export declare const getManifest: (params: IGetManifestParams) => Promise<{
|
|
1
|
+
export declare const getManifest: () => Promise<{
|
|
6
2
|
data: {
|
|
7
3
|
sync: {
|
|
8
4
|
eventBusArn: string;
|
|
@@ -12,6 +8,6 @@ export declare const getManifest: (params: IGetManifestParams) => Promise<{
|
|
|
12
8
|
};
|
|
13
9
|
error?: undefined;
|
|
14
10
|
} | {
|
|
15
|
-
error: any;
|
|
16
11
|
data?: undefined;
|
|
12
|
+
error: any;
|
|
17
13
|
}>;
|
package/sync/utils/manifest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServiceDiscovery } from "@webiny/api";
|
|
1
|
+
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
2
2
|
import zod from "zod";
|
|
3
3
|
import { createZodError } from "@webiny/utils";
|
|
4
4
|
const validateManifest = zod.object({
|
|
@@ -8,10 +8,8 @@ const validateManifest = zod.object({
|
|
|
8
8
|
region: zod.string()
|
|
9
9
|
})
|
|
10
10
|
});
|
|
11
|
-
const getManifest = async (
|
|
12
|
-
const documentClient = params.getDocumentClient();
|
|
11
|
+
const getManifest = async ()=>{
|
|
13
12
|
try {
|
|
14
|
-
ServiceDiscovery.setDocumentClient(documentClient);
|
|
15
13
|
const manifest = await ServiceDiscovery.load();
|
|
16
14
|
if (!manifest?.sync) return {
|
|
17
15
|
error: new Error("Sync System Manifest not found. Probably Sync System is not turned on.")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync/utils/manifest.js","sources":["../../../src/sync/utils/manifest.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api\";\nimport zod from \"zod\";\nimport { createZodError } from \"@webiny/utils\";\
|
|
1
|
+
{"version":3,"file":"sync/utils/manifest.js","sources":["../../../src/sync/utils/manifest.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport zod from \"zod\";\nimport { createZodError } from \"@webiny/utils\";\n\nconst validateManifest = zod.object({\n sync: zod.object({\n eventBusArn: zod.string(),\n eventBusName: zod.string(),\n region: zod.string()\n })\n});\n\nexport const getManifest = async () => {\n try {\n const manifest = await ServiceDiscovery.load();\n if (!manifest?.sync) {\n return {\n /*\n * This error will be silent. We do not want to log or throw at this point.\n */\n error: new Error(\n \"Sync System Manifest not found. Probably Sync System is not turned on.\"\n )\n };\n }\n const { data, error } = validateManifest.safeParse(manifest);\n if (error) {\n const err = createZodError(error);\n return {\n error: err\n };\n }\n return {\n data\n };\n } catch (ex) {\n return {\n error: ex\n };\n }\n};\n"],"names":["validateManifest","zod","getManifest","manifest","ServiceDiscovery","Error","data","error","err","createZodError","ex"],"mappings":";;;AAIA,MAAMA,mBAAmBC,IAAI,MAAM,CAAC;IAChC,MAAMA,IAAI,MAAM,CAAC;QACb,aAAaA,IAAI,MAAM;QACvB,cAAcA,IAAI,MAAM;QACxB,QAAQA,IAAI,MAAM;IACtB;AACJ;AAEO,MAAMC,cAAc;IACvB,IAAI;QACA,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAC5C,IAAI,CAACD,UAAU,MACX,OAAO;YAIH,OAAO,IAAIE,MACP;QAER;QAEJ,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAGP,iBAAiB,SAAS,CAACG;QACnD,IAAII,OAAO;YACP,MAAMC,MAAMC,eAAeF;YAC3B,OAAO;gBACH,OAAOC;YACX;QACJ;QACA,OAAO;YACHF;QACJ;IACJ,EAAE,OAAOI,IAAI;QACT,OAAO;YACH,OAAOA;QACX;IACJ;AACJ"}
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Context as BaseContext } from "@webiny/handler-aws/types.js";
|
|
2
1
|
export type CommandType = "put" | "delete";
|
|
3
2
|
export type ExtendedCommandType = "put" | "delete" | "update";
|
|
4
3
|
export type AllCommandType = ExtendedCommandType | "batchWrite" | "null";
|
|
@@ -7,7 +6,6 @@ export declare enum DynamoDBTableType {
|
|
|
7
6
|
OPENSEARCH = "opensearch",
|
|
8
7
|
UNKNOWN = "unknown"
|
|
9
8
|
}
|
|
10
|
-
export type Context = BaseContext;
|
|
11
9
|
export interface IFileLambdaPayloadInfo {
|
|
12
10
|
bucket: string;
|
|
13
11
|
region: string;
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["export type CommandType = \"put\" | \"delete\";\nexport type ExtendedCommandType = \"put\" | \"delete\" | \"update\";\nexport type AllCommandType = ExtendedCommandType | \"batchWrite\" | \"null\";\n\nexport enum DynamoDBTableType {\n REGULAR = \"regular\",\n OPENSEARCH = \"opensearch\",\n UNKNOWN = \"unknown\"\n}\n\nexport interface IFileLambdaPayloadInfo {\n bucket: string;\n region: string;\n}\n\nexport interface ICopyFileLambdaPayload {\n action: \"copyFile\";\n key: string;\n source: IFileLambdaPayloadInfo;\n target: IFileLambdaPayloadInfo;\n}\n\nexport interface IDeleteFileLambdaPayload {\n action: \"deleteFile\";\n key: string;\n target: IFileLambdaPayloadInfo;\n}\n\nexport interface IUserLambdaPayloadInfo {\n region: string;\n userPoolId: string;\n}\n\nexport interface IDeleteUserLambdaPayload {\n action: \"deleteUser\";\n username: string;\n target: IUserLambdaPayloadInfo;\n}\n\nexport interface ICopyUserLambdaPayload {\n action: \"createUser\" | \"updateUser\";\n username: string;\n source: IUserLambdaPayloadInfo;\n target: IUserLambdaPayloadInfo;\n}\n"],"names":["DynamoDBTableType"],"mappings":"AAIO,IAAKA,0BAAiBA,WAAAA,GAAAA,SAAjBA,iBAAiB;;;;WAAjBA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { S3Client, S3ClientConfig } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
|
+
import type { CognitoIdentityProvider, CognitoIdentityProviderClientConfig } from "@webiny/aws-sdk/client-cognito-identity-provider/index.js";
|
|
3
|
+
import type { Plugin } from "@webiny/plugins/types.js";
|
|
4
|
+
export interface ISyncWorkerConfig {
|
|
5
|
+
createS3Client(config: S3ClientConfig): Pick<S3Client, "send">;
|
|
6
|
+
createCognitoIdentityProviderClient(config: CognitoIdentityProviderClientConfig): Pick<CognitoIdentityProvider, "send">;
|
|
7
|
+
plugins?: Plugin[];
|
|
8
|
+
}
|
|
9
|
+
export declare const SyncWorkerConfig: import("@webiny/di").Abstraction<ISyncWorkerConfig>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker/SyncWorkerConfig.js","sources":["../../src/worker/SyncWorkerConfig.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { S3Client, S3ClientConfig } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport type {\n CognitoIdentityProvider,\n CognitoIdentityProviderClientConfig\n} from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport type { Plugin } from \"@webiny/plugins/types.js\";\n\nexport interface ISyncWorkerConfig {\n createS3Client(config: S3ClientConfig): Pick<S3Client, \"send\">;\n createCognitoIdentityProviderClient(\n config: CognitoIdentityProviderClientConfig\n ): Pick<CognitoIdentityProvider, \"send\">;\n plugins?: Plugin[];\n}\n\nexport const SyncWorkerConfig = createAbstraction<ISyncWorkerConfig>(\"SyncWorkerConfig\");\n"],"names":["SyncWorkerConfig","createAbstraction"],"mappings":";AAgBO,MAAMA,mBAAmBC,kBAAqC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IEventHandler } from "@webiny/event-handler-core";
|
|
2
|
+
export interface ISyncWorkerEvent {
|
|
3
|
+
action: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface ISyncWorkerResult {
|
|
7
|
+
success: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ISyncWorkerEventHandler extends IEventHandler<ISyncWorkerEvent, ISyncWorkerResult> {
|
|
10
|
+
}
|
|
11
|
+
export declare const SyncWorkerEventHandler: import("@webiny/di").Abstraction<ISyncWorkerEventHandler>;
|
|
12
|
+
export declare namespace SyncWorkerEventHandler {
|
|
13
|
+
type Interface = ISyncWorkerEventHandler;
|
|
14
|
+
}
|