@webiny/api-core-ddb 0.0.0-unstable.0156a4c312

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/ApiCoreDdbFeature.d.ts +12 -0
  2. package/ApiCoreDdbFeature.js +16 -0
  3. package/ApiCoreDdbFeature.js.map +1 -0
  4. package/LICENSE +21 -0
  5. package/README.md +11 -0
  6. package/adminUsers/definitions/entities.d.ts +3 -0
  7. package/adminUsers/definitions/entities.js +9 -0
  8. package/adminUsers/definitions/entities.js.map +1 -0
  9. package/adminUsers/definitions/types.d.ts +5 -0
  10. package/adminUsers/definitions/types.js +0 -0
  11. package/adminUsers/index.d.ts +2 -0
  12. package/adminUsers/index.js +150 -0
  13. package/adminUsers/index.js.map +1 -0
  14. package/adminUsers/types.d.ts +22 -0
  15. package/adminUsers/types.js +8 -0
  16. package/adminUsers/types.js.map +1 -0
  17. package/createApiCoreDdb.d.ts +7 -0
  18. package/createApiCoreDdb.js +26 -0
  19. package/createApiCoreDdb.js.map +1 -0
  20. package/index.d.ts +4 -0
  21. package/index.js +3 -0
  22. package/keyValueStore/KeyValueStoreDynamoTable.d.ts +39 -0
  23. package/keyValueStore/KeyValueStoreDynamoTable.js +43 -0
  24. package/keyValueStore/KeyValueStoreDynamoTable.js.map +1 -0
  25. package/keyValueStore/KeyValueStoreStorageOperations.d.ts +28 -0
  26. package/keyValueStore/KeyValueStoreStorageOperations.js +234 -0
  27. package/keyValueStore/KeyValueStoreStorageOperations.js.map +1 -0
  28. package/keyValueStore/index.d.ts +8 -0
  29. package/keyValueStore/index.js +5 -0
  30. package/keyValueStore/index.js.map +1 -0
  31. package/package.json +45 -0
  32. package/security/definitions/entities.d.ts +5 -0
  33. package/security/definitions/entities.js +23 -0
  34. package/security/definitions/entities.js.map +1 -0
  35. package/security/definitions/types.d.ts +14 -0
  36. package/security/definitions/types.js +0 -0
  37. package/security/index.d.ts +3 -0
  38. package/security/index.js +401 -0
  39. package/security/index.js.map +1 -0
  40. package/security/types.d.ts +10 -0
  41. package/security/types.js +9 -0
  42. package/security/types.js.map +1 -0
  43. package/serviceDiscovery/DdbServiceManifestLoader.d.ts +7 -0
  44. package/serviceDiscovery/DdbServiceManifestLoader.js +27 -0
  45. package/serviceDiscovery/DdbServiceManifestLoader.js.map +1 -0
  46. package/serviceDiscovery/index.d.ts +1 -0
  47. package/serviceDiscovery/index.js +1 -0
  48. package/tenancy/definitions/tenantEntity.d.ts +8 -0
  49. package/tenancy/definitions/tenantEntity.js +8 -0
  50. package/tenancy/definitions/tenantEntity.js.map +1 -0
  51. package/tenancy/definitions/types.d.ts +6 -0
  52. package/tenancy/definitions/types.js +0 -0
  53. package/tenancy/index.d.ts +2 -0
  54. package/tenancy/index.js +115 -0
  55. package/tenancy/index.js.map +1 -0
  56. package/tenancy/types.d.ts +10 -0
  57. package/tenancy/types.js +7 -0
  58. package/tenancy/types.js.map +1 -0
