@prismicio/e2e-tests-utils 1.12.0-alpha.3 → 1.12.0-alpha.5

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.
@@ -45,12 +45,12 @@ class IntegrationFieldsClient {
45
45
  log.logHttpResponse(response);
46
46
  throw new Error(`Could not add integration field catalog ${name}`);
47
47
  }
48
- return `${this.repository}--${strings.toSnakeCase(name)}`;
48
+ return `${this.repository}--${strings.slugify(name)}`;
49
49
  }
50
50
  async createToken(catalogId) {
51
51
  const response = await this.wroomClient.post(this.repository, `app/settings/integrationfields/pushcustom/${catalogId}/token`);
52
52
  const { data: tokenData, status } = response;
53
- if (status !== 200) {
53
+ if (status !== 201) {
54
54
  log.logHttpResponse(response);
55
55
  throw new Error(`Could not create token for integration field catalog ${catalogId}`);
56
56
  }
@@ -78,19 +78,10 @@ class IntegrationFieldsClient {
78
78
  }
79
79
  async setupIntegrationFields(integrationFields) {
80
80
  for (const integrationField of integrationFields) {
81
- const catalogId = await this.addCatalog({
82
- name: integrationField.name,
83
- description: integrationField.description
84
- });
85
- await this.addDataToCatalog({
86
- catalogId,
87
- data: integrationField.data
88
- });
89
- await this.addToCustomType({
90
- catalogId,
91
- customTypeId: integrationField.customTypeId,
92
- fieldId: integrationField.fieldId
93
- });
81
+ const { name, description, customTypeId, fieldId, data } = integrationField;
82
+ const catalogId = await this.addCatalog({ name, description });
83
+ await this.addDataToCatalog({ catalogId, data });
84
+ await this.addToCustomType({ catalogId, customTypeId, fieldId });
94
85
  }
95
86
  }
96
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFields.cjs","sources":["../../../src/clients/integrationFields.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { IntegrationFieldConfig, IntegrationFieldData } from \"../types\";\n\nimport { logHttpResponse } from \"../utils/log\";\nimport { toSnakeCase } from \"../utils/strings\";\n\nimport { CustomTypesApiClient } from \"./customTypesApi\";\nimport { WroomClient } from \"./wroom\";\n\n/**\n * Client for interacting with Integration Fields routes to create integration\n * field catalogs and add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string;\n\tprivate readonly customTypesApiClient: CustomTypesApiClient;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly repository: string;\n\tprivate readonly tokens: Record<string, string> = {};\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient;\n\t\t\twroomClient: WroomClient;\n\t\t\trepository: string;\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL;\n\t\tthis.customTypesApiClient = config.customTypesApiClient;\n\t\tthis.wroomClient = config.wroomClient;\n\t\tthis.repository = config.repository;\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId));\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t});\n\n\t\treturn client;\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string;\n\t\tdescription: string;\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"Already existing integration field\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`);\n\t\t}\n\n\t\treturn `${this.repository}--${toSnakeCase(name)}`;\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<void> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t);\n\n\t\tconst { data: tokenData, status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not create token for integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\n\t\tconst token = tokenData[0];\n\t\tthis.tokens[catalogId] = token;\n\n\t\treturn token;\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string;\n\t\tdata: IntegrationFieldData[];\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId);\n\t\tconst response = await client.post(\n\t\t\t`/write/${catalogId}`,\n\t\t\tJSON.stringify(data),\n\t\t);\n\n\t\tconst { status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not add data to integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string;\n\t\tcustomTypeId: string;\n\t\tfieldId: string;\n\t}): Promise<void> {\n\t\tconst customType =\n\t\t\tawait this.customTypesApiClient.getTypeById(customTypeId);\n\n\t\tconst field = customType.json.Main[fieldId];\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Field ${fieldId} not found or is not an Integration Field`,\n\t\t\t);\n\t\t}\n\n\t\tfield.config = { ...(field.config ?? {}), catalog: catalogId };\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType]);\n\t}\n\n\tasync setupIntegrationFields(\n\t\tintegrationFields: IntegrationFieldConfig[],\n\t): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst catalogId = await this.addCatalog({\n\t\t\t\tname: integrationField.name,\n\t\t\t\tdescription: integrationField.description,\n\t\t\t});\n\t\t\tawait this.addDataToCatalog({\n\t\t\t\tcatalogId,\n\t\t\t\tdata: integrationField.data,\n\t\t\t});\n\t\t\tawait this.addToCustomType({\n\t\t\t\tcatalogId,\n\t\t\t\tcustomTypeId: integrationField.customTypeId,\n\t\t\t\tfieldId: integrationField.fieldId,\n\t\t\t});\n\t\t}\n\t}\n}\n"],"names":["logHttpResponse","toSnakeCase"],"mappings":";;;;;;;;;;;MAca,wBAAuB;AAAA,EAOnC,YACC,SACA,QAIC;AAZe;AACA;AACA;AACA;AACA,kCAAiC,CAAA;AAUjD,SAAK,UAAU;AACf,SAAK,uBAAuB,OAAO;AACnC,SAAK,cAAc,OAAO;AAC1B,SAAK,aAAa,OAAO;AAAA,EAC1B;AAAA,EAEQ,MAAM,UAAU,WAAiB;AAClC,UAAA,QAAQ,KAAK,OAAO,SAAS,KAAM,MAAM,KAAK,YAAY,SAAS;AAEnE,UAAA,SAAS,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG,KAAK,OAAO;AAAA,MACxB,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,SAAS;AAAA,QACR,cAAc;AAAA,QACd,eAAe,UAAU,KAAK;AAAA,MAC9B;AAAA,IAAA,CACD;AAEM,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,WAAW,EACxB,MACA,eAIA;AACA,UAAM,WAAW,MAAM,KAAK,YAAY,KACvC,KAAK,YACL,6CACA;AAAA,MACC,gBAAgB;AAAA,MAChB,uBAAuB;AAAA,IAAA,CACvB;AAGI,UAAA,EAAE,MAAM,OAAW,IAAA;AACzB,UAAM,UACL,WAAW,OACV,WAAW,OACV,KAAgB,SAAS,oCAAoC;AAChE,QAAI,CAAC,SAAS;AACbA,UAAA,gBAAgB,QAAQ;AACxB,YAAM,IAAI,MAAM,2CAA2C,IAAI,EA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AiB;AAAA,QACvB,aAAa,iBAAiB;AAAA,MAAA,CAC9B;AACD,YAAM,KAAK,iBAAiB;AAAA,QAC3B;AAAA,QACA,MAAM,iBAAiB;AAAA,MAAA,CACvB;AACD,YAAM,KAAK,gBAAgB;AAAA,QAC1B;AAAA,QACA,cAAc,iBAAiB;AAAA,QAC/B,SAAS,iBAAiB;AAAA,MAAA,CAC1B;AAAA,IACF;AAAA,EACD;AACA;;"}
1
+ {"version":3,"file":"integrationFields.cjs","sources":["../../../src/clients/integrationFields.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { IntegrationFieldConfig, IntegrationFieldData } from \"../types\";\n\nimport { logHttpResponse } from \"../utils/log\";\nimport { slugify } from \"../utils/strings\";\n\nimport { CustomTypesApiClient } from \"./customTypesApi\";\nimport { WroomClient } from \"./wroom\";\n\n/**\n * Client for interacting with Integration Fields routes to create integration\n * field catalogs and add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string;\n\tprivate readonly customTypesApiClient: CustomTypesApiClient;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly repository: string;\n\tprivate readonly tokens: Record<string, string> = {};\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient;\n\t\t\twroomClient: WroomClient;\n\t\t\trepository: string;\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL;\n\t\tthis.customTypesApiClient = config.customTypesApiClient;\n\t\tthis.wroomClient = config.wroomClient;\n\t\tthis.repository = config.repository;\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId));\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t});\n\n\t\treturn client;\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string;\n\t\tdescription: string;\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"Already existing integration field\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`);\n\t\t}\n\n\t\treturn `${this.repository}--${slugify(name)}`;\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t);\n\n\t\tconst { data: tokenData, status } = response;\n\t\tif (status !== 201) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not create token for integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\n\t\tconst token = tokenData[0];\n\t\tthis.tokens[catalogId] = token;\n\n\t\treturn token;\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string;\n\t\tdata: IntegrationFieldData[];\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId);\n\t\tconst response = await client.post(\n\t\t\t`/write/${catalogId}`,\n\t\t\tJSON.stringify(data),\n\t\t);\n\n\t\tconst { status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not add data to integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string;\n\t\tcustomTypeId: string;\n\t\tfieldId: string;\n\t}): Promise<void> {\n\t\tconst customType =\n\t\t\tawait this.customTypesApiClient.getTypeById(customTypeId);\n\n\t\tconst field = customType.json.Main[fieldId];\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Field ${fieldId} not found or is not an Integration Field`,\n\t\t\t);\n\t\t}\n\n\t\tfield.config = { ...(field.config ?? {}), catalog: catalogId };\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType]);\n\t}\n\n\tasync setupIntegrationFields(\n\t\tintegrationFields: IntegrationFieldConfig[],\n\t): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst { name, description, customTypeId, fieldId, data } =\n\t\t\t\tintegrationField;\n\n\t\t\tconst catalogId = await this.addCatalog({ name, description });\n\t\t\tawait this.addDataToCatalog({ catalogId, data });\n\t\t\tawait this.addToCustomType({ catalogId, customTypeId, fieldId });\n\t\t}\n\t}\n}\n"],"names":["logHttpResponse","slugify"],"mappings":";;;;;;;;;;;MAca,wBAAuB;AAAA,EAOnC,YACC,SACA,QAIC;AAZe;AACA;AACA;AACA;AACA,kCAAiC,CAAA;AAUjD,SAAK,UAAU;AACf,SAAK,uBAAuB,OAAO;AACnC,SAAK,cAAc,OAAO;AAC1B,SAAK,aAAa,OAAO;AAAA,EAC1B;AAAA,EAEQ,MAAM,UAAU,WAAiB;AAClC,UAAA,QAAQ,KAAK,OAAO,SAAS,KAAM,MAAM,KAAK,YAAY,SAAS;AAEnE,UAAA,SAAS,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG,KAAK,OAAO;AAAA,MACxB,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,SAAS;AAAA,QACR,cAAc;AAAA,QACd,eAAe,UAAU,KAAK;AAAA,MA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AY;AAEzD,UAAM,QAAQ,WAAW,KAAK,KAAK,OAAO;AAC1C,QAAI,CAAC,SAAS,MAAM,SAAS,qBAAqB;AACjD,YAAM,IAAI,MACT,SAAS,OAAO,2CAA2C;AAAA,IAE7D;AAEM,UAAA,SAAS,EAAE,GAAI,MAAM,UAAU,IAAK,SAAS;AAEnD,UAAM,KAAK,qBAAqB,kBAAkB,CAAC,UAAU,CAAC;AAAA,EAC/D;AAAA,EAEA,MAAM,uBACL,mBAA2C;AAE3C,eAAW,oBAAoB,mBAAmB;AACjD,YAAM,EAAE,MAAM,aAAa,cAAc,SAAS,KACjD,IAAA;AAED,YAAM,YAAY,MAAM,KAAK,WAAW,EAAE,MAAM,aAAa;AAC7D,YAAM,KAAK,iBAAiB,EAAE,WAAW,KAAM,CAAA;AAC/C,YAAM,KAAK,gBAAgB,EAAE,WAAW,cAAc,SAAS;AAAA,IAChE;AAAA,EACD;AACA;;"}
@@ -6,7 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import axios from "axios";
8
8
  import { logHttpResponse } from "../utils/log.js";
