@webiny/api-core-ddb 6.3.0 → 6.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adminUsers/definitions/entities.js +5 -6
- package/adminUsers/definitions/entities.js.map +1 -1
- package/adminUsers/definitions/types.js +0 -3
- package/adminUsers/index.js +135 -156
- package/adminUsers/index.js.map +1 -1
- package/adminUsers/types.js +5 -4
- package/adminUsers/types.js.map +1 -1
- package/createApiCoreDdb.js +19 -22
- package/createApiCoreDdb.js.map +1 -1
- package/index.js +0 -2
- package/keyValueStore/KeyValueStoreDynamoTable.js +24 -25
- package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -1
- package/keyValueStore/KeyValueStoreStorageOperations.d.ts +2 -1
- package/keyValueStore/KeyValueStoreStorageOperations.js +72 -72
- package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -1
- package/keyValueStore/index.js +2 -3
- package/keyValueStore/index.js.map +1 -1
- package/package.json +9 -9
- package/security/definitions/entities.js +19 -24
- package/security/definitions/entities.js.map +1 -1
- package/security/definitions/types.js +0 -3
- package/security/index.js +389 -464
- package/security/index.js.map +1 -1
- package/security/types.js +6 -5
- package/security/types.js.map +1 -1
- package/tenancy/definitions/tenantEntity.js +5 -9
- package/tenancy/definitions/tenantEntity.js.map +1 -1
- package/tenancy/definitions/types.js +0 -3
- package/tenancy/index.js +107 -127
- package/tenancy/index.js.map +1 -1
- package/tenancy/types.js +4 -3
- package/tenancy/types.js.map +1 -1
- package/adminUsers/definitions/types.js.map +0 -1
- package/index.js.map +0 -1
- package/security/definitions/types.js.map +0 -1
- package/tenancy/definitions/types.js.map +0 -1
|
@@ -1,83 +1,83 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
2
|
import { KeyValueStoreDynamoTable } from "./KeyValueStoreDynamoTable.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
createScopedKey(key, scope) {
|
|
9
|
-
return `${scope}:${key}`;
|
|
10
|
-
}
|
|
11
|
-
async get(key, scope) {
|
|
12
|
-
try {
|
|
13
|
-
const scopedKey = this.createScopedKey(key, scope);
|
|
14
|
-
const entry = await this.entity.get(this.table.createKeys({
|
|
15
|
-
scopedKey
|
|
16
|
-
}));
|
|
17
|
-
if (!entry) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Return the user-facing key without scope prefix
|
|
22
|
-
return {
|
|
23
|
-
key,
|
|
24
|
-
value: entry.data.value,
|
|
25
|
-
scope: entry.data.scope
|
|
26
|
-
};
|
|
27
|
-
} catch (err) {
|
|
28
|
-
throw WebinyError.from(err, {
|
|
29
|
-
message: "Could not get key-value record.",
|
|
30
|
-
code: "GET_KEY_VALUE_ERROR",
|
|
31
|
-
data: {
|
|
32
|
-
key,
|
|
33
|
-
scope
|
|
34
|
-
}
|
|
35
|
-
});
|
|
3
|
+
class KeyValueStoreStorageOperations {
|
|
4
|
+
constructor(dynamoDbClient){
|
|
5
|
+
this.table = new KeyValueStoreDynamoTable(dynamoDbClient);
|
|
6
|
+
this.entity = this.table.getEntity();
|
|
36
7
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
8
|
+
createScopedKey(key, scope) {
|
|
9
|
+
return `${scope}:${key}`;
|
|
10
|
+
}
|
|
11
|
+
async get(key, scope) {
|
|
12
|
+
try {
|
|
13
|
+
const scopedKey = this.createScopedKey(key, scope);
|
|
14
|
+
const entry = await this.entity.get(this.table.createKeys({
|
|
15
|
+
scopedKey
|
|
16
|
+
}));
|
|
17
|
+
if (!entry) return null;
|
|
18
|
+
const ttl = Number(entry.expiresAt);
|
|
19
|
+
if (ttl && ttl <= Math.floor(Date.now() / 1000)) return null;
|
|
20
|
+
return {
|
|
21
|
+
key,
|
|
22
|
+
value: entry.data.value,
|
|
23
|
+
scope: entry.data.scope
|
|
24
|
+
};
|
|
25
|
+
} catch (err) {
|
|
26
|
+
throw WebinyError.from(err, {
|
|
27
|
+
message: "Could not get key-value record.",
|
|
28
|
+
code: "GET_KEY_VALUE_ERROR",
|
|
29
|
+
data: {
|
|
30
|
+
key,
|
|
31
|
+
scope
|
|
32
|
+
}
|
|
33
|
+
});
|
|
51
34
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
35
|
+
}
|
|
36
|
+
async set(key, value, scope, options) {
|
|
37
|
+
try {
|
|
38
|
+
const scopedKey = this.createScopedKey(key, scope);
|
|
39
|
+
const keys = this.table.createKeys({
|
|
40
|
+
scopedKey
|
|
41
|
+
});
|
|
42
|
+
await this.entity.put({
|
|
43
|
+
...keys,
|
|
44
|
+
TYPE: "KeyValueStore",
|
|
45
|
+
expiresAt: options?.expiresAt ? Math.floor(options.expiresAt.getTime() / 1000) : void 0,
|
|
46
|
+
data: {
|
|
47
|
+
key,
|
|
48
|
+
value,
|
|
49
|
+
scope
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
} catch (err) {
|
|
53
|
+
throw WebinyError.from(err, {
|
|
54
|
+
message: "Could not set key-value record.",
|
|
55
|
+
code: "SET_KEY_VALUE_ERROR",
|
|
56
|
+
data: {
|
|
57
|
+
key,
|
|
58
|
+
scope
|
|
59
|
+
}
|
|
60
|
+
});
|
|
60
61
|
}
|
|
61
|
-
});
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
async delete(key, scope) {
|
|
64
|
+
try {
|
|
65
|
+
const scopedKey = this.createScopedKey(key, scope);
|
|
66
|
+
await this.entity.delete(this.table.createKeys({
|
|
67
|
+
scopedKey
|
|
68
|
+
}));
|
|
69
|
+
} catch (err) {
|
|
70
|
+
throw WebinyError.from(err, {
|
|
71
|
+
message: "Could not delete key-value record.",
|
|
72
|
+
code: "DELETE_KEY_VALUE_ERROR",
|
|
73
|
+
data: {
|
|
74
|
+
key,
|
|
75
|
+
scope
|
|
76
|
+
}
|
|
77
|
+
});
|
|
77
78
|
}
|
|
78
|
-
});
|
|
79
79
|
}
|
|
80
|
-
}
|
|
81
80
|
}
|
|
81
|
+
export { KeyValueStoreStorageOperations };
|
|
82
82
|
|
|
83
83
|
//# sourceMappingURL=KeyValueStoreStorageOperations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"keyValueStore/KeyValueStoreStorageOperations.js","sources":["../../src/keyValueStore/KeyValueStoreStorageOperations.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { IKeyValueStoreSetOptions } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport { KeyValueStoreDynamoTable } from \"./KeyValueStoreDynamoTable.js\";\n\ninterface KeyValueRecord {\n key: string;\n value: any;\n scope: string;\n}\n\nexport class KeyValueStoreStorageOperations {\n private readonly table;\n private readonly entity;\n\n constructor(dynamoDbClient: DynamoDBDocument) {\n this.table = new KeyValueStoreDynamoTable<KeyValueRecord>(dynamoDbClient);\n this.entity = this.table.getEntity();\n }\n\n private createScopedKey(key: string, scope: string): string {\n return `${scope}:${key}`;\n }\n\n async get(key: string, scope: string): Promise<KeyValueRecord | null> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const entry = await this.entity.get(this.table.createKeys({ scopedKey }));\n\n if (!entry) {\n return null;\n }\n\n const ttl = Number(entry.expiresAt);\n if (ttl && ttl <= Math.floor(Date.now() / 1000)) {\n return null;\n }\n\n return {\n key,\n value: entry.data.value,\n scope: entry.data.scope\n };\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not get key-value record.\",\n code: \"GET_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n\n async set(\n key: string,\n value: any,\n scope: string,\n options?: IKeyValueStoreSetOptions\n ): Promise<void> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const keys = this.table.createKeys({ scopedKey });\n\n await this.entity.put({\n ...keys,\n TYPE: \"KeyValueStore\",\n expiresAt: options?.expiresAt\n ? Math.floor(options.expiresAt.getTime() / 1000)\n : undefined,\n data: {\n key,\n value,\n scope\n }\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not set key-value record.\",\n code: \"SET_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n\n async delete(key: string, scope: string): Promise<void> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n await this.entity.delete(this.table.createKeys({ scopedKey }));\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete key-value record.\",\n code: \"DELETE_KEY_VALUE_ERROR\",\n data: { key, scope }\n });\n }\n }\n}\n"],"names":["KeyValueStoreStorageOperations","dynamoDbClient","KeyValueStoreDynamoTable","key","scope","scopedKey","entry","ttl","Number","Math","Date","err","WebinyError","value","options","keys","undefined"],"mappings":";;AAWO,MAAMA;IAIT,YAAYC,cAAgC,CAAE;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAIC,yBAAyCD;QAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS;IACtC;IAEQ,gBAAgBE,GAAW,EAAEC,KAAa,EAAU;QACxD,OAAO,GAAGA,MAAM,CAAC,EAAED,KAAK;IAC5B;IAEA,MAAM,IAAIA,GAAW,EAAEC,KAAa,EAAkC;QAClE,IAAI;YACA,MAAMC,YAAY,IAAI,CAAC,eAAe,CAACF,KAAKC;YAC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AAC;gBAAEC;YAAU;QAC/D,EAAE,OAAOM,KAAK;YACV,MAAMC,YAAY,IAAI,CAACD,KAAK;gBACxB,SAAS;gBACT,MAAM;gBACN,MAAM;oBAAER;oBAAKC;gBAAM;YACvB;QACJ;IACJ;AACJ"}
|
package/keyValueStore/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { KeyValueStoreStorageOperations } from "./KeyValueStoreStorageOperations.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
const createStorageOperations = (params)=>new KeyValueStoreStorageOperations(params.documentClient);
|
|
3
|
+
export { createStorageOperations };
|
|
5
4
|
|
|
6
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"keyValueStore/index.js","sources":["../../src/keyValueStore/index.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { KeyValueStoreStorageOperations } from \"./KeyValueStoreStorageOperations.js\";\n\nexport interface CreateKeyValueStoreStorageOperations {\n (params: { documentClient: DynamoDBDocument }): KeyValueStoreStorageOperations;\n}\n\nexport const createStorageOperations: CreateKeyValueStoreStorageOperations = params => {\n return new KeyValueStoreStorageOperations(params.documentClient);\n};\n"],"names":["createStorageOperations","params","KeyValueStoreStorageOperations"],"mappings":";AAOO,MAAMA,0BAAgEC,CAAAA,SAClE,IAAIC,+BAA+BD,OAAO,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core-ddb",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"author": "Webiny Ltd.",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@webiny/api": "6.
|
|
25
|
-
"@webiny/api-core": "6.
|
|
26
|
-
"@webiny/aws-sdk": "6.
|
|
27
|
-
"@webiny/db-dynamodb": "6.
|
|
28
|
-
"@webiny/error": "6.
|
|
24
|
+
"@webiny/api": "6.4.0-beta.1",
|
|
25
|
+
"@webiny/api-core": "6.4.0-beta.1",
|
|
26
|
+
"@webiny/aws-sdk": "6.4.0-beta.1",
|
|
27
|
+
"@webiny/db-dynamodb": "6.4.0-beta.1",
|
|
28
|
+
"@webiny/error": "6.4.0-beta.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@webiny/api": "0.0.0",
|
|
32
|
-
"@webiny/build-tools": "6.
|
|
33
|
-
"@webiny/project-utils": "6.
|
|
32
|
+
"@webiny/build-tools": "6.4.0-beta.1",
|
|
33
|
+
"@webiny/project-utils": "6.4.0-beta.1",
|
|
34
34
|
"jest-dynalite": "3.6.1",
|
|
35
35
|
"rimraf": "6.1.3",
|
|
36
36
|
"typescript": "6.0.3"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"access": "public",
|
|
40
40
|
"directory": "dist"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "73237b8243693038c072bae1c0b783387448cbbe"
|
|
43
43
|
}
|
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import { createStandardEntity, standardEntityAttributes } from "@webiny/db-dynamodb";
|
|
2
2
|
import { ENTITIES } from "../types.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
attributes: {
|
|
23
|
-
...standardEntityAttributes
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
};
|
|
3
|
+
const createRoleEntity = (table)=>createStandardEntity({
|
|
4
|
+
name: ENTITIES.ROLE,
|
|
5
|
+
table
|
|
6
|
+
});
|
|
7
|
+
const createTeamEntity = (table)=>createStandardEntity({
|
|
8
|
+
name: ENTITIES.TEAM,
|
|
9
|
+
table,
|
|
10
|
+
attributes: {
|
|
11
|
+
...standardEntityAttributes
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const createApiKeyEntity = (table)=>createStandardEntity({
|
|
15
|
+
name: ENTITIES.API_KEY,
|
|
16
|
+
table,
|
|
17
|
+
attributes: {
|
|
18
|
+
...standardEntityAttributes
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export { createApiKeyEntity, createRoleEntity, createTeamEntity };
|
|
27
22
|
|
|
28
23
|
//# sourceMappingURL=entities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"security/definitions/entities.js","sources":["../../../src/security/definitions/entities.ts"],"sourcesContent":["import { createStandardEntity, standardEntityAttributes } from \"@webiny/db-dynamodb\";\nimport type { StorageApiKey, StorageRole, StorageTeam } from \"@webiny/api-core/types/security.js\";\nimport type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport { ENTITIES } from \"../types.js\";\nimport type { IApiKeyEntity, IRoleEntity, ITeamEntity } from \"~/security/definitions/types.js\";\n\nexport const createRoleEntity = (table: Table<string, string, string>): IRoleEntity => {\n return createStandardEntity<StorageRole>({\n name: ENTITIES.ROLE,\n table\n });\n};\n\nexport const createTeamEntity = (table: Table<string, string, string>): ITeamEntity => {\n return createStandardEntity<StorageTeam>({\n name: ENTITIES.TEAM,\n table,\n attributes: {\n ...standardEntityAttributes\n }\n });\n};\n\nexport const createApiKeyEntity = (table: Table<string, string, string>): IApiKeyEntity => {\n return createStandardEntity<StorageApiKey>({\n name: ENTITIES.API_KEY,\n table,\n attributes: {\n ...standardEntityAttributes\n }\n });\n};\n"],"names":["createRoleEntity","table","createStandardEntity","ENTITIES","createTeamEntity","standardEntityAttributes","createApiKeyEntity"],"mappings":";;AAMO,MAAMA,mBAAmB,CAACC,QACtBC,qBAAkC;QACrC,MAAMC,SAAS,IAAI;QACnBF;IACJ;AAGG,MAAMG,mBAAmB,CAACH,QACtBC,qBAAkC;QACrC,MAAMC,SAAS,IAAI;QACnBF;QACA,YAAY;YACR,GAAGI,wBAAwB;QAC/B;IACJ;AAGG,MAAMC,qBAAqB,CAACL,QACxBC,qBAAoC;QACvC,MAAMC,SAAS,OAAO;QACtBF;QACA,YAAY;YACR,GAAGI,wBAAwB;QAC/B;IACJ"}
|