@spencerls/react-native-nfc 1.0.1 → 1.0.2

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.d.mts CHANGED
@@ -1,133 +1,165 @@
1
1
  import * as react_native_nfc_manager from 'react-native-nfc-manager';
2
- import { TagEvent, NdefRecord } from 'react-native-nfc-manager';
2
+ import { TagEvent, NfcTech, NdefRecord } from 'react-native-nfc-manager';
3
+
4
+ type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
5
+
6
+ interface NfcState {
7
+ mode: NfcMode;
8
+ tag: TagEvent | null;
9
+ }
3
10
 
4
- type NfcState = "idle" | "starting" | "active" | "stopping" | "writing";
5
11
  type NfcListener = (state: NfcState) => void;
6
12
  declare class NfcService {
7
13
  private state;
8
- private lastTag;
9
14
  private listeners;
10
15
  constructor();
11
16
  private setState;
12
17
  getState(): NfcState;
13
- getLastTag(): TagEvent | null;
14
18
  subscribe(fn: NfcListener): () => void;
15
19
  startReader(readerModeFlags: number, onTag?: (tag: TagEvent) => void): Promise<void>;
16
20
  stopReader(): Promise<void>;
17
- writeNdef(records: NdefRecord[]): Promise<{
18
- success: boolean;
19
- error: undefined;
20
- }>;
21
+ withTechnology<T>(tech: NfcTech | NfcTech[], handler: () => Promise<T>): Promise<T>;
21
22
  }
22
23
  declare const nfcService: NfcService;
23
24
 
