@casual-simulation/aux-common 2.0.27 → 2.0.31

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.
@@ -1,5 +1,5 @@
1
1
  import { AuxGlobalContext, DEBUG_STRING } from './AuxGlobalContext';
2
- import { BotTags, Bot, ShowChatOptions, BotAction, BotsState, CameraType, BarcodeFormat, PortalType, ShowInputOptions, StartCheckoutOptions, LocalFormAnimationAction, ShareOptions, Easing, BotAnchorPoint, RuntimeBot, BotSpace, EaseType, RegisterPrefixOptions, OpenCircleWipeOptions, SuperShoutAction, ShowToastAction, ShowJoinCodeAction, RequestFullscreenAction, ExitFullscreenAction, ShowHtmlAction, HideHtmlAction, SetClipboardAction, FocusOnBotAction, ShowChatBarAction, EnableARAction, EnableVRAction, DownloadAction, ShowUploadAuxFileAction, OpenQRCodeScannerAction, ShowQRCodeAction, OpenBarcodeScannerAction, ShowBarcodeAction, LoadServerAction, UnloadServerAction, ImportAUXAction, ReplaceDragBotAction, ShowInputForTagAction, GoToDimensionAction, GoToURLAction, OpenURLAction, OpenConsoleAction, StartCheckoutAction, FinishCheckoutAction, ApplyStateAction, RejectAction, FocusOnOptions, SnapTarget, AddDropSnapTargetsAction, RecordingOptions, Recording, SyntheticVoice, EnablePOVAction, EnableCustomDraggingAction, SetAppOutputAction, Record, RecordReference, PartialBotsState, ParsedBotLink, ConvertGeolocationToWhat3WordsOptions } from '../bots';
2
+ import { BotTags, Bot, ShowChatOptions, BotAction, BotsState, CameraType, BarcodeFormat, PortalType, ShowInputOptions, StartCheckoutOptions, LocalFormAnimationAction, ShareOptions, Easing, BotAnchorPoint, RuntimeBot, BotSpace, EaseType, RegisterPrefixOptions, OpenCircleWipeOptions, SuperShoutAction, ShowToastAction, ShowJoinCodeAction, RequestFullscreenAction, ExitFullscreenAction, ShowHtmlAction, HideHtmlAction, SetClipboardAction, FocusOnBotAction, ShowChatBarAction, EnableARAction, EnableVRAction, DownloadAction, ShowUploadAuxFileAction, OpenQRCodeScannerAction, ShowQRCodeAction, OpenBarcodeScannerAction, ShowBarcodeAction, LoadServerAction, UnloadServerAction, ImportAUXAction, ReplaceDragBotAction, ShowInputForTagAction, GoToDimensionAction, GoToURLAction, OpenURLAction, OpenConsoleAction, StartCheckoutAction, FinishCheckoutAction, ApplyStateAction, RejectAction, FocusOnOptions, SnapTarget, AddDropSnapTargetsAction, RecordingOptions, Recording, SyntheticVoice, EnablePOVAction, EnableCustomDraggingAction, SetAppOutputAction, Record, RecordReference, PartialBotsState, ParsedBotLink, ConvertGeolocationToWhat3WordsOptions, BeginAudioRecordingAction } from '../bots';
3
3
  import { RemoteAction } from '@casual-simulation/causal-trees';
4
4
  import '../polyfill/Array.first.polyfill';
5
5
  import '../polyfill/Array.last.polyfill';
@@ -8,7 +8,7 @@ import './PerformanceNowPolyfill';
8
8
  import './BlobPolyfill';
9
9
  import { AuxDevice } from './AuxDevice';
10
10
  import { AuxVersion } from './AuxVersion';
11
- import { CreatePublicRecordKeyResult, GetDataResult, RecordDataResult, RecordFileFailure } from '@casual-simulation/aux-records';
11
+ import { CreatePublicRecordKeyResult, GetDataResult, RecordDataResult, RecordFileFailure, EraseDataResult, EraseFileResult } from '@casual-simulation/aux-records';
12
12
  /**
13
13
  * Defines an interface for a function that provides HTML VDOM capabilities to bots.
14
14
  */
