@rare-id/platform-kit-nest 0.1.0

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.
@@ -0,0 +1,22 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { RarePlatformKit } from '@rare-id/platform-kit-web';
3
+
4
+ declare const RARE_PLATFORM_KIT: unique symbol;
5
+ declare class RareAuthGuard implements CanActivate {
6
+ private readonly kit;
7
+ constructor(kit: RarePlatformKit);
8
+ canActivate(context: ExecutionContext): Promise<boolean>;
9
+ }
10
+ declare class RarePlatformKitModule {
11
+ private constructor();
12
+ static forRoot(kit: RarePlatformKit): {
13
+ module: typeof RarePlatformKitModule;
14
+ providers: (typeof RareAuthGuard | {
15
+ provide: symbol;
16
+ useValue: RarePlatformKit;
17
+ })[];
18
+ exports: (symbol | typeof RareAuthGuard)[];
19
+ };
20
+ }
21
+
22
+ export { RARE_PLATFORM_KIT, RareAuthGuard, RarePlatformKitModule };
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
12
+
13
+ // src/index.ts
14
+ import {
15
+ Inject,
16
+ Injectable,
17
+ Module
18
+ } from "@nestjs/common";
19
+ var RARE_PLATFORM_KIT = /* @__PURE__ */ Symbol("RARE_PLATFORM_KIT");
20
+ var RareAuthGuard = class {
21
+ constructor(kit) {
22
+ this.kit = kit;
23
+ }
24
+ async canActivate(context) {
25
+ const req = context.switchToHttp().getRequest();
26
+ const sessionToken = String(req.headers.authorization ?? "").replace(
27
+ /^Bearer\s+/i,
28
+ ""
29
+ );
30
+ if (!sessionToken) {
31
+ return false;
32
+ }
33
+ try {
34
+ await this.kit.verifyAction({
35
+ sessionToken,
36
+ action: String(req.body?.action ?? "request"),
37
+ actionPayload: req.body?.action_payload ?? {},
38
+ nonce: String(req.body?.nonce ?? ""),
39
+ issuedAt: Number(req.body?.issued_at ?? 0),
40
+ expiresAt: Number(req.body?.expires_at ?? 0),
41
+ signatureBySession: String(req.body?.signature_by_session ?? "")
42
+ });
43
+ return true;
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
48
+ };
49
+ RareAuthGuard = __decorateClass([
50
+ Injectable(),
51
+ __decorateParam(0, Inject(RARE_PLATFORM_KIT))
52
+ ], RareAuthGuard);
53
+ var RarePlatformKitModule = class {
54
+ constructor() {
55
+ }
56
+ static forRoot(kit) {
57
+ return {
58
+ module: RarePlatformKitModule,
59
+ providers: [
60
+ {
61
+ provide: RARE_PLATFORM_KIT,
62
+ useValue: kit
63
+ },
64
+ RareAuthGuard
65
+ ],
66
+ exports: [RARE_PLATFORM_KIT, RareAuthGuard]
67
+ };
68
+ }
69
+ };
70
+ RarePlatformKitModule = __decorateClass([
71
+ Module({})
72
+ ], RarePlatformKitModule);
73
+ export {
74
+ RARE_PLATFORM_KIT,
75
+ RareAuthGuard,
76
+ RarePlatformKitModule
77
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@rare-id/platform-kit-nest",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "sideEffects": false,
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/0xsidfan/Rare.git",
21
+ "directory": "rare-platform-kit-ts/packages/platform-kit-nest"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public",
25
+ "provenance": false
26
+ },
27
+ "dependencies": {
28
+ "@nestjs/common": "^11.0.11",
29
+ "reflect-metadata": "^0.2.2",
30
+ "rxjs": "^7.8.2",
31
+ "@rare-id/platform-kit-web": "0.1.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup src/index.ts --format esm --dts",
35
+ "test": "vitest run",
36
+ "lint": "biome check src",
37
+ "typecheck": "tsc -p tsconfig.json --noEmit"
38
+ }
39
+ }