@superblocksteam/shared 0.9619.7 → 0.9620.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 (197) hide show
  1. package/dist/bindings/utils.js +1 -1
  2. package/dist/bindings/utils.js.map +1 -1
  3. package/dist/constants.d.ts +12 -8
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/constants.js +10 -8
  6. package/dist/constants.js.map +1 -1
  7. package/dist/database-lifecycle/appDatabaseImport.d.ts +16 -0
  8. package/dist/database-lifecycle/appDatabaseImport.d.ts.map +1 -1
  9. package/dist/database-lifecycle/appDatabaseImport.js.map +1 -1
  10. package/dist/database-lifecycle/appDatabaseStatus.d.ts +12 -2
  11. package/dist/database-lifecycle/appDatabaseStatus.d.ts.map +1 -1
  12. package/dist/database-lifecycle/appDatabaseStatus.js +8 -2
  13. package/dist/database-lifecycle/appDatabaseStatus.js.map +1 -1
  14. package/dist/database-lifecycle/appDatabaseStatus.test.js +2 -0
  15. package/dist/database-lifecycle/appDatabaseStatus.test.js.map +1 -1
  16. package/dist/database-lifecycle/dataImport.d.ts +3 -0
  17. package/dist/database-lifecycle/dataImport.d.ts.map +1 -1
  18. package/dist/database-lifecycle/dataImport.js.map +1 -1
  19. package/dist/database-lifecycle/importCompatibility.d.ts +13 -0
  20. package/dist/database-lifecycle/importCompatibility.d.ts.map +1 -1
  21. package/dist/database-lifecycle/importCompatibility.js +33 -0
  22. package/dist/database-lifecycle/importCompatibility.js.map +1 -1
  23. package/dist/database-lifecycle/importCompatibility.test.js +47 -1
  24. package/dist/database-lifecycle/importCompatibility.test.js.map +1 -1
  25. package/dist/database-lifecycle/index.d.ts +5 -1
  26. package/dist/database-lifecycle/index.d.ts.map +1 -1
  27. package/dist/database-lifecycle/index.js +4 -0
  28. package/dist/database-lifecycle/index.js.map +1 -1
  29. package/dist/errors/integration.js +1 -1
  30. package/dist/errors/integration.js.map +1 -1
  31. package/dist/headers.d.ts +9 -0
  32. package/dist/headers.d.ts.map +1 -0
  33. package/dist/headers.js +12 -0
  34. package/dist/headers.js.map +1 -0
  35. package/dist/jwt/verifier.js +1 -1
  36. package/dist/jwt/verifier.js.map +1 -1
  37. package/dist/observability/index.d.ts +1 -0
  38. package/dist/observability/index.d.ts.map +1 -1
  39. package/dist/observability/index.js +1 -0
  40. package/dist/observability/index.js.map +1 -1
  41. package/dist/package.json +1 -1
  42. package/dist/pageMigrations/migrations/v5to6.d.ts.map +1 -1
  43. package/dist/pageMigrations/migrations/v5to6.js +6 -1
  44. package/dist/pageMigrations/migrations/v5to6.js.map +1 -1
  45. package/dist/pageMigrations/migrations/v6to7/adjustModalCanvases.js +1 -1
  46. package/dist/pageMigrations/migrations/v6to7/adjustModalCanvases.js.map +1 -1
  47. package/dist/pageMigrations/migrations/v6to7/migrateToDimensions.js +1 -1
  48. package/dist/pageMigrations/migrations/v6to7/migrateToDimensions.js.map +1 -1
  49. package/dist/pageMigrations/migrations/v7to8.d.ts.map +1 -1
  50. package/dist/pageMigrations/migrations/v7to8.js +2 -1
  51. package/dist/pageMigrations/migrations/v7to8.js.map +1 -1
  52. package/dist/pages/pageV8.js +1 -1
  53. package/dist/pages/pageV8.js.map +1 -1
  54. package/dist/plugins/index.d.ts +1 -0
  55. package/dist/plugins/index.d.ts.map +1 -1
  56. package/dist/plugins/index.js +1 -0
  57. package/dist/plugins/index.js.map +1 -1
  58. package/dist/plugins/templates/shared/openapi.js +1 -1
  59. package/dist/plugins/templates/shared/openapi.js.map +1 -1
  60. package/dist/plugins/unsupported-integration-types.d.ts +10 -0
  61. package/dist/plugins/unsupported-integration-types.d.ts.map +1 -0
  62. package/dist/plugins/unsupported-integration-types.js +29 -0
  63. package/dist/plugins/unsupported-integration-types.js.map +1 -0
  64. package/dist/refactoring/application.d.ts.map +1 -1
  65. package/dist/refactoring/application.js +2 -1
  66. package/dist/refactoring/application.js.map +1 -1
  67. package/dist/refactoring/refactor.d.ts.map +1 -1
  68. package/dist/refactoring/refactor.js +4 -1
  69. package/dist/refactoring/refactor.js.map +1 -1
  70. package/dist/refactoring/rename.js +1 -1
  71. package/dist/refactoring/rename.js.map +1 -1
  72. package/dist/refactoring/updates.d.ts.map +1 -1
  73. package/dist/refactoring/updates.js +3 -1
  74. package/dist/refactoring/updates.js.map +1 -1
  75. package/dist/signing/index.js +1 -1
  76. package/dist/signing/index.js.map +1 -1
  77. package/dist/socket/dist-entry.test.js +10 -2
  78. package/dist/socket/dist-entry.test.js.map +1 -1
  79. package/dist/socket/protocol.d.ts +21 -0
  80. package/dist/socket/protocol.d.ts.map +1 -1
  81. package/dist/types/ai/builder-caller.d.ts +16 -0
  82. package/dist/types/ai/builder-caller.d.ts.map +1 -0
  83. package/dist/types/ai/builder-caller.js +64 -0
  84. package/dist/types/ai/builder-caller.js.map +1 -0
  85. package/dist/types/ai/builder-caller.test.d.ts +2 -0
  86. package/dist/types/ai/builder-caller.test.d.ts.map +1 -0
  87. package/dist/types/ai/builder-caller.test.js +40 -0
  88. package/dist/types/ai/builder-caller.test.js.map +1 -0
  89. package/dist/types/ai/index.d.ts +10 -0
  90. package/dist/types/ai/index.d.ts.map +1 -1
  91. package/dist/types/ai/index.js +2 -0
  92. package/dist/types/ai/index.js.map +1 -1
  93. package/dist/types/api/execution.d.ts.map +1 -1
  94. package/dist/types/api/execution.js +4 -1
  95. package/dist/types/api/execution.js.map +1 -1
  96. package/dist/types/api/global.js +1 -1
  97. package/dist/types/api/global.js.map +1 -1
  98. package/dist/types/application/index.d.ts +2 -0
  99. package/dist/types/application/index.d.ts.map +1 -1
  100. package/dist/types/application/index.js.map +1 -1
  101. package/dist/types/branch/index.d.ts +76 -0
  102. package/dist/types/branch/index.d.ts.map +1 -1
  103. package/dist/types/common/response.d.ts +3 -0
  104. package/dist/types/common/response.d.ts.map +1 -1
  105. package/dist/types/common/response.js +2 -0
  106. package/dist/types/common/response.js.map +1 -1
  107. package/dist/types/datasource/auth.js +1 -1
  108. package/dist/types/datasource/auth.js.map +1 -1
  109. package/dist/types/event/index.d.ts +1 -0
  110. package/dist/types/event/index.d.ts.map +1 -1
  111. package/dist/types/event/index.js +1 -0
  112. package/dist/types/event/index.js.map +1 -1
  113. package/dist/types/page/event.d.ts.map +1 -1
  114. package/dist/types/page/event.js +2 -1
  115. package/dist/types/page/event.js.map +1 -1
  116. package/dist/types/plugin/evaluation.d.ts.map +1 -1
  117. package/dist/types/plugin/evaluation.js +3 -1
  118. package/dist/types/plugin/evaluation.js.map +1 -1
  119. package/dist/utils/attachment-validation.d.ts.map +1 -1
  120. package/dist/utils/attachment-validation.js +5 -4
  121. package/dist/utils/attachment-validation.js.map +1 -1
  122. package/dist/utils/bytestring.d.ts.map +1 -1
  123. package/dist/utils/bytestring.js +4 -3
  124. package/dist/utils/bytestring.js.map +1 -1
  125. package/dist/utils/bytestring.test.d.ts +2 -0
  126. package/dist/utils/bytestring.test.d.ts.map +1 -0
  127. package/dist/utils/bytestring.test.js +23 -0
  128. package/dist/utils/bytestring.test.js.map +1 -0
  129. package/dist/utils/configuration.d.ts.map +1 -1
  130. package/dist/utils/configuration.js +3 -1
  131. package/dist/utils/configuration.js.map +1 -1
  132. package/dist/utils/index.d.ts +1 -0
  133. package/dist/utils/index.d.ts.map +1 -1
  134. package/dist/utils/index.js +1 -0
  135. package/dist/utils/index.js.map +1 -1
  136. package/dist/utils/openApiSpecRef.d.ts +3 -0
  137. package/dist/utils/openApiSpecRef.d.ts.map +1 -0
  138. package/dist/utils/openApiSpecRef.js +27 -0
  139. package/dist/utils/openApiSpecRef.js.map +1 -0
  140. package/dist/utils/openApiSpecRef.test.d.ts +2 -0
  141. package/dist/utils/openApiSpecRef.test.d.ts.map +1 -0
  142. package/dist/utils/openApiSpecRef.test.js +16 -0
  143. package/dist/utils/openApiSpecRef.test.js.map +1 -0
  144. package/dist/utils/page.js +1 -1
  145. package/dist/utils/page.js.map +1 -1
  146. package/dist/utils/url.js +1 -1
  147. package/dist/utils/url.js.map +1 -1
  148. package/package.json +16 -16
  149. package/src/bindings/utils.ts +1 -1
  150. package/src/constants.ts +14 -8
  151. package/src/database-lifecycle/appDatabaseImport.ts +34 -0
  152. package/src/database-lifecycle/appDatabaseStatus.test.ts +2 -0
  153. package/src/database-lifecycle/appDatabaseStatus.ts +19 -3
  154. package/src/database-lifecycle/dataImport.ts +6 -0
  155. package/src/database-lifecycle/importCompatibility.test.ts +60 -1
  156. package/src/database-lifecycle/importCompatibility.ts +52 -0
  157. package/src/database-lifecycle/index.ts +6 -0
  158. package/src/errors/integration.ts +1 -1
  159. package/src/headers.ts +11 -0
  160. package/src/jwt/verifier.ts +1 -1
  161. package/src/observability/index.ts +1 -0
  162. package/src/pageMigrations/migrations/v5to6.ts +6 -1
  163. package/src/pageMigrations/migrations/v6to7/adjustModalCanvases.ts +1 -1
  164. package/src/pageMigrations/migrations/v6to7/migrateToDimensions.ts +1 -1
  165. package/src/pageMigrations/migrations/v7to8.ts +2 -1
  166. package/src/pages/pageV8.ts +1 -1
  167. package/src/plugins/index.ts +1 -0
  168. package/src/plugins/templates/shared/openapi.ts +1 -1
  169. package/src/plugins/unsupported-integration-types.ts +30 -0
  170. package/src/refactoring/application.ts +2 -1
  171. package/src/refactoring/refactor.ts +4 -1
  172. package/src/refactoring/rename.ts +1 -1
  173. package/src/refactoring/updates.ts +3 -1
  174. package/src/signing/index.ts +1 -1
  175. package/src/socket/dist-entry.test.ts +14 -2
  176. package/src/socket/protocol.ts +12 -0
  177. package/src/types/ai/builder-caller.test.ts +45 -0
  178. package/src/types/ai/builder-caller.ts +63 -0
  179. package/src/types/ai/index.ts +11 -0
  180. package/src/types/api/execution.ts +4 -1
  181. package/src/types/api/global.ts +1 -1
  182. package/src/types/application/index.ts +2 -0
  183. package/src/types/branch/index.ts +74 -0
  184. package/src/types/common/response.ts +3 -0
  185. package/src/types/datasource/auth.ts +1 -1
  186. package/src/types/event/index.ts +1 -0
  187. package/src/types/page/event.ts +2 -1
  188. package/src/types/plugin/evaluation.ts +3 -1
  189. package/src/utils/attachment-validation.ts +8 -4
  190. package/src/utils/bytestring.test.ts +31 -0
  191. package/src/utils/bytestring.ts +6 -3
  192. package/src/utils/configuration.ts +3 -1
  193. package/src/utils/index.ts +1 -0
  194. package/src/utils/openApiSpecRef.test.ts +20 -0
  195. package/src/utils/openApiSpecRef.ts +30 -0
  196. package/src/utils/page.ts +1 -1
  197. package/src/utils/url.ts +1 -1