@@ -260,39 +260,6 @@ export interface TagSpecificApiOptions {
260
260
  */
261
261
  config: RuntimeBot;
262
262
  }
263
- /**
264
- * Defines an interface that represents the list of bots and tags that are included in a bundle.
265
- */
266
- export interface BundleModules {
267
- [id: string]: Set<string>;
268
- }
269
- /**
270
- * Defines an interface that represents a bundle of code.
271
- */
272
- export interface CodeBundle {
273
- /**
274
- * The tag the bundle was built from.
275
- */
276
- tag: string;
277
- /**
278
- * The source code that the bundle contains.
279
- * If an error occurred, then this will be null/undefined.
280
- */
281
- source?: string;
282
- /**
283
- * The error that occurred while building the bundle.
284
- * Null/Undefined if an error did not happen.
285
- */
286
- error?: string;
287
- /**
288
- * The list of warnings that occurred while building the bundle.
289
- */
290
- warnings: string[];
291
- /**
292
- * The list of modules that the bundle contains.
293
- */
294
- modules: BundleModules;
295
- }
296
263
  /**
297
264
  * Defines an interface that represents a set of records that were retrieved.
298
265
  */
@@ -597,12 +564,20 @@ export declare function createDefaultLibrary(context: AuxGlobalContext): {
597
564
  getPublicRecordKey: (name: string) => Promise<CreatePublicRecordKeyResult>;
598
565
  isRecordKey: (key: unknown) => boolean;
599
566
  recordData: (recordKey: string, address: string, data: any) => Promise<RecordDataResult>;
567
+ recordManualApprovalData: (recordKey: string, address: string, data: any) => Promise<RecordDataResult>;
600
568
  getData: (recordKeyOrName: string, address: string) => Promise<GetDataResult>;
569
+ getManualApprovalData: (recordKeyOrName: string, address: string) => Promise<GetDataResult>;
570
+ eraseData: (recordKey: string, address: string) => Promise<EraseDataResult>;
571
+ eraseManualApprovalData: (recordKey: string, address: string) => Promise<EraseDataResult>;
601
572
  recordFile: (recordKey: string, data: any, options?: RecordFileOptions) => Promise<RecordFileApiResult>;
602
573
  getFile: {
603
574
  (result: RecordFileApiSuccess): Promise<any>;
604
575
  (url: string): Promise<any>;
605
576
  };
577
+ eraseFile: {
578
+ (recordKey: string, result: RecordFileApiSuccess): Promise<EraseFileResult>;
579
+ (recordKey: string, url: string): Promise<EraseFileResult>;
580
+ };
606
581
  convertGeolocationToWhat3Words: (location: ConvertGeolocationToWhat3WordsOptions) => Promise<string>;
607
582
  setupInst: (inst: string, botOrMod?: Mod) => Promise<any>;
608
583
  remotes: () => Promise<string[]>;
@@ -613,6 +588,8 @@ export declare function createDefaultLibrary(context: AuxGlobalContext): {
613
588
  inst: string;
614
589
  lastUpdateTime: Date;
615
590
  }[]>;
591
+ beginAudioRecording: (options?: Omit<BeginAudioRecordingAction, 'type' | 'taskId'>) => Promise<void>;
592
+ endAudioRecording: () => Promise<Blob>;
616
593
  readonly vars: any;
617
594
  };
