@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.
- package/dist/bindings/utils.js +1 -1
- package/dist/bindings/utils.js.map +1 -1
- package/dist/constants.d.ts +12 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +10 -8
- package/dist/constants.js.map +1 -1
- package/dist/database-lifecycle/appDatabaseImport.d.ts +16 -0
- package/dist/database-lifecycle/appDatabaseImport.d.ts.map +1 -1
- package/dist/database-lifecycle/appDatabaseImport.js.map +1 -1
- package/dist/database-lifecycle/appDatabaseStatus.d.ts +12 -2
- package/dist/database-lifecycle/appDatabaseStatus.d.ts.map +1 -1
- package/dist/database-lifecycle/appDatabaseStatus.js +8 -2
- package/dist/database-lifecycle/appDatabaseStatus.js.map +1 -1
- package/dist/database-lifecycle/appDatabaseStatus.test.js +2 -0
- package/dist/database-lifecycle/appDatabaseStatus.test.js.map +1 -1
- package/dist/database-lifecycle/dataImport.d.ts +3 -0
- package/dist/database-lifecycle/dataImport.d.ts.map +1 -1
- package/dist/database-lifecycle/dataImport.js.map +1 -1
- package/dist/database-lifecycle/importCompatibility.d.ts +13 -0
- package/dist/database-lifecycle/importCompatibility.d.ts.map +1 -1
- package/dist/database-lifecycle/importCompatibility.js +33 -0
- package/dist/database-lifecycle/importCompatibility.js.map +1 -1
- package/dist/database-lifecycle/importCompatibility.test.js +47 -1
- package/dist/database-lifecycle/importCompatibility.test.js.map +1 -1
- package/dist/database-lifecycle/index.d.ts +5 -1
- package/dist/database-lifecycle/index.d.ts.map +1 -1
- package/dist/database-lifecycle/index.js +4 -0
- package/dist/database-lifecycle/index.js.map +1 -1
- package/dist/errors/integration.js +1 -1
- package/dist/errors/integration.js.map +1 -1
- package/dist/headers.d.ts +9 -0
- package/dist/headers.d.ts.map +1 -0
- package/dist/headers.js +12 -0
- package/dist/headers.js.map +1 -0
- package/dist/jwt/verifier.js +1 -1
- package/dist/jwt/verifier.js.map +1 -1
- package/dist/observability/index.d.ts +1 -0
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +1 -0
- package/dist/observability/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/pageMigrations/migrations/v5to6.d.ts.map +1 -1
- package/dist/pageMigrations/migrations/v5to6.js +6 -1
- package/dist/pageMigrations/migrations/v5to6.js.map +1 -1
- package/dist/pageMigrations/migrations/v6to7/adjustModalCanvases.js +1 -1
- package/dist/pageMigrations/migrations/v6to7/adjustModalCanvases.js.map +1 -1
- package/dist/pageMigrations/migrations/v6to7/migrateToDimensions.js +1 -1
- package/dist/pageMigrations/migrations/v6to7/migrateToDimensions.js.map +1 -1
- package/dist/pageMigrations/migrations/v7to8.d.ts.map +1 -1
- package/dist/pageMigrations/migrations/v7to8.js +2 -1
- package/dist/pageMigrations/migrations/v7to8.js.map +1 -1
- package/dist/pages/pageV8.js +1 -1
- package/dist/pages/pageV8.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/templates/shared/openapi.js +1 -1
- package/dist/plugins/templates/shared/openapi.js.map +1 -1
- package/dist/plugins/unsupported-integration-types.d.ts +10 -0
- package/dist/plugins/unsupported-integration-types.d.ts.map +1 -0
- package/dist/plugins/unsupported-integration-types.js +29 -0
- package/dist/plugins/unsupported-integration-types.js.map +1 -0
- package/dist/refactoring/application.d.ts.map +1 -1
- package/dist/refactoring/application.js +2 -1
- package/dist/refactoring/application.js.map +1 -1
- package/dist/refactoring/refactor.d.ts.map +1 -1
- package/dist/refactoring/refactor.js +4 -1
- package/dist/refactoring/refactor.js.map +1 -1
- package/dist/refactoring/rename.js +1 -1
- package/dist/refactoring/rename.js.map +1 -1
- package/dist/refactoring/updates.d.ts.map +1 -1
- package/dist/refactoring/updates.js +3 -1
- package/dist/refactoring/updates.js.map +1 -1
- package/dist/signing/index.js +1 -1
- package/dist/signing/index.js.map +1 -1
- package/dist/socket/dist-entry.test.js +10 -2
- package/dist/socket/dist-entry.test.js.map +1 -1
- package/dist/socket/protocol.d.ts +21 -0
- package/dist/socket/protocol.d.ts.map +1 -1
- package/dist/types/ai/builder-caller.d.ts +16 -0
- package/dist/types/ai/builder-caller.d.ts.map +1 -0
- package/dist/types/ai/builder-caller.js +64 -0
- package/dist/types/ai/builder-caller.js.map +1 -0
- package/dist/types/ai/builder-caller.test.d.ts +2 -0
- package/dist/types/ai/builder-caller.test.d.ts.map +1 -0
- package/dist/types/ai/builder-caller.test.js +40 -0
- package/dist/types/ai/builder-caller.test.js.map +1 -0
- package/dist/types/ai/index.d.ts +10 -0
- package/dist/types/ai/index.d.ts.map +1 -1
- package/dist/types/ai/index.js +2 -0
- package/dist/types/ai/index.js.map +1 -1
- package/dist/types/api/execution.d.ts.map +1 -1
- package/dist/types/api/execution.js +4 -1
- package/dist/types/api/execution.js.map +1 -1
- package/dist/types/api/global.js +1 -1
- package/dist/types/api/global.js.map +1 -1
- package/dist/types/application/index.d.ts +2 -0
- package/dist/types/application/index.d.ts.map +1 -1
- package/dist/types/application/index.js.map +1 -1
- package/dist/types/branch/index.d.ts +76 -0
- package/dist/types/branch/index.d.ts.map +1 -1
- package/dist/types/common/response.d.ts +3 -0
- package/dist/types/common/response.d.ts.map +1 -1
- package/dist/types/common/response.js +2 -0
- package/dist/types/common/response.js.map +1 -1
- package/dist/types/datasource/auth.js +1 -1
- package/dist/types/datasource/auth.js.map +1 -1
- package/dist/types/event/index.d.ts +1 -0
- package/dist/types/event/index.d.ts.map +1 -1
- package/dist/types/event/index.js +1 -0
- package/dist/types/event/index.js.map +1 -1
- package/dist/types/page/event.d.ts.map +1 -1
- package/dist/types/page/event.js +2 -1
- package/dist/types/page/event.js.map +1 -1
- package/dist/types/plugin/evaluation.d.ts.map +1 -1
- package/dist/types/plugin/evaluation.js +3 -1
- package/dist/types/plugin/evaluation.js.map +1 -1
- package/dist/utils/attachment-validation.d.ts.map +1 -1
- package/dist/utils/attachment-validation.js +5 -4
- package/dist/utils/attachment-validation.js.map +1 -1
- package/dist/utils/bytestring.d.ts.map +1 -1
- package/dist/utils/bytestring.js +4 -3
- package/dist/utils/bytestring.js.map +1 -1
- package/dist/utils/bytestring.test.d.ts +2 -0
- package/dist/utils/bytestring.test.d.ts.map +1 -0
- package/dist/utils/bytestring.test.js +23 -0
- package/dist/utils/bytestring.test.js.map +1 -0
- package/dist/utils/configuration.d.ts.map +1 -1
- package/dist/utils/configuration.js +3 -1
- package/dist/utils/configuration.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/openApiSpecRef.d.ts +3 -0
- package/dist/utils/openApiSpecRef.d.ts.map +1 -0
- package/dist/utils/openApiSpecRef.js +27 -0
- package/dist/utils/openApiSpecRef.js.map +1 -0
- package/dist/utils/openApiSpecRef.test.d.ts +2 -0
- package/dist/utils/openApiSpecRef.test.d.ts.map +1 -0
- package/dist/utils/openApiSpecRef.test.js +16 -0
- package/dist/utils/openApiSpecRef.test.js.map +1 -0
- package/dist/utils/page.js +1 -1
- package/dist/utils/page.js.map +1 -1
- package/dist/utils/url.js +1 -1
- package/dist/utils/url.js.map +1 -1
- package/package.json +16 -16
- package/src/bindings/utils.ts +1 -1
- package/src/constants.ts +14 -8
- package/src/database-lifecycle/appDatabaseImport.ts +34 -0
- package/src/database-lifecycle/appDatabaseStatus.test.ts +2 -0
- package/src/database-lifecycle/appDatabaseStatus.ts +19 -3
- package/src/database-lifecycle/dataImport.ts +6 -0
- package/src/database-lifecycle/importCompatibility.test.ts +60 -1
- package/src/database-lifecycle/importCompatibility.ts +52 -0
- package/src/database-lifecycle/index.ts +6 -0
- package/src/errors/integration.ts +1 -1
- package/src/headers.ts +11 -0
- package/src/jwt/verifier.ts +1 -1
- package/src/observability/index.ts +1 -0
- package/src/pageMigrations/migrations/v5to6.ts +6 -1
- package/src/pageMigrations/migrations/v6to7/adjustModalCanvases.ts +1 -1
- package/src/pageMigrations/migrations/v6to7/migrateToDimensions.ts +1 -1
- package/src/pageMigrations/migrations/v7to8.ts +2 -1
- package/src/pages/pageV8.ts +1 -1
- package/src/plugins/index.ts +1 -0
- package/src/plugins/templates/shared/openapi.ts +1 -1
- package/src/plugins/unsupported-integration-types.ts +30 -0
- package/src/refactoring/application.ts +2 -1
- package/src/refactoring/refactor.ts +4 -1
- package/src/refactoring/rename.ts +1 -1
- package/src/refactoring/updates.ts +3 -1
- package/src/signing/index.ts +1 -1
- package/src/socket/dist-entry.test.ts +14 -2
- package/src/socket/protocol.ts +12 -0
- package/src/types/ai/builder-caller.test.ts +45 -0
- package/src/types/ai/builder-caller.ts +63 -0
- package/src/types/ai/index.ts +11 -0
- package/src/types/api/execution.ts +4 -1
- package/src/types/api/global.ts +1 -1
- package/src/types/application/index.ts +2 -0
- package/src/types/branch/index.ts +74 -0
- package/src/types/common/response.ts +3 -0
- package/src/types/datasource/auth.ts +1 -1
- package/src/types/event/index.ts +1 -0
- package/src/types/page/event.ts +2 -1
- package/src/types/plugin/evaluation.ts +3 -1
- package/src/utils/attachment-validation.ts +8 -4
- package/src/utils/bytestring.test.ts +31 -0
- package/src/utils/bytestring.ts +6 -3
- package/src/utils/configuration.ts +3 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/openApiSpecRef.test.ts +20 -0
- package/src/utils/openApiSpecRef.ts +30 -0
- package/src/utils/page.ts +1 -1
- 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;
|
package/src/types/event/index.ts
CHANGED
package/src/types/page/event.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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
|
|
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
|
-
|
|
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
|
+
});
|
package/src/utils/bytestring.ts
CHANGED
|
@@ -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 (
|
|
20
|
-
if (
|
|
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 {
|
package/src/utils/index.ts
CHANGED
|
@@ -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
package/src/utils/url.ts
CHANGED