@webiny/api-websockets-ddb 0.0.0-unstable.0d717d18dd
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/LICENSE +21 -0
- package/README.md +11 -0
- package/WebsocketsConnectionRegistry.d.ts +16 -0
- package/WebsocketsConnectionRegistry.js +121 -0
- package/WebsocketsConnectionRegistry.js.map +1 -0
- package/WebsocketsDdbFeature.d.ts +5 -0
- package/WebsocketsDdbFeature.js +16 -0
- package/WebsocketsDdbFeature.js.map +1 -0
- package/entity.d.ts +2 -0
- package/entity.js +48 -0
- package/entity.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/api-websockets-ddb
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ConnectionRegistry } from "@webiny/api-websockets/exports/api.js";
|
|
2
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
|
+
export declare class WebsocketsConnectionRegistry implements ConnectionRegistry.Interface {
|
|
4
|
+
private readonly entity;
|
|
5
|
+
constructor(documentClient: DynamoDBDocument);
|
|
6
|
+
register(params: ConnectionRegistry.RegisterParams): Promise<ConnectionRegistry.Data>;
|
|
7
|
+
unregister(params: ConnectionRegistry.UnregisterParams): Promise<void>;
|
|
8
|
+
private getViaConnection;
|
|
9
|
+
listViaConnections(connections: string[]): Promise<ConnectionRegistry.Data[]>;
|
|
10
|
+
listViaIdentity(identity: string): Promise<ConnectionRegistry.Data[]>;
|
|
11
|
+
listViaTenant(tenant: string): Promise<ConnectionRegistry.Data[]>;
|
|
12
|
+
listAll(): Promise<ConnectionRegistry.Data[]>;
|
|
13
|
+
updateLastSeen(_connectionId: string): Promise<void>;
|
|
14
|
+
listStale(_olderThan: Date): Promise<ConnectionRegistry.Data[]>;
|
|
15
|
+
private store;
|
|
16
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { createEntity } from "./entity.js";
|
|
3
|
+
const PK = "WS#CONNECTIONS";
|
|
4
|
+
const GSI1_PK = "WS#CONNECTIONS#IDENTITY";
|
|
5
|
+
const GSI2_PK = "WS#CONNECTIONS#TENANT";
|
|
6
|
+
class WebsocketsConnectionRegistry {
|
|
7
|
+
constructor(documentClient){
|
|
8
|
+
this.entity = createEntity(documentClient);
|
|
9
|
+
}
|
|
10
|
+
async register(params) {
|
|
11
|
+
const { connectionId, tenant, identity, endpoint, connectedOn } = params;
|
|
12
|
+
const data = {
|
|
13
|
+
connectionId,
|
|
14
|
+
identity,
|
|
15
|
+
tenant,
|
|
16
|
+
endpoint,
|
|
17
|
+
connectedOn
|
|
18
|
+
};
|
|
19
|
+
await this.store(data);
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
async unregister(params) {
|
|
23
|
+
const { connectionId } = params;
|
|
24
|
+
const keys = {
|
|
25
|
+
PK: PK,
|
|
26
|
+
SK: connectionId
|
|
27
|
+
};
|
|
28
|
+
const original = await this.getViaConnection(connectionId);
|
|
29
|
+
if (!original) {
|
|
30
|
+
const message = `There is no connection with ID "${connectionId}".`;
|
|
31
|
+
console.error(message);
|
|
32
|
+
throw new error(message, "CONNECTION_NOT_FOUND", keys);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
await this.entity.delete(keys);
|
|
36
|
+
} catch (ex) {
|
|
37
|
+
console.error(`Could not remove connection from the database: ${original.connectionId}`);
|
|
38
|
+
throw new error(ex.message, ex.code, keys);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async getViaConnection(connectionId) {
|
|
42
|
+
const item = await this.entity.get({
|
|
43
|
+
PK: PK,
|
|
44
|
+
SK: connectionId
|
|
45
|
+
});
|
|
46
|
+
if (!item) return null;
|
|
47
|
+
return item?.data || null;
|
|
48
|
+
}
|
|
49
|
+
async listViaConnections(connections) {
|
|
50
|
+
const reader = this.entity.createEntityReader({
|
|
51
|
+
read: connections.map((id)=>({
|
|
52
|
+
PK: PK,
|
|
53
|
+
SK: id
|
|
54
|
+
}))
|
|
55
|
+
});
|
|
56
|
+
const results = await reader.execute();
|
|
57
|
+
return results.map((item)=>item.data);
|
|
58
|
+
}
|
|
59
|
+
async listViaIdentity(identity) {
|
|
60
|
+
const items = await this.entity.queryAll({
|
|
61
|
+
partitionKey: GSI1_PK,
|
|
62
|
+
options: {
|
|
63
|
+
index: "GSI1",
|
|
64
|
+
eq: identity
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return items.map((item)=>item.data);
|
|
68
|
+
}
|
|
69
|
+
async listViaTenant(tenant) {
|
|
70
|
+
const options = {
|
|
71
|
+
beginsWith: `T#${tenant}`
|
|
72
|
+
};
|
|
73
|
+
const items = await this.entity.queryAll({
|
|
74
|
+
partitionKey: GSI2_PK,
|
|
75
|
+
options: {
|
|
76
|
+
...options,
|
|
77
|
+
index: "GSI2"
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return items.map((item)=>item.data);
|
|
81
|
+
}
|
|
82
|
+
async listAll() {
|
|
83
|
+
const items = await this.entity.queryAll({
|
|
84
|
+
partitionKey: PK,
|
|
85
|
+
options: {
|
|
86
|
+
gte: " "
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return items.map((item)=>item.data);
|
|
90
|
+
}
|
|
91
|
+
async updateLastSeen(_connectionId) {}
|
|
92
|
+
async listStale(_olderThan) {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
async store(data) {
|
|
96
|
+
const { connectionId, tenant, identity } = data;
|
|
97
|
+
const item = {
|
|
98
|
+
PK: PK,
|
|
99
|
+
SK: connectionId,
|
|
100
|
+
GSI1_PK: GSI1_PK,
|
|
101
|
+
GSI1_SK: identity.id,
|
|
102
|
+
GSI2_PK: GSI2_PK,
|
|
103
|
+
GSI2_SK: `T#${tenant}`,
|
|
104
|
+
GSI_TENANT: tenant,
|
|
105
|
+
TYPE: "ws.connection",
|
|
106
|
+
data
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
return await this.entity.put(item);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
throw error.from(err, {
|
|
112
|
+
message: "Could not store websockets connection data.",
|
|
113
|
+
code: "STORE_WEBSOCKETS_CONNECTION_DATA_ERROR",
|
|
114
|
+
data: item
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export { WebsocketsConnectionRegistry };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=WebsocketsConnectionRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebsocketsConnectionRegistry.js","sources":["../src/WebsocketsConnectionRegistry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ConnectionRegistry } from \"@webiny/api-websockets/exports/api.js\";\nimport { createEntity } from \"./entity.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { EntityQueryOptions } from \"@webiny/db-dynamodb/toolbox.js\";\n\nconst PK = `WS#CONNECTIONS`;\nconst GSI1_PK = \"WS#CONNECTIONS#IDENTITY\";\nconst GSI2_PK = \"WS#CONNECTIONS#TENANT\";\n\nexport class WebsocketsConnectionRegistry implements ConnectionRegistry.Interface {\n private readonly entity;\n\n public constructor(documentClient: DynamoDBDocument) {\n this.entity = createEntity(documentClient);\n }\n\n public async register(\n params: ConnectionRegistry.RegisterParams\n ): Promise<ConnectionRegistry.Data> {\n const { connectionId, tenant, identity, endpoint, connectedOn } = params;\n\n const data: ConnectionRegistry.Data = {\n connectionId,\n identity,\n tenant,\n endpoint,\n connectedOn\n };\n await this.store(data);\n return data;\n }\n\n public async unregister(params: ConnectionRegistry.UnregisterParams): Promise<void> {\n const { connectionId } = params;\n\n const keys = {\n PK,\n SK: connectionId\n };\n const original = await this.getViaConnection(connectionId);\n if (!original) {\n const message = `There is no connection with ID \"${connectionId}\".`;\n console.error(message);\n throw new WebinyError(message, \"CONNECTION_NOT_FOUND\", keys);\n }\n\n try {\n await this.entity.delete(keys);\n } catch (ex) {\n console.error(\n `Could not remove connection from the database: ${original.connectionId}`\n );\n throw new WebinyError(ex.message, ex.code, keys);\n }\n }\n\n private async getViaConnection(connectionId: string): Promise<ConnectionRegistry.Data | null> {\n const item = await this.entity.get({\n PK,\n SK: connectionId\n });\n if (!item) {\n return null;\n }\n return item?.data || null;\n }\n\n public async listViaConnections(connections: string[]): Promise<ConnectionRegistry.Data[]> {\n const reader = this.entity.createEntityReader({\n read: connections.map(id => {\n return {\n PK,\n SK: id\n };\n })\n });\n\n const results = await reader.execute();\n\n return results.map(item => {\n return item.data;\n });\n }\n\n public async listViaIdentity(identity: string): Promise<ConnectionRegistry.Data[]> {\n const items = await this.entity.queryAll({\n partitionKey: GSI1_PK,\n options: {\n index: \"GSI1\",\n eq: identity\n }\n });\n return items.map(item => {\n return item.data;\n });\n }\n\n public async listViaTenant(tenant: string): Promise<ConnectionRegistry.Data[]> {\n const options: Partial<EntityQueryOptions> = {\n beginsWith: `T#${tenant}`\n };\n\n const items = await this.entity.queryAll({\n partitionKey: GSI2_PK,\n options: {\n ...options,\n index: \"GSI2\"\n }\n });\n return items.map(item => {\n return item.data;\n });\n }\n\n public async listAll(): Promise<ConnectionRegistry.Data[]> {\n const items = await this.entity.queryAll({\n partitionKey: PK,\n options: {\n gte: \" \"\n }\n });\n return items.map(item => {\n return item.data;\n });\n }\n\n /* No-op: heartbeat-based tracking is server-only; DDB registry does not track lastSeen. */\n public async updateLastSeen(_connectionId: string): Promise<void> {\n return;\n }\n\n /* No-op: stale connection cleanup is server-only; DDB registry always returns empty. */\n public async listStale(_olderThan: Date): Promise<ConnectionRegistry.Data[]> {\n return [];\n }\n\n private async store(data: ConnectionRegistry.Data) {\n const { connectionId, tenant, identity } = data;\n const item = {\n PK,\n SK: connectionId,\n GSI1_PK,\n GSI1_SK: identity.id,\n GSI2_PK,\n GSI2_SK: `T#${tenant}`,\n GSI_TENANT: tenant,\n TYPE: \"ws.connection\",\n data\n };\n try {\n return await this.entity.put(item);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not store websockets connection data.\",\n code: \"STORE_WEBSOCKETS_CONNECTION_DATA_ERROR\",\n data: item\n });\n }\n }\n}\n"],"names":["PK","GSI1_PK","GSI2_PK","WebsocketsConnectionRegistry","documentClient","createEntity","params","connectionId","tenant","identity","endpoint","connectedOn","data","keys","original","message","console","WebinyError","ex","item","connections","reader","id","results","items","options","_connectionId","_olderThan","err"],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { DynamoDBClient } from "@webiny/db-dynamodb";
|
|
3
|
+
import { ConnectionRegistry } from "@webiny/api-websockets/features/ConnectionRegistry/abstractions.js";
|
|
4
|
+
import { WebsocketsConnectionRegistry } from "./WebsocketsConnectionRegistry.js";
|
|
5
|
+
const WebsocketsDdbFeature = createFeature({
|
|
6
|
+
name: "WebsocketsDdb",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.registerFactory(ConnectionRegistry, ()=>{
|
|
9
|
+
const db = container.resolve(DynamoDBClient);
|
|
10
|
+
return new WebsocketsConnectionRegistry(db.client);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
export { WebsocketsDdbFeature };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=WebsocketsDdbFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebsocketsDdbFeature.js","sources":["../src/WebsocketsDdbFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { DynamoDBClient } from \"@webiny/db-dynamodb\";\nimport { ConnectionRegistry } from \"@webiny/api-websockets/features/ConnectionRegistry/abstractions.js\";\nimport { WebsocketsConnectionRegistry } from \"./WebsocketsConnectionRegistry.js\";\n\nexport const WebsocketsDdbFeature = createFeature({\n name: \"WebsocketsDdb\",\n register(container: Container) {\n container.registerFactory(ConnectionRegistry, () => {\n const db = container.resolve(DynamoDBClient);\n return new WebsocketsConnectionRegistry(db.client);\n });\n }\n});\n"],"names":["WebsocketsDdbFeature","createFeature","container","ConnectionRegistry","db","DynamoDBClient","WebsocketsConnectionRegistry"],"mappings":";;;;AAKO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,eAAe,CAACC,oBAAoB;YAC1C,MAAMC,KAAKF,UAAU,OAAO,CAACG;YAC7B,OAAO,IAAIC,6BAA6BF,GAAG,MAAM;QACrD;IACJ;AACJ"}
|
package/entity.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
export declare const createEntity: (documentClient: DynamoDBDocument) => import("@webiny/db-dynamodb").IEntity<import("@webiny/db-dynamodb").IStandardEntityAttributes<import("@webiny/api-websockets/features/ConnectionRegistry/abstractions").IWebsocketsConnectionRegistryData>>;
|
package/entity.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createStandardEntity, createTable } from "@webiny/db-dynamodb";
|
|
2
|
+
const entity_name = "SocketsConnectionRegistry";
|
|
3
|
+
const createEntity = (documentClient)=>{
|
|
4
|
+
const table = createTable({
|
|
5
|
+
name: String(process.env.DB_TABLE),
|
|
6
|
+
documentClient
|
|
7
|
+
});
|
|
8
|
+
return createStandardEntity({
|
|
9
|
+
name: entity_name,
|
|
10
|
+
table: table.table,
|
|
11
|
+
attributes: {
|
|
12
|
+
PK: {
|
|
13
|
+
partitionKey: true
|
|
14
|
+
},
|
|
15
|
+
SK: {
|
|
16
|
+
sortKey: true
|
|
17
|
+
},
|
|
18
|
+
GSI1_PK: {
|
|
19
|
+
type: "string",
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
GSI1_SK: {
|
|
23
|
+
type: "string",
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
GSI2_PK: {
|
|
27
|
+
type: "string",
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
GSI2_SK: {
|
|
31
|
+
type: "string",
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
TYPE: {
|
|
35
|
+
type: "string",
|
|
36
|
+
default: entity_name,
|
|
37
|
+
required: true
|
|
38
|
+
},
|
|
39
|
+
data: {
|
|
40
|
+
type: "map",
|
|
41
|
+
required: true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
export { createEntity };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=entity.js.map
|
package/entity.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.js","sources":["../src/entity.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { createStandardEntity, createTable } from \"@webiny/db-dynamodb\";\nimport { ConnectionRegistry } from \"@webiny/api-websockets/exports/api.js\";\n\nconst name = \"SocketsConnectionRegistry\";\n\nexport const createEntity = (documentClient: DynamoDBDocument) => {\n const table = createTable({\n name: String(process.env.DB_TABLE),\n documentClient\n });\n\n return createStandardEntity<ConnectionRegistry.Data>({\n name,\n table: table.table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\",\n required: true\n },\n GSI1_SK: {\n type: \"string\",\n required: true\n },\n GSI2_PK: {\n type: \"string\",\n required: true\n },\n GSI2_SK: {\n type: \"string\",\n required: true\n },\n TYPE: {\n type: \"string\",\n default: name,\n required: true\n },\n data: {\n type: \"map\",\n required: true\n }\n }\n });\n};\n"],"names":["name","createEntity","documentClient","table","createTable","String","process","createStandardEntity"],"mappings":";AAIA,MAAMA,cAAO;AAEN,MAAMC,eAAe,CAACC;IACzB,MAAMC,QAAQC,YAAY;QACtB,MAAMC,OAAOC,QAAQ,GAAG,CAAC,QAAQ;QACjCJ;IACJ;IAEA,OAAOK,qBAA8C;QACjDP,MAAAA;QACA,OAAOG,MAAM,KAAK;QAClB,YAAY;YACR,IAAI;gBACA,cAAc;YAClB;YACA,IAAI;gBACA,SAAS;YACb;YACA,SAAS;gBACL,MAAM;gBACN,UAAU;YACd;YACA,SAAS;gBACL,MAAM;gBACN,UAAU;YACd;YACA,SAAS;gBACL,MAAM;gBACN,UAAU;YACd;YACA,SAAS;gBACL,MAAM;gBACN,UAAU;YACd;YACA,MAAM;gBACF,MAAM;gBACN,SAASH;gBACT,UAAU;YACd;YACA,MAAM;gBACF,MAAM;gBACN,UAAU;YACd;QACJ;IACJ;AACJ"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-websockets-ddb",
|
|
3
|
+
"version": "0.0.0-unstable.0d717d18dd",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"@webiny/api-websockets",
|
|
7
|
+
"storage-operations",
|
|
8
|
+
"dynamodb",
|
|
9
|
+
"ddb",
|
|
10
|
+
"sau:ddb"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
15
|
+
},
|
|
16
|
+
"description": "DynamoDB storage operations for @webiny/api-websockets.",
|
|
17
|
+
"author": "Webiny Ltd.",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./index.js",
|
|
21
|
+
"./*": "./*"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@webiny/api-websockets": "0.0.0-unstable.0d717d18dd",
|
|
25
|
+
"@webiny/aws-sdk": "0.0.0-unstable.0d717d18dd",
|
|
26
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.0d717d18dd",
|
|
27
|
+
"@webiny/error": "0.0.0-unstable.0d717d18dd",
|
|
28
|
+
"@webiny/feature": "0.0.0-unstable.0d717d18dd"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
|
|
32
|
+
"@webiny/project-utils": "0.0.0-unstable.0d717d18dd",
|
|
33
|
+
"rimraf": "6.1.3",
|
|
34
|
+
"typescript": "7.0.2",
|
|
35
|
+
"vitest": "4.1.10"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"webiny": {
|
|
41
|
+
"publishFrom": "dist"
|
|
42
|
+
}
|
|
43
|
+
}
|