@relyio/sdk 0.2.1 → 0.3.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/{chunk-7W4MJXQ4.cjs → chunk-54WP2PWG.cjs} +215 -96
  4. package/dist/chunk-BBUB7C2Z.js +81 -0
  5. package/dist/{chunk-FJK7ZWKK.cjs → chunk-HMVGXUGR.cjs} +156 -221
  6. package/dist/chunk-LSRPMNPT.cjs +89 -0
  7. package/dist/{chunk-2QUK2ZGD.js → chunk-LYRYCIX5.js} +157 -219
  8. package/dist/{chunk-RJBIJ2ZK.js → chunk-QIZOBT5F.js} +215 -96
  9. package/dist/client/index.cjs +4 -3
  10. package/dist/client/index.d.cts +4 -3
  11. package/dist/client/index.d.ts +4 -3
  12. package/dist/client/index.js +2 -1
  13. package/dist/define-content-type-CBfnTWSS.d.cts +716 -0
  14. package/dist/define-content-type-CBfnTWSS.d.ts +716 -0
  15. package/dist/{define-schema-DHvUCKwj.d.cts → define-schema-BD6HSPnG.d.ts} +55 -722
  16. package/dist/{define-schema-DHvUCKwj.d.ts → define-schema-BfXeR6K8.d.cts} +55 -722
  17. package/dist/dev-handshake/index.cjs +37 -0
  18. package/dist/dev-handshake/index.d.cts +144 -0
  19. package/dist/dev-handshake/index.d.ts +144 -0
  20. package/dist/dev-handshake/index.js +4 -0
  21. package/dist/{index-DGWaawHt.d.cts → index-BDpar3FO.d.cts} +22 -6
  22. package/dist/{index-BsUqCAu8.d.cts → index-DuEhsGdE.d.ts} +516 -2155
  23. package/dist/{index-B-KiFHbx.d.ts → index-Dx01iwaf.d.ts} +22 -6
  24. package/dist/{index-BsUqCAu8.d.ts → index-ulOrcfPa.d.cts} +516 -2155
  25. package/dist/index.cjs +67 -70
  26. package/dist/index.d.cts +28 -13
  27. package/dist/index.d.ts +28 -13
  28. package/dist/index.js +3 -2
  29. package/dist/schema/index.cjs +35 -47
  30. package/dist/schema/index.d.cts +3 -2
  31. package/dist/schema/index.d.ts +3 -2
  32. package/dist/schema/index.js +1 -1
  33. package/dist/types/index.d.cts +2 -1
  34. package/dist/types/index.d.ts +2 -1
  35. package/package.json +11 -5
@@ -4,174 +4,6 @@ var chunkMWMSFIWN_cjs = require('./chunk-MWMSFIWN.cjs');
4
4
 
5
5
  /* RelyIO SDK - Built with ❤️ by the RelyIO Team */
6
6
 
