@fluxenginejp/sftest 1.1.0 → 1.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.
Files changed (61) hide show
  1. package/dist/cli/sftest.js +70 -7
  2. package/dist/pages/common/ElementStates.d.ts +145 -0
  3. package/dist/pages/common/ElementStates.js +295 -0
  4. package/dist/pages/common/FileRelatedListPage.d.ts +107 -0
  5. package/dist/pages/common/FileRelatedListPage.js +361 -0
  6. package/dist/pages/common/ListViewPage.d.ts +60 -4
  7. package/dist/pages/common/ListViewPage.js +267 -26
  8. package/dist/pages/common/PageButtons.d.ts +72 -2
  9. package/dist/pages/common/PageButtons.js +184 -3
  10. package/dist/pages/common/RecordData.d.ts +13 -0
  11. package/dist/pages/common/RecordData.js +21 -4
  12. package/dist/pages/common/RecordDetailPage.d.ts +103 -5
  13. package/dist/pages/common/RecordDetailPage.js +273 -19
  14. package/dist/pages/common/RecordFields.d.ts +66 -1
  15. package/dist/pages/common/RecordFields.js +119 -7
  16. package/dist/pages/common/RecordFormDialog.d.ts +74 -2
  17. package/dist/pages/common/RecordFormDialog.js +180 -5
  18. package/dist/pages/common/RecordPage.d.ts +46 -5
  19. package/dist/pages/common/RecordPage.js +92 -15
  20. package/dist/pages/common/ScreenDialog.d.ts +11 -0
  21. package/dist/pages/common/ScreenDialog.js +23 -0
  22. package/dist/pages/common/listViewPicker.d.ts +26 -0
  23. package/dist/pages/common/listViewPicker.js +114 -0
  24. package/dist/pages/common/listViewReady.d.ts +34 -0
  25. package/dist/pages/common/listViewReady.js +133 -0
  26. package/dist/pages/common/relatedLists.d.ts +24 -0
  27. package/dist/pages/common/relatedLists.js +65 -0
  28. package/dist/pages/common/scrollCapture.d.ts +2 -1
  29. package/dist/pages/common/scrollCapture.js +21 -2
  30. package/dist/steps/common/common.steps.js +39 -18
  31. package/dist/steps/common/dialog.steps.js +9 -4
  32. package/dist/steps/common/file.steps.d.ts +1 -0
  33. package/dist/steps/common/file.steps.js +52 -0
  34. package/dist/steps/common/import.steps.js +4 -2
  35. package/dist/steps/common/record.steps.js +10 -3
  36. package/dist/steps/common/state.steps.d.ts +1 -0
  37. package/dist/steps/common/state.steps.js +95 -0
  38. package/dist/support/FileDownloads.d.ts +87 -0
  39. package/dist/support/FileDownloads.js +203 -0
  40. package/dist/support/SalesforceFiles.d.ts +52 -0
  41. package/dist/support/SalesforceFiles.js +103 -0
  42. package/dist/support/UploadErrors.d.ts +61 -0
  43. package/dist/support/UploadErrors.js +100 -0
  44. package/dist/support/fileInputs.d.ts +25 -0
  45. package/dist/support/fileInputs.js +57 -0
  46. package/dist/support/fileUploadReceipt.d.ts +26 -0
  47. package/dist/support/fileUploadReceipt.js +59 -0
  48. package/dist/support/fixtures.d.ts +550 -14
  49. package/dist/support/fixtures.js +87 -9
  50. package/dist/support/globalSetup.js +5 -0
  51. package/dist/support/mismatch.d.ts +76 -0
  52. package/dist/support/mismatch.js +136 -0
  53. package/dist/support/session.js +6 -5
  54. package/dist/support/sf.js +23 -3
  55. package/dist/support/startupTiming.d.ts +44 -0
  56. package/dist/support/startupTiming.js +97 -0
  57. package/docs/CHANGELOG.md +147 -112
  58. package/docs/SPEC.html +1614 -517
  59. package/package.json +81 -81
  60. package/readme.md +96 -90
  61. package/scripts/backup-account.bat +1 -1
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SalesforceFiles = void 0;
4
+ /**
5
+ * Salesforce Filesの関連データと、保存応答に対応するバージョンの初版を照合する。
6
+ * UIの描画完了・アップロード・今回の送信に対応する応答の取得・削除は、このクラスでは行わない。
7
+ *
8
+ * @author Fluxengine.co.jp
9
+ */
10
+ const fileInputs_1 = require("./fileInputs");
11
+ const sf_1 = require("./sf");
12
+ /**
13
+ * 対象レコードに関連付けられたファイルを、タイトルと拡張子で特定する。
14
+ * シナリオの状態は持たず、照合ごとに最新の関連付けを取得する。
15
+ * CLI のユーザで取得したデータだけでは画面表示や権限を保証しない。
16
+ */
17
+ class SalesforceFiles {
18
+ query;
19
+ /**
20
+ * Salesforce の共通の SOQL 呼び出しを保持する。
21
+ * @param query - SOQL の実行。ローカル検証では模擬の結果を渡せる。
22
+ */
23
+ constructor(query = sf_1.sfQuery) {
24
+ this.query = query;
25
+ }
26
+ /**
27
+ * 今回の保存応答が、新しい文書の初版を作成したことを確認する。
28
+ * @param receipt - 今回の画面操作の保存応答。
29
+ * @returns 初版ならtrue。既存文書の新しい版ならfalse。
30
+ * @throws バージョンの取得・照合ができない場合。
31
+ */
32
+ isNewDocument(receipt) {
33
+ if (!/^068[a-zA-Z0-9]{12}(?:[a-zA-Z0-9]{3})?$/.test(receipt.versionId)
34
+ || !/^069[a-zA-Z0-9]{12}(?:[a-zA-Z0-9]{3})?$/.test(receipt.documentId))
35
+ throw new Error('保存応答のIDが不正です');
36
+ const rows = this.query(`SELECT Id, ContentDocumentId, VersionNumber FROM ContentVersion WHERE Id = ${(0, sf_1.soqlString)(receipt.versionId)}`);
37
+ const row = rows[0];
38
+ if (rows.length !== 1 || !row || typeof row !== 'object'
39
+ || !('Id' in row) || row.Id !== receipt.versionId
40
+ || !('ContentDocumentId' in row) || row.ContentDocumentId !== receipt.documentId
41
+ || !('VersionNumber' in row) || typeof row.VersionNumber !== 'string' || !/^\d+$/.test(row.VersionNumber)) {
42
+ throw new Error('今回保存したバージョンの作成情報を確認できません');
43
+ }
44
+ return row.VersionNumber === '1';
45
+ }
46
+ /**
47
+ * 関連付け先の全ファイルを取得し、必要なデータを検証する。
48
+ *
49
+ * @param recordId - 指定した関連リストの関連付け先レコードの15桁または18桁の ID。
50
+ * @returns 検証済みのファイル一覧。関連付けの重複は同じ ID ごとにまとめる。
51
+ * @throws ID が不正、通信が失敗、結果のタイトル・拡張子などを取得できない場合。
52
+ */
53
+ linkedFiles(recordId) {
54
+ if (!/^[a-zA-Z0-9]{15}(?:[a-zA-Z0-9]{3})?$/.test(recordId))
55
+ throw new Error('関連付け先のレコード ID が不正です');
56
+ const rows = this.query(`SELECT ContentDocumentId, ContentDocument.Title, ContentDocument.FileExtension FROM ContentDocumentLink WHERE LinkedEntityId = ${(0, sf_1.soqlString)(recordId)}`);
57
+ const files = new Map();
58
+ for (const row of rows) {
59
+ if (!row || typeof row !== 'object' || !('ContentDocumentId' in row) || !('ContentDocument' in row)) {
60
+ throw new Error('ファイルの関連付け情報を取得できません');
61
+ }
62
+ const id = row.ContentDocumentId;
63
+ const document = row.ContentDocument;
64
+ if (typeof id !== 'string' || !/^069[a-zA-Z0-9]{12}(?:[a-zA-Z0-9]{3})?$/.test(id)
65
+ || !document || typeof document !== 'object' || !('Title' in document) || !('FileExtension' in document)
66
+ || typeof document.Title !== 'string' || !document.Title
67
+ || !(document.FileExtension === null || typeof document.FileExtension === 'string')) {
68
+ throw new Error('ファイルの ID・表示名・拡張子を確認できません');
69
+ }
70
+ const file = { id, title: document.Title, extension: (document.FileExtension ?? '').toLowerCase() };
71
+ const previous = files.get(id);
72
+ if (previous && (previous.title !== file.title || previous.extension !== file.extension)) {
73
+ throw new Error(`ファイル "${id}" の情報が一致しません`);
74
+ }
75
+ files.set(id, file);
76
+ }
77
+ return [...files.values()];
78
+ }
79
+ /**
80
+ * 名前と拡張子の両方が一致する関連ファイルを取得する。
81
+ * @param recordId - 関連付け先レコードの ID。
82
+ * @param fileName - 拡張子を含む名前。
83
+ * @returns 一致する候補。0件と識別情報の取得失敗を区別する。
84
+ */
85
+ matchingFiles(recordId, fileName) {
86
+ const identity = (0, fileInputs_1.fileIdentity)(fileName);
87
+ return this.linkedFiles(recordId).filter(file => file.title === identity.title && file.extension === identity.extension);
88
+ }
89
+ /**
90
+ * 操作対象のファイルを1件に特定する。
91
+ * @param recordId - 関連付け先レコードの ID。
92
+ * @param fileName - 拡張子を含む名前。
93
+ * @returns 1件に特定したファイル。
94
+ * @throws 一致するファイルが0件または複数の場合。
95
+ */
96
+ uniqueFile(recordId, fileName) {
97
+ const files = this.matchingFiles(recordId, fileName);
98
+ if (files.length !== 1)
99
+ throw new Error(`ファイル "${fileName}" が ${files.length} 件あります(1件である必要があります)`);
100
+ return files[0];
101
+ }
102
+ }
103
+ exports.SalesforceFiles = SalesforceFiles;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * アップロードの画面エラーの記録と、未処理のエラーの確認を扱う。
3
+ * 通信・入力パス・待機の失敗を画面エラーに変換しない。
4
+ *
5
+ * @author Fluxengine.co.jp
6
+ */
7
+ import type { TestInfo } from '@playwright/test';
8
+ import type { Evidence } from '../pages/common/scrollCapture';
9
+ /**
10
+ * シナリオ単位で直前のアップロードエラーを保持する。
11
+ * 確認に成功した場合だけ処理済みにし、新しい操作で直前の結果を更新する。
12
+ */
13
+ export declare class UploadErrors {
14
+ private testInfo;
15
+ private evidence;
16
+ private message?;
17
+ private pending;
18
+ /**
19
+ * エラーの添付と画面キャプチャーの取得に使う部品を保持する。
20
+ * @param testInfo - シナリオの添付先。
21
+ * @param evidence - 画面キャプチャーの取得。
22
+ */
23
+ constructor(testInfo: Pick<TestInfo, 'attach'>, evidence: Evidence);
24
+ /**
25
+ * 新しいアップロードを始め、直前の結果を初期化する。
26
+ * @throws 前のエラーが未処理の場合。前の結果を消して続行しない。
27
+ */
28
+ begin(): void;
29
+ /**
30
+ * 画面で確認したエラーを保持し、文字と画面を添付する。
31
+ * @param message - 画面で確認したエラーメッセージ。空文字列は受け付けない。
32
+ * @returns 添付と画面キャプチャーの取得が終わった時点で解決する。
33
+ * @throws メッセージが空、前のエラーが未処理、添付が失敗した場合。
34
+ */
35
+ record(message: string): Promise<void>;
36
+ /**
37
+ * 直前のエラーを確認し、期待に合った場合だけ処理済みにする。
38
+ * @param expected - 含まれることを期待する文字列。省略時はメッセージを問わない。
39
+ * @throws エラーがない、期待文字列が空、メッセージが一致しない場合。
40
+ */
41
+ expectError(expected?: string): void;
42
+ /**
43
+ * 直前のアップロードの画面エラーを確認し、期待と異なる場合は不一致の説明を返す(20261013-002。標準の検査のステップ用。仕様書 4.3)。
44
+ *
45
+ * 実際の画面エラーがあれば、文言が一致しなくても、照合した時点で処理済みにする(実際のエラーを確認したことと、不一致の両方を残す)。
46
+ * エラーがなかった場合(正常にアップロードできた場合)も、不一致の説明を返す(取消・再送はしない)。
47
+ *
48
+ * @param expected - 期待するエラーの文字(部分一致)。省略時は、エラーになったことだけを確認する。
49
+ * @returns 期待どおりなら undefined。期待と異なる場合は不一致の説明。
50
+ * @throws 期待するエラーの文字が空の場合(記述の誤り)。
51
+ */
52
+ errorMismatch(expected?: string): string | undefined;
53
+ /**
54
+ * 次のステップへ進んでよいかを判定する。
55
+ * @param stepTitle - キーワードを除いたステップの文言。
56
+ * @returns 未処理のエラーで続行できない場合の理由。それ以外は undefined。
57
+ */
58
+ checkBeforeStep(stepTitle: string): string | undefined;
59
+ /** シナリオ終了時に残った未処理のエラーの理由。 */
60
+ remainingProblem(): string | undefined;
61
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UploadErrors = void 0;
4
+ /** アップロードエラーを確認するステップの文言。組み込み時に定義と一致させる。 */
5
+ const ERROR_STEP = /^アップロードエラー(になる| ".*" が表示される)$/;
6
+ /**
7
+ * シナリオ単位で直前のアップロードエラーを保持する。
8
+ * 確認に成功した場合だけ処理済みにし、新しい操作で直前の結果を更新する。
9
+ */
10
+ class UploadErrors {
11
+ testInfo;
12
+ evidence;
13
+ message;
14
+ pending = false;
15
+ /**
16
+ * エラーの添付と画面キャプチャーの取得に使う部品を保持する。
17
+ * @param testInfo - シナリオの添付先。
18
+ * @param evidence - 画面キャプチャーの取得。
19
+ */
20
+ constructor(testInfo, evidence) {
21
+ this.testInfo = testInfo;
22
+ this.evidence = evidence;
23
+ }
24
+ /**
25
+ * 新しいアップロードを始め、直前の結果を初期化する。
26
+ * @throws 前のエラーが未処理の場合。前の結果を消して続行しない。
27
+ */
28
+ begin() {
29
+ if (this.pending)
30
+ throw new Error(`アップロードエラーが未処理です: ${this.message}`);
31
+ this.message = undefined;
32
+ }
33
+ /**
34
+ * 画面で確認したエラーを保持し、文字と画面を添付する。
35
+ * @param message - 画面で確認したエラーメッセージ。空文字列は受け付けない。
36
+ * @returns 添付と画面キャプチャーの取得が終わった時点で解決する。
37
+ * @throws メッセージが空、前のエラーが未処理、添付が失敗した場合。
38
+ */
39
+ async record(message) {
40
+ if (!message.trim())
41
+ throw new Error('アップロードエラーのメッセージが空です');
42
+ if (this.pending)
43
+ throw new Error('前のアップロードエラーが未処理です');
44
+ this.message = message;
45
+ this.pending = true;
46
+ await this.testInfo.attach('アップロードエラー', { body: message, contentType: 'text/plain' });
47
+ await this.evidence('アップロードエラー_画面');
48
+ }
49
+ /**
50
+ * 直前のエラーを確認し、期待に合った場合だけ処理済みにする。
51
+ * @param expected - 含まれることを期待する文字列。省略時はメッセージを問わない。
52
+ * @throws エラーがない、期待文字列が空、メッセージが一致しない場合。
53
+ */
54
+ expectError(expected) {
55
+ if (expected !== undefined && !expected.trim())
56
+ throw new Error('期待するアップロードエラーが空です');
57
+ if (this.message === undefined)
58
+ throw new Error('直前のアップロードはエラーになっていません');
59
+ if (expected !== undefined && !this.message.includes(expected)) {
60
+ throw new Error(`アップロードエラーが一致しません(期待: "${expected}"、実際: "${this.message}")`);
61
+ }
62
+ this.pending = false;
63
+ }
64
+ /**
65
+ * 直前のアップロードの画面エラーを確認し、期待と異なる場合は不一致の説明を返す(20261013-002。標準の検査のステップ用。仕様書 4.3)。
66
+ *
67
+ * 実際の画面エラーがあれば、文言が一致しなくても、照合した時点で処理済みにする(実際のエラーを確認したことと、不一致の両方を残す)。
68
+ * エラーがなかった場合(正常にアップロードできた場合)も、不一致の説明を返す(取消・再送はしない)。
69
+ *
70
+ * @param expected - 期待するエラーの文字(部分一致)。省略時は、エラーになったことだけを確認する。
71
+ * @returns 期待どおりなら undefined。期待と異なる場合は不一致の説明。
72
+ * @throws 期待するエラーの文字が空の場合(記述の誤り)。
73
+ */
74
+ errorMismatch(expected) {
75
+ if (expected !== undefined && !expected.trim())
76
+ throw new Error('期待するアップロードエラーが空です');
77
+ if (this.message === undefined)
78
+ return '直前のアップロードはエラーになっていません';
79
+ this.pending = false;
80
+ if (expected !== undefined && !this.message.includes(expected)) {
81
+ return `アップロードエラーが一致しません(期待: "${expected}"、実際: "${this.message}")`;
82
+ }
83
+ return undefined;
84
+ }
85
+ /**
86
+ * 次のステップへ進んでよいかを判定する。
87
+ * @param stepTitle - キーワードを除いたステップの文言。
88
+ * @returns 未処理のエラーで続行できない場合の理由。それ以外は undefined。
89
+ */
90
+ checkBeforeStep(stepTitle) {
91
+ if (!this.pending || /^ID ".*"$/.test(stepTitle) || ERROR_STEP.test(stepTitle))
92
+ return undefined;
93
+ return this.remainingProblem();
94
+ }
95
+ /** シナリオ終了時に残った未処理のエラーの理由。 */
96
+ remainingProblem() {
97
+ return this.pending ? `アップロードエラーを確認しないままです: ${this.message}` : undefined;
98
+ }
99
+ }
100
+ exports.UploadErrors = UploadErrors;
@@ -0,0 +1,25 @@
1
+ /** Salesforce のタイトルと拡張子で照合する名前。拡張子には先頭のピリオドを含めない。 */
2
+ export type FileIdentity = {
3
+ title: string;
4
+ extension: string;
5
+ };
6
+ /**
7
+ * プロジェクトを基準に、読み取り可能な通常のファイルを特定する。
8
+ *
9
+ * @param inputPath - 相対パスまたはフルパス。前後の空白はファイル名として保持する。
10
+ * @param projectDir - コマンドを実行するプロジェクトのフォルダ。
11
+ * @returns 入力ファイルを読み取れることを確認した絶対パス。
12
+ * @throws パスが空、ファイルがない、通常のファイルでない、読み取れない場合。
13
+ */
14
+ export declare function readableFile(inputPath: string, projectDir?: string): Promise<string>;
15
+ /**
16
+ * 拡張子を含むファイル名を、表示名と拡張子に分ける。
17
+ *
18
+ * 最後のピリオドを拡張子の境界とする。拡張子のない名前も扱う。
19
+ * タイトルは大文字・小文字を保持し、拡張子は Salesforce の表記差を照合するため小文字にする。
20
+ *
21
+ * @param fileName - パスを含まないファイル名。
22
+ * @returns 表示名と拡張子。
23
+ * @throws 空の名前、パス、Windows で使用できない名前の場合。
24
+ */
25
+ export declare function fileIdentity(fileName: string): FileIdentity;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readableFile = readableFile;
7
+ exports.fileIdentity = fileIdentity;
8
+ /**
9
+ * ファイル操作の入力パスと、表示名・拡張子の組み合わせを扱う。
10
+ *
11
+ * @author Fluxengine.co.jp
12
+ */
13
+ const promises_1 = require("node:fs/promises");
14
+ const node_fs_1 = require("node:fs");
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ /**
17
+ * プロジェクトを基準に、読み取り可能な通常のファイルを特定する。
18
+ *
19
+ * @param inputPath - 相対パスまたはフルパス。前後の空白はファイル名として保持する。
20
+ * @param projectDir - コマンドを実行するプロジェクトのフォルダ。
21
+ * @returns 入力ファイルを読み取れることを確認した絶対パス。
22
+ * @throws パスが空、ファイルがない、通常のファイルでない、読み取れない場合。
23
+ */
24
+ async function readableFile(inputPath, projectDir = process.cwd()) {
25
+ if (!inputPath || inputPath.includes('\0'))
26
+ throw new Error('入力ファイルのパスが空、または不正です');
27
+ const absolute = node_path_1.default.resolve(projectDir, inputPath);
28
+ try {
29
+ if (!(await (0, promises_1.stat)(absolute)).isFile())
30
+ throw new Error('通常のファイルではありません');
31
+ await (0, promises_1.access)(absolute, node_fs_1.constants.R_OK);
32
+ }
33
+ catch (error) {
34
+ const reason = error instanceof Error ? error.message : String(error);
35
+ throw new Error(`入力ファイル "${inputPath}" を読み取れません: ${reason}`);
36
+ }
37
+ return absolute;
38
+ }
39
+ /**
40
+ * 拡張子を含むファイル名を、表示名と拡張子に分ける。
41
+ *
42
+ * 最後のピリオドを拡張子の境界とする。拡張子のない名前も扱う。
43
+ * タイトルは大文字・小文字を保持し、拡張子は Salesforce の表記差を照合するため小文字にする。
44
+ *
45
+ * @param fileName - パスを含まないファイル名。
46
+ * @returns 表示名と拡張子。
47
+ * @throws 空の名前、パス、Windows で使用できない名前の場合。
48
+ */
49
+ function fileIdentity(fileName) {
50
+ if (!fileName || /[\\/:*?"<>|\x00-\x1f]/.test(fileName) || /[. ]$/.test(fileName)) {
51
+ throw new Error(`ファイル名 "${fileName}" はパスを含まない名前で指定してください`);
52
+ }
53
+ const dot = fileName.lastIndexOf('.');
54
+ return dot > 0
55
+ ? { title: fileName.slice(0, dot), extension: fileName.slice(dot + 1).toLowerCase() }
56
+ : { title: fileName, extension: '' };
57
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 標準のファイル選択操作に対応する保存応答から、作成されたバージョンを取り出す。
3
+ * 応答の本文・認証情報は保存せず、同じリクエスト内のアクションIDで照合する。
4
+ *
5
+ * @author Fluxengine.co.jp
6
+ */
7
+ /** 今回の保存応答が返したファイルとバージョンのID。 */
8
+ export type FileUploadReceipt = {
9
+ documentId: string;
10
+ versionId: string;
11
+ };
12
+ /**
13
+ * 保存リクエストのアクションIDを取得する。
14
+ * @param postData - Auraリクエストのフォーム本文。
15
+ * @returns 保存アクションのID。該当しない通信では空配列。
16
+ * @throws 保存アクションのIDが不正な場合。
17
+ */
18
+ export declare function uploadActionIds(postData: string | null): string[];
19
+ /**
20
+ * 対応する保存アクションの成功応答を取得する。
21
+ * @param body - Aura応答の本文。
22
+ * @param actionIds - 今回のリクエストの保存アクションID。
23
+ * @returns 成功した保存のID。画面で確認する保存エラーでは空配列。
24
+ * @throws 応答の構造または成功応答のIDが不正な場合。
25
+ */
26
+ export declare function uploadReceipts(body: string, actionIds: readonly string[]): FileUploadReceipt[];
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadActionIds = uploadActionIds;
4
+ exports.uploadReceipts = uploadReceipts;
5
+ /** 標準のファイルアップロードが使用する保存アクション。 */
6
+ const SAVE_ACTION = 'serviceComponent://ui.chatter.components.aura.components.forceChatter.chatter.PublisherFileAttachmentController/ACTION$saveContentVersion';
7
+ /** 外部JSONのオブジェクトかを確認する。 */
8
+ function isObject(value) {
9
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
10
+ }
11
+ /**
12
+ * 保存リクエストのアクションIDを取得する。
13
+ * @param postData - Auraリクエストのフォーム本文。
14
+ * @returns 保存アクションのID。該当しない通信では空配列。
15
+ * @throws 保存アクションのIDが不正な場合。
16
+ */
17
+ function uploadActionIds(postData) {
18
+ const message = new URLSearchParams(postData ?? '').get('message');
19
+ if (!message)
20
+ return [];
21
+ const request = JSON.parse(message);
22
+ if (!isObject(request) || !Array.isArray(request.actions))
23
+ return [];
24
+ return request.actions.flatMap((action) => {
25
+ if (!isObject(action) || action.descriptor !== SAVE_ACTION)
26
+ return [];
27
+ if (typeof action.id !== 'string' || !action.id)
28
+ throw new Error('ファイル保存アクションのIDを取得できません');
29
+ return [action.id];
30
+ });
31
+ }
32
+ /**
33
+ * 対応する保存アクションの成功応答を取得する。
34
+ * @param body - Aura応答の本文。
35
+ * @param actionIds - 今回のリクエストの保存アクションID。
36
+ * @returns 成功した保存のID。画面で確認する保存エラーでは空配列。
37
+ * @throws 応答の構造または成功応答のIDが不正な場合。
38
+ */
39
+ function uploadReceipts(body, actionIds) {
40
+ const response = JSON.parse(body.replace(/^while\(1\);?/, ''));
41
+ if (!isObject(response) || !Array.isArray(response.actions))
42
+ throw new Error('ファイル保存の応答を取得できません');
43
+ const actions = response.actions;
44
+ return actionIds.flatMap(id => {
45
+ const matches = actions.filter((action) => isObject(action) && action.id === id);
46
+ if (matches.length !== 1 || !isObject(matches[0]))
47
+ throw new Error('ファイル保存の応答を特定できません');
48
+ const action = matches[0];
49
+ if (action.state === 'ERROR')
50
+ return [];
51
+ const value = action.returnValue;
52
+ if (action.state !== 'SUCCESS' || !isObject(value)
53
+ || typeof value.docid !== 'string' || !/^069[a-zA-Z0-9]{12}(?:[a-zA-Z0-9]{3})?$/.test(value.docid)
54
+ || typeof value.versionId !== 'string' || !/^068[a-zA-Z0-9]{12}(?:[a-zA-Z0-9]{3})?$/.test(value.versionId)) {
55
+ throw new Error('保存されたファイルとバージョンのIDを確認できません');
56
+ }
57
+ return [{ documentId: value.docid, versionId: value.versionId }];
58
+ });
59
+ }