Skip to content

Commit

Permalink
Merge pull request #466 from instantcommerce/refactor/rebranding
Browse files Browse the repository at this point in the history
[refactor] rebranding
  • Loading branch information
ggurkal authored Aug 17, 2022
2 parents be3c0ce + 374eb1d commit da2c966
Show file tree
Hide file tree
Showing 33 changed files with 110 additions and 95 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Story of AMS
Copyright (c) 2021 Instant Commerce

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div align="center">
<a aria-label="Story of AMS logo" href="https://storyofams.com/" target="_blank" align="center">
<img src="https://avatars.githubusercontent.com/u/19343504" alt="Story of AMS" width="100">
<a aria-label="Instant Commerce logo" href="https://instantcommerce.io/" target="_blank" align="center">
<img src="https://avatars.githubusercontent.com/u/93975473" alt="Instant Commerce" width="100">
</a>
<h1 align="center">@storyofams/next-api-decorators</h1>
<h1 align="center">next-api-decorators</h1>
<p align="center">
<a aria-label="releases" href="https://GitHub.com/storyofams/next-api-decorators/releases/" target="_blank">
<img src="https://github.com/storyofams/next-api-decorators/workflows/Release/badge.svg">
<a aria-label="releases" href="https://github.com/instantcommerce/next-api-decorators/releases/" target="_blank">
<img src="https://github.com/instantcommerce/next-api-decorators/workflows/Release/badge.svg">
</a>
<a aria-label="npm" href="https://www.npmjs.com/package/@storyofams/next-api-decorators" target="_blank">
<img src="https://img.shields.io/npm/v/@storyofams/next-api-decorators">
<a aria-label="npm" href="https://www.npmjs.com/package/next-api-decorators" target="_blank">
<img src="https://img.shields.io/npm/v/next-api-decorators">
</a>
<a aria-label="codecov" href="https://codecov.io/gh/storyofams/next-api-decorators" target="_blank">
<img src="https://codecov.io/gh/storyofams/next-api-decorators/branch/master/graph/badge.svg?token=ZV0YT4HU5H">
<a aria-label="codecov" href="https://codecov.io/gh/instantcommerce/next-api-decorators" target="_blank">
<img src="https://codecov.io/gh/instantcommerce/next-api-decorators/branch/master/graph/badge.svg?token=ZV0YT4HU5H">
</a>
<a aria-label="stars" href="https://github.com/storyofams/next-api-decorators/stargazers/" target="_blank">
<img src="https://img.shields.io/github/stars/storyofams/next-api-decorators.svg?style=social&label=Star&maxAge=86400" />
<a aria-label="stars" href="https://github.com/instantcommerce/next-api-decorators/stargazers/" target="_blank">
<img src="https://img.shields.io/github/stars/instantcommerce/next-api-decorators.svg?style=social&label=Star&maxAge=86400" />
</a>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions examples/route-matching/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @storyofams/next-api-decorators/example
# next-api-decorators/example

Example usage of the `@storyofams/next-api-decorators` with Next.js
Example usage of the `next-api-decorators` with Next.js

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion examples/route-matching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type-check": "tsc"
},
"dependencies": {
"@storyofams/next-api-decorators": "../../dist",
"next-api-decorators": "../../dist",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"next": "^12.1.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/route-matching/pages/api/postman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Download,
DownloadFileResult,
createHandler,
} from '@storyofams/next-api-decorators';
} from 'next-api-decorators';

class Postman {
private pathToFile = `${process.cwd()}/postman.json`;
Expand Down
2 changes: 1 addition & 1 deletion examples/route-matching/pages/api/users/[[...params]].ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ParseNumberPipe,
DefaultValuePipe,
NotFoundException,
} from '@storyofams/next-api-decorators';
} from 'next-api-decorators';
import { User, sampleUserData } from '../../../data';
import { CreateUserInput, UpdateUserInput } from '../../../dto';

Expand Down
2 changes: 1 addition & 1 deletion examples/route-matching/postman.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"name": "@storyofams/next-api-decorators/example",
"name": "next-api-decorators/example",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
Expand Down
6 changes: 3 additions & 3 deletions examples/route-matching/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"next-api-decorators@../../dist":
version "0.0.0"

"@mdx-js/[email protected]":
version "1.6.22"
resolved "https://registry.yarnpkg.com/@mdx-js/util/-/util-1.6.22.tgz#219dfd89ae5b97a8801f015323ffa4b62f45718b"
Expand Down Expand Up @@ -390,9 +393,6 @@
resolved "https://registry.yarnpkg.com/@storyofams/eslint-config-ams/-/eslint-config-ams-1.1.3.tgz#ee6de44c89c6fabe401e6883f8b08ccc11fdc538"
integrity sha512-iygvgZQIu8CicKYzXdHfEfrGXf23BeSeHrIDdj+zl0f85Al1lPINTC90y9xtQdbKKgw9iXrlmuiaJIjL1o1Y1w==

