@slicemachine/init 1.1.9 → 1.1.10-alpha.11

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.
@@ -0,0 +1,75 @@
1
+ import { Component, Manifest, Slices } from "@slicemachine/core/build/models";
2
+ import { Acl, ClientError } from "@slicemachine/client";
3
+ import { InitClient, logs } from "../../utils";
4
+ import * as Libraries from "@slicemachine/core/build/libraries";
5
+ import { promptToPushSlices } from "./prompts";
6
+ import { updateSlicesWithScreenshots } from "./s3";
7
+ import { writeError } from "../../utils/logs";
8
+
9
+ export async function sendSlices(
10
+ client: InitClient,
11
+ cwd: string,
12
+ manifest: Manifest
13
+ ): Promise<boolean> {
14
+ if (!manifest.libraries) return Promise.resolve(false); // No libraries defined
15
+
16
+ const libraries = Libraries.libraries(cwd, manifest.libraries);
17
+ const components = libraries.reduce<Array<Component>>((acc, lib) => {
18
+ return [...acc, ...lib.components];
19
+ }, []);
20
+
21
+ if (components.length === 0) return Promise.resolve(false); // No slices to send found in the libraries
22
+
23
+ const remoteSlicesIds: string[] = await client
24
+ .getSlices()
25
+ .then((slices) => slices.map((slice) => slice.id));
26
+
27
+ // If the repository already has Slices, ask the user to confirm.
28
+ if (remoteSlicesIds.length) {
29
+ const pushAnyway = await promptToPushSlices();
30
+ if (pushAnyway === false) return Promise.resolve(true);
31
+ }
32
+
33
+ const spinner = logs.spinner(
34
+ "Pushing existing Slice models to your repository"
35
+ );
36
+ spinner.start();
37
+
38
+ const acl: Acl | null = await client
39
+ .createAcl()
40
+ .catch((error: ClientError) => {
41
+ writeError(
42
+ "Uploading screenshots for your slices failed, please contact us."
43
+ );
44
+ writeError(error.message, "Full error:");
45
+ return null;
46
+ });
47
+
48
+ // If the acl failed to be created, don't mind the screenshots.
49
+ const models = acl
50
+ ? await updateSlicesWithScreenshots(client, acl, components)
51
+ : components.map((component) => component.model);
52
+
53
+ await Promise.all(
54
+ models.map(async (model) => {
55
+ const slice = Slices.fromSM(model);
56
+
57
+ const promise = remoteSlicesIds.includes(slice.id)
58
+ ? client.updateSlice(slice)
59
+ : client.insertSlice(slice);
60
+
61
+ return promise.catch((error: ClientError) => {
62
+ logs.writeError(`Sending slice ${model.id} - ${error.message}`);
63
+
64
+ // throwing the error again to stop the Promise.all
65
+ throw error;
66
+ });
67
+ })
68
+ ).catch(() => {
69
+ // the error about the slice that failed to be pushed should be in the terminal already.
70
+ process.exit(1);
71
+ });
72
+
73
+ spinner.succeed();
74
+ return Promise.resolve(true);
75
+ }
@@ -81,13 +81,17 @@ const authenticationHandler =
81
81
  };
82
82
  };
83
83
 