7
- // src/schema/define-workflow.ts
8
- function defineWorkflowStage(id, config) {
9
- if (!id || id.length === 0) {
10
- throw new Error("Workflow stage ID is required");
11
- }
12
- const stageIdPattern = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$|^[a-z][a-zA-Z0-9]*$/;
13
- if (!stageIdPattern.test(id)) {
14
- throw new Error(
15
- `Workflow stage ID '${id}' must be kebab-case (e.g., editorial-review) or camelCase (e.g., editorialReview)`
16
- );
17
- }
18
- if (id.length > 64) {
19
- throw new Error(`Workflow stage ID '${id}' must be 64 characters or less`);
20
- }
21
- if (!config.displayName || config.displayName.length === 0) {
22
- throw new Error("Workflow stage displayName is required");
23
- }
24
- if (config.displayName.length > 128) {
25
- throw new Error(`Workflow stage displayName must be 128 characters or less`);
26
- }
27
- if (config.description != null && config.description.length > 512) {
28
- throw new Error(`Workflow stage description must be 512 characters or less`);
29
- }
30
- const requiredApprovals = config.requiredApprovals ?? 1;
31
- if (requiredApprovals < 1 || requiredApprovals > 10) {
32
- throw new Error(`requiredApprovals must be between 1 and 10`);
33
- }
34
- if (config.timeoutDays !== void 0) {
35
- if (config.timeoutDays < 1 || config.timeoutDays > 365) {
36
- throw new Error(`timeoutDays must be between 1 and 365`);
37
- }
38
- }
39
- if (config.autoAssign) {
40
- if (!Array.isArray(config.autoAssign.roles) || config.autoAssign.roles.length === 0) {
41
- throw new Error(`autoAssign.roles must be a non-empty array`);
42
- }
43
- }
44
- return {
45
- _tag: "workflowStage",
46
- id,
47
- displayName: config.displayName,
48
- ...config.description !== void 0 && config.description !== "" && { description: config.description },
49
- requiredApprovals,
50
- ...config.allowedRoles !== void 0 && config.allowedRoles.length > 0 && { allowedRoles: config.allowedRoles },
51
- ...config.autoAssign !== void 0 && { autoAssign: config.autoAssign },
52
- ...config.timeoutDays !== void 0 && { timeoutDays: config.timeoutDays },
53
- ...config.escalation !== void 0 && { escalation: config.escalation }
54
- };
55
- }
56
- chunkMWMSFIWN_cjs.__name(defineWorkflowStage, "defineWorkflowStage");
57
- function defineWorkflow(config) {
58
- const enabled = config.enabled ?? false;
59
- const stages = config.stages ?? [];
60
- if (stages.length > 0) {
61
- const stageIds = /* @__PURE__ */ new Set();
62
- for (const stage of stages) {
63
- if (stageIds.has(stage.id)) {
64
- throw new Error(`Duplicate workflow stage ID '${stage.id}'`);
65
- }
66
- stageIds.add(stage.id);
67
- }
68
- }
69
- return {
70
- _tag: "workflow",
71
- enabled,
72
- stages
73
- };
74
- }
75
- chunkMWMSFIWN_cjs.__name(defineWorkflow, "defineWorkflow");
76
- function defineContentTypeWorkflow(config) {
77
- return {
78
- ...config.enabled !== void 0 && { enabled: config.enabled },
79
- ...config.stages !== void 0 && config.stages.length > 0 && { stages: config.stages },
80
- ...config.autoPublish !== void 0 && { autoPublish: config.autoPublish },
81
- ...config.requireAllLocales !== void 0 && { requireAllLocales: config.requireAllLocales }
82
- };
83
- }
84
- chunkMWMSFIWN_cjs.__name(defineContentTypeWorkflow, "defineContentTypeWorkflow");
85
- function isWorkflowStageDefinition(value) {
86
- return typeof value === "object" && value !== null && "_tag" in value && value._tag === "workflowStage";
87
- }
88
- chunkMWMSFIWN_cjs.__name(isWorkflowStageDefinition, "isWorkflowStageDefinition");
89
- function isWorkflowDefinition(value) {
90
- return typeof value === "object" && value !== null && "_tag" in value && value._tag === "workflow";
91
- }
92
- chunkMWMSFIWN_cjs.__name(isWorkflowDefinition, "isWorkflowDefinition");
93
- function getWorkflowStageIds(workflow) {
94
- return workflow.stages.map((s) => s.id);
95
- }
96
- chunkMWMSFIWN_cjs.__name(getWorkflowStageIds, "getWorkflowStageIds");
97
- function findWorkflowStage(workflow, stageId) {
98
- return workflow.stages.find((s) => s.id === stageId);
99
- }
100
- chunkMWMSFIWN_cjs.__name(findWorkflowStage, "findWorkflowStage");
101
- function getNextWorkflowStage(workflow, currentStageId) {
102
- const currentIndex = workflow.stages.findIndex((s) => s.id === currentStageId);
103
- if (currentIndex === -1 || currentIndex === workflow.stages.length - 1) {
104
- return null;
105
- }
106
- const nextStage = workflow.stages[currentIndex + 1];
107
- return nextStage ?? null;
108
- }
109
- chunkMWMSFIWN_cjs.__name(getNextWorkflowStage, "getNextWorkflowStage");
110
- function getFirstWorkflowStage(workflow) {
111
- if (workflow.stages.length === 0) return null;
112
- const firstStage = workflow.stages[0];
113
- return firstStage ?? null;
114
- }
115
- chunkMWMSFIWN_cjs.__name(getFirstWorkflowStage, "getFirstWorkflowStage");
116
- function isFinalWorkflowStage(workflow, stageId) {
117
- if (workflow.stages.length === 0) return false;
118
- const lastStage = workflow.stages[workflow.stages.length - 1];
119
- return lastStage?.id === stageId;
120
- }
121
- chunkMWMSFIWN_cjs.__name(isFinalWorkflowStage, "isFinalWorkflowStage");
122
- function workflowToJSON(workflow) {
123
- return {
124
- enabled: workflow.enabled,
125
- ...workflow.stages.length > 0 && {
126
- stages: workflow.stages.map((stage) => {
127
- const { _tag: _, ...rest } = stage;
128
- return rest;
129
- })
130
- }
131
- };
132
- }
133
- chunkMWMSFIWN_cjs.__name(workflowToJSON, "workflowToJSON");
134
-
135
- // src/schema/define-view.ts
136
- function generateSlugFromId(id) {
137
- return id.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
138
- }
139
- chunkMWMSFIWN_cjs.__name(generateSlugFromId, "generateSlugFromId");
140
- function defineView(id, config) {
141
- if (!id.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) {
142
- throw new Error(
143
- `View ID '${id}' must start with a letter and contain only letters, numbers, underscores, and hyphens`
144
- );
145
- }
146
- if (!config.name || config.name.length === 0) {
147
- throw new Error(`View '${id}' must have a name`);
148
- }
149
- if (config.metadataFields && config.metadataFields.length > 3) {
150
- throw new Error(`View '${id}' can have at most 3 metadata fields`);
151
- }
152
- if (!config.scope?.type) {
153
- throw new Error(`View '${id}' must have a valid scope`);
154
- }
155
- const slug2 = config.slug ?? generateSlugFromId(id);
156
- if (!slug2.match(/^[a-z][a-z0-9-]*$/)) {
157
- throw new Error(
158
- `View '${id}' slug '${slug2}' must be lowercase, start with a letter, and contain only letters, numbers, and hyphens`
159
- );
160
- }
161
- return {
162
- _tag: "view",
163
- id,
164
- slug: slug2,
165
- ...config
166
- };
167
- }
168
- chunkMWMSFIWN_cjs.__name(defineView, "defineView");
169
- function viewToJSON(view) {
170
- const { _tag, ...rest } = view;
171
- return rest;
172
- }
173
- chunkMWMSFIWN_cjs.__name(viewToJSON, "viewToJSON");
174
-
175
7
  // src/schema/define-schema.ts