"@storyofams/next-api-decorators@../../dist":
version "0.0.0"

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down
4 changes: 2 additions & 2 deletions examples/with-next-auth/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `@storyofams/next-api-decorators` example with `next-auth`
# `next-api-decorators` example with `next-auth`

Example usage of the `@storyofams/next-api-decorators` with `next-auth`. This example only covers logging in via Github, for more providers please refer to `next-auth` documentation [here](https://next-auth.js.org/configuration/providers).
Example usage of the `next-api-decorators` with `next-auth`. This example only covers logging in via Github, for more providers please refer to `next-auth` documentation [here](https://next-auth.js.org/configuration/providers).

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion examples/with-next-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type-check": "tsc"
},
"dependencies": {
"@storyofams/next-api-decorators": "../../dist",
"next-api-decorators": "../../dist",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"next": "^12.1.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-next-auth/pages/api/users/[[...params]].ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
NextFunction,
UnauthorizedException,
SetHeader,
} from '@storyofams/next-api-decorators';
} from 'next-api-decorators';
import { NextApiRequest, NextApiResponse } from 'next';
import { getToken } from 'next-auth/jwt';
import { User, sampleUserData } from '../../../data';
Expand Down
2 changes: 1 addition & 1 deletion examples/with-next-auth/postman.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"name": "@storyofams/next-api-decorators/example",
"name": "next-api-decorators/example",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
Expand Down
6 changes: 3 additions & 3 deletions examples/with-next-auth/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"next-api-decorators@../../dist":
version "0.0.0"

"@mdx-js/[email protected]":
version "1.6.22"
resolved "https://registry.yarnpkg.com/@mdx-js/util/-/util-1.6.22.tgz#219dfd89ae5b97a8801f015323ffa4b62f45718b"
Expand Down Expand Up @@ -395,9 +398,6 @@
resolved "https://registry.yarnpkg.com/@storyofams/eslint-config-ams/-/eslint-config-ams-1.1.3.tgz#ee6de44c89c6fabe401e6883f8b08ccc11fdc538"
integrity sha512-iygvgZQIu8CicKYzXdHfEfrGXf23BeSeHrIDdj+zl0f85Al1lPINTC90y9xtQdbKKgw9iXrlmuiaJIjL1o1Y1w==

