npm package diff

Package: @forge/cli

Versions: 12.8.0-next.18-experimental-003d118 - 12.8.0-next.24

File: package/out/service/custom-scopes-service.js

Index: package/out/service/custom-scopes-service.js
===================================================================
--- package/out/service/custom-scopes-service.js
+++ package/out/service/custom-scopes-service.js
@@ -0,0 +1,66 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.create = void 0;
+const tslib_1 = require("tslib");
+const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
+const yaml_1 = tslib_1.__importDefault(require("yaml"));
+const custom_scopes_1 = require("../custom-scopes");
+const create = (repo) => {
+    return new DefaultService(repo);
+};
+exports.create = create;
+class DefaultService {
+    repository;
+    constructor(repository) {
+        this.repository = repository;
+    }
+    async listScopes(appId, environmentId) {
+        const result = await this.repository.load(appId, environmentId);
+        switch (result.status) {
+            case "Ok":
+                return { status: "Ok", scopes: result.scopes };
+            case "InvalidResponseError":
+                return { status: "InvalidResponseError" };
+        }
+    }
+    async createScopes(appId, environmentId, scopesFilePath) {
+        let rawFile;
+        try {
+            rawFile = fs_extra_1.default.readFileSync(scopesFilePath, 'utf8');
+        }
+        catch (e) {
+            return { status: "FileReadError", path: scopesFilePath, error: String(e) };
+        }
+        const yamlDocument = yaml_1.default.parseDocument(rawFile);
+        if (yamlDocument.errors.length > 0) {
+            const errors = yamlDocument.errors.map((e) => e.message);
+            return { status: "YAMLParseError", errors };
+        }
+        const validationResult = custom_scopes_1.validation.validate(yamlDocument.toJSON());
+        if (!validationResult.isValid) {
+            const errors = [];
+            for (const error of validationResult.errors) {
+                const { instancePath, message } = error;
+                errors.push(`${instancePath}: ${message || 'unknown validation error'}`);
+            }
+            return { status: "ValidationError", errors };
+        }
+        const scopes = Object.entries(validationResult.data.scopes).map(([name, { displayName, description }]) => ({
+            name,
+            description,
+            displayName
+        }));
+        const repositoryResult = await this.repository.store({
+            appId,
+            environmentId,
+            scopes
+        });
+        switch (repositoryResult.status) {
+            case "Ok":
+                return { status: "Ok" };
+            case "RemoteError":
+                return { status: "RemoteError", errors: repositoryResult.errors };
+        }
+    }
+}
+//# sourceMappingURL=custom-scopes-service.js.map
\ No newline at end of file