@spencerls/react-native-nfc 1.0.1 → 1.0.3

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,173 @@
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
+ /**
26
+ * NFC root namespace providing access to:
27
+ * - NfcService
28
+ * - ISO15693 NFC-V ops
29
+ * - NFC-A ops
30
+ * - NDEF operations
31
+ */
32
+ declare const nfc: {
33
+ readonly service: NfcService;
34
+ /** ISO15693 protocol helpers and high-level operations */
35
+ readonly v: {
36
+ readonly utils: {
37
+ readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
38
+ readonly Flags: {
39
+ readonly HIGH_DATA_RATE: 2;
40
+ readonly ADDRESSED: 32;
41
+ };
42
+ readonly Commands: {
43
+ readonly READ_SINGLE_BLOCK: 32;
44
+ readonly WRITE_SINGLE_BLOCK: 33;
45
+ readonly GET_SYSTEM_INFO: 43;
46
+ };
47
+ readonly flags: (...bits: number[]) => number;
48
+ readonly reverseUid: (tagIdHex: string) => number[];
49
+ readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
50
+ readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
51
+ readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
52
+ readonly parseReadResponse: (resp: number[]) => Uint8Array;
53
+ readonly parseWriteResponse: (resp: number[]) => void;
54
+ readonly parseSystemInfo: (resp: number[]) => any;
55
+ readonly detectManufacturer: (uid: string) => string;
56
+ };
57
+ readonly withVTag: <T>(handler: (tag: react_native_nfc_manager.TagEvent & {
58
+ id: string;
59
+ }) => Promise<T>) => Promise<T>;
60
+ readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
61
+ readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
62
+ readonly getSystemInfoNfcV: () => Promise<any>;
63
+ };
64
+ /** NFC-A / Type 2 helpers and operations */
65
+ readonly a: {
66
+ readonly utils: {};
67
+ readonly transceive: (data: number[]) => Promise<number[]>;
68
+ };
69
+ /** NDEF read/write utilities and operations */
70
+ readonly ndef: {
71
+ readonly utils: {};
72
+ readonly writeNdef: (records: react_native_nfc_manager.NdefRecord[]) => Promise<void>;
73
+ readonly writeTextNdef: (text: string) => Promise<void>;
74
+ readonly writeUriNdef: (uri: string) => Promise<void>;
75
+ };
76
+ };
77
+
78
+ declare const operations$2: {
79
+ transceive(data: number[]): Promise<number[]>;
99
80
  };
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>;
81
+
82
+ declare const NfcAUtils: {};
83
+
84
+ declare const index$2_NfcAUtils: typeof NfcAUtils;
85
+ declare namespace index$2 {
86
+ export { index$2_NfcAUtils as NfcAUtils, operations$2 as operations };
87
+ }
88
+
89
+ declare const operations$1: {
90
+ writeNdef(records: NdefRecord[]): Promise<void>;
91
+ writeTextNdef(text: string): Promise<void>;
92
+ writeUriNdef(uri: string): Promise<void>;
106
93
  };
