@or-sdk/api-tokens-lambda 1.0.1-beta.4009.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,168 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ApiTokensLambda = void 0;
40
+ var client_lambda_1 = require("@aws-sdk/client-lambda");
41
+ var ApiTokensLambda = (function () {
42
+ function ApiTokensLambda(params) {
43
+ this.lambda = new client_lambda_1.Lambda(params.isLocal ? {
44
+ apiVersion: '2015-03-31',
45
+ endpoint: 'http://localhost:3015',
46
+ } : {});
47
+ this.functionName = params.functionName;
48
+ }
49
+ ApiTokensLambda.prototype.invoke = function (event) {
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var response, buf, result;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0: return [4, this.lambda.invoke({
55
+ FunctionName: this.functionName,
56
+ Payload: Buffer.from(JSON.stringify({
57
+ action: event.action,
58
+ payload: event.payload,
59
+ })),
60
+ InvocationType: 'RequestResponse',
61
+ })];
62
+ case 1:
63
+ response = _a.sent();
64
+ buf = Buffer.from((response === null || response === void 0 ? void 0 : response.Payload) || []);
65
+ result = JSON.parse(buf.toString());
66
+ if (typeof result === 'object' && result !== null && 'error' in result) {
67
+ throw new Error(result.error);
68
+ }
69
+ return [2, result];
70
+ }
71
+ });
72
+ });
73
+ };
74
+ ApiTokensLambda.prototype.create = function (data) {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0: return [4, this.invoke({
79
+ action: 'create-token',
80
+ payload: data,
81
+ })];
82
+ case 1: return [2, _a.sent()];
83
+ }
84
+ });
85
+ });
86
+ };
87
+ ApiTokensLambda.prototype.findAll = function (data) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0: return [4, this.invoke({
92
+ action: 'find-all-tokens',
93
+ payload: data,
94
+ })];
95
+ case 1: return [2, _a.sent()];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ ApiTokensLambda.prototype.findById = function (data) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0: return [4, this.invoke({
105
+ action: 'find-token-by-id',
106
+ payload: data,
107
+ })];
108
+ case 1: return [2, _a.sent()];
109
+ }
110
+ });
111
+ });
112
+ };
113
+ ApiTokensLambda.prototype.findByName = function (data) {
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0: return [4, this.invoke({
118
+ action: 'find-token-by-name',
119
+ payload: data,
120
+ })];
121
+ case 1: return [2, _a.sent()];
122
+ }
123
+ });
124
+ });
125
+ };
126
+ ApiTokensLambda.prototype.update = function (data) {
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0: return [4, this.invoke({
131
+ action: 'update-token',
132
+ payload: data,
133
+ })];
134
+ case 1: return [2, _a.sent()];
135
+ }
136
+ });
137
+ });
138
+ };
139
+ ApiTokensLambda.prototype.delete = function (data) {
140
+ return __awaiter(this, void 0, void 0, function () {
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0: return [4, this.invoke({
144
+ action: 'delete-token',
145
+ payload: data,
146
+ })];
147
+ case 1: return [2, _a.sent()];
148
+ }
149
+ });
150
+ });
151
+ };
152
+ ApiTokensLambda.prototype.validate = function (token) {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ return __generator(this, function (_a) {
155
+ switch (_a.label) {
156
+ case 0: return [4, this.invoke({
157
+ action: 'validate-token',
158
+ payload: { token: token },
159
+ })];
160
+ case 1: return [2, _a.sent()];
161
+ }
162
+ });
163
+ });
164
+ };
165
+ return ApiTokensLambda;
166
+ }());
167
+ exports.ApiTokensLambda = ApiTokensLambda;
168
+ //# sourceMappingURL=ApiTokensLambda.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiTokensLambda.js","sourceRoot":"","sources":["../../src/ApiTokensLambda.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAgD;AAuBhD;IAaE,yBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YACxC,UAAU,EAAE,YAAY;YACxB,QAAQ,EAAE,uBAAuB;SAClC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACR,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;IAC1C,CAAC;IAEa,gCAAM,GAApB,UAAqB,KAAkB;;;;;4BACpB,WAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;4BACxC,YAAY,EAAE,IAAI,CAAC,YAAY;4BAC/B,OAAO,EAAE,MAAM,CAAC,IAAI,CAClB,IAAI,CAAC,SAAS,CAAC;gCACb,MAAM,EAAE,KAAK,CAAC,MAAM;gCACpB,OAAO,EAAE,KAAK,CAAC,OAAO;6BACvB,CAAC,CACH;4BACD,cAAc,EAAE,iBAAiB;yBAClC,CAAC,EAAA;;wBATI,QAAQ,GAAG,SASf;wBAEI,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,KAAI,EAAE,CAAC,CAAC;wBAC3C,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;wBAE1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ACd,CAAC,EAAA;4BAHF,WAAO,SAGL,EAAC;;;;KACJ;IAOK,kCAAQ,GAAd,UAAe,KAAa;;;;4BACnB,WAAM,IAAI,CAAC,MAAM,CAAC;4BACvB,MAAM,EAAE,gBAAgB;4BACxB,OAAO,EAAE,EAAE,KAAK,OAAA,EAAE;yBACnB,CAAC,EAAA;4BAHF,WAAO,SAGL,EAAC;;;;KACJ;IACH,sBAAC;AAAD,CAAC,AAxJD,IAwJC;AAxJY,0CAAe"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ApiTokensLambda = void 0;
18
+ var ApiTokensLambda_1 = require("./ApiTokensLambda");
19
+ Object.defineProperty(exports, "ApiTokensLambda", { enumerable: true, get: function () { return ApiTokensLambda_1.ApiTokensLambda; } });
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,94 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Lambda } from '@aws-sdk/client-lambda';
11
+ export class ApiTokensLambda {
12
+ constructor(params) {
13
+ this.lambda = new Lambda(params.isLocal ? {
14
+ apiVersion: '2015-03-31',
15
+ endpoint: 'http://localhost:3015',
16
+ } : {});
17
+ this.functionName = params.functionName;
18
+ }
19
+ invoke(event) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const response = yield this.lambda.invoke({
22
+ FunctionName: this.functionName,
23
+ Payload: Buffer.from(JSON.stringify({
24
+ action: event.action,
25
+ payload: event.payload,
26
+ })),
27
+ InvocationType: 'RequestResponse',
28
+ });
29
+ const buf = Buffer.from((response === null || response === void 0 ? void 0 : response.Payload) || []);
30
+ const result = JSON.parse(buf.toString());
31
+ if (typeof result === 'object' && result !== null && 'error' in result) {
32
+ throw new Error(result.error);
33
+ }
34
+ return result;
35
+ });
36
+ }
37
+ create(data) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return yield this.invoke({
40
+ action: 'create-token',
41
+ payload: data,
42
+ });
43
+ });
44
+ }
45
+ findAll(data) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return yield this.invoke({
48
+ action: 'find-all-tokens',
49
+ payload: data,
50
+ });
51
+ });
52
+ }
53
+ findById(data) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return yield this.invoke({
56
+ action: 'find-token-by-id',
57
+ payload: data,
58
+ });
59
+ });
60
+ }
61
+ findByName(data) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ return yield this.invoke({
64
+ action: 'find-token-by-name',
65
+ payload: data,
66
+ });
67
+ });
68
+ }
69
+ update(data) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ return yield this.invoke({
72
+ action: 'update-token',
73
+ payload: data,
74
+ });
75
+ });
76
+ }
77
+ delete(data) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ return yield this.invoke({
80
+ action: 'delete-token',
81
+ payload: data,
82
+ });
83
+ });
84
+ }
85
+ validate(token) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ return yield this.invoke({
88
+ action: 'validate-token',
89
+ payload: { token },
90
+ });
91
+ });
92
+ }
93
+ }
94
+ //# sourceMappingURL=ApiTokensLambda.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiTokensLambda.js","sourceRoot":"","sources":["../../src/ApiTokensLambda.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAuBhD,MAAM,OAAO,eAAe;IAa1B,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YACxC,UAAU,EAAE,YAAY;YACxB,QAAQ,EAAE,uBAAuB;SAClC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACR,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;IAC1C,CAAC;IAEa,MAAM,CAAC,KAAkB;;YACrC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;gBACxC,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,OAAO,EAAE,MAAM,CAAC,IAAI,CAClB,IAAI,CAAC,SAAS,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IAAI,CAAC,MAAM,CAAC;gBACvB,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;KAAA;IAUK,MAAM,CAAC,IAA2B;;YACtC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC;gBACvB,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;KAAA;IAOK,QAAQ,CAAC,KAAa;;YAC1B,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC;gBACvB,MAAM,EAAE,gBAAgB;gBACxB,OAAO,EAAE,EAAE,KAAK,EAAE;aACnB,CAAC,CAAC;QACL,CAAC;KAAA;CACF"}
@@ -0,0 +1,3 @@
1
+ export { ApiTokensLambda } from './ApiTokensLambda';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { ApiTokenCreatedResult, ApiTokenResult, CreateApiTokenPayload, DeleteApiTokenPayload, FindAllTokensPayload, FindTokenByIdPayload, FindTokenByNamePayload, LambdaConfig, UpdateApiTokenPayload, ValidateTokenResult } from './types';
2
+ export declare class ApiTokensLambda {
3
+ private readonly lambda;
4
+ private readonly functionName;
5
+ constructor(params: LambdaConfig);
6
+ private invoke;
7
+ create(data: CreateApiTokenPayload): Promise<ApiTokenCreatedResult>;
8
+ findAll(data: FindAllTokensPayload): Promise<ApiTokenResult[]>;
9
+ findById(data: FindTokenByIdPayload): Promise<ApiTokenResult>;
10
+ findByName(data: FindTokenByNamePayload): Promise<ApiTokenResult>;
11
+ update(data: UpdateApiTokenPayload): Promise<ApiTokenResult>;
12
+ delete(data: DeleteApiTokenPayload): Promise<{
13
+ success: boolean;
14
+ }>;
15
+ validate(token: string): Promise<ValidateTokenResult>;
16
+ }
17
+ //# sourceMappingURL=ApiTokensLambda.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiTokensLambda.d.ts","sourceRoot":"","sources":["../../src/ApiTokensLambda.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,EAEZ,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AASjB,qBAAa,eAAe;IAU1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAE1B,MAAM,EAAE,YAAY;YAQlB,MAAM;IAkCd,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAcnE,OAAO,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAe9D,QAAQ,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IAe7D,UAAU,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;IAoBjE,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC;IAe5D,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAYlE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAM5D"}
@@ -0,0 +1,3 @@
1
+ export { ApiTokensLambda } from './ApiTokensLambda';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,SAAS,CAAC"}
@@ -0,0 +1,83 @@
1
+ export type LambdaConfig = {
2
+ isLocal: boolean;
3
+ functionName: string;
4
+ };
5
+ export type LambdaEvent = {
6
+ action: string;
7
+ payload: any;
8
+ };
9
+ export type CreateApiTokenPayload = {
10
+ name: string;
11
+ role: string;
12
+ accountId: string;
13
+ createdBy?: string;
14
+ expiresAt?: string | null;
15
+ metadata?: Record<string, unknown> | null;
16
+ permissions?: string[];
17
+ };
18
+ export type FindAllTokensPayload = {
19
+ accountId?: string;
20
+ isActive?: boolean;
21
+ };
22
+ export type FindTokenByIdPayload = {
23
+ id: string;
24
+ accountId: string;
25
+ role: string;
26
+ };
27
+ export type FindTokenByNamePayload = {
28
+ name: string;
29
+ accountId: string;
30
+ role: string;
31
+ };
32
+ export type UpdateApiTokenPayload = {
33
+ id: string;
34
+ name?: string;
35
+ isActive?: boolean;
36
+ expiresAt?: string | null;
37
+ metadata?: Record<string, unknown> | null;
38
+ permissions?: string[];
39
+ accountId: string;
40
+ role: string;
41
+ };
42
+ export type DeleteApiTokenPayload = {
43
+ id: string;
44
+ accountId: string;
45
+ role: string;
46
+ };
47
+ export type ValidateApiTokenPayload = {
48
+ token: string;
49
+ };
50
+ export type ApiTokenResult = {
51
+ id: string;
52
+ name: string;
53
+ role: string;
54
+ accountId: string;
55
+ createdBy: string | null;
56
+ isActive: boolean;
57
+ expiresAt: string | null;
58
+ metadata: Record<string, unknown> | null;
59
+ createdAt: string;
60
+ updatedAt: string;
61
+ permissions: string[];
62
+ };
63
+ export type ApiTokenCreatedResult = ApiTokenResult & {
64
+ token: string;
65
+ };
66
+ export type PermissionGroup = {
67
+ serviceName: string;
68
+ permissions: {
69
+ name: string;
70
+ effect: boolean;
71
+ }[];
72
+ };
73
+ export type ValidateTokenResult = {
74
+ allow: boolean;
75
+ reason?: string;
76
+ tokenId?: string;
77
+ accountId?: string;
78
+ userId?: string | null;
79
+ role?: string;
80
+ expire?: number | null;
81
+ permissions?: PermissionGroup[];
82
+ };
83
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,M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,CAAA;KAAE,EAAE,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,eAAe,EAAE,CAAC;CACjC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@or-sdk/api-tokens-lambda",
3
+ "version": "1.0.1-beta.4009.0",
4
+ "license": "Apache-2.0",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "scripts": {
9
+ "build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
10
+ "build:cjs": "tsc --project tsconfig.json",
11
+ "build:esm": "tsc --project tsconfig.esm.json",
12
+ "build:types": "tsc --project tsconfig.types.json",
13
+ "build:watch": "concurrently -r --hide 1,2 \"pnpm build:watch:cjs\" \"pnpm build:watch:esm\" \"pnpm build:watch:types\"",
14
+ "build:watch:cjs": "tsc --project tsconfig.json -w",
15
+ "build:watch:esm": "tsc --project tsconfig.esm.json -w",
16
+ "build:watch:types": "tsc --project tsconfig.types.json -w",
17
+ "clean": "rm -rf ./dist",
18
+ "dev": "pnpm build:watch:esm"
19
+ },
20
+ "dependencies": {
21
+ "@aws-sdk/client-lambda": "3.726.0"
22
+ },
23
+ "devDependencies": {
24
+ "concurrently": "9.0.1",
25
+ "typescript": "5.6.2"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }
@@ -0,0 +1,176 @@
1
+ import { Lambda } from '@aws-sdk/client-lambda';
2
+
3
+ import {
4
+ ApiTokenCreatedResult,
5
+ ApiTokenResult,
6
+ CreateApiTokenPayload,
7
+ DeleteApiTokenPayload,
8
+ FindAllTokensPayload,
9
+ FindTokenByIdPayload,
10
+ FindTokenByNamePayload,
11
+ LambdaConfig,
12
+ LambdaEvent,
13
+ UpdateApiTokenPayload,
14
+ ValidateTokenResult,
15
+ } from './types';
16
+
17
+ /**
18
+ * Client for interacting with the API Tokens Lambda function
19
+ * ## Installation:
20
+ * ```
21
+ * $ npm i @or-sdk/api-tokens-lambda
22
+ * ```
23
+ */
24
+ export class ApiTokensLambda {
25
+ /**
26
+ * ```typescript
27
+ * import { ApiTokensLambda } from '@or-sdk/api-tokens-lambda'
28
+ * const apiTokensLambda = new ApiTokensLambda({
29
+ * isLocal: false,
30
+ * functionName: 'api-tokens-core-function-name'
31
+ * });
32
+ * ```
33
+ */
34
+ private readonly lambda: Lambda;
35
+ private readonly functionName: string;
36
+
37
+ constructor(params: LambdaConfig) {
38
+ this.lambda = new Lambda(params.isLocal ? {
39
+ apiVersion: '2015-03-31',
40
+ endpoint: 'http://localhost:3015',
41
+ } : {});
42
+ this.functionName = params.functionName;
43
+ }
44
+
45
+ private async invoke(event: LambdaEvent) {
46
+ const response = await this.lambda.invoke({
47
+ FunctionName: this.functionName,
48
+ Payload: Buffer.from(
49
+ JSON.stringify({
50
+ action: event.action,
51
+ payload: event.payload,
52
+ }),
53
+ ),
54
+ InvocationType: 'RequestResponse',
55
+ });
56
+
57
+ const buf = Buffer.from(response?.Payload || []);
58
+ const result = JSON.parse(buf.toString());
59
+
60
+ if (typeof result === 'object' && result !== null && 'error' in result) {
61
+ throw new Error(result.error);
62
+ }
63
+
64
+ return result;
65
+ }
66
+
67
+ /**
68
+ * Creates a new API token
69
+ * @param {CreateApiTokenPayload} data - Token creation data
70
+ * @param {string} data.name - Name of the API token
71
+ * @param {string} data.role - Role assigned to the API token
72
+ * @param {string} data.accountId - Account identifier
73
+ * @param {string} [data.createdBy] - User who created the token
74
+ * @param {string} [data.expiresAt] - Token expiration date (ISO 8601)
75
+ * @param {Record<string, unknown>} [data.metadata] - Additional metadata
76
+ * @param {string[]} [data.permissions] - Permission scopes
77
+ * @returns {Promise<ApiTokenCreatedResult>} Created token including the raw token string
78
+ */
79
+ async create(data: CreateApiTokenPayload): Promise<ApiTokenCreatedResult> {
80
+ return await this.invoke({
81
+ action: 'create-token',
82
+ payload: data,
83
+ });
84
+ }
85
+
86
+ /**
87
+ * Lists all API tokens for an account
88
+ * @param {FindAllTokensPayload} data - Filter parameters
89
+ * @param {string} [data.accountId] - Account identifier
90
+ * @param {boolean} [data.isActive] - Filter by active status
91
+ * @returns {Promise<ApiTokenResult[]>} List of API tokens
92
+ */
93
+ async findAll(data: FindAllTokensPayload): Promise<ApiTokenResult[]> {
94
+ return await this.invoke({
95
+ action: 'find-all-tokens',
96
+ payload: data,
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Gets an API token by its ID
102
+ * @param {FindTokenByIdPayload} data - Request parameters
103
+ * @param {string} data.id - API Token identifier
104
+ * @param {string} data.accountId - Account identifier
105
+ * @param {string} data.role - User role for authorization
106
+ * @returns {Promise<ApiTokenResult>} The API token
107
+ */
108
+ async findById(data: FindTokenByIdPayload): Promise<ApiTokenResult> {
109
+ return await this.invoke({
110
+ action: 'find-token-by-id',
111
+ payload: data,
112
+ });
113
+ }
114
+
115
+ /**
116
+ * Gets an API token by its name
117
+ * @param {FindTokenByNamePayload} data - Request parameters
118
+ * @param {string} data.name - API Token name
119
+ * @param {string} data.accountId - Account identifier
120
+ * @param {string} data.role - User role for authorization
121
+ * @returns {Promise<ApiTokenResult>} The API token
122
+ */
123
+ async findByName(data: FindTokenByNamePayload): Promise<ApiTokenResult> {
124
+ return await this.invoke({
125
+ action: 'find-token-by-name',
126
+ payload: data,
127
+ });
128
+ }
129
+
130
+ /**
131
+ * Updates an existing API token
132
+ * @param {UpdateApiTokenPayload} data - Update parameters
133
+ * @param {string} data.id - API Token identifier
134
+ * @param {string} [data.name] - Name of the API token
135
+ * @param {boolean} [data.isActive] - Whether the token is active
136
+ * @param {string} [data.expiresAt] - Token expiration date (ISO 8601)
137
+ * @param {Record<string, unknown>} [data.metadata] - Additional metadata
138
+ * @param {string[]} [data.permissions] - Replace all linked permissions
139
+ * @param {string} data.accountId - Account identifier
140
+ * @param {string} data.role - User role for authorization
141
+ * @returns {Promise<ApiTokenResult>} Updated API token
142
+ */
143
+ async update(data: UpdateApiTokenPayload): Promise<ApiTokenResult> {
144
+ return await this.invoke({
145
+ action: 'update-token',
146
+ payload: data,
147
+ });
148
+ }
149
+
150
+ /**
151
+ * Deletes an API token
152
+ * @param {DeleteApiTokenPayload} data - Delete parameters
153
+ * @param {string} data.id - API Token identifier
154
+ * @param {string} data.accountId - Account identifier
155
+ * @param {string} data.role - User role for authorization
156
+ * @returns {Promise<{ success: boolean }>}
157
+ */
158
+ async delete(data: DeleteApiTokenPayload): Promise<{ success: boolean }> {
159
+ return await this.invoke({
160
+ action: 'delete-token',
161
+ payload: data,
162
+ });
163
+ }
164
+
165
+ /**
166
+ * Validates a raw API token string
167
+ * @param {string} token - Raw API token string to validate
168
+ * @returns {Promise<ValidateTokenResult>} Validation result
169
+ */
170
+ async validate(token: string): Promise<ValidateTokenResult> {
171
+ return await this.invoke({
172
+ action: 'validate-token',
173
+ payload: { token },
174
+ });
175
+ }
176
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { ApiTokensLambda } from './ApiTokensLambda';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,91 @@
1
+ export type LambdaConfig = {
2
+ isLocal: boolean;
3
+ functionName: string;
4
+ };
5
+
6
+ export type LambdaEvent = {
7
+ action: string;
8
+ payload: any;
9
+ };
10
+
11
+ export type CreateApiTokenPayload = {
12
+ name: string;
13
+ role: string;
14
+ accountId: string;
15
+ createdBy?: string;
16
+ expiresAt?: string | null;
17
+ metadata?: Record<string, unknown> | null;
18
+ permissions?: string[];
19
+ };
20
+
21
+ export type FindAllTokensPayload = {
22
+ accountId?: string;
23
+ isActive?: boolean;
24
+ };
25
+
26
+ export type FindTokenByIdPayload = {
27
+ id: string;
28
+ accountId: string;
29
+ role: string;
30
+ };
31
+
32
+ export type FindTokenByNamePayload = {
33
+ name: string;
34
+ accountId: string;
35
+ role: string;
36
+ };
37
+
38
+ export type UpdateApiTokenPayload = {
39
+ id: string;
40
+ name?: string;
41
+ isActive?: boolean;
42
+ expiresAt?: string | null;
43
+ metadata?: Record<string, unknown> | null;
44
+ permissions?: string[];
45
+ accountId: string;
46
+ role: string;
47
+ };
48
+
49
+ export type DeleteApiTokenPayload = {
50
+ id: string;
51
+ accountId: string;
52
+ role: string;
53
+ };
54
+
55
+ export type ValidateApiTokenPayload = {
56
+ token: string;
57
+ };
58
+
59
+ export type ApiTokenResult = {
60
+ id: string;
61
+ name: string;
62
+ role: string;
63
+ accountId: string;
64
+ createdBy: string | null;
65
+ isActive: boolean;
66
+ expiresAt: string | null;
67
+ metadata: Record<string, unknown> | null;
68
+ createdAt: string;
69
+ updatedAt: string;
70
+ permissions: string[];
71
+ };
72
+
73
+ export type ApiTokenCreatedResult = ApiTokenResult & {
74
+ token: string;
75
+ };
76
+
77
+ export type PermissionGroup = {
78
+ serviceName: string;
79
+ permissions: { name: string; effect: boolean }[];
80
+ };
81
+
82
+ export type ValidateTokenResult = {
83
+ allow: boolean;
84
+ reason?: string;
85
+ tokenId?: string;
86
+ accountId?: string;
87
+ userId?: string | null;
88
+ role?: string;
89
+ expire?: number | null;
90
+ permissions?: PermissionGroup[];
91
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.esm.json",
3
+ "compilerOptions": {
4
+ "declarationDir": "./dist/types",
5
+ "rootDir": "./src",
6
+ "declaration": true
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/esm",
5
+ "declarationDir": "./dist/types",
6
+ "module": "ES6",
7
+ "target": "es6",
8
+ "rootDir": "./src",
9
+ "declaration": true,
10
+ "declarationMap": true
11
+ }
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types/",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "emitDeclarationOnly": true
9
+ }
10
+ }