@prismicio/e2e-tests-utils 1.12.0-alpha.0 → 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/clients/manageV2.cjs +15 -1
- package/dist/clients/manageV2.cjs.map +1 -1
- package/dist/clients/manageV2.d.ts +11 -0
- package/dist/clients/manageV2.js +15 -1
- package/dist/clients/manageV2.js.map +1 -1
- package/dist/clients/wroom.cjs +1 -1
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.js +1 -1
- package/dist/clients/wroom.js.map +1 -1
- 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 +33 -1
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +12 -1
- package/dist/managers/repository.js +33 -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/clients/manageV2.ts +18 -1
- package/src/clients/wroom.ts +1 -1
- package/src/managers/repositories.ts +13 -0
- package/src/managers/repository.ts +55 -0
- 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<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices);\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;AAErC,QAAA,CAAC,OAAO,MAAM;AACjBA,UAAA,yBAAyB,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.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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,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;;"}
|
|
@@ -36,4 +36,10 @@ export declare class CustomTypesApiClient extends AuthenticatedApiClient {
|
|
|
36
36
|
* @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,+BAA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odash.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,SA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;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,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,oCAAo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EA,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;;"}
|
|
@@ -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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AAM,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;"}
|
|
@@ -47,6 +47,20 @@ class ManageV2Client {
|
|
|
47
47
|
author: ManageV2StaticAuthor
|
|
48
48
|
});
|
|
49
49
|
}));
|
|
50
|
+
/**
|
|
51
|
+
* The function `toggleIntegrationFields` enables or disables the Integration
|
|
52
|
+
* Fields feature
|
|
53
|
+
*
|
|
54
|
+
* @param repository - The Repository name
|
|
55
|
+
* @param enabled - The feature new status
|
|
56
|
+
*/
|
|
57
|
+
__publicField(this, "toggleIntegrationFields", this.assertTokenExist((params) => {
|
|
58
|
+
return this.client.post("/repository/toggleIntegrationFields", {
|
|
59
|
+
domain: params.repository,
|
|
60
|
+
enabled: params.enabled,
|
|
61
|
+
author: ManageV2StaticAuthor
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
50
64
|
/**
|
|
51
65
|
* The function `changePlan` changes the plan of a repository the database
|
|
52
66
|
*
|
|
@@ -102,7 +116,7 @@ class ManageV2Client {
|
|
|
102
116
|
});
|
|
103
117
|
this.client.interceptors.response.use((response) => {
|
|
104
118
|
const cookies$1 = response.headers["set-cookie"];
|
|
105
|
-
if (cookies$1 && cookies.extractCookie(cookies$1, "
|
|
119
|
+
if (cookies$1 && cookies.extractCookie(cookies$1, "SESSION")) {
|
|
106
120
|
this.client.defaults.headers["Cookie"] = cookies$1;
|
|
107
121
|
}
|
|
108
122
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manageV2.cjs","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\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 ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"
|
|
1
|
+
{"version":3,"file":"manageV2.cjs","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\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 ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * The function generates a JWT token using the provided configuration\n\t * parameters.\n\t *\n\t * @param {ManageV2Config} config - The `config` parameter in the\n\t * `generateToken` function is of type `ManageV2Config`. It contains the\n\t * following properties:\n\t *\n\t * @returns A JSON Web Token (JWT) is being returned by the `generateToken`\n\t * function. The token is signed using the provided `config.secret` with the\n\t * HS256 algorithm and includes the specified audience and issuer values.\n\t */\n\tprivate generateToken(config: ManageV2Config): string {\n\t\treturn jwt.sign({}, config.secret, {\n\t\t\talgorithm: \"HS256\",\n\t\t\taudience: config.audience,\n\t\t\tissuer: \"prismic.io\",\n\t\t});\n\t}\n\n\t/**\n\t * The function `assertTokenExist` checks if a token exists before executing a\n\t * given function.\n\t *\n\t * @param f - The `assertTokenExist` function takes a function `f` as a\n\t * parameter. This function `f` should accept a parameter of type\n\t * `Parameters` and return a Promise that resolves to an AxiosResponse. The\n\t * `assertTokenExist` function ensures that a token is not null before\n\t * calling the provided\n\t *\n\t * @returns A function is being returned that takes a parameter of type\n\t * Parameters and checks if the token is null. If the token is null, an\n\t * error is thrown. Otherwise, the function f is called with the provided\n\t * parameters.\n\t */\n\tprivate assertTokenExist<Parameters>(\n\t\tf: (_: Parameters) => Promise<AxiosResponse>,\n\t) {\n\t\treturn (params: Parameters) => {\n\t\t\tif (this.token === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Undefined configuration for ManageV2 while trying to use it's routes\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\treturn f(params);\n\t\t\t}\n\t\t};\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/**\n\t * The function `toggleRolePerLocal` enables or disables the RolesPerLocale\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleRolePerLocal = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleRolesPerLocale\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `toggleCustomRoles` enables or disables the CustomRoles\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleCustomRoles = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleCustomRoles\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `toggleIntegrationFields` enables or disables the Integration\n\t * Fields feature\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleIntegrationFields = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleIntegrationFields\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `changePlan` changes the plan of a repository the database\n\t *\n\t * @param repository - The Repository name\n\t * @param newPlanId - The new planId\n\t * @param bypassManualBilling - Beware that using this will not verify that\n\t * the database and Stripe are in sync\n\t */\n\tchangePlan = this.assertTokenExist(\n\t\t({\n\t\t\trepository,\n\t\t\tnewPlanId,\n\t\t\tbypassManualBilling = false,\n\t\t}: {\n\t\t\trepository: string;\n\t\t\tnewPlanId: string;\n\t\t\tbypassManualBilling?: boolean;\n\t\t}) => {\n\t\t\treturn this.client.post(\n\t\t\t\t`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,\n\t\t\t\t{\n\t\t\t\t\tdomain: repository,\n\t\t\t\t\tnewPlan: newPlanId,\n\t\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t);\n\n\t/**\n\t * The function `addUserToRepository` adds a user corresponding to the email\n\t * to the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\taddUserToRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/addUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `removeUserFromRepository` removes a user corresponding to the\n\t * email from the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\tremoveUserFromRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/removeUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n}\n"],"names":["cookies","extractCookie"],"mappings":";;;;;;;;;;;AAOA,MAAM,uBAAuB;MAMhB,eAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1B,YAAY,SAAiB,QAAmC;AAPvD;AACD;AAAA,iCAAuB;AA0F/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAAqB,KAAK,iBACzB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,oCAAoC;AAAA,QAC3D,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6CAAoB,KAAK,iBACxB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,iCAAiC;AAAA,QACxD,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mDAA0B,KAAK,iBAC9B,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,uCAAuC;AAAA,QAC9D,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAWF;AAAA;AAAA;AAAA;AAAA;AAAA;A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,cAAc,QAAsB;AAC3C,WAAO,IAAI,KAAK,IAAI,OAAO,QAAQ;AAAA,MAClC,WAAW;AAAA,MACX,UAAU,OAAO;AAAA,MACjB,QAAQ;AAAA,IAAA,CACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBQ,iBACP,GAA4C;AAE5C,WAAO,CAAC,WAAsB;AACzB,UAAA,KAAK,UAAU,MAAM;AAClB,cAAA,IAAI,MACT,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MAChB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAmHA;;"}
|
|
@@ -64,6 +64,17 @@ export declare class ManageV2Client {
|
|
|
64
64
|
repository: string;
|
|
65
65
|
enabled: boolean;
|
|
66
66
|
}) => Promise<AxiosResponse<any, any>>;
|
|
67
|
+
/**
|
|
68
|
+
* The function `toggleIntegrationFields` enables or disables the Integration
|
|
69
|
+
* Fields feature
|
|
70
|
+
*
|
|
71
|
+
* @param repository - The Repository name
|
|
72
|
+
* @param enabled - The feature new status
|
|
73
|
+
*/
|
|
74
|
+
toggleIntegrationFields: (params: {
|
|
75
|
+
repository: string;
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
}) => Promise<AxiosResponse<any, any>>;
|
|
67
78
|
/**
|
|
68
79
|
* The function `changePlan` changes the plan of a repository the database
|
|
69
80
|
*
|
package/dist/clients/manageV2.js
CHANGED
|
@@ -45,6 +45,20 @@ class ManageV2Client {
|
|
|
45
45
|
author: ManageV2StaticAuthor
|
|
46
46
|
});
|
|
47
47
|
}));
|
|
48
|
+
/**
|
|
49
|
+
* The function `toggleIntegrationFields` enables or disables the Integration
|
|
50
|
+
* Fields feature
|
|
51
|
+
*
|
|
52
|
+
* @param repository - The Repository name
|
|
53
|
+
* @param enabled - The feature new status
|
|
54
|
+
*/
|
|
55
|
+
__publicField(this, "toggleIntegrationFields", this.assertTokenExist((params) => {
|
|
56
|
+
return this.client.post("/repository/toggleIntegrationFields", {
|
|
57
|
+
domain: params.repository,
|
|
58
|
+
enabled: params.enabled,
|
|
59
|
+
author: ManageV2StaticAuthor
|
|
60
|
+
});
|
|
61
|
+
}));
|
|
48
62
|
/**
|
|
49
63
|
* The function `changePlan` changes the plan of a repository the database
|
|
50
64
|
*
|
|
@@ -100,7 +114,7 @@ class ManageV2Client {
|
|
|
100
114
|
});
|
|
101
115
|
this.client.interceptors.response.use((response) => {
|
|
102
116
|
const cookies = response.headers["set-cookie"];
|
|
103
|
-
if (cookies && extractCookie(cookies, "
|
|
117
|
+
if (cookies && extractCookie(cookies, "SESSION")) {
|
|
104
118
|
this.client.defaults.headers["Cookie"] = cookies;
|
|
105
119
|
}
|
|
106
120
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manageV2.js","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\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 ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"
|
|
1
|
+
{"version":3,"file":"manageV2.js","sources":["../../../src/clients/manageV2.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\nimport jwt from \"jsonwebtoken\";\n\nimport { ManageV2Config } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\n\nconst ManageV2StaticAuthor = \"prismic-e2e-tests-utils\";\n\n/**\n * Client for interacting with ManageV2 routes to perform operations on\n * repositories.\n */\nexport class ManageV2Client {\n\treadonly client: AxiosInstance; // Not private to have it available on tests\n\tprivate token: string | null = null;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param config - ManageV2 configuration variable to call ManageV2.\n\t */\n\tconstructor(baseUrl: string, config?: ManageV2Config | undefined) {\n\t\tthis.token = config ? this.generateToken(config) : null;\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL: `${baseUrl}/manageroutes/`,\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 ${this.token}`,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * The function generates a JWT token using the provided configuration\n\t * parameters.\n\t *\n\t * @param {ManageV2Config} config - The `config` parameter in the\n\t * `generateToken` function is of type `ManageV2Config`. It contains the\n\t * following properties:\n\t *\n\t * @returns A JSON Web Token (JWT) is being returned by the `generateToken`\n\t * function. The token is signed using the provided `config.secret` with the\n\t * HS256 algorithm and includes the specified audience and issuer values.\n\t */\n\tprivate generateToken(config: ManageV2Config): string {\n\t\treturn jwt.sign({}, config.secret, {\n\t\t\talgorithm: \"HS256\",\n\t\t\taudience: config.audience,\n\t\t\tissuer: \"prismic.io\",\n\t\t});\n\t}\n\n\t/**\n\t * The function `assertTokenExist` checks if a token exists before executing a\n\t * given function.\n\t *\n\t * @param f - The `assertTokenExist` function takes a function `f` as a\n\t * parameter. This function `f` should accept a parameter of type\n\t * `Parameters` and return a Promise that resolves to an AxiosResponse. The\n\t * `assertTokenExist` function ensures that a token is not null before\n\t * calling the provided\n\t *\n\t * @returns A function is being returned that takes a parameter of type\n\t * Parameters and checks if the token is null. If the token is null, an\n\t * error is thrown. Otherwise, the function f is called with the provided\n\t * parameters.\n\t */\n\tprivate assertTokenExist<Parameters>(\n\t\tf: (_: Parameters) => Promise<AxiosResponse>,\n\t) {\n\t\treturn (params: Parameters) => {\n\t\t\tif (this.token === null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Undefined configuration for ManageV2 while trying to use it's routes\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\treturn f(params);\n\t\t\t}\n\t\t};\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/**\n\t * The function `toggleRolePerLocal` enables or disables the RolesPerLocale\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleRolePerLocal = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleRolesPerLocale\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `toggleCustomRoles` enables or disables the CustomRoles\n\t * workflow\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleCustomRoles = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleCustomRoles\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `toggleIntegrationFields` enables or disables the Integration\n\t * Fields feature\n\t *\n\t * @param repository - The Repository name\n\t * @param enabled - The feature new status\n\t */\n\ttoggleIntegrationFields = this.assertTokenExist(\n\t\t(params: { repository: string; enabled: boolean }) => {\n\t\t\treturn this.client.post(\"/repository/toggleIntegrationFields\", {\n\t\t\t\tdomain: params.repository,\n\t\t\t\tenabled: params.enabled,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `changePlan` changes the plan of a repository the database\n\t *\n\t * @param repository - The Repository name\n\t * @param newPlanId - The new planId\n\t * @param bypassManualBilling - Beware that using this will not verify that\n\t * the database and Stripe are in sync\n\t */\n\tchangePlan = this.assertTokenExist(\n\t\t({\n\t\t\trepository,\n\t\t\tnewPlanId,\n\t\t\tbypassManualBilling = false,\n\t\t}: {\n\t\t\trepository: string;\n\t\t\tnewPlanId: string;\n\t\t\tbypassManualBilling?: boolean;\n\t\t}) => {\n\t\t\treturn this.client.post(\n\t\t\t\t`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`,\n\t\t\t\t{\n\t\t\t\t\tdomain: repository,\n\t\t\t\t\tnewPlan: newPlanId,\n\t\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t);\n\n\t/**\n\t * The function `addUserToRepository` adds a user corresponding to the email\n\t * to the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\taddUserToRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/addUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n\n\t/**\n\t * The function `removeUserFromRepository` removes a user corresponding to the\n\t * email from the given repository\n\t *\n\t * @param repository - The Repository name\n\t * @param email - The user email\n\t */\n\tremoveUserFromRepository = this.assertTokenExist(\n\t\t({ repository, email }: { repository: string; email: string }) => {\n\t\t\treturn this.client.post(\"/repository/removeUser\", {\n\t\t\t\tdomain: repository,\n\t\t\t\temail: email,\n\t\t\t\tauthor: ManageV2StaticAuthor,\n\t\t\t});\n\t\t},\n\t);\n}\n"],"names":[],"mappings":";;;;;;;;;AAOA,MAAM,uBAAuB;MAMhB,eAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1B,YAAY,SAAiB,QAAmC;AAPvD;AACD;AAAA,iCAAuB;AA0F/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAAqB,KAAK,iBACzB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,oCAAoC;AAAA,QAC3D,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6CAAoB,KAAK,iBACxB,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,iCAAiC;AAAA,QACxD,QAAQ,OAAO;AAAA,QACf,SAAS,OAAO;AAAA,QAChB,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mDAA0B,KAAK,iBAC9B,CAAC,WAAoD;AAC7C,aAAA,KAAK,OAAO,KAAK,uCAAuC;AAAA,QAC9D,QAAQ,OAAO;A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ACP;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcQ,cAAc,QAAsB;AAC3C,WAAO,IAAI,KAAK,IAAI,OAAO,QAAQ;AAAA,MAClC,WAAW;AAAA,MACX,UAAU,OAAO;AAAA,MACjB,QAAQ;AAAA,IAAA,CACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBQ,iBACP,GAA4C;AAE5C,WAAO,CAAC,WAAsB;AACzB,UAAA,KAAK,UAAU,MAAM;AAClB,cAAA,IAAI,MACT,sEAAsE;AAAA,MAAA,OAEjE;AACN,eAAO,EAAE,MAAM;AAAA,MAChB;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,aAAU;AACF,WAAA,KAAK,OAAO;EACpB;AAmHA;"}
|
package/dist/clients/wroom.cjs
CHANGED
|
@@ -37,7 +37,7 @@ class WroomClient {
|
|
|
37
37
|
});
|
|
38
38
|
this.client.interceptors.response.use((response) => {
|
|
39
39
|
const cookies$1 = response.headers["set-cookie"];
|
|
40
|
-
if (cookies$1 && cookies.extractCookie(cookies$1, "
|
|
40
|
+
if (cookies$1 && cookies.extractCookie(cookies$1, "SESSION")) {
|
|
41
41
|
this.client.defaults.headers["Cookie"] = cookies$1;
|
|
42
42
|
}
|
|
43
43
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wroom.cjs","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/**\n * Client for interacting with the Wroom service to perform operations on\n * repositories.\n */\nexport class WroomClient {\n\tprivate readonly client: AxiosInstance;\n\tprivate loggedIn = false;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param auth - Authentication credentials.\n\t * @param cluster - Cluster where to create the repository (only work in\n\t * staging)\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t\tcluster?: string,\n\t) {\n\t\tconst clusterHeader = cluster\n\t\t\t? {\n\t\t\t\t\t\"X-Prismic-Cluster\": cluster,\n\t\t\t\t}\n\t\t\t: {};\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\txsrfCookieName: \"X_XSRF\",\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\t...clusterHeader,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"
|
|
1
|
+
{"version":3,"file":"wroom.cjs","sources":["../../../src/clients/wroom.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from \"axios\";\n\nimport { AuthConfig } from \"../types\";\n\nimport { extractCookie } from \"../utils/cookies\";\nimport { logHttpResponse, logger } from \"../utils/log\";\nimport { getRepositoryUrl } from \"../utils/urls\";\n\n/**\n * Client for interacting with the Wroom service to perform operations on\n * repositories.\n */\nexport class WroomClient {\n\tprivate readonly client: AxiosInstance;\n\tprivate loggedIn = false;\n\n\t/**\n\t * @param baseURL - The base URL of the Wroom app. ex: https://prismic.io\n\t * @param auth - Authentication credentials.\n\t * @param cluster - Cluster where to create the repository (only work in\n\t * staging)\n\t */\n\tconstructor(\n\t\tbaseURL: string,\n\t\tprivate readonly auth: AuthConfig,\n\t\tcluster?: string,\n\t) {\n\t\tconst clusterHeader = cluster\n\t\t\t? {\n\t\t\t\t\t\"X-Prismic-Cluster\": cluster,\n\t\t\t\t}\n\t\t\t: {};\n\n\t\tthis.client = axios.create({\n\t\t\tbaseURL,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\txsrfCookieName: \"X_XSRF\",\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\t...clusterHeader,\n\t\t\t},\n\t\t});\n\n\t\t// cookies are not forwarded automatically in a non-browser env\n\t\tthis.client.interceptors.response.use((response) => {\n\t\t\tconst cookies = response.headers[\"set-cookie\"];\n\t\t\tif (cookies && extractCookie(cookies, \"SESSION\")) {\n\t\t\t\tthis.client.defaults.headers[\"Cookie\"] = cookies;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t});\n\t}\n\n\tgetBaseURL(): string {\n\t\treturn this.client.getUri();\n\t}\n\n\t/** authenticated GET request on the wroom backend */\n\tasync get(repository: string | null, path: string): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\n\t\treturn this.client.get(url);\n\t}\n\n\t/** authenticated POST request on the wroom backend */\n\tasync post(\n\t\trepository: string | null,\n\t\tpath: string,\n\t\tdata?: unknown,\n\t): Promise<AxiosResponse> {\n\t\tif (!this.loggedIn) {\n\t\t\tawait this.login();\n\t\t}\n\n\t\tlet url = new URL(path, this.client.getUri()).toString();\n\t\tif (repository) {\n\t\t\turl = getRepositoryUrl(url, repository);\n\t\t}\n\t\tconst response = await this.client.post(url.toString(), data, {\n\t\t\tparams: {\n\t\t\t\t_: extractCookie(this.client.defaults.headers[\"Cookie\"], \"X_XSRF\"),\n\t\t\t},\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Update the role of a user in the repository\n\t *\n\t * @param {string} repository - The repository name\n\t * @param {string} email - The email of the user\n\t * @param {string} role - The new role to be given\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRole(\n\t\trepository: string,\n\t\temail: string,\n\t\trole: string,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email, profile: role });\n\t\tconst path = `/app/settings/users/profiles?${params.toString()}`;\n\n\t\treturn this.post(repository, path);\n\t}\n\n\t/**\n\t * Update the role of a user in the repository\n\t *\n\t * @param {string} repository - The repository name\n\t * @param {string} email - The email of the user\n\t * @param {string} rolePerLocal - The role per local object\n\t *\n\t * @returns The Axios Reponse\n\t */\n\tasync updateRolePerLocal(\n\t\trepository: string,\n\t\temail: string,\n\t\trolePerLocal: Record<string, string>,\n\t): Promise<AxiosResponse> {\n\t\tconst params = new URLSearchParams({ email });\n\t\tconst path = `/app/settings/users/rolesperlocale?${params.toString()}`;\n\n\t\treturn this.post(repository, path, rolePerLocal);\n\t}\n\n\t/**\n\t * Authenticate Wroom to call Wroom unofficial endpoints.\n\t *\n\t * @throws Error if the login to Wroom fails.\n\t */\n\tprivate async login(): Promise<void> {\n\t\tconst profiler = logger.startTimer();\n\t\tconst response = await this.client.post<string>(\"/authentication/signin\", {\n\t\t\temail: this.auth.email,\n\t\t\tpassword: this.auth.password,\n\t\t});\n\n\t\tif (response.status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\"Could not login to Prismic, check your credentials\");\n\t\t}\n\t\tthis.loggedIn = true;\n\t\tprofiler.done({ message: \"logged in to Prismic\" });\n\t}\n}\n"],"names":["cookies","extractCookie","getRepositoryUrl","logger","logHttpResponse"],"mappings":";;;;;;;;;;;;MAYa,YAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvB,YACC,SACiB,MACjB,SAAgB;AADC;AAXD;AACT,oCAAW;AAUD,SAAI,OAAJ;AAGjB,UAAM,gBAAgB,UACnB;AAAA,MACA,qBAAqB;AAAA,QAErB;AAEE,SAAA,SAAS,MAAM,OAAO;AAAA,MAC1B;AAAA,M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,YACA,OACA,MAAY;AAEZ,UAAM,SAAS,IAAI,gBAAgB,EAAE,OAAO,SAAS,MAAM;AAC3D,UAAM,OAAO,gCAAgC,OAAO,SAAA,CAAU;AAEvD,WAAA,KAAK,KAAK,YAAY,IAAI;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,mBACL,YACA,OACA,cAAoC;AAEpC,UAAM,SAAS,IAAI,gBAAgB,EAAE,MAAO,CAAA;AAC5C,UAAM,OAAO,sCAAsC,OAAO,SAAA,CAAU;AAEpE,WAAO,KAAK,KAAK,YAAY,MAAM,YAAY;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,MAAM,QAAK;AACZ,UAAA,WAAWE,WAAO;AACxB,UAAM,WAAW,MAAM,KAAK,OAAO,KAAa,0BAA0B;AAAA,MACzE,OAAO,KAAK,KAAK;AAAA,MACjB,UAAU,KAAK,KAAK;AAAA,IAAA,CACpB;AAEG,QAAA,SAAS,WAAW,KAAK;AAC5BC,UAAA,gBAAgB,QAAQ;AAClB,YAAA,IAAI,MAAM,oDAAoD;AAAA,IACrE;AACA,SAAK,WAAW;AAChB,aAAS,KAAK,EAAE,SAAS,uBAAwB,CAAA;AAAA,EAClD;AACA;;"}
|
package/dist/clients/wroom.js
CHANGED
|
@@ -35,7 +35,7 @@ class WroomClient {
|
|
|
35
35
|
});
|
|
36
36
|
this.client.interceptors.response.use((response) => {
|
|
37
37
|
const cookies = response.headers["set-cookie"];
|
|
38
|
-
if (cookies && extractCookie(cookies, "
|
|
38
|
+
if (cookies && extractCookie(cookies, "SESSION")) {
|
|
39
39
|
this.client.defaults.headers["Cookie"] = cookies;
|
|
40
40
|
}
|
|
41
41
|
return response;
|