@or-sdk/api-tokens 1.0.1-beta.3986.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.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ ## Installation:
2
+ ```
3
+ $ npm i @or-sdk/api-tokens
4
+ ```
5
+
6
+
7
+ ## Usage:
8
+ ```typescript
9
+ import { ApiTokens } from '@or-sdk/api-tokens'
10
+
11
+ const apiTokens = new ApiTokens({
12
+ token: 'my-account-token-string',
13
+ apiTokensUrl: 'http://example.api-tokens/endpoint'
14
+ });
15
+ ```
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ 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);
28
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.ApiTokens = void 0;
55
+ var base_1 = require("@or-sdk/base");
56
+ var constants_1 = require("./constants");
57
+ var ApiTokens = (function (_super) {
58
+ __extends(ApiTokens, _super);
59
+ function ApiTokens(params) {
60
+ var token = params.token, discoveryUrl = params.discoveryUrl, apiTokensUrl = params.apiTokensUrl;
61
+ return _super.call(this, {
62
+ token: token,
63
+ discoveryUrl: discoveryUrl,
64
+ serviceUrl: apiTokensUrl,
65
+ serviceKey: constants_1.SERVICE_KEY,
66
+ }) || this;
67
+ }
68
+ ApiTokens.prototype.create = function (params) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ var data;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0: return [4, this.callApiV2({
74
+ method: 'POST',
75
+ route: '/api-tokens',
76
+ data: params,
77
+ })];
78
+ case 1:
79
+ data = _a.sent();
80
+ return [2, data];
81
+ }
82
+ });
83
+ });
84
+ };
85
+ ApiTokens.prototype.list = function () {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ var data;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0: return [4, this.callApiV2({
91
+ method: 'GET',
92
+ route: '/api-tokens',
93
+ })];
94
+ case 1:
95
+ data = _a.sent();
96
+ return [2, data];
97
+ }
98
+ });
99
+ });
100
+ };
101
+ ApiTokens.prototype.getById = function (id) {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var data;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0: return [4, this.callApiV2({
107
+ method: 'GET',
108
+ route: "/api-tokens/".concat(id),
109
+ })];
110
+ case 1:
111
+ data = _a.sent();
112
+ return [2, data];
113
+ }
114
+ });
115
+ });
116
+ };
117
+ ApiTokens.prototype.update = function (id, params) {
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var data;
120
+ return __generator(this, function (_a) {
121
+ switch (_a.label) {
122
+ case 0: return [4, this.callApiV2({
123
+ method: 'PUT',
124
+ route: "/api-tokens/".concat(id),
125
+ data: params,
126
+ })];
127
+ case 1:
128
+ data = _a.sent();
129
+ return [2, data];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ ApiTokens.prototype.delete = function (id) {
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ var data;
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0: return [4, this.callApiV2({
140
+ method: 'DELETE',
141
+ route: "/api-tokens/".concat(id),
142
+ })];
143
+ case 1:
144
+ data = _a.sent();
145
+ return [2, data];
146
+ }
147
+ });
148
+ });
149
+ };
150
+ ApiTokens.prototype.validate = function (token) {
151
+ return __awaiter(this, void 0, void 0, function () {
152
+ var data;
153
+ return __generator(this, function (_a) {
154
+ switch (_a.label) {
155
+ case 0: return [4, this.callApiV2({
156
+ method: 'POST',
157
+ route: '/api-tokens/validate',
158
+ data: { token: token },
159
+ })];
160
+ case 1:
161
+ data = _a.sent();
162
+ return [2, data];
163
+ }
164
+ });
165
+ });
166
+ };
167
+ return ApiTokens;
168
+ }(base_1.Base));
169
+ exports.ApiTokens = ApiTokens;
170
+ //# sourceMappingURL=ApiTokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiTokens.js","sourceRoot":"","sources":["../../src/ApiTokens.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AAEpC,yCAA0C;AAiB1C;IAA+B,6BAAI;IAUjC,mBAAY,MAAuB;QACzB,IAAA,KAAK,GAAiC,MAAM,MAAvC,EAAE,YAAY,GAAmB,MAAM,aAAzB,EAAE,YAAY,GAAK,MAAM,aAAX,CAAY;QACrD,OAAA,MAAK,YAAC;YACJ,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,UAAU,EAAE,YAAY;YACxB,UAAU,EAAE,uBAAW;SACxB,CAAC,SAAC;IACL,CAAC;IAYK,0BAAM,GAAZ,UAAa,MAAyB;;;;;4BACvB,WAAM,IAAI,CAAC,SAAS,CAAuB;4BACtD,MAAM,EAAE,MAAM;4BACd,KAAK,EAAE,aAAa;4BACpB,IAAI,EAAE,MAAM;yBACb,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBACF,WAAO,IAAI,EAAC;;;;KACb;IAMK,wBAAI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(exports, "__esModule", { value: true });
3
+ exports.SERVICE_KEY = void 0;
4
+ exports.SERVICE_KEY = 'api-tokens-api';
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,gBAAgB,CAAC"}
@@ -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.ApiTokens = void 0;
18
+ var ApiTokens_1 = require("./ApiTokens");
19
+ Object.defineProperty(exports, "ApiTokens", { enumerable: true, get: function () { return ApiTokens_1.ApiTokens; } });
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,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,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,80 @@
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 { Base } from '@or-sdk/base';
11
+ import { SERVICE_KEY } from './constants';
12
+ export class ApiTokens extends Base {
13
+ constructor(params) {
14
+ const { token, discoveryUrl, apiTokensUrl } = params;
15
+ super({
16
+ token,
17
+ discoveryUrl,
18
+ serviceUrl: apiTokensUrl,
19
+ serviceKey: SERVICE_KEY,
20
+ });
21
+ }
22
+ create(params) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const data = yield this.callApiV2({
25
+ method: 'POST',
26
+ route: '/api-tokens',
27
+ data: params,
28
+ });
29
+ return data;
30
+ });
31
+ }
32
+ list() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const data = yield this.callApiV2({
35
+ method: 'GET',
36
+ route: '/api-tokens',
37
+ });
38
+ return data;
39
+ });
40
+ }
41
+ getById(id) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const data = yield this.callApiV2({
44
+ method: 'GET',
45
+ route: `/api-tokens/${id}`,
46
+ });
47
+ return data;
48
+ });
49
+ }
50
+ update(id, params) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const data = yield this.callApiV2({
53
+ method: 'PUT',
54
+ route: `/api-tokens/${id}`,
55
+ data: params,
56
+ });
57
+ return data;
58
+ });
59
+ }
60
+ delete(id) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const data = yield this.callApiV2({
63
+ method: 'DELETE',
64
+ route: `/api-tokens/${id}`,
65
+ });
66
+ return data;
67
+ });
68
+ }
69
+ validate(token) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const data = yield this.callApiV2({
72
+ method: 'POST',
73
+ route: '/api-tokens/validate',
74
+ data: { token },
75
+ });
76
+ return data;
77
+ });
78
+ }
79
+ }
80
+ //# sourceMappingURL=ApiTokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiTokens.js","sourceRoot":"","sources":["../../src/ApiTokens.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAiB1C,MAAM,OAAO,SAAU,SAAQ,IAAI;IAUjC,YAAY,MAAuB;QACjC,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QACrD,KAAK,CAAC;YACJ,KAAK;YACL,YAAY;YACZ,UAAU,EAAE,YAAY;YACxB,UAAU,EAAE,WAAW;SACxB,CAAC,CAAC;IACL,CAAC;IAYK,MAAM,CAAC,MAAyB;;YACpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAuB;gBACtD,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,aAAa;gBACpB,IAAI,EAAE,MAAM;aACb,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAMK,IAAI;;YACR,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAa;gBAC5C,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,aAAa;aACrB,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAOK,OAAO,CAAC,EAAU;;YACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAW;gBAC1C,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,eAAe,EAAE,EAAE;aAC3B,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAcK,MAAM,CAAC,EAAU,EAAE,MAAyB;;YAChD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAW;gBAC1C,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,eAAe,EAAE,EAAE;gBAC1B,IAAI,EAAE,MAAM;aACb,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAOK,MAAM,CAAC,EAAU;;YACrB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAuB;gBACtD,MAAM,EAAE,QAAQ;gBAChB,KAAK,EAAE,eAAe,EAAE,EAAE;aAC3B,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAOK,QAAQ,CAAC,KAAa;;YAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAA2B;gBAC1D,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,sBAAsB;gBAC7B,IAAI,EAAE,EAAE,KAAK,EAAE;aAChB,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;CACF"}
@@ -0,0 +1,2 @@
1
+ export const SERVICE_KEY = 'api-tokens-api';
2
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { ApiTokens } from './ApiTokens';
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,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,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,14 @@
1
+ import { Base } from '@or-sdk/base';
2
+ import { ApiToken, ApiTokensConfig, ApiTokenWithRawValue, CreateApiTokenDto, UpdateApiTokenDto, ValidateApiTokenResponse } from './types';
3
+ export declare class ApiTokens extends Base {
4
+ constructor(params: ApiTokensConfig);
5
+ create(params: CreateApiTokenDto): Promise<ApiTokenWithRawValue>;
6
+ list(): Promise<ApiToken[]>;
7
+ getById(id: string): Promise<ApiToken>;
8
+ update(id: string, params: UpdateApiTokenDto): Promise<ApiToken>;
9
+ delete(id: string): Promise<{
10
+ success: boolean;
11
+ }>;
12
+ validate(token: string): Promise<ValidateApiTokenResponse>;
13
+ }
14
+ //# sourceMappingURL=ApiTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiTokens.d.ts","sourceRoot":"","sources":["../../src/ApiTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,OAAO,EACL,QAAQ,EACR,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AASjB,qBAAa,SAAU,SAAQ,IAAI;gBAUrB,MAAM,EAAE,eAAe;IAoB7B,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAahE,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAa3B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAoBtC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAchE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAajD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAQjE"}
@@ -0,0 +1,2 @@
1
+ export declare const SERVICE_KEY = "api-tokens-api";
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { ApiTokens } from './ApiTokens';
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,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { Token } from '@or-sdk/base';
2
+ export type ApiTokensConfig = {
3
+ token: Token;
4
+ apiTokensUrl: string;
5
+ discoveryUrl?: string;
6
+ };
7
+ export type ApiToken = {
8
+ id: string;
9
+ name: string;
10
+ role: string;
11
+ accountId: string;
12
+ isActive: boolean;
13
+ expiresAt?: string;
14
+ metadata?: Record<string, unknown>;
15
+ permissions?: string[];
16
+ createdBy?: string;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ };
20
+ export type ApiTokenWithRawValue = ApiToken & {
21
+ token: string;
22
+ };
23
+ export type CreateApiTokenDto = {
24
+ name: string;
25
+ role: string;
26
+ expiresAt?: string;
27
+ metadata?: Record<string, unknown>;
28
+ permissions?: string[];
29
+ };
30
+ export type UpdateApiTokenDto = {
31
+ name?: string;
32
+ role?: string;
33
+ isActive?: boolean;
34
+ expiresAt?: string;
35
+ metadata?: Record<string, unknown>;
36
+ permissions?: string[];
37
+ };
38
+ export type ValidateApiTokenResponse = {
39
+ valid: boolean;
40
+ accountId?: string;
41
+ role?: string;
42
+ permissions?: string[];
43
+ };
44
+ //# sourceMappingURL=types.d.ts.map
@@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AAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@or-sdk/api-tokens",
3
+ "version": "1.0.1-beta.3986.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
+ "@or-sdk/base": "^0.42.5"
22
+ },
23
+ "devDependencies": {
24
+ "concurrently": "9.0.1",
25
+ "typescript": "5.6.2"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }
@@ -0,0 +1,131 @@
1
+ import { Base } from '@or-sdk/base';
2
+
3
+ import { SERVICE_KEY } from './constants';
4
+ import {
5
+ ApiToken,
6
+ ApiTokensConfig,
7
+ ApiTokenWithRawValue,
8
+ CreateApiTokenDto,
9
+ UpdateApiTokenDto,
10
+ ValidateApiTokenResponse,
11
+ } from './types';
12
+
13
+ /**
14
+ * OneReach API Tokens service client
15
+ * ## Installation:
16
+ * ```
17
+ * $ npm i @or-sdk/api-tokens
18
+ * ```
19
+ */
20
+ export class ApiTokens extends Base {
21
+ /**
22
+ * ```typescript
23
+ * import { ApiTokens } from '@or-sdk/api-tokens'
24
+ * const apiTokens = new ApiTokens({
25
+ * token: 'my-account-token-string',
26
+ * apiTokensUrl: 'http://example.api-tokens/endpoint'
27
+ * });
28
+ * ```
29
+ */
30
+ constructor(params: ApiTokensConfig) {
31
+ const { token, discoveryUrl, apiTokensUrl } = params;
32
+ super({
33
+ token,
34
+ discoveryUrl,
35
+ serviceUrl: apiTokensUrl,
36
+ serviceKey: SERVICE_KEY,
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Creates a new API token
42
+ * @param {CreateApiTokenDto} params - Token creation data
43
+ * @param {string} params.name - Name of the API token
44
+ * @param {string} params.role - Role assigned to the API token
45
+ * @param {string} [params.expiresAt] - Token expiration date (ISO 8601)
46
+ * @param {Record<string, unknown>} [params.metadata] - Additional metadata
47
+ * @param {string[]} [params.permissions] - Permission scopes
48
+ * @returns {Promise<ApiTokenWithRawValue>} Created token including the raw token string
49
+ */
50
+ async create(params: CreateApiTokenDto): Promise<ApiTokenWithRawValue> {
51
+ const data = await this.callApiV2<ApiTokenWithRawValue>({
52
+ method: 'POST',
53
+ route: '/api-tokens',
54
+ data: params,
55
+ });
56
+ return data;
57
+ }
58
+
59
+ /**
60
+ * Lists all API tokens for the current account
61
+ * @returns {Promise<ApiToken[]>} List of API tokens
62
+ */
63
+ async list(): Promise<ApiToken[]> {
64
+ const data = await this.callApiV2<ApiToken[]>({
65
+ method: 'GET',
66
+ route: '/api-tokens',
67
+ });
68
+ return data;
69
+ }
70
+
71
+ /**
72
+ * Gets an API token by its ID
73
+ * @param {string} id - API Token identifier
74
+ * @returns {Promise<ApiToken>} The API token
75
+ */
76
+ async getById(id: string): Promise<ApiToken> {
77
+ const data = await this.callApiV2<ApiToken>({
78
+ method: 'GET',
79
+ route: `/api-tokens/${id}`,
80
+ });
81
+ return data;
82
+ }
83
+
84
+ /**
85
+ * Updates an existing API token
86
+ * @param {string} id - API Token identifier
87
+ * @param {UpdateApiTokenDto} params - Fields to update
88
+ * @param {string} [params.name] - Name of the API token
89
+ * @param {string} [params.role] - Role assigned to the API token
90
+ * @param {boolean} [params.isActive] - Whether the token is active
91
+ * @param {string} [params.expiresAt] - Token expiration date (ISO 8601)
92
+ * @param {Record<string, unknown>} [params.metadata] - Additional metadata
93
+ * @param {string[]} [params.permissions] - Replace all linked permissions
94
+ * @returns {Promise<ApiToken>} Updated API token
95
+ */
96
+ async update(id: string, params: UpdateApiTokenDto): Promise<ApiToken> {
97
+ const data = await this.callApiV2<ApiToken>({
98
+ method: 'PUT',
99
+ route: `/api-tokens/${id}`,
100
+ data: params,
101
+ });
102
+ return data;
103
+ }
104
+
105
+ /**
106
+ * Deletes an API token
107
+ * @param {string} id - API Token identifier
108
+ * @returns {Promise<{ success: boolean }>}
109
+ */
110
+ async delete(id: string): Promise<{ success: boolean }> {
111
+ const data = await this.callApiV2<{ success: boolean }>({
112
+ method: 'DELETE',
113
+ route: `/api-tokens/${id}`,
114
+ });
115
+ return data;
116
+ }
117
+
118
+ /**
119
+ * Validates a raw API token string
120
+ * @param {string} token - Raw API token string to validate
121
+ * @returns {Promise<ValidateApiTokenResponse>} Validation result
122
+ */
123
+ async validate(token: string): Promise<ValidateApiTokenResponse> {
124
+ const data = await this.callApiV2<ValidateApiTokenResponse>({
125
+ method: 'POST',
126
+ route: '/api-tokens/validate',
127
+ data: { token },
128
+ });
129
+ return data;
130
+ }
131
+ }
@@ -0,0 +1 @@
1
+ export const SERVICE_KEY = 'api-tokens-api';
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { ApiTokens } from './ApiTokens';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { Token } from '@or-sdk/base';
2
+
3
+ export type ApiTokensConfig = {
4
+ /**
5
+ * token
6
+ */
7
+ token: Token;
8
+ /**
9
+ * API Tokens service URL
10
+ */
11
+ apiTokensUrl: string;
12
+ discoveryUrl?: string;
13
+ };
14
+
15
+ export type ApiToken = {
16
+ id: string;
17
+ name: string;
18
+ role: string;
19
+ accountId: string;
20
+ isActive: boolean;
21
+ expiresAt?: string;
22
+ metadata?: Record<string, unknown>;
23
+ permissions?: string[];
24
+ createdBy?: string;
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ };
28
+
29
+ export type ApiTokenWithRawValue = ApiToken & {
30
+ /** Raw token string, only returned on creation */
31
+ token: string;
32
+ };
33
+
34
+ export type CreateApiTokenDto = {
35
+ /** Name of the API token */
36
+ name: string;
37
+ /** Role assigned to the API token (e.g. 'guest', 'user', 'admin') */
38
+ role: string;
39
+ /** Token expiration date (ISO 8601) */
40
+ expiresAt?: string;
41
+ /** Additional metadata */
42
+ metadata?: Record<string, unknown>;
43
+ /** Permission scopes (e.g. ['service-a:read', 'service-b:write']) */
44
+ permissions?: string[];
45
+ };
46
+
47
+ export type UpdateApiTokenDto = {
48
+ /** Name of the API token */
49
+ name?: string;
50
+ /** Role assigned to the API token */
51
+ role?: string;
52
+ /** Whether the token is active */
53
+ isActive?: boolean;
54
+ /** Token expiration date (ISO 8601) */
55
+ expiresAt?: string;
56
+ /** Additional metadata */
57
+ metadata?: Record<string, unknown>;
58
+ /** Replace all linked permissions */
59
+ permissions?: string[];
60
+ };
61
+
62
+ export type ValidateApiTokenResponse = {
63
+ valid: boolean;
64
+ accountId?: string;
65
+ role?: string;
66
+ permissions?: string[];
67
+ };
@@ -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
+ }