@usearete/react 0.49.0 → 0.51.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/dist/index.cjs +51 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +39 -6
- package/dist/index.esm.js +48 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/testing.d.ts +10 -0
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -293,6 +293,7 @@ function AreteProvider({ children, ...config }) {
|
|
|
293
293
|
validateFrames: config.validateFrames,
|
|
294
294
|
onFrameValidationError: config.onFrameValidationError,
|
|
295
295
|
auth: config.auth,
|
|
296
|
+
...(config.environment !== undefined ? { environment: config.environment } : {}),
|
|
296
297
|
wallet: latestWalletRef.current,
|
|
297
298
|
}).then((client) => {
|
|
298
299
|
const ownsAttempt = lifecycleRef.current.active
|
|
@@ -324,7 +325,7 @@ function AreteProvider({ children, ...config }) {
|
|
|
324
325
|
trackConnectingPromise(connectingRef.current, cacheKey, connectionPromise);
|
|
325
326
|
notifyClientChange({ cacheKey, status: 'connecting' });
|
|
326
327
|
return connectionPromise;
|
|
327
|
-
}, [config.autoConnect, config.autoReconnect, config.reconnectIntervals, config.maxReconnectAttempts, config.maxEntriesPerView, config.flushIntervalMs, config.fetch, config.validateFrames, config.onFrameValidationError, config.auth, notifyClientChange]);
|
|
328
|
+
}, [config.autoConnect, config.autoReconnect, config.reconnectIntervals, config.maxReconnectAttempts, config.maxEntriesPerView, config.flushIntervalMs, config.fetch, config.validateFrames, config.onFrameValidationError, config.auth, config.environment, notifyClientChange]);
|
|
328
329
|
const getClient = React.useCallback((stack, options) => {
|
|
329
330
|
if (!stack) {
|
|
330
331
|
if (clientsRef.current.size === 1) {
|
|
@@ -426,6 +427,45 @@ function useConnectionState(stack, options) {
|
|
|
426
427
|
return state;
|
|
427
428
|
}
|
|
428
429
|
|
|
430
|
+
/**
|
|
431
|
+
* The world the enclosing `AreteProvider`'s clients talk to: `'dev'` for
|
|
432
|
+
* the project's dev environment, `'production'` otherwise. With a stack,
|
|
433
|
+
* the connected client's own `client.environment`; before it connects (or
|
|
434
|
+
* without a stack), what the provider's `environment` decides. Outside a
|
|
435
|
+
* provider, `'production'`.
|
|
436
|
+
*/
|
|
437
|
+
function useAreteEnvironment(stack, options) {
|
|
438
|
+
const context = useOptionalAreteContext();
|
|
439
|
+
// Read again when a client connects.
|
|
440
|
+
const [, setRevision] = React.useState(0);
|
|
441
|
+
const subscribe = context?.subscribeToClientChanges;
|
|
442
|
+
React.useEffect(() => subscribe?.(() => setRevision((revision) => revision + 1)), [subscribe]);
|
|
443
|
+
const client = context?.getClient(stack ?? context.config.stack, options);
|
|
444
|
+
if (client)
|
|
445
|
+
return client.environment;
|
|
446
|
+
if (!context)
|
|
447
|
+
return 'production';
|
|
448
|
+
try {
|
|
449
|
+
return sdk.resolveEnvironmentSwitch(context.config.environment).mode;
|
|
450
|
+
}
|
|
451
|
+
catch {
|
|
452
|
+
// A malformed switch fails the client with INVALID_CONFIG; the badge
|
|
453
|
+
// only reports where a working client goes.
|
|
454
|
+
return 'production';
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* A small badge that says the app is talking to the dev environment.
|
|
459
|
+
* Renders nothing in production, so it can stay in the app's status or
|
|
460
|
+
* diagnostics area. Carries `data-arete-environment="dev"` for styling.
|
|
461
|
+
*/
|
|
462
|
+
function AreteEnvironmentBadge({ label = 'Dev environment', className, style, stack, }) {
|
|
463
|
+
const environment = useAreteEnvironment(stack);
|
|
464
|
+
if (environment !== 'dev')
|
|
465
|
+
return null;
|
|
466
|
+
return (React.createElement("span", { role: "status", "data-arete-environment": "dev", className: className, style: style }, label));
|
|
467
|
+
}
|
|
468
|
+
|
|
429
469
|
const AreteSessionContext = React.createContext(null);
|
|
430
470
|
/**
|
|
431
471
|
* `ready()` rejects with this when its `AreteSessionProvider` was removed
|
|
@@ -546,10 +586,14 @@ function AreteSessionProvider(props) {
|
|
|
546
586
|
const given = (props.options ?? {});
|
|
547
587
|
const inheritedAuth = arete?.config.auth;
|
|
548
588
|
const inheritedFetch = arete?.config.fetch;
|
|
589
|
+
const inheritedEnvironment = arete?.config.environment;
|
|
549
590
|
const options = useSameShape({
|
|
550
591
|
...given,
|
|
551
592
|
...(given.auth === undefined && inheritedAuth ? { auth: inheritedAuth } : {}),
|
|
552
593
|
...(given.fetch === undefined && inheritedFetch ? { fetch: inheritedFetch } : {}),
|
|
594
|
+
...(given.environment === undefined && inheritedEnvironment !== undefined
|
|
595
|
+
? { environment: inheritedEnvironment }
|
|
596
|
+
: {}),
|
|
553
597
|
});
|
|
554
598
|
const [attempt, setAttempt] = React.useState(0);
|
|
555
599
|
const key = React.useMemo(() => ({ definition, options, external: externalSession, attempt }), [definition, options, externalSession, attempt]);
|
|
@@ -3276,6 +3320,10 @@ Object.defineProperty(exports, 'DEFAULT_MAX_ENTRIES_PER_VIEW', {
|
|
|
3276
3320
|
enumerable: true,
|
|
3277
3321
|
get: function () { return sdk.DEFAULT_MAX_ENTRIES_PER_VIEW; }
|
|
3278
3322
|
});
|
|
3323
|
+
Object.defineProperty(exports, 'DevEnvironmentError', {
|
|
3324
|
+
enumerable: true,
|
|
3325
|
+
get: function () { return sdk.DevEnvironmentError; }
|
|
3326
|
+
});
|
|
3279
3327
|
Object.defineProperty(exports, 'FrameProcessor', {
|
|
3280
3328
|
enumerable: true,
|
|
3281
3329
|
get: function () { return sdk.FrameProcessor; }
|
|
@@ -3440,6 +3488,7 @@ Object.defineProperty(exports, 'withPrograms', {
|
|
|
3440
3488
|
enumerable: true,
|
|
3441
3489
|
get: function () { return sdk.withPrograms; }
|
|
3442
3490
|
});
|
|
3491
|
+
exports.AreteEnvironmentBadge = AreteEnvironmentBadge;
|
|
3443
3492
|
exports.AreteProvider = AreteProvider;
|
|
3444
3493
|
exports.AreteSessionProvider = AreteSessionProvider;
|
|
3445
3494
|
exports.AreteSessionUnavailableError = AreteSessionUnavailableError;
|
|
@@ -3457,6 +3506,7 @@ exports.toOperationMutationError = toOperationMutationError;
|
|
|
3457
3506
|
exports.useAllowedSteps = useAllowedSteps;
|
|
3458
3507
|
exports.useArete = useArete;
|
|
3459
3508
|
exports.useAreteContext = useAreteContext;
|
|
3509
|
+
exports.useAreteEnvironment = useAreteEnvironment;
|
|
3460
3510
|
exports.useAreteSession = useAreteSession;
|
|
3461
3511
|
exports.useAsyncRead = useAsyncRead;
|
|
3462
3512
|
exports.useConnectionState = useConnectionState;
|