618
595
  portal: {
@@ -715,7 +692,7 @@ export declare function createDefaultLibrary(context: AuxGlobalContext): {
715
692
  y: number;
716
693
  z: number;
717
694
  };
718
- beginAudioRecording: () => Promise<void>;
695
+ beginAudioRecording: (options?: Omit<BeginAudioRecordingAction, 'type' | 'taskId'>) => Promise<void>;
719
696
  endAudioRecording: () => Promise<Blob>;
720
697
  beginRecording: (options?: RecordingOptions) => Promise<void>;
721
698
  endRecording: () => Promise<Recording>;
@@ -11,7 +11,7 @@ import { DEBUG_STRING, debugStringifyFunction, } from './AuxGlobalContext';
11
11
  import { hasValue, trimTag, isBot, BOT_SPACE_TAG, toast as toastMessage, showJoinCode as calcShowJoinCode, requestFullscreen, exitFullscreen, html as htmlMessage, hideHtml as hideHtmlMessage, setClipboard as calcSetClipboard, tweenTo as calcTweenTo, showChat as calcShowChat, hideChat as calcHideChat, runScript, enableAR as calcEnableAR, disableAR as calcDisableAR, enableVR as calcEnableVR, disableVR as calcDisableVR, showUploadAuxFile as calcShowUploadAuxFile, openQRCodeScanner as calcOpenQRCodeScanner, showQRCode as calcShowQRCode, openBarcodeScanner as calcOpenBarcodeScanner, showBarcode as calcShowBarcode, importAUX as calcImportAUX, showInputForTag as calcShowInputForTag, showInput as calcShowInput, replaceDragBot as calcReplaceDragBot, goToDimension as calcGoToDimension, goToURL as calcGoToURL, openURL as calcOpenURL, checkout as calcCheckout, playSound as calcPlaySound, bufferSound as calcBufferSound, cancelSound as calcCancelSound, setupServer as calcSetupServer, shell as calcShell, backupToGithub as calcBackupToGithub, backupAsDownload as calcBackupAsDownload, finishCheckout as calcFinishCheckout, markHistory as calcMarkHistory, browseHistory as calcBrowseHistory, restoreHistoryMark as calcRestoreHistoryMark, loadFile as calcLoadFile, saveFile as calcSaveFile, reject as calcReject, localFormAnimation as calcLocalFormAnimation, webhook as calcWebhook, superShout as calcSuperShout, share as calcShare, registerPrefix as calcRegisterPrefix, createCertificate as calcCreateCertificate, signTag as calcSignTag, revokeCertificate as calcRevokeCertificate, localPositionTween as calcLocalPositionTween, localRotationTween as calcLocalRotationTween, showUploadFiles as calcShowUploadFiles, download, loadSimulation, unloadSimulation, getUploadState, addState, getPortalTag, KNOWN_PORTALS, openConsole, tagsOnBot, getOriginalObject, getBotSpace, trimEvent, CREATE_ACTION_NAME, CREATE_ANY_ACTION_NAME, DESTROY_ACTION_NAME, ORIGINAL_OBJECT, unlockSpace, getRemoteCount, getServers, getRemotes, action, getServerStatuses, setSpacePassword, exportGpioPin, unexportGpioPin, setGpioPin, getGpioPin, rpioInitPin, rpioExitPin, rpioOpenPin, rpioModePin, rpioReadPin, rpioReadSequencePin, rpioWritePin, rpioWriteSequencePin, rpioReadpadPin, rpioWritepadPin, rpioPudPin, rpioPollPin, rpioClosePin, rpioI2CBeginPin, rpioI2CSetSlaveAddressPin, rpioI2CSetBaudRatePin, rpioI2CSetClockDividerPin, rpioI2CReadPin, rpioI2CWritePin,
12
12
  // rpioI2CReadRegisterRestartPin,
13
13
  // rpioI2CWriteReadRestartPin,
14
- rpioI2CEndPin, rpioPWMSetClockDividerPin, rpioPWMSetRangePin, rpioPWMSetDataPin, rpioSPIBeginPin, rpioSPIChipSelectPin, rpioSPISetCSPolarityPin, rpioSPISetClockDividerPin, rpioSPISetDataModePin, rpioSPITransferPin, rpioSPIWritePin, rpioSPIEndPin, serialConnectPin, serialOpenPin, serialStreamPin, serialUpdatePin, serialWritePin, serialReadPin, serialClosePin, serialFlushPin, serialDrainPin, serialPausePin, serialResumePin, calculateAnchorPoint, calculateAnchorPointOffset, getBotPosition as calcGetBotPosition, isRuntimeBot, SET_TAG_MASK_SYMBOL, CLEAR_TAG_MASKS_SYMBOL, getBotScale, EDIT_TAG_SYMBOL, EDIT_TAG_MASK_SYMBOL, circleWipe, addDropSnap as calcAddDropSnap, animateToPosition, beginAudioRecording as calcBeginAudioRecording, endAudioRecording as calcEndAudioRecording, beginRecording as calcBeginRecording, endRecording as calcEndRecording, speakText as calcSpeakText, getVoices as calcGetVoices, getGeolocation as calcGetGeolocation, cancelAnimation, disablePOV, enablePOV, enableCustomDragging as calcEnableCustomDragging, MINI_PORTAL, registerCustomApp, setAppOutput, unregisterCustomApp, requestAuthData as calcRequestAuthData, createBot, defineGlobalBot as calcDefineGlobalBot, TEMPORARY_BOT_PARTITION_ID, convertToString, GET_TAG_MASKS_SYMBOL, isBotLink, parseBotLink, createBotLink, convertGeolocationToWhat3Words as calcConvertGeolocationToWhat3Words, getPublicRecordKey as calcGetPublicRecordKey, recordData as calcRecordData, getRecordData, recordFile as calcRecordFile, } from '../bots';
14
+ rpioI2CEndPin, rpioPWMSetClockDividerPin, rpioPWMSetRangePin, rpioPWMSetDataPin, rpioSPIBeginPin, rpioSPIChipSelectPin, rpioSPISetCSPolarityPin, rpioSPISetClockDividerPin, rpioSPISetDataModePin, rpioSPITransferPin, rpioSPIWritePin, rpioSPIEndPin, serialConnectPin, serialOpenPin, serialStreamPin, serialUpdatePin, serialWritePin, serialReadPin, serialClosePin, serialFlushPin, serialDrainPin, serialPausePin, serialResumePin, calculateAnchorPoint, calculateAnchorPointOffset, getBotPosition as calcGetBotPosition, isRuntimeBot, SET_TAG_MASK_SYMBOL, CLEAR_TAG_MASKS_SYMBOL, getBotScale, EDIT_TAG_SYMBOL, EDIT_TAG_MASK_SYMBOL, circleWipe, addDropSnap as calcAddDropSnap, animateToPosition, beginAudioRecording as calcBeginAudioRecording, endAudioRecording as calcEndAudioRecording, beginRecording as calcBeginRecording, endRecording as calcEndRecording, speakText as calcSpeakText, getVoices as calcGetVoices, getGeolocation as calcGetGeolocation, cancelAnimation, disablePOV, enablePOV, enableCustomDragging as calcEnableCustomDragging, MINI_PORTAL, registerCustomApp, setAppOutput, unregisterCustomApp, requestAuthData as calcRequestAuthData, createBot, defineGlobalBot as calcDefineGlobalBot, TEMPORARY_BOT_PARTITION_ID, convertToString, GET_TAG_MASKS_SYMBOL, isBotLink, parseBotLink, createBotLink, convertGeolocationToWhat3Words as calcConvertGeolocationToWhat3Words, getPublicRecordKey as calcGetPublicRecordKey, recordData as calcRecordData, getRecordData, eraseRecordData, recordFile as calcRecordFile, eraseFile as calcEraseFile, } from '../bots';
15
15
  import { sortBy, every, cloneDeep, union, isEqual, flatMap } from 'lodash';
