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

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.
@@ -50,7 +50,7 @@ class IntegrationFieldsClient {
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
  }
@@ -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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C;AAGf,UAAA,EAAE,OAAW,IAAA;AACnB,QAAI,WAAW,KAAK;AACnBA,UAAA,gBAAgB,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.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 !== 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 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,EAAE;AAAA,IAClE;AAEA,WAAO,GAAG,KAAK,UAAU,KAAKC,oBAAY,IAAI,CAA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AAiB;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;;"}
@@ -48,7 +48,7 @@ class IntegrationFieldsClient {
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
  }
@@ -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,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IACnB,KAAK,UAAU,IAAI,CAAC;AAGf,UAAA,EAAE,OAAW,IAAA;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 { 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 !== 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 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,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;AACb,sBAAgB,QAAQ;AACxB,YAAM,IAAI,MAAM,2CAA2C,IAAI,EAAE;AAAA,IAClE;AAEA,WAAO,GAAG,KAAK,UAAU,KAAK,YAAY,IAAI,CAAC;AAAA,EAChD;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,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;"}
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.4",
4
4
  "description": "A collection of utilities for to manage Prismic test data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -85,7 +85,7 @@ export class IntegrationFieldsClient {
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}`,