@lowdefy/build 4.0.0-alpha.21 → 4.0.0-alpha.24

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.
@@ -13,66 +13,59 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- function buildCallbacks({ components , context }) {
17
- if (type.isArray(components.auth.callbacks)) {
18
- components.auth.callbacks.forEach((callback)=>{
19
- if (type.isUndefined(callback.id)) {
20
- throw new Error(`Auth callback id missing.`);
16
+ function buildAuthPlugin({ counter , pluginConfig , typeClass }) {
17
+ if (type.isArray(pluginConfig)) {
18
+ pluginConfig.forEach((plugin)=>{
19
+ if (type.isUndefined(plugin.id)) {
20
+ throw new Error(`Auth ${typeClass} id missing.`);
21
21
  }
22
- if (!type.isString(callback.id)) {
23
- throw new Error(`Auth callback id is not a string. Received ${JSON.stringify(callback.id)}.`);
22
+ if (!type.isString(plugin.id)) {
23
+ throw new Error(`Auth ${typeClass} id is not a string. Received ${JSON.stringify(plugin.id)}.`);
24
24
  }
25
- if (!type.isString(callback.type)) {
26
- throw new Error(`Auth callback type is not a string at callback "${callback.id}". Received ${JSON.stringify(callback.type)}.`);
25
+ if (!type.isString(plugin.type)) {
26
+ throw new Error(`Auth ${typeClass} type is not a string at ${typeClass} "${plugin.id}". Received ${JSON.stringify(plugin.type)}.`);
27
27
  }
28
- context.typeCounters.auth.callbacks.increment(callback.type);
28
+ counter.increment(plugin.type);
29
29
  });
30
30
  }
31
31
  }
32
- function buildEvents({ components , context }) {
33
- if (type.isArray(components.auth.events)) {
34
- components.auth.events.forEach((event)=>{
35
- if (type.isUndefined(event.id)) {
36
- throw new Error(`Auth event id missing.`);
37
- }
38
- if (!type.isString(event.id)) {
39
- throw new Error(`Auth event id is not a string. Received ${JSON.stringify(event.id)}.`);
40
- }
41
- if (!type.isString(event.type)) {
42
- throw new Error(`Auth event type is not a string at event "${event.id}". Received ${JSON.stringify(event.type)}.`);
43
- }
44
- context.typeCounters.auth.events.increment(event.type);
45
- });
32
+ function buildAdapter({ components , context }) {
33
+ const { adapter } = components.auth;
34
+ if (type.isNone(adapter)) {
35
+ return;
46
36
  }
47
- }
48
- function buildProviders({ components , context }) {
49
- if (type.isArray(components.auth.providers)) {
50
- components.auth.providers.forEach((provider)=>{
51
- if (type.isUndefined(provider.id)) {
52
- throw new Error(`Auth provider id missing.`);
53
- }
54
- if (!type.isString(provider.id)) {
55
- throw new Error(`Auth provider id is not a string. Received ${JSON.stringify(provider.id)}.`);
56
- }
57
- if (!type.isString(provider.type)) {
58
- throw new Error(`Auth provider type is not a string at provider "${provider.id}". Received ${JSON.stringify(provider.type)}.`);
59
- }
60
- context.typeCounters.auth.providers.increment(provider.type);
61
- });
37
+ if (type.isUndefined(adapter.id)) {
38
+ throw new Error(`Auth adapter id missing.`);
39
+ }
40
+ if (!type.isString(adapter.id)) {
41
+ throw new Error(`Auth adapter id is not a string. Received ${JSON.stringify(adapter.id)}.`);
62
42
  }
43
+ if (!type.isString(adapter.type)) {
44
+ throw new Error(`Auth adapter type is not a string at adapter "${adapter.id}". Received ${JSON.stringify(adapter.type)}.`);
45
+ }
46
+ context.typeCounters.auth.adapters.increment(adapter.type);
63
47
  }
64
48
  function buildAuthPlugins({ components , context }) {
65
- buildCallbacks({
49
+ const counters = context.typeCounters.auth;
50
+ const authConfig = components.auth;
51
+ buildAdapter({
66
52
  components,
67
53
  context
68
54
  });
69
- buildEvents({
70
- components,
71
- context
55
+ buildAuthPlugin({
56
+ counter: counters.callbacks,
57
+ pluginConfig: authConfig.callbacks,
58
+ typeClass: 'callback'
72
59
  });
73
- buildProviders({
74
- components,
75
- context
60
+ buildAuthPlugin({
61
+ counter: counters.events,
62
+ pluginConfig: authConfig.events,
63
+ typeClass: 'event'
64
+ });
65
+ buildAuthPlugin({
66
+ counter: counters.providers,
67
+ pluginConfig: authConfig.providers,
68
+ typeClass: 'provider'
76
69
  });
77
70
  }
78
71
  export default buildAuthPlugins;
@@ -23,6 +23,7 @@ function getPluginPackages({ components }) {
23
23
  });
24
24
  }
25
25
  getPackages(components.types.actions);
26
+ getPackages(components.types.auth.adapters);
26
27
  getPackages(components.types.auth.callbacks);
27
28
  getPackages(components.types.auth.events);
28
29
  getPackages(components.types.auth.providers);
@@ -54,6 +55,10 @@ function buildImportsDev({ components , context }) {
54
55
  map: context.typesMap.actions
55
56
  }),
56
57
  auth: {
58
+ adapters: buildImportClassDev({
59
+ pluginPackages,
60
+ map: context.typesMap.auth.adapters
61
+ }),
57
62
  callbacks: buildImportClassDev({
58
63
  pluginPackages,
59
64
  map: context.typesMap.auth.callbacks
@@ -27,6 +27,7 @@ function buildImportsProd({ components , context }) {
27
27
  return {
28
28
  actions: buildImportClassProd(components.types.actions),
29
29
  auth: {
30
+ adapters: buildImportClassProd(components.types.auth.adapters),
30
31
  callbacks: buildImportClassProd(components.types.auth.callbacks),
31
32
  events: buildImportClassProd(components.types.auth.events),
32
33
  providers: buildImportClassProd(components.types.auth.providers)
@@ -47,6 +47,9 @@ function buildEvents(block, pageContext) {
47
47
  if (!type.isArray(block.events[key].try)) {
48
48
  throw new Error(`Try actions must be an array at "${block.blockId}" in event "${key}.try" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
49
49
  }
50
+ if (type.isNone(block.events[key].catch)) {
51
+ block.events[key].catch = [];
52
+ }
50
53
  if (!type.isArray(block.events[key].catch)) {
51
54
  throw new Error(`Catch actions must be an array at "${block.blockId}" in event "${key}.catch" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].catch)}`);
52
55
  }
@@ -45,6 +45,7 @@ function buildTypes({ components , context }) {
45
45
  components.types = {
46
46
  actions: {},
47
47
  auth: {
48
+ adapters: {},
48
49
  callbacks: {},
49
50
  events: {},
50
51
  providers: {}
@@ -63,6 +64,12 @@ function buildTypes({ components , context }) {
63
64
  store: components.types.actions,
64
65
  typeClass: 'Action'
65
66
  });
67
+ buildTypeClass(context, {
68
+ counter: typeCounters.auth.adapters,
69
+ definitions: context.typesMap.auth.adapters,
70
+ store: components.types.auth.adapters,
71
+ typeClass: 'Auth adapter'
72
+ });
66
73
  buildTypeClass(context, {
67
74
  counter: typeCounters.auth.callbacks,
68
75
  definitions: context.typesMap.auth.callbacks,
@@ -25,6 +25,7 @@ async function updateServerPackageJson({ components , context }) {
25
25
  });
26
26
  }
27
27
  getPackages(components.types.actions);
28
+ getPackages(components.types.auth.adapters);
28
29
  getPackages(components.types.auth.callbacks);
29
30
  getPackages(components.types.auth.events);
30
31
  getPackages(components.types.auth.providers);
@@ -14,6 +14,10 @@
14
14
  limitations under the License.
15
15
  */ import generateImportFile from './generateImportFile.js';
16
16
  async function writeAuthImports({ components , context }) {
17
+ await context.writeBuildArtifact('plugins/auth/adapters.js', generateImportFile({
18
+ imports: components.imports.auth.adapters,
19
+ importPath: 'auth/adapters'
20
+ }));
17
21
  await context.writeBuildArtifact('plugins/auth/callbacks.js', generateImportFile({
18
22
  imports: components.imports.auth.callbacks,
19
23
  importPath: 'auth/callbacks'
@@ -29,6 +29,7 @@ function createContext({ customTypesMap , directories , logger , refResolver , s
29
29
  typeCounters: {
30
30
  actions: createCounter(),
31
31
  auth: {
32
+ adapters: createCounter(),
32
33
  callbacks: createCounter(),
33
34
  events: createCounter(),
34
35
  providers: createCounter()