@@ -1,4 +1,5 @@
1
1
  import type { ApplicationSignatureTreeSigned, Signature } from '../../signing/index.js';
2
+ import type { AiBuilderBinding } from '../ai/index.js';
2
3
  import type {
3
4
  ApplicationUserDto,
4
5
  BaseBlock,
@@ -535,6 +536,7 @@ export type PostApplicationCreateRequestBody = {
535
536
  templateName?: string;
536
537
  /** When provided, server generates an AI app name from this prompt */
537
538
  initialPrompt?: string;
539
+ builderHarness?: AiBuilderBinding['harness'];
538
540
  };
539
541
  export interface ApplicationPageClonePayload {
540
542
  applicationId: string;
@@ -7,3 +7,77 @@ export interface BranchDto {
7
7
  checkedOut?: boolean;
8
8
  baseBranchName?: string;
9
9
  }
10
+
11
+ export type BranchStatus = {
12
+ branch: string;
13
+ branchHead: string | null;
14
+ mainHead: string | null;
15
+ /** ahead and behind count only commits since the merge base that changed the tree. Merge commits do not count. */
16
+ ahead: number;
17
+ behind: number;
18
+ mainAuthors: Array<{ id: string; name: string | null }>;
19
+ /** A merge with conflicts waits for the checkpoint that resolves it. */
20
+ pendingMerge: boolean;
21
+ /** The branch lands on main by itself when that checkpoint is saved. */
22
+ landPending: boolean;
23
+ hasUncommittedChanges: boolean;
24
+ /** Another user's publish going out for this app. Publishing waits until it finishes. */
25
+ otherPublish?: { userId: string; userName: string | null } | null;
26
+ /** The app's user branches. A branch with a holder is locked to that user until they leave. */
27
+ branches?: UserBranchSummary[];
28
+ };
29
+
30
+ export type UserBranchSummary = {
31
+ name: string;
32
+ /** The title of a named branch; null for the owner's default branch. */
33
+ title: string | null;
34
+ ownerId: string | null;
35
+ ownerName: string | null;
36
+ holderId: string | null;
37
+ holderName: string | null;
38
+ };
39
+
40
+ export type BranchIncomingCommit = {
41
+ commitId: string;
42
+ committerId: string | null;
43
+ committerName: string | null;
44
+ message: string | null;
45
+ paths: string[];
46
+ };
47
+
48
+ export type BranchConflict = { path: string; kind: string };
49
+
50
+ export type BranchUpdateResult = {
51
+ outcome: 'up-to-date' | 'clean' | 'conflict';
52
+ /** The new branch head. Set only for a clean outcome. */
53
+ commitId?: string;
54
+ conflicts: BranchConflict[];
55
+ incoming: BranchIncomingCommit[];
56
+ /** The note for Clark: commit count and changed paths, no authors or messages. Empty when nothing came in. */
57
+ contextNote: string;
58
+ };
59
+
60
+ export type BranchLandResult = {
61
+ /**
62
+ * 'contended' means main moved during every land attempt. 'migrating' means the app database is applying migrations
63
+ * before main moves: land again to finish. 'migration-failed' means one of the branch's migrations failed.
64
+ */
65
+ outcome: 'landed' | 'up-to-date' | 'conflict' | 'contended' | 'migrating' | 'migration-failed';
66
+ /** The worker's error, for 'migration-failed'. */
67
+ migrationError?: string;
68
+ mainHead: string;
69
+ update?: BranchUpdateResult;
70
+ contextNote: string;
71
+ };
72
+
73
+ // Lands only a branch's new migration files on main, once the user confirms. 'collision' means a file's number is not
74
+ // above every migration main or the database has. 'migrating' means main takes the files once every data tag's
75
+ // database reports them ready.
76
+ export type BranchMigrationLandResult = {
77
+ outcome: 'landed' | 'migrating' | 'migration-failed' | 'confirmation-required' | 'collision' | 'busy' | 'nothing-to-land';
78
+ mainHead: string;
79
+ /** The main commit that carries the files, once one exists. */
80
+ commitId?: string;
81
+ migrationError?: string;
82
+ collisions?: { path: string; nextVersion: string }[];
83
+ };
@@ -1,3 +1,4 @@
1
+ import type { DestructiveMigrationFinding } from '../../database-lifecycle/destructiveMigrations.js';
1
2
  import type { DatasourceConfiguration } from '../datasource/index.js';
2
3
  import type { Timing } from './timing.js';
3
4
 
@@ -72,6 +73,8 @@ export class ErrorDto {
72
73
  superblocksError?: SuperblocksError;
73
74
  reauth?: ReauthDetails;
74
75
  signInRefusal?: SignInRefusal;
76
+ /** What a refused migration would delete, so the client can ask about exactly these. */
77
+ findings?: DestructiveMigrationFinding[];
75
78
 
76
79
  constructor({ code, message, type }: { code: number | string; message: string; type?: SuperblocksError }) {
77
80
  this.code = code;
@@ -1,5 +1,5 @@
1
1
  import JSON5 from 'json5';
2
- import { isEmpty } from 'lodash-es';
2
+ import isEmpty from 'lodash-es/isEmpty.js';
3
3
 
4
4
  import type { ClientAuthMethod } from '../../plugins/index.js';
5
5
  import type { OAuthErrorResponse, OAuthTokenResponse } from '../auth/index.js';
@@ -36,6 +36,7 @@ export enum EventEntityType {
36
36
  COMPONENT = 'component',
37
37
  REPOSITORY = 'repository',
38
38
  AI = 'ai',
39
+ BUILDER_MCP = 'builder_mcp',
39
40
  /** App Databases logical DB (one per data tag / database_binding). */
40
41
  APP_DATABASE = 'app_database',
41
42
  CVE = 'cve',
@@ -1,4 +1,5 @@
1
- import { isArray, isPlainObject } from 'lodash-es';
1
+ import isArray from 'lodash-es/isArray.js';
2
+ import isPlainObject from 'lodash-es/isPlainObject.js';
2
3
 
3
4
  import type { ApplicationScope } from '../../types/application/index.js';
4
5
  import type { NotificationPosition } from './notification.js';
@@ -2,7 +2,9 @@ import type { TreeCursor } from '@lezer/common';
2
2
  import type { LRParser } from '@lezer/lr';
3
3
  import type { Token, TokenizeOptions } from 'esprima';
4
4
  import type { SourceLocation } from 'estree';
5
- import { get, isFunction, isPlainObject } from 'lodash-es';
5
+ import get from 'lodash-es/get.js';
6
+ import isFunction from 'lodash-es/isFunction.js';
7
+ import isPlainObject from 'lodash-es/isPlainObject.js';
6
8
 
7
9
  export type EvaluationPair = {
8
10
  binding: string;
@@ -1,4 +1,4 @@
1
- import { PDFDocument, PDFPageLeaf, PDFPageTree } from 'pdf-lib';
1
+ import type { PDFDocument, PDFPageLeaf, PDFPageTree } from 'pdf-lib';
2
2
 
3
3
  import { detectAttachmentArchiveType, isDumpAttachment } from './attachment-delivery.js';
4
4
  import { getTextAttachmentType, isOfficeXml, isXlsxAttachmentFile } from './attachment-upload.js';
@@ -253,7 +253,9 @@ function validateText(bytes: Uint8Array): void {
253
253
  }
254
254
  }
255
255
 
256
- function countPdfPages(document: PDFDocument): number {
256
+ type PdfLib = typeof import('pdf-lib');
257
+
258
+ function countPdfPages(document: PDFDocument, { PDFPageLeaf, PDFPageTree }: PdfLib): number {
257
259
  const pending: (PDFPageLeaf | PDFPageTree)[] = [document.catalog.Pages()];
258
260
  const visited = new Set<PDFPageTree>();
259
261
  let pages = 0;
@@ -287,9 +289,11 @@ async function validatePdf(bytes: Uint8Array): Promise<number> {
287
289
  if (!new TextDecoder('latin1').decode(bytes.subarray(0, 1028)).includes('%PDF-')) {
288
290
  throw new AttachmentValidationError('invalid_content');
289
291
  }
292
+ // pdf-lib is large, so load it only when a PDF is actually validated instead of on every import of this package.
293
+ const pdfLib = await import('pdf-lib');
290
294
  try {
291
- const document = await PDFDocument.load(bytes, { throwOnInvalidObject: true, updateMetadata: false });
292
- return countPdfPages(document);
295
+ const document = await pdfLib.PDFDocument.load(bytes, { throwOnInvalidObject: true, updateMetadata: false });
296
+ return countPdfPages(document, pdfLib);
293
297
  } catch (error) {
294
298
  if (error instanceof AttachmentValidationError) throw error;
295
299
  throw new AttachmentValidationError('invalid_content');
@@ -0,0 +1,31 @@
1
+ import { expect, test } from 'vitest';
2
+
3
+ import { decodeBytestrings } from './bytestring.js';
4
+
5
+ test('decodes nested serialized buffers to Uint8Array and leaves other values alone', () => {
6
+ const decoded = decodeBytestrings(
7
+ {
8
+ file: { type: 'Buffer', data: [104, 105] },
9
+ rows: [{ type: 'Buffer', data: [1] }, null, 'text'],
10
+ notBytes: { type: 'Buffer', data: ['a'] }
11
+ },
12
+ false
13
+ );
14
+
15
+ expect(decoded).toEqual({
16
+ file: new Uint8Array([104, 105]),
17
+ rows: [new Uint8Array([1]), null, 'text'],
18
+ notBytes: { type: 'Buffer', data: ['a'] }
19
+ });
20
+ });
21
+
22
+ test('decodes a top level serialized buffer to a node.js Buffer', () => {
23
+ expect(decodeBytestrings({ type: 'Buffer', data: [104, 105] }, true)).toEqual(Buffer.from('hi'));
24
+ });
25
+
26
+ test('decodes buffers inside a top level array and keeps it an array', () => {
27
+ const decoded = decodeBytestrings([{ type: 'Buffer', data: [1] }, 2], false);
28
+
29
+ expect(Array.isArray(decoded)).toBe(true);
30
+ expect(decoded).toEqual([new Uint8Array([1]), 2]);
31
+ });
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { isNumber, isObject } from 'lodash-es';
3
2
 
4
3
  /**
5
4
  * Convert all objects that represent a bytestring to a node.js Buffer or a Uint8Array.
@@ -16,8 +15,12 @@ import { isNumber, isObject } from 'lodash-es';
16
15
  *
17
16
  */
18
17
  export function decodeBytestrings<T>(value: T, useNodeJSBuffer: boolean): T {
19
- if (isObject(value)) {
20
- if ((value as any).type === 'Buffer' && Array.isArray((value as any).data) && (value as any).data.every((x: unknown) => isNumber(x))) {
18
+ if (typeof value === 'object' && value !== null) {
19
+ if (
20
+ (value as any).type === 'Buffer' &&
21
+ Array.isArray((value as any).data) &&
22
+ (value as any).data.every((x: unknown) => typeof x === 'number')
23
+ ) {
21
24
  if (useNodeJSBuffer) {
22
25
  return Buffer.from(value as any) as unknown as T;
23
26
  } else {
@@ -1,4 +1,6 @@
1
- import { find, get, set } from 'lodash-es';
1
+ import find from 'lodash-es/find.js';
2
+ import get from 'lodash-es/get.js';
3
+ import set from 'lodash-es/set.js';
2
4
 
3
5
  import {
4
6
  type FieldListFormItem,
@@ -12,6 +12,7 @@ export * from './launchDarkly.js';
12
12
  export * from './maskCredential.js';
13
13
  export * from './normalize.js';
14
14
  export * from './normalizeRoleName.js';
15
+ export * from './openApiSpecRef.js';
15
16
  export * from './page.js';
16
17
  export * from './string.js';
17
18
  export * from './time.js';
@@ -0,0 +1,20 @@
1
+ import { describe, expect, test } from 'vitest';
2
+
3
+ import { generateOpenApiSpecRef, getOpenApiSpecFileName } from './openApiSpecRef.js';
4
+
5
+ describe('openApiSpecRef', () => {
6
+ test('round-trips a file name through the ref', () => {
7
+ const ref = generateOpenApiSpecRef('65312acf-1bce-4ab5-95a9-787a8f78edde', 'petstore_v2.yaml');
8
+
9
+ expect(ref).toBe('65312acf-1bce-4ab5-95a9-787a8f78edde_petstore_v2.yaml');
10
+ expect(getOpenApiSpecFileName(ref)).toBe('petstore_v2.yaml');
11
+ });
12
+
13
+ test('takes the last path segment of a URL ref', () => {
14
+ expect(getOpenApiSpecFileName('https://example.com/specs/petstore.json')).toBe('petstore.json');
15
+ });
16
+
17
+ test('returns a ref with no id prefix unchanged', () => {
18
+ expect(getOpenApiSpecFileName('petstore.json')).toBe('petstore.json');
19
+ });
20
+ });
@@ -0,0 +1,30 @@
1
+ // An uploaded OpenAPI spec is stored in Bucketeer under `<integrationId>_<fileName>`
2
+ // and that string is saved on the integration configuration as `openApiSpecRef`.
3
+ // A ref may instead be a URL when the spec is fetched remotely rather than uploaded.
4
+
5
+ const isValidUrl = (urlString: string): boolean => {
6
+ try {
7
+ new URL(urlString);
8
+ return true;
9
+ } catch {
10
+ return false;
11
+ }
12
+ };
13
+
14
+ export const generateOpenApiSpecRef = (datasourceId: string, fileName: string): string => {
15
+ return `${datasourceId}_${fileName}`;
16
+ };
17
+
18
+ export const getOpenApiSpecFileName = (openApiSpecRef: string): string | undefined => {
19
+ if (isValidUrl(openApiSpecRef)) {
20
+ // Return the last part of the url that represents the file name
21
+ return openApiSpecRef.split('/').pop();
22
+ }
23
+ const startPos = openApiSpecRef.indexOf('_');
24
+
25
+ if (startPos !== -1) {
26
+ return openApiSpecRef.substring(startPos + 1);
27
+ }
28
+
29
+ return openApiSpecRef;
30
+ };
package/src/utils/page.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { cloneDeep } from 'lodash-es';
1
+ import cloneDeep from 'lodash-es/cloneDeep.js';
2
2
 
3
3
  import { pageV6, pageV7, pageV8 } from '../pages/index.js';
4
4
  import type { AnyPageDSL, PageDSL4and5, PageDSL6, PageDSL7, PageDSL8, WidgetProps8 } from '../types/page/index.js';
package/src/utils/url.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { isEmpty } from 'lodash-es';
1
+ import isEmpty from 'lodash-es/isEmpty.js';
2
2
 
3
3
  import type { Property } from '../index.js';
4
4
  import { RestApiBodyDataType } from '../types/index.js';