9
- import { toSnakeCase } from "../utils/strings.js";
9
+ import { slugify } from "../utils/strings.js";
10
10
  class IntegrationFieldsClient {
11
11
  constructor(baseURL, config) {
12
12
  __publicField(this, "baseURL");
@@ -43,12 +43,12 @@ class IntegrationFieldsClient {
43
43
  logHttpResponse(response);
44
44
  throw new Error(`Could not add integration field catalog ${name}`);
45
45
  }
46
- return `${this.repository}--${toSnakeCase(name)}`;
46
+ return `${this.repository}--${slugify(name)}`;
47
47
  }
48
48
  async createToken(catalogId) {
49
49
  const response = await this.wroomClient.post(this.repository, `app/settings/integrationfields/pushcustom/${catalogId}/token`);
50
50
  const { data: tokenData, status } = response;
51
- if (status !== 200) {
51
+ if (status !== 201) {
52
52
  logHttpResponse(response);
53
53
  throw new Error(`Could not create token for integration field catalog ${catalogId}`);
54
54
  }
@@ -76,19 +76,10 @@ class IntegrationFieldsClient {
76
76
  }
77
77
  async setupIntegrationFields(integrationFields) {
78
78
  for (const integrationField of integrationFields) {
79
- const catalogId = await this.addCatalog({
80
- name: integrationField.name,
81
- description: integrationField.description
82
- });
83
- await this.addDataToCatalog({
84
- catalogId,
85
- data: integrationField.data
86
- });
87
- await this.addToCustomType({
88
- catalogId,
89
- customTypeId: integrationField.customTypeId,
90
- fieldId: integrationField.fieldId
91
- });
79
+ const { name, description, customTypeId, fieldId, data } = integrationField;
80
+ const catalogId = await this.addCatalog({ name, description });
81
+ await this.addDataToCatalog({ catalogId, data });
82
+ await this.addToCustomType({ catalogId, customTypeId, fieldId });
92
83
  }
93
84
  }
94
85
  }
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFields.js","sources":["../../../src/clients/integrationFields.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { IntegrationFieldConfig, IntegrationFieldData } from \"../types\";\n\nimport { logHttpResponse } from \"../utils/log\";\nimport { toSnakeCase } from \"../utils/strings\";\n\nimport { CustomTypesApiClient } from \"./customTypesApi\";\nimport { WroomClient } from \"./wroom\";\n\n/**\n * Client for interacting with Integration Fields routes to create integration\n * field catalogs and add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string;\n\tprivate readonly customTypesApiClient: CustomTypesApiClient;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly repository: string;\n\tprivate readonly tokens: Record<string, string> = {};\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient;\n\t\t\twroomClient: WroomClient;\n\t\t\trepository: string;\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL;\n\t\tthis.customTypesApiClient = config.customTypesApiClient;\n\t\tthis.wroomClient = config.wroomClient;\n\t\tthis.repository = config.repository;\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId));\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t});\n\n\t\treturn client;\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string;\n\t\tdescription: string;\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"Already existing integration field\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`);\n\t\t}\n\n\t\treturn `${this.repository}--${toSnakeCase(name)}`;\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<void> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t);\n\n\t\tconst { data: tokenData, status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not create token for integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\n\t\tconst token = tokenData[0];\n\t\tthis.tokens[catalogId] = token;\n\n\t\treturn token;\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string;\n\t\tdata: IntegrationFieldData[];\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId);\n\t\tconst response = await client.post(\n\t\t\t`/write/${catalogId}`,\n\t\t\tJSON.stringify(data),\n\t\t);\n\n\t\tconst { status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not add data to integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string;\n\t\tcustomTypeId: string;\n\t\tfieldId: string;\n\t}): Promise<void> {\n\t\tconst customType =\n\t\t\tawait this.customTypesApiClient.getTypeById(customTypeId);\n\n\t\tconst field = customType.json.Main[fieldId];\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Field ${fieldId} not found or is not an Integration Field`,\n\t\t\t);\n\t\t}\n\n\t\tfield.config = { ...(field.config ?? {}), catalog: catalogId };\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType]);\n\t}\n\n\tasync setupIntegrationFields(\n\t\tintegrationFields: IntegrationFieldConfig[],\n\t): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst catalogId = await this.addCatalog({\n\t\t\t\tname: integrationField.name,\n\t\t\t\tdescription: integrationField.description,\n\t\t\t});\n\t\t\tawait this.addDataToCatalog({\n\t\t\t\tcatalogId,\n\t\t\t\tdata: integrationField.data,\n\t\t\t});\n\t\t\tawait this.addToCustomType({\n\t\t\t\tcatalogId,\n\t\t\t\tcustomTypeId: integrationField.customTypeId,\n\t\t\t\tfieldId: integrationField.fieldId,\n\t\t\t});\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;MAca,wBAAuB;AAAA,EAOnC,YACC,SACA,QAIC;AAZe;AACA;AACA;AACA;AACA,kCAAiC,CAAA;AAUjD,SAAK,UAAU;AACf,SAAK,uBAAuB,OAAO;AACnC,SAAK,cAAc,OAAO;AAC1B,SAAK,aAAa,OAAO;AAAA,EAC1B;AAAA,EAEQ,MAAM,UAAU,WAAiB;AAClC,UAAA,QAAQ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A;AACnB,QAAI,WAAW,KAAK;AACnB,sBAAgB,QAAQ;AACxB,YAAM,IAAI,MACT,mDAAmD,SAAS,EAAE;AAAA,IAEhE;AAAA,EACD;AAAA,EAEQ,MAAM,gBAAgB,EAC7B,WACA,cACA,WAKA;AACA,UAAM,aACL,MAAM,KAAK,qBAAqB,YAAY,YAAY;AAEzD,UAAM,QAAQ,WAAW,KAAK,KAAK,OAAO;AAC1C,QAAI,CAAC,SAAS,MAAM,SAAS,qBAAqB;AACjD,YAAM,IAAI,MACT,SAAS,OAAO,2CAA2C;AAAA,IAE7D;AAEM,UAAA,SAAS,EAAE,GAAI,MAAM,UAAU,IAAK,SAAS;AAEnD,UAAM,KAAK,qBAAqB,kBAAkB,CAAC,UAAU,CAAC;AAAA,EAC/D;AAAA,EAEA,MAAM,uBACL,mBAA2C;AAE3C,eAAW,oBAAoB,mBAAmB;AAC3C,YAAA,YAAY,MAAM,KAAK,WAAW;AAAA,QACvC,MAAM,iBAAiB;AAAA,QACvB,aAAa,iBAAiB;AAAA,MAAA,CAC9B;AACD,YAAM,KAAK,iBAAiB;AAAA,QAC3B;AAAA,QACA,MAAM,iBAAiB;AAAA,MAAA,CACvB;AACD,YAAM,KAAK,gBAAgB;AAAA,QAC1B;AAAA,QACA,cAAc,iBAAiB;AAAA,QAC/B,SAAS,iBAAiB;AAAA,MAAA,CAC1B;AAAA,IACF;AAAA,EACD;AACA;"}
1
+ {"version":3,"file":"integrationFields.js","sources":["../../../src/clients/integrationFields.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { IntegrationFieldConfig, IntegrationFieldData } from \"../types\";\n\nimport { logHttpResponse } from \"../utils/log\";\nimport { slugify } from \"../utils/strings\";\n\nimport { CustomTypesApiClient } from \"./customTypesApi\";\nimport { WroomClient } from \"./wroom\";\n\n/**\n * Client for interacting with Integration Fields routes to create integration\n * field catalogs and add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string;\n\tprivate readonly customTypesApiClient: CustomTypesApiClient;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly repository: string;\n\tprivate readonly tokens: Record<string, string> = {};\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient;\n\t\t\twroomClient: WroomClient;\n\t\t\trepository: string;\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL;\n\t\tthis.customTypesApiClient = config.customTypesApiClient;\n\t\tthis.wroomClient = config.wroomClient;\n\t\tthis.repository = config.repository;\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId));\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t});\n\n\t\treturn client;\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string;\n\t\tdescription: string;\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"Already existing integration field\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`);\n\t\t}\n\n\t\treturn `${this.repository}--${slugify(name)}`;\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t);\n\n\t\tconst { data: tokenData, status } = response;\n\t\tif (status !== 201) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not create token for integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\n\t\tconst token = tokenData[0];\n\t\tthis.tokens[catalogId] = token;\n\n\t\treturn token;\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string;\n\t\tdata: IntegrationFieldData[];\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId);\n\t\tconst response = await client.post(\n\t\t\t`/write/${catalogId}`,\n\t\t\tJSON.stringify(data),\n\t\t);\n\n\t\tconst { status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not add data to integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string;\n\t\tcustomTypeId: string;\n\t\tfieldId: string;\n\t}): Promise<void> {\n\t\tconst customType =\n\t\t\tawait this.customTypesApiClient.getTypeById(customTypeId);\n\n\t\tconst field = customType.json.Main[fieldId];\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Field ${fieldId} not found or is not an Integration Field`,\n\t\t\t);\n\t\t}\n\n\t\tfield.config = { ...(field.config ?? {}), catalog: catalogId };\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType]);\n\t}\n\n\tasync setupIntegrationFields(\n\t\tintegrationFields: IntegrationFieldConfig[],\n\t): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst { name, description, customTypeId, fieldId, data } =\n\t\t\t\tintegrationField;\n\n\t\t\tconst catalogId = await this.addCatalog({ name, description });\n\t\t\tawait this.addD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ration.${url.hostname}`,
64
64
  assetApi: `${protocol}://asset-api.${url.hostname}`,
