@webiny/api-aco-sql 6.6.0-alpha.11 → 6.6.0-alpha.13
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/AcoSqlSchemaSetup.js +3 -1
- package/AcoSqlSchemaSetup.js.map +1 -1
- package/FolderLevelPermissionsStorageOperations.d.ts +11 -5
- package/FolderLevelPermissionsStorageOperations.js +31 -14
- package/FolderLevelPermissionsStorageOperations.js.map +1 -1
- package/SqlFlpStorageOperations.d.ts +3 -2
- package/SqlFlpStorageOperations.js +4 -1
- package/SqlFlpStorageOperations.js.map +1 -1
- package/package.json +11 -11
package/AcoSqlSchemaSetup.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from "@webiny/api-core-sql";
|
|
2
|
+
import { tenantNeutralScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
2
3
|
import { FolderLevelPermissionsStorageOperations } from "./FolderLevelPermissionsStorageOperations.js";
|
|
3
4
|
class AcoSqlSchemaSetupImpl {
|
|
4
5
|
constructor(knex, schemaConfig){
|
|
@@ -9,7 +10,8 @@ class AcoSqlSchemaSetupImpl {
|
|
|
9
10
|
setup() {
|
|
10
11
|
const operations = new FolderLevelPermissionsStorageOperations({
|
|
11
12
|
knex: this.knex.client,
|
|
12
|
-
tableNamePrefix: this.schemaConfig?.tableNamePrefix
|
|
13
|
+
tableNamePrefix: this.schemaConfig?.tableNamePrefix,
|
|
14
|
+
scopeTenant: tenantNeutralScopeTenant
|
|
13
15
|
});
|
|
14
16
|
return operations.setupSchema();
|
|
15
17
|
}
|
package/AcoSqlSchemaSetup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcoSqlSchemaSetup.js","sources":["../src/AcoSqlSchemaSetup.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from \"@webiny/api-core-sql\";\nimport { FolderLevelPermissionsStorageOperations } from \"./FolderLevelPermissionsStorageOperations.js\";\n\n/** The `aco` schema setup step: the folder-level permissions table. */\nclass AcoSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {\n public readonly name = \"aco\";\n\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public setup(): Promise<void> {\n const operations = new FolderLevelPermissionsStorageOperations({\n knex: this.knex.client,\n tableNamePrefix: this.schemaConfig?.tableNamePrefix\n });\n return operations.setupSchema();\n }\n}\n\nexport const AcoSqlSchemaSetup = SqlSchemaSetup.createImplementation({\n implementation: AcoSqlSchemaSetupImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["AcoSqlSchemaSetupImpl","knex","schemaConfig","operations","FolderLevelPermissionsStorageOperations","AcoSqlSchemaSetup","SqlSchemaSetup","KnexClient","SqlSchemaConfig"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AcoSqlSchemaSetup.js","sources":["../src/AcoSqlSchemaSetup.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig, SqlSchemaSetup } from \"@webiny/api-core-sql\";\nimport { tenantNeutralScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { FolderLevelPermissionsStorageOperations } from \"./FolderLevelPermissionsStorageOperations.js\";\n\n/** The `aco` schema setup step: the folder-level permissions table. */\nclass AcoSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {\n public readonly name = \"aco\";\n\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public setup(): Promise<void> {\n const operations = new FolderLevelPermissionsStorageOperations({\n knex: this.knex.client,\n tableNamePrefix: this.schemaConfig?.tableNamePrefix,\n // The setup runs in no tenant, and only creates the table.\n scopeTenant: tenantNeutralScopeTenant\n });\n return operations.setupSchema();\n }\n}\n\nexport const AcoSqlSchemaSetup = SqlSchemaSetup.createImplementation({\n implementation: AcoSqlSchemaSetupImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["AcoSqlSchemaSetupImpl","knex","schemaConfig","operations","FolderLevelPermissionsStorageOperations","tenantNeutralScopeTenant","AcoSqlSchemaSetup","SqlSchemaSetup","KnexClient","SqlSchemaConfig"],"mappings":";;;AAKA,MAAMA;IAGF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;aAJL,IAAI,GAAG;IAKpB;IAEI,QAAuB;QAC1B,MAAMC,aAAa,IAAIC,wCAAwC;YAC3D,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;YACtB,iBAAiB,IAAI,CAAC,YAAY,EAAE;YAEpC,aAAaC;QACjB;QACA,OAAOF,WAAW,WAAW;IACjC;AACJ;AAEO,MAAMG,oBAAoBC,eAAe,oBAAoB,CAAC;IACjE,gBAAgBP;IAChB,cAAc;QAACQ;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
import type { AcoFolderLevelPermissionsStorageOperations, FolderLevelPermission, StorageOperationsBatchUpdateFlpParams, StorageOperationsCreateFlpParams, StorageOperationsDeleteFlpParams, StorageOperationsGetFlpParams, StorageOperationsListFlpsParams, StorageOperationsUpdateFlpParams } from "@webiny/api-aco/types.js";
|
|
3
|
+
import type { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
3
4
|
export interface StorageOperationsConfig {
|
|
4
5
|
knex: Knex;
|
|
5
6
|
tableNamePrefix?: string;
|
|
@@ -8,20 +9,25 @@ export interface StorageOperationsConfig {
|
|
|
8
9
|
* `@webiny/api-core-sql`): the table is never checked for or created at runtime.
|
|
9
10
|
*/
|
|
10
11
|
schemaManaged?: boolean;
|
|
12
|
+
/** The tenant the storage acts on: its tenant scope's. The schema setup runs without one. */
|
|
13
|
+
scopeTenant: ScopeTenant.Interface;
|
|
11
14
|
}
|
|
12
15
|
export declare class FolderLevelPermissionsStorageOperations implements AcoFolderLevelPermissionsStorageOperations {
|
|
13
16
|
private readonly knex;
|
|
14
17
|
private readonly tableName;
|
|
15
18
|
private readonly schemaManaged;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
private readonly scopeTenant;
|
|
20
|
+
constructor({ knex, tableNamePrefix, schemaManaged, scopeTenant }: StorageOperationsConfig);
|
|
21
|
+
list({ where }: StorageOperationsListFlpsParams): Promise<FolderLevelPermission[]>;
|
|
22
|
+
get(params: StorageOperationsGetFlpParams): Promise<FolderLevelPermission | null>;
|
|
23
|
+
create(params: StorageOperationsCreateFlpParams): Promise<FolderLevelPermission>;
|
|
20
24
|
update({ data: inputData, original }: StorageOperationsUpdateFlpParams): Promise<FolderLevelPermission>;
|
|
21
|
-
delete(
|
|
25
|
+
delete(params: StorageOperationsDeleteFlpParams): Promise<void>;
|
|
22
26
|
batchUpdate({ items }: StorageOperationsBatchUpdateFlpParams): Promise<FolderLevelPermission[]>;
|
|
23
27
|
private ensureTable;
|
|
24
28
|
setupSchema(): Promise<void>;
|
|
29
|
+
/** The permission with its scope's tenant, whatever tenant it carries. */
|
|
30
|
+
private inScope;
|
|
25
31
|
private toRow;
|
|
26
32
|
private fromRow;
|
|
27
33
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
2
|
const BASE_TABLE_NAME = "webiny_aco_flp";
|
|
3
3
|
class FolderLevelPermissionsStorageOperations {
|
|
4
|
-
constructor({ knex, tableNamePrefix, schemaManaged }){
|
|
4
|
+
constructor({ knex, tableNamePrefix, schemaManaged, scopeTenant }){
|
|
5
5
|
this.knex = knex;
|
|
6
|
+
this.scopeTenant = scopeTenant;
|
|
6
7
|
this.schemaManaged = true === schemaManaged;
|
|
7
8
|
this.tableName = tableNamePrefix ? `${tableNamePrefix}_${BASE_TABLE_NAME}` : BASE_TABLE_NAME;
|
|
8
9
|
}
|
|
9
|
-
async list({ where
|
|
10
|
+
async list({ where }) {
|
|
11
|
+
const { type, path_startsWith, parentId } = where;
|
|
12
|
+
const tenant = this.scopeTenant.getId();
|
|
10
13
|
try {
|
|
11
14
|
await this.ensureTable();
|
|
12
15
|
if (parentId) {
|
|
@@ -17,6 +20,10 @@ class FolderLevelPermissionsStorageOperations {
|
|
|
17
20
|
const rows = await this.knex(this.tableName).where("tenant", tenant).andWhere("type", type).andWhere("path", "like", path_startsWith + "%");
|
|
18
21
|
return rows.map((row)=>this.fromRow(row));
|
|
19
22
|
}
|
|
23
|
+
if (type) {
|
|
24
|
+
const rows = await this.knex(this.tableName).where("tenant", tenant).andWhere("type", type);
|
|
25
|
+
return rows.map((row)=>this.fromRow(row));
|
|
26
|
+
}
|
|
20
27
|
throw new WebinyError("Missing required parameters.", "LIST_FLP_MISSING_PARAMETERS", {
|
|
21
28
|
tenant,
|
|
22
29
|
type,
|
|
@@ -30,7 +37,9 @@ class FolderLevelPermissionsStorageOperations {
|
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
39
|
}
|
|
33
|
-
async get(
|
|
40
|
+
async get(params) {
|
|
41
|
+
const { id } = params;
|
|
42
|
+
const tenant = this.scopeTenant.getId();
|
|
34
43
|
try {
|
|
35
44
|
await this.ensureTable();
|
|
36
45
|
const row = await this.knex(this.tableName).where("tenant", tenant).andWhere("id", id).first();
|
|
@@ -47,7 +56,8 @@ class FolderLevelPermissionsStorageOperations {
|
|
|
47
56
|
});
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
|
-
async create(
|
|
59
|
+
async create(params) {
|
|
60
|
+
const data = this.inScope(params.data);
|
|
51
61
|
try {
|
|
52
62
|
await this.ensureTable();
|
|
53
63
|
await this.knex(this.tableName).insert(this.toRow(data));
|
|
@@ -63,12 +73,12 @@ class FolderLevelPermissionsStorageOperations {
|
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
75
|
async update({ data: inputData, original }) {
|
|
76
|
+
const data = this.inScope({
|
|
77
|
+
...original,
|
|
78
|
+
...inputData
|
|
79
|
+
});
|
|
66
80
|
try {
|
|
67
81
|
await this.ensureTable();
|
|
68
|
-
const data = {
|
|
69
|
-
...original,
|
|
70
|
-
...inputData
|
|
71
|
-
};
|
|
72
82
|
await this.knex(this.tableName).where("tenant", data.tenant).andWhere("id", data.id).update(this.toRow(data));
|
|
73
83
|
return data;
|
|
74
84
|
} catch (err) {
|
|
@@ -82,7 +92,8 @@ class FolderLevelPermissionsStorageOperations {
|
|
|
82
92
|
});
|
|
83
93
|
}
|
|
84
94
|
}
|
|
85
|
-
async delete(
|
|
95
|
+
async delete(params) {
|
|
96
|
+
const flp = this.inScope(params.flp);
|
|
86
97
|
try {
|
|
87
98
|
await this.ensureTable();
|
|
88
99
|
await this.knex(this.tableName).where("tenant", flp.tenant).andWhere("id", flp.id).delete();
|
|
@@ -97,15 +108,15 @@ class FolderLevelPermissionsStorageOperations {
|
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
110
|
async batchUpdate({ items }) {
|
|
111
|
+
const scopedItems = items.map(({ original, data: inputData })=>this.inScope({
|
|
112
|
+
...original,
|
|
113
|
+
...inputData
|
|
114
|
+
}));
|
|
100
115
|
try {
|
|
101
116
|
await this.ensureTable();
|
|
102
117
|
return await this.knex.transaction(async (trx)=>{
|
|
103
118
|
const updatedItems = [];
|
|
104
|
-
for (const
|
|
105
|
-
const data = {
|
|
106
|
-
...original,
|
|
107
|
-
...inputData
|
|
108
|
-
};
|
|
119
|
+
for (const data of scopedItems){
|
|
109
120
|
await trx(this.tableName).where("tenant", data.tenant).andWhere("id", data.id).update(this.toRow(data));
|
|
110
121
|
updatedItems.push(data);
|
|
111
122
|
}
|
|
@@ -142,6 +153,12 @@ class FolderLevelPermissionsStorageOperations {
|
|
|
142
153
|
]);
|
|
143
154
|
});
|
|
144
155
|
}
|
|
156
|
+
inScope(record) {
|
|
157
|
+
return {
|
|
158
|
+
...record,
|
|
159
|
+
tenant: this.scopeTenant.getId()
|
|
160
|
+
};
|
|
161
|
+
}
|
|
145
162
|
toRow(data) {
|
|
146
163
|
return {
|
|
147
164
|
id: data.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FolderLevelPermissionsStorageOperations.js","sources":["../src/FolderLevelPermissionsStorageOperations.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { WebinyError } from \"@webiny/error\";\nimport type {\n AcoFolderLevelPermissionsStorageOperations,\n FolderLevelPermission,\n StorageOperationsBatchUpdateFlpParams,\n StorageOperationsCreateFlpParams,\n StorageOperationsDeleteFlpParams,\n StorageOperationsGetFlpParams,\n StorageOperationsListFlpsParams,\n StorageOperationsUpdateFlpParams\n} from \"@webiny/api-aco/types.js\";\n\ninterface FlpRow {\n id: string;\n tenant: string;\n type: string;\n slug: string;\n path: string;\n parentId: string;\n permissions: string;\n}\n\nconst BASE_TABLE_NAME = \"webiny_aco_flp\";\n\nexport interface StorageOperationsConfig {\n knex: Knex;\n tableNamePrefix?: string;\n /**\n * The schema was set up before the API took traffic (see `SqlSchemaConfig` in\n * `@webiny/api-core-sql`): the table is never checked for or created at runtime.\n */\n schemaManaged?: boolean;\n}\n\nexport class FolderLevelPermissionsStorageOperations implements AcoFolderLevelPermissionsStorageOperations {\n private readonly knex: Knex;\n private readonly tableName: string;\n private readonly schemaManaged: boolean;\n\n constructor({ knex, tableNamePrefix, schemaManaged }: StorageOperationsConfig) {\n this.knex = knex;\n this.schemaManaged = schemaManaged === true;\n this.tableName = tableNamePrefix\n ? `${tableNamePrefix}_${BASE_TABLE_NAME}`\n : BASE_TABLE_NAME;\n }\n\n public async list({\n where: { tenant, type, path_startsWith, parentId }\n }: StorageOperationsListFlpsParams): Promise<FolderLevelPermission[]> {\n try {\n await this.ensureTable();\n\n if (parentId) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"parentId\", parentId);\n\n return rows.map(row => this.fromRow(row));\n }\n\n if (path_startsWith) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"type\", type)\n .andWhere(\"path\", \"like\", path_startsWith + \"%\");\n\n return rows.map(row => this.fromRow(row));\n }\n\n throw new WebinyError(\"Missing required parameters.\", \"LIST_FLP_MISSING_PARAMETERS\", {\n tenant,\n type,\n path_startsWith,\n parentId\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list folder level permissions.\",\n code: \"LIST_FLP_ERROR\"\n });\n }\n }\n\n public async get({\n tenant,\n id\n }: StorageOperationsGetFlpParams): Promise<FolderLevelPermission | null> {\n try {\n await this.ensureTable();\n\n const row = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"id\", id)\n .first();\n\n if (!row) {\n return null;\n }\n\n return this.fromRow(row);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load folder level permission.\",\n code: \"GET_FLP_ERROR\",\n data: { tenant, id }\n });\n }\n }\n\n public async create({\n data\n }: StorageOperationsCreateFlpParams): Promise<FolderLevelPermission> {\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName).insert(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create folder level permission.\",\n code: \"CREATE_FLP_ERROR\",\n data: { data }\n });\n }\n }\n\n public async update({\n data: inputData,\n original\n }: StorageOperationsUpdateFlpParams): Promise<FolderLevelPermission> {\n try {\n await this.ensureTable();\n\n const data = {\n ...original,\n ...inputData\n };\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update folder level permission.\",\n code: \"UPDATE_FLP_ERROR\",\n data: { inputData, original }\n });\n }\n }\n\n public async delete({ flp }: StorageOperationsDeleteFlpParams): Promise<void> {\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", flp.tenant)\n .andWhere(\"id\", flp.id)\n .delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete folder level permission.\",\n code: \"DELETE_FLP_ERROR\",\n data: { flp }\n });\n }\n }\n\n public async batchUpdate({\n items\n }: StorageOperationsBatchUpdateFlpParams): Promise<FolderLevelPermission[]> {\n try {\n await this.ensureTable();\n\n // Built inside the callback: a transaction that loses its connection runs it again.\n return await this.knex.transaction(async trx => {\n const updatedItems: FolderLevelPermission[] = [];\n for (const { original, data: inputData } of items) {\n const data = {\n ...original,\n ...inputData\n };\n\n await trx<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n updatedItems.push(data);\n }\n return updatedItems;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not batch update folder level permissions.\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: { items }\n });\n }\n }\n\n private async ensureTable(): Promise<void> {\n // Set up before the API took traffic, so don't check for it on every call.\n if (this.schemaManaged) {\n return;\n }\n await this.setupSchema();\n }\n\n /* Creates the table if missing, whatever the mode (deploy-time schema setup). */\n public async setupSchema(): Promise<void> {\n const exists = await this.knex.schema.hasTable(this.tableName);\n if (exists) {\n return;\n }\n\n await this.knex.schema.createTable(this.tableName, table => {\n table.text(\"id\").notNullable();\n table.text(\"tenant\").notNullable();\n table.text(\"type\").notNullable();\n table.text(\"slug\").notNullable();\n table.text(\"path\").notNullable();\n table.text(\"parentId\").notNullable();\n table.text(\"permissions\").notNullable();\n table.primary([\"tenant\", \"id\"]);\n });\n }\n\n private toRow(data: FolderLevelPermission & { tenant: string }): FlpRow {\n return {\n id: data.id,\n tenant: data.tenant,\n type: data.type,\n slug: data.slug,\n path: data.path,\n parentId: data.parentId,\n permissions: JSON.stringify(data.permissions)\n };\n }\n\n private fromRow(row: FlpRow): FolderLevelPermission {\n return {\n id: row.id,\n parentId: row.parentId,\n slug: row.slug,\n path: row.path,\n permissions: JSON.parse(row.permissions),\n type: row.type\n };\n }\n}\n"],"names":["BASE_TABLE_NAME","FolderLevelPermissionsStorageOperations","knex","tableNamePrefix","schemaManaged","tenant","type","path_startsWith","parentId","rows","row","WebinyError","err","id","data","inputData","original","flp","items","trx","updatedItems","exists","table","JSON"],"mappings":";AAuBA,MAAMA,kBAAkB;AAYjB,MAAMC;IAKT,YAAY,EAAEC,IAAI,EAAEC,eAAe,EAAEC,aAAa,EAA2B,CAAE;QAC3E,IAAI,CAAC,IAAI,GAAGF;QACZ,IAAI,CAAC,aAAa,GAAGE,AAAkB,SAAlBA;QACrB,IAAI,CAAC,SAAS,GAAGD,kBACX,GAAGA,gBAAgB,CAAC,EAAEH,iBAAiB,GACvCA;IACV;IAEA,MAAa,KAAK,EACd,OAAO,EAAEK,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAEC,QAAQ,EAAE,EACpB,EAAoC;QAClE,IAAI;YACA,MAAM,IAAI,CAAC,WAAW;YAEtB,IAAIA,UAAU;gBACV,MAAMC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAS,IAAI,CAAC,SAAS,EAC9C,KAAK,CAAC,UAAUJ,QAChB,QAAQ,CAAC,YAAYG;gBAE1B,OAAOC,KAAK,GAAG,CAACC,CAAAA,MAAO,IAAI,CAAC,OAAO,CAACA;YACxC;YAEA,IAAIH,iBAAiB;gBACjB,MAAME,OAAO,MAAM,IAAI,CAAC,IAAI,CAAS,IAAI,CAAC,SAAS,EAC9C,KAAK,CAAC,UAAUJ,QAChB,QAAQ,CAAC,QAAQC,MACjB,QAAQ,CAAC,QAAQ,QAAQC,kBAAkB;gBAEhD,OAAOE,KAAK,GAAG,CAACC,CAAAA,MAAO,IAAI,CAAC,OAAO,CAACA;YACxC;YAEA,MAAM,IAAIC,YAAY,gCAAgC,+BAA+B;gBACjFN;gBACAC;gBACAC;gBACAC;YACJ;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AM,IAAI,CAAC,WAAW;IAC1B;IAGA,MAAa,cAA6B;QACtC,MAAMG,SAAS,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS;QAC7D,IAAIA,QACA;QAGJ,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,EAAEC,CAAAA;YAC/CA,MAAM,IAAI,CAAC,MAAM,WAAW;YAC5BA,MAAM,IAAI,CAAC,UAAU,WAAW;YAChCA,MAAM,IAAI,CAAC,QAAQ,WAAW;YAC9BA,MAAM,IAAI,CAAC,QAAQ,WAAW;YAC9BA,MAAM,IAAI,CAAC,QAAQ,WAAW;YAC9BA,MAAM,IAAI,CAAC,YAAY,WAAW;YAClCA,MAAM,IAAI,CAAC,eAAe,WAAW;YACrCA,MAAM,OAAO,CAAC;gBAAC;gBAAU;aAAK;QAClC;IACJ;IAEQ,MAAMR,IAAgD,EAAU;QACpE,OAAO;YACH,IAAIA,KAAK,EAAE;YACX,QAAQA,KAAK,MAAM;YACnB,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;YACvB,aAAaS,KAAK,SAAS,CAACT,KAAK,WAAW;QAChD;IACJ;IAEQ,QAAQJ,GAAW,EAAyB;QAChD,OAAO;YACH,IAAIA,IAAI,EAAE;YACV,UAAUA,IAAI,QAAQ;YACtB,MAAMA,IAAI,IAAI;YACd,MAAMA,IAAI,IAAI;YACd,aAAaa,KAAK,KAAK,CAACb,IAAI,WAAW;YACvC,MAAMA,IAAI,IAAI;QAClB;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"FolderLevelPermissionsStorageOperations.js","sources":["../src/FolderLevelPermissionsStorageOperations.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { WebinyError } from \"@webiny/error\";\nimport type {\n AcoFolderLevelPermissionsStorageOperations,\n FolderLevelPermission,\n StorageOperationsBatchUpdateFlpParams,\n StorageOperationsCreateFlpParams,\n StorageOperationsDeleteFlpParams,\n StorageOperationsGetFlpParams,\n StorageOperationsListFlpsParams,\n StorageOperationsUpdateFlpParams\n} from \"@webiny/api-aco/types.js\";\nimport type { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\n\ninterface FlpRow {\n id: string;\n tenant: string;\n type: string;\n slug: string;\n path: string;\n parentId: string;\n permissions: string;\n}\n\nconst BASE_TABLE_NAME = \"webiny_aco_flp\";\n\nexport interface StorageOperationsConfig {\n knex: Knex;\n tableNamePrefix?: string;\n /**\n * The schema was set up before the API took traffic (see `SqlSchemaConfig` in\n * `@webiny/api-core-sql`): the table is never checked for or created at runtime.\n */\n schemaManaged?: boolean;\n /** The tenant the storage acts on: its tenant scope's. The schema setup runs without one. */\n scopeTenant: ScopeTenant.Interface;\n}\n\nexport class FolderLevelPermissionsStorageOperations implements AcoFolderLevelPermissionsStorageOperations {\n private readonly knex: Knex;\n private readonly tableName: string;\n private readonly schemaManaged: boolean;\n private readonly scopeTenant: ScopeTenant.Interface;\n\n constructor({ knex, tableNamePrefix, schemaManaged, scopeTenant }: StorageOperationsConfig) {\n this.knex = knex;\n this.scopeTenant = scopeTenant;\n this.schemaManaged = schemaManaged === true;\n this.tableName = tableNamePrefix\n ? `${tableNamePrefix}_${BASE_TABLE_NAME}`\n : BASE_TABLE_NAME;\n }\n\n public async list({\n where\n }: StorageOperationsListFlpsParams): Promise<FolderLevelPermission[]> {\n const { type, path_startsWith, parentId } = where;\n const tenant = this.scopeTenant.getId();\n try {\n await this.ensureTable();\n\n if (parentId) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"parentId\", parentId);\n\n return rows.map(row => this.fromRow(row));\n }\n\n if (path_startsWith) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"type\", type)\n .andWhere(\"path\", \"like\", path_startsWith + \"%\");\n\n return rows.map(row => this.fromRow(row));\n }\n\n // All folder level permissions of a folder type.\n if (type) {\n const rows = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"type\", type);\n\n return rows.map(row => this.fromRow(row));\n }\n\n throw new WebinyError(\"Missing required parameters.\", \"LIST_FLP_MISSING_PARAMETERS\", {\n tenant,\n type,\n path_startsWith,\n parentId\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list folder level permissions.\",\n code: \"LIST_FLP_ERROR\"\n });\n }\n }\n\n public async get(params: StorageOperationsGetFlpParams): Promise<FolderLevelPermission | null> {\n const { id } = params;\n const tenant = this.scopeTenant.getId();\n try {\n await this.ensureTable();\n\n const row = await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", tenant)\n .andWhere(\"id\", id)\n .first();\n\n if (!row) {\n return null;\n }\n\n return this.fromRow(row);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not load folder level permission.\",\n code: \"GET_FLP_ERROR\",\n data: { tenant, id }\n });\n }\n }\n\n public async create(params: StorageOperationsCreateFlpParams): Promise<FolderLevelPermission> {\n const data = this.inScope(params.data);\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName).insert(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create folder level permission.\",\n code: \"CREATE_FLP_ERROR\",\n data: { data }\n });\n }\n }\n\n public async update({\n data: inputData,\n original\n }: StorageOperationsUpdateFlpParams): Promise<FolderLevelPermission> {\n const data = this.inScope({\n ...original,\n ...inputData\n });\n\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update folder level permission.\",\n code: \"UPDATE_FLP_ERROR\",\n data: { inputData, original }\n });\n }\n }\n\n public async delete(params: StorageOperationsDeleteFlpParams): Promise<void> {\n const flp = this.inScope(params.flp);\n try {\n await this.ensureTable();\n\n await this.knex<FlpRow>(this.tableName)\n .where(\"tenant\", flp.tenant)\n .andWhere(\"id\", flp.id)\n .delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete folder level permission.\",\n code: \"DELETE_FLP_ERROR\",\n data: { flp }\n });\n }\n }\n\n public async batchUpdate({\n items\n }: StorageOperationsBatchUpdateFlpParams): Promise<FolderLevelPermission[]> {\n const scopedItems = items.map(({ original, data: inputData }) => {\n return this.inScope({\n ...original,\n ...inputData\n });\n });\n\n try {\n await this.ensureTable();\n\n // Built inside the callback: a transaction that loses its connection runs it again.\n return await this.knex.transaction(async trx => {\n const updatedItems: FolderLevelPermission[] = [];\n for (const data of scopedItems) {\n await trx<FlpRow>(this.tableName)\n .where(\"tenant\", data.tenant)\n .andWhere(\"id\", data.id)\n .update(this.toRow(data));\n\n updatedItems.push(data);\n }\n return updatedItems;\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not batch update folder level permissions.\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: { items }\n });\n }\n }\n\n private async ensureTable(): Promise<void> {\n // Set up before the API took traffic, so don't check for it on every call.\n if (this.schemaManaged) {\n return;\n }\n await this.setupSchema();\n }\n\n /* Creates the table if missing, whatever the mode (deploy-time schema setup). */\n public async setupSchema(): Promise<void> {\n const exists = await this.knex.schema.hasTable(this.tableName);\n if (exists) {\n return;\n }\n\n await this.knex.schema.createTable(this.tableName, table => {\n table.text(\"id\").notNullable();\n table.text(\"tenant\").notNullable();\n table.text(\"type\").notNullable();\n table.text(\"slug\").notNullable();\n table.text(\"path\").notNullable();\n table.text(\"parentId\").notNullable();\n table.text(\"permissions\").notNullable();\n table.primary([\"tenant\", \"id\"]);\n });\n }\n\n /** The permission with its scope's tenant, whatever tenant it carries. */\n private inScope<T extends { tenant?: string | null }>(record: T): T & { tenant: string } {\n return { ...record, tenant: this.scopeTenant.getId() };\n }\n\n private toRow(data: FolderLevelPermission & { tenant: string }): FlpRow {\n return {\n id: data.id,\n tenant: data.tenant,\n type: data.type,\n slug: data.slug,\n path: data.path,\n parentId: data.parentId,\n permissions: JSON.stringify(data.permissions)\n };\n }\n\n private fromRow(row: FlpRow): FolderLevelPermission {\n return {\n id: row.id,\n parentId: row.parentId,\n slug: row.slug,\n path: row.path,\n permissions: JSON.parse(row.permissions),\n type: row.type\n };\n }\n}\n"],"names":["BASE_TABLE_NAME","FolderLevelPermissionsStorageOperations","knex","tableNamePrefix","schemaManaged","scopeTenant","where","type","path_startsWith","parentId","tenant","rows","row","WebinyError","err","params","id","data","inputData","original","flp","items","scopedItems","trx","updatedItems","exists","table","record","JSON"],"mappings":";AAwBA,MAAMA,kBAAkB;AAcjB,MAAMC;IAMT,YAAY,EAAEC,IAAI,EAAEC,eAAe,EAAEC,aAAa,EAAEC,WAAW,EAA2B,CAAE;QACxF,IAAI,CAAC,IAAI,GAAGH;QACZ,IAAI,CAAC,WAAW,GAAGG;QACnB,IAAI,CAAC,aAAa,GAAGD,AAAkB,SAAlBA;QACrB,IAAI,CAAC,SAAS,GAAGD,kBACX,GAAGA,gBAAgB,CAAC,EAAEH,iBAAiB,GACvCA;IACV;IAEA,MAAa,KAAK,EACdM,KAAK,EACyB,EAAoC;QAClE,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAEC,QAAQ,EAAE,GAAGH;QAC5C,MAAMI,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK;QACrC,IAAI;YACA,MAAM,IAAI,CAAC,WAAW;YAEtB,IAAID,UAAU;gBACV,MAAME,OAAO,MAAM,IAAI,CAAC,IAAI,CAAS,IAAI,CAAC,SAAS,EAC9C,KAAK,CAAC,UAAUD,QAChB,QAAQ,CAAC,YAAYD;gBAE1B,OAAOE,KAAK,GAAG,CAACC,CAAAA,MAAO,IAAI,CAAC,OAAO,CAACA;YACxC;YAEA,IAAIJ,iBAAiB;gBACjB,MAAMG,OAAO,MAAM,IAAI,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,CAAC,eAAe,WAAW;YACrCA,MAAM,OAAO,CAAC;gBAAC;gBAAU;aAAK;QAClC;IACJ;IAGQ,QAA8CC,MAAS,EAA0B;QACrF,OAAO;YAAE,GAAGA,MAAM;YAAE,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK;QAAG;IACzD;IAEQ,MAAMV,IAAgD,EAAU;QACpE,OAAO;YACH,IAAIA,KAAK,EAAE;YACX,QAAQA,KAAK,MAAM;YACnB,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;YACvB,aAAaW,KAAK,SAAS,CAACX,KAAK,WAAW;QAChD;IACJ;IAEQ,QAAQL,GAAW,EAAyB;QAChD,OAAO;YACH,IAAIA,IAAI,EAAE;YACV,UAAUA,IAAI,QAAQ;YACtB,MAAMA,IAAI,IAAI;YACd,MAAMA,IAAI,IAAI;YACd,aAAagB,KAAK,KAAK,CAAChB,IAAI,WAAW;YACvC,MAAMA,IAAI,IAAI;QAClB;IACJ;AACJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { KnexClient, SqlSchemaConfig } from "@webiny/api-core-sql";
|
|
2
2
|
import { FlpStorageOperations } from "@webiny/api-aco/features/folder/shared/abstractions.js";
|
|
3
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
3
4
|
import { FolderLevelPermissionsStorageOperations } from "./FolderLevelPermissionsStorageOperations.js";
|
|
4
|
-
/** Folder-level permissions on the container's connection and table prefix. */
|
|
5
|
+
/** Folder-level permissions on the container's connection and table prefix, for its scope's tenant. */
|
|
5
6
|
declare class SqlFlpStorageOperationsImpl extends FolderLevelPermissionsStorageOperations implements FlpStorageOperations.Interface {
|
|
6
|
-
constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface);
|
|
7
|
+
constructor(knex: KnexClient.Interface, scopeTenant: ScopeTenant.Interface, schemaConfig?: SqlSchemaConfig.Interface);
|
|
7
8
|
}
|
|
8
9
|
export declare const SqlFlpStorageOperations: typeof SqlFlpStorageOperationsImpl & {
|
|
9
10
|
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-aco/types.js").AcoFolderLevelPermissionsStorageOperations>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { KnexClient, SqlSchemaConfig } from "@webiny/api-core-sql";
|
|
2
2
|
import { FlpStorageOperations } from "@webiny/api-aco/features/folder/shared/abstractions.js";
|
|
3
|
+
import { ScopeTenant } from "@webiny/api-core/features/tenancy/ScopeTenant/index.js";
|
|
3
4
|
import { FolderLevelPermissionsStorageOperations } from "./FolderLevelPermissionsStorageOperations.js";
|
|
4
5
|
class SqlFlpStorageOperationsImpl extends FolderLevelPermissionsStorageOperations {
|
|
5
|
-
constructor(knex, schemaConfig){
|
|
6
|
+
constructor(knex, scopeTenant, schemaConfig){
|
|
6
7
|
super({
|
|
7
8
|
knex: knex.client,
|
|
9
|
+
scopeTenant,
|
|
8
10
|
tableNamePrefix: schemaConfig?.tableNamePrefix,
|
|
9
11
|
schemaManaged: schemaConfig?.isManaged() === true
|
|
10
12
|
});
|
|
@@ -14,6 +16,7 @@ const SqlFlpStorageOperations = FlpStorageOperations.createImplementation({
|
|
|
14
16
|
implementation: SqlFlpStorageOperationsImpl,
|
|
15
17
|
dependencies: [
|
|
16
18
|
KnexClient,
|
|
19
|
+
ScopeTenant,
|
|
17
20
|
[
|
|
18
21
|
SqlSchemaConfig,
|
|
19
22
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlFlpStorageOperations.js","sources":["../src/SqlFlpStorageOperations.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig } from \"@webiny/api-core-sql\";\nimport { FlpStorageOperations } from \"@webiny/api-aco/features/folder/shared/abstractions.js\";\nimport { FolderLevelPermissionsStorageOperations } from \"./FolderLevelPermissionsStorageOperations.js\";\n\n/** Folder-level permissions on the container's connection and table prefix. */\nclass SqlFlpStorageOperationsImpl\n extends FolderLevelPermissionsStorageOperations\n implements FlpStorageOperations.Interface\n{\n public constructor(knex: KnexClient.Interface
|
|
1
|
+
{"version":3,"file":"SqlFlpStorageOperations.js","sources":["../src/SqlFlpStorageOperations.ts"],"sourcesContent":["import { KnexClient, SqlSchemaConfig } from \"@webiny/api-core-sql\";\nimport { FlpStorageOperations } from \"@webiny/api-aco/features/folder/shared/abstractions.js\";\nimport { ScopeTenant } from \"@webiny/api-core/features/tenancy/ScopeTenant/index.js\";\nimport { FolderLevelPermissionsStorageOperations } from \"./FolderLevelPermissionsStorageOperations.js\";\n\n/** Folder-level permissions on the container's connection and table prefix, for its scope's tenant. */\nclass SqlFlpStorageOperationsImpl\n extends FolderLevelPermissionsStorageOperations\n implements FlpStorageOperations.Interface\n{\n public constructor(\n knex: KnexClient.Interface,\n scopeTenant: ScopeTenant.Interface,\n schemaConfig?: SqlSchemaConfig.Interface\n ) {\n super({\n knex: knex.client,\n scopeTenant,\n tableNamePrefix: schemaConfig?.tableNamePrefix,\n schemaManaged: schemaConfig?.isManaged() === true\n });\n }\n}\n\nexport const SqlFlpStorageOperations = FlpStorageOperations.createImplementation({\n implementation: SqlFlpStorageOperationsImpl,\n dependencies: [KnexClient, ScopeTenant, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["SqlFlpStorageOperationsImpl","FolderLevelPermissionsStorageOperations","knex","scopeTenant","schemaConfig","SqlFlpStorageOperations","FlpStorageOperations","KnexClient","ScopeTenant","SqlSchemaConfig"],"mappings":";;;;AAMA,MAAMA,oCACMC;IAGR,YACIC,IAA0B,EAC1BC,WAAkC,EAClCC,YAAwC,CAC1C;QACE,KAAK,CAAC;YACF,MAAMF,KAAK,MAAM;YACjBC;YACA,iBAAiBC,cAAc;YAC/B,eAAeA,cAAc,gBAAgB;QACjD;IACJ;AACJ;AAEO,MAAMC,0BAA0BC,qBAAqB,oBAAoB,CAAC;IAC7E,gBAAgBN;IAChB,cAAc;QAACO;QAAYC;QAAa;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAClF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-aco-sql",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-aco",
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"./*": "./*"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@webiny/api-aco": "6.6.0-alpha.
|
|
24
|
-
"@webiny/api-core
|
|
25
|
-
"@webiny/
|
|
26
|
-
"@webiny/
|
|
27
|
-
"@webiny/
|
|
23
|
+
"@webiny/api-aco": "6.6.0-alpha.13",
|
|
24
|
+
"@webiny/api-core": "6.6.0-alpha.13",
|
|
25
|
+
"@webiny/api-core-sql": "6.6.0-alpha.13",
|
|
26
|
+
"@webiny/error": "6.6.0-alpha.13",
|
|
27
|
+
"@webiny/feature": "6.6.0-alpha.13",
|
|
28
|
+
"@webiny/handler": "6.6.0-alpha.13",
|
|
28
29
|
"knex": "3.3.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@webiny/
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"rimraf": "6.1.3",
|
|
32
|
+
"@webiny/build-tools": "6.6.0-alpha.13",
|
|
33
|
+
"better-sqlite3": "13.2.0",
|
|
34
|
+
"rimraf": "6.1.4",
|
|
35
35
|
"typescript": "7.0.2",
|
|
36
|
-
"vitest": "5.
|
|
36
|
+
"vitest": "5.1.1"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|