@@ -0,0 +1,234 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { KeyValueStoreDynamoTable } from "./KeyValueStoreDynamoTable.js";
3
+ const nowInSeconds = ()=>Math.floor(Date.now() / 1000);
4
+ const toEpochSeconds = (date)=>Math.ceil(date.getTime() / 1000);
5
+ const isExpired = (expiresAt)=>{
6
+ const ttl = Number(expiresAt);
7
+ return Boolean(ttl) && ttl <= nowInSeconds();
8
+ };
9
+ const isConditionFailed = (error)=>error?.name === "ConditionalCheckFailedException";
10
+ const notExistsCondition = ()=>({
11
+ expression: "attribute_not_exists(#pk) OR #expiresAt <= :now",
12
+ names: {
13
+ "#pk": "PK",
14
+ "#expiresAt": "expiresAt"
15
+ },
16
+ values: {
17
+ ":now": nowInSeconds()
18
+ }
19
+ });
20
+ const liveCondition = ()=>({
21
+ expression: "attribute_exists(#pk) AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)",
22
+ names: {
23
+ "#pk": "PK",
24
+ "#expiresAt": "expiresAt"
25
+ },
26
+ values: {
27
+ ":now": nowInSeconds()
28
+ }
29
+ });
30
+ const liveValueCondition = (equals)=>({
31
+ expression: "#data.#value = :equals AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)",
32
+ names: {
33
+ "#data": "data",
34
+ "#value": "value",
35
+ "#expiresAt": "expiresAt"
36
+ },
37
+ values: {
38
+ ":equals": equals,
39
+ ":now": nowInSeconds()
40
+ }
41
+ });
42
+ const toCondition = (condition)=>{
43
+ if (!condition) return;
44
+ if (void 0 !== condition.equals) return liveValueCondition(condition.equals);
45
+ if (condition.exists) return liveCondition();
46
+ return notExistsCondition();
47
+ };
48
+ class KeyValueStoreStorageOperations {
49
+ constructor(dynamoDbClient){
50
+ this.table = new KeyValueStoreDynamoTable(dynamoDbClient);
51
+ this.entity = this.table.getEntity();
52
+ this.client = dynamoDbClient;
53
+ }
54
+ createScopedKey(key, scope) {
55
+ return `${scope}:${key}`;
56
+ }
57
+ async get(key, scope) {
58
+ try {
59
+ const scopedKey = this.createScopedKey(key, scope);
60
+ const entry = await this.entity.get(this.table.createKeys({
61
+ scopedKey
62
+ }));
63
+ if (!entry) return null;
64
+ if (isExpired(entry.expiresAt)) return null;
65
+ return {
66
+ key,
67
+ value: entry.data.value,
68
+ scope: entry.data.scope
69
+ };
70
+ } catch (err) {
71
+ throw WebinyError.from(err, {
72
+ message: "Could not get key-value record.",
73
+ code: "GET_KEY_VALUE_ERROR",
74
+ data: {
75
+ key,
76
+ scope
77
+ }
78
+ });
79
+ }
80
+ }
81
+ async set(key, value, scope, options) {
82
+ try {
83
+ const scopedKey = this.createScopedKey(key, scope);
84
+ const keys = this.table.createKeys({
85
+ scopedKey
86
+ });
87
+ const item = {
88
+ ...keys,
89
+ TYPE: "KeyValueStore",
90
+ expiresAt: options?.expiresAt ? toEpochSeconds(options.expiresAt) : void 0,
91
+ data: {
92
+ key,
93
+ value,
94
+ scope
95
+ }
96
+ };
97
+ const collection = options?.collection;
98
+ if (collection) {
99
+ const listKeys = this.table.createListKeys({
100
+ key,
101
+ scope,
102
+ collection
103
+ });
104
+ Object.assign(item, listKeys);
105
+ }
106
+ const condition = toCondition(options?.condition);
107
+ if (!condition) {
108
+ await this.entity.put(item);
109
+ return true;
110
+ }
111
+ const params = this.entity.entity.putParams(item, {
112
+ strictSchemaCheck: false
113
+ });
114
+ await this.client.put({
115
+ ...params,
116
+ ConditionExpression: condition.expression,
117
+ ExpressionAttributeNames: {
118
+ ...params.ExpressionAttributeNames,
119
+ ...condition.names
120
+ },
121
+ ExpressionAttributeValues: {
122
+ ...params.ExpressionAttributeValues,
123
+ ...condition.values
124
+ }
125
+ });
126
+ return true;
127
+ } catch (err) {
128
+ if (isConditionFailed(err)) return false;
129
+ throw WebinyError.from(err, {
130
+ message: "Could not set key-value record.",
131
+ code: "SET_KEY_VALUE_ERROR",
132
+ data: {
133
+ key,
134
+ scope
135
+ }
136
+ });
137
+ }
138
+ }
139
+ async delete(key, scope, options) {
140
+ try {
141
+ const scopedKey = this.createScopedKey(key, scope);
142
+ const keys = this.table.createKeys({
143
+ scopedKey
144
+ });
145
+ const condition = toCondition(options?.condition);
146
+ if (!condition) {
147
+ await this.entity.delete(keys);
148
+ return true;
149
+ }
150
+ const params = this.entity.entity.deleteParams(keys);
151
+ await this.client.delete({
152
+ ...params,
153
+ ConditionExpression: condition.expression,
154
+ ExpressionAttributeNames: {
155
+ ...params.ExpressionAttributeNames,
156
+ ...condition.names
157
+ },
158
+ ExpressionAttributeValues: {
159
+ ...params.ExpressionAttributeValues,
160
+ ...condition.values
161
+ }
162
+ });
163
+ return true;
164
+ } catch (err) {
165
+ if (isConditionFailed(err)) return false;
166
+ throw WebinyError.from(err, {
167
+ message: "Could not delete key-value record.",
168
+ code: "DELETE_KEY_VALUE_ERROR",
169
+ data: {
170
+ key,
171
+ scope
172
+ }
173
+ });
174
+ }
175
+ }
176
+ async list(params) {
177
+ const { collection, scope, limit, reverse, after } = params;
178
+ try {
179
+ const partitionKey = this.table.createListPartitionKey(scope, collection);
180
+ let startKey;
181
+ if (void 0 !== after) startKey = this.createStartKey({
182
+ key: after,
183
+ scope,
184
+ collection
185
+ });
186
+ const { items, lastEvaluatedKey } = await this.entity.queryPerPage({
187
+ partitionKey,
188
+ options: {
189
+ index: "GSI1",
190
+ limit: limit + 1,
191
+ reverse,
192
+ startKey
193
+ }
194
+ });
195
+ const page = items.slice(0, limit);
196
+ const keyOf = (item)=>item.data.key ?? "";
197
+ let lastKey = null;
198
+ if (items.length > limit) lastKey = keyOf(page[page.length - 1]);
199
+ else if (lastEvaluatedKey) lastKey = this.table.parseListSortKey(lastEvaluatedKey.GSI1_SK);
200
+ return {
201
+ items: page.filter((item)=>!isExpired(item.expiresAt)).map((item)=>({
202
+ key: keyOf(item),
203
+ value: item.data.value
204
+ })),
205
+ lastKey
206
+ };
207
+ } catch (err) {
208
+ throw WebinyError.from(err, {
209
+ message: "Could not list key-value records.",
210
+ code: "LIST_KEY_VALUE_ERROR",
211
+ data: {
212
+ collection,
213
+ scope,
214
+ after
215
+ }
216
+ });
217
+ }
218
+ }
219
+ createStartKey(params) {
220
+ const { key, scope } = params;
221
+ const scopedKey = this.createScopedKey(key, scope);
222
+ const tableKeys = this.table.createKeys({
223
+ scopedKey
224
+ });
225
+ const listKeys = this.table.createListKeys(params);
226
+ return {
227
+ ...tableKeys,
228
+ ...listKeys
229
+ };
230
+ }
231
+ }
232
+ export { KeyValueStoreStorageOperations };
233
+
234
+ //# sourceMappingURL=KeyValueStoreStorageOperations.js.map
@@ -0,0 +1 @@
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 { IKeyValueStorageListParams } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueStorageListResult } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueStoreSetOptions } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueDeleteOptions } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IKeyValueWriteCondition } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { KeyValueComparable } from \"@webiny/api-core/features/keyValueStore/abstractions.js\";\nimport type { IGlobalEntityAttributes } from \"@webiny/db-dynamodb\";\nimport { KeyValueStoreDynamoTable } from \"./KeyValueStoreDynamoTable.js\";\n\ninterface KeyValueRecord {\n key: string;\n value: any;\n scope: string;\n}\n\nconst nowInSeconds = (): number => {\n return Math.floor(Date.now() / 1000);\n};\n\n/*\n * DynamoDB keeps `expiresAt` in whole seconds. Rounded up, a record never counts as expired before\n * the time it was given; rounded down, an `exists: false` write could take it over up to a\n * second early.\n */\nconst toEpochSeconds = (date: Date): number => {\n return Math.ceil(date.getTime() / 1000);\n};\n\nconst isExpired = (expiresAt: unknown): boolean => {\n const ttl = Number(expiresAt);\n return Boolean(ttl) && ttl <= nowInSeconds();\n};\n\nconst isConditionFailed = (error: unknown): boolean => {\n return (error as { name?: unknown })?.name === \"ConditionalCheckFailedException\";\n};\n\ninterface ICondition {\n expression: string;\n names: Record<string, string>;\n values: Record<string, unknown>;\n}\n\n/*\n * DynamoDB's TTL deletes expired items late, so each condition checks the time itself. DynamoDB\n * rejects a name or value the expression does not use, so each condition carries exactly its own.\n */\nconst notExistsCondition = (): ICondition => {\n return {\n expression: \"attribute_not_exists(#pk) OR #expiresAt <= :now\",\n names: { \"#pk\": \"PK\", \"#expiresAt\": \"expiresAt\" },\n values: { \":now\": nowInSeconds() }\n };\n};\n\nconst liveCondition = (): ICondition => {\n return {\n expression:\n \"attribute_exists(#pk) AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)\",\n names: { \"#pk\": \"PK\", \"#expiresAt\": \"expiresAt\" },\n values: { \":now\": nowInSeconds() }\n };\n};\n\nconst liveValueCondition = (equals: KeyValueComparable): ICondition => {\n return {\n expression:\n \"#data.#value = :equals AND (attribute_not_exists(#expiresAt) OR #expiresAt > :now)\",\n names: { \"#data\": \"data\", \"#value\": \"value\", \"#expiresAt\": \"expiresAt\" },\n values: { \":equals\": equals, \":now\": nowInSeconds() }\n };\n};\n\nconst toCondition = (condition: IKeyValueWriteCondition | undefined): ICondition | undefined => {\n if (!condition) {\n return undefined;\n }\n if (condition.equals !== undefined) {\n return liveValueCondition(condition.equals);\n }\n if (condition.exists) {\n return liveCondition();\n }\n return notExistsCondition();\n};\n\nexport class KeyValueStoreStorageOperations {\n private readonly table;\n private readonly entity;\n private readonly client;\n\n constructor(dynamoDbClient: DynamoDBDocument) {\n this.table = new KeyValueStoreDynamoTable<KeyValueRecord>(dynamoDbClient);\n this.entity = this.table.getEntity();\n this.client = dynamoDbClient;\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 if (isExpired(entry.expiresAt)) {\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<boolean> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const keys = this.table.createKeys({ scopedKey });\n\n const item: IGlobalEntityAttributes<KeyValueRecord> = {\n ...keys,\n TYPE: \"KeyValueStore\",\n expiresAt: options?.expiresAt ? toEpochSeconds(options.expiresAt) : undefined,\n data: {\n key,\n value,\n scope\n }\n };\n\n /*\n * A put replaces the whole item, so a write without a collection also drops GSI1 keys\n * an earlier write gave it, which takes the record out of that collection.\n */\n const collection = options?.collection;\n if (collection) {\n const listKeys = this.table.createListKeys({ key, scope, collection });\n Object.assign(item, listKeys);\n }\n\n const condition = toCondition(options?.condition);\n if (!condition) {\n await this.entity.put(item);\n return true;\n }\n\n // The entity builds the put it would send itself, so the stored item is the same.\n const params = this.entity.entity.putParams(item, { strictSchemaCheck: false });\n await this.client.put({\n ...params,\n ConditionExpression: condition.expression,\n ExpressionAttributeNames: {\n ...params.ExpressionAttributeNames,\n ...condition.names\n },\n ExpressionAttributeValues: {\n ...params.ExpressionAttributeValues,\n ...condition.values\n }\n });\n return true;\n } catch (err) {\n if (isConditionFailed(err)) {\n return false;\n }\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, options?: IKeyValueDeleteOptions): Promise<boolean> {\n try {\n const scopedKey = this.createScopedKey(key, scope);\n const keys = this.table.createKeys({ scopedKey });\n const condition = toCondition(options?.condition);\n if (!condition) {\n await this.entity.delete(keys);\n return true;\n }\n\n const params = this.entity.entity.deleteParams(keys);\n await this.client.delete({\n ...params,\n ConditionExpression: condition.expression,\n ExpressionAttributeNames: {\n ...params.ExpressionAttributeNames,\n ...condition.names\n },\n ExpressionAttributeValues: {\n ...params.ExpressionAttributeValues,\n ...condition.values\n }\n });\n return true;\n } catch (err) {\n if (isConditionFailed(err)) {\n return false;\n }\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 async list(params: IKeyValueStorageListParams): Promise<IKeyValueStorageListResult> {\n const { collection, scope, limit, reverse, after } = params;\n try {\n const partitionKey = this.table.createListPartitionKey(scope, collection);\n\n let startKey: Record<string, string> | undefined;\n if (after !== undefined) {\n startKey = this.createStartKey({ key: after, scope, collection });\n }\n\n // One extra record tells whether another page exists without a second, empty read.\n const { items, lastEvaluatedKey } = await this.entity.queryPerPage<\n IGlobalEntityAttributes<KeyValueRecord>\n >({\n partitionKey,\n options: {\n index: \"GSI1\",\n limit: limit + 1,\n reverse,\n startKey\n }\n });\n\n const page = items.slice(0, limit);\n // A key DynamoDB holds as \"\" comes back as null from the entity.\n const keyOf = (item: (typeof items)[number]) => item.data.key ?? \"\";\n\n let lastKey: string | null = null;\n if (items.length > limit) {\n lastKey = keyOf(page[page.length - 1]);\n } else if (lastEvaluatedKey) {\n // The 1 MB read limit cut the page short of `limit`.\n lastKey = this.table.parseListSortKey(lastEvaluatedKey.GSI1_SK as string);\n }\n\n return {\n items: page\n .filter(item => !isExpired(item.expiresAt))\n .map(item => ({ key: keyOf(item), value: item.data.value })),\n lastKey\n };\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list key-value records.\",\n code: \"LIST_KEY_VALUE_ERROR\",\n data: { collection, scope, after }\n });\n }\n }\n\n /**\n * A GSI query resumes from the full key of an item: the table's own PK and SK as well as the\n * index's. All four follow from the scope, collection and key, so the item does not have to\n * exist any more.\n */\n private createStartKey(params: { key: string; scope: string; collection: string }) {\n const { key, scope } = params;\n const scopedKey = this.createScopedKey(key, scope);\n const tableKeys = this.table.createKeys({ scopedKey });\n const listKeys = this.table.createListKeys(params);\n\n return { ...tableKeys, ...listKeys };\n }\n}\n"],"names":["nowInSeconds","Math","Date","toEpochSeconds","date","isExpired","expiresAt","ttl","Number","Boolean","isConditionFailed","error","notExistsCondition","liveCondition","liveValueCondition","equals","toCondition","condition","undefined","KeyValueStoreStorageOperations","dynamoDbClient","KeyValueStoreDynamoTable","key","scope","scopedKey","entry","err","WebinyError","value","options","keys","item","collection","listKeys","Object","params","limit","reverse","after","partitionKey","startKey","items","lastEvaluatedKey","page","keyOf","lastKey","tableKeys"],"mappings":";;AAiBA,MAAMA,eAAe,IACVC,KAAK,KAAK,CAACC,KAAK,GAAG,KAAK;AAQnC,MAAMC,iBAAiB,CAACC,OACbH,KAAK,IAAI,CAACG,KAAK,OAAO,KAAK;AAGtC,MAAMC,YAAY,CAACC;IACf,MAAMC,M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I,CAAC,KAAK,CAAC,cAAc,CAACE;QAE3C,OAAO;YAAE,GAAGW,SAAS;YAAE,GAAGb,QAAQ;QAAC;IACvC;AACJ"}
@@ -0,0 +1,8 @@
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import { KeyValueStoreStorageOperations } from "./KeyValueStoreStorageOperations.js";
3
+ export interface CreateKeyValueStoreStorageOperations {
4
+ (params: {
5
+ documentClient: DynamoDBDocument;
6
+ }): KeyValueStoreStorageOperations;
7
+ }
8
+ export declare const createStorageOperations: CreateKeyValueStoreStorageOperations;
@@ -0,0 +1,5 @@
1
+ import { KeyValueStoreStorageOperations } from "./KeyValueStoreStorageOperations.js";
2
+ const createStorageOperations = (params)=>new KeyValueStoreStorageOperations(params.documentClient);
3
+ export { createStorageOperations };
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@webiny/api-core-ddb",
3
+ "version": "0.0.0-unstable.0156a4c312",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/webiny/webiny-js.git"
12
+ },
13
+ "keywords": [
14
+ "@webiny/api-core",
15
+ "storage-operations",
16
+ "dynamodb",
17
+ "ddb",
18
+ "sau:ddb"
19
+ ],
20
+ "description": "DynamoDB-specific dependencies for @webiny/api-core.",
21
+ "author": "Webiny Ltd.",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@webiny/api": "0.0.0-unstable.0156a4c312",
25
+ "@webiny/api-core": "0.0.0-unstable.0156a4c312",
26
+ "@webiny/aws-sdk": "0.0.0-unstable.0156a4c312",
27
+ "@webiny/db-dynamodb": "0.0.0-unstable.0156a4c312",
28
+ "@webiny/error": "0.0.0-unstable.0156a4c312",
29
+ "@webiny/feature": "0.0.0-unstable.0156a4c312"
30
+ },
31
+ "devDependencies": {
32
+ "@webiny/api": "0.0.0-unstable.0156a4c312",
33
+ "@webiny/build-tools": "0.0.0-unstable.0156a4c312",
34
+ "jest-dynalite": "3.6.1",
35
+ "rimraf": "6.1.3",
36
+ "typescript": "7.0.2",
37
+ "vitest": "5.0.5"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "webiny": {
43
+ "publishFrom": "dist"
44
+ }
45
+ }
@@ -0,0 +1,5 @@
1
+ import type { Table } from "@webiny/db-dynamodb/toolbox.js";
2
+ import type { IApiKeyEntity, IRoleEntity, ITeamEntity } from "../../security/definitions/types.js";
3
+ export declare const createRoleEntity: (table: Table<string, string, string>) => IRoleEntity;
4
+ export declare const createTeamEntity: (table: Table<string, string, string>) => ITeamEntity;
5
+ export declare const createApiKeyEntity: (table: Table<string, string, string>) => IApiKeyEntity;
@@ -0,0 +1,23 @@
1
+ import { createStandardEntity, standardEntityAttributes } from "@webiny/db-dynamodb";
2
+ import { ENTITIES } from "../types.js";
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 };
22
+
23
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,14 @@
1
+ import type { IEntity, IStandardEntityAttributes } from "@webiny/db-dynamodb";
2
+ import type { StorageApiKey, StorageRole, StorageTeam } from "@webiny/api-core/types/security.js";
3
+ export interface IRoleEntityAttributes extends IStandardEntityAttributes<StorageRole> {
4
+ TYPE: string;
5
+ }
6
+ export type IRoleEntity = IEntity<IRoleEntityAttributes>;
7
+ export interface ITeamEntityAttributes extends IStandardEntityAttributes<StorageTeam> {
8
+ TYPE: string;
9
+ }
10
+ export type ITeamEntity = IEntity<ITeamEntityAttributes>;
11
+ export interface IApiKeyEntityAttributes extends IStandardEntityAttributes<StorageApiKey> {
12
+ TYPE: string;
13
+ }
14
+ export type IApiKeyEntity = IEntity<IApiKeyEntityAttributes>;
File without changes
@@ -0,0 +1,3 @@
1
+ import type { SecurityStorageParams } from "./types.js";
2
+ import type { SecurityStorageOperations } from "@webiny/api-core/types/security.js";
3
+ export declare const createStorageOperations: (params: SecurityStorageParams) => SecurityStorageOperations;