24
- declare function decodeRecord(record: {
25
- tnf: number;
26
- type: number[] | string;
27
- id?: number[];
28
- payload: number[];
29
- }): {
30
- kind: string;
31
- text: string;
32
- lang: string;
33
- uri?: undefined;
34
- mimeType?: undefined;
35
- data?: undefined;
36
- type?: undefined;
37
- tnf?: undefined;
38
- payload?: undefined;
39
- } | {
40
- kind: string;
41
- uri: string;
42
- text?: undefined;
43
- lang?: undefined;
44
- mimeType?: undefined;
45
- data?: undefined;
46
- type?: undefined;
47
- tnf?: undefined;
48
- payload?: undefined;
49
- } | {
50
- kind: string;
51
- mimeType: string;
52
- data: any;
53
- text?: undefined;
54
- lang?: undefined;
55
- uri?: undefined;
56
- type?: undefined;
57
- tnf?: undefined;
58
- payload?: undefined;
59
- } | {
60
- kind: string;
61
- mimeType: string;
62
- data: Uint8Array<ArrayBufferLike>;
63
- text: string | null;
64
- lang?: undefined;
65
- uri?: undefined;
66
- type?: undefined;
67
- tnf?: undefined;
68
- payload?: undefined;
69
- } | {
70
- kind: string;
71
- uri: string;
72
- data: Uint8Array<ArrayBufferLike>;
73
- text?: undefined;
74
- lang?: undefined;
75
- mimeType?: undefined;
76
- type?: undefined;
77
- tnf?: undefined;
78
- payload?: undefined;
79
- } | {
80
- kind: string;
81
- type: string;
82
- data: Uint8Array<ArrayBufferLike>;
83
- text?: undefined;
84
- lang?: undefined;
85
- uri?: undefined;
86
- mimeType?: undefined;
87
- tnf?: undefined;
88
- payload?: undefined;
89
- } | {
90
- kind: string;
91
- tnf: number;
92
- type: string;
93
- payload: Uint8Array<ArrayBufferLike>;
94
- text?: undefined;
95
- lang?: undefined;
96
- uri?: undefined;
97
- mimeType?: undefined;
98
- data?: undefined;
25
+ declare const operations$2: {
26
+ transceive(data: number[]): Promise<number[]>;
99
27
  };
100
- declare function decodeJson(record: NdefRecord): any;
101
- declare function encodeJson(obj: any): {
102
- tnf: 2;
103
- type: number[];
104
- id: never[];
105
- payload: Uint8Array<ArrayBuffer>;
28
+
29
+ declare const NfcAUtils: {};
30
+
31
+ declare const aUtils_NfcAUtils: typeof NfcAUtils;
32
+ declare namespace aUtils {
33
+ export { aUtils_NfcAUtils as NfcAUtils };
34
+ }
35
+
36
+ declare namespace index$2 {
37
+ export { operations$2 as operations, aUtils as utils };
38
+ }
39
+
40
+ declare const operations$1: {
41
+ writeNdef(records: NdefRecord[]): Promise<void>;
42
+ writeTextNdef(text: string): Promise<void>;
43
+ writeUriNdef(uri: string): Promise<void>;
106
44
  };
107
- declare function encodeMime(mimeType: string, data: Uint8Array): {
108
- tnf: 2;
109
- type: number[];
110
- id: never[];
111
- payload: Uint8Array<ArrayBufferLike>;
45
+
46
+ declare const NdefUtils: {};
47
+
48
+ declare const ndefUtils_NdefUtils: typeof NdefUtils;
49
+ declare namespace ndefUtils {
50
+ export { ndefUtils_NdefUtils as NdefUtils };
51
+ }
52
+
53
+ declare namespace index$1 {
54
+ export { operations$1 as operations, ndefUtils as utils };
55
+ }
56
+
57
+ declare const operations: {
58
+ withVTag<T>(handler: (tag: TagEvent & {
59
+ id: string;
60
+ }) => Promise<T>): Promise<T>;
61
+ writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
62
+ readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
63
+ getSystemInfoNfcV(): Promise<any>;
112
64
  };
113
- declare function willFit(tag: TagEvent, records: NdefRecord[]): boolean | null;
114
- declare function spaceLeft(tag: TagEvent, records: NdefRecord[]): number | null;
115
- declare const NfcUtils: {
116
- Ndef: {
117
- decodeRecord: typeof decodeRecord;
118
- decodeJson: typeof decodeJson;
119
- encodeText: (text: string, lang?: string) => NdefRecord;
120
- encodeUri: (uri: string) => NdefRecord;
121
- encodeJson: typeof encodeJson;
122
- encodeMime: typeof encodeMime;
123
- willFit: typeof willFit;
124
- spaceLeft: typeof spaceLeft;
65
+
66
+ declare const NfcVUtils: {
67
+ readonly tech: NfcTech[];
68
+ readonly Flags: {
69
+ readonly HIGH_DATA_RATE: 2;
70
+ readonly ADDRESSED: 32;
71
+ };
72
+ readonly Commands: {
73
+ readonly READ_SINGLE_BLOCK: 32;
74
+ readonly WRITE_SINGLE_BLOCK: 33;
75
+ readonly GET_SYSTEM_INFO: 43;
125
76
  };
77
+ /**
78
+ * Combine multiple flag bits into one byte.
79
+ * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
80
+ */
81
+ readonly flags: (...bits: number[]) => number;
82
+ /**
83
+ * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
84
+ * ISO15693 requires reversed UID for addressed commands.
85
+ */
86
+ readonly reverseUid: (tagIdHex: string) => number[];
87
+ /**
88
+ * Build READ_SINGLE_BLOCK command.
89
+ * FLAGS: addressed + high data rate by default.
90
+ */
91
+ readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
92
+ /**
93
+ * Build WRITE_SINGLE_BLOCK command.
94
+ * Note: data must match the block size (usually 4 or 8 bytes).
95
+ */
96
+ readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
97
+ /**
98
+ * Build GET_SYSTEM_INFO command.
99
+ */
100
+ readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
101
+ /**
102
+ * Parse a READ_SINGLE_BLOCK response.
103
+ * Response format:
104
+ * - byte[0] = status (0x00 = success)
105
+ * - byte[1..] = block payload bytes
106
+ */
107
+ readonly parseReadResponse: (resp: number[]) => Uint8Array;
108
+ /**
109
+ * Parse WRITE_SINGLE_BLOCK response.
110
+ * Successful write has resp[0] === 0x00.
111
+ */
112
+ readonly parseWriteResponse: (resp: number[]) => void;
113
+ /**
114
+ * Parse GET_SYSTEM_INFO response.
115
+ * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
116
+ */
117
+ readonly parseSystemInfo: (resp: number[]) => any;
118
+ /** Identify common manufacturers based on UID prefix */
119
+ readonly detectManufacturer: (uid: string) => string;
126
120
  };
127
121
 
128
- declare function useNfcState(): {
129
- state: NfcState;
130
- lastTag: react_native_nfc_manager.TagEvent | null;
122
+ declare const vUtils_NfcVUtils: typeof NfcVUtils;
123
+ declare namespace vUtils {
124
+ export { vUtils_NfcVUtils as NfcVUtils };
125
+ }
126
+
127
+ declare const index_operations: typeof operations;
128
+ declare namespace index {
129
+ export { index_operations as operations, vUtils as utils };
130
+ }
131
+
132
+ /**
133
+ * NFC root namespace providing access to:
134
+ * - NfcService
135
+ * - ISO15693 NFC-V ops
136
+ * - NFC-A ops
137
+ * - NDEF operations
138
+ */
139
+ declare const nfc: {
140
+ readonly service: NfcService;
141
+ /** ISO15693 protocol helpers and high-level operations */
142
+ readonly v: {
143
+ readonly utils: typeof vUtils;
144
+ readonly withVTag: <T>(handler: (tag: react_native_nfc_manager.TagEvent & {
145
+ id: string;
146
+ }) => Promise<T>) => Promise<T>;
147
+ readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
148
+ readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
149
+ readonly getSystemInfoNfcV: () => Promise<any>;
150
+ };
151
+ /** NFC-A / Type 2 helpers and operations */
152
+ readonly a: {
153
+ readonly utils: typeof aUtils;
154
+ readonly transceive: (data: number[]) => Promise<number[]>;
155
+ };
156
+ /** NDEF read/write utilities and operations */
157
+ readonly ndef: {
158
+ readonly utils: typeof ndefUtils;
159
+ readonly writeNdef: (records: react_native_nfc_manager.NdefRecord[]) => Promise<void>;
160
+ readonly writeTextNdef: (text: string) => Promise<void>;
161
+ readonly writeUriNdef: (uri: string) => Promise<void>;
162
+ };
131
163
  };
132
164
 
133
- export { type NfcListener, type NfcState, NfcUtils, nfcService, useNfcState };
165
+ export { type NfcMode, type NfcState, index$1 as ndef, nfc, index$2 as nfcA, nfcService, index as nfcV };
package/dist/index.d.ts CHANGED
@@ -1,133 +1,165 @@
1
1
  import * as react_native_nfc_manager from 'react-native-nfc-manager';
2
- import { TagEvent, NdefRecord } from 'react-native-nfc-manager';
2
+ import { TagEvent, NfcTech, NdefRecord } from 'react-native-nfc-manager';
3
+
4
+ type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
5
+
6
+ interface NfcState {
7
+ mode: NfcMode;
8
+ tag: TagEvent | null;
9
+ }
3
10
 
4
- type NfcState = "idle" | "starting" | "active" | "stopping" | "writing";
5
11
  type NfcListener = (state: NfcState) => void;
6
12
  declare class NfcService {
7
13
  private state;
8
- private lastTag;
9
14
  private listeners;
10
15
  constructor();
11
16
  private setState;
12
17
  getState(): NfcState;
13
- getLastTag(): TagEvent | null;
14
18
  subscribe(fn: NfcListener): () => void;
15
19
  startReader(readerModeFlags: number, onTag?: (tag: TagEvent) => void): Promise<void>;
16
20
  stopReader(): Promise<void>;
17
- writeNdef(records: NdefRecord[]): Promise<{
18
- success: boolean;
19
- error: undefined;
20
- }>;
21
+ withTechnology<T>(tech: NfcTech | NfcTech[], handler: () => Promise<T>): Promise<T>;
21
22
  }
22
23
  declare const nfcService: NfcService;
23
24
 
24
- declare function decodeRecord(record: {
25
- tnf: number;
26
- type: number[] | string;
27
- id?: number[];
28
- payload: number[];
29
- }): {
30
- kind: string;
31
- text: string;
32
- lang: string;
33
- uri?: undefined;
34
- mimeType?: undefined;
35
- data?: undefined;
36
- type?: undefined;
37
- tnf?: undefined;
38
- payload?: undefined;
39
- } | {
40
- kind: string;
41
- uri: string;
42
- text?: undefined;
43
- lang?: undefined;
44
- mimeType?: undefined;
45
- data?: undefined;
46
- type?: undefined;
47
- tnf?: undefined;
48
- payload?: undefined;
49
- } | {
50
- kind: string;
51
- mimeType: string;
52
- data: any;
53
- text?: undefined;
54
- lang?: undefined;
55
- uri?: undefined;
56
- type?: undefined;
57
- tnf?: undefined;
58
- payload?: undefined;
59
- } | {
60
- kind: string;
61
- mimeType: string;
62
- data: Uint8Array<ArrayBufferLike>;
63
- text: string | null;
64
- lang?: undefined;
65
- uri?: undefined;
66
- type?: undefined;
67
- tnf?: undefined;
68
- payload?: undefined;
69
- } | {
70
- kind: string;
71
- uri: string;
72
- data: Uint8Array<ArrayBufferLike>;
73
- text?: undefined;
74
- lang?: undefined;
75
- mimeType?: undefined;
76
- type?: undefined;
77
- tnf?: undefined;
78
- payload?: undefined;
79
- } | {
80
- kind: string;
81
- type: string;
82
- data: Uint8Array<ArrayBufferLike>;
83
- text?: undefined;
84
- lang?: undefined;
85
- uri?: undefined;
86
- mimeType?: undefined;
87
- tnf?: undefined;
88
- payload?: undefined;
89
- } | {
90
- kind: string;
91
- tnf: number;
92
- type: string;
93
- payload: Uint8Array<ArrayBufferLike>;
94
- text?: undefined;
95
- lang?: undefined;
96
- uri?: undefined;
97
- mimeType?: undefined;
98
- data?: undefined;
25
+ declare const operations$2: {
26
+ transceive(data: number[]): Promise<number[]>;
99
27
  };
100
- declare function decodeJson(record: NdefRecord): any;
101
- declare function encodeJson(obj: any): {
102
- tnf: 2;
103
- type: number[];
104
- id: never[];
105
- payload: Uint8Array<ArrayBuffer>;
28
+
29
+ declare const NfcAUtils: {};
30
+
31
+ declare const aUtils_NfcAUtils: typeof NfcAUtils;
32
+ declare namespace aUtils {
33
+ export { aUtils_NfcAUtils as NfcAUtils };
34
+ }
35
+
36
+ declare namespace index$2 {
37
+ export { operations$2 as operations, aUtils as utils };
38
+ }
39
+
40
+ declare const operations$1: {
41
+ writeNdef(records: NdefRecord[]): Promise<void>;
42
+ writeTextNdef(text: string): Promise<void>;
43
+ writeUriNdef(uri: string): Promise<void>;
106
44
  };
107
- declare function encodeMime(mimeType: string, data: Uint8Array): {
108
- tnf: 2;
109
- type: number[];
110
- id: never[];
111
- payload: Uint8Array<ArrayBufferLike>;
45
+
46
+ declare const NdefUtils: {};
47
+
48
+ declare const ndefUtils_NdefUtils: typeof NdefUtils;
49
+ declare namespace ndefUtils {
50
+ export { ndefUtils_NdefUtils as NdefUtils };
51
+ }
52
+
53
+ declare namespace index$1 {
54
+ export { operations$1 as operations, ndefUtils as utils };
55
+ }
56
+
57
+ declare const operations: {
58
+ withVTag<T>(handler: (tag: TagEvent & {
59
+ id: string;
60
+ }) => Promise<T>): Promise<T>;
61
+ writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
62
+ readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
63
+ getSystemInfoNfcV(): Promise<any>;
112
64
  };
113
- declare function willFit(tag: TagEvent, records: NdefRecord[]): boolean | null;
114
- declare function spaceLeft(tag: TagEvent, records: NdefRecord[]): number | null;
115
- declare const NfcUtils: {
116
- Ndef: {
117
- decodeRecord: typeof decodeRecord;
118
- decodeJson: typeof decodeJson;
119
- encodeText: (text: string, lang?: string) => NdefRecord;
120
- encodeUri: (uri: string) => NdefRecord;
121
- encodeJson: typeof encodeJson;
122
- encodeMime: typeof encodeMime;
123
- willFit: typeof willFit;
124
- spaceLeft: typeof spaceLeft;
65
+
66
+ declare const NfcVUtils: {
67
+ readonly tech: NfcTech[];
68
+ readonly Flags: {
69
+ readonly HIGH_DATA_RATE: 2;
70
+ readonly ADDRESSED: 32;
71
+ };
72
+ readonly Commands: {
73
+ readonly READ_SINGLE_BLOCK: 32;
74
+ readonly WRITE_SINGLE_BLOCK: 33;
75
+ readonly GET_SYSTEM_INFO: 43;
125
76
  };
77
+ /**
78
+ * Combine multiple flag bits into one byte.
79
+ * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
80
+ */
81
+ readonly flags: (...bits: number[]) => number;
82
+ /**
83
+ * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
84
+ * ISO15693 requires reversed UID for addressed commands.
85
+ */
86
+ readonly reverseUid: (tagIdHex: string) => number[];
87
+ /**
88
+ * Build READ_SINGLE_BLOCK command.
89
+ * FLAGS: addressed + high data rate by default.
90
+ */
91
+ readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
92
+ /**
93
+ * Build WRITE_SINGLE_BLOCK command.
94
+ * Note: data must match the block size (usually 4 or 8 bytes).
95
+ */
96
+ readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
97
+ /**
98
+ * Build GET_SYSTEM_INFO command.
99
+ */
100
+ readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
101
+ /**
102
+ * Parse a READ_SINGLE_BLOCK response.
103
+ * Response format:
104
+ * - byte[0] = status (0x00 = success)
105
+ * - byte[1..] = block payload bytes
106
+ */
107
+ readonly parseReadResponse: (resp: number[]) => Uint8Array;
108
+ /**
109
+ * Parse WRITE_SINGLE_BLOCK response.
110
+ * Successful write has resp[0] === 0x00.
111
+ */
112
+ readonly parseWriteResponse: (resp: number[]) => void;
113
+ /**
114
+ * Parse GET_SYSTEM_INFO response.
115
+ * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
116
+ */
117
+ readonly parseSystemInfo: (resp: number[]) => any;
118
+ /** Identify common manufacturers based on UID prefix */
119
+ readonly detectManufacturer: (uid: string) => string;
126
120
  };
127
121
 
128
- declare function useNfcState(): {
129
- state: NfcState;
130
- lastTag: react_native_nfc_manager.TagEvent | null;
122
+ declare const vUtils_NfcVUtils: typeof NfcVUtils;
123
+ declare namespace vUtils {
124
+ export { vUtils_NfcVUtils as NfcVUtils };
125
+ }
126
+
127
+ declare const index_operations: typeof operations;
128
+ declare namespace index {
129
+ export { index_operations as operations, vUtils as utils };
130
+ }
131
+
132
+ /**
133
+ * NFC root namespace providing access to:
134
+ * - NfcService
135
+ * - ISO15693 NFC-V ops
136
+ * - NFC-A ops
137
+ * - NDEF operations
138
+ */
139
+ declare const nfc: {
140
+ readonly service: NfcService;
141
+ /** ISO15693 protocol helpers and high-level operations */
142
+ readonly v: {
143
+ readonly utils: typeof vUtils;
144
+ readonly withVTag: <T>(handler: (tag: react_native_nfc_manager.TagEvent & {
145
+ id: string;
146
+ }) => Promise<T>) => Promise<T>;
147
+ readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
148
+ readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
149
+ readonly getSystemInfoNfcV: () => Promise<any>;
150
+ };
151
+ /** NFC-A / Type 2 helpers and operations */
152
+ readonly a: {
153
+ readonly utils: typeof aUtils;
154
+ readonly transceive: (data: number[]) => Promise<number[]>;
155
+ };
156
+ /** NDEF read/write utilities and operations */
157
+ readonly ndef: {
158
+ readonly utils: typeof ndefUtils;
159
+ readonly writeNdef: (records: react_native_nfc_manager.NdefRecord[]) => Promise<void>;
160
+ readonly writeTextNdef: (text: string) => Promise<void>;
161
+ readonly writeUriNdef: (uri: string) => Promise<void>;
162
+ };
131
163
  };
132
164
 
133
- export { type NfcListener, type NfcState, NfcUtils, nfcService, useNfcState };
165
+ export { type NfcMode, type NfcState, index$1 as ndef, nfc, index$2 as nfcA, nfcService, index as nfcV };