@prismicio/e2e-tests-utils 1.2.0 → 1.3.1
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/authenticationApi.cjs +21 -2
- package/dist/clients/authenticationApi.cjs.map +1 -1
- package/dist/clients/authenticationApi.d.ts +3 -2
- package/dist/clients/authenticationApi.js +22 -3
- package/dist/clients/authenticationApi.js.map +1 -1
- package/dist/clients/contentApi.cjs +141 -0
- package/dist/clients/contentApi.cjs.map +1 -0
- package/dist/clients/contentApi.d.ts +106 -0
- package/dist/clients/contentApi.js +141 -0
- package/dist/clients/contentApi.js.map +1 -0
- package/dist/clients/coreApi.cjs +12 -2
- package/dist/clients/coreApi.cjs.map +1 -1
- package/dist/clients/coreApi.d.ts +1 -0
- package/dist/clients/coreApi.js +12 -2
- package/dist/clients/coreApi.js.map +1 -1
- package/dist/clients/customTypesApi.cjs +1 -0
- package/dist/clients/customTypesApi.cjs.map +1 -1
- package/dist/clients/customTypesApi.js +1 -0
- package/dist/clients/customTypesApi.js.map +1 -1
- package/dist/clients/manageV2.cjs +145 -0
- package/dist/clients/manageV2.cjs.map +1 -0
- package/dist/clients/manageV2.d.ts +91 -0
- package/dist/clients/manageV2.js +145 -0
- package/dist/clients/manageV2.js.map +1 -0
- package/dist/clients/migrationApi.cjs +36 -0
- package/dist/clients/migrationApi.cjs.map +1 -0
- package/dist/clients/migrationApi.d.ts +20 -0
- package/dist/clients/migrationApi.js +36 -0
- package/dist/clients/migrationApi.js.map +1 -0
- package/dist/clients/wroom.cjs +28 -0
- package/dist/clients/wroom.cjs.map +1 -1
- package/dist/clients/wroom.d.ts +22 -2
- package/dist/clients/wroom.js +28 -0
- package/dist/clients/wroom.js.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/managers/repositories.cjs +25 -18
- package/dist/managers/repositories.cjs.map +1 -1
- package/dist/managers/repositories.d.ts +12 -22
- package/dist/managers/repositories.js +25 -18
- package/dist/managers/repositories.js.map +1 -1
- package/dist/managers/repository.cjs +184 -41
- package/dist/managers/repository.cjs.map +1 -1
- package/dist/managers/repository.d.ts +77 -22
- package/dist/managers/repository.js +184 -41
- package/dist/managers/repository.js.map +1 -1
- package/dist/types.d.ts +20 -1
- package/dist/utils/cookies.cjs.map +1 -1
- package/dist/utils/cookies.js.map +1 -1
- package/dist/utils/log.cjs.map +1 -1
- package/dist/utils/log.js.map +1 -1
- package/package.json +9 -2
- package/src/clients/authenticationApi.ts +33 -4
- package/src/clients/contentApi.ts +235 -0
- package/src/clients/coreApi.ts +14 -1
- package/src/clients/manageV2.ts +178 -0
- package/src/clients/migrationApi.ts +69 -0
- package/src/clients/wroom.ts +42 -2
- package/src/index.ts +2 -0
- package/src/managers/repositories.ts +46 -37
- package/src/managers/repository.ts +263 -70
- package/src/types.ts +29 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\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\tasync function 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 result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(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\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(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.data;\n\t}\n\n\tasync function 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\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && 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 function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait 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 function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,SAAS;AAAA,MACR;AAAA,IACA;AAAA,EAAA,CACD;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,
|
|
1
|
+
{"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\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\tasync function 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 result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(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\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(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.data;\n\t}\n\n\tasync function 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\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && 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 function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait 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 function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":["logger","logHttpResponse"],"mappings":";;;;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,IACtB,SAAS;AAAA,MACR;AAAA,IACA;AAAA,EAAA,CACD;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AAEO,WAAA;AAAA,EAAA,CACP;AAYc,iBAAA,OACd,UACA,WACA,MAAc;AAER,UAAA,WAAWA,WAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,SAAS,MAAM,OAAO,KAAK,MAAM,MAAM,EAAE,SAAS,CAAE,EAAA,CAAE;AACxD,QAAA,CAAC,CAAC,KAAK,GAAG,EAAE,SAAS,OAAO,MAAM,GAAG;AACxCC,UAAA,gBAAgB,MAAM;AACtB,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AAAA,IAAA,CACrE;AAAA,EACF;AAEA,iBAAe,eACd,UAAsB;AAEtB,UAAM,SAAS,MAAM,OAAO,IAAI,QAAQ;AAExC,QAAI,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,GAAG;AACnCA,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AAEA,WAAO,OAAO;AAAA,EACf;AAEe,iBAAA,cACd,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;AAGA,iBAAe,gBACd,UACA,aAAyB,IAAE;AAErB,UAAA,cAAc,MAAM,eAAe,QAAQ;AACjD,UAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,cAAc,aAAa,SAAS;AAE5D,aAAO,aAAa,OAAO,UAAU,WAAW,SAAS;AAAA,IACzD,CAAA,CAAC;AAAA,EAEJ;AAOe,iBAAA,kBAAkB,cAA4B,IAAE;AACxD,UAAA,gBAAgB,eAAe,WAAW;AAAA,EACjD;AAOe,iBAAA,aAAa,SAAwB,IAAE;AAC/C,UAAA,gBAAgB,UAAU,MAAM;AAAA,EACvC;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypesApi.js","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\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\tasync function 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 result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(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\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(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.data;\n\t}\n\n\tasync function 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\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && 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 function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait 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 function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":[],"mappings":";;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,SAAS;AAAA,MACR;AAAA,IACA;AAAA,EAAA,CACD;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,
|
|
1
|
+
{"version":3,"file":"customTypesApi.js","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\nimport isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logHttpResponse, logger } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type CustomTypesClient = {\n\tcreateCustomTypes(customTypes: CustomType[]): Promise<void>;\n\tcreateSlices(slices: SharedSlice[]): Promise<void>;\n};\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport const createCustomTypesApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): CustomTypesClient => {\n\ttype ItemType = CustomType | SharedSlice;\n\ttype ItemTypePath = \"customtypes\" | \"slices\";\n\ttype ItemOperation = \"insert\" | \"update\";\n\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\n\t\treturn config;\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\tasync function 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 result = await client.post(path, data, { headers: {} });\n\t\tif (![201, 204].includes(result.status)) {\n\t\t\tlogHttpResponse(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\tasync function getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst result = await client.get(endpoint);\n\n\t\tif (![200].includes(result.status)) {\n\t\t\tlogHttpResponse(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.data;\n\t}\n\n\tasync function 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\tasync function upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t) {\n\t\tconst remoteItems = await getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && 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 function createCustomTypes(customTypes: CustomType[] = []) {\n\t\tawait 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 function createSlices(slices: SharedSlice[] = []) {\n\t\tawait upsertIfChanged(\"slices\", slices);\n\t}\n\n\treturn {\n\t\tcreateCustomTypes,\n\t\tcreateSlices,\n\t};\n};\n"],"names":[],"mappings":";;;AAqBO,MAAM,6BAA6B,CACzC,SACA,YACA,eACsB;AAKhB,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,gBAAgB,MAAM;AAAA;AAAA,IACtB,SAAS;AAAA,MACR;AAAA,IACA;AAAA,EAAA,CACD;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AAEO,WAAA;AAAA,EAAA,CACP;AAYc,iBAAA,OACd,UACA,WACA,MAAc;AAER,UAAA,WAAW,OAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,SAAS,MAAM,OAAO,KAAK,MAAM,MAAM,EAAE,SAAS,CAAE,EAAA,CAAE;AACxD,QAAA,CAAC,CAAC,KAAK,GAAG,EAAE,SAAS,OAAO,MAAM,GAAG;AACxC,sBAAgB,MAAM;AACtB,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AAAA,IAAA,CACrE;AAAA,EACF;AAEA,iBAAe,eACd,UAAsB;AAEtB,UAAM,SAAS,MAAM,OAAO,IAAI,QAAQ;AAExC,QAAI,CAAC,CAAC,GAAG,EAAE,SAAS,OAAO,MAAM,GAAG;AACnC,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AAEA,WAAO,OAAO;AAAA,EACf;AAEe,iBAAA,cACd,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;AAGA,iBAAe,gBACd,UACA,aAAyB,IAAE;AAErB,UAAA,cAAc,MAAM,eAAe,QAAQ;AACjD,UAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAa;AAClC,YAAM,YAAY,MAAM,cAAc,aAAa,SAAS;AAE5D,aAAO,aAAa,OAAO,UAAU,WAAW,SAAS;AAAA,IACzD,CAAA,CAAC;AAAA,EAEJ;AAOe,iBAAA,kBAAkB,cAA4B,IAAE;AACxD,UAAA,gBAAgB,eAAe,WAAW;AAAA,EACjD;AAOe,iBAAA,aAAa,SAAwB,IAAE;AAC/C,UAAA,gBAAgB,UAAU,MAAM;AAAA,EACvC;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
|
@@ -0,0 +1,145 @@
|
|
|
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 jwt = require("jsonwebtoken");
|
|
11
|
+
const cookies = require("../utils/cookies.cjs");
|
|
12
|
+
const ManageV2StaticAuthor = "prismic-e2e-tests-utils";
|
|
13
|
+
class ManageV2Client {
|
|
14
|
+
/**
|
|
15
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
16
|
+
* @param config - ManageV2 configuration variable to call ManageV2.
|
|
17
|
+
*/
|
|
18
|
+
constructor(baseUrl, config) {
|
|
19
|
+
__publicField(this, "client");
|
|
20
|
+
// Not private to have it available on tests
|
|
21
|
+
__publicField(this, "token", null);
|
|
22
|
+
/**
|
|
23
|
+
* The function `toggleRolePerLocal` enable or disable the role per local
|
|
24
|
+
* feature
|
|
25
|
+
*
|
|
26
|
+
* @param repository - The Repository name
|
|
27
|
+
* @param enabled - The feature new status
|
|
28
|
+
*/
|
|
29
|
+
__publicField(this, "toggleRolePerLocal", this.assertTokenExist((params) => {
|
|
30
|
+
return this.client.post("/repository/toggleRolesPerLocale", {
|
|
31
|
+
domain: params.repository,
|
|
32
|
+
enabled: params.enabled,
|
|
33
|
+
author: ManageV2StaticAuthor
|
|
34
|
+
});
|
|
35
|
+
}));
|
|
36
|
+
/**
|
|
37
|
+
* The function `changePlan` changes the plan of a repository the database
|
|
38
|
+
*
|
|
39
|
+
* @param repository - The Repository name
|
|
40
|
+
* @param newPlanId - The new planId
|
|
41
|
+
* @param bypassManualBilling - Beware that using this will not verify that
|
|
42
|
+
* the database and Stripe are in sync
|
|
43
|
+
*/
|
|
44
|
+
__publicField(this, "changePlan", this.assertTokenExist(({ repository, newPlanId, bypassManualBilling = false }) => {
|
|
45
|
+
return this.client.post(`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`, {
|
|
46
|
+
domain: repository,
|
|
47
|
+
newPlan: newPlanId,
|
|
48
|
+
author: ManageV2StaticAuthor
|
|
49
|
+
});
|
|
50
|
+
}));
|
|
51
|
+
/**
|
|
52
|
+
* The function `addUserToRepository` adds a user corresponding to the email
|
|
53
|
+
* to the given repository
|
|
54
|
+
*
|
|
55
|
+
* @param repository - The Repository name
|
|
56
|
+
* @param email - The user email
|
|
57
|
+
*/
|
|
58
|
+
__publicField(this, "addUserToRepository", this.assertTokenExist(({ repository, email }) => {
|
|
59
|
+
return this.client.post("/repository/addUser", {
|
|
60
|
+
domain: repository,
|
|
61
|
+
email,
|
|
62
|
+
author: ManageV2StaticAuthor
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
/**
|
|
66
|
+
* The function `removeUserFromRepository` removes a user corresponding to the
|
|
67
|
+
* email from the given repository
|
|
68
|
+
*
|
|
69
|
+
* @param repository - The Repository name
|
|
70
|
+
* @param email - The user email
|
|
71
|
+
*/
|
|
72
|
+
__publicField(this, "removeUserFromRepository", this.assertTokenExist(({ repository, email }) => {
|
|
73
|
+
return this.client.post("/repository/removeUser", {
|
|
74
|
+
domain: repository,
|
|
75
|
+
email,
|
|
76
|
+
author: ManageV2StaticAuthor
|
|
77
|
+
});
|
|
78
|
+
}));
|
|
79
|
+
this.token = config ? this.generateToken(config) : null;
|
|
80
|
+
this.client = axios.create({
|
|
81
|
+
baseURL: `${baseUrl}/manageroutes/`,
|
|
82
|
+
withCredentials: true,
|
|
83
|
+
validateStatus: () => true,
|
|
84
|
+
headers: {
|
|
85
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
86
|
+
Authorization: `Bearer ${this.token}`
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.client.interceptors.response.use((response) => {
|
|
90
|
+
const cookies$1 = response.headers["set-cookie"];
|
|
91
|
+
if (cookies$1 && cookies.extractCookie(cookies$1, "SESSION")) {
|
|
92
|
+
this.client.defaults.headers["Cookie"] = cookies$1;
|
|
93
|
+
}
|
|
94
|
+
return response;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The function generates a JWT token using the provided configuration
|
|
99
|
+
* parameters.
|
|
100
|
+
*
|
|
101
|
+
* @param {ManageV2Config} config - The `config` parameter in the
|
|
102
|
+
* `generateToken` function is of type `ManageV2Config`. It contains the
|
|
103
|
+
* following properties:
|
|
104
|
+
*
|
|
105
|
+
* @returns A JSON Web Token (JWT) is being returned by the `generateToken`
|
|
106
|
+
* function. The token is signed using the provided `config.secret` with the
|
|
107
|
+
* HS256 algorithm and includes the specified audience and issuer values.
|
|
108
|
+
*/
|
|
109
|
+
generateToken(config) {
|
|
110
|
+
return jwt.sign({}, config.secret, {
|
|
111
|
+
algorithm: "HS256",
|
|
112
|
+
audience: config.audience,
|
|
113
|
+
issuer: "prismic.io"
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The function `assertTokenExist` checks if a token exists before executing a
|
|
118
|
+
* given function.
|
|
119
|
+
*
|
|
120
|
+
* @param f - The `assertTokenExist` function takes a function `f` as a
|
|
121
|
+
* parameter. This function `f` should accept a parameter of type
|
|
122
|
+
* `Parameters` and return a Promise that resolves to an AxiosResponse. The
|
|
123
|
+
* `assertTokenExist` function ensures that a token is not null before
|
|
124
|
+
* calling the provided
|
|
125
|
+
*
|
|
126
|
+
* @returns A function is being returned that takes a parameter of type
|
|
127
|
+
* Parameters and checks if the token is null. If the token is null, an
|
|
128
|
+
* error is thrown. Otherwise, the function f is called with the provided
|
|
129
|
+
* parameters.
|
|
130
|
+
*/
|
|
131
|
+
assertTokenExist(f) {
|
|
132
|
+
return (params) => {
|
|
133
|
+
if (this.token === null) {
|
|
134
|
+
throw new Error("Undefined configuration for ManageV2 while trying to use it's routes");
|
|
135
|
+
} else {
|
|
136
|
+
return f(params);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
getBaseURL() {
|
|
141
|
+
return this.client.getUri();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.ManageV2Client = ManageV2Client;
|
|
145
|
+
//# sourceMappingURL=manageV2.cjs.map
|
|
@@ -0,0 +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, \"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` enable or disable the role per local\n\t * feature\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 `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;AAWF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAa,KAAK,iBACjB,CAAC,EACA,YACA,WACA,sBAAsB,YAKlB;AACJ,aAAO,KAAK,OAAO,KAClB,8CAA8C,mBAAmB,IACjE;AAAA,QACC,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CAEF;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+CAAsB,KAAK,iBAC1B,CAAC,EAAE,YAAY,YAAkD;AACzD,aAAA,KAAK,OAAO,KAAK,uBAAuB;AAAA,QAC9C,QAAQ;AAAA,QACR;AAAA,QACA,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oDAA2B,KAAK,iBAC/B,CAAC,EAAE,YAAY,YAAkD;AACzD,aAAA,KAAK,OAAO,KAAK,0BAA0B;AAAA,QACjD,QAAQ;AAAA,QACR;AAAA,QACA,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAzJD,SAAK,QAAQ,SAAS,KAAK,cAAc,MAAM,IAAI;AAE9C,SAAA,SAAS,MAAM,OAAO;AAAA,MAC1B,SAAS,GAAG,OAAO;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,SAAS;AAAA,QACR,cAAc;AAAA,QACd,eAAe,UAAU,KAAK,KAAK;AAAA,MACnC;AAAA,IAAA,CACD;AAGD,SAAK,OAAO,aAAa,SAAS,IAAI,CAAC,aAAY;AAC5C,YAAAA,YAAU,SAAS,QAAQ,YAAY;AAC7C,UAAIA,aAAWC,QAAAA,cAAcD,WAAS,SAAS,GAAG;AACjD,aAAK,OAAO,SAAS,QAAQ,QAAQ,IAAIA;AAAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACP;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;AAiFA;;"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosResponse } from "axios";
|
|
2
|
+
import { ManageV2Config } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Client for interacting with ManageV2 routes to perform operations on
|
|
5
|
+
* repositories.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ManageV2Client {
|
|
8
|
+
readonly client: AxiosInstance;
|
|
9
|
+
private token;
|
|
10
|
+
/**
|
|
11
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
12
|
+
* @param config - ManageV2 configuration variable to call ManageV2.
|
|
13
|
+
*/
|
|
14
|
+
constructor(baseUrl: string, config?: ManageV2Config | undefined);
|
|
15
|
+
/**
|
|
16
|
+
* The function generates a JWT token using the provided configuration
|
|
17
|
+
* parameters.
|
|
18
|
+
*
|
|
19
|
+
* @param {ManageV2Config} config - The `config` parameter in the
|
|
20
|
+
* `generateToken` function is of type `ManageV2Config`. It contains the
|
|
21
|
+
* following properties:
|
|
22
|
+
*
|
|
23
|
+
* @returns A JSON Web Token (JWT) is being returned by the `generateToken`
|
|
24
|
+
* function. The token is signed using the provided `config.secret` with the
|
|
25
|
+
* HS256 algorithm and includes the specified audience and issuer values.
|
|
26
|
+
*/
|
|
27
|
+
private generateToken;
|
|
28
|
+
/**
|
|
29
|
+
* The function `assertTokenExist` checks if a token exists before executing a
|
|
30
|
+
* given function.
|
|
31
|
+
*
|
|
32
|
+
* @param f - The `assertTokenExist` function takes a function `f` as a
|
|
33
|
+
* parameter. This function `f` should accept a parameter of type
|
|
34
|
+
* `Parameters` and return a Promise that resolves to an AxiosResponse. The
|
|
35
|
+
* `assertTokenExist` function ensures that a token is not null before
|
|
36
|
+
* calling the provided
|
|
37
|
+
*
|
|
38
|
+
* @returns A function is being returned that takes a parameter of type
|
|
39
|
+
* Parameters and checks if the token is null. If the token is null, an
|
|
40
|
+
* error is thrown. Otherwise, the function f is called with the provided
|
|
41
|
+
* parameters.
|
|
42
|
+
*/
|
|
43
|
+
private assertTokenExist;
|
|
44
|
+
getBaseURL(): string;
|
|
45
|
+
/**
|
|
46
|
+
* The function `toggleRolePerLocal` enable or disable the role per local
|
|
47
|
+
* feature
|
|
48
|
+
*
|
|
49
|
+
* @param repository - The Repository name
|
|
50
|
+
* @param enabled - The feature new status
|
|
51
|
+
*/
|
|
52
|
+
toggleRolePerLocal: (params: {
|
|
53
|
+
repository: string;
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
}) => Promise<AxiosResponse<any, any>>;
|
|
56
|
+
/**
|
|
57
|
+
* The function `changePlan` changes the plan of a repository the database
|
|
58
|
+
*
|
|
59
|
+
* @param repository - The Repository name
|
|
60
|
+
* @param newPlanId - The new planId
|
|
61
|
+
* @param bypassManualBilling - Beware that using this will not verify that
|
|
62
|
+
* the database and Stripe are in sync
|
|
63
|
+
*/
|
|
64
|
+
changePlan: (params: {
|
|
65
|
+
repository: string;
|
|
66
|
+
newPlanId: string;
|
|
67
|
+
bypassManualBilling?: boolean | undefined;
|
|
68
|
+
}) => Promise<AxiosResponse<any, any>>;
|
|
69
|
+
/**
|
|
70
|
+
* The function `addUserToRepository` adds a user corresponding to the email
|
|
71
|
+
* to the given repository
|
|
72
|
+
*
|
|
73
|
+
* @param repository - The Repository name
|
|
74
|
+
* @param email - The user email
|
|
75
|
+
*/
|
|
76
|
+
addUserToRepository: (params: {
|
|
77
|
+
repository: string;
|
|
78
|
+
email: string;
|
|
79
|
+
}) => Promise<AxiosResponse<any, any>>;
|
|
80
|
+
/**
|
|
81
|
+
* The function `removeUserFromRepository` removes a user corresponding to the
|
|
82
|
+
* email from the given repository
|
|
83
|
+
*
|
|
84
|
+
* @param repository - The Repository name
|
|
85
|
+
* @param email - The user email
|
|
86
|
+
*/
|
|
87
|
+
removeUserFromRepository: (params: {
|
|
88
|
+
repository: string;
|
|
89
|
+
email: string;
|
|
90
|
+
}) => Promise<AxiosResponse<any, any>>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
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 jwt from "jsonwebtoken";
|
|
9
|
+
import { extractCookie } from "../utils/cookies.js";
|
|
10
|
+
const ManageV2StaticAuthor = "prismic-e2e-tests-utils";
|
|
11
|
+
class ManageV2Client {
|
|
12
|
+
/**
|
|
13
|
+
* @param baseURL - The base URL of the Wroom app. ex: https://prismic.io
|
|
14
|
+
* @param config - ManageV2 configuration variable to call ManageV2.
|
|
15
|
+
*/
|
|
16
|
+
constructor(baseUrl, config) {
|
|
17
|
+
__publicField(this, "client");
|
|
18
|
+
// Not private to have it available on tests
|
|
19
|
+
__publicField(this, "token", null);
|
|
20
|
+
/**
|
|
21
|
+
* The function `toggleRolePerLocal` enable or disable the role per local
|
|
22
|
+
* feature
|
|
23
|
+
*
|
|
24
|
+
* @param repository - The Repository name
|
|
25
|
+
* @param enabled - The feature new status
|
|
26
|
+
*/
|
|
27
|
+
__publicField(this, "toggleRolePerLocal", this.assertTokenExist((params) => {
|
|
28
|
+
return this.client.post("/repository/toggleRolesPerLocale", {
|
|
29
|
+
domain: params.repository,
|
|
30
|
+
enabled: params.enabled,
|
|
31
|
+
author: ManageV2StaticAuthor
|
|
32
|
+
});
|
|
33
|
+
}));
|
|
34
|
+
/**
|
|
35
|
+
* The function `changePlan` changes the plan of a repository the database
|
|
36
|
+
*
|
|
37
|
+
* @param repository - The Repository name
|
|
38
|
+
* @param newPlanId - The new planId
|
|
39
|
+
* @param bypassManualBilling - Beware that using this will not verify that
|
|
40
|
+
* the database and Stripe are in sync
|
|
41
|
+
*/
|
|
42
|
+
__publicField(this, "changePlan", this.assertTokenExist(({ repository, newPlanId, bypassManualBilling = false }) => {
|
|
43
|
+
return this.client.post(`/repository/changePlan?bypassManualBilling=${bypassManualBilling}`, {
|
|
44
|
+
domain: repository,
|
|
45
|
+
newPlan: newPlanId,
|
|
46
|
+
author: ManageV2StaticAuthor
|
|
47
|
+
});
|
|
48
|
+
}));
|
|
49
|
+
/**
|
|
50
|
+
* The function `addUserToRepository` adds a user corresponding to the email
|
|
51
|
+
* to the given repository
|
|
52
|
+
*
|
|
53
|
+
* @param repository - The Repository name
|
|
54
|
+
* @param email - The user email
|
|
55
|
+
*/
|
|
56
|
+
__publicField(this, "addUserToRepository", this.assertTokenExist(({ repository, email }) => {
|
|
57
|
+
return this.client.post("/repository/addUser", {
|
|
58
|
+
domain: repository,
|
|
59
|
+
email,
|
|
60
|
+
author: ManageV2StaticAuthor
|
|
61
|
+
});
|
|
62
|
+
}));
|
|
63
|
+
/**
|
|
64
|
+
* The function `removeUserFromRepository` removes a user corresponding to the
|
|
65
|
+
* email from the given repository
|
|
66
|
+
*
|
|
67
|
+
* @param repository - The Repository name
|
|
68
|
+
* @param email - The user email
|
|
69
|
+
*/
|
|
70
|
+
__publicField(this, "removeUserFromRepository", this.assertTokenExist(({ repository, email }) => {
|
|
71
|
+
return this.client.post("/repository/removeUser", {
|
|
72
|
+
domain: repository,
|
|
73
|
+
email,
|
|
74
|
+
author: ManageV2StaticAuthor
|
|
75
|
+
});
|
|
76
|
+
}));
|
|
77
|
+
this.token = config ? this.generateToken(config) : null;
|
|
78
|
+
this.client = axios.create({
|
|
79
|
+
baseURL: `${baseUrl}/manageroutes/`,
|
|
80
|
+
withCredentials: true,
|
|
81
|
+
validateStatus: () => true,
|
|
82
|
+
headers: {
|
|
83
|
+
"User-Agent": "prismic-cli/prismic-e2e-tests-utils",
|
|
84
|
+
Authorization: `Bearer ${this.token}`
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.client.interceptors.response.use((response) => {
|
|
88
|
+
const cookies = response.headers["set-cookie"];
|
|
89
|
+
if (cookies && extractCookie(cookies, "SESSION")) {
|
|
90
|
+
this.client.defaults.headers["Cookie"] = cookies;
|
|
91
|
+
}
|
|
92
|
+
return response;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The function generates a JWT token using the provided configuration
|
|
97
|
+
* parameters.
|
|
98
|
+
*
|
|
99
|
+
* @param {ManageV2Config} config - The `config` parameter in the
|
|
100
|
+
* `generateToken` function is of type `ManageV2Config`. It contains the
|
|
101
|
+
* following properties:
|
|
102
|
+
*
|
|
103
|
+
* @returns A JSON Web Token (JWT) is being returned by the `generateToken`
|
|
104
|
+
* function. The token is signed using the provided `config.secret` with the
|
|
105
|
+
* HS256 algorithm and includes the specified audience and issuer values.
|
|
106
|
+
*/
|
|
107
|
+
generateToken(config) {
|
|
108
|
+
return jwt.sign({}, config.secret, {
|
|
109
|
+
algorithm: "HS256",
|
|
110
|
+
audience: config.audience,
|
|
111
|
+
issuer: "prismic.io"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The function `assertTokenExist` checks if a token exists before executing a
|
|
116
|
+
* given function.
|
|
117
|
+
*
|
|
118
|
+
* @param f - The `assertTokenExist` function takes a function `f` as a
|
|
119
|
+
* parameter. This function `f` should accept a parameter of type
|
|
120
|
+
* `Parameters` and return a Promise that resolves to an AxiosResponse. The
|
|
121
|
+
* `assertTokenExist` function ensures that a token is not null before
|
|
122
|
+
* calling the provided
|
|
123
|
+
*
|
|
124
|
+
* @returns A function is being returned that takes a parameter of type
|
|
125
|
+
* Parameters and checks if the token is null. If the token is null, an
|
|
126
|
+
* error is thrown. Otherwise, the function f is called with the provided
|
|
127
|
+
* parameters.
|
|
128
|
+
*/
|
|
129
|
+
assertTokenExist(f) {
|
|
130
|
+
return (params) => {
|
|
131
|
+
if (this.token === null) {
|
|
132
|
+
throw new Error("Undefined configuration for ManageV2 while trying to use it's routes");
|
|
133
|
+
} else {
|
|
134
|
+
return f(params);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
getBaseURL() {
|
|
139
|
+
return this.client.getUri();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
ManageV2Client
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=manageV2.js.map
|
|
@@ -0,0 +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, \"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` enable or disable the role per local\n\t * feature\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 `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;AAWF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAa,KAAK,iBACjB,CAAC,EACA,YACA,WACA,sBAAsB,YAKlB;AACJ,aAAO,KAAK,OAAO,KAClB,8CAA8C,mBAAmB,IACjE;AAAA,QACC,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CAEF;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+CAAsB,KAAK,iBAC1B,CAAC,EAAE,YAAY,YAAkD;AACzD,aAAA,KAAK,OAAO,KAAK,uBAAuB;AAAA,QAC9C,QAAQ;AAAA,QACR;AAAA,QACA,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAUF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oDAA2B,KAAK,iBAC/B,CAAC,EAAE,YAAY,YAAkD;AACzD,aAAA,KAAK,OAAO,KAAK,0BAA0B;AAAA,QACjD,QAAQ;AAAA,QACR;AAAA,QACA,QAAQ;AAAA,MAAA,CACR;AAAA,IAAA,CACD;AAzJD,SAAK,QAAQ,SAAS,KAAK,cAAc,MAAM,IAAI;AAE9C,SAAA,SAAS,MAAM,OAAO;AAAA,MAC1B,SAAS,GAAG,OAAO;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,SAAS;AAAA,QACR,cAAc;AAAA,QACd,eAAe,UAAU,KAAK,KAAK;AAAA,MACnC;AAAA,IAAA,CACD;AAGD,SAAK,OAAO,aAAa,SAAS,IAAI,CAAC,aAAY;AAC5C,YAAA,UAAU,SAAS,QAAQ,YAAY;AAC7C,UAAI,WAAW,cAAc,SAAS,SAAS,GAAG;AACjD,aAAK,OAAO,SAAS,QAAQ,QAAQ,IAAI;AAAA,MAC1C;AAEO,aAAA;AAAA,IAAA,CACP;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;AAiFA;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const log = require("../utils/log.cjs");
|
|
5
|
+
const createMigrationApiClient = (baseURL, repository, authClient) => {
|
|
6
|
+
const client = axios.create({
|
|
7
|
+
baseURL,
|
|
8
|
+
headers: {
|
|
9
|
+
repository
|
|
10
|
+
},
|
|
11
|
+
validateStatus: () => true
|
|
12
|
+
// Don't throw on 4XX errors
|
|
13
|
+
});
|
|
14
|
+
client.interceptors.request.use(async (config) => {
|
|
15
|
+
const auth = "Authorization";
|
|
16
|
+
if (!config.headers[auth]) {
|
|
17
|
+
const token = await authClient.getToken();
|
|
18
|
+
config.headers[auth] = `Bearer ${token}`;
|
|
19
|
+
}
|
|
20
|
+
config.headers["repository"] = repository;
|
|
21
|
+
return config;
|
|
22
|
+
});
|
|
23
|
+
async function createDocument(data) {
|
|
24
|
+
const result = await client.post("/documents", data);
|
|
25
|
+
if (201 !== result.status) {
|
|
26
|
+
log.logHttpResponse(result);
|
|
27
|
+
throw new Error("Could not create a document with the migration api.");
|
|
28
|
+
}
|
|
29
|
+
return result.data;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
createDocument
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.createMigrationApiClient = createMigrationApiClient;
|
|
36
|
+
//# sourceMappingURL=migrationApi.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrationApi.cjs","sources":["../../../src/clients/migrationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { logHttpResponse } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type MigrationClient = {\n\tcreateDocument(data: DocumentPayload): Promise<DocumentResponse>;\n};\n\nexport type DocumentPayload = {\n\tuid?: string | null;\n\tlang: string;\n\ttitle: string;\n\ttags?: string[];\n\talternate_language_id?: string;\n\tdata: Record<string, unknown>;\n};\n\nexport type DocumentResponse = {\n\tid: string;\n\ttype: string;\n\tlang: string;\n\ttitle: string;\n\tuid?: string;\n};\n\nexport const createMigrationApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): MigrationClient => {\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\t\tconfig.headers[\"repository\"] = repository;\n\n\t\treturn config;\n\t});\n\n\tasync function createDocument(\n\t\tdata: DocumentPayload,\n\t): Promise<DocumentResponse> {\n\t\tconst result = await client.post<DocumentResponse>(\"/documents\", data);\n\n\t\tif (201 !== result.status) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not create a document with the migration api.\");\n\t\t}\n\n\t\treturn result.data;\n\t}\n\n\treturn {\n\t\tcreateDocument,\n\t};\n};\n"],"names":["logHttpResponse"],"mappings":";;;;AA2BO,MAAM,2BAA2B,CACvC,SACA,YACA,eACoB;AACd,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,SAAS;AAAA,MACR;AAAA,IACA;AAAA,IACD,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AACO,WAAA,QAAQ,YAAY,IAAI;AAExB,WAAA;AAAA,EAAA,CACP;AAED,iBAAe,eACd,MAAqB;AAErB,UAAM,SAAS,MAAM,OAAO,KAAuB,cAAc,IAAI;AAEjE,QAAA,QAAQ,OAAO,QAAQ;AAC1BA,UAAA,gBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,qDAAqD;AAAA,IACtE;AAEA,WAAO,OAAO;AAAA,EACf;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthenticationClient } from "./authenticationApi";
|
|
2
|
+
export type MigrationClient = {
|
|
3
|
+
createDocument(data: DocumentPayload): Promise<DocumentResponse>;
|
|
4
|
+
};
|
|
5
|
+
export type DocumentPayload = {
|
|
6
|
+
uid?: string | null;
|
|
7
|
+
lang: string;
|
|
8
|
+
title: string;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
alternate_language_id?: string;
|
|
11
|
+
data: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
export type DocumentResponse = {
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
lang: string;
|
|
17
|
+
title: string;
|
|
18
|
+
uid?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const createMigrationApiClient: (baseURL: string, repository: string, authClient: AuthenticationClient) => MigrationClient;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { logHttpResponse } from "../utils/log.js";
|
|
3
|
+
const createMigrationApiClient = (baseURL, repository, authClient) => {
|
|
4
|
+
const client = axios.create({
|
|
5
|
+
baseURL,
|
|
6
|
+
headers: {
|
|
7
|
+
repository
|
|
8
|
+
},
|
|
9
|
+
validateStatus: () => true
|
|
10
|
+
// Don't throw on 4XX errors
|
|
11
|
+
});
|
|
12
|
+
client.interceptors.request.use(async (config) => {
|
|
13
|
+
const auth = "Authorization";
|
|
14
|
+
if (!config.headers[auth]) {
|
|
15
|
+
const token = await authClient.getToken();
|
|
16
|
+
config.headers[auth] = `Bearer ${token}`;
|
|
17
|
+
}
|
|
18
|
+
config.headers["repository"] = repository;
|
|
19
|
+
return config;
|
|
20
|
+
});
|
|
21
|
+
async function createDocument(data) {
|
|
22
|
+
const result = await client.post("/documents", data);
|
|
23
|
+
if (201 !== result.status) {
|
|
24
|
+
logHttpResponse(result);
|
|
25
|
+
throw new Error("Could not create a document with the migration api.");
|
|
26
|
+
}
|
|
27
|
+
return result.data;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
createDocument
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
createMigrationApiClient
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=migrationApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrationApi.js","sources":["../../../src/clients/migrationApi.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { logHttpResponse } from \"../utils/log\";\n\nimport { AuthenticationClient } from \"./authenticationApi\";\n\nexport type MigrationClient = {\n\tcreateDocument(data: DocumentPayload): Promise<DocumentResponse>;\n};\n\nexport type DocumentPayload = {\n\tuid?: string | null;\n\tlang: string;\n\ttitle: string;\n\ttags?: string[];\n\talternate_language_id?: string;\n\tdata: Record<string, unknown>;\n};\n\nexport type DocumentResponse = {\n\tid: string;\n\ttype: string;\n\tlang: string;\n\ttitle: string;\n\tuid?: string;\n};\n\nexport const createMigrationApiClient = (\n\tbaseURL: string,\n\trepository: string,\n\tauthClient: AuthenticationClient,\n): MigrationClient => {\n\tconst client: AxiosInstance = axios.create({\n\t\tbaseURL,\n\t\theaders: {\n\t\t\trepository,\n\t\t},\n\t\tvalidateStatus: () => true, // Don't throw on 4XX errors\n\t});\n\n\t// Add an interceptor to authenticate requests\n\tclient.interceptors.request.use(async (config) => {\n\t\tconst auth = \"Authorization\";\n\t\tif (!config.headers[auth]) {\n\t\t\tconst token = await authClient.getToken();\n\t\t\tconfig.headers[auth] = `Bearer ${token}`;\n\t\t}\n\t\tconfig.headers[\"repository\"] = repository;\n\n\t\treturn config;\n\t});\n\n\tasync function createDocument(\n\t\tdata: DocumentPayload,\n\t): Promise<DocumentResponse> {\n\t\tconst result = await client.post<DocumentResponse>(\"/documents\", data);\n\n\t\tif (201 !== result.status) {\n\t\t\tlogHttpResponse(result);\n\t\t\tthrow new Error(\"Could not create a document with the migration api.\");\n\t\t}\n\n\t\treturn result.data;\n\t}\n\n\treturn {\n\t\tcreateDocument,\n\t};\n};\n"],"names":[],"mappings":";;AA2BO,MAAM,2BAA2B,CACvC,SACA,YACA,eACoB;AACd,QAAA,SAAwB,MAAM,OAAO;AAAA,IAC1C;AAAA,IACA,SAAS;AAAA,MACR;AAAA,IACA;AAAA,IACD,gBAAgB,MAAM;AAAA;AAAA,EAAA,CACtB;AAGD,SAAO,aAAa,QAAQ,IAAI,OAAO,WAAU;AAChD,UAAM,OAAO;AACb,QAAI,CAAC,OAAO,QAAQ,IAAI,GAAG;AACpB,YAAA,QAAQ,MAAM,WAAW;AAC/B,aAAO,QAAQ,IAAI,IAAI,UAAU,KAAK;AAAA,IACvC;AACO,WAAA,QAAQ,YAAY,IAAI;AAExB,WAAA;AAAA,EAAA,CACP;AAED,iBAAe,eACd,MAAqB;AAErB,UAAM,SAAS,MAAM,OAAO,KAAuB,cAAc,IAAI;AAEjE,QAAA,QAAQ,OAAO,QAAQ;AAC1B,sBAAgB,MAAM;AAChB,YAAA,IAAI,MAAM,qDAAqD;AAAA,IACtE;AAEA,WAAO,OAAO;AAAA,EACf;AAEO,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
|
package/dist/clients/wroom.cjs
CHANGED
|
@@ -67,6 +67,34 @@ class WroomClient {
|
|
|
67
67
|
});
|
|
68
68
|
return response;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Update the role of a user in the repository
|
|
72
|
+
*
|
|
73
|
+
* @param {string} repository - The repository name
|
|
74
|
+
* @param {string} email - The email of the user
|
|
75
|
+
* @param {string} role - The new role to be given
|
|
76
|
+
*
|
|
77
|
+
* @returns The Axios Reponse
|
|
78
|
+
*/
|
|
79
|
+
async updateRole(repository, email, role) {
|
|
80
|
+
const params = new URLSearchParams({ email, profile: role });
|
|
81
|
+
const path = `/app/settings/users/profiles?${params.toString()}`;
|
|
82
|
+
return this.post(repository, path);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Update the role of a user in the repository
|
|
86
|
+
*
|
|
87
|
+
* @param {string} repository - The repository name
|
|
88
|
+
* @param {string} email - The email of the user
|
|
89
|
+
* @param {string} rolePerLocal - The role per local object
|
|
90
|
+
*
|
|
91
|
+
* @returns The Axios Reponse
|
|
92
|
+
*/
|
|
93
|
+
async updateRolePerLocal(repository, email, rolePerLocal) {
|
|
94
|
+
const params = new URLSearchParams({ email });
|
|
95
|
+
const path = `/app/settings/users/rolesperlocale?${params.toString()}`;
|
|
96
|
+
return this.post(repository, path, rolePerLocal);
|
|
97
|
+
}
|
|
70
98
|
/**
|
|
71
99
|
* Authenticate Wroom to call Wroom unofficial endpoints.
|
|
72
100
|
*
|