176
8
  function defineSchema(config) {
177
9
  if (config.contentTypes == null || Object.keys(config.contentTypes).length === 0) {
@@ -276,53 +108,6 @@ function defineSchema(config) {
276
108
  };
277
109
  }
278
110
  chunkMWMSFIWN_cjs.__name(defineSchema, "defineSchema");
279
- function schemaToJSON(schema) {
280
- const stripTag = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((obj) => {
281
- const { _tag, ...rest } = obj;
282
- return rest;
283
- }, "stripTag");
284
- return {
285
- // Include locales if defined (strip _tag from each locale)
286
- ...schema.locales && schema.locales.length > 0 && {
287
- locales: schema.locales.map((locale) => stripTag(locale))
288
- },
289
- contentTypes: Object.fromEntries(
290
- Object.entries(schema.contentTypes).map(([key, value]) => [key, stripTag(value)])
291
- ),
292
- components: Object.fromEntries(
293
- Object.entries(schema.components).map(([key, value]) => [key, stripTag(value)])
294
- ),
295
- singletonContentTypes: Object.fromEntries(
296
- Object.entries(schema.singletonContentTypes).map(([key, value]) => [key, stripTag(value)])
297
- ),
298
- queries: Object.fromEntries(
299
- Object.entries(schema.queries).map(([key, value]) => [key, stripTag(value)])
300
- ),
301
- ...schema.settingsGroups && {
302
- settingsGroups: Object.fromEntries(
303
- Object.entries(schema.settingsGroups).map(([key, value]) => [key, stripTag(value)])
304
- )
305
- },
306
- ...schema.assetTypes && Object.keys(schema.assetTypes).length > 0 && {
307
- assetTypes: Object.fromEntries(
308
- Object.entries(schema.assetTypes).map(([key, value]) => [key, stripTag(value)])
309
- )
310
- },
311
- // Include roles if defined (strip _tag from each role)
312
- ...schema.roles && schema.roles.length > 0 && {
313
- roles: schema.roles.map((role) => stripTag(role))
314
- },
315
- // Include workflow if defined (convert to JSON format)
316
- ...schema.workflow && {
317
- workflow: workflowToJSON(schema.workflow)
318
- },
319
- // Include views if defined (convert to JSON format)
320
- ...schema.views && schema.views.length > 0 && {
321
- views: schema.views.map((view) => viewToJSON(view))
322
- }
323
- };
324
- }
325
- chunkMWMSFIWN_cjs.__name(schemaToJSON, "schemaToJSON");
326
111
 
327
112
  // src/schema/define-locale.ts
328
113
  var BCP47_PATTERN = /^[a-z]{2}(-[A-Z]{2})?$/;
@@ -605,6 +390,157 @@ function getBuiltInRoleActions(roleId) {
605
390
  }
606
391
  chunkMWMSFIWN_cjs.__name(getBuiltInRoleActions, "getBuiltInRoleActions");
607
392
 
393
+ // src/schema/define-workflow.ts
394
+ function defineWorkflowStage(id, config) {
395
+ if (!id || id.length === 0) {
396
+ throw new Error("Workflow stage ID is required");
397
+ }
398
+ const stageIdPattern = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$|^[a-z][a-zA-Z0-9]*$/;
399
+ if (!stageIdPattern.test(id)) {
400
+ throw new Error(
401
+ `Workflow stage ID '${id}' must be kebab-case (e.g., editorial-review) or camelCase (e.g., editorialReview)`
402
+ );
403
+ }
404
+ if (id.length > 64) {
405
+ throw new Error(`Workflow stage ID '${id}' must be 64 characters or less`);
406
+ }
407
+ if (!config.displayName || config.displayName.length === 0) {
408
+ throw new Error("Workflow stage displayName is required");
409
+ }
410
+ if (config.displayName.length > 128) {
411
+ throw new Error(`Workflow stage displayName must be 128 characters or less`);
412
+ }
413
+ if (config.description != null && config.description.length > 512) {
414
+ throw new Error(`Workflow stage description must be 512 characters or less`);
415
+ }
416
+ const requiredApprovals = config.requiredApprovals ?? 1;
417
+ if (requiredApprovals < 1 || requiredApprovals > 10) {
418
+ throw new Error(`requiredApprovals must be between 1 and 10`);
419
+ }
420
+ if (config.timeoutDays !== void 0) {
421
+ if (config.timeoutDays < 1 || config.timeoutDays > 365) {
422
+ throw new Error(`timeoutDays must be between 1 and 365`);
423
+ }
424
+ }
425
+ if (config.autoAssign) {
426
+ if (!Array.isArray(config.autoAssign.roles) || config.autoAssign.roles.length === 0) {
427
+ throw new Error(`autoAssign.roles must be a non-empty array`);
428
+ }
429
+ }
430
+ return {
431
+ _tag: "workflowStage",
432
+ id,
433
+ displayName: config.displayName,
434
+ ...config.description !== void 0 && config.description !== "" && { description: config.description },
435
+ requiredApprovals,
436
+ ...config.allowedRoles !== void 0 && config.allowedRoles.length > 0 && { allowedRoles: config.allowedRoles },
437
+ ...config.autoAssign !== void 0 && { autoAssign: config.autoAssign },
438
+ ...config.timeoutDays !== void 0 && { timeoutDays: config.timeoutDays },
439
+ ...config.escalation !== void 0 && { escalation: config.escalation }
440
+ };
441
+ }
442
+ chunkMWMSFIWN_cjs.__name(defineWorkflowStage, "defineWorkflowStage");
443
+ function defineWorkflow(config) {
444
+ const enabled = config.enabled ?? false;
445
+ const stages = config.stages ?? [];
446
+ if (stages.length > 0) {
447
+ const stageIds = /* @__PURE__ */ new Set();
448
+ for (const stage of stages) {
449
+ if (stageIds.has(stage.id)) {
450
+ throw new Error(`Duplicate workflow stage ID '${stage.id}'`);
451
+ }
452
+ stageIds.add(stage.id);
453
+ }
454
+ }
455
+ return {
456
+ _tag: "workflow",
457
+ enabled,
458
+ stages
459
+ };
460
+ }
461
+ chunkMWMSFIWN_cjs.__name(defineWorkflow, "defineWorkflow");
462
+ function defineContentTypeWorkflow(config) {
463
+ return {
464
+ ...config.enabled !== void 0 && { enabled: config.enabled },
465
+ ...config.stages !== void 0 && config.stages.length > 0 && { stages: config.stages },
466
+ ...config.autoPublish !== void 0 && { autoPublish: config.autoPublish },
467
+ ...config.requireAllLocales !== void 0 && { requireAllLocales: config.requireAllLocales }
468
+ };
469
+ }
470
+ chunkMWMSFIWN_cjs.__name(defineContentTypeWorkflow, "defineContentTypeWorkflow");
471
+ function isWorkflowStageDefinition(value) {
472
+ return typeof value === "object" && value !== null && "_tag" in value && value._tag === "workflowStage";
473
+ }
474
+ chunkMWMSFIWN_cjs.__name(isWorkflowStageDefinition, "isWorkflowStageDefinition");
475
+ function isWorkflowDefinition(value) {
476
+ return typeof value === "object" && value !== null && "_tag" in value && value._tag === "workflow";
477
+ }
478
+ chunkMWMSFIWN_cjs.__name(isWorkflowDefinition, "isWorkflowDefinition");
479
+ function getWorkflowStageIds(workflow) {
480
+ return workflow.stages.map((s) => s.id);
481
+ }
482
+ chunkMWMSFIWN_cjs.__name(getWorkflowStageIds, "getWorkflowStageIds");
483
+ function findWorkflowStage(workflow, stageId) {
484
+ return workflow.stages.find((s) => s.id === stageId);
485
+ }
486
+ chunkMWMSFIWN_cjs.__name(findWorkflowStage, "findWorkflowStage");
487
+ function getNextWorkflowStage(workflow, currentStageId) {
488
+ const currentIndex = workflow.stages.findIndex((s) => s.id === currentStageId);
489
+ if (currentIndex === -1 || currentIndex === workflow.stages.length - 1) {
490
+ return null;
491
+ }
492
+ const nextStage = workflow.stages[currentIndex + 1];
493
+ return nextStage ?? null;
494
+ }
495
+ chunkMWMSFIWN_cjs.__name(getNextWorkflowStage, "getNextWorkflowStage");
496
+ function getFirstWorkflowStage(workflow) {
497
+ if (workflow.stages.length === 0) return null;
498
+ const firstStage = workflow.stages[0];
499
+ return firstStage ?? null;
500
+ }
501
+ chunkMWMSFIWN_cjs.__name(getFirstWorkflowStage, "getFirstWorkflowStage");
502
+ function isFinalWorkflowStage(workflow, stageId) {
503
+ if (workflow.stages.length === 0) return false;
504
+ const lastStage = workflow.stages[workflow.stages.length - 1];
505
+ return lastStage?.id === stageId;
506
+ }
507
+ chunkMWMSFIWN_cjs.__name(isFinalWorkflowStage, "isFinalWorkflowStage");
508
+
509
+ // src/schema/define-view.ts
510
+ function generateSlugFromId(id) {
511
+ return id.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
512
+ }
513
+ chunkMWMSFIWN_cjs.__name(generateSlugFromId, "generateSlugFromId");
514
+ function defineView(id, config) {
515
+ if (!id.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) {
516
+ throw new Error(
517
+ `View ID '${id}' must start with a letter and contain only letters, numbers, underscores, and hyphens`
518
+ );
519
+ }
520
+ if (!config.name || config.name.length === 0) {
521
+ throw new Error(`View '${id}' must have a name`);
522
+ }
523
+ if (config.metadataFields && config.metadataFields.length > 3) {
524
+ throw new Error(`View '${id}' can have at most 3 metadata fields`);
525
+ }
526
+ if (!config.scope?.type) {
527
+ throw new Error(`View '${id}' must have a valid scope`);
528
+ }
529
+ const slug2 = config.slug ?? generateSlugFromId(id);
530
+ if (!slug2.match(/^[a-z][a-z0-9-]*$/)) {
531
+ throw new Error(
532
+ `View '${id}' slug '${slug2}' must be lowercase, start with a letter, and contain only letters, numbers, and hyphens`
533
+ );
534
+ }
535
+ return {
536
+ _tag: "view",
537
+ id,
538
+ slug: slug2,
539
+ ...config
540
+ };
541
+ }
542
+ chunkMWMSFIWN_cjs.__name(defineView, "defineView");
543
+
608
544
  // src/schema/define-query.ts
609
545
  function defineQuery(name, config) {
610
546
  if (!config.fetch && !config.aggregate && !config.search && !config.similar) {
@@ -625,7 +561,9 @@ function defineQuery(name, config) {
625
561
  include: config.include,
626
562
  filters: config.filters,
627
563
  select: config.select,
628
- cache: config.cache
564
+ cache: config.cache,
565
+ parameters: config.parameters,
566
+ cardinality: config.cardinality
629
567
  };
630
568
  }
631
569
  chunkMWMSFIWN_cjs.__name(defineQuery, "defineQuery");
@@ -769,8 +707,5 @@ exports.isLocaleDefinition = isLocaleDefinition;
769
707
  exports.isRoleDefinition = isRoleDefinition;
770
708
  exports.isWorkflowDefinition = isWorkflowDefinition;
771
709
  exports.isWorkflowStageDefinition = isWorkflowStageDefinition;
772
- exports.schemaToJSON = schemaToJSON;
773
- exports.viewToJSON = viewToJSON;
774
- exports.workflowToJSON = workflowToJSON;
775
- //# sourceMappingURL=chunk-FJK7ZWKK.cjs.map
776
- //# sourceMappingURL=chunk-FJK7ZWKK.cjs.map
710
+ //# sourceMappingURL=chunk-HMVGXUGR.cjs.map
711
+ //# sourceMappingURL=chunk-HMVGXUGR.cjs.map
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ var chunkMWMSFIWN_cjs = require('./chunk-MWMSFIWN.cjs');
4
+
5
+ /* RelyIO SDK - Built with ❤️ by the RelyIO Team */
6
+
7
+ // src/dev-handshake/index.ts
8
+ var DEV_CONTEXT_DIR = ".relyio";
9
+ var DEV_CONTEXT_FILENAME = "dev.json";
10
+ var DEV_CONTEXT_FILE = `${DEV_CONTEXT_DIR}/${DEV_CONTEXT_FILENAME}`;
11
+ var DEV_ENV = {
12
+ dataset: "RELYIO_DEV_DATASET",
13
+ apiKey: "RELYIO_DEV_API_KEY",
14
+ expiresAt: "RELYIO_DEV_EXPIRES_AT"
15
+ };
16
+ function readDeadline(raw, now) {
17
+ if (raw === void 0 || raw === null || raw === "") return { state: "none" };
18
+ if (typeof raw !== "string") return { state: "unreadable" };
19
+ const deadline = new Date(raw).getTime();
20
+ if (!Number.isFinite(deadline)) return { state: "unreadable" };
21
+ return deadline <= now ? { state: "passed", expiredAt: raw } : { state: "live", expiresAt: raw };
22
+ }
23
+ chunkMWMSFIWN_cjs.__name(readDeadline, "readDeadline");
24
+ function parseDevContextFile(raw, now) {
25
+ let parsed;
26
+ try {
27
+ parsed = JSON.parse(raw);
28
+ } catch {
29
+ return { state: "unreadable", reason: "not-json" };
30
+ }
31
+ if (typeof parsed !== "object" || parsed === null) {
32
+ return { state: "unreadable", reason: "not-json" };
33
+ }
34
+ const record = parsed;
35
+ const { datasetId, previewApiKey, branchId, expiresAt } = record;
36
+ if (typeof datasetId !== "string" || datasetId === "" || typeof previewApiKey !== "string" || previewApiKey === "" || typeof branchId !== "string" || branchId === "") {
37
+ return { state: "unreadable", reason: "missing-fields" };
38
+ }
39
+ const deadline = readDeadline(expiresAt, now);
40
+ if (deadline.state === "unreadable") return { state: "unreadable", reason: "bad-expiry" };
41
+ const context = {
42
+ datasetId,
43
+ previewApiKey,
44
+ branchId,
45
+ expiresAt: deadline.state === "none" ? null : expiresAt
46
+ };
47
+ return deadline.state === "passed" ? { state: "expired", context, expiredAt: deadline.expiredAt } : { state: "active", context };
48
+ }
49
+ chunkMWMSFIWN_cjs.__name(parseDevContextFile, "parseDevContextFile");
50
+ function buildDevEnv(context) {
51
+ const env = {
52
+ [DEV_ENV.dataset]: context.datasetId,
53
+ [DEV_ENV.apiKey]: context.previewApiKey
54
+ };
55
+ if (context.expiresAt != null && context.expiresAt !== "") {
56
+ env[DEV_ENV.expiresAt] = context.expiresAt;
57
+ }
58
+ return env;
59
+ }
60
+ chunkMWMSFIWN_cjs.__name(buildDevEnv, "buildDevEnv");
61
+ function parseDevEnv(env, now) {
62
+ const dataset = env?.[DEV_ENV.dataset];
63
+ const apiKey = env?.[DEV_ENV.apiKey];
64
+ if (dataset == null || dataset === "" || apiKey == null || apiKey === "") {
65
+ return { state: "absent" };
66
+ }
67
+ const deadline = readDeadline(env?.[DEV_ENV.expiresAt], now);
68
+ switch (deadline.state) {
69
+ case "unreadable":
70
+ return { state: "unreadable", reason: "bad-expiry" };
71
+ case "passed":
72
+ return { state: "expired", expiredAt: deadline.expiredAt };
73
+ case "live":
74
+ return { state: "active", credentials: { dataset, apiKey }, expiresAt: deadline.expiresAt };
75
+ case "none":
76
+ return { state: "active", credentials: { dataset, apiKey }, expiresAt: null };
77
+ }
78
+ }
79
+ chunkMWMSFIWN_cjs.__name(parseDevEnv, "parseDevEnv");
80
+
81
+ exports.DEV_CONTEXT_DIR = DEV_CONTEXT_DIR;
82
+ exports.DEV_CONTEXT_FILE = DEV_CONTEXT_FILE;
83
+ exports.DEV_CONTEXT_FILENAME = DEV_CONTEXT_FILENAME;
84
+ exports.DEV_ENV = DEV_ENV;
85
+ exports.buildDevEnv = buildDevEnv;
86
+ exports.parseDevContextFile = parseDevContextFile;
87
+ exports.parseDevEnv = parseDevEnv;
88
+ //# sourceMappingURL=chunk-LSRPMNPT.cjs.map
89
+ //# sourceMappingURL=chunk-LSRPMNPT.cjs.map