anear-js-api 2.0.1 → 2.1.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.
|
@@ -8,6 +8,9 @@ async function registerAppVersionFromCi({
|
|
|
8
8
|
gitSha = process.env.GITHUB_SHA,
|
|
9
9
|
imageUri = process.env.IMAGE_URI,
|
|
10
10
|
assetManifestHash = process.env.ASSET_MANIFEST_HASH,
|
|
11
|
+
imageAssetsUrl = process.env.IMAGE_ASSETS_URL,
|
|
12
|
+
fontAssetsUrl = process.env.FONT_ASSETS_URL,
|
|
13
|
+
cssUrl = process.env.CSS_URL,
|
|
11
14
|
status = 'building'
|
|
12
15
|
} = {}) {
|
|
13
16
|
if (!appId || !version) {
|
|
@@ -19,7 +22,10 @@ async function registerAppVersionFromCi({
|
|
|
19
22
|
status,
|
|
20
23
|
git_sha: gitSha,
|
|
21
24
|
image_uri: imageUri,
|
|
22
|
-
asset_manifest_hash: assetManifestHash
|
|
25
|
+
asset_manifest_hash: assetManifestHash,
|
|
26
|
+
image_assets_url: imageAssetsUrl,
|
|
27
|
+
font_assets_url: fontAssetsUrl,
|
|
28
|
+
css_url: cssUrl
|
|
23
29
|
})
|
|
24
30
|
|
|
25
31
|
return data
|
|
@@ -61,6 +61,8 @@ const C = require('../utils/Constants')
|
|
|
61
61
|
const CreateVersionedEventChannelNameTemplate = (appId, appVersion) => `anear:${appId}:v:${normalizeVersionToken(appVersion)}:e`
|
|
62
62
|
const DefaultTemplatesRootDir = "./views"
|
|
63
63
|
const SkipRuntimeAssetSync = process.env.ANEARAPP_SKIP_RUNTIME_ASSET_SYNC === 'true'
|
|
64
|
+
const FallbackImageAssetsUrl = process.env.ANEARAPP_IMAGE_ASSETS_URL || null
|
|
65
|
+
const FallbackFontAssetsUrl = process.env.ANEARAPP_FONT_ASSETS_URL || null
|
|
64
66
|
|
|
65
67
|
// Process-wide signal handling.
|
|
66
68
|
// We install exactly once per process to avoid duplicate handlers in reconnect/restart scenarios.
|
|
@@ -161,13 +163,27 @@ const AnearCoreServiceMachineConfig = appId => ({
|
|
|
161
163
|
{
|
|
162
164
|
guard: 'runtimeAssetSyncDisabled',
|
|
163
165
|
actions: () => logger.info('[ACSM] Runtime asset sync disabled; assuming CI has already published assets'),
|
|
164
|
-
target: '
|
|
166
|
+
target: 'resolveVersionAssetUrls'
|
|
165
167
|
},
|
|
166
168
|
{
|
|
167
169
|
target: 'uploadNewImageAssets'
|
|
168
170
|
}
|
|
169
171
|
]
|
|
170
172
|
},
|
|
173
|
+
resolveVersionAssetUrls: {
|
|
174
|
+
invoke: {
|
|
175
|
+
src: 'fetchLatestAppVersionAssets',
|
|
176
|
+
input: ({ context }) => ({ appId: context.appId }),
|
|
177
|
+
onDone: {
|
|
178
|
+
actions: assign({
|
|
179
|
+
imageAssetsUrl: ({ event }) => event.output.imageAssetsUrl,
|
|
180
|
+
fontAssetsUrl: ({ event }) => event.output.fontAssetsUrl
|
|
181
|
+
}),
|
|
182
|
+
target: 'loadAndCompilePugTemplates'
|
|
183
|
+
},
|
|
184
|
+
onError: '#failure'
|
|
185
|
+
}
|
|
186
|
+
},
|
|
171
187
|
uploadNewImageAssets: {
|
|
172
188
|
invoke: {
|
|
173
189
|
src: 'uploadNewImageAssets',
|
|
@@ -255,6 +271,19 @@ const AnearCoreServiceMachineFunctions = {
|
|
|
255
271
|
// v5 pattern: async "services" become Promise Actors via `fromPromise`.
|
|
256
272
|
// The invoked actor receives `input` from the invoking state's `invoke.input`.
|
|
257
273
|
fetchAppData: fromPromise(({ input }) => AnearApi.getApp(input.appId)),
|
|
274
|
+
fetchLatestAppVersionAssets: fromPromise(async ({ input }) => {
|
|
275
|
+
const latestVersion = await AnearApi.getLatestAppVersion(input.appId)
|
|
276
|
+
const attrs = latestVersion?.attributes || {}
|
|
277
|
+
const imageAssetsUrl = attrs['image-assets-url'] || FallbackImageAssetsUrl
|
|
278
|
+
const fontAssetsUrl = attrs['font-assets-url'] || FallbackFontAssetsUrl
|
|
279
|
+
|
|
280
|
+
if (!imageAssetsUrl) {
|
|
281
|
+
throw new Error('[ACSM] Missing image-assets-url for latest app version; set app_version image_assets_url in ANAPI or ANEARAPP_IMAGE_ASSETS_URL env var')
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
logger.info(`[ACSM] Using pre-published version assets image_base=${imageAssetsUrl}`)
|
|
285
|
+
return { imageAssetsUrl, fontAssetsUrl }
|
|
286
|
+
}),
|
|
258
287
|
uploadNewImageAssets: fromPromise(({ input }) => {
|
|
259
288
|
const uploader = new ImageAssetsUploader(C.ImagesDirPath, input.appId)
|
|
260
289
|
return uploader.uploadAssets()
|