@webiny/api-record-locking 6.4.0-beta.0 → 6.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -6,4 +6,4 @@ export interface ICreateContextPluginParams {
6
6
  */
7
7
  timeout?: number;
8
8
  }
9
- export declare const createRecordLocking: (params?: ICreateContextPluginParams) => ContextPlugin<ApiCoreContext>[];
9
+ export declare const createRecordLocking: (params?: ICreateContextPluginParams) => (ContextPlugin<ApiCoreContext> | import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types").Context>)[];
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ContextPlugin } from "@webiny/api";
2
+ import { createRegisterExtensionPlugin } from "@webiny/handler";
2
3
  import { WcpContext } from "@webiny/api-core/features/wcp/WcpContext/index.js";
3
4
  import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels";
4
5
  import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel";
@@ -10,14 +11,13 @@ import { IdentityContext } from "@webiny/api-core/features/security/IdentityCont
10
11
  import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
11
12
  import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
12
13
  const createContextPlugin = (params)=>{
13
- const plugin = new ContextPlugin(async (context)=>{
14
+ const recordLockingContextPlugin = new ContextPlugin(async (context)=>{
14
15
  const tenantContext = context.container.resolve(TenantContext);
15
16
  const identityContext = context.container.resolve(IdentityContext);
16
17
  const wcp = context.container.resolve(WcpContext);
17
18
  const getModel = context.container.resolve(GetModelUseCase);
18
19
  const listModels = context.container.resolve(ListModelsUseCase);
19
20
  if (!wcp.canUseRecordLocking() || !tenantContext.getTenant()) return;
20
- context.container.register(RecordLockingModel);
21
21
  const timeout = getTimeout(params?.timeout);
22
22
  const [model, publicModels] = await identityContext.withoutAuthorization(async ()=>{
23
23
  const [model, publicModels] = await Promise.all([
@@ -43,12 +43,18 @@ const createContextPlugin = (params)=>{
43
43
  model
44
44
  });
45
45
  });
46
- plugin.name = "context.recordLocking";
47
- return plugin;
46
+ recordLockingContextPlugin.name = "context.recordLocking";
47
+ return recordLockingContextPlugin;
48
48
  };
49
- const createRecordLocking = (params)=>[
50
- createContextPlugin(params)
49
+ const createRecordLocking = (params)=>{
50
+ const modelsPlugin = createRegisterExtensionPlugin((context)=>{
51
+ context.container.register(RecordLockingModel);
52
+ });
53
+ return [
54
+ createContextPlugin(params),
55
+ modelsPlugin
51
56
  ];
57
+ };
52
58
  export { createRecordLocking };
53
59
 
54
60
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { WcpContext } from \"@webiny/api-core/features/wcp/WcpContext/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel\";\nimport { RecordLockingModel, RECORD_LOCKING_MODEL_ID } from \"~/domain/RecordLockingModel.js\";\nimport { getTimeout } from \"~/utils/getTimeout.js\";\nimport { RecordLockingFeature } from \"~/features/RecordLockingFeature.js\";\nimport { createGraphQLSchema } from \"~/graphql/schema.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\n\nexport interface ICreateContextPluginParams {\n /**\n * A number of seconds after the last activity to wait before the record is automatically unlocked.\n */\n timeout?: number;\n}\n\nconst createContextPlugin = (params?: ICreateContextPluginParams) => {\n const plugin = new ContextPlugin<ApiCoreContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const identityContext = context.container.resolve(IdentityContext);\n const wcp = context.container.resolve(WcpContext);\n const getModel = context.container.resolve(GetModelUseCase);\n const listModels = context.container.resolve(ListModelsUseCase);\n\n if (!wcp.canUseRecordLocking() || !tenantContext.getTenant()) {\n return;\n }\n\n // Register the private model\n context.container.register(RecordLockingModel);\n\n // Determine timeout value\n const timeout = getTimeout(params?.timeout);\n\n // Fetch CMS model to use for storing record locking data\n const [model, publicModels] = await identityContext.withoutAuthorization(async () => {\n const [model, publicModels] = await Promise.all([\n // Get a record locking model\n getModel.execute(RECORD_LOCKING_MODEL_ID),\n // Get all models\n listModels.execute({ includePrivate: false })\n ]);\n\n return [model.value, publicModels.value];\n });\n\n const fieldRegistry = context.container.resolve(CmsModelFieldToGraphQLRegistry);\n\n // Register GraphQL schema plugin\n const graphQlPlugin = await createGraphQLSchema({\n model,\n models: publicModels,\n fieldRegistry\n });\n\n context.plugins.register(graphQlPlugin);\n\n // Register features\n RecordLockingFeature.register(context.container, {\n timeout,\n model\n });\n });\n plugin.name = \"context.recordLocking\";\n\n return plugin;\n};\n\nexport const createRecordLocking = (params?: ICreateContextPluginParams) => {\n return [createContextPlugin(params)];\n};\n"],"names":["createContextPlugin","params","plugin","ContextPlugin","context","tenantContext","TenantContext","identityContext","IdentityContext","wcp","WcpContext","getModel","GetModelUseCase","listModels","ListModelsUseCase","RecordLockingModel","timeout","getTimeout","model","publicModels","Promise","RECORD_LOCKING_MODEL_ID","fieldRegistry","CmsModelFieldToGraphQLRegistry","graphQlPlugin","createGraphQLSchema","RecordLockingFeature","createRecordLocking"],"mappings":";;;;;;;;;;;AAoBA,MAAMA,sBAAsB,CAACC;IACzB,MAAMC,SAAS,IAAIC,cAA8B,OAAMC;QACnD,MAAMC,gBAAgBD,QAAQ,SAAS,CAAC,OAAO,CAACE;QAChD,MAAMC,kBAAkBH,QAAQ,SAAS,CAAC,OAAO,CAACI;QAClD,MAAMC,MAAML,QAAQ,SAAS,CAAC,OAAO,CAACM;QACtC,MAAMC,WAAWP,QAAQ,SAAS,CAAC,OAAO,CAACQ;QAC3C,MAAMC,aAAaT,QAAQ,SAAS,CAAC,OAAO,CAACU;QAE7C,IAAI,CAACL,IAAI,mBAAmB,MAAM,CAACJ,cAAc,SAAS,IACtD;QAIJD,QAAQ,SAAS,CAAC,QAAQ,CAACW;QAG3B,MAAMC,UAAUC,WAAWhB,QAAQ;QAGnC,MAAM,CAACiB,OAAOC,aAAa,GAAG,MAAMZ,gBAAgB,oBAAoB,CAAC;YACrE,MAAM,CAACW,OAAOC,aAAa,GAAG,MAAMC,QAAQ,GAAG,CAAC;gBAE5CT,SAAS,OAAO,CAACU;gBAEjBR,WAAW,OAAO,CAAC;oBAAE,gBAAgB;gBAAM;aAC9C;YAED,OAAO;gBAACK,MAAM,KAAK;gBAAEC,aAAa,KAAK;aAAC;QAC5C;QAEA,MAAMG,gBAAgBlB,QAAQ,SAAS,CAAC,OAAO,CAACmB;QAGhD,MAAMC,gBAAgB,MAAMC,oBAAoB;YAC5CP;YACA,QAAQC;YACRG;QACJ;QAEAlB,QAAQ,OAAO,CAAC,QAAQ,CAACoB;QAGzBE,qBAAqB,QAAQ,CAACtB,QAAQ,SAAS,EAAE;YAC7CY;YACAE;QACJ;IACJ;IACAhB,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX;AAEO,MAAMyB,sBAAsB,CAAC1B,SACzB;QAACD,oBAAoBC;KAAQ"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { WcpContext } from \"@webiny/api-core/features/wcp/WcpContext/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel\";\nimport { RecordLockingModel, RECORD_LOCKING_MODEL_ID } from \"~/domain/RecordLockingModel.js\";\nimport { getTimeout } from \"~/utils/getTimeout.js\";\nimport { RecordLockingFeature } from \"~/features/RecordLockingFeature.js\";\nimport { createGraphQLSchema } from \"~/graphql/schema.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\n\nexport interface ICreateContextPluginParams {\n /**\n * A number of seconds after the last activity to wait before the record is automatically unlocked.\n */\n timeout?: number;\n}\n\nconst createContextPlugin = (params?: ICreateContextPluginParams) => {\n const recordLockingContextPlugin = new ContextPlugin<ApiCoreContext>(async context => {\n const tenantContext = context.container.resolve(TenantContext);\n const identityContext = context.container.resolve(IdentityContext);\n const wcp = context.container.resolve(WcpContext);\n const getModel = context.container.resolve(GetModelUseCase);\n const listModels = context.container.resolve(ListModelsUseCase);\n\n if (!wcp.canUseRecordLocking() || !tenantContext.getTenant()) {\n return;\n }\n\n // Determine timeout value\n const timeout = getTimeout(params?.timeout);\n\n // Fetch CMS model to use for storing record locking data\n const [model, publicModels] = await identityContext.withoutAuthorization(async () => {\n const [model, publicModels] = await Promise.all([\n // Get a record locking model\n getModel.execute(RECORD_LOCKING_MODEL_ID),\n // Get all models\n listModels.execute({ includePrivate: false })\n ]);\n\n return [model.value, publicModels.value];\n });\n\n const fieldRegistry = context.container.resolve(CmsModelFieldToGraphQLRegistry);\n\n // Register GraphQL schema plugin\n const graphQlPlugin = await createGraphQLSchema({\n model,\n models: publicModels,\n fieldRegistry\n });\n\n context.plugins.register(graphQlPlugin);\n\n // Register features\n RecordLockingFeature.register(context.container, {\n timeout,\n model\n });\n });\n recordLockingContextPlugin.name = \"context.recordLocking\";\n\n return recordLockingContextPlugin;\n};\n\nexport const createRecordLocking = (params?: ICreateContextPluginParams) => {\n const modelsPlugin = createRegisterExtensionPlugin(context => {\n context.container.register(RecordLockingModel);\n });\n\n return [createContextPlugin(params), modelsPlugin];\n};\n"],"names":["createContextPlugin","params","recordLockingContextPlugin","ContextPlugin","context","tenantContext","TenantContext","identityContext","IdentityContext","wcp","WcpContext","getModel","GetModelUseCase","listModels","ListModelsUseCase","timeout","getTimeout","model","publicModels","Promise","RECORD_LOCKING_MODEL_ID","fieldRegistry","CmsModelFieldToGraphQLRegistry","graphQlPlugin","createGraphQLSchema","RecordLockingFeature","createRecordLocking","modelsPlugin","createRegisterExtensionPlugin","RecordLockingModel"],"mappings":";;;;;;;;;;;;AAqBA,MAAMA,sBAAsB,CAACC;IACzB,MAAMC,6BAA6B,IAAIC,cAA8B,OAAMC;QACvE,MAAMC,gBAAgBD,QAAQ,SAAS,CAAC,OAAO,CAACE;QAChD,MAAMC,kBAAkBH,QAAQ,SAAS,CAAC,OAAO,CAACI;QAClD,MAAMC,MAAML,QAAQ,SAAS,CAAC,OAAO,CAACM;QACtC,MAAMC,WAAWP,QAAQ,SAAS,CAAC,OAAO,CAACQ;QAC3C,MAAMC,aAAaT,QAAQ,SAAS,CAAC,OAAO,CAACU;QAE7C,IAAI,CAACL,IAAI,mBAAmB,MAAM,CAACJ,cAAc,SAAS,IACtD;QAIJ,MAAMU,UAAUC,WAAWf,QAAQ;QAGnC,MAAM,CAACgB,OAAOC,aAAa,GAAG,MAAMX,gBAAgB,oBAAoB,CAAC;YACrE,MAAM,CAACU,OAAOC,aAAa,GAAG,MAAMC,QAAQ,GAAG,CAAC;gBAE5CR,SAAS,OAAO,CAACS;gBAEjBP,WAAW,OAAO,CAAC;oBAAE,gBAAgB;gBAAM;aAC9C;YAED,OAAO;gBAACI,MAAM,KAAK;gBAAEC,aAAa,KAAK;aAAC;QAC5C;QAEA,MAAMG,gBAAgBjB,QAAQ,SAAS,CAAC,OAAO,CAACkB;QAGhD,MAAMC,gBAAgB,MAAMC,oBAAoB;YAC5CP;YACA,QAAQC;YACRG;QACJ;QAEAjB,QAAQ,OAAO,CAAC,QAAQ,CAACmB;QAGzBE,qBAAqB,QAAQ,CAACrB,QAAQ,SAAS,EAAE;YAC7CW;YACAE;QACJ;IACJ;IACAf,2BAA2B,IAAI,GAAG;IAElC,OAAOA;AACX;AAEO,MAAMwB,sBAAsB,CAACzB;IAChC,MAAM0B,eAAeC,8BAA8BxB,CAAAA;QAC/CA,QAAQ,SAAS,CAAC,QAAQ,CAACyB;IAC/B;IAEA,OAAO;QAAC7B,oBAAoBC;QAAS0B;KAAa;AACtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-record-locking",
3
- "version": "6.4.0-beta.0",
3
+ "version": "6.4.0-beta.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -16,21 +16,21 @@
16
16
  ],
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@webiny/api": "6.4.0-beta.0",
20
- "@webiny/api-headless-cms": "6.4.0-beta.0",
21
- "@webiny/api-websockets": "6.4.0-beta.0",
22
- "@webiny/feature": "6.4.0-beta.0",
23
- "@webiny/handler": "6.4.0-beta.0",
24
- "@webiny/handler-aws": "6.4.0-beta.0",
25
- "@webiny/handler-graphql": "6.4.0-beta.0",
26
- "@webiny/plugins": "6.4.0-beta.0",
27
- "@webiny/utils": "6.4.0-beta.0"
19
+ "@webiny/api": "6.4.0-beta.2",
20
+ "@webiny/api-headless-cms": "6.4.0-beta.2",
21
+ "@webiny/api-websockets": "6.4.0-beta.2",
22
+ "@webiny/feature": "6.4.0-beta.2",
23
+ "@webiny/handler": "6.4.0-beta.2",
24
+ "@webiny/handler-aws": "6.4.0-beta.2",
25
+ "@webiny/handler-graphql": "6.4.0-beta.2",
26
+ "@webiny/plugins": "6.4.0-beta.2",
27
+ "@webiny/utils": "6.4.0-beta.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@webiny/api-core": "6.4.0-beta.0",
31
- "@webiny/build-tools": "6.4.0-beta.0",
32
- "@webiny/project-utils": "6.4.0-beta.0",
33
- "@webiny/wcp": "6.4.0-beta.0",
30
+ "@webiny/api-core": "6.4.0-beta.2",
31
+ "@webiny/build-tools": "6.4.0-beta.2",
32
+ "@webiny/project-utils": "6.4.0-beta.2",
33
+ "@webiny/wcp": "6.4.0-beta.2",
34
34
  "graphql": "16.14.0",
35
35
  "rimraf": "6.1.3",
36
36
  "type-fest": "5.6.0",
@@ -41,5 +41,5 @@
41
41
  "access": "public",
42
42
  "directory": "dist"
43
43
  },
44
- "gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
44
+ "gitHead": "872f9f50baa1ff6915a5f338216f84bf0b6dfd24"
45
45
  }