@casual-simulation/aux-common 2.0.21 → 2.0.27

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.
@@ -2238,96 +2238,6 @@ declare interface UnsuccessfulGeolocation {
2238
2238
  */
2239
2239
  declare type GeoLocation = SuccessfulGeolocation | UnsuccessfulGeolocation;
2240
2240
 
2241
-
2242
- /**
2243
- * Defines an event that publishes a record.
2244
- */
2245
- export interface PublishRecordAction extends AsyncAction {
2246
- type: 'publish_record';
2247
-
2248
- /**
2249
- * The auth token that should be used to authenticate the publish record request.
2250
- */
2251
- token: string;
2252
-
2253
- /**
2254
- * The address that the record should be published to.
2255
- */
2256
- address: string;
2257
-
2258
- /**
2259
- * The record data that should be published.
2260
- */
2261
- record: any;
2262
-
2263
- /**
2264
- * The space that the record should be published in.
2265
- */
2266
- space: RecordSpace;
2267
-
2268
- uncopiable: true;
2269
- }
2270
-
2271
- export interface RecordDefinition {
2272
- /**
2273
- * The auth token that should be used to authenticate the publish record request.
2274
- * Different auth tokens can be used to publish records to different CasualOS.me accounts.
2275
- * Defaults to using the auth token in the auth bot.
2276
- */
2277
- authToken?: string;
2278
-
2279
- /**
2280
- * The space that the record should be published in.
2281
- * Defaults to tempRestricted.
2282
- */
2283
- space?: RecordSpace;
2284
-
2285
- /**
2286
- * The record that should be published.
2287
- */
2288
- record: any;
2289
- }
2290
-
2291
- export interface AddressedRecord extends RecordDefinition {
2292
- /**
2293
- * The address that the record should be published to.
2294
- */
2295
- address: string;
2296
- }
2297
-
2298
- export interface PrefixedRecord extends RecordDefinition {
2299
- /**
2300
- * The prefix that the record should be published with.
2301
- */
2302
- prefix?: string;
2303
-
2304
- /**
2305
- * The ID that the record should be published with.
2306
- * Defaults to a UUID.
2307
- */
2308
- id?: string;
2309
- }
2310
-
2311
- export type PublishableRecord = AddressedRecord | PrefixedRecord;
2312
-
2313
-
2314
- export interface DeletableRecord {
2315
- /**
2316
- * The auth token that should be used to authenticate the delete record request.
2317
- */
2318
- authToken?: string;
2319
-
2320
- /**
2321
- * The space that the record lives in.
2322
- */
2323
- space: RecordSpace;
2324
-
2325
- /**
2326
- * The address that the record was published to.
2327
- */
2328
- address: string;
2329
- };
2330
-
2331
2241
  /**
2332
2242
  * Defines an interface that represents options for converting a geolocation to a what3words address.
2333
2243
  */
@@ -2921,6 +2831,170 @@ export interface DebuggerOptions {
2921
2831
  configBot: Bot | BotTags;
2922
2832
  }
2923
2833
 
2834
+
2835
+ /**
2836
+ * Defines an interface that represents the result of a "create public record key" operation.
2837
+ */
2838
+ export type CreatePublicRecordKeyResult =
2839
+ | CreatePublicRecordKeySuccess
2840
+ | CreatePublicRecordKeyFailure;
2841
+
2842
+ /**
2843
+ * Defines an interface that represents a successful "create public record key" result.
2844
+ */
2845
+ export interface CreatePublicRecordKeySuccess {
2846
+ /**
2847
+ * Whether the operation was successful.
2848
+ */
2849
+ success: true;
2850
+
2851
+ /**
2852
+ * The key that was created.
2853
+ */
2854
+ recordKey: string;
2855
+
2856
+ /**
2857
+ * The name of the record the key was created for.
2858
+ */
2859
+ recordName: string;
2860
+ }
2861
+
2862
+ /**
2863
+ * Defines an interface that represents a failed "create public record key" result.
2864
+ */
2865
+ export interface CreatePublicRecordKeyFailure {
2866
+ /**
2867
+ * Whether the operation was successful.
2868
+ */
2869
+ success: false;
2870
+
2871
+ /**
2872
+ * The type of error that occurred.
2873
+ */
2874
+ errorCode: UnauthorizedToCreateRecordKeyError | GeneralRecordError;
2875
+
2876
+ /**
2877
+ * The error message.
2878
+ */
2879
+ errorMessage: string;
2880
+ }
2881
+
2882
+ /**
2883
+ * Defines an error that occurs when a user is not authorized to create a key for the public record.
2884
+ * This may happen when the user is not the owner of the record.
2885
+ */
2886
+ export type UnauthorizedToCreateRecordKeyError =
2887
+ 'unauthorized_to_create_record_key';
2888
+
2889
+ /**
2890
+ * Defines an error that occurs when an unspecified error occurs while creating a public record key.
2891
+ */
2892
+ export type GeneralRecordError = 'general_record_error';
2893
+
2894
+ /**
2895
+ * Defines an error that occurs when an unspecified error occurs while creating a public record key.
2896
+ */
2897
+ export type InvalidRecordKey = 'invalid_record_key';
2898
+
2899
+ /**
2900
+ * Defines an error that occurs when an unspecified error occurs while creating a public record key.
2901
+ */
2902
+ export type ServerError = 'server_error';
2903
+
2904
+ /**
2905
+ * Defines an error that occurs when the user is not logged in but they are required to be in order to perform an action.
2906
+ */
2907
+ export type NotLoggedInError = 'not_logged_in';
2908
+
2909
+ export type RecordNotFoundError = 'record_not_found';
2910
+
2911
+
2912
+
2913
+ export type RecordDataResult = RecordDataSuccess | RecordDataFailure;
2914
+
2915
+ export interface RecordDataSuccess {
2916
+ success: true;
2917
+ recordName: string;
2918
+ address: string;
2919
+ }
2920
+
2921
+ export interface RecordDataFailure {
2922
+ success: false;
2923
+ errorCode:
2924
+ | ServerError
2925
+ | NotLoggedInError
2926
+ | InvalidRecordKey
2927
+ | RecordNotFoundError
2928
+ | 'data_too_large';
2929
+ errorMessage: string;
2930
+ }
2931
+
2932
+ export type GetDataResult = GetDataSuccess | GetDataFailure;
2933
+
2934
+ /**
2935
+ * Defines an interface that represents a successful "get data" result.
2936
+ */
2937
+ export interface GetDataSuccess {
2938
+ success: true;
2939
+
2940
+ /**
2941
+ * The data that was stored.
2942
+ */
2943
+ data: any;
2944
+
2945
+ /**
2946
+ * The name of the record.
2947
+ */
2948
+ recordName: string;
2949
+
2950
+ /**
2951
+ * The ID of the user that owns the record.
2952
+ */
2953
+ publisherId: string;
2954
+
2955
+ /**
2956
+ * The ID of the user that sent the data.
2957
+ */
2958
+ subjectId: string;
2959
+ }
2960
+
2961
+ export interface GetDataFailure {
2962
+ success: false;
2963
+ errorCode: ServerError | 'data_not_found';
2964
+ errorMessage: string;
2965
+ }
2966
+
2967
+
2968
+ export type RecordFileResult = RecordFileSuccess | RecordFileFailure;
2969
+
2970
+ export interface RecordFileSuccess {
2971
+ success: true;
2972
+
2973
+ /**
2974
+ * The URL that the file can be accessed at.
2975
+ */
2976
+ url: string;
2977
+
2978
+ /**
2979
+ * The SHA-256 hash of the file.
2980
+ * When downloading the URL, the resulting data is guaranteed to have a SHA-256 hash that matches this value.
2981
+ */
2982
+ sha256Hash: string;
2983
+ }
2984
+
2985
+ export interface RecordFileFailure {
2986
+ success: false;
2987
+ errorCode:
2988
+ | ServerError
2989
+ | NotLoggedInError
2990
+ | InvalidRecordKey
2991
+ | RecordNotFoundError
2992
+ | 'file_already_exists'
2993
+ | 'invalid_file_data';
2994
+ errorMessage: string;
2995
+ }
2996
+
2997
+
2924
2998
  declare global {
2925
2999
 
2926
3000
  /**
@@ -3526,30 +3600,6 @@ declare global {
3526
3600
  */
3527
3601
  function not(filter: BotFilterFunction): BotFilterFunction;
3528
3602
 
3529
- /**
3530
- * Creates a record filter that retrieves records created by the given Auth ID.
3531
- * @param authID The ID of the creator of the records.
3532
- */
3533
- function byAuthID(authID: string): AuthIdRecordFilter;
3534
-
3535
- /**
3536
- * Creates a record filter that retrieves records with the given address.
3537
- * @param address The address that the record was stored at.
3538
- */
3539
- function byAddress(address: string): AddressRecordFilter;
3540
-
3541
- /**
3542
- * Creates a record filter that retrieves records with the given address.
3543
- * @param token The auth token that should be used to authenticate the getRecords() request.
3544
- */
3545
- function withAuthToken(token: string): AuthTokenRecordFilter;
3546
-
3547
- /**
3548
- * Creates a record filter that retrieves records with the given prefix in their address.
3549
- * @param prefix The prefix that should be matched to record addresses.
3550
- */
3551
- function byPrefix(prefix: string): PrefixRecordFilter;
3552
-
3553
3603
  /**
3554
3604
  * Gets the value of the given tag stored in the given bot.
3555
3605
  * @param bot The bot.
@@ -4299,30 +4349,6 @@ interface Debugger {
4299
4349
  */
4300
4350
  not(filter: BotFilterFunction): BotFilterFunction;
4301
4351
 
4302
- /**
4303
- * Creates a record filter that retrieves records created by the given Auth ID.
4304
- * @param authID The ID of the creator of the records.
4305
- */
4306
- byAuthID(authID: string): AuthIdRecordFilter;
4307
-
4308
- /**
4309
- * Creates a record filter that retrieves records with the given address.
4310
- * @param address The address that the record was stored at.
4311
- */
4312
- byAddress(address: string): AddressRecordFilter;
4313
-
4314
- /**
4315
- * Creates a record filter that retrieves records with the given address.
4316
- * @param token The auth token that should be used to authenticate the getRecords() request.
4317
- */
4318
- withAuthToken(token: string): AuthTokenRecordFilter;
4319
-
4320
- /**
4321
- * Creates a record filter that retrieves records with the given prefix in their address.
4322
- * @param prefix The prefix that should be matched to record addresses.
4323
- */
4324
- byPrefix(prefix: string): PrefixRecordFilter;
4325
-
4326
4352
  /**
4327
4353
  * Gets the value of the given tag stored in the given bot.
4328
4354
  * @param bot The bot.
@@ -4513,6 +4539,22 @@ interface Debugger {
4513
4539
  perf: Perf;
4514
4540
  }
4515
4541
 
4542
+ /**
4543
+ * Defines an interface that represents the set of additional options that can be provided when recording a file.
4544
+ */
4545
+ interface RecordFileOptions {
4546
+ /**
4547
+ * The description of the file.
4548
+ */
4549
+ description?: string;
4550
+
4551
+ /**
4552
+ * The MIME type of the file.
4553
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types for more information.
4554
+ */
4555
+ mimeType?: string;
4556
+ }
4557
+
4516
4558
  interface Os {
4517
4559
  /**
4518
4560
  * Sleeps for time in ms.
@@ -5135,28 +5177,67 @@ interface Os {
5135
5177
  */
5136
5178
  requestAuthBot(): Promise<Bot>;
5137
5179
 
5138
- /**
5139
- * Requests an auth token that does not expire and can be used to authorize other app bundles to publish records for this app bundle.
5140
- */
5141
- requestPermanentAuthToken: MaskFunc<() => Promise<string>>;
5180
+ /**
5181
+ * Gets an access key for the given public record.
5182
+ * @param name The name of the record.
5183
+ */
5184
+ getPublicRecordKey(recordName: string): Promise<CreatePublicRecordKeyResult>;
5142
5185
 
5143
- /**
5144
- * Publishes a record that can be used across instances.
5145
- * @param recordDefinition The data that should be used to publish the record.
5146
- */
5147
- publishRecord: MaskFunc<(recordDefinition: PublishableRecord) => Promise<void>>;
5186
+ /**
5187
+ * Determines if the given value is a record key.
5188
+ * @param key The value to check.
5189
+ */
5190
+ isRecordKey(key: unknown): boolean;
5148
5191
 
5149
- /**
5150
- * Retrives a list of records using the given filters.
5151
- * @param filters The list of filters that should be used to retrieve some records.
5152
- */
5153
- getRecords: MaskFunc<(...filters: RecordFilters[]) => Promise<GetRecordsResult>>;
5192
+ /**
5193
+ * Records the given data to the given address inside the record for the given record key.
5194
+ * @param recordKey The key that should be used to access the record.
5195
+ * @param address The address that the data should be stored at inside the record.
5196
+ * @param data The data that should be stored.
5197
+ */
5198
+ recordData(
5199
+ recordKey: string,
5200
+ address: string,
5201
+ data: any
5202
+ ): Promise<RecordDataResult>;
5203
+
5204
+ /**
5205
+ * Gets the data stored in the given record at the given address.
5206
+ * @param recordKeyOrName The record that the data should be retrieved from.
5207
+ * @param address The address that the data is stored at.
5208
+ */
5209
+ getData(
5210
+ recordKeyOrName: string,
5211
+ address: string
5212
+ ): Promise<GetDataResult>;
5213
+
5214
+ /**
5215
+ * Records the given data as a file.
5216
+ * @param recordKey The record that the file should be recorded in.
5217
+ * @param data The data that should be recorded.
5218
+ * @param options The options that should be used to record the file.
5219
+ */
5220
+ recordFile(
5221
+ recordKey: string,
5222
+ data: any,
5223
+ options?: RecordFileOptions
5224
+ ): Promise<RecordFileResult>;
5154
5225
 
5155
5226
  /**
5156
- * Requests that the given record be destroyed.
5157
- * @param record The record that should be deleted.
5227
+ * Gets the data stored in the given file.
5228
+ * @param result The successful result of a os.recordFile() call.
5158
5229
  */
5159
- destroyRecord: MaskFunc<(record: DeletableRecord) => Promise<void>>;
5230
+ getFile(result: RecordFileSuccess): Promise<any>;
5231
+ /**
5232
+ * Gets the data stored in the given file.
5233
+ * @param url The URL that the file is stored at.
5234
+ */
5235
+ getFile(url: string): Promise<any>;
5236
+ /**
5237
+ * Gets the data stored in the given file.
5238
+ * @param urlOrRecordFileResult The URL or the successful result of the record file operation.
5239
+ */
5240
+ getFile(urlOrRecordFileResult: string | RecordFileSuccess): Promise<any>;
5160
5241
 
5161
5242
  /**
5162
5243
  * Converts the given geolocation to a what3words (https://what3words.com/) address.
@@ -5169,7 +5250,7 @@ interface Os {
5169
5250
  * @param prefix The prefix that code tags should start with.
5170
5251
  * @param options The options that should be used for the prefix.
5171
5252
  */
5172
- registerTagPrefix(prefix: string, options?: RegisterPrefixOptions): Promise<void>;
5253
+ registerTagPrefix(prefix: string, options?: RegisterPrefixOptions): Promise<void>;
5173
5254
 
5174
5255
  /**
5175
5256
  * Gets the number of devices that are viewing the current inst.
@@ -12,7 +12,7 @@ import { addToContext, MemoryGlobalContext, removeFromContext, isInContext, } fr
12
12
  import { createDefaultLibrary, } from './AuxLibrary';
13
13
  import { createRuntimeBot, RealtimeEditMode, } from './RuntimeBot';
14
14
  import { RanOutOfEnergyError } from './AuxResults';
15
- import { convertToCopiableValue, DeepObjectError, formatAuthToken, } from './Utils';
15
+ import { convertToCopiableValue, DeepObjectError, } from './Utils';
16
16
  import { DefaultRealtimeEditModeProvider, } from './AuxRealtimeEditModeProvider';
17
17
  import { sortBy, forOwn, merge, union } from 'lodash';
18
18
  import { tagValueHash } from '../aux-format-2/AuxOpTypes';
@@ -326,12 +326,6 @@ export class AuxRuntime {
326
326
  this._processCore([asyncResult(action.taskId, null)]);
327
327
  }
328
328
  }
329
- else if (action.type === 'update_auth_data') {
330
- const bot = this._compiledState[action.data.userId];
331
- if (bot) {
332
- this.updateTag(bot, 'authToken', formatAuthToken(action.data.token, action.data.service));
333
- }
334
- }
335
329
  else {
336
330
  this._actionBatch.push(action);
337
331
  }