16
16
  import { remote as calcRemote, } from '@casual-simulation/causal-trees';
17
17
  import { RanOutOfEnergyError } from './AuxResults';
@@ -293,9 +293,14 @@ export function createDefaultLibrary(context) {
293
293
  getPublicRecordKey,
294
294
  isRecordKey,
295
295
  recordData,
296
+ recordManualApprovalData,
296
297
  getData,
298
+ getManualApprovalData,
299
+ eraseData,
300
+ eraseManualApprovalData,
297
301
  recordFile,
298
302
  getFile,
303
+ eraseFile,
299
304
  convertGeolocationToWhat3Words,
300
305
  setupInst: setupServer,
301
306
  remotes,
@@ -303,6 +308,8 @@ export function createDefaultLibrary(context) {
303
308
  remoteCount: serverRemoteCount,
304
309
  totalRemoteCount: totalRemoteCount,
305
310
  instStatuses: serverStatuses,
311
+ beginAudioRecording,
312
+ endAudioRecording,
306
313
  get vars() {
307
314
  return context.global;
308
315
  },
@@ -1948,10 +1955,14 @@ export function createDefaultLibrary(context) {
1948
1955
  function requestAuthBot() {
1949
1956
  return __awaiter(this, void 0, void 0, function* () {
1950
1957
  const data = yield requestAuthData();
1958
+ if (!data) {
1959
+ return null;
1960
+ }
1951
1961
  let bot = getBot('id', data.userId);
1952
1962
  if (!bot) {
1953
1963
  bot = context.createBot(createBot(data.userId, {
1954
1964
  avatarAddress: data.avatarUrl,
1965
+ avatarPortraitAddress: data.avatarPortraitUrl,
1955
1966
  name: data.name,
1956
1967
  }, TEMPORARY_BOT_PARTITION_ID));
1957
1968
  }
@@ -1992,8 +2003,28 @@ export function createDefaultLibrary(context) {
1992
2003
  * @param data The data that should be stored.
1993
2004
  */
1994
2005
  function recordData(recordKey, address, data) {
2006
+ return baseRecordData(recordKey, address, data, false);
2007
+ }
2008
+ /**
2009
+ * Records the given data to the given address inside the record for the given record key.
2010
+ * Requires manual approval in order to read, write, or erase this data.
2011
+ *
2012
+ * @param recordKey The key that should be used to access the record.
2013
+ * @param address The address that the data should be stored at inside the record.
2014
+ * @param data The data that should be stored.
2015
+ */
2016
+ function recordManualApprovalData(recordKey, address, data) {
2017
+ return baseRecordData(recordKey, address, data, true);
2018
+ }
2019
+ /**
2020
+ * Records the given data to the given address inside the record for the given record key.
2021
+ * @param recordKey The key that should be used to access the record.
2022
+ * @param address The address that the data should be stored at inside the record.
2023
+ * @param data The data that should be stored.
2024
+ */
2025
+ function baseRecordData(recordKey, address, data, requiresApproval) {
1995
2026
  const task = context.createTask();
1996
- const event = calcRecordData(recordKey, address, data, task.taskId);
2027
+ const event = calcRecordData(recordKey, address, convertToCopiableValue(data), requiresApproval, task.taskId);
1997
2028
  return addAsyncAction(task, event);
1998
2029
  }
1999
2030
  /**
@@ -2002,11 +2033,66 @@ export function createDefaultLibrary(context) {
2002
2033
  * @param address The address that the data is stored at.
2003
2034
  */
2004
2035
  function getData(recordKeyOrName, address) {
2036
+ return baseGetData(recordKeyOrName, address, false);
2037
+ }
2038
+ /**
2039
+ * Gets the data stored in the given record at the given address.
2040
+ * @param recordKeyOrName The record that the data should be retrieved from.
2041
+ * @param address The address that the data is stored at.
2042
+ */
2043
+ function getManualApprovalData(recordKeyOrName, address) {
2044
+ return baseGetData(recordKeyOrName, address, true);
2045
+ }
2046
+ /**
2047
+ * Gets the data stored in the given record at the given address.
2048
+ * @param recordKeyOrName The record that the data should be retrieved from.
2049
+ * @param address The address that the data is stored at.
2050
+ */
2051
+ function baseGetData(recordKeyOrName, address, requiresApproval) {
2005
2052
  let recordName = isRecordKey(recordKeyOrName)
2006
2053
  ? parseRecordKey(recordKeyOrName)[0]
2007
2054
  : recordKeyOrName;
2008
2055
  const task = context.createTask();
2009
- const event = getRecordData(recordName, address, task.taskId);
2056
+ const event = getRecordData(recordName, address, requiresApproval, task.taskId);
2057
+ return addAsyncAction(task, event);
2058
+ }
2059
+ /**
2060
+ * Erases the data stored in the given record at the given address.
2061
+ * @param recordKey The key that should be used to access the record.
2062
+ * @param address The address that the data should be erased from.
2063
+ */
2064
+ function eraseData(recordKey, address) {
2065
+ return baseEraseData(recordKey, address, false);
2066
+ }
2067
+ /**
2068
+ * Erases the data stored in the given record at the given address.
2069
+ *
2070
+ * @param recordKey The key that should be used to access the record.
2071
+ * @param address The address that the data should be erased from.
2072
+ */
2073
+ function eraseManualApprovalData(recordKey, address) {
2074
+ return baseEraseData(recordKey, address, true);
2075
+ }
2076
+ /**
2077
+ * Erases the data stored in the given record at the given address.
2078
+ * @param recordKey The key that should be used to access the record.
2079
+ * @param address The address that the data should be erased from.
2080
+ */
2081
+ function baseEraseData(recordKey, address, requiresApproval) {
2082
+ if (!hasValue(recordKey)) {
2083
+ throw new Error('A recordKey must be provided.');
2084
+ }
2085
+ else if (typeof recordKey !== 'string') {
2086
+ throw new Error('recordKey must be a string.');
2087
+ }
2088
+ if (!hasValue(address)) {
2089
+ throw new Error('A address must be provided.');
2090
+ }
2091
+ else if (typeof address !== 'string') {
2092
+ throw new Error('address must be a string.');
2093
+ }
2094
+ const task = context.createTask();
2095
+ const event = eraseRecordData(recordKey, address, requiresApproval, task.taskId);
2010
2096
  return addAsyncAction(task, event);
2011
2097
  }
2012
2098
  /**
@@ -2026,7 +2112,7 @@ export function createDefaultLibrary(context) {
2026
2112
  throw new Error('data must be provided.');
2027
2113
  }
2028
2114
  const task = context.createTask();
2029
- const event = calcRecordFile(recordKey, data, options === null || options === void 0 ? void 0 : options.description, options === null || options === void 0 ? void 0 : options.mimeType, task.taskId);
2115
+ const event = calcRecordFile(recordKey, convertToCopiableValue(data), options === null || options === void 0 ? void 0 : options.description, options === null || options === void 0 ? void 0 : options.mimeType, task.taskId);
2030
2116
  return addAsyncAction(task, event);
2031
2117
  }
2032
2118
  /**
@@ -2055,6 +2141,35 @@ export function createDefaultLibrary(context) {
2055
2141
  final[ORIGINAL_OBJECT] = action;
2056
2142
  return final;
2057
2143
  }
2144
+ /**
2145
+ * Deletes the specified file using the given record key.
2146
+ * @param recordKey The key that should be used to delete the file.
2147
+ * @param urlOrRecordFileResult The URL or the successful result of the record file operation.
2148
+ */
2149
+ function eraseFile(recordKey, fileUrlOrRecordFileResult) {
2150
+ if (!hasValue(recordKey)) {
2151
+ throw new Error('A recordKey must be provided.');
2152
+ }
2153
+ else if (typeof recordKey !== 'string') {
2154
+ throw new Error('recordKey must be a string.');
2155
+ }
2156
+ if (!hasValue(fileUrlOrRecordFileResult)) {
2157
+ throw new Error('A url or successful os.recordFile() result must be provided.');
2158
+ }
2159
+ let url;
2160
+ if (typeof fileUrlOrRecordFileResult === 'string') {
2161
+ url = fileUrlOrRecordFileResult;
2162
+ }
2163
+ else {
2164
+ if (!fileUrlOrRecordFileResult.success) {
2165
+ throw new Error('The result must be a successful os.recordFile() result.');
2166
+ }
2167
+ url = fileUrlOrRecordFileResult.url;
2168
+ }
2169
+ const task = context.createTask();
2170
+ const event = calcEraseFile(recordKey, url, task.taskId);
2171
+ return addAsyncAction(task, event);
2172
+ }
2058
2173
  /**
2059
2174
  * Converts the given geolocation to a what3words (https://what3words.com/) address.
2060
2175
  * @param location The latitude and longitude that should be converted to a 3 word address.
@@ -3217,9 +3332,9 @@ export function createDefaultLibrary(context) {
3217
3332
  /**
3218
3333
  * Starts a new audio recording.
3219
3334
  */
3220
- function beginAudioRecording() {
3335
+ function beginAudioRecording(options) {
3221
3336
  const task = context.createTask();
3222
- const action = calcBeginAudioRecording(task.taskId);
3337
+ const action = calcBeginAudioRecording(options !== null && options !== void 0 ? options : {}, task.taskId);
3223
3338
  return addAsyncAction(task, action);
3224
3339
  }
3225
3340
  /**