diff --git a/CHANGELOG.md b/CHANGELOG.md index d07ce636..594b7af7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### Unreleased +* Models can now directly be imported from the top-level `nylas` package + ### 7.0.0 / 2024-02-05 * **BREAKING CHANGE**: Node SDK v7 supports the Nylas API v3 exclusively, dropping support for any endpoints that are not available in v3. * **BREAKING CHANGE**: Convert `Nylas` class from a static to a non-static class diff --git a/package.json b/package.json index dd41e1ef..f465089a 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "lint:prettier:check": "prettier --check '**/*.{ts,js}'", "export-version": "node scripts/exportVersion.js", "generate-lib-package-json": "node scripts/generateLibPackageJson.js", - "prebuild": "npm run export-version", + "generate-model-index": "node scripts/generateModelIndex.js", + "prebuild": "npm run export-version && npm run generate-model-index", "build": "rm -rf lib && npm run build-esm && npm run build-cjs && npm run generate-lib-package-json", "build-esm": "tsc -p tsconfig.esm.json", "build-cjs": "tsc -p tsconfig.cjs.json", diff --git a/scripts/generateModelIndex.js b/scripts/generateModelIndex.js new file mode 100644 index 00000000..5d91e8d2 --- /dev/null +++ b/scripts/generateModelIndex.js @@ -0,0 +1,15 @@ +const fs = require('fs'); +const path = require('path'); + +const comment = '// This file is generated by scripts/generateModelIndex.js\n'; +const modelsDir = path.join(__dirname, '..', 'src', 'models'); +let indexContent = ''; + +fs.readdirSync(modelsDir).forEach(file => { + if (file.endsWith('.ts') && file !== 'index.ts') { + const modelName = file.replace('.ts', '.js'); + indexContent += `export * from './${modelName}';\n`; + } +}); + +fs.writeFileSync(path.join(modelsDir, 'index.ts'), comment + indexContent); diff --git a/src/models/index.ts b/src/models/index.ts new file mode 100644 index 00000000..570e4c43 --- /dev/null +++ b/src/models/index.ts @@ -0,0 +1,22 @@ +// This file is generated by scripts/generateModelIndex.js +export * from './applicationDetails.js'; +export * from './attachments.js'; +export * from './auth.js'; +export * from './availability.js'; +export * from './calendars.js'; +export * from './connectors.js'; +export * from './contacts.js'; +export * from './credentials.js'; +export * from './drafts.js'; +export * from './error.js'; +export * from './events.js'; +export * from './folders.js'; +export * from './freeBusy.js'; +export * from './grants.js'; +export * from './listQueryParams.js'; +export * from './messages.js'; +export * from './redirectUri.js'; +export * from './response.js'; +export * from './smartCompose.js'; +export * from './threads.js'; +export * from './webhooks.js'; diff --git a/src/nylas.ts b/src/nylas.ts index 658084c8..f786c1f0 100644 --- a/src/nylas.ts +++ b/src/nylas.ts @@ -1,3 +1,5 @@ +export * from './models/index.js'; + import APIClient from './apiClient.js'; import { NylasConfig, DEFAULT_SERVER_URL } from './config.js'; import { Calendars } from './resources/calendars.js';