"@storyofams/next-api-decorators@../../dist":
version "0.0.0"

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down
2 changes: 1 addition & 1 deletion lib/createHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { parseRequestUrl } from './internals/parseRequestUrl';
*
* @example
* ```ts
* import { createHandler, Get } from '@storyofams/next-api-decorators';
* import { createHandler, Get } from 'next-api-decorators';
*
* class Events {
* Get()
Expand Down
22 changes: 11 additions & 11 deletions lib/decorators/httpMethod.decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function applyHttpMethod(verb: HttpVerb, path: string) {
if (process.env.NODE_ENV === 'development' && path !== '/') {
loadPackage('path-to-regexp', {
context: '@' + verb.charAt(0).toUpperCase() + verb.slice(1).toLowerCase(),
docsUrl: 'https://github.com/storyofams/next-api-decorators#route-matching'
docsUrl: 'https://next-api-decorators.vercel.app/docs/routing/route-matching'
});
}

Expand All @@ -41,12 +41,12 @@ export function Get(): MethodDecorator;
/**
* Makes the method for the defined path a GET request handler.
*
* @param path Route path. Supports Express.js style [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* @param path Route path. Supports Express.js style [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
* including route parameters (e.g. `'/:id'`) and regular expressions.
*
* @remarks
* `path-to-regexp` needs to be installed, otherwise request handlers with non-empty path parameters will not be handled.
* More information: [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* More information: [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
*/
export function Get(path: string): MethodDecorator;
export function Get(path: string = '/'): MethodDecorator {
Expand All @@ -58,12 +58,12 @@ export function Post(): MethodDecorator;
/**
* Makes the method for the defined path a POST request handler.
*
* @param path Route path. Supports Express.js style [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* @param path Route path. Supports Express.js style [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
* including route parameters (e.g. `'/:id'`) and regular expressions.
*
* @remarks
* `path-to-regexp` needs to be installed, otherwise request handlers with non-empty path parameters will not be handled.
* More information: [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* More information: [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
*/
export function Post(path: string): MethodDecorator;
export function Post(path: string = '/'): MethodDecorator {
Expand All @@ -75,12 +75,12 @@ export function Put(): MethodDecorator;
/**
* Makes the method for the defined path a PUT request handler.
*
* @param path Route path. Supports Express.js style [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* @param path Route path. Supports Express.js style [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
* including route parameters (e.g. `'/:id'`) and regular expressions.
*
* @remarks
* `path-to-regexp` needs to be installed, otherwise request handlers with non-empty path parameters will not be handled.
* More information: [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* More information: [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
*/
export function Put(path: string): MethodDecorator;
export function Put(path: string = '/'): MethodDecorator {
Expand All @@ -92,12 +92,12 @@ export function Delete(): MethodDecorator;
/**
* Makes the method for the defined path a DELETE request handler.
*
* @param path Route path. Supports Express.js style [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* @param path Route path. Supports Express.js style [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
* including route parameters (e.g. `'/:id'`) and regular expressions.
*
* @remarks
* `path-to-regexp` needs to be installed, otherwise request handlers with non-empty path parameters will not be handled.
* More information: [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* More information: [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
*/
export function Delete(path: string): MethodDecorator;
export function Delete(path: string = '/'): MethodDecorator {
Expand All @@ -109,12 +109,12 @@ export function Patch(): MethodDecorator;
/**
* Makes the method for the defined path a PATCH request handler.
*
* @param path Route path. Supports Express.js style [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* @param path Route path. Supports Express.js style [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
* including route parameters (e.g. `'/:id'`) and regular expressions.
*
* @remarks
* `path-to-regexp` needs to be installed, otherwise request handlers with non-empty path parameters will not be handled.
* More information: [route matching](https://github.com/storyofams/next-api-decorators#route-matching)
* More information: [route matching](https://next-api-decorators.vercel.app/docs/routing/route-matching)
*/
export function Patch(path: string): MethodDecorator;
export function Patch(path: string = '/'): MethodDecorator {
Expand Down
12 changes: 6 additions & 6 deletions lib/internals/getCallerInfo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('getCallerInfo', () => {
providedStack ??
(nextJsVersion === 12_0_9
? `Error
at Object.getCallerInfo (/unix-example-path/node_modules/@storyofams/next-api-decorators/dist/internals/getCallerInfo.js:9:30)
at createHandler (/unix-example-path/node_modules/@storyofams/next-api-decorators/dist/createHandler.js:30:51)
at Object.getCallerInfo (/unix-example-path/node_modules/next-api-decorators/dist/internals/getCallerInfo.js:9:30)
at createHandler (/unix-example-path/node_modules/next-api-decorators/dist/createHandler.js:30:51)
at eval (webpack-internal:///(api)/./${path}.ts:91:144)
at Object.(api)/./${path}.ts (/unix-example-path/.next/server/${path}.js:32:1)
at __webpack_require__ (/unix-example-path/.next/server/webpack-api-runtime.js:33:42)
Expand All @@ -26,8 +26,8 @@ describe('getCallerInfo', () => {
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)`
: `Error
at Object.getCallerInfo (/unix-example-path/node_modules/@storyofams/next-api-decorators/dist/internals/getCallerInfo.js:9:30)
at createHandler (/unix-example-path/node_modules/@storyofams/next-api-decorators/dist/createHandler.js:30:51)
at Object.getCallerInfo (/unix-example-path/node_modules/next-api-decorators/dist/internals/getCallerInfo.js:9:30)
at createHandler (/unix-example-path/node_modules/next-api-decorators/dist/createHandler.js:30:51)
at eval (webpack-internal:///./${path}.ts:91:144)
at Object../${path}.ts (/unix-example-path/.next/server/${path}.js:32:1)
at __webpack_require__ (/unix-example-path/.next/server/webpack-api-runtime.js:33:42)
Expand Down Expand Up @@ -116,8 +116,8 @@ describe('getCallerInfo', () => {
'pages/api/users/deep/[[...params]]',
undefined,
'Error\n' +
' at Object.getCallerInfo (C:/Users/exampleuser/project/route-matching/node_modules/@storyofams/next-api-decorators/dist/internals/getCallerInfo.js:9:30)\n' +
' at createHandler (C:/Users/exampleuser/project/route-matching/node_modules/@storyofams/next-api-decorators/dist/createHandler.js:30:51)\n' +
' at Object.getCallerInfo (C:/Users/exampleuser/project/route-matching/node_modules/next-api-decorators/dist/internals/getCallerInfo.js:9:30)\n' +
' at createHandler (C:/Users/exampleuser/project/route-matching/node_modules/next-api-decorators/dist/createHandler.js:30:51)\n' +
' at Object../pages/api/users/deep/[[...params]].ts (C:/Users/exampleuser/project/route-matching/.next/server/pages/api/users/deep/[[...params]].js:287:142)\n' +
' at __webpack_require__ (C:/Users/exampleuser/project/route-matching/.next/server/webpack-runtime.js:25:42)\n' +
' at __webpack_exec__ (C:/Users/exampleuser/project/route-matching/.next/server/pages/api/users/deep/[[...params]].js:319:52)\n' +
Expand Down
14 changes: 7 additions & 7 deletions lib/internals/validateObject.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('validateObject', () => {
public email!: string;
}

const result = await validateObject(Dto, { secondaryEmail: 'dev@storyofams.com' });
const result = await validateObject(Dto, { secondaryEmail: 'dev@instantcommerce.io' });

expect(result).toHaveProperty('secondaryEmail', 'dev@storyofams.com');
expect(result).toHaveProperty('secondaryEmail', 'dev@instantcommerce.io');

spy.mockRestore();
});
Expand All @@ -32,9 +32,9 @@ describe('validateObject', () => {
public email!: string;
}

const result = await validateObject(Dto, { secondaryEmail: 'dev@storyofams.com' });
const result = await validateObject(Dto, { secondaryEmail: 'dev@instantcommerce.io' });

expect(result).toHaveProperty('secondaryEmail', 'dev@storyofams.com');
expect(result).toHaveProperty('secondaryEmail', 'dev@instantcommerce.io');

spy.mockRestore();
});
Expand All @@ -48,13 +48,13 @@ describe('validateObject', () => {

const result = await validateObject(
Dto,
{ email: 'dev@storyofams.com', secondaryEmail: 'hello@storyofams.com' },
{ email: 'dev@instantcommerce.io', secondaryEmail: 'hello@instantcommerce.io' },
{
transformOptions: { excludeExtraneousValues: true }
}
);

expect(result).toHaveProperty('email', 'dev@storyofams.com');
expect(result).not.toHaveProperty('secondaryEmail', 'hello@storyofams.com');
expect(result).toHaveProperty('email', 'dev@instantcommerce.io');
expect(result).not.toHaveProperty('secondaryEmail', 'hello@instantcommerce.io');
});
});
2 changes: 1 addition & 1 deletion lib/pipes/validators/validation.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('ValidationPipe', () => {
}

expect(
ValidationPipe()('{"email":"hello@storyofams.com","name":"Hello world"}', { metaType: DTO })
ValidationPipe()('{"email":"hello@instantcommerce.io","name":"Hello world"}', { metaType: DTO })
).rejects.toThrowError(BadRequestException);
});
});
4 changes: 2 additions & 2 deletions lib/pipes/validators/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export interface ValidationPipeOptions extends ValidatorOptions {
*
* @remarks
* `class-validator` and `class-transformer` need to be installed.
* More information: [data transfer object](https://github.com/storyofams/next-api-decorators#data-transfer-object)
* More information: [data transfer object](https://next-api-decorators.vercel.app/docs/validation)
*/
export function ValidationPipe(options?: ValidationPipeOptions): ParameterPipe<any> {
if (process.env.NODE_ENV === 'development') {
(['class-validator', 'class-transformer'] as const).forEach(requiredPackage =>
loadPackage(requiredPackage, {
context: 'ValidationPipe',
docsUrl: 'https://github.com/storyofams/next-api-decorators#data-transfer-object'
docsUrl: 'https://next-api-decorators.vercel.app/docs/validation'
})
);
}
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "@storyofams/next-api-decorators",
"name": "next-api-decorators",
"description": "Collection of decorators to create typed Next.js API routes, with easy request validation and transformation.",
"version": "0.0.0-development",
"author": {
"name": "Story of AMS",
"url": "https://storyofams.com",
"email": "dev@storyofams.com"
"name": "Instant Commerce",
"url": "https://instantcommerce.io",
"email": "dev@instantcommerce.io"
},
"main": "dist/index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/storyofams/next-api-decorators"
"url": "https://github.com/instantcommerce/next-api-decorators"
},
"bugs": {
"url": "https://github.com/storyofams/next-api-decorators/issues"
"url": "https://github.com/instantcommerce/next-api-decorators/issues"
},
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion website/docs/api/create-param-decorator.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ As a basic example, let's get the browser information of the client via a decora

First we create our decorator:
```ts
import { createParamDecorator } from '@storyofams/next-api-decorators';
import { createParamDecorator } from 'next-api-decorators';

export const UserAgent = createParamDecorator<string | undefined>(
req => req.headers['user-agent']
Expand Down
Loading

0 comments on commit da2c966

Please sign in to comment.