84
+ function stripTrailingSlash(str: string) {
85
+ return str.endsWith("/") ? str.slice(0, -1) : str;
86
+ }
87
+
84
88
  function buildServer(base: string, port: number, host: string): hapi.Server {
85
89
  const server = hapi.server({
86
90
  port,
87
91
  host,
88
92
  routes: {
89
93
  cors: {
90
- origin: [base],
94
+ origin: [stripTrailingSlash(base)],
91
95
  headers: ["Origin", "X-Requested-With", "Content-Type", "Accept"],
92
96
  },
93
97
  },
@@ -1,26 +1,30 @@
1
- import { Utils, Models } from "@slicemachine/core";
1
+ import { Utils } from "@slicemachine/core";
2
2
  import { startServerAndOpenBrowser } from "./helpers";
3
3
  import {
4
- Communication,
5
4
  Endpoints,
6
5
  PrismicSharedConfigManager,
7
6
  } from "@slicemachine/core/build/prismic";
7
+ import { InitClient } from "../client";
8
8
 
9
9
  async function startAuth({
10
- base,
10
+ client,
11
11
  url,
12
12
  action,
13
13
  }: {
14
- base: string;
14
+ client: InitClient;
15
15
  url: string;
16
16
  action: "signup" | "login";
17
17
  }): Promise<void> {
18
- const { onLoginFail } = await startServerAndOpenBrowser(url, action, base);
18
+ const { onLoginFail } = await startServerAndOpenBrowser(
19
+ url,
20
+ action,
21
+ client.apisEndpoints.Wroom
22
+ );
19
23
  try {
20
24
  // We wait 3 minutes before timeout
21
- await Utils.Poll.startPolling<Models.UserInfo | null, Models.UserInfo>(
22
- () => Auth.validateSession(base),
23
- (user): user is Models.UserInfo => !!user,
25
+ await Utils.Poll.startPolling<boolean, boolean>(
26
+ () => Auth.validateSession(client),
27
+ (isSessionValid): isSessionValid is boolean => isSessionValid == true,
24
28
  3000,
25
29
  60
26
30
  );
@@ -31,33 +35,29 @@ async function startAuth({
31
35
  }
32
36
 
33
37
  export const Auth = {
34
- login: async (base: string): Promise<void> => {
35
- const endpoints = Endpoints.buildEndpoints(base);
38
+ login: async (client: InitClient): Promise<void> => {
39
+ const endpoints = Endpoints.buildEndpoints(client.apisEndpoints.Wroom);
36
40
  return startAuth({
37
- base,
41
+ client,
38
42
  url: endpoints.Dashboard.cliLogin,
39
43
  action: "login",
40
44
  });
41
45
  },
42
- signup: async (base: string): Promise<void> => {
43
- const endpoints = Endpoints.buildEndpoints(base);
44
- return startAuth({
45
- base,
46
- url: endpoints.Dashboard.cliSignup,
47
- action: "signup",
48
- });
49
- },
50
- logout: (): void => PrismicSharedConfigManager.remove(),
51
- validateSession: async (
52
- requiredBase: string
53
- ): Promise<Models.UserInfo | null> => {
54
- const config = PrismicSharedConfigManager.get();
46
+ validateSession: async (client: InitClient): Promise<boolean> => {
47
+ const authToken = PrismicSharedConfigManager.getAuth();
55
48
 
56
- if (!config.cookies.length) return Promise.resolve(null); // default config, logged out.
57
- if (requiredBase != config.base) return Promise.resolve(null); // not the same base so it doesn't count.
58
-
59
- return Communication.validateSession(config.cookies, requiredBase).catch(
60
- () => null
61
- );
49
+ // verify token is by retrieving the profile, update the config if need be.
50
+ return client
51
+ .updateAuthenticationToken(authToken)
52
+ .profile()
53
+ .then((userProfile) => {
54
+ // settings shortId and IntercomHash as we switch between dev and prod.
55
+ PrismicSharedConfigManager.setProperties({
56
+ shortId: userProfile.shortId,
57
+ intercomHash: userProfile.intercomHash,
58
+ });
59
+ return true;
60
+ })
61
+ .catch(() => false);
62
62
  },
63
63
  };
@@ -0,0 +1,67 @@
1
+ import * as t from "io-ts";
2
+ import { Models } from "@slicemachine/core";
3
+ import { PrismicSharedConfigManager } from "@slicemachine/core/build/prismic";
4
+ import { Client, getAndValidateResponse } from "@slicemachine/client";
5
+
6
+ export class InitClient extends Client {
7
+ async listRepositories(): Promise<Models.Repository[]> {
8
+ return getAndValidateResponse<Models.Repository[]>(
9
+ this._get(`${this.apisEndpoints.Users}repositories`),
10
+ "repository list",
11
+ t.array(Models.Repository)
12
+ );
13
+ }
14
+
15
+ async createRepository(
16
+ domain: string,
17
+ framework: Models.Frameworks
18
+ ): Promise<string> {
19
+ const data = {
20
+ domain,
21
+ framework,
22
+ plan: "personal",
23
+ isAnnual: "false",
24
+ role: "developer",
25
+ };
26
+
27
+ return this._fetch({
28
+ method: "post",
29
+ url: `${this.apisEndpoints.Wroom}authentication/newrepository?app=slicemachine`,
30
+ data: data,
31
+ headers: {
32
+ Cookie: PrismicSharedConfigManager.get().cookies,
33
+ "User-Agent": "prismic-cli/sm", // special user agent just for this route.
34
+ },
35
+ }).then(() => domain);
36
+ }
37
+
38
+ async domainExist(domain: string): Promise<boolean> {
39
+ return getAndValidateResponse<boolean>(
40
+ this._get(
41
+ `${this.apisEndpoints.Wroom}app/dashboard/repositories/${domain}/exists`
42
+ ),
43
+ "repository exists",
44
+ t.boolean
45
+ );
46
+ }
47
+
48
+ async pushDocuments(
49
+ signature: string,
50
+ documents: Record<string, unknown>,
51
+ cookies: string
52
+ ) {
53
+ if (!this.repository) throw new Error("Repository undefined in the client");
54
+ const repositoryDirectUrl = new URL(this.apisEndpoints.Wroom);
55
+ repositoryDirectUrl.hostname = `${this.repository}.${repositoryDirectUrl.hostname}`;
56
+
57
+ return this._fetch({
58
+ method: "post",
59
+ url: `${repositoryDirectUrl.toString()}starter/documents`,
60
+ data: { signature, documents: JSON.stringify(documents) },
61
+ headers: {
62
+ Cookie: cookies,
63
+ "User-Agent": "prismic-cli/0", // special user agent just for this route.
64
+ },
65
+ });
66
+ }
67
+ }
@@ -1,30 +1,24 @@
1
1
  import type { Models } from "@slicemachine/core";
2
2
  import * as logs from "./logs";
3
- import * as Prismic from "@slicemachine/core/build/prismic";
3
+ import { InitClient } from "./client";
4
4
 
5
5
  export function createRepository(
6
+ client: InitClient,
6
7
  domain: string,
7
- framework: Models.Frameworks,
8
- cookies: string,
9
- base: string
8
+ framework: Models.Frameworks
10
9
  ): Promise<string> {
11
10
  const spinner = logs.spinner("Creating Prismic Repository");
12
11
  spinner.start();
13
12
 
14
- return Prismic.Communication.createRepository(
15
- domain,
16
- cookies,
17
- framework,
18
- base
19
- )
20
- .then((res) => {
21
- const addressUrl = new URL(base);
22
- const repoDomainName = res.data.domain || domain;
23
- addressUrl.hostname = `${repoDomainName}.${addressUrl.hostname}`;
13
+ return client
14
+ .createRepository(domain, framework)
15
+ .then((domain: string) => {
16
+ const addressUrl = new URL(client.apisEndpoints.Wroom);
17
+ addressUrl.hostname = `${domain}.${addressUrl.hostname}`;
24
18
  const address = addressUrl.toString();
25
19
  spinner.succeed(`We created your new repository ${address}`);
26
20
 
27
- return repoDomainName;
21
+ return domain;
28
22
  })
29
23
  .catch((error: Error) => {
30
24
  spinner.fail(`Error creating repository ${domain}`);
@@ -0,0 +1,18 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export async function lsdir(dir: string): Promise<Array<string>> {
5
+ return fs.promises.readdir(dir).then((dirs) => {
6
+ return dirs
7
+ .filter((name) => fs.statSync(path.join(dir, name)).isDirectory())
8
+ .map((subdirectory) => path.join(dir, subdirectory));
9
+ });
10
+ }
11
+
12
+ export async function lsfiles(dir: string): Promise<Array<string>> {
13
+ return fs.promises.readdir(dir).then((dirs) => {
14
+ return dirs
15
+ .filter((name) => fs.statSync(path.join(dir, name)).isFile())
16
+ .map((file) => path.join(dir, file));
17
+ });
18
+ }
@@ -1,7 +1,10 @@
1
+ import { ApplicationMode } from "@slicemachine/client";
1
2
  import util from "util";
2
3
  import { exec } from "child_process";
3
4
  export * as logs from "./logs";
4
5
  export { Auth } from "./auth";
6
+ export * from "./client";
7
+ export * from "./fs";
5
8
 
6
9
  export function findArgument(args: string[], name: string): string | undefined {
7
10
  const flagIndex: number = args.indexOf(`--${name}`);
@@ -15,6 +18,24 @@ export function findArgument(args: string[], name: string): string | undefined {
15
18
  return flagValue;
16
19
  }
17
20
 
21
+ export function findFlag(args: string[], name: string): boolean {
22
+ const toFind = `--${name}`;
23
+ return args.includes(toFind);
24
+ }
25
+
18
26
  export const execCommand: (
19
27
  command: string
20
28
  ) => Promise<{ stderr: string; stdout: string }> = util.promisify(exec);
29
+
30
+ export function getApplicationMode(
31
+ argumentValue: string | undefined
32
+ ): ApplicationMode | null {
33
+ switch (argumentValue) {
34
+ case ApplicationMode.PROD:
35
+ case ApplicationMode.STAGE:
36
+ case ApplicationMode.DEV:
37
+ return argumentValue;
38
+ default:
39
+ return null;
40
+ }
41
+ }
@@ -0,0 +1,44 @@
1
+ import { InitClient } from "./client";
2
+
3
+ export async function validateRepositoryName(
4
+ client: InitClient,
5
+ name: string
6
+ ): Promise<boolean> {
7
+ const domain = name.trim();
8
+ const errors = [];
9
+
10
+ const startsWithLetter = /^[a-zA-Z]/.test(domain);
11
+ if (!startsWithLetter) errors.push("Must start with a letter.");
12
+
13
+ const acceptedChars = /^[a-z0-9-]+$/.test(domain);
14
+ if (!acceptedChars)
15
+ errors.push("Must contain only lowercase letters, numbers and hyphens.");
16
+
17
+ const fourCharactersOrMore = domain.length >= 4;
18
+ if (!fourCharactersOrMore)
19
+ errors.push(
20
+ "Must have four or more alphanumeric characters and/or hyphens."
21
+ );
22
+
23
+ const endsWithALetterOrNumber = /[a-z0-9]$/.test(domain);
24
+ if (!endsWithALetterOrNumber)
25
+ errors.push("Must end in a letter or a number.");
26
+
27
+ const thirtyCharacterOrLess = domain.length <= 30;
28
+ if (!thirtyCharacterOrLess) errors.push("Must be 30 characters or less");
29
+
30
+ if (errors.length > 0) {
31
+ const errorString = errors.map((d, i) => `(${i + 1}: ${d}`).join(" ");
32
+ const msg = `Validation errors: ${errorString}`;
33
+ return Promise.reject(new Error(msg));
34
+ }
35
+
36
+ return client
37
+ .domainExist(domain)
38
+ .then((isAvailable) =>
39
+ isAvailable
40
+ ? true
41
+ : Promise.reject(new Error(`${name} is already in use`))
42
+ )
43
+ .catch(() => Promise.reject(new Error(`${name} is already in use`)));
44
+ }
package/.caches/eslint DELETED
@@ -1 +0,0 @@
1
- [{"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/check.test.ts":"1","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/choose-or-create-repo.test.ts":"2","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/configure-project.test.ts":"3","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/create-repo-sm-core.test.ts":"4","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/detect-framework.test.ts":"5","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/install-lib.test.ts":"6","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/install-required-dependencies.test.ts":"7","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/logInOrBypass.test.ts":"8","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/auth.test.ts":"9","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/communication.test.ts":"10","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/create-repo.test.ts":"11","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/index.test.ts":"12","/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/tracker.test.ts":"13","/Users/marc/Projects/prismic/slice-machine/packages/init/src/index.ts":"14","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/choose-or-create-a-repository.ts":"15","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/configure-project.ts":"16","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/detect-framework.ts":"17","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/display-final-message.ts":"18","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/index.ts":"19","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/install-lib.ts":"20","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/install-required-dependencies.ts":"21","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/loginOrBypass.ts":"22","/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/validate-pkg.ts":"23","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/PackageManager.ts":"24","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/auth/helpers.ts":"25","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/auth/index.ts":"26","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/communication.ts":"27","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/create-repo.ts":"28","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/index.ts":"29","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/logs.ts":"30","/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/tracker.ts":"31"},{"hash":"32","results":"33","hashOfConfig":"34"},{"hash":"35","results":"36","hashOfConfig":"34"},{"hash":"37","results":"38","hashOfConfig":"34"},{"hash":"39","results":"40","hashOfConfig":"34"},{"hash":"41","results":"42","hashOfConfig":"34"},{"hash":"43","results":"44","hashOfConfig":"34"},{"hash":"45","results":"46","hashOfConfig":"34"},{"hash":"47","results":"48","hashOfConfig":"34"},{"hash":"49","results":"50","hashOfConfig":"34"},{"hash":"51","results":"52","hashOfConfig":"34"},{"hash":"53","results":"54","hashOfConfig":"34"},{"hash":"55","results":"56","hashOfConfig":"34"},{"hash":"57","results":"58","hashOfConfig":"34"},{"hash":"59","results":"60","hashOfConfig":"34"},{"hash":"61","results":"62","hashOfConfig":"34"},{"hash":"63","results":"64","hashOfConfig":"34"},{"hash":"65","results":"66","hashOfConfig":"34"},{"hash":"67","results":"68","hashOfConfig":"34"},{"hash":"69","results":"70","hashOfConfig":"34"},{"hash":"71","results":"72","hashOfConfig":"34"},{"hash":"73","results":"74","hashOfConfig":"34"},{"hash":"75","results":"76","hashOfConfig":"34"},{"hash":"77","results":"78","hashOfConfig":"34"},{"hash":"79","results":"80","hashOfConfig":"34"},{"hash":"81","results":"82","hashOfConfig":"34"},{"hash":"83","results":"84","hashOfConfig":"34"},{"hash":"85","results":"86","hashOfConfig":"34"},{"hash":"87","results":"88","hashOfConfig":"34"},{"hash":"89","results":"90","hashOfConfig":"34"},{"hash":"91","results":"92","hashOfConfig":"34"},{"hash":"93","results":"94","hashOfConfig":"34"},"77d8e3cce94d2db592b4a96c6d6cde76",{"filePath":"95","messages":"96","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1b7mvzj","961df16402003e17b627b5bd56efd69b",{"filePath":"97","messages":"98","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"b732a4122a7b882e82b98e3a2d52016d",{"filePath":"99","messages":"100","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"95f2472186d8811318d0b9aacdb04bfd",{"filePath":"101","messages":"102","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"e8ba1dde300d0f874c7dd1f60967080d",{"filePath":"103","messages":"104","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"66455b7da51f68df8e1d4306625fff64",{"filePath":"105","messages":"106","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"d198806102439bff4802153a74d3129b",{"filePath":"107","messages":"108","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"3439b285eeacc711dad9073d4ffac791",{"filePath":"109","messages":"110","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"715c60b8f5adf74923dbaceeeca7f7a1",{"filePath":"111","messages":"112","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"c61c12d13a5cd2fae48ca10963e88003",{"filePath":"113","messages":"114","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"22a606271ed98ca3addcf414e9a63c4d",{"filePath":"115","messages":"116","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"a2c73ddeaeac2340d84a65c635b7f6a4",{"filePath":"117","messages":"118","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"52a27bf060c4a76ad1201b853a0f2e91",{"filePath":"119","messages":"120","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"cfb9f9de80597d5d6678f1a79447d9b1",{"filePath":"121","messages":"122","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"b4a15d6a2d6516368a5c8f17cb9d28a9",{"filePath":"123","messages":"124","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"e5d8b2db316dd5b448154dddcc81ad40",{"filePath":"125","messages":"126","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"9828c95696fee562dd2f44015a8719aa",{"filePath":"127","messages":"128","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"42b59dab9067a0761f37385b5d18bcb9",{"filePath":"129","messages":"130","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"05531ba7533214a64ce92ab2430b5f96",{"filePath":"131","messages":"132","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"cf9081f34e2511376279cb263a6c3ebc",{"filePath":"133","messages":"134","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"7525cb9408294b05290d26abe1c95150",{"filePath":"135","messages":"136","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"31a96d957c9a5ac6173c699b41665933",{"filePath":"137","messages":"138","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"372e43153e227c33eaa7c6a9dc7b3827",{"filePath":"139","messages":"140","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"b8ac4c7fbde61fc55938af62b0bfa022",{"filePath":"141","messages":"142","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"f29fbe3d7e82c9539d1e1fb574315015",{"filePath":"143","messages":"144","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"0c3566a914d83fc46cb3ffb8f8e88ea6",{"filePath":"145","messages":"146","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"4d15a5af3c4942486308237d8e8f5d57",{"filePath":"147","messages":"148","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"cac6e2abb9b0e4d3ee0a7d8df12af250",{"filePath":"149","messages":"150","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"17f371201bc5b9b38b58f342d75f4f56",{"filePath":"151","messages":"152","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"3c1b68b0f61533d4a36176930478849b",{"filePath":"153","messages":"154","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"7db4902e037b6febf41feb40bf2099a6",{"filePath":"155","messages":"156","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/check.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/choose-or-create-repo.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/configure-project.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/create-repo-sm-core.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/detect-framework.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/install-lib.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/install-required-dependencies.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/logInOrBypass.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/auth.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/communication.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/create-repo.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/index.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/__tests__/utils/tracker.test.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/index.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/choose-or-create-a-repository.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/configure-project.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/detect-framework.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/display-final-message.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/index.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/install-lib.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/install-required-dependencies.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/loginOrBypass.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/steps/validate-pkg.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/PackageManager.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/auth/helpers.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/auth/index.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/communication.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/create-repo.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/index.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/logs.ts",[],"/Users/marc/Projects/prismic/slice-machine/packages/init/src/utils/tracker.ts",[]]
@@ -1,72 +0,0 @@
1
- import axios from "axios";
2
- import * as t from "io-ts";
3
- import { pipe } from "fp-ts/function";
4
- import { fold } from "fp-ts/Either";
5
- import { Utils, Models, CONSTS } from "@slicemachine/core";
6
- import * as Prismic from "@slicemachine/core/build/prismic";
7
-
8
- export async function getUserProfile(
9
- cookies: string,
10
- base = CONSTS.DEFAULT_BASE
11
- ): Promise<Models.UserProfile> {
12
- const userServiceBase =
13
- CONSTS.DEFAULT_BASE === base
14
- ? CONSTS.USER_SERVICE_BASE
15
- : CONSTS.USER_SERVICE_STAGING_BASE;
16
-
17
- // note the auth server also provides a userId
18
- const url = new URL(userServiceBase);
19
- url.pathname = "profile";
20
-
21
- const endpoint = url.toString();
22
- const token = Utils.Cookie.parsePrismicAuthToken(cookies);
23
-
24
- return axios
25
- .get<Models.UserProfile>(endpoint, {
26
- headers: {
27
- Authorization: `Bearer ${token}`,
28
- },
29
- })
30
- .then((res) =>
31
- pipe(
32
- Models.UserProfile.decode(res.data),
33
- fold<t.Errors, Models.UserProfile, Models.UserProfile>(
34
- () => {
35
- throw new Error("Can't parse user profile");
36
- },
37
- (data: Models.UserProfile) => data
38
- )
39
- )
40
- );
41
- }
42
-
43
- export async function validateSessionAndGetProfile(
44
- base = CONSTS.DEFAULT_BASE
45
- ): Promise<{
46
- info: Models.UserInfo;
47
- profile: Models.UserProfile | null;
48
- } | null> {
49
- const config = Prismic.PrismicSharedConfigManager.get();
50
-
51
- if (!config.cookies.length) return Promise.resolve(null); // default config, logged out.
52
- if (base != config.base) return Promise.resolve(null); // not the same base so it doesn't
53
-
54
- try {
55
- const info = await Prismic.Communication.validateSession(
56
- config.cookies,
57
- base
58
- );
59
- const profile = await getUserProfile(config.cookies, base).catch(
60
- () => null
61
- );
62
- if (profile?.shortId) {
63
- Prismic.PrismicSharedConfigManager.setProperties({
64
- shortId: profile.shortId,
65
- intercomHash: profile.intercomHash,
66
- });
67
- }
68
- return { info, profile };
69
- } catch {
70
- return null;
71
- }
72
- }