@dataships/launcher 0.1.0 → 0.2.0

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.
@@ -1,4 +1,4 @@
1
1
  {
2
- "launcher.js": "sha384-LKyFGKElWKSVH/mBuoN935DjDoNN8Db19ybdrjdP2XMHXf1idpPbAnE3dGedFgdL",
3
- "modules/alia-0.1.0.js": "sha384-9xPpfZ0igsFhzDbG07mFdUITev2k3I0o7etHTpGoQs5w62AS7dP03ecGtveijSYp"
2
+ "launcher.js": "sha384-G6itJsfiMshc5Sdg9NdFuI8cJxq4WCMsU19gsN9NxviUC7rxTApGRZ8lgvqXY5aG",
3
+ "modules/alia-0.2.0.js": "sha384-jW/3r9fyQjBcLKnIiLSbASojfBstddKdOxHnOUtnHRvJBbaMuD3yDJprA0GaLkQv"
4
4
  }
package/dist/launcher.js CHANGED
@@ -12,6 +12,19 @@
12
12
  // src/elementsApi.ts
13
13
  var ELEMENTS_PATH = "/v1/elements";
14
14
  var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
15
+ var parseChannels = (value) => {
16
+ if (value === void 0) return [];
17
+ if (!Array.isArray(value)) return null;
18
+ const channels = [];
19
+ for (const entry of value) {
20
+ if (typeof entry !== "object" || entry === null) return null;
21
+ const { channel, subscriptionType } = entry;
22
+ if (!isNonEmptyString(channel) || !isNonEmptyString(subscriptionType))
23
+ return null;
24
+ channels.push({ channel, subscriptionType });
25
+ }
26
+ return channels;
27
+ };
15
28
  var parseElements = (body) => {
16
29
  if (typeof body !== "object" || body === null) return null;
17
30
  const { datashipsSessionId, token, elements } = body;
@@ -20,13 +33,15 @@
20
33
  const refs = [];
21
34
  for (const element of elements) {
22
35
  if (typeof element !== "object" || element === null) return null;
23
- const { type, id } = element;
36
+ const { type, id, channels } = element;
24
37
  if (!isNonEmptyString(type) || !isNonEmptyString(id)) return null;
25
- refs.push({ type, id });
38
+ const parsedChannels = parseChannels(channels);
39
+ if (!parsedChannels) return null;
40
+ refs.push({ type, id, channels: parsedChannels });
26
41
  }
27
42
  return { datashipsSessionId, token, elements: refs };
28
43
  };
29
- var idsOfType = (data, type) => data.elements.filter((element) => element.type === type).map((element) => element.id);
44
+ var elementsOfType = (data, type) => data.elements.filter((element) => element.type === type);
30
45
  var fetchElements = async (fetchFn, baseUrl, publicKey) => {
31
46
  try {
32
47
  const response = await fetchFn(`${baseUrl}${ELEMENTS_PATH}`, {
@@ -132,7 +147,7 @@
132
147
  var MODULES = [
133
148
  {
134
149
  type: "ALIA_FORM",
135
- file: `modules/alia-${"0.1.0"}.js`,
150
+ file: `modules/alia-${"0.2.0"}.js`,
136
151
  watch: watchAlia
137
152
  }
138
153
  ];
@@ -154,7 +169,7 @@
154
169
  if (!config) return;
155
170
  const guard = win;
156
171
  if (guard.__datashipsLauncher) return;
157
- guard.__datashipsLauncher = { version: "0.1.0" };
172
+ guard.__datashipsLauncher = { version: "0.2.0" };
158
173
  const modules = env.modules ?? MODULES;
159
174
  const importModule = env.importModule ?? defaultImport;
160
175
  const load = (definition, context, beforeStart) => startModule(importModule, config, definition, context, beforeStart);
@@ -165,7 +180,7 @@
165
180
  preview: true,
166
181
  token: null,
167
182
  datashipsSessionId: null,
168
- campaignIds: [],
183
+ elements: [],
169
184
  events: []
170
185
  };
171
186
  await Promise.all(modules.map((definition) => load(definition, context)));
@@ -177,8 +192,10 @@
177
192
  }));
178
193
  const outcome = await resolveElements(env, config);
179
194
  for (const { definition, watch } of watched) {
180
- const campaignIds = outcome.status === "ok" ? idsOfType(outcome.data, definition.type) : [];
181
- if (outcome.status !== "ok" || campaignIds.length === 0) {
195
+ const elements = outcome.status === "ok" ? elementsOfType(outcome.data, definition.type).map(
196
+ ({ id, channels }) => ({ id, channels })
197
+ ) : [];
198
+ if (outcome.status !== "ok" || elements.length === 0) {
182
199
  watch.stop();
183
200
  continue;
184
201
  }
@@ -188,7 +205,7 @@
188
205
  preview: false,
189
206
  token: outcome.data.token,
190
207
  datashipsSessionId: outcome.data.datashipsSessionId,
191
- campaignIds,
208
+ elements,
192
209
  events: watch.events
193
210
  };
194
211
  void watch.present.then(() => load(definition, context, watch.stop));