65
- integrationFieldApi: url.hostname === "prismic.io" ? `${protocol}://if-api.${url.hostname}/if` : `${protocol}://api.${url.hostname}/if`
66
- // IS THIS CORRECT FOR SQUAD ENV?
65
+ integrationFieldApi: url.hostname === "prismic.io" ? `${protocol}://if-api.${url.hostname}` : `${protocol}://api.${url.hostname}`
67
66
  };
68
67
  }
69
68
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"repositories.cjs","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { SetupConfiguration, UrlConfig } from \"../types\";\n\nimport { AssetApiClient } from \"../clients/assetApi\";\nimport { AuthenticationApiClient } from \"../clients/authenticationApi\";\nimport { CoreApiClient } from \"../clients/coreApi\";\nimport { CustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { IntegrationFieldsClient } from \"../clients/integrationFields\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { MigrationApiClient } from \"../clients/migrationApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param configuration - Global object containing the different configurations\n * required to setup the RepositoriesManager.\n *\n * - {@link configuration.urlConfig}: Configuration around the API's URLs management.\n * - {@link configuration.authConfig}: Configuration around the authentication of a user.\n * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\tconfiguration: SetupConfiguration,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(configuration);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly config: Omit<SetupConfiguration, \"urlConfig\"> & {\n\t\turlConfig: UrlConfig;\n\t};\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationApiClient;\n\tprivate readonly manageV2Client: ManageV2Client;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param configuration - Global object containing the different configuration\n\t * required to setup the different clients.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(configuration: SetupConfiguration) {\n\t\tthis.config = {\n\t\t\t...configuration,\n\t\t\tcluster: configuration.cluster,\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig:\n\t\t\t\ttypeof configuration.urlConfig === \"string\"\n\t\t\t\t\t? this.inferUrls(configuration.urlConfig)\n\t\t\t\t\t: configuration.urlConfig,\n\t\t};\n\n\t\tthis.wroomClient = new WroomClient(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.authConfig,\n\t\t\tthis.config.cluster,\n\t\t);\n\t\tthis.authClient = new AuthenticationApiClient(\n\t\t\tthis.config.urlConfig.authenticationApi,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.manageV2Client = new ManageV2Client(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.manageV2Config,\n\t\t);\n\n\t\t// This logic specific to staging environment allow us to target a specific version of the custom types API.\n\t\t// This is only works for unify-exp at the moment.\n\t\t// Having this logic here avoids duplicating it across different CI workflows.\n\t\tthis.config.urlConfig.customTypesApi =\n\t\t\tconfiguration.environment === \"stage\" &&\n\t\t\tconfiguration.cluster === \"unify-exp\"\n\t\t\t\t? `https://customtypes.wroom.io/${configuration.cluster}/`\n\t\t\t\t: this.config.urlConfig.customTypesApi;\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t\tmigrationApi: `${protocol}://migration.${url.hostname}`,\n\t\t\tassetApi: `${protocol}://asset-api.${url.hostname}`,\n\t\t\tintegrationFieldApi:\n\t\t\t\turl.hostname === \"prismic.io\"\n\t\t\t\t\t? `${protocol}://if-api.${url.hostname}/if`\n\t\t\t\t\t: `${protocol}://api.${url.hostname}/if`, // IS THIS CORRECT FOR SQUAD ENV?\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"next\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tconst version = await repository.getDeployedVersion();\n\n\t\tprofiler.done({\n\t\t\tmessage: `created repository '${repositoryName}', Wroom version is \"${version}\"`,\n\t\t});\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.config.authConfig.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param repository - The name of the repository.\n\t */\n\tgetRepositoryManager(repository: string): RepositoryManager {\n\t\tconst { urlConfig } = this.config;\n\t\tconst authToken = () => this.authClient.getToken();\n\t\tconst customTypeClient = new CustomTypesApiClient(\n\t\t\turlConfig.customTypesApi,\n\t\t\t{\n\t\t\t\tauthToken,\n\t\t\t\trepository,\n\t\t\t},\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(urlConfig.baseURL, repository);\n\t\tconst coreApiClient = new CoreApiClient(coreApiUrl, authToken);\n\t\tconst migrationApiClient = urlConfig.migrationApi\n\t\t\t? new MigrationApiClient(urlConfig.migrationApi, {\n\t\t\t\t\tauthToken,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\t\tconst assetApiClient = new AssetApiClient(urlConfig.assetApi, {\n\t\t\tauthToken,\n\t\t\trepository,\n\t\t});\n\t\tconst integrationFieldsClient = urlConfig.integrationFieldApi\n\t\t\t? new IntegrationFieldsClient(urlConfig.integrationFieldApi, {\n\t\t\t\t\tcustomTypesApiClient: customTypeClient,\n\t\t\t\t\twroomClient: this.wroomClient,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\treturn new RepositoryManager(\n\t\t\trepository,\n\t\t\tcoreApiClient,\n\t\t\tthis.authClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t\tmigrationApiClient,\n\t\t\tassetApiClient,\n\t\t\tthis.manageV2Client,\n\t\t\tintegrationFieldsClient,\n\t\t);\n\t}\n}\n"],"names":["EnvVariableManager","WroomClient","AuthenticationApiClient","ManageV2Client","logger","randomString","logHttpResponse","repository","CustomTypesApiClient","getRepositoryUrl","CoreApiClient","MigrationApiClient","AssetApiClient","IntegrationFieldsClient","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,kBACwB;AACjB,SAAA,IAAI,oBAAoB,aAAa;AAC7C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB/B,YAAY,eAAiC;AAnB5B;AAGA;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAIA,sCACnC,0BAA0B;AAS1B,SAAK,SAAS;AAAA,MACb,GAAG;AAAA,MACH,SAAS,cAAc;AAAA;AAAA,MAEvB,WACC,OAAO,cAAc,cAAc,WAChC,KAAK,UAAU,cAAc,SAAS,IACtC,cAAc;AAAA,IAAA;AAGnB,SAAK,cAAc,IAAIC,MACtB,YAAA,KAAK,OAAO,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AK,WAAW,SAAQ;AAChD,UAAM,mBAAmB,IAAIC,oCAC5B,UAAU,gBACV;AAAA,MACC;AAAA,MAAA,YACAD;AAAAA,IAAA,CACA;AAEF,UAAM,aAAaE,KAAA,iBAAiB,UAAU,SAASF,YAAU;AACjE,UAAM,gBAAgB,IAAIG,QAAAA,cAAc,YAAY,SAAS;AAC7D,UAAM,qBAAqB,UAAU,eAClC,IAAIC,aAAA,mBAAmB,UAAU,cAAc;AAAA,MAC/C;AAAA,MAAA,YACAJ;AAAAA,IAAA,CACA,IACA;AACH,UAAM,iBAAiB,IAAIK,wBAAe,UAAU,UAAU;AAAA,MAC7D;AAAA,MAAA,YACAL;AAAAA,IAAA,CACA;AACD,UAAM,0BAA0B,UAAU,sBACvC,IAAIM,kBAAA,wBAAwB,UAAU,qBAAqB;AAAA,MAC3D,sBAAsB;AAAA,MACtB,aAAa,KAAK;AAAA,MAAA,YAClBN;AAAAA,IAAA,CACA,IACA;AAEH,WAAO,IAAIO,WAAA,kBACVP,cACA,eACA,KAAK,YACL,KAAK,aACL,kBACA,oBACA,gBACA,KAAK,gBACL,uBAAuB;AAAA,EAEzB;AACA;;;"}
1
+ {"version":3,"file":"repositories.cjs","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { SetupConfiguration, UrlConfig } from \"../types\";\n\nimport { AssetApiClient } from \"../clients/assetApi\";\nimport { AuthenticationApiClient } from \"../clients/authenticationApi\";\nimport { CoreApiClient } from \"../clients/coreApi\";\nimport { CustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { IntegrationFieldsClient } from \"../clients/integrationFields\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { MigrationApiClient } from \"../clients/migrationApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param configuration - Global object containing the different configurations\n * required to setup the RepositoriesManager.\n *\n * - {@link configuration.urlConfig}: Configuration around the API's URLs management.\n * - {@link configuration.authConfig}: Configuration around the authentication of a user.\n * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\tconfiguration: SetupConfiguration,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(configuration);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly config: Omit<SetupConfiguration, \"urlConfig\"> & {\n\t\turlConfig: UrlConfig;\n\t};\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationApiClient;\n\tprivate readonly manageV2Client: ManageV2Client;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param configuration - Global object containing the different configuration\n\t * required to setup the different clients.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(configuration: SetupConfiguration) {\n\t\tthis.config = {\n\t\t\t...configuration,\n\t\t\tcluster: configuration.cluster,\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig:\n\t\t\t\ttypeof configuration.urlConfig === \"string\"\n\t\t\t\t\t? this.inferUrls(configuration.urlConfig)\n\t\t\t\t\t: configuration.urlConfig,\n\t\t};\n\n\t\tthis.wroomClient = new WroomClient(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.authConfig,\n\t\t\tthis.config.cluster,\n\t\t);\n\t\tthis.authClient = new AuthenticationApiClient(\n\t\t\tthis.config.urlConfig.authenticationApi,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.manageV2Client = new ManageV2Client(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.manageV2Config,\n\t\t);\n\n\t\t// This logic specific to staging environment allow us to target a specific version of the custom types API.\n\t\t// This is only works for unify-exp at the moment.\n\t\t// Having this logic here avoids duplicating it across different CI workflows.\n\t\tthis.config.urlConfig.customTypesApi =\n\t\t\tconfiguration.environment === \"stage\" &&\n\t\t\tconfiguration.cluster === \"unify-exp\"\n\t\t\t\t? `https://customtypes.wroom.io/${configuration.cluster}/`\n\t\t\t\t: this.config.urlConfig.customTypesApi;\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t\tmigrationApi: `${protocol}://migration.${url.hostname}`,\n\t\t\tassetApi: `${protocol}://asset-api.${url.hostname}`,\n\t\t\tintegrationFieldApi:\n\t\t\t\turl.hostname === \"prismic.io\"\n\t\t\t\t\t? `${protocol}://if-api.${url.hostname}`\n\t\t\t\t\t: `${protocol}://api.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"next\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tconst version = await repository.getDeployedVersion();\n\n\t\tprofiler.done({\n\t\t\tmessage: `created repository '${repositoryName}', Wroom version is \"${version}\"`,\n\t\t});\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.config.authConfig.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param repository - The name of the repository.\n\t */\n\tgetRepositoryManager(repository: string): RepositoryManager {\n\t\tconst { urlConfig } = this.config;\n\t\tconst authToken = () => this.authClient.getToken();\n\t\tconst customTypeClient = new CustomTypesApiClient(\n\t\t\turlConfig.customTypesApi,\n\t\t\t{\n\t\t\t\tauthToken,\n\t\t\t\trepository,\n\t\t\t},\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(urlConfig.baseURL, repository);\n\t\tconst coreApiClient = new CoreApiClient(coreApiUrl, authToken);\n\t\tconst migrationApiClient = urlConfig.migrationApi\n\t\t\t? new MigrationApiClient(urlConfig.migrationApi, {\n\t\t\t\t\tauthToken,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\t\tconst assetApiClient = new AssetApiClient(urlConfig.assetApi, {\n\t\t\tauthToken,\n\t\t\trepository,\n\t\t});\n\t\tconst integrationFieldsClient = urlConfig.integrationFieldApi\n\t\t\t? new IntegrationFieldsClient(urlConfig.integrationFieldApi, {\n\t\t\t\t\tcustomTypesApiClient: customTypeClient,\n\t\t\t\t\twroomClient: this.wroomClient,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\treturn new RepositoryManager(\n\t\t\trepository,\n\t\t\tcoreApiClient,\n\t\t\tthis.authClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t\tmigrationApiClient,\n\t\t\tassetApiClient,\n\t\t\tthis.manageV2Client,\n\t\t\tintegrationFieldsClient,\n\t\t);\n\t}\n}\n"],"names":["EnvVariableManager","WroomClient","AuthenticationApiClient","ManageV2Client","logger","randomString","logHttpResponse","repository","CustomTypesApiClient","getRepositoryUrl","CoreApiClient","MigrationApiClient","AssetApiClient","IntegrationFieldsClient","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,kBACwB;AACj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C5D;AAAA,IACD;AACK,SAAA,aAAa,OAAOA,WAAU;AACnC,aAAS,KAAK,EAAE,SAAS,uBAAuBA,WAAU,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAQ;AACP,UAAA,eAAe,KAAK,aAAa;AACvC,eAAWA,eAAc,cAAc;AAChC,YAAA,KAAK,iBAAiBA,WAAU;AAAA,IACvC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAAqBA,cAAkB;AAChC,UAAA,EAAE,UAAS,IAAK,KAAK;AAC3B,UAAM,YAAY,MAAM,KAAK,WAAW,SAAQ;AAChD,UAAM,mBAAmB,IAAIC,oCAC5B,UAAU,gBACV;AAAA,MACC;AAAA,MAAA,YACAD;AAAAA,IAAA,CACA;AAEF,UAAM,aAAaE,KAAA,iBAAiB,UAAU,SAASF,YAAU;AACjE,UAAM,gBAAgB,IAAIG,QAAAA,cAAc,YAAY,SAAS;AAC7D,UAAM,qBAAqB,UAAU,eAClC,IAAIC,aAAA,mBAAmB,UAAU,cAAc;AAAA,MAC/C;AAAA,MAAA,YACAJ;AAAAA,IAAA,CACA,IACA;AACH,UAAM,iBAAiB,IAAIK,wBAAe,UAAU,UAAU;AAAA,MAC7D;AAAA,MAAA,YACAL;AAAAA,IAAA,CACA;AACD,UAAM,0BAA0B,UAAU,sBACvC,IAAIM,kBAAA,wBAAwB,UAAU,qBAAqB;AAAA,MAC3D,sBAAsB;AAAA,MACtB,aAAa,KAAK;AAAA,MAAA,YAClBN;AAAAA,IAAA,CACA,IACA;AAEH,WAAO,IAAIO,WAAA,kBACVP,cACA,eACA,KAAK,YACL,KAAK,aACL,kBACA,oBACA,gBACA,KAAK,gBACL,uBAAuB;AAAA,EAEzB;AACA;;;"}
@@ -60,8 +60,7 @@ class RepositoriesManager {
60
60
  customTypesApi: `${protocol}://customtypes.${url.hostname}`,
61
61
  migrationApi: `${protocol}://migration.${url.hostname}`,
62
62
  assetApi: `${protocol}://asset-api.${url.hostname}`,
63
- integrationFieldApi: url.hostname === "prismic.io" ? `${protocol}://if-api.${url.hostname}/if` : `${protocol}://api.${url.hostname}/if`
64
- // IS THIS CORRECT FOR SQUAD ENV?
63
+ integrationFieldApi: url.hostname === "prismic.io" ? `${protocol}://if-api.${url.hostname}` : `${protocol}://api.${url.hostname}`
65
64
  };
66
65
  }
67
66
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"repositories.js","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { SetupConfiguration, UrlConfig } from \"../types\";\n\nimport { AssetApiClient } from \"../clients/assetApi\";\nimport { AuthenticationApiClient } from \"../clients/authenticationApi\";\nimport { CoreApiClient } from \"../clients/coreApi\";\nimport { CustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { IntegrationFieldsClient } from \"../clients/integrationFields\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { MigrationApiClient } from \"../clients/migrationApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param configuration - Global object containing the different configurations\n * required to setup the RepositoriesManager.\n *\n * - {@link configuration.urlConfig}: Configuration around the API's URLs management.\n * - {@link configuration.authConfig}: Configuration around the authentication of a user.\n * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\tconfiguration: SetupConfiguration,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(configuration);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly config: Omit<SetupConfiguration, \"urlConfig\"> & {\n\t\turlConfig: UrlConfig;\n\t};\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationApiClient;\n\tprivate readonly manageV2Client: ManageV2Client;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param configuration - Global object containing the different configuration\n\t * required to setup the different clients.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(configuration: SetupConfiguration) {\n\t\tthis.config = {\n\t\t\t...configuration,\n\t\t\tcluster: configuration.cluster,\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig:\n\t\t\t\ttypeof configuration.urlConfig === \"string\"\n\t\t\t\t\t? this.inferUrls(configuration.urlConfig)\n\t\t\t\t\t: configuration.urlConfig,\n\t\t};\n\n\t\tthis.wroomClient = new WroomClient(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.authConfig,\n\t\t\tthis.config.cluster,\n\t\t);\n\t\tthis.authClient = new AuthenticationApiClient(\n\t\t\tthis.config.urlConfig.authenticationApi,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.manageV2Client = new ManageV2Client(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.manageV2Config,\n\t\t);\n\n\t\t// This logic specific to staging environment allow us to target a specific version of the custom types API.\n\t\t// This is only works for unify-exp at the moment.\n\t\t// Having this logic here avoids duplicating it across different CI workflows.\n\t\tthis.config.urlConfig.customTypesApi =\n\t\t\tconfiguration.environment === \"stage\" &&\n\t\t\tconfiguration.cluster === \"unify-exp\"\n\t\t\t\t? `https://customtypes.wroom.io/${configuration.cluster}/`\n\t\t\t\t: this.config.urlConfig.customTypesApi;\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t\tmigrationApi: `${protocol}://migration.${url.hostname}`,\n\t\t\tassetApi: `${protocol}://asset-api.${url.hostname}`,\n\t\t\tintegrationFieldApi:\n\t\t\t\turl.hostname === \"prismic.io\"\n\t\t\t\t\t? `${protocol}://if-api.${url.hostname}/if`\n\t\t\t\t\t: `${protocol}://api.${url.hostname}/if`, // IS THIS CORRECT FOR SQUAD ENV?\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"next\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tconst version = await repository.getDeployedVersion();\n\n\t\tprofiler.done({\n\t\t\tmessage: `created repository '${repositoryName}', Wroom version is \"${version}\"`,\n\t\t});\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.config.authConfig.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param repository - The name of the repository.\n\t */\n\tgetRepositoryManager(repository: string): RepositoryManager {\n\t\tconst { urlConfig } = this.config;\n\t\tconst authToken = () => this.authClient.getToken();\n\t\tconst customTypeClient = new CustomTypesApiClient(\n\t\t\turlConfig.customTypesApi,\n\t\t\t{\n\t\t\t\tauthToken,\n\t\t\t\trepository,\n\t\t\t},\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(urlConfig.baseURL, repository);\n\t\tconst coreApiClient = new CoreApiClient(coreApiUrl, authToken);\n\t\tconst migrationApiClient = urlConfig.migrationApi\n\t\t\t? new MigrationApiClient(urlConfig.migrationApi, {\n\t\t\t\t\tauthToken,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\t\tconst assetApiClient = new AssetApiClient(urlConfig.assetApi, {\n\t\t\tauthToken,\n\t\t\trepository,\n\t\t});\n\t\tconst integrationFieldsClient = urlConfig.integrationFieldApi\n\t\t\t? new IntegrationFieldsClient(urlConfig.integrationFieldApi, {\n\t\t\t\t\tcustomTypesApiClient: customTypeClient,\n\t\t\t\t\twroomClient: this.wroomClient,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\treturn new RepositoryManager(\n\t\t\trepository,\n\t\t\tcoreApiClient,\n\t\t\tthis.authClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t\tmigrationApiClient,\n\t\t\tassetApiClient,\n\t\t\tthis.manageV2Client,\n\t\t\tintegrationFieldsClient,\n\t\t);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,kBACwB;AACjB,SAAA,IAAI,oBAAoB,aAAa;AAC7C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB/B,YAAY,eAAiC;AAnB5B;AAGA;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAI,mBACnC,0BAA0B;AAS1B,SAAK,SAAS;AAAA,MACb,GAAG;AAAA,MACH,SAAS,cAAc;AAAA;AAAA,MAEvB,WACC,OAAO,cAAc,cAAc,WAChC,KAAK,UAAU,cAAc,SAAS,IACtC,cAAc;AAAA,IAAA;AAGnB,SAAK,cAAc,IAAI,YACtB,KAAK,OAAO,UAAU,SACtB,KAAK,OAAO,YACZ,KAAK,OAAO,OAAO;AAEf,SAAA,aAAa,IAAI,wBACrB,KAAK,OAAO,UAAU,mBACtB,KAAK,OAAO,UAAU;AAElB,SAAA,iBAAiB,IAAI,eACzB,KAAK,OAAO,UAAU,SACtB,K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mB,UAAU,cAAc;AAAA,MAC/C;AAAA,MACA;AAAA,IAAA,CACA,IACA;AACH,UAAM,iBAAiB,IAAI,eAAe,UAAU,UAAU;AAAA,MAC7D;AAAA,MACA;AAAA,IAAA,CACA;AACD,UAAM,0BAA0B,UAAU,sBACvC,IAAI,wBAAwB,UAAU,qBAAqB;AAAA,MAC3D,sBAAsB;AAAA,MACtB,aAAa,KAAK;AAAA,MAClB;AAAA,IAAA,CACA,IACA;AAEH,WAAO,IAAI,kBACV,YACA,eACA,KAAK,YACL,KAAK,aACL,kBACA,oBACA,gBACA,KAAK,gBACL,uBAAuB;AAAA,EAEzB;AACA;"}
1
+ {"version":3,"file":"repositories.js","sources":["../../../src/managers/repositories.ts"],"sourcesContent":["import { SetupConfiguration, UrlConfig } from \"../types\";\n\nimport { AssetApiClient } from \"../clients/assetApi\";\nimport { AuthenticationApiClient } from \"../clients/authenticationApi\";\nimport { CoreApiClient } from \"../clients/coreApi\";\nimport { CustomTypesApiClient } from \"../clients/customTypesApi\";\nimport { IntegrationFieldsClient } from \"../clients/integrationFields\";\nimport { ManageV2Client } from \"../clients/manageV2\";\nimport { MigrationApiClient } from \"../clients/migrationApi\";\nimport { WroomClient } from \"../clients/wroom\";\nimport { EnvVariableManager } from \"../utils/envVariableManager\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { randomString } from \"../utils/random\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\nimport { RepositoryConfig, RepositoryManager } from \"./repository\";\n\n/**\n * Factory method to create a RepositoriesManager to manage repositories test\n * data.\n *\n * @param configuration - Global object containing the different configurations\n * required to setup the RepositoriesManager.\n *\n * - {@link configuration.urlConfig}: Configuration around the API's URLs management.\n * - {@link configuration.authConfig}: Configuration around the authentication of a user.\n * - {@link configuration.manageV2Config}: Optional Configuration used to make calls to ManageV2.\n *\n * @returns An instance of {@link RepositoriesManager} to manage test data.\n */\nexport const createRepositoriesManager = (\n\tconfiguration: SetupConfiguration,\n): RepositoriesManager => {\n\treturn new RepositoriesManager(configuration);\n};\n\n/** Utility object to manage Prismic test data */\nexport class RepositoriesManager {\n\tprivate readonly config: Omit<SetupConfiguration, \"urlConfig\"> & {\n\t\turlConfig: UrlConfig;\n\t};\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly authClient: AuthenticationApiClient;\n\tprivate readonly manageV2Client: ManageV2Client;\n\t/**\n\t * helper to keep track of repositories across independent test phases (setup,\n\t * teardown)\n\t */\n\tprivate readonly repositories = new EnvVariableManager(\n\t\t\"_PRISMIC_E2E_TESTS_REPOS\",\n\t);\n\n\t/**\n\t * @param configuration - Global object containing the different configuration\n\t * required to setup the different clients.\n\t * @param credentials - Authentication credentials (email and password)\n\t */\n\tconstructor(configuration: SetupConfiguration) {\n\t\tthis.config = {\n\t\t\t...configuration,\n\t\t\tcluster: configuration.cluster,\n\t\t\t// When a string is provided, treat it as the 'base' property\n\t\t\turlConfig:\n\t\t\t\ttypeof configuration.urlConfig === \"string\"\n\t\t\t\t\t? this.inferUrls(configuration.urlConfig)\n\t\t\t\t\t: configuration.urlConfig,\n\t\t};\n\n\t\tthis.wroomClient = new WroomClient(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.authConfig,\n\t\t\tthis.config.cluster,\n\t\t);\n\t\tthis.authClient = new AuthenticationApiClient(\n\t\t\tthis.config.urlConfig.authenticationApi,\n\t\t\tthis.config.authConfig,\n\t\t);\n\t\tthis.manageV2Client = new ManageV2Client(\n\t\t\tthis.config.urlConfig.baseURL,\n\t\t\tthis.config.manageV2Config,\n\t\t);\n\n\t\t// This logic specific to staging environment allow us to target a specific version of the custom types API.\n\t\t// This is only works for unify-exp at the moment.\n\t\t// Having this logic here avoids duplicating it across different CI workflows.\n\t\tthis.config.urlConfig.customTypesApi =\n\t\t\tconfiguration.environment === \"stage\" &&\n\t\t\tconfiguration.cluster === \"unify-exp\"\n\t\t\t\t? `https://customtypes.wroom.io/${configuration.cluster}/`\n\t\t\t\t: this.config.urlConfig.customTypesApi;\n\t}\n\n\t/**\n\t * If the baseURL is prismic.io, assume the other services have the format\n\t * <name>.prismic.io\n\t */\n\tprivate inferUrls(baseURL: string): UrlConfig {\n\t\tconst url = new URL(baseURL);\n\t\tconst protocol = url.protocol.slice(0, -1); // Remove the trailing colon from the protocol\n\n\t\treturn {\n\t\t\tbaseURL: baseURL,\n\t\t\tauthenticationApi: `${protocol}://auth.${url.hostname}`,\n\t\t\tcustomTypesApi: `${protocol}://customtypes.${url.hostname}`,\n\t\t\tmigrationApi: `${protocol}://migration.${url.hostname}`,\n\t\t\tassetApi: `${protocol}://asset-api.${url.hostname}`,\n\t\t\tintegrationFieldApi:\n\t\t\t\turl.hostname === \"prismic.io\"\n\t\t\t\t\t? `${protocol}://if-api.${url.hostname}`\n\t\t\t\t\t: `${protocol}://api.${url.hostname}`,\n\t\t};\n\t}\n\n\t/**\n\t * Generate a user token from the authentication service.\n\t *\n\t * @returns a JWT token\n\t */\n\tasync getUserApiToken(): Promise<string> {\n\t\treturn this.authClient.getToken();\n\t}\n\n\t/**\n\t * Create a new repository in Wroom.\n\t *\n\t * @param repositoryName - The name of the repository.\n\t *\n\t * @throws Error if the repository creation fails.\n\t */\n\tasync createRepository(\n\t\tconfig: {\n\t\t\tprefix?: string;\n\t\t} & RepositoryConfig = {},\n\t): Promise<RepositoryManager> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst { prefix = \"e2e-tests\" } = config;\n\t\tconst repositoryName = `${prefix}-${randomString()}`;\n\n\t\tconst response = await this.wroomClient.post(\n\t\t\tnull,\n\t\t\t\"authentication/newrepository\",\n\t\t\t{\n\t\t\t\tdomain: repositoryName,\n\t\t\t\tframework: \"next\",\n\t\t\t\tplan: \"personal\",\n\t\t\t\tisAnnual: \"false\",\n\t\t\t\trole: \"developer\",\n\t\t\t},\n\t\t);\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not create repository ${repositoryName}`);\n\t\t}\n\t\tthis.repositories.add(repositoryName);\n\n\t\tconst repository = this.getRepositoryManager(repositoryName);\n\t\tconst version = await repository.getDeployedVersion();\n\n\t\tprofiler.done({\n\t\t\tmessage: `created repository '${repositoryName}', Wroom version is \"${version}\"`,\n\t\t});\n\t\tawait repository.configure(config);\n\n\t\treturn repository;\n\t}\n\n\t/**\n\t * Delete a repository from Wroom.\n\t *\n\t * @param repository - The name of the repository.\n\t *\n\t * @throws Error if the repository deletion fails.\n\t */\n\tasync deleteRepository(repository: string): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\n\t\tconst post = async () =>\n\t\t\tthis.wroomClient.post(repository, \"app/settings/delete\", {\n\t\t\t\tconfirm: repository,\n\t\t\t\tpassword: this.config.authConfig.password,\n\t\t\t});\n\t\tconst response = await post();\n\t\tif (response.status !== 200) {\n\t\t\t// sometimes the deletion returns 500 but actually succeeds\n\t\t\t// we run the query again and check the repo is actually deleted (404)\n\t\t\tconst retry = await post();\n\t\t\tif (retry.status !== 404) {\n\t\t\t\tlogHttpResponse(response);\n\t\t\t\tthrow new Error(`Could not delete repository ${repository}`);\n\t\t\t}\n\t\t}\n\t\tthis.repositories.remove(repository);\n\t\tprofiler.done({ message: `deleted repository '${repository}'` });\n\t}\n\n\t/**\n\t * Cleanup test data. For example, it deletes repositories created using\n\t * createRepository()\n\t */\n\tasync tearDown(): Promise<void> {\n\t\tconst repositories = this.repositories.getAll();\n\t\tfor (const repository of repositories) {\n\t\t\tawait this.deleteRepository(repository);\n\t\t}\n\t}\n\n\t/**\n\t * Return a repository utilities object for a repository.\n\t *\n\t * @param repository - The name of the repository.\n\t */\n\tgetRepositoryManager(repository: string): RepositoryManager {\n\t\tconst { urlConfig } = this.config;\n\t\tconst authToken = () => this.authClient.getToken();\n\t\tconst customTypeClient = new CustomTypesApiClient(\n\t\t\turlConfig.customTypesApi,\n\t\t\t{\n\t\t\t\tauthToken,\n\t\t\t\trepository,\n\t\t\t},\n\t\t);\n\t\tconst coreApiUrl = getRepositoryUrl(urlConfig.baseURL, repository);\n\t\tconst coreApiClient = new CoreApiClient(coreApiUrl, authToken);\n\t\tconst migrationApiClient = urlConfig.migrationApi\n\t\t\t? new MigrationApiClient(urlConfig.migrationApi, {\n\t\t\t\t\tauthToken,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\t\tconst assetApiClient = new AssetApiClient(urlConfig.assetApi, {\n\t\t\tauthToken,\n\t\t\trepository,\n\t\t});\n\t\tconst integrationFieldsClient = urlConfig.integrationFieldApi\n\t\t\t? new IntegrationFieldsClient(urlConfig.integrationFieldApi, {\n\t\t\t\t\tcustomTypesApiClient: customTypeClient,\n\t\t\t\t\twroomClient: this.wroomClient,\n\t\t\t\t\trepository,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\treturn new RepositoryManager(\n\t\t\trepository,\n\t\t\tcoreApiClient,\n\t\t\tthis.authClient,\n\t\t\tthis.wroomClient,\n\t\t\tcustomTypeClient,\n\t\t\tmigrationApiClient,\n\t\t\tassetApiClient,\n\t\t\tthis.manageV2Client,\n\t\t\tintegrationFieldsClient,\n\t\t);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA8Ba,MAAA,4BAA4B,CACxC,kBACwB;AACjB,SAAA,IAAI,oBAAoB,aAAa;AAC7C;MAGa,oBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB/B,YAAY,eAAiC;AAnB5B;AAGA;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA,wCAAe,IAAI,mBACnC,0BAA0B;AAS1B,SAAK,SAAS;AAAA,MACb,GAAG;AAAA,MACH,SAAS,cAAc;AAAA;AAAA,MAEvB,WACC,OAAO,cAAc,cAAc,WAChC,KAAK,UAAU,cAAc,SAAS,IACtC,cAAc;AAAA,IAAA;AAGnB,SAAK,cAAc,IAAI,YACtB,KAAK,OAAO,UAAU,SACtB,KAAK,OAAO,YACZ,KAAK,OAAO,OAAO;AAEf,SAAA,aAAa,IAAI,w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SAAS,UAAU;AACjE,UAAM,gBAAgB,IAAI,cAAc,YAAY,SAAS;AAC7D,UAAM,qBAAqB,UAAU,eAClC,IAAI,mBAAmB,UAAU,cAAc;AAAA,MAC/C;AAAA,MACA;AAAA,IAAA,CACA,IACA;AACH,UAAM,iBAAiB,IAAI,eAAe,UAAU,UAAU;AAAA,MAC7D;AAAA,MACA;AAAA,IAAA,CACA;AACD,UAAM,0BAA0B,UAAU,sBACvC,IAAI,wBAAwB,UAAU,qBAAqB;AAAA,MAC3D,sBAAsB;AAAA,MACtB,aAAa,KAAK;AAAA,MAClB;AAAA,IAAA,CACA,IACA;AAEH,WAAO,IAAI,kBACV,YACA,eACA,KAAK,YACL,KAAK,aACL,kBACA,oBACA,gBACA,KAAK,gBACL,uBAAuB;AAAA,EAEzB;AACA;"}
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const toSnakeCase = (str) => {
4
- return str.replace(/[\s\-]+/g, "_").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase().replace(/[^a-z0-9_]/g, "").replace(/^_+|_+$/g, "");
3
+ const slugify = (str) => {
4
+ const noWhitespace = str.trim().replace(/ /g, "_");
5
+ const normalized = noWhitespace.normalize("NFD").replace(new RegExp("\\p{M}+", "gu"), "");
6
+ const slug = normalized.replace(/[^A-Za-z0-9_-]/g, "").toLowerCase();
7
+ return slug || "";
5
8
  };
6
- exports.toSnakeCase = toSnakeCase;
9
+ exports.slugify = slugify;
7
10
  //# sourceMappingURL=strings.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.cjs","sources":["../../../src/utils/strings.ts"],"sourcesContent":["/**\n * Convert a string to snake_case\n *\n * @param str - The string to convert to snake_case\n *\n * @returns The snake_case string\n */\nexport const toSnakeCase = (str: string): string => {\n\treturn str\n\t\t.replace(/[\\s\\-]+/g, \"_\")\n\t\t.replace(/([a-z])([A-Z])/g, \"$1_$2\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_]/g, \"\")\n\t\t.replace(/^_+|_+$/g, \"\");\n};\n"],"names":[],"mappings":";;AAOa,MAAA,cAAc,CAAC,QAAuB;AAClD,SAAO,IACL,QAAQ,YAAY,GAAG,EACvB,QAAQ,mBAAmB,OAAO,EAClC,cACA,QAAQ,eAAe,EAAE,EACzB,QAAQ,YAAY,EAAE;AACzB;;"}
1
+ {"version":3,"file":"strings.cjs","sources":["../../../src/utils/strings.ts"],"sourcesContent":["/**\n * Convert string to a slug suitable for Integration Fields.\n *\n * @param str - The input string to slugify.\n *\n * @returns The slugified string (empty string if no valid characters remain).\n *\n * Inspired by the Wroom slugify function:\n * https://github.com/prismicio/wroom/blob/09452b75fa5fabdaf3cd81383741cd02d30c9c9f/subprojects/common/app/utils/String.scala#L55\n */\nexport const slugify = (str: string): string => {\n\tconst noWhitespace = str.trim().replace(/ /g, \"_\");\n\tconst normalized = noWhitespace.normalize(\"NFD\").replace(/\\p{M}+/gu, \"\");\n\tconst slug = normalized.replace(/[^A-Za-z0-9_-]/g, \"\").toLowerCase();\n\n\treturn slug || \"\";\n};\n"],"names":[],"mappings":";;AAUa,MAAA,UAAU,CAAC,QAAuB;AAC9C,QAAM,eAAe,IAAI,KAAA,EAAO,QAAQ,MAAM,GAAG;AACjD,QAAM,aAAa,aAAa,UAAU,KAAK,EAAE,QAAQ,WAAA,WAAA,OAAY,EAAE;AACvE,QAAM,OAAO,WAAW,QAAQ,mBAAmB,EAAE,EAAE;AAEvD,SAAO,QAAQ;AAChB;;"}
@@ -1,8 +1,11 @@
1
1
  /**
2
- * Convert a string to snake_case
2
+ * Convert string to a slug suitable for Integration Fields.
3
3
  *
4
- * @param str - The string to convert to snake_case
4
+ * @param str - The input string to slugify.
5
5
  *
6
- * @returns The snake_case string
6
+ * @returns The slugified string (empty string if no valid characters remain).
7
+ *
8
+ * Inspired by the Wroom slugify function:
9
+ * https://github.com/prismicio/wroom/blob/09452b75fa5fabdaf3cd81383741cd02d30c9c9f/subprojects/common/app/utils/String.scala#L55
7
10
  */
8
- export declare const toSnakeCase: (str: string) => string;
11
+ export declare const slugify: (str: string) => string;
@@ -1,7 +1,10 @@
1
- const toSnakeCase = (str) => {
2
- return str.replace(/[\s\-]+/g, "_").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase().replace(/[^a-z0-9_]/g, "").replace(/^_+|_+$/g, "");
1
+ const slugify = (str) => {
2
+ const noWhitespace = str.trim().replace(/ /g, "_");
3
+ const normalized = noWhitespace.normalize("NFD").replace(new RegExp("\\p{M}+", "gu"), "");
4
+ const slug = normalized.replace(/[^A-Za-z0-9_-]/g, "").toLowerCase();
5
+ return slug || "";
3
6
  };
4
7
  export {
5
- toSnakeCase
8
+ slugify
6
9
  };
7
10
  //# sourceMappingURL=strings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.js","sources":["../../../src/utils/strings.ts"],"sourcesContent":["/**\n * Convert a string to snake_case\n *\n * @param str - The string to convert to snake_case\n *\n * @returns The snake_case string\n */\nexport const toSnakeCase = (str: string): string => {\n\treturn str\n\t\t.replace(/[\\s\\-]+/g, \"_\")\n\t\t.replace(/([a-z])([A-Z])/g, \"$1_$2\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_]/g, \"\")\n\t\t.replace(/^_+|_+$/g, \"\");\n};\n"],"names":[],"mappings":"AAOa,MAAA,cAAc,CAAC,QAAuB;AAClD,SAAO,IACL,QAAQ,YAAY,GAAG,EACvB,QAAQ,mBAAmB,OAAO,EAClC,cACA,QAAQ,eAAe,EAAE,EACzB,QAAQ,YAAY,EAAE;AACzB;"}
1
+ {"version":3,"file":"strings.js","sources":["../../../src/utils/strings.ts"],"sourcesContent":["/**\n * Convert string to a slug suitable for Integration Fields.\n *\n * @param str - The input string to slugify.\n *\n * @returns The slugified string (empty string if no valid characters remain).\n *\n * Inspired by the Wroom slugify function:\n * https://github.com/prismicio/wroom/blob/09452b75fa5fabdaf3cd81383741cd02d30c9c9f/subprojects/common/app/utils/String.scala#L55\n */\nexport const slugify = (str: string): string => {\n\tconst noWhitespace = str.trim().replace(/ /g, \"_\");\n\tconst normalized = noWhitespace.normalize(\"NFD\").replace(/\\p{M}+/gu, \"\");\n\tconst slug = normalized.replace(/[^A-Za-z0-9_-]/g, \"\").toLowerCase();\n\n\treturn slug || \"\";\n};\n"],"names":[],"mappings":"AAUa,MAAA,UAAU,CAAC,QAAuB;AAC9C,QAAM,eAAe,IAAI,KAAA,EAAO,QAAQ,MAAM,GAAG;AACjD,QAAM,aAAa,aAAa,UAAU,KAAK,EAAE,QAAQ,WAAA,WAAA,OAAY,EAAE;AACvE,QAAM,OAAO,WAAW,QAAQ,mBAAmB,EAAE,EAAE;AAEvD,SAAO,QAAQ;AAChB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/e2e-tests-utils",
3
- "version": "1.12.0-alpha.3",
3
+ "version": "1.12.0-alpha.5",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -3,7 +3,7 @@ import axios, { AxiosInstance } from "axios";
3
3
  import { IntegrationFieldConfig, IntegrationFieldData } from "../types";
4
4
 
5
5
  import { logHttpResponse } from "../utils/log";
6
- import { toSnakeCase } from "../utils/strings";
6
+ import { slugify } from "../utils/strings";
7
7
 
8
8
  import { CustomTypesApiClient } from "./customTypesApi";
9
9
  import { WroomClient } from "./wroom";
@@ -75,17 +75,17 @@ export class IntegrationFieldsClient {
75
75
  throw new Error(`Could not add integration field catalog ${name}`);
76
76
  }
77
77
 
78
- return `${this.repository}--${toSnakeCase(name)}`;
78
+ return `${this.repository}--${slugify(name)}`;
79
79
  }
80
80
 
81
- private async createToken(catalogId: string): Promise<void> {
81
+ private async createToken(catalogId: string): Promise<string> {
82
82
  const response = await this.wroomClient.post(
83
83
  this.repository,
84
84
  `app/settings/integrationfields/pushcustom/${catalogId}/token`,
85
85
  );
86
86
 
87
87
  const { data: tokenData, status } = response;
88
- if (status !== 200) {
88
+ if (status !== 201) {
89
89
  logHttpResponse(response);
90
90
  throw new Error(
91
91
  `Could not create token for integration field catalog ${catalogId}`,
@@ -148,19 +148,12 @@ export class IntegrationFieldsClient {
148
148
  integrationFields: IntegrationFieldConfig[],
149
149
  ): Promise<void> {
150
150
  for (const integrationField of integrationFields) {
151
- const catalogId = await this.addCatalog({
152
- name: integrationField.name,
153
- description: integrationField.description,
154
- });
155
- await this.addDataToCatalog({
156
- catalogId,
157
- data: integrationField.data,
158
- });
159
- await this.addToCustomType({
160
- catalogId,
161
- customTypeId: integrationField.customTypeId,
162
- fieldId: integrationField.fieldId,
163
- });
151
+ const { name, description, customTypeId, fieldId, data } =
152
+ integrationField;
153
+
154
+ const catalogId = await this.addCatalog({ name, description });
155
+ await this.addDataToCatalog({ catalogId, data });
156
+ await this.addToCustomType({ catalogId, customTypeId, fieldId });
164
157
  }
165
158
  }
166
159
  }
@@ -106,8 +106,8 @@ export class RepositoriesManager {
106
106
  assetApi: `${protocol}://asset-api.${url.hostname}`,
107
107
  integrationFieldApi:
108
108
  url.hostname === "prismic.io"
109
- ? `${protocol}://if-api.${url.hostname}/if`
110
- : `${protocol}://api.${url.hostname}/if`, // IS THIS CORRECT FOR SQUAD ENV?
109
+ ? `${protocol}://if-api.${url.hostname}`
110
+ : `${protocol}://api.${url.hostname}`,
111
111
  };
112
112
  }
113
113
 
@@ -1,15 +1,17 @@
1
1
  /**
2
- * Convert a string to snake_case
2
+ * Convert string to a slug suitable for Integration Fields.
3
3
  *
4
- * @param str - The string to convert to snake_case
4
+ * @param str - The input string to slugify.
5
5
  *
6
- * @returns The snake_case string
6
+ * @returns The slugified string (empty string if no valid characters remain).
7
+ *
8
+ * Inspired by the Wroom slugify function:
9
+ * https://github.com/prismicio/wroom/blob/09452b75fa5fabdaf3cd81383741cd02d30c9c9f/subprojects/common/app/utils/String.scala#L55
7
10
  */
8
- export const toSnakeCase = (str: string): string => {
9
- return str
10
- .replace(/[\s\-]+/g, "_")
11
- .replace(/([a-z])([A-Z])/g, "$1_$2")
12
- .toLowerCase()
13
- .replace(/[^a-z0-9_]/g, "")
14
- .replace(/^_+|_+$/g, "");
11
+ export const slugify = (str: string): string => {
12
+ const noWhitespace = str.trim().replace(/ /g, "_");
13
+ const normalized = noWhitespace.normalize("NFD").replace(/\p{M}+/gu, "");
14
+ const slug = normalized.replace(/[^A-Za-z0-9_-]/g, "").toLowerCase();
15
+
16
+ return slug || "";
15
17
  };