@prismicio/e2e-tests-utils 1.12.0-alpha.1 → 1.12.0-alpha.2
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.
- package/dist/clients/customTypesApi.cjs +13 -0
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.d.ts +6 -0
- package/dist/clients/customTypesApi.js +13 -0
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/integrationFields.cjs +100 -0
- package/dist/clients/integrationFields.cjs.map +1 -0
- package/dist/clients/integrationFields.d.ts +25 -0
- package/dist/clients/integrationFields.js +100 -0
- package/dist/clients/integrationFields.js.map +1 -0
- package/dist/managers/repositories.cjs +10 -2
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.js +10 -2
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +14 -1
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +6 -2
- package/dist/managers/repository.js +14 -1
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/utils/strings.cjs +7 -0
- package/dist/utils/strings.cjs.map +1 -0
- package/dist/utils/strings.d.ts +8 -0
- package/dist/utils/strings.js +7 -0
- package/dist/utils/strings.js.map +1 -0
- package/package.json +1 -1
- package/src/clients/customTypesApi.ts +16 -0
- package/src/clients/integrationFields.ts +169 -0
- package/src/managers/repositories.ts +13 -0
- package/src/managers/repository.ts +27 -1
- package/src/types.ts +18 -0
- package/src/utils/strings.ts +15 -0
|
@@ -73,6 +73,19 @@ class CustomTypesApiClient extends apiClient.AuthenticatedApiClient {
|
|
|
73
73
|
async createSlices(slices = []) {
|
|
74
74
|
await this.upsertIfChanged("slices", slices);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Get a custom type by its id.
|
|
78
|
+
*
|
|
79
|
+
* @param customTypeId - The id of the custom type to get.
|
|
80
|
+
*/
|
|
81
|
+
async getTypeById(customTypeId) {
|
|
82
|
+
const remoteItems = await this.getRemoteItems("customtypes");
|
|
83
|
+
const remoteItem = remoteItems.find((remote) => remote.id === customTypeId);
|
|
84
|
+
if (!remoteItem || "type" in remoteItem) {
|
|
85
|
+
throw new Error(`Custom type ${customTypeId} not found`);
|
|
86
|
+
}
|
|
87
|
+
return remoteItem;
|
|
88
|
+
}
|
|
76
89
|
}
|
|
77
90
|
exports.CustomTypesApiClient = CustomTypesApiClient;
|
|
78
91
|
//# sourceMappingURL=customTypesApi.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype ItemType = CustomType | SharedSlice;\ntype ItemTypePath = \"customtypes\" | \"slices\";\ntype ItemOperation = \"insert\" | \"update\";\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(path, { data });\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tprivate async getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(endpoint);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[] = []): Promise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AM,cAAc,MAAM,KAAK,eAAe,QAAQ;AACtD,UAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,KAAK,cAAc,aAAa,SAAS;AAEjE,aAAO,aAAa,KAAK,OAAO,UAAU,WAAW,SAAS;AAAA,IAC9D,CAAA,CAAC;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,cAA4B,IAAE;AAC/C,UAAA,KAAK,gBAAgB,eAAe,WAAW;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,SAAwB,IAAE;AACtC,UAAA,KAAK,gBAAgB,UAAU,MAAM;AAAA,EAC5C;AACA;;"}
|
|
1
|
+
{"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype ItemType = CustomType | SharedSlice;\ntype ItemTypePath = \"customtypes\" | \"slices\";\ntype ItemOperation = \"insert\" | \"update\";\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(path, { data });\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tprivate async getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(endpoint);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices);\n\t}\n\n\t/**\n\t * Get a custom type by its id.\n\t *\n\t * @param customTypeId - The id of the custom type to get.\n\t */\n\tasync getTypeById(customTypeId: string): Promise<CustomType> {\n\t\tconst remoteItems = await this.getRemoteItems(\"customtypes\");\n\n\t\tconst remoteItem = remoteItems.find((remote) => remote.id === customTypeId);\n\t\tif (!remoteItem || \"type\" in remoteItem) {\n\t\t\tthrow new Error(`Custom type ${customTypeId} not found`);\n\t\t}\n\n\t\treturn remoteItem;\n\t}\n}\n"],"names":["AuthenticatedApiClient","logger","logPlaywrightApiResponse"],"mappings":";;;;;AAmBM,MAAO,6BAA6BA,UAAAA,uBAAsB;AAAA,EAC/D,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYQ,MAAM,OACb,UACA,WACA,MAAc;AAER,UAAA,WAAWC,WAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,MAAM,EAAE,MAAM;AAC5C,QAAA,CAAC,OAAO,MAAM;AACjBC,UAAA,yBAAyB,MAAM;AAC/B,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AAAA,IAAA,CACrE;AAAA,EACF;AAAA,EAEQ,MAAM,eACb,UAAsB;AAEhB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;AAEr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* @param slices -
|
|
37
37
|
*/
|
|
38
38
|
createSlices(slices?: SharedSlice[]): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Get a custom type by its id.
|
|
41
|
+
*
|
|
42
|
+
* @param customTypeId - The id of the custom type to get.
|
|
43
|
+
*/
|
|
44
|
+
getTypeById(customTypeId: string): Promise<CustomType>;
|
|
39
45
|
}
|
|
@@ -71,6 +71,19 @@ class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
|
71
71
|
async createSlices(slices = []) {
|
|
72
72
|
await this.upsertIfChanged("slices", slices);
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Get a custom type by its id.
|
|
76
|
+
*
|
|
77
|
+
* @param customTypeId - The id of the custom type to get.
|
|
78
|
+
*/
|
|
79
|
+
async getTypeById(customTypeId) {
|
|
80
|
+
const remoteItems = await this.getRemoteItems("customtypes");
|
|
81
|
+
const remoteItem = remoteItems.find((remote) => remote.id === customTypeId);
|
|
82
|
+
if (!remoteItem || "type" in remoteItem) {
|
|
83
|
+
throw new Error(`Custom type ${customTypeId} not found`);
|
|
84
|
+
}
|
|
85
|
+
return remoteItem;
|
|
86
|
+
}
|
|
74
87
|
}
|
|
75
88
|
export {
|
|
76
89
|
CustomTypesApiClient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypesApi.js","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype ItemType = CustomType | SharedSlice;\ntype ItemTypePath = \"customtypes\" | \"slices\";\ntype ItemOperation = \"insert\" | \"update\";\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(path, { data });\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tprivate async getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(endpoint);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices);\n\t}\n}\n"],"names":[],"mappings":";;;AAmBM,MAAO,6BAA6B,uBAAsB;AAAA,EAC/D,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYQ,MAAM,OACb,UACA,WACA,MAAc;AAER,UAAA,WAAW,OAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,MAAM,EAAE,MAAM;AAC5C,QAAA,CAAC,OAAO,MAAM;AACjB,+BAAyB,MAAM;AAC/B,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AAAA,IAAA,CACrE;AAAA,EACF;AAAA,EAEQ,MAAM,eACb,UAAsB;AAEhB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;AAErC,QAAA,CAAC,OAAO,MAAM;AACjB,+BAAyB,MAAM;AACzB,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AAEA,WAAO,OAAO;EACf;AAAA,EAEQ,MAAM,cACb,aACA,OAAe;AAET,UAAA,aAAa,YAAY,KAC9B,CAAC,WAAqC,OAAO,OAAO,MAAM,EAAE;AAE7D,QAAI,CAAC,YAAY;AACT,aAAA;AAAA,IACR;AACA,QAAI,CAAC,QAAQ,OAAO,UAAU,GAAG;AACzB,aAAA;AAAA,IACR;AAEA;AAAA,EACD;AAAA;AAAA,EAGQ,MAAM,gBACb,UACA,aAAyB,IAAE;AAE3B,UAAM,cAAc,MAAM,KAAK,eAAe,QAAQ;AACtD,UAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,KAAK,cAAc,aAAa,SAAS;AAEjE,aAAO,aAAa,KAAK,OAAO,UAAU,WAAW,SAAS;AAAA,IAC9D,CAAA,CAAC;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,cAA4B,IAAE;AAC/C,UAAA,KAAK,gBAAgB,eAAe,WAAW;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,SAAwB,IAAE;AACtC,UAAA,KAAK,gBAAgB,UAAU,MAAM;AAAA,EAC5C;AACA;"}
|
|
1
|
+
{"version":3,"file":"customTypesApi.js","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype ItemType = CustomType | SharedSlice;\ntype ItemTypePath = \"customtypes\" | \"slices\";\ntype ItemOperation = \"insert\" | \"update\";\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(path, { data });\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tprivate async getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(endpoint);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices);\n\t}\n\n\t/**\n\t * Get a custom type by its id.\n\t *\n\t * @param customTypeId - The id of the custom type to get.\n\t */\n\tasync getTypeById(customTypeId: string): Promise<CustomType> {\n\t\tconst remoteItems = await this.getRemoteItems(\"customtypes\");\n\n\t\tconst remoteItem = remoteItems.find((remote) => remote.id === customTypeId);\n\t\tif (!remoteItem || \"type\" in remoteItem) {\n\t\t\tthrow new Error(`Custom type ${customTypeId} not found`);\n\t\t}\n\n\t\treturn remoteItem;\n\t}\n}\n"],"names":[],"mappings":";;;AAmBM,MAAO,6BAA6B,uBAAsB;AAAA,EAC/D,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYQ,MAAM,OACb,UACA,WACA,MAAc;AAER,UAAA,WAAW,OAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,MAAM,E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A,MAAM,YAAY,cAAoB;AACrC,UAAM,cAAc,MAAM,KAAK,eAAe,aAAa;AAE3D,UAAM,aAAa,YAAY,KAAK,CAAC,WAAW,OAAO,OAAO,YAAY;AACtE,QAAA,CAAC,cAAc,UAAU,YAAY;AACxC,YAAM,IAAI,MAAM,eAAe,YAAY,YAAY;AAAA,IACxD;AAEO,WAAA;AAAA,EACR;AACA;"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
const axios = require("axios");
|
|
10
|
+
const log = require("../utils/log.cjs");
|
|
11
|
+
const strings = require("../utils/strings.cjs");
|
|
12
|
+
class IntegrationFieldsClient {
|
|
13
|
+
constructor(baseURL, config) {
|
|
14
|
+
__publicField(this, "baseURL");
|
|
15
|
+
__publicField(this, "customTypesApiClient");
|
|
16
|
+
__publicField(this, "wroomClient");
|
|
17
|
+
__publicField(this, "repository");
|
|
18
|
+
__publicField(this, "tokens", {});
|
|
19
|
+
this.baseURL = baseURL;
|
|
20
|
+
this.customTypesApiClient = config.customTypesApiClient;
|
|
21
|
+
this.wroomClient = config.wroomClient;
|
|
22
|
+
this.repository = config.repository;
|
|
23
|
+
}
|
|
24
|
+
async getClient(catalogId) {
|
|
25
|
+
const token = this.tokens[catalogId] || await this.createToken(catalogId);
|
|
26
|
+
const client = axios.create({
|
|
27
|
+
baseURL: `${this.baseURL}/if/`,
|
|
28
|
+
withCredentials: true,
|
|
29
|
+
validateStatus: () => true,
|
|
30
|
+
headers: {
|
|
31
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
32
|
+
Authorization: `Bearer ${token}`
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return client;
|
|
36
|
+
}
|
|
37
|
+
async addCatalog({ name, description }) {
|
|
38
|
+
const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/pushcustom", {
|
|
39
|
+
"catalog-name": name,
|
|
40
|
+
"catalog-description": description
|
|
41
|
+
});
|
|
42
|
+
const { data, status } = response;
|
|
43
|
+
const success = status === 200 || status === 400 && data.includes("Already existing integration field");
|
|
44
|
+
if (!success) {
|
|
45
|
+
log.logHttpResponse(response);
|
|
46
|
+
throw new Error(`Could not add integration field catalog ${name}`);
|
|
47
|
+
}
|
|
48
|
+
return `${this.repository}--${strings.toSnakeCase(name)}`;
|
|
49
|
+
}
|
|
50
|
+
async createToken(catalogId) {
|
|
51
|
+
const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/createtoken", {
|
|
52
|
+
"catalog-id": catalogId
|
|
53
|
+
});
|
|
54
|
+
const { data: tokenData, status } = response;
|
|
55
|
+
if (status !== 200) {
|
|
56
|
+
log.logHttpResponse(response);
|
|
57
|
+
throw new Error(`Could not create token for integration field catalog ${catalogId}`);
|
|
58
|
+
}
|
|
59
|
+
const token = tokenData[0];
|
|
60
|
+
this.tokens[catalogId] = token;
|
|
61
|
+
return token;
|
|
62
|
+
}
|
|
63
|
+
async addDataToCatalog({ catalogId, data }) {
|
|
64
|
+
const client = await this.getClient(catalogId);
|
|
65
|
+
const response = await client.post(`/write/${catalogId}`, JSON.stringify(data));
|
|
66
|
+
const { status } = response;
|
|
67
|
+
if (status !== 200) {
|
|
68
|
+
log.logHttpResponse(response);
|
|
69
|
+
throw new Error(`Could not add data to integration field catalog ${catalogId}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async addToCustomType({ catalogId, customTypeId, fieldId }) {
|
|
73
|
+
const customType = await this.customTypesApiClient.getTypeById(customTypeId);
|
|
74
|
+
const field = customType.json.Main[fieldId];
|
|
75
|
+
if (!field || field.type !== "IntegrationFields") {
|
|
76
|
+
throw new Error(`Field ${fieldId} not found or is not an Integration Field`);
|
|
77
|
+
}
|
|
78
|
+
field.config = { ...field.config ?? {}, catalog: catalogId };
|
|
79
|
+
await this.customTypesApiClient.createCustomTypes([customType]);
|
|
80
|
+
}
|
|
81
|
+
async setupIntegrationFields(integrationFields) {
|
|
82
|
+
for (const integrationField of integrationFields) {
|
|
83
|
+
const catalogId = await this.addCatalog({
|
|
84
|
+
name: integrationField.name,
|
|
85
|
+
description: integrationField.description
|
|
86
|
+
});
|
|
87
|
+
await this.addDataToCatalog({
|
|
88
|
+
catalogId,
|
|
89
|
+
data: integrationField.data
|
|
90
|
+
});
|
|
91
|
+
await this.addToCustomType({
|
|
92
|
+
catalogId,
|
|
93
|
+
customTypeId: integrationField.customTypeId,
|
|
94
|
+
fieldId: integrationField.fieldId
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.IntegrationFieldsClient = IntegrationFieldsClient;
|
|
100
|
+
//# sourceMappingURL=integrationFields.cjs.map
|
|
@@ -0,0 +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/createtoken\",\n\t\t\t{\n\t\t\t\t\"catalog-id\": catalogId,\n\t\t\t},\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,EAAE;AAAA,IAClE;AAEA,WAAO,GAAG,KAAK,UAAU,KAAKC,oBAAY,IAAI,CAAC;AAAA,EAChD;AAAA,EAEQ,MAAM,YAAY,WAAiB;AAC1C,UAAM,WAAW,MAAM,KAAK,YAAY,KACvC,KAAK,YACL,8CACA;AAAA,MACC,cAAc;AAAA,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cAAc,iBAAiB;AAAA,QAC/B,SAAS,iBAAiB;AAAA,MAAA,CAC1B;AAAA,IACF;AAAA,EACD;AACA;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IntegrationFieldConfig } from "../types";
|
|
2
|
+
import { CustomTypesApiClient } from "./customTypesApi";
|
|
3
|
+
import { WroomClient } from "./wroom";
|
|
4
|
+
/**
|
|
5
|
+
* Client for interacting with Integration Fields routes to create integration
|
|
6
|
+
* field catalogs and add them to custom type fields.
|
|
7
|
+
*/
|
|
8
|
+
export declare class IntegrationFieldsClient {
|
|
9
|
+
private readonly baseURL;
|
|
10
|
+
private readonly customTypesApiClient;
|
|
11
|
+
private readonly wroomClient;
|
|
12
|
+
private readonly repository;
|
|
13
|
+
private readonly tokens;
|
|
14
|
+
constructor(baseURL: string, config: {
|
|
15
|
+
customTypesApiClient: CustomTypesApiClient;
|
|
16
|
+
wroomClient: WroomClient;
|
|
17
|
+
repository: string;
|
|
18
|
+
});
|
|
19
|
+
private getClient;
|
|
20
|
+
private addCatalog;
|
|
21
|
+
private createToken;
|
|
22
|
+
private addDataToCatalog;
|
|
23
|
+
private addToCustomType;
|
|
24
|
+
setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import axios from "axios";
|
|
8
|
+
import { logHttpResponse } from "../utils/log.js";
|
|
9
|
+
import { toSnakeCase } from "../utils/strings.js";
|
|
10
|
+
class IntegrationFieldsClient {
|
|
11
|
+
constructor(baseURL, config) {
|
|
12
|
+
__publicField(this, "baseURL");
|
|
13
|
+
__publicField(this, "customTypesApiClient");
|
|
14
|
+
__publicField(this, "wroomClient");
|
|
15
|
+
__publicField(this, "repository");
|
|
16
|
+
__publicField(this, "tokens", {});
|
|
17
|
+
this.baseURL = baseURL;
|
|
18
|
+
this.customTypesApiClient = config.customTypesApiClient;
|
|
19
|
+
this.wroomClient = config.wroomClient;
|
|
20
|
+
this.repository = config.repository;
|
|
21
|
+
}
|
|
22
|
+
async getClient(catalogId) {
|
|
23
|
+
const token = this.tokens[catalogId] || await this.createToken(catalogId);
|
|
24
|
+
const client = axios.create({
|
|
25
|
+
baseURL: `${this.baseURL}/if/`,
|
|
26
|
+
withCredentials: true,
|
|
27
|
+
validateStatus: () => true,
|
|
28
|
+
headers: {
|
|
29
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
30
|
+
Authorization: `Bearer ${token}`
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return client;
|
|
34
|
+
}
|
|
35
|
+
async addCatalog({ name, description }) {
|
|
36
|
+
const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/pushcustom", {
|
|
37
|
+
"catalog-name": name,
|
|
38
|
+
"catalog-description": description
|
|
39
|
+
});
|
|
40
|
+
const { data, status } = response;
|
|
41
|
+
const success = status === 200 || status === 400 && data.includes("Already existing integration field");
|
|
42
|
+
if (!success) {
|
|
43
|
+
logHttpResponse(response);
|
|
44
|
+
throw new Error(`Could not add integration field catalog ${name}`);
|
|
45
|
+
}
|
|
46
|
+
return `${this.repository}--${toSnakeCase(name)}`;
|
|
47
|
+
}
|
|
48
|
+
async createToken(catalogId) {
|
|
49
|
+
const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/createtoken", {
|
|
50
|
+
"catalog-id": catalogId
|
|
51
|
+
});
|
|
52
|
+
const { data: tokenData, status } = response;
|
|
53
|
+
if (status !== 200) {
|
|
54
|
+
logHttpResponse(response);
|
|
55
|
+
throw new Error(`Could not create token for integration field catalog ${catalogId}`);
|
|
56
|
+
}
|
|
57
|
+
const token = tokenData[0];
|
|
58
|
+
this.tokens[catalogId] = token;
|
|
59
|
+
return token;
|
|
60
|
+
}
|
|
61
|
+
async addDataToCatalog({ catalogId, data }) {
|
|
62
|
+
const client = await this.getClient(catalogId);
|
|
63
|
+
const response = await client.post(`/write/${catalogId}`, JSON.stringify(data));
|
|
64
|
+
const { status } = response;
|
|
65
|
+
if (status !== 200) {
|
|
66
|
+
logHttpResponse(response);
|
|
67
|
+
throw new Error(`Could not add data to integration field catalog ${catalogId}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async addToCustomType({ catalogId, customTypeId, fieldId }) {
|
|
71
|
+
const customType = await this.customTypesApiClient.getTypeById(customTypeId);
|
|
72
|
+
const field = customType.json.Main[fieldId];
|
|
73
|
+
if (!field || field.type !== "IntegrationFields") {
|
|
74
|
+
throw new Error(`Field ${fieldId} not found or is not an Integration Field`);
|
|
75
|
+
}
|
|
76
|
+
field.config = { ...field.config ?? {}, catalog: catalogId };
|
|
77
|
+
await this.customTypesApiClient.createCustomTypes([customType]);
|
|
78
|
+
}
|
|
79
|
+
async setupIntegrationFields(integrationFields) {
|
|
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
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
IntegrationFieldsClient
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=integrationFields.js.map
|
|
@@ -0,0 +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/createtoken\",\n\t\t\t{\n\t\t\t\t\"catalog-id\": catalogId,\n\t\t\t},\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,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,KAA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AA,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;"}
|
|
@@ -10,6 +10,7 @@ const assetApi = require("../clients/assetApi.cjs");
|
|
|
10
10
|
const authenticationApi = require("../clients/authenticationApi.cjs");
|
|
11
11
|
const coreApi = require("../clients/coreApi.cjs");
|
|
12
12
|
const customTypesApi = require("../clients/customTypesApi.cjs");
|
|
13
|
+
const integrationFields = require("../clients/integrationFields.cjs");
|
|
13
14
|
const manageV2 = require("../clients/manageV2.cjs");
|
|
14
15
|
const migrationApi = require("../clients/migrationApi.cjs");
|
|
15
16
|
const wroom = require("../clients/wroom.cjs");
|
|
@@ -60,7 +61,9 @@ class RepositoriesManager {
|
|
|
60
61
|
authenticationApi: `${protocol}://auth.${url.hostname}`,
|
|
61
62
|
customTypesApi: `${protocol}://customtypes.${url.hostname}`,
|
|
62
63
|
migrationApi: `${protocol}://migration.${url.hostname}`,
|
|
63
|
-
assetApi: `${protocol}://asset-api.${url.hostname}
|
|
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?
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
/**
|
|
@@ -158,7 +161,12 @@ class RepositoriesManager {
|
|
|
158
161
|
authToken,
|
|
159
162
|
repository: repository$1
|
|
160
163
|
});
|
|
161
|
-
|
|
164
|
+
const integrationFieldsClient = urlConfig.integrationFieldApi ? new integrationFields.IntegrationFieldsClient(urlConfig.integrationFieldApi, {
|
|
165
|
+
customTypesApiClient: customTypeClient,
|
|
166
|
+
wroomClient: this.wroomClient,
|
|
167
|
+
repository: repository$1
|
|
168
|
+
}) : void 0;
|
|
169
|
+
return new repository.RepositoryManager(repository$1, coreApiClient, this.authClient, this.wroomClient, customTypeClient, migrationApiClient, assetApiClient, this.manageV2Client, integrationFieldsClient);
|
|
162
170
|
}
|
|
163
171
|
}
|
|
164
172
|
exports.RepositoriesManager = RepositoriesManager;
|
|
@@ -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 { 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};\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\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);\n\t}\n}\n"],"names":["EnvVariableManager","WroomClient","AuthenticationApiClient","ManageV2Client","logger","randomString","logHttpResponse","repository","CustomTypesApiClient","getRepositoryUrl","CoreApiClient","MigrationApiClient","AssetApiClient","RepositoryManager"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6Ba,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,UAAU,SACtB,KAAK,OAAO,YACZ,KAAK,OAAO,OAAO;AAEf,SAAA,aAAa,IAAIC,kBACrB,wBAAA,KAAK,OAAO,UAAU,mBACtB,KAAK,OAAO,UAAU;AAElB,SAAA,iBA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AAA,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;AAED,WAAO,IAAIM,WAAAA,kBACVN,cACA,eACA,KAAK,YACL,KAAK,aACL,kBACA,oBACA,gBACA,KAAK,cAAc;AAAA,EAErB;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}/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,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AY,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;;;"}
|
|
@@ -8,6 +8,7 @@ import { AssetApiClient } from "../clients/assetApi.js";
|
|
|
8
8
|
import { AuthenticationApiClient } from "../clients/authenticationApi.js";
|
|
9
9
|
import { CoreApiClient } from "../clients/coreApi.js";
|
|
10
10
|
import { CustomTypesApiClient } from "../clients/customTypesApi.js";
|
|
11
|
+
import { IntegrationFieldsClient } from "../clients/integrationFields.js";
|
|
11
12
|
import { ManageV2Client } from "../clients/manageV2.js";
|
|
12
13
|
import { MigrationApiClient } from "../clients/migrationApi.js";
|
|
13
14
|
import { WroomClient } from "../clients/wroom.js";
|
|
@@ -58,7 +59,9 @@ class RepositoriesManager {
|
|
|
58
59
|
authenticationApi: `${protocol}://auth.${url.hostname}`,
|
|
59
60
|
customTypesApi: `${protocol}://customtypes.${url.hostname}`,
|
|
60
61
|
migrationApi: `${protocol}://migration.${url.hostname}`,
|
|
61
|
-
assetApi: `${protocol}://asset-api.${url.hostname}
|
|
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?
|
|
62
65
|
};
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
@@ -156,7 +159,12 @@ class RepositoriesManager {
|
|
|
156
159
|
authToken,
|
|
157
160
|
repository
|
|
158
161
|
});
|
|
159
|
-
|
|
162
|
+
const integrationFieldsClient = urlConfig.integrationFieldApi ? new IntegrationFieldsClient(urlConfig.integrationFieldApi, {
|
|
163
|
+
customTypesApiClient: customTypeClient,
|
|
164
|
+
wroomClient: this.wroomClient,
|
|
165
|
+
repository
|
|
166
|
+
}) : void 0;
|
|
167
|
+
return new RepositoryManager(repository, coreApiClient, this.authClient, this.wroomClient, customTypeClient, migrationApiClient, assetApiClient, this.manageV2Client, integrationFieldsClient);
|
|
160
168
|
}
|
|
161
169
|
}
|
|
162
170
|
export {
|
|
@@ -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 { 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};\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\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);\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA6Ba,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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AAA,IAAA,CACA,IACA;AACH,UAAM,iBAAiB,IAAI,eAAe,UAAU,UAAU;AAAA,MAC7D;AAAA,MACA;AAAA,IAAA,CACA;AAED,WAAO,IAAI,kBACV,YACA,eACA,KAAK,YACL,KAAK,aACL,kBACA,oBACA,gBACA,KAAK,cAAc;AAAA,EAErB;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}/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,KAAK,OAAO,cAAc;AAM3B,SAAK,OAAO,UAAU,iBAC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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;"}
|
|
@@ -11,7 +11,7 @@ const contentApi = require("../clients/contentApi.cjs");
|
|
|
11
11
|
const log = require("../utils/log.cjs");
|
|
12
12
|
const urls = require("../utils/urls.cjs");
|
|
13
13
|
class RepositoryManager {
|
|
14
|
-
constructor(name, coreApiClient, authApiClient, wroomClient, customTypesApiClient, migrationApiClient, assetApiClient, manageV2Client) {
|
|
14
|
+
constructor(name, coreApiClient, authApiClient, wroomClient, customTypesApiClient, migrationApiClient, assetApiClient, manageV2Client, integrationFieldsClient) {
|
|
15
15
|
__publicField(this, "name");
|
|
16
16
|
__publicField(this, "coreApiClient");
|
|
17
17
|
__publicField(this, "authApiClient");
|
|
@@ -20,6 +20,7 @@ class RepositoryManager {
|
|
|
20
20
|
__publicField(this, "migrationApiClient");
|
|
21
21
|
__publicField(this, "assetApiClient");
|
|
22
22
|
__publicField(this, "manageV2Client");
|
|
23
|
+
__publicField(this, "integrationFieldsClient");
|
|
23
24
|
this.name = name;
|
|
24
25
|
this.coreApiClient = coreApiClient;
|
|
25
26
|
this.authApiClient = authApiClient;
|
|
@@ -28,6 +29,7 @@ class RepositoryManager {
|
|
|
28
29
|
this.migrationApiClient = migrationApiClient;
|
|
29
30
|
this.assetApiClient = assetApiClient;
|
|
30
31
|
this.manageV2Client = manageV2Client;
|
|
32
|
+
this.integrationFieldsClient = integrationFieldsClient;
|
|
31
33
|
}
|
|
32
34
|
async configure(config) {
|
|
33
35
|
const hasLangConfig = config.defaultLocale || config.locales || config.customLocale;
|
|
@@ -77,6 +79,7 @@ class RepositoryManager {
|
|
|
77
79
|
}
|
|
78
80
|
if (config.integrationFields) {
|
|
79
81
|
await this.toggleIntegrationFields(true);
|
|
82
|
+
await this.setupIntegrationFields(config.integrationFields);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
/** @returns the repository base url, like https://my-repo.prismic.io */
|
|
@@ -525,6 +528,16 @@ class RepositoryManager {
|
|
|
525
528
|
});
|
|
526
529
|
return result;
|
|
527
530
|
}
|
|
531
|
+
async setupIntegrationFields(integrationFields) {
|
|
532
|
+
const profiler = log.logger.startTimer();
|
|
533
|
+
if (!this.integrationFieldsClient) {
|
|
534
|
+
throw new Error("Integration Fields client not found. Did you provide a integration fields api url in the configuration?");
|
|
535
|
+
}
|
|
536
|
+
await this.integrationFieldsClient.setupIntegrationFields(integrationFields);
|
|
537
|
+
profiler.done({
|
|
538
|
+
message: `Integration Fields setup`
|
|
539
|
+
});
|
|
540
|
+
}
|
|
528
541
|
}
|
|
529
542
|
exports.RepositoryManager = RepositoryManager;
|
|
530
543
|
//# sourceMappingURL=repository.cjs.map
|