107
- declare function encodeMime(mimeType: string, data: Uint8Array): {
108
- tnf: 2;
109
- type: number[];
110
- id: never[];
111
- payload: Uint8Array<ArrayBufferLike>;
94
+
95
+ declare const NdefUtils: {};
96
+
97
+ declare const index$1_NdefUtils: typeof NdefUtils;
98
+ declare namespace index$1 {
99
+ export { index$1_NdefUtils as NdefUtils, operations$1 as operations };
100
+ }
101
+
102
+ declare const operations: {
103
+ withVTag<T>(handler: (tag: TagEvent & {
104
+ id: string;
105
+ }) => Promise<T>): Promise<T>;
106
+ writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
107
+ readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
108
+ getSystemInfoNfcV(): Promise<any>;
112
109
  };
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;
110
+
111
+ declare const NfcVUtils: {
112
+ readonly tech: NfcTech.NfcV | NfcTech[];
113
+ readonly Flags: {
114
+ readonly HIGH_DATA_RATE: 2;
115
+ readonly ADDRESSED: 32;
116
+ };
117
+ readonly Commands: {
118
+ readonly READ_SINGLE_BLOCK: 32;
119
+ readonly WRITE_SINGLE_BLOCK: 33;
120
+ readonly GET_SYSTEM_INFO: 43;
125
121
  };
122
+ /**
123
+ * Combine multiple flag bits into one byte.
124
+ * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
125
+ */
126
+ readonly flags: (...bits: number[]) => number;
127
+ /**
128
+ * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
129
+ * ISO15693 requires reversed UID for addressed commands.
130
+ */
131
+ readonly reverseUid: (tagIdHex: string) => number[];
132
+ /**
133
+ * Build READ_SINGLE_BLOCK command.
134
+ * FLAGS: addressed + high data rate by default.
135
+ */
136
+ readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
137
+ /**
138
+ * Build WRITE_SINGLE_BLOCK command.
139
+ * Note: data must match the block size (usually 4 or 8 bytes).
140
+ */
141
+ readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
142
+ /**
143
+ * Build GET_SYSTEM_INFO command.
144
+ */
145
+ readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
146
+ /**
147
+ * Parse a READ_SINGLE_BLOCK response.
148
+ * Response format:
149
+ * - byte[0] = status (0x00 = success)
150
+ * - byte[1..] = block payload bytes
151
+ */
152
+ readonly parseReadResponse: (resp: number[]) => Uint8Array;
153
+ /**
154
+ * Parse WRITE_SINGLE_BLOCK response.
155
+ * Successful write has resp[0] === 0x00.
156
+ */
157
+ readonly parseWriteResponse: (resp: number[]) => void;
158
+ /**
159
+ * Parse GET_SYSTEM_INFO response.
160
+ * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
161
+ */
162
+ readonly parseSystemInfo: (resp: number[]) => any;
163
+ /** Identify common manufacturers based on UID prefix */
164
+ readonly detectManufacturer: (uid: string) => string;
126
165
  };
127
166
 
128
- declare function useNfcState(): {
129
- state: NfcState;
130
- lastTag: react_native_nfc_manager.TagEvent | null;
131
- };
167
+ declare const index_NfcVUtils: typeof NfcVUtils;
168
+ declare const index_operations: typeof operations;
169
+ declare namespace index {
170
+ export { index_NfcVUtils as NfcVUtils, index_operations as operations };
171
+ }
132
172
 
133
- export { type NfcListener, type NfcState, NfcUtils, nfcService, useNfcState };
173
+ 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,173 @@
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
+ /**
26
+ * NFC root namespace providing access to:
27
+ * - NfcService
28
+ * - ISO15693 NFC-V ops
29
+ * - NFC-A ops
30
+ * - NDEF operations
31
+ */
32
+ declare const nfc: {
33
+ readonly service: NfcService;
34
+ /** ISO15693 protocol helpers and high-level operations */
35
+ readonly v: {
36
+ readonly utils: {
37
+ readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
38
+ readonly Flags: {
39
+ readonly HIGH_DATA_RATE: 2;
40
+ readonly ADDRESSED: 32;
41
+ };
42
+ readonly Commands: {
43
+ readonly READ_SINGLE_BLOCK: 32;
44
+ readonly WRITE_SINGLE_BLOCK: 33;
45
+ readonly GET_SYSTEM_INFO: 43;
46
+ };
47
+ readonly flags: (...bits: number[]) => number;
48
+ readonly reverseUid: (tagIdHex: string) => number[];
49
+ readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
50
+ readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
51
+ readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
52
+ readonly parseReadResponse: (resp: number[]) => Uint8Array;
53
+ readonly parseWriteResponse: (resp: number[]) => void;
54
+ readonly parseSystemInfo: (resp: number[]) => any;
55
+ readonly detectManufacturer: (uid: string) => string;
56
+ };
57
+ readonly withVTag: <T>(handler: (tag: react_native_nfc_manager.TagEvent & {
58
+ id: string;
59
+ }) => Promise<T>) => Promise<T>;
60
+ readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
61
+ readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
62
+ readonly getSystemInfoNfcV: () => Promise<any>;
63
+ };
64
+ /** NFC-A / Type 2 helpers and operations */
65
+ readonly a: {
66
+ readonly utils: {};
67
+ readonly transceive: (data: number[]) => Promise<number[]>;
68
+ };
69
+ /** NDEF read/write utilities and operations */
70
+ readonly ndef: {
71
+ readonly utils: {};
72
+ readonly writeNdef: (records: react_native_nfc_manager.NdefRecord[]) => Promise<void>;
73
+ readonly writeTextNdef: (text: string) => Promise<void>;
74
+ readonly writeUriNdef: (uri: string) => Promise<void>;
75
+ };
76
+ };
77
+
78
+ declare const operations$2: {
79
+ transceive(data: number[]): Promise<number[]>;
99
80
  };
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>;
81
+
82
+ declare const NfcAUtils: {};
83
+
84
+ declare const index$2_NfcAUtils: typeof NfcAUtils;
85
+ declare namespace index$2 {
86
+ export { index$2_NfcAUtils as NfcAUtils, operations$2 as operations };
87
+ }
88
+
89
+ declare const operations$1: {
90
+ writeNdef(records: NdefRecord[]): Promise<void>;
91
+ writeTextNdef(text: string): Promise<void>;
92
+ writeUriNdef(uri: string): Promise<void>;
106
93
  };
107
- declare function encodeMime(mimeType: string, data: Uint8Array): {
108
- tnf: 2;
109
- type: number[];
110
- id: never[];
111
- payload: Uint8Array<ArrayBufferLike>;
94
+
95
+ declare const NdefUtils: {};
96
+
97
+ declare const index$1_NdefUtils: typeof NdefUtils;
98
+ declare namespace index$1 {
99
+ export { index$1_NdefUtils as NdefUtils, operations$1 as operations };
100
+ }
101
+
102
+ declare const operations: {
103
+ withVTag<T>(handler: (tag: TagEvent & {
104
+ id: string;
105
+ }) => Promise<T>): Promise<T>;
106
+ writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
107
+ readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
108
+ getSystemInfoNfcV(): Promise<any>;
112
109
  };
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;
110
+
111
+ declare const NfcVUtils: {
112
+ readonly tech: NfcTech.NfcV | NfcTech[];
113
+ readonly Flags: {
114
+ readonly HIGH_DATA_RATE: 2;
115
+ readonly ADDRESSED: 32;
116
+ };
117
+ readonly Commands: {
118
+ readonly READ_SINGLE_BLOCK: 32;
119
+ readonly WRITE_SINGLE_BLOCK: 33;
120
+ readonly GET_SYSTEM_INFO: 43;
125
121
  };
122
+ /**
123
+ * Combine multiple flag bits into one byte.
124
+ * Example: Flags.ADDRESSED | Flags.HIGH_DATA_RATE
125
+ */
126
+ readonly flags: (...bits: number[]) => number;
127
+ /**
128
+ * Convert tag.id hex string (MSB->LSB) into reversed byte array (LSB->MSB)
129
+ * ISO15693 requires reversed UID for addressed commands.
130
+ */
131
+ readonly reverseUid: (tagIdHex: string) => number[];
132
+ /**
133
+ * Build READ_SINGLE_BLOCK command.
134
+ * FLAGS: addressed + high data rate by default.
135
+ */
136
+ readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
137
+ /**
138
+ * Build WRITE_SINGLE_BLOCK command.
139
+ * Note: data must match the block size (usually 4 or 8 bytes).
140
+ */
141
+ readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
142
+ /**
143
+ * Build GET_SYSTEM_INFO command.
144
+ */
145
+ readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
146
+ /**
147
+ * Parse a READ_SINGLE_BLOCK response.
148
+ * Response format:
149
+ * - byte[0] = status (0x00 = success)
150
+ * - byte[1..] = block payload bytes
151
+ */
152
+ readonly parseReadResponse: (resp: number[]) => Uint8Array;
153
+ /**
154
+ * Parse WRITE_SINGLE_BLOCK response.
155
+ * Successful write has resp[0] === 0x00.
156
+ */
157
+ readonly parseWriteResponse: (resp: number[]) => void;
158
+ /**
159
+ * Parse GET_SYSTEM_INFO response.
160
+ * Returns: UID, DSFID, AFI, numberOfBlocks, blockSize, manufacturer
161
+ */
162
+ readonly parseSystemInfo: (resp: number[]) => any;
163
+ /** Identify common manufacturers based on UID prefix */
164
+ readonly detectManufacturer: (uid: string) => string;
126
165
  };
127
166
 
128
- declare function useNfcState(): {
129
- state: NfcState;
130
- lastTag: react_native_nfc_manager.TagEvent | null;
131
- };
167
+ declare const index_NfcVUtils: typeof NfcVUtils;
168
+ declare const index_operations: typeof operations;
169
+ declare namespace index {
170
+ export { index_NfcVUtils as NfcVUtils, index_operations as operations };
171
+ }
132
172
 
133
- export { type NfcListener, type NfcState, NfcUtils, nfcService, useNfcState };
173
+ export { type NfcMode, type NfcState, index$1 as ndef, nfc, index$2 as nfcA, nfcService, index as nfcV };