diff --git a/.circleci/config.yml b/.circleci/config.yml index 2c79eb3b..fb8152ed 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ jobs: lint-and-test: docker: - - image: "cimg/base:stable" + - image: "cimg/base:current" parameters: node-version: type: string @@ -35,7 +35,7 @@ jobs: build: docker: - - image: "cimg/base:stable" + - image: "cimg/base:current" steps: - checkout - node/install: @@ -47,7 +47,7 @@ jobs: lint-commits: docker: - - image: "cimg/base:stable" + - image: "cimg/base:current" steps: - checkout - node/install: @@ -57,7 +57,7 @@ jobs: semantic-release: docker: - - image: "cimg/base:stable" + - image: "cimg/base:current" steps: - checkout - vault/get-secrets: diff --git a/CHANGELOG.md b/CHANGELOG.md index a9a6ec23..4680321c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.6.0](https://github.com/contentful/node-apps-toolkit/compare/v3.5.0...v3.6.0) (2024-07-31) + + +### Features + +* add types for resource events ([#675](https://github.com/contentful/node-apps-toolkit/issues/675)) ([b8fed5b](https://github.com/contentful/node-apps-toolkit/commit/b8fed5b809cb0562982259fbbb13aad6037386fe)) + # [3.5.0](https://github.com/contentful/node-apps-toolkit/compare/v3.4.2...v3.5.0) (2024-07-25) diff --git a/package-lock.json b/package-lock.json index c826fcd5..91d330dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentful/node-apps-toolkit", - "version": "3.5.0", + "version": "3.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentful/node-apps-toolkit", - "version": "3.5.0", + "version": "3.6.0", "license": "MIT", "dependencies": { "@types/debug": "^4.1.5", diff --git a/package.json b/package.json index f3d490dd..ce9dee00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentful/node-apps-toolkit", - "version": "3.5.0", + "version": "3.6.0", "description": "A collection of helpers and utilities for creating NodeJS Contentful Apps", "main": "lib/index.js", "engines": { diff --git a/src/keys/get-management-token.spec.ts b/src/keys/get-management-token.spec.ts index 201e2a5e..591947bb 100644 --- a/src/keys/get-management-token.spec.ts +++ b/src/keys/get-management-token.spec.ts @@ -37,6 +37,9 @@ describe('getManagementToken', () => { const httpClient = { post } as unknown as HttpClient const getManagementToken = createGetManagementToken(logger, httpClient, defaultCache) + console.log('dirname is ', __dirname) + console.log('dirname is ', path.dirname(__dirname)) + console.log('Private Key Location:', path.join(__dirname, '..', '..', 'keys', 'key.pem')) const result = await getManagementToken(PRIVATE_KEY, DEFAULT_OPTIONS) assert.deepStrictEqual(result, mockToken) diff --git a/src/requests/typings/function.ts b/src/requests/typings/function.ts index 331f98bd..5c9c1add 100644 --- a/src/requests/typings/function.ts +++ b/src/requests/typings/function.ts @@ -16,6 +16,14 @@ import { ScheduledActionProps, TaskProps, } from 'contentful-management' +import { + RESOURCES_SEARCH_EVENT, + RESOURCES_LOOKUP_EVENT, + type ResourcesLookupRequest, + type ResourcesLookupResponse, + type ResourcesSearchRequest, + type ResourcesSearchResponse, +} from './resources' const GRAPHQL_FIELD_MAPPING_EVENT = 'graphql.field.mapping' const GRAPHQL_QUERY_EVENT = 'graphql.query' @@ -180,9 +188,22 @@ type FunctionEventHandlers = { event: AppEventRequest response: AppEventTransformationResponse } + [RESOURCES_SEARCH_EVENT]: { + event: ResourcesSearchRequest + response: ResourcesSearchResponse + } + [RESOURCES_LOOKUP_EVENT]: { + event: ResourcesLookupRequest + response: ResourcesLookupResponse + } } -export type FunctionEvent = GraphQLFieldTypeMappingRequest | GraphQLQueryRequest | AppEventRequest +export type FunctionEvent = + | GraphQLFieldTypeMappingRequest + | GraphQLQueryRequest + | AppEventRequest + | ResourcesSearchRequest + | ResourcesLookupRequest export type FunctionEventType = keyof FunctionEventHandlers /** diff --git a/src/requests/typings/resources.ts b/src/requests/typings/resources.ts new file mode 100644 index 00000000..4cedff1c --- /dev/null +++ b/src/requests/typings/resources.ts @@ -0,0 +1,39 @@ +export const RESOURCES_SEARCH_EVENT = 'resources.search' +export const RESOURCES_LOOKUP_EVENT = 'resources.lookup' + +export type ResourcesSearchRequest = { + type: 'resources.search' + resourceType: string + query: string + limit?: number + pages?: { + nextCursor: string + } +} + +export type ResourcesSearchResponse = Record> = { + items: S[] + pages: { + nextCursor?: string + } +} + +type Scalar = string | number | boolean + +export type ResourcesLookupRequest = Record> = + { + type: 'resources.lookup' + lookupBy: L + resourceType: string + limit?: number + pages?: { + nextCursor: string + } + } + +export type ResourcesLookupResponse = Record> = { + items: L[] + pages: { + nextCursor?: string + } +} diff --git a/test/integration/keys.test.ts b/test/integration/keys.test.ts index ba658b81..6b19b4d1 100644 --- a/test/integration/keys.test.ts +++ b/test/integration/keys.test.ts @@ -24,7 +24,10 @@ describe('Keys Utilities', () => { throw new Error('Missing Environment setup') } - const privateKey = fs.readFileSync(path.join(__dirname, '..', '..', 'keys', 'key.pem'), 'utf-8') + const privateKeyPath = path.join(__dirname, '..', '..', 'keys', 'key.pem') + console.log(fs.readdirSync(path.dirname(privateKeyPath))) + + const privateKey = fs.readFileSync(privateKeyPath, 'utf-8') const token = await getManagementToken(privateKey, { appInstallationId, diff --git a/test/make-private-keys.sh b/test/make-private-keys.sh index 2f48200e..f7884cd6 100644 --- a/test/make-private-keys.sh +++ b/test/make-private-keys.sh @@ -3,4 +3,6 @@ mkdir -p keys openssl req -x509 -newkey rsa:4096 -nodes -batch -noout -keyout keys/key.pem -openssl rsa -in keys/key.pem -pubout -outform DER -out keys/key.der.pub \ No newline at end of file +openssl rsa -in keys/key.pem -pubout -outform DER -out keys/key.der.pub +echo "Newly created private and public keys:" +ls -l keys \ No newline at end of file