@mapcreator/api 0.0.0-saga.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/LICENSE +29 -0
- package/README.md +86 -0
- package/cjs/api/apiCommon.d.ts +7 -0
- package/cjs/api/apiCommon.d.ts.map +1 -0
- package/cjs/api/apiCommon.js +31 -0
- package/cjs/api/apiCommon.js.map +1 -0
- package/cjs/api/choropleth.d.ts +41 -0
- package/cjs/api/choropleth.d.ts.map +1 -0
- package/cjs/api/choropleth.js +15 -0
- package/cjs/api/choropleth.js.map +1 -0
- package/cjs/api/color.d.ts +16 -0
- package/cjs/api/color.d.ts.map +1 -0
- package/cjs/api/color.js +8 -0
- package/cjs/api/color.js.map +1 -0
- package/cjs/api/dimension.d.ts +25 -0
- package/cjs/api/dimension.d.ts.map +1 -0
- package/cjs/api/dimension.js +14 -0
- package/cjs/api/dimension.js.map +1 -0
- package/cjs/api/dimensionSet.d.ts +15 -0
- package/cjs/api/dimensionSet.d.ts.map +1 -0
- package/cjs/api/dimensionSet.js +7 -0
- package/cjs/api/dimensionSet.js.map +1 -0
- package/cjs/api/feature.d.ts +16 -0
- package/cjs/api/feature.d.ts.map +1 -0
- package/cjs/api/feature.js +8 -0
- package/cjs/api/feature.js.map +1 -0
- package/cjs/api/font.d.ts +29 -0
- package/cjs/api/font.d.ts.map +1 -0
- package/cjs/api/font.js +18 -0
- package/cjs/api/font.js.map +1 -0
- package/cjs/api/fontFamily.d.ts +17 -0
- package/cjs/api/fontFamily.d.ts.map +1 -0
- package/cjs/api/fontFamily.js +17 -0
- package/cjs/api/fontFamily.js.map +1 -0
- package/cjs/api/highlight.d.ts +41 -0
- package/cjs/api/highlight.d.ts.map +1 -0
- package/cjs/api/highlight.js +25 -0
- package/cjs/api/highlight.js.map +1 -0
- package/cjs/api/job.d.ts +41 -0
- package/cjs/api/job.d.ts.map +1 -0
- package/cjs/api/job.js +71 -0
- package/cjs/api/job.js.map +1 -0
- package/cjs/api/jobResult.d.ts +40 -0
- package/cjs/api/jobResult.d.ts.map +1 -0
- package/cjs/api/jobResult.js +35 -0
- package/cjs/api/jobResult.js.map +1 -0
- package/cjs/api/jobRevision.d.ts +76 -0
- package/cjs/api/jobRevision.d.ts.map +1 -0
- package/cjs/api/jobRevision.js +132 -0
- package/cjs/api/jobRevision.js.map +1 -0
- package/cjs/api/jobShare.d.ts +26 -0
- package/cjs/api/jobShare.d.ts.map +1 -0
- package/cjs/api/jobShare.js +9 -0
- package/cjs/api/jobShare.js.map +1 -0
- package/cjs/api/jobType.d.ts +17 -0
- package/cjs/api/jobType.d.ts.map +1 -0
- package/cjs/api/jobType.js +11 -0
- package/cjs/api/jobType.js.map +1 -0
- package/cjs/api/language.d.ts +17 -0
- package/cjs/api/language.d.ts.map +1 -0
- package/cjs/api/language.js +3 -0
- package/cjs/api/language.js.map +1 -0
- package/cjs/api/layer.d.ts +26 -0
- package/cjs/api/layer.d.ts.map +1 -0
- package/cjs/api/layer.js +14 -0
- package/cjs/api/layer.js.map +1 -0
- package/cjs/api/layerFaq.d.ts +27 -0
- package/cjs/api/layerFaq.d.ts.map +1 -0
- package/cjs/api/layerFaq.js +16 -0
- package/cjs/api/layerFaq.js.map +1 -0
- package/cjs/api/layerGroup.d.ts +16 -0
- package/cjs/api/layerGroup.d.ts.map +1 -0
- package/cjs/api/layerGroup.js +36 -0
- package/cjs/api/layerGroup.js.map +1 -0
- package/cjs/api/mapstyleSet.d.ts +31 -0
- package/cjs/api/mapstyleSet.d.ts.map +1 -0
- package/cjs/api/mapstyleSet.js +19 -0
- package/cjs/api/mapstyleSet.js.map +1 -0
- package/cjs/api/message.d.ts +32 -0
- package/cjs/api/message.d.ts.map +1 -0
- package/cjs/api/message.js +37 -0
- package/cjs/api/message.js.map +1 -0
- package/cjs/api/organisation.d.ts +40 -0
- package/cjs/api/organisation.d.ts.map +1 -0
- package/cjs/api/organisation.js +42 -0
- package/cjs/api/organisation.js.map +1 -0
- package/cjs/api/resources.d.ts +59 -0
- package/cjs/api/resources.d.ts.map +1 -0
- package/cjs/api/resources.js +57 -0
- package/cjs/api/resources.js.map +1 -0
- package/cjs/api/svg.d.ts +21 -0
- package/cjs/api/svg.d.ts.map +1 -0
- package/cjs/api/svg.js +15 -0
- package/cjs/api/svg.js.map +1 -0
- package/cjs/api/svgSet.d.ts +22 -0
- package/cjs/api/svgSet.d.ts.map +1 -0
- package/cjs/api/svgSet.js +25 -0
- package/cjs/api/svgSet.js.map +1 -0
- package/cjs/api/user.d.ts +128 -0
- package/cjs/api/user.d.ts.map +1 -0
- package/cjs/api/user.js +146 -0
- package/cjs/api/user.js.map +1 -0
- package/cjs/index.d.ts +26 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +51 -0
- package/cjs/index.js.map +1 -0
- package/cjs/oauth.d.ts +27 -0
- package/cjs/oauth.d.ts.map +1 -0
- package/cjs/oauth.js +245 -0
- package/cjs/oauth.js.map +1 -0
- package/cjs/utils.d.ts +72 -0
- package/cjs/utils.d.ts.map +1 -0
- package/cjs/utils.js +220 -0
- package/cjs/utils.js.map +1 -0
- package/esm/api/apiCommon.d.ts +7 -0
- package/esm/api/apiCommon.d.ts.map +1 -0
- package/esm/api/apiCommon.js +28 -0
- package/esm/api/apiCommon.js.map +1 -0
- package/esm/api/choropleth.d.ts +41 -0
- package/esm/api/choropleth.d.ts.map +1 -0
- package/esm/api/choropleth.js +11 -0
- package/esm/api/choropleth.js.map +1 -0
- package/esm/api/color.d.ts +16 -0
- package/esm/api/color.d.ts.map +1 -0
- package/esm/api/color.js +5 -0
- package/esm/api/color.js.map +1 -0
- package/esm/api/dimension.d.ts +25 -0
- package/esm/api/dimension.d.ts.map +1 -0
- package/esm/api/dimension.js +11 -0
- package/esm/api/dimension.js.map +1 -0
- package/esm/api/dimensionSet.d.ts +15 -0
- package/esm/api/dimensionSet.d.ts.map +1 -0
- package/esm/api/dimensionSet.js +4 -0
- package/esm/api/dimensionSet.js.map +1 -0
- package/esm/api/feature.d.ts +16 -0
- package/esm/api/feature.d.ts.map +1 -0
- package/esm/api/feature.js +5 -0
- package/esm/api/feature.js.map +1 -0
- package/esm/api/font.d.ts +29 -0
- package/esm/api/font.d.ts.map +1 -0
- package/esm/api/font.js +14 -0
- package/esm/api/font.js.map +1 -0
- package/esm/api/fontFamily.d.ts +17 -0
- package/esm/api/fontFamily.d.ts.map +1 -0
- package/esm/api/fontFamily.js +13 -0
- package/esm/api/fontFamily.js.map +1 -0
- package/esm/api/highlight.d.ts +41 -0
- package/esm/api/highlight.d.ts.map +1 -0
- package/esm/api/highlight.js +21 -0
- package/esm/api/highlight.js.map +1 -0
- package/esm/api/job.d.ts +41 -0
- package/esm/api/job.d.ts.map +1 -0
- package/esm/api/job.js +59 -0
- package/esm/api/job.js.map +1 -0
- package/esm/api/jobResult.d.ts +40 -0
- package/esm/api/jobResult.d.ts.map +1 -0
- package/esm/api/jobResult.js +30 -0
- package/esm/api/jobResult.js.map +1 -0
- package/esm/api/jobRevision.d.ts +76 -0
- package/esm/api/jobRevision.d.ts.map +1 -0
- package/esm/api/jobRevision.js +120 -0
- package/esm/api/jobRevision.js.map +1 -0
- package/esm/api/jobShare.d.ts +26 -0
- package/esm/api/jobShare.d.ts.map +1 -0
- package/esm/api/jobShare.js +6 -0
- package/esm/api/jobShare.js.map +1 -0
- package/esm/api/jobType.d.ts +17 -0
- package/esm/api/jobType.d.ts.map +1 -0
- package/esm/api/jobType.js +8 -0
- package/esm/api/jobType.js.map +1 -0
- package/esm/api/language.d.ts +17 -0
- package/esm/api/language.d.ts.map +1 -0
- package/esm/api/language.js +2 -0
- package/esm/api/language.js.map +1 -0
- package/esm/api/layer.d.ts +26 -0
- package/esm/api/layer.d.ts.map +1 -0
- package/esm/api/layer.js +11 -0
- package/esm/api/layer.js.map +1 -0
- package/esm/api/layerFaq.d.ts +27 -0
- package/esm/api/layerFaq.d.ts.map +1 -0
- package/esm/api/layerFaq.js +12 -0
- package/esm/api/layerFaq.js.map +1 -0
- package/esm/api/layerGroup.d.ts +16 -0
- package/esm/api/layerGroup.d.ts.map +1 -0
- package/esm/api/layerGroup.js +33 -0
- package/esm/api/layerGroup.js.map +1 -0
- package/esm/api/mapstyleSet.d.ts +31 -0
- package/esm/api/mapstyleSet.d.ts.map +1 -0
- package/esm/api/mapstyleSet.js +16 -0
- package/esm/api/mapstyleSet.js.map +1 -0
- package/esm/api/message.d.ts +32 -0
- package/esm/api/message.d.ts.map +1 -0
- package/esm/api/message.js +32 -0
- package/esm/api/message.js.map +1 -0
- package/esm/api/organisation.d.ts +40 -0
- package/esm/api/organisation.d.ts.map +1 -0
- package/esm/api/organisation.js +36 -0
- package/esm/api/organisation.js.map +1 -0
- package/esm/api/resources.d.ts +59 -0
- package/esm/api/resources.d.ts.map +1 -0
- package/esm/api/resources.js +51 -0
- package/esm/api/resources.js.map +1 -0
- package/esm/api/svg.d.ts +21 -0
- package/esm/api/svg.d.ts.map +1 -0
- package/esm/api/svg.js +11 -0
- package/esm/api/svg.js.map +1 -0
- package/esm/api/svgSet.d.ts +22 -0
- package/esm/api/svgSet.d.ts.map +1 -0
- package/esm/api/svgSet.js +21 -0
- package/esm/api/svgSet.js.map +1 -0
- package/esm/api/user.d.ts +128 -0
- package/esm/api/user.d.ts.map +1 -0
- package/esm/api/user.js +127 -0
- package/esm/api/user.js.map +1 -0
- package/esm/index.d.ts +26 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +26 -0
- package/esm/index.js.map +1 -0
- package/esm/oauth.d.ts +27 -0
- package/esm/oauth.d.ts.map +1 -0
- package/esm/oauth.js +237 -0
- package/esm/oauth.js.map +1 -0
- package/esm/utils.d.ts +72 -0
- package/esm/utils.d.ts.map +1 -0
- package/esm/utils.js +206 -0
- package/esm/utils.js.map +1 -0
- package/package.json +80 -0
- package/src/README.md +126 -0
- package/src/api/apiCommon.ts +70 -0
- package/src/api/choropleth.ts +105 -0
- package/src/api/color.ts +22 -0
- package/src/api/dimension.ts +44 -0
- package/src/api/dimensionSet.ts +20 -0
- package/src/api/feature.ts +22 -0
- package/src/api/font.ts +49 -0
- package/src/api/fontFamily.ts +43 -0
- package/src/api/highlight.ts +87 -0
- package/src/api/job.ts +129 -0
- package/src/api/jobResult.ts +95 -0
- package/src/api/jobRevision.ts +278 -0
- package/src/api/jobShare.ts +35 -0
- package/src/api/jobType.ts +26 -0
- package/src/api/language.ts +19 -0
- package/src/api/layer.ts +38 -0
- package/src/api/layerFaq.ts +53 -0
- package/src/api/layerGroup.ts +69 -0
- package/src/api/mapstyleSet.ts +48 -0
- package/src/api/message.ts +80 -0
- package/src/api/organisation.ts +95 -0
- package/src/api/resources.ts +143 -0
- package/src/api/svg.ts +33 -0
- package/src/api/svgSet.ts +56 -0
- package/src/api/user.ts +327 -0
- package/src/index.ts +42 -0
- package/src/oauth.ts +314 -0
- package/src/utils.ts +342 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { type ApiLayerData, type Layer, layerRevivers } from './layer.js';
|
|
2
|
+
import { apiHost, authenticate, token } from '../oauth.js';
|
|
3
|
+
import type { ApiMapstyleSetData } from './mapstyleSet.js';
|
|
4
|
+
import type { ApiLanguageData } from './language.js';
|
|
5
|
+
import {
|
|
6
|
+
APIError,
|
|
7
|
+
type ApiCommon,
|
|
8
|
+
type ApiCommonData,
|
|
9
|
+
type ApiError,
|
|
10
|
+
type ApiSuccess,
|
|
11
|
+
type Flatten,
|
|
12
|
+
HTTPError,
|
|
13
|
+
NetworkError,
|
|
14
|
+
type Revivers,
|
|
15
|
+
defaultListHeader,
|
|
16
|
+
deletedNoneParam,
|
|
17
|
+
lastJobRevision,
|
|
18
|
+
request,
|
|
19
|
+
} from '../utils.js';
|
|
20
|
+
|
|
21
|
+
export type FileFormat =
|
|
22
|
+
| 'png'
|
|
23
|
+
| 'jpg'
|
|
24
|
+
| 'tiff'
|
|
25
|
+
| 'svg'
|
|
26
|
+
| 'pdf'
|
|
27
|
+
| 'web'
|
|
28
|
+
| 'web_download'
|
|
29
|
+
| 'webm'
|
|
30
|
+
| 'mp4'
|
|
31
|
+
| 'mov'
|
|
32
|
+
| 'eps'
|
|
33
|
+
| 'eps_log'
|
|
34
|
+
| 'png_sequence'
|
|
35
|
+
| 'jpg_sequence'
|
|
36
|
+
| 'mxf';
|
|
37
|
+
|
|
38
|
+
export type JobRevision = {
|
|
39
|
+
id: number;
|
|
40
|
+
jobId: number;
|
|
41
|
+
revision: number;
|
|
42
|
+
languageCode: string;
|
|
43
|
+
mapstyleSetId: number;
|
|
44
|
+
output: FileFormat;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ApiJobRevision = {
|
|
48
|
+
data: {
|
|
49
|
+
id: number; // The id of the job revision (sortable)
|
|
50
|
+
job_id: number; // The id of the job related to this revision (searchable, sortable)
|
|
51
|
+
revision: number; // The revision number (searchable, sortable)
|
|
52
|
+
language_code: string; // The language code of the revision (searchable, sortable)
|
|
53
|
+
mapstyle_set_id: number; // The id of the mapstyle set
|
|
54
|
+
archived: boolean; // Whether the revision has been generated (searchable, sortable)
|
|
55
|
+
output: FileFormat; // The output file type
|
|
56
|
+
} & ApiCommonData;
|
|
57
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
58
|
+
|
|
59
|
+
export type ApiJobRevisionData = Flatten<Exclude<ApiJobRevision, ApiError>['data']>;
|
|
60
|
+
|
|
61
|
+
export const jobRevisionRevivers: Revivers<ApiJobRevision, JobRevision> = {
|
|
62
|
+
archived: undefined,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export async function createJobRevision(
|
|
66
|
+
jobId: number,
|
|
67
|
+
languageCode: string,
|
|
68
|
+
mapstyleSetId: number,
|
|
69
|
+
layers: number[],
|
|
70
|
+
output: FileFormat,
|
|
71
|
+
jobObject: Record<string, unknown>,
|
|
72
|
+
): Promise<JobRevision> {
|
|
73
|
+
const pathname = `/v1/jobs/${jobId}/revisions`;
|
|
74
|
+
const path = `${pathname}?${deletedNoneParam}`;
|
|
75
|
+
const body = {
|
|
76
|
+
language_code: languageCode,
|
|
77
|
+
mapstyle_set_id: mapstyleSetId,
|
|
78
|
+
object: JSON.stringify(jobObject),
|
|
79
|
+
output,
|
|
80
|
+
layers,
|
|
81
|
+
};
|
|
82
|
+
const options = { revivers: jobRevisionRevivers };
|
|
83
|
+
|
|
84
|
+
return request<ApiJobRevision, JobRevision>(path, body, null, options);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function getJobRevision(jobId: number): Promise<JobRevision | undefined> {
|
|
88
|
+
const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}`;
|
|
89
|
+
const options = { revivers: jobRevisionRevivers };
|
|
90
|
+
|
|
91
|
+
return request<ApiJobRevision, JobRevision>(path, null, null, options).catch(() => undefined);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function getJobRevisionObject<JobObject>(jobId: number): Promise<JobObject> {
|
|
95
|
+
const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/object`;
|
|
96
|
+
const path = `${pathname}?${deletedNoneParam}`;
|
|
97
|
+
|
|
98
|
+
return request<ApiCommon, string>(path).then(JSON.parse) as Promise<JobObject>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type JobCanBuild = {
|
|
102
|
+
canBuild: boolean;
|
|
103
|
+
paymentSource: string;
|
|
104
|
+
reason: string | null;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type ApiJobCanBuild = {
|
|
108
|
+
data: {
|
|
109
|
+
can_build: boolean;
|
|
110
|
+
payment_source: string;
|
|
111
|
+
reason: string | null;
|
|
112
|
+
} & ApiCommonData;
|
|
113
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
114
|
+
|
|
115
|
+
// Also known as `canBuild()`
|
|
116
|
+
export async function getJobRevisionBuild(jobId: number): Promise<JobCanBuild> {
|
|
117
|
+
const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build`;
|
|
118
|
+
const path = `${pathname}?${deletedNoneParam}`;
|
|
119
|
+
|
|
120
|
+
return request<ApiJobCanBuild, JobCanBuild>(path);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type JobRevisionBuild = {
|
|
124
|
+
jobRevisionId: number;
|
|
125
|
+
revision: number;
|
|
126
|
+
status: string;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export type ApiJobRevisionBuild = {
|
|
130
|
+
data: {
|
|
131
|
+
job_revision_id: number; // The id of the job revision
|
|
132
|
+
status: string; // The status of the job result (searchable, sortable)
|
|
133
|
+
contract_id: number; // The id of the contract that was active when the map was created
|
|
134
|
+
process_start: string; // The datetime when the job process started (searchable, sortable)
|
|
135
|
+
process_end: string; // The datetime when the job process ended (searchable, sortable)
|
|
136
|
+
last_downloaded: string; // The last time the archive was downloaded (searchable, sortable)
|
|
137
|
+
bought: boolean; // Checks if the result is bought or not (searchable, sortable)
|
|
138
|
+
revision: number; // The revision number of the job revision
|
|
139
|
+
job_revision: ApiJobRevisionData;
|
|
140
|
+
} & ApiCommonData;
|
|
141
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
142
|
+
|
|
143
|
+
export type ApiJobRevisionBuildData = Flatten<Exclude<ApiJobRevisionBuild, ApiError>['data']>;
|
|
144
|
+
|
|
145
|
+
export const jobRevisionBuildRevivers: Revivers<ApiJobRevisionBuild, JobRevisionBuild> = {
|
|
146
|
+
contract_id: undefined,
|
|
147
|
+
process_start: undefined,
|
|
148
|
+
process_end: undefined,
|
|
149
|
+
last_downloaded: undefined,
|
|
150
|
+
bought: undefined,
|
|
151
|
+
job_revision: undefined,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export async function registerJobRevisionBuild(
|
|
155
|
+
jobId: number,
|
|
156
|
+
status: string,
|
|
157
|
+
start: Date,
|
|
158
|
+
end: Date,
|
|
159
|
+
): Promise<JobRevisionBuild> {
|
|
160
|
+
const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build/register`;
|
|
161
|
+
const path = `${pathname}?${deletedNoneParam}`;
|
|
162
|
+
const body = { status, process_start: start, process_end: end };
|
|
163
|
+
const options = { revivers: jobRevisionBuildRevivers };
|
|
164
|
+
|
|
165
|
+
return request<ApiJobRevisionBuild, JobRevisionBuild>(path, body, null, options);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function cloneJobRevision(jobId: number, newTitle?: string): Promise<JobRevision> {
|
|
169
|
+
const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/clone`;
|
|
170
|
+
const path = `${pathname}?${deletedNoneParam}`;
|
|
171
|
+
const body = { title: newTitle ?? null };
|
|
172
|
+
const options = {
|
|
173
|
+
revivers: {
|
|
174
|
+
...jobRevisionRevivers,
|
|
175
|
+
layers: undefined,
|
|
176
|
+
language: undefined,
|
|
177
|
+
mapstyle_set: undefined,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
type ApiJobRevisionWithData = {
|
|
182
|
+
data: ApiJobRevisionData & {
|
|
183
|
+
layers: ApiLayerData[];
|
|
184
|
+
language: ApiLanguageData;
|
|
185
|
+
mapstyle_set: ApiMapstyleSetData;
|
|
186
|
+
};
|
|
187
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
188
|
+
|
|
189
|
+
return request<ApiJobRevisionWithData, JobRevision>(path, body, null, options);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export async function listJobRevisionLayers(jobId: number): Promise<Layer[]> {
|
|
193
|
+
const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/layers`;
|
|
194
|
+
const options = { revivers: layerRevivers };
|
|
195
|
+
|
|
196
|
+
type ApiLayerArray = {
|
|
197
|
+
data: ApiLayerData[];
|
|
198
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
199
|
+
|
|
200
|
+
return request<ApiLayerArray, Layer>(path, null, defaultListHeader, options);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type JobRevisionOutputUrl = { url: string };
|
|
204
|
+
|
|
205
|
+
export type ApiJobRevisionOutputUrl = {
|
|
206
|
+
data: JobRevisionOutputUrl & ApiCommonData;
|
|
207
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
208
|
+
|
|
209
|
+
export async function getJobRevisionOutputUrl(jobId: number): Promise<JobRevisionOutputUrl> {
|
|
210
|
+
await createJobRevisionBuild(jobId);
|
|
211
|
+
|
|
212
|
+
const path = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/output-url`;
|
|
213
|
+
|
|
214
|
+
return request<ApiJobRevisionOutputUrl, JobRevisionOutputUrl>(path);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type JobRevisionOutput = { blob: Blob; filename?: string | undefined };
|
|
218
|
+
|
|
219
|
+
export async function getJobRevisionOutput(jobId: number): Promise<JobRevisionOutput> {
|
|
220
|
+
await createJobRevisionBuild(jobId);
|
|
221
|
+
|
|
222
|
+
const href = `${apiHost}/v1/jobs/${jobId}/revisions/${lastJobRevision}/result/output`;
|
|
223
|
+
const headers = { ...(token ? { Authorization: token.toString() } : null) };
|
|
224
|
+
const response = await fetch(href, { headers }).catch((error: Error) => {
|
|
225
|
+
throw new NetworkError(error?.message ?? error);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
if (response.ok) {
|
|
229
|
+
const blob = await response.blob().catch(() => {
|
|
230
|
+
throw new APIError({ success: false, error: { type: 'TypeError', message: 'Malformed Blob response' } });
|
|
231
|
+
});
|
|
232
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
233
|
+
|
|
234
|
+
if (contentDisposition) {
|
|
235
|
+
const filenameRegex = /filename\*\s*=\s*UTF-8''(.+)/i;
|
|
236
|
+
const filenameMatch = contentDisposition.match(filenameRegex);
|
|
237
|
+
|
|
238
|
+
if (filenameMatch?.[1]) {
|
|
239
|
+
return { blob, filename: filenameMatch[1] };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const fallbackRegex = /filename\s*=\s*"([^"]+)"/i;
|
|
243
|
+
const fallbackMatch = contentDisposition.match(fallbackRegex);
|
|
244
|
+
|
|
245
|
+
if (fallbackMatch?.[1]) {
|
|
246
|
+
return { blob, filename: fallbackMatch[1] };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return { blob };
|
|
251
|
+
} else {
|
|
252
|
+
// eslint-disable-next-line default-case
|
|
253
|
+
switch (response.status) {
|
|
254
|
+
case 401:
|
|
255
|
+
await authenticate();
|
|
256
|
+
break; // NO-OP
|
|
257
|
+
case 403:
|
|
258
|
+
case 404:
|
|
259
|
+
case 406:
|
|
260
|
+
case 429:
|
|
261
|
+
throw new APIError(
|
|
262
|
+
(await response.json().catch(() => ({
|
|
263
|
+
success: false,
|
|
264
|
+
error: { type: 'HttpException', message: response.statusText },
|
|
265
|
+
}))) as ApiError,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
throw new HTTPError(response);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async function createJobRevisionBuild(jobId: number): Promise<string> {
|
|
274
|
+
const pathname = `/v1/jobs/${jobId}/revisions/${lastJobRevision}/build`;
|
|
275
|
+
const path = `${pathname}?${deletedNoneParam}`;
|
|
276
|
+
|
|
277
|
+
return request<ApiCommon, string>(path, null, null, { method: 'POST' });
|
|
278
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ApiCommon, type ApiCommonData, type ApiError, type ApiSuccess, type Flatten, request } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
export type JobShareVisibility = 'private' | 'organisation' | 'public';
|
|
4
|
+
|
|
5
|
+
export type JobShare = {
|
|
6
|
+
id: number;
|
|
7
|
+
jobId: number;
|
|
8
|
+
visibility: JobShareVisibility;
|
|
9
|
+
hashKey: string;
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
webUrl: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type ApiJobShare = {
|
|
15
|
+
data: {
|
|
16
|
+
id: number; // The id of the job share (sortable)
|
|
17
|
+
job_id: number; // The id of the job related to this share
|
|
18
|
+
visibility: string; // The visibility of the job share (searchable, sortable)
|
|
19
|
+
hash_key: string; // The hash key of the job share
|
|
20
|
+
apiUrl: string; // TODO: not present in API specification!
|
|
21
|
+
webUrl: string; // TODO: not present in API specification!
|
|
22
|
+
} & ApiCommonData;
|
|
23
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
24
|
+
|
|
25
|
+
export type ApiJobShareData = Flatten<Exclude<ApiJobShare, ApiError>['data']>;
|
|
26
|
+
|
|
27
|
+
export type ApiJobShareArray = {
|
|
28
|
+
data: ApiJobShareData[];
|
|
29
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
30
|
+
|
|
31
|
+
export async function deleteJobShare(jobShareId: number): Promise<Record<string, never>> {
|
|
32
|
+
const path = `/v1/jobs/shares/${jobShareId}`;
|
|
33
|
+
|
|
34
|
+
return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'DELETE' });
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ApiCommonData, ApiError, ApiSuccess, Flatten, Revivers } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
export type JobType = {
|
|
4
|
+
id: number;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ApiJobType = {
|
|
8
|
+
data: {
|
|
9
|
+
id: number; // The id of the job type (sortable)
|
|
10
|
+
name: string; // The name of the job type (searchable, sortable)
|
|
11
|
+
preview: string | null; // The preview file name of the job type
|
|
12
|
+
description: string | null; // The description of the job type (searchable, sortable)
|
|
13
|
+
components: string | null; // The components of the job type
|
|
14
|
+
order?: number; // TODO: not present in API specification!
|
|
15
|
+
} & ApiCommonData;
|
|
16
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
17
|
+
|
|
18
|
+
export type ApiJobTypeData = Flatten<Exclude<ApiJobType, ApiError>['data']>;
|
|
19
|
+
|
|
20
|
+
export const jobTypeRevivers: Revivers<ApiJobType, JobType> = {
|
|
21
|
+
name: undefined,
|
|
22
|
+
preview: undefined,
|
|
23
|
+
description: undefined,
|
|
24
|
+
components: undefined,
|
|
25
|
+
order: undefined,
|
|
26
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ApiCommonData, ApiError, ApiSuccess, Flatten } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
export type Language = {
|
|
4
|
+
code: string;
|
|
5
|
+
name: string;
|
|
6
|
+
locale: string;
|
|
7
|
+
interface: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ApiLanguage = {
|
|
11
|
+
data: {
|
|
12
|
+
code: string; // The language code
|
|
13
|
+
name: string; // The name of the language (searchable, sortable)
|
|
14
|
+
locale: string; // The locale string for the language (searchable, sortable)
|
|
15
|
+
interface: boolean; // If this language can be used for user interfaces
|
|
16
|
+
} & ApiCommonData;
|
|
17
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
18
|
+
|
|
19
|
+
export type ApiLanguageData = Flatten<Exclude<ApiLanguage, ApiError>['data']>;
|
package/src/api/layer.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ApiCommonData, ApiError, ApiSuccess, Flatten, Revivers } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
export type Layer = {
|
|
4
|
+
id: number;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
svg: string | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ApiLayer = {
|
|
11
|
+
data: {
|
|
12
|
+
id: number; // The id of the layer (sortable)
|
|
13
|
+
name: string; // The name of the layer (searchable, sortable)
|
|
14
|
+
path: string; // The path to the layer
|
|
15
|
+
description: string; // The description of the layer (searchable, sortable)
|
|
16
|
+
image: string | null; // The image related to a layer
|
|
17
|
+
svg: string | null; // The svg related to a layer
|
|
18
|
+
scale_min: number; // The minimum scale for the layer (searchable, sortable)
|
|
19
|
+
scale_max: number; // The maximum scale for the layer (searchable, sortable)
|
|
20
|
+
pangaea_ready: boolean; // Whether a layer is prepared for Pangaea (searchable, sortable)
|
|
21
|
+
svg_set_id: number | null; // TODO: not present in API specification!
|
|
22
|
+
pivot: unknown; // TODO: not present in API specification!
|
|
23
|
+
order?: number; // TODO: not present in API specification!
|
|
24
|
+
} & ApiCommonData;
|
|
25
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
26
|
+
|
|
27
|
+
export type ApiLayerData = Flatten<Exclude<ApiLayer, ApiError>['data']>;
|
|
28
|
+
|
|
29
|
+
export const layerRevivers: Revivers<ApiLayer, Layer> = {
|
|
30
|
+
path: undefined,
|
|
31
|
+
image: undefined,
|
|
32
|
+
scale_min: undefined,
|
|
33
|
+
scale_max: undefined,
|
|
34
|
+
pangaea_ready: undefined,
|
|
35
|
+
svg_set_id: undefined,
|
|
36
|
+
pivot: undefined,
|
|
37
|
+
order: undefined,
|
|
38
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ApiCommonData,
|
|
3
|
+
type ApiError,
|
|
4
|
+
type ApiSuccess,
|
|
5
|
+
type Flatten,
|
|
6
|
+
type Revivers,
|
|
7
|
+
defaultListHeader,
|
|
8
|
+
getSearchParams,
|
|
9
|
+
request,
|
|
10
|
+
} from '../utils.js';
|
|
11
|
+
|
|
12
|
+
export type LayerFaq = {
|
|
13
|
+
id: number;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
mediaUrl: string;
|
|
17
|
+
readMoreUrl: string;
|
|
18
|
+
tags: string[];
|
|
19
|
+
layerId: number;
|
|
20
|
+
order?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ApiLayerFaq = {
|
|
24
|
+
data: {
|
|
25
|
+
id: number; // The id of the layer faq (sortable)
|
|
26
|
+
name: string; // The name of this layer faq (searchable, sortable)
|
|
27
|
+
description: string; // The description of the layer faq (searchable)
|
|
28
|
+
media_url: string; // The image for the faq (searchable)
|
|
29
|
+
read_more_url: string; // A link to a page with more information (searchable)
|
|
30
|
+
tags: string[]; // A list of tags to search in (searchable)
|
|
31
|
+
layer_id: number; // TODO: not present in API specification!
|
|
32
|
+
order?: number; // TODO: not present in API specification!
|
|
33
|
+
} & ApiCommonData;
|
|
34
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
35
|
+
|
|
36
|
+
export type ApiLayerFaqData = Flatten<Exclude<ApiLayerFaq, ApiError>['data']>;
|
|
37
|
+
|
|
38
|
+
export const layerFaqRevivers: Revivers<ApiLayerFaq, LayerFaq> = {
|
|
39
|
+
order: undefined,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export async function listLayerFaqs(): Promise<LayerFaq[]> {
|
|
43
|
+
const pathname = `/v1/layer-faqs`;
|
|
44
|
+
const query = getSearchParams({ sort: 'order,name' });
|
|
45
|
+
const path = `${pathname}?${query}`;
|
|
46
|
+
const options = { revivers: layerFaqRevivers };
|
|
47
|
+
|
|
48
|
+
type ApiLayerFaqArray = {
|
|
49
|
+
data: ApiLayerFaqData[];
|
|
50
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
51
|
+
|
|
52
|
+
return request<ApiLayerFaqArray, LayerFaq>(path, null, defaultListHeader, options);
|
|
53
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Layer } from './layer.js';
|
|
2
|
+
import {
|
|
3
|
+
type ApiCommonData,
|
|
4
|
+
type ApiError,
|
|
5
|
+
type ApiSuccess,
|
|
6
|
+
type Flatten,
|
|
7
|
+
getSearchParams,
|
|
8
|
+
request,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
|
|
11
|
+
export type LayerGroup = {
|
|
12
|
+
id: number;
|
|
13
|
+
name: string;
|
|
14
|
+
layers: Layer[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ApiLayerGroup = {
|
|
18
|
+
data: {
|
|
19
|
+
id: number; // The id of the layer group (sortable)
|
|
20
|
+
name: string; // The name of the layer group (searchable, sortable)
|
|
21
|
+
} & ApiCommonData;
|
|
22
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
23
|
+
|
|
24
|
+
export type ApiLayerGroupData = Flatten<Exclude<ApiLayerGroup, ApiError>['data']>;
|
|
25
|
+
|
|
26
|
+
export async function listLayerGroups(layers: Layer[]): Promise<LayerGroup[]> {
|
|
27
|
+
const pathname = `/v1/layer-groups/for-layer-ids`;
|
|
28
|
+
const query = getSearchParams({ layer_ids: layers.map(layer => layer.id) });
|
|
29
|
+
const path = `${pathname}?${query}`;
|
|
30
|
+
|
|
31
|
+
type ApiLayerGroupArray = {
|
|
32
|
+
data: Array<ApiLayerGroupData & { layers: Array<{ id: number }> }>;
|
|
33
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
34
|
+
|
|
35
|
+
const layerGroups = await request<ApiLayerGroupArray, LayerGroup>(path);
|
|
36
|
+
|
|
37
|
+
// Arrange layers in an object by id for fast lookups
|
|
38
|
+
const layerMap = new Map(layers.map(layer => [layer.id, layer]));
|
|
39
|
+
|
|
40
|
+
// Create a set of all layer ids that belong to a group
|
|
41
|
+
const groupedLayerIds = new Set<number>();
|
|
42
|
+
|
|
43
|
+
for (const layerGroup of layerGroups) {
|
|
44
|
+
// Replace layers from the API response with their full representation
|
|
45
|
+
layerGroup.layers = layerGroup.layers
|
|
46
|
+
.map(groupLayer => layerMap.get(groupLayer.id))
|
|
47
|
+
.filter((layer): layer is Layer => layer !== undefined);
|
|
48
|
+
|
|
49
|
+
// Remember that these layers belong to a group
|
|
50
|
+
for (const layer of layerGroup.layers) {
|
|
51
|
+
groupedLayerIds.add(layer.id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Get a list of layers that don’t belong to any group
|
|
56
|
+
const miscLayers = layers.filter(layer => !groupedLayerIds.has(layer.id));
|
|
57
|
+
|
|
58
|
+
// Sort it alphabetically
|
|
59
|
+
miscLayers.sort((a, b) => a.name.localeCompare(b.name));
|
|
60
|
+
|
|
61
|
+
// Put them all in a separate group
|
|
62
|
+
const miscLayerGroup: LayerGroup = {
|
|
63
|
+
id: 999,
|
|
64
|
+
layers: miscLayers,
|
|
65
|
+
name: 'Other layers',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return [...layerGroups, miscLayerGroup];
|
|
69
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ApiCommonData, ApiError, ApiSuccess, Flatten, Revivers } from '../utils.js';
|
|
2
|
+
|
|
3
|
+
export type MapstyleSet = {
|
|
4
|
+
id: number;
|
|
5
|
+
name: string;
|
|
6
|
+
supportsSvg: boolean;
|
|
7
|
+
disableInteractive: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ApiMapstyleSet = {
|
|
11
|
+
data: {
|
|
12
|
+
id: number; // The id of the mapstyle set (sortable)
|
|
13
|
+
name: string; // The name of the mapstyle set (searchable, sortable)
|
|
14
|
+
description: string; // The description of the set (searchable, sortable)
|
|
15
|
+
supports_svg: boolean; // If the set supports svg (searchable, sortable)
|
|
16
|
+
disable_interactive: boolean; // If interactive export is disabled
|
|
17
|
+
job_type_id: number; // The id of the job type (searchable)
|
|
18
|
+
preview_lat: number; // The latitude for the preview image
|
|
19
|
+
preview_lon: number; // The longitude for the preview image
|
|
20
|
+
preview_language_code: string; // The language code of the preview
|
|
21
|
+
world_cache: string | null; // The name of the world cache (sortable)
|
|
22
|
+
world_cache_max_zoom: number | null; // The max zoom level of the world cache (sortable)
|
|
23
|
+
css: string | null; // Custom CSS for the MapstyleSet (sortable)
|
|
24
|
+
locator_ready: boolean; // If the set can be used as locator (searchable, sortable)
|
|
25
|
+
show_underlying_elements: boolean; // Shows elements even if behind annotations
|
|
26
|
+
ace_on_osm: boolean; // Use OSM source as data for ACE maps (searchable, sortable)
|
|
27
|
+
order?: number; // TODO: not present in API specification!
|
|
28
|
+
custom_settings?: string | null; // TODO: not present in API specification!
|
|
29
|
+
} & ApiCommonData;
|
|
30
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
31
|
+
|
|
32
|
+
export type ApiMapstyleSetData = Flatten<Exclude<ApiMapstyleSet, ApiError>['data']>;
|
|
33
|
+
|
|
34
|
+
export const mapstyleSetRevivers: Revivers<ApiMapstyleSet, MapstyleSet> = {
|
|
35
|
+
description: undefined,
|
|
36
|
+
job_type_id: undefined,
|
|
37
|
+
preview_lat: undefined,
|
|
38
|
+
preview_lon: undefined,
|
|
39
|
+
preview_language_code: undefined,
|
|
40
|
+
world_cache: undefined,
|
|
41
|
+
world_cache_max_zoom: undefined,
|
|
42
|
+
css: undefined,
|
|
43
|
+
locator_ready: undefined,
|
|
44
|
+
show_underlying_elements: undefined,
|
|
45
|
+
ace_on_osm: undefined,
|
|
46
|
+
order: undefined,
|
|
47
|
+
custom_settings: undefined,
|
|
48
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ApiCommon,
|
|
3
|
+
type ApiCommonData,
|
|
4
|
+
type ApiError,
|
|
5
|
+
type ApiSuccess,
|
|
6
|
+
type Flatten,
|
|
7
|
+
type Revivers,
|
|
8
|
+
request,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
|
|
11
|
+
export type Message = {
|
|
12
|
+
index: number;
|
|
13
|
+
image: string;
|
|
14
|
+
date: string;
|
|
15
|
+
read: boolean;
|
|
16
|
+
type: 'New feature' | 'Announcement';
|
|
17
|
+
video: boolean;
|
|
18
|
+
title: string;
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type ApiMessageVariant = {
|
|
23
|
+
language_code: string;
|
|
24
|
+
content: string;
|
|
25
|
+
title: string;
|
|
26
|
+
} & ApiCommonData;
|
|
27
|
+
|
|
28
|
+
export type ApiMessage = {
|
|
29
|
+
data: {
|
|
30
|
+
id: number; // The message id (sortable)
|
|
31
|
+
media_url: string; // The media url for this message (searchable, sortable)
|
|
32
|
+
style: string; // TODO: not present in API specification!
|
|
33
|
+
publish_at: string | null; // TODO: not present in API specification!
|
|
34
|
+
ends_at: string | null; // TODO: not present in API specification!
|
|
35
|
+
variants: ApiMessageVariant[];
|
|
36
|
+
} & ApiCommonData;
|
|
37
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
38
|
+
|
|
39
|
+
export type ApiMessageData = Flatten<Exclude<ApiMessage, ApiError>['data']>;
|
|
40
|
+
|
|
41
|
+
const parseVideo = (url: string, id = getYoutubeVideoId(url)): string =>
|
|
42
|
+
(id ? `https://www.youtube.com/embed/${id}` : url);
|
|
43
|
+
|
|
44
|
+
export const messageRevivers: Revivers<ApiMessage, Message> = {
|
|
45
|
+
id: undefined,
|
|
46
|
+
media_url: undefined,
|
|
47
|
+
style: undefined,
|
|
48
|
+
publish_at: undefined,
|
|
49
|
+
ends_at: undefined,
|
|
50
|
+
variants: undefined,
|
|
51
|
+
|
|
52
|
+
index: (data: ApiMessageData) => data.id,
|
|
53
|
+
image: (data: ApiMessageData) => parseVideo(data.media_url),
|
|
54
|
+
date: (data: ApiMessageData) => data.created_at as string,
|
|
55
|
+
read: () => false,
|
|
56
|
+
type: (data: ApiMessageData) => (data.style === 'regular' ? 'New feature' : 'Announcement'),
|
|
57
|
+
video: (data: ApiMessageData) => data.media_url.includes('www.youtube.com'),
|
|
58
|
+
title: (data: ApiMessageData) => data.variants[0].title,
|
|
59
|
+
text: (data: ApiMessageData) => data.variants[0].content,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export async function markMessageAsRead(messageId: number): Promise<Record<string, never>> {
|
|
63
|
+
const path = `/v1/messages/${messageId}/read`;
|
|
64
|
+
|
|
65
|
+
return request<ApiCommon, Record<string, never>>(path, null, null, { method: 'PUT' });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getYoutubeVideoId(url: string): string | undefined {
|
|
69
|
+
url = url.trim();
|
|
70
|
+
|
|
71
|
+
// Reference prefixed with a $ or video id
|
|
72
|
+
if (/^\$?[\w\-_]+$/.test(url)) {
|
|
73
|
+
return url;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const regex =
|
|
77
|
+
/(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)&?/;
|
|
78
|
+
|
|
79
|
+
return (regex.exec(url) || [])[1];
|
|
80
|
+
}
|