@kmlckj/licos-platform-sdk 0.5.0 → 0.6.1
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 +31 -33
- package/package.json +45 -45
- package/src/browser.d.ts +0 -74
- package/src/browser.js +1 -102
- package/src/database.js +255 -0
- package/src/index.d.ts +189 -72
- package/src/index.js +3 -120
- package/src/runtime.js +70 -0
- package/src/shared.js +0 -246
- package/src/storage.js +155 -0
package/src/index.d.ts
CHANGED
|
@@ -1,89 +1,206 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
content_type: string;
|
|
6
|
-
size_bytes: number;
|
|
7
|
-
preview_url: string;
|
|
8
|
-
download_url: string;
|
|
1
|
+
export class PlatformSdkError extends Error {
|
|
2
|
+
status?: number;
|
|
3
|
+
code?: number;
|
|
4
|
+
details?: unknown;
|
|
9
5
|
}
|
|
10
6
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
export class ConfigurationError extends PlatformSdkError {}
|
|
8
|
+
export class ApiError extends PlatformSdkError {}
|
|
9
|
+
|
|
10
|
+
export interface DatabaseFilter {
|
|
11
|
+
field: string;
|
|
12
|
+
op: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not_in' | 'is_null' | 'is_not_null' | 'like' | 'ilike' | string;
|
|
13
|
+
value?: unknown;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
export interface DatabaseOrderBy {
|
|
17
|
+
field: string;
|
|
18
|
+
direction?: 'asc' | 'desc';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface DatabaseRange {
|
|
22
|
+
from: number;
|
|
23
|
+
to: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DatabaseResponse {
|
|
27
|
+
data?: Record<string, unknown>[];
|
|
28
|
+
count?: number;
|
|
29
|
+
affectedRows?: number;
|
|
30
|
+
message?: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface DatabaseQueryOptions {
|
|
35
|
+
select?: string | string[];
|
|
36
|
+
filters?: DatabaseFilter[];
|
|
37
|
+
orderBy?: DatabaseOrderBy[];
|
|
38
|
+
range?: DatabaseRange;
|
|
39
|
+
limit?: number;
|
|
40
|
+
offset?: number;
|
|
41
|
+
count?: boolean;
|
|
42
|
+
head?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DatabaseMutationOptions {
|
|
46
|
+
row?: Record<string, unknown>;
|
|
47
|
+
rows?: Record<string, unknown>[];
|
|
48
|
+
values?: Record<string, unknown>;
|
|
49
|
+
filters?: DatabaseFilter[];
|
|
50
|
+
updates?: Array<{ filters?: DatabaseFilter[]; values?: Record<string, unknown> }>;
|
|
51
|
+
deletes?: Array<{ filters?: DatabaseFilter[] }>;
|
|
52
|
+
conflictKeys?: string[];
|
|
53
|
+
returning?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface DatabaseOperation {
|
|
57
|
+
type: 'query' | 'insert' | 'update' | 'delete' | 'upsert' | string;
|
|
58
|
+
request: Record<string, unknown>;
|
|
23
59
|
}
|
|
24
60
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
export interface TableQuery {
|
|
62
|
+
select(...fields: string[]): TableQuery;
|
|
63
|
+
filter(field: string, op: string, value?: unknown): TableQuery;
|
|
64
|
+
eq(field: string, value: unknown): TableQuery;
|
|
65
|
+
neq(field: string, value: unknown): TableQuery;
|
|
66
|
+
gt(field: string, value: unknown): TableQuery;
|
|
67
|
+
gte(field: string, value: unknown): TableQuery;
|
|
68
|
+
lt(field: string, value: unknown): TableQuery;
|
|
69
|
+
lte(field: string, value: unknown): TableQuery;
|
|
70
|
+
in(field: string, value: unknown[]): TableQuery;
|
|
71
|
+
notIn(field: string, value: unknown[]): TableQuery;
|
|
72
|
+
isNull(field: string): TableQuery;
|
|
73
|
+
isNotNull(field: string): TableQuery;
|
|
74
|
+
like(field: string, value: string): TableQuery;
|
|
75
|
+
ilike(field: string, value: string): TableQuery;
|
|
76
|
+
order(field: string, options?: { desc?: boolean }): TableQuery;
|
|
77
|
+
range(from: number, to: number): TableQuery;
|
|
78
|
+
limit(value: number): TableQuery;
|
|
79
|
+
offset(value: number): TableQuery;
|
|
80
|
+
withCount(options?: { head?: boolean }): TableQuery;
|
|
81
|
+
execute(): Promise<DatabaseResponse>;
|
|
82
|
+
single(): Promise<DatabaseResponse>;
|
|
83
|
+
maybeSingle(): Promise<DatabaseResponse>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function query(table: string, options?: DatabaseQueryOptions): Promise<DatabaseResponse>;
|
|
87
|
+
export function single(table: string, options?: DatabaseQueryOptions & { maybe?: boolean }): Promise<DatabaseResponse>;
|
|
88
|
+
export function maybeSingle(table: string, options?: DatabaseQueryOptions): Promise<DatabaseResponse>;
|
|
89
|
+
export function aggregate(table: string, aggregateName: string, options?: { field?: string; groupBy?: string[]; filters?: DatabaseFilter[] }): Promise<DatabaseResponse>;
|
|
90
|
+
export function insert(table: string, options?: DatabaseMutationOptions): Promise<DatabaseResponse>;
|
|
91
|
+
export function updateRows(table: string, options?: DatabaseMutationOptions): Promise<DatabaseResponse>;
|
|
92
|
+
export function deleteRows(table: string, options?: DatabaseMutationOptions): Promise<DatabaseResponse>;
|
|
93
|
+
export function upsert(table: string, options?: DatabaseMutationOptions): Promise<DatabaseResponse>;
|
|
94
|
+
export function transaction(operations: DatabaseOperation[]): Promise<DatabaseResponse[]>;
|
|
95
|
+
export function rpc(functionName: string, args?: Record<string, unknown>): Promise<DatabaseResponse>;
|
|
96
|
+
export function table(name: string): TableQuery;
|
|
97
|
+
|
|
98
|
+
export const database: {
|
|
99
|
+
query: typeof query;
|
|
100
|
+
single: typeof single;
|
|
101
|
+
maybeSingle: typeof maybeSingle;
|
|
102
|
+
aggregate: typeof aggregate;
|
|
103
|
+
insert: typeof insert;
|
|
104
|
+
updateRows: typeof updateRows;
|
|
105
|
+
deleteRows: typeof deleteRows;
|
|
106
|
+
upsert: typeof upsert;
|
|
107
|
+
transaction: typeof transaction;
|
|
108
|
+
rpc: typeof rpc;
|
|
109
|
+
table: typeof table;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export interface StorageSummary {
|
|
113
|
+
workspaceId?: string;
|
|
36
114
|
projectId?: string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
115
|
+
scope?: string;
|
|
116
|
+
bucketName?: string;
|
|
117
|
+
usedSizeBytes?: number;
|
|
118
|
+
fileCount?: number;
|
|
119
|
+
folderCount?: number;
|
|
120
|
+
serviceEnabled?: boolean;
|
|
121
|
+
[key: string]: unknown;
|
|
40
122
|
}
|
|
41
123
|
|
|
42
|
-
export interface
|
|
43
|
-
|
|
124
|
+
export interface StorageFolder {
|
|
125
|
+
id?: string;
|
|
126
|
+
workspaceId?: string;
|
|
44
127
|
projectId?: string;
|
|
128
|
+
scope?: string;
|
|
129
|
+
parentId?: string | null;
|
|
130
|
+
folderName?: string;
|
|
131
|
+
folderPath?: string;
|
|
132
|
+
createdAt?: string;
|
|
133
|
+
updatedAt?: string;
|
|
134
|
+
[key: string]: unknown;
|
|
45
135
|
}
|
|
46
136
|
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
137
|
+
export interface StorageFile {
|
|
138
|
+
id?: string;
|
|
139
|
+
workspaceId?: string;
|
|
140
|
+
projectId?: string;
|
|
141
|
+
scope?: string;
|
|
142
|
+
folderId?: string | null;
|
|
143
|
+
folderPath?: string;
|
|
144
|
+
fileName?: string;
|
|
145
|
+
contentType?: string;
|
|
146
|
+
sizeBytes?: number;
|
|
147
|
+
storageBucket?: string;
|
|
148
|
+
storageKey?: string;
|
|
149
|
+
downloadUrl?: string;
|
|
150
|
+
createdAt?: string;
|
|
151
|
+
updatedAt?: string;
|
|
152
|
+
[key: string]: unknown;
|
|
51
153
|
}
|
|
52
154
|
|
|
53
|
-
export
|
|
54
|
-
|
|
155
|
+
export interface StorageEntries {
|
|
156
|
+
currentFolderId?: string | null;
|
|
157
|
+
currentFolderName?: string;
|
|
158
|
+
currentFolderPath?: string;
|
|
159
|
+
breadcrumbs?: unknown[];
|
|
160
|
+
folders?: StorageFolder[];
|
|
161
|
+
files?: StorageFile[];
|
|
162
|
+
[key: string]: unknown;
|
|
163
|
+
}
|
|
55
164
|
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
165
|
+
export interface UploadFileOptions {
|
|
166
|
+
folderId?: string;
|
|
167
|
+
fileName?: string;
|
|
168
|
+
contentType?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface ShareUrlOptions {
|
|
172
|
+
expirySeconds?: number;
|
|
64
173
|
}
|
|
65
174
|
|
|
66
|
-
export function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
):
|
|
71
|
-
export function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
): Promise<
|
|
80
|
-
export function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
175
|
+
export function summary(): Promise<StorageSummary>;
|
|
176
|
+
export function listFolders(): Promise<StorageFolder[]>;
|
|
177
|
+
export function listEntries(options?: { folderId?: string }): Promise<StorageEntries>;
|
|
178
|
+
export function listFiles(): Promise<StorageFile[]>;
|
|
179
|
+
export function createFolder(folderName: string, options?: { parentId?: string }): Promise<StorageFolder>;
|
|
180
|
+
export function renameFolder(folderId: string, folderName: string): Promise<StorageFolder>;
|
|
181
|
+
export function deleteFolder(folderId: string): Promise<void>;
|
|
182
|
+
export function uploadFile(
|
|
183
|
+
input: string | Blob | Buffer | Uint8Array,
|
|
184
|
+
options?: UploadFileOptions,
|
|
185
|
+
): Promise<StorageFile>;
|
|
186
|
+
export function renameFile(fileId: string, fileName: string): Promise<StorageFile>;
|
|
187
|
+
export function moveFile(fileId: string, options?: { folderId?: string }): Promise<StorageFile>;
|
|
188
|
+
export function shareUrl(fileId: string, options?: ShareUrlOptions): Promise<{ url?: string; expiresAt?: string; [key: string]: unknown }>;
|
|
189
|
+
export function objectExists(options?: { fileId?: string; objectKey?: string }): Promise<{ fileId?: string; bucketName?: string; objectKey?: string; exists?: boolean; [key: string]: unknown }>;
|
|
190
|
+
export function deleteFile(fileId: string): Promise<void>;
|
|
191
|
+
|
|
192
|
+
export const storage: {
|
|
193
|
+
summary: typeof summary;
|
|
194
|
+
listFolders: typeof listFolders;
|
|
195
|
+
listEntries: typeof listEntries;
|
|
196
|
+
listFiles: typeof listFiles;
|
|
197
|
+
createFolder: typeof createFolder;
|
|
198
|
+
renameFolder: typeof renameFolder;
|
|
199
|
+
deleteFolder: typeof deleteFolder;
|
|
200
|
+
uploadFile: typeof uploadFile;
|
|
201
|
+
renameFile: typeof renameFile;
|
|
202
|
+
moveFile: typeof moveFile;
|
|
203
|
+
shareUrl: typeof shareUrl;
|
|
204
|
+
objectExists: typeof objectExists;
|
|
205
|
+
deleteFile: typeof deleteFile;
|
|
206
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,120 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
ApiError,
|
|
6
|
-
ConfigurationError,
|
|
7
|
-
PlatformSdkError,
|
|
8
|
-
downloadBlob,
|
|
9
|
-
encodeObjectKey,
|
|
10
|
-
encodeStorageSegment,
|
|
11
|
-
fileNameFromPath,
|
|
12
|
-
guessContentType,
|
|
13
|
-
normalizeBaseUrl,
|
|
14
|
-
resolveProjectId,
|
|
15
|
-
resolveUserId,
|
|
16
|
-
uploadFile,
|
|
17
|
-
} from './shared.js';
|
|
18
|
-
|
|
19
|
-
export class StorageClient {
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
this.baseUrl = options.baseUrl;
|
|
22
|
-
this.token = options.token;
|
|
23
|
-
this.userId = options.userId;
|
|
24
|
-
this.projectId = options.projectId;
|
|
25
|
-
this.fetchImpl = options.fetch ?? fetch;
|
|
26
|
-
this.headers = options.headers;
|
|
27
|
-
this.credentials = options.credentials;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
previewUrl(bucket, objectKey) {
|
|
31
|
-
const baseUrl = normalizeBaseUrl(this.baseUrl);
|
|
32
|
-
return `${baseUrl}/api/v1/public/storage/${encodeStorageSegment(bucket)}/${encodeObjectKey(objectKey)}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
downloadUrl(bucket, objectKey) {
|
|
36
|
-
return `${this.previewUrl(bucket, objectKey)}?download=1`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async uploadUser(file) {
|
|
40
|
-
const baseUrl = normalizeBaseUrl(this.baseUrl);
|
|
41
|
-
return this.#upload(`${baseUrl}/api/v1/storage/upload/user`, file);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async uploadProject(file, options = {}) {
|
|
45
|
-
const baseUrl = normalizeBaseUrl(this.baseUrl);
|
|
46
|
-
const userId = resolveUserId(options.userId ?? this.userId);
|
|
47
|
-
const projectId = resolveProjectId(options.projectId ?? this.projectId);
|
|
48
|
-
return this.#upload(
|
|
49
|
-
`${baseUrl}/api/v1/storage/upload/project/${encodeStorageSegment(userId)}/${encodeStorageSegment(projectId)}`,
|
|
50
|
-
file,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async download(url, outputPath) {
|
|
55
|
-
const blob = await downloadBlob(this.fetchImpl, url, {
|
|
56
|
-
token: this.token,
|
|
57
|
-
headers: this.headers,
|
|
58
|
-
credentials: this.credentials,
|
|
59
|
-
});
|
|
60
|
-
if (outputPath === undefined) {
|
|
61
|
-
return blob;
|
|
62
|
-
}
|
|
63
|
-
const buffer = Buffer.from(await blob.arrayBuffer());
|
|
64
|
-
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
65
|
-
await fs.writeFile(outputPath, buffer);
|
|
66
|
-
return outputPath;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async #upload(url, file) {
|
|
70
|
-
return uploadFile(
|
|
71
|
-
this.fetchImpl,
|
|
72
|
-
url,
|
|
73
|
-
file,
|
|
74
|
-
{
|
|
75
|
-
token: this.token,
|
|
76
|
-
headers: this.headers,
|
|
77
|
-
credentials: this.credentials,
|
|
78
|
-
},
|
|
79
|
-
async (filePath) => {
|
|
80
|
-
const fileBuffer = await fs.readFile(filePath);
|
|
81
|
-
const fileName = fileNameFromPath(filePath);
|
|
82
|
-
const contentType = guessContentType(fileName);
|
|
83
|
-
return {
|
|
84
|
-
fileName,
|
|
85
|
-
contentType,
|
|
86
|
-
blob: new Blob([fileBuffer], { type: contentType }),
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function defaultClient(options = {}) {
|
|
94
|
-
return new StorageClient(options);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function previewUrl(bucket, objectKey, options = {}) {
|
|
98
|
-
return defaultClient(options).previewUrl(bucket, objectKey);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function downloadUrl(bucket, objectKey, options = {}) {
|
|
102
|
-
return defaultClient(options).downloadUrl(bucket, objectKey);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function uploadUser(filePath, options = {}) {
|
|
106
|
-
return defaultClient(options).uploadUser(filePath);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function uploadProject(filePath, options = {}) {
|
|
110
|
-
return defaultClient(options).uploadProject(filePath, options);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export async function download(url, outputPathOrOptions, maybeOptions = {}) {
|
|
114
|
-
if (typeof outputPathOrOptions === 'string') {
|
|
115
|
-
return defaultClient(maybeOptions).download(url, outputPathOrOptions);
|
|
116
|
-
}
|
|
117
|
-
return defaultClient(outputPathOrOptions ?? {}).download(url);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { PlatformSdkError, ConfigurationError, ApiError };
|
|
1
|
+
export { PlatformSdkError, ConfigurationError, ApiError } from './shared.js';
|
|
2
|
+
export * from './database.js';
|
|
3
|
+
export * from './storage.js';
|
package/src/runtime.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ConfigurationError } from './shared.js';
|
|
2
|
+
|
|
3
|
+
export function env(name) {
|
|
4
|
+
const value = process.env[name];
|
|
5
|
+
if (typeof value !== 'string') return undefined;
|
|
6
|
+
const trimmed = value.trim();
|
|
7
|
+
return trimmed ? trimmed : undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function normalizeBaseUrl(value) {
|
|
11
|
+
let trimmed = value.trim().replace(/\/+$/, '');
|
|
12
|
+
if (trimmed.endsWith('/api/v1')) {
|
|
13
|
+
trimmed = trimmed.slice(0, -'/api/v1'.length);
|
|
14
|
+
}
|
|
15
|
+
return trimmed.replace(/\/+$/, '');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function serviceBaseUrl(hostEnv, portEnv, defaultPort) {
|
|
19
|
+
const host = env(hostEnv);
|
|
20
|
+
if (!host) return undefined;
|
|
21
|
+
return `http://${host}:${env(portEnv) || defaultPort}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function platformBaseUrl() {
|
|
25
|
+
const value =
|
|
26
|
+
env('LICOS_PLATFORM_API_BASE_URL') ||
|
|
27
|
+
serviceBaseUrl('AIOS_PLATFORM_SERVICE_HOST', 'AIOS_PLATFORM_SERVICE_PORT', '9100') ||
|
|
28
|
+
serviceBaseUrl('LICOS_PLATFORM_SERVICE_HOST', 'LICOS_PLATFORM_SERVICE_PORT', '9100') ||
|
|
29
|
+
serviceBaseUrl('PLATFORM_SERVICE_HOST', 'PLATFORM_SERVICE_PORT', '9100');
|
|
30
|
+
if (!value) {
|
|
31
|
+
throw new ConfigurationError('LICOS_PLATFORM_API_BASE_URL is not configured');
|
|
32
|
+
}
|
|
33
|
+
return normalizeBaseUrl(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function projectEnvironment(overrideEnvName) {
|
|
37
|
+
const explicit = ((overrideEnvName ? env(overrideEnvName) : undefined) || '').toLowerCase();
|
|
38
|
+
if (explicit === 'dev' || explicit === 'prod') return explicit;
|
|
39
|
+
const projectEnv = (env('LICOS_PROJECT_ENV') || env('AGENT_ENV') || '').toLowerCase();
|
|
40
|
+
return ['prod', 'production', 'release'].includes(projectEnv) ? 'prod' : 'dev';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function runtimeConfig({ environmentOverrideEnv } = {}) {
|
|
44
|
+
const projectId = env('LICOS_PROJECT_ID') || env('AGENT_PROJECT_ID');
|
|
45
|
+
if (!projectId) {
|
|
46
|
+
throw new ConfigurationError('LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured');
|
|
47
|
+
}
|
|
48
|
+
const token = env('LICOS_RUNTIME_TOKEN') || env('LICOS_USER_TOKEN');
|
|
49
|
+
if (!token) {
|
|
50
|
+
throw new ConfigurationError('LICOS_RUNTIME_TOKEN or LICOS_USER_TOKEN is not configured');
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
baseUrl: platformBaseUrl(),
|
|
54
|
+
projectId,
|
|
55
|
+
environment: projectEnvironment(environmentOverrideEnv),
|
|
56
|
+
token,
|
|
57
|
+
workspaceId: env('LICOS_WORKSPACE_ID') || env('AGENT_WORKSPACE_ID'),
|
|
58
|
+
userId: env('LICOS_USER_ID') || env('AGENT_USER_ID'),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function authHeaders(config, contentType = 'application/json') {
|
|
63
|
+
const result = {
|
|
64
|
+
Authorization: `Bearer ${config.token}`,
|
|
65
|
+
};
|
|
66
|
+
if (contentType) result['Content-Type'] = contentType;
|
|
67
|
+
if (config.workspaceId) result['X-Workspace-Id'] = config.workspaceId;
|
|
68
|
+
if (config.userId) result['X-User-Id'] = config.userId;
|
|
69
|
+
return result;
|
|
70
|
+
}
|