Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 3.1.0

**Housekeeping:**

- Slim down the default request context to `headers`, `ip`, and `library`. The
client id is carried by `headers` (the `x-castle-client-id` header / `__cid`
cookie) and resolved by Castle server-side, so the SDK no longer derives it
separately.
- Remove the internal client-id extraction service and the now-unused cookie
helper (`HeadersGetCookieService`) along with the `cookies` plumbing in
`ContextGetDefaultService` / `ContextPrepareService`.

## 3.0.0

**BREAKING CHANGES:**
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const castle = new Castle({ apiSecret: process.env.CASTLE_API_SECRET });

const context = ContextPrepareService.call(
req,
{ cookies: req.cookies },
undefined,
castle.configuration
);

Expand Down Expand Up @@ -74,7 +74,7 @@ With CommonJS:
const { Castle, ContextPrepareService } = require('@castleio/sdk');
```

`ContextPrepareService.call(request, options, configuration)` extracts the IP, headers, and client id that Castle needs from a Node `request` object. See [Advanced configuration](#advanced-configuration) for how header allow/deny lists and proxy chains are resolved.
`ContextPrepareService.call(request, options, configuration)` extracts the IP and headers that Castle needs from a Node `request` object. See [Advanced configuration](#advanced-configuration) for how header allow/deny lists and proxy chains are resolved.

## Configuration

Expand Down
15 changes: 8 additions & 7 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Releasing

1. Create branch `release/X.Y.Z` from `master`.
1. Create branch `release/X.Y.Z` from `develop`.
2. Update `version` in `package.json` to the new version
3. Run `npm install` (to refresh `package-lock.json`)
4. Update the `CHANGELOG.md` for the impending release
5. `git commit -am "release X.Y.Z"` (where X.Y.Z is the new version)
6. Push to Github, make PR to the `master` branch, and when approved, merge.
7. Make a release on Github from the `master` branch, specify tag as `vX.Y.Z` to create a tag.
8. `git checkout master && git pull`
9. Clean unversioned files: `git clean -fdx dist`
10. `npm run build && npm pack` to verify the package
11. `npm publish`
6. Push to Github, make PR to the `develop` branch, and when approved, merge.
7. Pull latest `develop`, merge it into `master`, and push `master` to `origin`.
8. Make a release on Github from the `master` branch, specify tag as `vX.Y.Z` to create a tag.
9. `git checkout master && git pull`
10. Clean unversioned files: `git clean -fdx dist`
11. `npm run build && npm pack` to verify the package
12. `npm publish`
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json.schemastore.org/package",
"name": "@castleio/sdk",
"description": "Castle SDK for Node",
"version": "3.0.0",
"version": "3.1.0",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion src/client-id/client-id.module.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/client-id/services/client-id-extract.service.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/client-id/services/index.ts

This file was deleted.

10 changes: 1 addition & 9 deletions src/context/services/context-get-default.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { isEmpty, pickByTruthy } from '../../utils/object';
import { Configuration } from '../../configuration';
import { ClientIdExtractService } from '../../client-id/client-id.module';
import { HeadersExtractService } from '../../headers/headers.module';
import { IPsExtractService } from '../../ips/ips.module';
import { version } from '../../../package.json';
import type { IncomingHttpHeaders } from 'http2';

const requestContextData = (
request: { headers: IncomingHttpHeaders },
cookies: string | undefined,
configuration: Configuration
): { [key: string]: any } => {
if (isEmpty(request)) {
return {};
}

const cookiesForClientId =
cookies || (request.headers as { [key: string]: any })?.cookies;
return {
client_id:
ClientIdExtractService.call(request.headers, cookiesForClientId) || false,
active: true,
headers: HeadersExtractService.call(request.headers, configuration),
ip: IPsExtractService.call(request.headers, configuration),
};
Expand All @@ -29,11 +22,10 @@ const requestContextData = (
export const ContextGetDefaultService = {
call: (
request: { headers: IncomingHttpHeaders },
cookies: string | undefined,
configuration: Configuration
): { [key: string]: any } => {
return {
...pickByTruthy(requestContextData(request, cookies, configuration)),
...pickByTruthy(requestContextData(request, configuration)),
library: {
name: 'castle-node',
version,
Expand Down
1 change: 0 additions & 1 deletion src/context/services/context-prepare.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const ContextPrepareService = {
) => {
const defaultContext = ContextGetDefaultService.call(
request,
options?.cookies,
configuration
);
return deepMerge(defaultContext, options?.context);
Expand Down
20 changes: 0 additions & 20 deletions src/headers/services/headers-get-cookie.service.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/headers/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './headers-extract.service';
export * from './headers-get-cookie.service';
53 changes: 0 additions & 53 deletions test/client-id/services/client-id-extract.service.test.ts

This file was deleted.

7 changes: 1 addition & 6 deletions test/context/services/context-get-default.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('ContextGetDefaultService', () => {
name: 'castle-node',
version,
},
client_id: 'client_id',
ip: '1.2.3.4',
};

Expand All @@ -35,11 +34,7 @@ describe('ContextGetDefaultService', () => {
} as ExpressRequest;

it('generates default context', () => {
const received = ContextGetDefaultService.call(
mockRequest,
undefined,
config
);
const received = ContextGetDefaultService.call(mockRequest, config);
expect(received).toMatchObject(expected);
});
});
Expand Down
70 changes: 0 additions & 70 deletions test/headers/services/headers-get-cookie.service.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/payload/services/payload-prepare-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('PayloadPrepareService', () => {
version,
},
client_id: '123',
active: true,
},
user_id: '123',
};
Expand Down
Loading