@magield/angular 0.0.0-stage → 0.7.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.
- package/LICENSE +27 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/provide.d.ts +17 -0
- package/dist/provide.js +32 -0
- package/dist/shield.service.d.ts +38 -0
- package/dist/shield.service.js +66 -0
- package/package.json +41 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2026 MagicShield. All rights reserved.
|
|
2
|
+
|
|
3
|
+
MAGIC SHIELD SDK LICENCE
|
|
4
|
+
|
|
5
|
+
This package is published to a public registry so that licensed customers can
|
|
6
|
+
install it with ordinary tooling. Being able to download it does not grant any
|
|
7
|
+
right to use it.
|
|
8
|
+
|
|
9
|
+
You may install, use and redistribute this package, unmodified and only as part
|
|
10
|
+
of your own application, solely to integrate that application with a Magic
|
|
11
|
+
Shield deployment that you are licensed to use under a written agreement with
|
|
12
|
+
MagicShield ("your Agreement"), and only for the term of your Agreement.
|
|
13
|
+
|
|
14
|
+
Except as your Agreement expressly allows, you may not:
|
|
15
|
+
|
|
16
|
+
- use this package for any other purpose, including to build, benchmark or
|
|
17
|
+
assist a competing product;
|
|
18
|
+
- modify it, or reverse engineer, decompile, deobfuscate or disassemble it,
|
|
19
|
+
except to the extent this restriction is unenforceable under applicable law;
|
|
20
|
+
- remove or alter this notice or any copyright or attribution in it.
|
|
21
|
+
|
|
22
|
+
THE PACKAGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXCEPT AS YOUR
|
|
23
|
+
AGREEMENT PROVIDES. IN NO EVENT SHALL MAGICSHIELD BE LIABLE FOR ANY CLAIM,
|
|
24
|
+
DAMAGES OR OTHER LIABILITY ARISING FROM THE PACKAGE OR ITS USE, EXCEPT AS YOUR
|
|
25
|
+
AGREEMENT PROVIDES.
|
|
26
|
+
|
|
27
|
+
Your Agreement governs if it conflicts with this notice.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InjectionToken, type EnvironmentProviders } from '@angular/core';
|
|
2
|
+
import type { ShieldConfig } from '@magield/web';
|
|
3
|
+
export declare const SHIELD_CONFIG: InjectionToken<ShieldConfig>;
|
|
4
|
+
/**
|
|
5
|
+
* Registers Magic Shield once, at the application root.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // app.config.ts
|
|
9
|
+
* providers: [provideShield({ siteKey: 'pk_live_…' })]
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* One instance for the application: warmed signals and the resolved device id
|
|
13
|
+
* live on it, so a per-component instance would redo that work every time.
|
|
14
|
+
*/
|
|
15
|
+
export declare function provideShield(config: ShieldConfig, options?: {
|
|
16
|
+
warmup?: boolean;
|
|
17
|
+
}): EnvironmentProviders;
|
package/dist/provide.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { inject, InjectionToken, makeEnvironmentProviders, NgZone } from '@angular/core';
|
|
2
|
+
import { ShieldService } from './shield.service.js';
|
|
3
|
+
export const SHIELD_CONFIG = new InjectionToken('magic-shield.config');
|
|
4
|
+
/**
|
|
5
|
+
* Registers Magic Shield once, at the application root.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // app.config.ts
|
|
9
|
+
* providers: [provideShield({ siteKey: 'pk_live_…' })]
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* One instance for the application: warmed signals and the resolved device id
|
|
13
|
+
* live on it, so a per-component instance would redo that work every time.
|
|
14
|
+
*/
|
|
15
|
+
export function provideShield(config, options = {}) {
|
|
16
|
+
return makeEnvironmentProviders([
|
|
17
|
+
{ provide: SHIELD_CONFIG, useValue: config },
|
|
18
|
+
{
|
|
19
|
+
provide: ShieldService,
|
|
20
|
+
useFactory: () => {
|
|
21
|
+
const zone = inject(NgZone, { optional: true });
|
|
22
|
+
const service = new ShieldService(inject(SHIELD_CONFIG), zone ?? undefined);
|
|
23
|
+
if (options.warmup !== false) {
|
|
24
|
+
// Not awaited and never surfaced: warmup is an optimisation, and a
|
|
25
|
+
// failed one must not break application bootstrap.
|
|
26
|
+
void service.warmup();
|
|
27
|
+
}
|
|
28
|
+
return service;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type CollectOptions, type CollectResult, type ShieldConfig } from '@magield/web';
|
|
2
|
+
import { type Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* Magic Shield for Angular.
|
|
5
|
+
*
|
|
6
|
+
* Collection runs **outside Angular's zone**. Signal collection touches timers,
|
|
7
|
+
* canvas and storage; inside the zone each of those schedules change detection,
|
|
8
|
+
* so a fingerprint would repaint the application several times for no reason.
|
|
9
|
+
* Results re-enter the zone so template bindings update normally.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ShieldService {
|
|
12
|
+
#private;
|
|
13
|
+
private readonly zone?;
|
|
14
|
+
/** Emits true once warmup has finished. Collection works before that; it is slower. */
|
|
15
|
+
readonly ready$: Observable<boolean>;
|
|
16
|
+
readonly deviceId$: Observable<string | null>;
|
|
17
|
+
constructor(config: ShieldConfig, zone?: ZoneLike | undefined);
|
|
18
|
+
get ready(): boolean;
|
|
19
|
+
get deviceId(): string | null;
|
|
20
|
+
warmup(): Promise<void>;
|
|
21
|
+
/** Returns a token. Nothing is sent anywhere — delivery is yours. */
|
|
22
|
+
collect(options: CollectOptions): Promise<CollectResult>;
|
|
23
|
+
/** The same call as an Observable, for templates and RxJS pipelines. */
|
|
24
|
+
collect$(options: CollectOptions): Observable<CollectResult>;
|
|
25
|
+
getDeviceId(): Promise<string | null>;
|
|
26
|
+
reset(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The part of NgZone this needs.
|
|
30
|
+
*
|
|
31
|
+
* Structural rather than an import of NgZone: it keeps @angular/core a peer
|
|
32
|
+
* dependency at the type level too, and makes the service testable without
|
|
33
|
+
* standing up a zone.
|
|
34
|
+
*/
|
|
35
|
+
export interface ZoneLike {
|
|
36
|
+
run<T>(fn: () => T): T;
|
|
37
|
+
runOutsideAngular<T>(fn: () => T): T;
|
|
38
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createShield, } from '@magield/web';
|
|
2
|
+
import { BehaviorSubject, from } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* Magic Shield for Angular.
|
|
5
|
+
*
|
|
6
|
+
* Collection runs **outside Angular's zone**. Signal collection touches timers,
|
|
7
|
+
* canvas and storage; inside the zone each of those schedules change detection,
|
|
8
|
+
* so a fingerprint would repaint the application several times for no reason.
|
|
9
|
+
* Results re-enter the zone so template bindings update normally.
|
|
10
|
+
*/
|
|
11
|
+
export class ShieldService {
|
|
12
|
+
#shield;
|
|
13
|
+
#ready;
|
|
14
|
+
#deviceId;
|
|
15
|
+
constructor(config, zone) {
|
|
16
|
+
this.zone = zone;
|
|
17
|
+
this.#ready = new BehaviorSubject(false);
|
|
18
|
+
this.#deviceId = new BehaviorSubject(null);
|
|
19
|
+
/** Emits true once warmup has finished. Collection works before that; it is slower. */
|
|
20
|
+
this.ready$ = this.#ready.asObservable();
|
|
21
|
+
this.deviceId$ = this.#deviceId.asObservable();
|
|
22
|
+
this.#shield = createShield(config);
|
|
23
|
+
}
|
|
24
|
+
get ready() {
|
|
25
|
+
return this.#ready.value;
|
|
26
|
+
}
|
|
27
|
+
get deviceId() {
|
|
28
|
+
return this.#deviceId.value;
|
|
29
|
+
}
|
|
30
|
+
async warmup() {
|
|
31
|
+
await this.#outside(async () => {
|
|
32
|
+
await this.#shield.warmup();
|
|
33
|
+
const id = await this.#shield.getDeviceId();
|
|
34
|
+
this.#inside(() => {
|
|
35
|
+
this.#deviceId.next(id);
|
|
36
|
+
this.#ready.next(true);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Returns a token. Nothing is sent anywhere — delivery is yours. */
|
|
41
|
+
async collect(options) {
|
|
42
|
+
return this.#outside(() => this.#shield.collect(options));
|
|
43
|
+
}
|
|
44
|
+
/** The same call as an Observable, for templates and RxJS pipelines. */
|
|
45
|
+
collect$(options) {
|
|
46
|
+
return from(this.collect(options));
|
|
47
|
+
}
|
|
48
|
+
async getDeviceId() {
|
|
49
|
+
const id = await this.#outside(() => this.#shield.getDeviceId());
|
|
50
|
+
this.#inside(() => this.#deviceId.next(id));
|
|
51
|
+
return id;
|
|
52
|
+
}
|
|
53
|
+
async reset() {
|
|
54
|
+
await this.#outside(() => this.#shield.reset());
|
|
55
|
+
this.#inside(() => this.#deviceId.next(null));
|
|
56
|
+
}
|
|
57
|
+
#outside(fn) {
|
|
58
|
+
return this.zone === undefined ? fn() : this.zone.runOutsideAngular(fn);
|
|
59
|
+
}
|
|
60
|
+
#inside(fn) {
|
|
61
|
+
if (this.zone === undefined)
|
|
62
|
+
fn();
|
|
63
|
+
else
|
|
64
|
+
this.zone.run(fn);
|
|
65
|
+
}
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magield/angular",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"description": "Angular bindings for the Magic Shield web SDK",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"!**/*.map",
|
|
9
|
+
"LICENSE"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@angular/core": ">=17",
|
|
24
|
+
"rxjs": ">=7"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@magield/web": "0.7.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@angular/core": "^19.0.4",
|
|
31
|
+
"@types/node": "^22.10.2",
|
|
32
|
+
"rxjs": "^7.8.1",
|
|
33
|
+
"typescript": "^5.7.2",
|
|
34
|
+
"vitest": "^2.1.8",
|
|
35
|
+
"zone.js": "^0.15.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.json",
|
|
39
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
40
|
+
"typecheck:tests": "tsc -p tsconfig.test.json",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"clean": "rm -rf dist .turbo"
|
|
43
|
+
}
|
|
6
44
|
}
|
package/README.md
DELETED