@okam/directus-node 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## 0.1.2 (2024-07-16)
2
+
3
+
4
+ ### 🩹 Fixes
5
+
6
+ - **directus-node:** fix package.json with published structured reference ([#153](https://github.com/OKAMca/stack/pull/153))
7
+
8
+
9
+ ### ❤️ Thank You
10
+
11
+ - Jérôme Trottier
12
+ - Pierre-Olivier Clerson @poclerson
13
+ - yanmorinokamca @yanmorinokamca
14
+
15
+ ## 0.1.1 (2024-07-09)
16
+
17
+
18
+ ### 🩹 Fixes
19
+
20
+ - **publish:** add building packages step to workflow ([c9ce442](https://github.com/OKAMca/stack/commit/c9ce442))
21
+
22
+
23
+ ### ❤️ Thank You
24
+
25
+ - Jérôme Trottier
26
+
1
27
  ## 0.1.0 (2024-06-28)
2
28
 
3
29
 
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@okam/directus-node",
3
- "main": "./index.js",
4
- "version": "0.1.0",
5
- "types": "./index.d.ts",
3
+ "main": "./src/index.js",
4
+ "version": "0.1.2",
5
+ "types": "./src/index.d.ts",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org"
8
8
  },
9
9
  "repository": {
10
10
  "url": "https://github.com/OKAMca/stack.git"
11
- }
12
- }
11
+ },
12
+ "type": "commonjs"
13
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/redirection';
2
+ export { default as graphqlCodegenConfig } from './lib/codegen';
package/src/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphqlCodegenConfig = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./lib/redirection"), exports);
6
+ var codegen_1 = require("./lib/codegen");
7
+ Object.defineProperty(exports, "graphqlCodegenConfig", { enumerable: true, get: function () { return codegen_1.default; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/directus/directus-node/src/index.ts"],"names":[],"mappings":";;;;AAAA,4DAAiC;AACjC,yCAA+D;AAAtD,+GAAA,OAAO,OAAwB"}
@@ -0,0 +1,2 @@
1
+ declare const graphqlCodegenConfig: (schemaUrl: string, generatePath: string, headers: Record<string, string>) => import("@graphql-codegen/plugin-helpers").Types.Config;
2
+ export default graphqlCodegenConfig;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphqlCodegenConfig = (schemaUrl, generatePath, headers) => {
4
+ const config = {
5
+ overwrite: true,
6
+ schema: [
7
+ {
8
+ [schemaUrl]: {
9
+ headers,
10
+ },
11
+ },
12
+ ],
13
+ documents: [`${__dirname}/apps/demo/**/*.graphql`],
14
+ ignoreNoDocuments: true, // for better experience with the watcher
15
+ generates: {
16
+ [generatePath]: {
17
+ preset: 'client',
18
+ },
19
+ },
20
+ };
21
+ return config;
22
+ };
23
+ exports.default = graphqlCodegenConfig;
24
+ //# sourceMappingURL=codegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../../../../libs/directus/directus-node/src/lib/codegen.ts"],"names":[],"mappings":";;AAEA,MAAM,oBAAoB,GAAG,CAAC,SAAiB,EAAE,YAAoB,EAAE,OAA+B,EAAE,EAAE;IACxG,MAAM,MAAM,GAAkB;QAC5B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE;YACN;gBACE,CAAC,SAAS,CAAC,EAAE;oBACX,OAAO;iBACR;aACF;SACF;QACD,SAAS,EAAE,CAAC,GAAG,SAAS,yBAAyB,CAAC;QAClD,iBAAiB,EAAE,IAAI,EAAE,yCAAyC;QAClE,SAAS,EAAE;YACT,CAAC,YAAY,CAAC,EAAE;gBACd,MAAM,EAAE,QAAQ;aACjB;SACF;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,kBAAe,oBAAoB,CAAA"}
@@ -0,0 +1,13 @@
1
+ interface TFetchRedirectsConfig {
2
+ graphqlEndpoint: string;
3
+ graphqlApiKey: string;
4
+ redirectsFilename: string;
5
+ rewritesFilename: string;
6
+ }
7
+ /**
8
+ * Get Fetch Redirects Configuration
9
+ * @returns {object}
10
+ */
11
+ export declare function getDefaultConfig(): TFetchRedirectsConfig;
12
+ export declare function fetchRedirects(config: TFetchRedirectsConfig): Promise<boolean>;
13
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchRedirects = exports.getDefaultConfig = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const promises_1 = require("node:fs/promises");
6
+ /**
7
+ * Get Fetch Redirects Configuration
8
+ * @returns {object}
9
+ */
10
+ function getDefaultConfig() {
11
+ return {
12
+ graphqlEndpoint: process.env['NEXT_PUBLIC_GRAPHQL_URL'] || '',
13
+ graphqlApiKey: process.env['NEXT_API_TOKEN_ADMIN'] || '',
14
+ redirectsFilename: './redirect/redirects.json',
15
+ rewritesFilename: './redirect/rewrites.json',
16
+ };
17
+ }
18
+ exports.getDefaultConfig = getDefaultConfig;
19
+ function fetchRedirects(config) {
20
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
+ const { graphqlEndpoint, graphqlApiKey, redirectsFilename, rewritesFilename } = config;
22
+ if (!graphqlEndpoint || !graphqlApiKey) {
23
+ throw new Error('Missing graphql configuration: NEXT_PUBLIC_GRAPHQL_URL or NEXT_API_TOKEN_ADMIN');
24
+ }
25
+ if (!redirectsFilename || !rewritesFilename) {
26
+ throw new Error('Missing filename');
27
+ }
28
+ const query = `query fetchRedirects {
29
+ redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort") {
30
+ source
31
+ destination
32
+ permanent
33
+ locale
34
+ }
35
+ rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort") {
36
+ source
37
+ destination
38
+ permanent
39
+ locale
40
+ }
41
+ }`;
42
+ const graphqlBody = {
43
+ query,
44
+ // "operationName": "",
45
+ variables: {},
46
+ };
47
+ try {
48
+ // console.info(`Fetching redirects on ${graphqlEndpoint}`)
49
+ const response = yield fetch(graphqlEndpoint, {
50
+ method: 'POST',
51
+ headers: {
52
+ // eslint-disable-next-line @typescript-eslint/naming-convention
53
+ 'Content-Type': 'application/json',
54
+ Authorization: `Bearer ${graphqlApiKey}`,
55
+ },
56
+ body: JSON.stringify(graphqlBody),
57
+ });
58
+ const { data } = yield response.json();
59
+ const writeDataRedirects = JSON.stringify(data.redirects || []);
60
+ yield (0, promises_1.writeFile)(redirectsFilename, writeDataRedirects);
61
+ const writeDataRewrites = JSON.stringify(data.rewrites || []);
62
+ yield (0, promises_1.writeFile)(rewritesFilename, writeDataRewrites);
63
+ }
64
+ catch (e) {
65
+ // console.error('GraphQL Error', (e as Error).message)
66
+ // return false
67
+ }
68
+ return true;
69
+ });
70
+ }
71
+ exports.fetchRedirects = fetchRedirects;
72
+ //# sourceMappingURL=redirection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirection.js","sourceRoot":"","sources":["../../../../../../libs/directus/directus-node/src/lib/redirection.ts"],"names":[],"mappings":";;;;AAAA,+CAA4C;AAQ5C;;;GAGG;AACH,SAAgB,gBAAgB;IAC9B,OAAO;QACL,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,IAAI,EAAE;QAC7D,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE;QACxD,iBAAiB,EAAE,2BAA2B;QAC9C,gBAAgB,EAAE,0BAA0B;KAC7C,CAAA;AACH,CAAC;AAPD,4CAOC;AAED,SAAsB,cAAc,CAAC,MAA6B;;QAChE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,iB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wDC"}
package/.eslintrc.js DELETED
@@ -1,21 +0,0 @@
1
- const { getDefaultIgnorePatterns } = require("../../../linter/helpers");
2
-
3
- module.exports = {
4
- extends: ['plugin:@nx/react', '../../../.eslintrc.js', '../../../linter/bases/typescript', '../../../linter/bases/regexp', '../../../linter/bases/jest', '../../../linter/bases/rtl', '../../../linter/bases/storybook', '../../../linter/bases/react', '../../../linter/bases/prettier', 'plugin:storybook/recommended'],
5
- ignorePatterns: ['!**/*', ...getDefaultIgnorePatterns()],
6
- overrides: [
7
- {
8
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
9
- // We set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting
10
- parserOptions: {
11
- project: `${__dirname}/tsconfig.*?.json`,
12
- },
13
- rules: {
14
- "@nx/dependency-checks": "error"
15
- }
16
- },
17
- ],
18
- rules: {
19
- 'react/react-in-jsx-scope': 'off',
20
- },
21
- }
package/jest.config.ts DELETED
@@ -1,11 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: 'directus-node',
4
- preset: '../../../jest.preset.js',
5
- testEnvironment: 'node',
6
- transform: {
7
- '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
8
- },
9
- moduleFileExtensions: ['ts', 'js', 'html'],
10
- coverageDirectory: '../../../coverage/libs/directus/directus-node',
11
- }
package/project.json DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "name": "directus-node",
3
- "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/directus/directus-node/src",
5
- "projectType": "library",
6
- "tags": [],
7
- "targets": {
8
- "build": {
9
- "executor": "@nx/js:tsc",
10
- "outputs": ["{options.outputPath}"],
11
- "options": {
12
- "outputPath": "dist/libs/directus/directus-node",
13
- "tsConfig": "libs/directus/directus-node/tsconfig.lib.json",
14
- "packageJson": "libs/directus/directus-node/package.json",
15
- "main": "libs/directus/directus-node/src/index.ts",
16
- "assets": ["libs/directus/directus-node/*.md"]
17
- }
18
- },
19
- "publish": {
20
- "command": "node tools/scripts/publish.mjs directus-node {args.ver} {args.tag}",
21
- "dependsOn": ["build"]
22
- },
23
- "lint": {
24
- "executor": "@nx/eslint:lint"
25
- },
26
- "test": {
27
- "executor": "@nx/jest:jest",
28
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
29
- "options": {
30
- "jestConfig": "libs/directus/directus-node/jest.config.ts"
31
- }
32
- }
33
- }
34
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/redirection'
2
- export { default as graphqlCodegenConfig } from './lib/codegen'
@@ -1,25 +0,0 @@
1
- import type { CodegenConfig } from '@graphql-codegen/cli'
2
-
3
- const graphqlCodegenConfig = (schemaUrl: string, generatePath: string, headers: Record<string, string>) => {
4
- const config: CodegenConfig = {
5
- overwrite: true,
6
- schema: [
7
- {
8
- [schemaUrl]: {
9
- headers,
10
- },
11
- },
12
- ],
13
- documents: [`${__dirname}/apps/demo/**/*.graphql`],
14
- ignoreNoDocuments: true, // for better experience with the watcher
15
- generates: {
16
- [generatePath]: {
17
- preset: 'client',
18
- },
19
- },
20
- }
21
-
22
- return config
23
- }
24
-
25
- export default graphqlCodegenConfig
@@ -1,78 +0,0 @@
1
- import { writeFile } from 'node:fs/promises'
2
-
3
- interface TFetchRedirectsConfig {
4
- graphqlEndpoint: string
5
- graphqlApiKey: string
6
- redirectsFilename: string
7
- rewritesFilename: string
8
- }
9
- /**
10
- * Get Fetch Redirects Configuration
11
- * @returns {object}
12
- */
13
- export function getDefaultConfig(): TFetchRedirectsConfig {
14
- return {
15
- graphqlEndpoint: process.env['NEXT_PUBLIC_GRAPHQL_URL'] || '',
16
- graphqlApiKey: process.env['NEXT_API_TOKEN_ADMIN'] || '',
17
- redirectsFilename: './redirect/redirects.json',
18
- rewritesFilename: './redirect/rewrites.json',
19
- }
20
- }
21
-
22
- export async function fetchRedirects(config: TFetchRedirectsConfig): Promise<boolean> {
23
- const { graphqlEndpoint, graphqlApiKey, redirectsFilename, rewritesFilename } = config
24
-
25
- if (!graphqlEndpoint || !graphqlApiKey) {
26
- throw new Error('Missing graphql configuration: NEXT_PUBLIC_GRAPHQL_URL or NEXT_API_TOKEN_ADMIN')
27
- }
28
-
29
- if (!redirectsFilename || !rewritesFilename) {
30
- throw new Error('Missing filename')
31
- }
32
-
33
- const query = `query fetchRedirects {
34
- redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort") {
35
- source
36
- destination
37
- permanent
38
- locale
39
- }
40
- rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort") {
41
- source
42
- destination
43
- permanent
44
- locale
45
- }
46
- }`
47
-
48
- const graphqlBody = {
49
- query,
50
- // "operationName": "",
51
- variables: {},
52
- }
53
-
54
- try {
55
- // console.info(`Fetching redirects on ${graphqlEndpoint}`)
56
- const response = await fetch(graphqlEndpoint, {
57
- method: 'POST',
58
- headers: {
59
- // eslint-disable-next-line @typescript-eslint/naming-convention
60
- 'Content-Type': 'application/json',
61
- Authorization: `Bearer ${graphqlApiKey}`,
62
- },
63
- body: JSON.stringify(graphqlBody),
64
- })
65
- const { data } = await response.json()
66
-
67
- const writeDataRedirects = JSON.stringify(data.redirects || [])
68
- await writeFile(redirectsFilename, writeDataRedirects)
69
-
70
- const writeDataRewrites = JSON.stringify(data.rewrites || [])
71
- await writeFile(rewritesFilename, writeDataRewrites)
72
- } catch (e) {
73
- // console.error('GraphQL Error', (e as Error).message)
74
- // return false
75
- }
76
-
77
- return true
78
- }
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "noImplicitOverride": true,
8
- "noPropertyAccessFromIndexSignature": true,
9
- "noImplicitReturns": true,
10
- "noFallthroughCasesInSwitch": true
11
- },
12
- "files": [],
13
- "include": [],
14
- "references": [
15
- {
16
- "path": "./tsconfig.lib.json"
17
- },
18
- {
19
- "path": "./tsconfig.spec.json"
20
- }
21
- ]
22
- }
package/tsconfig.lib.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "outDir": "../../../dist/out-tsc",
6
- "declaration": true,
7
- "types": ["node"]
8
- },
9
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
10
- "include": ["src/**/*.ts"]
11
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9
- }